Re: Confused by smp_read_barrier_depends() in rxrpc_rotate_tx_window()

From: David Howells
Date: Tue Jun 03 2008 - 06:22:36 EST


Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx> wrote:

> I confess to being confused by the smp_read_barrier_depends() in
> rxrpc_rotate_tx_window(). It looks like it is ordering the prior
> fetch of tail from call->acks_tail with the subsequent use of

No. call->acks_head vs [tail].

> tail as an index into the call->acks_window[] array, but then the
> code does an assignment to call->acks_tail a few lines later.
>
> If we hold a lock protecting call->acks_tail, why do we need the
> smp_read_barrier_depends()? If we don't hold such a lock, why
> is the assignment to call->acks_tail safe?

We don't hold a lock protecting call->acks_tail. The head insertion and the
tail extraction are only protected by memory barriers.

int tail = call->acks_tail, old_tail;
int win = CIRC_CNT(call->acks_head, tail, call->acks_winsz);
...
smp_read_barrier_depends();
_skb = call->acks_window[tail] & ~1;

In this bit of code, we must protect against seeing the item at '[tail]' set
after 'call->acks_head' itself is updated, hence why we need a barrier here.
Possibly it should be smp_rmb() rather than smp_read_barrier_depends().

_skb = call->acks_window[tail] & ~1;
...
old_tail = tail;
tail = (tail + 1) & (call->acks_winsz - 1);
call->acks_tail = tail;

I believe this does not require a barrier between reading '[tail]' and updating
'tail' because there's no way we can update tail without first reading
'[tail]'.

David
--
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/