From: Peter Zijlstra <peterz@infradead.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Boqun Feng <boqun.feng@gmail.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
Jonathan Corbet <corbet@lwn.net>,
Michal Hocko <mhocko@kernel.org>,
David Howells <dhowells@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Will Deacon <will.deacon@arm.com>
Subject: Re: [PATCH] Documentation: Remove misleading examples of the barriers in wake_*()
Date: Tue, 6 Oct 2015 18:04:50 +0200 [thread overview]
Message-ID: <20151006160450.GS3604@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20150921174611.GA28059@redhat.com>
On Mon, Sep 21, 2015 at 07:46:11PM +0200, Oleg Nesterov wrote:
> On 09/18, Peter Zijlstra wrote:
> >
> > the text is correct, right?
>
> Yes, it looks good to me and helpful.
>
> But damn. I forgot why exactly try_to_wake_up() needs rmb() after
> ->on_cpu check... It looks reasonable in any case, but I do not
> see any strong reason immediately.
I read it like the smp_rmb() we have for
acquire__after_spin_is_unlocked. Except, as you note below, we need to
need an smp_read_barrier_depends for control barriers as well....
(I'm starting to think we're having more control deps what we were
thinking...)
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1947,7 +1947,13 @@ try_to_wake_up(struct task_struct *p, un
while (p->on_cpu)
cpu_relax();
/*
- * Pairs with the smp_wmb() in finish_lock_switch().
+ * Combined with the control dependency above, we have an effective
+ * smp_load_acquire() without the need for full barriers.
+ *
+ * Pairs with the smp_store_release() in finish_lock_switch().
+ *
+ * This ensures that tasks getting woken will be fully ordered against
+ * their previous state and preserve Program Order.
*/
smp_rmb();
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1073,6 +1073,9 @@ static inline void finish_lock_switch(st
* We must ensure this doesn't happen until the switch is completely
* finished.
*
+ * In particular, the load of prev->state in finish_task_switch() must
+ * happen before this.
+ *
* Pairs with the control dependency and rmb in try_to_wake_up().
*/
smp_store_release(&prev->on_cpu, 0);
Updates the comments to clarify the release/acquire pair on p->on_cpu.
> Say,
>
> p->sched_contributes_to_load = !!task_contributes_to_load(p);
> p->state = TASK_WAKING;
>
> we can actually do this before "while (p->on_cpu)", afaics. However
> we must not do this before the previous p->on_rq check.
No, we must not touch the task before p->on_cpu is cleared, up until
that point the task is owned by the 'previous' CPU.
> So perhaps this rmb() helps to ensure task_contributes_to_load() can't
> happen before p->on_rq check...
>
> As for "p->state = TASK_WAKING" we have the control dependency in both
> cases. But the modern fashion suggests to use _CTRL().
Yes, but I'm not sure we should go write:
while (READ_ONCE_CTRL(p->on_cpu))
cpu_relax();
Or:
while (p->on_cpu)
cpu_relax();
smp_read_barrier_depends();
It seems to me that doing the smp_mb() (for Alpha) inside the loop might
be sub-optimal.
That said, it would be good if Paul (or anyone really) can explain to me
the reason for: 5af4692a75da ("smp: Make control dependencies work on
Alpha, improve documentation"). The Changelog simply states that Alpha
needs the mb, but not how/why etc.
> Although cpu_relax()
> should imply barrier(), but afaik this is not documented.
I think we're relying on that in many places..
> In short, I got lost ;) Now I don't even understand why we do not need
> another rmb() between p->on_rq and p->on_cpu. Suppose a thread T does
>
> set_current_state(...);
> schedule();
>
> it can be preempted in between, after that we have "on_rq && !on_cpu".
> Then it gets CPU again and calls schedule() which clears on_rq.
>
> What guarantees that if ttwu() sees on_rq == 0 cleared by schedule()
> then it can _not_ still see the old value of on_cpu == 0?
Right, let me go have a think about that ;-)
next prev parent reply other threads:[~2015-10-06 16:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-08 1:14 [PATCH] Documentation: Remove misleading examples of the barriers in wake_*() Boqun Feng
2015-09-09 19:28 ` Paul E. McKenney
2015-09-10 2:16 ` Boqun Feng
2015-09-10 17:55 ` Oleg Nesterov
2015-09-11 16:59 ` Boqun Feng
2015-09-17 13:01 ` Peter Zijlstra
2015-09-17 17:01 ` Oleg Nesterov
2015-09-18 6:49 ` Peter Zijlstra
2015-09-21 17:46 ` Oleg Nesterov
2015-10-06 16:04 ` Peter Zijlstra [this message]
2015-10-06 16:24 ` Peter Zijlstra
2015-10-06 16:35 ` Will Deacon
2015-10-06 19:57 ` Peter Zijlstra
2015-10-07 11:10 ` Peter Zijlstra
2015-10-07 15:40 ` Paul E. McKenney
2015-09-24 13:21 ` Boqun Feng
2015-10-06 16:06 ` Peter Zijlstra
2015-10-11 15:26 ` Boqun Feng
2015-10-12 0:40 ` Paul E. McKenney
2015-10-12 9:06 ` Boqun Feng
2015-10-12 11:54 ` Peter Zijlstra
2015-10-12 13:09 ` Boqun Feng
2015-10-12 16:26 ` Peter Zijlstra
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=20151006160450.GS3604@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=boqun.feng@gmail.com \
--cc=corbet@lwn.net \
--cc=dhowells@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=torvalds@linux-foundation.org \
--cc=will.deacon@arm.com \
/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;
as well as URLs for NNTP newsgroup(s).