On Sun, Dec 3, 2017 at 1:17 PM, Stephen Graf <s_g...@telus.net> wrote:
> I am working on sxitwi.c and have a question on the tsleep function. > > Any documentation describes the timo parameter to tsleep as: > > If non-zero, the process will sleep for at most timo/hz seconds. If this > amount of time elapses and no wakeup(ident) has occurred, and no signal > (if PCATCHwas set) was posted, tsleep() will return EWOULDBLOCK. > > I would like to know what “timo/hz” means. Hz is the symbol for cycles, > but > what does it mean in this context? If the timo parameter is set to 100, > does tsleep sleep for at most 100 seconds or 100 divided by something? > hz is a global variable that describes the number of interrupts per second the timer produces. Usually this number is something like 50, 60, 100, 1000 or 1024 in *BSD, but YMMV. So this isn't "Hz" in the standard frequency measurement sense, though it is closely related since it's the number of interrupts per second for the system... It's exported as the kern.hz sysctl. When you pass in 100 for timo to tsleep, that's 100 ticks, which would be 100 / hz seconds. If you want to sleep for a second, pass in 'hz'. This also works with fractions of a second, but if you have an hz == 100 and pass in hz / 30, there will be some truncation that gives 3 ticks or 30ms rather than the desired 33.33...ms. This is why you'll often see '+1' thoughtlessly added to the value so you sleep at least that long in case where hz / blah isn't an exact number. Warner