Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
9 Views

rdtsc anomaly

I wrote a test program to compare the results from rdtsc and gettimeofday. I ran the test of Nehalem X5570. I understand that this platform has Invariant TSC.

The test program is as follows:
1. start = x86_get_timer();
2. while loop downcounting register value from 2.93e+09 till 0
3. end = x86_get_timer();
4. Display the result.

With just the above steps, the result printed varying drastically. I can't explain why it is so, even when I do taskset to run the program.

I added gettimeofday calls before and after to compare the results. The results of both rdtsc and gettimeofday were consistent, but the result of gettimeofday is almost half of rdtsc value.

I've attached the program for readers to review and comment.

Thanks,
SlackMack
0 Kudos
4 Replies
Highlighted
9 Views


Try

[cpp]    return ((((unsigned long long)hi)<<32) | (lo & 0xffffffff));[/cpp]

Jim Dempsey
0 Kudos
Highlighted
Black Belt
9 Views


Try

[cpp]    return ((((unsigned long long)hi)<<32) | (lo & 0xffffffff));[/cpp]

Jim Dempsey
With Intel or Microsoft compilers, the _rdtsc() macro takes care of this stuff, and the return value may be treated as unsigned long long int.
0 Kudos
Highlighted
Beginner
9 Views

Does the suggested solution work?
0 Kudos
Highlighted
Black Belt
9 Views

Neither you nor the original poster specified which compiler you intend to use, or which defines were set, so the reasonable assumption was made that correcting the obvious error in combining low and high order parts would help.
0 Kudos