title: how to access rdmsr from c program?
body: <p>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:</p>
  
  <pre><code>asm volatile("rdmsr":"=a"(lo),"=d"(hi):"c"(0x10));
  </code></pre>
  
  <p>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.</p>
  
  <p>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.)</p>
  
  <p>Some related posts are <a href="https://stackoverflow.com/questions/11183654/cannot-read-back-from-msr">Cannot read back from MSR</a> and <a href="https://stackoverflow.com/questions/5875778/execute-rdmsr-and-wrmsr-instructions-from-c-c-code">rdmsr,wrmsr from c/c++ code</a></p>