Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Jun 2013 07:22:00 -0700
From:      mdf@FreeBSD.org
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        Konstantin Belousov <kostikbel@gmail.com>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, Gleb Smirnoff <glebius@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>
Subject:   Re: svn commit: r252032 - head/sys/amd64/include
Message-ID:  <CAMBSHm94eV94EQs-NR_vM8QVTDdBhXPdG254coTftX5YmAJEVw@mail.gmail.com>
In-Reply-To: <20130624211428.O2235@besplex.bde.org>
References:  <20130621065839.J916@besplex.bde.org> <20130621081116.E1151@besplex.bde.org> <20130621090207.F1318@besplex.bde.org> <20130621064901.GS1214@FreeBSD.org> <20130621184140.G848@besplex.bde.org> <20130621135427.GA1214@FreeBSD.org> <20130622110352.J2033@besplex.bde.org> <20130622124832.S2347@besplex.bde.org> <20130622174921.I3112@besplex.bde.org> <20130623073343.GY91021@kib.kiev.ua> <20130624081056.GD1214@FreeBSD.org> <20130624211428.O2235@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
[snipping everything about counter64, atomic ops, cycles, etc.]

I wonder if the idea explained in this paper:

http://static.usenix.org/event/usenix03/tech/freenix03/full_papers/mcgarry/mcgarry_html/

Which seems to be used in FreeBSD for some ARM atomics:

http://svnweb.freebsd.org/base/head/sys/arm/include/atomic.h?view=annotate
, look for ARM_RAS_START

would be more efficient.

To summarize: one marks a section of code such that if a thread is
interrupted during the code it restarts at the beginning instead of where
it was interrupted.  This has been used to implement atomic increment on
some hardware without the necessary instructions.  Here it could be used to
implement atomic increment on the per-cpu counter without the overhead of
an atomic instruction.

It's multiple stores to mark the section of code doing the increment, but
they're all per-cpu or per thread.  That may be cheaper than an atomic
increment, at least on 32-bit platforms that are doing an atomic 64-bit
increment.

I haven't benchmarked this (ENOTIME, plus I'm on vacation right now), but
using restartable sections requires three stores (add an item to a linked
list, 64-bit increment for the counter, remove an item from a linked list).
 Some of the penalty is payed in the context switch code, which has to
check if the instruction pointer is in one of these critical sections.  I
haven't checked to see if this code is enabled on all architectures or just
ARM.  But if context switches are less frequent than counter increments in
the networking code, it's still a win for most uses.

Thanks,
matthew



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAMBSHm94eV94EQs-NR_vM8QVTDdBhXPdG254coTftX5YmAJEVw>