From patchwork Thu Oct 16 19:29:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 400168 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 108321400DD for ; Thu, 16 Oct 2014 18:30:25 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id F11B71A1DFB for ; Thu, 16 Oct 2014 18:30:24 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-ig0-x233.google.com (mail-ig0-x233.google.com [IPv6:2607:f8b0:4001:c05::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id ABF101A0388 for ; Thu, 16 Oct 2014 18:25:59 +1100 (AEDT) Received: by mail-ig0-f179.google.com with SMTP id h18so2945547igc.6 for ; Thu, 16 Oct 2014 00:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p0FgpzhR36iV1xINn7Av6e/LP9DZRtqC0fEeM5cMxrw=; b=KCEupN8wkQBpXR7GpRn24lpBSUxf3MbZ+pZNDgK5ucpmIslEE3qJeQYaFC4vG17qnM uFBch8T+ePTslJ0czvMLdDbT4Ub88EpNvmHXuZcm4lf105U6LQ+wrVfZSt/o0jskqLdw sIlHKKwj3IVX9GWIFPxki3pITDrQO89MiF/o/tkpAWwNo2JZs9QAlZcZJNUemZ63uux9 FZUKxWerWYTuse1AxbMSAzro0iU4hxIBAWA+JMAqj/n3mR+Y4Nr1emuoVfbdfP6OsNYF 1KCdxhMEwsLvw/RkHy+j/B7l/h8kDfoKhBPIPXwmnhCRw2z2E7cbaoc/LZRaHqBaVyGU uZOA== X-Received: by 10.50.128.170 with SMTP id np10mr2953725igb.42.1413444357440; Thu, 16 Oct 2014 00:25:57 -0700 (PDT) Received: from localhost ([202.108.130.193]) by mx.google.com with ESMTPSA id mj3sm14083463igb.11.2014.10.16.00.25.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Oct 2014 00:25:56 -0700 (PDT) From: kernelfans@gmail.com To: linuxppc-dev@lists.ozlabs.org, kvm-ppc@vger.kernel.org Subject: [RFC 05/11] sched: introduce stop_cpus_async() to schedule special tsk on cpu Date: Thu, 16 Oct 2014 15:29:54 -0400 Message-Id: <1413487800-7162-6-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1413487800-7162-1-git-send-email-kernelfans@gmail.com> References: <1413487800-7162-1-git-send-email-kernelfans@gmail.com> Cc: Paul Mackerras , Alexander Graf X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The proto will be: cpu1 cpuX stop_cpus_async() bring cpuX to a special state signal flag and trapped check for flag The func help powerpc to reuse the scheme of cpu_stopper_task to force the secondary hwthread goto NAP state, in which state, cpu will not run any longer until the master cpu tells them to go. Signed-off-by: Liu Ping Fan --- include/linux/stop_machine.h | 2 ++ kernel/stop_machine.c | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h index d2abbdb..871c1bf 100644 --- a/include/linux/stop_machine.h +++ b/include/linux/stop_machine.h @@ -32,6 +32,8 @@ int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void * void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg, struct cpu_stop_work *work_buf); int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg); +int stop_cpus_async(const struct cpumask *cpumask, cpu_stop_fn_t fn, + void *arg); int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg); #else /* CONFIG_SMP */ diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 695f0c6..d26fd6a 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -354,13 +354,15 @@ static void queue_stop_cpus_work(const struct cpumask *cpumask, } static int __stop_cpus(const struct cpumask *cpumask, - cpu_stop_fn_t fn, void *arg) + cpu_stop_fn_t fn, void *arg, bool sync) { struct cpu_stop_done done; - cpu_stop_init_done(&done, cpumask_weight(cpumask)); + if (sync) + cpu_stop_init_done(&done, cpumask_weight(cpumask)); queue_stop_cpus_work(cpumask, fn, arg, &done); - wait_for_completion(&done.completion); + if (sync) + wait_for_completion(&done.completion); return done.executed ? done.ret : -ENOENT; } @@ -398,7 +400,20 @@ int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg) /* static works are used, process one request at a time */ mutex_lock(&stop_cpus_mutex); - ret = __stop_cpus(cpumask, fn, arg); + ret = __stop_cpus(cpumask, fn, arg, true); + mutex_unlock(&stop_cpus_mutex); + return ret; +} + +/* similar to stop_cpus(), but not wait for the ack. */ +int stop_cpus_async(const struct cpumask *cpumask, cpu_stop_fn_t fn, + void *arg) +{ + int ret; + + /* static works are used, process one request at a time */ + mutex_lock(&stop_cpus_mutex); + ret = __stop_cpus(cpumask, fn, arg, false); mutex_unlock(&stop_cpus_mutex); return ret; } @@ -428,7 +443,7 @@ int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg) /* static works are used, process one request at a time */ if (!mutex_trylock(&stop_cpus_mutex)) return -EAGAIN; - ret = __stop_cpus(cpumask, fn, arg); + ret = __stop_cpus(cpumask, fn, arg, true); mutex_unlock(&stop_cpus_mutex); return ret; }