From patchwork Tue Nov 29 05:34:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 84498 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1458951qgi; Mon, 28 Nov 2016 21:35:16 -0800 (PST) X-Received: by 10.84.217.149 with SMTP id p21mr30428786pli.121.1480397716536; Mon, 28 Nov 2016 21:35:16 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p7si58338749pgf.238.2016.11.28.21.35.16; Mon, 28 Nov 2016 21:35:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753214AbcK2FfO (ORCPT + 13 others); Tue, 29 Nov 2016 00:35:14 -0500 Received: from mail-pf0-f176.google.com ([209.85.192.176]:36830 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752592AbcK2FfN (ORCPT ); Tue, 29 Nov 2016 00:35:13 -0500 Received: by mail-pf0-f176.google.com with SMTP id 189so29645226pfz.3 for ; Mon, 28 Nov 2016 21:35:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=g1a0xYJ+ij013UWgiEa/0cRgL2Qu1dbRP/V3X8QWBgQ=; b=hZB1EEnS/Gc0mVBEc7pnSDEoAicH50iBTfszRMWfj4fV0XKfCX/pshV2ps2sX2gKkb 64hC/d4Nl3eeopAaPCBQXSCewHMWI/l1iWqItKNwcNZcxSp7agh4xjhFPXcAh+eOGaEu bYCSKEdFl+d/l1VY8gJc+LHHJD476MgulYWoI= 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=g1a0xYJ+ij013UWgiEa/0cRgL2Qu1dbRP/V3X8QWBgQ=; b=OGdtfkPq5gKeGk7E0Q1JGsfJnYvFrEH1VpTS1XrPhTNhK0e1pADElkKzeSEByRA8tz hYkxD0Pjg3iM1Ip7THiQ2+8TZTUBBvyEPh5VvWgFGNylLKqaGhgpqzqzt13rh/sEK+6a PURyAACHPWpofg3EbJwzNc2duTG2wTH/Pn2qq+nfgTUu9/7ewMzgn8OBl4dH7ZyrvIzD O3cpkW00/EqiGisPXD/eeaq5G4n0lnBXUEG3gRqoi7wDpX3Mm9+/jvAgDSVmJ00koA0s oDLxl4sYIzJ2bEQZFrkTnT6F3WKAGZyRJnl+9uml1FLkTbEMcY/VTHDLnrprBW9h4hcE CgqQ== X-Gm-Message-State: AKaTC02nVVEyL5bkjF8TFwqeUHPV9AxkWxhHc6HazpuMBs+QAl4VNQOS+9KUll8lDLpTi02m X-Received: by 10.84.133.129 with SMTP id f1mr56902799plf.64.1480397712950; Mon, 28 Nov 2016 21:35:12 -0800 (PST) Received: from localhost ([122.172.89.192]) by smtp.gmail.com with ESMTPSA id r2sm91196161pfi.67.2016.11.28.21.35.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Nov 2016 21:35:12 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , jy0922.shim@samsung.com, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Viresh Kumar , "# v4 . 4+" Subject: [PATCH V2] PM / OPP: Allow inactive opp_device to be present in dev list Date: Tue, 29 Nov 2016 11:04:52 +0530 Message-Id: <3bb7733d915c2e3e1cfcda8b8c798294a3c6ebbd.1480397575.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Joonyoung Shim reported an interesting problem on his ARM octa-core Odoroid-XU3 platform. During system suspend, dev_pm_opp_put_regulator() was failing for a struct device for which dev_pm_opp_set_regulator() is called earlier. This happened because an earlier call to dev_pm_opp_of_cpumask_remove_table() function (from cpufreq-dt.c file) removed all the entries from opp_table->dev_list apart from the last CPU device in the cpumask of CPUs sharing the OPP. But both dev_pm_opp_set_regulator() and dev_pm_opp_put_regulator() routines get CPU device for the first CPU in the cpumask. And so the OPP core failed to find the OPP table for the struct device. In order to fix that up properly, we need to revisit APIs like dev_pm_opp_set_regulator() and make them talk in terms of cookies provided by the OPP core. But such a solution will be hard to backport to stable kernels. This patch attempts to fix this problem (in a Hacky way) by specially handling the first cpu in the mask. A FIXME is also added to make sure that this Hack doesn't get unnoticed later on. Cc: # v4.4+ Signed-off-by: Viresh Kumar --- V1->V2: - A completely different approach, more of hack so that backport to stable kernels can be done easily. - A more comprehensive solution is required to fix the design flaws. drivers/base/power/opp/cpu.c | 50 +++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) -- 2.7.1.410.g6faf27b -- To unsubscribe from this list: send the line "unsubscribe linux-pm" 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/drivers/base/power/opp/cpu.c b/drivers/base/power/opp/cpu.c index 8c3434bdb26d..5d1b0f98bcb0 100644 --- a/drivers/base/power/opp/cpu.c +++ b/drivers/base/power/opp/cpu.c @@ -118,26 +118,46 @@ void dev_pm_opp_free_cpufreq_table(struct device *dev, EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table); #endif /* CONFIG_CPU_FREQ */ +void _cpu_remove_table(unsigned int cpu, bool of) +{ + struct device *cpu_dev = get_cpu_device(cpu); + + if (!cpu_dev) { + pr_err("%s: failed to get cpu%d device\n", __func__, cpu); + return; + } + + if (of) + dev_pm_opp_of_remove_table(cpu_dev); + else + dev_pm_opp_remove_table(cpu_dev); +} + void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of) { - struct device *cpu_dev; - int cpu; + struct cpumask tmpmask; + int cpu, first_cpu; WARN_ON(cpumask_empty(cpumask)); - for_each_cpu(cpu, cpumask) { - cpu_dev = get_cpu_device(cpu); - if (!cpu_dev) { - pr_err("%s: failed to get cpu%d device\n", __func__, - cpu); - continue; - } - - if (of) - dev_pm_opp_of_remove_table(cpu_dev); - else - dev_pm_opp_remove_table(cpu_dev); - } + /* + * The first cpu in the cpumask is important as that is used to create + * the opp-table initially and routines like dev_pm_opp_put_regulator() + * will expect the list-dev for the first CPU to be present while such + * routines are called, otherwise we will fail to find the opp-table for + * such devices. + * + * FIXME: Cleanup this mess and implement cookie based solutions instead + * of working on the device pointer. + */ + first_cpu = cpumask_first(cpumask); + cpumask_copy(&tmpmask, cpumask); + cpumask_clear_cpu(first_cpu, &tmpmask); + + for_each_cpu(cpu, &tmpmask) + _cpu_remove_table(cpu, of); + + _cpu_remove_table(first_cpu, of); } /**