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

David Howells
2010-01-07T11:06:11Z

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.

(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