From patchwork Thu Jun 9 22:55:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 9168591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46793604DB for ; Thu, 9 Jun 2016 22:59:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36CDA28347 for ; Thu, 9 Jun 2016 22:59:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A8072835B; Thu, 9 Jun 2016 22:59:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A4DB728347 for ; Thu, 9 Jun 2016 22:59:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bB8ta-0005NK-IP; Thu, 09 Jun 2016 22:57:50 +0000 Received: from linutronix.de ([2001:470:1f0b:db:abcd:42:0:1] helo=Galois.linutronix.de) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bB8tX-0005KQ-Qa for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2016 22:57:48 +0000 Received: from localhost ([127.0.0.1]) by Galois.linutronix.de with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1bB8t6-0002cT-Fc; Fri, 10 Jun 2016 00:57:20 +0200 Date: Fri, 10 Jun 2016 00:55:26 +0200 (CEST) From: Thomas Gleixner To: Stefan Agner Subject: Re: [PATCH 1/2] clk: imx: do not sleep if IRQ's are still disabled In-Reply-To: <1162370a4389413d2d4ff0eb79ff13ac@agner.ch> Message-ID: References: <20160426012341.GB8870@tiger> <1461663072.7839.17.camel@pengutronix.de> <20160427015835.GE30692@tiger> <20160602145915.GA31124@shlinux2> <20160607070440.GA32573@shlinux2> <1162370a4389413d2d4ff0eb79ff13ac@agner.ch> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1, SHORTCIRCUIT=-0.0001 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160609_155748_040213_D4C5A12F X-CRM114-Status: GOOD ( 27.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dong Aisheng , Michael Turquette , Stephen Boyd , LKML , linux-clk@vger.kernel.org, "Rafael J. Wysocki" , kernel@pengutronix.de, Shawn Guo , Ingo Molnar , LAK , Lucas Stach Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, 9 Jun 2016, Stefan Agner wrote: > On 2016-06-09 13:08, Thomas Gleixner wrote: > > On Tue, 7 Jun 2016, Dong Aisheng wrote: > >> Then it may need introduce a lot changes and increase many new core APIs. > >> Is that a problem? > > > > No. That's all better than each driver having broken workarounds. It's a > > common problem so it wants to be addressed at the core level. There you have a > > central point to do this and you can still catch abusers which call stuff from > > the wrong context. The hacks in the drivers don't allow that because they look > > at the context, i.e. irq disabled, instead of checking the system state. > > IMHO, the hacky part of my patch was how I detected whether to use sleep > or delay. That said I am ok with API extension too, I guess it is fairly > common use case... I found at least 6 clock prepare functions with sleep > in it (and some udelays, all between 1-100). > > Your proposed solution uses "early_boot_or_suspend_resume" which I did > not found as a convenient function in the wild :-) > > How would you implement that? Early boot is simple. Supsend/resume is not that hard either. We have a patch in RT which does exactly what you need. See below. Then the state check simply becomes: system_state != SYSTEM_RUNNING Thanks, tglx 8<--------------------------- diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 350dfb08aee3..5e63b681f58e 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -473,6 +473,7 @@ extern enum system_states { SYSTEM_HALT, SYSTEM_POWER_OFF, SYSTEM_RESTART, + SYSTEM_SUSPEND, } system_state; #define TAINT_PROPRIETARY_MODULE 0 diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index b7342a24f559..bfd9e0982f15 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -285,6 +285,8 @@ static int create_image(int platform_mode) local_irq_disable(); + system_state = SYSTEM_SUSPEND; + error = syscore_suspend(); if (error) { printk(KERN_ERR "PM: Some system devices failed to power down, " @@ -314,6 +316,7 @@ static int create_image(int platform_mode) syscore_resume(); Enable_irqs: + system_state = SYSTEM_RUNNING; local_irq_enable(); Enable_cpus: @@ -437,6 +440,7 @@ static int resume_target_kernel(bool platform_mode) goto Enable_cpus; local_irq_disable(); + system_state = SYSTEM_SUSPEND; error = syscore_suspend(); if (error) @@ -470,6 +474,7 @@ static int resume_target_kernel(bool platform_mode) syscore_resume(); Enable_irqs: + system_state = SYSTEM_RUNNING; local_irq_enable(); Enable_cpus: @@ -555,6 +560,7 @@ int hibernation_platform_enter(void) goto Enable_cpus; local_irq_disable(); + system_state = SYSTEM_SUSPEND; syscore_suspend(); if (pm_wakeup_pending()) { error = -EAGAIN; @@ -567,6 +573,7 @@ int hibernation_platform_enter(void) Power_up: syscore_resume(); + system_state = SYSTEM_RUNNING; local_irq_enable(); Enable_cpus: diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index f9fe133c13e2..80ebc0726290 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -359,6 +359,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) arch_suspend_disable_irqs(); BUG_ON(!irqs_disabled()); + system_state = SYSTEM_SUSPEND; + error = syscore_suspend(); if (!error) { *wakeup = pm_wakeup_pending(); @@ -375,6 +377,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup) syscore_resume(); } + system_state = SYSTEM_RUNNING; + arch_suspend_enable_irqs(); BUG_ON(irqs_disabled());