Skip to contentSkip to conversation

cpufreq: Use existing stub functions instead of IS_ENABLED macro

PATCH In review Daniel Lezcano 4 participants 23 messages Jun 21, 2019 – Jun 24, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 cpufreq: Use existing stub functions instead of IS_ENABLED macro

The functions stub already exist for the condition the IS_ENABLED is trying to avoid.

Remove the IS_ENABLED macros as they are pointless.

---
 drivers/cpufreq/cpufreq.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/cpufreq/cpufreq.c +2 -4
index 85ff958e01f1..7c72f7d3509c 100644
@@ -1378,8 +1378,7 @@ static int cpufreq_online(unsigned int cpu)
 	if (cpufreq_driver->ready)
 		cpufreq_driver->ready(policy);
 
-	if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
-	    cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
+	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
 		policy->cdev = of_cpufreq_cooling_register(policy);
 
 	pr_debug("initialization complete\n");
@@ -1469,8 +1468,7 @@ static int cpufreq_offline(unsigned int cpu)
 		goto unlock;
 	}
 
-	if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
-	    cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
+	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
 		cpufreq_cooling_unregister(policy->cdev);
 		policy->cdev = NULL;
 	}
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/6 thermal/drivers/cpu_cooling: Unregister with the policy

Currently the function cpufreq_cooling_register() returns a cooling device pointer which is used back as a pointer to call the function cpufreq_cooling_unregister(). Even if it is correct, it would make sense to not leak the structure inside a cpufreq driver and keep the code thermal code self-encapsulate. Moreover, that forces to add an extra variable in each driver using this function.

Instead of passing the cooling device to unregister, pass the policy.

---
 drivers/cpufreq/arm_big_little.c               |  2 +-
 drivers/cpufreq/cpufreq.c                      |  2 +-
 drivers/thermal/cpu_cooling.c                  | 18 ++++++++++--------
 drivers/thermal/imx_thermal.c                  |  4 ++--
 .../thermal/ti-soc-thermal/ti-thermal-common.c |  2 +-
 include/linux/cpu_cooling.h                    |  6 +++---
 6 files changed, 18 insertions(+), 16 deletions(-)
drivers/cpufreq/arm_big_little.c +1 -1
index 7fe52fcddcf1..6b243202caa9 100644
@@ -502,7 +502,7 @@ static int bL_cpufreq_exit(struct cpufreq_policy *policy)
 	int cur_cluster = cpu_to_cluster(policy->cpu);
 
 	if (cur_cluster < MAX_CLUSTERS) {
-		cpufreq_cooling_unregister(cdev[cur_cluster]);
+		cpufreq_cooling_unregister(policy);
 		cdev[cur_cluster] = NULL;
 	}
 
drivers/cpufreq/cpufreq.c +1 -1
index 7c72f7d3509c..dfbc9bea606c 100644
@@ -1469,7 +1469,7 @@ static int cpufreq_offline(unsigned int cpu)
 	}
 
 	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
-		cpufreq_cooling_unregister(policy->cdev);
+		cpufreq_cooling_unregister(policy);
 		policy->cdev = NULL;
 	}
 
drivers/thermal/cpu_cooling.c +10 -8
index 83486775e593..007c7c6bf845 100644
@@ -78,6 +78,7 @@ struct cpufreq_cooling_device {
 	struct cpufreq_policy *policy;
 	struct list_head node;
 	struct time_in_idle *idle_time;
+	struct thermal_cooling_device *cdev;
 };
 
 static DEFINE_IDA(cpufreq_ida);
@@ -606,6 +607,7 @@ __cpufreq_cooling_register(struct device_node *np,
 		goto remove_ida;
 
 	cpufreq_cdev->clipped_freq = get_state_freq(cpufreq_cdev, 0);
+	cpufreq_cdev->cdev = cdev;
 
 	mutex_lock(&cooling_list_lock);
 	/* Register the notifier for first cpufreq cooling device */
@@ -699,18 +701,18 @@ EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register);
  *
  * This interface function unregisters the "thermal-cpufreq-%x" cooling device.
  */
-void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
+void cpufreq_cooling_unregister(struct cpufreq_policy *policy)
 {
 	struct cpufreq_cooling_device *cpufreq_cdev;
 	bool last;
 
-	if (!cdev)
-		return;
-
-	cpufreq_cdev = cdev->devdata;
-
 	mutex_lock(&cooling_list_lock);
-	list_del(&cpufreq_cdev->node);
+	list_for_each_entry(cpufreq_cdev, &cpufreq_cdev_list, node) {
+		if (cpufreq_cdev->policy == policy) {
+			list_del(&cpufreq_cdev->node);
+			break;
+		}
+	}
 	/* Unregister the notifier for the last cpufreq cooling device */
 	last = list_empty(&cpufreq_cdev_list);
 	mutex_unlock(&cooling_list_lock);
@@ -719,7 +721,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
 		cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block,
 					    CPUFREQ_POLICY_NOTIFIER);
 
