From 67d7b8f4c8f61b521ba1e8a24c5c3cc0a28ee8a8 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Tue, 2 Aug 2022 00:58:19 +0800 Subject: [PATCH] config_tools: board_inspector: fix MSR reads and writes The MSR reading and writing routines today has the following issues: 1. The missing of /dev/cpu/*/msr is not properly captured as it is reported via FileNotFoundError rather than IOError. 2. The wrmsr logic is not updated to use the tmpdevfs msr file. This patch fixes the issues above which is a prerequisite of adding additional MSR parsing classes. Tracked-On: #7948 Signed-off-by: Junjie Mao --- .../board_inspector/cpuparser/platformbase.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/misc/config_tools/board_inspector/cpuparser/platformbase.py b/misc/config_tools/board_inspector/cpuparser/platformbase.py index 308edf477..7acaa0661 100644 --- a/misc/config_tools/board_inspector/cpuparser/platformbase.py +++ b/misc/config_tools/board_inspector/cpuparser/platformbase.py @@ -139,11 +139,11 @@ class MSR(object): @classmethod def rdmsr(cls, cpu_id: int) -> int: try: - with open(f'/dev/cpu/{cpu_id}/msr', 'rb') as msr_reader: + with open(f'/dev/cpu/{cpu_id}/msr', 'rb', buffering=0) as msr_reader: msr_reader.seek(cls.addr) r = msr_reader.read(8) r = cls(int.from_bytes(r, 'little')) - except IOError: + except FileNotFoundError: logging.critical(f"Missing CPU MSR file at /dev/cpu/{cpu_id}/msr. Check the value of CONFIG_X86_MSR " \ "in the kernel config. Set it to 'Y' and rebuild the kernel. Then rerun the Board Inspector.") sys.exit(1) @@ -154,7 +154,14 @@ class MSR(object): def wrmsr(self, cpu_id=None): if cpu_id is None: cpu_id = self.cpu_id - bits.wrmsr(cpu_id, self.addr, self.value) + try: + with open(f'/dev/cpu/{cpu_id}/msr', 'wb', buffering=0) as msr_reader: + msr_reader.seek(self.addr) + r = msr_reader.write(int.to_bytes(self.value, 8, 'little')) + except FileNotFoundError: + logging.critical(f"Missing CPU MSR file at /dev/cpu/{cpu_id}/msr. Check the value of CONFIG_X86_MSR " \ + "in the kernel config. Set it to 'Y' and rebuild the kernel. Then rerun the Board Inspector.") + sys.exit(1) def __str__(self): T = type(self)