From patchwork Thu Mar 16 05:29:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 95377 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp660673qgd; Wed, 15 Mar 2017 22:30:32 -0700 (PDT) X-Received: by 10.99.99.1 with SMTP id x1mr7828077pgb.134.1489642232247; Wed, 15 Mar 2017 22:30:32 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d82si2946670pfe.328.2017.03.15.22.30.32; Wed, 15 Mar 2017 22:30:32 -0700 (PDT) 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=pass 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751565AbdCPFa1 (ORCPT + 13 others); Thu, 16 Mar 2017 01:30:27 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:34398 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751524AbdCPFa0 (ORCPT ); Thu, 16 Mar 2017 01:30:26 -0400 Received: by mail-pf0-f172.google.com with SMTP id v190so18981942pfb.1 for ; Wed, 15 Mar 2017 22:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=FsPDJCZbMHm7p09r/mrEt1bv4BcN7YYEo4DktZdv/z8=; b=JKCHqs1bQSIizg8Ol/qYgqqLQDQmjDcVd/aaya4gu/MPy52Jv+z+YOV5QpagxWPLas tQonCql3F2cgEdLoIOr46tllkx2oNIuCUjYYAqn2VRNiezL3A0ADdwAxMHlmf4kw2OAe lnnUKi7NlI5nU54MgNWPSDb2E72sRo235C7RM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=FsPDJCZbMHm7p09r/mrEt1bv4BcN7YYEo4DktZdv/z8=; b=suDU/PwFr7vwsh5sGOFST92Bhk0QLQmLsW8lafOMyMyusL2En/YAlrhyVbjSWat+9o y7lvw46vULAuxj5+7PJkZbiagQESSKQXmIHtD0pE0hYvLzDF8Lkxdrtn3Jk3GEOwrUVO 6TWxRY2fCU7Atg89SE7y8wQ08Pxw3xa2L7/nbN+t1suiMsniko1ldc/hGPMHVHAdE9Cj t1DtNcyjjGnzdqE4maQmxiH+5BWg+fYzAJ5nGlEyNxL7LWILc+MZL7qtOEUolgMIina9 uxlG4C7lc3AUwOI8cy5nzSs0Dfsxh1uJqF4ExFIYVqEoz2gZnV7EUtcysf0wzSvi2hJ2 aukQ== X-Gm-Message-State: AFeK/H1IeBKfIwFNOPXnI5+bm3UMr0BE2qP3niekEkASFZ3CBqmzPw1RQBRQuZpQ0wn5ot5f X-Received: by 10.99.125.68 with SMTP id m4mr8103274pgn.13.1489642219559; Wed, 15 Mar 2017 22:30:19 -0700 (PDT) Received: from localhost ([122.171.239.200]) by smtp.gmail.com with ESMTPSA id m12sm7457666pgc.46.2017.03.15.22.30.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 22:30:18 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Javi Merino , Zhang Rui , Eduardo Valentin , Viresh Kumar , Sudeep Holla , Amit Daniel Kachhap , Keerthy Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , linux-omap@vger.kernel.org Subject: [PATCH 07/17] thermal: cpu_cooling: use cpufreq_policy to register cooling device Date: Thu, 16 Mar 2017 10:59:42 +0530 Message-Id: <49002ee5678fadd27987b3ec322f2773614a95e3.1489640000.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The CPU cooling driver uses the cpufreq policy, to get clip_cpus, the frequency table, etc. Most of the callers of CPU cooling driver's registration routines have the cpufreq policy with them, but they only pass the policy->related_cpus cpumask. The __cpufreq_cooling_register() routine then gets the policy by itself and uses it. It would be much better if the callers can pass the policy instead directly. This also fixes a basic design flaw, where the policy can be freed while the CPU cooling driver is still active. Signed-off-by: Viresh Kumar --- drivers/cpufreq/arm_big_little.c | 2 +- drivers/cpufreq/cpufreq-dt.c | 2 +- drivers/cpufreq/dbx500-cpufreq.c | 2 +- drivers/cpufreq/mt8173-cpufreq.c | 4 +- drivers/cpufreq/qoriq-cpufreq.c | 3 +- drivers/thermal/cpu_cooling.c | 60 ++++++++-------------- drivers/thermal/imx_thermal.c | 22 ++++++-- drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 22 +++++--- include/linux/cpu_cooling.h | 26 +++++----- 9 files changed, 71 insertions(+), 72 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/cpufreq/arm_big_little.c b/drivers/cpufreq/arm_big_little.c index 418042201e6d..ea6d62547b10 100644 --- a/drivers/cpufreq/arm_big_little.c +++ b/drivers/cpufreq/arm_big_little.c @@ -540,7 +540,7 @@ static void bL_cpufreq_ready(struct cpufreq_policy *policy) &power_coefficient); cdev[cur_cluster] = of_cpufreq_power_cooling_register(np, - policy->related_cpus, power_coefficient, NULL); + policy, power_coefficient, NULL); if (IS_ERR(cdev[cur_cluster])) { dev_err(cpu_dev, "running cpufreq without cooling device: %ld\n", diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index c943787d761e..fef3c2160691 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -326,7 +326,7 @@ static void cpufreq_ready(struct cpufreq_policy *policy) &power_coefficient); priv->cdev = of_cpufreq_power_cooling_register(np, - policy->related_cpus, power_coefficient, NULL); + policy, power_coefficient, NULL); if (IS_ERR(priv->cdev)) { dev_err(priv->cpu_dev, "running cpufreq without cooling device: %ld\n", diff --git a/drivers/cpufreq/dbx500-cpufreq.c b/drivers/cpufreq/dbx500-cpufreq.c index 3575b82210ba..4ee0431579c1 100644 --- a/drivers/cpufreq/dbx500-cpufreq.c +++ b/drivers/cpufreq/dbx500-cpufreq.c @@ -43,7 +43,7 @@ static int dbx500_cpufreq_exit(struct cpufreq_policy *policy) static void dbx500_cpufreq_ready(struct cpufreq_policy *policy) { - cdev = cpufreq_cooling_register(policy->cpus); + cdev = cpufreq_cooling_register(policy); if (IS_ERR(cdev)) pr_err("Failed to register cooling device %ld\n", PTR_ERR(cdev)); else diff --git a/drivers/cpufreq/mt8173-cpufreq.c b/drivers/cpufreq/mt8173-cpufreq.c index fd1886faf33a..f9f00fb4bc3a 100644 --- a/drivers/cpufreq/mt8173-cpufreq.c +++ b/drivers/cpufreq/mt8173-cpufreq.c @@ -320,9 +320,7 @@ static void mtk_cpufreq_ready(struct cpufreq_policy *policy) of_property_read_u32(np, DYNAMIC_POWER, &capacitance); info->cdev = of_cpufreq_power_cooling_register(np, - policy->related_cpus, - capacitance, - NULL); + policy, capacitance, NULL); if (IS_ERR(info->cdev)) { dev_err(info->cpu_dev, diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c index e2ea433a5f9c..4ada55b8856e 100644 --- a/drivers/cpufreq/qoriq-cpufreq.c +++ b/drivers/cpufreq/qoriq-cpufreq.c @@ -278,8 +278,7 @@ static void qoriq_cpufreq_ready(struct cpufreq_policy *policy) struct device_node *np = of_get_cpu_node(policy->cpu, NULL); if (of_find_property(np, "#cooling-cells", NULL)) { - cpud->cdev = of_cpufreq_cooling_register(np, - policy->related_cpus); + cpud->cdev = of_cpufreq_cooling_register(np, policy); if (IS_ERR(cpud->cdev) && PTR_ERR(cpud->cdev) != -ENOSYS) { pr_err("cpu%d is not running as cooling device: %ld\n", diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 46e90122b746..a97ebb7bf27f 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -718,7 +718,7 @@ static unsigned int find_next_max(struct cpufreq_frequency_table *table, /** * __cpufreq_cooling_register - helper function to create cpufreq cooling device * @np: a valid struct device_node to the cooling device device tree node - * @clip_cpus: cpumask of cpus where the frequency constraints will happen. + * @policy: cpufreq policy * Normally this should be same as cpufreq policy->related_cpus. * @capacitance: dynamic power coefficient for these cpus * @plat_static_func: function to calculate the static power consumed by these @@ -734,44 +734,28 @@ static unsigned int find_next_max(struct cpufreq_frequency_table *table, */ static struct thermal_cooling_device * __cpufreq_cooling_register(struct device_node *np, - const struct cpumask *clip_cpus, u32 capacitance, + struct cpufreq_policy *policy, u32 capacitance, get_static_t plat_static_func) { - struct cpufreq_policy *policy; struct thermal_cooling_device *cdev; struct cpufreq_cooling_device *cpufreq_dev; char dev_name[THERMAL_NAME_LENGTH]; struct cpufreq_frequency_table *pos, *table; - cpumask_var_t temp_mask; unsigned int freq, i, num_cpus; int ret; struct thermal_cooling_device_ops *cooling_ops; - if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL)) - return ERR_PTR(-ENOMEM); - - cpumask_and(temp_mask, clip_cpus, cpu_online_mask); - policy = cpufreq_cpu_get(cpumask_first(temp_mask)); - if (!policy) { - pr_debug("%s: CPUFreq policy not found\n", __func__); - cdev = ERR_PTR(-EPROBE_DEFER); - goto free_cpumask; - } - table = policy->freq_table; if (!table) { pr_debug("%s: CPUFreq table not found\n", __func__); - cdev = ERR_PTR(-ENODEV); - goto put_policy; + return ERR_PTR(-ENODEV); } cpufreq_dev = kzalloc(sizeof(*cpufreq_dev), GFP_KERNEL); - if (!cpufreq_dev) { - cdev = ERR_PTR(-ENOMEM); - goto put_policy; - } + if (!cpufreq_dev) + return ERR_PTR(-ENOMEM); - num_cpus = cpumask_weight(clip_cpus); + num_cpus = cpumask_weight(policy->related_cpus); cpufreq_dev->time_in_idle = kcalloc(num_cpus, sizeof(*cpufreq_dev->time_in_idle), GFP_KERNEL); @@ -802,7 +786,7 @@ __cpufreq_cooling_register(struct device_node *np, /* max_level is an index, not a counter */ cpufreq_dev->max_level--; - cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); + cpumask_copy(&cpufreq_dev->allowed_cpus, policy->related_cpus); if (capacitance) { cpufreq_dev->plat_get_static_power = plat_static_func; @@ -857,7 +841,7 @@ __cpufreq_cooling_register(struct device_node *np, CPUFREQ_POLICY_NOTIFIER); mutex_unlock(&cooling_list_lock); - goto put_policy; + return cdev; remove_ida: ida_simple_remove(&cpufreq_ida, cpufreq_dev->id); @@ -871,16 +855,12 @@ __cpufreq_cooling_register(struct device_node *np, kfree(cpufreq_dev->time_in_idle); free_cdev: kfree(cpufreq_dev); -put_policy: - cpufreq_cpu_put(policy); -free_cpumask: - free_cpumask_var(temp_mask); return cdev; } /** * cpufreq_cooling_register - function to create cpufreq cooling device. - * @clip_cpus: cpumask of cpus where the frequency constraints will happen. + * @policy: cpufreq policy * * This interface function registers the cpufreq cooling device with the name * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq @@ -890,16 +870,16 @@ __cpufreq_cooling_register(struct device_node *np, * on failure, it returns a corresponding ERR_PTR(). */ struct thermal_cooling_device * -cpufreq_cooling_register(const struct cpumask *clip_cpus) +cpufreq_cooling_register(struct cpufreq_policy *policy) { - return __cpufreq_cooling_register(NULL, clip_cpus, 0, NULL); + return __cpufreq_cooling_register(NULL, policy, 0, NULL); } EXPORT_SYMBOL_GPL(cpufreq_cooling_register); /** * of_cpufreq_cooling_register - function to create cpufreq cooling device. * @np: a valid struct device_node to the cooling device device tree node - * @clip_cpus: cpumask of cpus where the frequency constraints will happen. + * @policy: cpufreq policy * * This interface function registers the cpufreq cooling device with the name * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq @@ -911,18 +891,18 @@ EXPORT_SYMBOL_GPL(cpufreq_cooling_register); */ struct thermal_cooling_device * of_cpufreq_cooling_register(struct device_node *np, - const struct cpumask *clip_cpus) + struct cpufreq_policy *policy) { if (!np) return ERR_PTR(-EINVAL); - return __cpufreq_cooling_register(np, clip_cpus, 0, NULL); + return __cpufreq_cooling_register(np, policy, 0, NULL); } EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); /** * cpufreq_power_cooling_register() - create cpufreq cooling device with power extensions - * @clip_cpus: cpumask of cpus where the frequency constraints will happen + * @policy: cpufreq policy * @capacitance: dynamic power coefficient for these cpus * @plat_static_func: function to calculate the static power consumed by these * cpus (optional) @@ -942,10 +922,10 @@ EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); * on failure, it returns a corresponding ERR_PTR(). */ struct thermal_cooling_device * -cpufreq_power_cooling_register(const struct cpumask *clip_cpus, u32 capacitance, +cpufreq_power_cooling_register(struct cpufreq_policy *policy, u32 capacitance, get_static_t plat_static_func) { - return __cpufreq_cooling_register(NULL, clip_cpus, capacitance, + return __cpufreq_cooling_register(NULL, policy, capacitance, plat_static_func); } EXPORT_SYMBOL(cpufreq_power_cooling_register); @@ -953,7 +933,7 @@ EXPORT_SYMBOL(cpufreq_power_cooling_register); /** * of_cpufreq_power_cooling_register() - create cpufreq cooling device with power extensions * @np: a valid struct device_node to the cooling device device tree node - * @clip_cpus: cpumask of cpus where the frequency constraints will happen + * @policy: cpufreq policy * @capacitance: dynamic power coefficient for these cpus * @plat_static_func: function to calculate the static power consumed by these * cpus (optional) @@ -975,14 +955,14 @@ EXPORT_SYMBOL(cpufreq_power_cooling_register); */ struct thermal_cooling_device * of_cpufreq_power_cooling_register(struct device_node *np, - const struct cpumask *clip_cpus, + struct cpufreq_policy *policy, u32 capacitance, get_static_t plat_static_func) { if (!np) return ERR_PTR(-EINVAL); - return __cpufreq_cooling_register(np, clip_cpus, capacitance, + return __cpufreq_cooling_register(np, policy, capacitance, plat_static_func); } EXPORT_SYMBOL(of_cpufreq_power_cooling_register); diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index fb648a45754e..f7ec39f46ee4 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -88,6 +89,7 @@ static struct thermal_soc_data thermal_imx6sx_data = { }; struct imx_thermal_data { + struct cpufreq_policy *policy; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; enum thermal_device_mode mode; @@ -525,13 +527,18 @@ static int imx_thermal_probe(struct platform_device *pdev) regmap_write(map, MISC0 + REG_SET, MISC0_REFTOP_SELBIASOFF); regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); - data->cdev = cpufreq_cooling_register(cpu_present_mask); + data->policy = cpufreq_cpu_get(0); + if (!data->policy) { + pr_debug("%s: CPUFreq policy not found\n", __func__); + return -EPROBE_DEFER; + } + + data->cdev = cpufreq_cooling_register(data->policy); if (IS_ERR(data->cdev)) { ret = PTR_ERR(data->cdev); - if (ret != -EPROBE_DEFER) - dev_err(&pdev->dev, - "failed to register cpufreq cooling device: %d\n", - ret); + dev_err(&pdev->dev, + "failed to register cpufreq cooling device: %d\n", ret); + cpufreq_cpu_put(data->policy); return ret; } @@ -542,6 +549,7 @@ static int imx_thermal_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to get thermal clk: %d\n", ret); cpufreq_cooling_unregister(data->cdev); + cpufreq_cpu_put(data->policy); return ret; } @@ -556,6 +564,7 @@ static int imx_thermal_probe(struct platform_device *pdev) if (ret) { dev_err(&pdev->dev, "failed to enable thermal clk: %d\n", ret); cpufreq_cooling_unregister(data->cdev); + cpufreq_cpu_put(data->policy); return ret; } @@ -571,6 +580,7 @@ static int imx_thermal_probe(struct platform_device *pdev) "failed to register thermal zone device %d\n", ret); clk_disable_unprepare(data->thermal_clk); cpufreq_cooling_unregister(data->cdev); + cpufreq_cpu_put(data->policy); return ret; } @@ -599,6 +609,7 @@ static int imx_thermal_probe(struct platform_device *pdev) clk_disable_unprepare(data->thermal_clk); thermal_zone_device_unregister(data->tz); cpufreq_cooling_unregister(data->cdev); + cpufreq_cpu_put(data->policy); return ret; } @@ -620,6 +631,7 @@ static int imx_thermal_remove(struct platform_device *pdev) thermal_zone_device_unregister(data->tz); cpufreq_cooling_unregister(data->cdev); + cpufreq_cpu_put(data->policy); return 0; } diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c index 0586bd0f2bab..cfc851d76d4b 100644 --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ /* common data structures */ struct ti_thermal_data { + struct cpufreq_policy *policy; struct thermal_zone_device *ti_thermal; struct thermal_zone_device *pcb_tz; struct thermal_cooling_device *cool_dev; @@ -395,15 +397,19 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) if (!data) return -EINVAL; + data->policy = cpufreq_cpu_get(0); + if (!data->policy) { + pr_debug("%s: CPUFreq policy not found\n", __func__); + return -EPROBE_DEFER; + } + /* Register cooling device */ - data->cool_dev = cpufreq_cooling_register(cpu_present_mask); + data->cool_dev = cpufreq_cooling_register(data->policy); if (IS_ERR(data->cool_dev)) { int ret = PTR_ERR(data->cool_dev); - - if (ret != -EPROBE_DEFER) - dev_err(bgp->dev, - "Failed to register cpu cooling device %d\n", - ret); + dev_err(bgp->dev, "Failed to register cpu cooling device %d\n", + ret); + cpufreq_cpu_put(data->policy); return ret; } @@ -418,8 +424,10 @@ int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id) data = ti_bandgap_get_sensor_data(bgp, id); - if (data) + if (data) { cpufreq_cooling_unregister(data->cool_dev); + cpufreq_cpu_put(data->policy); + } return 0; } diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h index 96c5e4c2f9c8..d4292ebc5c8b 100644 --- a/include/linux/cpu_cooling.h +++ b/include/linux/cpu_cooling.h @@ -28,47 +28,49 @@ #include #include +struct cpufreq_policy; + typedef int (*get_static_t)(cpumask_t *cpumask, int interval, unsigned long voltage, u32 *power); #ifdef CONFIG_CPU_THERMAL /** * cpufreq_cooling_register - function to create cpufreq cooling device. - * @clip_cpus: cpumask of cpus where the frequency constraints will happen + * @policy: cpufreq policy. */ struct thermal_cooling_device * -cpufreq_cooling_register(const struct cpumask *clip_cpus); +cpufreq_cooling_register(struct cpufreq_policy *policy); struct thermal_cooling_device * -cpufreq_power_cooling_register(const struct cpumask *clip_cpus, +cpufreq_power_cooling_register(struct cpufreq_policy *policy, u32 capacitance, get_static_t plat_static_func); /** * of_cpufreq_cooling_register - create cpufreq cooling device based on DT. * @np: a valid struct device_node to the cooling device device tree node. - * @clip_cpus: cpumask of cpus where the frequency constraints will happen + * @policy: cpufreq policy. */ #ifdef CONFIG_THERMAL_OF struct thermal_cooling_device * of_cpufreq_cooling_register(struct device_node *np, - const struct cpumask *clip_cpus); + struct cpufreq_policy *policy); struct thermal_cooling_device * of_cpufreq_power_cooling_register(struct device_node *np, - const struct cpumask *clip_cpus, + struct cpufreq_policy *policy, u32 capacitance, get_static_t plat_static_func); #else static inline struct thermal_cooling_device * of_cpufreq_cooling_register(struct device_node *np, - const struct cpumask *clip_cpus) + struct cpufreq_policy *policy) { return ERR_PTR(-ENOSYS); } static inline struct thermal_cooling_device * of_cpufreq_power_cooling_register(struct device_node *np, - const struct cpumask *clip_cpus, + struct cpufreq_policy *policy, u32 capacitance, get_static_t plat_static_func) { @@ -84,12 +86,12 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev); #else /* !CONFIG_CPU_THERMAL */ static inline struct thermal_cooling_device * -cpufreq_cooling_register(const struct cpumask *clip_cpus) +cpufreq_cooling_register(struct cpufreq_policy *policy) { return ERR_PTR(-ENOSYS); } static inline struct thermal_cooling_device * -cpufreq_power_cooling_register(const struct cpumask *clip_cpus, +cpufreq_power_cooling_register(struct cpufreq_policy *policy, u32 capacitance, get_static_t plat_static_func) { return NULL; @@ -97,14 +99,14 @@ cpufreq_power_cooling_register(const struct cpumask *clip_cpus, static inline struct thermal_cooling_device * of_cpufreq_cooling_register(struct device_node *np, - const struct cpumask *clip_cpus) + struct cpufreq_policy *policy) { return ERR_PTR(-ENOSYS); } static inline struct thermal_cooling_device * of_cpufreq_power_cooling_register(struct device_node *np, - const struct cpumask *clip_cpus, + struct cpufreq_policy *policy, u32 capacitance, get_static_t plat_static_func) { From patchwork Thu Mar 16 05:29:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 95387 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp661266qgd; Wed, 15 Mar 2017 22:32:38 -0700 (PDT) X-Received: by 10.99.245.21 with SMTP id w21mr7797402pgh.33.1489642358435; Wed, 15 Mar 2017 22:32:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k80si2958658pfk.272.2017.03.15.22.32.38; Wed, 15 Mar 2017 22:32:38 -0700 (PDT) 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=pass 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751918AbdCPFch (ORCPT + 13 others); Thu, 16 Mar 2017 01:32:37 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:35028 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751577AbdCPFae (ORCPT ); Thu, 16 Mar 2017 01:30:34 -0400 Received: by mail-pf0-f176.google.com with SMTP id x63so13585837pfx.2 for ; Wed, 15 Mar 2017 22:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=L1YaUY203qGcmTbO35M18mXykg/bJ1YrlR5dUCmKm1g=; b=WvyvJUZatPpkDJnAgqRoPY7k3mE5LviGnLsMvQSCVitFCxQAd9oztqT70R2rUpA0Wn CH9QfmORIbzmlSclaevoQ3i1/iku4bjvTb1k+etgSG6UKDuQRmwO8rClsubxGqy1YcDA szachjy/LUw9fuuFbWG7Rm9Wzlk4whwl/ps8o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=L1YaUY203qGcmTbO35M18mXykg/bJ1YrlR5dUCmKm1g=; b=hb9FV1K2IqYUjmebmngtacUMNmjQf3irbyGhqpv1cyYBmUa8pXN+cNMP596dC77FHc Wz6YcatkAa7lt2bbZbKDhHgTMve1QKG/Hv3V6RXE9Q4rhG/QsC5EEsujK74BvR+nWkjh /sqqBMea/m2nnVEzb+RxMYx5sagBIBEhxK7dN1tVV2Hg4CQl+4uhHTQ2cQ7Hu8c8MU1m UruMEeOC5sTznxqYGa/67qSnaHmlske1o+5I0SlG2xDdH9+l0KX1Z3moV4E7VMdCyS29 c6JsEeOfgt0QIEnAQUvVmJmRpi9hkHtc+RVbqyfJUGfh0CPaM0jfU7dV01Q/IKy/Bn0A Uh4A== X-Gm-Message-State: AFeK/H3CAx3WOmJq1vcC8TlmvUY4ceCTXMtiUnpPqcBeud/IogsLaQuZJ1HjIqslndOOwl+m X-Received: by 10.98.210.133 with SMTP id c127mr7947868pfg.83.1489642222856; Wed, 15 Mar 2017 22:30:22 -0700 (PDT) Received: from localhost ([122.171.239.200]) by smtp.gmail.com with ESMTPSA id m12sm7458152pgc.46.2017.03.15.22.30.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 22:30:22 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Javi Merino , Zhang Rui , Eduardo Valentin , Viresh Kumar , Amit Daniel Kachhap Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot Subject: [PATCH 08/17] cpufreq: create cpufreq_table_count_valid_entries() Date: Thu, 16 Mar 2017 10:59:43 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We need such a routine at two places already, lets create one. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq_stats.c | 13 ++++--------- drivers/thermal/cpu_cooling.c | 22 +++++++++------------- include/linux/cpufreq.h | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 22 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index f570ead62454..9c3d319dc129 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -170,11 +170,10 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy) unsigned int i = 0, count = 0, ret = -ENOMEM; struct cpufreq_stats *stats; unsigned int alloc_size; - struct cpufreq_frequency_table *pos, *table; + struct cpufreq_frequency_table *pos; - /* We need cpufreq table for creating stats table */ - table = policy->freq_table; - if (unlikely(!table)) + count = cpufreq_table_count_valid_entries(policy); + if (!count) return; /* stats already initialized */ @@ -185,10 +184,6 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy) if (!stats) return; - /* Find total allocation size */ - cpufreq_for_each_valid_entry(pos, table) - count++; - alloc_size = count * sizeof(int) + count * sizeof(u64); alloc_size += count * count * sizeof(int); @@ -205,7 +200,7 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy) stats->max_state = count; /* Find valid-unique entries */ - cpufreq_for_each_valid_entry(pos, table) + cpufreq_for_each_valid_entry(pos, policy->freq_table) if (freq_table_get_index(stats, pos->frequency) == -1) stats->freq_table[i++] = pos->frequency; diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index a97ebb7bf27f..2c169fee693e 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -740,14 +740,14 @@ __cpufreq_cooling_register(struct device_node *np, struct thermal_cooling_device *cdev; struct cpufreq_cooling_device *cpufreq_dev; char dev_name[THERMAL_NAME_LENGTH]; - struct cpufreq_frequency_table *pos, *table; unsigned int freq, i, num_cpus; int ret; struct thermal_cooling_device_ops *cooling_ops; - table = policy->freq_table; - if (!table) { - pr_debug("%s: CPUFreq table not found\n", __func__); + i = cpufreq_table_count_valid_entries(policy); + if (!i) { + pr_debug("%s: CPUFreq table not found or has no valid entries\n", + __func__); return ERR_PTR(-ENODEV); } @@ -772,20 +772,16 @@ __cpufreq_cooling_register(struct device_node *np, goto free_time_in_idle; } - /* Find max levels */ - cpufreq_for_each_valid_entry(pos, table) - cpufreq_dev->max_level++; + /* max_level is an index, not a counter */ + cpufreq_dev->max_level = i - 1; - cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) * - cpufreq_dev->max_level, GFP_KERNEL); + cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) * i, + GFP_KERNEL); if (!cpufreq_dev->freq_table) { cdev = ERR_PTR(-ENOMEM); goto free_time_in_idle_timestamp; } - /* max_level is an index, not a counter */ - cpufreq_dev->max_level--; - cpumask_copy(&cpufreq_dev->allowed_cpus, policy->related_cpus); if (capacitance) { @@ -811,7 +807,7 @@ __cpufreq_cooling_register(struct device_node *np, /* Fill freq-table in descending order of frequencies */ for (i = 0, freq = -1; i <= cpufreq_dev->max_level; i++) { - freq = find_next_max(table, freq); + freq = find_next_max(policy->freq_table, freq); cpufreq_dev->freq_table[i] = freq; /* Warn for duplicate entries */ diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 87165f06a307..affc13568af6 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -855,6 +855,20 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy, return -EINVAL; } } + +static inline int cpufreq_table_count_valid_entries(const struct cpufreq_policy *policy) +{ + struct cpufreq_frequency_table *pos; + int count = 0; + + if (unlikely(!policy->freq_table)) + return 0; + + cpufreq_for_each_valid_entry(pos, policy->freq_table) + count++; + + return count; +} #else static inline int cpufreq_boost_trigger_state(int state) { From patchwork Thu Mar 16 05:29:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 95386 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp661236qgd; Wed, 15 Mar 2017 22:32:31 -0700 (PDT) X-Received: by 10.98.72.88 with SMTP id v85mr7920099pfa.99.1489642350940; Wed, 15 Mar 2017 22:32:30 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k80si2958658pfk.272.2017.03.15.22.32.30; Wed, 15 Mar 2017 22:32:30 -0700 (PDT) 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=pass 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751667AbdCPFak (ORCPT + 13 others); Thu, 16 Mar 2017 01:30:40 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:35907 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751638AbdCPFaf (ORCPT ); Thu, 16 Mar 2017 01:30:35 -0400 Received: by mail-pf0-f172.google.com with SMTP id o126so18994103pfb.3 for ; Wed, 15 Mar 2017 22:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=W4mXduu0wjv/eACg7byHuaSvBsKv+IC/7961nKcsOFk=; b=Cm7ixbPHscQQ3m6r0jtzaVamO1Js6ORicDIqpyEPjAUwvTjjOus1BznGOXWToJdtj0 PYUqYsEYj8F5RIcpzogsxcIwjYG0VZqLVDNTgowhB+I0ehsjebj1oAid1IBWKZ8JnpTu O7IkaM2qynJgRGrqHYLjuKKfJFW1UpYip1bHU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=W4mXduu0wjv/eACg7byHuaSvBsKv+IC/7961nKcsOFk=; b=EX5SO7YEGbRCH22LfpSr6DlWNKArEQoGIBZ8wSCQZTEZgnjgA7F0as+t74B6uYQXc+ ao0N+CLTrUOGhc8zVVPTc196pfDB3hCTYi93HeIwtPjAnakeP+Adr8jQdvv5mKOZ4OrA 2YJXhu9HwL3CV/nDE8fJ8qb/+nTThZihXqFEJ3UNjdsPqiIH2Mc6UxaqpVt67O/vHicp NkkvoH2lhlvifD5wbTsP2qudEjBJF5Sae9oj1/tVohB25QJOjCH6rkNywFb4/A9zryFS kl27vS8KJIOiNdAEIu1c2QGvdAOJ3M/+DMciiwBzx7aUJNyu1AynXiyLrS8M5XSif/sM OkuQ== X-Gm-Message-State: AFeK/H0B6Gbq1t0daoZuTdnmNM/TFZFWBvrXWCsStiRkw/HhyiSUNVNkcAdGbxMIz/G8wgzt X-Received: by 10.98.103.146 with SMTP id t18mr8173273pfj.135.1489642229029; Wed, 15 Mar 2017 22:30:29 -0700 (PDT) Received: from localhost ([122.171.239.200]) by smtp.gmail.com with ESMTPSA id b8sm7500214pgn.6.2017.03.15.22.30.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 22:30:28 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Javi Merino , Zhang Rui , Eduardo Valentin , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot Subject: [PATCH 10/17] thermal: cpu_cooling: OPPs are registered for all CPUs Date: Thu, 16 Mar 2017 10:59:45 +0530 Message-Id: <7a99a212c7c7b4a0b8ce9cc723bb2f16b7ef0962.1489640000.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The OPPs are registered for all CPUs of a cpufreq policy now and we don't need to run the loop in build_dyn_power_table(). Just check for the policy->cpu and we should be fine. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 7590279bf1de..1df6c9039e45 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -83,7 +83,7 @@ struct power_table { * @dyn_power_table: array of struct power_table for frequency to power * conversion, sorted in ascending order. * @dyn_power_table_entries: number of entries in the @dyn_power_table array - * @cpu_dev: the first cpu_device from @allowed_cpus that has OPPs registered + * @cpu_dev: the cpu_device of policy->cpu. * @plat_get_static_power: callback to calculate the static power * * This structure is required for keeping information of each registered @@ -208,24 +208,20 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_dev, struct power_table *power_table; struct dev_pm_opp *opp; struct device *dev = NULL; - int num_opps = 0, cpu, i, ret = 0; + int num_opps = 0, cpu = cpufreq_dev->policy->cpu, i, ret = 0; unsigned long freq; - for_each_cpu(cpu, &cpufreq_dev->allowed_cpus) { - dev = get_cpu_device(cpu); - if (!dev) { - dev_warn(&cpufreq_dev->cdev->device, - "No cpu device for cpu %d\n", cpu); - continue; - } - - num_opps = dev_pm_opp_get_opp_count(dev); - if (num_opps > 0) - break; - else if (num_opps < 0) - return num_opps; + dev = get_cpu_device(cpu); + if (unlikely(!dev)) { + dev_warn(&cpufreq_dev->cdev->device, + "No cpu device for cpu %d\n", cpu); + return -ENODEV; } + num_opps = dev_pm_opp_get_opp_count(dev); + if (num_opps < 0) + return num_opps; + if (num_opps == 0) return -EINVAL; From patchwork Thu Mar 16 05:29:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 95383 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp660844qgd; Wed, 15 Mar 2017 22:31:09 -0700 (PDT) X-Received: by 10.84.129.67 with SMTP id 61mr9858150plb.16.1489642269424; Wed, 15 Mar 2017 22:31:09 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si2965884pfk.113.2017.03.15.22.31.09; Wed, 15 Mar 2017 22:31:09 -0700 (PDT) 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=pass 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751787AbdCPFa6 (ORCPT + 13 others); Thu, 16 Mar 2017 01:30:58 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:36202 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751286AbdCPFa4 (ORCPT ); Thu, 16 Mar 2017 01:30:56 -0400 Received: by mail-pg0-f45.google.com with SMTP id g2so19548198pge.3 for ; Wed, 15 Mar 2017 22:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=SUCE7hhGNTwZbcdP8Jf8Sn1cZJamsaSV6A82ICsj63U=; b=Sycr/gUMrJMvKn3c5WTBiMYeXCapaAWyTZkCprd7gkkKHDk0Va0M2JBv5CIiaNLC4v 0sS/hNLMgxSRfYvH/Bw4oVd/aKaDTLq7VGULm6ERQwNdysiWMabYofa9Fg1+suKeQNUt +2F9GybXZEApr4zrCt04auRsMmVLDe8AECzcg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=SUCE7hhGNTwZbcdP8Jf8Sn1cZJamsaSV6A82ICsj63U=; b=UY6KzGsjokf+X63r9fBcslE0QMYOVmRGgKcQfCi4ltjzoLSJlC2TMEGsRNDLrYCoZ/ lCVR/Iwd0zC3qrFP97SbW7humXe8OnmJnh6A8+kEjRMQxnoOHsw6fx1AdYTAaxC78VzW yKzKVox7etu18rWQWfxQHvkEiMqKU9zkTRljsp3PVNJI6O2LNCmH38KsxBu0EsnDNn8H QyqVGMoghA7sKtrfLhCmapYKgR6NUt+YR8q1pWR1+lzw0nQpPrt/1NNqnBU6obformbJ hS6dYwv337Hv+xisYptLcgtERpM+op5MH/bcndwgM4QMmn3rHRremc774yLFzAbpK70p wnkg== X-Gm-Message-State: AFeK/H3WoPAcZxbm5xhQKNcGjPwVrwV6ZBmzKKbonyFsdts7rnyleDTaRJCRb8AYIavZOaBt X-Received: by 10.99.241.21 with SMTP id f21mr7855117pgi.16.1489642245575; Wed, 15 Mar 2017 22:30:45 -0700 (PDT) Received: from localhost ([122.171.239.200]) by smtp.gmail.com with ESMTPSA id u69sm7400606pfg.121.2017.03.15.22.30.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Mar 2017 22:30:44 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Javi Merino , Zhang Rui , Eduardo Valentin , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot Subject: [PATCH 15/17] thermal: cpu_cooling: don't store cpu_dev in cpufreq_dev Date: Thu, 16 Mar 2017 10:59:50 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 'cpu_dev' is used by only one function, get_static_power(), and it wouldn't be time consuming to get the cpu device structure within it. This would help removing cpu_dev from struct cpufreq_cooling_device. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index fd84802d2e8e..fb535fd5aa12 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -87,7 +87,6 @@ struct time_in_idle { * @node: list_head to link all cpufreq_cooling_device together. * @last_load: load measured by the latest call to cpufreq_get_requested_power() * @idle_time: idle time stats - * @cpu_dev: the cpu_device of policy->cpu. * @plat_get_static_power: callback to calculate the static power * * This structure is required for keeping information of each registered @@ -104,7 +103,6 @@ struct cpufreq_cooling_device { struct list_head node; u32 last_load; struct time_in_idle *idle_time; - struct device *cpu_dev; get_static_t plat_get_static_power; }; @@ -256,8 +254,6 @@ static int update_freq_table(struct cpufreq_cooling_device *cpufreq_dev, freq_table[i].power = power; } - cpufreq_dev->cpu_dev = dev; - return 0; } @@ -339,19 +335,22 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_dev, { struct dev_pm_opp *opp; unsigned long voltage; - struct cpumask *cpumask = cpufreq_dev->policy->related_cpus; + struct cpufreq_policy *policy = cpufreq_dev->policy; + struct cpumask *cpumask = policy->related_cpus; unsigned long freq_hz = freq * 1000; + struct device *dev; - if (!cpufreq_dev->plat_get_static_power || !cpufreq_dev->cpu_dev) { + if (!cpufreq_dev->plat_get_static_power) { *power = 0; return 0; } - opp = dev_pm_opp_find_freq_exact(cpufreq_dev->cpu_dev, freq_hz, - true); + dev = get_cpu_device(policy->cpu); + WARN_ON(!dev); + + opp = dev_pm_opp_find_freq_exact(dev, freq_hz, true); if (IS_ERR(opp)) { - dev_warn_ratelimited(cpufreq_dev->cpu_dev, - "Failed to find OPP for frequency %lu: %ld\n", + dev_warn_ratelimited(dev, "Failed to find OPP for frequency %lu: %ld\n", freq_hz, PTR_ERR(opp)); return -EINVAL; } @@ -360,8 +359,7 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_dev, dev_pm_opp_put(opp); if (voltage == 0) { - dev_err_ratelimited(cpufreq_dev->cpu_dev, - "Failed to get voltage for frequency %lu\n", + dev_err_ratelimited(dev, "Failed to get voltage for frequency %lu\n", freq_hz); return -EINVAL; }