From: Ingo Molnar <mingo@elte.hu>
To: Oleg Nesterov <oleg@redhat.com>
Cc: David Howells <dhowells@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Trond.Myklebust@netapp.com, serue@us.ibm.com, steved@redhat.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] Document that wake_up(), complete() and co. imply a full memory barrier
Date: Wed, 22 Apr 2009 16:56:58 +0200 [thread overview]
Message-ID: <20090422145658.GA15088@elte.hu> (raw)
In-Reply-To: <20090422143930.GA1212@redhat.com>
* Oleg Nesterov <oleg@redhat.com> wrote:
> On 04/22, Ingo Molnar wrote:
> >
> > * David Howells <dhowells@redhat.com> wrote:
> >
> > > Oleg Nesterov <oleg@redhat.com> wrote:
> > >
> > > > > That's an interesting question. Should wake_up() imply a barrier of any
> > > > > sort, I wonder. Well, __wake_up() does impose a barrier as it uses a
> > > > > spinlock, but I wonder if that's sufficient.
> > > >
> > > > wake_up() does imply the barrier. Note the smp_wmb() in try_to_wake_up().
> > > > And in fact this wmb() implies mb(), because spin_lock() itself is STORE,
> > > > and the futher LOADs can't leak up before spin_lock().
> > > >
> > > > But afaics, this doesn't matter? prepare_to_wait() sets
> > > > task->state under wait_queue_head_t->lock and wake_up() takes
> > > > this look too, so we can't miss the event.
> > > >
> > > > Or I completely misunderstood the issue...
> > >
> > > The problem is not what wake_up() and co. do, it's what you are
> > > allowed to assume that they do.
> > >
> > > However, I think you're right, and that we can assume they imply a
> > > full memory barrier. To this end, I've attached a patch to
> > > document this.
> > >
> > > David
> > > ---
> > > From: David Howells <dhowells@redhat.com>
> > > Subject: [PATCH] Document that wake_up(), complete() and co. imply a full memory barrier
> > >
> > > Add to the memory barriers document to note that wake_up(), complete() and
> > > co. all imply a full memory barrier.
> >
> > No. They dont generally imply a full memory barrier versus any
> > arbitrary prior (or following) memory access.
> >
> > try_to_wake_up() has an smp_wmb() so it is a write memory barrier
> > (but not necessarily a read memory barrier). Otherwise there are
> > spinlocks there but spinlocks are not explicit 'full memory
> > barriers'.
>
> Yes. But please look at the changelog in
>
> "Add memory barrier semantics to wake_up() & co"
> 04e2f1741d235ba599037734878d72e57cb302b5
yes - but still that commit is only wrt. the ->state check.
> However, I must admit, I don't understand how to document the
> semantics correctly. This wmb() before spin_lock() ensures we
> don't read task->state before previous STOREs. This is what we
> care about, and this is what I meant when I said "this wmb()
> implies mb()".
>
> So, I think that try_to_wake_up() implies that the LOADS after it
> can't be reordered with STOREs before it (and wmb() of course).
Note that the patch David sent says "full memory barrier", not "full
memory barrier wrt. task->state":
+ (*) wake_up(), try_to_wake_up() and co. imply a full memory barrier.
+
+ (*) complete() and co. imply a full memory barrier.
These statements are not true in that form, as this code does not
imply a full memory barrier. It does imply one on task->state
_alone_ (and a couple of other wq-internal variables it happens to
read for sure).
But even that one isnt entirely true in the two sub-cases i noted:
the !wq case (which can happen in object state teardown) and the
special ->func handler (which can happen in custom wakeup code a'la
eventpoll).
So adding a comment that says "this is a full memory barrier" is
simply not true to that extent, and is easily misunderstood. Adding
"this is a fully memory barrier for task->state dependent data flow"
would be more correct. (with a 'as long as wq is not NULL, and as
long as the code using this isnt overriding ->func)
Agreed?
Ingo
next prev parent reply other threads:[~2009-04-22 14:57 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 [this message]
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
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=20090422145658.GA15088@elte.hu \
--to=mingo@elte.hu \
--cc=Trond.Myklebust@netapp.com \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nickpiggin@yahoo.com.au \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=serue@us.ibm.com \
--cc=steved@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.