From patchwork Fri Jan 4 16:59:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1933981 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id EC1A33FF0F for ; Fri, 4 Jan 2013 17:03:41 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TrAda-0006Ld-QJ; Fri, 04 Jan 2013 17:00:55 +0000 Received: from mail-wi0-f179.google.com ([209.85.212.179]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TrAct-0006B0-PR for linux-arm-kernel@lists.infradead.org; Fri, 04 Jan 2013 17:00:15 +0000 Received: by mail-wi0-f179.google.com with SMTP id o1so35161wic.6 for ; Fri, 04 Jan 2013 09:00:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=9bMwnGsWijigqTz1b5/26ksl9nw/ry0jVyUNpcx+q2Y=; b=oOqZu7G7xX7VqnT5imLFeHSjENlPZCCTq/LUkuaoe7HfR4ox1iLmb6LLOF92P/Aysk 6JelGDtkWO+q666/qRNSOOyKL13V/ubjp9+pOS2yn7RPHMTzpLxnfb41pPQGIrlFb/pS KxFtMAuNLM74Tq6VniCwwv2xgePvFRmKUZx87JGlj7wbzwh5Xf5UAKlSfb2FQ5W64AiF j24c5ik7fkXE/cmz/azx6M6i0QPCFUu4wSHY9kTJWQs2ou8zbIh+6laGtsR9WLpbgNJf CW5Iii5GIrCXqzV1GgfFaHY7zfx12YDo4UIZPnj5+g3KFcXEF3bU4kXMq+BwSJJ8j9T8 0lFA== X-Received: by 10.194.21.70 with SMTP id t6mr84865039wje.42.1357318810570; Fri, 04 Jan 2013 09:00:10 -0800 (PST) Received: from mai.home (AToulouse-654-1-322-234.w86-199.abo.wanadoo.fr. [86.199.209.234]) by mx.google.com with ESMTPS id t17sm91133761wiv.6.2013.01.04.09.00.08 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 04 Jan 2013 09:00:09 -0800 (PST) From: Daniel Lezcano To: kgene.kim@samsung.com Subject: [PATCH 5/5] ARM: exynos: enable/disable cpuidle when cpu1 is down/up Date: Fri, 4 Jan 2013 17:59:59 +0100 Message-Id: <1357318799-24378-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1357318799-24378-1-git-send-email-daniel.lezcano@linaro.org> References: <1357318799-24378-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQlUnQaNXZKDRD4qhRjPCj4msZAgTis1RZQjy2uUscdgS+ejGKMWtz0/nrSLFU25hsz+oNJB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130104_120012_055242_CA266681 X-CRM114-Status: GOOD ( 22.48 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.179 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-samsung-soc@vger.kernel.org, linaro-dev@lists.linaro.org, linux-arm-kernel@lists.infradead.org, patches@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org What we have now is (1) cpu0 going always to WFI when cpu1 is up, (2) cpu0 going to all states when cpu1 is down. In other words, cpuidle is disabled when cpu1 is up and enabled when cpu1 is down. This patch use the cpu hotplug notifier to enable/disable cpuidle, when the cpu1 is plugged or unplugged. That clarifies the code and make it simpler. Signed-off: Daniel Lezcano Acked-by: Amit Daniel Kachhap --- arch/arm/mach-exynos/cpuidle.c | 117 +++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 48 deletions(-) diff --git a/arch/arm/mach-exynos/cpuidle.c b/arch/arm/mach-exynos/cpuidle.c index e6f006b..d8f6f33 100644 --- a/arch/arm/mach-exynos/cpuidle.c +++ b/arch/arm/mach-exynos/cpuidle.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -36,31 +38,8 @@ #define S5P_CHECK_AFTR 0xFCBA0D10 -static int exynos4_enter_lowpower(struct cpuidle_device *dev, - struct cpuidle_driver *drv, - int index); - static struct cpuidle_device exynos4_cpuidle_device; -static struct cpuidle_driver exynos4_idle_driver = { - .name = "exynos4_idle", - .owner = THIS_MODULE, - .en_core_tk_irqen = 1, - .states = { - [0] = ARM_CPUIDLE_WFI_STATE, - [1] = { - .enter = exynos4_enter_lowpower, - .exit_latency = 300, - .target_residency = 100000, - .flags = CPUIDLE_FLAG_TIME_VALID, - .name = "C1", - .desc = "ARM power down", - }, - }, - .state_count = 2, - .safe_state_index = 0, -}; - /* Ext-GIC nIRQ/nFIQ is the only wakeup source in AFTR */ static void exynos4_set_wakeupmask(void) { @@ -93,9 +72,9 @@ static int idle_finisher(unsigned long flags) return 1; } -static int exynos4_enter_core0_aftr(struct cpuidle_device *dev, - struct cpuidle_driver *drv, - int index) +static int exynos4_enter_lowpower(struct cpuidle_device *dev, + struct cpuidle_driver *drv, + int index) { unsigned long tmp; @@ -143,22 +122,6 @@ static int exynos4_enter_core0_aftr(struct cpuidle_device *dev, return index; } -static int exynos4_enter_lowpower(struct cpuidle_device *dev, - struct cpuidle_driver *drv, - int index) -{ - int new_index = index; - - /* This mode only can be entered when other core's are offline */ - if (num_online_cpus() > 1) - new_index = drv->safe_state_index; - - if (new_index == 0) - return arm_cpuidle_simple_enter(dev, drv, new_index); - else - return exynos4_enter_core0_aftr(dev, drv, new_index); -} - static void __init exynos5_core_down_clk(void) { unsigned int tmp; @@ -191,6 +154,62 @@ static void __init exynos5_core_down_clk(void) __raw_writel(tmp, EXYNOS5_PWR_CTRL2); } +static int cpu_hotplug_notify(struct notifier_block *n, + unsigned long action, void *hcpu) +{ + int ret; + + /* + * cpu0 can't be shutdown on Origen, so this routine is + * called only for cpu1. + */ + + switch (action & 0xf) { + + case CPU_ONLINE: + cpuidle_pause_and_lock(); + cpuidle_disable_device(&exynos4_cpuidle_device); + cpuidle_resume_and_unlock(); + break; + + case CPU_DEAD: + if (!exynos4_cpuidle_device.registered) { + ret = cpuidle_register_device(&exynos4_cpuidle_device); + WARN_ONCE(ret, "Failed to register cpuidle device"); + } else { + cpuidle_pause_and_lock(); + cpuidle_enable_device(&exynos4_cpuidle_device); + cpuidle_resume_and_unlock(); + } + break; + } + + return NOTIFY_OK; +} + +static struct notifier_block cpu_hotplug_notifier = { + .notifier_call = cpu_hotplug_notify, +}; + +static struct cpuidle_driver exynos4_idle_driver = { + .name = "exynos4_idle", + .owner = THIS_MODULE, + .en_core_tk_irqen = 1, + .states = { + [0] = ARM_CPUIDLE_WFI_STATE, + [1] = { + .enter = exynos4_enter_lowpower, + .exit_latency = 300, + .target_residency = 100000, + .flags = CPUIDLE_FLAG_TIME_VALID, + .name = "C1", + .desc = "ARM power down", + }, + }, + .state_count = 2, + .safe_state_index = 0, +}; + static int __init exynos4_init_cpuidle(void) { int ret; @@ -204,12 +223,14 @@ static int __init exynos4_init_cpuidle(void) return ret; } - ret = cpuidle_register_device(&exynos4_cpuidle_device); - if (ret) { - printk(KERN_ERR "CPUidle register device failed\n"); - return ret; - } + ret = register_cpu_notifier(&cpu_hotplug_notifier); + if (ret) + goto out_unregister_driver; +out: + return ret; - return 0; +out_unregister_driver: + cpuidle_unregister_driver(&exynos4_idle_driver); + goto out; } device_initcall(exynos4_init_cpuidle);