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: 9168587 X-Patchwork-Delegate: sboyd@codeaurora.org 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 9C5D0604DB for ; Thu, 9 Jun 2016 22:57:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CC112833D for ; Thu, 9 Jun 2016 22:57:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 816EB2835C; Thu, 9 Jun 2016 22:57:32 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19ABE2833D for ; Thu, 9 Jun 2016 22:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751535AbcFIW52 (ORCPT ); Thu, 9 Jun 2016 18:57:28 -0400 Received: from www.linutronix.de ([62.245.132.108]:56571 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751381AbcFIW51 (ORCPT ); Thu, 9 Jun 2016 18:57:27 -0400 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 cc: Dong Aisheng , Shawn Guo , Lucas Stach , Michael Turquette , Stephen Boyd , LKML , Ingo Molnar , kernel@pengutronix.de, linux-clk@vger.kernel.org, LAK , "Rafael J. Wysocki" 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 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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<--------------------------- --- To unsubscribe from this list: send the line "unsubscribe linux-clk" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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());