config-tools: add cpu affinity static allocator

If a cpu_affinity node of SOS is not present in the scenario.xml,
assign the native cpus which are not assigned to pre-launched vm to
SOS vm.

Tracked-On: #5980
Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Yang,Yu-chu 2021-04-06 15:51:32 -07:00 committed by wenlingz
parent 3ed36ff02a
commit 9c85d70057
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
#!/usr/bin/env python3
#
# Copyright (C) 2021 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import sys, os
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library'))
import common, board_cfg_lib
def sos_cpu_affinity(etree):
if common.get_node("//vm[vm_type = 'SOS_VM']", etree) is None:
return None
if common.get_node("//vm[vm_type = 'SOS_VM' and count(cpu_affinity)]", etree) is not None:
return None
sos_extend_all_cpus = board_cfg_lib.get_processor_info()
pre_all_cpus = etree.xpath("//vm[vm_type = 'PRE_RT_VM' or vm_type = 'PRE_STD_VM' or vm_type = 'SAFETY_VM']/cpu_affinity/pcpu_id/text()")
cpus_for_sos = list(set(sos_extend_all_cpus) - set(pre_all_cpus))
return sorted(cpus_for_sos)
def fn(board_etree, scenario_etree, allocation_etree):
cpus_for_sos = sos_cpu_affinity(scenario_etree)
if cpus_for_sos:
if common.get_node("//vm[vm_type = 'SOS_VM']", scenario_etree) is not None:
vm_id = common.get_node("//vm[vm_type = 'SOS_VM']/@id", scenario_etree)
allocation_sos_vm_node = common.get_node(f"/acrn-config/vm[@id='{vm_id}']", allocation_etree)
if allocation_sos_vm_node is None:
allocation_sos_vm_node = common.append_node("/acrn-config/vm", None, allocation_etree, id = vm_id)
if common.get_node("./vm_type", allocation_sos_vm_node) is None:
common.append_node("./vm_type", "SOS_VM", allocation_sos_vm_node)
for pcpu_id in cpus_for_sos:
common.append_node("./cpu_affinity/pcpu_id", str(pcpu_id), allocation_sos_vm_node)