diff options
| -rw-r--r-- | drivers/cpufreq/cpufreq_userspace.c | 79 |
1 files changed, 43 insertions, 36 deletions
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c index cb2ac01a41a1..32244aa7cc0c 100644 --- a/drivers/cpufreq/cpufreq_userspace.c +++ b/drivers/cpufreq/cpufreq_userspace.c | |||
| @@ -30,16 +30,18 @@ | |||
| 30 | /** | 30 | /** |
| 31 | * A few values needed by the userspace governor | 31 | * A few values needed by the userspace governor |
| 32 | */ | 32 | */ |
| 33 | static unsigned int cpu_max_freq[NR_CPUS]; | 33 | static DEFINE_PER_CPU(unsigned int, cpu_max_freq); |
| 34 | static unsigned int cpu_min_freq[NR_CPUS]; | 34 | static DEFINE_PER_CPU(unsigned int, cpu_min_freq); |
| 35 | static unsigned int cpu_cur_freq[NR_CPUS]; /* current CPU freq */ | 35 | static DEFINE_PER_CPU(unsigned int, cpu_cur_freq); /* current CPU freq */ |
| 36 | static unsigned int cpu_set_freq[NR_CPUS]; /* CPU freq desired by userspace */ | 36 | static DEFINE_PER_CPU(unsigned int, cpu_set_freq); /* CPU freq desired by |
| 37 | static unsigned int cpu_is_managed[NR_CPUS]; | 37 | userspace */ |
| 38 | static DEFINE_PER_CPU(unsigned int, cpu_is_managed); | ||
| 38 | 39 | ||
| 39 | static DEFINE_MUTEX (userspace_mutex); | 40 | static DEFINE_MUTEX (userspace_mutex); |
| 40 | static int cpus_using_userspace_governor; | 41 | static int cpus_using_userspace_governor; |
| 41 | 42 | ||
| 42 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg) | 43 | #define dprintk(msg...) \ |
| 44 | cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg) | ||
| 43 | 45 | ||
| 44 | /* keep track of frequency transitions */ | 46 | /* keep track of frequency transitions */ |
| 45 | static int | 47 | static int |
| @@ -48,12 +50,12 @@ userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val, | |||
| 48 | { | 50 | { |
| 49 | struct cpufreq_freqs *freq = data; | 51 | struct cpufreq_freqs *freq = data; |
| 50 | 52 | ||
| 51 | if (!cpu_is_managed[freq->cpu]) | 53 | if (!per_cpu(cpu_is_managed, freq->cpu)) |
| 52 | return 0; | 54 | return 0; |
| 53 | 55 | ||
| 54 | dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n", | 56 | dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n", |
| 55 | freq->cpu, freq->new); | 57 | freq->cpu, freq->new); |
| 56 | cpu_cur_freq[freq->cpu] = freq->new; | 58 | per_cpu(cpu_cur_freq, freq->cpu) = freq->new; |
| 57 | 59 | ||
| 58 | return 0; | 60 | return 0; |
| 59 | } | 61 | } |
| @@ -77,15 +79,15 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq) | |||
| 77 | dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq); | 79 | dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq); |
| 78 | 80 | ||
| 79 | mutex_lock(&userspace_mutex); | 81 | mutex_lock(&userspace_mutex); |
| 80 | if (!cpu_is_managed[policy->cpu]) | 82 | if (!per_cpu(cpu_is_managed, policy->cpu)) |
| 81 | goto err; | 83 | goto err; |
| 82 | 84 | ||
| 83 | cpu_set_freq[policy->cpu] = freq; | 85 | per_cpu(cpu_set_freq, policy->cpu) = freq; |
| 84 | 86 | ||
| 85 | if (freq < cpu_min_freq[policy->cpu]) | 87 | if (freq < per_cpu(cpu_min_freq, policy->cpu)) |
| 86 | freq = cpu_min_freq[policy->cpu]; | 88 | freq = per_cpu(cpu_min_freq, policy->cpu); |
| 87 | if (freq > cpu_max_freq[policy->cpu]) | 89 | if (freq > per_cpu(cpu_max_freq, policy->cpu)) |
| 88 | freq = cpu_max_freq[policy->cpu]; | 90 | freq = per_cpu(cpu_max_freq, policy->cpu); |
| 89 | 91 | ||
| 90 | /* | 92 | /* |
| 91 | * We're safe from concurrent calls to ->target() here | 93 | * We're safe from concurrent calls to ->target() here |
| @@ -104,7 +106,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq) | |||
| 104 | 106 | ||
| 105 | static ssize_t show_speed(struct cpufreq_policy *policy, char *buf) | 107 | static ssize_t show_speed(struct cpufreq_policy *policy, char *buf) |
| 106 | { | 108 | { |
| 107 | return sprintf(buf, "%u\n", cpu_cur_freq[policy->cpu]); | 109 | return sprintf(buf, "%u\n", per_cpu(cpu_cur_freq, policy->cpu)); |
| 108 | } | 110 | } |
| 109 | 111 | ||
| 110 | static int cpufreq_governor_userspace(struct cpufreq_policy *policy, | 112 | static int cpufreq_governor_userspace(struct cpufreq_policy *policy, |
| @@ -127,12 +129,17 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, | |||
| 127 | } | 129 | } |
| 128 | cpus_using_userspace_governor++; | 130 | cpus_using_userspace_governor++; |
| 129 | 131 | ||
| 130 | cpu_is_managed[cpu] = 1; | 132 | per_cpu(cpu_is_managed, cpu) = 1; |
| 131 | cpu_min_freq[cpu] = policy->min; | 133 | per_cpu(cpu_min_freq, cpu) = policy->min; |
| 132 | cpu_max_freq[cpu] = policy->max; | 134 | per_cpu(cpu_max_freq, cpu) = policy->max; |
| 133 | cpu_cur_freq[cpu] = policy->cur; | 135 | per_cpu(cpu_cur_freq, cpu) = policy->cur; |
| 134 | cpu_set_freq[cpu] = policy->cur; | 136 | per_cpu(cpu_set_freq, cpu) = policy->cur; |
| 135 | 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]); | 137 | dprintk("managing cpu %u started " |
| 138 | "(%u - %u kHz, currently %u kHz)\n", | ||
| 139 | cpu, | ||
| 140 | per_cpu(cpu_min_freq, cpu), | ||
| 141 | per_cpu(cpu_max_freq, cpu), | ||
| 142 | per_cpu(cpu_cur_freq, cpu)); | ||
| 136 | 143 | ||
| 137 | mutex_unlock(&userspace_mutex); | 144 | mutex_unlock(&userspace_mutex); |
| 138 | break; | 145 | break; |
| @@ -145,34 +152,34 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, | |||
| 145 | CPUFREQ_TRANSITION_NOTIFIER); | 152 | CPUFREQ_TRANSITION_NOTIFIER); |
| 146 | } | 153 | } |
| 147 | 154 | ||
| 148 | cpu_is_managed[cpu] = 0; | 155 | per_cpu(cpu_is_managed, cpu) = 0; |
| 149 | cpu_min_freq[cpu] = 0; | 156 | per_cpu(cpu_min_freq, cpu) = 0; |
| 150 | cpu_max_freq[cpu] = 0; | 157 | per_cpu(cpu_max_freq, cpu) = 0; |
| 151 | cpu_set_freq[cpu] = 0; | 158 | per_cpu(cpu_set_freq, cpu) = 0; |
| 152 | dprintk("managing cpu %u stopped\n", cpu); | 159 | dprintk("managing cpu %u stopped\n", cpu); |
| 153 | mutex_unlock(&userspace_mutex); | 160 | mutex_unlock(&userspace_mutex); |
| 154 | break; | 161 | break; |
| 155 | case CPUFREQ_GOV_LIMITS: | 162 | case CPUFREQ_GOV_LIMITS: |
| 156 | mutex_lock(&userspace_mutex); | 163 | mutex_lock(&userspace_mutex); |
| 157 | dprintk("limit event for cpu %u: %u - %u kHz," | 164 | dprintk("limit event for cpu %u: %u - %u kHz, " |
| 158 | "currently %u kHz, last set to %u kHz\n", | 165 | "currently %u kHz, last set to %u kHz\n", |
| 159 | cpu, policy->min, policy->max, | 166 | cpu, policy->min, policy->max, |
| 160 | cpu_cur_freq[cpu], cpu_set_freq[cpu]); | 167 | per_cpu(cpu_cur_freq, cpu), |
| 161 | if (policy->max < cpu_set_freq[cpu]) { | 168 | per_cpu(cpu_set_freq, cpu)); |
| 169 | if (policy->max < per_cpu(cpu_set_freq, cpu)) { | ||
| 162 | __cpufreq_driver_target(policy, policy->max, | 170 | __cpufreq_driver_target(policy, policy->max, |
| 163 | CPUFREQ_RELATION_H); | 171 | CPUFREQ_RELATION_H); |
| 164 | } | 172 | } else if (policy->min > per_cpu(cpu_set_freq, cpu)) { |
| 165 | else if (policy->min > cpu_set_freq[cpu]) { | ||
| 166 | __cpufreq_driver_target(policy, policy->min, | 173 | __cpufreq_driver_target(policy, policy->min, |
| 167 | CPUFREQ_RELATION_L); | 174 | CPUFREQ_RELATION_L); |
| 168 | } | 175 | } else { |
| 169 | else { | 176 | __cpufreq_driver_target(policy, |
| 170 | __cpufreq_driver_target(policy, cpu_set_freq[cpu], | 177 | per_cpu(cpu_set_freq, cpu), |
| 171 | CPUFREQ_RELATION_L); | 178 | CPUFREQ_RELATION_L); |
| 172 | } | 179 | } |
| 173 | cpu_min_freq[cpu] = policy->min; | 180 | per_cpu(cpu_min_freq, cpu) = policy->min; |
| 174 | cpu_max_freq[cpu] = policy->max; | 181 | per_cpu(cpu_max_freq, cpu) = policy->max; |
| 175 | cpu_cur_freq[cpu] = policy->cur; | 182 | per_cpu(cpu_cur_freq, cpu) = policy->cur; |
| 176 | mutex_unlock(&userspace_mutex); | 183 | mutex_unlock(&userspace_mutex); |
| 177 | break; | 184 | break; |
| 178 | } | 185 | } |
