On Wed, Jan 16, 2019 at 5:24 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote: > > On Mon, Jan 14, 2019 at 11:30:12AM -0800, Suren Baghdasaryan wrote: > > For memory ordering (which Johannes also pointed out) the critical point is: > > > > times[cpu] += delta | if g->polling: > > smp_wmb() | g->polling = polling = 0 > > cmpxchg(g->polling, 0, 1) | smp_rmb() > > | delta = times[*] (through goto SLOWPATH) > > > > So that hotpath writes to times[] then g->polling and slowpath reads > > g->polling then times[]. cmpxchg() implies a full barrier, so we can > > drop smp_wmb(). Something like this: > > > > times[cpu] += delta | if g->polling: > > cmpxchg(g->polling, 0, 1) | g->polling = polling = 0 > > | smp_rmb() > > | delta = times[*] (through goto SLOWPATH) > > > > Would that address your concern about ordering? > > cmpxchg() implies smp_mb() before and after, so the smp_wmb() on the > left column is superfluous. Should I keep it in the comments to make it obvious and add a note about implicit barriers being the reason we don't call smp_mb() in the code explicitly? > The right hand column is actively wrong; because that reads like it > wants to order a store (g->polling = 0) and a load (d = times[]), and > therefore requires smp_mb(). Just to clarify, smp_mb() is needed only in the comments or do you want an explicit smp_mb() in the code as well? As Johannes noted get_recent_times() which is part of "delta = times[*]" operation involves read_seqcount section that should act as implicit memory barrier in the slowpath. > Also, you probably want to use atomic_t for g->polling, because we > (sadly) have architectures where regular stores and atomic ops don't > work 'right'. Oh, I see. Will do. Thanks! > -- > You received this message because you are subscribed to the Google Groups "kernel-team" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@xxxxxxxxxxx. >