From: Amit Daniel Kachhap <amit.daniel@samsung.com>
To: linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org
Cc: Zhang Rui <rui.zhang@intel.com>,
linux-kernel@vger.kernel.org, amit.kachhap@gmail.com,
edubezval@gmail.com, rjw@rjwysocki.net,
linux-arm-kernel@lists.infradead.org, lenb@kernel.org
Subject: [PATCH v1 1/6] thermal: cpu_cooling: Fix the notification mechanism by using per cpu structure
Date: Thu, 29 May 2014 13:45:29 +0530 [thread overview]
Message-ID: <1401351334-11210-2-git-send-email-amit.daniel@samsung.com> (raw)
In-Reply-To: <1401351334-11210-1-git-send-email-amit.daniel@samsung.com>
Currently the notification data is supplied to the thermal notifiers using
a single global pointer. This method will have race condition if cpu cooling
interfaces are used by more than 1 clients (more than 1 cdev) to cause cpufreq
clipping. Also the notifier data is presented as per cpu cpufreq policy
structure. This was needed as same cpu is used later in thermal cpufreq handler
function.
Signed-off-by: Amit Daniel Kachhap <amit.daniel@samsung.com>
---
drivers/thermal/cpu_cooling.c | 38 +++++++++++++++-----------------------
1 files changed, 15 insertions(+), 23 deletions(-)
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 4246262..16388b0 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -58,7 +58,7 @@ static unsigned int cpufreq_dev_count;
/* notify_table passes value to the CPUFREQ_ADJUST callback function. */
#define NOTIFY_INVALID NULL
-static struct cpufreq_cooling_device *notify_device;
+static DEFINE_PER_CPU(struct cpufreq_cooling_device *, notify_device);
/**
* get_idr - function to get a unique id.
@@ -98,23 +98,6 @@ static void release_idr(struct idr *idr, int id)
/* Below code defines functions to be used for cpufreq as cooling device */
-/**
- * is_cpufreq_valid - function to check frequency transitioning capability.
- * @cpu: cpu for which check is needed.
- *
- * This function will check the current state of the system if
- * it is capable of changing the frequency for a given @cpu.
- *
- * Return: 0 if the system is not currently capable of changing
- * the frequency of given cpu. !0 in case the frequency is changeable.
- */
-static int is_cpufreq_valid(int cpu)
-{
- struct cpufreq_policy policy;
-
- return !cpufreq_get_policy(&policy, cpu);
-}
-
enum cpufreq_cooling_property {
GET_LEVEL,
GET_FREQ,
@@ -294,11 +277,18 @@ static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device,
cpufreq_device->cpufreq_state = cooling_state;
cpufreq_device->cpufreq_val = clip_freq;
- notify_device = cpufreq_device;
for_each_cpu(cpuid, mask) {
- if (is_cpufreq_valid(cpuid))
+ if (cpufreq_get_policy(&policy, cpu) == 0) {
+ /*
+ * Store the notification data in the cpu pointed by
+ * cpufreq policy structure. This is needed as this cpu
+ * will be used later to fetch correct data pointer.
+ */
+ per_cpu(notify_device, policy.cpu) = cpufreq_device;
cpufreq_update_policy(cpuid);
+ per_cpu(notify_device, policy.cpu) = NOTIFY_INVALID;
+ }
}
notify_device = NOTIFY_INVALID;
@@ -323,12 +313,14 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
{
struct cpufreq_policy *policy = data;
unsigned long max_freq = 0;
+ struct cpufreq_cooling_device *cpufreq_device
+ = per_cpu(notify_device, policy->cpu);
- if (event != CPUFREQ_ADJUST || notify_device == NOTIFY_INVALID)
+ if (event != CPUFREQ_ADJUST || cpufreq_device == NOTIFY_INVALID)
return 0;
- if (cpumask_test_cpu(policy->cpu, ¬ify_device->allowed_cpus))
- max_freq = notify_device->cpufreq_val;
+ if (cpumask_test_cpu(policy->cpu, &cpufreq_device->allowed_cpus))
+ max_freq = cpufreq_device->cpufreq_val;
else
return 0;
--
1.7.1
next prev parent reply other threads:[~2014-05-29 8:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-29 8:15 [PATCH v1 0/6] ACPI: thermal: Migrate cpufreq cooling to generic cpu_cooling layer Amit Daniel Kachhap
2014-05-29 8:15 ` Amit Daniel Kachhap [this message]
2014-05-29 8:15 ` [PATCH v1 2/6] thermal: cpu_cooling: Support passing driver private data Amit Daniel Kachhap
2014-05-29 12:06 ` Javi Merino
2014-06-02 9:24 ` Amit Kachhap
2014-06-02 18:57 ` Eduardo Valentin
2014-05-29 8:15 ` [PATCH v1 3/6] thermal: thermal-core: Add notifications support for the cooling states Amit Daniel Kachhap
2014-05-29 12:24 ` Javi Merino
2014-06-02 9:31 ` Amit Kachhap
2014-06-02 10:14 ` Javi Merino
2014-05-29 8:15 ` [PATCH v1 4/6] thermal: cpu_cooling: Add support to find up/low frequency levels Amit Daniel Kachhap
2014-05-29 8:15 ` [PATCH v1 5/6] thermal: thermal_core: Remove the max cooling limit check in registration Amit Daniel Kachhap
2014-05-29 8:15 ` [PATCH v1 6/6] ACPI: thermal: processor: Use the generic cpufreq infrastructure Amit Daniel Kachhap
2014-05-29 12:42 ` Javi Merino
2014-06-02 9:21 ` Amit Kachhap
2014-06-02 10:20 ` Javi Merino
2014-06-02 17:36 ` Eduardo Valentin
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=1401351334-11210-2-git-send-email-amit.daniel@samsung.com \
--to=amit.daniel@samsung.com \
--cc=amit.kachhap@gmail.com \
--cc=edubezval@gmail.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome