Skip to contentSkip to conversation

Confused by smp_read_barrier_depends() in rxrpc_rotate_tx_window()

DISCUSSION Paul E. McKenney 2 participants 2 messages May 30, 2008 – Jun 3, 2008

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 3 lines · Paul E. McKenney

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].

Quoted 6 lines

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