Skip to contentSkip to conversation

thermal: cpu_cooling: check for the readiness of cpufreq layer

PATCH Superseded Eduardo Valentin 2 participants 4 messages Nov 26, 2014 – Nov 28, 2014

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Eduardo Valentin

author maintainer
#0 lore raw

PATCH 1/1 thermal: cpu_cooling: check for the readiness of cpufreq layer

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 at vger.kernel.org
Cc Grant Likely <[email protected]>
Cc Kukjin Kim <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Cc linux-kernel at vger.kernel.org
Cc linux-pm at vger.kernel.org
Cc linux-samsung-soc at vger.kernel.org
Cc Naveen Krishna Chatradhi <[email protected]>
Cc Rob Herring <[email protected]>
Cc Zhang Rui <[email protected]>
---
 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(-)

---

This is attempt to organize the cpu cooling vs. cpufreq boot sequencing. The main change in this patch, as in the commit log, is to have the check for the cpufreq layer in the cpu cooling device registration, instead of in thermal drivers. This way, drivers don't need to bother about it, they just need to propagate the error value.

This change was tested on top of:
(0) - Viresh's change in cpufreq layer and cpufreq-dt (up to patch 4):
https://patchwork.kernel.org/patch/5384141/
https://patchwork.kernel.org/patch/5384151/
https://patchwork.kernel.org/patch/5384161/
https://patchwork.kernel.org/patch/5384171/
(1) - fix of thermal core:
https://patchwork.kernel.org/patch/5326991/

After Viresh's changes, cpufreq-dt is properly sequenced with cpu cooling registration. Non-of based drivers also should take advantage if these changes, as now they do not need to check for cpufreq layer. The check is where it belongs, in cpu cooling device registration.

BR, Eduardo Valentin

drivers/thermal/cpu_cooling.c +5 -0
index 1ab0018..9e6945b 100644
@@ -440,6 +440,11 @@ __cpufreq_cooling_register(struct device_node *np,
 	int ret = 0, i;
 	struct cpufreq_policy policy;
 
+	if (!cpufreq_get_current_driver() || !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 */
drivers/thermal/db8500_cpufreq_cooling.c +0 -5
index 786d192..1ac7ec6 100644
@@ -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);
 
drivers/thermal/imx_thermal.c +0 -5
index 5a1f107..16405b4 100644
@@ -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;
drivers/thermal/samsung/exynos_thermal_common.c +1 -1
index 3f5ad25..f84975e 100644
@@ -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++;
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +0 -6
index 5fd0386..cf88585 100644
@@ -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)) {
Signature · 1 line
2.1.3
Acked-by on v1 1/1
#1 lore raw

Few nits..

Quoted 2 lines · Eduardo Valentin

---

The normal practice is to write the non-commitable part here ...

Quoted 7 lines
 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(-)

---

But this works as well :)

Quoted 28 lines

This is attempt to organize the cpu cooling vs. cpufreq boot sequencing. The main change in this patch, as in the commit log, is to have the check for the cpufreq layer in the cpu cooling device registration, instead of in thermal drivers. This way, drivers don't need to bother about it, they just need to propagate the error value.

This change was tested on top of:
(0) - Viresh's change in cpufreq layer and cpufreq-dt (up to patch 4):
https://patchwork.kernel.org/patch/5384141/
https://patchwork.kernel.org/patch/5384151/
https://patchwork.kernel.org/patch/5384161/
https://patchwork.kernel.org/patch/5384171/
(1) - fix of thermal core:
https://patchwork.kernel.org/patch/5326991/

After Viresh's changes, cpufreq-dt is properly sequenced with cpu cooling registration. Non-of based drivers also should take advantage if these changes, as now they do not need to check for cpufreq layer. The check is where it belongs, in cpu cooling device registration.

BR, Eduardo Valentin

drivers/thermal/cpu_cooling.c +0 -0
index 1ab0018..9e6945b 100644

drivers/thermal/cpu_cooling.c __cpufreq_cooling_register(struct device_node *np, · line 443

Quoted 4 lines
drivers/thermal/cpu_cooling.c +1 -0
@@ -440,6 +440,11 @@ __cpufreq_cooling_register(struct device_node *np,
        int ret = 0, i;
        struct cpufreq_policy policy;
 
+       if (!cpufreq_get_current_driver() || !cpufreq_frequency_get_table(0)) {

Only !cpufreq_frequency_get_table(0) is enough here.

For rest:

author maintainer
#2 lore raw

Hello Viresh,

Quoted 9 lines · Viresh Kumar

Few nits..

Quoted 2 lines · Eduardo Valentin

---

The normal practice is to write the non-commitable part here ...

err... normal practice by whom? hehe...

My "normal" practice is to allow people to read the diff stat before my extra comments :-)

Quoted 10 lines
Quoted 7 lines
 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(-)

---

But this works as well :)

hehe ok.

Quoted 31 lines
Quoted 31 lines

This is attempt to organize the cpu cooling vs. cpufreq boot sequencing. The main change in this patch, as in the commit log, is to have the check for the cpufreq layer in the cpu cooling device registration, instead of in thermal drivers. This way, drivers don't need to bother about it, they just need to propagate the error value.

This change was tested on top of:
(0) - Viresh's change in cpufreq layer and cpufreq-dt (up to patch 4):
https://patchwork.kernel.org/patch/5384141/
https://patchwork.kernel.org/patch/5384151/
https://patchwork.kernel.org/patch/5384161/
https://patchwork.kernel.org/patch/5384171/
(1) - fix of thermal core:
https://patchwork.kernel.org/patch/5326991/

After Viresh's changes, cpufreq-dt is properly sequenced with cpu cooling registration. Non-of based drivers also should take advantage if these changes, as now they do not need to check for cpufreq layer. The check is where it belongs, in cpu cooling device registration.

BR, Eduardo Valentin

drivers/thermal/cpu_cooling.c +0 -0
index 1ab0018..9e6945b 100644
@@ -440,6 +440,11 @@ __cpufreq_cooling_register(struct device_node *np,
        int ret = 0, i;
        struct cpufreq_policy policy;
 
Quoted 4 lines

drivers/thermal/cpu_cooling.c __cpufreq_cooling_register(struct device_node *np, · line 443

Quoted 1 line
drivers/thermal/cpu_cooling.c +1 -0
+       if (!cpufreq_get_current_driver() || !cpufreq_frequency_get_table(0)) {

Only !cpufreq_frequency_get_table(0) is enough here.

Yeah, I thought of it too. Just combined what people had in their drivers here. But I agree that latter is enough.

Quoted 3 lines

For rest:

Ok.

though.. "normal practice" says ack's are oftern used by the maintainer
of the affected code (quoting Documentation/SubmittingPatches) :-)
BR, Eduardo Valenti
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141127/8e88e19b/attachment.sig>

#3 lore raw
Quoted 6 lines · Eduardo Valentin
Quoted 1 line

Ok.

though.. "normal practice" says ack's are oftern used by the maintainer of the affected code (quoting Documentation/SubmittingPatches) :-)

Hehe :)

Another paragraph from the same file:

Acked-by: does not necessarily indicate acknowledgement of the entire patch. For example, if a patch affects multiple subsystems and has an Acked-by: from one subsystem maintainer then this usually indicates acknowledgement of just the part which affects that maintainer's code. Judgement should be used here. When in doubt people should refer to the original discussion in the mailing list archives.

So my Acked-by was as cpufreq subsystem Maintainer :)