Re: [PATCH 1/3] sched, timer: Remove usages of ACCESS_ONCE in the scheduler

From: Jason Low
Date: Wed Apr 15 2015 - 14:49:34 EST


On Wed, 2015-04-15 at 09:46 +0200, Ingo Molnar wrote:
> * Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> > You are correct. Now I'm thinking that the WRITE_ONCE() is not needed,
> > and just a:
> >
> > p->mm->numa_scan_seq = READ_ONCE(p->numa_scan_seq) + 1;
> >
> > Can be done. But I'm still trying to wrap my head around why this is
> > needed here. Comments would have been really helpful. We should make
> > all READ_ONCE() WRITE_ONCE and obsolete ACCESS_ONCE() have mandatory
> > comments just like we do with memory barriers.
>
> So the original ACCESS_ONCE() barriers were misguided to begin with: I
> think they tried to handle races with the scheduler balancing softirq
> and tried to avoid having to use atomics for the sequence counter
> (which would be overkill), but things like ACCESS_ONCE(x)++ never
> guaranteed atomicity (or even coherency) of the update.
>
> But since in reality this is only statistical sampling code, all these
> compiler barriers can be removed I think. Peter, Mel, Rik, do you
> agree?

So I'll keep the READ_ONCE nested inside WRITE_ONCE for the purpose of
this patch since this patch is a conversion from ACCESS_ONCE, but yes,
if the original purpose of ACCESS_ONCE was to do an atomic increment,
then the ACCESS_ONCE doesn't help with that.

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