Re: [PATCH] Document Linux's circular buffering capabilities

From: Stefan Richter
Date: Sat Mar 13 2010 - 04:26:56 EST


David Howells wrote:
> Stefan Richter <stefanr@xxxxxxxxxxxxxxxxx> wrote:
>> "...do this" could be misunderstood as "use a modulus instruction",
...
> How about:
>
> Calculation of the occupancy or the remaining capacity of an
> arbitrarily sized circular buffer would normally be a slow operation,
> requiring the use of a modulus (divide) instruction. However, if the
> buffer is of a power-of-2 size,
[...]

Yep.

>> I don't understand why ACCESS_ONCE is needed here. The CIRC_SPACE and
>> CIRC_CNT macros do not look at head and tail more than once.
>
> In this example they don't, but say someone wants to read several elements
> from the buffer, they might end up accessing their copy of head several times.

Would you agree to add a quick note that these examples are simple
enough to not strictly require ACCESS_ONCE but are meant to show what
more general code would have to do? Else a reader might be left puzzled
why he can't see in the example code the circumstances which require
ACCESS_ONCE and may remain unsure about where to use it in his own works...

(BTW, good that I came across your documentation posting. This twist
with possibly multiple loads was not apparent to me too. I am going to
have to have another look at some driver code with this in mind...)
--
Stefan Richter
-=====-==-=- --== -==-=
http://arcgraph.de/sr/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/