All of lore.kernel.org
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: linux-pm@vger.kernel.org, edubezval@gmail.com
Cc: linaro-kernel@lists.linaro.org, rui.zhang@intel.com,
	Viresh Kumar <viresh.kumar@linaro.org>
Subject: [PATCH 23/26] cpu_cooling: Pass 'cpufreq_dev' to get_property()
Date: Fri, 28 Nov 2014 15:14:17 +0530	[thread overview]
Message-ID: <54fc6ebea71dda145d9631330e6760ab845796b9.1417167599.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1417167599.git.viresh.kumar@linaro.org>
In-Reply-To: <cover.1417167599.git.viresh.kumar@linaro.org>

We already know the value of 'cpufreq_dev->max_level' and so there is no need
calculating that once again. For this, we need to send 'cpufreq_dev' to
get_property().

Make all necessary changes for this change. Because cpufreq_cooling_get_level()
doesn't have access to 'cpufreq_dev', it is updated to iterate over the list of
cpufreq_cooling_devices to get cooling device for the cpu number passed to it.
This also makes it robust to return levels only for the CPU registered via a
cooling device. We don't have to support anything that isn't registered yet.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/thermal/cpu_cooling.c | 47 ++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 4965a55..07414c5 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -86,7 +86,7 @@ enum cpufreq_cooling_property {
 
 /**
  * get_property - fetch a property of interest for a given cpu.
- * @cpu: cpu for which the property is required
+ * @cpufreq_dev: cpufreq_dev for which the property is required
  * @input: query parameter
  * @output: query return
  * @property: type of query (frequency, level)
@@ -103,20 +103,20 @@ enum cpufreq_cooling_property {
  *
  * Return: 0 on success, -EINVAL when invalid parameters are passed.
  */
-static int get_property(unsigned int cpu, unsigned long input,
-			unsigned int *output,
+static int get_property(struct cpufreq_cooling_device *cpufreq_dev,
+			unsigned long input, unsigned int *output,
 			enum cpufreq_cooling_property property)
 {
 	int i;
-	unsigned long max_level = 0, level = 0;
+	unsigned long level = 0;
 	unsigned int freq = CPUFREQ_ENTRY_INVALID;
 	int descend = -1;
-	struct cpufreq_frequency_table *pos, *table =
-					cpufreq_frequency_get_table(cpu);
+	struct cpufreq_frequency_table *pos, *table;
 
 	if (!output)
 		return -EINVAL;
 
+	table = cpufreq_frequency_get_table(cpumask_first(&cpufreq_dev->allowed_cpus));
 	if (!table)
 		return -EINVAL;
 
@@ -130,18 +130,10 @@ static int get_property(unsigned int cpu, unsigned long input,
 			descend = freq > pos->frequency;
 
 		freq = pos->frequency;
-		max_level++;
 	}
 
-	/* No valid cpu frequency entry */
-	if (max_level == 0)
-		return -EINVAL;
-
-	/* max_level is an index, not a counter */
-	max_level--;
-
 	if (property == GET_FREQ)
-		level = descend ? input : (max_level - input);
+		level = descend ? input : (cpufreq_dev->max_level - input);
 
 	i = 0;
 	cpufreq_for_each_valid_entry(pos, table) {
@@ -154,7 +146,7 @@ static int get_property(unsigned int cpu, unsigned long input,
 
 		if (property == GET_LEVEL && (unsigned int)input == freq) {
 			/* get level by frequency */
-			*output = descend ? i : (max_level - i);
+			*output = descend ? i : (cpufreq_dev->max_level - i);
 			return 0;
 		}
 		if (property == GET_FREQ && level == i) {
@@ -181,12 +173,25 @@ static int get_property(unsigned int cpu, unsigned long input,
  */
 unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq)
 {
-	unsigned int val;
+	struct cpufreq_cooling_device *cpufreq_dev;
 
-	if (get_property(cpu, (unsigned long)freq, &val, GET_LEVEL))
-		return THERMAL_CSTATE_INVALID;
+	mutex_lock(&cooling_cpufreq_lock);
+	list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, head) {
+		if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) {
+			unsigned int val;
+
+			mutex_unlock(&cooling_cpufreq_lock);
+			if (get_property(cpufreq_dev, (unsigned long)freq, &val,
+					 GET_LEVEL))
+				return THERMAL_CSTATE_INVALID;
+
+			return (unsigned long)val;
+		}
+	}
+	mutex_unlock(&cooling_cpufreq_lock);
 
-	return (unsigned long)val;
+	pr_err("%s: cpu:%d not part of any cooling device\n", __func__, cpu);
+	return THERMAL_CSTATE_INVALID;
 }
 EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level);
 
@@ -289,7 +294,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 	if (cpufreq_device->cpufreq_state == state)
 		return 0;
 
-	ret = get_property(cpu, state, &clip_freq, GET_FREQ);
+	ret = get_property(cpufreq_device, state, &clip_freq, GET_FREQ);
 	if (ret)
 		return ret;
 
-- 
2.0.3.693.g996b0fd


  parent reply	other threads:[~2014-11-28  9:46 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-28  9:43 [PATCH 00/26] thermal: cpu_cooling: Fixes and cleanups Viresh Kumar
2014-11-28  9:43 ` [PATCH 01/26] thermal: db8500: pass cpu_present_mask to cpufreq_cooling_register() Viresh Kumar
2014-11-28  9:43 ` [PATCH 02/26] thermal: imx: " Viresh Kumar
2014-11-28  9:43 ` [PATCH 03/26] thermal: exynos: " Viresh Kumar
2014-11-28  9:43 ` [PATCH 04/26] thermal: exynos: Handle -EPROBE_DEFER properly Viresh Kumar
2014-12-02 23:08   ` Eduardo Valentin
2014-11-28  9:43 ` [PATCH 05/26] cpu_cooling: random comment fixups Viresh Kumar
2014-12-02 23:09   ` Eduardo Valentin
2014-11-28  9:44 ` [PATCH 06/26] cpu_cooling: fix doc comment over struct cpufreq_cooling_device Viresh Kumar
2014-11-28  9:44 ` [PATCH 07/26] cpu_cooling: Add comment to clarify relation between cooling state and frequency Viresh Kumar
2014-11-28  9:44 ` [PATCH 08/26] cpu_cooling: Pass variable instead of its type to sizeof() Viresh Kumar
2014-12-02 15:26   ` Javi Merino
2014-12-02 23:07     ` Eduardo Valentin
2014-12-03  4:38       ` Viresh Kumar
2014-11-28  9:44 ` [PATCH 09/26] cpu_cooling: no need to set cpufreq_state to zero Viresh Kumar
2014-11-28  9:44 ` [PATCH 10/26] cpu_cooling: no need to set cpufreq_dev to NULL Viresh Kumar
2014-11-28  9:44 ` [PATCH 11/26] cpu_cooling: propagate error returned by idr_alloc() Viresh Kumar
2014-12-02 15:35   ` Javi Merino
2014-12-03  4:36     ` Viresh Kumar
2014-12-02 23:03   ` Eduardo Valentin
2014-11-28  9:44 ` [PATCH 12/26] cpu_cooling: Don't match min/max frequencies for all CPUs on cooling register Viresh Kumar
2014-11-28  9:44 ` [PATCH 13/26] cpu_cooling: don't iterate over all allowed_cpus to update cpufreq policy Viresh Kumar
2014-11-28  9:44 ` [PATCH 14/26] cpu_cooling: Don't check is_cpufreq_valid() Viresh Kumar
2014-11-28  9:44 ` [PATCH 15/26] cpu_cooling: do error handling at the bottom in __cpufreq_cooling_register() Viresh Kumar
2014-12-02 15:45   ` Javi Merino
2014-11-28  9:44 ` [PATCH 16/26] cpu_cooling: Drop useless locking around idr_alloc/idr_remove Viresh Kumar
2014-12-02 15:53   ` Javi Merino
2014-12-02 23:05   ` Eduardo Valentin
2014-12-03  9:32     ` Viresh Kumar
2014-11-28  9:44 ` [PATCH 17/26] cpu_cooling: Merge cpufreq_apply_cooling() into cpufreq_set_cur_state() Viresh Kumar
2014-11-28  9:44 ` [PATCH 18/26] cpu_cooling: Merge get_cpu_frequency() " Viresh Kumar
2014-11-28  9:44 ` [PATCH 19/26] cpu_cooling: find max level during device registration Viresh Kumar
2014-12-02 23:39   ` Eduardo Valentin
2014-12-03  4:57     ` Viresh Kumar
2014-12-03 13:40       ` Eduardo Valentin
2014-11-28  9:44 ` [PATCH 20/26] cpu_cooling: get_property() doesn't need to support GET_MAXL anymore Viresh Kumar
2014-11-28  9:44 ` [PATCH 21/26] cpu_cooling: create list of cpufreq_cooling_devices Viresh Kumar
2014-12-02 23:12   ` Eduardo Valentin
2014-11-28  9:44 ` [PATCH 22/26] cpu_cooling: use cpufreq_dev_list instead of cpufreq_dev_count Viresh Kumar
2014-11-28  9:44 ` Viresh Kumar [this message]
2014-11-28  9:44 ` [PATCH 24/26] cpu_cooling: Store frequencies in descending order Viresh Kumar
2014-12-02 23:21   ` Eduardo Valentin
2014-12-03  4:52     ` Viresh Kumar
2014-12-03 13:41       ` Eduardo Valentin
     [not found]         ` <CAKohponw7E9yyvjhP97CzjtcFcq3N+5ysde7DR5q+Nm0s=bKAw@mail.gmail.com>
2014-12-03 14:00           ` Eduardo Valentin
2014-11-28  9:44 ` [PATCH 25/26] cpu_cooling: Use cpufreq_dev->freq_table for finding level/freq Viresh Kumar
2014-12-02 23:36   ` Eduardo Valentin
2014-12-03  5:10     ` Viresh Kumar
2014-12-03 13:32       ` Eduardo Valentin
2014-11-28  9:44 ` [PATCH 26/26] cpu_cooling: update copyright tags Viresh Kumar
2014-12-02 19:41   ` Eduardo Valentin
2014-12-03  4:34     ` Viresh Kumar
2014-12-04  4:41       ` amit daniel kachhap
2014-11-28 13:26 ` [PATCH 00/26] thermal: cpu_cooling: Fixes and cleanups Eduardo Valentin
2014-11-28 13:41   ` Viresh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54fc6ebea71dda145d9631330e6760ab845796b9.1417167599.git.viresh.kumar@linaro.org \
    --to=viresh.kumar@linaro.org \
    --cc=edubezval@gmail.com \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.