diff options
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r-- | drivers/cpufreq/cpufreq.c | 61 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_conservative.c | 155 | ||||
-rw-r--r-- | drivers/cpufreq/cpufreq_ondemand.c | 11 |
3 files changed, 99 insertions, 128 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index aed80e6aec6d..9b6ae7dc8b8a 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -52,9 +52,8 @@ static void handle_update(void *data); | |||
52 | * changes to devices when the CPU clock speed changes. | 52 | * changes to devices when the CPU clock speed changes. |
53 | * The mutex locks both lists. | 53 | * The mutex locks both lists. |
54 | */ | 54 | */ |
55 | static struct notifier_block *cpufreq_policy_notifier_list; | 55 | static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list); |
56 | static struct notifier_block *cpufreq_transition_notifier_list; | 56 | static BLOCKING_NOTIFIER_HEAD(cpufreq_transition_notifier_list); |
57 | static DECLARE_RWSEM (cpufreq_notifier_rwsem); | ||
58 | 57 | ||
59 | 58 | ||
60 | static LIST_HEAD(cpufreq_governor_list); | 59 | static LIST_HEAD(cpufreq_governor_list); |
@@ -247,8 +246,6 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | |||
247 | dprintk("notification %u of frequency transition to %u kHz\n", | 246 | dprintk("notification %u of frequency transition to %u kHz\n", |
248 | state, freqs->new); | 247 | state, freqs->new); |
249 | 248 | ||
250 | down_read(&cpufreq_notifier_rwsem); | ||
251 | |||
252 | policy = cpufreq_cpu_data[freqs->cpu]; | 249 | policy = cpufreq_cpu_data[freqs->cpu]; |
253 | switch (state) { | 250 | switch (state) { |
254 | 251 | ||
@@ -266,20 +263,19 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | |||
266 | freqs->old = policy->cur; | 263 | freqs->old = policy->cur; |
267 | } | 264 | } |
268 | } | 265 | } |
269 | notifier_call_chain(&cpufreq_transition_notifier_list, | 266 | blocking_notifier_call_chain(&cpufreq_transition_notifier_list, |
270 | CPUFREQ_PRECHANGE, freqs); | 267 | CPUFREQ_PRECHANGE, freqs); |
271 | adjust_jiffies(CPUFREQ_PRECHANGE, freqs); | 268 | adjust_jiffies(CPUFREQ_PRECHANGE, freqs); |
272 | break; | 269 | break; |
273 | 270 | ||
274 | case CPUFREQ_POSTCHANGE: | 271 | case CPUFREQ_POSTCHANGE: |
275 | adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); | 272 | adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); |
276 | notifier_call_chain(&cpufreq_transition_notifier_list, | 273 | blocking_notifier_call_chain(&cpufreq_transition_notifier_list, |
277 | CPUFREQ_POSTCHANGE, freqs); | 274 | CPUFREQ_POSTCHANGE, freqs); |
278 | if (likely(policy) && likely(policy->cpu == freqs->cpu)) | 275 | if (likely(policy) && likely(policy->cpu == freqs->cpu)) |
279 | policy->cur = freqs->new; | 276 | policy->cur = freqs->new; |
280 | break; | 277 | break; |
281 | } | 278 | } |
282 | up_read(&cpufreq_notifier_rwsem); | ||
283 | } | 279 | } |
284 | EXPORT_SYMBOL_GPL(cpufreq_notify_transition); | 280 | EXPORT_SYMBOL_GPL(cpufreq_notify_transition); |
285 | 281 | ||
@@ -1007,7 +1003,7 @@ static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg) | |||
1007 | freqs.old = cpu_policy->cur; | 1003 | freqs.old = cpu_policy->cur; |
1008 | freqs.new = cur_freq; | 1004 | freqs.new = cur_freq; |
1009 | 1005 | ||
1010 | notifier_call_chain(&cpufreq_transition_notifier_list, | 1006 | blocking_notifier_call_chain(&cpufreq_transition_notifier_list, |
1011 | CPUFREQ_SUSPENDCHANGE, &freqs); | 1007 | CPUFREQ_SUSPENDCHANGE, &freqs); |
1012 | adjust_jiffies(CPUFREQ_SUSPENDCHANGE, &freqs); | 1008 | adjust_jiffies(CPUFREQ_SUSPENDCHANGE, &freqs); |
1013 | 1009 | ||
@@ -1088,7 +1084,8 @@ static int cpufreq_resume(struct sys_device * sysdev) | |||
1088 | freqs.old = cpu_policy->cur; | 1084 | freqs.old = cpu_policy->cur; |
1089 | freqs.new = cur_freq; | 1085 | freqs.new = cur_freq; |
1090 | 1086 | ||
1091 | notifier_call_chain(&cpufreq_transition_notifier_list, | 1087 | blocking_notifier_call_chain( |
1088 | &cpufreq_transition_notifier_list, | ||
1092 | CPUFREQ_RESUMECHANGE, &freqs); | 1089 | CPUFREQ_RESUMECHANGE, &freqs); |
1093 | adjust_jiffies(CPUFREQ_RESUMECHANGE, &freqs); | 1090 | adjust_jiffies(CPUFREQ_RESUMECHANGE, &freqs); |
1094 | 1091 | ||
@@ -1125,24 +1122,24 @@ static struct sysdev_driver cpufreq_sysdev_driver = { | |||
1125 | * changes in cpufreq policy. | 1122 | * changes in cpufreq policy. |
1126 | * | 1123 | * |
1127 | * This function may sleep, and has the same return conditions as | 1124 | * This function may sleep, and has the same return conditions as |
1128 | * notifier_chain_register. | 1125 | * blocking_notifier_chain_register. |
1129 | */ | 1126 | */ |
1130 | int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list) | 1127 | int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list) |
1131 | { | 1128 | { |
1132 | int ret; | 1129 | int ret; |
1133 | 1130 | ||
1134 | down_write(&cpufreq_notifier_rwsem); | ||
1135 | switch (list) { | 1131 | switch (list) { |
1136 | case CPUFREQ_TRANSITION_NOTIFIER: | 1132 | case CPUFREQ_TRANSITION_NOTIFIER: |
1137 | ret = notifier_chain_register(&cpufreq_transition_notifier_list, nb); | 1133 | ret = blocking_notifier_chain_register( |
1134 | &cpufreq_transition_notifier_list, nb); | ||
1138 | break; | 1135 | break; |
1139 | case CPUFREQ_POLICY_NOTIFIER: | 1136 | case CPUFREQ_POLICY_NOTIFIER: |
1140 | ret = notifier_chain_register(&cpufreq_policy_notifier_list, nb); | 1137 | ret = blocking_notifier_chain_register( |
1138 | &cpufreq_policy_notifier_list, nb); | ||
1141 | break; | 1139 | break; |
1142 | default: | 1140 | default: |
1143 | ret = -EINVAL; | 1141 | ret = -EINVAL; |
1144 | } | 1142 | } |
1145 | up_write(&cpufreq_notifier_rwsem); | ||
1146 | 1143 | ||
1147 | return ret; | 1144 | return ret; |
1148 | } | 1145 | } |
@@ -1157,24 +1154,24 @@ EXPORT_SYMBOL(cpufreq_register_notifier); | |||
1157 | * Remove a driver from the CPU frequency notifier list. | 1154 | * Remove a driver from the CPU frequency notifier list. |
1158 | * | 1155 | * |
1159 | * This function may sleep, and has the same return conditions as | 1156 | * This function may sleep, and has the same return conditions as |
1160 | * notifier_chain_unregister. | 1157 | * blocking_notifier_chain_unregister. |
1161 | */ | 1158 | */ |
1162 | int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list) | 1159 | int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list) |
1163 | { | 1160 | { |
1164 | int ret; | 1161 | int ret; |
1165 | 1162 | ||
1166 | down_write(&cpufreq_notifier_rwsem); | ||
1167 | switch (list) { | 1163 | switch (list) { |
1168 | case CPUFREQ_TRANSITION_NOTIFIER: | 1164 | case CPUFREQ_TRANSITION_NOTIFIER: |
1169 | ret = notifier_chain_unregister(&cpufreq_transition_notifier_list, nb); | 1165 | ret = blocking_notifier_chain_unregister( |
1166 | &cpufreq_transition_notifier_list, nb); | ||
1170 | break; | 1167 | break; |
1171 | case CPUFREQ_POLICY_NOTIFIER: | 1168 | case CPUFREQ_POLICY_NOTIFIER: |
1172 | ret = notifier_chain_unregister(&cpufreq_policy_notifier_list, nb); | 1169 | ret = blocking_notifier_chain_unregister( |
1170 | &cpufreq_policy_notifier_list, nb); | ||
1173 | break; | 1171 | break; |
1174 | default: | 1172 | default: |
1175 | ret = -EINVAL; | 1173 | ret = -EINVAL; |
1176 | } | 1174 | } |
1177 | up_write(&cpufreq_notifier_rwsem); | ||
1178 | 1175 | ||
1179 | return ret; | 1176 | return ret; |
1180 | } | 1177 | } |
@@ -1346,29 +1343,23 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_poli | |||
1346 | if (ret) | 1343 | if (ret) |
1347 | goto error_out; | 1344 | goto error_out; |
1348 | 1345 | ||
1349 | down_read(&cpufreq_notifier_rwsem); | ||
1350 | |||
1351 | /* adjust if necessary - all reasons */ | 1346 | /* adjust if necessary - all reasons */ |
1352 | notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_ADJUST, | 1347 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
1353 | policy); | 1348 | CPUFREQ_ADJUST, policy); |
1354 | 1349 | ||
1355 | /* adjust if necessary - hardware incompatibility*/ | 1350 | /* adjust if necessary - hardware incompatibility*/ |
1356 | notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_INCOMPATIBLE, | 1351 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
1357 | policy); | 1352 | CPUFREQ_INCOMPATIBLE, policy); |
1358 | 1353 | ||
1359 | /* verify the cpu speed can be set within this limit, | 1354 | /* verify the cpu speed can be set within this limit, |
1360 | which might be different to the first one */ | 1355 | which might be different to the first one */ |
1361 | ret = cpufreq_driver->verify(policy); | 1356 | ret = cpufreq_driver->verify(policy); |
1362 | if (ret) { | 1357 | if (ret) |
1363 | up_read(&cpufreq_notifier_rwsem); | ||
1364 | goto error_out; | 1358 | goto error_out; |
1365 | } | ||
1366 | 1359 | ||
1367 | /* notification of the new policy */ | 1360 | /* notification of the new policy */ |
1368 | notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_NOTIFY, | 1361 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
1369 | policy); | 1362 | CPUFREQ_NOTIFY, policy); |
1370 | |||
1371 | up_read(&cpufreq_notifier_rwsem); | ||
1372 | 1363 | ||
1373 | data->min = policy->min; | 1364 | data->min = policy->min; |
1374 | data->max = policy->max; | 1365 | data->max = policy->max; |
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c index ac38766b2583..037f6bf4543c 100644 --- a/drivers/cpufreq/cpufreq_conservative.c +++ b/drivers/cpufreq/cpufreq_conservative.c | |||
@@ -35,12 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #define DEF_FREQUENCY_UP_THRESHOLD (80) | 37 | #define DEF_FREQUENCY_UP_THRESHOLD (80) |
38 | #define MIN_FREQUENCY_UP_THRESHOLD (0) | ||
39 | #define MAX_FREQUENCY_UP_THRESHOLD (100) | ||
40 | |||
41 | #define DEF_FREQUENCY_DOWN_THRESHOLD (20) | 38 | #define DEF_FREQUENCY_DOWN_THRESHOLD (20) |
42 | #define MIN_FREQUENCY_DOWN_THRESHOLD (0) | ||
43 | #define MAX_FREQUENCY_DOWN_THRESHOLD (100) | ||
44 | 39 | ||
45 | /* | 40 | /* |
46 | * The polling frequency of this governor depends on the capability of | 41 | * The polling frequency of this governor depends on the capability of |
@@ -53,10 +48,14 @@ | |||
53 | * All times here are in uS. | 48 | * All times here are in uS. |
54 | */ | 49 | */ |
55 | static unsigned int def_sampling_rate; | 50 | static unsigned int def_sampling_rate; |
56 | #define MIN_SAMPLING_RATE (def_sampling_rate / 2) | 51 | #define MIN_SAMPLING_RATE_RATIO (2) |
52 | /* for correct statistics, we need at least 10 ticks between each measure */ | ||
53 | #define MIN_STAT_SAMPLING_RATE (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) | ||
54 | #define MIN_SAMPLING_RATE (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) | ||
57 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) | 55 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) |
58 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (100000) | 56 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) |
59 | #define DEF_SAMPLING_DOWN_FACTOR (5) | 57 | #define DEF_SAMPLING_DOWN_FACTOR (1) |
58 | #define MAX_SAMPLING_DOWN_FACTOR (10) | ||
60 | #define TRANSITION_LATENCY_LIMIT (10 * 1000) | 59 | #define TRANSITION_LATENCY_LIMIT (10 * 1000) |
61 | 60 | ||
62 | static void do_dbs_timer(void *data); | 61 | static void do_dbs_timer(void *data); |
@@ -66,6 +65,8 @@ struct cpu_dbs_info_s { | |||
66 | unsigned int prev_cpu_idle_up; | 65 | unsigned int prev_cpu_idle_up; |
67 | unsigned int prev_cpu_idle_down; | 66 | unsigned int prev_cpu_idle_down; |
68 | unsigned int enable; | 67 | unsigned int enable; |
68 | unsigned int down_skip; | ||
69 | unsigned int requested_freq; | ||
69 | }; | 70 | }; |
70 | static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); | 71 | static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); |
71 | 72 | ||
@@ -87,6 +88,8 @@ static struct dbs_tuners dbs_tuners_ins = { | |||
87 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, | 88 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, |
88 | .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD, | 89 | .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD, |
89 | .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, | 90 | .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, |
91 | .ignore_nice = 0, | ||
92 | .freq_step = 5, | ||
90 | }; | 93 | }; |
91 | 94 | ||
92 | static inline unsigned int get_cpu_idle_time(unsigned int cpu) | 95 | static inline unsigned int get_cpu_idle_time(unsigned int cpu) |
@@ -136,7 +139,7 @@ static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, | |||
136 | unsigned int input; | 139 | unsigned int input; |
137 | int ret; | 140 | int ret; |
138 | ret = sscanf (buf, "%u", &input); | 141 | ret = sscanf (buf, "%u", &input); |
139 | if (ret != 1 ) | 142 | if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1) |
140 | return -EINVAL; | 143 | return -EINVAL; |
141 | 144 | ||
142 | mutex_lock(&dbs_mutex); | 145 | mutex_lock(&dbs_mutex); |
@@ -173,8 +176,7 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused, | |||
173 | ret = sscanf (buf, "%u", &input); | 176 | ret = sscanf (buf, "%u", &input); |
174 | 177 | ||
175 | mutex_lock(&dbs_mutex); | 178 | mutex_lock(&dbs_mutex); |
176 | if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || | 179 | if (ret != 1 || input > 100 || input < 0 || |
177 | input < MIN_FREQUENCY_UP_THRESHOLD || | ||
178 | input <= dbs_tuners_ins.down_threshold) { | 180 | input <= dbs_tuners_ins.down_threshold) { |
179 | mutex_unlock(&dbs_mutex); | 181 | mutex_unlock(&dbs_mutex); |
180 | return -EINVAL; | 182 | return -EINVAL; |
@@ -194,8 +196,7 @@ static ssize_t store_down_threshold(struct cpufreq_policy *unused, | |||
194 | ret = sscanf (buf, "%u", &input); | 196 | ret = sscanf (buf, "%u", &input); |
195 | 197 | ||
196 | mutex_lock(&dbs_mutex); | 198 | mutex_lock(&dbs_mutex); |
197 | if (ret != 1 || input > MAX_FREQUENCY_DOWN_THRESHOLD || | 199 | if (ret != 1 || input > 100 || input < 0 || |
198 | input < MIN_FREQUENCY_DOWN_THRESHOLD || | ||
199 | input >= dbs_tuners_ins.up_threshold) { | 200 | input >= dbs_tuners_ins.up_threshold) { |
200 | mutex_unlock(&dbs_mutex); | 201 | mutex_unlock(&dbs_mutex); |
201 | return -EINVAL; | 202 | return -EINVAL; |
@@ -297,31 +298,17 @@ static struct attribute_group dbs_attr_group = { | |||
297 | static void dbs_check_cpu(int cpu) | 298 | static void dbs_check_cpu(int cpu) |
298 | { | 299 | { |
299 | unsigned int idle_ticks, up_idle_ticks, down_idle_ticks; | 300 | unsigned int idle_ticks, up_idle_ticks, down_idle_ticks; |
301 | unsigned int tmp_idle_ticks, total_idle_ticks; | ||
300 | unsigned int freq_step; | 302 | unsigned int freq_step; |
301 | unsigned int freq_down_sampling_rate; | 303 | unsigned int freq_down_sampling_rate; |
302 | static int down_skip[NR_CPUS]; | 304 | struct cpu_dbs_info_s *this_dbs_info = &per_cpu(cpu_dbs_info, cpu); |
303 | static int requested_freq[NR_CPUS]; | ||
304 | static unsigned short init_flag = 0; | ||
305 | struct cpu_dbs_info_s *this_dbs_info; | ||
306 | struct cpu_dbs_info_s *dbs_info; | ||
307 | |||
308 | struct cpufreq_policy *policy; | 305 | struct cpufreq_policy *policy; |
309 | unsigned int j; | ||
310 | 306 | ||
311 | this_dbs_info = &per_cpu(cpu_dbs_info, cpu); | ||
312 | if (!this_dbs_info->enable) | 307 | if (!this_dbs_info->enable) |
313 | return; | 308 | return; |
314 | 309 | ||
315 | policy = this_dbs_info->cur_policy; | 310 | policy = this_dbs_info->cur_policy; |
316 | 311 | ||
317 | if ( init_flag == 0 ) { | ||
318 | for_each_online_cpu(j) { | ||
319 | dbs_info = &per_cpu(cpu_dbs_info, j); | ||
320 | requested_freq[j] = dbs_info->cur_policy->cur; | ||
321 | } | ||
322 | init_flag = 1; | ||
323 | } | ||
324 | |||
325 | /* | 312 | /* |
326 | * The default safe range is 20% to 80% | 313 | * The default safe range is 20% to 80% |
327 | * Every sampling_rate, we check | 314 | * Every sampling_rate, we check |
@@ -337,39 +324,29 @@ static void dbs_check_cpu(int cpu) | |||
337 | */ | 324 | */ |
338 | 325 | ||
339 | /* Check for frequency increase */ | 326 | /* Check for frequency increase */ |
340 | |||
341 | idle_ticks = UINT_MAX; | 327 | idle_ticks = UINT_MAX; |
342 | for_each_cpu_mask(j, policy->cpus) { | ||
343 | unsigned int tmp_idle_ticks, total_idle_ticks; | ||
344 | struct cpu_dbs_info_s *j_dbs_info; | ||
345 | 328 | ||
346 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | 329 | /* Check for frequency increase */ |
347 | /* Check for frequency increase */ | 330 | total_idle_ticks = get_cpu_idle_time(cpu); |
348 | total_idle_ticks = get_cpu_idle_time(j); | 331 | tmp_idle_ticks = total_idle_ticks - |
349 | tmp_idle_ticks = total_idle_ticks - | 332 | this_dbs_info->prev_cpu_idle_up; |
350 | j_dbs_info->prev_cpu_idle_up; | 333 | this_dbs_info->prev_cpu_idle_up = total_idle_ticks; |
351 | j_dbs_info->prev_cpu_idle_up = total_idle_ticks; | 334 | |
352 | 335 | if (tmp_idle_ticks < idle_ticks) | |
353 | if (tmp_idle_ticks < idle_ticks) | 336 | idle_ticks = tmp_idle_ticks; |
354 | idle_ticks = tmp_idle_ticks; | ||
355 | } | ||
356 | 337 | ||
357 | /* Scale idle ticks by 100 and compare with up and down ticks */ | 338 | /* Scale idle ticks by 100 and compare with up and down ticks */ |
358 | idle_ticks *= 100; | 339 | idle_ticks *= 100; |
359 | up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * | 340 | up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * |
360 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate); | 341 | usecs_to_jiffies(dbs_tuners_ins.sampling_rate); |
361 | 342 | ||
362 | if (idle_ticks < up_idle_ticks) { | 343 | if (idle_ticks < up_idle_ticks) { |
363 | down_skip[cpu] = 0; | 344 | this_dbs_info->down_skip = 0; |
364 | for_each_cpu_mask(j, policy->cpus) { | 345 | this_dbs_info->prev_cpu_idle_down = |
365 | struct cpu_dbs_info_s *j_dbs_info; | 346 | this_dbs_info->prev_cpu_idle_up; |
366 | 347 | ||
367 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | ||
368 | j_dbs_info->prev_cpu_idle_down = | ||
369 | j_dbs_info->prev_cpu_idle_up; | ||
370 | } | ||
371 | /* if we are already at full speed then break out early */ | 348 | /* if we are already at full speed then break out early */ |
372 | if (requested_freq[cpu] == policy->max) | 349 | if (this_dbs_info->requested_freq == policy->max) |
373 | return; | 350 | return; |
374 | 351 | ||
375 | freq_step = (dbs_tuners_ins.freq_step * policy->max) / 100; | 352 | freq_step = (dbs_tuners_ins.freq_step * policy->max) / 100; |
@@ -378,49 +355,45 @@ static void dbs_check_cpu(int cpu) | |||
378 | if (unlikely(freq_step == 0)) | 355 | if (unlikely(freq_step == 0)) |
379 | freq_step = 5; | 356 | freq_step = 5; |
380 | 357 | ||
381 | requested_freq[cpu] += freq_step; | 358 | this_dbs_info->requested_freq += freq_step; |
382 | if (requested_freq[cpu] > policy->max) | 359 | if (this_dbs_info->requested_freq > policy->max) |
383 | requested_freq[cpu] = policy->max; | 360 | this_dbs_info->requested_freq = policy->max; |
384 | 361 | ||
385 | __cpufreq_driver_target(policy, requested_freq[cpu], | 362 | __cpufreq_driver_target(policy, this_dbs_info->requested_freq, |
386 | CPUFREQ_RELATION_H); | 363 | CPUFREQ_RELATION_H); |
387 | return; | 364 | return; |
388 | } | 365 | } |
389 | 366 | ||
390 | /* Check for frequency decrease */ | 367 | /* Check for frequency decrease */ |
391 | down_skip[cpu]++; | 368 | this_dbs_info->down_skip++; |
392 | if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor) | 369 | if (this_dbs_info->down_skip < dbs_tuners_ins.sampling_down_factor) |
393 | return; | 370 | return; |
394 | 371 | ||
395 | idle_ticks = UINT_MAX; | 372 | /* Check for frequency decrease */ |
396 | for_each_cpu_mask(j, policy->cpus) { | 373 | total_idle_ticks = this_dbs_info->prev_cpu_idle_up; |
397 | unsigned int tmp_idle_ticks, total_idle_ticks; | 374 | tmp_idle_ticks = total_idle_ticks - |
398 | struct cpu_dbs_info_s *j_dbs_info; | 375 | this_dbs_info->prev_cpu_idle_down; |
376 | this_dbs_info->prev_cpu_idle_down = total_idle_ticks; | ||
399 | 377 | ||
400 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | 378 | if (tmp_idle_ticks < idle_ticks) |
401 | total_idle_ticks = j_dbs_info->prev_cpu_idle_up; | 379 | idle_ticks = tmp_idle_ticks; |
402 | tmp_idle_ticks = total_idle_ticks - | ||
403 | j_dbs_info->prev_cpu_idle_down; | ||
404 | j_dbs_info->prev_cpu_idle_down = total_idle_ticks; | ||
405 | |||
406 | if (tmp_idle_ticks < idle_ticks) | ||
407 | idle_ticks = tmp_idle_ticks; | ||
408 | } | ||
409 | 380 | ||
410 | /* Scale idle ticks by 100 and compare with up and down ticks */ | 381 | /* Scale idle ticks by 100 and compare with up and down ticks */ |
411 | idle_ticks *= 100; | 382 | idle_ticks *= 100; |
412 | down_skip[cpu] = 0; | 383 | this_dbs_info->down_skip = 0; |
413 | 384 | ||
414 | freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * | 385 | freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * |
415 | dbs_tuners_ins.sampling_down_factor; | 386 | dbs_tuners_ins.sampling_down_factor; |
416 | down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) * | 387 | down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) * |
417 | usecs_to_jiffies(freq_down_sampling_rate); | 388 | usecs_to_jiffies(freq_down_sampling_rate); |
418 | 389 | ||
419 | if (idle_ticks > down_idle_ticks) { | 390 | if (idle_ticks > down_idle_ticks) { |
420 | /* if we are already at the lowest speed then break out early | 391 | /* |
392 | * if we are already at the lowest speed then break out early | ||
421 | * or if we 'cannot' reduce the speed as the user might want | 393 | * or if we 'cannot' reduce the speed as the user might want |
422 | * freq_step to be zero */ | 394 | * freq_step to be zero |
423 | if (requested_freq[cpu] == policy->min | 395 | */ |
396 | if (this_dbs_info->requested_freq == policy->min | ||
424 | || dbs_tuners_ins.freq_step == 0) | 397 | || dbs_tuners_ins.freq_step == 0) |
425 | return; | 398 | return; |
426 | 399 | ||
@@ -430,13 +403,12 @@ static void dbs_check_cpu(int cpu) | |||
430 | if (unlikely(freq_step == 0)) | 403 | if (unlikely(freq_step == 0)) |
431 | freq_step = 5; | 404 | freq_step = 5; |
432 | 405 | ||
433 | requested_freq[cpu] -= freq_step; | 406 | this_dbs_info->requested_freq -= freq_step; |
434 | if (requested_freq[cpu] < policy->min) | 407 | if (this_dbs_info->requested_freq < policy->min) |
435 | requested_freq[cpu] = policy->min; | 408 | this_dbs_info->requested_freq = policy->min; |
436 | 409 | ||
437 | __cpufreq_driver_target(policy, | 410 | __cpufreq_driver_target(policy, this_dbs_info->requested_freq, |
438 | requested_freq[cpu], | 411 | CPUFREQ_RELATION_H); |
439 | CPUFREQ_RELATION_H); | ||
440 | return; | 412 | return; |
441 | } | 413 | } |
442 | } | 414 | } |
@@ -493,11 +465,13 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
493 | j_dbs_info = &per_cpu(cpu_dbs_info, j); | 465 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
494 | j_dbs_info->cur_policy = policy; | 466 | j_dbs_info->cur_policy = policy; |
495 | 467 | ||
496 | j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); | 468 | j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(cpu); |
497 | j_dbs_info->prev_cpu_idle_down | 469 | j_dbs_info->prev_cpu_idle_down |
498 | = j_dbs_info->prev_cpu_idle_up; | 470 | = j_dbs_info->prev_cpu_idle_up; |
499 | } | 471 | } |
500 | this_dbs_info->enable = 1; | 472 | this_dbs_info->enable = 1; |
473 | this_dbs_info->down_skip = 0; | ||
474 | this_dbs_info->requested_freq = policy->cur; | ||
501 | sysfs_create_group(&policy->kobj, &dbs_attr_group); | 475 | sysfs_create_group(&policy->kobj, &dbs_attr_group); |
502 | dbs_enable++; | 476 | dbs_enable++; |
503 | /* | 477 | /* |
@@ -507,16 +481,17 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
507 | if (dbs_enable == 1) { | 481 | if (dbs_enable == 1) { |
508 | unsigned int latency; | 482 | unsigned int latency; |
509 | /* policy latency is in nS. Convert it to uS first */ | 483 | /* policy latency is in nS. Convert it to uS first */ |
484 | latency = policy->cpuinfo.transition_latency / 1000; | ||
485 | if (latency == 0) | ||
486 | latency = 1; | ||
510 | 487 | ||
511 | latency = policy->cpuinfo.transition_latency; | 488 | def_sampling_rate = 10 * latency * |
512 | if (latency < 1000) | ||
513 | latency = 1000; | ||
514 | |||
515 | def_sampling_rate = (latency / 1000) * | ||
516 | DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; | 489 | DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; |
490 | |||
491 | if (def_sampling_rate < MIN_STAT_SAMPLING_RATE) | ||
492 | def_sampling_rate = MIN_STAT_SAMPLING_RATE; | ||
493 | |||
517 | dbs_tuners_ins.sampling_rate = def_sampling_rate; | 494 | dbs_tuners_ins.sampling_rate = def_sampling_rate; |
518 | dbs_tuners_ins.ignore_nice = 0; | ||
519 | dbs_tuners_ins.freq_step = 5; | ||
520 | 495 | ||
521 | dbs_timer_init(); | 496 | dbs_timer_init(); |
522 | } | 497 | } |
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c index 69aa1db8336c..956d121cb161 100644 --- a/drivers/cpufreq/cpufreq_ondemand.c +++ b/drivers/cpufreq/cpufreq_ondemand.c | |||
@@ -84,6 +84,7 @@ struct dbs_tuners { | |||
84 | static struct dbs_tuners dbs_tuners_ins = { | 84 | static struct dbs_tuners dbs_tuners_ins = { |
85 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, | 85 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, |
86 | .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, | 86 | .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, |
87 | .ignore_nice = 0, | ||
87 | }; | 88 | }; |
88 | 89 | ||
89 | static inline unsigned int get_cpu_idle_time(unsigned int cpu) | 90 | static inline unsigned int get_cpu_idle_time(unsigned int cpu) |
@@ -350,6 +351,9 @@ static void dbs_check_cpu(int cpu) | |||
350 | freq_next = (freq_next * policy->cur) / | 351 | freq_next = (freq_next * policy->cur) / |
351 | (dbs_tuners_ins.up_threshold - 10); | 352 | (dbs_tuners_ins.up_threshold - 10); |
352 | 353 | ||
354 | if (freq_next < policy->min) | ||
355 | freq_next = policy->min; | ||
356 | |||
353 | if (freq_next <= ((policy->cur * 95) / 100)) | 357 | if (freq_next <= ((policy->cur * 95) / 100)) |
354 | __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L); | 358 | __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L); |
355 | } | 359 | } |
@@ -395,8 +399,11 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
395 | return -EINVAL; | 399 | return -EINVAL; |
396 | 400 | ||
397 | if (policy->cpuinfo.transition_latency > | 401 | if (policy->cpuinfo.transition_latency > |
398 | (TRANSITION_LATENCY_LIMIT * 1000)) | 402 | (TRANSITION_LATENCY_LIMIT * 1000)) { |
403 | printk(KERN_WARNING "ondemand governor failed to load " | ||
404 | "due to too long transition latency\n"); | ||
399 | return -EINVAL; | 405 | return -EINVAL; |
406 | } | ||
400 | if (this_dbs_info->enable) /* Already enabled */ | 407 | if (this_dbs_info->enable) /* Already enabled */ |
401 | break; | 408 | break; |
402 | 409 | ||
@@ -431,8 +438,6 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
431 | def_sampling_rate = MIN_STAT_SAMPLING_RATE; | 438 | def_sampling_rate = MIN_STAT_SAMPLING_RATE; |
432 | 439 | ||
433 | dbs_tuners_ins.sampling_rate = def_sampling_rate; | 440 | dbs_tuners_ins.sampling_rate = def_sampling_rate; |
434 | dbs_tuners_ins.ignore_nice = 0; | ||
435 | |||
436 | dbs_timer_init(); | 441 | dbs_timer_init(); |
437 | } | 442 | } |
438 | 443 | ||