enable TRex to run with --rt : real time priority for DP and RX cores 71/5271/1
authorimarom <[email protected]>
Mon, 23 Jan 2017 12:06:52 +0000 (14:06 +0200)
committerimarom <[email protected]>
Mon, 23 Jan 2017 12:07:49 +0000 (14:07 +0200)
Signed-off-by: imarom <[email protected]>
scripts/trex_show_threads.py
src/bp_sim.h
src/main_dpdk.cpp

index 1824d07..d0e34fe 100755 (executable)
@@ -17,7 +17,8 @@ def read_task_stats (task_path):
     stat_data = open(stat, 'r').readline().split()
 
     stats_dict['last_sched_cpu'] = stat_data[-14]
-
+    stats_dict['priority'] = stat_data[17] if stat_data[43] == '0' else 'RT'
+    
     return stats_dict
 
 
@@ -26,7 +27,7 @@ def show_threads (pid):
     task_paths = ["{0}/{1}".format(process_dir, task) for task in os.listdir(process_dir)]
 
     
-    header = [ 'Task Name', 'PID', 'Allowed CPU', 'Last Sched CPU', 'Asked Ctx Switch', 'Forced Ctx Switch']
+    header = [ 'Task Name', 'PID', 'Priority', 'Allowed CPU', 'Last Sched CPU', 'Asked Ctx Switch', 'Forced Ctx Switch']
     for x in header:
         print('{:^20}'.format(x)),
     print("")
@@ -41,6 +42,7 @@ def show_threads (pid):
         # name
         print("{:<20}".format(task['name'])),
         print("{:^20}".format(task['pid'])),
+        print("{:^20}".format(task['priority'])),
         print("{:^20}".format(task['cpus_allowed_list'])),
         print("{:^20}".format(task['last_sched_cpu'])),
         print("{:^20}".format(task['voluntary_ctxt_switches'])),
index 282e7fe..217446e 100755 (executable)
@@ -628,6 +628,14 @@ public:
         return (btGetMaskBit32(m_flags1, 9, 9) ? true : false);
     }
 
+    void set_rt_prio_mode(bool enable) {
+        btSetMaskBit32(m_flags1, 10, 10, (enable ? 1 : 0) );
+    }
+
+    bool get_rt_prio_mode() {
+        return (btGetMaskBit32(m_flags1, 10, 10) ? true : false);
+    }
+    
 public:
     void Dump(FILE *fd);
 
index aa31cf0..f58e403 100644 (file)
@@ -713,7 +713,8 @@ enum { OPT_HELP,
        OPT_ARP_REF_PER,
        OPT_NO_OFED_CHECK,
        OPT_NO_SCAPY_SERVER,
-       OPT_ACTIVE_FLOW
+       OPT_ACTIVE_FLOW,
+       OPT_RT
 };
 
 /* these are the argument types:
@@ -774,6 +775,7 @@ static CSimpleOpt::SOption parser_options[] =
         { OPT_ARP_REF_PER,            "--arp-refresh-period", SO_REQ_SEP },
         { OPT_NO_OFED_CHECK,          "--no-ofed-check",   SO_NONE    },
         { OPT_NO_SCAPY_SERVER,        "--no-scapy-server", SO_NONE    },
+        { OPT_RT,                     "--rt",              SO_NONE    },
         SO_END_OF_OPTIONS
     };
 
@@ -828,6 +830,7 @@ static int usage(){
     printf(" --no-ofed-check            : Disable the check of OFED version \n");
     printf(" --no-scapy-server          : Disable Scapy server implicit start at stateless \n");
     printf(" --no-watchdog              : Disable watchdog \n");
+    printf(" --rt                       : Run TRex DP/RX cores in realtime priority \n");
     printf(" -p                         : Send all flow packets from the same interface (choosed randomly between client ad server ports) without changing their src/dst IP \n");
     printf(" -pm                        : Platform factor. If you have splitter in the setup, you can multiply the total results by this factor \n");
     printf("    e.g --pm 2.0 will multiply all the results bps in this factor \n");
@@ -956,6 +959,9 @@ static int parse_options(int argc, char *argv[], CParserOption* po, bool first_t
                 po->preview.set_ipv6_mode_enable(true);
                 break;
 
+            case OPT_RT:
+                po->preview.set_rt_prio_mode(true);
+                break;
 
             case OPT_LEARN :
                 po->m_learn_mode = CParserOption::LEARN_MODE_IP_OPTION;
@@ -4845,8 +4851,20 @@ int CGlobalTRex::run_in_master() {
 
 int CGlobalTRex::run_in_rx_core(void){
 
+    CPreviewMode *lp = &CGlobalInfo::m_options.preview;
+    
     rte_thread_setname(pthread_self(), "TRex RX");
-
+    
+    /* set RT mode if set */
+    if (lp->get_rt_prio_mode()) {
+        struct sched_param param;
+        param.sched_priority = sched_get_priority_max(SCHED_FIFO);
+        if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &param) != 0) {
+            perror("setting RT priroity mode on RX core failed with error");
+            exit(EXIT_FAILURE);
+        }
+    }
+    
     if (get_is_stateless()) {
         m_sl_rx_running = true;
         m_rx_sl.start();
@@ -4863,11 +4881,22 @@ int CGlobalTRex::run_in_rx_core(void){
 
 int CGlobalTRex::run_in_core(virtual_thread_id_t virt_core_id){
     std::stringstream ss;
-
+    CPreviewMode *lp = &CGlobalInfo::m_options.preview;
+    
     ss << "Trex DP core " << int(virt_core_id);
     rte_thread_setname(pthread_self(), ss.str().c_str());
+    
+    /* set RT mode if set */
+    if (lp->get_rt_prio_mode()) {
+        struct sched_param param;
+        param.sched_priority = sched_get_priority_max(SCHED_FIFO);
+        if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &param) != 0) {
+            perror("setting RT priroity mode on DP core failed with error");
+            exit(EXIT_FAILURE);
+        }
+    }
 
-    CPreviewMode *lp=&CGlobalInfo::m_options.preview;
+    
     if ( lp->getSingleCore() &&
          (virt_core_id==2 ) &&
          (lp-> getCores() ==1) ){