From patchwork Wed May 1 17:06:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Holt X-Patchwork-Id: 2508351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id E8BBB3FC5A for ; Wed, 1 May 2013 17:09:22 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UXaW2-0006PI-GX; Wed, 01 May 2013 17:08:27 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UXaVh-0007ph-0t; Wed, 01 May 2013 17:08:05 +0000 Received: from relay3.sgi.com ([192.48.152.1] helo=relay.sgi.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UXaV5-0007jZ-L1 for linux-arm-kernel@lists.infradead.org; Wed, 01 May 2013 17:07:33 +0000 Received: from estes.americas.sgi.com (estes.americas.sgi.com [128.162.236.10]) by relay3.corp.sgi.com (Postfix) with ESMTP id 1021BAC001; Wed, 1 May 2013 10:07:05 -0700 (PDT) Received: from asylum.americas.sgi.com (asylum.americas.sgi.com [128.162.246.107]) by estes.americas.sgi.com (Postfix) with ESMTP id A30A17002B0D; Wed, 1 May 2013 12:07:04 -0500 (CDT) Received: by asylum.americas.sgi.com (Postfix, from userid 1641) id 9B8CF826D23; Wed, 1 May 2013 12:07:04 -0500 (CDT) From: Robin Holt To: Andrew Morton , "H. Peter Anvin" , Russell King , Guan Xuetao , Miguel Boton Subject: [PATCH -v7 01/11] CPU hotplug: Provide a generic helper to disable/enable CPU hotplug Date: Wed, 1 May 2013 12:06:41 -0500 Message-Id: <1367428011-17123-2-git-send-email-holt@sgi.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1367428011-17123-1-git-send-email-holt@sgi.com> References: <1367428011-17123-1-git-send-email-holt@sgi.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130501_130728_277412_52399D7C X-CRM114-Status: GOOD ( 17.78 ) X-Spam-Score: -6.8 (------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-6.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [192.48.152.1 listed in list.dnswl.org] -2.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Russ Anderson , the arch/x86 maintainers , Linux Kernel Mailing List , stable@vger.kernel.org, Robin Holt , "Srivatsa S. Bhat" , Arm Mailing List X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org There are instances in the kernel where we would like to disable CPU hotplug (from sysfs) during some important operation. Today the freezer code depends on this and the code to do it was kinda tailor-made for that. Restructure the code and make it generic enough to be useful for other usecases too. Signed-off-by: Srivatsa S. Bhat Signed-off-by: Robin Holt To: Andrew Morton To: H. Peter Anvin Cc: Russ Anderson Cc: Robin Holt Cc: Russell King Cc: Guan Xuetao Cc: Linux Kernel Mailing List Cc: the arch/x86 maintainers Cc: Arm Mailing List Cc: --- Changes since -v6: - Added a #define for non-hotplug case. --- include/linux/cpu.h | 3 +++ kernel/cpu.c | 27 +++++++++------------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/include/linux/cpu.h b/include/linux/cpu.h index c6f6e08..3e450c0 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -141,6 +141,8 @@ static inline void unregister_cpu_notifier(struct notifier_block *nb) } #endif +extern void cpu_hotplug_disable(void); +extern void cpu_hotplug_enable(void); int cpu_up(unsigned int cpu); void notify_cpu_starting(unsigned int cpu); extern void cpu_maps_update_begin(void); @@ -148,6 +150,7 @@ extern void cpu_maps_update_done(void); #else /* CONFIG_SMP */ +#define cpu_hotplug_disable() do { } while (0) #define cpu_notifier(fn, pri) do { (void)(fn); } while (0) static inline int register_cpu_notifier(struct notifier_block *nb) diff --git a/kernel/cpu.c b/kernel/cpu.c index b5e4ab2..28769f5 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -541,29 +541,20 @@ static int __init alloc_frozen_cpus(void) core_initcall(alloc_frozen_cpus); /* - * Prevent regular CPU hotplug from racing with the freezer, by disabling CPU - * hotplug when tasks are about to be frozen. Also, don't allow the freezer - * to continue until any currently running CPU hotplug operation gets - * completed. - * To modify the 'cpu_hotplug_disabled' flag, we need to acquire the - * 'cpu_add_remove_lock'. And this same lock is also taken by the regular - * CPU hotplug path and released only after it is complete. Thus, we - * (and hence the freezer) will block here until any currently running CPU - * hotplug operation gets completed. + * Wait for currently running CPU hotplug operations to complete (if any) and + * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects + * the 'cpu_hotplug_disabled' flag. The same lock is also acquired by the + * hotplug path before performing hotplug operations. So acquiring that lock + * guarantees mutual exclusion from any currently running hotplug operations. */ -void cpu_hotplug_disable_before_freeze(void) +void cpu_hotplug_disable(void) { cpu_maps_update_begin(); cpu_hotplug_disabled = 1; cpu_maps_update_done(); } - -/* - * When tasks have been thawed, re-enable regular CPU hotplug (which had been - * disabled while beginning to freeze tasks). - */ -void cpu_hotplug_enable_after_thaw(void) +void cpu_hotplug_enable(void) { cpu_maps_update_begin(); cpu_hotplug_disabled = 0; @@ -589,12 +580,12 @@ cpu_hotplug_pm_callback(struct notifier_block *nb, case PM_SUSPEND_PREPARE: case PM_HIBERNATION_PREPARE: - cpu_hotplug_disable_before_freeze(); + cpu_hotplug_disable(); break; case PM_POST_SUSPEND: case PM_POST_HIBERNATION: - cpu_hotplug_enable_after_thaw(); + cpu_hotplug_enable(); break; default: