lkml.org 
[lkml]   [2010]   [Jun]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/4] input: Introduce buflock, a one-to-many circular buffer mechanism
On Thu,  3 Jun 2010 10:00:59 +0200 "Henrik Rydberg" <rydberg@euromail.se> wrote:

> In spite of the many lock patterns and fifo helpers in the kernel, the
> case of a single writer feeding many readers via a circular buffer
> seems to be uncovered. This patch adds the buflock, a minimalistic
> interface implementing SMP-safe locking for such a buffer. Under
> normal operation, given adequate buffer size, the operation is
> lock-less. The template is given the name buflock to emphasize that
> the locking depends on the buffer read/write clashes.
>

Seems that reviewers have already covered most of the oddities.

> +/*
> + * Write to buffer without locking
> + *
> + * bw - the buflock_writer keeping track of the write position
> + * buf - the buffer to write to (array of item type)
> + * size - the size of the circular buffer (must be a power of two)
> + * item - the item to write
> + *
> + * There is no locking involved during write, so this method is
> + * suitable to use in interrupt context.
> + */

And if the buffer fills up, it silently overwrites old data?

There are many options in this sort of thing. Certain choices have
been made here and they should be spelled out exhaustively please.

> +#define buflock_write(bw, buf, size, item) \
> + do { \
> + bw.next_head = (bw.head + 1) & ((size) - 1); \
> + smp_wmb(); \
> + buf[bw.head] = item; \
> + smp_wmb(); \
> + bw.head = bw.next_head; \
> + smp_wmb(); \
> + } while (0)

I don't think there's a reason why these all had to be implemented as
bloaty, un-typesafe macros? Especially as buggy ones which reference
their arguments multiple times!

Code it in C if possible, please.


\
 
 \ /
  Last update: 2010-06-05 03:39    [W:0.095 / U:0.288 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site