Skip to contentSkip to conversation

Timeout overflow in select()

DISCUSSION Colin Plumb 2 participants 2 messages Nov 23, 1998 – Nov 25, 1998

lore
Share & tools
lore
#0 lore raw

Marc Slemko <[email protected]> uncovered:

Quoted 4 lines

it is correct to place an upper limit on the timeout.
From the single unix spec
(http://www.opengroup.org/publications/catalog/t912.htm):
Implementations may place limitations on the maximum timeout interval

Quoted 8 lines

supported. On all implementations, the maximum timeout interval supported will be at least 31 days. If the timeout argument specifies a timeout interval greater than the implementation-dependent maximum value, the maximum value will be used as the actual timeout value. Implementations may also place limitations on the granularity of timeout intervals. If the requested timeout interval requires a finer granularity than the implementation supports, the actual timeout interval will be rounded up to the next supported value.

Note that this can impose an upper limit on HZ.
In particular, 2^32 jiffies is 31 days at 1603.5 Hz. If you need an extra bit, 2^31 jiffies is 31 days at 801.8 Hz.

Thus, a 31-bit jiffies limit is not compatible with HZ=1024.

(I distinctly recall looking at the POSIX spec and seeing in the definition of clock() that it must not wrap before 24 hours, which, if clock_t is a 32-bit type, implies a maximum CLOCKS_PER_SEC of 49710. Thus, the common CLOCKS_PER_SEC=1000000 violates this badly, as it wraps in 1:11:34.967296. Unfortunately, I don't have a copy of POSIX.1 handy to check my memory.)

Signature · 6 lines
	-Colin

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#1 lore raw
Quoted 3 lines · Colin Plumb
Quoted 3 lines

Implementations may place limitations on the maximum timeout interval supported. On all implementations, the maximum timeout interval supported will be at least 31 days.

[...]

Quoted 5 lines

Note that this can impose an upper limit on HZ.
In particular, 2^32 jiffies is 31 days at 1603.5 Hz. If you need an extra bit, 2^31 jiffies is 31 days at 801.8 Hz.

Thus, a 31-bit jiffies limit is not compatible with HZ=1024.

My first reaction was to say that all this was hypothetical (looking at i386 only). But it's not, because of the Alpha. If we want to be conformant, and have a large HZ, and still have a 32 bit time_t, we have to loop around the do_select() as I suggested in my original email. I guess it can be exercised by crippling the timeout allowed to go to "current->timeout", to (say) a few minutes.

Poll: what do you think? Do we want that loop? Or do we just say that a couple days for the maximum timeout when you have a big HZ is good enough? (and the hell with those standards).

Poll: Has anyone ever seen (heard of) code which would use huge timeouts in select() and would require accuracy on them? (ie, wouldn't like at all to be woken up before it's due) Does anyone know what other Unices do?

"He who has not sinned ...": my fix didn't include any checking on tv_usec. While it takes care of the overflow (well, mostly) that started this thread, it doesn't close the select() argument checks issue. I should add something, so that we're 100% sure that the computed timeout is valid. BTW, we probably should be tolerant with negative tv_usec values (the current select() very much is). There could be some code out there that does "0.999 seconds" as (1 sec, -1000 microseconds). Or stuff like that, you get the idea. So a little bit of double guessing is to be expected.

(Colin: sorry for the mess, and thanks)
--
Stephane Belmon <[email protected]>
University of California, San Diego
Computer Science and Engineering Department

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/