From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753134AbbBRRGs (ORCPT ); Wed, 18 Feb 2015 12:06:48 -0500 Received: from terminus.zytor.com ([198.137.202.10]:38928 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751734AbbBRRGq (ORCPT ); Wed, 18 Feb 2015 12:06:46 -0500 Date: Wed, 18 Feb 2015 09:05:49 -0800 From: tip-bot for Peter Zijlstra Message-ID: Cc: linux-kernel@vger.kernel.org, ktkhai@parallels.com, mingo@kernel.org, tglx@linutronix.de, oleg@redhat.com, hpa@zytor.com, peterz@infradead.org, paulmck@linux.vnet.ibm.com, torvalds@linux-foundation.org Reply-To: mingo@kernel.org, ktkhai@parallels.com, linux-kernel@vger.kernel.org, oleg@redhat.com, peterz@infradead.org, hpa@zytor.com, tglx@linutronix.de, paulmck@linux.vnet.ibm.com, torvalds@linux-foundation.org In-Reply-To: <20150217121258.GM5029@twins.programming.kicks-ass.net> References: <20150217121258.GM5029@twins.programming.kicks-ass.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/core] sched: Clarify ordering between task_rq_lock() and move_queued_task() Git-Commit-ID: 74b8a4cb6ce3685049ee124243a52238c5cabe55 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 74b8a4cb6ce3685049ee124243a52238c5cabe55 Gitweb: http://git.kernel.org/tip/74b8a4cb6ce3685049ee124243a52238c5cabe55 Author: Peter Zijlstra AuthorDate: Tue, 17 Feb 2015 13:07:38 +0100 Committer: Ingo Molnar CommitDate: Wed, 18 Feb 2015 14:27:28 +0100 sched: Clarify ordering between task_rq_lock() and move_queued_task() There was a wee bit of confusion around the exact ordering here; clarify things. Reported-by: Kirill Tkhai Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Paul E. McKenney Link: http://lkml.kernel.org/r/20150217121258.GM5029@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar --- kernel/sched/core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 1f37fe7..fd0a6ed 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -341,6 +341,22 @@ static struct rq *task_rq_lock(struct task_struct *p, unsigned long *flags) raw_spin_lock_irqsave(&p->pi_lock, *flags); rq = task_rq(p); raw_spin_lock(&rq->lock); + /* + * move_queued_task() task_rq_lock() + * + * ACQUIRE (rq->lock) + * [S] ->on_rq = MIGRATING [L] rq = task_rq() + * WMB (__set_task_cpu()) ACQUIRE (rq->lock); + * [S] ->cpu = new_cpu [L] task_rq() + * [L] ->on_rq + * RELEASE (rq->lock) + * + * If we observe the old cpu in task_rq_lock, the acquire of + * the old rq->lock will fully serialize against the stores. + * + * If we observe the new cpu in task_rq_lock, the acquire will + * pair with the WMB to ensure we must then also see migrating. + */ if (likely(rq == task_rq(p) && !task_on_rq_migrating(p))) return rq; raw_spin_unlock(&rq->lock);