-	thermal_cooling_device_unregister(cdev);
+	thermal_cooling_device_unregister(cpufreq_cdev->cdev);
 	ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id);
 	kfree(cpufreq_cdev->idle_time);
 	kfree(cpufreq_cdev);
drivers/thermal/imx_thermal.c +2 -2
index bb6754a5342c..6746f1b73eb7 100644
@@ -680,7 +680,7 @@ static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
 
 static void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data *data)
 {
-	cpufreq_cooling_unregister(data->cdev);
+	cpufreq_cooling_unregister(data->policy);
 	cpufreq_cpu_put(data->policy);
 }
 
@@ -872,7 +872,7 @@ static int imx_thermal_remove(struct platform_device *pdev)
 		clk_disable_unprepare(data->thermal_clk);
 
 	thermal_zone_device_unregister(data->tz);
-	cpufreq_cooling_unregister(data->cdev);
+	cpufreq_cooling_unregister(data->policy);
 	cpufreq_cpu_put(data->policy);
 
 	return 0;
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +1 -1
index b4f981daeaf2..217b1aae8b4f 100644
@@ -277,7 +277,7 @@ int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id)
 	data = ti_bandgap_get_sensor_data(bgp, id);
 
 	if (data) {
-		cpufreq_cooling_unregister(data->cool_dev);
+		cpufreq_cooling_unregister(data->policy);
 		if (data->policy)
 			cpufreq_cpu_put(data->policy);
 	}
include/linux/cpu_cooling.h +3 -3
index bae54bb7c048..89f469ee4be4 100644
@@ -29,9 +29,9 @@ cpufreq_cooling_register(struct cpufreq_policy *policy);
 
 /**
  * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
- * @cdev: thermal cooling device pointer.
+ * @policy: cpufreq policy
  */
-void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev);
+void cpufreq_cooling_unregister(struct cpufreq_policy *policy);
 
 #else /* !CONFIG_CPU_THERMAL */
 static inline struct thermal_cooling_device *
@@ -41,7 +41,7 @@ cpufreq_cooling_register(struct cpufreq_policy *policy)
 }
 
 static inline
-void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
+void cpufreq_cooling_unregister(struct cpufreq_policy *policy)
 {
 	return;
 }
Signature · 1 line
2.17.1
maintainer Acked-by on v1 2/6
#2 lore raw

Re: [PATCH 2/6] thermal/drivers/cpu_cooling: Unregister with the policy

Quoted 10 lines · Daniel Lezcano

Currently the function cpufreq_cooling_register() returns a cooling device pointer which is used back as a pointer to call the function cpufreq_cooling_unregister(). Even if it is correct, it would make sense to not leak the structure inside a cpufreq driver and keep the code thermal code self-encapsulate. Moreover, that forces to add an extra variable in each driver using this function.

Instead of passing the cooling device to unregister, pass the policy.

Quoted 8 lines
---
 drivers/cpufreq/arm_big_little.c               |  2 +-
 drivers/cpufreq/cpufreq.c                      |  2 +-
 drivers/thermal/cpu_cooling.c                  | 18 ++++++++++--------
 drivers/thermal/imx_thermal.c                  |  4 ++--
 .../thermal/ti-soc-thermal/ti-thermal-common.c |  2 +-
 include/linux/cpu_cooling.h                    |  6 +++---
 6 files changed, 18 insertions(+), 16 deletions(-)
Signature · 1 line
viresh
#3 lore raw

Re: [PATCH 2/6] thermal/drivers/cpu_cooling: Unregister with the policy

Quoted 20 lines · Viresh Kumar
Quoted 10 lines · Daniel Lezcano

Currently the function cpufreq_cooling_register() returns a cooling device pointer which is used back as a pointer to call the function cpufreq_cooling_unregister(). Even if it is correct, it would make sense to not leak the structure inside a cpufreq driver and keep the code thermal code self-encapsulate. Moreover, that forces to add an extra variable in each driver using this function.

Instead of passing the cooling device to unregister, pass the policy.

Quoted 8 lines
---
 drivers/cpufreq/arm_big_little.c               |  2 +-
 drivers/cpufreq/cpufreq.c                      |  2 +-
 drivers/thermal/cpu_cooling.c                  | 18 ++++++++++--------
 drivers/thermal/imx_thermal.c                  |  4 ++--
 .../thermal/ti-soc-thermal/ti-thermal-common.c |  2 +-
 include/linux/cpu_cooling.h                    |  6 +++---
 6 files changed, 18 insertions(+), 16 deletions(-)
Quoted 1 line

Just a side note, does it make sense to have the function called from imx_thermal.c and ti-thermal-common.c? Sounds like also a leakage from cpufreq to thermal drivers, no?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
maintainer
#4 lore raw

