From patchwork Tue May 7 14:39:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Holt X-Patchwork-Id: 2535501 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 445DB3FC5A for ; Tue, 7 May 2013 14:41:24 +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 1UZj4d-0004Wk-2l; Tue, 07 May 2013 14:40:59 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UZj4W-0005Hr-1U; Tue, 07 May 2013 14:40:52 +0000 Received: from relay2.sgi.com ([192.48.179.30] helo=relay.sgi.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UZj4T-0005Fm-6e for linux-arm-kernel@lists.infradead.org; Tue, 07 May 2013 14:40:49 +0000 Received: from estes.americas.sgi.com (estes.americas.sgi.com [128.162.236.10]) by relay2.corp.sgi.com (Postfix) with ESMTP id 559C5304098; Tue, 7 May 2013 07:40:26 -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 1F86970026C8; Tue, 7 May 2013 09:40:26 -0500 (CDT) Received: by asylum.americas.sgi.com (Postfix, from userid 1641) id 16E2B932122; Tue, 7 May 2013 09:40:26 -0500 (CDT) From: Robin Holt To: Andrew Morton Subject: [PATCH -v8 01/11] CPU hotplug: Provide a generic helper to disable/enable CPU hotplug Date: Tue, 7 May 2013 09:39:45 -0500 Message-Id: <1367937595-32241-2-git-send-email-holt@sgi.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1367937595-32241-1-git-send-email-holt@sgi.com> References: <1367937595-32241-1-git-send-email-holt@sgi.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130507_104049_301233_3C9C0F1D X-CRM114-Status: GOOD ( 17.67 ) X-Spam-Score: -5.5 (-----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-5.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [192.48.179.30 listed in list.dnswl.org] -1.3 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 , Russell King , the arch/x86 maintainers , Linux Kernel Mailing List , stable@vger.kernel.org, Robin Holt , "Srivatsa S. Bhat" , "H. Peter Anvin" , Guan Xuetao , 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 From: "Srivatsa S. Bhat" 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 Cc: 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: