From patchwork Wed Dec 24 00:11:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 5535891 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 135229F1CD for ; Wed, 24 Dec 2014 00:15:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 370232011D for ; Wed, 24 Dec 2014 00:15:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D34C20115 for ; Wed, 24 Dec 2014 00:15:37 +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 1Y3ZYi-0003Gs-NV; Wed, 24 Dec 2014 00:12:12 +0000 Received: from mail-ig0-x236.google.com ([2607:f8b0:4001:c05::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y3ZYg-0003DU-4C for linux-arm-kernel@lists.infradead.org; Wed, 24 Dec 2014 00:12:11 +0000 Received: by mail-ig0-f182.google.com with SMTP id hn15so6300189igb.9 for ; Tue, 23 Dec 2014 16:11:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=tFoitreZXTdY7JZ6VbNSY6PA29V/GuZ327b4FLYXhy4=; b=Fhs2Of/JfbEzamds+F8Kb9Hra4PBDD4X9mjbZdmfPbvuP6s5ZGiHTv3vocfAjG0eZ7 U2vtU5RdRDNvmfgqUw4zNF1gAsIb4HiVxrCbp9vyw9CpPyJq7oMZqo3yJrD5gXZHd6FY 6bBn0JvJWOMmPkMmxmon309L8W9G9aAIZ7P98= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tFoitreZXTdY7JZ6VbNSY6PA29V/GuZ327b4FLYXhy4=; b=B8nx16ZcyNNjfDz8vpEtKzFTV2brPLdLz5HlOxA3BGNWUKa58K9O8FUUzFld43SlH3 16B7rFvZeDUNBRPYNI5SNfSz8yrN2RLK0vXZMuh8yRePcLZXJnvAhq0w7pLc+GvIDmqp cbmPPrFO1fmO2vAHdSeIfgflN5auYK7NCh/YXy5LtGHWR7/02T2B6zJ5lgNtP/x2eGkn UTf6nuIeopynFTgzEMwAiZ9i4m4FnT59iy9sOkn9sNFCdh/Ar07cKvwJIWLgZj4LqwoD OsYtjG4BhOP1T10VLk3BeWSN2pkD33ns0XVrALFssOK7ZMHl+BJkLl2lCJXf3n/hkZnu EzTw== X-Gm-Message-State: ALoCoQnhWmIg5KF1c7mRBcKhml/R6FRpkUf+7eG2SdbuBOERQQWrh1Tr+2zGUUXrL3FtCX5ObICA X-Received: by 10.42.96.195 with SMTP id k3mr23687784icn.7.1419379907356; Tue, 23 Dec 2014 16:11:47 -0800 (PST) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by mx.google.com with ESMTPSA id s10sm7035382igr.2.2014.12.23.16.11.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Dec 2014 16:11:46 -0800 (PST) From: Doug Anderson To: rjw@rjwysocki.net, viresh.kumar@linaro.org Subject: [PATCH] cpufreq: suspend cpufreq governors on shutdown Date: Tue, 23 Dec 2014 16:11:41 -0800 Message-Id: <1419379901-17182-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141223_161210_253140_5FFD8891 X-CRM114-Status: GOOD ( 14.83 ) X-Spam-Score: -0.8 (/) Cc: Heiko Stuebner , linux-pm@vger.kernel.org, Dmitry Torokhov , Doug Anderson , linux-kernel@vger.kernel.org, Chris Zhong , Dylan Reid , Sonny Rao , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 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 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We should stop cpufreq governors when we shut down the system. If we don't do this, we can end up with this deadlock: 1. cpufreq governor may be running on a CPU other than CPU0. 2. In machine_restart() we call smp_send_stop() which stops CPUs. If one of these CPUs was actively running a cpufreq governor then it may have the mutex / spinlock needed to access the main PMIC in the system (perhaps over I2C) 3. If a machine needs access to the main PMIC in order to shutdown then it will never get it since the mutex was lost when the other CPU stopped. Let's avoid the race by stopping the cpufreq governor at shutdown, which is a sensible thing to do anyway. Signed-off-by: Doug Anderson --- NOTE: This was developed / tested / on a 3.14 kernel with backports. I have confirmed that it compiles on a mainline kernel and doesn't crash, but I haven't verified that there isn't some other fix in mainline that also fixes this problem. If you are aware of such a fix then please drop this patch. drivers/cpufreq/cpufreq.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index a09a29c..bd89721 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -2550,6 +2551,15 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver) } EXPORT_SYMBOL_GPL(cpufreq_unregister_driver); +static void cpufreq_shutdown(void) +{ + cpufreq_suspend(); +} + +static struct syscore_ops cpufreq_syscore_ops = { + .shutdown = cpufreq_shutdown, +}; + static int __init cpufreq_core_init(void) { if (cpufreq_disabled()) @@ -2558,6 +2568,8 @@ static int __init cpufreq_core_init(void) cpufreq_global_kobject = kobject_create(); BUG_ON(!cpufreq_global_kobject); + register_syscore_ops(&cpufreq_syscore_ops); + return 0; } core_initcall(cpufreq_core_init);