aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2013-06-05 02:17:38 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-06-18 20:01:07 -0400
commitd1922f02562fe230396400e466e6e38dfeb072f5 (patch)
tree48af6f97ddb9af49c376cf9b312620721a893833 /drivers/cpufreq
parent7fb6a53db58c729ff470095371f431b6d66c527b (diff)
cpufreq: Simplify userspace governor
Userspace governor has got more code than what it needs for its functioning, so simplify it. Portions of code removed are: - Extra header files which aren't required anymore (rearrange them as well). - cpu_{max|min|cur|set}_freq, as they are always the same as policy->{max|min|cur}. - userspace_cpufreq_notifier_block as we don't need to set cpu_cur_freq anymore. - cpus_using_userspace_governor as it was for the notifier code. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r--drivers/cpufreq/cpufreq_userspace.c108
1 files changed, 12 insertions, 96 deletions
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
index bbeb9c0720a6..5dc77b7a7594 100644
--- a/drivers/cpufreq/cpufreq_userspace.c
+++ b/drivers/cpufreq/cpufreq_userspace.c
@@ -13,55 +13,13 @@
13 13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/smp.h>
19#include <linux/init.h>
20#include <linux/spinlock.h>
21#include <linux/interrupt.h>
22#include <linux/cpufreq.h> 16#include <linux/cpufreq.h>
23#include <linux/cpu.h> 17#include <linux/init.h>
24#include <linux/types.h> 18#include <linux/module.h>
25#include <linux/fs.h>
26#include <linux/sysfs.h>
27#include <linux/mutex.h> 19#include <linux/mutex.h>
28 20
29/**
30 * A few values needed by the userspace governor
31 */
32static DEFINE_PER_CPU(unsigned int, cpu_max_freq);
33static DEFINE_PER_CPU(unsigned int, cpu_min_freq);
34static DEFINE_PER_CPU(unsigned int, cpu_cur_freq); /* current CPU freq */
35static DEFINE_PER_CPU(unsigned int, cpu_set_freq); /* CPU freq desired by
36 userspace */
37static DEFINE_PER_CPU(unsigned int, cpu_is_managed); 21static DEFINE_PER_CPU(unsigned int, cpu_is_managed);
38
39static DEFINE_MUTEX(userspace_mutex); 22static DEFINE_MUTEX(userspace_mutex);
40static int cpus_using_userspace_governor;
41
42/* keep track of frequency transitions */
43static int
44userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
45 void *data)
46{
47 struct cpufreq_freqs *freq = data;
48
49 if (!per_cpu(cpu_is_managed, freq->cpu))
50 return 0;
51
52 if (val == CPUFREQ_POSTCHANGE) {
53 pr_debug("saving cpu_cur_freq of cpu %u to be %u kHz\n",
54 freq->cpu, freq->new);
55 per_cpu(cpu_cur_freq, freq->cpu) = freq->new;
56 }
57
58 return 0;
59}
60
61static struct notifier_block userspace_cpufreq_notifier_block = {
62 .notifier_call = userspace_cpufreq_notifier
63};
64
65 23
66/** 24/**
67 * cpufreq_set - set the CPU frequency 25 * cpufreq_set - set the CPU frequency
@@ -80,13 +38,6 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
80 if (!per_cpu(cpu_is_managed, policy->cpu)) 38 if (!per_cpu(cpu_is_managed, policy->cpu))
81 goto err; 39 goto err;
82 40
83 per_cpu(cpu_set_freq, policy->cpu) = freq;
84
85 if (freq < per_cpu(cpu_min_freq, policy->cpu))
86 freq = per_cpu(cpu_min_freq, policy->cpu);
87 if (freq > per_cpu(cpu_max_freq, policy->cpu))
88 freq = per_cpu(cpu_max_freq, policy->cpu);
89
90 /* 41 /*
91 * We're safe from concurrent calls to ->target() here 42 * We're safe from concurrent calls to ->target() here
92 * as we hold the userspace_mutex lock. If we were calling 43 * as we hold the userspace_mutex lock. If we were calling
@@ -107,7 +58,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
107 58
108static ssize_t show_speed(struct cpufreq_policy *policy, char *buf) 59static ssize_t show_speed(struct cpufreq_policy *policy, char *buf)
109{ 60{
110 return sprintf(buf, "%u\n", per_cpu(cpu_cur_freq, policy->cpu)); 61 return sprintf(buf, "%u\n", policy->cur);
111} 62}
112 63
113static int cpufreq_governor_userspace(struct cpufreq_policy *policy, 64static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
@@ -119,66 +70,31 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy,
119 switch (event) { 70 switch (event) {
120 case CPUFREQ_GOV_START: 71 case CPUFREQ_GOV_START:
121 BUG_ON(!policy->cur); 72 BUG_ON(!policy->cur);
122 mutex_lock(&userspace_mutex); 73 pr_debug("started managing cpu %u\n", cpu);
123
124 if (cpus_using_userspace_governor == 0) {
125 cpufreq_register_notifier(
126 &userspace_cpufreq_notifier_block,
127 CPUFREQ_TRANSITION_NOTIFIER);
128 }
129 cpus_using_userspace_governor++;
130 74
75 mutex_lock(&userspace_mutex);
131 per_cpu(cpu_is_managed, cpu) = 1; 76 per_cpu(cpu_is_managed, cpu) = 1;
132 per_cpu(cpu_min_freq, cpu) = policy->min;
133 per_cpu(cpu_max_freq, cpu) = policy->max;
134 per_cpu(cpu_cur_freq, cpu) = policy->cur;
135 per_cpu(cpu_set_freq, cpu) = policy->cur;
136 pr_debug("managing cpu %u started "
137 "(%u - %u kHz, currently %u kHz)\n",
138 cpu,
139 per_cpu(cpu_min_freq, cpu),
140 per_cpu(cpu_max_freq, cpu),
141 per_cpu(cpu_cur_freq, cpu));
142
143 mutex_unlock(&userspace_mutex); 77 mutex_unlock(&userspace_mutex);
144 break; 78 break;
145 case CPUFREQ_GOV_STOP: 79 case CPUFREQ_GOV_STOP:
146 mutex_lock(&userspace_mutex); 80 pr_debug("managing cpu %u stopped\n", cpu);
147 cpus_using_userspace_governor--;
148 if (cpus_using_userspace_governor == 0) {
149 cpufreq_unregister_notifier(
150 &userspace_cpufreq_notifier_block,
151 CPUFREQ_TRANSITION_NOTIFIER);
152 }
153 81
82 mutex_lock(&userspace_mutex);
154 per_cpu(cpu_is_managed, cpu) = 0; 83 per_cpu(cpu_is_managed, cpu) = 0;
155 per_cpu(cpu_min_freq, cpu) = 0;
156 per_cpu(cpu_max_freq, cpu) = 0;
157 per_cpu(cpu_set_freq, cpu) = 0;
158 pr_debug("managing cpu %u stopped\n", cpu);
159 mutex_unlock(&userspace_mutex); 84 mutex_unlock(&userspace_mutex);
160 break; 85 break;
161 case CPUFREQ_GOV_LIMITS: 86 case CPUFREQ_GOV_LIMITS:
162 mutex_lock(&userspace_mutex); 87 mutex_lock(&userspace_mutex);
163 pr_debug("limit event for cpu %u: %u - %u kHz, " 88 pr_debug("limit event for cpu %u: %u - %u kHz, currently %u kHz\n",
164 "currently %u kHz, last set to %u kHz\n",
165 cpu, policy->min, policy->max, 89 cpu, policy->min, policy->max,
166 per_cpu(cpu_cur_freq, cpu), 90 policy->cur);
167 per_cpu(cpu_set_freq, cpu)); 91
168 if (policy->max < per_cpu(cpu_set_freq, cpu)) { 92 if (policy->max < policy->cur)
169 __cpufreq_driver_target(policy, policy->max, 93 __cpufreq_driver_target(policy, policy->max,
170 CPUFREQ_RELATION_H); 94 CPUFREQ_RELATION_H);
171 } else if (policy->min > per_cpu(cpu_set_freq, cpu)) { 95 else if (policy->min > policy->cur)
172 __cpufreq_driver_target(policy, policy->min, 96 __cpufreq_driver_target(policy, policy->min,
173 CPUFREQ_RELATION_L); 97 CPUFREQ_RELATION_L);
174 } else {
175 __cpufreq_driver_target(policy,
176 per_cpu(cpu_set_freq, cpu),
177 CPUFREQ_RELATION_L);
178 }
179 per_cpu(cpu_min_freq, cpu) = policy->min;
180 per_cpu(cpu_max_freq, cpu) = policy->max;
181 per_cpu(cpu_cur_freq, cpu) = policy->cur;
182 mutex_unlock(&userspace_mutex); 98 mutex_unlock(&userspace_mutex);
183 break; 99 break;
184 } 100 }