From patchwork Sun Jun 23 13:40:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Srivatsa S. Bhat" X-Patchwork-Id: 2768121 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B7789F245 for ; Sun, 23 Jun 2013 13:56:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD10F2018C for ; Sun, 23 Jun 2013 13:56:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B039A20187 for ; Sun, 23 Jun 2013 13:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752119Ab3FWNnu (ORCPT ); Sun, 23 Jun 2013 09:43:50 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:47868 "EHLO e28smtp05.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752002Ab3FWNnt (ORCPT ); Sun, 23 Jun 2013 09:43:49 -0400 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 23 Jun 2013 19:08:46 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 23 Jun 2013 19:08:43 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id C5423E0043; Sun, 23 Jun 2013 19:13:12 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r5NDhsjV30474408; Sun, 23 Jun 2013 19:13:54 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5NDhe3K001398; Sun, 23 Jun 2013 23:43:42 +1000 Received: from srivatsabhat.in.ibm.com ([9.79.195.141]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r5NDhdWu001373; Sun, 23 Jun 2013 23:43:39 +1000 From: "Srivatsa S. Bhat" Subject: [PATCH 10/45] sched/core: Use get/put_online_cpus_atomic() to prevent CPU offline To: tglx@linutronix.de, peterz@infradead.org, tj@kernel.org, oleg@redhat.com, paulmck@linux.vnet.ibm.com, rusty@rustcorp.com.au, mingo@kernel.org, akpm@linux-foundation.org, namhyung@kernel.org, walken@google.com, vincent.guittot@linaro.org, laijs@cn.fujitsu.com Cc: rostedt@goodmis.org, wangyun@linux.vnet.ibm.com, xiaoguangrong@linux.vnet.ibm.com, sbw@mit.edu, fweisbec@gmail.com, zhong@linux.vnet.ibm.com, nikunj@linux.vnet.ibm.com, srivatsa.bhat@linux.vnet.ibm.com, linux-pm@vger.kernel.org, linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Ingo Molnar , Peter Zijlstra Date: Sun, 23 Jun 2013 19:10:27 +0530 Message-ID: <20130623134020.19094.59333.stgit@srivatsabhat.in.ibm.com> In-Reply-To: <20130623133642.19094.16038.stgit@srivatsabhat.in.ibm.com> References: <20130623133642.19094.16038.stgit@srivatsabhat.in.ibm.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13062313-8256-0000-0000-0000080B6415 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Once stop_machine() is gone from the CPU offline path, we won't be able to depend on disabling preemption to prevent CPUs from going offline from under us. Use the get/put_online_cpus_atomic() APIs to prevent CPUs from going offline, while invoking from atomic context. Cc: Ingo Molnar Cc: Peter Zijlstra Signed-off-by: Srivatsa S. Bhat --- kernel/sched/core.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 195658b..accd550 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1160,11 +1160,11 @@ void kick_process(struct task_struct *p) { int cpu; - preempt_disable(); + get_online_cpus_atomic(); cpu = task_cpu(p); if ((cpu != smp_processor_id()) && task_curr(p)) smp_send_reschedule(cpu); - preempt_enable(); + put_online_cpus_atomic(); } EXPORT_SYMBOL_GPL(kick_process); #endif /* CONFIG_SMP */ @@ -1172,6 +1172,9 @@ EXPORT_SYMBOL_GPL(kick_process); #ifdef CONFIG_SMP /* * ->cpus_allowed is protected by both rq->lock and p->pi_lock + * + * Must be called within get/put_online_cpus_atomic(), to prevent + * CPUs from going offline from under us. */ static int select_fallback_rq(int cpu, struct task_struct *p) { @@ -1245,6 +1248,9 @@ out: /* * The caller (fork, wakeup) owns p->pi_lock, ->cpus_allowed is stable. + * + * Must be called within get/put_online_cpus_atomic(), to prevent + * CPUs from going offline from under us. */ static inline int select_task_rq(struct task_struct *p, int sd_flags, int wake_flags) @@ -1489,6 +1495,8 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) unsigned long flags; int cpu, success = 0; + get_online_cpus_atomic(); + smp_wmb(); raw_spin_lock_irqsave(&p->pi_lock, flags); if (!(p->state & state)) @@ -1531,6 +1539,7 @@ stat: out: raw_spin_unlock_irqrestore(&p->pi_lock, flags); + put_online_cpus_atomic(); return success; } @@ -1753,6 +1762,8 @@ void wake_up_new_task(struct task_struct *p) unsigned long flags; struct rq *rq; + get_online_cpus_atomic(); + raw_spin_lock_irqsave(&p->pi_lock, flags); #ifdef CONFIG_SMP /* @@ -1773,6 +1784,8 @@ void wake_up_new_task(struct task_struct *p) p->sched_class->task_woken(rq, p); #endif task_rq_unlock(rq, p, &flags); + + put_online_cpus_atomic(); } #ifdef CONFIG_PREEMPT_NOTIFIERS @@ -3886,6 +3899,8 @@ bool __sched yield_to(struct task_struct *p, bool preempt) unsigned long flags; int yielded = 0; + get_online_cpus_atomic(); + local_irq_save(flags); rq = this_rq(); @@ -3931,6 +3946,8 @@ out_unlock: out_irq: local_irq_restore(flags); + put_online_cpus_atomic(); + if (yielded > 0) schedule(); @@ -4331,9 +4348,11 @@ static int migration_cpu_stop(void *data) * The original target cpu might have gone down and we might * be on another cpu but it doesn't matter. */ + get_online_cpus_atomic(); local_irq_disable(); __migrate_task(arg->task, raw_smp_processor_id(), arg->dest_cpu); local_irq_enable(); + put_online_cpus_atomic(); return 0; }