lkml.org 
[lkml]   [2009]   [May]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 3/3] ring-buffer: make cpu buffer entries counter atomic

On Fri, 1 May 2009, Ingo Molnar wrote:
> >
> > Ah, maybe there's confusion in my explanation. When I talk about
> > writers and readers, I'm talking about those writers into the ring
> > buffer and readers from the ring buffer. But both writers and
> > readers write to the entries counter. Readers subtract and writers
> > add. But writers can also subtract on overruns.
>
> a solution for that would be to split it into two counts - for both
> sides. Or to eliminate it if possible. We _really_ need to make the
> ring-buffer _much_ cheaper than it is today.

I was thinking the same thing :-)

Actually we would have three counters. All incremental.

entries
overruns
read

The writer when adding an entry would increment entries

The writer when overwriting will increment overruns

The reader would increment read.

We could even make it 64 bits (or more) on all archs. Heck, make it two
longs (128 bits for 64 bit archs). Since we only need to worry about
interrupts, we only increment the second counter if we wrapped the first.
I doubt a single interrupt (or many) could wrap the first counter. If it
could, we have more to worry about than counters.

Thus the number of entries in the buffer would be:

(entries - overruns) - read

-- Steve



\
 
 \ /
  Last update: 2009-05-01 19:59    [W:0.063 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site