lkml.org 
[lkml]   [2014]   [Apr]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: question on read_barrier_depends
On Wed, 16 Apr 2014, Oliver Neukum wrote:

> Hi,
>
> I am looking at memory ordering and a question hit me.
> I was looking at the kfifo code. kfifo_put() has a barrier:
>
> )[__kfifo->in & __tmp->kfifo.mask] = \
> (typeof(*__tmp->type))__val; \
> smp_wmb(); \
> __kfifo->in++; \
>
> Looking at kfifo_get()
>
> __ret = !kfifo_is_empty(__tmp); \
> if (__ret) { \
> *(typeof(__tmp->type))__val = \
> (__is_kfifo_ptr(__tmp) ? \
>
> A thought struck me. There is no corresponding barrier. I cannot
> help myself, but I think there needs to be a smp_read_barrier_depends()
> between reading kfifo->in (in kfifo_is empty) and reading val.
> What do you think?

I think you are right.

In addition, the following code in kfifo_get() does this:

*(typeof(__tmp->type))__val = \
(__is_kfifo_ptr(__tmp) ? \
((typeof(__tmp->type))__kfifo->data) : \
(__tmp->buf) \
)[__kfifo->out & __tmp->kfifo.mask]; \
smp_wmb(); \
__kfifo->out++; \

It looks like the smp_wmb() should really be smp_mb(), because it
separates the _read_ for val from the _write_ of kfifo->out.

Alan Stern



\
 
 \ /
  Last update: 2014-04-16 18:01    [W:0.091 / U:1.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site