mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-29 00:37:15 +00:00
acrn-config: parse cpu_affinity from launch config xmls
Parse cpu_affinity from launch config xmls and generate '--cpu_affinity' as acrn-dm args. Tracked-On: #4641 Signed-off-by: Wei Liu <weix.w.liu@intel.com> Acked-by: Victor Sun <victor.sun@intel.com> Acked-by: Terry Zou <terry.zou@intel.com>
This commit is contained in:
parent
233f2deb4b
commit
a43b42b2a0
@ -3,6 +3,7 @@
|
|||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import scenario_cfg_lib
|
||||||
import launch_cfg_lib
|
import launch_cfg_lib
|
||||||
import common
|
import common
|
||||||
import pt
|
import pt
|
||||||
@ -85,10 +86,14 @@ def off_line_cpus(args, vmid, uos_type, config):
|
|||||||
:param uos_type: the type of UOS
|
:param uos_type: the type of UOS
|
||||||
:param config: it is a file pointer to write offline cpu information
|
:param config: it is a file pointer to write offline cpu information
|
||||||
"""
|
"""
|
||||||
cpus = ''
|
pcpu_id_list = get_cpu_affinity_list(args["cpu_affinity"], vmid)
|
||||||
cpus = '..'.join(list(args["off_pcpus"][vmid]))
|
if not pcpu_id_list:
|
||||||
if not cpus.strip():
|
sos_vmid = launch_cfg_lib.get_sos_vmid()
|
||||||
key = "launch script error:"
|
cpu_affinity = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE, "cpu_affinity", "pcpu_id")
|
||||||
|
pcpu_id_list = get_cpu_affinity_list(cpu_affinity, sos_vmid+vmid)
|
||||||
|
|
||||||
|
if not pcpu_id_list:
|
||||||
|
key = "scenario config error"
|
||||||
launch_cfg_lib.ERR_LIST[key] = "No available cpu to offline and pass it to vm {}".format(vmid)
|
launch_cfg_lib.ERR_LIST[key] = "No available cpu to offline and pass it to vm {}".format(vmid)
|
||||||
|
|
||||||
print('offline_path="/sys/class/vhm/acrn_vhm"', file=config)
|
print('offline_path="/sys/class/vhm/acrn_vhm"', file=config)
|
||||||
@ -100,7 +105,7 @@ def off_line_cpus(args, vmid, uos_type, config):
|
|||||||
print('fi', file=config)
|
print('fi', file=config)
|
||||||
print("", file=config)
|
print("", file=config)
|
||||||
print("# offline pinned vCPUs from SOS before launch UOS", file=config)
|
print("# offline pinned vCPUs from SOS before launch UOS", file=config)
|
||||||
print("for i in `ls -d /sys/devices/system/cpu/cpu[{}]`; do".format(cpus), file=config)
|
print("for i in `ls -d /sys/devices/system/cpu/cpu[{}]`; do".format('..'.join(pcpu_id_list)), file=config)
|
||||||
print(" online=`cat $i/online`", file=config)
|
print(" online=`cat $i/online`", file=config)
|
||||||
print(' idx=`echo $i | tr -cd "[1-99]"`', file=config)
|
print(' idx=`echo $i | tr -cd "[1-99]"`', file=config)
|
||||||
print(" echo cpu$idx online=$online", file=config)
|
print(" echo cpu$idx online=$online", file=config)
|
||||||
@ -397,7 +402,8 @@ def launch_end(names, args, virt_io, vmid, config):
|
|||||||
print("", file=config)
|
print("", file=config)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if args['cpu_sharing'][vmid] == "Disabled":
|
sos_vmid = launch_cfg_lib.get_sos_vmid()
|
||||||
|
if args['cpu_sharing'] == "SCHED_NOOP" or common.VM_TYPES[vmid+sos_vmid] == "POST_RT_VM":
|
||||||
off_line_cpus(args, vmid, uos_type, config)
|
off_line_cpus(args, vmid, uos_type, config)
|
||||||
|
|
||||||
uos_launch(names, args, virt_io, vmid, config)
|
uos_launch(names, args, virt_io, vmid, config)
|
||||||
@ -506,6 +512,22 @@ def virtio_args_set(dm, virt_io, vmid, config):
|
|||||||
launch_cfg_lib.virtual_dev_slot("virtio-console"),
|
launch_cfg_lib.virtual_dev_slot("virtio-console"),
|
||||||
virt_io['console'][vmid]), file=config)
|
virt_io['console'][vmid]), file=config)
|
||||||
|
|
||||||
|
def get_cpu_affinity_list(cpu_affinity, vmid):
|
||||||
|
pcpu_id_list = ''
|
||||||
|
for uos_id,cpus in cpu_affinity.items():
|
||||||
|
if vmid == uos_id:
|
||||||
|
pcpu_id_list = [id for id in list(cpu_affinity[uos_id]) if id != None]
|
||||||
|
return pcpu_id_list
|
||||||
|
|
||||||
|
|
||||||
|
def pcpu_arg_set(dm, vmid, config):
|
||||||
|
|
||||||
|
if dm['cpu_sharing'] == "SCHED_NOOP":
|
||||||
|
return
|
||||||
|
pcpu_id_list = get_cpu_affinity_list(dm["cpu_affinity"], vmid)
|
||||||
|
if pcpu_id_list:
|
||||||
|
print(" --cpu_affinity {} \\".format(','.join(pcpu_id_list)), file=config)
|
||||||
|
|
||||||
|
|
||||||
def dm_arg_set(names, sel, virt_io, dm, vmid, config):
|
def dm_arg_set(names, sel, virt_io, dm, vmid, config):
|
||||||
|
|
||||||
@ -582,6 +604,9 @@ def dm_arg_set(names, sel, virt_io, dm, vmid, config):
|
|||||||
# vbootloader setting
|
# vbootloader setting
|
||||||
vboot_arg_set(dm, vmid, config)
|
vboot_arg_set(dm, vmid, config)
|
||||||
|
|
||||||
|
# pcpu-list args set
|
||||||
|
pcpu_arg_set(dm, vmid, config)
|
||||||
|
|
||||||
# redirect console
|
# redirect console
|
||||||
if dm['vuart0'][vmid] == "Enable":
|
if dm['vuart0'][vmid] == "Enable":
|
||||||
print(" -s 1:0,lpc \\", file=config)
|
print(" -s 1:0,lpc \\", file=config)
|
||||||
|
@ -7,6 +7,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library'))
|
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library'))
|
||||||
from launch_item import AvailablePthru, PthruSelected, VirtioDeviceSelect, AcrnDmArgs
|
from launch_item import AvailablePthru, PthruSelected, VirtioDeviceSelect, AcrnDmArgs
|
||||||
|
import board_cfg_lib
|
||||||
import launch_cfg_lib
|
import launch_cfg_lib
|
||||||
import com
|
import com
|
||||||
import common
|
import common
|
||||||
@ -47,8 +48,8 @@ def get_launch_item_values(board_info):
|
|||||||
|
|
||||||
launch_item_values["uos,vbootloader"] = launch_cfg_lib.BOOT_TYPE
|
launch_item_values["uos,vbootloader"] = launch_cfg_lib.BOOT_TYPE
|
||||||
launch_item_values['uos,vuart0'] = launch_cfg_lib.DM_VUART0
|
launch_item_values['uos,vuart0'] = launch_cfg_lib.DM_VUART0
|
||||||
launch_item_values['uos,cpu_sharing'] = launch_cfg_lib.CPU_SHARING
|
|
||||||
launch_item_values['uos,poweroff_channel'] = launch_cfg_lib.PM_CHANNEL
|
launch_item_values['uos,poweroff_channel'] = launch_cfg_lib.PM_CHANNEL
|
||||||
|
launch_item_values["uos,cpu_affinity"] = board_cfg_lib.get_processor_info()
|
||||||
|
|
||||||
return launch_item_values
|
return launch_item_values
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
import common
|
import common
|
||||||
import board_cfg_lib
|
import board_cfg_lib
|
||||||
import launch_cfg_lib
|
import launch_cfg_lib
|
||||||
|
import scenario_cfg_lib
|
||||||
|
|
||||||
class AcrnDmArgs:
|
class AcrnDmArgs:
|
||||||
args = {}
|
args = {}
|
||||||
@ -22,9 +23,9 @@ class AcrnDmArgs:
|
|||||||
self.args["gvt_args"] = common.get_leaf_tag_map(self.launch_info, "gvt_args")
|
self.args["gvt_args"] = common.get_leaf_tag_map(self.launch_info, "gvt_args")
|
||||||
self.args["vbootloader"] = common.get_leaf_tag_map(self.launch_info, "vbootloader")
|
self.args["vbootloader"] = common.get_leaf_tag_map(self.launch_info, "vbootloader")
|
||||||
self.args["vuart0"] = common.get_leaf_tag_map(self.launch_info, "vuart0")
|
self.args["vuart0"] = common.get_leaf_tag_map(self.launch_info, "vuart0")
|
||||||
self.args["cpu_sharing"] = common.get_leaf_tag_map(self.launch_info, "cpu_sharing")
|
self.args["cpu_sharing"] = common.get_hv_item_tag(self.scenario_info, "FEATURES", "SCHEDULER")
|
||||||
self.args["pm_channel"] = common.get_leaf_tag_map(self.launch_info, "poweroff_channel")
|
self.args["pm_channel"] = common.get_leaf_tag_map(self.launch_info, "poweroff_channel")
|
||||||
self.args["off_pcpus"] = common.get_leaf_tag_map(self.scenario_info, "cpu_affinity", "pcpu_id")
|
self.args["cpu_affinity"] = common.get_leaf_tag_map(self.launch_info, "cpu_affinity", "pcpu_id")
|
||||||
self.args["xhci"] = common.get_leaf_tag_map(self.launch_info, "usb_xhci")
|
self.args["xhci"] = common.get_leaf_tag_map(self.launch_info, "usb_xhci")
|
||||||
|
|
||||||
def check_item(self):
|
def check_item(self):
|
||||||
@ -34,7 +35,8 @@ class AcrnDmArgs:
|
|||||||
launch_cfg_lib.mem_size_check(self.args["mem_size"], "mem_size")
|
launch_cfg_lib.mem_size_check(self.args["mem_size"], "mem_size")
|
||||||
launch_cfg_lib.args_aval_check(self.args["vbootloader"], "vbootloader", launch_cfg_lib.BOOT_TYPE)
|
launch_cfg_lib.args_aval_check(self.args["vbootloader"], "vbootloader", launch_cfg_lib.BOOT_TYPE)
|
||||||
launch_cfg_lib.args_aval_check(self.args["vuart0"], "vuart0", launch_cfg_lib.DM_VUART0)
|
launch_cfg_lib.args_aval_check(self.args["vuart0"], "vuart0", launch_cfg_lib.DM_VUART0)
|
||||||
launch_cfg_lib.cpu_sharing_check(self.args["cpu_sharing"], "cpu_sharing")
|
err_dic = scenario_cfg_lib.cpus_per_vm_check(self.launch_info, self.args["cpu_affinity"], "pcpu_id")
|
||||||
|
launch_cfg_lib.ERR_LIST.update(err_dic)
|
||||||
|
|
||||||
|
|
||||||
class AvailablePthru():
|
class AvailablePthru():
|
||||||
|
@ -13,7 +13,6 @@ ERR_LIST = {}
|
|||||||
BOOT_TYPE = ['no', 'vsbl', 'ovmf']
|
BOOT_TYPE = ['no', 'vsbl', 'ovmf']
|
||||||
RTOS_TYPE = ['no', 'Soft RT', 'Hard RT']
|
RTOS_TYPE = ['no', 'Soft RT', 'Hard RT']
|
||||||
DM_VUART0 = ['Disable', 'Enable']
|
DM_VUART0 = ['Disable', 'Enable']
|
||||||
CPU_SHARING = ['Disabled', 'Enabled']
|
|
||||||
UOS_TYPES = ['CLEARLINUX', 'ANDROID', 'ALIOS', 'PREEMPT-RT LINUX', 'VXWORKS', 'WINDOWS', 'ZEPHYR', 'GENERIC LINUX']
|
UOS_TYPES = ['CLEARLINUX', 'ANDROID', 'ALIOS', 'PREEMPT-RT LINUX', 'VXWORKS', 'WINDOWS', 'ZEPHYR', 'GENERIC LINUX']
|
||||||
|
|
||||||
PT_SUB_PCI = {}
|
PT_SUB_PCI = {}
|
||||||
@ -487,45 +486,6 @@ def check_block_mount(virtio_blk_dic):
|
|||||||
MOUNT_FLAG_DIC[vmid] = mount_flags
|
MOUNT_FLAG_DIC[vmid] = mount_flags
|
||||||
|
|
||||||
|
|
||||||
def cpu_sharing_check(cpu_sharing, item):
|
|
||||||
"""
|
|
||||||
Check cpu sharing status with cpu affinity setting
|
|
||||||
:param cpu_share_status:
|
|
||||||
:param item:
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
use_cpus = []
|
|
||||||
use_same_cpu = False
|
|
||||||
vm_cpu_share = []
|
|
||||||
vm_cpu_share_consistent = True
|
|
||||||
|
|
||||||
cpu_affinity = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE, "cpu_affinity", "pcpu_id")
|
|
||||||
for vm_i in cpu_affinity.keys():
|
|
||||||
for cpu in cpu_affinity[vm_i]:
|
|
||||||
if cpu in use_cpus:
|
|
||||||
use_same_cpu = True
|
|
||||||
else:
|
|
||||||
use_cpus.append(cpu)
|
|
||||||
|
|
||||||
for vm_i in cpu_sharing.keys():
|
|
||||||
cpu_share = cpu_sharing[vm_i]
|
|
||||||
stat_len = len(vm_cpu_share)
|
|
||||||
if stat_len != 0 and cpu_share not in vm_cpu_share:
|
|
||||||
vm_cpu_share_consistent = False
|
|
||||||
else:
|
|
||||||
vm_cpu_share.append(cpu_share)
|
|
||||||
|
|
||||||
if not vm_cpu_share_consistent:
|
|
||||||
key = "uos:id={},{}".format(vm_i, item)
|
|
||||||
ERR_LIST[key] = "CPU sharing for all VMs should be consistent to 'Disabled' or 'Enabled'"
|
|
||||||
return
|
|
||||||
|
|
||||||
if cpu_sharing[vm_i] == "Disabled" and use_same_cpu:
|
|
||||||
key = "uos:id={},{}".format(vm_i, item)
|
|
||||||
ERR_LIST[key] = "The same pcpu was configurated in scenario config, and not allow to set the cpu_sharing to 'Disabled'!"
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def bdf_duplicate_check(bdf_dic):
|
def bdf_duplicate_check(bdf_dic):
|
||||||
"""
|
"""
|
||||||
Check if exist duplicate slot
|
Check if exist duplicate slot
|
||||||
|
@ -200,25 +200,47 @@ def guest_flag_check(guest_flags, branch_tag, leaf_tag):
|
|||||||
ERR_LIST[key] = "Unknow guest flag"
|
ERR_LIST[key] = "Unknow guest flag"
|
||||||
|
|
||||||
|
|
||||||
def cpus_per_vm_check(id_cpus_per_vm_dic, item):
|
def cpus_per_vm_check(config_file, id_cpus_per_vm_dic, item):
|
||||||
"""
|
"""
|
||||||
Check cpu number of per vm
|
Check cpu number of per vm
|
||||||
:param item: vm pcpu_id item in xml
|
:param item: vm pcpu_id item in xml
|
||||||
:return: None
|
:return: error informations
|
||||||
"""
|
"""
|
||||||
|
err_dic = {}
|
||||||
|
use_cpus = []
|
||||||
|
cpu_sharing_enabled = True
|
||||||
|
|
||||||
|
cpu_sharing = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "SCHEDULER")
|
||||||
|
if cpu_sharing == "SCHED_NOOP":
|
||||||
|
cpu_sharing_enabled = False
|
||||||
|
|
||||||
|
cpu_affinity = common.get_leaf_tag_map(config_file, "cpu_affinity", "pcpu_id")
|
||||||
|
for vm_i in id_cpus_per_vm_dic.keys():
|
||||||
|
for cpu in id_cpus_per_vm_dic[vm_i]:
|
||||||
|
if cpu in use_cpus and not cpu_sharing_enabled:
|
||||||
|
key = "vm:id={},{}".format(vm_i, item)
|
||||||
|
err_dic[key] = "The same pcpu was configurated in <pcpu_id>/<cpu_affinity>, but CPU sharing is disabled by 'SCHED_NOOP'. Please re-configurate them!"
|
||||||
|
return err_dic
|
||||||
|
else:
|
||||||
|
use_cpus.append(cpu)
|
||||||
|
|
||||||
for vm_i, vm_type in common.VM_TYPES.items():
|
for vm_i, vm_type in common.VM_TYPES.items():
|
||||||
if vm_i not in id_cpus_per_vm_dic.keys() and "SOS_VM" == VM_DB[vm_type]['load_type']:
|
if vm_i not in id_cpus_per_vm_dic.keys() and "SOS_VM" == VM_DB[vm_type]['load_type']:
|
||||||
continue
|
continue
|
||||||
elif vm_i not in id_cpus_per_vm_dic.keys() and VM_DB[vm_type]['load_type'] in ("PRE_LAUNCHED_VM", "POST_LAUNCHED_VM"):
|
elif vm_i not in id_cpus_per_vm_dic.keys() and VM_DB[vm_type]['load_type'] in ("PRE_LAUNCHED_VM", "POST_LAUNCHED_VM"):
|
||||||
key = "vm:id={},{}".format(vm_i, item)
|
key = "vm:id={},{}".format(vm_i, item)
|
||||||
ERR_LIST[key] = "Pre launched_vm and Post launched vm should have cpus assignment"
|
err_dic[key] = "Pre launched_vm and Post launched vm should have cpus assignment"
|
||||||
return
|
return err_dic
|
||||||
|
|
||||||
|
# duplicate cpus assign the same VM check
|
||||||
cpus_vm_i = id_cpus_per_vm_dic[vm_i]
|
cpus_vm_i = id_cpus_per_vm_dic[vm_i]
|
||||||
if not cpus_vm_i:
|
for cpu_id in cpus_vm_i:
|
||||||
|
if cpus_vm_i.count(cpu_id) >= 2:
|
||||||
key = "vm:id={},{}".format(vm_i, item)
|
key = "vm:id={},{}".format(vm_i, item)
|
||||||
ERR_LIST[key] = "{} VM have no assignment cpus".format(vm_type)
|
err_dic[key] = "VM should not use the same pcpu id:{}".format(cpu_id)
|
||||||
return
|
return err_dic
|
||||||
|
|
||||||
|
return err_dic
|
||||||
|
|
||||||
|
|
||||||
def mem_start_hpa_check(id_start_hpa_dic, prime_item, item):
|
def mem_start_hpa_check(id_start_hpa_dic, prime_item, item):
|
||||||
|
@ -312,9 +312,10 @@ class VmInfo:
|
|||||||
scenario_cfg_lib.vm_name_check(self.name, "name")
|
scenario_cfg_lib.vm_name_check(self.name, "name")
|
||||||
scenario_cfg_lib.load_vm_check(self.load_vm, "load_vm")
|
scenario_cfg_lib.load_vm_check(self.load_vm, "load_vm")
|
||||||
scenario_cfg_lib.guest_flag_check(self.guest_flags, "guest_flags", "guest_flag")
|
scenario_cfg_lib.guest_flag_check(self.guest_flags, "guest_flags", "guest_flag")
|
||||||
scenario_cfg_lib.cpus_per_vm_check(self.cpus_per_vm, "pcpu_id")
|
err_dic = scenario_cfg_lib.cpus_per_vm_check(self.scenario_info, self.cpus_per_vm, "pcpu_id")
|
||||||
|
|
||||||
self.mem_info.check_item()
|
self.mem_info.check_item()
|
||||||
self.os_cfg.check_item()
|
self.os_cfg.check_item()
|
||||||
self.cfg_pci.check_item()
|
self.cfg_pci.check_item()
|
||||||
self.vuart.check_item()
|
self.vuart.check_item()
|
||||||
|
scenario_cfg_lib.ERR_LIST.update(err_dic)
|
||||||
|
Loading…
Reference in New Issue
Block a user