"sleep" in freebsd kernel

M. Warner Losh imp at bsdimp.com
Sun Feb 4 06:57:55 UTC 2007


In message: <e80b0eb70702031854n57d81f6ar8b7f46be9d34d1a8 at mail.gmail.com>
            "lu ping" <luping.nju at gmail.com> writes:
: I have a kernel thread running as a daemon, and I want to make it sleep for
: a while in an infinite loop. I guess I can use "tsleep" but it only timeout
: after intergal system ticks, which only has millisecond granularity, but I
: want to make it sleep in some microsecond. Is there any way I can do this in
: the kernel?

Make HZ=10000 and you get 100us timeouts. :-)

However, there are issues with that...

There's presently no easy way to sleep for microseconds without some
kind of hardware assist.  Maybe the daemon you are running can access
custom hardware, which you could use to schedule your interrupt in the
near future.

There is DELAY which will delay things by a number of microseconds,
but it isn't that useful if you are doing it a lot because it is a
busy wait, not a scheduling event.

Warner


More information about the freebsd-hackers mailing list