Add affinity for scapy_daemon_server to master thread from config file 23/5323/1
authorYaroslav Brustinov <[email protected]>
Wed, 21 Dec 2016 14:36:29 +0000 (16:36 +0200)
committerYaroslav Brustinov <[email protected]>
Wed, 21 Dec 2016 14:36:29 +0000 (16:36 +0200)
Change-Id: I83d3138b713f3448bbc649e6d7a5fabe3860285c
Signed-off-by: Yaroslav Brustinov <[email protected]>
scripts/dpdk_setup_ports.py
scripts/scapy_daemon_server

index 1edf8f8..3f24b24 100755 (executable)
@@ -543,7 +543,11 @@ Other network devices
                 else:
                        print('WARNING: Some other program is using DPDK driver.\nIf it is TRex and you did not configure it for dual run, current command will fail.')
         if map_driver.parent_args.stl:
-            ret = os.system('%s scapy_daemon_server restart' % sys.executable)
+            try:
+                master_core = self.m_cfg_dict[0]['platform']['master_thread_id']
+            except:
+                master_core = 0
+            ret = os.system('%s scapy_daemon_server restart -c %s' % (sys.executable, master_core))
             if ret:
                 sys.exit(1)
 
index 99f8a6a..a5e4df0 100755 (executable)
@@ -73,7 +73,7 @@ def run_command(command, timeout = 15, poll_rate = 0.1, cwd = None):
 def get_daemon_pid():
     pid = None
     for conn in netstat.netstat():
-        if conn[2] == '0.0.0.0' and int(conn[3]) == args.daemon_port and conn[6] == 'LISTEN':
+        if conn[2] == '0.0.0.0' and int(conn[3]) == args.port and conn[6] == 'LISTEN':
             pid = conn[7]
             if pid is None:
                 raise Exception('Found the connection, but could not determine pid: %s' % conn)
@@ -84,7 +84,7 @@ def get_daemon_pid():
 # faster variant of get_daemon_pid
 def is_running():
     for conn in netstat.netstat(with_pid = False):
-        if conn[2] == '0.0.0.0' and int(conn[3]) == args.daemon_port and conn[6] == 'LISTEN':
+        if conn[2] == '0.0.0.0' and int(conn[3]) == args.port and conn[6] == 'LISTEN':
             return True
     return False
 
@@ -102,8 +102,8 @@ def start_daemon():
         return
     server_path = os.path.join(pwd, 'automation', 'trex_control_plane', 'stl', 'services', 'scapy_server')
     with tempfile.TemporaryFile() as stdout_file:
-        subprocess.Popen(shlex.split("su -s /bin/bash -c '%s scapy_zmq_server.py -s %s' nobody" % (sys.executable, args.daemon_port)), stdout = stdout_file,
-                    stderr = subprocess.STDOUT, cwd = server_path, close_fds = True, universal_newlines = True)
+        subprocess.Popen(shlex.split("taskset -c %s su -s /bin/bash -c '%s scapy_zmq_server.py -s %s' nobody" % (args.core, sys.executable, args.port)),
+                    stdout = stdout_file, stderr = subprocess.STDOUT, cwd = server_path, close_fds = True, universal_newlines = True)
         ret = progress(is_running, 'Starting Scapy server', 'Scapy server is started', 'Scapy server failed to run')
         if ret:
             stdout_file.seek(0)
@@ -151,10 +151,10 @@ if __name__ == '__main__':
         formatter_class = RawTextHelpFormatter,
     )
     
-    parser.add_argument('-p', '--port', type = int, default = 4507, metavar = 'PORT', dest = 'daemon_port',
+    parser.add_argument('-p', '--port', type = int, default = 4507,
             help='Select tcp port on which Scapy server will listen.\nDefault is 4507.')
-    #parser.add_argument('-c', '--core', type = int, default = 0,
-    #        help='Core number to set affinity.\nAdvised to set on free core or TRex master thread core\nDefault is 0.')
+    parser.add_argument('-c', '--core', type = int, default = 0,
+            help='Core number to set affinity.\nAdvised to set on free core or TRex master thread core\nDefault is 0.')
     parser.add_argument('action', choices=action_funcs.keys(),
                             action='store', help=actions_help)
     parser.usage = None