rdtsc and the sleep fcn (Was problem with rdtsc instruction on Pentium M)

From: John Doe (spamtrap_at_crayne.org)
Date: 10/28/04


Date: Thu, 28 Oct 2004 19:01:31 +0000 (UTC)

I ran some more tests with rdtsc. It turns out that when I use it to time
ordinary programs the numbers are not that different from those obtained by
the time( ) function. It is only when I time the sleep( ) function that the
numbers are off by a maginitude of seconds, far less than they should be.

So my hunch is that the timestamp counter on my Pentium M stops counting
cycles during part of the sleep( ) function. Maybe this function goes into
the idle loop, causing the tsc to stop counting. Is there any workaround for
this in the OS? I read that someone in the previous post designed their own
idle loop to prevent the CPU from going into the main idle loop.

I'm looking for a similar solution, but I don't want the processor to be
doing unnecessary work when it is supposed to idle. (I'll be exploiting idle
periods for power management.)

Any suggestions?

Vasanth