public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: dhowells@redhat.com, Ingo Molnar <mingo@elte.hu>,
	Oleg Nesterov <oleg@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	serue@us.ibm.com, viro@zeniv.linux.org.uk,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Nick Piggin <nickpiggin@yahoo.com.au>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] It may not be assumed that wake_up(), finish_wait() and co. imply a memory barrier
Date: Thu, 23 Apr 2009 21:35:45 +0100	[thread overview]
Message-ID: <22170.1240518945@redhat.com> (raw)
In-Reply-To: <alpine.LFD.2.00.0904231004120.3101@localhost.localdomain>

Linus Torvalds <torvalds@linux-foundation.org> wrote:

> 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.

Well, Ingo's point is it could be left up to the caller of wake_up() to supply
the barrier:

	*my_variable = 1234;
	smp_wmb();
	wake_up(&my_queue);

or:

	spin_lock(&my_lock);
	*my_variable = 1234;
	wake_up(&my_queue);
	spin_unlock(&my_lock);

on the condition that the sleeper also gets the lock.

Also, he points out that wake_up() and co. may not insert useful memory barrier
at all, for three reasons:

 (1) If there's no-one to wake up, then certain wake functions will return
     immediately.

 (2) If there's no-one to wake up, then other wake functions will only impose
     LOCK and UNLOCK barriers.

 (3) If someone supplies a special awakener instead of default_wake_function(),
     then they can bypass try_to_wake_up() and whatever barrier that implies.

     Though as far as I can see, if you want to wake someone up, you *have* to
     go through try_to_wake_up().

What I'd like to say is that wake_up() and friends _will_ interpose at least a
write barrier _if_ they wake anything up (which is more or less what you said
above).  If they don't wake anything up, then there's no need for a memory
barrier between the assignment to my_variable and the non-existent alterations
to the state of the task not being awoken.

David

  reply	other threads:[~2009-04-23 20:38 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-13 18:17 [PATCH] slow_work_thread() should do the exclusive wait Oleg Nesterov
2009-04-13 19:03 ` Trond Myklebust
2009-04-13 19:14   ` Oleg Nesterov
2009-04-13 21:40   ` David Howells
2009-04-13 21:48     ` Oleg Nesterov
2009-04-13 21:57       ` Trond Myklebust
2009-04-13 22:24         ` Oleg Nesterov
2009-04-15 23:27           ` Andrew Morton
2009-04-16  9:10             ` David Howells
2009-04-16 14:33               ` Oleg Nesterov
2009-04-22 13:37                 ` [PATCH] Document that wake_up(), complete() and co. imply a full memory barrier David Howells
2009-04-22 13:51                   ` Ingo Molnar
2009-04-22 14:39                     ` Oleg Nesterov
2009-04-22 14:56                       ` Ingo Molnar
2009-04-22 15:07                         ` Oleg Nesterov
2009-04-22 15:12                     ` David Howells
2009-04-22 15:19                       ` Ingo Molnar
2009-04-22 16:23                       ` David Howells
2009-04-22 17:57                         ` Ingo Molnar
2009-04-23 16:32                           ` [PATCH] It may not be assumed that wake_up(), finish_wait() and co. imply a " David Howells
2009-04-23 16:55                             ` Oleg Nesterov
2009-04-24 11:46                               ` David Howells
2009-04-24 15:08                                 ` Paul E. McKenney
2009-04-24 17:08                                   ` Oleg Nesterov
2009-04-24 17:43                                     ` Paul E. McKenney
2009-04-24 17:48                                   ` David Howells
2009-04-24 18:06                                     ` Paul E. McKenney
2009-04-28 10:18                                       ` David Howells
2009-04-28 13:00                                         ` Paul E. McKenney
2009-04-24 17:28                                 ` Oleg Nesterov
2009-04-24 17:53                                   ` David Howells
2009-04-24 18:30                                     ` Oleg Nesterov
2009-04-23 17:07                             ` Linus Torvalds
2009-04-23 20:35                               ` David Howells [this message]
2009-04-23 21:12                                 ` Linus Torvalds
2009-04-23 21:24                                   ` Ingo Molnar
2009-04-23 16:36                           ` [PATCH] Document that wake_up(), complete() and co. imply a full " Oleg Nesterov
2009-04-23 20:37                             ` David Howells
2009-04-23 16:00             ` [PATCH] slow_work_thread() should do the exclusive wait David Howells
2009-04-23 16:18               ` Oleg Nesterov
2009-04-13 21:35 ` David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22170.1240518945@redhat.com \
    --to=dhowells@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nickpiggin@yahoo.com.au \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=serue@us.ibm.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox