History

[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.

Venkatesh Pallipadi committed 20 years ago

Commit ccb2fe21 parent 501b7c72 files · +42 −98Browse files

Unified · Split

2 files
  1. drivers/cpufreq/cpufreq_ondemand.c +40 −98
  2. include/asm-generic/cputime.h +2 −0
drivers/cpufreq/cpufreq_ondemand.c+40−98
@@ -56,16 +56,14 @@ static unsigned int def_sampling_rate; · 55 unmodified lines
5656 #define MIN_SAMPLING_RATE (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
5757 #define MAX_SAMPLING_RATE (500 * def_sampling_rate)
5858 #define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000)
59−#define DEF_SAMPLING_DOWN_FACTOR (1)
60−#define MAX_SAMPLING_DOWN_FACTOR (10)
6159 #define TRANSITION_LATENCY_LIMIT (10 * 1000)
6260
6361 static void do_dbs_timer(void *data);
6462
6563 struct cpu_dbs_info_s {
64+ cputime64_t prev_cpu_idle;
65+ cputime64_t prev_cpu_wall;
6666 struct cpufreq_policy *cur_policy;
67− unsigned int prev_cpu_idle_up;
68− unsigned int prev_cpu_idle_down;
6967 unsigned int enable;
7068 };
7169 static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
@@ -87,24 +85,26 @@ static struct workqueue_struct *dbs_workq; · 15 unmodified lines
8785
8886 struct dbs_tuners {
8987 unsigned int sampling_rate;
90− unsigned int sampling_down_factor;
9188 unsigned int up_threshold;
9289 unsigned int ignore_nice;
9390 };
9491
9592 static struct dbs_tuners dbs_tuners_ins = {
9693 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
97− .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
9894 .ignore_nice = 0,
9995 };
10096
101−static inline unsigned int get_cpu_idle_time(unsigned int cpu)
97+static inline cputime64_t get_cpu_idle_time(unsigned int cpu)
10298 {
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;
108108 }
109109
110110 /************************** sysfs interface ************************/
@@ -133,29 +133,9 @@ static ssize_t show_##file_name \ · 22 unmodified lines
133133 return sprintf(buf, "%u\n", dbs_tuners_ins.object); \
134134 }
135135 show_one(sampling_rate, sampling_rate);
136−show_one(sampling_down_factor, sampling_down_factor);
137136 show_one(up_threshold, up_threshold);
138137 show_one(ignore_nice_load, ignore_nice);
139138
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−
159139 static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
160140 const char *buf, size_t count)
161141 {
@@ -217,12 +197,12 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy, · 55 unmodified lines
217197 }
218198 dbs_tuners_ins.ignore_nice = input;
219199
220− /* we need to re-evaluate prev_cpu_idle_up and prev_cpu_idle_down */
200+ /* we need to re-evaluate prev_cpu_idle */
221201 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();
226206 }
227207 mutex_unlock(&dbs_mutex);
228208
@@ -234,7 +214,6 @@ static struct freq_attr _name = \ · 5 unmodified lines
234214 __ATTR(_name, 0644, show_##_name, store_##_name)
235215
236216 define_one_rw(sampling_rate);
237−define_one_rw(sampling_down_factor);
238217 define_one_rw(up_threshold);
239218 define_one_rw(ignore_nice_load);
240219
@@ -242,7 +221,6 @@ static struct attribute * dbs_attributes[] = { · 1 unmodified line
242221 &sampling_rate_max.attr,
243222 &sampling_rate_min.attr,
244223 &sampling_rate.attr,
245− &sampling_down_factor.attr,
246224 &up_threshold.attr,
247225 &ignore_nice_load.attr,
248226 NULL
@@ -257,11 +235,10 @@ static struct attribute_group dbs_attr_group = { · 8 unmodified lines
257235
258236 static void dbs_check_cpu(int cpu)
259237 {
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;
264240 struct cpu_dbs_info_s *this_dbs_info;
241+ cputime64_t cur_jiffies;
265242
266243 struct cpufreq_policy *policy;
267244 unsigned int j;
@@ -271,10 +248,14 @@ static void dbs_check_cpu(int cpu) · 3 unmodified lines
271248 return;
272249
273250 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;
274255 /*
275256 * Every sampling_rate, we check, if current idle time is less
276257 * 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
278259 * frequency which can sustain the load while keeping idle time over
279260 * 30%. If such a frequency exist, we try to decrease to this frequency.
280261 *
@@ -283,36 +264,26 @@ static void dbs_check_cpu(int cpu) · 2 unmodified lines
283264 * 5% (default) of current frequency
284265 */
285266
286− /* Check for frequency increase */
267+ /* Get Idle Time */
287268 idle_ticks = UINT_MAX;
288269 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;
290272 struct cpu_dbs_info_s *j_dbs_info;
291273
292274 j_dbs_info = &per_cpu(cpu_dbs_info, j);
293275 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;
297279
298280 if (tmp_idle_ticks < idle_ticks)
299281 idle_ticks = tmp_idle_ticks;
300282 }
283+ load = (100 * (total_ticks - idle_ticks)) / total_ticks;
301284
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) {
316287 /* if we are already at full speed then break out early */
317288 if (policy->cur == policy->max)
318289 return;
@@ -323,50 +294,22 @@ static void dbs_check_cpu(int cpu) · 4 unmodified lines
323294 }
324295
325296 /* 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;
347297 /* if we cannot reduce the frequency anymore, break out early */
348298 if (policy->cur == policy->min)
349299 return;
350300
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−
356301 /*
357302 * The optimal frequency is the frequency that is the lowest that
358303 * can support the current CPU usage without triggering the up
359304 * policy. To be safe, we focus 10 points under the threshold.
360305 */
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) /
363309 (dbs_tuners_ins.up_threshold - 10);
364310
365− if (freq_next < policy->min)
366− freq_next = policy->min;
367−
368− if (freq_next <= ((policy->cur * 95) / 100))
369311 __cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_L);
312+ }
370313 }
371314
372315 static void do_dbs_timer(void *data)
@@ -432,9 +375,8 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, · 59 unmodified lines
432375 j_dbs_info = &per_cpu(cpu_dbs_info, j);
433376 j_dbs_info->cur_policy = policy;
434377
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();
438380 }
439381 this_dbs_info->enable = 1;
440382 sysfs_create_group(&policy->kobj, &dbs_attr_group);
include/asm-generic/cputime.h+2−0
@@ -24,7 +24,9 @@ typedef u64 cputime64_t; · 23 unmodified lines
2424
2525 #define cputime64_zero (0ULL)
2626 #define cputime64_add(__a, __b) ((__a) + (__b))
27+#define cputime64_sub(__a, __b) ((__a) - (__b))
2728 #define cputime64_to_jiffies64(__ct) (__ct)
29+#define jiffies64_to_cputime64(__jif) (__jif)
2830 #define cputime_to_cputime64(__ct) ((u64) __ct)
2931
3032