Re: [PATCH] It may not be assumed that wake_up(), finish_wait() and co. imply a memory barrier

Linus Torvalds
2009-04-23T17:13:23Z

On Thu, 23 Apr 2009, David Howells wrote:
>
> I was wondering if wake_up() and friends should in fact imply smp_wmb(), but I
> guess that they're often used in conjunction with spinlocks - and in such a
> situation a barrier is unnecessary overhead.

I think we _have_ to imply a smp_wmb() in the wakup semantics, because
otherwise sleepers can't do anything sane (no amount of barriers on the
sleeping side will help). IOW, there basically has to be an implied write
barrier between the thing that causes an event to become true, and the
thing that turns 'task->state' back to RUNNING.

This is similar to the issue of doing cross-CPU IPI's: sending an IPI
_must_ imply a memory barrier with the IPI mechanism, because otherwise
the receiver could never do anything sane.

Linus