blob: 26ea5c8130ecec1fb8a0c8515f683dd1467c9b60 [file] [log] [blame]
Dario Faggioliaab03e02013-11-28 11:14:43 +01001/*
2 * Deadline Scheduling Class (SCHED_DEADLINE)
3 *
4 * Earliest Deadline First (EDF) + Constant Bandwidth Server (CBS).
5 *
6 * Tasks that periodically executes their instances for less than their
7 * runtime won't miss any of their deadlines.
8 * Tasks that are not periodic or sporadic or that tries to execute more
9 * than their reserved bandwidth will be slowed down (and may potentially
10 * miss some of their deadlines), and won't affect any other task.
11 *
12 * Copyright (C) 2012 Dario Faggioli <raistlin@linux.it>,
Juri Lelli1baca4c2013-11-07 14:43:38 +010013 * Juri Lelli <juri.lelli@gmail.com>,
Dario Faggioliaab03e02013-11-28 11:14:43 +010014 * Michael Trimarchi <michael@amarulasolutions.com>,
15 * Fabio Checconi <fchecconi@gmail.com>
16 */
17#include "sched.h"
Joonwoo Parkf7d6cd42017-01-17 15:19:43 -080018#include "walt.h"
Dario Faggioliaab03e02013-11-28 11:14:43 +010019
Juri Lelli6bfd6d72013-11-07 14:43:47 +010020#include <linux/slab.h>
21
Dario Faggioli332ac172013-11-07 14:43:45 +010022struct dl_bandwidth def_dl_bandwidth;
23
Dario Faggioliaab03e02013-11-28 11:14:43 +010024static inline struct task_struct *dl_task_of(struct sched_dl_entity *dl_se)
25{
26 return container_of(dl_se, struct task_struct, dl);
27}
28
29static inline struct rq *rq_of_dl_rq(struct dl_rq *dl_rq)
30{
31 return container_of(dl_rq, struct rq, dl);
32}
33
34static inline struct dl_rq *dl_rq_of_se(struct sched_dl_entity *dl_se)
35{
36 struct task_struct *p = dl_task_of(dl_se);
37 struct rq *rq = task_rq(p);
38
39 return &rq->dl;
40}
41
42static inline int on_dl_rq(struct sched_dl_entity *dl_se)
43{
44 return !RB_EMPTY_NODE(&dl_se->rb_node);
45}
46
47static inline int is_leftmost(struct task_struct *p, struct dl_rq *dl_rq)
48{
49 struct sched_dl_entity *dl_se = &p->dl;
50
51 return dl_rq->rb_leftmost == &dl_se->rb_node;
52}
53
Dario Faggioli332ac172013-11-07 14:43:45 +010054void init_dl_bandwidth(struct dl_bandwidth *dl_b, u64 period, u64 runtime)
55{
56 raw_spin_lock_init(&dl_b->dl_runtime_lock);
57 dl_b->dl_period = period;
58 dl_b->dl_runtime = runtime;
59}
60
Dario Faggioli332ac172013-11-07 14:43:45 +010061void init_dl_bw(struct dl_bw *dl_b)
62{
63 raw_spin_lock_init(&dl_b->lock);
64 raw_spin_lock(&def_dl_bandwidth.dl_runtime_lock);
Peter Zijlstra17248132013-12-17 12:44:49 +010065 if (global_rt_runtime() == RUNTIME_INF)
Dario Faggioli332ac172013-11-07 14:43:45 +010066 dl_b->bw = -1;
67 else
Peter Zijlstra17248132013-12-17 12:44:49 +010068 dl_b->bw = to_ratio(global_rt_period(), global_rt_runtime());
Dario Faggioli332ac172013-11-07 14:43:45 +010069 raw_spin_unlock(&def_dl_bandwidth.dl_runtime_lock);
70 dl_b->total_bw = 0;
71}
72
Abel Vesa07c54f72015-03-03 13:50:27 +020073void init_dl_rq(struct dl_rq *dl_rq)
Dario Faggioliaab03e02013-11-28 11:14:43 +010074{
75 dl_rq->rb_root = RB_ROOT;
Juri Lelli1baca4c2013-11-07 14:43:38 +010076
77#ifdef CONFIG_SMP
78 /* zero means no -deadline tasks */
79 dl_rq->earliest_dl.curr = dl_rq->earliest_dl.next = 0;
80
81 dl_rq->dl_nr_migratory = 0;
82 dl_rq->overloaded = 0;
83 dl_rq->pushable_dl_tasks_root = RB_ROOT;
Dario Faggioli332ac172013-11-07 14:43:45 +010084#else
85 init_dl_bw(&dl_rq->dl_bw);
Juri Lelli1baca4c2013-11-07 14:43:38 +010086#endif
Dario Faggioliaab03e02013-11-28 11:14:43 +010087}
88
Juri Lelli1baca4c2013-11-07 14:43:38 +010089#ifdef CONFIG_SMP
90
91static inline int dl_overloaded(struct rq *rq)
92{
93 return atomic_read(&rq->rd->dlo_count);
94}
95
96static inline void dl_set_overload(struct rq *rq)
97{
98 if (!rq->online)
99 return;
100
101 cpumask_set_cpu(rq->cpu, rq->rd->dlo_mask);
102 /*
103 * Must be visible before the overload count is
104 * set (as in sched_rt.c).
105 *
106 * Matched by the barrier in pull_dl_task().
107 */
108 smp_wmb();
109 atomic_inc(&rq->rd->dlo_count);
110}
111
112static inline void dl_clear_overload(struct rq *rq)
113{
114 if (!rq->online)
115 return;
116
117 atomic_dec(&rq->rd->dlo_count);
118 cpumask_clear_cpu(rq->cpu, rq->rd->dlo_mask);
119}
120
121static void update_dl_migration(struct dl_rq *dl_rq)
122{
Kirill Tkhai995b9ea2014-02-18 02:24:13 +0400123 if (dl_rq->dl_nr_migratory && dl_rq->dl_nr_running > 1) {
Juri Lelli1baca4c2013-11-07 14:43:38 +0100124 if (!dl_rq->overloaded) {
125 dl_set_overload(rq_of_dl_rq(dl_rq));
126 dl_rq->overloaded = 1;
127 }
128 } else if (dl_rq->overloaded) {
129 dl_clear_overload(rq_of_dl_rq(dl_rq));
130 dl_rq->overloaded = 0;
131 }
132}
133
134static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
135{
136 struct task_struct *p = dl_task_of(dl_se);
Juri Lelli1baca4c2013-11-07 14:43:38 +0100137
Thomas Gleixner50605ff2016-05-11 14:23:31 +0200138 if (tsk_nr_cpus_allowed(p) > 1)
Juri Lelli1baca4c2013-11-07 14:43:38 +0100139 dl_rq->dl_nr_migratory++;
140
141 update_dl_migration(dl_rq);
142}
143
144static void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
145{
146 struct task_struct *p = dl_task_of(dl_se);
Juri Lelli1baca4c2013-11-07 14:43:38 +0100147
Thomas Gleixner50605ff2016-05-11 14:23:31 +0200148 if (tsk_nr_cpus_allowed(p) > 1)
Juri Lelli1baca4c2013-11-07 14:43:38 +0100149 dl_rq->dl_nr_migratory--;
150
151 update_dl_migration(dl_rq);
152}
153
154/*
155 * The list of pushable -deadline task is not a plist, like in
156 * sched_rt.c, it is an rb-tree with tasks ordered by deadline.
157 */
158static void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p)
159{
160 struct dl_rq *dl_rq = &rq->dl;
161 struct rb_node **link = &dl_rq->pushable_dl_tasks_root.rb_node;
162 struct rb_node *parent = NULL;
163 struct task_struct *entry;
164 int leftmost = 1;
165
166 BUG_ON(!RB_EMPTY_NODE(&p->pushable_dl_tasks));
167
168 while (*link) {
169 parent = *link;
170 entry = rb_entry(parent, struct task_struct,
171 pushable_dl_tasks);
172 if (dl_entity_preempt(&p->dl, &entry->dl))
173 link = &parent->rb_left;
174 else {
175 link = &parent->rb_right;
176 leftmost = 0;
177 }
178 }
179
Wanpeng Li7d92de32015-12-03 17:42:10 +0800180 if (leftmost) {
Juri Lelli1baca4c2013-11-07 14:43:38 +0100181 dl_rq->pushable_dl_tasks_leftmost = &p->pushable_dl_tasks;
Wanpeng Li7d92de32015-12-03 17:42:10 +0800182 dl_rq->earliest_dl.next = p->dl.deadline;
183 }
Juri Lelli1baca4c2013-11-07 14:43:38 +0100184
185 rb_link_node(&p->pushable_dl_tasks, parent, link);
186 rb_insert_color(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
187}
188
189static void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p)
190{
191 struct dl_rq *dl_rq = &rq->dl;
192
193 if (RB_EMPTY_NODE(&p->pushable_dl_tasks))
194 return;
195
196 if (dl_rq->pushable_dl_tasks_leftmost == &p->pushable_dl_tasks) {
197 struct rb_node *next_node;
198
199 next_node = rb_next(&p->pushable_dl_tasks);
200 dl_rq->pushable_dl_tasks_leftmost = next_node;
Wanpeng Li7d92de32015-12-03 17:42:10 +0800201 if (next_node) {
202 dl_rq->earliest_dl.next = rb_entry(next_node,
203 struct task_struct, pushable_dl_tasks)->dl.deadline;
204 }
Juri Lelli1baca4c2013-11-07 14:43:38 +0100205 }
206
207 rb_erase(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
208 RB_CLEAR_NODE(&p->pushable_dl_tasks);
209}
210
211static inline int has_pushable_dl_tasks(struct rq *rq)
212{
213 return !RB_EMPTY_ROOT(&rq->dl.pushable_dl_tasks_root);
214}
215
216static int push_dl_task(struct rq *rq);
217
Peter Zijlstradc877342014-02-12 15:47:29 +0100218static inline bool need_pull_dl_task(struct rq *rq, struct task_struct *prev)
219{
220 return dl_task(prev);
221}
222
Peter Zijlstra9916e212015-06-11 14:46:43 +0200223static DEFINE_PER_CPU(struct callback_head, dl_push_head);
224static DEFINE_PER_CPU(struct callback_head, dl_pull_head);
Peter Zijlstrae3fca9e2015-06-11 14:46:37 +0200225
226static void push_dl_tasks(struct rq *);
Peter Zijlstra9916e212015-06-11 14:46:43 +0200227static void pull_dl_task(struct rq *);
Peter Zijlstrae3fca9e2015-06-11 14:46:37 +0200228
229static inline void queue_push_tasks(struct rq *rq)
Peter Zijlstradc877342014-02-12 15:47:29 +0100230{
Peter Zijlstrae3fca9e2015-06-11 14:46:37 +0200231 if (!has_pushable_dl_tasks(rq))
232 return;
233
Peter Zijlstra9916e212015-06-11 14:46:43 +0200234 queue_balance_callback(rq, &per_cpu(dl_push_head, rq->cpu), push_dl_tasks);
235}
236
237static inline void queue_pull_task(struct rq *rq)
238{
239 queue_balance_callback(rq, &per_cpu(dl_pull_head, rq->cpu), pull_dl_task);
Peter Zijlstradc877342014-02-12 15:47:29 +0100240}
241
Wanpeng Lifa9c9d12015-03-27 07:08:35 +0800242static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq);
243
Peter Zijlstraa649f232015-06-11 14:46:49 +0200244static struct rq *dl_task_offline_migration(struct rq *rq, struct task_struct *p)
Wanpeng Lifa9c9d12015-03-27 07:08:35 +0800245{
246 struct rq *later_rq = NULL;
Wanpeng Lifa9c9d12015-03-27 07:08:35 +0800247
248 later_rq = find_lock_later_rq(p, rq);
Wanpeng Lifa9c9d12015-03-27 07:08:35 +0800249 if (!later_rq) {
250 int cpu;
251
252 /*
253 * If we cannot preempt any rq, fall back to pick any
254 * online cpu.
255 */
Wanpeng Lifa9c9d12015-03-27 07:08:35 +0800256 cpu = cpumask_any_and(cpu_active_mask, tsk_cpus_allowed(p));
257 if (cpu >= nr_cpu_ids) {
258 /*
259 * Fail to find any suitable cpu.
260 * The task will never come back!
261 */
262 BUG_ON(dl_bandwidth_enabled());
263
264 /*
265 * If admission control is disabled we
266 * try a little harder to let the task
267 * run.
268 */
269 cpu = cpumask_any(cpu_active_mask);
270 }
271 later_rq = cpu_rq(cpu);
272 double_lock_balance(rq, later_rq);
273 }
274
Wanpeng Lifa9c9d12015-03-27 07:08:35 +0800275 set_task_cpu(p, later_rq->cpu);
Peter Zijlstraa649f232015-06-11 14:46:49 +0200276 double_unlock_balance(later_rq, rq);
277
278 return later_rq;
Wanpeng Lifa9c9d12015-03-27 07:08:35 +0800279}
280
Juri Lelli1baca4c2013-11-07 14:43:38 +0100281#else
282
283static inline
284void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p)
285{
286}
287
288static inline
289void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p)
290{
291}
292
293static inline
294void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
295{
296}
297
298static inline
299void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
300{
301}
302
Peter Zijlstradc877342014-02-12 15:47:29 +0100303static inline bool need_pull_dl_task(struct rq *rq, struct task_struct *prev)
304{
305 return false;
306}
307
Peter Zijlstra0ea60c22015-06-11 14:46:42 +0200308static inline void pull_dl_task(struct rq *rq)
Peter Zijlstradc877342014-02-12 15:47:29 +0100309{
Peter Zijlstradc877342014-02-12 15:47:29 +0100310}
311
Peter Zijlstrae3fca9e2015-06-11 14:46:37 +0200312static inline void queue_push_tasks(struct rq *rq)
Peter Zijlstradc877342014-02-12 15:47:29 +0100313{
314}
Peter Zijlstra9916e212015-06-11 14:46:43 +0200315
316static inline void queue_pull_task(struct rq *rq)
Juri Lelli1baca4c2013-11-07 14:43:38 +0100317{
318}
319#endif /* CONFIG_SMP */
320
Dario Faggioliaab03e02013-11-28 11:14:43 +0100321static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags);
322static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags);
323static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p,
324 int flags);
325
326/*
327 * We are being explicitly informed that a new instance is starting,
328 * and this means that:
329 * - the absolute deadline of the entity has to be placed at
330 * current time + relative deadline;
331 * - the runtime of the entity has to be set to the maximum value.
332 *
333 * The capability of specifying such event is useful whenever a -deadline
334 * entity wants to (try to!) synchronize its behaviour with the scheduler's
335 * one, and to (try to!) reconcile itself with its own scheduling
336 * parameters.
337 */
Juri Lelli98b0a852016-08-05 16:07:55 +0100338static inline void setup_new_dl_entity(struct sched_dl_entity *dl_se)
Dario Faggioliaab03e02013-11-28 11:14:43 +0100339{
340 struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
341 struct rq *rq = rq_of_dl_rq(dl_rq);
342
Juri Lelli98b0a852016-08-05 16:07:55 +0100343 WARN_ON(dl_se->dl_boosted);
Luca Abeni72f9f3f2016-03-07 12:27:04 +0100344 WARN_ON(dl_time_before(rq_clock(rq), dl_se->deadline));
345
346 /*
347 * We are racing with the deadline timer. So, do nothing because
348 * the deadline timer handler will take care of properly recharging
349 * the runtime and postponing the deadline
350 */
351 if (dl_se->dl_throttled)
352 return;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100353
354 /*
355 * We use the regular wall clock time to set deadlines in the
356 * future; in fact, we must consider execution overheads (time
357 * spent on hardirq context, etc.).
358 */
Juri Lelli98b0a852016-08-05 16:07:55 +0100359 dl_se->deadline = rq_clock(rq) + dl_se->dl_deadline;
360 dl_se->runtime = dl_se->dl_runtime;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100361}
362
363/*
364 * Pure Earliest Deadline First (EDF) scheduling does not deal with the
365 * possibility of a entity lasting more than what it declared, and thus
366 * exhausting its runtime.
367 *
368 * Here we are interested in making runtime overrun possible, but we do
369 * not want a entity which is misbehaving to affect the scheduling of all
370 * other entities.
371 * Therefore, a budgeting strategy called Constant Bandwidth Server (CBS)
372 * is used, in order to confine each entity within its own bandwidth.
373 *
374 * This function deals exactly with that, and ensures that when the runtime
375 * of a entity is replenished, its deadline is also postponed. That ensures
376 * the overrunning entity can't interfere with other entity in the system and
377 * can't make them miss their deadlines. Reasons why this kind of overruns
378 * could happen are, typically, a entity voluntarily trying to overcome its
xiaofeng.yan1b09d292014-07-07 05:59:04 +0000379 * runtime, or it just underestimated it during sched_setattr().
Dario Faggioliaab03e02013-11-28 11:14:43 +0100380 */
Dario Faggioli2d3d8912013-11-07 14:43:44 +0100381static void replenish_dl_entity(struct sched_dl_entity *dl_se,
382 struct sched_dl_entity *pi_se)
Dario Faggioliaab03e02013-11-28 11:14:43 +0100383{
384 struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
385 struct rq *rq = rq_of_dl_rq(dl_rq);
386
Dario Faggioli2d3d8912013-11-07 14:43:44 +0100387 BUG_ON(pi_se->dl_runtime <= 0);
388
389 /*
390 * This could be the case for a !-dl task that is boosted.
391 * Just go with full inherited parameters.
392 */
393 if (dl_se->dl_deadline == 0) {
394 dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline;
395 dl_se->runtime = pi_se->dl_runtime;
396 }
397
Peter Zijlstra48be3a62016-02-23 13:28:22 +0100398 if (dl_se->dl_yielded && dl_se->runtime > 0)
399 dl_se->runtime = 0;
400
Dario Faggioliaab03e02013-11-28 11:14:43 +0100401 /*
402 * We keep moving the deadline away until we get some
403 * available runtime for the entity. This ensures correct
404 * handling of situations where the runtime overrun is
405 * arbitrary large.
406 */
407 while (dl_se->runtime <= 0) {
Dario Faggioli2d3d8912013-11-07 14:43:44 +0100408 dl_se->deadline += pi_se->dl_period;
409 dl_se->runtime += pi_se->dl_runtime;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100410 }
411
412 /*
413 * At this point, the deadline really should be "in
414 * the future" with respect to rq->clock. If it's
415 * not, we are, for some reason, lagging too much!
416 * Anyway, after having warn userspace abut that,
417 * we still try to keep the things running by
418 * resetting the deadline and the budget of the
419 * entity.
420 */
421 if (dl_time_before(dl_se->deadline, rq_clock(rq))) {
Steven Rostedtc219b7d2016-02-10 12:04:22 -0500422 printk_deferred_once("sched: DL replenish lagged too much\n");
Dario Faggioli2d3d8912013-11-07 14:43:44 +0100423 dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline;
424 dl_se->runtime = pi_se->dl_runtime;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100425 }
Peter Zijlstra1019a352014-11-26 08:44:03 +0800426
427 if (dl_se->dl_yielded)
428 dl_se->dl_yielded = 0;
429 if (dl_se->dl_throttled)
430 dl_se->dl_throttled = 0;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100431}
432
433/*
434 * Here we check if --at time t-- an entity (which is probably being
435 * [re]activated or, in general, enqueued) can use its remaining runtime
436 * and its current deadline _without_ exceeding the bandwidth it is
437 * assigned (function returns true if it can't). We are in fact applying
438 * one of the CBS rules: when a task wakes up, if the residual runtime
439 * over residual deadline fits within the allocated bandwidth, then we
440 * can keep the current (absolute) deadline and residual budget without
441 * disrupting the schedulability of the system. Otherwise, we should
442 * refill the runtime and set the deadline a period in the future,
443 * because keeping the current (absolute) deadline of the task would
Dario Faggioli712e5e32014-01-27 12:20:15 +0100444 * result in breaking guarantees promised to other tasks (refer to
445 * Documentation/scheduler/sched-deadline.txt for more informations).
Dario Faggioliaab03e02013-11-28 11:14:43 +0100446 *
447 * This function returns true if:
448 *
Steven Rostedt (VMware)28714e92017-03-02 15:10:59 +0100449 * runtime / (deadline - t) > dl_runtime / dl_deadline ,
Dario Faggioliaab03e02013-11-28 11:14:43 +0100450 *
451 * IOW we can't recycle current parameters.
Harald Gustafsson755378a2013-11-07 14:43:40 +0100452 *
Steven Rostedt (VMware)28714e92017-03-02 15:10:59 +0100453 * Notice that the bandwidth check is done against the deadline. For
Harald Gustafsson755378a2013-11-07 14:43:40 +0100454 * task with deadline equal to period this is the same of using
Steven Rostedt (VMware)28714e92017-03-02 15:10:59 +0100455 * dl_period instead of dl_deadline in the equation above.
Dario Faggioliaab03e02013-11-28 11:14:43 +0100456 */
Dario Faggioli2d3d8912013-11-07 14:43:44 +0100457static bool dl_entity_overflow(struct sched_dl_entity *dl_se,
458 struct sched_dl_entity *pi_se, u64 t)
Dario Faggioliaab03e02013-11-28 11:14:43 +0100459{
460 u64 left, right;
461
462 /*
463 * left and right are the two sides of the equation above,
464 * after a bit of shuffling to use multiplications instead
465 * of divisions.
466 *
467 * Note that none of the time values involved in the two
468 * multiplications are absolute: dl_deadline and dl_runtime
469 * are the relative deadline and the maximum runtime of each
470 * instance, runtime is the runtime left for the last instance
471 * and (deadline - t), since t is rq->clock, is the time left
472 * to the (absolute) deadline. Even if overflowing the u64 type
473 * is very unlikely to occur in both cases, here we scale down
474 * as we want to avoid that risk at all. Scaling down by 10
475 * means that we reduce granularity to 1us. We are fine with it,
476 * since this is only a true/false check and, anyway, thinking
477 * of anything below microseconds resolution is actually fiction
478 * (but still we want to give the user that illusion >;).
479 */
Steven Rostedt (VMware)28714e92017-03-02 15:10:59 +0100480 left = (pi_se->dl_deadline >> DL_SCALE) * (dl_se->runtime >> DL_SCALE);
Dario Faggioli332ac172013-11-07 14:43:45 +0100481 right = ((dl_se->deadline - t) >> DL_SCALE) *
482 (pi_se->dl_runtime >> DL_SCALE);
Dario Faggioliaab03e02013-11-28 11:14:43 +0100483
484 return dl_time_before(right, left);
485}
486
487/*
Daniel Bristot de Oliveira0559ea32017-05-29 16:24:03 +0200488 * Revised wakeup rule [1]: For self-suspending tasks, rather then
489 * re-initializing task's runtime and deadline, the revised wakeup
490 * rule adjusts the task's runtime to avoid the task to overrun its
491 * density.
Dario Faggioliaab03e02013-11-28 11:14:43 +0100492 *
Daniel Bristot de Oliveira0559ea32017-05-29 16:24:03 +0200493 * Reasoning: a task may overrun the density if:
494 * runtime / (deadline - t) > dl_runtime / dl_deadline
495 *
496 * Therefore, runtime can be adjusted to:
497 * runtime = (dl_runtime / dl_deadline) * (deadline - t)
498 *
499 * In such way that runtime will be equal to the maximum density
500 * the task can use without breaking any rule.
501 *
502 * [1] Luca Abeni, Giuseppe Lipari, and Juri Lelli. 2015. Constant
503 * bandwidth server revisited. SIGBED Rev. 11, 4 (January 2015), 19-24.
504 */
505static void
506update_dl_revised_wakeup(struct sched_dl_entity *dl_se, struct rq *rq)
507{
508 u64 laxity = dl_se->deadline - rq_clock(rq);
509
510 /*
511 * If the task has deadline < period, and the deadline is in the past,
512 * it should already be throttled before this check.
513 *
514 * See update_dl_entity() comments for further details.
515 */
516 WARN_ON(dl_time_before(dl_se->deadline, rq_clock(rq)));
517
518 dl_se->runtime = (dl_se->dl_density * laxity) >> 20;
519}
520
521/*
522 * Regarding the deadline, a task with implicit deadline has a relative
523 * deadline == relative period. A task with constrained deadline has a
524 * relative deadline <= relative period.
525 *
526 * We support constrained deadline tasks. However, there are some restrictions
527 * applied only for tasks which do not have an implicit deadline. See
528 * update_dl_entity() to know more about such restrictions.
529 *
530 * The dl_is_implicit() returns true if the task has an implicit deadline.
531 */
532static inline bool dl_is_implicit(struct sched_dl_entity *dl_se)
533{
534 return dl_se->dl_deadline == dl_se->dl_period;
535}
536
537/*
538 * When a deadline entity is placed in the runqueue, its runtime and deadline
539 * might need to be updated. This is done by a CBS wake up rule. There are two
540 * different rules: 1) the original CBS; and 2) the Revisited CBS.
541 *
542 * When the task is starting a new period, the Original CBS is used. In this
543 * case, the runtime is replenished and a new absolute deadline is set.
544 *
545 * When a task is queued before the begin of the next period, using the
546 * remaining runtime and deadline could make the entity to overflow, see
547 * dl_entity_overflow() to find more about runtime overflow. When such case
548 * is detected, the runtime and deadline need to be updated.
549 *
550 * If the task has an implicit deadline, i.e., deadline == period, the Original
551 * CBS is applied. the runtime is replenished and a new absolute deadline is
552 * set, as in the previous cases.
553 *
554 * However, the Original CBS does not work properly for tasks with
555 * deadline < period, which are said to have a constrained deadline. By
556 * applying the Original CBS, a constrained deadline task would be able to run
557 * runtime/deadline in a period. With deadline < period, the task would
558 * overrun the runtime/period allowed bandwidth, breaking the admission test.
559 *
560 * In order to prevent this misbehave, the Revisited CBS is used for
561 * constrained deadline tasks when a runtime overflow is detected. In the
562 * Revisited CBS, rather than replenishing & setting a new absolute deadline,
563 * the remaining runtime of the task is reduced to avoid runtime overflow.
564 * Please refer to the comments update_dl_revised_wakeup() function to find
565 * more about the Revised CBS rule.
Dario Faggioliaab03e02013-11-28 11:14:43 +0100566 */
Dario Faggioli2d3d8912013-11-07 14:43:44 +0100567static void update_dl_entity(struct sched_dl_entity *dl_se,
568 struct sched_dl_entity *pi_se)
Dario Faggioliaab03e02013-11-28 11:14:43 +0100569{
570 struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
571 struct rq *rq = rq_of_dl_rq(dl_rq);
572
Dario Faggioliaab03e02013-11-28 11:14:43 +0100573 if (dl_time_before(dl_se->deadline, rq_clock(rq)) ||
Dario Faggioli2d3d8912013-11-07 14:43:44 +0100574 dl_entity_overflow(dl_se, pi_se, rq_clock(rq))) {
Daniel Bristot de Oliveira0559ea32017-05-29 16:24:03 +0200575
576 if (unlikely(!dl_is_implicit(dl_se) &&
577 !dl_time_before(dl_se->deadline, rq_clock(rq)) &&
578 !dl_se->dl_boosted)){
579 update_dl_revised_wakeup(dl_se, rq);
580 return;
581 }
582
Dario Faggioli2d3d8912013-11-07 14:43:44 +0100583 dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline;
584 dl_se->runtime = pi_se->dl_runtime;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100585 }
586}
587
Daniel Bristot de Oliveira9cc56a02017-03-02 15:10:57 +0100588static inline u64 dl_next_period(struct sched_dl_entity *dl_se)
589{
590 return dl_se->deadline - dl_se->dl_deadline + dl_se->dl_period;
591}
592
Dario Faggioliaab03e02013-11-28 11:14:43 +0100593/*
594 * If the entity depleted all its runtime, and if we want it to sleep
595 * while waiting for some new execution time to become available, we
Daniel Bristot de Oliveira9cc56a02017-03-02 15:10:57 +0100596 * set the bandwidth replenishment timer to the replenishment instant
Dario Faggioliaab03e02013-11-28 11:14:43 +0100597 * and try to activate it.
598 *
599 * Notice that it is important for the caller to know if the timer
600 * actually started or not (i.e., the replenishment instant is in
601 * the future or in the past).
602 */
Peter Zijlstraa649f232015-06-11 14:46:49 +0200603static int start_dl_timer(struct task_struct *p)
Dario Faggioliaab03e02013-11-28 11:14:43 +0100604{
Peter Zijlstraa649f232015-06-11 14:46:49 +0200605 struct sched_dl_entity *dl_se = &p->dl;
606 struct hrtimer *timer = &dl_se->dl_timer;
607 struct rq *rq = task_rq(p);
Dario Faggioliaab03e02013-11-28 11:14:43 +0100608 ktime_t now, act;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100609 s64 delta;
610
Peter Zijlstraa649f232015-06-11 14:46:49 +0200611 lockdep_assert_held(&rq->lock);
612
Dario Faggioliaab03e02013-11-28 11:14:43 +0100613 /*
614 * We want the timer to fire at the deadline, but considering
615 * that it is actually coming from rq->clock and not from
616 * hrtimer's time base reading.
617 */
Daniel Bristot de Oliveira9cc56a02017-03-02 15:10:57 +0100618 act = ns_to_ktime(dl_next_period(dl_se));
Peter Zijlstraa649f232015-06-11 14:46:49 +0200619 now = hrtimer_cb_get_time(timer);
Dario Faggioliaab03e02013-11-28 11:14:43 +0100620 delta = ktime_to_ns(now) - rq_clock(rq);
621 act = ktime_add_ns(act, delta);
622
623 /*
624 * If the expiry time already passed, e.g., because the value
625 * chosen as the deadline is too small, don't even try to
626 * start the timer in the past!
627 */
628 if (ktime_us_delta(act, now) < 0)
629 return 0;
630
Peter Zijlstraa649f232015-06-11 14:46:49 +0200631 /*
632 * !enqueued will guarantee another callback; even if one is already in
633 * progress. This ensures a balanced {get,put}_task_struct().
634 *
635 * The race against __run_timer() clearing the enqueued state is
636 * harmless because we're holding task_rq()->lock, therefore the timer
637 * expiring after we've done the check will wait on its task_rq_lock()
638 * and observe our state.
639 */
640 if (!hrtimer_is_queued(timer)) {
641 get_task_struct(p);
642 hrtimer_start(timer, act, HRTIMER_MODE_ABS);
643 }
Dario Faggioliaab03e02013-11-28 11:14:43 +0100644
Thomas Gleixnercc9684d2015-04-14 21:09:06 +0000645 return 1;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100646}
647
648/*
649 * This is the bandwidth enforcement timer callback. If here, we know
650 * a task is not on its dl_rq, since the fact that the timer was running
651 * means the task is throttled and needs a runtime replenishment.
652 *
653 * However, what we actually do depends on the fact the task is active,
654 * (it is on its rq) or has been removed from there by a call to
655 * dequeue_task_dl(). In the former case we must issue the runtime
656 * replenishment and add the task back to the dl_rq; in the latter, we just
657 * do nothing but clearing dl_throttled, so that runtime and deadline
658 * updating (and the queueing back to dl_rq) will be done by the
659 * next call to enqueue_task_dl().
660 */
661static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
662{
663 struct sched_dl_entity *dl_se = container_of(timer,
664 struct sched_dl_entity,
665 dl_timer);
666 struct task_struct *p = dl_task_of(dl_se);
Peter Zijlstraeb580752015-07-31 21:28:18 +0200667 struct rq_flags rf;
Kirill Tkhai0f397f22014-05-20 13:33:42 +0400668 struct rq *rq;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100669
Peter Zijlstraeb580752015-07-31 21:28:18 +0200670 rq = task_rq_lock(p, &rf);
Kirill Tkhai0f397f22014-05-20 13:33:42 +0400671
Dario Faggioliaab03e02013-11-28 11:14:43 +0100672 /*
Peter Zijlstraa649f232015-06-11 14:46:49 +0200673 * The task might have changed its scheduling policy to something
674 * different than SCHED_DEADLINE (through switched_fromd_dl()).
Dario Faggioliaab03e02013-11-28 11:14:43 +0100675 */
Peter Zijlstraa649f232015-06-11 14:46:49 +0200676 if (!dl_task(p)) {
677 __dl_clear_params(p);
678 goto unlock;
679 }
680
681 /*
Peter Zijlstraa649f232015-06-11 14:46:49 +0200682 * The task might have been boosted by someone else and might be in the
683 * boosting/deboosting path, its not throttled.
684 */
685 if (dl_se->dl_boosted)
686 goto unlock;
687
688 /*
689 * Spurious timer due to start_dl_timer() race; or we already received
690 * a replenishment from rt_mutex_setprio().
691 */
692 if (!dl_se->dl_throttled)
Dario Faggioliaab03e02013-11-28 11:14:43 +0100693 goto unlock;
694
695 sched_clock_tick();
696 update_rq_clock(rq);
Kirill Tkhaia79ec892015-02-16 15:38:34 +0300697
698 /*
699 * If the throttle happened during sched-out; like:
700 *
701 * schedule()
702 * deactivate_task()
703 * dequeue_task_dl()
704 * update_curr_dl()
705 * start_dl_timer()
706 * __dequeue_task_dl()
707 * prev->on_rq = 0;
708 *
709 * We can be both throttled and !queued. Replenish the counter
710 * but do not enqueue -- wait for our wakeup to do that.
711 */
712 if (!task_on_rq_queued(p)) {
713 replenish_dl_entity(dl_se, dl_se);
714 goto unlock;
715 }
716
Wanpeng Li61c7aca2016-08-31 18:27:44 +0800717#ifdef CONFIG_SMP
718 if (unlikely(!rq->online)) {
719 /*
720 * If the runqueue is no longer available, migrate the
721 * task elsewhere. This necessarily changes rq.
722 */
723 lockdep_unpin_lock(&rq->lock, rf.cookie);
724 rq = dl_task_offline_migration(rq, p);
725 rf.cookie = lockdep_pin_lock(&rq->lock);
Wanpeng Li0a4d4da2017-03-06 21:51:28 -0800726 update_rq_clock(rq);
Wanpeng Li61c7aca2016-08-31 18:27:44 +0800727
728 /*
729 * Now that the task has been migrated to the new RQ and we
730 * have that locked, proceed as normal and enqueue the task
731 * there.
732 */
733 }
734#endif
735
Peter Zijlstra1019a352014-11-26 08:44:03 +0800736 enqueue_task_dl(rq, p, ENQUEUE_REPLENISH);
737 if (dl_task(rq->curr))
738 check_preempt_curr_dl(rq, p, 0);
739 else
740 resched_curr(rq);
Peter Zijlstraa649f232015-06-11 14:46:49 +0200741
Juri Lelli1baca4c2013-11-07 14:43:38 +0100742#ifdef CONFIG_SMP
Peter Zijlstra1019a352014-11-26 08:44:03 +0800743 /*
Peter Zijlstraa649f232015-06-11 14:46:49 +0200744 * Queueing this task back might have overloaded rq, check if we need
745 * to kick someone away.
Peter Zijlstra1019a352014-11-26 08:44:03 +0800746 */
Peter Zijlstra0aaafaa2015-10-23 11:50:08 +0200747 if (has_pushable_dl_tasks(rq)) {
748 /*
749 * Nothing relies on rq->lock after this, so its safe to drop
750 * rq->lock.
751 */
Matt Fleming5a91d732016-09-21 14:38:10 +0100752 rq_unpin_lock(rq, &rf);
Peter Zijlstra1019a352014-11-26 08:44:03 +0800753 push_dl_task(rq);
Matt Fleming5a91d732016-09-21 14:38:10 +0100754 rq_repin_lock(rq, &rf);
Peter Zijlstra0aaafaa2015-10-23 11:50:08 +0200755 }
Juri Lelli1baca4c2013-11-07 14:43:38 +0100756#endif
Peter Zijlstraa649f232015-06-11 14:46:49 +0200757
Dario Faggioliaab03e02013-11-28 11:14:43 +0100758unlock:
Peter Zijlstraeb580752015-07-31 21:28:18 +0200759 task_rq_unlock(rq, p, &rf);
Dario Faggioliaab03e02013-11-28 11:14:43 +0100760
Peter Zijlstraa649f232015-06-11 14:46:49 +0200761 /*
762 * This can free the task_struct, including this hrtimer, do not touch
763 * anything related to that after this.
764 */
765 put_task_struct(p);
766
Dario Faggioliaab03e02013-11-28 11:14:43 +0100767 return HRTIMER_NORESTART;
768}
769
770void init_dl_task_timer(struct sched_dl_entity *dl_se)
771{
772 struct hrtimer *timer = &dl_se->dl_timer;
773
Dario Faggioliaab03e02013-11-28 11:14:43 +0100774 hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
775 timer->function = dl_task_timer;
776}
777
Daniel Bristot de Oliveiraa2e29112017-03-02 15:10:58 +0100778/*
779 * During the activation, CBS checks if it can reuse the current task's
780 * runtime and period. If the deadline of the task is in the past, CBS
781 * cannot use the runtime, and so it replenishes the task. This rule
782 * works fine for implicit deadline tasks (deadline == period), and the
783 * CBS was designed for implicit deadline tasks. However, a task with
784 * constrained deadline (deadine < period) might be awakened after the
785 * deadline, but before the next period. In this case, replenishing the
786 * task would allow it to run for runtime / deadline. As in this case
787 * deadline < period, CBS enables a task to run for more than the
788 * runtime / period. In a very loaded system, this can cause a domino
789 * effect, making other tasks miss their deadlines.
790 *
791 * To avoid this problem, in the activation of a constrained deadline
792 * task after the deadline but before the next period, throttle the
793 * task and set the replenishing timer to the begin of the next period,
794 * unless it is boosted.
795 */
796static inline void dl_check_constrained_dl(struct sched_dl_entity *dl_se)
797{
798 struct task_struct *p = dl_task_of(dl_se);
799 struct rq *rq = rq_of_dl_rq(dl_rq_of_se(dl_se));
800
801 if (dl_time_before(dl_se->deadline, rq_clock(rq)) &&
802 dl_time_before(rq_clock(rq), dl_next_period(dl_se))) {
803 if (unlikely(dl_se->dl_boosted || !start_dl_timer(p)))
804 return;
805 dl_se->dl_throttled = 1;
Xunlei Pang1ad4f282017-05-10 21:03:37 +0800806 if (dl_se->runtime > 0)
807 dl_se->runtime = 0;
Daniel Bristot de Oliveiraa2e29112017-03-02 15:10:58 +0100808 }
809}
810
Dario Faggioliaab03e02013-11-28 11:14:43 +0100811static
Zhiqiang Zhang6fab5412015-06-15 11:15:20 +0800812int dl_runtime_exceeded(struct sched_dl_entity *dl_se)
Dario Faggioliaab03e02013-11-28 11:14:43 +0100813{
Luca Abeni269ad802014-12-17 11:50:32 +0100814 return (dl_se->runtime <= 0);
Dario Faggioliaab03e02013-11-28 11:14:43 +0100815}
816
Juri Lellifaa59932014-02-21 11:37:15 +0100817extern bool sched_rt_bandwidth_account(struct rt_rq *rt_rq);
818
Dario Faggioliaab03e02013-11-28 11:14:43 +0100819/*
820 * Update the current task's runtime statistics (provided it is still
821 * a -deadline task and has not been removed from the dl_rq).
822 */
823static void update_curr_dl(struct rq *rq)
824{
825 struct task_struct *curr = rq->curr;
826 struct sched_dl_entity *dl_se = &curr->dl;
827 u64 delta_exec;
828
829 if (!dl_task(curr) || !on_dl_rq(dl_se))
830 return;
831
832 /*
833 * Consumed budget is computed considering the time as
834 * observed by schedulable tasks (excluding time spent
835 * in hardirq context, etc.). Deadlines are instead
836 * computed using hard walltime. This seems to be the more
837 * natural solution, but the full ramifications of this
838 * approach need further study.
839 */
840 delta_exec = rq_clock_task(rq) - curr->se.exec_start;
Peter Zijlstra48be3a62016-02-23 13:28:22 +0100841 if (unlikely((s64)delta_exec <= 0)) {
842 if (unlikely(dl_se->dl_yielded))
843 goto throttle;
Kirill Tkhai734ff2a2014-03-04 19:25:46 +0400844 return;
Peter Zijlstra48be3a62016-02-23 13:28:22 +0100845 }
Dario Faggioliaab03e02013-11-28 11:14:43 +0100846
Rafael J. Wysocki58919e82016-08-16 22:14:55 +0200847 /* kick cpufreq (see the comment in kernel/sched/sched.h). */
Rafael J. Wysocki12bde332016-08-10 03:11:17 +0200848 cpufreq_update_this_cpu(rq, SCHED_CPUFREQ_DL);
Wanpeng Li594dd292016-04-22 17:07:24 +0800849
Dario Faggioliaab03e02013-11-28 11:14:43 +0100850 schedstat_set(curr->se.statistics.exec_max,
851 max(curr->se.statistics.exec_max, delta_exec));
852
853 curr->se.sum_exec_runtime += delta_exec;
854 account_group_exec_runtime(curr, delta_exec);
855
856 curr->se.exec_start = rq_clock_task(rq);
857 cpuacct_charge(curr, delta_exec);
858
Dario Faggioli239be4a2013-11-07 14:43:39 +0100859 sched_rt_avg_update(rq, delta_exec);
860
Peter Zijlstra48be3a62016-02-23 13:28:22 +0100861 dl_se->runtime -= delta_exec;
862
863throttle:
864 if (dl_runtime_exceeded(dl_se) || dl_se->dl_yielded) {
Peter Zijlstra1019a352014-11-26 08:44:03 +0800865 dl_se->dl_throttled = 1;
Dario Faggioliaab03e02013-11-28 11:14:43 +0100866 __dequeue_task_dl(rq, curr, 0);
Peter Zijlstraa649f232015-06-11 14:46:49 +0200867 if (unlikely(dl_se->dl_boosted || !start_dl_timer(curr)))
Dario Faggioliaab03e02013-11-28 11:14:43 +0100868 enqueue_task_dl(rq, curr, ENQUEUE_REPLENISH);
869
870 if (!is_leftmost(curr, &rq->dl))
Kirill Tkhai88751252014-06-29 00:03:57 +0400871 resched_curr(rq);
Dario Faggioliaab03e02013-11-28 11:14:43 +0100872 }
Peter Zijlstra17248132013-12-17 12:44:49 +0100873
874 /*
875 * Because -- for now -- we share the rt bandwidth, we need to
876 * account our runtime there too, otherwise actual rt tasks
877 * would be able to exceed the shared quota.
878 *
879 * Account to the root rt group for now.
880 *
881 * The solution we're working towards is having the RT groups scheduled
882 * using deadline servers -- however there's a few nasties to figure
883 * out before that can happen.
884 */
885 if (rt_bandwidth_enabled()) {
886 struct rt_rq *rt_rq = &rq->rt;
887
888 raw_spin_lock(&rt_rq->rt_runtime_lock);
Peter Zijlstra17248132013-12-17 12:44:49 +0100889 /*
890 * We'll let actual RT tasks worry about the overflow here, we
Juri Lellifaa59932014-02-21 11:37:15 +0100891 * have our own CBS to keep us inline; only account when RT
892 * bandwidth is relevant.
Peter Zijlstra17248132013-12-17 12:44:49 +0100893 */
Juri Lellifaa59932014-02-21 11:37:15 +0100894 if (sched_rt_bandwidth_account(rt_rq))
895 rt_rq->rt_time += delta_exec;
Peter Zijlstra17248132013-12-17 12:44:49 +0100896 raw_spin_unlock(&rt_rq->rt_runtime_lock);
897 }
Dario Faggioliaab03e02013-11-28 11:14:43 +0100898}
899
Juri Lelli1baca4c2013-11-07 14:43:38 +0100900#ifdef CONFIG_SMP
901
Juri Lelli1baca4c2013-11-07 14:43:38 +0100902static void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline)
903{
904 struct rq *rq = rq_of_dl_rq(dl_rq);
905
906 if (dl_rq->earliest_dl.curr == 0 ||
907 dl_time_before(deadline, dl_rq->earliest_dl.curr)) {
Juri Lelli1baca4c2013-11-07 14:43:38 +0100908 dl_rq->earliest_dl.curr = deadline;
Tommaso Cucinottad8206bb2016-08-14 16:27:08 +0200909 cpudl_set(&rq->rd->cpudl, rq->cpu, deadline);
Juri Lelli1baca4c2013-11-07 14:43:38 +0100910 }
911}
912
913static void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline)
914{
915 struct rq *rq = rq_of_dl_rq(dl_rq);
916
917 /*
918 * Since we may have removed our earliest (and/or next earliest)
919 * task we must recompute them.
920 */
921 if (!dl_rq->dl_nr_running) {
922 dl_rq->earliest_dl.curr = 0;
923 dl_rq->earliest_dl.next = 0;
Tommaso Cucinottad8206bb2016-08-14 16:27:08 +0200924 cpudl_clear(&rq->rd->cpudl, rq->cpu);
Juri Lelli1baca4c2013-11-07 14:43:38 +0100925 } else {
926 struct rb_node *leftmost = dl_rq->rb_leftmost;
927 struct sched_dl_entity *entry;
928
929 entry = rb_entry(leftmost, struct sched_dl_entity, rb_node);
930 dl_rq->earliest_dl.curr = entry->deadline;
Tommaso Cucinottad8206bb2016-08-14 16:27:08 +0200931 cpudl_set(&rq->rd->cpudl, rq->cpu, entry->deadline);
Juri Lelli1baca4c2013-11-07 14:43:38 +0100932 }
933}
934
935#else
936
937static inline void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {}
938static inline void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {}
939
940#endif /* CONFIG_SMP */
941
942static inline
943void inc_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
944{
945 int prio = dl_task_of(dl_se)->prio;
946 u64 deadline = dl_se->deadline;
947
948 WARN_ON(!dl_prio(prio));
949 dl_rq->dl_nr_running++;
Kirill Tkhai72465442014-05-09 03:00:14 +0400950 add_nr_running(rq_of_dl_rq(dl_rq), 1);
Pavankumar Kondetid3370502017-07-20 11:47:13 +0530951 walt_inc_cumulative_runnable_avg(rq_of_dl_rq(dl_rq), dl_task_of(dl_se));
Juri Lelli1baca4c2013-11-07 14:43:38 +0100952
953 inc_dl_deadline(dl_rq, deadline);
954 inc_dl_migration(dl_se, dl_rq);
955}
956
957static inline
958void dec_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
959{
960 int prio = dl_task_of(dl_se)->prio;
961
962 WARN_ON(!dl_prio(prio));
963 WARN_ON(!dl_rq->dl_nr_running);
964 dl_rq->dl_nr_running--;
Kirill Tkhai72465442014-05-09 03:00:14 +0400965 sub_nr_running(rq_of_dl_rq(dl_rq), 1);
Pavankumar Kondetid3370502017-07-20 11:47:13 +0530966 walt_dec_cumulative_runnable_avg(rq_of_dl_rq(dl_rq), dl_task_of(dl_se));
Juri Lelli1baca4c2013-11-07 14:43:38 +0100967
968 dec_dl_deadline(dl_rq, dl_se->deadline);
969 dec_dl_migration(dl_se, dl_rq);
970}
971
Dario Faggioliaab03e02013-11-28 11:14:43 +0100972static void __enqueue_dl_entity(struct sched_dl_entity *dl_se)
973{
974 struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
975 struct rb_node **link = &dl_rq->rb_root.rb_node;
976 struct rb_node *parent = NULL;
977 struct sched_dl_entity *entry;
978 int leftmost = 1;
979
980 BUG_ON(!RB_EMPTY_NODE(&dl_se->rb_node));
981
982 while (*link) {
983 parent = *link;
984 entry = rb_entry(parent, struct sched_dl_entity, rb_node);
985 if (dl_time_before(dl_se->deadline, entry->deadline))
986 link = &parent->rb_left;
987 else {
988 link = &parent->rb_right;
989 leftmost = 0;
990 }
991 }
992
993 if (leftmost)
994 dl_rq->rb_leftmost = &dl_se->rb_node;
995
996 rb_link_node(&dl_se->rb_node, parent, link);
997 rb_insert_color(&dl_se->rb_node, &dl_rq->rb_root);
998
Juri Lelli1baca4c2013-11-07 14:43:38 +0100999 inc_dl_tasks(dl_se, dl_rq);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001000}
1001
1002static void __dequeue_dl_entity(struct sched_dl_entity *dl_se)
1003{
1004 struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
1005
1006 if (RB_EMPTY_NODE(&dl_se->rb_node))
1007 return;
1008
1009 if (dl_rq->rb_leftmost == &dl_se->rb_node) {
1010 struct rb_node *next_node;
1011
1012 next_node = rb_next(&dl_se->rb_node);
1013 dl_rq->rb_leftmost = next_node;
1014 }
1015
1016 rb_erase(&dl_se->rb_node, &dl_rq->rb_root);
1017 RB_CLEAR_NODE(&dl_se->rb_node);
1018
Juri Lelli1baca4c2013-11-07 14:43:38 +01001019 dec_dl_tasks(dl_se, dl_rq);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001020}
1021
1022static void
Dario Faggioli2d3d8912013-11-07 14:43:44 +01001023enqueue_dl_entity(struct sched_dl_entity *dl_se,
1024 struct sched_dl_entity *pi_se, int flags)
Dario Faggioliaab03e02013-11-28 11:14:43 +01001025{
1026 BUG_ON(on_dl_rq(dl_se));
1027
1028 /*
1029 * If this is a wakeup or a new instance, the scheduling
1030 * parameters of the task might need updating. Otherwise,
1031 * we want a replenishment of its runtime.
1032 */
Luca Abeni72f9f3f2016-03-07 12:27:04 +01001033 if (flags & ENQUEUE_WAKEUP)
Dario Faggioli2d3d8912013-11-07 14:43:44 +01001034 update_dl_entity(dl_se, pi_se);
Luca Abeni6a503c32014-12-17 11:50:31 +01001035 else if (flags & ENQUEUE_REPLENISH)
1036 replenish_dl_entity(dl_se, pi_se);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001037
1038 __enqueue_dl_entity(dl_se);
1039}
1040
1041static void dequeue_dl_entity(struct sched_dl_entity *dl_se)
1042{
1043 __dequeue_dl_entity(dl_se);
1044}
1045
1046static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
1047{
Dario Faggioli2d3d8912013-11-07 14:43:44 +01001048 struct task_struct *pi_task = rt_mutex_get_top_task(p);
1049 struct sched_dl_entity *pi_se = &p->dl;
1050
1051 /*
1052 * Use the scheduling parameters of the top pi-waiter
Andrea Parriff277d42015-08-05 15:56:19 +02001053 * task if we have one and its (absolute) deadline is
Dario Faggioli2d3d8912013-11-07 14:43:44 +01001054 * smaller than our one... OTW we keep our runtime and
1055 * deadline.
1056 */
Juri Lelli64be6f12014-10-24 10:16:37 +01001057 if (pi_task && p->dl.dl_boosted && dl_prio(pi_task->normal_prio)) {
Dario Faggioli2d3d8912013-11-07 14:43:44 +01001058 pi_se = &pi_task->dl;
Juri Lelli64be6f12014-10-24 10:16:37 +01001059 } else if (!dl_prio(p->normal_prio)) {
1060 /*
1061 * Special case in which we have a !SCHED_DEADLINE task
1062 * that is going to be deboosted, but exceedes its
1063 * runtime while doing so. No point in replenishing
1064 * it, as it's going to return back to its original
1065 * scheduling class after this.
1066 */
1067 BUG_ON(!p->dl.dl_boosted || flags != ENQUEUE_REPLENISH);
1068 return;
1069 }
Dario Faggioli2d3d8912013-11-07 14:43:44 +01001070
Dario Faggioliaab03e02013-11-28 11:14:43 +01001071 /*
Daniel Bristot de Oliveiraa2e29112017-03-02 15:10:58 +01001072 * Check if a constrained deadline task was activated
1073 * after the deadline but before the next period.
1074 * If that is the case, the task will be throttled and
1075 * the replenishment timer will be set to the next period.
1076 */
Daniel Bristot de Oliveira0559ea32017-05-29 16:24:03 +02001077 if (!p->dl.dl_throttled && !dl_is_implicit(&p->dl))
Daniel Bristot de Oliveiraa2e29112017-03-02 15:10:58 +01001078 dl_check_constrained_dl(&p->dl);
1079
1080 /*
Dario Faggioliaab03e02013-11-28 11:14:43 +01001081 * If p is throttled, we do nothing. In fact, if it exhausted
1082 * its budget it needs a replenishment and, since it now is on
1083 * its rq, the bandwidth timer callback (which clearly has not
1084 * run yet) will take care of this.
1085 */
Peter Zijlstra1019a352014-11-26 08:44:03 +08001086 if (p->dl.dl_throttled && !(flags & ENQUEUE_REPLENISH))
Dario Faggioliaab03e02013-11-28 11:14:43 +01001087 return;
1088
Dario Faggioli2d3d8912013-11-07 14:43:44 +01001089 enqueue_dl_entity(&p->dl, pi_se, flags);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001090
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001091 if (!task_current(rq, p) && tsk_nr_cpus_allowed(p) > 1)
Juri Lelli1baca4c2013-11-07 14:43:38 +01001092 enqueue_pushable_dl_task(rq, p);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001093}
1094
1095static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
1096{
1097 dequeue_dl_entity(&p->dl);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001098 dequeue_pushable_dl_task(rq, p);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001099}
1100
1101static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
1102{
1103 update_curr_dl(rq);
1104 __dequeue_task_dl(rq, p, flags);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001105}
1106
1107/*
1108 * Yield task semantic for -deadline tasks is:
1109 *
1110 * get off from the CPU until our next instance, with
1111 * a new runtime. This is of little use now, since we
1112 * don't have a bandwidth reclaiming mechanism. Anyway,
1113 * bandwidth reclaiming is planned for the future, and
1114 * yield_task_dl will indicate that some spare budget
1115 * is available for other task instances to use it.
1116 */
1117static void yield_task_dl(struct rq *rq)
1118{
Dario Faggioliaab03e02013-11-28 11:14:43 +01001119 /*
1120 * We make the task go to sleep until its current deadline by
1121 * forcing its runtime to zero. This way, update_curr_dl() stops
1122 * it and the bandwidth timer will wake it up and will give it
Juri Lelli5bfd1262014-04-15 13:49:04 +02001123 * new scheduling parameters (thanks to dl_yielded=1).
Dario Faggioliaab03e02013-11-28 11:14:43 +01001124 */
Peter Zijlstra48be3a62016-02-23 13:28:22 +01001125 rq->curr->dl.dl_yielded = 1;
1126
Kirill Tkhai6f1607f2015-02-04 12:09:32 +03001127 update_rq_clock(rq);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001128 update_curr_dl(rq);
Wanpeng Li44fb0852015-03-10 12:20:00 +08001129 /*
1130 * Tell update_rq_clock() that we've just updated,
1131 * so we don't do microscopic update in schedule()
1132 * and double the fastpath cost.
1133 */
1134 rq_clock_skip_update(rq, true);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001135}
1136
Juri Lelli1baca4c2013-11-07 14:43:38 +01001137#ifdef CONFIG_SMP
1138
1139static int find_later_rq(struct task_struct *task);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001140
1141static int
1142select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags)
1143{
1144 struct task_struct *curr;
1145 struct rq *rq;
1146
Wanpeng Li1d7e9742014-10-14 10:22:39 +08001147 if (sd_flag != SD_BALANCE_WAKE)
Juri Lelli1baca4c2013-11-07 14:43:38 +01001148 goto out;
1149
1150 rq = cpu_rq(cpu);
1151
1152 rcu_read_lock();
Jason Low316c1608d2015-04-28 13:00:20 -07001153 curr = READ_ONCE(rq->curr); /* unlocked access */
Juri Lelli1baca4c2013-11-07 14:43:38 +01001154
1155 /*
1156 * If we are dealing with a -deadline task, we must
1157 * decide where to wake it up.
1158 * If it has a later deadline and the current task
1159 * on this rq can't move (provided the waking task
1160 * can!) we prefer to send it somewhere else. On the
1161 * other hand, if it has a shorter deadline, we
1162 * try to make it stay here, it might be important.
1163 */
1164 if (unlikely(dl_task(curr)) &&
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001165 (tsk_nr_cpus_allowed(curr) < 2 ||
Juri Lelli1baca4c2013-11-07 14:43:38 +01001166 !dl_entity_preempt(&p->dl, &curr->dl)) &&
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001167 (tsk_nr_cpus_allowed(p) > 1)) {
Juri Lelli1baca4c2013-11-07 14:43:38 +01001168 int target = find_later_rq(p);
1169
Wanpeng Li9d514262015-05-13 14:01:03 +08001170 if (target != -1 &&
Luca Abeni5aa50502015-10-16 10:06:21 +02001171 (dl_time_before(p->dl.deadline,
1172 cpu_rq(target)->dl.earliest_dl.curr) ||
1173 (cpu_rq(target)->dl.dl_nr_running == 0)))
Juri Lelli1baca4c2013-11-07 14:43:38 +01001174 cpu = target;
1175 }
1176 rcu_read_unlock();
1177
1178out:
1179 return cpu;
1180}
1181
1182static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
1183{
1184 /*
1185 * Current can't be migrated, useless to reschedule,
1186 * let's hope p can move out.
1187 */
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001188 if (tsk_nr_cpus_allowed(rq->curr) == 1 ||
Juri Lelli6bfd6d72013-11-07 14:43:47 +01001189 cpudl_find(&rq->rd->cpudl, rq->curr, NULL) == -1)
Juri Lelli1baca4c2013-11-07 14:43:38 +01001190 return;
1191
1192 /*
1193 * p is migratable, so let's not schedule it and
1194 * see if it is pushed or pulled somewhere else.
1195 */
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001196 if (tsk_nr_cpus_allowed(p) != 1 &&
Juri Lelli6bfd6d72013-11-07 14:43:47 +01001197 cpudl_find(&rq->rd->cpudl, p, NULL) != -1)
Juri Lelli1baca4c2013-11-07 14:43:38 +01001198 return;
1199
Kirill Tkhai88751252014-06-29 00:03:57 +04001200 resched_curr(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001201}
1202
1203#endif /* CONFIG_SMP */
1204
Dario Faggioliaab03e02013-11-28 11:14:43 +01001205/*
1206 * Only called when both the current and waking task are -deadline
1207 * tasks.
1208 */
1209static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p,
1210 int flags)
1211{
Juri Lelli1baca4c2013-11-07 14:43:38 +01001212 if (dl_entity_preempt(&p->dl, &rq->curr->dl)) {
Kirill Tkhai88751252014-06-29 00:03:57 +04001213 resched_curr(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001214 return;
1215 }
1216
1217#ifdef CONFIG_SMP
1218 /*
1219 * In the unlikely case current and p have the same deadline
1220 * let us try to decide what's the best thing to do...
1221 */
Dario Faggioli332ac172013-11-07 14:43:45 +01001222 if ((p->dl.deadline == rq->curr->dl.deadline) &&
1223 !test_tsk_need_resched(rq->curr))
Juri Lelli1baca4c2013-11-07 14:43:38 +01001224 check_preempt_equal_dl(rq, p);
1225#endif /* CONFIG_SMP */
Dario Faggioliaab03e02013-11-28 11:14:43 +01001226}
1227
1228#ifdef CONFIG_SCHED_HRTICK
1229static void start_hrtick_dl(struct rq *rq, struct task_struct *p)
1230{
xiaofeng.yan177ef2a2014-08-26 03:15:41 +00001231 hrtick_start(rq, p->dl.runtime);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001232}
Wanpeng Li36ce9882014-11-11 09:52:26 +08001233#else /* !CONFIG_SCHED_HRTICK */
1234static void start_hrtick_dl(struct rq *rq, struct task_struct *p)
1235{
1236}
Dario Faggioliaab03e02013-11-28 11:14:43 +01001237#endif
1238
1239static struct sched_dl_entity *pick_next_dl_entity(struct rq *rq,
1240 struct dl_rq *dl_rq)
1241{
1242 struct rb_node *left = dl_rq->rb_leftmost;
1243
1244 if (!left)
1245 return NULL;
1246
1247 return rb_entry(left, struct sched_dl_entity, rb_node);
1248}
1249
Peter Zijlstrae7904a22015-08-01 19:25:08 +02001250struct task_struct *
Matt Fleming5a91d732016-09-21 14:38:10 +01001251pick_next_task_dl(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
Dario Faggioliaab03e02013-11-28 11:14:43 +01001252{
1253 struct sched_dl_entity *dl_se;
1254 struct task_struct *p;
1255 struct dl_rq *dl_rq;
1256
1257 dl_rq = &rq->dl;
1258
Kirill Tkhaia1d9a322014-04-10 17:38:36 +04001259 if (need_pull_dl_task(rq, prev)) {
Peter Zijlstracbce1a62015-06-11 14:46:54 +02001260 /*
1261 * This is OK, because current is on_cpu, which avoids it being
1262 * picked for load-balance and preemption/IRQs are still
1263 * disabled avoiding further scheduler activity on it and we're
1264 * being very careful to re-start the picking loop.
1265 */
Matt Fleming5a91d732016-09-21 14:38:10 +01001266 rq_unpin_lock(rq, rf);
Peter Zijlstra38033c32014-01-23 20:32:21 +01001267 pull_dl_task(rq);
Matt Fleming5a91d732016-09-21 14:38:10 +01001268 rq_repin_lock(rq, rf);
Kirill Tkhaia1d9a322014-04-10 17:38:36 +04001269 /*
1270 * pull_rt_task() can drop (and re-acquire) rq->lock; this
1271 * means a stop task can slip in, in which case we need to
1272 * re-start task selection.
1273 */
Kirill Tkhaida0c1e62014-08-20 13:47:32 +04001274 if (rq->stop && task_on_rq_queued(rq->stop))
Kirill Tkhaia1d9a322014-04-10 17:38:36 +04001275 return RETRY_TASK;
1276 }
1277
Kirill Tkhai734ff2a2014-03-04 19:25:46 +04001278 /*
1279 * When prev is DL, we may throttle it in put_prev_task().
1280 * So, we update time before we check for dl_nr_running.
1281 */
1282 if (prev->sched_class == &dl_sched_class)
1283 update_curr_dl(rq);
Peter Zijlstra38033c32014-01-23 20:32:21 +01001284
Dario Faggioliaab03e02013-11-28 11:14:43 +01001285 if (unlikely(!dl_rq->dl_nr_running))
1286 return NULL;
1287
Peter Zijlstra3f1d2a32014-02-12 10:49:30 +01001288 put_prev_task(rq, prev);
Peter Zijlstra606dba22012-02-11 06:05:00 +01001289
Dario Faggioliaab03e02013-11-28 11:14:43 +01001290 dl_se = pick_next_dl_entity(rq, dl_rq);
1291 BUG_ON(!dl_se);
1292
1293 p = dl_task_of(dl_se);
1294 p->se.exec_start = rq_clock_task(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001295
1296 /* Running task will never be pushed. */
Juri Lelli71362652014-01-14 12:03:51 +01001297 dequeue_pushable_dl_task(rq, p);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001298
Dario Faggioliaab03e02013-11-28 11:14:43 +01001299 if (hrtick_enabled(rq))
1300 start_hrtick_dl(rq, p);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001301
Peter Zijlstrae3fca9e2015-06-11 14:46:37 +02001302 queue_push_tasks(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001303
Dario Faggioliaab03e02013-11-28 11:14:43 +01001304 return p;
1305}
1306
1307static void put_prev_task_dl(struct rq *rq, struct task_struct *p)
1308{
1309 update_curr_dl(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001310
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001311 if (on_dl_rq(&p->dl) && tsk_nr_cpus_allowed(p) > 1)
Juri Lelli1baca4c2013-11-07 14:43:38 +01001312 enqueue_pushable_dl_task(rq, p);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001313}
1314
1315static void task_tick_dl(struct rq *rq, struct task_struct *p, int queued)
1316{
1317 update_curr_dl(rq);
1318
Wanpeng Lia7bebf42014-11-26 08:44:01 +08001319 /*
1320 * Even when we have runtime, update_curr_dl() might have resulted in us
1321 * not being the leftmost task anymore. In that case NEED_RESCHED will
1322 * be set and schedule() will start a new hrtick for the next task.
1323 */
1324 if (hrtick_enabled(rq) && queued && p->dl.runtime > 0 &&
1325 is_leftmost(p, &rq->dl))
Dario Faggioliaab03e02013-11-28 11:14:43 +01001326 start_hrtick_dl(rq, p);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001327}
1328
1329static void task_fork_dl(struct task_struct *p)
1330{
1331 /*
1332 * SCHED_DEADLINE tasks cannot fork and this is achieved through
1333 * sched_fork()
1334 */
1335}
1336
1337static void task_dead_dl(struct task_struct *p)
1338{
Dario Faggioli332ac172013-11-07 14:43:45 +01001339 struct dl_bw *dl_b = dl_bw_of(task_cpu(p));
1340
1341 /*
1342 * Since we are TASK_DEAD we won't slip out of the domain!
1343 */
1344 raw_spin_lock_irq(&dl_b->lock);
Peter Zijlstra40767b02015-01-28 15:08:03 +01001345 /* XXX we should retain the bw until 0-lag */
Dario Faggioli332ac172013-11-07 14:43:45 +01001346 dl_b->total_bw -= p->dl.dl_bw;
1347 raw_spin_unlock_irq(&dl_b->lock);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001348}
1349
1350static void set_curr_task_dl(struct rq *rq)
1351{
1352 struct task_struct *p = rq->curr;
1353
1354 p->se.exec_start = rq_clock_task(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001355
1356 /* You can't push away the running task */
1357 dequeue_pushable_dl_task(rq, p);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001358}
1359
Juri Lelli1baca4c2013-11-07 14:43:38 +01001360#ifdef CONFIG_SMP
1361
1362/* Only try algorithms three times */
1363#define DL_MAX_TRIES 3
1364
1365static int pick_dl_task(struct rq *rq, struct task_struct *p, int cpu)
1366{
1367 if (!task_running(rq, p) &&
Kirill Tkhai1ba93d42014-09-12 17:42:20 +04001368 cpumask_test_cpu(cpu, tsk_cpus_allowed(p)))
Juri Lelli1baca4c2013-11-07 14:43:38 +01001369 return 1;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001370 return 0;
1371}
1372
Wanpeng Li8b5e7702015-05-13 14:01:01 +08001373/*
1374 * Return the earliest pushable rq's task, which is suitable to be executed
1375 * on the CPU, NULL otherwise:
1376 */
1377static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu)
1378{
1379 struct rb_node *next_node = rq->dl.pushable_dl_tasks_leftmost;
1380 struct task_struct *p = NULL;
1381
1382 if (!has_pushable_dl_tasks(rq))
1383 return NULL;
1384
1385next_node:
1386 if (next_node) {
1387 p = rb_entry(next_node, struct task_struct, pushable_dl_tasks);
1388
1389 if (pick_dl_task(rq, p, cpu))
1390 return p;
1391
1392 next_node = rb_next(next_node);
1393 goto next_node;
1394 }
1395
1396 return NULL;
1397}
1398
Juri Lelli1baca4c2013-11-07 14:43:38 +01001399static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask_dl);
1400
1401static int find_later_rq(struct task_struct *task)
1402{
1403 struct sched_domain *sd;
Christoph Lameter4ba29682014-08-26 19:12:21 -05001404 struct cpumask *later_mask = this_cpu_cpumask_var_ptr(local_cpu_mask_dl);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001405 int this_cpu = smp_processor_id();
1406 int best_cpu, cpu = task_cpu(task);
1407
1408 /* Make sure the mask is initialized first */
1409 if (unlikely(!later_mask))
1410 return -1;
1411
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001412 if (tsk_nr_cpus_allowed(task) == 1)
Juri Lelli1baca4c2013-11-07 14:43:38 +01001413 return -1;
1414
Juri Lelli91ec6772014-09-19 10:22:41 +01001415 /*
1416 * We have to consider system topology and task affinity
1417 * first, then we can look for a suitable cpu.
1418 */
Juri Lelli6bfd6d72013-11-07 14:43:47 +01001419 best_cpu = cpudl_find(&task_rq(task)->rd->cpudl,
1420 task, later_mask);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001421 if (best_cpu == -1)
1422 return -1;
1423
1424 /*
1425 * If we are here, some target has been found,
1426 * the most suitable of which is cached in best_cpu.
1427 * This is, among the runqueues where the current tasks
1428 * have later deadlines than the task's one, the rq
1429 * with the latest possible one.
1430 *
1431 * Now we check how well this matches with task's
1432 * affinity and system topology.
1433 *
1434 * The last cpu where the task run is our first
1435 * guess, since it is most likely cache-hot there.
1436 */
1437 if (cpumask_test_cpu(cpu, later_mask))
1438 return cpu;
1439 /*
1440 * Check if this_cpu is to be skipped (i.e., it is
1441 * not in the mask) or not.
1442 */
1443 if (!cpumask_test_cpu(this_cpu, later_mask))
1444 this_cpu = -1;
1445
1446 rcu_read_lock();
1447 for_each_domain(cpu, sd) {
1448 if (sd->flags & SD_WAKE_AFFINE) {
1449
1450 /*
1451 * If possible, preempting this_cpu is
1452 * cheaper than migrating.
1453 */
1454 if (this_cpu != -1 &&
1455 cpumask_test_cpu(this_cpu, sched_domain_span(sd))) {
1456 rcu_read_unlock();
1457 return this_cpu;
1458 }
1459
1460 /*
1461 * Last chance: if best_cpu is valid and is
1462 * in the mask, that becomes our choice.
1463 */
1464 if (best_cpu < nr_cpu_ids &&
1465 cpumask_test_cpu(best_cpu, sched_domain_span(sd))) {
1466 rcu_read_unlock();
1467 return best_cpu;
1468 }
1469 }
1470 }
1471 rcu_read_unlock();
1472
1473 /*
1474 * At this point, all our guesses failed, we just return
1475 * 'something', and let the caller sort the things out.
1476 */
1477 if (this_cpu != -1)
1478 return this_cpu;
1479
1480 cpu = cpumask_any(later_mask);
1481 if (cpu < nr_cpu_ids)
1482 return cpu;
1483
1484 return -1;
1485}
1486
1487/* Locks the rq it finds */
1488static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq)
1489{
1490 struct rq *later_rq = NULL;
1491 int tries;
1492 int cpu;
1493
1494 for (tries = 0; tries < DL_MAX_TRIES; tries++) {
1495 cpu = find_later_rq(task);
1496
1497 if ((cpu == -1) || (cpu == rq->cpu))
1498 break;
1499
1500 later_rq = cpu_rq(cpu);
1501
Luca Abeni5aa50502015-10-16 10:06:21 +02001502 if (later_rq->dl.dl_nr_running &&
1503 !dl_time_before(task->dl.deadline,
Wanpeng Li9d514262015-05-13 14:01:03 +08001504 later_rq->dl.earliest_dl.curr)) {
1505 /*
1506 * Target rq has tasks of equal or earlier deadline,
1507 * retrying does not release any lock and is unlikely
1508 * to yield a different result.
1509 */
1510 later_rq = NULL;
1511 break;
1512 }
1513
Juri Lelli1baca4c2013-11-07 14:43:38 +01001514 /* Retry if something changed. */
1515 if (double_lock_balance(rq, later_rq)) {
1516 if (unlikely(task_rq(task) != rq ||
1517 !cpumask_test_cpu(later_rq->cpu,
Thomas Gleixnerade42e02016-05-11 14:23:30 +02001518 tsk_cpus_allowed(task)) ||
Kirill Tkhaida0c1e62014-08-20 13:47:32 +04001519 task_running(rq, task) ||
Xunlei Pang13b5ab02016-05-09 12:11:31 +08001520 !dl_task(task) ||
Kirill Tkhaida0c1e62014-08-20 13:47:32 +04001521 !task_on_rq_queued(task))) {
Juri Lelli1baca4c2013-11-07 14:43:38 +01001522 double_unlock_balance(rq, later_rq);
1523 later_rq = NULL;
1524 break;
1525 }
1526 }
1527
1528 /*
1529 * If the rq we found has no -deadline task, or
1530 * its earliest one has a later deadline than our
1531 * task, the rq is a good one.
1532 */
1533 if (!later_rq->dl.dl_nr_running ||
1534 dl_time_before(task->dl.deadline,
1535 later_rq->dl.earliest_dl.curr))
1536 break;
1537
1538 /* Otherwise we try again. */
1539 double_unlock_balance(rq, later_rq);
1540 later_rq = NULL;
1541 }
1542
1543 return later_rq;
1544}
1545
1546static struct task_struct *pick_next_pushable_dl_task(struct rq *rq)
1547{
1548 struct task_struct *p;
1549
1550 if (!has_pushable_dl_tasks(rq))
1551 return NULL;
1552
1553 p = rb_entry(rq->dl.pushable_dl_tasks_leftmost,
1554 struct task_struct, pushable_dl_tasks);
1555
1556 BUG_ON(rq->cpu != task_cpu(p));
1557 BUG_ON(task_current(rq, p));
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001558 BUG_ON(tsk_nr_cpus_allowed(p) <= 1);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001559
Kirill Tkhaida0c1e62014-08-20 13:47:32 +04001560 BUG_ON(!task_on_rq_queued(p));
Juri Lelli1baca4c2013-11-07 14:43:38 +01001561 BUG_ON(!dl_task(p));
1562
1563 return p;
1564}
1565
1566/*
1567 * See if the non running -deadline tasks on this rq
1568 * can be sent to some other CPU where they can preempt
1569 * and start executing.
1570 */
1571static int push_dl_task(struct rq *rq)
1572{
1573 struct task_struct *next_task;
1574 struct rq *later_rq;
Wanpeng Lic51b8ab2014-11-06 15:22:44 +08001575 int ret = 0;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001576
1577 if (!rq->dl.overloaded)
1578 return 0;
1579
1580 next_task = pick_next_pushable_dl_task(rq);
1581 if (!next_task)
1582 return 0;
1583
1584retry:
1585 if (unlikely(next_task == rq->curr)) {
1586 WARN_ON(1);
1587 return 0;
1588 }
1589
1590 /*
1591 * If next_task preempts rq->curr, and rq->curr
1592 * can move away, it makes sense to just reschedule
1593 * without going further in pushing next_task.
1594 */
1595 if (dl_task(rq->curr) &&
1596 dl_time_before(next_task->dl.deadline, rq->curr->dl.deadline) &&
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001597 tsk_nr_cpus_allowed(rq->curr) > 1) {
Kirill Tkhai88751252014-06-29 00:03:57 +04001598 resched_curr(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001599 return 0;
1600 }
1601
1602 /* We might release rq lock */
1603 get_task_struct(next_task);
1604
1605 /* Will lock the rq it'll find */
1606 later_rq = find_lock_later_rq(next_task, rq);
1607 if (!later_rq) {
1608 struct task_struct *task;
1609
1610 /*
1611 * We must check all this again, since
1612 * find_lock_later_rq releases rq->lock and it is
1613 * then possible that next_task has migrated.
1614 */
1615 task = pick_next_pushable_dl_task(rq);
1616 if (task_cpu(next_task) == rq->cpu && task == next_task) {
1617 /*
1618 * The task is still there. We don't try
1619 * again, some other cpu will pull it when ready.
1620 */
Juri Lelli1baca4c2013-11-07 14:43:38 +01001621 goto out;
1622 }
1623
1624 if (!task)
1625 /* No more tasks */
1626 goto out;
1627
1628 put_task_struct(next_task);
1629 next_task = task;
1630 goto retry;
1631 }
1632
Syed Rameez Mustafadddcab72016-09-07 16:18:27 -07001633 next_task->on_rq = TASK_ON_RQ_MIGRATING;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001634 deactivate_task(rq, next_task, 0);
1635 set_task_cpu(next_task, later_rq->cpu);
1636 activate_task(later_rq, next_task, 0);
Syed Rameez Mustafadddcab72016-09-07 16:18:27 -07001637 next_task->on_rq = TASK_ON_RQ_QUEUED;
Wanpeng Lic51b8ab2014-11-06 15:22:44 +08001638 ret = 1;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001639
Kirill Tkhai88751252014-06-29 00:03:57 +04001640 resched_curr(later_rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001641
1642 double_unlock_balance(rq, later_rq);
1643
1644out:
1645 put_task_struct(next_task);
1646
Wanpeng Lic51b8ab2014-11-06 15:22:44 +08001647 return ret;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001648}
1649
1650static void push_dl_tasks(struct rq *rq)
1651{
Andrea Parri4ffa08e2015-08-05 15:56:18 +02001652 /* push_dl_task() will return true if it moved a -deadline task */
Juri Lelli1baca4c2013-11-07 14:43:38 +01001653 while (push_dl_task(rq))
1654 ;
1655}
1656
Peter Zijlstra0ea60c22015-06-11 14:46:42 +02001657static void pull_dl_task(struct rq *this_rq)
Juri Lelli1baca4c2013-11-07 14:43:38 +01001658{
Peter Zijlstra0ea60c22015-06-11 14:46:42 +02001659 int this_cpu = this_rq->cpu, cpu;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001660 struct task_struct *p;
Peter Zijlstra0ea60c22015-06-11 14:46:42 +02001661 bool resched = false;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001662 struct rq *src_rq;
1663 u64 dmin = LONG_MAX;
1664
1665 if (likely(!dl_overloaded(this_rq)))
Peter Zijlstra0ea60c22015-06-11 14:46:42 +02001666 return;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001667
1668 /*
1669 * Match the barrier from dl_set_overloaded; this guarantees that if we
1670 * see overloaded we must also see the dlo_mask bit.
1671 */
1672 smp_rmb();
1673
1674 for_each_cpu(cpu, this_rq->rd->dlo_mask) {
1675 if (this_cpu == cpu)
1676 continue;
1677
1678 src_rq = cpu_rq(cpu);
1679
1680 /*
1681 * It looks racy, abd it is! However, as in sched_rt.c,
1682 * we are fine with this.
1683 */
1684 if (this_rq->dl.dl_nr_running &&
1685 dl_time_before(this_rq->dl.earliest_dl.curr,
1686 src_rq->dl.earliest_dl.next))
1687 continue;
1688
1689 /* Might drop this_rq->lock */
1690 double_lock_balance(this_rq, src_rq);
1691
1692 /*
1693 * If there are no more pullable tasks on the
1694 * rq, we're done with it.
1695 */
1696 if (src_rq->dl.dl_nr_running <= 1)
1697 goto skip;
1698
Wanpeng Li8b5e7702015-05-13 14:01:01 +08001699 p = pick_earliest_pushable_dl_task(src_rq, this_cpu);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001700
1701 /*
1702 * We found a task to be pulled if:
1703 * - it preempts our current (if there's one),
1704 * - it will preempt the last one we pulled (if any).
1705 */
1706 if (p && dl_time_before(p->dl.deadline, dmin) &&
1707 (!this_rq->dl.dl_nr_running ||
1708 dl_time_before(p->dl.deadline,
1709 this_rq->dl.earliest_dl.curr))) {
1710 WARN_ON(p == src_rq->curr);
Kirill Tkhaida0c1e62014-08-20 13:47:32 +04001711 WARN_ON(!task_on_rq_queued(p));
Juri Lelli1baca4c2013-11-07 14:43:38 +01001712
1713 /*
1714 * Then we pull iff p has actually an earlier
1715 * deadline than the current task of its runqueue.
1716 */
1717 if (dl_time_before(p->dl.deadline,
1718 src_rq->curr->dl.deadline))
1719 goto skip;
1720
Peter Zijlstra0ea60c22015-06-11 14:46:42 +02001721 resched = true;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001722
Syed Rameez Mustafadddcab72016-09-07 16:18:27 -07001723 p->on_rq = TASK_ON_RQ_MIGRATING;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001724 deactivate_task(src_rq, p, 0);
1725 set_task_cpu(p, this_cpu);
1726 activate_task(this_rq, p, 0);
Syed Rameez Mustafadddcab72016-09-07 16:18:27 -07001727 p->on_rq = TASK_ON_RQ_QUEUED;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001728 dmin = p->dl.deadline;
1729
1730 /* Is there any other task even earlier? */
1731 }
1732skip:
1733 double_unlock_balance(this_rq, src_rq);
1734 }
1735
Peter Zijlstra0ea60c22015-06-11 14:46:42 +02001736 if (resched)
1737 resched_curr(this_rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001738}
1739
1740/*
1741 * Since the task is not running and a reschedule is not going to happen
1742 * anytime soon on its runqueue, we try pushing it away now.
1743 */
1744static void task_woken_dl(struct rq *rq, struct task_struct *p)
1745{
1746 if (!task_running(rq, p) &&
1747 !test_tsk_need_resched(rq->curr) &&
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001748 tsk_nr_cpus_allowed(p) > 1 &&
Juri Lelli1baca4c2013-11-07 14:43:38 +01001749 dl_task(rq->curr) &&
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001750 (tsk_nr_cpus_allowed(rq->curr) < 2 ||
Wanpeng Li6b0a5632014-10-31 06:39:34 +08001751 !dl_entity_preempt(&p->dl, &rq->curr->dl))) {
Juri Lelli1baca4c2013-11-07 14:43:38 +01001752 push_dl_tasks(rq);
1753 }
1754}
1755
1756static void set_cpus_allowed_dl(struct task_struct *p,
1757 const struct cpumask *new_mask)
1758{
Juri Lelli7f514122014-09-19 10:22:40 +01001759 struct root_domain *src_rd;
Peter Zijlstra6c370672015-05-15 17:43:36 +02001760 struct rq *rq;
Juri Lelli1baca4c2013-11-07 14:43:38 +01001761
1762 BUG_ON(!dl_task(p));
1763
Juri Lelli7f514122014-09-19 10:22:40 +01001764 rq = task_rq(p);
1765 src_rd = rq->rd;
1766 /*
1767 * Migrating a SCHED_DEADLINE task between exclusive
1768 * cpusets (different root_domains) entails a bandwidth
1769 * update. We already made space for us in the destination
1770 * domain (see cpuset_can_attach()).
1771 */
1772 if (!cpumask_intersects(src_rd->span, new_mask)) {
1773 struct dl_bw *src_dl_b;
1774
1775 src_dl_b = dl_bw_of(cpu_of(rq));
1776 /*
1777 * We now free resources of the root_domain we are migrating
1778 * off. In the worst case, sched_setattr() may temporary fail
1779 * until we complete the update.
1780 */
1781 raw_spin_lock(&src_dl_b->lock);
1782 __dl_clear(src_dl_b, p->dl.dl_bw);
1783 raw_spin_unlock(&src_dl_b->lock);
1784 }
1785
Peter Zijlstra6c370672015-05-15 17:43:36 +02001786 set_cpus_allowed_common(p, new_mask);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001787}
1788
1789/* Assumes rq->lock is held */
1790static void rq_online_dl(struct rq *rq)
1791{
1792 if (rq->dl.overloaded)
1793 dl_set_overload(rq);
Juri Lelli6bfd6d72013-11-07 14:43:47 +01001794
Xunlei Pang16b26942015-01-19 04:49:36 +00001795 cpudl_set_freecpu(&rq->rd->cpudl, rq->cpu);
Juri Lelli6bfd6d72013-11-07 14:43:47 +01001796 if (rq->dl.dl_nr_running > 0)
Tommaso Cucinottad8206bb2016-08-14 16:27:08 +02001797 cpudl_set(&rq->rd->cpudl, rq->cpu, rq->dl.earliest_dl.curr);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001798}
1799
1800/* Assumes rq->lock is held */
1801static void rq_offline_dl(struct rq *rq)
1802{
1803 if (rq->dl.overloaded)
1804 dl_clear_overload(rq);
Juri Lelli6bfd6d72013-11-07 14:43:47 +01001805
Tommaso Cucinottad8206bb2016-08-14 16:27:08 +02001806 cpudl_clear(&rq->rd->cpudl, rq->cpu);
Xunlei Pang16b26942015-01-19 04:49:36 +00001807 cpudl_clear_freecpu(&rq->rd->cpudl, rq->cpu);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001808}
1809
Wanpeng Lia6c0e742015-05-13 14:01:02 +08001810void __init init_sched_dl_class(void)
Juri Lelli1baca4c2013-11-07 14:43:38 +01001811{
1812 unsigned int i;
1813
1814 for_each_possible_cpu(i)
1815 zalloc_cpumask_var_node(&per_cpu(local_cpu_mask_dl, i),
1816 GFP_KERNEL, cpu_to_node(i));
1817}
1818
1819#endif /* CONFIG_SMP */
1820
Dario Faggioliaab03e02013-11-28 11:14:43 +01001821static void switched_from_dl(struct rq *rq, struct task_struct *p)
1822{
Peter Zijlstraa649f232015-06-11 14:46:49 +02001823 /*
1824 * Start the deadline timer; if we switch back to dl before this we'll
1825 * continue consuming our current CBS slice. If we stay outside of
1826 * SCHED_DEADLINE until the deadline passes, the timer will reset the
1827 * task.
1828 */
1829 if (!start_dl_timer(p))
1830 __dl_clear_params(p);
Juri Lellia5e7be32014-09-19 10:22:39 +01001831
Juri Lelli1baca4c2013-11-07 14:43:38 +01001832 /*
1833 * Since this might be the only -deadline task on the rq,
1834 * this is the right place to try to pull some other one
1835 * from an overloaded cpu, if any.
1836 */
Wanpeng Licd660912014-10-31 06:39:35 +08001837 if (!task_on_rq_queued(p) || rq->dl.dl_nr_running)
1838 return;
1839
Peter Zijlstra9916e212015-06-11 14:46:43 +02001840 queue_pull_task(rq);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001841}
1842
Juri Lelli1baca4c2013-11-07 14:43:38 +01001843/*
1844 * When switching to -deadline, we may overload the rq, then
1845 * we try to push someone off, if possible.
1846 */
Dario Faggioliaab03e02013-11-28 11:14:43 +01001847static void switched_to_dl(struct rq *rq, struct task_struct *p)
1848{
Luca Abeni72f9f3f2016-03-07 12:27:04 +01001849
Juri Lelli98b0a852016-08-05 16:07:55 +01001850 /* If p is not queued we will update its parameters at next wakeup. */
1851 if (!task_on_rq_queued(p))
1852 return;
1853
1854 /*
1855 * If p is boosted we already updated its params in
1856 * rt_mutex_setprio()->enqueue_task(..., ENQUEUE_REPLENISH),
1857 * p's deadline being now already after rq_clock(rq).
1858 */
1859 if (dl_time_before(p->dl.deadline, rq_clock(rq)))
1860 setup_new_dl_entity(&p->dl);
1861
1862 if (rq->curr != p) {
Juri Lelli1baca4c2013-11-07 14:43:38 +01001863#ifdef CONFIG_SMP
Thomas Gleixner50605ff2016-05-11 14:23:31 +02001864 if (tsk_nr_cpus_allowed(p) > 1 && rq->dl.overloaded)
Peter Zijlstra9916e212015-06-11 14:46:43 +02001865 queue_push_tasks(rq);
Sebastian Andrzej Siewior916c5cfe2017-01-24 15:40:06 +01001866#endif
Peter Zijlstra9916e212015-06-11 14:46:43 +02001867 if (dl_task(rq->curr))
1868 check_preempt_curr_dl(rq, p, 0);
1869 else
1870 resched_curr(rq);
Dario Faggioliaab03e02013-11-28 11:14:43 +01001871 }
1872}
1873
Juri Lelli1baca4c2013-11-07 14:43:38 +01001874/*
1875 * If the scheduling parameters of a -deadline task changed,
1876 * a push or pull operation might be needed.
1877 */
Dario Faggioliaab03e02013-11-28 11:14:43 +01001878static void prio_changed_dl(struct rq *rq, struct task_struct *p,
1879 int oldprio)
1880{
Kirill Tkhaida0c1e62014-08-20 13:47:32 +04001881 if (task_on_rq_queued(p) || rq->curr == p) {
Dario Faggioliaab03e02013-11-28 11:14:43 +01001882#ifdef CONFIG_SMP
Juri Lelli1baca4c2013-11-07 14:43:38 +01001883 /*
1884 * This might be too much, but unfortunately
1885 * we don't have the old deadline value, and
1886 * we can't argue if the task is increasing
1887 * or lowering its prio, so...
1888 */
1889 if (!rq->dl.overloaded)
Peter Zijlstra9916e212015-06-11 14:46:43 +02001890 queue_pull_task(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001891
1892 /*
1893 * If we now have a earlier deadline task than p,
1894 * then reschedule, provided p is still on this
1895 * runqueue.
1896 */
Peter Zijlstra9916e212015-06-11 14:46:43 +02001897 if (dl_time_before(rq->dl.earliest_dl.curr, p->dl.deadline))
Kirill Tkhai88751252014-06-29 00:03:57 +04001898 resched_curr(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001899#else
1900 /*
1901 * Again, we don't know if p has a earlier
1902 * or later deadline, so let's blindly set a
1903 * (maybe not needed) rescheduling point.
1904 */
Kirill Tkhai88751252014-06-29 00:03:57 +04001905 resched_curr(rq);
Juri Lelli1baca4c2013-11-07 14:43:38 +01001906#endif /* CONFIG_SMP */
Peter Zijlstra801ccdb2016-02-25 15:01:49 +01001907 }
Dario Faggioliaab03e02013-11-28 11:14:43 +01001908}
Dario Faggioliaab03e02013-11-28 11:14:43 +01001909
1910const struct sched_class dl_sched_class = {
1911 .next = &rt_sched_class,
1912 .enqueue_task = enqueue_task_dl,
1913 .dequeue_task = dequeue_task_dl,
1914 .yield_task = yield_task_dl,
1915
1916 .check_preempt_curr = check_preempt_curr_dl,
1917
1918 .pick_next_task = pick_next_task_dl,
1919 .put_prev_task = put_prev_task_dl,
1920
1921#ifdef CONFIG_SMP
1922 .select_task_rq = select_task_rq_dl,
Juri Lelli1baca4c2013-11-07 14:43:38 +01001923 .set_cpus_allowed = set_cpus_allowed_dl,
1924 .rq_online = rq_online_dl,
1925 .rq_offline = rq_offline_dl,
Juri Lelli1baca4c2013-11-07 14:43:38 +01001926 .task_woken = task_woken_dl,
Dario Faggioliaab03e02013-11-28 11:14:43 +01001927#endif
1928
1929 .set_curr_task = set_curr_task_dl,
1930 .task_tick = task_tick_dl,
1931 .task_fork = task_fork_dl,
1932 .task_dead = task_dead_dl,
1933
1934 .prio_changed = prio_changed_dl,
1935 .switched_from = switched_from_dl,
1936 .switched_to = switched_to_dl,
Stanislaw Gruszka6e998912014-11-12 16:58:44 +01001937
1938 .update_curr = update_curr_dl,
Joonwoo Parkf7d6cd42017-01-17 15:19:43 -08001939#ifdef CONFIG_SCHED_WALT
Pavankumar Kondetid3370502017-07-20 11:47:13 +05301940 .fixup_walt_sched_stats = fixup_walt_sched_stats_common,
Pavankumar Kondeti1c847af2019-09-04 10:08:32 +05301941 .fixup_cumulative_runnable_avg = walt_fixup_cumulative_runnable_avg,
Syed Rameez Mustafadddcab72016-09-07 16:18:27 -07001942#endif
Dario Faggioliaab03e02013-11-28 11:14:43 +01001943};
Wanpeng Liacb32132014-10-31 06:39:33 +08001944
1945#ifdef CONFIG_SCHED_DEBUG
1946extern void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq);
1947
1948void print_dl_stats(struct seq_file *m, int cpu)
1949{
1950 print_dl_rq(m, cpu, &cpu_rq(cpu)->dl);
1951}
1952#endif /* CONFIG_SCHED_DEBUG */