title: Accuracy of rdtsc for benchmarking and time stamp counter frequency
body: <p>As part of a benchmarking task, I was investigating the different mechanisms that can be used to measure elapsed time. I've finalised on using <code>clock_gettime</code>, but I did do sufficient research and testing with the <code>RDTSC</code> instruction as well. I have several question regarding the same (based on what I read on several online threads):</p>
  
  <ul>
  <li><p>On newer processors (>Pentium 4), the TSC ticks at the maximum frequency of the CPU on the system. Is this correct? In that case is it valid to use the number of ticks and frequency to determine the time?</p></li>
  <li><p>If the above is true, it means TSC is unaffected by changes in CPU frequency due to power saving and other features. Knowing this, would it mean the total ticks obtained by using <code>RDTSC</code> are NOT the actual ticks used by the sampled piece of code - since the code would run at the frequency of the CPU and not that of the TSC? In addition, does this mean the time obtained by using the TSC ticks and CPU frequency isn't the actual time used by the code piece?</p></li>
  <li><p>I'm finding lots of different statements about the synchronizing of the TSC value across cores (see <a href="https://stackoverflow.com/questions/3388134/rdtsc-accuracy-across-cpu-cores" title="this thread">this thread</a>). I'm not sure what is correct and I'm guessing it depends on the processor model as well. But can it be assumed to be synchronized among cores on newer CPUs? (This is without using <code>sched_set_affinity</code>)?</p></li>
  </ul>
  
  <p>Do note that I'm not using <code>RDTSC</code> due to the various problems associated with it (portability, reliability etc). These questions are just to improve my understanding of how TSC works and of benchmarking in general.</p>