Re: rdtsc and the sleep fcn (Was problem with rdtsc instruction on Pentium M)
From: Michael Brown (spamtrap_at_crayne.org)
Date: 10/29/04
- Previous message: René: "Re: Problems with Earthlink news server"
- In reply to: John Doe: "rdtsc and the sleep fcn (Was problem with rdtsc instruction on Pentium M)"
- Next in thread: Vasanth Venkatachalam: "Re: rdtsc and the sleep fcn (Was problem with rdtsc instruction on Pentium M)"
- Reply: Vasanth Venkatachalam: "Re: rdtsc and the sleep fcn (Was problem with rdtsc instruction on Pentium M)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 28 Oct 2004 22:10:27 +0000 (UTC)
John Doe wrote:
> 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.
This is correct (as have been mentioned many times). Any halfway decent
modern OS's sleep function won't sit in a loop. It marks the thread as
sleeping, puts a notification in a queue to wake it up at some later point
in time, then goes off and does something else for a while (runs another
thread, idles, etc). As part of idleing, the CPU is slowed down which stuffs
up the TSC.
> Is there any workaround for this in the OS?
The solution is not to use RDTSC. The alternatives depend on the OS you are
using, which by your newsreader I'm guessing is Windows. In this case, use
the QueryPerformanceCounter function for high-resolution timing. On modern
mobile (ie: non TSC-stable systems) it uses the ACPI timer which has a
constant frequency regardless of the CPU frequency. IIRC the utime function
does the same thing on Linux (when ACPI support is compiled in, of course).
> 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.)
In that case you simply cannot use RDTSC. The primary way of saving power is
to throttle down the CPU, which disturbs the TSC.
[...]
-- Michael Brown www.emboss.co.nz : OOS/RSI software and more :) Add michael@ to emboss.co.nz - My inbox is always open
- Previous message: René: "Re: Problems with Earthlink news server"
- In reply to: John Doe: "rdtsc and the sleep fcn (Was problem with rdtsc instruction on Pentium M)"
- Next in thread: Vasanth Venkatachalam: "Re: rdtsc and the sleep fcn (Was problem with rdtsc instruction on Pentium M)"
- Reply: Vasanth Venkatachalam: "Re: rdtsc and the sleep fcn (Was problem with rdtsc instruction on Pentium M)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|