X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fcpufreq%2Fcpufreq_userspace.c;h=cb2ac01a41a1c55a0faa2480d823aa91b7b3b001;hb=c906049447019d69b9cc2d591a142af561afa7f9;hp=a648970338b09a1a641799fc3d52e10b2d14b604;hpb=7b595756ec1f49e0049a9e01a1298d53a7faaa15;p=linux-2.6 diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c index a648970338..cb2ac01a41 100644 --- a/drivers/cpufreq/cpufreq_userspace.c +++ b/drivers/cpufreq/cpufreq_userspace.c @@ -37,6 +37,7 @@ static unsigned int cpu_set_freq[NR_CPUS]; /* CPU freq desired by userspace */ static unsigned int cpu_is_managed[NR_CPUS]; static DEFINE_MUTEX (userspace_mutex); +static int cpus_using_userspace_governor; #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg) @@ -47,7 +48,11 @@ userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val, { struct cpufreq_freqs *freq = data; - dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n", freq->cpu, freq->new); + if (!cpu_is_managed[freq->cpu]) + return 0; + + dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n", + freq->cpu, freq->new); cpu_cur_freq[freq->cpu] = freq->new; return 0; @@ -60,12 +65,12 @@ static struct notifier_block userspace_cpufreq_notifier_block = { /** * cpufreq_set - set the CPU frequency + * @policy: pointer to policy struct where freq is being set * @freq: target frequency in kHz - * @cpu: CPU for which the frequency is to be set * * Sets the CPU frequency to freq. */ -static int cpufreq_set(unsigned int freq, struct cpufreq_policy *policy) +static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq) { int ret = -EINVAL; @@ -97,34 +102,11 @@ static int cpufreq_set(unsigned int freq, struct cpufreq_policy *policy) } -/************************** sysfs interface ************************/ -static ssize_t show_speed (struct cpufreq_policy *policy, char *buf) -{ - return sprintf (buf, "%u\n", cpu_cur_freq[policy->cpu]); -} - -static ssize_t -store_speed (struct cpufreq_policy *policy, const char *buf, size_t count) +static ssize_t show_speed(struct cpufreq_policy *policy, char *buf) { - unsigned int freq = 0; - unsigned int ret; - - ret = sscanf (buf, "%u", &freq); - if (ret != 1) - return -EINVAL; - - cpufreq_set(freq, policy); - - return count; + return sprintf(buf, "%u\n", cpu_cur_freq[policy->cpu]); } -static struct freq_attr freq_attr_scaling_setspeed = -{ - .attr = { .name = "scaling_setspeed", .mode = 0644 }, - .show = show_speed, - .store = store_speed, -}; - static int cpufreq_governor_userspace(struct cpufreq_policy *policy, unsigned int event) { @@ -137,10 +119,13 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, return -EINVAL; BUG_ON(!policy->cur); mutex_lock(&userspace_mutex); - rc = sysfs_create_file (&policy->kobj, - &freq_attr_scaling_setspeed.attr); - if (rc) - goto start_out; + + if (cpus_using_userspace_governor == 0) { + cpufreq_register_notifier( + &userspace_cpufreq_notifier_block, + CPUFREQ_TRANSITION_NOTIFIER); + } + cpus_using_userspace_governor++; cpu_is_managed[cpu] = 1; cpu_min_freq[cpu] = policy->min; @@ -148,16 +133,22 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, cpu_cur_freq[cpu] = policy->cur; cpu_set_freq[cpu] = policy->cur; dprintk("managing cpu %u started (%u - %u kHz, currently %u kHz)\n", cpu, cpu_min_freq[cpu], cpu_max_freq[cpu], cpu_cur_freq[cpu]); -start_out: + mutex_unlock(&userspace_mutex); break; case CPUFREQ_GOV_STOP: mutex_lock(&userspace_mutex); + cpus_using_userspace_governor--; + if (cpus_using_userspace_governor == 0) { + cpufreq_unregister_notifier( + &userspace_cpufreq_notifier_block, + CPUFREQ_TRANSITION_NOTIFIER); + } + cpu_is_managed[cpu] = 0; cpu_min_freq[cpu] = 0; cpu_max_freq[cpu] = 0; cpu_set_freq[cpu] = 0; - sysfs_remove_file (&policy->kobj, &freq_attr_scaling_setspeed.attr); dprintk("managing cpu %u stopped\n", cpu); mutex_unlock(&userspace_mutex); break; @@ -192,13 +183,14 @@ start_out: struct cpufreq_governor cpufreq_gov_userspace = { .name = "userspace", .governor = cpufreq_governor_userspace, + .store_setspeed = cpufreq_set, + .show_setspeed = show_speed, .owner = THIS_MODULE, }; EXPORT_SYMBOL(cpufreq_gov_userspace); static int __init cpufreq_gov_userspace_init(void) { - cpufreq_register_notifier(&userspace_cpufreq_notifier_block, CPUFREQ_TRANSITION_NOTIFIER); return cpufreq_register_governor(&cpufreq_gov_userspace); } @@ -206,7 +198,6 @@ static int __init cpufreq_gov_userspace_init(void) static void __exit cpufreq_gov_userspace_exit(void) { cpufreq_unregister_governor(&cpufreq_gov_userspace); - cpufreq_unregister_notifier(&userspace_cpufreq_notifier_block, CPUFREQ_TRANSITION_NOTIFIER); } @@ -214,5 +205,9 @@ MODULE_AUTHOR ("Dominik Brodowski , Russell King