Reputation: 353
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.)
Some related posts are Cannot read back from MSR and rdmsr,wrmsr from c/c++ code
Upvotes: 0
Views: 1897
Reputation: 12263
You confuse CPU/hardware privileges (restrictions on instructions to execute, memory accesses) with OS/system privileges (OS functions, files, etc.). A root application does not run at a different CPU privilege level than code of a normal user. It just has more allowance for OS functions.
You have to run that instruction from the OS kernel which typically runs at ring 0.
Upvotes: 2