Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1 | /* |
| 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 Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 13 | * Juri Lelli <juri.lelli@gmail.com>, |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 14 | * Michael Trimarchi <michael@amarulasolutions.com>, |
| 15 | * Fabio Checconi <fchecconi@gmail.com> |
| 16 | */ |
| 17 | #include "sched.h" |
| 18 | |
Juri Lelli | 6bfd6d7 | 2013-11-07 14:43:47 +0100 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 21 | struct dl_bandwidth def_dl_bandwidth; |
| 22 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 23 | static inline struct task_struct *dl_task_of(struct sched_dl_entity *dl_se) |
| 24 | { |
| 25 | return container_of(dl_se, struct task_struct, dl); |
| 26 | } |
| 27 | |
| 28 | static inline struct rq *rq_of_dl_rq(struct dl_rq *dl_rq) |
| 29 | { |
| 30 | return container_of(dl_rq, struct rq, dl); |
| 31 | } |
| 32 | |
| 33 | static inline struct dl_rq *dl_rq_of_se(struct sched_dl_entity *dl_se) |
| 34 | { |
| 35 | struct task_struct *p = dl_task_of(dl_se); |
| 36 | struct rq *rq = task_rq(p); |
| 37 | |
| 38 | return &rq->dl; |
| 39 | } |
| 40 | |
| 41 | static inline int on_dl_rq(struct sched_dl_entity *dl_se) |
| 42 | { |
| 43 | return !RB_EMPTY_NODE(&dl_se->rb_node); |
| 44 | } |
| 45 | |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 46 | static inline |
| 47 | void add_running_bw(u64 dl_bw, struct dl_rq *dl_rq) |
| 48 | { |
| 49 | u64 old = dl_rq->running_bw; |
| 50 | |
| 51 | lockdep_assert_held(&(rq_of_dl_rq(dl_rq))->lock); |
| 52 | dl_rq->running_bw += dl_bw; |
| 53 | SCHED_WARN_ON(dl_rq->running_bw < old); /* overflow */ |
| 54 | } |
| 55 | |
| 56 | static inline |
| 57 | void sub_running_bw(u64 dl_bw, struct dl_rq *dl_rq) |
| 58 | { |
| 59 | u64 old = dl_rq->running_bw; |
| 60 | |
| 61 | lockdep_assert_held(&(rq_of_dl_rq(dl_rq))->lock); |
| 62 | dl_rq->running_bw -= dl_bw; |
| 63 | SCHED_WARN_ON(dl_rq->running_bw > old); /* underflow */ |
| 64 | if (dl_rq->running_bw > old) |
| 65 | dl_rq->running_bw = 0; |
| 66 | } |
| 67 | |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 68 | void dl_change_utilization(struct task_struct *p, u64 new_bw) |
| 69 | { |
| 70 | if (task_on_rq_queued(p)) |
| 71 | return; |
| 72 | |
| 73 | if (!p->dl.dl_non_contending) |
| 74 | return; |
| 75 | |
| 76 | sub_running_bw(p->dl.dl_bw, &task_rq(p)->dl); |
| 77 | p->dl.dl_non_contending = 0; |
| 78 | /* |
| 79 | * If the timer handler is currently running and the |
| 80 | * timer cannot be cancelled, inactive_task_timer() |
| 81 | * will see that dl_not_contending is not set, and |
| 82 | * will not touch the rq's active utilization, |
| 83 | * so we are still safe. |
| 84 | */ |
| 85 | if (hrtimer_try_to_cancel(&p->dl.inactive_timer) == 1) |
| 86 | put_task_struct(p); |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * The utilization of a task cannot be immediately removed from |
| 91 | * the rq active utilization (running_bw) when the task blocks. |
| 92 | * Instead, we have to wait for the so called "0-lag time". |
| 93 | * |
| 94 | * If a task blocks before the "0-lag time", a timer (the inactive |
| 95 | * timer) is armed, and running_bw is decreased when the timer |
| 96 | * fires. |
| 97 | * |
| 98 | * If the task wakes up again before the inactive timer fires, |
| 99 | * the timer is cancelled, whereas if the task wakes up after the |
| 100 | * inactive timer fired (and running_bw has been decreased) the |
| 101 | * task's utilization has to be added to running_bw again. |
| 102 | * A flag in the deadline scheduling entity (dl_non_contending) |
| 103 | * is used to avoid race conditions between the inactive timer handler |
| 104 | * and task wakeups. |
| 105 | * |
| 106 | * The following diagram shows how running_bw is updated. A task is |
| 107 | * "ACTIVE" when its utilization contributes to running_bw; an |
| 108 | * "ACTIVE contending" task is in the TASK_RUNNING state, while an |
| 109 | * "ACTIVE non contending" task is a blocked task for which the "0-lag time" |
| 110 | * has not passed yet. An "INACTIVE" task is a task for which the "0-lag" |
| 111 | * time already passed, which does not contribute to running_bw anymore. |
| 112 | * +------------------+ |
| 113 | * wakeup | ACTIVE | |
| 114 | * +------------------>+ contending | |
| 115 | * | add_running_bw | | |
| 116 | * | +----+------+------+ |
| 117 | * | | ^ |
| 118 | * | dequeue | | |
| 119 | * +--------+-------+ | | |
| 120 | * | | t >= 0-lag | | wakeup |
| 121 | * | INACTIVE |<---------------+ | |
| 122 | * | | sub_running_bw | | |
| 123 | * +--------+-------+ | | |
| 124 | * ^ | | |
| 125 | * | t < 0-lag | | |
| 126 | * | | | |
| 127 | * | V | |
| 128 | * | +----+------+------+ |
| 129 | * | sub_running_bw | ACTIVE | |
| 130 | * +-------------------+ | |
| 131 | * inactive timer | non contending | |
| 132 | * fired +------------------+ |
| 133 | * |
| 134 | * The task_non_contending() function is invoked when a task |
| 135 | * blocks, and checks if the 0-lag time already passed or |
| 136 | * not (in the first case, it directly updates running_bw; |
| 137 | * in the second case, it arms the inactive timer). |
| 138 | * |
| 139 | * The task_contending() function is invoked when a task wakes |
| 140 | * up, and checks if the task is still in the "ACTIVE non contending" |
| 141 | * state or not (in the second case, it updates running_bw). |
| 142 | */ |
| 143 | static void task_non_contending(struct task_struct *p) |
| 144 | { |
| 145 | struct sched_dl_entity *dl_se = &p->dl; |
| 146 | struct hrtimer *timer = &dl_se->inactive_timer; |
| 147 | struct dl_rq *dl_rq = dl_rq_of_se(dl_se); |
| 148 | struct rq *rq = rq_of_dl_rq(dl_rq); |
| 149 | s64 zerolag_time; |
| 150 | |
| 151 | /* |
| 152 | * If this is a non-deadline task that has been boosted, |
| 153 | * do nothing |
| 154 | */ |
| 155 | if (dl_se->dl_runtime == 0) |
| 156 | return; |
| 157 | |
| 158 | WARN_ON(hrtimer_active(&dl_se->inactive_timer)); |
| 159 | WARN_ON(dl_se->dl_non_contending); |
| 160 | |
| 161 | zerolag_time = dl_se->deadline - |
| 162 | div64_long((dl_se->runtime * dl_se->dl_period), |
| 163 | dl_se->dl_runtime); |
| 164 | |
| 165 | /* |
| 166 | * Using relative times instead of the absolute "0-lag time" |
| 167 | * allows to simplify the code |
| 168 | */ |
| 169 | zerolag_time -= rq_clock(rq); |
| 170 | |
| 171 | /* |
| 172 | * If the "0-lag time" already passed, decrease the active |
| 173 | * utilization now, instead of starting a timer |
| 174 | */ |
| 175 | if (zerolag_time < 0) { |
| 176 | if (dl_task(p)) |
| 177 | sub_running_bw(dl_se->dl_bw, dl_rq); |
Luca Abeni | 387e313 | 2017-05-18 22:13:30 +0200 | [diff] [blame] | 178 | if (!dl_task(p) || p->state == TASK_DEAD) { |
| 179 | struct dl_bw *dl_b = dl_bw_of(task_cpu(p)); |
| 180 | |
| 181 | raw_spin_lock(&dl_b->lock); |
| 182 | __dl_clear(dl_b, p->dl.dl_bw); |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 183 | __dl_clear_params(p); |
Luca Abeni | 387e313 | 2017-05-18 22:13:30 +0200 | [diff] [blame] | 184 | raw_spin_unlock(&dl_b->lock); |
| 185 | } |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 186 | |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | dl_se->dl_non_contending = 1; |
| 191 | get_task_struct(p); |
| 192 | hrtimer_start(timer, ns_to_ktime(zerolag_time), HRTIMER_MODE_REL); |
| 193 | } |
| 194 | |
| 195 | static void task_contending(struct sched_dl_entity *dl_se) |
| 196 | { |
| 197 | struct dl_rq *dl_rq = dl_rq_of_se(dl_se); |
| 198 | |
| 199 | /* |
| 200 | * If this is a non-deadline task that has been boosted, |
| 201 | * do nothing |
| 202 | */ |
| 203 | if (dl_se->dl_runtime == 0) |
| 204 | return; |
| 205 | |
| 206 | if (dl_se->dl_non_contending) { |
| 207 | dl_se->dl_non_contending = 0; |
| 208 | /* |
| 209 | * If the timer handler is currently running and the |
| 210 | * timer cannot be cancelled, inactive_task_timer() |
| 211 | * will see that dl_not_contending is not set, and |
| 212 | * will not touch the rq's active utilization, |
| 213 | * so we are still safe. |
| 214 | */ |
| 215 | if (hrtimer_try_to_cancel(&dl_se->inactive_timer) == 1) |
| 216 | put_task_struct(dl_task_of(dl_se)); |
| 217 | } else { |
| 218 | /* |
| 219 | * Since "dl_non_contending" is not set, the |
| 220 | * task's utilization has already been removed from |
| 221 | * active utilization (either when the task blocked, |
| 222 | * when the "inactive timer" fired). |
| 223 | * So, add it back. |
| 224 | */ |
| 225 | add_running_bw(dl_se->dl_bw, dl_rq); |
| 226 | } |
| 227 | } |
| 228 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 229 | static inline int is_leftmost(struct task_struct *p, struct dl_rq *dl_rq) |
| 230 | { |
| 231 | struct sched_dl_entity *dl_se = &p->dl; |
| 232 | |
| 233 | return dl_rq->rb_leftmost == &dl_se->rb_node; |
| 234 | } |
| 235 | |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 236 | void init_dl_bandwidth(struct dl_bandwidth *dl_b, u64 period, u64 runtime) |
| 237 | { |
| 238 | raw_spin_lock_init(&dl_b->dl_runtime_lock); |
| 239 | dl_b->dl_period = period; |
| 240 | dl_b->dl_runtime = runtime; |
| 241 | } |
| 242 | |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 243 | void init_dl_bw(struct dl_bw *dl_b) |
| 244 | { |
| 245 | raw_spin_lock_init(&dl_b->lock); |
| 246 | raw_spin_lock(&def_dl_bandwidth.dl_runtime_lock); |
Peter Zijlstra | 1724813 | 2013-12-17 12:44:49 +0100 | [diff] [blame] | 247 | if (global_rt_runtime() == RUNTIME_INF) |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 248 | dl_b->bw = -1; |
| 249 | else |
Peter Zijlstra | 1724813 | 2013-12-17 12:44:49 +0100 | [diff] [blame] | 250 | dl_b->bw = to_ratio(global_rt_period(), global_rt_runtime()); |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 251 | raw_spin_unlock(&def_dl_bandwidth.dl_runtime_lock); |
| 252 | dl_b->total_bw = 0; |
| 253 | } |
| 254 | |
Abel Vesa | 07c54f7 | 2015-03-03 13:50:27 +0200 | [diff] [blame] | 255 | void init_dl_rq(struct dl_rq *dl_rq) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 256 | { |
| 257 | dl_rq->rb_root = RB_ROOT; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 258 | |
| 259 | #ifdef CONFIG_SMP |
| 260 | /* zero means no -deadline tasks */ |
| 261 | dl_rq->earliest_dl.curr = dl_rq->earliest_dl.next = 0; |
| 262 | |
| 263 | dl_rq->dl_nr_migratory = 0; |
| 264 | dl_rq->overloaded = 0; |
| 265 | dl_rq->pushable_dl_tasks_root = RB_ROOT; |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 266 | #else |
| 267 | init_dl_bw(&dl_rq->dl_bw); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 268 | #endif |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 269 | |
| 270 | dl_rq->running_bw = 0; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 273 | #ifdef CONFIG_SMP |
| 274 | |
| 275 | static inline int dl_overloaded(struct rq *rq) |
| 276 | { |
| 277 | return atomic_read(&rq->rd->dlo_count); |
| 278 | } |
| 279 | |
| 280 | static inline void dl_set_overload(struct rq *rq) |
| 281 | { |
| 282 | if (!rq->online) |
| 283 | return; |
| 284 | |
| 285 | cpumask_set_cpu(rq->cpu, rq->rd->dlo_mask); |
| 286 | /* |
| 287 | * Must be visible before the overload count is |
| 288 | * set (as in sched_rt.c). |
| 289 | * |
| 290 | * Matched by the barrier in pull_dl_task(). |
| 291 | */ |
| 292 | smp_wmb(); |
| 293 | atomic_inc(&rq->rd->dlo_count); |
| 294 | } |
| 295 | |
| 296 | static inline void dl_clear_overload(struct rq *rq) |
| 297 | { |
| 298 | if (!rq->online) |
| 299 | return; |
| 300 | |
| 301 | atomic_dec(&rq->rd->dlo_count); |
| 302 | cpumask_clear_cpu(rq->cpu, rq->rd->dlo_mask); |
| 303 | } |
| 304 | |
| 305 | static void update_dl_migration(struct dl_rq *dl_rq) |
| 306 | { |
Kirill Tkhai | 995b9ea | 2014-02-18 02:24:13 +0400 | [diff] [blame] | 307 | if (dl_rq->dl_nr_migratory && dl_rq->dl_nr_running > 1) { |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 308 | if (!dl_rq->overloaded) { |
| 309 | dl_set_overload(rq_of_dl_rq(dl_rq)); |
| 310 | dl_rq->overloaded = 1; |
| 311 | } |
| 312 | } else if (dl_rq->overloaded) { |
| 313 | dl_clear_overload(rq_of_dl_rq(dl_rq)); |
| 314 | dl_rq->overloaded = 0; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) |
| 319 | { |
| 320 | struct task_struct *p = dl_task_of(dl_se); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 321 | |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 322 | if (p->nr_cpus_allowed > 1) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 323 | dl_rq->dl_nr_migratory++; |
| 324 | |
| 325 | update_dl_migration(dl_rq); |
| 326 | } |
| 327 | |
| 328 | static void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) |
| 329 | { |
| 330 | struct task_struct *p = dl_task_of(dl_se); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 331 | |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 332 | if (p->nr_cpus_allowed > 1) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 333 | dl_rq->dl_nr_migratory--; |
| 334 | |
| 335 | update_dl_migration(dl_rq); |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * The list of pushable -deadline task is not a plist, like in |
| 340 | * sched_rt.c, it is an rb-tree with tasks ordered by deadline. |
| 341 | */ |
| 342 | static void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p) |
| 343 | { |
| 344 | struct dl_rq *dl_rq = &rq->dl; |
| 345 | struct rb_node **link = &dl_rq->pushable_dl_tasks_root.rb_node; |
| 346 | struct rb_node *parent = NULL; |
| 347 | struct task_struct *entry; |
| 348 | int leftmost = 1; |
| 349 | |
| 350 | BUG_ON(!RB_EMPTY_NODE(&p->pushable_dl_tasks)); |
| 351 | |
| 352 | while (*link) { |
| 353 | parent = *link; |
| 354 | entry = rb_entry(parent, struct task_struct, |
| 355 | pushable_dl_tasks); |
| 356 | if (dl_entity_preempt(&p->dl, &entry->dl)) |
| 357 | link = &parent->rb_left; |
| 358 | else { |
| 359 | link = &parent->rb_right; |
| 360 | leftmost = 0; |
| 361 | } |
| 362 | } |
| 363 | |
Wanpeng Li | 7d92de3 | 2015-12-03 17:42:10 +0800 | [diff] [blame] | 364 | if (leftmost) { |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 365 | dl_rq->pushable_dl_tasks_leftmost = &p->pushable_dl_tasks; |
Wanpeng Li | 7d92de3 | 2015-12-03 17:42:10 +0800 | [diff] [blame] | 366 | dl_rq->earliest_dl.next = p->dl.deadline; |
| 367 | } |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 368 | |
| 369 | rb_link_node(&p->pushable_dl_tasks, parent, link); |
| 370 | rb_insert_color(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root); |
| 371 | } |
| 372 | |
| 373 | static void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p) |
| 374 | { |
| 375 | struct dl_rq *dl_rq = &rq->dl; |
| 376 | |
| 377 | if (RB_EMPTY_NODE(&p->pushable_dl_tasks)) |
| 378 | return; |
| 379 | |
| 380 | if (dl_rq->pushable_dl_tasks_leftmost == &p->pushable_dl_tasks) { |
| 381 | struct rb_node *next_node; |
| 382 | |
| 383 | next_node = rb_next(&p->pushable_dl_tasks); |
| 384 | dl_rq->pushable_dl_tasks_leftmost = next_node; |
Wanpeng Li | 7d92de3 | 2015-12-03 17:42:10 +0800 | [diff] [blame] | 385 | if (next_node) { |
| 386 | dl_rq->earliest_dl.next = rb_entry(next_node, |
| 387 | struct task_struct, pushable_dl_tasks)->dl.deadline; |
| 388 | } |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | rb_erase(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root); |
| 392 | RB_CLEAR_NODE(&p->pushable_dl_tasks); |
| 393 | } |
| 394 | |
| 395 | static inline int has_pushable_dl_tasks(struct rq *rq) |
| 396 | { |
| 397 | return !RB_EMPTY_ROOT(&rq->dl.pushable_dl_tasks_root); |
| 398 | } |
| 399 | |
| 400 | static int push_dl_task(struct rq *rq); |
| 401 | |
Peter Zijlstra | dc87734 | 2014-02-12 15:47:29 +0100 | [diff] [blame] | 402 | static inline bool need_pull_dl_task(struct rq *rq, struct task_struct *prev) |
| 403 | { |
| 404 | return dl_task(prev); |
| 405 | } |
| 406 | |
Peter Zijlstra | 9916e21 | 2015-06-11 14:46:43 +0200 | [diff] [blame] | 407 | static DEFINE_PER_CPU(struct callback_head, dl_push_head); |
| 408 | static DEFINE_PER_CPU(struct callback_head, dl_pull_head); |
Peter Zijlstra | e3fca9e | 2015-06-11 14:46:37 +0200 | [diff] [blame] | 409 | |
| 410 | static void push_dl_tasks(struct rq *); |
Peter Zijlstra | 9916e21 | 2015-06-11 14:46:43 +0200 | [diff] [blame] | 411 | static void pull_dl_task(struct rq *); |
Peter Zijlstra | e3fca9e | 2015-06-11 14:46:37 +0200 | [diff] [blame] | 412 | |
| 413 | static inline void queue_push_tasks(struct rq *rq) |
Peter Zijlstra | dc87734 | 2014-02-12 15:47:29 +0100 | [diff] [blame] | 414 | { |
Peter Zijlstra | e3fca9e | 2015-06-11 14:46:37 +0200 | [diff] [blame] | 415 | if (!has_pushable_dl_tasks(rq)) |
| 416 | return; |
| 417 | |
Peter Zijlstra | 9916e21 | 2015-06-11 14:46:43 +0200 | [diff] [blame] | 418 | queue_balance_callback(rq, &per_cpu(dl_push_head, rq->cpu), push_dl_tasks); |
| 419 | } |
| 420 | |
| 421 | static inline void queue_pull_task(struct rq *rq) |
| 422 | { |
| 423 | queue_balance_callback(rq, &per_cpu(dl_pull_head, rq->cpu), pull_dl_task); |
Peter Zijlstra | dc87734 | 2014-02-12 15:47:29 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Wanpeng Li | fa9c9d1 | 2015-03-27 07:08:35 +0800 | [diff] [blame] | 426 | static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq); |
| 427 | |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 428 | static struct rq *dl_task_offline_migration(struct rq *rq, struct task_struct *p) |
Wanpeng Li | fa9c9d1 | 2015-03-27 07:08:35 +0800 | [diff] [blame] | 429 | { |
| 430 | struct rq *later_rq = NULL; |
Wanpeng Li | fa9c9d1 | 2015-03-27 07:08:35 +0800 | [diff] [blame] | 431 | |
| 432 | later_rq = find_lock_later_rq(p, rq); |
Wanpeng Li | fa9c9d1 | 2015-03-27 07:08:35 +0800 | [diff] [blame] | 433 | if (!later_rq) { |
| 434 | int cpu; |
| 435 | |
| 436 | /* |
| 437 | * If we cannot preempt any rq, fall back to pick any |
| 438 | * online cpu. |
| 439 | */ |
Ingo Molnar | 0c98d34 | 2017-02-05 15:38:10 +0100 | [diff] [blame] | 440 | cpu = cpumask_any_and(cpu_active_mask, &p->cpus_allowed); |
Wanpeng Li | fa9c9d1 | 2015-03-27 07:08:35 +0800 | [diff] [blame] | 441 | if (cpu >= nr_cpu_ids) { |
| 442 | /* |
| 443 | * Fail to find any suitable cpu. |
| 444 | * The task will never come back! |
| 445 | */ |
| 446 | BUG_ON(dl_bandwidth_enabled()); |
| 447 | |
| 448 | /* |
| 449 | * If admission control is disabled we |
| 450 | * try a little harder to let the task |
| 451 | * run. |
| 452 | */ |
| 453 | cpu = cpumask_any(cpu_active_mask); |
| 454 | } |
| 455 | later_rq = cpu_rq(cpu); |
| 456 | double_lock_balance(rq, later_rq); |
| 457 | } |
| 458 | |
Wanpeng Li | fa9c9d1 | 2015-03-27 07:08:35 +0800 | [diff] [blame] | 459 | set_task_cpu(p, later_rq->cpu); |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 460 | double_unlock_balance(later_rq, rq); |
| 461 | |
| 462 | return later_rq; |
Wanpeng Li | fa9c9d1 | 2015-03-27 07:08:35 +0800 | [diff] [blame] | 463 | } |
| 464 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 465 | #else |
| 466 | |
| 467 | static inline |
| 468 | void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p) |
| 469 | { |
| 470 | } |
| 471 | |
| 472 | static inline |
| 473 | void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p) |
| 474 | { |
| 475 | } |
| 476 | |
| 477 | static inline |
| 478 | void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) |
| 479 | { |
| 480 | } |
| 481 | |
| 482 | static inline |
| 483 | void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) |
| 484 | { |
| 485 | } |
| 486 | |
Peter Zijlstra | dc87734 | 2014-02-12 15:47:29 +0100 | [diff] [blame] | 487 | static inline bool need_pull_dl_task(struct rq *rq, struct task_struct *prev) |
| 488 | { |
| 489 | return false; |
| 490 | } |
| 491 | |
Peter Zijlstra | 0ea60c2 | 2015-06-11 14:46:42 +0200 | [diff] [blame] | 492 | static inline void pull_dl_task(struct rq *rq) |
Peter Zijlstra | dc87734 | 2014-02-12 15:47:29 +0100 | [diff] [blame] | 493 | { |
Peter Zijlstra | dc87734 | 2014-02-12 15:47:29 +0100 | [diff] [blame] | 494 | } |
| 495 | |
Peter Zijlstra | e3fca9e | 2015-06-11 14:46:37 +0200 | [diff] [blame] | 496 | static inline void queue_push_tasks(struct rq *rq) |
Peter Zijlstra | dc87734 | 2014-02-12 15:47:29 +0100 | [diff] [blame] | 497 | { |
| 498 | } |
Peter Zijlstra | 9916e21 | 2015-06-11 14:46:43 +0200 | [diff] [blame] | 499 | |
| 500 | static inline void queue_pull_task(struct rq *rq) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 501 | { |
| 502 | } |
| 503 | #endif /* CONFIG_SMP */ |
| 504 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 505 | static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags); |
| 506 | static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags); |
| 507 | static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p, |
| 508 | int flags); |
| 509 | |
| 510 | /* |
| 511 | * We are being explicitly informed that a new instance is starting, |
| 512 | * and this means that: |
| 513 | * - the absolute deadline of the entity has to be placed at |
| 514 | * current time + relative deadline; |
| 515 | * - the runtime of the entity has to be set to the maximum value. |
| 516 | * |
| 517 | * The capability of specifying such event is useful whenever a -deadline |
| 518 | * entity wants to (try to!) synchronize its behaviour with the scheduler's |
| 519 | * one, and to (try to!) reconcile itself with its own scheduling |
| 520 | * parameters. |
| 521 | */ |
Juri Lelli | 98b0a85 | 2016-08-05 16:07:55 +0100 | [diff] [blame] | 522 | static inline void setup_new_dl_entity(struct sched_dl_entity *dl_se) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 523 | { |
| 524 | struct dl_rq *dl_rq = dl_rq_of_se(dl_se); |
| 525 | struct rq *rq = rq_of_dl_rq(dl_rq); |
| 526 | |
Juri Lelli | 98b0a85 | 2016-08-05 16:07:55 +0100 | [diff] [blame] | 527 | WARN_ON(dl_se->dl_boosted); |
Luca Abeni | 72f9f3f | 2016-03-07 12:27:04 +0100 | [diff] [blame] | 528 | WARN_ON(dl_time_before(rq_clock(rq), dl_se->deadline)); |
| 529 | |
| 530 | /* |
| 531 | * We are racing with the deadline timer. So, do nothing because |
| 532 | * the deadline timer handler will take care of properly recharging |
| 533 | * the runtime and postponing the deadline |
| 534 | */ |
| 535 | if (dl_se->dl_throttled) |
| 536 | return; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 537 | |
| 538 | /* |
| 539 | * We use the regular wall clock time to set deadlines in the |
| 540 | * future; in fact, we must consider execution overheads (time |
| 541 | * spent on hardirq context, etc.). |
| 542 | */ |
Juri Lelli | 98b0a85 | 2016-08-05 16:07:55 +0100 | [diff] [blame] | 543 | dl_se->deadline = rq_clock(rq) + dl_se->dl_deadline; |
| 544 | dl_se->runtime = dl_se->dl_runtime; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Pure Earliest Deadline First (EDF) scheduling does not deal with the |
| 549 | * possibility of a entity lasting more than what it declared, and thus |
| 550 | * exhausting its runtime. |
| 551 | * |
| 552 | * Here we are interested in making runtime overrun possible, but we do |
| 553 | * not want a entity which is misbehaving to affect the scheduling of all |
| 554 | * other entities. |
| 555 | * Therefore, a budgeting strategy called Constant Bandwidth Server (CBS) |
| 556 | * is used, in order to confine each entity within its own bandwidth. |
| 557 | * |
| 558 | * This function deals exactly with that, and ensures that when the runtime |
| 559 | * of a entity is replenished, its deadline is also postponed. That ensures |
| 560 | * the overrunning entity can't interfere with other entity in the system and |
| 561 | * can't make them miss their deadlines. Reasons why this kind of overruns |
| 562 | * could happen are, typically, a entity voluntarily trying to overcome its |
xiaofeng.yan | 1b09d29 | 2014-07-07 05:59:04 +0000 | [diff] [blame] | 563 | * runtime, or it just underestimated it during sched_setattr(). |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 564 | */ |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 565 | static void replenish_dl_entity(struct sched_dl_entity *dl_se, |
| 566 | struct sched_dl_entity *pi_se) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 567 | { |
| 568 | struct dl_rq *dl_rq = dl_rq_of_se(dl_se); |
| 569 | struct rq *rq = rq_of_dl_rq(dl_rq); |
| 570 | |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 571 | BUG_ON(pi_se->dl_runtime <= 0); |
| 572 | |
| 573 | /* |
| 574 | * This could be the case for a !-dl task that is boosted. |
| 575 | * Just go with full inherited parameters. |
| 576 | */ |
| 577 | if (dl_se->dl_deadline == 0) { |
| 578 | dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline; |
| 579 | dl_se->runtime = pi_se->dl_runtime; |
| 580 | } |
| 581 | |
Peter Zijlstra | 48be3a6 | 2016-02-23 13:28:22 +0100 | [diff] [blame] | 582 | if (dl_se->dl_yielded && dl_se->runtime > 0) |
| 583 | dl_se->runtime = 0; |
| 584 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 585 | /* |
| 586 | * We keep moving the deadline away until we get some |
| 587 | * available runtime for the entity. This ensures correct |
| 588 | * handling of situations where the runtime overrun is |
| 589 | * arbitrary large. |
| 590 | */ |
| 591 | while (dl_se->runtime <= 0) { |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 592 | dl_se->deadline += pi_se->dl_period; |
| 593 | dl_se->runtime += pi_se->dl_runtime; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /* |
| 597 | * At this point, the deadline really should be "in |
| 598 | * the future" with respect to rq->clock. If it's |
| 599 | * not, we are, for some reason, lagging too much! |
| 600 | * Anyway, after having warn userspace abut that, |
| 601 | * we still try to keep the things running by |
| 602 | * resetting the deadline and the budget of the |
| 603 | * entity. |
| 604 | */ |
| 605 | if (dl_time_before(dl_se->deadline, rq_clock(rq))) { |
Steven Rostedt | c219b7d | 2016-02-10 12:04:22 -0500 | [diff] [blame] | 606 | printk_deferred_once("sched: DL replenish lagged too much\n"); |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 607 | dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline; |
| 608 | dl_se->runtime = pi_se->dl_runtime; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 609 | } |
Peter Zijlstra | 1019a35 | 2014-11-26 08:44:03 +0800 | [diff] [blame] | 610 | |
| 611 | if (dl_se->dl_yielded) |
| 612 | dl_se->dl_yielded = 0; |
| 613 | if (dl_se->dl_throttled) |
| 614 | dl_se->dl_throttled = 0; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /* |
| 618 | * Here we check if --at time t-- an entity (which is probably being |
| 619 | * [re]activated or, in general, enqueued) can use its remaining runtime |
| 620 | * and its current deadline _without_ exceeding the bandwidth it is |
| 621 | * assigned (function returns true if it can't). We are in fact applying |
| 622 | * one of the CBS rules: when a task wakes up, if the residual runtime |
| 623 | * over residual deadline fits within the allocated bandwidth, then we |
| 624 | * can keep the current (absolute) deadline and residual budget without |
| 625 | * disrupting the schedulability of the system. Otherwise, we should |
| 626 | * refill the runtime and set the deadline a period in the future, |
| 627 | * because keeping the current (absolute) deadline of the task would |
Dario Faggioli | 712e5e3 | 2014-01-27 12:20:15 +0100 | [diff] [blame] | 628 | * result in breaking guarantees promised to other tasks (refer to |
| 629 | * Documentation/scheduler/sched-deadline.txt for more informations). |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 630 | * |
| 631 | * This function returns true if: |
| 632 | * |
Steven Rostedt (VMware) | 2317d5f | 2017-03-02 15:10:59 +0100 | [diff] [blame] | 633 | * runtime / (deadline - t) > dl_runtime / dl_deadline , |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 634 | * |
| 635 | * IOW we can't recycle current parameters. |
Harald Gustafsson | 755378a | 2013-11-07 14:43:40 +0100 | [diff] [blame] | 636 | * |
Steven Rostedt (VMware) | 2317d5f | 2017-03-02 15:10:59 +0100 | [diff] [blame] | 637 | * Notice that the bandwidth check is done against the deadline. For |
Harald Gustafsson | 755378a | 2013-11-07 14:43:40 +0100 | [diff] [blame] | 638 | * task with deadline equal to period this is the same of using |
Steven Rostedt (VMware) | 2317d5f | 2017-03-02 15:10:59 +0100 | [diff] [blame] | 639 | * dl_period instead of dl_deadline in the equation above. |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 640 | */ |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 641 | static bool dl_entity_overflow(struct sched_dl_entity *dl_se, |
| 642 | struct sched_dl_entity *pi_se, u64 t) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 643 | { |
| 644 | u64 left, right; |
| 645 | |
| 646 | /* |
| 647 | * left and right are the two sides of the equation above, |
| 648 | * after a bit of shuffling to use multiplications instead |
| 649 | * of divisions. |
| 650 | * |
| 651 | * Note that none of the time values involved in the two |
| 652 | * multiplications are absolute: dl_deadline and dl_runtime |
| 653 | * are the relative deadline and the maximum runtime of each |
| 654 | * instance, runtime is the runtime left for the last instance |
| 655 | * and (deadline - t), since t is rq->clock, is the time left |
| 656 | * to the (absolute) deadline. Even if overflowing the u64 type |
| 657 | * is very unlikely to occur in both cases, here we scale down |
| 658 | * as we want to avoid that risk at all. Scaling down by 10 |
| 659 | * means that we reduce granularity to 1us. We are fine with it, |
| 660 | * since this is only a true/false check and, anyway, thinking |
| 661 | * of anything below microseconds resolution is actually fiction |
| 662 | * (but still we want to give the user that illusion >;). |
| 663 | */ |
Steven Rostedt (VMware) | 2317d5f | 2017-03-02 15:10:59 +0100 | [diff] [blame] | 664 | left = (pi_se->dl_deadline >> DL_SCALE) * (dl_se->runtime >> DL_SCALE); |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 665 | right = ((dl_se->deadline - t) >> DL_SCALE) * |
| 666 | (pi_se->dl_runtime >> DL_SCALE); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 667 | |
| 668 | return dl_time_before(right, left); |
| 669 | } |
| 670 | |
| 671 | /* |
| 672 | * When a -deadline entity is queued back on the runqueue, its runtime and |
| 673 | * deadline might need updating. |
| 674 | * |
| 675 | * The policy here is that we update the deadline of the entity only if: |
| 676 | * - the current deadline is in the past, |
| 677 | * - using the remaining runtime with the current deadline would make |
| 678 | * the entity exceed its bandwidth. |
| 679 | */ |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 680 | static void update_dl_entity(struct sched_dl_entity *dl_se, |
| 681 | struct sched_dl_entity *pi_se) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 682 | { |
| 683 | struct dl_rq *dl_rq = dl_rq_of_se(dl_se); |
| 684 | struct rq *rq = rq_of_dl_rq(dl_rq); |
| 685 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 686 | if (dl_time_before(dl_se->deadline, rq_clock(rq)) || |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 687 | dl_entity_overflow(dl_se, pi_se, rq_clock(rq))) { |
| 688 | dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline; |
| 689 | dl_se->runtime = pi_se->dl_runtime; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Daniel Bristot de Oliveira | 5ac69d3 | 2017-03-02 15:10:57 +0100 | [diff] [blame] | 693 | static inline u64 dl_next_period(struct sched_dl_entity *dl_se) |
| 694 | { |
| 695 | return dl_se->deadline - dl_se->dl_deadline + dl_se->dl_period; |
| 696 | } |
| 697 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 698 | /* |
| 699 | * If the entity depleted all its runtime, and if we want it to sleep |
| 700 | * while waiting for some new execution time to become available, we |
Daniel Bristot de Oliveira | 5ac69d3 | 2017-03-02 15:10:57 +0100 | [diff] [blame] | 701 | * set the bandwidth replenishment timer to the replenishment instant |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 702 | * and try to activate it. |
| 703 | * |
| 704 | * Notice that it is important for the caller to know if the timer |
| 705 | * actually started or not (i.e., the replenishment instant is in |
| 706 | * the future or in the past). |
| 707 | */ |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 708 | static int start_dl_timer(struct task_struct *p) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 709 | { |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 710 | struct sched_dl_entity *dl_se = &p->dl; |
| 711 | struct hrtimer *timer = &dl_se->dl_timer; |
| 712 | struct rq *rq = task_rq(p); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 713 | ktime_t now, act; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 714 | s64 delta; |
| 715 | |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 716 | lockdep_assert_held(&rq->lock); |
| 717 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 718 | /* |
| 719 | * We want the timer to fire at the deadline, but considering |
| 720 | * that it is actually coming from rq->clock and not from |
| 721 | * hrtimer's time base reading. |
| 722 | */ |
Daniel Bristot de Oliveira | 5ac69d3 | 2017-03-02 15:10:57 +0100 | [diff] [blame] | 723 | act = ns_to_ktime(dl_next_period(dl_se)); |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 724 | now = hrtimer_cb_get_time(timer); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 725 | delta = ktime_to_ns(now) - rq_clock(rq); |
| 726 | act = ktime_add_ns(act, delta); |
| 727 | |
| 728 | /* |
| 729 | * If the expiry time already passed, e.g., because the value |
| 730 | * chosen as the deadline is too small, don't even try to |
| 731 | * start the timer in the past! |
| 732 | */ |
| 733 | if (ktime_us_delta(act, now) < 0) |
| 734 | return 0; |
| 735 | |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 736 | /* |
| 737 | * !enqueued will guarantee another callback; even if one is already in |
| 738 | * progress. This ensures a balanced {get,put}_task_struct(). |
| 739 | * |
| 740 | * The race against __run_timer() clearing the enqueued state is |
| 741 | * harmless because we're holding task_rq()->lock, therefore the timer |
| 742 | * expiring after we've done the check will wait on its task_rq_lock() |
| 743 | * and observe our state. |
| 744 | */ |
| 745 | if (!hrtimer_is_queued(timer)) { |
| 746 | get_task_struct(p); |
| 747 | hrtimer_start(timer, act, HRTIMER_MODE_ABS); |
| 748 | } |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 749 | |
Thomas Gleixner | cc9684d | 2015-04-14 21:09:06 +0000 | [diff] [blame] | 750 | return 1; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /* |
| 754 | * This is the bandwidth enforcement timer callback. If here, we know |
| 755 | * a task is not on its dl_rq, since the fact that the timer was running |
| 756 | * means the task is throttled and needs a runtime replenishment. |
| 757 | * |
| 758 | * However, what we actually do depends on the fact the task is active, |
| 759 | * (it is on its rq) or has been removed from there by a call to |
| 760 | * dequeue_task_dl(). In the former case we must issue the runtime |
| 761 | * replenishment and add the task back to the dl_rq; in the latter, we just |
| 762 | * do nothing but clearing dl_throttled, so that runtime and deadline |
| 763 | * updating (and the queueing back to dl_rq) will be done by the |
| 764 | * next call to enqueue_task_dl(). |
| 765 | */ |
| 766 | static enum hrtimer_restart dl_task_timer(struct hrtimer *timer) |
| 767 | { |
| 768 | struct sched_dl_entity *dl_se = container_of(timer, |
| 769 | struct sched_dl_entity, |
| 770 | dl_timer); |
| 771 | struct task_struct *p = dl_task_of(dl_se); |
Peter Zijlstra | eb58075 | 2015-07-31 21:28:18 +0200 | [diff] [blame] | 772 | struct rq_flags rf; |
Kirill Tkhai | 0f397f2 | 2014-05-20 13:33:42 +0400 | [diff] [blame] | 773 | struct rq *rq; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 774 | |
Peter Zijlstra | eb58075 | 2015-07-31 21:28:18 +0200 | [diff] [blame] | 775 | rq = task_rq_lock(p, &rf); |
Kirill Tkhai | 0f397f2 | 2014-05-20 13:33:42 +0400 | [diff] [blame] | 776 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 777 | /* |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 778 | * The task might have changed its scheduling policy to something |
Daniel Bristot de Oliveira | 9846d50 | 2016-11-08 11:15:23 +0100 | [diff] [blame] | 779 | * different than SCHED_DEADLINE (through switched_from_dl()). |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 780 | */ |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 781 | if (!dl_task(p)) |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 782 | goto unlock; |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 783 | |
| 784 | /* |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 785 | * The task might have been boosted by someone else and might be in the |
| 786 | * boosting/deboosting path, its not throttled. |
| 787 | */ |
| 788 | if (dl_se->dl_boosted) |
| 789 | goto unlock; |
| 790 | |
| 791 | /* |
| 792 | * Spurious timer due to start_dl_timer() race; or we already received |
| 793 | * a replenishment from rt_mutex_setprio(). |
| 794 | */ |
| 795 | if (!dl_se->dl_throttled) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 796 | goto unlock; |
| 797 | |
| 798 | sched_clock_tick(); |
| 799 | update_rq_clock(rq); |
Kirill Tkhai | a79ec89 | 2015-02-16 15:38:34 +0300 | [diff] [blame] | 800 | |
| 801 | /* |
| 802 | * If the throttle happened during sched-out; like: |
| 803 | * |
| 804 | * schedule() |
| 805 | * deactivate_task() |
| 806 | * dequeue_task_dl() |
| 807 | * update_curr_dl() |
| 808 | * start_dl_timer() |
| 809 | * __dequeue_task_dl() |
| 810 | * prev->on_rq = 0; |
| 811 | * |
| 812 | * We can be both throttled and !queued. Replenish the counter |
| 813 | * but do not enqueue -- wait for our wakeup to do that. |
| 814 | */ |
| 815 | if (!task_on_rq_queued(p)) { |
| 816 | replenish_dl_entity(dl_se, dl_se); |
| 817 | goto unlock; |
| 818 | } |
| 819 | |
Wanpeng Li | 61c7aca | 2016-08-31 18:27:44 +0800 | [diff] [blame] | 820 | #ifdef CONFIG_SMP |
| 821 | if (unlikely(!rq->online)) { |
| 822 | /* |
| 823 | * If the runqueue is no longer available, migrate the |
| 824 | * task elsewhere. This necessarily changes rq. |
| 825 | */ |
| 826 | lockdep_unpin_lock(&rq->lock, rf.cookie); |
| 827 | rq = dl_task_offline_migration(rq, p); |
| 828 | rf.cookie = lockdep_pin_lock(&rq->lock); |
Wanpeng Li | dcc3b5f | 2017-03-06 21:51:28 -0800 | [diff] [blame] | 829 | update_rq_clock(rq); |
Wanpeng Li | 61c7aca | 2016-08-31 18:27:44 +0800 | [diff] [blame] | 830 | |
| 831 | /* |
| 832 | * Now that the task has been migrated to the new RQ and we |
| 833 | * have that locked, proceed as normal and enqueue the task |
| 834 | * there. |
| 835 | */ |
| 836 | } |
| 837 | #endif |
| 838 | |
Peter Zijlstra | 1019a35 | 2014-11-26 08:44:03 +0800 | [diff] [blame] | 839 | enqueue_task_dl(rq, p, ENQUEUE_REPLENISH); |
| 840 | if (dl_task(rq->curr)) |
| 841 | check_preempt_curr_dl(rq, p, 0); |
| 842 | else |
| 843 | resched_curr(rq); |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 844 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 845 | #ifdef CONFIG_SMP |
Peter Zijlstra | 1019a35 | 2014-11-26 08:44:03 +0800 | [diff] [blame] | 846 | /* |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 847 | * Queueing this task back might have overloaded rq, check if we need |
| 848 | * to kick someone away. |
Peter Zijlstra | 1019a35 | 2014-11-26 08:44:03 +0800 | [diff] [blame] | 849 | */ |
Peter Zijlstra | 0aaafaa | 2015-10-23 11:50:08 +0200 | [diff] [blame] | 850 | if (has_pushable_dl_tasks(rq)) { |
| 851 | /* |
| 852 | * Nothing relies on rq->lock after this, so its safe to drop |
| 853 | * rq->lock. |
| 854 | */ |
Matt Fleming | d8ac897 | 2016-09-21 14:38:10 +0100 | [diff] [blame] | 855 | rq_unpin_lock(rq, &rf); |
Peter Zijlstra | 1019a35 | 2014-11-26 08:44:03 +0800 | [diff] [blame] | 856 | push_dl_task(rq); |
Matt Fleming | d8ac897 | 2016-09-21 14:38:10 +0100 | [diff] [blame] | 857 | rq_repin_lock(rq, &rf); |
Peter Zijlstra | 0aaafaa | 2015-10-23 11:50:08 +0200 | [diff] [blame] | 858 | } |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 859 | #endif |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 860 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 861 | unlock: |
Peter Zijlstra | eb58075 | 2015-07-31 21:28:18 +0200 | [diff] [blame] | 862 | task_rq_unlock(rq, p, &rf); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 863 | |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 864 | /* |
| 865 | * This can free the task_struct, including this hrtimer, do not touch |
| 866 | * anything related to that after this. |
| 867 | */ |
| 868 | put_task_struct(p); |
| 869 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 870 | return HRTIMER_NORESTART; |
| 871 | } |
| 872 | |
| 873 | void init_dl_task_timer(struct sched_dl_entity *dl_se) |
| 874 | { |
| 875 | struct hrtimer *timer = &dl_se->dl_timer; |
| 876 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 877 | hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 878 | timer->function = dl_task_timer; |
| 879 | } |
| 880 | |
Daniel Bristot de Oliveira | df8eac8 | 2017-03-02 15:10:58 +0100 | [diff] [blame] | 881 | /* |
| 882 | * During the activation, CBS checks if it can reuse the current task's |
| 883 | * runtime and period. If the deadline of the task is in the past, CBS |
| 884 | * cannot use the runtime, and so it replenishes the task. This rule |
| 885 | * works fine for implicit deadline tasks (deadline == period), and the |
| 886 | * CBS was designed for implicit deadline tasks. However, a task with |
| 887 | * constrained deadline (deadine < period) might be awakened after the |
| 888 | * deadline, but before the next period. In this case, replenishing the |
| 889 | * task would allow it to run for runtime / deadline. As in this case |
| 890 | * deadline < period, CBS enables a task to run for more than the |
| 891 | * runtime / period. In a very loaded system, this can cause a domino |
| 892 | * effect, making other tasks miss their deadlines. |
| 893 | * |
| 894 | * To avoid this problem, in the activation of a constrained deadline |
| 895 | * task after the deadline but before the next period, throttle the |
| 896 | * task and set the replenishing timer to the begin of the next period, |
| 897 | * unless it is boosted. |
| 898 | */ |
| 899 | static inline void dl_check_constrained_dl(struct sched_dl_entity *dl_se) |
| 900 | { |
| 901 | struct task_struct *p = dl_task_of(dl_se); |
| 902 | struct rq *rq = rq_of_dl_rq(dl_rq_of_se(dl_se)); |
| 903 | |
| 904 | if (dl_time_before(dl_se->deadline, rq_clock(rq)) && |
| 905 | dl_time_before(rq_clock(rq), dl_next_period(dl_se))) { |
| 906 | if (unlikely(dl_se->dl_boosted || !start_dl_timer(p))) |
| 907 | return; |
| 908 | dl_se->dl_throttled = 1; |
| 909 | } |
| 910 | } |
| 911 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 912 | static |
Zhiqiang Zhang | 6fab541 | 2015-06-15 11:15:20 +0800 | [diff] [blame] | 913 | int dl_runtime_exceeded(struct sched_dl_entity *dl_se) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 914 | { |
Luca Abeni | 269ad80 | 2014-12-17 11:50:32 +0100 | [diff] [blame] | 915 | return (dl_se->runtime <= 0); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 916 | } |
| 917 | |
Juri Lelli | faa5993 | 2014-02-21 11:37:15 +0100 | [diff] [blame] | 918 | extern bool sched_rt_bandwidth_account(struct rt_rq *rt_rq); |
| 919 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 920 | /* |
Luca Abeni | c52f14d | 2017-05-18 22:13:31 +0200 | [diff] [blame^] | 921 | * This function implements the GRUB accounting rule: |
| 922 | * according to the GRUB reclaiming algorithm, the runtime is |
| 923 | * not decreased as "dq = -dt", but as "dq = -Uact dt", where |
| 924 | * Uact is the (per-runqueue) active utilization. |
| 925 | * Since rq->dl.running_bw contains Uact * 2^BW_SHIFT, the result |
| 926 | * has to be shifted right by BW_SHIFT. |
| 927 | */ |
| 928 | u64 grub_reclaim(u64 delta, struct rq *rq) |
| 929 | { |
| 930 | delta *= rq->dl.running_bw; |
| 931 | delta >>= BW_SHIFT; |
| 932 | |
| 933 | return delta; |
| 934 | } |
| 935 | |
| 936 | /* |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 937 | * Update the current task's runtime statistics (provided it is still |
| 938 | * a -deadline task and has not been removed from the dl_rq). |
| 939 | */ |
| 940 | static void update_curr_dl(struct rq *rq) |
| 941 | { |
| 942 | struct task_struct *curr = rq->curr; |
| 943 | struct sched_dl_entity *dl_se = &curr->dl; |
| 944 | u64 delta_exec; |
| 945 | |
| 946 | if (!dl_task(curr) || !on_dl_rq(dl_se)) |
| 947 | return; |
| 948 | |
| 949 | /* |
| 950 | * Consumed budget is computed considering the time as |
| 951 | * observed by schedulable tasks (excluding time spent |
| 952 | * in hardirq context, etc.). Deadlines are instead |
| 953 | * computed using hard walltime. This seems to be the more |
| 954 | * natural solution, but the full ramifications of this |
| 955 | * approach need further study. |
| 956 | */ |
| 957 | delta_exec = rq_clock_task(rq) - curr->se.exec_start; |
Peter Zijlstra | 48be3a6 | 2016-02-23 13:28:22 +0100 | [diff] [blame] | 958 | if (unlikely((s64)delta_exec <= 0)) { |
| 959 | if (unlikely(dl_se->dl_yielded)) |
| 960 | goto throttle; |
Kirill Tkhai | 734ff2a | 2014-03-04 19:25:46 +0400 | [diff] [blame] | 961 | return; |
Peter Zijlstra | 48be3a6 | 2016-02-23 13:28:22 +0100 | [diff] [blame] | 962 | } |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 963 | |
Rafael J. Wysocki | 58919e8 | 2016-08-16 22:14:55 +0200 | [diff] [blame] | 964 | /* kick cpufreq (see the comment in kernel/sched/sched.h). */ |
Rafael J. Wysocki | 12bde33 | 2016-08-10 03:11:17 +0200 | [diff] [blame] | 965 | cpufreq_update_this_cpu(rq, SCHED_CPUFREQ_DL); |
Wanpeng Li | 594dd29 | 2016-04-22 17:07:24 +0800 | [diff] [blame] | 966 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 967 | schedstat_set(curr->se.statistics.exec_max, |
| 968 | max(curr->se.statistics.exec_max, delta_exec)); |
| 969 | |
| 970 | curr->se.sum_exec_runtime += delta_exec; |
| 971 | account_group_exec_runtime(curr, delta_exec); |
| 972 | |
| 973 | curr->se.exec_start = rq_clock_task(rq); |
| 974 | cpuacct_charge(curr, delta_exec); |
| 975 | |
Dario Faggioli | 239be4a | 2013-11-07 14:43:39 +0100 | [diff] [blame] | 976 | sched_rt_avg_update(rq, delta_exec); |
| 977 | |
Luca Abeni | c52f14d | 2017-05-18 22:13:31 +0200 | [diff] [blame^] | 978 | delta_exec = grub_reclaim(delta_exec, rq); |
Peter Zijlstra | 48be3a6 | 2016-02-23 13:28:22 +0100 | [diff] [blame] | 979 | dl_se->runtime -= delta_exec; |
| 980 | |
| 981 | throttle: |
| 982 | if (dl_runtime_exceeded(dl_se) || dl_se->dl_yielded) { |
Peter Zijlstra | 1019a35 | 2014-11-26 08:44:03 +0800 | [diff] [blame] | 983 | dl_se->dl_throttled = 1; |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 984 | __dequeue_task_dl(rq, curr, 0); |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 985 | if (unlikely(dl_se->dl_boosted || !start_dl_timer(curr))) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 986 | enqueue_task_dl(rq, curr, ENQUEUE_REPLENISH); |
| 987 | |
| 988 | if (!is_leftmost(curr, &rq->dl)) |
Kirill Tkhai | 8875125 | 2014-06-29 00:03:57 +0400 | [diff] [blame] | 989 | resched_curr(rq); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 990 | } |
Peter Zijlstra | 1724813 | 2013-12-17 12:44:49 +0100 | [diff] [blame] | 991 | |
| 992 | /* |
| 993 | * Because -- for now -- we share the rt bandwidth, we need to |
| 994 | * account our runtime there too, otherwise actual rt tasks |
| 995 | * would be able to exceed the shared quota. |
| 996 | * |
| 997 | * Account to the root rt group for now. |
| 998 | * |
| 999 | * The solution we're working towards is having the RT groups scheduled |
| 1000 | * using deadline servers -- however there's a few nasties to figure |
| 1001 | * out before that can happen. |
| 1002 | */ |
| 1003 | if (rt_bandwidth_enabled()) { |
| 1004 | struct rt_rq *rt_rq = &rq->rt; |
| 1005 | |
| 1006 | raw_spin_lock(&rt_rq->rt_runtime_lock); |
Peter Zijlstra | 1724813 | 2013-12-17 12:44:49 +0100 | [diff] [blame] | 1007 | /* |
| 1008 | * We'll let actual RT tasks worry about the overflow here, we |
Juri Lelli | faa5993 | 2014-02-21 11:37:15 +0100 | [diff] [blame] | 1009 | * have our own CBS to keep us inline; only account when RT |
| 1010 | * bandwidth is relevant. |
Peter Zijlstra | 1724813 | 2013-12-17 12:44:49 +0100 | [diff] [blame] | 1011 | */ |
Juri Lelli | faa5993 | 2014-02-21 11:37:15 +0100 | [diff] [blame] | 1012 | if (sched_rt_bandwidth_account(rt_rq)) |
| 1013 | rt_rq->rt_time += delta_exec; |
Peter Zijlstra | 1724813 | 2013-12-17 12:44:49 +0100 | [diff] [blame] | 1014 | raw_spin_unlock(&rt_rq->rt_runtime_lock); |
| 1015 | } |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 1018 | static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer) |
| 1019 | { |
| 1020 | struct sched_dl_entity *dl_se = container_of(timer, |
| 1021 | struct sched_dl_entity, |
| 1022 | inactive_timer); |
| 1023 | struct task_struct *p = dl_task_of(dl_se); |
| 1024 | struct rq_flags rf; |
| 1025 | struct rq *rq; |
| 1026 | |
| 1027 | rq = task_rq_lock(p, &rf); |
| 1028 | |
| 1029 | if (!dl_task(p) || p->state == TASK_DEAD) { |
Luca Abeni | 387e313 | 2017-05-18 22:13:30 +0200 | [diff] [blame] | 1030 | struct dl_bw *dl_b = dl_bw_of(task_cpu(p)); |
| 1031 | |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 1032 | if (p->state == TASK_DEAD && dl_se->dl_non_contending) { |
| 1033 | sub_running_bw(p->dl.dl_bw, dl_rq_of_se(&p->dl)); |
| 1034 | dl_se->dl_non_contending = 0; |
| 1035 | } |
Luca Abeni | 387e313 | 2017-05-18 22:13:30 +0200 | [diff] [blame] | 1036 | |
| 1037 | raw_spin_lock(&dl_b->lock); |
| 1038 | __dl_clear(dl_b, p->dl.dl_bw); |
| 1039 | raw_spin_unlock(&dl_b->lock); |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 1040 | __dl_clear_params(p); |
| 1041 | |
| 1042 | goto unlock; |
| 1043 | } |
| 1044 | if (dl_se->dl_non_contending == 0) |
| 1045 | goto unlock; |
| 1046 | |
| 1047 | sched_clock_tick(); |
| 1048 | update_rq_clock(rq); |
| 1049 | |
| 1050 | sub_running_bw(dl_se->dl_bw, &rq->dl); |
| 1051 | dl_se->dl_non_contending = 0; |
| 1052 | unlock: |
| 1053 | task_rq_unlock(rq, p, &rf); |
| 1054 | put_task_struct(p); |
| 1055 | |
| 1056 | return HRTIMER_NORESTART; |
| 1057 | } |
| 1058 | |
| 1059 | void init_dl_inactive_task_timer(struct sched_dl_entity *dl_se) |
| 1060 | { |
| 1061 | struct hrtimer *timer = &dl_se->inactive_timer; |
| 1062 | |
| 1063 | hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 1064 | timer->function = inactive_task_timer; |
| 1065 | } |
| 1066 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1067 | #ifdef CONFIG_SMP |
| 1068 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1069 | static void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline) |
| 1070 | { |
| 1071 | struct rq *rq = rq_of_dl_rq(dl_rq); |
| 1072 | |
| 1073 | if (dl_rq->earliest_dl.curr == 0 || |
| 1074 | dl_time_before(deadline, dl_rq->earliest_dl.curr)) { |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1075 | dl_rq->earliest_dl.curr = deadline; |
Tommaso Cucinotta | d8206bb | 2016-08-14 16:27:08 +0200 | [diff] [blame] | 1076 | cpudl_set(&rq->rd->cpudl, rq->cpu, deadline); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | static void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline) |
| 1081 | { |
| 1082 | struct rq *rq = rq_of_dl_rq(dl_rq); |
| 1083 | |
| 1084 | /* |
| 1085 | * Since we may have removed our earliest (and/or next earliest) |
| 1086 | * task we must recompute them. |
| 1087 | */ |
| 1088 | if (!dl_rq->dl_nr_running) { |
| 1089 | dl_rq->earliest_dl.curr = 0; |
| 1090 | dl_rq->earliest_dl.next = 0; |
Tommaso Cucinotta | d8206bb | 2016-08-14 16:27:08 +0200 | [diff] [blame] | 1091 | cpudl_clear(&rq->rd->cpudl, rq->cpu); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1092 | } else { |
| 1093 | struct rb_node *leftmost = dl_rq->rb_leftmost; |
| 1094 | struct sched_dl_entity *entry; |
| 1095 | |
| 1096 | entry = rb_entry(leftmost, struct sched_dl_entity, rb_node); |
| 1097 | dl_rq->earliest_dl.curr = entry->deadline; |
Tommaso Cucinotta | d8206bb | 2016-08-14 16:27:08 +0200 | [diff] [blame] | 1098 | cpudl_set(&rq->rd->cpudl, rq->cpu, entry->deadline); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | #else |
| 1103 | |
| 1104 | static inline void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {} |
| 1105 | static inline void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {} |
| 1106 | |
| 1107 | #endif /* CONFIG_SMP */ |
| 1108 | |
| 1109 | static inline |
| 1110 | void inc_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) |
| 1111 | { |
| 1112 | int prio = dl_task_of(dl_se)->prio; |
| 1113 | u64 deadline = dl_se->deadline; |
| 1114 | |
| 1115 | WARN_ON(!dl_prio(prio)); |
| 1116 | dl_rq->dl_nr_running++; |
Kirill Tkhai | 7246544 | 2014-05-09 03:00:14 +0400 | [diff] [blame] | 1117 | add_nr_running(rq_of_dl_rq(dl_rq), 1); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1118 | |
| 1119 | inc_dl_deadline(dl_rq, deadline); |
| 1120 | inc_dl_migration(dl_se, dl_rq); |
| 1121 | } |
| 1122 | |
| 1123 | static inline |
| 1124 | void dec_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) |
| 1125 | { |
| 1126 | int prio = dl_task_of(dl_se)->prio; |
| 1127 | |
| 1128 | WARN_ON(!dl_prio(prio)); |
| 1129 | WARN_ON(!dl_rq->dl_nr_running); |
| 1130 | dl_rq->dl_nr_running--; |
Kirill Tkhai | 7246544 | 2014-05-09 03:00:14 +0400 | [diff] [blame] | 1131 | sub_nr_running(rq_of_dl_rq(dl_rq), 1); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1132 | |
| 1133 | dec_dl_deadline(dl_rq, dl_se->deadline); |
| 1134 | dec_dl_migration(dl_se, dl_rq); |
| 1135 | } |
| 1136 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1137 | static void __enqueue_dl_entity(struct sched_dl_entity *dl_se) |
| 1138 | { |
| 1139 | struct dl_rq *dl_rq = dl_rq_of_se(dl_se); |
| 1140 | struct rb_node **link = &dl_rq->rb_root.rb_node; |
| 1141 | struct rb_node *parent = NULL; |
| 1142 | struct sched_dl_entity *entry; |
| 1143 | int leftmost = 1; |
| 1144 | |
| 1145 | BUG_ON(!RB_EMPTY_NODE(&dl_se->rb_node)); |
| 1146 | |
| 1147 | while (*link) { |
| 1148 | parent = *link; |
| 1149 | entry = rb_entry(parent, struct sched_dl_entity, rb_node); |
| 1150 | if (dl_time_before(dl_se->deadline, entry->deadline)) |
| 1151 | link = &parent->rb_left; |
| 1152 | else { |
| 1153 | link = &parent->rb_right; |
| 1154 | leftmost = 0; |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | if (leftmost) |
| 1159 | dl_rq->rb_leftmost = &dl_se->rb_node; |
| 1160 | |
| 1161 | rb_link_node(&dl_se->rb_node, parent, link); |
| 1162 | rb_insert_color(&dl_se->rb_node, &dl_rq->rb_root); |
| 1163 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1164 | inc_dl_tasks(dl_se, dl_rq); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | static void __dequeue_dl_entity(struct sched_dl_entity *dl_se) |
| 1168 | { |
| 1169 | struct dl_rq *dl_rq = dl_rq_of_se(dl_se); |
| 1170 | |
| 1171 | if (RB_EMPTY_NODE(&dl_se->rb_node)) |
| 1172 | return; |
| 1173 | |
| 1174 | if (dl_rq->rb_leftmost == &dl_se->rb_node) { |
| 1175 | struct rb_node *next_node; |
| 1176 | |
| 1177 | next_node = rb_next(&dl_se->rb_node); |
| 1178 | dl_rq->rb_leftmost = next_node; |
| 1179 | } |
| 1180 | |
| 1181 | rb_erase(&dl_se->rb_node, &dl_rq->rb_root); |
| 1182 | RB_CLEAR_NODE(&dl_se->rb_node); |
| 1183 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1184 | dec_dl_tasks(dl_se, dl_rq); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | static void |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 1188 | enqueue_dl_entity(struct sched_dl_entity *dl_se, |
| 1189 | struct sched_dl_entity *pi_se, int flags) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1190 | { |
| 1191 | BUG_ON(on_dl_rq(dl_se)); |
| 1192 | |
| 1193 | /* |
| 1194 | * If this is a wakeup or a new instance, the scheduling |
| 1195 | * parameters of the task might need updating. Otherwise, |
| 1196 | * we want a replenishment of its runtime. |
| 1197 | */ |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1198 | if (flags & ENQUEUE_WAKEUP) { |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 1199 | task_contending(dl_se); |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 1200 | update_dl_entity(dl_se, pi_se); |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1201 | } else if (flags & ENQUEUE_REPLENISH) { |
Luca Abeni | 6a503c3 | 2014-12-17 11:50:31 +0100 | [diff] [blame] | 1202 | replenish_dl_entity(dl_se, pi_se); |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1203 | } |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1204 | |
| 1205 | __enqueue_dl_entity(dl_se); |
| 1206 | } |
| 1207 | |
| 1208 | static void dequeue_dl_entity(struct sched_dl_entity *dl_se) |
| 1209 | { |
| 1210 | __dequeue_dl_entity(dl_se); |
| 1211 | } |
| 1212 | |
Daniel Bristot de Oliveira | df8eac8 | 2017-03-02 15:10:58 +0100 | [diff] [blame] | 1213 | static inline bool dl_is_constrained(struct sched_dl_entity *dl_se) |
| 1214 | { |
| 1215 | return dl_se->dl_deadline < dl_se->dl_period; |
| 1216 | } |
| 1217 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1218 | static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags) |
| 1219 | { |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 1220 | struct task_struct *pi_task = rt_mutex_get_top_task(p); |
| 1221 | struct sched_dl_entity *pi_se = &p->dl; |
| 1222 | |
| 1223 | /* |
| 1224 | * Use the scheduling parameters of the top pi-waiter |
Andrea Parri | ff277d4 | 2015-08-05 15:56:19 +0200 | [diff] [blame] | 1225 | * task if we have one and its (absolute) deadline is |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 1226 | * smaller than our one... OTW we keep our runtime and |
| 1227 | * deadline. |
| 1228 | */ |
Juri Lelli | 64be6f1 | 2014-10-24 10:16:37 +0100 | [diff] [blame] | 1229 | if (pi_task && p->dl.dl_boosted && dl_prio(pi_task->normal_prio)) { |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 1230 | pi_se = &pi_task->dl; |
Juri Lelli | 64be6f1 | 2014-10-24 10:16:37 +0100 | [diff] [blame] | 1231 | } else if (!dl_prio(p->normal_prio)) { |
| 1232 | /* |
| 1233 | * Special case in which we have a !SCHED_DEADLINE task |
| 1234 | * that is going to be deboosted, but exceedes its |
| 1235 | * runtime while doing so. No point in replenishing |
| 1236 | * it, as it's going to return back to its original |
| 1237 | * scheduling class after this. |
| 1238 | */ |
| 1239 | BUG_ON(!p->dl.dl_boosted || flags != ENQUEUE_REPLENISH); |
| 1240 | return; |
| 1241 | } |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 1242 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1243 | /* |
Daniel Bristot de Oliveira | df8eac8 | 2017-03-02 15:10:58 +0100 | [diff] [blame] | 1244 | * Check if a constrained deadline task was activated |
| 1245 | * after the deadline but before the next period. |
| 1246 | * If that is the case, the task will be throttled and |
| 1247 | * the replenishment timer will be set to the next period. |
| 1248 | */ |
| 1249 | if (!p->dl.dl_throttled && dl_is_constrained(&p->dl)) |
| 1250 | dl_check_constrained_dl(&p->dl); |
| 1251 | |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1252 | if (p->on_rq == TASK_ON_RQ_MIGRATING || flags & ENQUEUE_RESTORE) |
| 1253 | add_running_bw(p->dl.dl_bw, &rq->dl); |
| 1254 | |
Daniel Bristot de Oliveira | df8eac8 | 2017-03-02 15:10:58 +0100 | [diff] [blame] | 1255 | /* |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1256 | * If p is throttled, we do not enqueue it. In fact, if it exhausted |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1257 | * its budget it needs a replenishment and, since it now is on |
| 1258 | * its rq, the bandwidth timer callback (which clearly has not |
| 1259 | * run yet) will take care of this. |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1260 | * However, the active utilization does not depend on the fact |
| 1261 | * that the task is on the runqueue or not (but depends on the |
| 1262 | * task's state - in GRUB parlance, "inactive" vs "active contending"). |
| 1263 | * In other words, even if a task is throttled its utilization must |
| 1264 | * be counted in the active utilization; hence, we need to call |
| 1265 | * add_running_bw(). |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1266 | */ |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1267 | if (p->dl.dl_throttled && !(flags & ENQUEUE_REPLENISH)) { |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 1268 | if (flags & ENQUEUE_WAKEUP) |
| 1269 | task_contending(&p->dl); |
| 1270 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1271 | return; |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1272 | } |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1273 | |
Dario Faggioli | 2d3d891 | 2013-11-07 14:43:44 +0100 | [diff] [blame] | 1274 | enqueue_dl_entity(&p->dl, pi_se, flags); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1275 | |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1276 | if (!task_current(rq, p) && p->nr_cpus_allowed > 1) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1277 | enqueue_pushable_dl_task(rq, p); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) |
| 1281 | { |
| 1282 | dequeue_dl_entity(&p->dl); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1283 | dequeue_pushable_dl_task(rq, p); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) |
| 1287 | { |
| 1288 | update_curr_dl(rq); |
| 1289 | __dequeue_task_dl(rq, p, flags); |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1290 | |
| 1291 | if (p->on_rq == TASK_ON_RQ_MIGRATING || flags & DEQUEUE_SAVE) |
| 1292 | sub_running_bw(p->dl.dl_bw, &rq->dl); |
| 1293 | |
| 1294 | /* |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 1295 | * This check allows to start the inactive timer (or to immediately |
| 1296 | * decrease the active utilization, if needed) in two cases: |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1297 | * when the task blocks and when it is terminating |
| 1298 | * (p->state == TASK_DEAD). We can handle the two cases in the same |
| 1299 | * way, because from GRUB's point of view the same thing is happening |
| 1300 | * (the task moves from "active contending" to "active non contending" |
| 1301 | * or "inactive") |
| 1302 | */ |
| 1303 | if (flags & DEQUEUE_SLEEP) |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 1304 | task_non_contending(p); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | /* |
| 1308 | * Yield task semantic for -deadline tasks is: |
| 1309 | * |
| 1310 | * get off from the CPU until our next instance, with |
| 1311 | * a new runtime. This is of little use now, since we |
| 1312 | * don't have a bandwidth reclaiming mechanism. Anyway, |
| 1313 | * bandwidth reclaiming is planned for the future, and |
| 1314 | * yield_task_dl will indicate that some spare budget |
| 1315 | * is available for other task instances to use it. |
| 1316 | */ |
| 1317 | static void yield_task_dl(struct rq *rq) |
| 1318 | { |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1319 | /* |
| 1320 | * We make the task go to sleep until its current deadline by |
| 1321 | * forcing its runtime to zero. This way, update_curr_dl() stops |
| 1322 | * it and the bandwidth timer will wake it up and will give it |
Juri Lelli | 5bfd126 | 2014-04-15 13:49:04 +0200 | [diff] [blame] | 1323 | * new scheduling parameters (thanks to dl_yielded=1). |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1324 | */ |
Peter Zijlstra | 48be3a6 | 2016-02-23 13:28:22 +0100 | [diff] [blame] | 1325 | rq->curr->dl.dl_yielded = 1; |
| 1326 | |
Kirill Tkhai | 6f1607f | 2015-02-04 12:09:32 +0300 | [diff] [blame] | 1327 | update_rq_clock(rq); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1328 | update_curr_dl(rq); |
Wanpeng Li | 44fb085 | 2015-03-10 12:20:00 +0800 | [diff] [blame] | 1329 | /* |
| 1330 | * Tell update_rq_clock() that we've just updated, |
| 1331 | * so we don't do microscopic update in schedule() |
| 1332 | * and double the fastpath cost. |
| 1333 | */ |
| 1334 | rq_clock_skip_update(rq, true); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1335 | } |
| 1336 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1337 | #ifdef CONFIG_SMP |
| 1338 | |
| 1339 | static int find_later_rq(struct task_struct *task); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1340 | |
| 1341 | static int |
| 1342 | select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags) |
| 1343 | { |
| 1344 | struct task_struct *curr; |
| 1345 | struct rq *rq; |
| 1346 | |
Wanpeng Li | 1d7e974 | 2014-10-14 10:22:39 +0800 | [diff] [blame] | 1347 | if (sd_flag != SD_BALANCE_WAKE) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1348 | goto out; |
| 1349 | |
| 1350 | rq = cpu_rq(cpu); |
| 1351 | |
| 1352 | rcu_read_lock(); |
Jason Low | 316c1608d | 2015-04-28 13:00:20 -0700 | [diff] [blame] | 1353 | curr = READ_ONCE(rq->curr); /* unlocked access */ |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1354 | |
| 1355 | /* |
| 1356 | * If we are dealing with a -deadline task, we must |
| 1357 | * decide where to wake it up. |
| 1358 | * If it has a later deadline and the current task |
| 1359 | * on this rq can't move (provided the waking task |
| 1360 | * can!) we prefer to send it somewhere else. On the |
| 1361 | * other hand, if it has a shorter deadline, we |
| 1362 | * try to make it stay here, it might be important. |
| 1363 | */ |
| 1364 | if (unlikely(dl_task(curr)) && |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1365 | (curr->nr_cpus_allowed < 2 || |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1366 | !dl_entity_preempt(&p->dl, &curr->dl)) && |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1367 | (p->nr_cpus_allowed > 1)) { |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1368 | int target = find_later_rq(p); |
| 1369 | |
Wanpeng Li | 9d51426 | 2015-05-13 14:01:03 +0800 | [diff] [blame] | 1370 | if (target != -1 && |
Luca Abeni | 5aa5050 | 2015-10-16 10:06:21 +0200 | [diff] [blame] | 1371 | (dl_time_before(p->dl.deadline, |
| 1372 | cpu_rq(target)->dl.earliest_dl.curr) || |
| 1373 | (cpu_rq(target)->dl.dl_nr_running == 0))) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1374 | cpu = target; |
| 1375 | } |
| 1376 | rcu_read_unlock(); |
| 1377 | |
| 1378 | out: |
| 1379 | return cpu; |
| 1380 | } |
| 1381 | |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 1382 | static void migrate_task_rq_dl(struct task_struct *p) |
| 1383 | { |
| 1384 | struct rq *rq; |
| 1385 | |
| 1386 | if (!(p->state == TASK_WAKING) || !(p->dl.dl_non_contending)) |
| 1387 | return; |
| 1388 | |
| 1389 | rq = task_rq(p); |
| 1390 | /* |
| 1391 | * Since p->state == TASK_WAKING, set_task_cpu() has been called |
| 1392 | * from try_to_wake_up(). Hence, p->pi_lock is locked, but |
| 1393 | * rq->lock is not... So, lock it |
| 1394 | */ |
| 1395 | raw_spin_lock(&rq->lock); |
| 1396 | sub_running_bw(p->dl.dl_bw, &rq->dl); |
| 1397 | p->dl.dl_non_contending = 0; |
| 1398 | /* |
| 1399 | * If the timer handler is currently running and the |
| 1400 | * timer cannot be cancelled, inactive_task_timer() |
| 1401 | * will see that dl_not_contending is not set, and |
| 1402 | * will not touch the rq's active utilization, |
| 1403 | * so we are still safe. |
| 1404 | */ |
| 1405 | if (hrtimer_try_to_cancel(&p->dl.inactive_timer) == 1) |
| 1406 | put_task_struct(p); |
| 1407 | |
| 1408 | raw_spin_unlock(&rq->lock); |
| 1409 | } |
| 1410 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1411 | static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p) |
| 1412 | { |
| 1413 | /* |
| 1414 | * Current can't be migrated, useless to reschedule, |
| 1415 | * let's hope p can move out. |
| 1416 | */ |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1417 | if (rq->curr->nr_cpus_allowed == 1 || |
Juri Lelli | 6bfd6d7 | 2013-11-07 14:43:47 +0100 | [diff] [blame] | 1418 | cpudl_find(&rq->rd->cpudl, rq->curr, NULL) == -1) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1419 | return; |
| 1420 | |
| 1421 | /* |
| 1422 | * p is migratable, so let's not schedule it and |
| 1423 | * see if it is pushed or pulled somewhere else. |
| 1424 | */ |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1425 | if (p->nr_cpus_allowed != 1 && |
Juri Lelli | 6bfd6d7 | 2013-11-07 14:43:47 +0100 | [diff] [blame] | 1426 | cpudl_find(&rq->rd->cpudl, p, NULL) != -1) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1427 | return; |
| 1428 | |
Kirill Tkhai | 8875125 | 2014-06-29 00:03:57 +0400 | [diff] [blame] | 1429 | resched_curr(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | #endif /* CONFIG_SMP */ |
| 1433 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1434 | /* |
| 1435 | * Only called when both the current and waking task are -deadline |
| 1436 | * tasks. |
| 1437 | */ |
| 1438 | static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p, |
| 1439 | int flags) |
| 1440 | { |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1441 | if (dl_entity_preempt(&p->dl, &rq->curr->dl)) { |
Kirill Tkhai | 8875125 | 2014-06-29 00:03:57 +0400 | [diff] [blame] | 1442 | resched_curr(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1443 | return; |
| 1444 | } |
| 1445 | |
| 1446 | #ifdef CONFIG_SMP |
| 1447 | /* |
| 1448 | * In the unlikely case current and p have the same deadline |
| 1449 | * let us try to decide what's the best thing to do... |
| 1450 | */ |
Dario Faggioli | 332ac17 | 2013-11-07 14:43:45 +0100 | [diff] [blame] | 1451 | if ((p->dl.deadline == rq->curr->dl.deadline) && |
| 1452 | !test_tsk_need_resched(rq->curr)) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1453 | check_preempt_equal_dl(rq, p); |
| 1454 | #endif /* CONFIG_SMP */ |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | #ifdef CONFIG_SCHED_HRTICK |
| 1458 | static void start_hrtick_dl(struct rq *rq, struct task_struct *p) |
| 1459 | { |
xiaofeng.yan | 177ef2a | 2014-08-26 03:15:41 +0000 | [diff] [blame] | 1460 | hrtick_start(rq, p->dl.runtime); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1461 | } |
Wanpeng Li | 36ce988 | 2014-11-11 09:52:26 +0800 | [diff] [blame] | 1462 | #else /* !CONFIG_SCHED_HRTICK */ |
| 1463 | static void start_hrtick_dl(struct rq *rq, struct task_struct *p) |
| 1464 | { |
| 1465 | } |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1466 | #endif |
| 1467 | |
| 1468 | static struct sched_dl_entity *pick_next_dl_entity(struct rq *rq, |
| 1469 | struct dl_rq *dl_rq) |
| 1470 | { |
| 1471 | struct rb_node *left = dl_rq->rb_leftmost; |
| 1472 | |
| 1473 | if (!left) |
| 1474 | return NULL; |
| 1475 | |
| 1476 | return rb_entry(left, struct sched_dl_entity, rb_node); |
| 1477 | } |
| 1478 | |
Peter Zijlstra | e7904a2 | 2015-08-01 19:25:08 +0200 | [diff] [blame] | 1479 | struct task_struct * |
Matt Fleming | d8ac897 | 2016-09-21 14:38:10 +0100 | [diff] [blame] | 1480 | pick_next_task_dl(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1481 | { |
| 1482 | struct sched_dl_entity *dl_se; |
| 1483 | struct task_struct *p; |
| 1484 | struct dl_rq *dl_rq; |
| 1485 | |
| 1486 | dl_rq = &rq->dl; |
| 1487 | |
Kirill Tkhai | a1d9a32 | 2014-04-10 17:38:36 +0400 | [diff] [blame] | 1488 | if (need_pull_dl_task(rq, prev)) { |
Peter Zijlstra | cbce1a6 | 2015-06-11 14:46:54 +0200 | [diff] [blame] | 1489 | /* |
| 1490 | * This is OK, because current is on_cpu, which avoids it being |
| 1491 | * picked for load-balance and preemption/IRQs are still |
| 1492 | * disabled avoiding further scheduler activity on it and we're |
| 1493 | * being very careful to re-start the picking loop. |
| 1494 | */ |
Matt Fleming | d8ac897 | 2016-09-21 14:38:10 +0100 | [diff] [blame] | 1495 | rq_unpin_lock(rq, rf); |
Peter Zijlstra | 38033c3 | 2014-01-23 20:32:21 +0100 | [diff] [blame] | 1496 | pull_dl_task(rq); |
Matt Fleming | d8ac897 | 2016-09-21 14:38:10 +0100 | [diff] [blame] | 1497 | rq_repin_lock(rq, rf); |
Kirill Tkhai | a1d9a32 | 2014-04-10 17:38:36 +0400 | [diff] [blame] | 1498 | /* |
T.Zhou | 176cedc | 2016-11-23 08:48:32 +0800 | [diff] [blame] | 1499 | * pull_dl_task() can drop (and re-acquire) rq->lock; this |
Kirill Tkhai | a1d9a32 | 2014-04-10 17:38:36 +0400 | [diff] [blame] | 1500 | * means a stop task can slip in, in which case we need to |
| 1501 | * re-start task selection. |
| 1502 | */ |
Kirill Tkhai | da0c1e6 | 2014-08-20 13:47:32 +0400 | [diff] [blame] | 1503 | if (rq->stop && task_on_rq_queued(rq->stop)) |
Kirill Tkhai | a1d9a32 | 2014-04-10 17:38:36 +0400 | [diff] [blame] | 1504 | return RETRY_TASK; |
| 1505 | } |
| 1506 | |
Kirill Tkhai | 734ff2a | 2014-03-04 19:25:46 +0400 | [diff] [blame] | 1507 | /* |
| 1508 | * When prev is DL, we may throttle it in put_prev_task(). |
| 1509 | * So, we update time before we check for dl_nr_running. |
| 1510 | */ |
| 1511 | if (prev->sched_class == &dl_sched_class) |
| 1512 | update_curr_dl(rq); |
Peter Zijlstra | 38033c3 | 2014-01-23 20:32:21 +0100 | [diff] [blame] | 1513 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1514 | if (unlikely(!dl_rq->dl_nr_running)) |
| 1515 | return NULL; |
| 1516 | |
Peter Zijlstra | 3f1d2a3 | 2014-02-12 10:49:30 +0100 | [diff] [blame] | 1517 | put_prev_task(rq, prev); |
Peter Zijlstra | 606dba2 | 2012-02-11 06:05:00 +0100 | [diff] [blame] | 1518 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1519 | dl_se = pick_next_dl_entity(rq, dl_rq); |
| 1520 | BUG_ON(!dl_se); |
| 1521 | |
| 1522 | p = dl_task_of(dl_se); |
| 1523 | p->se.exec_start = rq_clock_task(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1524 | |
| 1525 | /* Running task will never be pushed. */ |
Juri Lelli | 7136265 | 2014-01-14 12:03:51 +0100 | [diff] [blame] | 1526 | dequeue_pushable_dl_task(rq, p); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1527 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1528 | if (hrtick_enabled(rq)) |
| 1529 | start_hrtick_dl(rq, p); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1530 | |
Peter Zijlstra | e3fca9e | 2015-06-11 14:46:37 +0200 | [diff] [blame] | 1531 | queue_push_tasks(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1532 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1533 | return p; |
| 1534 | } |
| 1535 | |
| 1536 | static void put_prev_task_dl(struct rq *rq, struct task_struct *p) |
| 1537 | { |
| 1538 | update_curr_dl(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1539 | |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1540 | if (on_dl_rq(&p->dl) && p->nr_cpus_allowed > 1) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1541 | enqueue_pushable_dl_task(rq, p); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | static void task_tick_dl(struct rq *rq, struct task_struct *p, int queued) |
| 1545 | { |
| 1546 | update_curr_dl(rq); |
| 1547 | |
Wanpeng Li | a7bebf4 | 2014-11-26 08:44:01 +0800 | [diff] [blame] | 1548 | /* |
| 1549 | * Even when we have runtime, update_curr_dl() might have resulted in us |
| 1550 | * not being the leftmost task anymore. In that case NEED_RESCHED will |
| 1551 | * be set and schedule() will start a new hrtick for the next task. |
| 1552 | */ |
| 1553 | if (hrtick_enabled(rq) && queued && p->dl.runtime > 0 && |
| 1554 | is_leftmost(p, &rq->dl)) |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1555 | start_hrtick_dl(rq, p); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | static void task_fork_dl(struct task_struct *p) |
| 1559 | { |
| 1560 | /* |
| 1561 | * SCHED_DEADLINE tasks cannot fork and this is achieved through |
| 1562 | * sched_fork() |
| 1563 | */ |
| 1564 | } |
| 1565 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1566 | static void set_curr_task_dl(struct rq *rq) |
| 1567 | { |
| 1568 | struct task_struct *p = rq->curr; |
| 1569 | |
| 1570 | p->se.exec_start = rq_clock_task(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1571 | |
| 1572 | /* You can't push away the running task */ |
| 1573 | dequeue_pushable_dl_task(rq, p); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 1574 | } |
| 1575 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1576 | #ifdef CONFIG_SMP |
| 1577 | |
| 1578 | /* Only try algorithms three times */ |
| 1579 | #define DL_MAX_TRIES 3 |
| 1580 | |
| 1581 | static int pick_dl_task(struct rq *rq, struct task_struct *p, int cpu) |
| 1582 | { |
| 1583 | if (!task_running(rq, p) && |
Ingo Molnar | 0c98d34 | 2017-02-05 15:38:10 +0100 | [diff] [blame] | 1584 | cpumask_test_cpu(cpu, &p->cpus_allowed)) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1585 | return 1; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1586 | return 0; |
| 1587 | } |
| 1588 | |
Wanpeng Li | 8b5e770 | 2015-05-13 14:01:01 +0800 | [diff] [blame] | 1589 | /* |
| 1590 | * Return the earliest pushable rq's task, which is suitable to be executed |
| 1591 | * on the CPU, NULL otherwise: |
| 1592 | */ |
| 1593 | static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu) |
| 1594 | { |
| 1595 | struct rb_node *next_node = rq->dl.pushable_dl_tasks_leftmost; |
| 1596 | struct task_struct *p = NULL; |
| 1597 | |
| 1598 | if (!has_pushable_dl_tasks(rq)) |
| 1599 | return NULL; |
| 1600 | |
| 1601 | next_node: |
| 1602 | if (next_node) { |
| 1603 | p = rb_entry(next_node, struct task_struct, pushable_dl_tasks); |
| 1604 | |
| 1605 | if (pick_dl_task(rq, p, cpu)) |
| 1606 | return p; |
| 1607 | |
| 1608 | next_node = rb_next(next_node); |
| 1609 | goto next_node; |
| 1610 | } |
| 1611 | |
| 1612 | return NULL; |
| 1613 | } |
| 1614 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1615 | static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask_dl); |
| 1616 | |
| 1617 | static int find_later_rq(struct task_struct *task) |
| 1618 | { |
| 1619 | struct sched_domain *sd; |
Christoph Lameter | 4ba2968 | 2014-08-26 19:12:21 -0500 | [diff] [blame] | 1620 | struct cpumask *later_mask = this_cpu_cpumask_var_ptr(local_cpu_mask_dl); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1621 | int this_cpu = smp_processor_id(); |
| 1622 | int best_cpu, cpu = task_cpu(task); |
| 1623 | |
| 1624 | /* Make sure the mask is initialized first */ |
| 1625 | if (unlikely(!later_mask)) |
| 1626 | return -1; |
| 1627 | |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1628 | if (task->nr_cpus_allowed == 1) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1629 | return -1; |
| 1630 | |
Juri Lelli | 91ec677 | 2014-09-19 10:22:41 +0100 | [diff] [blame] | 1631 | /* |
| 1632 | * We have to consider system topology and task affinity |
| 1633 | * first, then we can look for a suitable cpu. |
| 1634 | */ |
Juri Lelli | 6bfd6d7 | 2013-11-07 14:43:47 +0100 | [diff] [blame] | 1635 | best_cpu = cpudl_find(&task_rq(task)->rd->cpudl, |
| 1636 | task, later_mask); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1637 | if (best_cpu == -1) |
| 1638 | return -1; |
| 1639 | |
| 1640 | /* |
| 1641 | * If we are here, some target has been found, |
| 1642 | * the most suitable of which is cached in best_cpu. |
| 1643 | * This is, among the runqueues where the current tasks |
| 1644 | * have later deadlines than the task's one, the rq |
| 1645 | * with the latest possible one. |
| 1646 | * |
| 1647 | * Now we check how well this matches with task's |
| 1648 | * affinity and system topology. |
| 1649 | * |
| 1650 | * The last cpu where the task run is our first |
| 1651 | * guess, since it is most likely cache-hot there. |
| 1652 | */ |
| 1653 | if (cpumask_test_cpu(cpu, later_mask)) |
| 1654 | return cpu; |
| 1655 | /* |
| 1656 | * Check if this_cpu is to be skipped (i.e., it is |
| 1657 | * not in the mask) or not. |
| 1658 | */ |
| 1659 | if (!cpumask_test_cpu(this_cpu, later_mask)) |
| 1660 | this_cpu = -1; |
| 1661 | |
| 1662 | rcu_read_lock(); |
| 1663 | for_each_domain(cpu, sd) { |
| 1664 | if (sd->flags & SD_WAKE_AFFINE) { |
| 1665 | |
| 1666 | /* |
| 1667 | * If possible, preempting this_cpu is |
| 1668 | * cheaper than migrating. |
| 1669 | */ |
| 1670 | if (this_cpu != -1 && |
| 1671 | cpumask_test_cpu(this_cpu, sched_domain_span(sd))) { |
| 1672 | rcu_read_unlock(); |
| 1673 | return this_cpu; |
| 1674 | } |
| 1675 | |
| 1676 | /* |
| 1677 | * Last chance: if best_cpu is valid and is |
| 1678 | * in the mask, that becomes our choice. |
| 1679 | */ |
| 1680 | if (best_cpu < nr_cpu_ids && |
| 1681 | cpumask_test_cpu(best_cpu, sched_domain_span(sd))) { |
| 1682 | rcu_read_unlock(); |
| 1683 | return best_cpu; |
| 1684 | } |
| 1685 | } |
| 1686 | } |
| 1687 | rcu_read_unlock(); |
| 1688 | |
| 1689 | /* |
| 1690 | * At this point, all our guesses failed, we just return |
| 1691 | * 'something', and let the caller sort the things out. |
| 1692 | */ |
| 1693 | if (this_cpu != -1) |
| 1694 | return this_cpu; |
| 1695 | |
| 1696 | cpu = cpumask_any(later_mask); |
| 1697 | if (cpu < nr_cpu_ids) |
| 1698 | return cpu; |
| 1699 | |
| 1700 | return -1; |
| 1701 | } |
| 1702 | |
| 1703 | /* Locks the rq it finds */ |
| 1704 | static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq) |
| 1705 | { |
| 1706 | struct rq *later_rq = NULL; |
| 1707 | int tries; |
| 1708 | int cpu; |
| 1709 | |
| 1710 | for (tries = 0; tries < DL_MAX_TRIES; tries++) { |
| 1711 | cpu = find_later_rq(task); |
| 1712 | |
| 1713 | if ((cpu == -1) || (cpu == rq->cpu)) |
| 1714 | break; |
| 1715 | |
| 1716 | later_rq = cpu_rq(cpu); |
| 1717 | |
Luca Abeni | 5aa5050 | 2015-10-16 10:06:21 +0200 | [diff] [blame] | 1718 | if (later_rq->dl.dl_nr_running && |
| 1719 | !dl_time_before(task->dl.deadline, |
Wanpeng Li | 9d51426 | 2015-05-13 14:01:03 +0800 | [diff] [blame] | 1720 | later_rq->dl.earliest_dl.curr)) { |
| 1721 | /* |
| 1722 | * Target rq has tasks of equal or earlier deadline, |
| 1723 | * retrying does not release any lock and is unlikely |
| 1724 | * to yield a different result. |
| 1725 | */ |
| 1726 | later_rq = NULL; |
| 1727 | break; |
| 1728 | } |
| 1729 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1730 | /* Retry if something changed. */ |
| 1731 | if (double_lock_balance(rq, later_rq)) { |
| 1732 | if (unlikely(task_rq(task) != rq || |
Ingo Molnar | 0c98d34 | 2017-02-05 15:38:10 +0100 | [diff] [blame] | 1733 | !cpumask_test_cpu(later_rq->cpu, &task->cpus_allowed) || |
Kirill Tkhai | da0c1e6 | 2014-08-20 13:47:32 +0400 | [diff] [blame] | 1734 | task_running(rq, task) || |
Xunlei Pang | 13b5ab0 | 2016-05-09 12:11:31 +0800 | [diff] [blame] | 1735 | !dl_task(task) || |
Kirill Tkhai | da0c1e6 | 2014-08-20 13:47:32 +0400 | [diff] [blame] | 1736 | !task_on_rq_queued(task))) { |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1737 | double_unlock_balance(rq, later_rq); |
| 1738 | later_rq = NULL; |
| 1739 | break; |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | /* |
| 1744 | * If the rq we found has no -deadline task, or |
| 1745 | * its earliest one has a later deadline than our |
| 1746 | * task, the rq is a good one. |
| 1747 | */ |
| 1748 | if (!later_rq->dl.dl_nr_running || |
| 1749 | dl_time_before(task->dl.deadline, |
| 1750 | later_rq->dl.earliest_dl.curr)) |
| 1751 | break; |
| 1752 | |
| 1753 | /* Otherwise we try again. */ |
| 1754 | double_unlock_balance(rq, later_rq); |
| 1755 | later_rq = NULL; |
| 1756 | } |
| 1757 | |
| 1758 | return later_rq; |
| 1759 | } |
| 1760 | |
| 1761 | static struct task_struct *pick_next_pushable_dl_task(struct rq *rq) |
| 1762 | { |
| 1763 | struct task_struct *p; |
| 1764 | |
| 1765 | if (!has_pushable_dl_tasks(rq)) |
| 1766 | return NULL; |
| 1767 | |
| 1768 | p = rb_entry(rq->dl.pushable_dl_tasks_leftmost, |
| 1769 | struct task_struct, pushable_dl_tasks); |
| 1770 | |
| 1771 | BUG_ON(rq->cpu != task_cpu(p)); |
| 1772 | BUG_ON(task_current(rq, p)); |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1773 | BUG_ON(p->nr_cpus_allowed <= 1); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1774 | |
Kirill Tkhai | da0c1e6 | 2014-08-20 13:47:32 +0400 | [diff] [blame] | 1775 | BUG_ON(!task_on_rq_queued(p)); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1776 | BUG_ON(!dl_task(p)); |
| 1777 | |
| 1778 | return p; |
| 1779 | } |
| 1780 | |
| 1781 | /* |
| 1782 | * See if the non running -deadline tasks on this rq |
| 1783 | * can be sent to some other CPU where they can preempt |
| 1784 | * and start executing. |
| 1785 | */ |
| 1786 | static int push_dl_task(struct rq *rq) |
| 1787 | { |
| 1788 | struct task_struct *next_task; |
| 1789 | struct rq *later_rq; |
Wanpeng Li | c51b8ab | 2014-11-06 15:22:44 +0800 | [diff] [blame] | 1790 | int ret = 0; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1791 | |
| 1792 | if (!rq->dl.overloaded) |
| 1793 | return 0; |
| 1794 | |
| 1795 | next_task = pick_next_pushable_dl_task(rq); |
| 1796 | if (!next_task) |
| 1797 | return 0; |
| 1798 | |
| 1799 | retry: |
| 1800 | if (unlikely(next_task == rq->curr)) { |
| 1801 | WARN_ON(1); |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
| 1805 | /* |
| 1806 | * If next_task preempts rq->curr, and rq->curr |
| 1807 | * can move away, it makes sense to just reschedule |
| 1808 | * without going further in pushing next_task. |
| 1809 | */ |
| 1810 | if (dl_task(rq->curr) && |
| 1811 | dl_time_before(next_task->dl.deadline, rq->curr->dl.deadline) && |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1812 | rq->curr->nr_cpus_allowed > 1) { |
Kirill Tkhai | 8875125 | 2014-06-29 00:03:57 +0400 | [diff] [blame] | 1813 | resched_curr(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1814 | return 0; |
| 1815 | } |
| 1816 | |
| 1817 | /* We might release rq lock */ |
| 1818 | get_task_struct(next_task); |
| 1819 | |
| 1820 | /* Will lock the rq it'll find */ |
| 1821 | later_rq = find_lock_later_rq(next_task, rq); |
| 1822 | if (!later_rq) { |
| 1823 | struct task_struct *task; |
| 1824 | |
| 1825 | /* |
| 1826 | * We must check all this again, since |
| 1827 | * find_lock_later_rq releases rq->lock and it is |
| 1828 | * then possible that next_task has migrated. |
| 1829 | */ |
| 1830 | task = pick_next_pushable_dl_task(rq); |
Byungchul Park | a776b96 | 2017-05-12 10:05:59 +0900 | [diff] [blame] | 1831 | if (task == next_task) { |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1832 | /* |
| 1833 | * The task is still there. We don't try |
| 1834 | * again, some other cpu will pull it when ready. |
| 1835 | */ |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1836 | goto out; |
| 1837 | } |
| 1838 | |
| 1839 | if (!task) |
| 1840 | /* No more tasks */ |
| 1841 | goto out; |
| 1842 | |
| 1843 | put_task_struct(next_task); |
| 1844 | next_task = task; |
| 1845 | goto retry; |
| 1846 | } |
| 1847 | |
| 1848 | deactivate_task(rq, next_task, 0); |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1849 | sub_running_bw(next_task->dl.dl_bw, &rq->dl); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1850 | set_task_cpu(next_task, later_rq->cpu); |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1851 | add_running_bw(next_task->dl.dl_bw, &later_rq->dl); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1852 | activate_task(later_rq, next_task, 0); |
Wanpeng Li | c51b8ab | 2014-11-06 15:22:44 +0800 | [diff] [blame] | 1853 | ret = 1; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1854 | |
Kirill Tkhai | 8875125 | 2014-06-29 00:03:57 +0400 | [diff] [blame] | 1855 | resched_curr(later_rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1856 | |
| 1857 | double_unlock_balance(rq, later_rq); |
| 1858 | |
| 1859 | out: |
| 1860 | put_task_struct(next_task); |
| 1861 | |
Wanpeng Li | c51b8ab | 2014-11-06 15:22:44 +0800 | [diff] [blame] | 1862 | return ret; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | static void push_dl_tasks(struct rq *rq) |
| 1866 | { |
Andrea Parri | 4ffa08e | 2015-08-05 15:56:18 +0200 | [diff] [blame] | 1867 | /* push_dl_task() will return true if it moved a -deadline task */ |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1868 | while (push_dl_task(rq)) |
| 1869 | ; |
| 1870 | } |
| 1871 | |
Peter Zijlstra | 0ea60c2 | 2015-06-11 14:46:42 +0200 | [diff] [blame] | 1872 | static void pull_dl_task(struct rq *this_rq) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1873 | { |
Peter Zijlstra | 0ea60c2 | 2015-06-11 14:46:42 +0200 | [diff] [blame] | 1874 | int this_cpu = this_rq->cpu, cpu; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1875 | struct task_struct *p; |
Peter Zijlstra | 0ea60c2 | 2015-06-11 14:46:42 +0200 | [diff] [blame] | 1876 | bool resched = false; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1877 | struct rq *src_rq; |
| 1878 | u64 dmin = LONG_MAX; |
| 1879 | |
| 1880 | if (likely(!dl_overloaded(this_rq))) |
Peter Zijlstra | 0ea60c2 | 2015-06-11 14:46:42 +0200 | [diff] [blame] | 1881 | return; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1882 | |
| 1883 | /* |
| 1884 | * Match the barrier from dl_set_overloaded; this guarantees that if we |
| 1885 | * see overloaded we must also see the dlo_mask bit. |
| 1886 | */ |
| 1887 | smp_rmb(); |
| 1888 | |
| 1889 | for_each_cpu(cpu, this_rq->rd->dlo_mask) { |
| 1890 | if (this_cpu == cpu) |
| 1891 | continue; |
| 1892 | |
| 1893 | src_rq = cpu_rq(cpu); |
| 1894 | |
| 1895 | /* |
| 1896 | * It looks racy, abd it is! However, as in sched_rt.c, |
| 1897 | * we are fine with this. |
| 1898 | */ |
| 1899 | if (this_rq->dl.dl_nr_running && |
| 1900 | dl_time_before(this_rq->dl.earliest_dl.curr, |
| 1901 | src_rq->dl.earliest_dl.next)) |
| 1902 | continue; |
| 1903 | |
| 1904 | /* Might drop this_rq->lock */ |
| 1905 | double_lock_balance(this_rq, src_rq); |
| 1906 | |
| 1907 | /* |
| 1908 | * If there are no more pullable tasks on the |
| 1909 | * rq, we're done with it. |
| 1910 | */ |
| 1911 | if (src_rq->dl.dl_nr_running <= 1) |
| 1912 | goto skip; |
| 1913 | |
Wanpeng Li | 8b5e770 | 2015-05-13 14:01:01 +0800 | [diff] [blame] | 1914 | p = pick_earliest_pushable_dl_task(src_rq, this_cpu); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1915 | |
| 1916 | /* |
| 1917 | * We found a task to be pulled if: |
| 1918 | * - it preempts our current (if there's one), |
| 1919 | * - it will preempt the last one we pulled (if any). |
| 1920 | */ |
| 1921 | if (p && dl_time_before(p->dl.deadline, dmin) && |
| 1922 | (!this_rq->dl.dl_nr_running || |
| 1923 | dl_time_before(p->dl.deadline, |
| 1924 | this_rq->dl.earliest_dl.curr))) { |
| 1925 | WARN_ON(p == src_rq->curr); |
Kirill Tkhai | da0c1e6 | 2014-08-20 13:47:32 +0400 | [diff] [blame] | 1926 | WARN_ON(!task_on_rq_queued(p)); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1927 | |
| 1928 | /* |
| 1929 | * Then we pull iff p has actually an earlier |
| 1930 | * deadline than the current task of its runqueue. |
| 1931 | */ |
| 1932 | if (dl_time_before(p->dl.deadline, |
| 1933 | src_rq->curr->dl.deadline)) |
| 1934 | goto skip; |
| 1935 | |
Peter Zijlstra | 0ea60c2 | 2015-06-11 14:46:42 +0200 | [diff] [blame] | 1936 | resched = true; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1937 | |
| 1938 | deactivate_task(src_rq, p, 0); |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1939 | sub_running_bw(p->dl.dl_bw, &src_rq->dl); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1940 | set_task_cpu(p, this_cpu); |
Luca Abeni | e36d867 | 2017-05-18 22:13:28 +0200 | [diff] [blame] | 1941 | add_running_bw(p->dl.dl_bw, &this_rq->dl); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1942 | activate_task(this_rq, p, 0); |
| 1943 | dmin = p->dl.deadline; |
| 1944 | |
| 1945 | /* Is there any other task even earlier? */ |
| 1946 | } |
| 1947 | skip: |
| 1948 | double_unlock_balance(this_rq, src_rq); |
| 1949 | } |
| 1950 | |
Peter Zijlstra | 0ea60c2 | 2015-06-11 14:46:42 +0200 | [diff] [blame] | 1951 | if (resched) |
| 1952 | resched_curr(this_rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | /* |
| 1956 | * Since the task is not running and a reschedule is not going to happen |
| 1957 | * anytime soon on its runqueue, we try pushing it away now. |
| 1958 | */ |
| 1959 | static void task_woken_dl(struct rq *rq, struct task_struct *p) |
| 1960 | { |
| 1961 | if (!task_running(rq, p) && |
| 1962 | !test_tsk_need_resched(rq->curr) && |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1963 | p->nr_cpus_allowed > 1 && |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1964 | dl_task(rq->curr) && |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 1965 | (rq->curr->nr_cpus_allowed < 2 || |
Wanpeng Li | 6b0a563 | 2014-10-31 06:39:34 +0800 | [diff] [blame] | 1966 | !dl_entity_preempt(&p->dl, &rq->curr->dl))) { |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1967 | push_dl_tasks(rq); |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | static void set_cpus_allowed_dl(struct task_struct *p, |
| 1972 | const struct cpumask *new_mask) |
| 1973 | { |
Juri Lelli | 7f51412 | 2014-09-19 10:22:40 +0100 | [diff] [blame] | 1974 | struct root_domain *src_rd; |
Peter Zijlstra | 6c37067 | 2015-05-15 17:43:36 +0200 | [diff] [blame] | 1975 | struct rq *rq; |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 1976 | |
| 1977 | BUG_ON(!dl_task(p)); |
| 1978 | |
Juri Lelli | 7f51412 | 2014-09-19 10:22:40 +0100 | [diff] [blame] | 1979 | rq = task_rq(p); |
| 1980 | src_rd = rq->rd; |
| 1981 | /* |
| 1982 | * Migrating a SCHED_DEADLINE task between exclusive |
| 1983 | * cpusets (different root_domains) entails a bandwidth |
| 1984 | * update. We already made space for us in the destination |
| 1985 | * domain (see cpuset_can_attach()). |
| 1986 | */ |
| 1987 | if (!cpumask_intersects(src_rd->span, new_mask)) { |
| 1988 | struct dl_bw *src_dl_b; |
| 1989 | |
| 1990 | src_dl_b = dl_bw_of(cpu_of(rq)); |
| 1991 | /* |
| 1992 | * We now free resources of the root_domain we are migrating |
| 1993 | * off. In the worst case, sched_setattr() may temporary fail |
| 1994 | * until we complete the update. |
| 1995 | */ |
| 1996 | raw_spin_lock(&src_dl_b->lock); |
| 1997 | __dl_clear(src_dl_b, p->dl.dl_bw); |
| 1998 | raw_spin_unlock(&src_dl_b->lock); |
| 1999 | } |
| 2000 | |
Peter Zijlstra | 6c37067 | 2015-05-15 17:43:36 +0200 | [diff] [blame] | 2001 | set_cpus_allowed_common(p, new_mask); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | /* Assumes rq->lock is held */ |
| 2005 | static void rq_online_dl(struct rq *rq) |
| 2006 | { |
| 2007 | if (rq->dl.overloaded) |
| 2008 | dl_set_overload(rq); |
Juri Lelli | 6bfd6d7 | 2013-11-07 14:43:47 +0100 | [diff] [blame] | 2009 | |
Xunlei Pang | 16b2694 | 2015-01-19 04:49:36 +0000 | [diff] [blame] | 2010 | cpudl_set_freecpu(&rq->rd->cpudl, rq->cpu); |
Juri Lelli | 6bfd6d7 | 2013-11-07 14:43:47 +0100 | [diff] [blame] | 2011 | if (rq->dl.dl_nr_running > 0) |
Tommaso Cucinotta | d8206bb | 2016-08-14 16:27:08 +0200 | [diff] [blame] | 2012 | cpudl_set(&rq->rd->cpudl, rq->cpu, rq->dl.earliest_dl.curr); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | /* Assumes rq->lock is held */ |
| 2016 | static void rq_offline_dl(struct rq *rq) |
| 2017 | { |
| 2018 | if (rq->dl.overloaded) |
| 2019 | dl_clear_overload(rq); |
Juri Lelli | 6bfd6d7 | 2013-11-07 14:43:47 +0100 | [diff] [blame] | 2020 | |
Tommaso Cucinotta | d8206bb | 2016-08-14 16:27:08 +0200 | [diff] [blame] | 2021 | cpudl_clear(&rq->rd->cpudl, rq->cpu); |
Xunlei Pang | 16b2694 | 2015-01-19 04:49:36 +0000 | [diff] [blame] | 2022 | cpudl_clear_freecpu(&rq->rd->cpudl, rq->cpu); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2023 | } |
| 2024 | |
Wanpeng Li | a6c0e74 | 2015-05-13 14:01:02 +0800 | [diff] [blame] | 2025 | void __init init_sched_dl_class(void) |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2026 | { |
| 2027 | unsigned int i; |
| 2028 | |
| 2029 | for_each_possible_cpu(i) |
| 2030 | zalloc_cpumask_var_node(&per_cpu(local_cpu_mask_dl, i), |
| 2031 | GFP_KERNEL, cpu_to_node(i)); |
| 2032 | } |
| 2033 | |
| 2034 | #endif /* CONFIG_SMP */ |
| 2035 | |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2036 | static void switched_from_dl(struct rq *rq, struct task_struct *p) |
| 2037 | { |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 2038 | /* |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 2039 | * task_non_contending() can start the "inactive timer" (if the 0-lag |
| 2040 | * time is in the future). If the task switches back to dl before |
| 2041 | * the "inactive timer" fires, it can continue to consume its current |
| 2042 | * runtime using its current deadline. If it stays outside of |
| 2043 | * SCHED_DEADLINE until the 0-lag time passes, inactive_task_timer() |
| 2044 | * will reset the task parameters. |
Peter Zijlstra | a649f23 | 2015-06-11 14:46:49 +0200 | [diff] [blame] | 2045 | */ |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 2046 | if (task_on_rq_queued(p) && p->dl.dl_runtime) |
| 2047 | task_non_contending(p); |
| 2048 | |
| 2049 | /* |
| 2050 | * We cannot use inactive_task_timer() to invoke sub_running_bw() |
| 2051 | * at the 0-lag time, because the task could have been migrated |
| 2052 | * while SCHED_OTHER in the meanwhile. |
| 2053 | */ |
| 2054 | if (p->dl.dl_non_contending) |
| 2055 | p->dl.dl_non_contending = 0; |
Juri Lelli | a5e7be3 | 2014-09-19 10:22:39 +0100 | [diff] [blame] | 2056 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2057 | /* |
| 2058 | * Since this might be the only -deadline task on the rq, |
| 2059 | * this is the right place to try to pull some other one |
| 2060 | * from an overloaded cpu, if any. |
| 2061 | */ |
Wanpeng Li | cd66091 | 2014-10-31 06:39:35 +0800 | [diff] [blame] | 2062 | if (!task_on_rq_queued(p) || rq->dl.dl_nr_running) |
| 2063 | return; |
| 2064 | |
Peter Zijlstra | 9916e21 | 2015-06-11 14:46:43 +0200 | [diff] [blame] | 2065 | queue_pull_task(rq); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2066 | } |
| 2067 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2068 | /* |
| 2069 | * When switching to -deadline, we may overload the rq, then |
| 2070 | * we try to push someone off, if possible. |
| 2071 | */ |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2072 | static void switched_to_dl(struct rq *rq, struct task_struct *p) |
| 2073 | { |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 2074 | if (hrtimer_try_to_cancel(&p->dl.inactive_timer) == 1) |
| 2075 | put_task_struct(p); |
Luca Abeni | 72f9f3f | 2016-03-07 12:27:04 +0100 | [diff] [blame] | 2076 | |
Juri Lelli | 98b0a85 | 2016-08-05 16:07:55 +0100 | [diff] [blame] | 2077 | /* If p is not queued we will update its parameters at next wakeup. */ |
| 2078 | if (!task_on_rq_queued(p)) |
| 2079 | return; |
| 2080 | |
| 2081 | /* |
| 2082 | * If p is boosted we already updated its params in |
| 2083 | * rt_mutex_setprio()->enqueue_task(..., ENQUEUE_REPLENISH), |
| 2084 | * p's deadline being now already after rq_clock(rq). |
| 2085 | */ |
| 2086 | if (dl_time_before(p->dl.deadline, rq_clock(rq))) |
| 2087 | setup_new_dl_entity(&p->dl); |
| 2088 | |
| 2089 | if (rq->curr != p) { |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2090 | #ifdef CONFIG_SMP |
Ingo Molnar | 4b53a34 | 2017-02-05 15:41:03 +0100 | [diff] [blame] | 2091 | if (p->nr_cpus_allowed > 1 && rq->dl.overloaded) |
Peter Zijlstra | 9916e21 | 2015-06-11 14:46:43 +0200 | [diff] [blame] | 2092 | queue_push_tasks(rq); |
Sebastian Andrzej Siewior | 619bd4a | 2017-01-24 15:40:06 +0100 | [diff] [blame] | 2093 | #endif |
Peter Zijlstra | 9916e21 | 2015-06-11 14:46:43 +0200 | [diff] [blame] | 2094 | if (dl_task(rq->curr)) |
| 2095 | check_preempt_curr_dl(rq, p, 0); |
| 2096 | else |
| 2097 | resched_curr(rq); |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2098 | } |
| 2099 | } |
| 2100 | |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2101 | /* |
| 2102 | * If the scheduling parameters of a -deadline task changed, |
| 2103 | * a push or pull operation might be needed. |
| 2104 | */ |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2105 | static void prio_changed_dl(struct rq *rq, struct task_struct *p, |
| 2106 | int oldprio) |
| 2107 | { |
Kirill Tkhai | da0c1e6 | 2014-08-20 13:47:32 +0400 | [diff] [blame] | 2108 | if (task_on_rq_queued(p) || rq->curr == p) { |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2109 | #ifdef CONFIG_SMP |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2110 | /* |
| 2111 | * This might be too much, but unfortunately |
| 2112 | * we don't have the old deadline value, and |
| 2113 | * we can't argue if the task is increasing |
| 2114 | * or lowering its prio, so... |
| 2115 | */ |
| 2116 | if (!rq->dl.overloaded) |
Peter Zijlstra | 9916e21 | 2015-06-11 14:46:43 +0200 | [diff] [blame] | 2117 | queue_pull_task(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2118 | |
| 2119 | /* |
| 2120 | * If we now have a earlier deadline task than p, |
| 2121 | * then reschedule, provided p is still on this |
| 2122 | * runqueue. |
| 2123 | */ |
Peter Zijlstra | 9916e21 | 2015-06-11 14:46:43 +0200 | [diff] [blame] | 2124 | if (dl_time_before(rq->dl.earliest_dl.curr, p->dl.deadline)) |
Kirill Tkhai | 8875125 | 2014-06-29 00:03:57 +0400 | [diff] [blame] | 2125 | resched_curr(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2126 | #else |
| 2127 | /* |
| 2128 | * Again, we don't know if p has a earlier |
| 2129 | * or later deadline, so let's blindly set a |
| 2130 | * (maybe not needed) rescheduling point. |
| 2131 | */ |
Kirill Tkhai | 8875125 | 2014-06-29 00:03:57 +0400 | [diff] [blame] | 2132 | resched_curr(rq); |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2133 | #endif /* CONFIG_SMP */ |
Peter Zijlstra | 801ccdb | 2016-02-25 15:01:49 +0100 | [diff] [blame] | 2134 | } |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2135 | } |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2136 | |
| 2137 | const struct sched_class dl_sched_class = { |
| 2138 | .next = &rt_sched_class, |
| 2139 | .enqueue_task = enqueue_task_dl, |
| 2140 | .dequeue_task = dequeue_task_dl, |
| 2141 | .yield_task = yield_task_dl, |
| 2142 | |
| 2143 | .check_preempt_curr = check_preempt_curr_dl, |
| 2144 | |
| 2145 | .pick_next_task = pick_next_task_dl, |
| 2146 | .put_prev_task = put_prev_task_dl, |
| 2147 | |
| 2148 | #ifdef CONFIG_SMP |
| 2149 | .select_task_rq = select_task_rq_dl, |
Luca Abeni | 209a0cb | 2017-05-18 22:13:29 +0200 | [diff] [blame] | 2150 | .migrate_task_rq = migrate_task_rq_dl, |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2151 | .set_cpus_allowed = set_cpus_allowed_dl, |
| 2152 | .rq_online = rq_online_dl, |
| 2153 | .rq_offline = rq_offline_dl, |
Juri Lelli | 1baca4c | 2013-11-07 14:43:38 +0100 | [diff] [blame] | 2154 | .task_woken = task_woken_dl, |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2155 | #endif |
| 2156 | |
| 2157 | .set_curr_task = set_curr_task_dl, |
| 2158 | .task_tick = task_tick_dl, |
| 2159 | .task_fork = task_fork_dl, |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2160 | |
| 2161 | .prio_changed = prio_changed_dl, |
| 2162 | .switched_from = switched_from_dl, |
| 2163 | .switched_to = switched_to_dl, |
Stanislaw Gruszka | 6e99891 | 2014-11-12 16:58:44 +0100 | [diff] [blame] | 2164 | |
| 2165 | .update_curr = update_curr_dl, |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 2166 | }; |
Wanpeng Li | acb3213 | 2014-10-31 06:39:33 +0800 | [diff] [blame] | 2167 | |
| 2168 | #ifdef CONFIG_SCHED_DEBUG |
| 2169 | extern void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq); |
| 2170 | |
| 2171 | void print_dl_stats(struct seq_file *m, int cpu) |
| 2172 | { |
| 2173 | print_dl_rq(m, cpu, &cpu_rq(cpu)->dl); |
| 2174 | } |
| 2175 | #endif /* CONFIG_SCHED_DEBUG */ |