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 <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2022-08-02 00:58:19 +08:00 committed by acrnsi-robot
parent a6614e7e2f
commit 67d7b8f4c8
1 changed files with 10 additions and 3 deletions

View File

@ -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)