Software Tuning, Performance Optimization & Platform Monitoring
Discussion regarding monitoring and software tuning methodologies, Performance Monitoring Unit (PMU) of Intel microprocessors, and platform updating.

how to use rdmsr from my C program?

anthony_b_
Beginner
1,828 Views

From intel software developer manual 3b, I came to know MSR (10H) equal to RDTSC. So I wanted to verify it using piece of code as follows in my program:

asm volatile("rdmsr":"=a"(lo),"=d"(hi):"c"(0x10));

But when I run my program it showed segmentation fault. Then a realized the caution that it work only in privilege level 0. So I run the program again with sudo access. This time the program ran without seg fault but the statement after asm volatile(..) are not getting executed. Even it dint work out.

What shall I do to make rdmsr work in my program?
(I am using linux on i7 core which supports these counters. I verified it.)

Thank you

0 Kudos
3 Replies
Adrian_C_
Beginner
1,828 Views

How would you do this in the Windows OS?

0 Kudos
Thomas_G_4
New Contributor II
1,829 Views

I don't know whether there is a WindowsOS native way to access the MSRs, probably through some debugging interface or such.

You can use the Windows driver from Intel PCM https://github.com/opcm/pcm to get an interface to the user space. For further information see the Windows HOWTO https://github.com/opcm/pcm/blob/master/WINDOWS_HOWTO.rtf

Here is also a link with some explanations how to install the driver: https://software.intel.com/en-us/forums/software-tuning-performance-optimization-platform-monitoring/topic/371243

0 Kudos
SB17
Beginner
1,829 Views

If it will be helpfull - good examples of how to use rd/wrmsr is the source code of Intel Performance Counter Monitor and Likwid.

 

 

0 Kudos
Reply