[PATCH v2] config_tools: offline cpu for own_pcpu VMs


Zhao, Yuanyuan
 

When launch a VM own pcpus, offline Service VM vcpus which use
the same pcpu by launch script.

v1->v2 add warning to offline cpu 0

Signed-off-by: Yuanyuan Zhao <yuanyuan.zhao@...>
---
misc/config_tools/launch_config/launch_cfg_gen.py | 1 +
misc/config_tools/launch_config/launch_script_template.sh | 8 ++++++--
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/misc/config_tools/launch_config/launch_cfg_gen.py b/misc/config_tools/launch_config/launch_cfg_gen.py
index 7c4668013..c1e7d6436 100755
--- a/misc/config_tools/launch_config/launch_cfg_gen.py
+++ b/misc/config_tools/launch_config/launch_cfg_gen.py
@@ -260,6 +260,7 @@ def generate_for_one_vm(board_etree, hv_scenario_etree, vm_scenario_etree, vm_id
script.add_plain_dm_parameter("--windows")
script.add_vm_descriptor("vm_type", f"'{eval_xpath(vm_scenario_etree, './/vm_type/text()', 'STANDARD_VM')}'")
script.add_vm_descriptor("scheduler", f"'{eval_xpath(hv_scenario_etree, './/SCHEDULER/text()')}'")
+ script.add_vm_descriptor("own_pcpu", f"'{eval_xpath(vm_scenario_etree, './/own_pcpu/text()')}'")

###
# CPU and memory resources
diff --git a/misc/config_tools/launch_config/launch_script_template.sh b/misc/config_tools/launch_config/launch_script_template.sh
index db11885f3..ca593b946 100644
--- a/misc/config_tools/launch_config/launch_script_template.sh
+++ b/misc/config_tools/launch_config/launch_script_template.sh
@@ -19,11 +19,15 @@ function offline_cpus() {
if [ -z ${processor_id} ]; then
continue
fi
+ if [ "${processor_id}" = "0" ]; then
+ echo "Warning: processor 0 can't be offline, there may be unexpect error!" >> /dev/stderr
+ continue
+ fi
cpu_path="/sys/devices/system/cpu/cpu${processor_id}"
if [ -f ${cpu_path}/online ]; then
online=`cat ${cpu_path}/online`
echo cpu${processor_id} online=${online} >> /dev/stderr
- if [ "${online}" = "1" ] && [ "${processor_id}" != "0" ]; then
+ if [ "${online}" = "1" ]; then
echo 0 > ${cpu_path}/online
online=`cat ${cpu_path}/online`
# during boot time, cpu hotplug may be disabled by pci_device_probe during a pci module insmod
@@ -90,7 +94,7 @@ function add_cpus() {
# Each parameter of this function is considered the apicid of processor (as is reported in /proc/cpuinfo) of
# a CPU assigned to a post-launched RTVM.

- if [ "${vm_type}" = "RTVM" ] || [ "${scheduler}" = "SCHED_NOOP" ]; then
+ if [ "${vm_type}" = "RTVM" ] || [ "${scheduler}" = "SCHED_NOOP" ] || [ "${own_pcpu}" = "y" ]; then
offline_cpus $*
fi

--
2.25.1


Junjie Mao
 

-----Original Message-----
From: Yuanyuan Zhao <yuanyuan.zhao@...>
Sent: Thursday, September 29, 2022 3:07 PM
To: Mao, Junjie <junjie.mao@...>; acrn-dev@...
Cc: yuanyuan.zhao@...
Subject: [PATCH v2] config_tools: offline cpu for own_pcpu VMs

When launch a VM own pcpus, offline Service VM vcpus which use
the same pcpu by launch script.

v1->v2 add warning to offline cpu 0

Signed-off-by: Yuanyuan Zhao <yuanyuan.zhao@...>
---
misc/config_tools/launch_config/launch_cfg_gen.py | 1 +
misc/config_tools/launch_config/launch_script_template.sh | 8 ++++++--
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/misc/config_tools/launch_config/launch_cfg_gen.py
b/misc/config_tools/launch_config/launch_cfg_gen.py
index 7c4668013..c1e7d6436 100755
--- a/misc/config_tools/launch_config/launch_cfg_gen.py
+++ b/misc/config_tools/launch_config/launch_cfg_gen.py
@@ -260,6 +260,7 @@ def generate_for_one_vm(board_etree, hv_scenario_etree,
vm_scenario_etree, vm_id
script.add_plain_dm_parameter("--windows")
script.add_vm_descriptor("vm_type", f"'{eval_xpath(vm_scenario_etree,
'.//vm_type/text()', 'STANDARD_VM')}'")
script.add_vm_descriptor("scheduler", f"'{eval_xpath(hv_scenario_etree,
'.//SCHEDULER/text()')}'")
+ script.add_vm_descriptor("own_pcpu", f"'{eval_xpath(vm_scenario_etree,
'.//own_pcpu/text()')}'")

###
# CPU and memory resources
diff --git a/misc/config_tools/launch_config/launch_script_template.sh
b/misc/config_tools/launch_config/launch_script_template.sh
index db11885f3..ca593b946 100644
--- a/misc/config_tools/launch_config/launch_script_template.sh
+++ b/misc/config_tools/launch_config/launch_script_template.sh
@@ -19,11 +19,15 @@ function offline_cpus() {
if [ -z ${processor_id} ]; then
continue
fi
+ if [ "${processor_id}" = "0" ]; then
+ echo "Warning: processor 0 can't be offline, there may be unexpect error!" >>
/dev/stderr
What kind of "unexpected error" are you referring to?

The general recommendation for error messages is to state the impact and guide users how they can fix this. Specific to this case the direct impact would be that the to-be-launched VM has to share physical CPU with the service VM, and to fix that the user may need to refine the CPU affinity of the to-be-launched VM or revert the manual changes to the launch script if there is any.

---
Best Regards
Junjie Mao

+ continue
+ fi
cpu_path="/sys/devices/system/cpu/cpu${processor_id}"
if [ -f ${cpu_path}/online ]; then
online=`cat ${cpu_path}/online`
echo cpu${processor_id} online=${online} >> /dev/stderr
- if [ "${online}" = "1" ] && [ "${processor_id}" != "0" ]; then
+ if [ "${online}" = "1" ]; then
echo 0 > ${cpu_path}/online
online=`cat ${cpu_path}/online`
# during boot time, cpu hotplug may be disabled by pci_device_probe
during a pci module insmod
@@ -90,7 +94,7 @@ function add_cpus() {
# Each parameter of this function is considered the apicid of processor (as is
reported in /proc/cpuinfo) of
# a CPU assigned to a post-launched RTVM.

- if [ "${vm_type}" = "RTVM" ] || [ "${scheduler}" = "SCHED_NOOP" ]; then
+ if [ "${vm_type}" = "RTVM" ] || [ "${scheduler}" = "SCHED_NOOP" ] || [ "${own_pcpu}"
= "y" ]; then
offline_cpus $*
fi

--
2.25.1