Skip to content
Snippets Groups Projects
Commit 26a30376 authored by Nadav Har'El's avatar Nadav Har'El
Browse files

Change "hz" to fix poll() premature timeout

msleep() measure times in units of 1/hz seconds. We had hz = 1,000,000,
which gives excellent resolution (microsecond) but a terible range
(limits msleep()'s timeout to 35 minutes).

We had a program (Cassandra) doing poll() with a timeout of 2 hours,
which caused msleep to think we gave a negative timeout.

This patch reduces hz to 1,000, i.e., have msleep() operate in the same units
as poll(). Looking at the code, I don't believe this change will have any
ill-effects - we don't need higher resolution (freebsd code is used to
hz=1,000, which is the default there), and the code converts time units to
hz's correctly, always using the hz macro. The allowed range for timeouts will
grow to over 24 days - and match poll()'s allowed range.
parent ddec52d1
No related branches found
No related tags found
No related merge requests found
......@@ -97,8 +97,16 @@ extern int tick;
#define TSECOND (1000000000L)
#define TMILISECOND (1000000L)
/* Defines how many ticks are in 1 second */
#define hz (1000000L)
/* BSD-originated functions like msleep() measure time in units of "ticks",
* which are defined here by the macro hz (there are hz ticks per second).
* hz can be changed to anything, and does not impose, for example, a timer
* interrupt hz times a second. A very high hz, for example 1000000, is
* fine, but because the timeout parameter to msleep is an int, it results
* in a maximum timeout of just 36 minutes.
* As a compromise, we currently choose hz=1000 (same as poll()'s resolution),
* which gets us 1ms resolution, and a 24 day range.
*/
#define hz (1000L)
#define ticks2ns(ticks) (ticks * (TSECOND / hz))
#define ns2ticks(ns) (ns / (TSECOND / hz))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment