linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 1/1] thermal: cpu_cooling: check for the readiness of cpufreq layer
@ 2014-11-27 14:12 Eduardo Valentin
  2014-11-28  8:05 ` Viresh Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Eduardo Valentin @ 2014-11-27 14:12 UTC (permalink / raw)
  To: Linux PM, Viresh Kumar, Lukasz Majewski
  Cc: LKML, Eduardo Valentin, devicetree, Grant Likely, Kukjin Kim,
	linux-arm-kernel, linux-samsung-soc, Naveen Krishna Chatradhi,
	Rob Herring, Zhang Rui

In this patch, the cpu_cooling code checks for the usability of cpufreq
layer before proceeding with the CPU cooling device registration. The
main reason is: CPU cooling device is not usable if cpufreq cannot
switch frequencies.

Similar checks are spread in thermal drivers. Thus, the advantage now
is to have the check in a single place: cpu cooling device registration.
For this reason, this patch also updates the existing drivers that
depend on CPU cooling to simply propagate the error code of the cpu
cooling registration call. Therefore, in case cpufreq is not ready, the
thermal drivers will still return -EPROBE_DEFER, in an attempt to try
again when cpufreq layer gets ready.

Cc: devicetree@vger.kernel.org
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Kukjin Kim <kgene.kim@samsung.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-pm@vger.kernel.org
Cc: linux-samsung-soc@vger.kernel.org
Cc: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
---
 drivers/thermal/cpu_cooling.c                      | 5 +++++
 drivers/thermal/db8500_cpufreq_cooling.c           | 5 -----
 drivers/thermal/imx_thermal.c                      | 5 -----
 drivers/thermal/samsung/exynos_thermal_common.c    | 2 +-
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 6 ------
 5 files changed, 6 insertions(+), 17 deletions(-)
---
(I'm sorry VireshK, I am still using my normal practice) :-)

Changes from V1:
 - As per Viresh K. suggestion's, the check for cpufreq layer readiness is now
   only a simple fetch for cpufreq table.

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 1ab0018..bed3fa2 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -440,6 +440,11 @@ __cpufreq_cooling_register(struct device_node *np,
 	int ret = 0, i;
 	struct cpufreq_policy policy;
 
+	if (!cpufreq_frequency_get_table(0)) {
+		pr_err("cpu_cooling: cpufreq layer not ready! Deferring.\n");
+		return ERR_PTR(-EPROBE_DEFER);
+	}
+
 	/* Verify that all the clip cpus have same freq_min, freq_max limit */
 	for_each_cpu(i, clip_cpus) {
 		/* continue if cpufreq policy not found and not return error */
diff --git a/drivers/thermal/db8500_cpufreq_cooling.c b/drivers/thermal/db8500_cpufreq_cooling.c
index 786d192..1ac7ec6 100644
--- a/drivers/thermal/db8500_cpufreq_cooling.c
+++ b/drivers/thermal/db8500_cpufreq_cooling.c
@@ -18,7 +18,6 @@
  */
 
 #include <linux/cpu_cooling.h>
-#include <linux/cpufreq.h>
 #include <linux/err.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -30,10 +29,6 @@ static int db8500_cpufreq_cooling_probe(struct platform_device *pdev)
 	struct thermal_cooling_device *cdev;
 	struct cpumask mask_val;
 
-	/* make sure cpufreq driver has been initialized */
-	if (!cpufreq_frequency_get_table(0))
-		return -EPROBE_DEFER;
-
 	cpumask_set_cpu(0, &mask_val);
 	cdev = cpufreq_cooling_register(&mask_val);
 
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index 5a1f107..16405b4 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -9,7 +9,6 @@
 
 #include <linux/clk.h>
 #include <linux/cpu_cooling.h>
-#include <linux/cpufreq.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/init.h>
@@ -459,10 +458,6 @@ static int imx_thermal_probe(struct platform_device *pdev)
 	int measure_freq;
 	int ret;
 
-	if (!cpufreq_get_current_driver()) {
-		dev_dbg(&pdev->dev, "no cpufreq driver!");
-		return -EPROBE_DEFER;
-	}
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c
index 3f5ad25..f84975e 100644
--- a/drivers/thermal/samsung/exynos_thermal_common.c
+++ b/drivers/thermal/samsung/exynos_thermal_common.c
@@ -373,7 +373,7 @@ int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf)
 		if (IS_ERR(th_zone->cool_dev[th_zone->cool_dev_size])) {
 			dev_err(sensor_conf->dev,
 				"Failed to register cpufreq cooling device\n");
-			ret = -EINVAL;
+			ret = PTR_ERR(th_zone->cool_dev[th_zone->cool_dev_size]);
 			goto err_unregister;
 		}
 		th_zone->cool_dev_size++;
diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
index 5fd0386..cf88585 100644
--- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
@@ -28,7 +28,6 @@
 #include <linux/kernel.h>
 #include <linux/workqueue.h>
 #include <linux/thermal.h>
-#include <linux/cpufreq.h>
 #include <linux/cpumask.h>
 #include <linux/cpu_cooling.h>
 #include <linux/of.h>
@@ -407,11 +406,6 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
 	if (!data)
 		return -EINVAL;
 
-	if (!cpufreq_get_current_driver()) {
-		dev_dbg(bgp->dev, "no cpufreq driver yet\n");
-		return -EPROBE_DEFER;
-	}
-
 	/* Register cooling device */
 	data->cool_dev = cpufreq_cooling_register(cpu_present_mask);
 	if (IS_ERR(data->cool_dev)) {
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCHv2 1/1] thermal: cpu_cooling: check for the readiness of cpufreq layer
  2014-11-27 14:12 [PATCHv2 1/1] thermal: cpu_cooling: check for the readiness of cpufreq layer Eduardo Valentin
@ 2014-11-28  8:05 ` Viresh Kumar
  2014-11-28 10:18   ` Lukasz Majewski
  0 siblings, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2014-11-28  8:05 UTC (permalink / raw)
  To: Eduardo Valentin
  Cc: Linux PM, Lukasz Majewski, LKML, devicetree, Grant Likely,
	Kukjin Kim, linux-arm-kernel, linux-samsung-soc, Rob Herring,
	Zhang Rui

On 27 November 2014 at 19:42, Eduardo Valentin <edubezval@gmail.com> wrote:
> (I'm sorry VireshK, I am still using my normal practice) :-)

That's fine :)

> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
> index 1ab0018..bed3fa2 100644
> --- a/drivers/thermal/cpu_cooling.c
> +++ b/drivers/thermal/cpu_cooling.c
> @@ -440,6 +440,11 @@ __cpufreq_cooling_register(struct device_node *np,
>         int ret = 0, i;
>         struct cpufreq_policy policy;
>
> +       if (!cpufreq_frequency_get_table(0)) {
> +               pr_err("cpu_cooling: cpufreq layer not ready! Deferring.\n");

Throwing an error here doesn't look to be the right thing. Ultimately
we will register the cooling dev when probed again after some time.

So, a pr_debug() suits more here.

Also, this breaks existing exynos thermal drivers as they don't handle
-EPROBE_DEFER well right now.

I reached here, because one of my patches had something similar to what
you wrote. Just for this file though, haven't updated any other drivers though.

Will be sending you my small patchset by end of day today, please see if
they make any sense at all..

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCHv2 1/1] thermal: cpu_cooling: check for the readiness of cpufreq layer
  2014-11-28  8:05 ` Viresh Kumar
