Commit ccb2fe209dac9ff67f6351e783e610073afaaeaf
Committed by
Dave Jones
1 parent
501b7c77de
Exists in
master
and in
7 other branches
[CPUFREQ] Remove slowdown from ondemand sampling path.
Remove slowdown from ondemand sampling path. This reduces the code path length in dbs_check_cpu() by half. slowdown was not used by ondemand by default. If there are any user level tools that were using this tunable, they may report error now. Signed-off-by: Alexey Starikovskiy <alexey.y.starikovskiy@intel.com> Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Dave Jones <davej@redhat.com>
Showing 2 changed files with 42 additions and 98 deletions Side-by-side Diff
drivers/cpufreq/cpufreq_ondemand.c
... | ... | @@ -56,16 +56,14 @@ |
56 | 56 | #define MIN_SAMPLING_RATE (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) |
57 | 57 | #define MAX_SAMPLING_RATE (500 * def_sampling_rate) |
58 | 58 | #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) |
59 | -#define DEF_SAMPLING_DOWN_FACTOR (1) | |
60 | -#define MAX_SAMPLING_DOWN_FACTOR (10) | |
61 | 59 | #define TRANSITION_LATENCY_LIMIT (10 * 1000) |
62 | 60 | |
63 | 61 | static void do_dbs_timer(void *data); |
64 | 62 | |
65 | 63 | struct cpu_dbs_info_s { |
64 | + cputime64_t prev_cpu_idle; | |
65 | + cputime64_t prev_cpu_wall; | |
66 | 66 | struct cpufreq_policy *cur_policy; |
67 | - unsigned int prev_cpu_idle_up; | |
68 | - unsigned int prev_cpu_idle_down; | |
69 | 67 | unsigned int enable; |
70 | 68 | }; |
71 | 69 | static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); |
72 | 70 | |
73 | 71 | |
74 | 72 | |
... | ... | @@ -87,24 +85,26 @@ |
87 | 85 | |
88 | 86 | struct dbs_tuners { |
89 | 87 | unsigned int sampling_rate; |
90 | - unsigned int sampling_down_factor; | |
91 | 88 | unsigned int up_threshold; |
92 | 89 | unsigned int ignore_nice; |
93 | 90 | }; |
94 | 91 | |
95 | 92 | static struct dbs_tuners dbs_tuners_ins = { |
96 | 93 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, |
97 | - .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, | |
98 | 94 | .ignore_nice = 0, |
99 | 95 | }; |
100 | 96 | |
101 | -static inline unsigned int get_cpu_idle_time(unsigned int cpu) | |
97 | +static inline cputime64_t get_cpu_idle_time(unsigned int cpu) | |
102 | 98 | { |
103 | - return kstat_cpu(cpu).cpustat.idle + | |
104 | - kstat_cpu(cpu).cpustat.iowait + | |
105 | - ( dbs_tuners_ins.ignore_nice ? | |
106 | - kstat_cpu(cpu).cpustat.nice : | |
107 | - 0); | |
99 | + cputime64_t retval; | |
100 | + | |
101 | + retval = cputime64_add(kstat_cpu(cpu).cpustat.idle, | |
102 | + kstat_cpu(cpu).cpustat.iowait); | |
103 | + | |
104 | + if (dbs_tuners_ins.ignore_nice) | |
105 | + retval = cputime64_add(retval, kstat_cpu(cpu).cpustat.nice); | |
106 | + | |
107 | + return retval; | |
108 | 108 | } |
109 | 109 | |
110 | 110 | /************************** sysfs interface ************************/ |
111 | 111 | |
... | ... | @@ -133,29 +133,9 @@ |
133 | 133 | return sprintf(buf, "%u\n", dbs_tuners_ins.object); \ |
134 | 134 | } |
135 | 135 | show_one(sampling_rate, sampling_rate); |
136 | -show_one(sampling_down_factor, sampling_down_factor); | |
137 | 136 | show_one(up_threshold, up_threshold); |
138 | 137 | show_one(ignore_nice_load, ignore_nice); |
139 | 138 | |
140 | -static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused, | |
141 | - const char *buf, size_t count) | |
142 | -{ | |
143 | - unsigned int input; | |
144 | - int ret; | |
145 | - ret = sscanf (buf, "%u", &input); | |
146 | - if (ret != 1 ) | |
147 | - return -EINVAL; | |
148 | - | |
149 | - if (input > MAX_SAMPLING_DOWN_FACTOR || input < 1) | |
150 | - return -EINVAL; | |
151 | - | |
152 | - mutex_lock(&dbs_mutex); | |
153 | - dbs_tuners_ins.sampling_down_factor = input; | |
154 | - mutex_unlock(&dbs_mutex); | |
155 | - | |
156 | - return count; | |
157 | -} | |
158 | - | |
159 | 139 | static ssize_t store_sampling_rate(struct cpufreq_policy *unused, |
160 | 140 | const char *buf, size_t count) |
161 | 141 | { |
162 | 142 | |
... | ... | @@ -217,12 +197,12 @@ |
217 | 197 | } |
218 | 198 | dbs_tuners_ins.ignore_nice = input; |
219 | 199 | |
220 | - /* we need to re-evaluate prev_cpu_idle_up and prev_cpu_idle_down */ | |
200 | + /* we need to re-evaluate prev_cpu_idle */ | |
221 | 201 | for_each_online_cpu(j) { |
222 | - struct cpu_dbs_info_s *j_dbs_info; | |
223 | - j_dbs_info = &per_cpu(cpu_dbs_info, j); | |
224 | - j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); | |
225 | - j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up; | |
202 | + struct cpu_dbs_info_s *dbs_info; | |
203 | + dbs_info = &per_cpu(cpu_dbs_info, j); | |
204 | + dbs_info->prev_cpu_idle = get_cpu_idle_time(j); | |
205 | + dbs_info->prev_cpu_wall = get_jiffies_64(); | |
226 | 206 | } |
227 | 207 | mutex_unlock(&dbs_mutex); |
228 | 208 | |
... | ... | @@ -234,7 +214,6 @@ |
234 | 214 | __ATTR(_name, 0644, show_##_name, store_##_name) |
235 | 215 | |
236 | 216 | define_one_rw(sampling_rate); |
237 | -define_one_rw(sampling_down_factor); | |
238 | 217 | define_one_rw(up_threshold); |
239 | 218 | define_one_rw(ignore_nice_load); |
240 | 219 | |
... | ... | @@ -242,7 +221,6 @@ |
242 | 221 | &sampling_rate_max.attr, |
243 | 222 | &sampling_rate_min.attr, |
244 | 223 | &sampling_rate.attr, |
245 | - &sampling_down_factor.attr, | |
246 | 224 | &up_threshold.attr, |
247 | 225 | &ignore_nice_load.attr, |
248 | 226 | NULL |
249 | 227 | |
... | ... | @@ -257,11 +235,10 @@ |
257 | 235 | |
258 | 236 | static void dbs_check_cpu(int cpu) |
259 | 237 | { |
260 | - unsigned int idle_ticks, up_idle_ticks, total_ticks; | |
261 | - unsigned int freq_next; | |
262 | - unsigned int freq_down_sampling_rate; | |
263 | - static int down_skip[NR_CPUS]; | |
238 | + unsigned int idle_ticks, total_ticks; | |
239 | + unsigned int load; | |
264 | 240 | struct cpu_dbs_info_s *this_dbs_info; |
241 | + cputime64_t cur_jiffies; | |
265 | 242 | |
266 | 243 | struct cpufreq_policy *policy; |
267 | 244 | unsigned int j; |
268 | 245 | |
... | ... | @@ -271,10 +248,14 @@ |
271 | 248 | return; |
272 | 249 | |
273 | 250 | policy = this_dbs_info->cur_policy; |
251 | + cur_jiffies = jiffies64_to_cputime64(get_jiffies_64()); | |
252 | + total_ticks = (unsigned int) cputime64_sub(cur_jiffies, | |
253 | + this_dbs_info->prev_cpu_wall); | |
254 | + this_dbs_info->prev_cpu_wall = cur_jiffies; | |
274 | 255 | /* |
275 | 256 | * Every sampling_rate, we check, if current idle time is less |
276 | 257 | * than 20% (default), then we try to increase frequency |
277 | - * Every sampling_rate*sampling_down_factor, we look for a the lowest | |
258 | + * Every sampling_rate, we look for a the lowest | |
278 | 259 | * frequency which can sustain the load while keeping idle time over |
279 | 260 | * 30%. If such a frequency exist, we try to decrease to this frequency. |
280 | 261 | * |
281 | 262 | |
282 | 263 | |
283 | 264 | |
284 | 265 | |
... | ... | @@ -283,36 +264,26 @@ |
283 | 264 | * 5% (default) of current frequency |
284 | 265 | */ |
285 | 266 | |
286 | - /* Check for frequency increase */ | |
267 | + /* Get Idle Time */ | |
287 | 268 | idle_ticks = UINT_MAX; |
288 | 269 | for_each_cpu_mask(j, policy->cpus) { |
289 | - unsigned int tmp_idle_ticks, total_idle_ticks; | |
270 | + cputime64_t total_idle_ticks; | |
271 | + unsigned int tmp_idle_ticks; | |
290 | 272 | struct cpu_dbs_info_s *j_dbs_info; |
291 | 273 | |
292 | 274 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
293 | 275 | total_idle_ticks = get_cpu_idle_time(j); |
294 | - tmp_idle_ticks = total_idle_ticks - | |
295 | - j_dbs_info->prev_cpu_idle_up; | |
296 | - j_dbs_info->prev_cpu_idle_up = total_idle_ticks; | |
276 | + tmp_idle_ticks = (unsigned int) cputime64_sub(total_idle_ticks, | |
277 | + j_dbs_info->prev_cpu_idle); | |
278 | + j_dbs_info->prev_cpu_idle = total_idle_ticks; | |
297 | 279 | |
298 | 280 | if (tmp_idle_ticks < idle_ticks) |
299 | 281 | idle_ticks = tmp_idle_ticks; |
300 | 282 | } |
283 | + load = (100 * (total_ticks - idle_ticks)) / total_ticks; | |
301 | 284 | |
302 | - /* Scale idle ticks by 100 and compare with up and down ticks */ | |
303 | - idle_ticks *= 100; | |
304 | - up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * | |
305 | - usecs_to_jiffies(dbs_tuners_ins.sampling_rate); | |
306 | - | |
307 | - if (idle_ticks < up_idle_ticks) { | |
308 | - down_skip[cpu] = 0; | |
309 | - for_each_cpu_mask(j, policy->cpus) { | |
310 | - struct cpu_dbs_info_s *j_dbs_info; | |
311 | - | |
312 | - j_dbs_info = &per_cpu(cpu_dbs_info, j); | |
313 | - j_dbs_info->prev_cpu_idle_down = | |
314 | - j_dbs_info->prev_cpu_idle_up; | |
315 | - } | |
285 | + /* Check for frequency increase */ | |
286 | + if (load > dbs_tuners_ins.up_threshold) { | |
316 | 287 | /* if we are already at full speed then break out early */ |
317 | 288 | if (policy->cur == policy->max) |
318 | 289 | return; |
319 | 290 | |
320 | 291 | |
321 | 292 | |
322 | 293 | |
... | ... | @@ -323,50 +294,22 @@ |
323 | 294 | } |
324 | 295 | |
325 | 296 | /* Check for frequency decrease */ |
326 | - down_skip[cpu]++; | |
327 | - if (down_skip[cpu] < dbs_tuners_ins.sampling_down_factor) | |
328 | - return; | |
329 | - | |
330 | - idle_ticks = UINT_MAX; | |
331 | - for_each_cpu_mask(j, policy->cpus) { | |
332 | - unsigned int tmp_idle_ticks, total_idle_ticks; | |
333 | - struct cpu_dbs_info_s *j_dbs_info; | |
334 | - | |
335 | - j_dbs_info = &per_cpu(cpu_dbs_info, j); | |
336 | - /* Check for frequency decrease */ | |
337 | - total_idle_ticks = j_dbs_info->prev_cpu_idle_up; | |
338 | - tmp_idle_ticks = total_idle_ticks - | |
339 | - j_dbs_info->prev_cpu_idle_down; | |
340 | - j_dbs_info->prev_cpu_idle_down = total_idle_ticks; | |
341 | - | |
342 | - if (tmp_idle_ticks < idle_ticks) | |
343 | - idle_ticks = tmp_idle_ticks; | |
344 | - } | |
345 | - | |
346 | - down_skip[cpu] = 0; | |
347 | 297 | /* if we cannot reduce the frequency anymore, break out early */ |
348 | 298 | if (policy->cur == policy->min) |
349 | 299 | return; |
350 | 300 | |
351 | - /* Compute how many ticks there are between two measurements */ | |
352 | - freq_down_sampling_rate = dbs_tuners_ins.sampling_rate * | |
353 | - dbs_tuners_ins.sampling_down_factor; | |
354 | - total_ticks = usecs_to_jiffies(freq_down_sampling_rate); | |
355 | - | |
356 | 301 | /* |
357 | 302 | * The optimal frequency is the frequency that is the lowest that |
358 | 303 | * can support the current CPU usage without triggering the up |
359 | 304 | * policy. To be safe, we focus 10 points under the threshold. |
360 | 305 | */ |
361 | - freq_next = ((total_ticks - idle_ticks) * 100) / total_ticks; | |
362 | - freq_next = (freq_next * policy->cur) / | |
306 | + if (load < (dbs_tuners_ins.up_threshold - 10)) { | |
307 | + unsigned int freq_next; | |
308 | + freq_next = (policy->cur * load) / | |
363 | 309 | (dbs_tuners_ins.up_threshold - 10); |
364 | 310 | |
365 | - if (freq_next < policy->min) | |
366 | - freq_next = policy->min; | |
367 | - | |
368 | - if (freq_next <= ((policy->cur * 95) / 100)) | |
369 | 311 | __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L); |
312 | + } | |
370 | 313 | } |
371 | 314 | |
372 | 315 | static void do_dbs_timer(void *data) |
... | ... | @@ -432,9 +375,8 @@ |
432 | 375 | j_dbs_info = &per_cpu(cpu_dbs_info, j); |
433 | 376 | j_dbs_info->cur_policy = policy; |
434 | 377 | |
435 | - j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); | |
436 | - j_dbs_info->prev_cpu_idle_down | |
437 | - = j_dbs_info->prev_cpu_idle_up; | |
378 | + j_dbs_info->prev_cpu_idle = get_cpu_idle_time(j); | |
379 | + j_dbs_info->prev_cpu_wall = get_jiffies_64(); | |
438 | 380 | } |
439 | 381 | this_dbs_info->enable = 1; |
440 | 382 | sysfs_create_group(&policy->kobj, &dbs_attr_group); |
include/asm-generic/cputime.h
... | ... | @@ -24,7 +24,9 @@ |
24 | 24 | |
25 | 25 | #define cputime64_zero (0ULL) |
26 | 26 | #define cputime64_add(__a, __b) ((__a) + (__b)) |
27 | +#define cputime64_sub(__a, __b) ((__a) - (__b)) | |
27 | 28 | #define cputime64_to_jiffies64(__ct) (__ct) |
29 | +#define jiffies64_to_cputime64(__jif) (__jif) | |
28 | 30 | #define cputime_to_cputime64(__ct) ((u64) __ct) |
29 | 31 | |
30 | 32 |