From: "hongbo.zhang" <hongbo.zhang@linaro.org>
To: linaro-dev@lists.linaro.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org
Cc: patches@linaro.org, linaro-kernel@lists.linaro.org,
STEricsson_nomadik_linux@list.st.com, kernel@igloocommunity.org,
"hongbo.zhang" <hongbo.zhang@linaro.com>
Subject: [PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.
Date: Fri, 26 Oct 2012 15:09:05 +0800 [thread overview]
Message-ID: <1351235345-13050-1-git-send-email-hongbo.zhang@linaro.com> (raw)
In-Reply-To: <50898F97.3000202@gmail.com>
From: "hongbo.zhang" <hongbo.zhang@linaro.com>
Problem of using this list is that the cpufreq_get_max_state callback will be
called when register cooling device by thermal_cooling_device_register, but
this list isn't ready at this moment. What's more, there is no need to maintain
such a list, we can get cpufreq_cooling_device instance by the private
thermal_cooling_device.devdata.
Signed-off-by: hongbo.zhang <hongbo.zhang@linaro.com>
---
drivers/thermal/cpu_cooling.c | 91 +++++++++----------------------------------
1 file changed, 19 insertions(+), 72 deletions(-)
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 415b041..2ffd12c 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
};
static LIST_HEAD(cooling_cpufreq_list);
static DEFINE_IDR(cpufreq_idr);
+static DEFINE_MUTEX(cooling_cpufreq_lock);
-static struct mutex cooling_cpufreq_lock;
+static unsigned int cpufreq_dev_count;
/* notify_table passes value to the CPUFREQ_ADJUST callback function. */
#define NOTIFY_INVALID NULL
@@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
- int ret = -EINVAL, i = 0;
- struct cpufreq_cooling_device *cpufreq_device;
- struct cpumask *maskPtr;
+ struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
+ struct cpumask *maskPtr = &cpufreq_device->allowed_cpus;
unsigned int cpu;
struct cpufreq_frequency_table *table;
unsigned long count = 0;
+ int i = 0;
- mutex_lock(&cooling_cpufreq_lock);
- list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) {
- if (cpufreq_device && cpufreq_device->cool_dev == cdev)
- break;
- }
- if (cpufreq_device == NULL)
- goto return_get_max_state;
-
- maskPtr = &cpufreq_device->allowed_cpus;
cpu = cpumask_any(maskPtr);
table = cpufreq_frequency_get_table(cpu);
if (!table) {
*state = 0;
- ret = 0;
- goto return_get_max_state;
+ return 0;
}
for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
@@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
if (count > 0) {
*state = --count;
- ret = 0;
+ return 0;
}
-return_get_max_state:
- mutex_unlock(&cooling_cpufreq_lock);
- return ret;
+ return -EINVAL;
}
/**
@@ -288,20 +277,10 @@ return_get_max_state:
static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
- int ret = -EINVAL;
- struct cpufreq_cooling_device *cpufreq_device;
+ struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
- mutex_lock(&cooling_cpufreq_lock);
- list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) {
- if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
- *state = cpufreq_device->cpufreq_state;
- ret = 0;
- break;
- }
- }
- mutex_unlock(&cooling_cpufreq_lock);
-
- return ret;
+ *state = cpufreq_device->cpufreq_state;
+ return 0;
}
/**
@@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
{
- int ret = -EINVAL;
- struct cpufreq_cooling_device *cpufreq_device;
+ struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
- mutex_lock(&cooling_cpufreq_lock);
- list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) {
- if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
- ret = 0;
- break;
- }
- }
- if (!ret)
- ret = cpufreq_apply_cooling(cpufreq_device, state);
-
- mutex_unlock(&cooling_cpufreq_lock);
-
- return ret;
+ return cpufreq_apply_cooling(cpufreq_device, state);
}
/* Bind cpufreq callbacks to thermal cooling device ops */
@@ -351,7 +317,7 @@ struct thermal_cooling_device *cpufreq_cooling_register(
{
struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL;
- unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
+ unsigned int min = 0, max = 0;
char dev_name[THERMAL_NAME_LENGTH];
int ret = 0, i;
struct cpufreq_policy policy;
@@ -360,9 +326,6 @@ struct thermal_cooling_device *cpufreq_cooling_register(
if (!cpufreq_frequency_get_table(cpumask_any(clip_cpus)))
return ERR_PTR(-EPROBE_DEFER);
- list_for_each_entry(cpufreq_dev, &cooling_cpufreq_list, node)
- cpufreq_dev_count++;
-
/*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*/
@@ -384,9 +347,6 @@ struct thermal_cooling_device *cpufreq_cooling_register(
cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus);
- if (cpufreq_dev_count == 0)
- mutex_init(&cooling_cpufreq_lock);
-
ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);
if (ret) {
kfree(cpufreq_dev);
@@ -405,12 +365,12 @@ struct thermal_cooling_device *cpufreq_cooling_register(
cpufreq_dev->cool_dev = cool_dev;
cpufreq_dev->cpufreq_state = 0;
mutex_lock(&cooling_cpufreq_lock);
- list_add_tail(&cpufreq_dev->node, &cooling_cpufreq_list);
/* Register the notifier for first cpufreq cooling device */
if (cpufreq_dev_count == 0)
cpufreq_register_notifier(&thermal_cpufreq_notifier_block,
CPUFREQ_POLICY_NOTIFIER);
+ cpufreq_dev_count++;
mutex_unlock(&cooling_cpufreq_lock);
return cool_dev;
@@ -423,33 +383,20 @@ EXPORT_SYMBOL(cpufreq_cooling_register);
*/
void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
{
- struct cpufreq_cooling_device *cpufreq_dev = NULL;
- unsigned int cpufreq_dev_count = 0;
+ struct cpufreq_cooling_device *cpufreq_dev = cdev->devdata;
mutex_lock(&cooling_cpufreq_lock);
- list_for_each_entry(cpufreq_dev, &cooling_cpufreq_list, node) {
- if (cpufreq_dev && cpufreq_dev->cool_dev == cdev)
- break;
- cpufreq_dev_count++;
- }
-
- if (!cpufreq_dev || cpufreq_dev->cool_dev != cdev) {
- mutex_unlock(&cooling_cpufreq_lock);
- return;
- }
-
- list_del(&cpufreq_dev->node);
+ cpufreq_dev_count--;
/* Unregister the notifier for the last cpufreq cooling device */
- if (cpufreq_dev_count == 1) {
+ if (cpufreq_dev_count == 0) {
cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block,
CPUFREQ_POLICY_NOTIFIER);
}
mutex_unlock(&cooling_cpufreq_lock);
+
thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
release_idr(&cpufreq_idr, cpufreq_dev->id);
- if (cpufreq_dev_count == 1)
- mutex_destroy(&cooling_cpufreq_lock);
kfree(cpufreq_dev);
}
EXPORT_SYMBOL(cpufreq_cooling_unregister);
--
1.7.11.3
next prev parent reply other threads:[~2012-10-26 7:09 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1350387889-15324-1-git-send-email-hongbo.zhang@linaro.com>
[not found] ` <1350387889-15324-2-git-send-email-hongbo.zhang@linaro.com>
2012-10-21 10:05 ` [PATCH 1/5] Thermal: do bind operation after thermal zone or cooling device register returns Francesco Lavra
2012-10-23 8:23 ` Hongbo Zhang
2012-10-23 22:13 ` Francesco Lavra
2012-10-24 2:37 ` Hongbo Zhang
[not found] ` <1350387889-15324-6-git-send-email-hongbo.zhang@linaro.com>
2012-10-21 15:01 ` [PATCH 5/5] Thermal: Add ST-Ericsson db8500 thermal dirver Francesco Lavra
2012-10-22 12:02 ` Hongbo Zhang
2012-10-22 18:51 ` Francesco Lavra
2012-10-24 4:40 ` Hongbo Zhang
2012-10-24 11:58 ` [PATCH V2 0/6] Fix thermal bugs and Upstream ST-Ericsson thermal driver hongbo.zhang
2012-10-24 11:58 ` [PATCH V2 1/6] Thermal: add indent for code alignment hongbo.zhang
[not found] ` <1351079900-32236-1-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-10-24 11:58 ` [PATCH V2 2/6] Thermal: make sure cpufreq cooling register after cpufreq driver hongbo.zhang
2012-10-29 11:42 ` Amit Kachhap
2012-10-30 8:59 ` Hongbo Zhang
2012-10-24 11:58 ` [PATCH V2 3/6] Thermal: fix bug of counting cpu frequencies hongbo.zhang
2012-10-24 13:34 ` Viresh Kumar
2012-10-29 11:54 ` Amit Kachhap
2012-10-24 11:58 ` [PATCH V2 5/6] Thermal: Add ST-Ericsson DB8500 thermal dirver hongbo.zhang
2012-10-24 14:38 ` Viresh Kumar
2012-10-25 8:26 ` Hongbo Zhang
2012-10-25 8:41 ` Viresh Kumar
2012-10-25 9:33 ` Hongbo Zhang
2012-10-25 9:42 ` Viresh Kumar
2012-10-25 10:43 ` Hongbo Zhang
[not found] ` <CAJLyvQw7=ucSTXH8YyPrm6LS8uDyxJkWGEVP2jQ3FL=cYN7frg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-25 9:56 ` Hongbo Zhang
2012-10-25 10:04 ` Viresh Kumar
2012-10-25 10:11 ` Viresh Kumar
2012-10-25 10:45 ` Hongbo Zhang
2012-10-25 11:13 ` [PATCH V2 5/6] Thermal: Add ST-Ericsson DB8500 thermal driver hongbo.zhang
2012-10-27 10:53 ` Francesco Lavra
2012-10-24 11:58 ` [PATCH V2 6/6] Thermal: Add ST-Ericsson DB8500 thermal properties and platform data hongbo.zhang
2012-10-24 14:32 ` Joe Perches
2012-10-25 3:45 ` Hongbo Zhang
[not found] ` <1351079900-32236-7-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-10-24 14:47 ` Viresh Kumar
[not found] ` <CAKohpom0EOAuahLQoNr1ODbTT-Trv3eE0-oBEmbbdbiKBJPCng-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-25 3:49 ` Hongbo Zhang
2012-10-25 11:15 ` hongbo.zhang
2012-10-25 11:39 ` hongbo.zhang
2012-10-24 11:58 ` [PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list hongbo.zhang
2012-10-25 19:14 ` Francesco Lavra
2012-10-26 2:59 ` Hongbo Zhang
2012-10-26 7:09 ` hongbo.zhang [this message]
2012-10-27 6:39 ` Francesco Lavra
2012-10-30 8:03 ` Amit Kachhap
2012-10-30 8:53 ` Hongbo Zhang
2012-10-30 16:48 ` [PATCH V3 0/5] Fix thermal bugs and Upstream ST-Ericsson thermal driver hongbo.zhang
2012-10-30 16:48 ` [PATCH V3 1/5] Thermal: add indent for code alignment hongbo.zhang
[not found] ` <1351615741-24134-2-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-11-07 6:54 ` Zhang Rui
[not found] ` <1351615741-24134-1-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-10-30 16:48 ` [PATCH V3 2/5] Thermal: fix bug of counting cpu frequencies hongbo.zhang
2012-11-07 6:54 ` Zhang Rui
2012-10-30 16:48 ` [PATCH V3 3/5] Thermal: Remove the cooling_cpufreq_list hongbo.zhang
2012-11-07 6:54 ` Zhang Rui
2012-11-09 11:54 ` Hongbo Zhang
2012-10-30 16:49 ` [PATCH V3 4/5] Thermal: Add ST-Ericsson DB8500 thermal driver hongbo.zhang
2012-10-31 2:33 ` Viresh Kumar
[not found] ` <1351615741-24134-5-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-11-01 1:52 ` Zhang, Rui
2012-11-06 10:17 ` Hongbo Zhang
2012-11-06 10:30 ` Hongbo Zhang
2012-11-01 14:48 ` Francesco Lavra
2012-10-30 16:49 ` [PATCH V3 5/5] Thermal: Add ST-Ericsson DB8500 thermal properties and platform data hongbo.zhang
2012-10-31 2:18 ` viresh kumar
2012-11-06 7:25 ` Hongbo Zhang
2012-10-31 2:08 ` [PATCH V3 0/5] Fix thermal bugs and Upstream ST-Ericsson thermal driver 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=1351235345-13050-1-git-send-email-hongbo.zhang@linaro.com \
--to=hongbo.zhang@linaro.org \
--cc=STEricsson_nomadik_linux@list.st.com \
--cc=hongbo.zhang@linaro.com \
--cc=kernel@igloocommunity.org \
--cc=linaro-dev@lists.linaro.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=patches@linaro.org \
/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 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).