182
180
/*********************************************************************
183
* UNIFIED DEBUG HELPERS *
184
*********************************************************************/
185
#ifdef CONFIG_CPU_FREQ_DEBUG
187
/* what part(s) of the CPUfreq subsystem are debugged? */
188
static unsigned int debug;
190
/* is the debug output ratelimit'ed using printk_ratelimit? User can
191
* set or modify this value.
193
static unsigned int debug_ratelimit = 1;
195
/* is the printk_ratelimit'ing enabled? It's enabled after a successful
196
* loading of a cpufreq driver, temporarily disabled when a new policy
197
* is set, and disabled upon cpufreq driver removal
199
static unsigned int disable_ratelimit = 1;
200
static DEFINE_SPINLOCK(disable_ratelimit_lock);
202
static void cpufreq_debug_enable_ratelimit(void)
206
spin_lock_irqsave(&disable_ratelimit_lock, flags);
207
if (disable_ratelimit)
209
spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
212
static void cpufreq_debug_disable_ratelimit(void)
216
spin_lock_irqsave(&disable_ratelimit_lock, flags);
218
spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
221
void cpufreq_debug_printk(unsigned int type, const char *prefix,
222
const char *fmt, ...)
231
spin_lock_irqsave(&disable_ratelimit_lock, flags);
232
if (!disable_ratelimit && debug_ratelimit
233
&& !printk_ratelimit()) {
234
spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
237
spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
239
len = snprintf(s, 256, KERN_DEBUG "%s: ", prefix);
242
len += vsnprintf(&s[len], (256 - len), fmt, args);
250
EXPORT_SYMBOL(cpufreq_debug_printk);
253
module_param(debug, uint, 0644);
254
MODULE_PARM_DESC(debug, "CPUfreq debugging: add 1 to debug core,"
255
" 2 to debug drivers, and 4 to debug governors.");
257
module_param(debug_ratelimit, uint, 0644);
258
MODULE_PARM_DESC(debug_ratelimit, "CPUfreq debugging:"
259
" set to 0 to disable ratelimiting.");
261
#else /* !CONFIG_CPU_FREQ_DEBUG */
263
static inline void cpufreq_debug_enable_ratelimit(void) { return; }
264
static inline void cpufreq_debug_disable_ratelimit(void) { return; }
266
#endif /* CONFIG_CPU_FREQ_DEBUG */
269
/*********************************************************************
270
181
* EXTERNALLY AFFECTING FREQUENCY CHANGES *
271
182
*********************************************************************/
339
250
if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
340
251
if ((policy) && (policy->cpu == freqs->cpu) &&
341
252
(policy->cur) && (policy->cur != freqs->old)) {
342
dprintk("Warning: CPU frequency is"
253
pr_debug("Warning: CPU frequency is"
343
254
" %u, cpufreq assumed %u kHz.\n",
344
255
freqs->old, policy->cur);
345
256
freqs->old = policy->cur;
353
264
case CPUFREQ_POSTCHANGE:
354
265
adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
355
dprintk("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new,
266
pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new,
356
267
(unsigned long)freqs->cpu);
357
268
trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu);
358
269
trace_cpu_frequency(freqs->new, freqs->cpu);
410
321
t = __find_governor(str_governor);
413
char *name = kasprintf(GFP_KERNEL, "cpufreq_%s",
419
mutex_unlock(&cpufreq_governor_mutex);
420
ret = request_module("%s", name);
421
mutex_lock(&cpufreq_governor_mutex);
424
t = __find_governor(str_governor);
326
mutex_unlock(&cpufreq_governor_mutex);
327
ret = request_module("cpufreq_%s", str_governor);
328
mutex_lock(&cpufreq_governor_mutex);
331
t = __find_governor(str_governor);
864
768
if (!cpu_online(j))
867
dprintk("CPU %u already managed, adding link\n", j);
771
pr_debug("CPU %u already managed, adding link\n", j);
868
772
managed_policy = cpufreq_cpu_get(cpu);
869
773
cpu_sys_dev = get_cpu_sysdev(j);
870
774
ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
1111
1011
unsigned int j;
1114
cpufreq_debug_disable_ratelimit();
1115
dprintk("unregistering CPU %u\n", cpu);
1014
pr_debug("unregistering CPU %u\n", cpu);
1117
1016
spin_lock_irqsave(&cpufreq_driver_lock, flags);
1118
1017
data = per_cpu(cpufreq_cpu_data, cpu);
1121
1020
spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1122
cpufreq_debug_enable_ratelimit();
1123
1021
unlock_policy_rwsem_write(cpu);
1124
1022
return -EINVAL;
1131
1029
* only need to unlink, put and exit
1133
1031
if (unlikely(cpu != data->cpu)) {
1134
dprintk("removing link\n");
1032
pr_debug("removing link\n");
1135
1033
cpumask_clear_cpu(cpu, data->cpus);
1136
1034
spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1137
1035
kobj = &sys_dev->kobj;
1138
1036
cpufreq_cpu_put(data);
1139
cpufreq_debug_enable_ratelimit();
1140
1037
unlock_policy_rwsem_write(cpu);
1141
1038
sysfs_remove_link(kobj, "cpufreq");
1169
1066
for_each_cpu(j, data->cpus) {
1172
dprintk("removing link for cpu %u\n", j);
1069
pr_debug("removing link for cpu %u\n", j);
1173
1070
#ifdef CONFIG_HOTPLUG_CPU
1174
1071
strncpy(per_cpu(cpufreq_cpu_governor, j),
1175
1072
data->governor->name, CPUFREQ_NAME_LEN);
1198
1095
* not referenced anymore by anybody before we proceed with
1201
dprintk("waiting for dropping of refcount\n");
1098
pr_debug("waiting for dropping of refcount\n");
1202
1099
wait_for_completion(cmp);
1203
dprintk("wait complete\n");
1100
pr_debug("wait complete\n");
1205
1102
lock_policy_rwsem_write(cpu);
1206
1103
if (cpufreq_driver->exit)
1207
1104
cpufreq_driver->exit(data);
1208
1105
unlock_policy_rwsem_write(cpu);
1107
#ifdef CONFIG_HOTPLUG_CPU
1108
/* when the CPU which is the parent of the kobj is hotplugged
1109
* offline, check for siblings, and create cpufreq sysfs interface
1112
if (unlikely(cpumask_weight(data->cpus) > 1)) {
1113
/* first sibling now owns the new sysfs dir */
1114
cpumask_clear_cpu(cpu, data->cpus);
1115
cpufreq_add_dev(get_cpu_sysdev(cpumask_first(data->cpus)));
1117
/* finally remove our own symlink */
1118
lock_policy_rwsem_write(cpu);
1119
__cpufreq_remove_dev(sys_dev);
1210
1123
free_cpumask_var(data->related_cpus);
1211
1124
free_cpumask_var(data->cpus);
1213
per_cpu(cpufreq_cpu_data, cpu) = NULL;
1215
cpufreq_debug_enable_ratelimit();
1238
1149
struct cpufreq_policy *policy =
1239
1150
container_of(work, struct cpufreq_policy, update);
1240
1151
unsigned int cpu = policy->cpu;
1241
dprintk("handle_update for cpu %u called\n", cpu);
1152
pr_debug("handle_update for cpu %u called\n", cpu);
1242
1153
cpufreq_update_policy(cpu);
1341
1252
EXPORT_SYMBOL(cpufreq_get);
1254
static struct sysdev_driver cpufreq_sysdev_driver = {
1255
.add = cpufreq_add_dev,
1256
.remove = cpufreq_remove_dev,
1345
* cpufreq_suspend - let the low level driver prepare for suspend
1261
* cpufreq_bp_suspend - Prepare the boot CPU for system suspend.
1263
* This function is only executed for the boot processor. The other CPUs
1264
* have been put offline by means of CPU hotplug.
1348
static int cpufreq_suspend(struct sys_device *sysdev, pm_message_t pmsg)
1266
static int cpufreq_bp_suspend(void)
1352
int cpu = sysdev->id;
1270
int cpu = smp_processor_id();
1353
1271
struct cpufreq_policy *cpu_policy;
1355
dprintk("suspending cpu %u\n", cpu);
1357
if (!cpu_online(cpu))
1360
/* we may be lax here as interrupts are off. Nonetheless
1361
* we need to grab the correct cpu policy, as to check
1362
* whether we really run on this CPU.
1273
pr_debug("suspending cpu %u\n", cpu);
1275
/* If there's no policy for the boot CPU, we have nothing to do. */
1365
1276
cpu_policy = cpufreq_cpu_get(cpu);
1366
1277
if (!cpu_policy)
1369
/* only handle each CPU group once */
1370
if (unlikely(cpu_policy->cpu != cpu))
1373
1280
if (cpufreq_driver->suspend) {
1374
1281
ret = cpufreq_driver->suspend(cpu_policy);
1391
1297
* what we believe it to be. This is a bit later than when it
1392
1298
* should be, but nonethteless it's better than calling
1393
1299
* cpufreq_driver->get() here which might re-enable interrupts...
1301
* This function is only executed for the boot CPU. The other CPUs have not
1302
* been turned on yet.
1395
static int cpufreq_resume(struct sys_device *sysdev)
1304
static void cpufreq_bp_resume(void)
1399
int cpu = sysdev->id;
1308
int cpu = smp_processor_id();
1400
1309
struct cpufreq_policy *cpu_policy;
1402
dprintk("resuming cpu %u\n", cpu);
1404
if (!cpu_online(cpu))
1407
/* we may be lax here as interrupts are off. Nonetheless
1408
* we need to grab the correct cpu policy, as to check
1409
* whether we really run on this CPU.
1311
pr_debug("resuming cpu %u\n", cpu);
1313
/* If there's no policy for the boot CPU, we have nothing to do. */
1412
1314
cpu_policy = cpufreq_cpu_get(cpu);
1413
1315
if (!cpu_policy)
1416
/* only handle each CPU group once */
1417
if (unlikely(cpu_policy->cpu != cpu))
1420
1318
if (cpufreq_driver->resume) {
1421
1319
ret = cpufreq_driver->resume(cpu_policy);
1432
1330
cpufreq_cpu_put(cpu_policy);
1436
static struct sysdev_driver cpufreq_sysdev_driver = {
1437
.add = cpufreq_add_dev,
1438
.remove = cpufreq_remove_dev,
1439
.suspend = cpufreq_suspend,
1440
.resume = cpufreq_resume,
1333
static struct syscore_ops cpufreq_syscore_ops = {
1334
.suspend = cpufreq_bp_suspend,
1335
.resume = cpufreq_bp_resume,
1526
1421
int retval = -EINVAL;
1528
dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu,
1423
pr_debug("target for CPU %u: %u kHz, relation %u\n", policy->cpu,
1529
1424
target_freq, relation);
1530
1425
if (cpu_online(policy->cpu) && cpufreq_driver->target)
1531
1426
retval = cpufreq_driver->target(policy, target_freq, relation);
1715
cpufreq_debug_disable_ratelimit();
1716
dprintk("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu,
1610
pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu,
1717
1611
policy->min, policy->max);
1719
1613
memcpy(&policy->cpuinfo, &data->cpuinfo,
1750
1644
data->min = policy->min;
1751
1645
data->max = policy->max;
1753
dprintk("new min and max freqs are %u - %u kHz\n",
1647
pr_debug("new min and max freqs are %u - %u kHz\n",
1754
1648
data->min, data->max);
1756
1650
if (cpufreq_driver->setpolicy) {
1757
1651
data->policy = policy->policy;
1758
dprintk("setting range\n");
1652
pr_debug("setting range\n");
1759
1653
ret = cpufreq_driver->setpolicy(policy);
1761
1655
if (policy->governor != data->governor) {
1762
1656
/* save old, working values */
1763
1657
struct cpufreq_governor *old_gov = data->governor;
1765
dprintk("governor switch\n");
1659
pr_debug("governor switch\n");
1767
1661
/* end old governor */
1768
1662
if (data->governor)
1772
1666
data->governor = policy->governor;
1773
1667
if (__cpufreq_governor(data, CPUFREQ_GOV_START)) {
1774
1668
/* new governor failed, so re-start old one */
1775
dprintk("starting governor %s failed\n",
1669
pr_debug("starting governor %s failed\n",
1776
1670
data->governor->name);
1778
1672
data->governor = old_gov;
1936
1829
/* if all ->init() calls failed, unregister */
1938
dprintk("no CPU initialized for driver %s\n",
1831
pr_debug("no CPU initialized for driver %s\n",
1939
1832
driver_data->name);
1940
1833
goto err_sysdev_unreg;
1944
1837
register_hotcpu_notifier(&cpufreq_cpu_notifier);
1945
dprintk("driver %s up and running\n", driver_data->name);
1946
cpufreq_debug_enable_ratelimit();
1838
pr_debug("driver %s up and running\n", driver_data->name);
1949
1841
err_sysdev_unreg:
1971
1863
unsigned long flags;
1973
cpufreq_debug_disable_ratelimit();
1975
if (!cpufreq_driver || (driver != cpufreq_driver)) {
1976
cpufreq_debug_enable_ratelimit();
1865
if (!cpufreq_driver || (driver != cpufreq_driver))
1977
1866
return -EINVAL;
1980
dprintk("unregistering driver %s\n", driver->name);
1868
pr_debug("unregistering driver %s\n", driver->name);
1982
1870
sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver);
1983
1871
unregister_hotcpu_notifier(&cpufreq_cpu_notifier);