Linux MSR tools
Notes about MSR tools in Linux,并结合一个具体的例子,展示其用法。本文大部分内容源于Linux读写CPU MSR寄存器命令rdmsr/wrmsr。
Linux内核源码提供了读写CPU MSR寄存器模块,使得用户空间可以直接读写MSR寄存器。
开源社区提供msr寄存器读写工具:msr-tools,其中有两个命令,rdmsr
/wrmsr
。
Prerequisite
要使rdmsr
/wrmsr
命令可以读写msr寄存器,系统中必须有msr模块,或将msr模块编译进内核。下面是从内核配置选项中选取的内容:1
2Processor type and features —>
<M> /dev/cpu/*/msr – Model-specific register support
1 | modprobe msr |
Demo
1 | root@kvm:~# rdmsr -h |
1 | root@kvm:~# rdmsr -p 0 0x1b |
由此可加:
- CPU 0 has set BSP flag, while CPU 1 has cleared BSP flag
- x2APIC mode is enabled
- APIC Global enabled
- …
Interface
/dev/cpu/CPUNUM/msr
provides an interface to read and write the model-specific registers (MSRs) of an x86 CPU. CPUNUM is the number of the CPU to access as listed in /proc/cpuinfo.
The register access is done by opening the file and seeking to the MSR number as offset in the file, and then reading or writing in chunks of 8 bytes.
Resource
man msr
- intel/msr-tools