From owner-freebsd-hackers Sun Nov 16 13:12:49 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id NAA15525 for hackers-outgoing; Sun, 16 Nov 1997 13:12:49 -0800 (PST) (envelope-from owner-freebsd-hackers) Received: from anlsun.ebr.anlw.anl.gov (anlsun.ebr.anlw.anl.gov [141.221.1.2]) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id NAA15515 for ; Sun, 16 Nov 1997 13:12:45 -0800 (PST) (envelope-from cmott@srv.net) Received: from darkstar.home (dialin1.anlw.anl.gov [141.221.254.101]) by anlsun.ebr.anlw.anl.gov (8.6.11/8.6.11) with SMTP id OAA17550; Sun, 16 Nov 1997 14:12:39 -0700 Date: Sun, 16 Nov 1997 14:12:07 -0700 (MST) From: Charles Mott X-Sender: cmott@darkstar.home To: Joerg Wunsch cc: hackers@FreeBSD.ORG Subject: Re: Reading kernel memory In-Reply-To: <19971116205014.XN38067@uriah.heep.sax.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk On Sun, 16 Nov 1997, J Wunsch wrote: > As Charles Mott wrote: > > > So if one really wants to map a kernel variable to > > user space, I am guessing something more sophisticated > > than the kvm routines are needed. > > Not sure, but perhaps it's possible to mmap() /dev/kmem? Yes, mmap() to /dev/kmem works (I tested it), and so reading the kernel time variable can be done very quickly. I hadn't figured this out yet when I made the earlier posting. As mentioned below, though, the granularity of this measurement (usually 10 msec) is not nearly as good as gettimeofday() because of microtime(). > > > Wandering through the kernel source code, I have also > > discovered that gettimeofday() actaully invokes a > > microtime() call which actually tries to determine the > > time by reading a timer and using it to refine the > > kernel time variable. > > After ktracing X11 applications, and seeing how often gettimeofday() > is actually called, i've been rather impressed that this entire > process is still reasonably faster nevertheless. The featuere is very > useful for fine-granularity traces, be it ktrace or tcpdump (or simply > the ping response time). The high accuracy ping time is one thing I've always liked about FreeBSD over Linux. Does anyone know what the response time for gettimeofday() is on a reasonably modern Pentium? It is about 60 microseconds on my ancient 386. Although I originally though a non-privileged /dev/timeofday (Tony Newfield's idea) combined with mmap() might be a good way to get quick timestamps, I tend to think the existing system is good enough, especially since processors are getting faster. Charles Mott