Microsecond sleeps with select() - Mailing list pgsql-hackers

From Bruce Momjian
Subject Microsecond sleeps with select()
Date
Msg-id 200102171641.LAA16661@candle.pha.pa.us
Whole thread Raw
Responses Re: Microsecond sleeps with select()  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
A comment on microsecond delays using select().  Most Unix kernels run
at 100hz, meaning that they have a programmable timer that interrupts
the CPU every 10 milliseconds.  The kernel only gets to control the cpu
during those tick interrupts or if a user application makes a kernel
call.

Therefore, it is no surprise the most Unix kernels can't do 5
microsecond sleeps.  The only way they could do it would be to reprogram
the timer interrupt if a wakeup was going to occur in less than 10
milliseconds.  I doubt many kernels do that because I don't think timer
interrupt programming is a very quick or accurate operation.  Also,
reprogramming it would make the actual 100hz timer unreliable.

Now, kernels could check on return from kernel to user code to see if
someone is ready to be woken up, but I doubt they do that either. 
Looking at the BSDI kernel, all timeouts are expressed in ticks, which
are 10 milliseconds.  Obviously there is no checking during kernel call
returns because they don't even store the sleeps with enough resolution
to perform a check.  In fact, the kernel doesn't even contain have a way
to measure microsecond timings.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Non-locale 7.1beta4 binaries on RedHat 6.2 test results.
Next
From: Lamar Owen
Date:
Subject: Re: Non-locale 7.1beta4 binaries on RedHat 6.2 test results.