From: Boqun Feng <boqun.feng@gmail.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Michal Hocko <mhocko@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
David Howells <dhowells@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Jonathan Corbet <corbet@lwn.net>
Subject: Re: wake_up_process implied memory barrier clarification
Date: Mon, 31 Aug 2015 08:37:20 +0800 [thread overview]
Message-ID: <20150831003719.GC924@fixme-laptop.cn.ibm.com> (raw)
In-Reply-To: <20150829142707.GA19263@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3384 bytes --]
Hi Oleg,
On Sat, Aug 29, 2015 at 04:27:07PM +0200, Oleg Nesterov wrote:
> Hello Boqun,
>
...
> > By this, I think you actually means the example below the added text,
> > i.e. the example for "to repeat..", right?
>
> And above. Even
>
> The barrier occurs before the task state is cleared
>
> is not actually right. This is misleading. What is really important is that
> we have a barrier before we _read_ the task state. And again, again, the
> fact that we actually have the write barrier is just the implementation
> detail.
>
Yes, agree with you. However, I didn't realize this problem before, I
will see what I can do ;-)
> > Subject: Documentation: call out conditional barriers of wait_*() and wake_up*()
> >
> > The memory barriers in some sleep and wakeup functions are conditional,
> > there are several situations that there is no barriers:
> >
> > 1. If wait_event() and co. actually don't prepare to sleep, there
> > may be no barrier in them.
>
> And thus (imo) we should not even try to document this. I mean, a user
> should not make any assumptions about the barriers inside wait_event().
>
Yep.
> > 2. No matter whether a sleep occurs or not, there may be no barrier
> > between a successful wait-condition checking(the result of which
> > is true) in wait_event() and the following instructions.
>
> Yes, this is true in any case. Not sure this deserves addtionional
> documentation, but see below.
>
> > 3. If wake_up() and co. actually wake up no one, there may be no
> > write barrier in them.
>
> See above.
>
> > --- a/Documentation/memory-barriers.txt
> > +++ b/Documentation/memory-barriers.txt
> > @@ -1975,7 +1975,8 @@ set_current_state() may be wrapped by:
> >
> > which therefore also imply a general memory barrier after setting the state.
> > The whole sequence above is available in various canned forms, all of which
> > -interpolate the memory barrier in the right place:
> > +imply a general barrier if and only if a sleep is at least about to happen,
> > +i.e. prepare_to_wait*() is called.
> >
> > wait_event();
> > wait_event_interruptible();
> > @@ -1986,6 +1987,9 @@ interpolate the memory barrier in the right place:
> > wait_on_bit();
> > wait_on_bit_lock();
> >
> > +Further more, no barrier is guaranteed after the successful wait condition
> > +checkings, whose results are true, in wait_*() and before the instructions
> > +following wait_*().
>
> Yes, perhaps this makes sense, but (to me) only because the explanation above
> looks a bit confusing to me. I simply can't understand why memory-barriers.txt
> mentions that barrier implied by set_current_state(). You need to know this
> if you want to understand how wait_event() works. You do not need to know
> about this barrier if you want to use wait_event(). If nothing else, because
> you can never rely on this barrier. Anf your examples below shows this.
>
Fair enough, I went too far. How about just a single paragraph saying
that:
The wake_up(), wait_event() and their friends have proper barriers in
them, but these implicity barriers are only for the correctness for
sleep and wakeup. So don't rely on these barriers for things that are
neither wait-conditons nor task states.
Is that OK to you?
Thank you for your comments ;-)
Regards,
Boqun
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2015-08-31 0:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-27 12:27 Michal Hocko
2015-08-27 12:43 ` Peter Zijlstra
2015-08-27 13:14 ` Michal Hocko
2015-08-27 18:26 ` Oleg Nesterov
2015-08-28 14:51 ` Michal Hocko
2015-08-28 16:06 ` Oleg Nesterov
2015-08-29 9:25 ` Boqun Feng
2015-08-29 14:27 ` Oleg Nesterov
2015-08-31 0:37 ` Boqun Feng [this message]
2015-08-31 18:33 ` Oleg Nesterov
2015-08-31 20:37 ` Paul E. McKenney
2015-09-01 3:40 ` Boqun Feng
2015-09-01 4:03 ` Paul E. McKenney
2015-09-01 9:59 ` Oleg Nesterov
2015-09-01 14:50 ` Boqun Feng
2015-09-01 16:39 ` Oleg Nesterov
2015-09-02 1:10 ` Boqun Feng
2015-09-07 17:06 ` Oleg Nesterov
2015-09-08 0:22 ` Boqun Feng
2015-09-01 9:41 ` Oleg Nesterov
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=20150831003719.GC924@fixme-laptop.cn.ibm.com \
--to=boqun.feng@gmail.com \
--cc=corbet@lwn.net \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
/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
all inboxes | Powered by JetHome®