@@ -66,7 +66,24 @@ def _sudo_cmd(self, cmd: str) -> str:
6666 pw = self ._resolve_sudo_password ()
6767 # Use printf to avoid issues with special chars in the password.
6868 return f"printf '%s\\ n' '{ pw } ' | sudo -S { cmd } "
69-
69+ def _realtime_core_control (self , instance_num : str ) -> Optional [str ]:
70+ """Return a CPU core list string for the real-time Control PLC instance."""
71+ # Example mapping: Control_PLC_01 → cores 0-3, Control_PLC_02 → cores 4-7
72+ t_cpus = self .config .demo .control_system .get ("t_cpus" )
73+ t_cpus = t_cpus .split ("," )
74+ if len (t_cpus ) < 4 :
75+ print ("[WARN] Not enough t_cpus specified for control_system. Expected at least 4." )
76+ return None
77+ if instance_num == "01" :
78+ return f"{ t_cpus [int (instance_num )- 1 ]} ,{ t_cpus [int (instance_num )]} " # cores 3,5
79+ elif instance_num == "02" :
80+ return f"{ t_cpus [int (instance_num )]} ,{ t_cpus [len (t_cpus )- 1 ]} " # cores 7,9
81+ def _realtime_core_io (self , instance_num : str ) -> Optional [str ]:
82+ """Return a CPU core list string for the real-time IO PLC instance."""
83+ # Example mapping: IO_PLC_01 → cores 8-11, IO_PLC_02 → cores 12-15
84+ t_cpus = self .config .demo .io_system .get ("t_cpus" )
85+ t_cpus = t_cpus .split ("," )
86+ return str (t_cpus [instance_num - 1 ])
7087 # Low-level helpers
7188 @staticmethod
7289 def _run_command (cmd : List [str ], capture : bool = False ) -> subprocess .CompletedProcess :
@@ -540,7 +557,7 @@ def launch_instance(
540557 # 1. Resolve the container IP from the JSON config
541558 container_ip = self ._extract_ip_from_config (app_type , instance_num )
542559
543- cpuset_cpus = cpuset_cpus or self .config . demo . get ( "cpuset_cpus" )
560+ cpuset_cpus = self ._realtime_core_io ( int ( instance_num )) if app_type == "io" else self . _realtime_core_control ( instance_num )
544561 cpuset_mems = cpuset_mems or self .config .demo .get ("cpuset_mems" )
545562 if not container_ip :
546563 print (f"[ERROR] No IP found for { container_name } " )
@@ -654,6 +671,8 @@ def start_control(self) -> int:
654671 ssh = None ,
655672 network = DEFAULT_NETWORK ,
656673 nic = nic ,
674+ cpuset_mems = self .config .demo .control_system .get ("cpuset_mems" ),
675+ cpuset_cpus = self ._realtime_core_control (instance_num ),
657676 )
658677 if rc != 0 :
659678 return rc
@@ -700,6 +719,7 @@ def start_io(self) -> int:
700719 ssh = ssh ,
701720 network = DEFAULT_NETWORK ,
702721 nic = nic ,
722+ cpuset_cpus = self ._realtime_core_io (int (instance_num )),
703723 )
704724 if rc != 0 :
705725 return rc
0 commit comments