Re: "Streaming" data from kernel to userland



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

Attachment: pgp3lklUtRDm4.pgp
Description: PGP signature



Relevant Pages

  • Re: Why system call need to copy the date from the userspace before using it
    ... > user space to kernel space before using it. ... to access user memory using specific accessors, like copy_to/from_user, ... - Userland can give you a bogus pointer. ...
    (Linux-Kernel)
  • Re: "Streaming" data from kernel to userland
    ... amounts of pretty much real-time data from kernel to a userland ... interface which could be used to transfer large amounts of constantly ...
    (freebsd-hackers)
  • Re: Attempted summary of "RT patch acceptance" thread
    ... tries to keep the userland API as close as possible to the non-RT one, ... by increasing the kernel complexity with relative slowdown. ... RTAI quickly becomes useless (ok it can run nanosleep with fusion fine, ... RTAI/rtlinux as the only hard-RT with guaranteed deadline. ...
    (Linux-Kernel)
  • Re: [RFC] Splitting kernel headers and deprecating __KERNEL__
    ... >> two parties on an ABI doesn't imply that one party gets to define it ... imposition, kernel developers won't care. ... because there's a contract with userland that they don't want to ... change in the copy/extract/whatever of kernel headers that userland is ...
    (Linux-Kernel)
  • Re: "Enhanced" MD code avaible for review
    ... be required to make this work correctly using a userland approach. ... > kernel, and having to try harder to crash the kernel. ... protected *sooner* if the system crashes. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)