Re: [PATCH 2/6] thermal/drivers/cpu_cooling: Unregister with the policy

Quoted 21 lines · Daniel Lezcano
Quoted 20 lines · Viresh Kumar
Quoted 18 lines · Daniel Lezcano

Currently the function cpufreq_cooling_register() returns a cooling device pointer which is used back as a pointer to call the function cpufreq_cooling_unregister(). Even if it is correct, it would make sense to not leak the structure inside a cpufreq driver and keep the code thermal code self-encapsulate. Moreover, that forces to add an extra variable in each driver using this function.

Instead of passing the cooling device to unregister, pass the policy.

---
 drivers/cpufreq/arm_big_little.c               |  2 +-
 drivers/cpufreq/cpufreq.c                      |  2 +-
 drivers/thermal/cpu_cooling.c                  | 18 ++++++++++--------
 drivers/thermal/imx_thermal.c                  |  4 ++--
 .../thermal/ti-soc-thermal/ti-thermal-common.c |  2 +-
 include/linux/cpu_cooling.h                    |  6 +++---
 6 files changed, 18 insertions(+), 16 deletions(-)
Quoted 5 lines
Quoted 1 line

Just a side note, does it make sense to have the function called from imx_thermal.c and ti-thermal-common.c? Sounds like also a leakage from cpufreq to thermal drivers, no?

I am not sure what you are proposing here :)

Signature · 1 line
viresh
#5 lore raw

Re: [PATCH 2/6] thermal/drivers/cpu_cooling: Unregister with the policy

Quoted 22 lines · Viresh Kumar
Quoted 21 lines · Daniel Lezcano
Quoted 20 lines · Viresh Kumar
Quoted 18 lines · Daniel Lezcano

Currently the function cpufreq_cooling_register() returns a cooling device pointer which is used back as a pointer to call the function cpufreq_cooling_unregister(). Even if it is correct, it would make sense to not leak the structure inside a cpufreq driver and keep the code thermal code self-encapsulate. Moreover, that forces to add an extra variable in each driver using this function.

Instead of passing the cooling device to unregister, pass the policy.

---
 drivers/cpufreq/arm_big_little.c               |  2 +-
 drivers/cpufreq/cpufreq.c                      |  2 +-
 drivers/thermal/cpu_cooling.c                  | 18 ++++++++++--------
 drivers/thermal/imx_thermal.c                  |  4 ++--
 .../thermal/ti-soc-thermal/ti-thermal-common.c |  2 +-
 include/linux/cpu_cooling.h                    |  6 +++---
 6 files changed, 18 insertions(+), 16 deletions(-)
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Just a side note, does it make sense to have the function called from imx_thermal.c and ti-thermal-common.c? Sounds like also a leakage from cpufreq to thermal drivers, no?

I am not sure what you are proposing here :)

Actually I'm asking your opinion :)

The structure in drivers/thermal/imx_thermal.c

struct imx_thermal_data {
struct cpufreq_policy *policy; <<<< in the thermal data ?! [ ... ]
};

And then:

#ifdef CONFIG_CPU_FREQ
/*
* Create cooling device in case no #cooling-cells property is available in
* CPU node
*/
static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)

{
        struct device_node *np;
        int ret;

        data->policy = cpufreq_cpu_get(0);
        if (!data->policy) {
                pr_debug("%s: CPUFreq policy not found\n", __func__);
                return -EPROBE_DEFER;
        }

        np = of_get_cpu_node(data->policy->cpu, NULL);

        if (!np || !of_find_property(np, "#cooling-cells", NULL)) {
                data->cdev = cpufreq_cooling_register(data->policy);
                if (IS_ERR(data->cdev)) {
                        ret = PTR_ERR(data->cdev);
                        cpufreq_cpu_put(data->policy);
                        return ret;
                }
        }

        return 0;
}

[ ... ]

Shouldn't this be move in the drivers/cpufreq/<whatever driver> ?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
maintainer
#6 lore raw

Re: [PATCH 2/6] thermal/drivers/cpu_cooling: Unregister with the policy

Quoted 42 lines · Daniel Lezcano

Actually I'm asking your opinion :)

The structure in drivers/thermal/imx_thermal.c

struct imx_thermal_data {
struct cpufreq_policy *policy; <<<< in the thermal data ?! [ ... ]
};

And then:

#ifdef CONFIG_CPU_FREQ
/*
* Create cooling device in case no #cooling-cells property is available in
* CPU node
*/
static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)

{
        struct device_node *np;
        int ret;

        data->policy = cpufreq_cpu_get(0);
        if (!data->policy) {
                pr_debug("%s: CPUFreq policy not found\n", __func__);
                return -EPROBE_DEFER;
        }

        np = of_get_cpu_node(data->policy->cpu, NULL);

        if (!np || !of_find_property(np, "#cooling-cells", NULL)) {
                data->cdev = cpufreq_cooling_register(data->policy);
                if (IS_ERR(data->cdev)) {
                        ret = PTR_ERR(data->cdev);
                        cpufreq_cpu_put(data->policy);
                        return ret;
                }
        }

        return 0;
}
Quoted 3 lines

