Re: why can't select() sleep for 1 jiffy?

Linus Torvalds (
Sat, 31 Aug 1996 17:15:42 +0300 (EET DST)

[ Btw - I'm back in Finland, and you can forget about the temporary US
address (in fact, it may not even exist any more). ]

On Fri, 30 Aug 1996, Ingo Molnar wrote:
> from fs/select.c:
> timeout = ROUND_UP(get_user(&tvp->tv_usec),(1000000/HZ));
> timeout += get_user(&tvp->tv_sec) * (unsigned long) HZ;
> if (timeout)
> timeout += jiffies + 1;
> Thus timeout is at least jiffies+2 [or 0]. So we cant sleep until the
> next jiffy, we have to wait for two timer interrupts.
> Is this some POSIX.1 thing?

Yes. POSIX requires that we sleep at LEAST as long as the timeout

The reason we do the "timeout += jiffies+1" thing is that the next timer tick
might be very soon indeed, so if we timed out on the next jiffy we would end
up waiting for just 0.5 jiffies on average. That's why we have to wait for at
least 2 timer ticks to be safe...