在Linux内核源码中提供了读写CPU MSR寄存器模块,使可以在用户空间直接读写MSR寄存器。
开源社区提供msr寄存器读写工具msrtools,其中有两个命令,rdmsr/wrmsr。要使rdmsr/wrmsr命令真正可以读写msr寄存器,系统中必须有msr模块,或将msr模块编译进内核,下面是从内核配置选项中选取的内容。
Processor type and features —>
<M> /dev/cpu/*/msr – Model-specific register support
实例:
root@ubuntu:~/linux-2.6.32.36-0.5# rdmsr 0x1a0
0
root@ubuntu:~/linux-2.6.32.36-0.5#
rdmsr和wrmsr命令格式如下:
root@ubuntu:~# rdmsr
Usage: rdmsr [options] regno
–help -h Print this help
–version -V Print current version
–hexadecimal -x Hexadecimal output (lower case)
–capital-hex -X Hexadecimal output (upper case)
–decimal -d Signed decimal output
–unsigned -u Unsigned decimal output
–octal -o Octal output
–c-language -c Format output as a C language constant
–zero-pad -0 Output leading zeroes
–raw -r Raw binary output
–processor # -p Select processor number (default 0)
–bitfield h:l -f Output bits [h:l] only
root@ubuntu:~#
root@ubuntu:~# wrmsr
Usage: wrmsr [options] regno value…
–help -h Print this help
–version -V Print current version
–processor # -p Select processor number (default 0)
root@ubuntu:~#
Leave a Reply