[ ... ]

Shouldn't this be move in the drivers/cpufreq/<whatever driver> ?

Sure, we have platform specific drivers where this can be moved :)

Signature · 1 line
viresh
#7 lore raw

PATCH 3/6 cpufreq/drivers/arm_big_little: Remove cooling device usage

In reply to Daniel Lezcano

The cpufreq_cooling_unregister() function uses now the policy to unregister itself. The only purpose of the cooling device pointer is to unregister the cpu cooling device.

As there is no more need of this pointer, remove it.

---
 drivers/cpufreq/arm_big_little.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/cpufreq/arm_big_little.c +2 -5
index 6b243202caa9..718c63231e66 100644
@@ -56,7 +56,6 @@ static bool bL_switching_enabled;
 #define ACTUAL_FREQ(cluster, freq)  ((cluster == A7_CLUSTER) ? freq << 1 : freq)
 #define VIRT_FREQ(cluster, freq)    ((cluster == A7_CLUSTER) ? freq >> 1 : freq)
 
-static struct thermal_cooling_device *cdev[MAX_CLUSTERS];
 static const struct cpufreq_arm_bL_ops *arm_bL_ops;
 static struct clk *clk[MAX_CLUSTERS];
 static struct cpufreq_frequency_table *freq_table[MAX_CLUSTERS + 1];
@@ -501,10 +500,8 @@ static int bL_cpufreq_exit(struct cpufreq_policy *policy)
 	struct device *cpu_dev;
 	int cur_cluster = cpu_to_cluster(policy->cpu);
 
-	if (cur_cluster < MAX_CLUSTERS) {
+	if (cur_cluster < MAX_CLUSTERS)
 		cpufreq_cooling_unregister(policy);
-		cdev[cur_cluster] = NULL;
-	}
 
 	cpu_dev = get_cpu_device(policy->cpu);
 	if (!cpu_dev) {
@@ -527,7 +524,7 @@ static void bL_cpufreq_ready(struct cpufreq_policy *policy)
 	if (cur_cluster >= MAX_CLUSTERS)
 		return;
 
-	cdev[cur_cluster] = of_cpufreq_cooling_register(policy);
+	of_cpufreq_cooling_register(policy);
 }
 
 static struct cpufreq_driver bL_cpufreq_driver = {
Signature · 1 line
2.17.1
maintainer Acked-by on v1 3/6
#8 lore raw

Re: [PATCH 3/6] cpufreq/drivers/arm_big_little: Remove cooling device usage

Quoted 36 lines · Daniel Lezcano

The cpufreq_cooling_unregister() function uses now the policy to unregister itself. The only purpose of the cooling device pointer is to unregister the cpu cooling device.

As there is no more need of this pointer, remove it.

---
 drivers/cpufreq/arm_big_little.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/cpufreq/arm_big_little.c +1 -4
index 6b243202caa9..718c63231e66 100644
@@ -56,7 +56,6 @@ static bool bL_switching_enabled;
 #define ACTUAL_FREQ(cluster, freq)  ((cluster == A7_CLUSTER) ? freq << 1 : freq)
 #define VIRT_FREQ(cluster, freq)    ((cluster == A7_CLUSTER) ? freq >> 1 : freq)
 
-static struct thermal_cooling_device *cdev[MAX_CLUSTERS];
 static const struct cpufreq_arm_bL_ops *arm_bL_ops;
 static struct clk *clk[MAX_CLUSTERS];
 static struct cpufreq_frequency_table *freq_table[MAX_CLUSTERS + 1];
@@ -501,10 +500,8 @@ static int bL_cpufreq_exit(struct cpufreq_policy *policy)
 	struct device *cpu_dev;
 	int cur_cluster = cpu_to_cluster(policy->cpu);
 
-	if (cur_cluster < MAX_CLUSTERS) {
+	if (cur_cluster < MAX_CLUSTERS)
 		cpufreq_cooling_unregister(policy);
-		cdev[cur_cluster] = NULL;
-	}
 
 	cpu_dev = get_cpu_device(policy->cpu);
 	if (!cpu_dev) {

drivers/cpufreq/arm_big_little.c static void bL_cpufreq_ready(struct cpufreq_policy *policy) · line 530

Quoted 8 lines
drivers/cpufreq/arm_big_little.c +1 -1
@@ -527,7 +524,7 @@ static void bL_cpufreq_ready(struct cpufreq_policy *policy)
 	if (cur_cluster >= MAX_CLUSTERS)
 		return;
 
-	cdev[cur_cluster] = of_cpufreq_cooling_register(policy);
+	of_cpufreq_cooling_register(policy);
 }
 
 static struct cpufreq_driver bL_cpufreq_driver = {

I will merge it with the previous commit if I were you.

Signature · 1 line
viresh
#9 lore raw

PATCH 4/6 cpufreq: Remove cooling device usage

In reply to Daniel Lezcano

The cpufreq_cooling_unregister() function uses now the policy to unregister itself. The only purpose of the cooling device pointer is to unregister the cpu cooling device.

As there is no more need of this pointer, remove it.

---
 drivers/cpufreq/cpufreq.c | 6 ++----
 include/linux/cpufreq.h   | 3 ---
 2 files changed, 2 insertions(+), 7 deletions(-)
drivers/cpufreq/cpufreq.c +2 -4
index dfbc9bea606c..1d8f85faeaca 100644
@@ -1379,7 +1379,7 @@ static int cpufreq_online(unsigned int cpu)
 		cpufreq_driver->ready(policy);
 
 	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
-		policy->cdev = of_cpufreq_cooling_register(policy);
+		of_cpufreq_cooling_register(policy);
 
 	pr_debug("initialization complete\n");
 
@@ -1468,10 +1468,8 @@ static int cpufreq_offline(unsigned int cpu)
 		goto unlock;
 	}
 
-	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
+	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
 		cpufreq_cooling_unregister(policy);
-		policy->cdev = NULL;
-	}
 
 	if (cpufreq_driver->stop_cpu)
 		cpufreq_driver->stop_cpu(policy);
