[PATCH v2] misc: add cpu details to launch script
chenli.wei
From: Chenli Wei <chenli.wei@...>
The current code use cpu_id in scenario xml and use apic_id of the pCPU
in the launched script, this confuses the user, especially the same name
"cpu_affinity" is used for these script.
So this patch add some comment to launched script to explain the
relationship between cpu_id and apic_id.
v1-->v2:
1. remove the board_cfg_lib
2. refine the logic of generate cpu list
Tracked-On: #6690
Signed-off-by: Chenli Wei <chenli.wei@...>
---
.../launch_config/launch_cfg_gen.py | 39 +++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/misc/config_tools/launch_config/launch_cfg_gen.py b/misc/config_tools/launch_config/launch_cfg_gen.py
index 38d843c8b..555ce019d 100755
--- a/misc/config_tools/launch_config/launch_cfg_gen.py
+++ b/misc/config_tools/launch_config/launch_cfg_gen.py
@@ -84,6 +84,7 @@ class LaunchScript:
self._vm_name = vm_name
self._vm_descriptors = {}
self._init_commands = []
+ self._cpu_list = {}
self._dm_parameters = []
self._deinit_commands = []
@@ -93,6 +94,9 @@ class LaunchScript:
def add_vm_descriptor(self, name, value):
self._vm_descriptors[name] = value
+ def add_sos_cpu_list(self, cpus, lapic_ids):
+ self._cpu_list = dict(zip(cpus, lapic_ids))
+
def add_init_command(self, command):
if command not in self._init_commands:
self._init_commands.append(command)
@@ -143,6 +147,36 @@ class LaunchScript:
s += f"{command}\n"
s += "\n"
+ s += """
+# Note for developers: The number of available logical CPUs depends on the
+# number of enabled cores and whether Hyperthreading is enabled in the BIOS
+# settings. CPU IDs are assigned to each logical CPU but are not the same ID
+# value throughout the system:
+#
+# Native CPU_ID:
+# ID enumerated by the Linux Kernel and shown in the
+# ACRN Configurator's CPU Affinity option (used in the scenario.xml)
+# Service VM CPU_ID:
+# ID assigned by the Service VM at runtime
+# APIC_ID:
+# Advanced Programmable Interrupt Controller's unique ID as
+# enumerated by the board inspector (used in this launch script)
+#
+# This table shows equivalent CPU IDs for this scenario and board:
+#
+"""
+ s += "\n"
+
+ s += "# Native CPU_ID Service VM CPU_ID APIC_ID\n"
+ s += "# ------------- ----------------- -------\n"
+ vcpu_id = 0
+ for cpu_info in self._cpu_list:
+ s += "# "
+ s += f"{cpu_info:3d}{'':17s}"
+ s += f"{vcpu_id:3d}{'':17s}"
+ s += f"{self._cpu_list[cpu_info]:3d}\n"
+ vcpu_id += 1
+ s += "\n"
s += "# Invoking ACRN device model\n"
s += "dm_params=(\n"
for param in self._dm_parameters:
@@ -389,6 +423,10 @@ def main(board_xml, scenario_xml, user_vm_id, out_dir):
return 1
service_vm_id = int(service_vm_id)
+ # Service VM CPU list
+ pre_all_cpus = eval_xpath_all(scenario_etree, "//vm[load_order = 'PRE_LAUNCHED_VM']/cpu_affinity//pcpu_id/text()")
+ cpus_for_sos = [x for x in eval_xpath_all(board_etree, "//processors//thread//cpu_id/text()") if x not in pre_all_cpus]
+
try:
os.mkdir(out_dir)
except FileExistsError:
@@ -410,6 +448,7 @@ def main(board_xml, scenario_xml, user_vm_id, out_dir):
continue
script = generate_for_one_vm(board_etree, hv_scenario_etree, post_vm, post_vm_id)
+ script.add_sos_cpu_list(sorted([int(x) for x in list(cpus_for_sos)]), sorted(cpu_id_to_lapic_id(board_etree, None, cpus_for_sos)))
script.write_to_file(os.path.join(out_dir, f"launch_user_vm_id{post_vm_id - service_vm_id}.sh"))
return 0
--
2.25.1
The current code use cpu_id in scenario xml and use apic_id of the pCPU
in the launched script, this confuses the user, especially the same name
"cpu_affinity" is used for these script.
So this patch add some comment to launched script to explain the
relationship between cpu_id and apic_id.
v1-->v2:
1. remove the board_cfg_lib
2. refine the logic of generate cpu list
Tracked-On: #6690
Signed-off-by: Chenli Wei <chenli.wei@...>
---
.../launch_config/launch_cfg_gen.py | 39 +++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/misc/config_tools/launch_config/launch_cfg_gen.py b/misc/config_tools/launch_config/launch_cfg_gen.py
index 38d843c8b..555ce019d 100755
--- a/misc/config_tools/launch_config/launch_cfg_gen.py
+++ b/misc/config_tools/launch_config/launch_cfg_gen.py
@@ -84,6 +84,7 @@ class LaunchScript:
self._vm_name = vm_name
self._vm_descriptors = {}
self._init_commands = []
+ self._cpu_list = {}
self._dm_parameters = []
self._deinit_commands = []
@@ -93,6 +94,9 @@ class LaunchScript:
def add_vm_descriptor(self, name, value):
self._vm_descriptors[name] = value
+ def add_sos_cpu_list(self, cpus, lapic_ids):
+ self._cpu_list = dict(zip(cpus, lapic_ids))
+
def add_init_command(self, command):
if command not in self._init_commands:
self._init_commands.append(command)
@@ -143,6 +147,36 @@ class LaunchScript:
s += f"{command}\n"
s += "\n"
+ s += """
+# Note for developers: The number of available logical CPUs depends on the
+# number of enabled cores and whether Hyperthreading is enabled in the BIOS
+# settings. CPU IDs are assigned to each logical CPU but are not the same ID
+# value throughout the system:
+#
+# Native CPU_ID:
+# ID enumerated by the Linux Kernel and shown in the
+# ACRN Configurator's CPU Affinity option (used in the scenario.xml)
+# Service VM CPU_ID:
+# ID assigned by the Service VM at runtime
+# APIC_ID:
+# Advanced Programmable Interrupt Controller's unique ID as
+# enumerated by the board inspector (used in this launch script)
+#
+# This table shows equivalent CPU IDs for this scenario and board:
+#
+"""
+ s += "\n"
+
+ s += "# Native CPU_ID Service VM CPU_ID APIC_ID\n"
+ s += "# ------------- ----------------- -------\n"
+ vcpu_id = 0
+ for cpu_info in self._cpu_list:
+ s += "# "
+ s += f"{cpu_info:3d}{'':17s}"
+ s += f"{vcpu_id:3d}{'':17s}"
+ s += f"{self._cpu_list[cpu_info]:3d}\n"
+ vcpu_id += 1
+ s += "\n"
s += "# Invoking ACRN device model\n"
s += "dm_params=(\n"
for param in self._dm_parameters:
@@ -389,6 +423,10 @@ def main(board_xml, scenario_xml, user_vm_id, out_dir):
return 1
service_vm_id = int(service_vm_id)
+ # Service VM CPU list
+ pre_all_cpus = eval_xpath_all(scenario_etree, "//vm[load_order = 'PRE_LAUNCHED_VM']/cpu_affinity//pcpu_id/text()")
+ cpus_for_sos = [x for x in eval_xpath_all(board_etree, "//processors//thread//cpu_id/text()") if x not in pre_all_cpus]
+
try:
os.mkdir(out_dir)
except FileExistsError:
@@ -410,6 +448,7 @@ def main(board_xml, scenario_xml, user_vm_id, out_dir):
continue
script = generate_for_one_vm(board_etree, hv_scenario_etree, post_vm, post_vm_id)
+ script.add_sos_cpu_list(sorted([int(x) for x in list(cpus_for_sos)]), sorted(cpu_id_to_lapic_id(board_etree, None, cpus_for_sos)))
script.write_to_file(os.path.join(out_dir, f"launch_user_vm_id{post_vm_id - service_vm_id}.sh"))
return 0
--
2.25.1