]> err.no Git - linux-2.6/blobdiff - drivers/cpufreq/cpufreq.c
ftrace: add ftrace_kill_atomic
[linux-2.6] / drivers / cpufreq / cpufreq.c
index 0f10ce21d879ed8b2c955fdda7e7ed88dac38853..1d41496ed2f83b648e1311ee8fecccbd56ad741d 100644 (file)
@@ -118,9 +118,11 @@ static void handle_update(struct work_struct *work);
 static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list);
 static struct srcu_notifier_head cpufreq_transition_notifier_list;
 
+static bool init_cpufreq_transition_notifier_list_called;
 static int __init init_cpufreq_transition_notifier_list(void)
 {
        srcu_init_notifier_head(&cpufreq_transition_notifier_list);
+       init_cpufreq_transition_notifier_list_called = true;
        return 0;
 }
 pure_initcall(init_cpufreq_transition_notifier_list);
@@ -410,7 +412,7 @@ static int cpufreq_parse_governor(char *str_governor, unsigned int *policy,
                                int ret;
 
                                mutex_unlock(&cpufreq_governor_mutex);
-                               ret = request_module(name);
+                               ret = request_module("%s", name);
                                mutex_lock(&cpufreq_governor_mutex);
 
                                if (ret == 0)
@@ -581,15 +583,13 @@ out:
        i += sprintf(&buf[i], "\n");
        return i;
 }
-/**
- * show_affected_cpus - show the CPUs affected by each transition
- */
-static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
+
+static ssize_t show_cpus(cpumask_t mask, char *buf)
 {
        ssize_t i = 0;
        unsigned int cpu;
 
-       for_each_cpu_mask(cpu, policy->cpus) {
+       for_each_cpu_mask(cpu, mask) {
                if (i)
                        i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
                i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
@@ -600,13 +600,32 @@ static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
        return i;
 }
 
+/**
+ * show_related_cpus - show the CPUs affected by each transition even if
+ * hw coordination is in use
+ */
+static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
+{
+       if (cpus_empty(policy->related_cpus))
+               return show_cpus(policy->cpus, buf);
+       return show_cpus(policy->related_cpus, buf);
+}
+
+/**
+ * show_affected_cpus - show the CPUs affected by each transition
+ */
+static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
+{
+       return show_cpus(policy->cpus, buf);
+}
+
 static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
                                        const char *buf, size_t count)
 {
        unsigned int freq = 0;
        unsigned int ret;
 
-       if (!policy->governor->store_setspeed)
+       if (!policy->governor || !policy->governor->store_setspeed)
                return -EINVAL;
 
        ret = sscanf(buf, "%u", &freq);
@@ -620,7 +639,7 @@ static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
 
 static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
 {
-       if (!policy->governor->show_setspeed)
+       if (!policy->governor || !policy->governor->show_setspeed)
                return sprintf(buf, "<unsupported>\n");
 
        return policy->governor->show_setspeed(policy, buf);
@@ -644,6 +663,7 @@ define_one_ro(cpuinfo_max_freq);
 define_one_ro(scaling_available_governors);
 define_one_ro(scaling_driver);
 define_one_ro(scaling_cur_freq);
+define_one_ro(related_cpus);
 define_one_ro(affected_cpus);
 define_one_rw(scaling_min_freq);
 define_one_rw(scaling_max_freq);
@@ -656,6 +676,7 @@ static struct attribute *default_attrs[] = {
        &scaling_min_freq.attr,
        &scaling_max_freq.attr,
        &affected_cpus.attr,
+       &related_cpus.attr,
        &scaling_governor.attr,
        &scaling_driver.attr,
        &scaling_available_governors.attr,
@@ -799,7 +820,6 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
        ret = cpufreq_driver->init(policy);
        if (ret) {
                dprintk("initialization failed\n");
-               unlock_policy_rwsem_write(cpu);
                goto err_out;
        }
        policy->user_policy.min = policy->cpuinfo.min_freq;
@@ -822,7 +842,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
                /* check for existing affected CPUs.  They may not be aware
                 * of it due to CPU Hotplug.
                 */
-               managed_policy = cpufreq_cpu_get(j);
+               managed_policy = cpufreq_cpu_get(j);            // FIXME: Where is this released?  What about error paths?
                if (unlikely(managed_policy)) {
 
                        /* Set proper policy_cpu */
@@ -841,14 +861,11 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
                        ret = sysfs_create_link(&sys_dev->kobj,
                                                &managed_policy->kobj,
                                                "cpufreq");
-                       if (ret) {
-                               unlock_policy_rwsem_write(cpu);
+                       if (ret)
                                goto err_out_driver_exit;
-                       }
 
                        cpufreq_debug_enable_ratelimit();
                        ret = 0;
-                       unlock_policy_rwsem_write(cpu);
                        goto err_out_driver_exit; /* call driver->exit() */
                }
        }
@@ -858,33 +875,26 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
        /* prepare interface data */
        ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, &sys_dev->kobj,
                                   "cpufreq");
-       if (ret) {
-               unlock_policy_rwsem_write(cpu);
+       if (ret)
                goto err_out_driver_exit;
-       }
+
        /* set up files for this cpu device */
        drv_attr = cpufreq_driver->attr;
        while ((drv_attr) && (*drv_attr)) {
                ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
-               if (ret) {
-                       unlock_policy_rwsem_write(cpu);
+               if (ret)
                        goto err_out_driver_exit;
-               }
                drv_attr++;
        }
-       if (cpufreq_driver->get){
+       if (cpufreq_driver->get) {
                ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
-               if (ret) {
-                       unlock_policy_rwsem_write(cpu);
+               if (ret)
                        goto err_out_driver_exit;
-               }
        }
-       if (cpufreq_driver->target){
+       if (cpufreq_driver->target) {
                ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
-               if (ret) {
-                       unlock_policy_rwsem_write(cpu);
+               if (ret)
                        goto err_out_driver_exit;
-               }
        }
 
        spin_lock_irqsave(&cpufreq_driver_lock, flags);
@@ -906,10 +916,8 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
                cpu_sys_dev = get_cpu_sysdev(j);
                ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
                                        "cpufreq");
-               if (ret) {
-                       unlock_policy_rwsem_write(cpu);
+               if (ret)
                        goto err_out_unregister;
-               }
        }
 
        policy->governor = NULL; /* to assure that the starting sequence is
@@ -920,13 +928,13 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
        policy->user_policy.policy = policy->policy;
        policy->user_policy.governor = policy->governor;
 
-       unlock_policy_rwsem_write(cpu);
-
        if (ret) {
                dprintk("setting policy failed\n");
                goto err_out_unregister;
        }
 
+       unlock_policy_rwsem_write(cpu);
+
        kobject_uevent(&policy->kobj, KOBJ_ADD);
        module_put(cpufreq_driver->owner);
        dprintk("initialization complete\n");
@@ -949,6 +957,7 @@ err_out_driver_exit:
                cpufreq_driver->exit(policy);
 
 err_out:
+       unlock_policy_rwsem_write(cpu);
        kfree(policy);
 
 nomem_out:
@@ -1379,6 +1388,8 @@ int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
 {
        int ret;
 
+       WARN_ON(!init_cpufreq_transition_notifier_list_called);
+
        switch (list) {
        case CPUFREQ_TRANSITION_NOTIFIER:
                ret = srcu_notifier_chain_register(