Skip to content

Commit 2544958

Browse files
committed
feat: rewrite msr_reader in python
Rewrite `msr_reader.sh` script in python to speed up manual validation of msr baselines. Bash script run in ~1 minute. python version runs in 0.35 seconds. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 71247bd commit 2544958

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

tests/data/msr/msr_reader.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Helper script used to read MSR values from ranges known to contain MSRs.
5+
6+
import os
7+
8+
msr_fd = open("/dev/cpu/0/msr", "r")
9+
10+
def print_msr(msr: int):
11+
try:
12+
msr_bytes = os.pread(msr_fd.fileno(), 8, msr)
13+
msr_value = int.from_bytes(msr_bytes, byteorder="little")
14+
print(f"{msr:#x},{msr_value:#x}")
15+
except:
16+
pass
17+
18+
print("MSR_ADDR,VALUE")
19+
for msr in range(0, 0xFFF + 1): print_msr(msr);
20+
for msr in range(0x10000, 0x10FFF + 1): print_msr(msr);
21+
for msr in range(0xC0000000, 0xC0011030 + 1): print_msr(msr);
22+
23+
print_msr(0x400000000);
24+
print_msr(0x2000000000);
25+
print_msr(0x4000000000);
26+
print_msr(0x8000000000);
27+
print_msr(0x1000000000000);
28+
print_msr(0x3c000000000000);
29+
print_msr(0x80000000000000);
30+
print_msr(0x40000000000000);

tests/integration_tests/functional/test_cpu_features_x86_64.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,12 @@ def test_cpu_rdmsr(
300300
vm.basic_config(vcpu_count=vcpus, mem_size_mib=guest_mem_mib)
301301
vm.set_cpu_template(cpu_template_any)
302302
vm.start()
303-
vm.ssh.scp_put(msr_reader_bin, "/tmp/msr_reader")
304-
_, stdout, stderr = vm.ssh.run("/tmp/msr_reader")
303+
# vm.ssh.scp_put(msr_reader_bin, "/tmp/msr_reader")
304+
# _, stdout, stderr = vm.ssh.run("/tmp/msr_reader")
305+
306+
vm.ssh.scp_put(msr_reader_bin, "/tmp/msr_reader.py")
307+
_, stdout, stderr = vm.ssh.run("python3 /tmp/msr_reader.py")
308+
305309
assert stderr == ""
306310

307311
# Load results read from the microvm

0 commit comments

Comments
 (0)