Blame view
kernel/sched/deadline.c
72.2 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
aab03e05e sched/deadline: A... |
2 3 4 5 6 7 8 9 10 11 12 13 |
/* * Deadline Scheduling Class (SCHED_DEADLINE) * * Earliest Deadline First (EDF) + Constant Bandwidth Server (CBS). * * Tasks that periodically executes their instances for less than their * runtime won't miss any of their deadlines. * Tasks that are not periodic or sporadic or that tries to execute more * than their reserved bandwidth will be slowed down (and may potentially * miss some of their deadlines), and won't affect any other task. * * Copyright (C) 2012 Dario Faggioli <raistlin@linux.it>, |
1baca4ce1 sched/deadline: A... |
14 |
* Juri Lelli <juri.lelli@gmail.com>, |
aab03e05e sched/deadline: A... |
15 16 17 18 |
* Michael Trimarchi <michael@amarulasolutions.com>, * Fabio Checconi <fchecconi@gmail.com> */ #include "sched.h" |
6bfd6d72f sched/deadline: s... |
19 |
#include <linux/slab.h> |
06a76fe08 sched/deadline: M... |
20 |
#include <uapi/linux/sched/types.h> |
6bfd6d72f sched/deadline: s... |
21 |
|
332ac17ef sched/deadline: A... |
22 |
struct dl_bandwidth def_dl_bandwidth; |
aab03e05e sched/deadline: A... |
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
static inline struct task_struct *dl_task_of(struct sched_dl_entity *dl_se) { return container_of(dl_se, struct task_struct, dl); } static inline struct rq *rq_of_dl_rq(struct dl_rq *dl_rq) { return container_of(dl_rq, struct rq, dl); } static inline struct dl_rq *dl_rq_of_se(struct sched_dl_entity *dl_se) { struct task_struct *p = dl_task_of(dl_se); struct rq *rq = task_rq(p); return &rq->dl; } static inline int on_dl_rq(struct sched_dl_entity *dl_se) { return !RB_EMPTY_NODE(&dl_se->rb_node); } |
06a76fe08 sched/deadline: M... |
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
#ifdef CONFIG_SMP static inline struct dl_bw *dl_bw_of(int i) { RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held(), "sched RCU must be held"); return &cpu_rq(i)->rd->dl_bw; } static inline int dl_bw_cpus(int i) { struct root_domain *rd = cpu_rq(i)->rd; int cpus = 0; RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held(), "sched RCU must be held"); for_each_cpu_and(i, rd->span, cpu_active_mask) cpus++; return cpus; } #else static inline struct dl_bw *dl_bw_of(int i) { return &cpu_rq(i)->dl.dl_bw; } static inline int dl_bw_cpus(int i) { return 1; } #endif |
e36d8677b sched/deadline: T... |
76 77 78 79 80 81 82 83 |
static inline void add_running_bw(u64 dl_bw, struct dl_rq *dl_rq) { u64 old = dl_rq->running_bw; lockdep_assert_held(&(rq_of_dl_rq(dl_rq))->lock); dl_rq->running_bw += dl_bw; SCHED_WARN_ON(dl_rq->running_bw < old); /* overflow */ |
8fd27231c sched/deadline: T... |
84 |
SCHED_WARN_ON(dl_rq->running_bw > dl_rq->this_bw); |
e36d8677b sched/deadline: T... |
85 86 87 88 89 90 91 92 93 94 95 96 97 |
} static inline void sub_running_bw(u64 dl_bw, struct dl_rq *dl_rq) { u64 old = dl_rq->running_bw; lockdep_assert_held(&(rq_of_dl_rq(dl_rq))->lock); dl_rq->running_bw -= dl_bw; SCHED_WARN_ON(dl_rq->running_bw > old); /* underflow */ if (dl_rq->running_bw > old) dl_rq->running_bw = 0; } |
8fd27231c sched/deadline: T... |
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
static inline void add_rq_bw(u64 dl_bw, struct dl_rq *dl_rq) { u64 old = dl_rq->this_bw; lockdep_assert_held(&(rq_of_dl_rq(dl_rq))->lock); dl_rq->this_bw += dl_bw; SCHED_WARN_ON(dl_rq->this_bw < old); /* overflow */ } static inline void sub_rq_bw(u64 dl_bw, struct dl_rq *dl_rq) { u64 old = dl_rq->this_bw; lockdep_assert_held(&(rq_of_dl_rq(dl_rq))->lock); dl_rq->this_bw -= dl_bw; SCHED_WARN_ON(dl_rq->this_bw > old); /* underflow */ if (dl_rq->this_bw > old) dl_rq->this_bw = 0; SCHED_WARN_ON(dl_rq->running_bw > dl_rq->this_bw); } |
209a0cbda sched/deadline: I... |
120 121 |
void dl_change_utilization(struct task_struct *p, u64 new_bw) { |
8fd27231c sched/deadline: T... |
122 |
struct rq *rq; |
209a0cbda sched/deadline: I... |
123 |
|
8fd27231c sched/deadline: T... |
124 |
if (task_on_rq_queued(p)) |
209a0cbda sched/deadline: I... |
125 |
return; |
8fd27231c sched/deadline: T... |
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
rq = task_rq(p); if (p->dl.dl_non_contending) { sub_running_bw(p->dl.dl_bw, &rq->dl); p->dl.dl_non_contending = 0; /* * If the timer handler is currently running and the * timer cannot be cancelled, inactive_task_timer() * will see that dl_not_contending is not set, and * will not touch the rq's active utilization, * so we are still safe. */ if (hrtimer_try_to_cancel(&p->dl.inactive_timer) == 1) put_task_struct(p); } sub_rq_bw(p->dl.dl_bw, &rq->dl); add_rq_bw(new_bw, &rq->dl); |
209a0cbda sched/deadline: I... |
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
} /* * The utilization of a task cannot be immediately removed from * the rq active utilization (running_bw) when the task blocks. * Instead, we have to wait for the so called "0-lag time". * * If a task blocks before the "0-lag time", a timer (the inactive * timer) is armed, and running_bw is decreased when the timer * fires. * * If the task wakes up again before the inactive timer fires, * the timer is cancelled, whereas if the task wakes up after the * inactive timer fired (and running_bw has been decreased) the * task's utilization has to be added to running_bw again. * A flag in the deadline scheduling entity (dl_non_contending) * is used to avoid race conditions between the inactive timer handler * and task wakeups. * * The following diagram shows how running_bw is updated. A task is * "ACTIVE" when its utilization contributes to running_bw; an * "ACTIVE contending" task is in the TASK_RUNNING state, while an * "ACTIVE non contending" task is a blocked task for which the "0-lag time" * has not passed yet. An "INACTIVE" task is a task for which the "0-lag" * time already passed, which does not contribute to running_bw anymore. * +------------------+ * wakeup | ACTIVE | * +------------------>+ contending | * | add_running_bw | | * | +----+------+------+ * | | ^ * | dequeue | | * +--------+-------+ | | * | | t >= 0-lag | | wakeup * | INACTIVE |<---------------+ | * | | sub_running_bw | | * +--------+-------+ | | * ^ | | * | t < 0-lag | | * | | | * | V | * | +----+------+------+ * | sub_running_bw | ACTIVE | * +-------------------+ | * inactive timer | non contending | * fired +------------------+ * * The task_non_contending() function is invoked when a task * blocks, and checks if the 0-lag time already passed or * not (in the first case, it directly updates running_bw; * in the second case, it arms the inactive timer). * * The task_contending() function is invoked when a task wakes * up, and checks if the task is still in the "ACTIVE non contending" * state or not (in the second case, it updates running_bw). */ static void task_non_contending(struct task_struct *p) { struct sched_dl_entity *dl_se = &p->dl; struct hrtimer *timer = &dl_se->inactive_timer; struct dl_rq *dl_rq = dl_rq_of_se(dl_se); struct rq *rq = rq_of_dl_rq(dl_rq); s64 zerolag_time; /* * If this is a non-deadline task that has been boosted, * do nothing */ if (dl_se->dl_runtime == 0) return; WARN_ON(hrtimer_active(&dl_se->inactive_timer)); WARN_ON(dl_se->dl_non_contending); zerolag_time = dl_se->deadline - div64_long((dl_se->runtime * dl_se->dl_period), dl_se->dl_runtime); /* * Using relative times instead of the absolute "0-lag time" * allows to simplify the code */ zerolag_time -= rq_clock(rq); /* * If the "0-lag time" already passed, decrease the active * utilization now, instead of starting a timer */ if (zerolag_time < 0) { if (dl_task(p)) sub_running_bw(dl_se->dl_bw, dl_rq); |
387e31300 sched/deadline: F... |
233 234 |
if (!dl_task(p) || p->state == TASK_DEAD) { struct dl_bw *dl_b = dl_bw_of(task_cpu(p)); |
8fd27231c sched/deadline: T... |
235 236 |
if (p->state == TASK_DEAD) sub_rq_bw(p->dl.dl_bw, &rq->dl); |
387e31300 sched/deadline: F... |
237 |
raw_spin_lock(&dl_b->lock); |
daec57983 sched/deadline: R... |
238 |
__dl_clear(dl_b, p->dl.dl_bw, dl_bw_cpus(task_cpu(p))); |
209a0cbda sched/deadline: I... |
239 |
__dl_clear_params(p); |
387e31300 sched/deadline: F... |
240 241 |
raw_spin_unlock(&dl_b->lock); } |
209a0cbda sched/deadline: I... |
242 243 244 245 246 247 248 249 |
return; } dl_se->dl_non_contending = 1; get_task_struct(p); hrtimer_start(timer, ns_to_ktime(zerolag_time), HRTIMER_MODE_REL); } |
8fd27231c sched/deadline: T... |
250 |
static void task_contending(struct sched_dl_entity *dl_se, int flags) |
209a0cbda sched/deadline: I... |
251 252 253 254 255 256 257 258 259 |
{ struct dl_rq *dl_rq = dl_rq_of_se(dl_se); /* * If this is a non-deadline task that has been boosted, * do nothing */ if (dl_se->dl_runtime == 0) return; |
8fd27231c sched/deadline: T... |
260 261 |
if (flags & ENQUEUE_MIGRATED) add_rq_bw(dl_se->dl_bw, dl_rq); |
209a0cbda sched/deadline: I... |
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
if (dl_se->dl_non_contending) { dl_se->dl_non_contending = 0; /* * If the timer handler is currently running and the * timer cannot be cancelled, inactive_task_timer() * will see that dl_not_contending is not set, and * will not touch the rq's active utilization, * so we are still safe. */ if (hrtimer_try_to_cancel(&dl_se->inactive_timer) == 1) put_task_struct(dl_task_of(dl_se)); } else { /* * Since "dl_non_contending" is not set, the * task's utilization has already been removed from * active utilization (either when the task blocked, * when the "inactive timer" fired). * So, add it back. */ add_running_bw(dl_se->dl_bw, dl_rq); } } |
aab03e05e sched/deadline: A... |
284 285 286 |
static inline int is_leftmost(struct task_struct *p, struct dl_rq *dl_rq) { struct sched_dl_entity *dl_se = &p->dl; |
2161573ec sched/deadline: r... |
287 |
return dl_rq->root.rb_leftmost == &dl_se->rb_node; |
aab03e05e sched/deadline: A... |
288 |
} |
332ac17ef sched/deadline: A... |
289 290 291 292 293 294 |
void init_dl_bandwidth(struct dl_bandwidth *dl_b, u64 period, u64 runtime) { raw_spin_lock_init(&dl_b->dl_runtime_lock); dl_b->dl_period = period; dl_b->dl_runtime = runtime; } |
332ac17ef sched/deadline: A... |
295 296 297 298 |
void init_dl_bw(struct dl_bw *dl_b) { raw_spin_lock_init(&dl_b->lock); raw_spin_lock(&def_dl_bandwidth.dl_runtime_lock); |
1724813d9 sched/deadline: R... |
299 |
if (global_rt_runtime() == RUNTIME_INF) |
332ac17ef sched/deadline: A... |
300 301 |
dl_b->bw = -1; else |
1724813d9 sched/deadline: R... |
302 |
dl_b->bw = to_ratio(global_rt_period(), global_rt_runtime()); |
332ac17ef sched/deadline: A... |
303 304 305 |
raw_spin_unlock(&def_dl_bandwidth.dl_runtime_lock); dl_b->total_bw = 0; } |
07c54f7a7 sched/core: Remov... |
306 |
void init_dl_rq(struct dl_rq *dl_rq) |
aab03e05e sched/deadline: A... |
307 |
{ |
2161573ec sched/deadline: r... |
308 |
dl_rq->root = RB_ROOT_CACHED; |
1baca4ce1 sched/deadline: A... |
309 310 311 312 313 314 315 |
#ifdef CONFIG_SMP /* zero means no -deadline tasks */ dl_rq->earliest_dl.curr = dl_rq->earliest_dl.next = 0; dl_rq->dl_nr_migratory = 0; dl_rq->overloaded = 0; |
2161573ec sched/deadline: r... |
316 |
dl_rq->pushable_dl_tasks_root = RB_ROOT_CACHED; |
332ac17ef sched/deadline: A... |
317 318 |
#else init_dl_bw(&dl_rq->dl_bw); |
1baca4ce1 sched/deadline: A... |
319 |
#endif |
e36d8677b sched/deadline: T... |
320 321 |
dl_rq->running_bw = 0; |
8fd27231c sched/deadline: T... |
322 |
dl_rq->this_bw = 0; |
4da3abcef sched/deadline: D... |
323 |
init_dl_rq_bw_ratio(dl_rq); |
1baca4ce1 sched/deadline: A... |
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
} #ifdef CONFIG_SMP static inline int dl_overloaded(struct rq *rq) { return atomic_read(&rq->rd->dlo_count); } static inline void dl_set_overload(struct rq *rq) { if (!rq->online) return; cpumask_set_cpu(rq->cpu, rq->rd->dlo_mask); /* * Must be visible before the overload count is * set (as in sched_rt.c). * * Matched by the barrier in pull_dl_task(). */ smp_wmb(); atomic_inc(&rq->rd->dlo_count); } static inline void dl_clear_overload(struct rq *rq) { if (!rq->online) return; atomic_dec(&rq->rd->dlo_count); cpumask_clear_cpu(rq->cpu, rq->rd->dlo_mask); } static void update_dl_migration(struct dl_rq *dl_rq) { |
995b9ea44 sched/deadline: R... |
360 |
if (dl_rq->dl_nr_migratory && dl_rq->dl_nr_running > 1) { |
1baca4ce1 sched/deadline: A... |
361 362 363 364 365 366 367 368 369 370 371 372 373 |
if (!dl_rq->overloaded) { dl_set_overload(rq_of_dl_rq(dl_rq)); dl_rq->overloaded = 1; } } else if (dl_rq->overloaded) { dl_clear_overload(rq_of_dl_rq(dl_rq)); dl_rq->overloaded = 0; } } static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) { struct task_struct *p = dl_task_of(dl_se); |
1baca4ce1 sched/deadline: A... |
374 |
|
4b53a3412 sched/core: Remov... |
375 |
if (p->nr_cpus_allowed > 1) |
1baca4ce1 sched/deadline: A... |
376 377 378 379 380 381 382 383 |
dl_rq->dl_nr_migratory++; update_dl_migration(dl_rq); } static void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) { struct task_struct *p = dl_task_of(dl_se); |
1baca4ce1 sched/deadline: A... |
384 |
|
4b53a3412 sched/core: Remov... |
385 |
if (p->nr_cpus_allowed > 1) |
1baca4ce1 sched/deadline: A... |
386 387 388 389 390 391 392 393 394 395 396 397 |
dl_rq->dl_nr_migratory--; update_dl_migration(dl_rq); } /* * The list of pushable -deadline task is not a plist, like in * sched_rt.c, it is an rb-tree with tasks ordered by deadline. */ static void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p) { struct dl_rq *dl_rq = &rq->dl; |
2161573ec sched/deadline: r... |
398 |
struct rb_node **link = &dl_rq->pushable_dl_tasks_root.rb_root.rb_node; |
1baca4ce1 sched/deadline: A... |
399 400 |
struct rb_node *parent = NULL; struct task_struct *entry; |
2161573ec sched/deadline: r... |
401 |
bool leftmost = true; |
1baca4ce1 sched/deadline: A... |
402 403 404 405 406 407 408 409 410 411 412 |
BUG_ON(!RB_EMPTY_NODE(&p->pushable_dl_tasks)); while (*link) { parent = *link; entry = rb_entry(parent, struct task_struct, pushable_dl_tasks); if (dl_entity_preempt(&p->dl, &entry->dl)) link = &parent->rb_left; else { link = &parent->rb_right; |
2161573ec sched/deadline: r... |
413 |
leftmost = false; |
1baca4ce1 sched/deadline: A... |
414 415 |
} } |
2161573ec sched/deadline: r... |
416 |
if (leftmost) |
7d92de3a8 sched/deadline: F... |
417 |
dl_rq->earliest_dl.next = p->dl.deadline; |
1baca4ce1 sched/deadline: A... |
418 419 |
rb_link_node(&p->pushable_dl_tasks, parent, link); |
2161573ec sched/deadline: r... |
420 421 |
rb_insert_color_cached(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root, leftmost); |
aab03e05e sched/deadline: A... |
422 |
} |
1baca4ce1 sched/deadline: A... |
423 424 425 426 427 428 |
static void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p) { struct dl_rq *dl_rq = &rq->dl; if (RB_EMPTY_NODE(&p->pushable_dl_tasks)) return; |
2161573ec sched/deadline: r... |
429 |
if (dl_rq->pushable_dl_tasks_root.rb_leftmost == &p->pushable_dl_tasks) { |
1baca4ce1 sched/deadline: A... |
430 431 432 |
struct rb_node *next_node; next_node = rb_next(&p->pushable_dl_tasks); |
7d92de3a8 sched/deadline: F... |
433 434 435 436 |
if (next_node) { dl_rq->earliest_dl.next = rb_entry(next_node, struct task_struct, pushable_dl_tasks)->dl.deadline; } |
1baca4ce1 sched/deadline: A... |
437 |
} |
2161573ec sched/deadline: r... |
438 |
rb_erase_cached(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root); |
1baca4ce1 sched/deadline: A... |
439 440 441 442 443 |
RB_CLEAR_NODE(&p->pushable_dl_tasks); } static inline int has_pushable_dl_tasks(struct rq *rq) { |
2161573ec sched/deadline: r... |
444 |
return !RB_EMPTY_ROOT(&rq->dl.pushable_dl_tasks_root.rb_root); |
1baca4ce1 sched/deadline: A... |
445 446 447 |
} static int push_dl_task(struct rq *rq); |
dc8773410 sched: Remove som... |
448 449 450 451 |
static inline bool need_pull_dl_task(struct rq *rq, struct task_struct *prev) { return dl_task(prev); } |
9916e2149 sched, dl: Conver... |
452 453 |
static DEFINE_PER_CPU(struct callback_head, dl_push_head); static DEFINE_PER_CPU(struct callback_head, dl_pull_head); |
e3fca9e7c sched: Replace po... |
454 455 |
static void push_dl_tasks(struct rq *); |
9916e2149 sched, dl: Conver... |
456 |
static void pull_dl_task(struct rq *); |
e3fca9e7c sched: Replace po... |
457 458 |
static inline void queue_push_tasks(struct rq *rq) |
dc8773410 sched: Remove som... |
459 |
{ |
e3fca9e7c sched: Replace po... |
460 461 |
if (!has_pushable_dl_tasks(rq)) return; |
9916e2149 sched, dl: Conver... |
462 463 464 465 466 467 |
queue_balance_callback(rq, &per_cpu(dl_push_head, rq->cpu), push_dl_tasks); } static inline void queue_pull_task(struct rq *rq) { queue_balance_callback(rq, &per_cpu(dl_pull_head, rq->cpu), pull_dl_task); |
dc8773410 sched: Remove som... |
468 |
} |
fa9c9d10e sched/deadline: S... |
469 |
static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq); |
a649f237d sched,dl: Fix sch... |
470 |
static struct rq *dl_task_offline_migration(struct rq *rq, struct task_struct *p) |
fa9c9d10e sched/deadline: S... |
471 472 |
{ struct rq *later_rq = NULL; |
fa9c9d10e sched/deadline: S... |
473 474 |
later_rq = find_lock_later_rq(p, rq); |
fa9c9d10e sched/deadline: S... |
475 476 477 478 479 480 481 |
if (!later_rq) { int cpu; /* * If we cannot preempt any rq, fall back to pick any * online cpu. */ |
0c98d344f sched/core: Remov... |
482 |
cpu = cpumask_any_and(cpu_active_mask, &p->cpus_allowed); |
fa9c9d10e sched/deadline: S... |
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
if (cpu >= nr_cpu_ids) { /* * Fail to find any suitable cpu. * The task will never come back! */ BUG_ON(dl_bandwidth_enabled()); /* * If admission control is disabled we * try a little harder to let the task * run. */ cpu = cpumask_any(cpu_active_mask); } later_rq = cpu_rq(cpu); double_lock_balance(rq, later_rq); } |
fa9c9d10e sched/deadline: S... |
500 |
set_task_cpu(p, later_rq->cpu); |
a649f237d sched,dl: Fix sch... |
501 502 503 |
double_unlock_balance(later_rq, rq); return later_rq; |
fa9c9d10e sched/deadline: S... |
504 |
} |
1baca4ce1 sched/deadline: A... |
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
#else static inline void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p) { } static inline void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p) { } static inline void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) { } static inline void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) { } |
dc8773410 sched: Remove som... |
526 527 528 529 |
static inline bool need_pull_dl_task(struct rq *rq, struct task_struct *prev) { return false; } |
0ea60c205 sched,dl: Remove ... |
530 |
static inline void pull_dl_task(struct rq *rq) |
dc8773410 sched: Remove som... |
531 |
{ |
dc8773410 sched: Remove som... |
532 |
} |
e3fca9e7c sched: Replace po... |
533 |
static inline void queue_push_tasks(struct rq *rq) |
dc8773410 sched: Remove som... |
534 |
{ |
dc8773410 sched: Remove som... |
535 |
} |
9916e2149 sched, dl: Conver... |
536 |
static inline void queue_pull_task(struct rq *rq) |
dc8773410 sched: Remove som... |
537 538 |
{ } |
1baca4ce1 sched/deadline: A... |
539 |
#endif /* CONFIG_SMP */ |
aab03e05e sched/deadline: A... |
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags); static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags); static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p, int flags); /* * We are being explicitly informed that a new instance is starting, * and this means that: * - the absolute deadline of the entity has to be placed at * current time + relative deadline; * - the runtime of the entity has to be set to the maximum value. * * The capability of specifying such event is useful whenever a -deadline * entity wants to (try to!) synchronize its behaviour with the scheduler's * one, and to (try to!) reconcile itself with its own scheduling * parameters. */ |
98b0a8578 sched/deadline: R... |
557 |
static inline void setup_new_dl_entity(struct sched_dl_entity *dl_se) |
aab03e05e sched/deadline: A... |
558 559 560 |
{ struct dl_rq *dl_rq = dl_rq_of_se(dl_se); struct rq *rq = rq_of_dl_rq(dl_rq); |
98b0a8578 sched/deadline: R... |
561 |
WARN_ON(dl_se->dl_boosted); |
72f9f3fdc sched/deadline: R... |
562 563 564 565 566 567 568 569 570 |
WARN_ON(dl_time_before(rq_clock(rq), dl_se->deadline)); /* * We are racing with the deadline timer. So, do nothing because * the deadline timer handler will take care of properly recharging * the runtime and postponing the deadline */ if (dl_se->dl_throttled) return; |
aab03e05e sched/deadline: A... |
571 572 573 574 575 576 |
/* * We use the regular wall clock time to set deadlines in the * future; in fact, we must consider execution overheads (time * spent on hardirq context, etc.). */ |
98b0a8578 sched/deadline: R... |
577 578 |
dl_se->deadline = rq_clock(rq) + dl_se->dl_deadline; dl_se->runtime = dl_se->dl_runtime; |
aab03e05e sched/deadline: A... |
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
} /* * Pure Earliest Deadline First (EDF) scheduling does not deal with the * possibility of a entity lasting more than what it declared, and thus * exhausting its runtime. * * Here we are interested in making runtime overrun possible, but we do * not want a entity which is misbehaving to affect the scheduling of all * other entities. * Therefore, a budgeting strategy called Constant Bandwidth Server (CBS) * is used, in order to confine each entity within its own bandwidth. * * This function deals exactly with that, and ensures that when the runtime * of a entity is replenished, its deadline is also postponed. That ensures * the overrunning entity can't interfere with other entity in the system and * can't make them miss their deadlines. Reasons why this kind of overruns * could happen are, typically, a entity voluntarily trying to overcome its |
1b09d29bc sched/rt: Fix rep... |
597 |
* runtime, or it just underestimated it during sched_setattr(). |
aab03e05e sched/deadline: A... |
598 |
*/ |
2d3d891d3 sched/deadline: A... |
599 600 |
static void replenish_dl_entity(struct sched_dl_entity *dl_se, struct sched_dl_entity *pi_se) |
aab03e05e sched/deadline: A... |
601 602 603 |
{ struct dl_rq *dl_rq = dl_rq_of_se(dl_se); struct rq *rq = rq_of_dl_rq(dl_rq); |
2d3d891d3 sched/deadline: A... |
604 605 606 607 608 609 610 611 612 613 |
BUG_ON(pi_se->dl_runtime <= 0); /* * This could be the case for a !-dl task that is boosted. * Just go with full inherited parameters. */ if (dl_se->dl_deadline == 0) { dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline; dl_se->runtime = pi_se->dl_runtime; } |
48be3a67d sched/deadline: A... |
614 615 |
if (dl_se->dl_yielded && dl_se->runtime > 0) dl_se->runtime = 0; |
aab03e05e sched/deadline: A... |
616 617 618 619 620 621 622 |
/* * We keep moving the deadline away until we get some * available runtime for the entity. This ensures correct * handling of situations where the runtime overrun is * arbitrary large. */ while (dl_se->runtime <= 0) { |
2d3d891d3 sched/deadline: A... |
623 624 |
dl_se->deadline += pi_se->dl_period; dl_se->runtime += pi_se->dl_runtime; |
aab03e05e sched/deadline: A... |
625 626 627 628 629 630 631 632 633 634 635 636 |
} /* * At this point, the deadline really should be "in * the future" with respect to rq->clock. If it's * not, we are, for some reason, lagging too much! * Anyway, after having warn userspace abut that, * we still try to keep the things running by * resetting the deadline and the budget of the * entity. */ if (dl_time_before(dl_se->deadline, rq_clock(rq))) { |
c219b7ddb sched/deadline: F... |
637 638 |
printk_deferred_once("sched: DL replenish lagged too much "); |
2d3d891d3 sched/deadline: A... |
639 640 |
dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline; dl_se->runtime = pi_se->dl_runtime; |
aab03e05e sched/deadline: A... |
641 |
} |
1019a359d sched/deadline: F... |
642 643 644 645 646 |
if (dl_se->dl_yielded) dl_se->dl_yielded = 0; if (dl_se->dl_throttled) dl_se->dl_throttled = 0; |
aab03e05e sched/deadline: A... |
647 648 649 650 651 652 653 654 655 656 657 658 659 |
} /* * Here we check if --at time t-- an entity (which is probably being * [re]activated or, in general, enqueued) can use its remaining runtime * and its current deadline _without_ exceeding the bandwidth it is * assigned (function returns true if it can't). We are in fact applying * one of the CBS rules: when a task wakes up, if the residual runtime * over residual deadline fits within the allocated bandwidth, then we * can keep the current (absolute) deadline and residual budget without * disrupting the schedulability of the system. Otherwise, we should * refill the runtime and set the deadline a period in the future, * because keeping the current (absolute) deadline of the task would |
712e5e34a sched/deadline: A... |
660 661 |
* result in breaking guarantees promised to other tasks (refer to * Documentation/scheduler/sched-deadline.txt for more informations). |
aab03e05e sched/deadline: A... |
662 663 664 |
* * This function returns true if: * |
2317d5f1c sched/deadline: U... |
665 |
* runtime / (deadline - t) > dl_runtime / dl_deadline , |
aab03e05e sched/deadline: A... |
666 667 |
* * IOW we can't recycle current parameters. |
755378a47 sched/deadline: A... |
668 |
* |
2317d5f1c sched/deadline: U... |
669 |
* Notice that the bandwidth check is done against the deadline. For |
755378a47 sched/deadline: A... |
670 |
* task with deadline equal to period this is the same of using |
2317d5f1c sched/deadline: U... |
671 |
* dl_period instead of dl_deadline in the equation above. |
aab03e05e sched/deadline: A... |
672 |
*/ |
2d3d891d3 sched/deadline: A... |
673 674 |
static bool dl_entity_overflow(struct sched_dl_entity *dl_se, struct sched_dl_entity *pi_se, u64 t) |
aab03e05e sched/deadline: A... |
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
{ u64 left, right; /* * left and right are the two sides of the equation above, * after a bit of shuffling to use multiplications instead * of divisions. * * Note that none of the time values involved in the two * multiplications are absolute: dl_deadline and dl_runtime * are the relative deadline and the maximum runtime of each * instance, runtime is the runtime left for the last instance * and (deadline - t), since t is rq->clock, is the time left * to the (absolute) deadline. Even if overflowing the u64 type * is very unlikely to occur in both cases, here we scale down * as we want to avoid that risk at all. Scaling down by 10 * means that we reduce granularity to 1us. We are fine with it, * since this is only a true/false check and, anyway, thinking * of anything below microseconds resolution is actually fiction * (but still we want to give the user that illusion >;). */ |
2317d5f1c sched/deadline: U... |
696 |
left = (pi_se->dl_deadline >> DL_SCALE) * (dl_se->runtime >> DL_SCALE); |
332ac17ef sched/deadline: A... |
697 698 |
right = ((dl_se->deadline - t) >> DL_SCALE) * (pi_se->dl_runtime >> DL_SCALE); |
aab03e05e sched/deadline: A... |
699 700 701 702 703 |
return dl_time_before(right, left); } /* |
3effcb424 sched/deadline: U... |
704 705 706 707 |
* Revised wakeup rule [1]: For self-suspending tasks, rather then * re-initializing task's runtime and deadline, the revised wakeup * rule adjusts the task's runtime to avoid the task to overrun its * density. |
aab03e05e sched/deadline: A... |
708 |
* |
3effcb424 sched/deadline: U... |
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
* Reasoning: a task may overrun the density if: * runtime / (deadline - t) > dl_runtime / dl_deadline * * Therefore, runtime can be adjusted to: * runtime = (dl_runtime / dl_deadline) * (deadline - t) * * In such way that runtime will be equal to the maximum density * the task can use without breaking any rule. * * [1] Luca Abeni, Giuseppe Lipari, and Juri Lelli. 2015. Constant * bandwidth server revisited. SIGBED Rev. 11, 4 (January 2015), 19-24. */ static void update_dl_revised_wakeup(struct sched_dl_entity *dl_se, struct rq *rq) { u64 laxity = dl_se->deadline - rq_clock(rq); /* * If the task has deadline < period, and the deadline is in the past, * it should already be throttled before this check. * * See update_dl_entity() comments for further details. */ WARN_ON(dl_time_before(dl_se->deadline, rq_clock(rq))); dl_se->runtime = (dl_se->dl_density * laxity) >> BW_SHIFT; } /* * Regarding the deadline, a task with implicit deadline has a relative * deadline == relative period. A task with constrained deadline has a * relative deadline <= relative period. * * We support constrained deadline tasks. However, there are some restrictions * applied only for tasks which do not have an implicit deadline. See * update_dl_entity() to know more about such restrictions. * * The dl_is_implicit() returns true if the task has an implicit deadline. */ static inline bool dl_is_implicit(struct sched_dl_entity *dl_se) { return dl_se->dl_deadline == dl_se->dl_period; } /* * When a deadline entity is placed in the runqueue, its runtime and deadline * might need to be updated. This is done by a CBS wake up rule. There are two * different rules: 1) the original CBS; and 2) the Revisited CBS. * * When the task is starting a new period, the Original CBS is used. In this * case, the runtime is replenished and a new absolute deadline is set. * * When a task is queued before the begin of the next period, using the * remaining runtime and deadline could make the entity to overflow, see * dl_entity_overflow() to find more about runtime overflow. When such case * is detected, the runtime and deadline need to be updated. * * If the task has an implicit deadline, i.e., deadline == period, the Original * CBS is applied. the runtime is replenished and a new absolute deadline is * set, as in the previous cases. * * However, the Original CBS does not work properly for tasks with * deadline < period, which are said to have a constrained deadline. By * applying the Original CBS, a constrained deadline task would be able to run * runtime/deadline in a period. With deadline < period, the task would * overrun the runtime/period allowed bandwidth, breaking the admission test. * * In order to prevent this misbehave, the Revisited CBS is used for * constrained deadline tasks when a runtime overflow is detected. In the * Revisited CBS, rather than replenishing & setting a new absolute deadline, * the remaining runtime of the task is reduced to avoid runtime overflow. * Please refer to the comments update_dl_revised_wakeup() function to find * more about the Revised CBS rule. |
aab03e05e sched/deadline: A... |
782 |
*/ |
2d3d891d3 sched/deadline: A... |
783 784 |
static void update_dl_entity(struct sched_dl_entity *dl_se, struct sched_dl_entity *pi_se) |
aab03e05e sched/deadline: A... |
785 786 787 |
{ struct dl_rq *dl_rq = dl_rq_of_se(dl_se); struct rq *rq = rq_of_dl_rq(dl_rq); |
aab03e05e sched/deadline: A... |
788 |
if (dl_time_before(dl_se->deadline, rq_clock(rq)) || |
2d3d891d3 sched/deadline: A... |
789 |
dl_entity_overflow(dl_se, pi_se, rq_clock(rq))) { |
3effcb424 sched/deadline: U... |
790 791 792 793 794 795 796 |
if (unlikely(!dl_is_implicit(dl_se) && !dl_time_before(dl_se->deadline, rq_clock(rq)) && !dl_se->dl_boosted)){ update_dl_revised_wakeup(dl_se, rq); return; } |
2d3d891d3 sched/deadline: A... |
797 798 |
dl_se->deadline = rq_clock(rq) + pi_se->dl_deadline; dl_se->runtime = pi_se->dl_runtime; |
aab03e05e sched/deadline: A... |
799 800 |
} } |
5ac69d377 sched/deadline: M... |
801 802 803 804 |
static inline u64 dl_next_period(struct sched_dl_entity *dl_se) { return dl_se->deadline - dl_se->dl_deadline + dl_se->dl_period; } |
aab03e05e sched/deadline: A... |
805 806 807 |
/* * If the entity depleted all its runtime, and if we want it to sleep * while waiting for some new execution time to become available, we |
5ac69d377 sched/deadline: M... |
808 |
* set the bandwidth replenishment timer to the replenishment instant |
aab03e05e sched/deadline: A... |
809 810 811 812 813 814 |
* and try to activate it. * * Notice that it is important for the caller to know if the timer * actually started or not (i.e., the replenishment instant is in * the future or in the past). */ |
a649f237d sched,dl: Fix sch... |
815 |
static int start_dl_timer(struct task_struct *p) |
aab03e05e sched/deadline: A... |
816 |
{ |
a649f237d sched,dl: Fix sch... |
817 818 819 |
struct sched_dl_entity *dl_se = &p->dl; struct hrtimer *timer = &dl_se->dl_timer; struct rq *rq = task_rq(p); |
aab03e05e sched/deadline: A... |
820 |
ktime_t now, act; |
aab03e05e sched/deadline: A... |
821 |
s64 delta; |
a649f237d sched,dl: Fix sch... |
822 |
lockdep_assert_held(&rq->lock); |
aab03e05e sched/deadline: A... |
823 824 825 826 827 |
/* * We want the timer to fire at the deadline, but considering * that it is actually coming from rq->clock and not from * hrtimer's time base reading. */ |
5ac69d377 sched/deadline: M... |
828 |
act = ns_to_ktime(dl_next_period(dl_se)); |
a649f237d sched,dl: Fix sch... |
829 |
now = hrtimer_cb_get_time(timer); |
aab03e05e sched/deadline: A... |
830 831 832 833 834 835 836 837 838 839 |
delta = ktime_to_ns(now) - rq_clock(rq); act = ktime_add_ns(act, delta); /* * If the expiry time already passed, e.g., because the value * chosen as the deadline is too small, don't even try to * start the timer in the past! */ if (ktime_us_delta(act, now) < 0) return 0; |
a649f237d sched,dl: Fix sch... |
840 841 842 843 844 845 846 847 848 849 850 851 852 |
/* * !enqueued will guarantee another callback; even if one is already in * progress. This ensures a balanced {get,put}_task_struct(). * * The race against __run_timer() clearing the enqueued state is * harmless because we're holding task_rq()->lock, therefore the timer * expiring after we've done the check will wait on its task_rq_lock() * and observe our state. */ if (!hrtimer_is_queued(timer)) { get_task_struct(p); hrtimer_start(timer, act, HRTIMER_MODE_ABS); } |
aab03e05e sched/deadline: A... |
853 |
|
cc9684d3c sched: deadline: ... |
854 |
return 1; |
aab03e05e sched/deadline: A... |
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 |
} /* * This is the bandwidth enforcement timer callback. If here, we know * a task is not on its dl_rq, since the fact that the timer was running * means the task is throttled and needs a runtime replenishment. * * However, what we actually do depends on the fact the task is active, * (it is on its rq) or has been removed from there by a call to * dequeue_task_dl(). In the former case we must issue the runtime * replenishment and add the task back to the dl_rq; in the latter, we just * do nothing but clearing dl_throttled, so that runtime and deadline * updating (and the queueing back to dl_rq) will be done by the * next call to enqueue_task_dl(). */ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer) { struct sched_dl_entity *dl_se = container_of(timer, struct sched_dl_entity, dl_timer); struct task_struct *p = dl_task_of(dl_se); |
eb5807514 sched/core: Intro... |
876 |
struct rq_flags rf; |
0f397f2c9 sched/dl: Fix rac... |
877 |
struct rq *rq; |
3960c8c0c sched: Make dl_ta... |
878 |
|
eb5807514 sched/core: Intro... |
879 |
rq = task_rq_lock(p, &rf); |
0f397f2c9 sched/dl: Fix rac... |
880 |
|
aab03e05e sched/deadline: A... |
881 |
/* |
a649f237d sched,dl: Fix sch... |
882 |
* The task might have changed its scheduling policy to something |
9846d50df sched/deadline: F... |
883 |
* different than SCHED_DEADLINE (through switched_from_dl()). |
a649f237d sched,dl: Fix sch... |
884 |
*/ |
209a0cbda sched/deadline: I... |
885 |
if (!dl_task(p)) |
a649f237d sched,dl: Fix sch... |
886 |
goto unlock; |
a649f237d sched,dl: Fix sch... |
887 888 |
/* |
a649f237d sched,dl: Fix sch... |
889 890 891 892 893 |
* The task might have been boosted by someone else and might be in the * boosting/deboosting path, its not throttled. */ if (dl_se->dl_boosted) goto unlock; |
a79ec89fd sched/dl: Prevent... |
894 |
|
fa9c9d10e sched/deadline: S... |
895 |
/* |
a649f237d sched,dl: Fix sch... |
896 897 |
* Spurious timer due to start_dl_timer() race; or we already received * a replenishment from rt_mutex_setprio(). |
fa9c9d10e sched/deadline: S... |
898 |
*/ |
a649f237d sched,dl: Fix sch... |
899 |
if (!dl_se->dl_throttled) |
fa9c9d10e sched/deadline: S... |
900 |
goto unlock; |
a649f237d sched,dl: Fix sch... |
901 902 903 |
sched_clock_tick(); update_rq_clock(rq); |
fa9c9d10e sched/deadline: S... |
904 |
|
a79ec89fd sched/dl: Prevent... |
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 |
/* * If the throttle happened during sched-out; like: * * schedule() * deactivate_task() * dequeue_task_dl() * update_curr_dl() * start_dl_timer() * __dequeue_task_dl() * prev->on_rq = 0; * * We can be both throttled and !queued. Replenish the counter * but do not enqueue -- wait for our wakeup to do that. */ if (!task_on_rq_queued(p)) { replenish_dl_entity(dl_se, dl_se); goto unlock; } |
1baca4ce1 sched/deadline: A... |
923 |
#ifdef CONFIG_SMP |
c0c8c9fa2 sched/deadline: F... |
924 |
if (unlikely(!rq->online)) { |
61c7aca69 sched/deadline: F... |
925 926 927 928 |
/* * If the runqueue is no longer available, migrate the * task elsewhere. This necessarily changes rq. */ |
c0c8c9fa2 sched/deadline: F... |
929 |
lockdep_unpin_lock(&rq->lock, rf.cookie); |
a649f237d sched,dl: Fix sch... |
930 |
rq = dl_task_offline_migration(rq, p); |
c0c8c9fa2 sched/deadline: F... |
931 |
rf.cookie = lockdep_pin_lock(&rq->lock); |
dcc3b5ffe sched/deadline: A... |
932 |
update_rq_clock(rq); |
61c7aca69 sched/deadline: F... |
933 934 935 936 937 938 |
/* * Now that the task has been migrated to the new RQ and we * have that locked, proceed as normal and enqueue the task * there. */ |
c0c8c9fa2 sched/deadline: F... |
939 |
} |
61c7aca69 sched/deadline: F... |
940 |
#endif |
a649f237d sched,dl: Fix sch... |
941 |
|
61c7aca69 sched/deadline: F... |
942 943 944 945 946 |
enqueue_task_dl(rq, p, ENQUEUE_REPLENISH); if (dl_task(rq->curr)) check_preempt_curr_dl(rq, p, 0); else resched_curr(rq); |
a649f237d sched,dl: Fix sch... |
947 |
|
61c7aca69 sched/deadline: F... |
948 |
#ifdef CONFIG_SMP |
a649f237d sched,dl: Fix sch... |
949 950 951 |
/* * Queueing this task back might have overloaded rq, check if we need * to kick someone away. |
1019a359d sched/deadline: F... |
952 |
*/ |
0aaafaabf sched/core: Add m... |
953 954 955 956 957 |
if (has_pushable_dl_tasks(rq)) { /* * Nothing relies on rq->lock after this, so its safe to drop * rq->lock. */ |
d8ac89713 sched/core: Add w... |
958 |
rq_unpin_lock(rq, &rf); |
1019a359d sched/deadline: F... |
959 |
push_dl_task(rq); |
d8ac89713 sched/core: Add w... |
960 |
rq_repin_lock(rq, &rf); |
0aaafaabf sched/core: Add m... |
961 |
} |
1baca4ce1 sched/deadline: A... |
962 |
#endif |
a649f237d sched,dl: Fix sch... |
963 |
|
aab03e05e sched/deadline: A... |
964 |
unlock: |
eb5807514 sched/core: Intro... |
965 |
task_rq_unlock(rq, p, &rf); |
aab03e05e sched/deadline: A... |
966 |
|
a649f237d sched,dl: Fix sch... |
967 968 969 970 971 |
/* * This can free the task_struct, including this hrtimer, do not touch * anything related to that after this. */ put_task_struct(p); |
aab03e05e sched/deadline: A... |
972 973 974 975 976 977 |
return HRTIMER_NORESTART; } void init_dl_task_timer(struct sched_dl_entity *dl_se) { struct hrtimer *timer = &dl_se->dl_timer; |
aab03e05e sched/deadline: A... |
978 979 980 |
hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); timer->function = dl_task_timer; } |
df8eac8ca sched/deadline: T... |
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
/* * During the activation, CBS checks if it can reuse the current task's * runtime and period. If the deadline of the task is in the past, CBS * cannot use the runtime, and so it replenishes the task. This rule * works fine for implicit deadline tasks (deadline == period), and the * CBS was designed for implicit deadline tasks. However, a task with * constrained deadline (deadine < period) might be awakened after the * deadline, but before the next period. In this case, replenishing the * task would allow it to run for runtime / deadline. As in this case * deadline < period, CBS enables a task to run for more than the * runtime / period. In a very loaded system, this can cause a domino * effect, making other tasks miss their deadlines. * * To avoid this problem, in the activation of a constrained deadline * task after the deadline but before the next period, throttle the * task and set the replenishing timer to the begin of the next period, * unless it is boosted. */ static inline void dl_check_constrained_dl(struct sched_dl_entity *dl_se) { struct task_struct *p = dl_task_of(dl_se); struct rq *rq = rq_of_dl_rq(dl_rq_of_se(dl_se)); if (dl_time_before(dl_se->deadline, rq_clock(rq)) && dl_time_before(rq_clock(rq), dl_next_period(dl_se))) { if (unlikely(dl_se->dl_boosted || !start_dl_timer(p))) return; dl_se->dl_throttled = 1; |
ae83b56a5 sched/deadline: Z... |
1009 1010 |
if (dl_se->runtime > 0) dl_se->runtime = 0; |
df8eac8ca sched/deadline: T... |
1011 1012 |
} } |
aab03e05e sched/deadline: A... |
1013 |
static |
6fab54101 sched/deadline: R... |
1014 |
int dl_runtime_exceeded(struct sched_dl_entity *dl_se) |
aab03e05e sched/deadline: A... |
1015 |
{ |
269ad8015 sched/deadline: A... |
1016 |
return (dl_se->runtime <= 0); |
aab03e05e sched/deadline: A... |
1017 |
} |
faa599373 sched/deadline: P... |
1018 |
extern bool sched_rt_bandwidth_account(struct rt_rq *rt_rq); |
aab03e05e sched/deadline: A... |
1019 |
/* |
c52f14d38 sched/deadline: I... |
1020 1021 |
* This function implements the GRUB accounting rule: * according to the GRUB reclaiming algorithm, the runtime is |
daec57983 sched/deadline: R... |
1022 1023 1024 1025 1026 1027 1028 |
* not decreased as "dq = -dt", but as * "dq = -max{u / Umax, (1 - Uinact - Uextra)} dt", * where u is the utilization of the task, Umax is the maximum reclaimable * utilization, Uinact is the (per-runqueue) inactive utilization, computed * as the difference between the "total runqueue utilization" and the * runqueue active utilization, and Uextra is the (per runqueue) extra * reclaimable utilization. |
9f0d1a507 sched/deadline: B... |
1029 |
* Since rq->dl.running_bw and rq->dl.this_bw contain utilizations |
daec57983 sched/deadline: R... |
1030 1031 1032 1033 1034 1035 1036 |
* multiplied by 2^BW_SHIFT, the result has to be shifted right by * BW_SHIFT. * Since rq->dl.bw_ratio contains 1 / Umax multipled by 2^RATIO_SHIFT, * dl_bw is multiped by rq->dl.bw_ratio and shifted right by RATIO_SHIFT. * Since delta is a 64 bit variable, to have an overflow its value * should be larger than 2^(64 - 20 - 8), which is more than 64 seconds. * So, overflow is not an issue here. |
c52f14d38 sched/deadline: I... |
1037 |
*/ |
588977742 sched/deadline: M... |
1038 |
static u64 grub_reclaim(u64 delta, struct rq *rq, struct sched_dl_entity *dl_se) |
c52f14d38 sched/deadline: I... |
1039 |
{ |
9f0d1a507 sched/deadline: B... |
1040 1041 |
u64 u_inact = rq->dl.this_bw - rq->dl.running_bw; /* Utot - Uact */ u64 u_act; |
daec57983 sched/deadline: R... |
1042 |
u64 u_act_min = (dl_se->dl_bw * rq->dl.bw_ratio) >> RATIO_SHIFT; |
c52f14d38 sched/deadline: I... |
1043 |
|
9f0d1a507 sched/deadline: B... |
1044 |
/* |
daec57983 sched/deadline: R... |
1045 1046 1047 1048 1049 1050 |
* Instead of computing max{u * bw_ratio, (1 - u_inact - u_extra)}, * we compare u_inact + rq->dl.extra_bw with * 1 - (u * rq->dl.bw_ratio >> RATIO_SHIFT), because * u_inact + rq->dl.extra_bw can be larger than * 1 * (so, 1 - u_inact - rq->dl.extra_bw would be negative * leading to wrong results) |
9f0d1a507 sched/deadline: B... |
1051 |
*/ |
daec57983 sched/deadline: R... |
1052 1053 |
if (u_inact + rq->dl.extra_bw > BW_UNIT - u_act_min) u_act = u_act_min; |
9f0d1a507 sched/deadline: B... |
1054 |
else |
daec57983 sched/deadline: R... |
1055 |
u_act = BW_UNIT - u_inact - rq->dl.extra_bw; |
9f0d1a507 sched/deadline: B... |
1056 1057 |
return (delta * u_act) >> BW_SHIFT; |
c52f14d38 sched/deadline: I... |
1058 1059 1060 |
} /* |
aab03e05e sched/deadline: A... |
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 |
* Update the current task's runtime statistics (provided it is still * a -deadline task and has not been removed from the dl_rq). */ static void update_curr_dl(struct rq *rq) { struct task_struct *curr = rq->curr; struct sched_dl_entity *dl_se = &curr->dl; u64 delta_exec; if (!dl_task(curr) || !on_dl_rq(dl_se)) return; /* * Consumed budget is computed considering the time as * observed by schedulable tasks (excluding time spent * in hardirq context, etc.). Deadlines are instead * computed using hard walltime. This seems to be the more * natural solution, but the full ramifications of this * approach need further study. */ delta_exec = rq_clock_task(rq) - curr->se.exec_start; |
48be3a67d sched/deadline: A... |
1082 1083 1084 |
if (unlikely((s64)delta_exec <= 0)) { if (unlikely(dl_se->dl_yielded)) goto throttle; |
734ff2a71 sched/rt: Fix pic... |
1085 |
return; |
48be3a67d sched/deadline: A... |
1086 |
} |
aab03e05e sched/deadline: A... |
1087 |
|
58919e83c cpufreq / sched: ... |
1088 |
/* kick cpufreq (see the comment in kernel/sched/sched.h). */ |
674e75411 sched: cpufreq: A... |
1089 |
cpufreq_update_util(rq, SCHED_CPUFREQ_DL); |
594dd290c sched/cpufreq: Op... |
1090 |
|
aab03e05e sched/deadline: A... |
1091 1092 1093 1094 1095 1096 1097 1098 |
schedstat_set(curr->se.statistics.exec_max, max(curr->se.statistics.exec_max, delta_exec)); curr->se.sum_exec_runtime += delta_exec; account_group_exec_runtime(curr, delta_exec); curr->se.exec_start = rq_clock_task(rq); cpuacct_charge(curr, delta_exec); |
239be4a98 sched/deadline: A... |
1099 |
sched_rt_avg_update(rq, delta_exec); |
2d4283e9d sched/deadline: M... |
1100 |
if (unlikely(dl_se->flags & SCHED_FLAG_RECLAIM)) |
9f0d1a507 sched/deadline: B... |
1101 |
delta_exec = grub_reclaim(delta_exec, rq, &curr->dl); |
48be3a67d sched/deadline: A... |
1102 1103 1104 1105 |
dl_se->runtime -= delta_exec; throttle: if (dl_runtime_exceeded(dl_se) || dl_se->dl_yielded) { |
1019a359d sched/deadline: F... |
1106 |
dl_se->dl_throttled = 1; |
aab03e05e sched/deadline: A... |
1107 |
__dequeue_task_dl(rq, curr, 0); |
a649f237d sched,dl: Fix sch... |
1108 |
if (unlikely(dl_se->dl_boosted || !start_dl_timer(curr))) |
aab03e05e sched/deadline: A... |
1109 1110 1111 |
enqueue_task_dl(rq, curr, ENQUEUE_REPLENISH); if (!is_leftmost(curr, &rq->dl)) |
8875125ef sched: Transform ... |
1112 |
resched_curr(rq); |
aab03e05e sched/deadline: A... |
1113 |
} |
1724813d9 sched/deadline: R... |
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 |
/* * Because -- for now -- we share the rt bandwidth, we need to * account our runtime there too, otherwise actual rt tasks * would be able to exceed the shared quota. * * Account to the root rt group for now. * * The solution we're working towards is having the RT groups scheduled * using deadline servers -- however there's a few nasties to figure * out before that can happen. */ if (rt_bandwidth_enabled()) { struct rt_rq *rt_rq = &rq->rt; raw_spin_lock(&rt_rq->rt_runtime_lock); |
1724813d9 sched/deadline: R... |
1130 1131 |
/* * We'll let actual RT tasks worry about the overflow here, we |
faa599373 sched/deadline: P... |
1132 1133 |
* have our own CBS to keep us inline; only account when RT * bandwidth is relevant. |
1724813d9 sched/deadline: R... |
1134 |
*/ |
faa599373 sched/deadline: P... |
1135 1136 |
if (sched_rt_bandwidth_account(rt_rq)) rt_rq->rt_time += delta_exec; |
1724813d9 sched/deadline: R... |
1137 1138 |
raw_spin_unlock(&rt_rq->rt_runtime_lock); } |
aab03e05e sched/deadline: A... |
1139 |
} |
209a0cbda sched/deadline: I... |
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 |
static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer) { struct sched_dl_entity *dl_se = container_of(timer, struct sched_dl_entity, inactive_timer); struct task_struct *p = dl_task_of(dl_se); struct rq_flags rf; struct rq *rq; rq = task_rq_lock(p, &rf); if (!dl_task(p) || p->state == TASK_DEAD) { |
387e31300 sched/deadline: F... |
1152 |
struct dl_bw *dl_b = dl_bw_of(task_cpu(p)); |
209a0cbda sched/deadline: I... |
1153 1154 |
if (p->state == TASK_DEAD && dl_se->dl_non_contending) { sub_running_bw(p->dl.dl_bw, dl_rq_of_se(&p->dl)); |
8fd27231c sched/deadline: T... |
1155 |
sub_rq_bw(p->dl.dl_bw, dl_rq_of_se(&p->dl)); |
209a0cbda sched/deadline: I... |
1156 1157 |
dl_se->dl_non_contending = 0; } |
387e31300 sched/deadline: F... |
1158 1159 |
raw_spin_lock(&dl_b->lock); |
daec57983 sched/deadline: R... |
1160 |
__dl_clear(dl_b, p->dl.dl_bw, dl_bw_cpus(task_cpu(p))); |
387e31300 sched/deadline: F... |
1161 |
raw_spin_unlock(&dl_b->lock); |
209a0cbda sched/deadline: I... |
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
__dl_clear_params(p); goto unlock; } if (dl_se->dl_non_contending == 0) goto unlock; sched_clock_tick(); update_rq_clock(rq); sub_running_bw(dl_se->dl_bw, &rq->dl); dl_se->dl_non_contending = 0; unlock: task_rq_unlock(rq, p, &rf); put_task_struct(p); return HRTIMER_NORESTART; } void init_dl_inactive_task_timer(struct sched_dl_entity *dl_se) { struct hrtimer *timer = &dl_se->inactive_timer; hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); timer->function = inactive_task_timer; } |
1baca4ce1 sched/deadline: A... |
1188 |
#ifdef CONFIG_SMP |
1baca4ce1 sched/deadline: A... |
1189 1190 1191 1192 1193 1194 |
static void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline) { struct rq *rq = rq_of_dl_rq(dl_rq); if (dl_rq->earliest_dl.curr == 0 || dl_time_before(deadline, dl_rq->earliest_dl.curr)) { |
1baca4ce1 sched/deadline: A... |
1195 |
dl_rq->earliest_dl.curr = deadline; |
d8206bb3f sched/deadline: S... |
1196 |
cpudl_set(&rq->rd->cpudl, rq->cpu, deadline); |
1baca4ce1 sched/deadline: A... |
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 |
} } static void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline) { struct rq *rq = rq_of_dl_rq(dl_rq); /* * Since we may have removed our earliest (and/or next earliest) * task we must recompute them. */ if (!dl_rq->dl_nr_running) { dl_rq->earliest_dl.curr = 0; dl_rq->earliest_dl.next = 0; |
d8206bb3f sched/deadline: S... |
1211 |
cpudl_clear(&rq->rd->cpudl, rq->cpu); |
1baca4ce1 sched/deadline: A... |
1212 |
} else { |
2161573ec sched/deadline: r... |
1213 |
struct rb_node *leftmost = dl_rq->root.rb_leftmost; |
1baca4ce1 sched/deadline: A... |
1214 1215 1216 1217 |
struct sched_dl_entity *entry; entry = rb_entry(leftmost, struct sched_dl_entity, rb_node); dl_rq->earliest_dl.curr = entry->deadline; |
d8206bb3f sched/deadline: S... |
1218 |
cpudl_set(&rq->rd->cpudl, rq->cpu, entry->deadline); |
1baca4ce1 sched/deadline: A... |
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 |
} } #else static inline void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {} static inline void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {} #endif /* CONFIG_SMP */ static inline void inc_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) { int prio = dl_task_of(dl_se)->prio; u64 deadline = dl_se->deadline; WARN_ON(!dl_prio(prio)); dl_rq->dl_nr_running++; |
724654478 sched, nohz: Chan... |
1237 |
add_nr_running(rq_of_dl_rq(dl_rq), 1); |
1baca4ce1 sched/deadline: A... |
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 |
inc_dl_deadline(dl_rq, deadline); inc_dl_migration(dl_se, dl_rq); } static inline void dec_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq) { int prio = dl_task_of(dl_se)->prio; WARN_ON(!dl_prio(prio)); WARN_ON(!dl_rq->dl_nr_running); dl_rq->dl_nr_running--; |
724654478 sched, nohz: Chan... |
1251 |
sub_nr_running(rq_of_dl_rq(dl_rq), 1); |
1baca4ce1 sched/deadline: A... |
1252 1253 1254 1255 |
dec_dl_deadline(dl_rq, dl_se->deadline); dec_dl_migration(dl_se, dl_rq); } |
aab03e05e sched/deadline: A... |
1256 1257 1258 |
static void __enqueue_dl_entity(struct sched_dl_entity *dl_se) { struct dl_rq *dl_rq = dl_rq_of_se(dl_se); |
2161573ec sched/deadline: r... |
1259 |
struct rb_node **link = &dl_rq->root.rb_root.rb_node; |
aab03e05e sched/deadline: A... |
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 |
struct rb_node *parent = NULL; struct sched_dl_entity *entry; int leftmost = 1; BUG_ON(!RB_EMPTY_NODE(&dl_se->rb_node)); while (*link) { parent = *link; entry = rb_entry(parent, struct sched_dl_entity, rb_node); if (dl_time_before(dl_se->deadline, entry->deadline)) link = &parent->rb_left; else { link = &parent->rb_right; leftmost = 0; } } |
aab03e05e sched/deadline: A... |
1276 |
rb_link_node(&dl_se->rb_node, parent, link); |
2161573ec sched/deadline: r... |
1277 |
rb_insert_color_cached(&dl_se->rb_node, &dl_rq->root, leftmost); |
aab03e05e sched/deadline: A... |
1278 |
|
1baca4ce1 sched/deadline: A... |
1279 |
inc_dl_tasks(dl_se, dl_rq); |
aab03e05e sched/deadline: A... |
1280 1281 1282 1283 1284 1285 1286 1287 |
} static void __dequeue_dl_entity(struct sched_dl_entity *dl_se) { struct dl_rq *dl_rq = dl_rq_of_se(dl_se); if (RB_EMPTY_NODE(&dl_se->rb_node)) return; |
2161573ec sched/deadline: r... |
1288 |
rb_erase_cached(&dl_se->rb_node, &dl_rq->root); |
aab03e05e sched/deadline: A... |
1289 |
RB_CLEAR_NODE(&dl_se->rb_node); |
1baca4ce1 sched/deadline: A... |
1290 |
dec_dl_tasks(dl_se, dl_rq); |
aab03e05e sched/deadline: A... |
1291 1292 1293 |
} static void |
2d3d891d3 sched/deadline: A... |
1294 1295 |
enqueue_dl_entity(struct sched_dl_entity *dl_se, struct sched_dl_entity *pi_se, int flags) |
aab03e05e sched/deadline: A... |
1296 1297 1298 1299 1300 1301 1302 1303 |
{ BUG_ON(on_dl_rq(dl_se)); /* * If this is a wakeup or a new instance, the scheduling * parameters of the task might need updating. Otherwise, * we want a replenishment of its runtime. */ |
e36d8677b sched/deadline: T... |
1304 |
if (flags & ENQUEUE_WAKEUP) { |
8fd27231c sched/deadline: T... |
1305 |
task_contending(dl_se, flags); |
2d3d891d3 sched/deadline: A... |
1306 |
update_dl_entity(dl_se, pi_se); |
e36d8677b sched/deadline: T... |
1307 |
} else if (flags & ENQUEUE_REPLENISH) { |
6a503c3be sched/deadline: F... |
1308 |
replenish_dl_entity(dl_se, pi_se); |
fd8cb2e71 sched/deadline: F... |
1309 1310 1311 1312 |
} else if ((flags & ENQUEUE_RESTORE) && dl_time_before(dl_se->deadline, rq_clock(rq_of_dl_rq(dl_rq_of_se(dl_se))))) { setup_new_dl_entity(dl_se); |
e36d8677b sched/deadline: T... |
1313 |
} |
aab03e05e sched/deadline: A... |
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 |
__enqueue_dl_entity(dl_se); } static void dequeue_dl_entity(struct sched_dl_entity *dl_se) { __dequeue_dl_entity(dl_se); } static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags) { |
2d3d891d3 sched/deadline: A... |
1325 1326 1327 1328 |
struct task_struct *pi_task = rt_mutex_get_top_task(p); struct sched_dl_entity *pi_se = &p->dl; /* |
193be41e3 sched/deadline: F... |
1329 1330 1331 1332 1333 1334 |
* Use the scheduling parameters of the top pi-waiter task if: * - we have a top pi-waiter which is a SCHED_DEADLINE task AND * - our dl_boosted is set (i.e. the pi-waiter's (absolute) deadline is * smaller than our deadline OR we are a !SCHED_DEADLINE task getting * boosted due to a SCHED_DEADLINE pi-waiter). * Otherwise we keep our runtime and deadline. |
2d3d891d3 sched/deadline: A... |
1335 |
*/ |
193be41e3 sched/deadline: F... |
1336 |
if (pi_task && dl_prio(pi_task->normal_prio) && p->dl.dl_boosted) { |
2d3d891d3 sched/deadline: A... |
1337 |
pi_se = &pi_task->dl; |
64be6f1f5 sched/deadline: D... |
1338 1339 1340 |
} else if (!dl_prio(p->normal_prio)) { /* * Special case in which we have a !SCHED_DEADLINE task |
193be41e3 sched/deadline: F... |
1341 |
* that is going to be deboosted, but exceeds its |
64be6f1f5 sched/deadline: D... |
1342 1343 1344 1345 1346 1347 1348 |
* runtime while doing so. No point in replenishing * it, as it's going to return back to its original * scheduling class after this. */ BUG_ON(!p->dl.dl_boosted || flags != ENQUEUE_REPLENISH); return; } |
2d3d891d3 sched/deadline: A... |
1349 |
|
aab03e05e sched/deadline: A... |
1350 |
/* |
df8eac8ca sched/deadline: T... |
1351 1352 1353 1354 1355 |
* Check if a constrained deadline task was activated * after the deadline but before the next period. * If that is the case, the task will be throttled and * the replenishment timer will be set to the next period. */ |
3effcb424 sched/deadline: U... |
1356 |
if (!p->dl.dl_throttled && !dl_is_implicit(&p->dl)) |
df8eac8ca sched/deadline: T... |
1357 |
dl_check_constrained_dl(&p->dl); |
8fd27231c sched/deadline: T... |
1358 1359 |
if (p->on_rq == TASK_ON_RQ_MIGRATING || flags & ENQUEUE_RESTORE) { add_rq_bw(p->dl.dl_bw, &rq->dl); |
e36d8677b sched/deadline: T... |
1360 |
add_running_bw(p->dl.dl_bw, &rq->dl); |
8fd27231c sched/deadline: T... |
1361 |
} |
e36d8677b sched/deadline: T... |
1362 |
|
df8eac8ca sched/deadline: T... |
1363 |
/* |
e36d8677b sched/deadline: T... |
1364 |
* If p is throttled, we do not enqueue it. In fact, if it exhausted |
aab03e05e sched/deadline: A... |
1365 1366 1367 |
* its budget it needs a replenishment and, since it now is on * its rq, the bandwidth timer callback (which clearly has not * run yet) will take care of this. |
e36d8677b sched/deadline: T... |
1368 1369 1370 1371 1372 1373 |
* However, the active utilization does not depend on the fact * that the task is on the runqueue or not (but depends on the * task's state - in GRUB parlance, "inactive" vs "active contending"). * In other words, even if a task is throttled its utilization must * be counted in the active utilization; hence, we need to call * add_running_bw(). |
aab03e05e sched/deadline: A... |
1374 |
*/ |
e36d8677b sched/deadline: T... |
1375 |
if (p->dl.dl_throttled && !(flags & ENQUEUE_REPLENISH)) { |
209a0cbda sched/deadline: I... |
1376 |
if (flags & ENQUEUE_WAKEUP) |
8fd27231c sched/deadline: T... |
1377 |
task_contending(&p->dl, flags); |
209a0cbda sched/deadline: I... |
1378 |
|
aab03e05e sched/deadline: A... |
1379 |
return; |
e36d8677b sched/deadline: T... |
1380 |
} |
aab03e05e sched/deadline: A... |
1381 |
|
2d3d891d3 sched/deadline: A... |
1382 |
enqueue_dl_entity(&p->dl, pi_se, flags); |
1baca4ce1 sched/deadline: A... |
1383 |
|
4b53a3412 sched/core: Remov... |
1384 |
if (!task_current(rq, p) && p->nr_cpus_allowed > 1) |
1baca4ce1 sched/deadline: A... |
1385 |
enqueue_pushable_dl_task(rq, p); |
aab03e05e sched/deadline: A... |
1386 1387 1388 1389 1390 |
} static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) { dequeue_dl_entity(&p->dl); |
1baca4ce1 sched/deadline: A... |
1391 |
dequeue_pushable_dl_task(rq, p); |
aab03e05e sched/deadline: A... |
1392 1393 1394 1395 1396 1397 |
} static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) { update_curr_dl(rq); __dequeue_task_dl(rq, p, flags); |
e36d8677b sched/deadline: T... |
1398 |
|
8fd27231c sched/deadline: T... |
1399 |
if (p->on_rq == TASK_ON_RQ_MIGRATING || flags & DEQUEUE_SAVE) { |
e36d8677b sched/deadline: T... |
1400 |
sub_running_bw(p->dl.dl_bw, &rq->dl); |
8fd27231c sched/deadline: T... |
1401 1402 |
sub_rq_bw(p->dl.dl_bw, &rq->dl); } |
e36d8677b sched/deadline: T... |
1403 1404 |
/* |
209a0cbda sched/deadline: I... |
1405 1406 |
* This check allows to start the inactive timer (or to immediately * decrease the active utilization, if needed) in two cases: |
e36d8677b sched/deadline: T... |
1407 1408 1409 1410 1411 1412 1413 |
* when the task blocks and when it is terminating * (p->state == TASK_DEAD). We can handle the two cases in the same * way, because from GRUB's point of view the same thing is happening * (the task moves from "active contending" to "active non contending" * or "inactive") */ if (flags & DEQUEUE_SLEEP) |
209a0cbda sched/deadline: I... |
1414 |
task_non_contending(p); |
aab03e05e sched/deadline: A... |
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 |
} /* * Yield task semantic for -deadline tasks is: * * get off from the CPU until our next instance, with * a new runtime. This is of little use now, since we * don't have a bandwidth reclaiming mechanism. Anyway, * bandwidth reclaiming is planned for the future, and * yield_task_dl will indicate that some spare budget * is available for other task instances to use it. */ static void yield_task_dl(struct rq *rq) { |
aab03e05e sched/deadline: A... |
1429 1430 1431 1432 |
/* * We make the task go to sleep until its current deadline by * forcing its runtime to zero. This way, update_curr_dl() stops * it and the bandwidth timer will wake it up and will give it |
5bfd126e8 sched/deadline: F... |
1433 |
* new scheduling parameters (thanks to dl_yielded=1). |
aab03e05e sched/deadline: A... |
1434 |
*/ |
48be3a67d sched/deadline: A... |
1435 |
rq->curr->dl.dl_yielded = 1; |
6f1607f1b sched/dl: Do upda... |
1436 |
update_rq_clock(rq); |
aab03e05e sched/deadline: A... |
1437 |
update_curr_dl(rq); |
44fb085bf sched/deadline: A... |
1438 1439 1440 1441 1442 1443 |
/* * Tell update_rq_clock() that we've just updated, * so we don't do microscopic update in schedule() * and double the fastpath cost. */ rq_clock_skip_update(rq, true); |
aab03e05e sched/deadline: A... |
1444 |
} |
1baca4ce1 sched/deadline: A... |
1445 1446 1447 |
#ifdef CONFIG_SMP static int find_later_rq(struct task_struct *task); |
1baca4ce1 sched/deadline: A... |
1448 1449 1450 1451 1452 1453 |
static int select_task_rq_dl(struct task_struct *p, int cpu, int sd_flag, int flags) { struct task_struct *curr; struct rq *rq; |
1d7e974cb sched/deadline: D... |
1454 |
if (sd_flag != SD_BALANCE_WAKE) |
1baca4ce1 sched/deadline: A... |
1455 1456 1457 1458 1459 |
goto out; rq = cpu_rq(cpu); rcu_read_lock(); |
316c1608d sched, timer: Con... |
1460 |
curr = READ_ONCE(rq->curr); /* unlocked access */ |
1baca4ce1 sched/deadline: A... |
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 |
/* * If we are dealing with a -deadline task, we must * decide where to wake it up. * If it has a later deadline and the current task * on this rq can't move (provided the waking task * can!) we prefer to send it somewhere else. On the * other hand, if it has a shorter deadline, we * try to make it stay here, it might be important. */ if (unlikely(dl_task(curr)) && |
4b53a3412 sched/core: Remov... |
1472 |
(curr->nr_cpus_allowed < 2 || |
1baca4ce1 sched/deadline: A... |
1473 |
!dl_entity_preempt(&p->dl, &curr->dl)) && |
4b53a3412 sched/core: Remov... |
1474 |
(p->nr_cpus_allowed > 1)) { |
1baca4ce1 sched/deadline: A... |
1475 |
int target = find_later_rq(p); |
9d5142624 sched/deadline: R... |
1476 |
if (target != -1 && |
5aa505078 sched/deadline: F... |
1477 1478 1479 |
(dl_time_before(p->dl.deadline, cpu_rq(target)->dl.earliest_dl.curr) || (cpu_rq(target)->dl.dl_nr_running == 0))) |
1baca4ce1 sched/deadline: A... |
1480 1481 1482 1483 1484 1485 1486 |
cpu = target; } rcu_read_unlock(); out: return cpu; } |
209a0cbda sched/deadline: I... |
1487 1488 1489 |
static void migrate_task_rq_dl(struct task_struct *p) { struct rq *rq; |
8fd27231c sched/deadline: T... |
1490 |
if (p->state != TASK_WAKING) |
209a0cbda sched/deadline: I... |
1491 1492 1493 1494 1495 1496 1497 1498 1499 |
return; rq = task_rq(p); /* * Since p->state == TASK_WAKING, set_task_cpu() has been called * from try_to_wake_up(). Hence, p->pi_lock is locked, but * rq->lock is not... So, lock it */ raw_spin_lock(&rq->lock); |
8fd27231c sched/deadline: T... |
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 |
if (p->dl.dl_non_contending) { sub_running_bw(p->dl.dl_bw, &rq->dl); p->dl.dl_non_contending = 0; /* * If the timer handler is currently running and the * timer cannot be cancelled, inactive_task_timer() * will see that dl_not_contending is not set, and * will not touch the rq's active utilization, * so we are still safe. */ if (hrtimer_try_to_cancel(&p->dl.inactive_timer) == 1) put_task_struct(p); } sub_rq_bw(p->dl.dl_bw, &rq->dl); |
209a0cbda sched/deadline: I... |
1514 1515 |
raw_spin_unlock(&rq->lock); } |
1baca4ce1 sched/deadline: A... |
1516 1517 1518 1519 1520 1521 |
static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p) { /* * Current can't be migrated, useless to reschedule, * let's hope p can move out. */ |
4b53a3412 sched/core: Remov... |
1522 |
if (rq->curr->nr_cpus_allowed == 1 || |
3261ed0b2 sched/deadline: C... |
1523 |
!cpudl_find(&rq->rd->cpudl, rq->curr, NULL)) |
1baca4ce1 sched/deadline: A... |
1524 1525 1526 1527 1528 1529 |
return; /* * p is migratable, so let's not schedule it and * see if it is pushed or pulled somewhere else. */ |
4b53a3412 sched/core: Remov... |
1530 |
if (p->nr_cpus_allowed != 1 && |
3261ed0b2 sched/deadline: C... |
1531 |
cpudl_find(&rq->rd->cpudl, p, NULL)) |
1baca4ce1 sched/deadline: A... |
1532 |
return; |
8875125ef sched: Transform ... |
1533 |
resched_curr(rq); |
1baca4ce1 sched/deadline: A... |
1534 1535 1536 |
} #endif /* CONFIG_SMP */ |
aab03e05e sched/deadline: A... |
1537 1538 1539 1540 1541 1542 1543 |
/* * Only called when both the current and waking task are -deadline * tasks. */ static void check_preempt_curr_dl(struct rq *rq, struct task_struct *p, int flags) { |
1baca4ce1 sched/deadline: A... |
1544 |
if (dl_entity_preempt(&p->dl, &rq->curr->dl)) { |
8875125ef sched: Transform ... |
1545 |
resched_curr(rq); |
1baca4ce1 sched/deadline: A... |
1546 1547 1548 1549 1550 1551 1552 1553 |
return; } #ifdef CONFIG_SMP /* * In the unlikely case current and p have the same deadline * let us try to decide what's the best thing to do... */ |
332ac17ef sched/deadline: A... |
1554 1555 |
if ((p->dl.deadline == rq->curr->dl.deadline) && !test_tsk_need_resched(rq->curr)) |
1baca4ce1 sched/deadline: A... |
1556 1557 |
check_preempt_equal_dl(rq, p); #endif /* CONFIG_SMP */ |
aab03e05e sched/deadline: A... |
1558 1559 1560 1561 1562 |
} #ifdef CONFIG_SCHED_HRTICK static void start_hrtick_dl(struct rq *rq, struct task_struct *p) { |
177ef2a63 sched/deadline: F... |
1563 |
hrtick_start(rq, p->dl.runtime); |
aab03e05e sched/deadline: A... |
1564 |
} |
36ce98818 sched/deadline: I... |
1565 1566 1567 1568 |
#else /* !CONFIG_SCHED_HRTICK */ static void start_hrtick_dl(struct rq *rq, struct task_struct *p) { } |
aab03e05e sched/deadline: A... |
1569 1570 1571 1572 1573 |
#endif static struct sched_dl_entity *pick_next_dl_entity(struct rq *rq, struct dl_rq *dl_rq) { |
2161573ec sched/deadline: r... |
1574 |
struct rb_node *left = rb_first_cached(&dl_rq->root); |
aab03e05e sched/deadline: A... |
1575 1576 1577 1578 1579 1580 |
if (!left) return NULL; return rb_entry(left, struct sched_dl_entity, rb_node); } |
181a80d1f sched: Mark pick_... |
1581 |
static struct task_struct * |
d8ac89713 sched/core: Add w... |
1582 |
pick_next_task_dl(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) |
aab03e05e sched/deadline: A... |
1583 1584 1585 1586 1587 1588 |
{ struct sched_dl_entity *dl_se; struct task_struct *p; struct dl_rq *dl_rq; dl_rq = &rq->dl; |
a1d9a3231 sched: Check for ... |
1589 |
if (need_pull_dl_task(rq, prev)) { |
cbce1a686 sched,lockdep: Em... |
1590 1591 1592 1593 1594 1595 |
/* * This is OK, because current is on_cpu, which avoids it being * picked for load-balance and preemption/IRQs are still * disabled avoiding further scheduler activity on it and we're * being very careful to re-start the picking loop. */ |
d8ac89713 sched/core: Add w... |
1596 |
rq_unpin_lock(rq, rf); |
38033c37f sched: Push down ... |
1597 |
pull_dl_task(rq); |
d8ac89713 sched/core: Add w... |
1598 |
rq_repin_lock(rq, rf); |
a1d9a3231 sched: Check for ... |
1599 |
/* |
176cedc4e sched/dl: Fix com... |
1600 |
* pull_dl_task() can drop (and re-acquire) rq->lock; this |
a1d9a3231 sched: Check for ... |
1601 1602 1603 |
* means a stop task can slip in, in which case we need to * re-start task selection. */ |
da0c1e65b sched: Add wrappe... |
1604 |
if (rq->stop && task_on_rq_queued(rq->stop)) |
a1d9a3231 sched: Check for ... |
1605 1606 |
return RETRY_TASK; } |
734ff2a71 sched/rt: Fix pic... |
1607 1608 1609 1610 1611 1612 |
/* * When prev is DL, we may throttle it in put_prev_task(). * So, we update time before we check for dl_nr_running. */ if (prev->sched_class == &dl_sched_class) update_curr_dl(rq); |
38033c37f sched: Push down ... |
1613 |
|
aab03e05e sched/deadline: A... |
1614 1615 |
if (unlikely(!dl_rq->dl_nr_running)) return NULL; |
3f1d2a318 sched: Fix hotplu... |
1616 |
put_prev_task(rq, prev); |
606dba2e2 sched: Push put_p... |
1617 |
|
aab03e05e sched/deadline: A... |
1618 1619 1620 1621 1622 |
dl_se = pick_next_dl_entity(rq, dl_rq); BUG_ON(!dl_se); p = dl_task_of(dl_se); p->se.exec_start = rq_clock_task(rq); |
1baca4ce1 sched/deadline: A... |
1623 1624 |
/* Running task will never be pushed. */ |
71362650b sched/deadline: N... |
1625 |
dequeue_pushable_dl_task(rq, p); |
1baca4ce1 sched/deadline: A... |
1626 |
|
aab03e05e sched/deadline: A... |
1627 1628 |
if (hrtick_enabled(rq)) start_hrtick_dl(rq, p); |
1baca4ce1 sched/deadline: A... |
1629 |
|
e3fca9e7c sched: Replace po... |
1630 |
queue_push_tasks(rq); |
1baca4ce1 sched/deadline: A... |
1631 |
|
aab03e05e sched/deadline: A... |
1632 1633 1634 1635 1636 1637 |
return p; } static void put_prev_task_dl(struct rq *rq, struct task_struct *p) { update_curr_dl(rq); |
1baca4ce1 sched/deadline: A... |
1638 |
|
4b53a3412 sched/core: Remov... |
1639 |
if (on_dl_rq(&p->dl) && p->nr_cpus_allowed > 1) |
1baca4ce1 sched/deadline: A... |
1640 |
enqueue_pushable_dl_task(rq, p); |
aab03e05e sched/deadline: A... |
1641 1642 1643 1644 1645 |
} static void task_tick_dl(struct rq *rq, struct task_struct *p, int queued) { update_curr_dl(rq); |
a7bebf488 sched/deadline: F... |
1646 1647 1648 1649 1650 1651 1652 |
/* * Even when we have runtime, update_curr_dl() might have resulted in us * not being the leftmost task anymore. In that case NEED_RESCHED will * be set and schedule() will start a new hrtick for the next task. */ if (hrtick_enabled(rq) && queued && p->dl.runtime > 0 && is_leftmost(p, &rq->dl)) |
aab03e05e sched/deadline: A... |
1653 |
start_hrtick_dl(rq, p); |
aab03e05e sched/deadline: A... |
1654 1655 1656 1657 1658 1659 1660 1661 1662 |
} static void task_fork_dl(struct task_struct *p) { /* * SCHED_DEADLINE tasks cannot fork and this is achieved through * sched_fork() */ } |
aab03e05e sched/deadline: A... |
1663 1664 1665 1666 1667 |
static void set_curr_task_dl(struct rq *rq) { struct task_struct *p = rq->curr; p->se.exec_start = rq_clock_task(rq); |
1baca4ce1 sched/deadline: A... |
1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 |
/* You can't push away the running task */ dequeue_pushable_dl_task(rq, p); } #ifdef CONFIG_SMP /* Only try algorithms three times */ #define DL_MAX_TRIES 3 static int pick_dl_task(struct rq *rq, struct task_struct *p, int cpu) { if (!task_running(rq, p) && |
0c98d344f sched/core: Remov... |
1681 |
cpumask_test_cpu(cpu, &p->cpus_allowed)) |
1baca4ce1 sched/deadline: A... |
1682 |
return 1; |
1baca4ce1 sched/deadline: A... |
1683 1684 |
return 0; } |
8b5e770ed sched/deadline: O... |
1685 1686 1687 1688 1689 1690 |
/* * Return the earliest pushable rq's task, which is suitable to be executed * on the CPU, NULL otherwise: */ static struct task_struct *pick_earliest_pushable_dl_task(struct rq *rq, int cpu) { |
2161573ec sched/deadline: r... |
1691 |
struct rb_node *next_node = rq->dl.pushable_dl_tasks_root.rb_leftmost; |
8b5e770ed sched/deadline: O... |
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 |
struct task_struct *p = NULL; if (!has_pushable_dl_tasks(rq)) return NULL; next_node: if (next_node) { p = rb_entry(next_node, struct task_struct, pushable_dl_tasks); if (pick_dl_task(rq, p, cpu)) return p; next_node = rb_next(next_node); goto next_node; } return NULL; } |
1baca4ce1 sched/deadline: A... |
1710 1711 1712 1713 1714 |
static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask_dl); static int find_later_rq(struct task_struct *task) { struct sched_domain *sd; |
4ba296842 percpu: Resolve a... |
1715 |
struct cpumask *later_mask = this_cpu_cpumask_var_ptr(local_cpu_mask_dl); |
1baca4ce1 sched/deadline: A... |
1716 |
int this_cpu = smp_processor_id(); |
b18c3ca11 sched/deadline: M... |
1717 |
int cpu = task_cpu(task); |
1baca4ce1 sched/deadline: A... |
1718 1719 1720 1721 |
/* Make sure the mask is initialized first */ if (unlikely(!later_mask)) return -1; |
4b53a3412 sched/core: Remov... |
1722 |
if (task->nr_cpus_allowed == 1) |
1baca4ce1 sched/deadline: A... |
1723 |
return -1; |
91ec6778e sched/deadline: F... |
1724 1725 1726 1727 |
/* * We have to consider system topology and task affinity * first, then we can look for a suitable cpu. */ |
3261ed0b2 sched/deadline: C... |
1728 |
if (!cpudl_find(&task_rq(task)->rd->cpudl, task, later_mask)) |
1baca4ce1 sched/deadline: A... |
1729 1730 1731 |
return -1; /* |
b18c3ca11 sched/deadline: M... |
1732 1733 1734 1735 |
* If we are here, some targets have been found, including * the most suitable which is, among the runqueues where the * current tasks have later deadlines than the task's one, the * rq with the latest possible one. |
1baca4ce1 sched/deadline: A... |
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 |
* * Now we check how well this matches with task's * affinity and system topology. * * The last cpu where the task run is our first * guess, since it is most likely cache-hot there. */ if (cpumask_test_cpu(cpu, later_mask)) return cpu; /* * Check if this_cpu is to be skipped (i.e., it is * not in the mask) or not. */ if (!cpumask_test_cpu(this_cpu, later_mask)) this_cpu = -1; rcu_read_lock(); for_each_domain(cpu, sd) { if (sd->flags & SD_WAKE_AFFINE) { |
b18c3ca11 sched/deadline: M... |
1755 |
int best_cpu; |
1baca4ce1 sched/deadline: A... |
1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 |
/* * If possible, preempting this_cpu is * cheaper than migrating. */ if (this_cpu != -1 && cpumask_test_cpu(this_cpu, sched_domain_span(sd))) { rcu_read_unlock(); return this_cpu; } |
b18c3ca11 sched/deadline: M... |
1766 1767 |
best_cpu = cpumask_first_and(later_mask, sched_domain_span(sd)); |
1baca4ce1 sched/deadline: A... |
1768 |
/* |
b18c3ca11 sched/deadline: M... |
1769 1770 1771 1772 |
* Last chance: if a cpu being in both later_mask * and current sd span is valid, that becomes our * choice. Of course, the latest possible cpu is * already under consideration through later_mask. |
1baca4ce1 sched/deadline: A... |
1773 |
*/ |
b18c3ca11 sched/deadline: M... |
1774 |
if (best_cpu < nr_cpu_ids) { |
1baca4ce1 sched/deadline: A... |
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 |
rcu_read_unlock(); return best_cpu; } } } rcu_read_unlock(); /* * At this point, all our guesses failed, we just return * 'something', and let the caller sort the things out. */ if (this_cpu != -1) return this_cpu; cpu = cpumask_any(later_mask); if (cpu < nr_cpu_ids) return cpu; return -1; } /* Locks the rq it finds */ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq) { struct rq *later_rq = NULL; int tries; int cpu; for (tries = 0; tries < DL_MAX_TRIES; tries++) { cpu = find_later_rq(task); if ((cpu == -1) || (cpu == rq->cpu)) break; later_rq = cpu_rq(cpu); |
5aa505078 sched/deadline: F... |
1810 1811 |
if (later_rq->dl.dl_nr_running && !dl_time_before(task->dl.deadline, |
9d5142624 sched/deadline: R... |
1812 1813 1814 1815 1816 1817 1818 1819 1820 |
later_rq->dl.earliest_dl.curr)) { /* * Target rq has tasks of equal or earlier deadline, * retrying does not release any lock and is unlikely * to yield a different result. */ later_rq = NULL; break; } |
1baca4ce1 sched/deadline: A... |
1821 1822 1823 |
/* Retry if something changed. */ if (double_lock_balance(rq, later_rq)) { if (unlikely(task_rq(task) != rq || |
0c98d344f sched/core: Remov... |
1824 |
!cpumask_test_cpu(later_rq->cpu, &task->cpus_allowed) || |
da0c1e65b sched: Add wrappe... |
1825 |
task_running(rq, task) || |
13b5ab02a sched/rt, sched/d... |
1826 |
!dl_task(task) || |
da0c1e65b sched: Add wrappe... |
1827 |
!task_on_rq_queued(task))) { |
1baca4ce1 sched/deadline: A... |
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 |
double_unlock_balance(rq, later_rq); later_rq = NULL; break; } } /* * If the rq we found has no -deadline task, or * its earliest one has a later deadline than our * task, the rq is a good one. */ if (!later_rq->dl.dl_nr_running || dl_time_before(task->dl.deadline, later_rq->dl.earliest_dl.curr)) break; /* Otherwise we try again. */ double_unlock_balance(rq, later_rq); later_rq = NULL; } return later_rq; } static struct task_struct *pick_next_pushable_dl_task(struct rq *rq) { struct task_struct *p; if (!has_pushable_dl_tasks(rq)) return NULL; |
2161573ec sched/deadline: r... |
1858 |
p = rb_entry(rq->dl.pushable_dl_tasks_root.rb_leftmost, |
1baca4ce1 sched/deadline: A... |
1859 1860 1861 1862 |
struct task_struct, pushable_dl_tasks); BUG_ON(rq->cpu != task_cpu(p)); BUG_ON(task_current(rq, p)); |
4b53a3412 sched/core: Remov... |
1863 |
BUG_ON(p->nr_cpus_allowed <= 1); |
1baca4ce1 sched/deadline: A... |
1864 |
|
da0c1e65b sched: Add wrappe... |
1865 |
BUG_ON(!task_on_rq_queued(p)); |
1baca4ce1 sched/deadline: A... |
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 |
BUG_ON(!dl_task(p)); return p; } /* * See if the non running -deadline tasks on this rq * can be sent to some other CPU where they can preempt * and start executing. */ static int push_dl_task(struct rq *rq) { struct task_struct *next_task; struct rq *later_rq; |
c51b8ab5a sched/deadline: F... |
1880 |
int ret = 0; |
1baca4ce1 sched/deadline: A... |
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 |
if (!rq->dl.overloaded) return 0; next_task = pick_next_pushable_dl_task(rq); if (!next_task) return 0; retry: if (unlikely(next_task == rq->curr)) { WARN_ON(1); return 0; } /* * If next_task preempts rq->curr, and rq->curr * can move away, it makes sense to just reschedule * without going further in pushing next_task. */ if (dl_task(rq->curr) && dl_time_before(next_task->dl.deadline, rq->curr->dl.deadline) && |
4b53a3412 sched/core: Remov... |
1902 |
rq->curr->nr_cpus_allowed > 1) { |
8875125ef sched: Transform ... |
1903 |
resched_curr(rq); |
1baca4ce1 sched/deadline: A... |
1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 |
return 0; } /* We might release rq lock */ get_task_struct(next_task); /* Will lock the rq it'll find */ later_rq = find_lock_later_rq(next_task, rq); if (!later_rq) { struct task_struct *task; /* * We must check all this again, since * find_lock_later_rq releases rq->lock and it is * then possible that next_task has migrated. */ task = pick_next_pushable_dl_task(rq); |
a776b968e sched/deadline: R... |
1921 |
if (task == next_task) { |
1baca4ce1 sched/deadline: A... |
1922 1923 1924 1925 |
/* * The task is still there. We don't try * again, some other cpu will pull it when ready. */ |
1baca4ce1 sched/deadline: A... |
1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 |
goto out; } if (!task) /* No more tasks */ goto out; put_task_struct(next_task); next_task = task; goto retry; } deactivate_task(rq, next_task, 0); |
e36d8677b sched/deadline: T... |
1939 |
sub_running_bw(next_task->dl.dl_bw, &rq->dl); |
8fd27231c sched/deadline: T... |
1940 |
sub_rq_bw(next_task->dl.dl_bw, &rq->dl); |
1baca4ce1 sched/deadline: A... |
1941 |
set_task_cpu(next_task, later_rq->cpu); |
8fd27231c sched/deadline: T... |
1942 |
add_rq_bw(next_task->dl.dl_bw, &later_rq->dl); |
e36d8677b sched/deadline: T... |
1943 |
add_running_bw(next_task->dl.dl_bw, &later_rq->dl); |
1baca4ce1 sched/deadline: A... |
1944 |
activate_task(later_rq, next_task, 0); |
c51b8ab5a sched/deadline: F... |
1945 |
ret = 1; |
1baca4ce1 sched/deadline: A... |
1946 |
|
8875125ef sched: Transform ... |
1947 |
resched_curr(later_rq); |
1baca4ce1 sched/deadline: A... |
1948 1949 1950 1951 1952 |
double_unlock_balance(rq, later_rq); out: put_task_struct(next_task); |
c51b8ab5a sched/deadline: F... |
1953 |
return ret; |
1baca4ce1 sched/deadline: A... |
1954 1955 1956 1957 |
} static void push_dl_tasks(struct rq *rq) { |
4ffa08ed4 sched/deadline: F... |
1958 |
/* push_dl_task() will return true if it moved a -deadline task */ |
1baca4ce1 sched/deadline: A... |
1959 1960 |
while (push_dl_task(rq)) ; |
aab03e05e sched/deadline: A... |
1961 |
} |
0ea60c205 sched,dl: Remove ... |
1962 |
static void pull_dl_task(struct rq *this_rq) |
1baca4ce1 sched/deadline: A... |
1963 |
{ |
0ea60c205 sched,dl: Remove ... |
1964 |
int this_cpu = this_rq->cpu, cpu; |
1baca4ce1 sched/deadline: A... |
1965 |
struct task_struct *p; |
0ea60c205 sched,dl: Remove ... |
1966 |
bool resched = false; |
1baca4ce1 sched/deadline: A... |
1967 1968 1969 1970 |
struct rq *src_rq; u64 dmin = LONG_MAX; if (likely(!dl_overloaded(this_rq))) |
0ea60c205 sched,dl: Remove ... |
1971 |
return; |
1baca4ce1 sched/deadline: A... |
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 |
/* * Match the barrier from dl_set_overloaded; this guarantees that if we * see overloaded we must also see the dlo_mask bit. */ smp_rmb(); for_each_cpu(cpu, this_rq->rd->dlo_mask) { if (this_cpu == cpu) continue; src_rq = cpu_rq(cpu); /* * It looks racy, abd it is! However, as in sched_rt.c, * we are fine with this. */ if (this_rq->dl.dl_nr_running && dl_time_before(this_rq->dl.earliest_dl.curr, src_rq->dl.earliest_dl.next)) continue; /* Might drop this_rq->lock */ double_lock_balance(this_rq, src_rq); /* * If there are no more pullable tasks on the * rq, we're done with it. */ if (src_rq->dl.dl_nr_running <= 1) goto skip; |
8b5e770ed sched/deadline: O... |
2003 |
p = pick_earliest_pushable_dl_task(src_rq, this_cpu); |
1baca4ce1 sched/deadline: A... |
2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 |
/* * We found a task to be pulled if: * - it preempts our current (if there's one), * - it will preempt the last one we pulled (if any). */ if (p && dl_time_before(p->dl.deadline, dmin) && (!this_rq->dl.dl_nr_running || dl_time_before(p->dl.deadline, this_rq->dl.earliest_dl.curr))) { WARN_ON(p == src_rq->curr); |
da0c1e65b sched: Add wrappe... |
2015 |
WARN_ON(!task_on_rq_queued(p)); |
1baca4ce1 sched/deadline: A... |
2016 2017 2018 2019 2020 2021 2022 2023 |
/* * Then we pull iff p has actually an earlier * deadline than the current task of its runqueue. */ if (dl_time_before(p->dl.deadline, src_rq->curr->dl.deadline)) goto skip; |
0ea60c205 sched,dl: Remove ... |
2024 |
resched = true; |
1baca4ce1 sched/deadline: A... |
2025 2026 |
deactivate_task(src_rq, p, 0); |
e36d8677b sched/deadline: T... |
2027 |
sub_running_bw(p->dl.dl_bw, &src_rq->dl); |
8fd27231c sched/deadline: T... |
2028 |
sub_rq_bw(p->dl.dl_bw, &src_rq->dl); |
1baca4ce1 sched/deadline: A... |
2029 |
set_task_cpu(p, this_cpu); |
8fd27231c sched/deadline: T... |
2030 |
add_rq_bw(p->dl.dl_bw, &this_rq->dl); |
e36d8677b sched/deadline: T... |
2031 |
add_running_bw(p->dl.dl_bw, &this_rq->dl); |
1baca4ce1 sched/deadline: A... |
2032 2033 2034 2035 2036 2037 2038 2039 |
activate_task(this_rq, p, 0); dmin = p->dl.deadline; /* Is there any other task even earlier? */ } skip: double_unlock_balance(this_rq, src_rq); } |
0ea60c205 sched,dl: Remove ... |
2040 2041 |
if (resched) resched_curr(this_rq); |
1baca4ce1 sched/deadline: A... |
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 |
} /* * Since the task is not running and a reschedule is not going to happen * anytime soon on its runqueue, we try pushing it away now. */ static void task_woken_dl(struct rq *rq, struct task_struct *p) { if (!task_running(rq, p) && !test_tsk_need_resched(rq->curr) && |
4b53a3412 sched/core: Remov... |
2052 |
p->nr_cpus_allowed > 1 && |
1baca4ce1 sched/deadline: A... |
2053 |
dl_task(rq->curr) && |
4b53a3412 sched/core: Remov... |
2054 |
(rq->curr->nr_cpus_allowed < 2 || |
6b0a563f3 sched/deadline: P... |
2055 |
!dl_entity_preempt(&p->dl, &rq->curr->dl))) { |
1baca4ce1 sched/deadline: A... |
2056 2057 2058 2059 2060 2061 2062 |
push_dl_tasks(rq); } } static void set_cpus_allowed_dl(struct task_struct *p, const struct cpumask *new_mask) { |
7f51412a4 sched/deadline: F... |
2063 |
struct root_domain *src_rd; |
6c37067e2 sched: Change the... |
2064 |
struct rq *rq; |
1baca4ce1 sched/deadline: A... |
2065 2066 |
BUG_ON(!dl_task(p)); |
7f51412a4 sched/deadline: F... |
2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 |
rq = task_rq(p); src_rd = rq->rd; /* * Migrating a SCHED_DEADLINE task between exclusive * cpusets (different root_domains) entails a bandwidth * update. We already made space for us in the destination * domain (see cpuset_can_attach()). */ if (!cpumask_intersects(src_rd->span, new_mask)) { struct dl_bw *src_dl_b; src_dl_b = dl_bw_of(cpu_of(rq)); /* * We now free resources of the root_domain we are migrating * off. In the worst case, sched_setattr() may temporary fail * until we complete the update. */ raw_spin_lock(&src_dl_b->lock); |
daec57983 sched/deadline: R... |
2085 |
__dl_clear(src_dl_b, p->dl.dl_bw, dl_bw_cpus(task_cpu(p))); |
7f51412a4 sched/deadline: F... |
2086 2087 |
raw_spin_unlock(&src_dl_b->lock); } |
6c37067e2 sched: Change the... |
2088 |
set_cpus_allowed_common(p, new_mask); |
1baca4ce1 sched/deadline: A... |
2089 2090 2091 2092 2093 2094 2095 |
} /* Assumes rq->lock is held */ static void rq_online_dl(struct rq *rq) { if (rq->dl.overloaded) dl_set_overload(rq); |
6bfd6d72f sched/deadline: s... |
2096 |
|
16b269436 sched/deadline: M... |
2097 |
cpudl_set_freecpu(&rq->rd->cpudl, rq->cpu); |
6bfd6d72f sched/deadline: s... |
2098 |
if (rq->dl.dl_nr_running > 0) |
d8206bb3f sched/deadline: S... |
2099 |
cpudl_set(&rq->rd->cpudl, rq->cpu, rq->dl.earliest_dl.curr); |
1baca4ce1 sched/deadline: A... |
2100 2101 2102 2103 2104 2105 2106 |
} /* Assumes rq->lock is held */ static void rq_offline_dl(struct rq *rq) { if (rq->dl.overloaded) dl_clear_overload(rq); |
6bfd6d72f sched/deadline: s... |
2107 |
|
d8206bb3f sched/deadline: S... |
2108 |
cpudl_clear(&rq->rd->cpudl, rq->cpu); |
16b269436 sched/deadline: M... |
2109 |
cpudl_clear_freecpu(&rq->rd->cpudl, rq->cpu); |
1baca4ce1 sched/deadline: A... |
2110 |
} |
a6c0e746f sched/deadline: M... |
2111 |
void __init init_sched_dl_class(void) |
1baca4ce1 sched/deadline: A... |
2112 2113 2114 2115 2116 2117 2118 2119 2120 |
{ unsigned int i; for_each_possible_cpu(i) zalloc_cpumask_var_node(&per_cpu(local_cpu_mask_dl, i), GFP_KERNEL, cpu_to_node(i)); } #endif /* CONFIG_SMP */ |
aab03e05e sched/deadline: A... |
2121 2122 |
static void switched_from_dl(struct rq *rq, struct task_struct *p) { |
a649f237d sched,dl: Fix sch... |
2123 |
/* |
209a0cbda sched/deadline: I... |
2124 2125 2126 2127 2128 2129 |
* task_non_contending() can start the "inactive timer" (if the 0-lag * time is in the future). If the task switches back to dl before * the "inactive timer" fires, it can continue to consume its current * runtime using its current deadline. If it stays outside of * SCHED_DEADLINE until the 0-lag time passes, inactive_task_timer() * will reset the task parameters. |
a649f237d sched,dl: Fix sch... |
2130 |
*/ |
209a0cbda sched/deadline: I... |
2131 2132 |
if (task_on_rq_queued(p) && p->dl.dl_runtime) task_non_contending(p); |
8fd27231c sched/deadline: T... |
2133 2134 |
if (!task_on_rq_queued(p)) sub_rq_bw(p->dl.dl_bw, &rq->dl); |
209a0cbda sched/deadline: I... |
2135 2136 2137 2138 2139 2140 2141 |
/* * We cannot use inactive_task_timer() to invoke sub_running_bw() * at the 0-lag time, because the task could have been migrated * while SCHED_OTHER in the meanwhile. */ if (p->dl.dl_non_contending) p->dl.dl_non_contending = 0; |
a5e7be3b2 sched/deadline: C... |
2142 |
|
1baca4ce1 sched/deadline: A... |
2143 2144 2145 2146 2147 |
/* * Since this might be the only -deadline task on the rq, * this is the right place to try to pull some other one * from an overloaded cpu, if any. */ |
cd6609116 sched/deadline: R... |
2148 2149 |
if (!task_on_rq_queued(p) || rq->dl.dl_nr_running) return; |
9916e2149 sched, dl: Conver... |
2150 |
queue_pull_task(rq); |
aab03e05e sched/deadline: A... |
2151 |
} |
1baca4ce1 sched/deadline: A... |
2152 2153 2154 2155 |
/* * When switching to -deadline, we may overload the rq, then * we try to push someone off, if possible. */ |
aab03e05e sched/deadline: A... |
2156 2157 |
static void switched_to_dl(struct rq *rq, struct task_struct *p) { |
209a0cbda sched/deadline: I... |
2158 2159 |
if (hrtimer_try_to_cancel(&p->dl.inactive_timer) == 1) put_task_struct(p); |
98b0a8578 sched/deadline: R... |
2160 2161 |
/* If p is not queued we will update its parameters at next wakeup. */ |
8fd27231c sched/deadline: T... |
2162 2163 |
if (!task_on_rq_queued(p)) { add_rq_bw(p->dl.dl_bw, &rq->dl); |
98b0a8578 sched/deadline: R... |
2164 |
|
8fd27231c sched/deadline: T... |
2165 2166 |
return; } |
72f9f3fdc sched/deadline: R... |
2167 |
|
98b0a8578 sched/deadline: R... |
2168 |
if (rq->curr != p) { |
1baca4ce1 sched/deadline: A... |
2169 |
#ifdef CONFIG_SMP |
4b53a3412 sched/core: Remov... |
2170 |
if (p->nr_cpus_allowed > 1 && rq->dl.overloaded) |
9916e2149 sched, dl: Conver... |
2171 |
queue_push_tasks(rq); |
619bd4a71 sched/rt: Add a m... |
2172 |
#endif |
9916e2149 sched, dl: Conver... |
2173 2174 2175 2176 |
if (dl_task(rq->curr)) check_preempt_curr_dl(rq, p, 0); else resched_curr(rq); |
aab03e05e sched/deadline: A... |
2177 2178 |
} } |
1baca4ce1 sched/deadline: A... |
2179 2180 2181 2182 |
/* * If the scheduling parameters of a -deadline task changed, * a push or pull operation might be needed. */ |
aab03e05e sched/deadline: A... |
2183 2184 2185 |
static void prio_changed_dl(struct rq *rq, struct task_struct *p, int oldprio) { |
da0c1e65b sched: Add wrappe... |
2186 |
if (task_on_rq_queued(p) || rq->curr == p) { |
aab03e05e sched/deadline: A... |
2187 |
#ifdef CONFIG_SMP |
1baca4ce1 sched/deadline: A... |
2188 2189 2190 2191 2192 2193 2194 |
/* * This might be too much, but unfortunately * we don't have the old deadline value, and * we can't argue if the task is increasing * or lowering its prio, so... */ if (!rq->dl.overloaded) |
9916e2149 sched, dl: Conver... |
2195 |
queue_pull_task(rq); |
1baca4ce1 sched/deadline: A... |
2196 2197 2198 2199 2200 2201 |
/* * If we now have a earlier deadline task than p, * then reschedule, provided p is still on this * runqueue. */ |
9916e2149 sched, dl: Conver... |
2202 |
if (dl_time_before(rq->dl.earliest_dl.curr, p->dl.deadline)) |
8875125ef sched: Transform ... |
2203 |
resched_curr(rq); |
1baca4ce1 sched/deadline: A... |
2204 2205 2206 2207 2208 2209 |
#else /* * Again, we don't know if p has a earlier * or later deadline, so let's blindly set a * (maybe not needed) rescheduling point. */ |
8875125ef sched: Transform ... |
2210 |
resched_curr(rq); |
1baca4ce1 sched/deadline: A... |
2211 |
#endif /* CONFIG_SMP */ |
801ccdbf0 sched/deadline: R... |
2212 |
} |
aab03e05e sched/deadline: A... |
2213 |
} |
aab03e05e sched/deadline: A... |
2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 |
const struct sched_class dl_sched_class = { .next = &rt_sched_class, .enqueue_task = enqueue_task_dl, .dequeue_task = dequeue_task_dl, .yield_task = yield_task_dl, .check_preempt_curr = check_preempt_curr_dl, .pick_next_task = pick_next_task_dl, .put_prev_task = put_prev_task_dl, #ifdef CONFIG_SMP .select_task_rq = select_task_rq_dl, |
209a0cbda sched/deadline: I... |
2228 |
.migrate_task_rq = migrate_task_rq_dl, |
1baca4ce1 sched/deadline: A... |
2229 2230 2231 |
.set_cpus_allowed = set_cpus_allowed_dl, .rq_online = rq_online_dl, .rq_offline = rq_offline_dl, |
1baca4ce1 sched/deadline: A... |
2232 |
.task_woken = task_woken_dl, |
aab03e05e sched/deadline: A... |
2233 2234 2235 2236 2237 |
#endif .set_curr_task = set_curr_task_dl, .task_tick = task_tick_dl, .task_fork = task_fork_dl, |
aab03e05e sched/deadline: A... |
2238 2239 2240 2241 |
.prio_changed = prio_changed_dl, .switched_from = switched_from_dl, .switched_to = switched_to_dl, |
6e998916d sched/cputime: Fi... |
2242 2243 |
.update_curr = update_curr_dl, |
aab03e05e sched/deadline: A... |
2244 |
}; |
acb32132e sched/deadline: A... |
2245 |
|
06a76fe08 sched/deadline: M... |
2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 |
int sched_dl_global_validate(void) { u64 runtime = global_rt_runtime(); u64 period = global_rt_period(); u64 new_bw = to_ratio(period, runtime); struct dl_bw *dl_b; int cpu, ret = 0; unsigned long flags; /* * Here we want to check the bandwidth not being set to some * value smaller than the currently allocated bandwidth in * any of the root_domains. * * FIXME: Cycling on all the CPUs is overdoing, but simpler than * cycling on root_domains... Discussion on different/better * solutions is welcome! */ for_each_possible_cpu(cpu) { rcu_read_lock_sched(); dl_b = dl_bw_of(cpu); raw_spin_lock_irqsave(&dl_b->lock, flags); if (new_bw < dl_b->total_bw) ret = -EBUSY; raw_spin_unlock_irqrestore(&dl_b->lock, flags); rcu_read_unlock_sched(); if (ret) break; } return ret; } void init_dl_rq_bw_ratio(struct dl_rq *dl_rq) { if (global_rt_runtime() == RUNTIME_INF) { dl_rq->bw_ratio = 1 << RATIO_SHIFT; dl_rq->extra_bw = 1 << BW_SHIFT; } else { dl_rq->bw_ratio = to_ratio(global_rt_runtime(), global_rt_period()) >> (BW_SHIFT - RATIO_SHIFT); dl_rq->extra_bw = to_ratio(global_rt_period(), global_rt_runtime()); } } void sched_dl_do_global(void) { u64 new_bw = -1; struct dl_bw *dl_b; int cpu; unsigned long flags; def_dl_bandwidth.dl_period = global_rt_period(); def_dl_bandwidth.dl_runtime = global_rt_runtime(); if (global_rt_runtime() != RUNTIME_INF) new_bw = to_ratio(global_rt_period(), global_rt_runtime()); /* * FIXME: As above... */ for_each_possible_cpu(cpu) { rcu_read_lock_sched(); dl_b = dl_bw_of(cpu); raw_spin_lock_irqsave(&dl_b->lock, flags); dl_b->bw = new_bw; raw_spin_unlock_irqrestore(&dl_b->lock, flags); rcu_read_unlock_sched(); init_dl_rq_bw_ratio(&cpu_rq(cpu)->dl); } } /* * We must be sure that accepting a new task (or allowing changing the * parameters of an existing one) is consistent with the bandwidth * constraints. If yes, this function also accordingly updates the currently * allocated bandwidth to reflect the new situation. * * This function is called while holding p's rq->lock. */ int sched_dl_overflow(struct task_struct *p, int policy, const struct sched_attr *attr) { struct dl_bw *dl_b = dl_bw_of(task_cpu(p)); u64 period = attr->sched_period ?: attr->sched_deadline; u64 runtime = attr->sched_runtime; u64 new_bw = dl_policy(policy) ? to_ratio(period, runtime) : 0; int cpus, err = -1; /* !deadline task may carry old deadline bandwidth */ if (new_bw == p->dl.dl_bw && task_has_dl_policy(p)) return 0; /* * Either if a task, enters, leave, or stays -deadline but changes * its parameters, we may need to update accordingly the total * allocated bandwidth of the container. */ raw_spin_lock(&dl_b->lock); cpus = dl_bw_cpus(task_cpu(p)); if (dl_policy(policy) && !task_has_dl_policy(p) && !__dl_overflow(dl_b, cpus, 0, new_bw)) { if (hrtimer_active(&p->dl.inactive_timer)) __dl_clear(dl_b, p->dl.dl_bw, cpus); __dl_add(dl_b, new_bw, cpus); err = 0; } else if (dl_policy(policy) && task_has_dl_policy(p) && !__dl_overflow(dl_b, cpus, p->dl.dl_bw, new_bw)) { /* * XXX this is slightly incorrect: when the task * utilization decreases, we should delay the total * utilization change until the task's 0-lag point. * But this would require to set the task's "inactive * timer" when the task is not inactive. */ __dl_clear(dl_b, p->dl.dl_bw, cpus); __dl_add(dl_b, new_bw, cpus); dl_change_utilization(p, new_bw); err = 0; } else if (!dl_policy(policy) && task_has_dl_policy(p)) { /* * Do not decrease the total deadline utilization here, * switched_from_dl() will take care to do it at the correct * (0-lag) time. */ err = 0; } raw_spin_unlock(&dl_b->lock); return err; } /* * This function initializes the sched_dl_entity of a newly becoming * SCHED_DEADLINE task. * * Only the static values are considered here, the actual runtime and the * absolute deadline will be properly calculated when the task is enqueued * for the first time with its new policy. */ void __setparam_dl(struct task_struct *p, const struct sched_attr *attr) { struct sched_dl_entity *dl_se = &p->dl; dl_se->dl_runtime = attr->sched_runtime; dl_se->dl_deadline = attr->sched_deadline; dl_se->dl_period = attr->sched_period ?: dl_se->dl_deadline; dl_se->flags = attr->sched_flags; dl_se->dl_bw = to_ratio(dl_se->dl_period, dl_se->dl_runtime); dl_se->dl_density = to_ratio(dl_se->dl_deadline, dl_se->dl_runtime); } void __getparam_dl(struct task_struct *p, struct sched_attr *attr) { struct sched_dl_entity *dl_se = &p->dl; attr->sched_priority = p->rt_priority; attr->sched_runtime = dl_se->dl_runtime; attr->sched_deadline = dl_se->dl_deadline; attr->sched_period = dl_se->dl_period; attr->sched_flags = dl_se->flags; } /* * This function validates the new parameters of a -deadline task. * We ask for the deadline not being zero, and greater or equal * than the runtime, as well as the period of being zero or * greater than deadline. Furthermore, we have to be sure that * user parameters are above the internal resolution of 1us (we * check sched_runtime only since it is always the smaller one) and * below 2^63 ns (we have to check both sched_deadline and * sched_period, as the latter can be zero). */ bool __checkparam_dl(const struct sched_attr *attr) { /* deadline != 0 */ if (attr->sched_deadline == 0) return false; /* * Since we truncate DL_SCALE bits, make sure we're at least * that big. */ if (attr->sched_runtime < (1ULL << DL_SCALE)) return false; /* * Since we use the MSB for wrap-around and sign issues, make * sure it's not set (mind that period can be equal to zero). */ if (attr->sched_deadline & (1ULL << 63) || attr->sched_period & (1ULL << 63)) return false; /* runtime <= deadline <= period (if period != 0) */ if ((attr->sched_period != 0 && attr->sched_period < attr->sched_deadline) || attr->sched_deadline < attr->sched_runtime) return false; return true; } /* * This function clears the sched_dl_entity static params. */ void __dl_clear_params(struct task_struct *p) { struct sched_dl_entity *dl_se = &p->dl; dl_se->dl_runtime = 0; dl_se->dl_deadline = 0; dl_se->dl_period = 0; dl_se->flags = 0; dl_se->dl_bw = 0; dl_se->dl_density = 0; dl_se->dl_throttled = 0; dl_se->dl_yielded = 0; dl_se->dl_non_contending = 0; } bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr) { struct sched_dl_entity *dl_se = &p->dl; if (dl_se->dl_runtime != attr->sched_runtime || dl_se->dl_deadline != attr->sched_deadline || dl_se->dl_period != attr->sched_period || dl_se->flags != attr->sched_flags) return true; return false; } #ifdef CONFIG_SMP int dl_task_can_attach(struct task_struct *p, const struct cpumask *cs_cpus_allowed) { unsigned int dest_cpu = cpumask_any_and(cpu_active_mask, cs_cpus_allowed); struct dl_bw *dl_b; bool overflow; int cpus, ret; unsigned long flags; rcu_read_lock_sched(); dl_b = dl_bw_of(dest_cpu); raw_spin_lock_irqsave(&dl_b->lock, flags); cpus = dl_bw_cpus(dest_cpu); overflow = __dl_overflow(dl_b, cpus, 0, p->dl.dl_bw); if (overflow) ret = -EBUSY; else { /* * We reserve space for this task in the destination * root_domain, as we can't fail after this point. * We will free resources in the source root_domain * later on (see set_cpus_allowed_dl()). */ __dl_add(dl_b, p->dl.dl_bw, cpus); ret = 0; } raw_spin_unlock_irqrestore(&dl_b->lock, flags); rcu_read_unlock_sched(); return ret; } int dl_cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial) { int ret = 1, trial_cpus; struct dl_bw *cur_dl_b; unsigned long flags; rcu_read_lock_sched(); cur_dl_b = dl_bw_of(cpumask_any(cur)); trial_cpus = cpumask_weight(trial); raw_spin_lock_irqsave(&cur_dl_b->lock, flags); if (cur_dl_b->bw != -1 && cur_dl_b->bw * trial_cpus < cur_dl_b->total_bw) ret = 0; raw_spin_unlock_irqrestore(&cur_dl_b->lock, flags); rcu_read_unlock_sched(); return ret; } bool dl_cpu_busy(unsigned int cpu) { unsigned long flags; struct dl_bw *dl_b; bool overflow; int cpus; rcu_read_lock_sched(); dl_b = dl_bw_of(cpu); raw_spin_lock_irqsave(&dl_b->lock, flags); cpus = dl_bw_cpus(cpu); overflow = __dl_overflow(dl_b, cpus, 0, 0); raw_spin_unlock_irqrestore(&dl_b->lock, flags); rcu_read_unlock_sched(); return overflow; } #endif |
acb32132e sched/deadline: A... |
2556 |
#ifdef CONFIG_SCHED_DEBUG |
acb32132e sched/deadline: A... |
2557 2558 2559 2560 2561 |
void print_dl_stats(struct seq_file *m, int cpu) { print_dl_rq(m, cpu, &cpu_rq(cpu)->dl); } #endif /* CONFIG_SCHED_DEBUG */ |