Re: [RFC PATCH v2] membarrier: expedited private command
From: Peter Zijlstra
Date: Tue Aug 01 2017 - 06:46:30 EST
On Tue, Aug 01, 2017 at 01:32:43PM +0300, Avi Kivity wrote:
> I hate to propose a way to make this more complicated, but this could be
> fixed by a process first declaring its intent to use expedited process-wide
> membarrier; if it does, then every context switch updates a process-wide
> cpumask indicating which cpus are currently running threads of that process:
>
> if (prev->mm != next->mm)
> if (prev->mm->running_cpumask)
> cpumask_clear(...);
> else if (next->mm->running_cpumask)
> cpumask_set(...);
>
> now only processes that want expedited process-wide membarrier pay for it
> (in other than some predictable branches). You can even have threads opt-in,
> so unrelated threads that don't participate in the party don't cause those
> bits to be set.
Either that or conditionally put in a smp_mb in switch_mm() for that
process. But yes, once we advertise intent (either explicit or implicit
on first use), there's various things that can be done.