Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

rdtsc anomaly

slackmack
Beginner
651 Views
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
jimdempseyatthecove
Honored Contributor III
651 Views

Try

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

Jim Dempsey
0 Kudos
TimP
Honored Contributor III
651 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
zhen436
Beginner
651 Views
Does the suggested solution work?
0 Kudos
TimP
Honored Contributor III
650 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
Reply