From patchwork Tue Nov 13 19:32:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fenghua Yu X-Patchwork-Id: 1737261 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 12765DF280 for ; Wed, 14 Nov 2012 02:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932517Ab2KNCdo (ORCPT ); Tue, 13 Nov 2012 21:33:44 -0500 Received: from mga14.intel.com ([143.182.124.37]:37267 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932502Ab2KNCdn (ORCPT ); Tue, 13 Nov 2012 21:33:43 -0500 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga102.ch.intel.com with ESMTP; 13 Nov 2012 18:33:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.83,247,1352102400"; d="scan'208";a="217413918" Received: from fenghua-desk.sc.intel.com ([10.3.52.80]) by azsmga001.ch.intel.com with ESMTP; 13 Nov 2012 18:33:41 -0800 From: "Fenghua Yu" To: "Ingo Molnar" , "Thomas Gleixner" , "H Peter Anvin" , "Linus Torvalds" , "Andrew Morton" , "Asit K Mallick" , "Tony Luck" , "Arjan Dan De Ven" , "Suresh B Siddha" , "Len Brown" , "Srivatssa S. Bhat" , "Randy Dunlap" , "Rafael J. Wysocki" , "Chen Gong" , "linux-kernel" , "linux-pm" , "x86" Cc: "Fenghua Yu" Subject: [PATCH v10 05/14] x86, hotplug, suspend: Online CPU0 for suspend or hibernate Date: Tue, 13 Nov 2012 11:32:42 -0800 Message-Id: <1352835171-3958-6-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 1.7.2 In-Reply-To: <1352835171-3958-1-git-send-email-fenghua.yu@intel.com> References: <1352835171-3958-1-git-send-email-fenghua.yu@intel.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Fenghua Yu Because x86 BIOS requires CPU0 to resume from sleep, suspend or hibernate can't be executed if CPU0 is detected offline. To make suspend or hibernate and further resume succeed, CPU0 must be online. Signed-off-by: Fenghua Yu --- arch/x86/power/cpu.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c index 218cdb1..adde775 100644 --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -237,3 +237,47 @@ void restore_processor_state(void) #ifdef CONFIG_X86_32 EXPORT_SYMBOL(restore_processor_state); #endif + +/* + * When bsp_check() is called in hibernate and suspend, cpu hotplug + * is disabled already. So it's unnessary to handle race condition between + * cpumask query and cpu hotplug. + */ +static int bsp_check(void) +{ + if (cpumask_first(cpu_online_mask) != 0) { + pr_warn("CPU0 is offline.\n"); + return -ENODEV; + } + + return 0; +} + +static int bsp_pm_callback(struct notifier_block *nb, unsigned long action, + void *ptr) +{ + int ret = 0; + + switch (action) { + case PM_SUSPEND_PREPARE: + case PM_HIBERNATION_PREPARE: + ret = bsp_check(); + break; + default: + break; + } + return notifier_from_errno(ret); +} + +static int __init bsp_pm_check_init(void) +{ + /* + * Set this bsp_pm_callback as lower priority than + * cpu_hotplug_pm_callback. So cpu_hotplug_pm_callback will be called + * earlier to disable cpu hotplug before bsp online check. + */ + pm_notifier(bsp_pm_callback, -INT_MAX); + return 0; +} + +core_initcall(bsp_pm_check_init);