linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal/cpu_cooling: remove local cooling state variable
@ 2015-07-21 22:13 Radivoje Jovanovic
  2015-07-24 15:26 ` Punit Agrawal
  0 siblings, 1 reply; 12+ messages in thread
From: Radivoje Jovanovic @ 2015-07-21 22:13 UTC (permalink / raw)
  To: LKML, Linux PM, Zhang Rui, Eduardo Valentin; +Cc: Radivoje Jovanovic

From: Radivoje Jovanovic <radivoje.jovanovic@intel.com>

there is no need to keep local state variable. if another driver
changes the policy under our feet the cpu_cooling driver will
have the wrong state. Get current state from the policy directly instead

Signed-off-by: Radivoje Jovanovic <radivoje.jovanovic@intel.com>
---
 drivers/thermal/cpu_cooling.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 6509c61..94ba2da 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -66,8 +66,6 @@ struct power_table {
  *	registered.
  * @cool_dev: thermal_cooling_device pointer to keep track of the
  *	registered cooling device.
- * @cpufreq_state: integer value representing the current state of cpufreq
- *	cooling	devices.
  * @cpufreq_val: integer value representing the absolute value of the clipped
  *	frequency.
  * @max_level: maximum cooling level. One less than total number of valid
@@ -90,7 +88,6 @@ struct power_table {
 struct cpufreq_cooling_device {
 	int id;
 	struct thermal_cooling_device *cool_dev;
-	unsigned int cpufreq_state;
 	unsigned int cpufreq_val;
 	unsigned int max_level;
 	unsigned int *freq_table;	/* In descending order */
@@ -486,10 +483,19 @@ static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
 				 unsigned long *state)
 {
 	struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
-
-	*state = cpufreq_device->cpufreq_state;
-
-	return 0;
+	struct cpufreq_policy policy;
+	struct cpumask *mask = &cpufreq_device->allowed_cpus;
+	unsigned int cpu = cpumask_any(mask);
+	unsigned int cur_state;
+
+	if (!cpufreq_get_policy(&policy, cpu)) {
+			cur_state = get_level(cpufreq_device, policy.max);
+			if (cur_state != THERMAL_CSTATE_INVALID) {
+				*state = cur_state;
+				return 0;
+			}
+	}
+	return -EINVAL;
 }
 
 /**
@@ -508,17 +514,20 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 	struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
 	unsigned int cpu = cpumask_any(&cpufreq_device->allowed_cpus);
 	unsigned int clip_freq;
+	unsigned long cur_state;
 
 	/* Request state should be less than max_level */
 	if (WARN_ON(state > cpufreq_device->max_level))
 		return -EINVAL;
 
+	if (cpufreq_get_cur_state(cpufreq_device->cool_dev, &cur_state))
+		return -EINVAL;
+
 	/* Check if the old cooling action is same as new cooling action */
-	if (cpufreq_device->cpufreq_state == state)
+	if (cur_state == state)
 		return 0;
 
 	clip_freq = cpufreq_device->freq_table[state];
-	cpufreq_device->cpufreq_state = state;
 	cpufreq_device->cpufreq_val = clip_freq;
 
 	cpufreq_update_policy(cpu);
-- 
1.9.1

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

end of thread, other threads:[~2015-08-03 19:31 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-21 22:13 [PATCH] thermal/cpu_cooling: remove local cooling state variable Radivoje Jovanovic
2015-07-24 15:26 ` Punit Agrawal
2015-07-24 17:09   ` Radivoje Jovanovic
2015-07-29 16:46     ` Punit Agrawal
2015-07-29 17:00       ` Radivoje Jovanovic
2015-07-30  8:05       ` Viresh Kumar
2015-07-30 20:21         ` Radivoje Jovanovic
2015-07-31  3:18           ` Viresh Kumar
2015-07-31 15:30             ` Radivoje Jovanovic
2015-08-01 11:34               ` Viresh Kumar
2015-08-03  3:13                 ` Viresh Kumar
2015-08-03 19:28                   ` Radivoje Jovanovic

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).