public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Confused by smp_read_barrier_depends() in rxrpc_rotate_tx_window()
@ 2008-05-30 12:45 Paul E. McKenney
  2008-06-03 10:19 ` David Howells
  0 siblings, 1 reply; 2+ messages in thread
From: Paul E. McKenney @ 2008-05-30 12:45 UTC (permalink / raw)
  To: dhowells; +Cc: linux-kernel

Hello, Dave!

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
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?

Help?

						Thanx, Paul

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Confused by smp_read_barrier_depends() in rxrpc_rotate_tx_window()
  2008-05-30 12:45 Confused by smp_read_barrier_depends() in rxrpc_rotate_tx_window() Paul E. McKenney
@ 2008-06-03 10:19 ` David Howells
  0 siblings, 0 replies; 2+ messages in thread
From: David Howells @ 2008-06-03 10:19 UTC (permalink / raw)
  To: paulmck; +Cc: dhowells, linux-kernel

Paul E. McKenney <paulmck@linux.vnet.ibm.com> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-06-03 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-30 12:45 Confused by smp_read_barrier_depends() in rxrpc_rotate_tx_window() Paul E. McKenney
2008-06-03 10:19 ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox