title: PMU for multi threaded environment
body: <p>I am planning to measure PMU counters for L1,L2,L3 misses branch prediction misses , I have read related Intel documents but i am unsure about the below scenarios.could some one please clarify ?</p>
  
  <pre><code>//assume PMU reset and PERFEVTSELx configurtion done above 
  ioctl(fd, IOCTL_MSR_CMDS, (long long)msr_start)  //PMU start counters
  my_program();
  ioctl(fd, IOCTL_MSR_CMDS, (long long)msr_stop)   ///PMU stop
  //now reading PMU counters 
  </code></pre>
  
  <p>1.what will happen if my process is scheduled out when my_program() is running, and scheduled to another core?</p>
  
  <p>2.what will happen if process scheduled out and schedule back to same core again, meanwhile some other process reset the PMU counters?</p>
  
  <p>How to make sure that we are reading the correct values from PMU counters.?</p>
  
  <blockquote>
    <p>Machine details:CentOS with Linux kernel 3.10.0-327.22.2.el7.x86_64 , which is powered up with Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz</p>
  </blockquote>
  
  <p>Thanks</p>