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? |
On Sun, 3 Dec 2017, Stephen Graf 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 PCATCH was 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? In this context it's referring not to the unit of Hertz but rather to the 'hz' kernel variable, as documented in the hz(9) manpage which is listed in the SEE ALSO section. > If the timo parameter is set to 100, does tsleep sleep for at most 100 > seconds or 100 divided by something? 100 / hz, which on most OpenBSD archs will end up being 1 second. If you know your desired duration, then just do the arithmetic with 'hz' to get the necessary 'timo' value to pass. If you look around the device tree you'll find examples. There are helper functions tvtohz(9) and tstohz (on the same manpage) for converting timeval or timespec values to 'timo' for use with tsleep and friends, but those are more for when you get such a value from userspace. Philip Guenther |
In reply to this post by Stephen Graf
--- On Sun, 12/3/17, Stephen Graf <[hidden email]> wrote:
> Hz is the symbol for cycles, Hz is equivalent to (seconds)^-1. So 1/Hz is just seconds. The documentation is very poor. |
In reply to this post by Stephen Graf
On Sun, Dec 3, 2017 at 1:17 PM, Stephen Graf <[hidden email]> 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 |
In reply to this post by Stephen Graf
Thank you all for your responses.
On my orange one, kern.clockrate=tick = 10000, tickadj = 40, hz = 100, profhz = 1000, stathz = 100, so a timo of 100 would be one second. -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Warner Losh Sent: Sunday, December 3, 2017 3:00 PM To: Stephen Graf <[hidden email]> Cc: [hidden email] Subject: Re: clarification of tsleep On Sun, Dec 3, 2017 at 1:17 PM, Stephen Graf <[hidden email]> 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 |
Free forum by Nabble | Edit this page |