ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I played the following piece of code on both Windows and Linux
// Windows with Visual Studio 2008
unsigned __int64 GetCycleCount()
{
__asm RDTSC
}
...
t = GetCycleCount();
t2 = GetCycleCount();
wprintf(TEXT("cycle diff: %d\r\n"), t2 - t);
...
// Linux with gcc
unsigned long long int GetCycleCount()
{
asm ("rdtsc");
}
...
t = GetCycleCount();
t2 = GetCycleCount();
printf("cycle diff: %d\n", t2 - t);
...
while I always got "cycle diff: 88" under Linux, I got 308 under Windows XP (SP3) occationally (most time I got 297)..
I am wondering why there may be a very small difference under Windows ? just 11 cycle ? If there was a context switch or something, there would be much much bigger difference that 11.
I didn't look at the code generated. I think whatever code was generated, the difference should be a constant unless it was interrupted between the two rdtsc instructions. In a case of interruption, I would expect much bigger difference than just 11 cycles. I didn't check Intel manual though..
I don't know if it is cache warming up. as if that were the issue, you should have seen the same numbers the first time the code was run. After all, code is not there in the caches when it runs the first time. In case it indeed is cache warming up, you could run the code in a loop to see if the numbers start matching.
Also, I am just thinking aloud here, could it be powersave features of the processor kicking in, perhaps, better implemented on Linux? If you are running the test on a laptop, you could set the CPU policy to performance to see if that changes anything.
Also, if possible, you could try running this code from a kernel module with interrupts disabled (I think on windows, cli/sti or something equivalent can be used). Although, context switches should be longer, but just to take them out of the equation altogether.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.