From owner-freebsd-current@FreeBSD.ORG Sat Mar 22 12:58:18 2008 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C83AA106566C for ; Sat, 22 Mar 2008 12:58:18 +0000 (UTC) (envelope-from barney_cordoba@yahoo.com) Received: from web63914.mail.re1.yahoo.com (web63914.mail.re1.yahoo.com [69.147.97.129]) by mx1.freebsd.org (Postfix) with SMTP id 777548FC1B for ; Sat, 22 Mar 2008 12:58:18 +0000 (UTC) (envelope-from barney_cordoba@yahoo.com) Received: (qmail 92504 invoked by uid 60001); 22 Mar 2008 12:58:17 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=jNfqaaQJuepJ8Xr5PTYPBywB+juuUrM3bXZkvKmeVourATx71kKFNdj0sQ5174ELLnc8tEKQnqAoQgH6sS1KLBskNHoK+W8KlDdg3cZgfDr3SLfPvC6steux0sPEjK1EPTTFohAEZ7BLY399gA6nJHckvfQ+DGToj6HaUVpjJ94=; X-YMail-OSG: L0QG_lUVM1m_OEvsmClCqoRXfuGj1S4qqj4f6CPE1vAyMJRoe83Lv4ntaQZuFX9QfZWieHu7INBJkPVeV9yoGxX0GjQBZAAVqY07BWSBz15afYRdWEyKzF3k0TjRJeztc3vmDN.LqMHEyxQ- Received: from [24.45.195.185] by web63914.mail.re1.yahoo.com via HTTP; Sat, 22 Mar 2008 05:58:17 PDT Date: Sat, 22 Mar 2008 05:58:17 -0700 (PDT) From: Barney Cordoba To: Julian Elischer In-Reply-To: <47E48957.7040903@elischer.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <523743.91444.qm@web63914.mail.re1.yahoo.com> Cc: current@freebsd.org Subject: Re: kvm_read() vs ioctl performance X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Mar 2008 12:58:18 -0000 --- Julian Elischer wrote: > Barney Cordoba wrote: > > --- Julian Elischer wrote: > > > >> Barney Cordoba wrote: > >>> --- Julian Elischer wrote: > >>> > >>>> Barney Cordoba wrote: > >>>>> I have an app which reads stats from the > kernel > >>>>> periodically, and there can be a lot of > >>>> iterations, > >>>>> sometimes 20,000 or more. I'm thinking of > >>>> converting > >>>>> from an ioctl method to kvm_read(). KVM is > >>>> certainly > >>>>> simpler, but its not clear what overhead is > >>>> involved, > >>>>> since kvm_read() likely has to call the kernel > >>>> also. > >>>>> Does anyone have a handle on the difference in > >>>>> overhead, assuming that the ioctl call is to a > >>>> module > >>>>> which does nothing more than copy the data and > >>>> return? > >>>> > >>>> tried a shared memory page? > >>> No, but I built a test and kvm_read is 70 times > >>> faster, in > >>> case anyone is interested. > >> cool.. > >> the only downside is that we are trying to get > away > >> from kvm direct > >> access. (which is why a shared page might give > the > >> same result with a > >> stable API which is not libkvm... BTW on an SMP > >> machine you have > >> no way to ensure that your stats are coherent if > you > >> use libkvm. > > > > The app is portable, and I'd prefer not to have > > different methods for LINUX and FreeBSD. When you > say > > "coherent", what exactly do you mean? > > there is no synchronisation between your app and the > device. > I dont know what sized structure you are reading but > how do you know > that the device isn't half way through writing it? > > A mmapped page would be more portable, > for example done in the way that a video frame > buffer is done. > All systems support that sort of semantic the same. > Then you can use memory semaphores to make sure that > the stuff is > consistent, because you can write back. Is this a page of memory, or some other "page" concept? As I mentioned, there are n structures, and there could be 20K or more of them. The structures are 72 bytes. Its also read-only, and not dreadfully important that the stats are exactly tied to a precise moment in time. Its similar to netstat. The stats are continuously being written. When we need to sync them, we can issue a "snapshot" ioctl that locks and copies the current stats to a static variable and then the variables are read. Barney ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs