Re: [PATCH] trace: Check for waiting readers before calling wakeup()

From: Linus Torvalds
Date: Wed May 04 2011 - 23:54:30 EST


On Wed, May 4, 2011 at 2:26 PM, Frederic Weisbecker <fweisbec@xxxxxxxxx> wrote:
> On Wed, May 04, 2011 at 02:21:28PM -0700, Vaibhav Nagarnaik wrote:
>> Steven, Frederic
>>
>> Does this patch look ok?
>>
>> Vaibhav Nagarnaik
>>
>
> No problem for me. I'll let Steve give the last word.

Almost every time somebody does this optimization, there's a race.

The thing is, because waitqueue_active() implies no barriers, if there
is somebody adding itself to the waitqueue just at the same time as
somebody is waking things up, the waiter may lose wakeup events -
there is no memory barriers to guarantee that the waker will see
either the waiter, or the waiter will see the event that it waited
for.

I dunno. It's sometimes safe, but it's equally often not safe unless
there is some other locking around the thing. So I'd be a bit nervous.
The tracer people would need to do some serious thinking about it.

Linus
--
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/