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: 5535881 Return-Path: X-Original-To: patchwork-linux-pm@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 895C79F2F7 for ; Wed, 24 Dec 2014 00:12:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BF72520115 for ; Wed, 24 Dec 2014 00:12:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E163D20108 for ; Wed, 24 Dec 2014 00:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754025AbaLXALt (ORCPT ); Tue, 23 Dec 2014 19:11:49 -0500 Received: from mail-ig0-f179.google.com ([209.85.213.179]:49133 "EHLO mail-ig0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751297AbaLXALs (ORCPT ); Tue, 23 Dec 2014 19:11:48 -0500 Received: by mail-ig0-f179.google.com with SMTP id r2so6285393igi.6 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=XGOgJHhMX25cpfZ8OQFf/BMYGbgPTzFanctDZ1dH7Iilq/wlI0vDvV3M3Xoo89/VDn TzpD10lG/rCUkCg4V/B0Uf96bd4M/WILTccKy+hneEya4zX2POYB+7ajHpL9xy3MX6Nq eKsbAY5eVSpwr8rq5R8ZCrlxfVCyRZwdDTlAunsy9zvx+wzN+zYXXv3xt8YUqxPkOweB JMpjAUVjf5u64WI+2TRjBpz8CMp+9iAub7v5BVsquc9KC5IDNlGA7+bwyCr3NrQfdFC5 p1mKKxnKA9V8HJGAePnHlGQ1IwMcL/t43GueGV55sPnI81THAZ7RFgkn2gU/D/Dy/f59 3RiA== X-Gm-Message-State: ALoCoQlpkTBcyn84oYtB5nHPWX/McsBbHakNhKWNHsMEL6IPjqiG//5X0dvZ+SbIoOsnslxDwZ8t 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 Cc: Heiko Stuebner , Dmitry Torokhov , Chris Zhong , linux-arm-kernel@lists.infradead.org, Sonny Rao , Dylan Reid , Doug Anderson , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.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 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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);