[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gettimeofday() and clock



On Mon, 2 Sep 2002, Steve Baker wrote:

> Mads Bondo Dydensborg wrote:
> > On Sun, 25 Aug 2002, Steve Baker wrote:
> > 
> >>usleep is given an argument in MICROSECONDS - but in practice it can't wake
> >>your program up any faster than the kernel timeslice - which is 1/50th second.
> 
> > Eh? Depends on platform, I believe, last I checked was 100Hz on intel, 
> > 1000Hz on alpha.
> 
> Really?   

I believe so. Look in
usr/include/asm/param.h

>I could have sworn it was 50Hz on Intel - because when my program
> does a short usleep (say 1 millisecond), it generally sleeps for ~20ms - which
> is 1/50th second.  Hence, I deduce that the kernel only wakes up and reschedules
> my program 50 times a second - and not 100Hz as you suggest.
> 
> I also believe the 50Hz figure because the *original* UNIX on PDP-11's used
> 50Hz - and I presumed that Linus picked the same number for compatibility.
> 
> Try running this:

[...]

Please look at e.g. 
http://www.tldp.org/HOWTO/mini/IO-Port-Programming-4.html
I am no expert, but I believe this is usually the reference one gets on 
these matters.

Perhaps, if you have time, you could try the realtime option and nanosleep 
instead. nanosleep does block the CPU though.


> I'd *really* like to see a shorter timeslice on Intel.  With
> 2GHz CPU's, even 100Hz is like an eternity.

I believe it _is_ possible to redefine HZ to something higher, even on 
Intel, but that it might lead to trouble.

> 
> A 1000Hz kernel timeslice - and (in consequence) a usleep that was
> accurate to ~1ms instead of ~20ms - would solve a *TON* of problems
> for graphics programs that want to run at 60Hz and yet still use
> 'usleep' to avoid blocking the CPU.

Yes, indeed.

Mads

-- 
Mads Bondo Dydensborg.                               madsdyd@challenge.dk
What I have done is to show that it is possible for the way the universe
began to be determined by the laws of science. In that case, it would not be
necessary to appeal to God to decide on how the universe began. This doesn't
prove that there is no God, only that God is not necessary.
                       - Stephen W. Hawking (Der Spiegel, 1989)