[lkml]   [2022]   [Dec]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectRe: [RFC 2/2] srcu: Remove memory barrier "E" as it is not required
On Sun, Dec 18, 2022 at 07:13:09PM +0000, Joel Fernandes (Google) wrote:
> During a flip, we have a full memory barrier before idx is incremented.
> The effect of this seems to be to guarantee that, if a READER sees srcu_idx
> updates (srcu_flip), then prior scans would not see its updates to counters on
> that index.
> That does not matter because of the following reason: If a prior scan did see
> counter updates on the new index, that means the prior scan would would wait
> for the reader when it probably did not need to.

I'm confused, isn't it actually what we want to prevent from?
The point of the barrier here is to make sure that the inactive index that
we just scanned is guaranteed to remain seen as inactive during the whole scan
(minus the possible twice residual increments from a given task that we debated
on Paul's patch, but we want the guarantee that the inactive index won't be
incremented thrice by a given task or any further while we are scanning it).

If some readers see the new index and increments the lock and we see that while
we are scanning it, there is a risk that the GP is going to be delayed indefinetly.

> @@ -982,14 +982,6 @@ static bool try_check_zero(struct srcu_struct *ssp, int idx, int trycount)
> */
> static void srcu_flip(struct srcu_struct *ssp)
> {
> - /*
> - * Ensure that if a given reader sees the new value of ->srcu_idx, this
> - * updater's earlier scans cannot have seen that reader's increments
> - * (which is OK, because this grace period need not wait on that
> - * reader).
> - */
> - smp_mb(); /* E */ /* Pairs with B and C. */

That said, I've been starring at this very barrier for the whole day, and I'm
wondering what does it match exactly on the other end?

------- ------
idx = ssp->srcu_idx; idx = srcu_idx;
READ srcu_unlock_count[srcu_idx ^ 1] srcu_lock_count[idx]++
smp_mb(); smp_mb();
READ srcu_lock_count[srcu_idx ^ 1] srcu_unlock_count[old_idx]++

For a true match, I would expect a barrier between srcu_idx read and
srcu_lock_count write. I'm not used to ordering writes after reads.
So what is the pattern here? I would expect something like the below
but that doesn't match the above:

C rwrw


P0(int *X, int *Y)
int x;
x = READ_ONCE(*X);
P1(int *X, int *Y)
int y;

y = READ_ONCE(*Y);
exists (0:x=1 /\ 1:y=1)

> -
> WRITE_ONCE(ssp->srcu_idx, ssp->srcu_idx + 1);
> /*
> --

 \ /
  Last update: 2022-12-18 22:43    [W:0.129 / U:0.428 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site