Programming Intel's Model-Specific Registers (MSRs)


Model (or sometimes called Machine) Specific Registers (MSRs) are a useful tool during debugging to determine the working of the processor. They can also be used to control the functioning of the processor such as the working of the cache memories, branch prediction logic etc.


Accessing MSRs

To access the MSR registers, there are two requirements.
  1. The kernel must support it.
  2. A user space application must be required to communicate with the kernel
The MSR Driver
For the Linux kernel, a module msr is to be present.

To check if your kernel has MSR support built in :

            $ cat /boot/config-2.6.28-18-generic | grep MSR
               CONFIG_X86_MSR=m 

On my Ubuntu 9.04, the MSR is a module. I added it to
the kernel with the command:
            
           $ sudo modprobe msr

Inserting the module would create the device files /dev/cpu/_processor_number_/msr. There would be one msr device for each processor.

User Space Access (msr-tools)
msr-tools can be downloaded from the kernel.org site http://www.kernel.org/pub/linux/utils/cpu/msr-tools/msr-tools-1.1.2.tar.bz2. If you are using Ubuntu, msr-tools can be installed using the package manager.

msr-tools have two executables:
rdmsr : This is used to read an MSR register.

            $ sudo rdmsr 0x198 
               6160b2406000b24       

wrmsr : This is used to write to an MSR register
  
            $ sudo wrmsr 0x198 6160b2406000b24



The MSR Registers
The MSR registers for the Intel Processor is present in the Appendix B of Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 3B: System Programming Guide



References
  1. http://blogs.koolwal.net/2009/09/19/howto-using-cpu-msr-tools-rdmsrwrmsr-in-debian-linux/

No comments:

Post a Comment

Followers