Subject: Re: kernel->userland r/o page mapping
To: Matthew Mondor <mm_lists@pulsar-zone.net>
From: Simon Burge <simonb@NetBSD.org>
List: tech-kern
Date: 03/09/2007 13:15:47
Matthew Mondor wrote:
Ignoring everything else...
> $ time ./clocktest1 1000000
> 8.35s real 0.52s user 7.81s system
[ gettimeofday ]
> $ time ./clocktest2 1000000
> 8.50s real 0.52s user 7.96s system
[ clock_gettime ]
> $ time ./clocktest3 1000000
> 3.40s real 0.29s user 3.09s system
[ kern.hardclock_ticks sysctl ]
Note that the kern.hardclock_ticks sysctl simply reads a kernel variable
and returns it without doing any extra work. That variable is updated
once per clock tick (obviously!). This will have a HZ granularity
(0.01 second for i386 by default?).
gettimeofday() (and I assume clock_gettime() from how long it takes)
will call microtime() or some variation thereof and actually give you
as high as resolution as possible of the current time, which will be
sub-microsecond on modern i386.
So no surprise that the sysctl program is faster...
Cheers,
Simon.