blob: c578370cd693fd56635482b622429598d561a761 [file] [log] [blame]
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001/*
2 * Completely Fair Scheduling (CFS) Class (SCHED_NORMAL/SCHED_BATCH)
3 *
4 * Copyright (C) 2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
5 *
6 * Interactivity improvements by Mike Galbraith
7 * (C) 2007 Mike Galbraith <efault@gmx.de>
8 *
9 * Various enhancements by Dmitry Adamushko.
10 * (C) 2007 Dmitry Adamushko <dmitry.adamushko@gmail.com>
11 *
12 * Group scheduling enhancements by Srivatsa Vaddagiri
13 * Copyright IBM Corporation, 2007
14 * Author: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>
15 *
16 * Scaled math optimizations by Thomas Gleixner
17 * Copyright (C) 2007, Thomas Gleixner <tglx@linutronix.de>
18 */
19
20/*
21 * Preemption granularity:
Ingo Molnar71fd3712007-08-24 20:39:10 +020022 * (default: 10 msec, units: nanoseconds)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +020023 *
24 * NOTE: this granularity value is not the same as the concept of
25 * 'timeslice length' - timeslices in CFS will typically be somewhat
26 * larger than this value. (to see the precise effective timeslice
27 * length of your workload, run vmstat and monitor the context-switches
28 * field)
29 *
30 * On SMP systems the value of this is multiplied by the log2 of the
31 * number of CPUs. (i.e. factor 2x on 2-way systems, 3x on 4-way
32 * systems, 4x on 8-way systems, 5x on 16-way systems, etc.)
33 */
Ingo Molnar71fd3712007-08-24 20:39:10 +020034unsigned int sysctl_sched_granularity __read_mostly = 10000000UL;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +020035
36/*
37 * SCHED_BATCH wake-up granularity.
Ingo Molnar71fd3712007-08-24 20:39:10 +020038 * (default: 25 msec, units: nanoseconds)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +020039 *
40 * This option delays the preemption effects of decoupled workloads
41 * and reduces their over-scheduling. Synchronous workloads will still
42 * have immediate wakeup/sleep latencies.
43 */
Ingo Molnar71fd3712007-08-24 20:39:10 +020044unsigned int sysctl_sched_batch_wakeup_granularity __read_mostly = 25000000UL;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +020045
46/*
47 * SCHED_OTHER wake-up granularity.
48 * (default: 1 msec, units: nanoseconds)
49 *
50 * This option delays the preemption effects of decoupled workloads
51 * and reduces their over-scheduling. Synchronous workloads will still
52 * have immediate wakeup/sleep latencies.
53 */
Ingo Molnar71fd3712007-08-24 20:39:10 +020054unsigned int sysctl_sched_wakeup_granularity __read_mostly = 1000000UL;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +020055
56unsigned int sysctl_sched_stat_granularity __read_mostly;
57
58/*
Ingo Molnar71fd3712007-08-24 20:39:10 +020059 * Initialized in sched_init_granularity() [to 5 times the base granularity]:
Ingo Molnarbf0f6f22007-07-09 18:51:58 +020060 */
61unsigned int sysctl_sched_runtime_limit __read_mostly;
62
63/*
64 * Debugging: various feature bits
65 */
66enum {
67 SCHED_FEAT_FAIR_SLEEPERS = 1,
68 SCHED_FEAT_SLEEPER_AVG = 2,
69 SCHED_FEAT_SLEEPER_LOAD_AVG = 4,
70 SCHED_FEAT_PRECISE_CPU_LOAD = 8,
71 SCHED_FEAT_START_DEBIT = 16,
72 SCHED_FEAT_SKIP_INITIAL = 32,
73};
74
75unsigned int sysctl_sched_features __read_mostly =
76 SCHED_FEAT_FAIR_SLEEPERS *1 |
Ingo Molnar5d2b3d32007-08-12 18:08:19 +020077 SCHED_FEAT_SLEEPER_AVG *0 |
Ingo Molnarbf0f6f22007-07-09 18:51:58 +020078 SCHED_FEAT_SLEEPER_LOAD_AVG *1 |
79 SCHED_FEAT_PRECISE_CPU_LOAD *1 |
80 SCHED_FEAT_START_DEBIT *1 |
81 SCHED_FEAT_SKIP_INITIAL *0;
82
83extern struct sched_class fair_sched_class;
84
85/**************************************************************
86 * CFS operations on generic schedulable entities:
87 */
88
89#ifdef CONFIG_FAIR_GROUP_SCHED
90
91/* cpu runqueue to which this cfs_rq is attached */
92static inline struct rq *rq_of(struct cfs_rq *cfs_rq)
93{
94 return cfs_rq->rq;
95}
96
97/* currently running entity (if any) on this cfs_rq */
98static inline struct sched_entity *cfs_rq_curr(struct cfs_rq *cfs_rq)
99{
100 return cfs_rq->curr;
101}
102
103/* An entity is a task if it doesn't "own" a runqueue */
104#define entity_is_task(se) (!se->my_q)
105
106static inline void
107set_cfs_rq_curr(struct cfs_rq *cfs_rq, struct sched_entity *se)
108{
109 cfs_rq->curr = se;
110}
111
112#else /* CONFIG_FAIR_GROUP_SCHED */
113
114static inline struct rq *rq_of(struct cfs_rq *cfs_rq)
115{
116 return container_of(cfs_rq, struct rq, cfs);
117}
118
119static inline struct sched_entity *cfs_rq_curr(struct cfs_rq *cfs_rq)
120{
121 struct rq *rq = rq_of(cfs_rq);
122
123 if (unlikely(rq->curr->sched_class != &fair_sched_class))
124 return NULL;
125
126 return &rq->curr->se;
127}
128
129#define entity_is_task(se) 1
130
131static inline void
132set_cfs_rq_curr(struct cfs_rq *cfs_rq, struct sched_entity *se) { }
133
134#endif /* CONFIG_FAIR_GROUP_SCHED */
135
136static inline struct task_struct *task_of(struct sched_entity *se)
137{
138 return container_of(se, struct task_struct, se);
139}
140
141
142/**************************************************************
143 * Scheduling class tree data structure manipulation methods:
144 */
145
146/*
147 * Enqueue an entity into the rb-tree:
148 */
149static inline void
150__enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
151{
152 struct rb_node **link = &cfs_rq->tasks_timeline.rb_node;
153 struct rb_node *parent = NULL;
154 struct sched_entity *entry;
155 s64 key = se->fair_key;
156 int leftmost = 1;
157
158 /*
159 * Find the right place in the rbtree:
160 */
161 while (*link) {
162 parent = *link;
163 entry = rb_entry(parent, struct sched_entity, run_node);
164 /*
165 * We dont care about collisions. Nodes with
166 * the same key stay together.
167 */
168 if (key - entry->fair_key < 0) {
169 link = &parent->rb_left;
170 } else {
171 link = &parent->rb_right;
172 leftmost = 0;
173 }
174 }
175
176 /*
177 * Maintain a cache of leftmost tree entries (it is frequently
178 * used):
179 */
180 if (leftmost)
181 cfs_rq->rb_leftmost = &se->run_node;
182
183 rb_link_node(&se->run_node, parent, link);
184 rb_insert_color(&se->run_node, &cfs_rq->tasks_timeline);
185 update_load_add(&cfs_rq->load, se->load.weight);
186 cfs_rq->nr_running++;
187 se->on_rq = 1;
188}
189
190static inline void
191__dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
192{
193 if (cfs_rq->rb_leftmost == &se->run_node)
194 cfs_rq->rb_leftmost = rb_next(&se->run_node);
195 rb_erase(&se->run_node, &cfs_rq->tasks_timeline);
196 update_load_sub(&cfs_rq->load, se->load.weight);
197 cfs_rq->nr_running--;
198 se->on_rq = 0;
199}
200
201static inline struct rb_node *first_fair(struct cfs_rq *cfs_rq)
202{
203 return cfs_rq->rb_leftmost;
204}
205
206static struct sched_entity *__pick_next_entity(struct cfs_rq *cfs_rq)
207{
208 return rb_entry(first_fair(cfs_rq), struct sched_entity, run_node);
209}
210
211/**************************************************************
212 * Scheduling class statistics methods:
213 */
214
215/*
216 * We rescale the rescheduling granularity of tasks according to their
217 * nice level, but only linearly, not exponentially:
218 */
219static long
220niced_granularity(struct sched_entity *curr, unsigned long granularity)
221{
222 u64 tmp;
223
Ingo Molnar7cff8cf2007-08-09 11:16:52 +0200224 if (likely(curr->load.weight == NICE_0_LOAD))
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200225 return granularity;
226 /*
Ingo Molnar7cff8cf2007-08-09 11:16:52 +0200227 * Positive nice levels get the same granularity as nice-0:
228 */
229 if (likely(curr->load.weight < NICE_0_LOAD)) {
230 tmp = curr->load.weight * (u64)granularity;
231 return (long) (tmp >> NICE_0_SHIFT);
232 }
233 /*
234 * Negative nice level tasks get linearly finer
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200235 * granularity:
236 */
Ingo Molnar7cff8cf2007-08-09 11:16:52 +0200237 tmp = curr->load.inv_weight * (u64)granularity;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200238
239 /*
240 * It will always fit into 'long':
241 */
Ingo Molnar7cff8cf2007-08-09 11:16:52 +0200242 return (long) (tmp >> WMULT_SHIFT);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200243}
244
245static inline void
246limit_wait_runtime(struct cfs_rq *cfs_rq, struct sched_entity *se)
247{
248 long limit = sysctl_sched_runtime_limit;
249
250 /*
251 * Niced tasks have the same history dynamic range as
252 * non-niced tasks:
253 */
254 if (unlikely(se->wait_runtime > limit)) {
255 se->wait_runtime = limit;
256 schedstat_inc(se, wait_runtime_overruns);
257 schedstat_inc(cfs_rq, wait_runtime_overruns);
258 }
259 if (unlikely(se->wait_runtime < -limit)) {
260 se->wait_runtime = -limit;
261 schedstat_inc(se, wait_runtime_underruns);
262 schedstat_inc(cfs_rq, wait_runtime_underruns);
263 }
264}
265
266static inline void
267__add_wait_runtime(struct cfs_rq *cfs_rq, struct sched_entity *se, long delta)
268{
269 se->wait_runtime += delta;
270 schedstat_add(se, sum_wait_runtime, delta);
271 limit_wait_runtime(cfs_rq, se);
272}
273
274static void
275add_wait_runtime(struct cfs_rq *cfs_rq, struct sched_entity *se, long delta)
276{
277 schedstat_add(cfs_rq, wait_runtime, -se->wait_runtime);
278 __add_wait_runtime(cfs_rq, se, delta);
279 schedstat_add(cfs_rq, wait_runtime, se->wait_runtime);
280}
281
282/*
283 * Update the current task's runtime statistics. Skip current tasks that
284 * are not in our scheduling class.
285 */
286static inline void
Ingo Molnarb7cc0892007-08-09 11:16:47 +0200287__update_curr(struct cfs_rq *cfs_rq, struct sched_entity *curr)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200288{
Ingo Molnarc5dcfe72007-08-09 11:16:46 +0200289 unsigned long delta, delta_exec, delta_fair, delta_mine;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200290 struct load_weight *lw = &cfs_rq->load;
291 unsigned long load = lw->weight;
292
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200293 delta_exec = curr->delta_exec;
Ingo Molnar8179ca232007-08-02 17:41:40 +0200294 schedstat_set(curr->exec_max, max((u64)delta_exec, curr->exec_max));
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200295
296 curr->sum_exec_runtime += delta_exec;
297 cfs_rq->exec_clock += delta_exec;
298
Ingo Molnarfd8bb432007-08-09 11:16:46 +0200299 if (unlikely(!load))
300 return;
301
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200302 delta_fair = calc_delta_fair(delta_exec, lw);
303 delta_mine = calc_delta_mine(delta_exec, curr->load.weight, lw);
304
Ingo Molnar0915c4e2007-08-09 11:16:45 +0200305 if (cfs_rq->sleeper_bonus > sysctl_sched_granularity) {
Ingo Molnar5d2b3d32007-08-12 18:08:19 +0200306 delta = min(cfs_rq->sleeper_bonus, (u64)delta_exec);
307 delta = calc_delta_mine(delta, curr->load.weight, lw);
308 delta = min((u64)delta, cfs_rq->sleeper_bonus);
Ingo Molnarb2133c82007-08-24 20:39:10 +0200309 delta = min(delta, (unsigned long)(
310 (long)sysctl_sched_runtime_limit - curr->wait_runtime));
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200311 cfs_rq->sleeper_bonus -= delta;
312 delta_mine -= delta;
313 }
314
315 cfs_rq->fair_clock += delta_fair;
316 /*
317 * We executed delta_exec amount of time on the CPU,
318 * but we were only entitled to delta_mine amount of
319 * time during that period (if nr_running == 1 then
320 * the two values are equal)
321 * [Note: delta_mine - delta_exec is negative]:
322 */
323 add_wait_runtime(cfs_rq, curr, delta_mine - delta_exec);
324}
325
Ingo Molnarb7cc0892007-08-09 11:16:47 +0200326static void update_curr(struct cfs_rq *cfs_rq)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200327{
328 struct sched_entity *curr = cfs_rq_curr(cfs_rq);
329 unsigned long delta_exec;
330
331 if (unlikely(!curr))
332 return;
333
334 /*
335 * Get the amount of time the current task was running
336 * since the last time we changed load (this cannot
337 * overflow on 32 bits):
338 */
Ingo Molnard2819182007-08-09 11:16:47 +0200339 delta_exec = (unsigned long)(rq_of(cfs_rq)->clock - curr->exec_start);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200340
341 curr->delta_exec += delta_exec;
342
343 if (unlikely(curr->delta_exec > sysctl_sched_stat_granularity)) {
Ingo Molnarb7cc0892007-08-09 11:16:47 +0200344 __update_curr(cfs_rq, curr);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200345 curr->delta_exec = 0;
346 }
Ingo Molnard2819182007-08-09 11:16:47 +0200347 curr->exec_start = rq_of(cfs_rq)->clock;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200348}
349
350static inline void
Ingo Molnar5870db52007-08-09 11:16:47 +0200351update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200352{
353 se->wait_start_fair = cfs_rq->fair_clock;
Ingo Molnard2819182007-08-09 11:16:47 +0200354 schedstat_set(se->wait_start, rq_of(cfs_rq)->clock);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200355}
356
357/*
358 * We calculate fair deltas here, so protect against the random effects
359 * of a multiplication overflow by capping it to the runtime limit:
360 */
361#if BITS_PER_LONG == 32
362static inline unsigned long
363calc_weighted(unsigned long delta, unsigned long weight, int shift)
364{
365 u64 tmp = (u64)delta * weight >> shift;
366
367 if (unlikely(tmp > sysctl_sched_runtime_limit*2))
368 return sysctl_sched_runtime_limit*2;
369 return tmp;
370}
371#else
372static inline unsigned long
373calc_weighted(unsigned long delta, unsigned long weight, int shift)
374{
375 return delta * weight >> shift;
376}
377#endif
378
379/*
380 * Task is being enqueued - update stats:
381 */
Ingo Molnard2417e52007-08-09 11:16:47 +0200382static void update_stats_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200383{
384 s64 key;
385
386 /*
387 * Are we enqueueing a waiting task? (for current tasks
388 * a dequeue/enqueue event is a NOP)
389 */
390 if (se != cfs_rq_curr(cfs_rq))
Ingo Molnar5870db52007-08-09 11:16:47 +0200391 update_stats_wait_start(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200392 /*
393 * Update the key:
394 */
395 key = cfs_rq->fair_clock;
396
397 /*
398 * Optimize the common nice 0 case:
399 */
400 if (likely(se->load.weight == NICE_0_LOAD)) {
401 key -= se->wait_runtime;
402 } else {
403 u64 tmp;
404
405 if (se->wait_runtime < 0) {
406 tmp = -se->wait_runtime;
407 key += (tmp * se->load.inv_weight) >>
408 (WMULT_SHIFT - NICE_0_SHIFT);
409 } else {
410 tmp = se->wait_runtime;
Ingo Molnara69edb52007-08-09 11:16:52 +0200411 key -= (tmp * se->load.inv_weight) >>
412 (WMULT_SHIFT - NICE_0_SHIFT);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200413 }
414 }
415
416 se->fair_key = key;
417}
418
419/*
420 * Note: must be called with a freshly updated rq->fair_clock.
421 */
422static inline void
Ingo Molnareac55ea2007-08-09 11:16:47 +0200423__update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200424{
425 unsigned long delta_fair = se->delta_fair_run;
426
Ingo Molnard2819182007-08-09 11:16:47 +0200427 schedstat_set(se->wait_max, max(se->wait_max,
428 rq_of(cfs_rq)->clock - se->wait_start));
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200429
430 if (unlikely(se->load.weight != NICE_0_LOAD))
431 delta_fair = calc_weighted(delta_fair, se->load.weight,
432 NICE_0_SHIFT);
433
434 add_wait_runtime(cfs_rq, se, delta_fair);
435}
436
437static void
Ingo Molnar9ef0a962007-08-09 11:16:47 +0200438update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200439{
440 unsigned long delta_fair;
441
442 delta_fair = (unsigned long)min((u64)(2*sysctl_sched_runtime_limit),
443 (u64)(cfs_rq->fair_clock - se->wait_start_fair));
444
445 se->delta_fair_run += delta_fair;
446 if (unlikely(abs(se->delta_fair_run) >=
447 sysctl_sched_stat_granularity)) {
Ingo Molnareac55ea2007-08-09 11:16:47 +0200448 __update_stats_wait_end(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200449 se->delta_fair_run = 0;
450 }
451
452 se->wait_start_fair = 0;
Ingo Molnar6cfb0d52007-08-02 17:41:40 +0200453 schedstat_set(se->wait_start, 0);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200454}
455
456static inline void
Ingo Molnar19b6a2e2007-08-09 11:16:48 +0200457update_stats_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200458{
Ingo Molnarb7cc0892007-08-09 11:16:47 +0200459 update_curr(cfs_rq);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200460 /*
461 * Mark the end of the wait period if dequeueing a
462 * waiting task:
463 */
464 if (se != cfs_rq_curr(cfs_rq))
Ingo Molnar9ef0a962007-08-09 11:16:47 +0200465 update_stats_wait_end(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200466}
467
468/*
469 * We are picking a new current task - update its stats:
470 */
471static inline void
Ingo Molnar79303e92007-08-09 11:16:47 +0200472update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200473{
474 /*
475 * We are starting a new run period:
476 */
Ingo Molnard2819182007-08-09 11:16:47 +0200477 se->exec_start = rq_of(cfs_rq)->clock;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200478}
479
480/*
481 * We are descheduling a task - update its stats:
482 */
483static inline void
Ingo Molnarc7e9b5b2007-08-09 11:16:48 +0200484update_stats_curr_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200485{
486 se->exec_start = 0;
487}
488
489/**************************************************
490 * Scheduling class queueing methods:
491 */
492
Ingo Molnardfdc119e2007-08-09 11:16:48 +0200493static void __enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200494{
495 unsigned long load = cfs_rq->load.weight, delta_fair;
496 long prev_runtime;
497
Ingo Molnarb2133c82007-08-24 20:39:10 +0200498 /*
499 * Do not boost sleepers if there's too much bonus 'in flight'
500 * already:
501 */
502 if (unlikely(cfs_rq->sleeper_bonus > sysctl_sched_runtime_limit))
503 return;
504
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200505 if (sysctl_sched_features & SCHED_FEAT_SLEEPER_LOAD_AVG)
506 load = rq_of(cfs_rq)->cpu_load[2];
507
508 delta_fair = se->delta_fair_sleep;
509
510 /*
511 * Fix up delta_fair with the effect of us running
512 * during the whole sleep period:
513 */
514 if (sysctl_sched_features & SCHED_FEAT_SLEEPER_AVG)
515 delta_fair = div64_likely32((u64)delta_fair * load,
516 load + se->load.weight);
517
518 if (unlikely(se->load.weight != NICE_0_LOAD))
519 delta_fair = calc_weighted(delta_fair, se->load.weight,
520 NICE_0_SHIFT);
521
522 prev_runtime = se->wait_runtime;
523 __add_wait_runtime(cfs_rq, se, delta_fair);
Ingo Molnarb2133c82007-08-24 20:39:10 +0200524 schedstat_add(cfs_rq, wait_runtime, se->wait_runtime);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200525 delta_fair = se->wait_runtime - prev_runtime;
526
527 /*
528 * Track the amount of bonus we've given to sleepers:
529 */
530 cfs_rq->sleeper_bonus += delta_fair;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200531}
532
Ingo Molnar2396af62007-08-09 11:16:48 +0200533static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200534{
535 struct task_struct *tsk = task_of(se);
536 unsigned long delta_fair;
537
538 if ((entity_is_task(se) && tsk->policy == SCHED_BATCH) ||
539 !(sysctl_sched_features & SCHED_FEAT_FAIR_SLEEPERS))
540 return;
541
542 delta_fair = (unsigned long)min((u64)(2*sysctl_sched_runtime_limit),
543 (u64)(cfs_rq->fair_clock - se->sleep_start_fair));
544
545 se->delta_fair_sleep += delta_fair;
546 if (unlikely(abs(se->delta_fair_sleep) >=
547 sysctl_sched_stat_granularity)) {
Ingo Molnardfdc119e2007-08-09 11:16:48 +0200548 __enqueue_sleeper(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200549 se->delta_fair_sleep = 0;
550 }
551
552 se->sleep_start_fair = 0;
553
554#ifdef CONFIG_SCHEDSTATS
555 if (se->sleep_start) {
Ingo Molnard2819182007-08-09 11:16:47 +0200556 u64 delta = rq_of(cfs_rq)->clock - se->sleep_start;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200557
558 if ((s64)delta < 0)
559 delta = 0;
560
561 if (unlikely(delta > se->sleep_max))
562 se->sleep_max = delta;
563
564 se->sleep_start = 0;
565 se->sum_sleep_runtime += delta;
566 }
567 if (se->block_start) {
Ingo Molnard2819182007-08-09 11:16:47 +0200568 u64 delta = rq_of(cfs_rq)->clock - se->block_start;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200569
570 if ((s64)delta < 0)
571 delta = 0;
572
573 if (unlikely(delta > se->block_max))
574 se->block_max = delta;
575
576 se->block_start = 0;
577 se->sum_sleep_runtime += delta;
578 }
579#endif
580}
581
582static void
Ingo Molnar668031c2007-08-09 11:16:48 +0200583enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int wakeup)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200584{
585 /*
586 * Update the fair clock.
587 */
Ingo Molnarb7cc0892007-08-09 11:16:47 +0200588 update_curr(cfs_rq);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200589
590 if (wakeup)
Ingo Molnar2396af62007-08-09 11:16:48 +0200591 enqueue_sleeper(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200592
Ingo Molnard2417e52007-08-09 11:16:47 +0200593 update_stats_enqueue(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200594 __enqueue_entity(cfs_rq, se);
595}
596
597static void
Ingo Molnar525c2712007-08-09 11:16:48 +0200598dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200599{
Ingo Molnar19b6a2e2007-08-09 11:16:48 +0200600 update_stats_dequeue(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200601 if (sleep) {
602 se->sleep_start_fair = cfs_rq->fair_clock;
603#ifdef CONFIG_SCHEDSTATS
604 if (entity_is_task(se)) {
605 struct task_struct *tsk = task_of(se);
606
607 if (tsk->state & TASK_INTERRUPTIBLE)
Ingo Molnard2819182007-08-09 11:16:47 +0200608 se->sleep_start = rq_of(cfs_rq)->clock;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200609 if (tsk->state & TASK_UNINTERRUPTIBLE)
Ingo Molnard2819182007-08-09 11:16:47 +0200610 se->block_start = rq_of(cfs_rq)->clock;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200611 }
612 cfs_rq->wait_runtime -= se->wait_runtime;
613#endif
614 }
615 __dequeue_entity(cfs_rq, se);
616}
617
618/*
619 * Preempt the current task with a newly woken task if needed:
620 */
621static void
622__check_preempt_curr_fair(struct cfs_rq *cfs_rq, struct sched_entity *se,
623 struct sched_entity *curr, unsigned long granularity)
624{
625 s64 __delta = curr->fair_key - se->fair_key;
626
627 /*
628 * Take scheduling granularity into account - do not
629 * preempt the current task unless the best task has
630 * a larger than sched_granularity fairness advantage:
631 */
632 if (__delta > niced_granularity(curr, granularity))
633 resched_task(rq_of(cfs_rq)->curr);
634}
635
636static inline void
Ingo Molnar8494f412007-08-09 11:16:48 +0200637set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200638{
639 /*
640 * Any task has to be enqueued before it get to execute on
641 * a CPU. So account for the time it spent waiting on the
642 * runqueue. (note, here we rely on pick_next_task() having
643 * done a put_prev_task_fair() shortly before this, which
644 * updated rq->fair_clock - used by update_stats_wait_end())
645 */
Ingo Molnar9ef0a962007-08-09 11:16:47 +0200646 update_stats_wait_end(cfs_rq, se);
Ingo Molnar79303e92007-08-09 11:16:47 +0200647 update_stats_curr_start(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200648 set_cfs_rq_curr(cfs_rq, se);
649}
650
Ingo Molnar9948f4b2007-08-09 11:16:48 +0200651static struct sched_entity *pick_next_entity(struct cfs_rq *cfs_rq)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200652{
653 struct sched_entity *se = __pick_next_entity(cfs_rq);
654
Ingo Molnar8494f412007-08-09 11:16:48 +0200655 set_next_entity(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200656
657 return se;
658}
659
Ingo Molnarab6cde22007-08-09 11:16:48 +0200660static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200661{
662 /*
663 * If still on the runqueue then deactivate_task()
664 * was not called and update_curr() has to be done:
665 */
666 if (prev->on_rq)
Ingo Molnarb7cc0892007-08-09 11:16:47 +0200667 update_curr(cfs_rq);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200668
Ingo Molnarc7e9b5b2007-08-09 11:16:48 +0200669 update_stats_curr_end(cfs_rq, prev);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200670
671 if (prev->on_rq)
Ingo Molnar5870db52007-08-09 11:16:47 +0200672 update_stats_wait_start(cfs_rq, prev);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200673 set_cfs_rq_curr(cfs_rq, NULL);
674}
675
676static void entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
677{
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200678 struct sched_entity *next;
Ingo Molnarc1b3da32007-08-09 11:16:47 +0200679
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200680 /*
681 * Dequeue and enqueue the task to update its
682 * position within the tree:
683 */
Ingo Molnar525c2712007-08-09 11:16:48 +0200684 dequeue_entity(cfs_rq, curr, 0);
Ingo Molnar668031c2007-08-09 11:16:48 +0200685 enqueue_entity(cfs_rq, curr, 0);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200686
687 /*
688 * Reschedule if another task tops the current one.
689 */
690 next = __pick_next_entity(cfs_rq);
691 if (next == curr)
692 return;
693
694 __check_preempt_curr_fair(cfs_rq, next, curr, sysctl_sched_granularity);
695}
696
697/**************************************************
698 * CFS operations on tasks:
699 */
700
701#ifdef CONFIG_FAIR_GROUP_SCHED
702
703/* Walk up scheduling entities hierarchy */
704#define for_each_sched_entity(se) \
705 for (; se; se = se->parent)
706
707static inline struct cfs_rq *task_cfs_rq(struct task_struct *p)
708{
709 return p->se.cfs_rq;
710}
711
712/* runqueue on which this entity is (to be) queued */
713static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se)
714{
715 return se->cfs_rq;
716}
717
718/* runqueue "owned" by this group */
719static inline struct cfs_rq *group_cfs_rq(struct sched_entity *grp)
720{
721 return grp->my_q;
722}
723
724/* Given a group's cfs_rq on one cpu, return its corresponding cfs_rq on
725 * another cpu ('this_cpu')
726 */
727static inline struct cfs_rq *cpu_cfs_rq(struct cfs_rq *cfs_rq, int this_cpu)
728{
729 /* A later patch will take group into account */
730 return &cpu_rq(this_cpu)->cfs;
731}
732
733/* Iterate thr' all leaf cfs_rq's on a runqueue */
734#define for_each_leaf_cfs_rq(rq, cfs_rq) \
735 list_for_each_entry(cfs_rq, &rq->leaf_cfs_rq_list, leaf_cfs_rq_list)
736
737/* Do the two (enqueued) tasks belong to the same group ? */
738static inline int is_same_group(struct task_struct *curr, struct task_struct *p)
739{
740 if (curr->se.cfs_rq == p->se.cfs_rq)
741 return 1;
742
743 return 0;
744}
745
746#else /* CONFIG_FAIR_GROUP_SCHED */
747
748#define for_each_sched_entity(se) \
749 for (; se; se = NULL)
750
751static inline struct cfs_rq *task_cfs_rq(struct task_struct *p)
752{
753 return &task_rq(p)->cfs;
754}
755
756static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se)
757{
758 struct task_struct *p = task_of(se);
759 struct rq *rq = task_rq(p);
760
761 return &rq->cfs;
762}
763
764/* runqueue "owned" by this group */
765static inline struct cfs_rq *group_cfs_rq(struct sched_entity *grp)
766{
767 return NULL;
768}
769
770static inline struct cfs_rq *cpu_cfs_rq(struct cfs_rq *cfs_rq, int this_cpu)
771{
772 return &cpu_rq(this_cpu)->cfs;
773}
774
775#define for_each_leaf_cfs_rq(rq, cfs_rq) \
776 for (cfs_rq = &rq->cfs; cfs_rq; cfs_rq = NULL)
777
778static inline int is_same_group(struct task_struct *curr, struct task_struct *p)
779{
780 return 1;
781}
782
783#endif /* CONFIG_FAIR_GROUP_SCHED */
784
785/*
786 * The enqueue_task method is called before nr_running is
787 * increased. Here we update the fair scheduling stats and
788 * then put the task into the rbtree:
789 */
Ingo Molnarfd390f62007-08-09 11:16:48 +0200790static void enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200791{
792 struct cfs_rq *cfs_rq;
793 struct sched_entity *se = &p->se;
794
795 for_each_sched_entity(se) {
796 if (se->on_rq)
797 break;
798 cfs_rq = cfs_rq_of(se);
Ingo Molnar668031c2007-08-09 11:16:48 +0200799 enqueue_entity(cfs_rq, se, wakeup);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200800 }
801}
802
803/*
804 * The dequeue_task method is called before nr_running is
805 * decreased. We remove the task from the rbtree and
806 * update the fair scheduling stats:
807 */
Ingo Molnarf02231e2007-08-09 11:16:48 +0200808static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int sleep)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200809{
810 struct cfs_rq *cfs_rq;
811 struct sched_entity *se = &p->se;
812
813 for_each_sched_entity(se) {
814 cfs_rq = cfs_rq_of(se);
Ingo Molnar525c2712007-08-09 11:16:48 +0200815 dequeue_entity(cfs_rq, se, sleep);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200816 /* Don't dequeue parent if it has other entities besides us */
817 if (cfs_rq->load.weight)
818 break;
819 }
820}
821
822/*
823 * sched_yield() support is very simple - we dequeue and enqueue
824 */
825static void yield_task_fair(struct rq *rq, struct task_struct *p)
826{
827 struct cfs_rq *cfs_rq = task_cfs_rq(p);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200828
Ingo Molnarc1b3da32007-08-09 11:16:47 +0200829 __update_rq_clock(rq);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200830 /*
831 * Dequeue and enqueue the task to update its
832 * position within the tree:
833 */
Ingo Molnar525c2712007-08-09 11:16:48 +0200834 dequeue_entity(cfs_rq, &p->se, 0);
Ingo Molnar668031c2007-08-09 11:16:48 +0200835 enqueue_entity(cfs_rq, &p->se, 0);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200836}
837
838/*
839 * Preempt the current task with a newly woken task if needed:
840 */
841static void check_preempt_curr_fair(struct rq *rq, struct task_struct *p)
842{
843 struct task_struct *curr = rq->curr;
844 struct cfs_rq *cfs_rq = task_cfs_rq(curr);
845 unsigned long gran;
846
847 if (unlikely(rt_prio(p->prio))) {
Ingo Molnara8e504d2007-08-09 11:16:47 +0200848 update_rq_clock(rq);
Ingo Molnarb7cc0892007-08-09 11:16:47 +0200849 update_curr(cfs_rq);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200850 resched_task(curr);
851 return;
852 }
853
854 gran = sysctl_sched_wakeup_granularity;
855 /*
856 * Batch tasks prefer throughput over latency:
857 */
858 if (unlikely(p->policy == SCHED_BATCH))
859 gran = sysctl_sched_batch_wakeup_granularity;
860
861 if (is_same_group(curr, p))
862 __check_preempt_curr_fair(cfs_rq, &p->se, &curr->se, gran);
863}
864
Ingo Molnarfb8d4722007-08-09 11:16:48 +0200865static struct task_struct *pick_next_task_fair(struct rq *rq)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200866{
867 struct cfs_rq *cfs_rq = &rq->cfs;
868 struct sched_entity *se;
869
870 if (unlikely(!cfs_rq->nr_running))
871 return NULL;
872
873 do {
Ingo Molnar9948f4b2007-08-09 11:16:48 +0200874 se = pick_next_entity(cfs_rq);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200875 cfs_rq = group_cfs_rq(se);
876 } while (cfs_rq);
877
878 return task_of(se);
879}
880
881/*
882 * Account for a descheduled task:
883 */
Ingo Molnar31ee5292007-08-09 11:16:49 +0200884static void put_prev_task_fair(struct rq *rq, struct task_struct *prev)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200885{
886 struct sched_entity *se = &prev->se;
887 struct cfs_rq *cfs_rq;
888
889 for_each_sched_entity(se) {
890 cfs_rq = cfs_rq_of(se);
Ingo Molnarab6cde22007-08-09 11:16:48 +0200891 put_prev_entity(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200892 }
893}
894
895/**************************************************
896 * Fair scheduling class load-balancing methods:
897 */
898
899/*
900 * Load-balancing iterator. Note: while the runqueue stays locked
901 * during the whole iteration, the current task might be
902 * dequeued so the iterator has to be dequeue-safe. Here we
903 * achieve that by always pre-iterating before returning
904 * the current task:
905 */
906static inline struct task_struct *
907__load_balance_iterator(struct cfs_rq *cfs_rq, struct rb_node *curr)
908{
909 struct task_struct *p;
910
911 if (!curr)
912 return NULL;
913
914 p = rb_entry(curr, struct task_struct, se.run_node);
915 cfs_rq->rb_load_balance_curr = rb_next(curr);
916
917 return p;
918}
919
920static struct task_struct *load_balance_start_fair(void *arg)
921{
922 struct cfs_rq *cfs_rq = arg;
923
924 return __load_balance_iterator(cfs_rq, first_fair(cfs_rq));
925}
926
927static struct task_struct *load_balance_next_fair(void *arg)
928{
929 struct cfs_rq *cfs_rq = arg;
930
931 return __load_balance_iterator(cfs_rq, cfs_rq->rb_load_balance_curr);
932}
933
Peter Williamsa4ac01c2007-08-09 11:16:46 +0200934#ifdef CONFIG_FAIR_GROUP_SCHED
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200935static int cfs_rq_best_prio(struct cfs_rq *cfs_rq)
936{
937 struct sched_entity *curr;
938 struct task_struct *p;
939
940 if (!cfs_rq->nr_running)
941 return MAX_PRIO;
942
943 curr = __pick_next_entity(cfs_rq);
944 p = task_of(curr);
945
946 return p->prio;
947}
Peter Williamsa4ac01c2007-08-09 11:16:46 +0200948#endif
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200949
Peter Williams43010652007-08-09 11:16:46 +0200950static unsigned long
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200951load_balance_fair(struct rq *this_rq, int this_cpu, struct rq *busiest,
Peter Williamsa4ac01c2007-08-09 11:16:46 +0200952 unsigned long max_nr_move, unsigned long max_load_move,
953 struct sched_domain *sd, enum cpu_idle_type idle,
954 int *all_pinned, int *this_best_prio)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200955{
956 struct cfs_rq *busy_cfs_rq;
957 unsigned long load_moved, total_nr_moved = 0, nr_moved;
958 long rem_load_move = max_load_move;
959 struct rq_iterator cfs_rq_iterator;
960
961 cfs_rq_iterator.start = load_balance_start_fair;
962 cfs_rq_iterator.next = load_balance_next_fair;
963
964 for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
Peter Williamsa4ac01c2007-08-09 11:16:46 +0200965#ifdef CONFIG_FAIR_GROUP_SCHED
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200966 struct cfs_rq *this_cfs_rq;
Ingo Molnare56f31a2007-08-10 23:05:11 +0200967 long imbalance;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200968 unsigned long maxload;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200969
970 this_cfs_rq = cpu_cfs_rq(busy_cfs_rq, this_cpu);
971
Ingo Molnare56f31a2007-08-10 23:05:11 +0200972 imbalance = busy_cfs_rq->load.weight - this_cfs_rq->load.weight;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200973 /* Don't pull if this_cfs_rq has more load than busy_cfs_rq */
974 if (imbalance <= 0)
975 continue;
976
977 /* Don't pull more than imbalance/2 */
978 imbalance /= 2;
979 maxload = min(rem_load_move, imbalance);
980
Peter Williamsa4ac01c2007-08-09 11:16:46 +0200981 *this_best_prio = cfs_rq_best_prio(this_cfs_rq);
982#else
Ingo Molnare56f31a2007-08-10 23:05:11 +0200983# define maxload rem_load_move
Peter Williamsa4ac01c2007-08-09 11:16:46 +0200984#endif
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200985 /* pass busy_cfs_rq argument into
986 * load_balance_[start|next]_fair iterators
987 */
988 cfs_rq_iterator.arg = busy_cfs_rq;
989 nr_moved = balance_tasks(this_rq, this_cpu, busiest,
990 max_nr_move, maxload, sd, idle, all_pinned,
Peter Williamsa4ac01c2007-08-09 11:16:46 +0200991 &load_moved, this_best_prio, &cfs_rq_iterator);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +0200992
993 total_nr_moved += nr_moved;
994 max_nr_move -= nr_moved;
995 rem_load_move -= load_moved;
996
997 if (max_nr_move <= 0 || rem_load_move <= 0)
998 break;
999 }
1000
Peter Williams43010652007-08-09 11:16:46 +02001001 return max_load_move - rem_load_move;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001002}
1003
1004/*
1005 * scheduler tick hitting a task of our scheduling class:
1006 */
1007static void task_tick_fair(struct rq *rq, struct task_struct *curr)
1008{
1009 struct cfs_rq *cfs_rq;
1010 struct sched_entity *se = &curr->se;
1011
1012 for_each_sched_entity(se) {
1013 cfs_rq = cfs_rq_of(se);
1014 entity_tick(cfs_rq, se);
1015 }
1016}
1017
1018/*
1019 * Share the fairness runtime between parent and child, thus the
1020 * total amount of pressure for CPU stays equal - new tasks
1021 * get a chance to run but frequent forkers are not allowed to
1022 * monopolize the CPU. Note: the parent runqueue is locked,
1023 * the child is not running yet.
1024 */
Ingo Molnaree0827d2007-08-09 11:16:49 +02001025static void task_new_fair(struct rq *rq, struct task_struct *p)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001026{
1027 struct cfs_rq *cfs_rq = task_cfs_rq(p);
1028 struct sched_entity *se = &p->se;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001029
1030 sched_info_queued(p);
1031
Ingo Molnard2417e52007-08-09 11:16:47 +02001032 update_stats_enqueue(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001033 /*
1034 * Child runs first: we let it run before the parent
1035 * until it reschedules once. We set up the key so that
1036 * it will preempt the parent:
1037 */
1038 p->se.fair_key = current->se.fair_key -
1039 niced_granularity(&rq->curr->se, sysctl_sched_granularity) - 1;
1040 /*
1041 * The first wait is dominated by the child-runs-first logic,
1042 * so do not credit it with that waiting time yet:
1043 */
1044 if (sysctl_sched_features & SCHED_FEAT_SKIP_INITIAL)
1045 p->se.wait_start_fair = 0;
1046
1047 /*
1048 * The statistical average of wait_runtime is about
1049 * -granularity/2, so initialize the task with that:
1050 */
1051 if (sysctl_sched_features & SCHED_FEAT_START_DEBIT)
1052 p->se.wait_runtime = -(sysctl_sched_granularity / 2);
1053
1054 __enqueue_entity(cfs_rq, se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001055}
1056
1057#ifdef CONFIG_FAIR_GROUP_SCHED
1058/* Account for a task changing its policy or group.
1059 *
1060 * This routine is mostly called to set cfs_rq->curr field when a task
1061 * migrates between groups/classes.
1062 */
1063static void set_curr_task_fair(struct rq *rq)
1064{
Bruce Ashfield7c6c16f2007-08-24 20:39:10 +02001065 struct sched_entity *se = &rq->curr->se;
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001066
Ingo Molnarc3b64f12007-08-09 11:16:51 +02001067 for_each_sched_entity(se)
1068 set_next_entity(cfs_rq_of(se), se);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001069}
1070#else
1071static void set_curr_task_fair(struct rq *rq)
1072{
1073}
1074#endif
1075
1076/*
1077 * All the scheduling class methods:
1078 */
1079struct sched_class fair_sched_class __read_mostly = {
1080 .enqueue_task = enqueue_task_fair,
1081 .dequeue_task = dequeue_task_fair,
1082 .yield_task = yield_task_fair,
1083
1084 .check_preempt_curr = check_preempt_curr_fair,
1085
1086 .pick_next_task = pick_next_task_fair,
1087 .put_prev_task = put_prev_task_fair,
1088
1089 .load_balance = load_balance_fair,
1090
1091 .set_curr_task = set_curr_task_fair,
1092 .task_tick = task_tick_fair,
1093 .task_new = task_new_fair,
1094};
1095
1096#ifdef CONFIG_SCHED_DEBUG
Ingo Molnar5cef9ec2007-08-09 11:16:47 +02001097static void print_cfs_stats(struct seq_file *m, int cpu)
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001098{
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001099 struct cfs_rq *cfs_rq;
1100
Ingo Molnarc3b64f12007-08-09 11:16:51 +02001101 for_each_leaf_cfs_rq(cpu_rq(cpu), cfs_rq)
Ingo Molnar5cef9ec2007-08-09 11:16:47 +02001102 print_cfs_rq(m, cpu, cfs_rq);
Ingo Molnarbf0f6f22007-07-09 18:51:58 +02001103}
1104#endif