From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 19 09:08:55 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0099316A494 for ; Fri, 19 Jan 2007 09:08:55 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from turion.vk2pj.dyndns.org (c220-239-3-125.belrs4.nsw.optusnet.com.au [220.239.3.125]) by mx1.freebsd.org (Postfix) with ESMTP id 8460E13C43E for ; Fri, 19 Jan 2007 09:08:54 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from turion.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by turion.vk2pj.dyndns.org (8.13.8/8.13.8) with ESMTP id l0J98nIO001409; Fri, 19 Jan 2007 20:08:49 +1100 (EST) (envelope-from peter@turion.vk2pj.dyndns.org) Received: (from peter@localhost) by turion.vk2pj.dyndns.org (8.13.8/8.13.8/Submit) id l0J98nnM001408; Fri, 19 Jan 2007 20:08:49 +1100 (EST) (envelope-from peter) Date: Fri, 19 Jan 2007 20:08:49 +1100 From: Peter Jeremy To: Ivan Voras Message-ID: <20070119090849.GA860@turion.vk2pj.dyndns.org> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="TB36FDmn/VVEgNH/" Content-Disposition: inline In-Reply-To: X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.13 (2006-08-11) Cc: freebsd-hackers@freebsd.org Subject: Re: "Streaming" data from kernel to userland X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jan 2007 09:08:55 -0000 --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. --=20 Peter Jeremy --TB36FDmn/VVEgNH/ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (FreeBSD) iD8DBQFFsIqh/opHv/APuIcRAmcfAJ0QVqWutkvgaRmDlNTKBB8LNAyDeQCfX7iL Ujj6NfVKcmuCxgnAeOl2huU= =j5Eg -----END PGP SIGNATURE----- --TB36FDmn/VVEgNH/--