acrn-hypervisor/misc/acrn-config/target/clos.py
Wei Liu 28d1b909e6 acrn-config: generate a scenario patch and apply to acrn-hypervisor
1.the script will parse the the board information which already
generated, $(scenario).xml modified by user, generate scenario
vm configuration and apply to the acrn-hypervisor source code base.

2.parse cpu/memory/ttys/rootfs information from native os and store it to
the source code

3.implemnt scenario_config and it's usage

usage: scenario_cfg_gen.py --board <board_info_file> -scenario <scenario_info_file>
board_info_file :  file name of the board info
scenario_info_file :  file name of the scenario info

sample:
	$ python3 scenario_cfg_gen.py --board ../board-xmls/apl-mrb.xml
--scenario ../config-xmls/scenarios/sdc.xml

Also improvement board config generate usage:
sample:
	$ python3 board_cfg_gen.py --board ../board-xmls/apl-mrb.xml
--scenario ../config-xmls/scenarios/sdc.xml

V1-V2:
    1). parse board_setting.xml was removed as these configuration will be
stitch into scenario configuration
    2). parse console for different formats
    3). parse epc sections
    4). add logical partition rootfs
    5). support to parse clos, while webui set to None type
    6). support to parse bootargs, while webui set to nul
    7). convert '-' to '_' for pci sub class name while generating source file

Tracked-On: #3602
Signed-off-by: Wei Liu <weix.w.liu@intel.com>
Acked-by: Terry Zou <terry.zou@intel.com>
2019-09-16 09:34:37 +08:00

88 lines
2.1 KiB
Python

# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import parser_lib
CACHE_TYPE = {
"L2":4,
"L3":2
}
def dump_cpuid_reg(cmd, reg):
"""execute the cmd of cpuid, and return the register value by reg
:param cmd: command what can be executed in shell
:param reg: register name
"""
cache_t = ''
res = parser_lib.cmd_execute(cmd)
if reg == "ebx":
idx = 3
if reg == "edx":
idx = 5
while True:
line = parser_lib.decode_stdout(res)
if not line:
break
if len(line.split()) <= 2:
continue
reg_value = line.split()[idx].split('=')[1]
if reg == "ebx":
if int(reg_value, 16) & CACHE_TYPE['L2'] != 0:
cache_t = "L2"
break
elif int(reg_value, 16) & CACHE_TYPE['L3'] != 0:
cache_t = "L3"
break
else:
cache_t = False
break
elif reg == "edx":
cache_t = int(reg_value, 16) + 1
break
return cache_t
def get_clos_info():
"""Get clos max and clos cache type"""
clos_max = 0
clos_cache = False
cmd = "cpuid -r -l 0x10"
clos_cache = dump_cpuid_reg(cmd, "ebx")
if clos_cache == "L2":
cmd = "cpuid -r -l 0x10 --subleaf 2"
elif clos_cache == "L3":
cmd = "cpuid -r -l 0x10 --subleaf 1"
else:
clos_max = 0
parser_lib.print_yel("CLOS is not supported!")
return (clos_cache, clos_max)
clos_max = dump_cpuid_reg(cmd, "edx")
return (clos_cache, clos_max)
def generate_info(board_info):
"""Generate clos information
:param board_info: this is the file which stores the hardware board information
"""
(clos_cache, clos_max) = get_clos_info()
with open(board_info, 'a+') as config:
print("\t<CLOS_INFO>", file=config)
print("\tclos supported by cache:{}".format(clos_cache), file=config)
print("\tclos max:{}".format(clos_max), file=config)
print("\t</CLOS_INFO>\n", file=config)