diff options
author | Arjan van de Ven <arjan@linux.intel.com> | 2006-07-26 09:40:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-07-26 10:21:40 -0400 |
commit | 153d7f3fcae7ed4e19328549aa9467acdfbced10 (patch) | |
tree | a7b15b844119663a276c7a99549ea5a06c16f19a /drivers/cpufreq/cpufreq.c | |
parent | 44eb123126d289bac398cac0232309c228386671 (diff) |
[PATCH] Reorganize the cpufreq cpu hotplug locking to not be totally bizare
The patch below moves the cpu hotplugging higher up in the cpufreq
layering; this is needed to avoid recursive taking of the cpu hotplug
lock and to otherwise detangle the mess.
The new rules are:
1. you must do lock_cpu_hotplug() around the following functions:
__cpufreq_driver_target
__cpufreq_governor (for CPUFREQ_GOV_LIMITS operation only)
__cpufreq_set_policy
2. governer methods (.governer) must NOT take the lock_cpu_hotplug()
lock in any way; they are called with the lock taken already
3. if your governer spawns a thread that does things, like calling
__cpufreq_driver_target, your thread must honor rule #1.
4. the policy lock and other cpufreq internal locks nest within
the lock_cpu_hotplug() lock.
I'm not entirely happy about how the __cpufreq_governor rule ended up
(conditional locking rule depending on the argument) but basically all
callers pass this as a constant so it's not too horrible.
The patch also removes the cpufreq_governor() function since during the
locking audit it turned out to be entirely unused (so no need to fix it)
The patch works on my testbox, but it could use more testing
(otoh... it can't be much worse than the current code)
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/cpufreq/cpufreq.c')
-rw-r--r-- | drivers/cpufreq/cpufreq.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 8d328186f774..bc1088d9b379 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -364,10 +364,12 @@ static ssize_t store_##file_name \ | |||
364 | if (ret != 1) \ | 364 | if (ret != 1) \ |
365 | return -EINVAL; \ | 365 | return -EINVAL; \ |
366 | \ | 366 | \ |
367 | lock_cpu_hotplug(); \ | ||
367 | mutex_lock(&policy->lock); \ | 368 | mutex_lock(&policy->lock); \ |
368 | ret = __cpufreq_set_policy(policy, &new_policy); \ | 369 | ret = __cpufreq_set_policy(policy, &new_policy); \ |
369 | policy->user_policy.object = policy->object; \ | 370 | policy->user_policy.object = policy->object; \ |
370 | mutex_unlock(&policy->lock); \ | 371 | mutex_unlock(&policy->lock); \ |
372 | unlock_cpu_hotplug(); \ | ||
371 | \ | 373 | \ |
372 | return ret ? ret : count; \ | 374 | return ret ? ret : count; \ |
373 | } | 375 | } |
@@ -1197,20 +1199,18 @@ EXPORT_SYMBOL(cpufreq_unregister_notifier); | |||
1197 | *********************************************************************/ | 1199 | *********************************************************************/ |
1198 | 1200 | ||
1199 | 1201 | ||
1202 | /* Must be called with lock_cpu_hotplug held */ | ||
1200 | int __cpufreq_driver_target(struct cpufreq_policy *policy, | 1203 | int __cpufreq_driver_target(struct cpufreq_policy *policy, |
1201 | unsigned int target_freq, | 1204 | unsigned int target_freq, |
1202 | unsigned int relation) | 1205 | unsigned int relation) |
1203 | { | 1206 | { |
1204 | int retval = -EINVAL; | 1207 | int retval = -EINVAL; |
1205 | 1208 | ||
1206 | lock_cpu_hotplug(); | ||
1207 | dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu, | 1209 | dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu, |
1208 | target_freq, relation); | 1210 | target_freq, relation); |
1209 | if (cpu_online(policy->cpu) && cpufreq_driver->target) | 1211 | if (cpu_online(policy->cpu) && cpufreq_driver->target) |
1210 | retval = cpufreq_driver->target(policy, target_freq, relation); | 1212 | retval = cpufreq_driver->target(policy, target_freq, relation); |
1211 | 1213 | ||
1212 | unlock_cpu_hotplug(); | ||
1213 | |||
1214 | return retval; | 1214 | return retval; |
1215 | } | 1215 | } |
1216 | EXPORT_SYMBOL_GPL(__cpufreq_driver_target); | 1216 | EXPORT_SYMBOL_GPL(__cpufreq_driver_target); |
@@ -1225,17 +1225,23 @@ int cpufreq_driver_target(struct cpufreq_policy *policy, | |||
1225 | if (!policy) | 1225 | if (!policy) |
1226 | return -EINVAL; | 1226 | return -EINVAL; |
1227 | 1227 | ||
1228 | lock_cpu_hotplug(); | ||
1228 | mutex_lock(&policy->lock); | 1229 | mutex_lock(&policy->lock); |
1229 | 1230 | ||
1230 | ret = __cpufreq_driver_target(policy, target_freq, relation); | 1231 | ret = __cpufreq_driver_target(policy, target_freq, relation); |
1231 | 1232 | ||
1232 | mutex_unlock(&policy->lock); | 1233 | mutex_unlock(&policy->lock); |
1234 | unlock_cpu_hotplug(); | ||
1233 | 1235 | ||
1234 | cpufreq_cpu_put(policy); | 1236 | cpufreq_cpu_put(policy); |
1235 | return ret; | 1237 | return ret; |
1236 | } | 1238 | } |
1237 | EXPORT_SYMBOL_GPL(cpufreq_driver_target); | 1239 | EXPORT_SYMBOL_GPL(cpufreq_driver_target); |
1238 | 1240 | ||
1241 | /* | ||
1242 | * Locking: Must be called with the lock_cpu_hotplug() lock held | ||
1243 | * when "event" is CPUFREQ_GOV_LIMITS | ||
1244 | */ | ||
1239 | 1245 | ||
1240 | static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event) | 1246 | static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event) |
1241 | { | 1247 | { |
@@ -1257,24 +1263,6 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event) | |||
1257 | } | 1263 | } |
1258 | 1264 | ||
1259 | 1265 | ||
1260 | int cpufreq_governor(unsigned int cpu, unsigned int event) | ||
1261 | { | ||
1262 | int ret = 0; | ||
1263 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); | ||
1264 | |||
1265 | if (!policy) | ||
1266 | return -EINVAL; | ||
1267 | |||
1268 | mutex_lock(&policy->lock); | ||
1269 | ret = __cpufreq_governor(policy, event); | ||
1270 | mutex_unlock(&policy->lock); | ||
1271 | |||
1272 | cpufreq_cpu_put(policy); | ||
1273 | return ret; | ||
1274 | } | ||
1275 | EXPORT_SYMBOL_GPL(cpufreq_governor); | ||
1276 | |||
1277 | |||
1278 | int cpufreq_register_governor(struct cpufreq_governor *governor) | 1266 | int cpufreq_register_governor(struct cpufreq_governor *governor) |
1279 | { | 1267 | { |
1280 | struct cpufreq_governor *t; | 1268 | struct cpufreq_governor *t; |
@@ -1342,6 +1330,9 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu) | |||
1342 | EXPORT_SYMBOL(cpufreq_get_policy); | 1330 | EXPORT_SYMBOL(cpufreq_get_policy); |
1343 | 1331 | ||
1344 | 1332 | ||
1333 | /* | ||
1334 | * Locking: Must be called with the lock_cpu_hotplug() lock held | ||
1335 | */ | ||
1345 | static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy) | 1336 | static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy) |
1346 | { | 1337 | { |
1347 | int ret = 0; | 1338 | int ret = 0; |
@@ -1436,6 +1427,8 @@ int cpufreq_set_policy(struct cpufreq_policy *policy) | |||
1436 | if (!data) | 1427 | if (!data) |
1437 | return -EINVAL; | 1428 | return -EINVAL; |
1438 | 1429 | ||
1430 | lock_cpu_hotplug(); | ||
1431 | |||
1439 | /* lock this CPU */ | 1432 | /* lock this CPU */ |
1440 | mutex_lock(&data->lock); | 1433 | mutex_lock(&data->lock); |
1441 | 1434 | ||
@@ -1446,6 +1439,8 @@ int cpufreq_set_policy(struct cpufreq_policy *policy) | |||
1446 | data->user_policy.governor = data->governor; | 1439 | data->user_policy.governor = data->governor; |
1447 | 1440 | ||
1448 | mutex_unlock(&data->lock); | 1441 | mutex_unlock(&data->lock); |
1442 | |||
1443 | unlock_cpu_hotplug(); | ||
1449 | cpufreq_cpu_put(data); | 1444 | cpufreq_cpu_put(data); |
1450 | 1445 | ||
1451 | return ret; | 1446 | return ret; |
@@ -1469,6 +1464,7 @@ int cpufreq_update_policy(unsigned int cpu) | |||
1469 | if (!data) | 1464 | if (!data) |
1470 | return -ENODEV; | 1465 | return -ENODEV; |
1471 | 1466 | ||
1467 | lock_cpu_hotplug(); | ||
1472 | mutex_lock(&data->lock); | 1468 | mutex_lock(&data->lock); |
1473 | 1469 | ||
1474 | dprintk("updating policy for CPU %u\n", cpu); | 1470 | dprintk("updating policy for CPU %u\n", cpu); |
@@ -1494,7 +1490,7 @@ int cpufreq_update_policy(unsigned int cpu) | |||
1494 | ret = __cpufreq_set_policy(data, &policy); | 1490 | ret = __cpufreq_set_policy(data, &policy); |
1495 | 1491 | ||
1496 | mutex_unlock(&data->lock); | 1492 | mutex_unlock(&data->lock); |
1497 | 1493 | unlock_cpu_hotplug(); | |
1498 | cpufreq_cpu_put(data); | 1494 | cpufreq_cpu_put(data); |
1499 | return ret; | 1495 | return ret; |
1500 | } | 1496 | } |