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

From: David Howells
Date: Thu Jan 07 2010 - 06:06:15 EST


Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxx> 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
--
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/