include/linux/cpufreq.h +0 -3
index d01a74fbc4db..9a42711f338b 100644
@@ -144,9 +144,6 @@ struct cpufreq_policy {
 
 	/* For cpufreq driver's internal use */
 	void			*driver_data;
-
-	/* Pointer to the cooling device if used for thermal mitigation */
-	struct thermal_cooling_device *cdev;
 };
 
 struct cpufreq_freqs {
Signature · 1 line
2.17.1
maintainer Acked-by on v1 4/6
#10 lore raw

Re: [PATCH 4/6] cpufreq: Remove cooling device usage

Quoted 42 lines · Daniel Lezcano

The cpufreq_cooling_unregister() function uses now the policy to unregister itself. The only purpose of the cooling device pointer is to unregister the cpu cooling device.

As there is no more need of this pointer, remove it.

---
 drivers/cpufreq/cpufreq.c | 6 ++----
 include/linux/cpufreq.h   | 3 ---
 2 files changed, 2 insertions(+), 7 deletions(-)
drivers/cpufreq/cpufreq.c +2 -4
index dfbc9bea606c..1d8f85faeaca 100644
@@ -1379,7 +1379,7 @@ static int cpufreq_online(unsigned int cpu)
 		cpufreq_driver->ready(policy);
 
 	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
-		policy->cdev = of_cpufreq_cooling_register(policy);
+		of_cpufreq_cooling_register(policy);
 
 	pr_debug("initialization complete\n");
 
@@ -1468,10 +1468,8 @@ static int cpufreq_offline(unsigned int cpu)
 		goto unlock;
 	}
 
-	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
+	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
 		cpufreq_cooling_unregister(policy);
-		policy->cdev = NULL;
-	}
 
 	if (cpufreq_driver->stop_cpu)
 		cpufreq_driver->stop_cpu(policy);
include/linux/cpufreq.h +0 -0
index d01a74fbc4db..9a42711f338b 100644

