Re: [RFC PATCH] introduce sys_membarrier(): process-wide memory barrier

Mathieu Desnoyers
2010-01-07T15:15:27Z

* David Howells (dhowells@redhat.com) wrote:
> Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> wrote:
>
> > The current implementation simply executes a memory barrier in an IPI
> > handler on each active cpu. Going through the hassle of taking run queue
> > locks and checking if the thread running on each online CPU belongs to
> > the current thread seems more heavyweight than the cost of the IPI
> > itself (not measured though).
>
> There's another way to do this:
>
> (1) For each threads you want to execute a memory barrier, mark in its
> task_struct that you want it to do a memory barrier and set
> TIF_NOTIFY_RESUME.
>
> (2) Interrupt all CPUs. The interrupt handler doesn't have to do anything.

AFAIK, the smp_mb() is not very costly compared to the IPI. So as your
proposal implies sending an IPI to the remote threads anyway, I don't
see how adding thread flags and extra tests in return to userland paths
will help us... it will just add extra tests and branches doing exactly
nothing.

Or am I missing your point entirely ?

Thanks,

Mathieu

>
> (3) When any of the threads marked in (1) gain CPU time, do_notify_resume()
> will be executed, and the do-memory-barrier flag can be tested and if it
> was set, the flag can be cleared and a memory barrier can be
> interpolated.
>
> The current thread will also pass through stage (3) on its way out, if it's
> marked in stage (1).
>
> David

--
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68