@ 2014-11-28 10:18   ` Lukasz Majewski
  2014-11-28 13:14     ` Eduardo Valentin
  0 siblings, 1 reply; 5+ messages in thread
From: Lukasz Majewski @ 2014-11-28 10:18 UTC (permalink / raw)
  To: Viresh Kumar, Eduardo Valentin
  Cc: devicetree, Lukasz Majewski, Kukjin Kim, Linux PM, LKML,
	Rob Herring, linux-samsung-soc, Grant Likely, Zhang Rui,
	linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1486 bytes --]

On Fri, 28 Nov 2014 13:35:49 +0530
Viresh Kumar <viresh.kumar@linaro.org> wrote:

> On 27 November 2014 at 19:42, Eduardo Valentin <edubezval@gmail.com>
> wrote:
> > (I'm sorry VireshK, I am still using my normal practice) :-)
> 
> That's fine :)
> 
> > diff --git a/drivers/thermal/cpu_cooling.c
> > b/drivers/thermal/cpu_cooling.c index 1ab0018..bed3fa2 100644
> > --- a/drivers/thermal/cpu_cooling.c
> > +++ b/drivers/thermal/cpu_cooling.c
> > @@ -440,6 +440,11 @@ __cpufreq_cooling_register(struct device_node
> > *np, int ret = 0, i;
> >         struct cpufreq_policy policy;
> >
> > +       if (!cpufreq_frequency_get_table(0)) {
> > +               pr_err("cpu_cooling: cpufreq layer not ready!
> > Deferring.\n");
> 
> Throwing an error here doesn't look to be the right thing. Ultimately
> we will register the cooling dev when probed again after some time.
> 
> So, a pr_debug() suits more here.
> 
> Also, this breaks existing exynos thermal drivers as they don't handle
> -EPROBE_DEFER well right now.

Unfortunately Viresh is correct here. Current (before rework) Exynos
TMU driver expects that cpu_cooling device will succeed.

> 
> I reached here, because one of my patches had something similar to
> what you wrote. Just for this file though, haven't updated any other
> drivers though.
> 
> Will be sending you my small patchset by end of day today, please see
> if they make any sense at all..

Best regards,
Łukasz Majewski

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCHv2 1/1] thermal: cpu_cooling: check for the readiness of cpufreq layer
  2014-11-28 10:18   ` Lukasz Majewski
@ 2014-11-28 13:14     ` Eduardo Valentin
  2014-11-28 13:43       ` Viresh Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Eduardo Valentin @ 2014-11-28 13:14 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Viresh Kumar, Linux PM, Lukasz Majewski, LKML, devicetree,
	Grant Likely, Kukjin Kim, linux-arm-kernel, linux-samsung-soc,
	Zhang Rui, Rob Herring

[-- Attachment #1: Type: text/plain, Size: 2926 bytes --]


Hello Folks,

On Fri, Nov 28, 2014 at 11:18:24AM +0100, Lukasz Majewski wrote:
> On Fri, 28 Nov 2014 13:35:49 +0530
> Viresh Kumar <viresh.kumar@linaro.org> wrote:
> 
> > On 27 November 2014 at 19:42, Eduardo Valentin <edubezval@gmail.com>
> > wrote:
> > > (I'm sorry VireshK, I am still using my normal practice) :-)
> > 
> > That's fine :)
> > 
> > > diff --git a/drivers/thermal/cpu_cooling.c
> > > b/drivers/thermal/cpu_cooling.c index 1ab0018..bed3fa2 100644
> > > --- a/drivers/thermal/cpu_cooling.c
> > > +++ b/drivers/thermal/cpu_cooling.c
> > > @@ -440,6 +440,11 @@ __cpufreq_cooling_register(struct device_node
> > > *np, int ret = 0, i;
> > >         struct cpufreq_policy policy;
> > >
> > > +       if (!cpufreq_frequency_get_table(0)) {
> > > +               pr_err("cpu_cooling: cpufreq layer not ready!
> > > Deferring.\n");
> > 
> > Throwing an error here doesn't look to be the right thing. Ultimately
> > we will register the cooling dev when probed again after some time.
> > 
> > So, a pr_debug() suits more here.
> > 

Yeah, I agree here. 

> > Also, this breaks existing exynos thermal drivers as they don't handle
> > -EPROBE_DEFER well right now.
> 
> Unfortunately Viresh is correct here. Current (before rework) Exynos
> TMU driver expects that cpu_cooling device will succeed.
> 


Well, I wouldn't say unfortunately, but fortunately! :-)

Ok. But I believe it is a matter of propagating the error code. As I
included in this patch: 

diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c
index 3f5ad25..f84975e 100644
--- a/drivers/thermal/samsung/exynos_thermal_common.c
+++ b/drivers/thermal/samsung/exynos_thermal_common.c
@@ -373,7 +373,7 @@ int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf)
 		if (IS_ERR(th_zone->cool_dev[th_zone->cool_dev_size])) {
 			dev_err(sensor_conf->dev,
 				"Failed to register cpufreq cooling device\n");
-			ret = -EINVAL;
+			ret = PTR_ERR(th_zone->cool_dev[th_zone->cool_dev_size]);
 			goto err_unregister;
 		}
 		th_zone->cool_dev_size++;



> > 
> > I reached here, because one of my patches had something similar to
> > what you wrote. Just for this file though, haven't updated any other
> > drivers though.
> > 
> > Will be sending you my small patchset by end of day today, please see
> > if they make any sense at all..

The version you sent (for exynos) is better because there is a check for
not print error messages in case of deferring.

However, I would prefer, at least to what comes to deferring, to update
the drivers altogether with the inclusion of the check in cpu cooling.
This way the change in behavior is atomic, in terms of commit changes.

Viresh, if you don't mind, I will merge your patch 04/26 into this one.

> 
> Best regards,
> Łukasz Majewski

BR, Eduardo Valentin

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCHv2 1/1] thermal: cpu_cooling: check for the readiness of cpufreq layer
  2014-11-28 13:14     ` Eduardo Valentin
@ 2014-11-28 13:43       ` Viresh Kumar
  0 siblings, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2014-11-28 13:43 UTC (permalink / raw)
  To: Eduardo Valentin
  Cc: Lukasz Majewski, Linux PM, Lukasz Majewski, LKML, devicetree,
	Grant Likely, Kukjin Kim, linux-arm-kernel, linux-samsung-soc,
	Zhang Rui, Rob Herring

On 28 November 2014 at 18:44, Eduardo Valentin <edubezval@gmail.com> wrote:
> Well, I wouldn't say unfortunately, but fortunately! :-)

+1 :)

> However, I would prefer, at least to what comes to deferring, to update
> the drivers altogether with the inclusion of the check in cpu cooling.
> This way the change in behavior is atomic, in terms of commit changes.
>
> Viresh, if you don't mind, I will merge your patch 04/26 into this one.

Sure, go ahead.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-11-28 13:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-27 14:12 [PATCHv2 1/1] thermal: cpu_cooling: check for the readiness of cpufreq layer Eduardo Valentin
2014-11-28  8:05 ` Viresh Kumar
2014-11-28 10:18   ` Lukasz Majewski
2014-11-28 13:14     ` Eduardo Valentin
2014-11-28 13:43       ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).