Fast gettimeofday(2) and clock_gettime(2)

Konstantin Belousov kostikbel at gmail.com
Thu Jun 7 17:28:51 UTC 2012


On Thu, Jun 07, 2012 at 08:50:55AM -0400, John Baldwin wrote:
> On Wednesday, June 06, 2012 4:59:38 pm Konstantin Belousov wrote:
> > On Wed, Jun 06, 2012 at 02:23:53PM -0400, John Baldwin wrote:
> > > On Wednesday, June 06, 2012 12:51:15 pm Konstantin Belousov wrote:
> > > > A positive result from the recent flame-bait on arch@ is the working
> > > > implementation of the fast gettimeofday(2) and clock_gettime(2). The
> > > > speedup I see is around 6-7x on the 2600K. I think the speedup could
> > > > be even bigger on the previous generation of CPUs, where lock
> > > > operations and syscall entry are costlier. A sample test runs of
> > > > tools/tools/syscall_timing are presented at the end of message.
> > > 
> > > In general this looks good but I see a few nits / races:
> > > 
> > > 1) You don't follow the model of clearing tk_current to 0 while you
> > >    are updating the structure that the in-kernel timecounter code
> > >    uses.  This also means you have to avoid using a tk_current of 0
> > >    and that userland has to keep spinning as long as tk_current is 0.
> > >    Without this I believe userland can read a partially updated
> > >    structure.
> > I changed the code to be much more similar to the kern_tc.c. I (re)added
> > the generation field, which is set to 0 upon kernel touching timehands.
> 
> Thank you.  BTW, I think we should use atomic_load_acq_int() on both accesses 
> to th_gen (and the in-kernel binuptime should do the same).  I realize this
> requires using rmb before the while condition in userland since we can't
> use atomic_load_acq_int() here.  I think it should also use 
> atomic_store_rel_int() for both stores to th_gen during the tc_windup()
> callback.
This is done. On the other hand, I removed a store_rel from updating
tk_current, since it is after enabling store to th_gen, and the order
there does not matter.

I also did some restructuring of the userspace, removing layers that
Bruce did not liked. Now top-level functions directly call binuptime().
I also shortened the preliminary operations by caching timekeep pointer.
Its double-initialization is safe.

Latest version is at
http://people.freebsd.org/~kib/misc/moronix.4.patch

I probably move all shared page helpers to separate file from kern_exec.c,
but this will happen after moronix is committed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20120607/4b030cc5/attachment.pgp


More information about the freebsd-arch mailing list