tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: zero runtime when negative
On Tue, Jun 26, 2012 at 10:28:52AM -0700, Matt Thomas wrote:
>
> On Jun 26, 2012, at 9:50 AM, Dennis Ferguson wrote:
>
> > The latter is a problem since many machines have no such counter
> > in hardware, and for those that do the unlikely-to-roll hardware counter is
> > often 64 bits wide and is a problem to sample with a 32 bit instruction set.
>
> Really? This hasn't been a problem on PowerPC with its 64-bit timebase.
>
> the algorithm is simple
>
> read upper
> read lower
> read upper again
> compare upper values, if they differ do the again.
That only works is the update is atomic.
If the value is a counter, just assume the low value is zero when
the upper value changes.
Linux has a 'neat' lock free (only needs write-write memory barriers)
for updating 64bit stats on a 32 bit system - provided there is only
one writer. All the work is done in the read path.
For stats that have to be written in two words, I think you could
use a scheme where the middle 32bite get written to a 3rd location.
The reader reads all three values until they are consistent.
(Assumes only one writer.)
David
--
David Laight: david%l8s.co.uk@localhost
Home |
Main Index |
Thread Index |
Old Index