Polling and Sleep in a Driver

M. Warner Losh imp at bsdimp.com
Sun Oct 19 17:55:18 UTC 2008


In message: <27cb3ada0810190720u2cc84097w2ed6425bc6ee8d3f at mail.gmail.com>
            "Len Gross" <sandiegobiker at gmail.com> writes:
: I have a MAC protocol written using Netgraph.   It runs in userland
: and uses a simple poll, sleep loop.  It has proved that the algorithms
: are correct, but the sleeps are not regular/accurate enough for my
: purposes.  (I have pushed Hz up quite a bit with no real effect)

This surprises me.  I've seen big effects going from 100Hz to 1000Hz.

: If I were to implement the algorithms within a driver would the sleeps
: still suffer from the same "non real-time" behaviour I see in
: userland?

Well, it depends on what you are seeing.  How accurate a sleep do you
need?  I've discovered that 2 / HZ is a good lower bound for sleep
inaccuracy in the kernel.  Often times this won't matter.  You may be
able to push the bounds with some clever hacks, but it still won't get
you below 1/Hz w/o some other interrupt source that can clock a higher
res timer.

Warner


More information about the freebsd-drivers mailing list