From 2e20494db1126b19aca75101b121ffcbdf4b02d4 Mon Sep 17 00:00:00 2001 From: "Yang,Yu-chu" Date: Fri, 11 Feb 2022 11:02:51 -0800 Subject: [PATCH] config-tools: bring all cores online Bring all the cores up in the beginning of the board_inspector.py It is expected to run board_inspector in clean and native environment. To resolve the issue that user may run other jobs which puts cores offline, bringing up all cores online so tool can run cpuid to extract all available cores information. Tracked-On: #7119 Signed-off-by: Yang,Yu-chu Reviewed-by: Junjie Mao Acked-by: Anthony Xu --- .../board_inspector/board_inspector.py | 14 +++++++++++++- .../board_inspector/cpuparser/__init__.py | 13 ++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/misc/config_tools/board_inspector/board_inspector.py b/misc/config_tools/board_inspector/board_inspector.py index 41067d12b..b6cffb885 100755 --- a/misc/config_tools/board_inspector/board_inspector.py +++ b/misc/config_tools/board_inspector/board_inspector.py @@ -11,7 +11,7 @@ import subprocess # nosec import lxml.etree import argparse from importlib import import_module -from cpuparser import parse_cpuid, get_online_cpu_ids +from cpuparser import parse_cpuid, get_online_cpu_ids, get_offline_cpu_ids script_dir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(script_dir)) @@ -48,6 +48,15 @@ def native_check(): logging.warning(f"Board inspector is running inside a Virtual Machine (VM). Running ACRN inside a VM is only" \ "supported under KVM/QEMU. Unexpected results may occur when deviating from that combination.") +def bring_up_cores(): + cpu_ids = get_offline_cpu_ids() + for id in cpu_ids: + try: + with open("/sys/devices/system/cpu/cpu{}/online".format(id), "w") as f: + f.write("1") + except : + logging.warning("Cannot bring up core with cpu id {}.".format(id)) + def main(board_name, board_xml, args): # Check that the dependencies are met check_deps() @@ -55,6 +64,9 @@ def main(board_name, board_xml, args): # Check if this is native os native_check() + # Bring up all cores + bring_up_cores() + try: # First invoke the legacy board parser to create the board XML ... legacy_parser = os.path.join(script_dir, "legacy", "board_parser.py") diff --git a/misc/config_tools/board_inspector/cpuparser/__init__.py b/misc/config_tools/board_inspector/cpuparser/__init__.py index 897bfd98c..0d0e2148d 100644 --- a/misc/config_tools/board_inspector/cpuparser/__init__.py +++ b/misc/config_tools/board_inspector/cpuparser/__init__.py @@ -60,14 +60,21 @@ def parse_cpuid(leaf, subleaf, cpu_id): else: return None -def get_online_cpu_ids(): +def parse_cpu_ids(file): acc = list() - with open("/sys/devices/system/cpu/online", "r") as f: + with open(file, "r") as f: line = f.read().strip() for r in line.split(","): if r.find("-") > 0: first, last = tuple(map(int, r.split("-"))) acc.extend(range(first, last + 1)) else: - acc.append(int(r)) + if r: + acc.append(int(r)) return acc + +def get_online_cpu_ids(): + return parse_cpu_ids("/sys/devices/system/cpu/online") + +def get_offline_cpu_ids(): + return parse_cpu_ids("/sys/devices/system/cpu/offline")