"Streaming" data from kernel to userland

Peter Jeremy peterjeremy at optushome.com.au
Fri Jan 19 09:08:55 UTC 2007


On Thu, 2007-Jan-18 23:22:01 +0100, Ivan Voras wrote:
>I'm thinking of doing something which would require streaming large
>amounts of pretty much real-time data from kernel to a userland
>application (for further processing).

The simplest interface is read().  The downside is that (in the
default case), you need to do a copyout() of the data.

My suggestion is mmap():  Userland mmap()'s a large buffer and your
kernel app treats it as a ring buffer and generated data directly into
it.  The trick here is informing userland when data is available and
how much there is.  The approach I've used is to store the kernel
write pointer (and optionally, the userland read pointer) in mmap()'d
memory as well.  Userland can block (to wait for the kernel to provide
more data) in various ways:
- If there's no data to process, sleep for a convenient period and
  check again.  This needs no support from your kernel driver.
- Use kqueue(), signal() or read() a token to indicate when some
  amount of data is available.

-- 
Peter Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20070119/a2d3cf34/attachment.pgp


More information about the freebsd-hackers mailing list