Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rdtsc may be reorderd by an out of order CPU #1

Open
majek opened this issue Jan 28, 2013 · 1 comment
Open

rdtsc may be reorderd by an out of order CPU #1

majek opened this issue Jan 28, 2013 · 1 comment

Comments

@majek
Copy link

majek commented Jan 28, 2013

This code looks wrong:

        __asm__ __volatile__("rdtsc" : "=a" (lo), "=d" (hi));

Snippet from this paper http://download.intel.com/embedded/software/IA/324264.pdf :

Starting with the Intel Pentium processor, most Intel CPUs support out-of-order execution of the code. The purpose is to optimize the penalties due to the different instruction latencies. Unfortunately this feature does not guarantee that the temporal sequence of the single compiled C instructions will respect the sequence of the instruction themselves as written in the source C file. When we call the RDTSC instruction, we pretend that that instruction will be executed exactly at the beginning and at the end of code being measured (i.e., we don’t want to measure compiled code executed outside of the RDTSC calls or executed in between the calls themselves).

@floodyberry
Copy link
Owner

It is kind of a lazy preference to not serialize with cpuid. If I'm calling it extremely frequently, I'm willing to live with some jitter instead of taking the overhead from cpuid, and if I'm not calling it frequently (e.g. measuring many repetitions at once), it's not going to make much of a difference.

In this case neither matter since I forgot to update t inside the testing loop, so it's basically only taking the first timing regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants