public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gautham R Shenoy <ego@in.ibm.com>
To: Gautham R Shenoy <ego@in.ibm.com>
Cc: rusty@rustcorp.com.au, torvalds@osdl.org, mingo@elte.hu,
	akpm@osdl.org, linux-kernel@vger.kernel.org, paulmck@us.ibm.com,
	vatsa@in.ibm.com, dipankar@in.ibm.com, gaughen@us.ibm.com,
	arjan@linux.intel.org, davej@redhat.com,
	venkatesh.pallipadi@intel.com, kiran@scalex86.org
Subject: [PATCH 2/5] lock_cpu_hotplug:Redesign - remove lock_cpu_hotplug from hot-cpu_callback path in cpufreq.
Date: Thu, 26 Oct 2006 16:23:42 +0530	[thread overview]
Message-ID: <20061026105342.GC11803@in.ibm.com> (raw)
In-Reply-To: <20061026105058.GB11803@in.ibm.com>

Ensure that the hot-cpu-callback path in cpufreq is free from any  
(un)lock_cpu_hotplug calls.

Signed-off-by : Gautham R Shenoy <ego@in.ibm.com>
---
 drivers/cpufreq/cpufreq.c       |   83 +++++++++++++++++++++++++++-------------
 drivers/cpufreq/cpufreq_stats.c |    4 +
 include/linux/cpufreq.h         |    1 
 3 files changed, 61 insertions(+), 27 deletions(-)

Index: hotplug/drivers/cpufreq/cpufreq.c
===================================================================
--- hotplug.orig/drivers/cpufreq/cpufreq.c
+++ hotplug/drivers/cpufreq/cpufreq.c
@@ -642,6 +642,7 @@ static struct kobj_type ktype_cpufreq = 
 };
 
 
+int _cpufreq_set_policy(struct cpufreq_policy *);
 /**
  * cpufreq_add_dev - add a CPU device
  *
@@ -776,11 +777,11 @@ static int cpufreq_add_dev (struct sys_d
 	}
 
 	policy->governor = NULL; /* to assure that the starting sequence is
-				  * run in cpufreq_set_policy */
+				  * run in _cpufreq_set_policy */
 	mutex_unlock(&policy->lock);
 
 	/* set default policy */
-	ret = cpufreq_set_policy(&new_policy);
+	ret = _cpufreq_set_policy(&new_policy);
 	if (ret) {
 		dprintk("setting policy failed\n");
 		goto err_out_unregister;
@@ -1284,7 +1285,9 @@ int __cpufreq_driver_target(struct cpufr
 }
 EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
 
-int cpufreq_driver_target(struct cpufreq_policy *policy,
+/*Locking: Must be called with lock_cpu_hotplug held, except from the
+hotcpu callback path */
+int _cpufreq_driver_target(struct cpufreq_policy *policy,
 			  unsigned int target_freq,
 			  unsigned int relation)
 {
@@ -1294,17 +1297,27 @@ int cpufreq_driver_target(struct cpufreq
 	if (!policy)
 		return -EINVAL;
 
-	lock_cpu_hotplug();
 	mutex_lock(&policy->lock);
 
 	ret = __cpufreq_driver_target(policy, target_freq, relation);
 
 	mutex_unlock(&policy->lock);
-	unlock_cpu_hotplug();
 
 	cpufreq_cpu_put(policy);
 	return ret;
 }
+int cpufreq_driver_target(struct cpufreq_policy *policy,
+			  unsigned int target_freq,
+			  unsigned int relation)
+{
+	int ret;
+
+	lock_cpu_hotplug();
+	ret = _cpufreq_driver_target(policy, target_freq, relation);
+	unlock_cpu_hotplug();
+
+	return ret;
+}
 EXPORT_SYMBOL_GPL(cpufreq_driver_target);
 
 int cpufreq_driver_getavg(struct cpufreq_policy *policy)
@@ -1511,13 +1524,8 @@ error_out:
 	return ret;
 }
 
-/**
- *	cpufreq_set_policy - set a new CPUFreq policy
- *	@policy: policy to be set.
- *
- *	Sets a new CPU frequency and voltage scaling policy.
- */
-int cpufreq_set_policy(struct cpufreq_policy *policy)
+/* Locking: To be called with lock_cpu_hotplug held. */
+int _cpufreq_set_policy(struct cpufreq_policy *policy)
 {
 	int ret = 0;
 	struct cpufreq_policy *data;
@@ -1529,8 +1537,6 @@ int cpufreq_set_policy(struct cpufreq_po
 	if (!data)
 		return -EINVAL;
 
-	lock_cpu_hotplug();
-
 	/* lock this CPU */
 	mutex_lock(&data->lock);
 
@@ -1541,23 +1547,32 @@ int cpufreq_set_policy(struct cpufreq_po
 	data->user_policy.governor = data->governor;
 
 	mutex_unlock(&data->lock);
-
-	unlock_cpu_hotplug();
 	cpufreq_cpu_put(data);
 
 	return ret;
 }
-EXPORT_SYMBOL(cpufreq_set_policy);
-
 
 /**
- *	cpufreq_update_policy - re-evaluate an existing cpufreq policy
- *	@cpu: CPU which shall be re-evaluated
+ *	cpufreq_set_policy - set a new CPUFreq policy
+ *	@policy: policy to be set.
  *
- *	Usefull for policy notifiers which have different necessities
- *	at different times.
+ *	Sets a new CPU frequency and voltage scaling policy.
  */
-int cpufreq_update_policy(unsigned int cpu)
+int cpufreq_set_policy(struct cpufreq_policy *policy)
+{
+	int ret;
+
+	lock_cpu_hotplug();
+	ret = _cpufreq_set_policy(policy);
+	unlock_cpu_hotplug();
+
+	return ret;
+}
+EXPORT_SYMBOL(cpufreq_set_policy);
+
+
+/* Locking: to be called with lock_cpu_hotplug held. */
+int __cpufreq_update_policy(unsigned int cpu)
 {
 	struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
 	struct cpufreq_policy policy;
@@ -1566,7 +1581,6 @@ int cpufreq_update_policy(unsigned int c
 	if (!data)
 		return -ENODEV;
 
-	lock_cpu_hotplug();
 	mutex_lock(&data->lock);
 
 	dprintk("updating policy for CPU %u\n", cpu);
@@ -1593,10 +1607,27 @@ int cpufreq_update_policy(unsigned int c
 	ret = __cpufreq_set_policy(data, &policy);
 
 	mutex_unlock(&data->lock);
-	unlock_cpu_hotplug();
 	cpufreq_cpu_put(data);
 	return ret;
 }
+
+/**
+ *	cpufreq_update_policy - re-evaluate an existing cpufreq policy
+ *	@cpu: CPU which shall be re-evaluated
+ *
+ *	Usefull for policy notifiers which have different necessities
+ *	at different times.
+ */
+int cpufreq_update_policy(unsigned int cpu)
+{
+	int ret;
+
+	lock_cpu_hotplug();
+	ret = __cpufreq_update_policy(cpu);
+	unlock_cpu_hotplug();
+
+	return ret;
+}
 EXPORT_SYMBOL(cpufreq_update_policy);
 
 #ifdef CONFIG_HOTPLUG_CPU
@@ -1623,7 +1654,7 @@ static int cpufreq_cpu_callback(struct n
 			 */
 			policy = cpufreq_cpu_data[cpu];
 			if (policy) {
-				cpufreq_driver_target(policy, policy->min,
+				_cpufreq_driver_target(policy, policy->min,
 						CPUFREQ_RELATION_H);
 			}
 			break;
Index: hotplug/drivers/cpufreq/cpufreq_stats.c
===================================================================
--- hotplug.orig/drivers/cpufreq/cpufreq_stats.c
+++ hotplug/drivers/cpufreq/cpufreq_stats.c
@@ -309,7 +309,7 @@ static int cpufreq_stat_cpu_callback(str
 
 	switch (action) {
 	case CPU_ONLINE:
-		cpufreq_update_policy(cpu);
+		__cpufreq_update_policy(cpu);
 		break;
 	case CPU_DEAD:
 		cpufreq_stats_free_table(cpu);
@@ -350,10 +350,12 @@ __init cpufreq_stats_init(void)
 	}
 
 	register_hotcpu_notifier(&cpufreq_stat_cpu_notifier);
+	lock_cpu_hotplug();
 	for_each_online_cpu(cpu) {
 		cpufreq_stat_cpu_callback(&cpufreq_stat_cpu_notifier,
 				CPU_ONLINE, (void *)(long)cpu);
 	}
+	unlock_cpu_hotplug();
 	return 0;
 }
 static void
Index: hotplug/include/linux/cpufreq.h
===================================================================
--- hotplug.orig/include/linux/cpufreq.h
+++ hotplug/include/linux/cpufreq.h
@@ -258,6 +258,7 @@ struct freq_attr {
 int cpufreq_set_policy(struct cpufreq_policy *policy);
 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
 int cpufreq_update_policy(unsigned int cpu);
+int __cpufreq_update_policy(unsigned int cpu);
 
 /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
 unsigned int cpufreq_get(unsigned int cpu);
-- 
Gautham R Shenoy
Linux Technology Center
IBM India.
"Freedom comes with a price tag of responsibility, which is still a bargain,
because Freedom is priceless!"

  reply	other threads:[~2006-10-26 10:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-26 10:48 [RFC 0/5] lock_cpu_hotplug: Redesign - A "lightweight" scalable version Gautham R Shenoy
2006-10-26 10:50 ` [PATCH 1/5] lock_cpu_hotplug:Redesign - Fix coding style issues in cpufreq Gautham R Shenoy
2006-10-26 10:53   ` Gautham R Shenoy [this message]
2006-10-26 10:55     ` [PATCH 3/5] lock_cpu_hotplug:Redesign - Use lock_cpu_hotplug in workqueue.c instead of workqueue_mutex Gautham R Shenoy
2006-10-26 10:57       ` [PATCH 4/5] lock_cpu_hotplug: Redesign - Lightweight implementation of lock_cpu_hotplug Gautham R Shenoy
2006-10-26 10:58         ` [PATCH 5/5] lock_cpu_hotplug: Redesign - Lockdep support for lightweight lock_cpu_hotplug Gautham R Shenoy
2006-10-26 21:14         ` [PATCH 4/5] lock_cpu_hotplug: Redesign - Lightweight implementation of lock_cpu_hotplug Paul Jackson
2006-10-27  3:49           ` Gautham R Shenoy

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=20061026105342.GC11803@in.ibm.com \
    --to=ego@in.ibm.com \
    --cc=akpm@osdl.org \
    --cc=arjan@linux.intel.org \
    --cc=davej@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=gaughen@us.ibm.com \
    --cc=kiran@scalex86.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulmck@us.ibm.com \
    --cc=rusty@rustcorp.com.au \
    --cc=torvalds@osdl.org \
    --cc=vatsa@in.ibm.com \
    --cc=venkatesh.pallipadi@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