include/linux/cpufreq.h struct cpufreq_policy { · line 149

Quoted 9 lines
include/linux/cpufreq.h +0 -3
@@ -144,9 +144,6 @@ struct cpufreq_policy {
 
 	/* For cpufreq driver's internal use */
 	void			*driver_data;
-
-	/* Pointer to the cooling device if used for thermal mitigation */
-	struct thermal_cooling_device *cdev;
 };
 
 struct cpufreq_freqs {

This too. In my view this should be merged with 2/6.

Signature · 1 line
viresh
#11 lore raw

PATCH 5/6 thermal/drivers/imx: Remove cooling device usage

In reply to Daniel Lezcano

The cpufreq_cooling_unregister() function uses now the policy to unregister itself. The only purpose of the cooling device pointer is to unregister the cpu cooling device.

As there is no more need of this pointer, remove it.

---
 drivers/thermal/imx_thermal.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/imx_thermal.c +4 -4
index 6746f1b73eb7..021c0948b740 100644
@@ -203,7 +203,6 @@ static struct thermal_soc_data thermal_imx7d_data = {
 struct imx_thermal_data {
 	struct cpufreq_policy *policy;
 	struct thermal_zone_device *tz;
-	struct thermal_cooling_device *cdev;
 	enum thermal_device_mode mode;
 	struct regmap *tempmon;
 	u32 c1, c2; /* See formula in imx_init_calib() */
@@ -656,6 +655,7 @@ MODULE_DEVICE_TABLE(of, of_imx_thermal_match);
 static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
 {
 	struct device_node *np;
+	struct thermal_cooling_device *cdev;
 	int ret;
 
 	data->policy = cpufreq_cpu_get(0);
@@ -667,9 +667,9 @@ static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
 	np = of_get_cpu_node(data->policy->cpu, NULL);
 
 	if (!np || !of_find_property(np, "#cooling-cells", NULL)) {
-		data->cdev = cpufreq_cooling_register(data->policy);
-		if (IS_ERR(data->cdev)) {
-			ret = PTR_ERR(data->cdev);
+		cdev = cpufreq_cooling_register(data->policy);
+		if (IS_ERR(cdev)) {
+			ret = PTR_ERR(cdev);
 			cpufreq_cpu_put(data->policy);
 			return ret;
 		}
Signature · 1 line
2.17.1
maintainer Acked-by on v1 5/6
#12 lore raw

Re: [PATCH 5/6] thermal/drivers/imx: Remove cooling device usage

Quoted 34 lines · Daniel Lezcano

The cpufreq_cooling_unregister() function uses now the policy to unregister itself. The only purpose of the cooling device pointer is to unregister the cpu cooling device.

As there is no more need of this pointer, remove it.

---
 drivers/thermal/imx_thermal.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/imx_thermal.c +1 -1
index 6746f1b73eb7..021c0948b740 100644
@@ -203,7 +203,6 @@ static struct thermal_soc_data thermal_imx7d_data = {
 struct imx_thermal_data {
 	struct cpufreq_policy *policy;
 	struct thermal_zone_device *tz;
-	struct thermal_cooling_device *cdev;
 	enum thermal_device_mode mode;
 	struct regmap *tempmon;
 	u32 c1, c2; /* See formula in imx_init_calib() */
@@ -656,6 +655,7 @@ MODULE_DEVICE_TABLE(of, of_imx_thermal_match);
 static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
 {
 	struct device_node *np;
+	struct thermal_cooling_device *cdev;
 	int ret;
 
 	data->policy = cpufreq_cpu_get(0);
@@ -667,9 +667,9 @@ static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
 	np = of_get_cpu_node(data->policy->cpu, NULL);
 

drivers/thermal/imx_thermal.c static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data) · line 675

Quoted 10 lines
drivers/thermal/imx_thermal.c +3 -3
 	if (!np || !of_find_property(np, "#cooling-cells", NULL)) {
-		data->cdev = cpufreq_cooling_register(data->policy);
-		if (IS_ERR(data->cdev)) {
-			ret = PTR_ERR(data->cdev);
+		cdev = cpufreq_cooling_register(data->policy);
+		if (IS_ERR(cdev)) {
+			ret = PTR_ERR(cdev);
 			cpufreq_cpu_put(data->policy);
 			return ret;
 		}

This too..

Signature · 1 line
viresh
#13 lore raw

PATCH 6/6 thermal/drivers/ti: Remove cooling device usage

In reply to Daniel Lezcano

The cpufreq_cooling_unregister() function uses now the policy to unregister itself. The only purpose of the cooling device pointer is to unregister the cpu cooling device.

As there is no more need of this pointer, remove it.

---
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +4 -4
index 217b1aae8b4f..170b70b6ec61 100644
@@ -41,7 +41,6 @@ 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;
 	struct ti_bandgap *bgp;
 	enum thermal_device_mode mode;
 	struct work_struct thermal_wq;
@@ -233,6 +232,7 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
 {
 	struct ti_thermal_data *data;
 	struct device_node *np = bgp->dev->of_node;
+	struct thermal_cooling_device *cdev;
 
 	/*
 	 * We are assuming here that if one deploys the zone
@@ -256,9 +256,9 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
 	}
 
 	/* Register cooling device */
-	data->cool_dev = cpufreq_cooling_register(data->policy);
-	if (IS_ERR(data->cool_dev)) {
-		int ret = PTR_ERR(data->cool_dev);
+	cdev = cpufreq_cooling_register(data->policy);
+	if (IS_ERR(cdev)) {
+		int ret = PTR_ERR(cdev);
 		dev_err(bgp->dev, "Failed to register cpu cooling device %d\n",
 			ret);
 		cpufreq_cpu_put(data->policy);
Signature · 1 line
2.17.1
maintainer Acked-by on v1 6/6
#14 lore raw

Re: [PATCH 6/6] thermal/drivers/ti: Remove cooling device usage

Quoted 34 lines · Daniel Lezcano

The cpufreq_cooling_unregister() function uses now the policy to unregister itself. The only purpose of the cooling device pointer is to unregister the cpu cooling device.

As there is no more need of this pointer, remove it.

---
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +1 -1
index 217b1aae8b4f..170b70b6ec61 100644
@@ -41,7 +41,6 @@ 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;
 	struct ti_bandgap *bgp;
 	enum thermal_device_mode mode;
 	struct work_struct thermal_wq;
@@ -233,6 +232,7 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
 {
 	struct ti_thermal_data *data;
 	struct device_node *np = bgp->dev->of_node;
+	struct thermal_cooling_device *cdev;
 
 	/*
 	 * We are assuming here that if one deploys the zone
@@ -256,9 +256,9 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
 	}
 

drivers/thermal/ti-soc-thermal/ti-thermal-common.c int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) · line 264

Quoted 10 lines
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +3 -3
 	/* Register cooling device */
-	data->cool_dev = cpufreq_cooling_register(data->policy);
-	if (IS_ERR(data->cool_dev)) {
-		int ret = PTR_ERR(data->cool_dev);
+	cdev = cpufreq_cooling_register(data->policy);
+	if (IS_ERR(cdev)) {
+		int ret = PTR_ERR(cdev);
 		dev_err(bgp->dev, "Failed to register cpu cooling device %d\n",
 			ret);
 		cpufreq_cpu_put(data->policy);

And this too..

Signature · 1 line
viresh
#15 lore raw
In reply to Daniel Lezcano
Quoted 5 lines · Daniel Lezcano

The functions stub already exist for the condition the IS_ENABLED is trying to avoid.

Remove the IS_ENABLED macros as they are pointless.

AFAICS, the IS_ENABLED checks are an optimization to avoid generating pointless code (including a branch) in case CONFIG_CPU_THERMAL is not set.

Why do you think that it is not useful?

Quoted 32 lines
---
 drivers/cpufreq/cpufreq.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/cpufreq/cpufreq.c +2 -5
index 85ff958e01f1..7c72f7d3509c 100644
@@ -1378,8 +1378,7 @@ static int cpufreq_online(unsigned int cpu)
        if (cpufreq_driver->ready)
                cpufreq_driver->ready(policy);
 
-       if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
-           cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
+       if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
                policy->cdev = of_cpufreq_cooling_register(policy);
 
        pr_debug("initialization complete\n");
@@ -1469,8 +1468,7 @@ static int cpufreq_offline(unsigned int cpu)
                goto unlock;
        }
 
-       if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
-           cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
+       if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
                cpufreq_cooling_unregister(policy->cdev);
                policy->cdev = NULL;
        }
--

2.17.1

#16 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Daniel Lezcano

The functions stub already exist for the condition the IS_ENABLED is trying to avoid.

Quoted 7 lines
Quoted 1 line

Remove the IS_ENABLED macros as they are pointless.

AFAICS, the IS_ENABLED checks are an optimization to avoid generating pointless code (including a branch) in case CONFIG_CPU_THERMAL is not set.

Why do you think that it is not useful?

I agree but I'm not a big fan of IS_ENABLED macros in the code when it is possible to avoid them.

What about adding a stub for that like:

#ifdef CPU_THERMAL
static inline int cpufreq_is_cooling_dev(struct cpufreq_driver *drv)

{
	return drv->flags & CPUFREQ_IS_COOLING_DEV;
}
#else
static inline int cpufreq_is_cooling_dev(struct cpufreq_driver *drv)
{
	return 0;
}

#endif

?

Quoted 32 lines
Quoted 32 lines
---
 drivers/cpufreq/cpufreq.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/cpufreq/cpufreq.c +2 -5
index 85ff958e01f1..7c72f7d3509c 100644
@@ -1378,8 +1378,7 @@ static int cpufreq_online(unsigned int cpu)
        if (cpufreq_driver->ready)
                cpufreq_driver->ready(policy);
 
-       if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
-           cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
+       if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
                policy->cdev = of_cpufreq_cooling_register(policy);
 
        pr_debug("initialization complete\n");
@@ -1469,8 +1468,7 @@ static int cpufreq_offline(unsigned int cpu)
                goto unlock;
        }
 
-       if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
-           cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
+       if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
                cpufreq_cooling_unregister(policy->cdev);
                policy->cdev = NULL;
        }
--

2.17.1

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#17 lore raw
Quoted 13 lines · CEST Daniel Lezcano
Quoted 12 lines · Rafael J. Wysocki
Quoted 5 lines · Daniel Lezcano

The functions stub already exist for the condition the IS_ENABLED is trying to avoid.

Remove the IS_ENABLED macros as they are pointless.

AFAICS, the IS_ENABLED checks are an optimization to avoid generating pointless code (including a branch) in case CONFIG_CPU_THERMAL is not set.

Quoted 6 lines
Quoted 1 line

Why do you think that it is not useful?

I agree but I'm not a big fan of IS_ENABLED macros in the code when it is possible to avoid them.

What about adding a stub for that like:

Well,

Quoted 11 lines

#ifdef CPU_THERMAL
static inline int cpufreq_is_cooling_dev(struct cpufreq_driver *drv)

{
	return drv->flags & CPUFREQ_IS_COOLING_DEV;
}
#else
static inline int cpufreq_is_cooling_dev(struct cpufreq_driver *drv)
{
	return 0;
}

#endif

This may as well be defined as

static inline int cpufreq_is_cooling_dev(struct cpufreq_driver *drv)

{
	return IS_ENABLED(CPU_THERMAL) && drv->flags & CPUFREQ_IS_COOLING_DEV;
}

which is fewer lines of code.

And I would call it something like cpufreq_thermal_control_enabled().

#18 lore raw
Quoted 35 lines · Rafael J. Wysocki
Quoted 13 lines · CEST Daniel Lezcano
Quoted 12 lines · Rafael J. Wysocki
Quoted 5 lines · Daniel Lezcano

The functions stub already exist for the condition the IS_ENABLED is trying to avoid.

Remove the IS_ENABLED macros as they are pointless.

AFAICS, the IS_ENABLED checks are an optimization to avoid generating pointless code (including a branch) in case CONFIG_CPU_THERMAL is not set.

Quoted 6 lines
Quoted 1 line

Why do you think that it is not useful?

I agree but I'm not a big fan of IS_ENABLED macros in the code when it is possible to avoid them.

What about adding a stub for that like:

Well,

Quoted 11 lines

#ifdef CPU_THERMAL
static inline int cpufreq_is_cooling_dev(struct cpufreq_driver *drv)

{
	return drv->flags & CPUFREQ_IS_COOLING_DEV;
}
#else
static inline int cpufreq_is_cooling_dev(struct cpufreq_driver *drv)
{
	return 0;
}

#endif

Quoted 8 lines

This may as well be defined as

static inline int cpufreq_is_cooling_dev(struct cpufreq_driver *drv)

{
	return IS_ENABLED(CPU_THERMAL) && drv->flags & CPUFREQ_IS_COOLING_DEV;
}

which is fewer lines of code.

Ah yes, even better.

Quoted 1 line

And I would call it something like cpufreq_thermal_control_enabled().

Ok, thanks!

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#19 lore raw
In reply to Daniel Lezcano

Hi Viresh,

Quoted 6 lines · Daniel Lezcano

The functions stub already exist for the condition the IS_ENABLED is trying to avoid.

Remove the IS_ENABLED macros as they are pointless.

what about this one?

Quoted 29 lines
---
 drivers/cpufreq/cpufreq.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/cpufreq/cpufreq.c +2 -4
index 85ff958e01f1..7c72f7d3509c 100644
@@ -1378,8 +1378,7 @@ static int cpufreq_online(unsigned int cpu)
 	if (cpufreq_driver->ready)
 		cpufreq_driver->ready(policy);
 
-	if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
-	    cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
+	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
 		policy->cdev = of_cpufreq_cooling_register(policy);
 
 	pr_debug("initialization complete\n");
@@ -1469,8 +1468,7 @@ static int cpufreq_offline(unsigned int cpu)
 		goto unlock;
 	}
 
-	if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
-	    cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
+	if (cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
 		cpufreq_cooling_unregister(policy->cdev);
 		policy->cdev = NULL;
 	}
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#20 lore raw
Quoted 5 lines · Daniel Lezcano

Hi Viresh,

On 21/06/2019 15:22, Daniel Lezcano wrote:

Quoted 8 lines
Quoted 6 lines

The functions stub already exist for the condition the IS_ENABLED is trying to avoid.

Remove the IS_ENABLED macros as they are pointless.

what about this one?

Care to respond to my question regarding this one in the first place, please?

#21 lore raw

Hi Rafael,

Quoted 10 lines · Rafael J. Wysocki
Quoted 8 lines · Daniel Lezcano

Hi Viresh,

Quoted 3 lines · Daniel Lezcano

The functions stub already exist for the condition the IS_ENABLED is trying to avoid.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Remove the IS_ENABLED macros as they are pointless.

what about this one?

Care to respond to my question regarding this one in the first place, please?

Ah yes, sorry, I missed your email.

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
maintainer
#22 lore raw
In reply to Daniel Lezcano
Quoted 4 lines · Daniel Lezcano

Hi Viresh,

On 21/06/2019 15:22, Daniel Lezcano wrote:

Quoted 8 lines
Quoted 6 lines

The functions stub already exist for the condition the IS_ENABLED is trying to avoid.

Remove the IS_ENABLED macros as they are pointless.

what about this one?

I didn't say something because Rafael already pointed out something which he wanted. Actually he was the one who suggested it to Amit initially.

http://lore.kernel.org/lkml/CAJZ5v0huESFqOADqyym-ci-XcWpL4tbcd9a-jxe_KArXKpHFyw@mail.gmail.com

Signature · 1 line
viresh