Lines Matching +full:pull +full:- +full:ups

1 // SPDX-License-Identifier: GPL-2.0
3 * Real-Time Scheduling Class (mapped to the SCHED_FIFO and SCHED_RR
12 * period over which we measure -rt task CPU usage in us.
70 array = &rt_rq->active; in init_rt_rq()
72 INIT_LIST_HEAD(array->queue + i); in init_rt_rq()
73 __clear_bit(i, array->bitmap); in init_rt_rq()
76 __set_bit(MAX_RT_PRIO, array->bitmap); in init_rt_rq()
79 rt_rq->highest_prio.curr = MAX_RT_PRIO-1; in init_rt_rq()
80 rt_rq->highest_prio.next = MAX_RT_PRIO-1; in init_rt_rq()
81 rt_rq->overloaded = 0; in init_rt_rq()
82 plist_head_init(&rt_rq->pushable_tasks); in init_rt_rq()
85 rt_rq->rt_queued = 0; in init_rt_rq()
88 rt_rq->rt_time = 0; in init_rt_rq()
89 rt_rq->rt_throttled = 0; in init_rt_rq()
90 rt_rq->rt_runtime = 0; in init_rt_rq()
91 raw_spin_lock_init(&rt_rq->rt_runtime_lock); in init_rt_rq()
106 raw_spin_lock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
108 overrun = hrtimer_forward_now(timer, rt_b->rt_period); in sched_rt_period_timer()
112 raw_spin_unlock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
114 raw_spin_lock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
117 rt_b->rt_period_active = 0; in sched_rt_period_timer()
118 raw_spin_unlock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
125 rt_b->rt_period = ns_to_ktime(period); in init_rt_bandwidth()
126 rt_b->rt_runtime = runtime; in init_rt_bandwidth()
128 raw_spin_lock_init(&rt_b->rt_runtime_lock); in init_rt_bandwidth()
130 hrtimer_init(&rt_b->rt_period_timer, CLOCK_MONOTONIC, in init_rt_bandwidth()
132 rt_b->rt_period_timer.function = sched_rt_period_timer; in init_rt_bandwidth()
137 raw_spin_lock(&rt_b->rt_runtime_lock); in do_start_rt_bandwidth()
138 if (!rt_b->rt_period_active) { in do_start_rt_bandwidth()
139 rt_b->rt_period_active = 1; in do_start_rt_bandwidth()
148 hrtimer_forward_now(&rt_b->rt_period_timer, ns_to_ktime(0)); in do_start_rt_bandwidth()
149 hrtimer_start_expires(&rt_b->rt_period_timer, in do_start_rt_bandwidth()
152 raw_spin_unlock(&rt_b->rt_runtime_lock); in do_start_rt_bandwidth()
157 if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF) in start_rt_bandwidth()
165 hrtimer_cancel(&rt_b->rt_period_timer); in destroy_rt_bandwidth()
168 #define rt_entity_is_task(rt_se) (!(rt_se)->my_q)
180 return rt_rq->rq; in rq_of_rt_rq()
185 return rt_se->rt_rq; in rt_rq_of_se()
190 struct rt_rq *rt_rq = rt_se->rt_rq; in rq_of_rt_se()
192 return rt_rq->rq; in rq_of_rt_se()
197 if (tg->rt_se) in unregister_rt_sched_group()
198 destroy_rt_bandwidth(&tg->rt_bandwidth); in unregister_rt_sched_group()
206 if (tg->rt_rq) in free_rt_sched_group()
207 kfree(tg->rt_rq[i]); in free_rt_sched_group()
208 if (tg->rt_se) in free_rt_sched_group()
209 kfree(tg->rt_se[i]); in free_rt_sched_group()
212 kfree(tg->rt_rq); in free_rt_sched_group()
213 kfree(tg->rt_se); in free_rt_sched_group()
222 rt_rq->highest_prio.curr = MAX_RT_PRIO-1; in init_tg_rt_entry()
223 rt_rq->rt_nr_boosted = 0; in init_tg_rt_entry()
224 rt_rq->rq = rq; in init_tg_rt_entry()
225 rt_rq->tg = tg; in init_tg_rt_entry()
227 tg->rt_rq[cpu] = rt_rq; in init_tg_rt_entry()
228 tg->rt_se[cpu] = rt_se; in init_tg_rt_entry()
234 rt_se->rt_rq = &rq->rt; in init_tg_rt_entry()
236 rt_se->rt_rq = parent->my_q; in init_tg_rt_entry()
238 rt_se->my_q = rt_rq; in init_tg_rt_entry()
239 rt_se->parent = parent; in init_tg_rt_entry()
240 INIT_LIST_HEAD(&rt_se->run_list); in init_tg_rt_entry()
249 tg->rt_rq = kcalloc(nr_cpu_ids, sizeof(rt_rq), GFP_KERNEL); in alloc_rt_sched_group()
250 if (!tg->rt_rq) in alloc_rt_sched_group()
252 tg->rt_se = kcalloc(nr_cpu_ids, sizeof(rt_se), GFP_KERNEL); in alloc_rt_sched_group()
253 if (!tg->rt_se) in alloc_rt_sched_group()
256 init_rt_bandwidth(&tg->rt_bandwidth, ktime_to_ns(global_rt_period()), 0); in alloc_rt_sched_group()
270 rt_rq->rt_runtime = tg->rt_bandwidth.rt_runtime; in alloc_rt_sched_group()
271 init_tg_rt_entry(tg, rt_rq, rt_se, i, parent->rt_se[i]); in alloc_rt_sched_group()
307 return &rq->rt; in rt_rq_of_se()
324 /* Try to pull RT tasks here if we lower this rq's prio */ in need_pull_rt_task()
325 return rq->online && rq->rt.highest_prio.curr > prev->prio; in need_pull_rt_task()
330 return atomic_read(&rq->rd->rto_count); in rt_overloaded()
335 if (!rq->online) in rt_set_overload()
338 cpumask_set_cpu(rq->cpu, rq->rd->rto_mask); in rt_set_overload()
349 atomic_inc(&rq->rd->rto_count); in rt_set_overload()
354 if (!rq->online) in rt_clear_overload()
358 atomic_dec(&rq->rd->rto_count); in rt_clear_overload()
359 cpumask_clear_cpu(rq->cpu, rq->rd->rto_mask); in rt_clear_overload()
364 return !plist_head_empty(&rq->rt.pushable_tasks); in has_pushable_tasks()
378 queue_balance_callback(rq, &per_cpu(rt_push_head, rq->cpu), push_rt_tasks); in rt_queue_push_tasks()
383 queue_balance_callback(rq, &per_cpu(rt_pull_head, rq->cpu), pull_rt_task); in rt_queue_pull_task()
388 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); in enqueue_pushable_task()
389 plist_node_init(&p->pushable_tasks, p->prio); in enqueue_pushable_task()
390 plist_add(&p->pushable_tasks, &rq->rt.pushable_tasks); in enqueue_pushable_task()
393 if (p->prio < rq->rt.highest_prio.next) in enqueue_pushable_task()
394 rq->rt.highest_prio.next = p->prio; in enqueue_pushable_task()
396 if (!rq->rt.overloaded) { in enqueue_pushable_task()
398 rq->rt.overloaded = 1; in enqueue_pushable_task()
404 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); in dequeue_pushable_task()
408 p = plist_first_entry(&rq->rt.pushable_tasks, in dequeue_pushable_task()
410 rq->rt.highest_prio.next = p->prio; in dequeue_pushable_task()
412 rq->rt.highest_prio.next = MAX_RT_PRIO-1; in dequeue_pushable_task()
414 if (rq->rt.overloaded) { in dequeue_pushable_task()
416 rq->rt.overloaded = 0; in dequeue_pushable_task()
441 return rt_se->on_rq; in on_rt_rq()
450 * is higher than the capacity of a @cpu. For non-heterogeneous system this
487 if (!rt_rq->tg) in sched_rt_runtime()
490 return rt_rq->rt_runtime; in sched_rt_runtime()
495 return ktime_to_ns(rt_rq->tg->rt_bandwidth.rt_period); in sched_rt_period()
503 tg = list_entry_rcu(tg->list.next, in next_task_group()
505 } while (&tg->list != &task_groups && task_group_is_autogroup(tg)); in next_task_group()
507 if (&tg->list == &task_groups) in next_task_group()
516 (rt_rq = iter->rt_rq[cpu_of(rq)]);)
519 for (; rt_se; rt_se = rt_se->parent)
523 return rt_se->my_q; in group_rt_rq()
531 struct task_struct *curr = rq_of_rt_rq(rt_rq)->curr; in sched_rt_rq_enqueue()
537 rt_se = rt_rq->tg->rt_se[cpu]; in sched_rt_rq_enqueue()
539 if (rt_rq->rt_nr_running) { in sched_rt_rq_enqueue()
545 if (rt_rq->highest_prio.curr < curr->prio) in sched_rt_rq_enqueue()
555 rt_se = rt_rq->tg->rt_se[cpu]; in sched_rt_rq_dequeue()
558 dequeue_top_rt_rq(rt_rq, rt_rq->rt_nr_running); in sched_rt_rq_dequeue()
568 return rt_rq->rt_throttled && !rt_rq->rt_nr_boosted; in rt_rq_throttled()
577 return !!rt_rq->rt_nr_boosted; in rt_se_boosted()
580 return p->prio != p->normal_prio; in rt_se_boosted()
586 return this_rq()->rd->span; in sched_rt_period_mask()
598 return container_of(rt_b, struct task_group, rt_bandwidth)->rt_rq[cpu]; in sched_rt_period_rt_rq()
603 return &rt_rq->tg->rt_bandwidth; in sched_rt_bandwidth()
610 return (hrtimer_active(&rt_b->rt_period_timer) || in sched_rt_bandwidth_account()
611 rt_rq->rt_time < rt_b->rt_runtime); in sched_rt_bandwidth_account()
621 struct root_domain *rd = rq_of_rt_rq(rt_rq)->rd; in do_balance_runtime()
625 weight = cpumask_weight(rd->span); in do_balance_runtime()
627 raw_spin_lock(&rt_b->rt_runtime_lock); in do_balance_runtime()
628 rt_period = ktime_to_ns(rt_b->rt_period); in do_balance_runtime()
629 for_each_cpu(i, rd->span) { in do_balance_runtime()
636 raw_spin_lock(&iter->rt_runtime_lock); in do_balance_runtime()
642 if (iter->rt_runtime == RUNTIME_INF) in do_balance_runtime()
649 diff = iter->rt_runtime - iter->rt_time; in do_balance_runtime()
652 if (rt_rq->rt_runtime + diff > rt_period) in do_balance_runtime()
653 diff = rt_period - rt_rq->rt_runtime; in do_balance_runtime()
654 iter->rt_runtime -= diff; in do_balance_runtime()
655 rt_rq->rt_runtime += diff; in do_balance_runtime()
656 if (rt_rq->rt_runtime == rt_period) { in do_balance_runtime()
657 raw_spin_unlock(&iter->rt_runtime_lock); in do_balance_runtime()
662 raw_spin_unlock(&iter->rt_runtime_lock); in do_balance_runtime()
664 raw_spin_unlock(&rt_b->rt_runtime_lock); in do_balance_runtime()
672 struct root_domain *rd = rq->rd; in __disable_runtime()
684 raw_spin_lock(&rt_b->rt_runtime_lock); in __disable_runtime()
685 raw_spin_lock(&rt_rq->rt_runtime_lock); in __disable_runtime()
691 if (rt_rq->rt_runtime == RUNTIME_INF || in __disable_runtime()
692 rt_rq->rt_runtime == rt_b->rt_runtime) in __disable_runtime()
694 raw_spin_unlock(&rt_rq->rt_runtime_lock); in __disable_runtime()
701 want = rt_b->rt_runtime - rt_rq->rt_runtime; in __disable_runtime()
706 for_each_cpu(i, rd->span) { in __disable_runtime()
713 if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF) in __disable_runtime()
716 raw_spin_lock(&iter->rt_runtime_lock); in __disable_runtime()
718 diff = min_t(s64, iter->rt_runtime, want); in __disable_runtime()
719 iter->rt_runtime -= diff; in __disable_runtime()
720 want -= diff; in __disable_runtime()
722 iter->rt_runtime -= want; in __disable_runtime()
723 want -= want; in __disable_runtime()
725 raw_spin_unlock(&iter->rt_runtime_lock); in __disable_runtime()
731 raw_spin_lock(&rt_rq->rt_runtime_lock); in __disable_runtime()
733 * We cannot be left wanting - that would mean some runtime in __disable_runtime()
740 * runtime - in which case borrowing doesn't make sense. in __disable_runtime()
742 rt_rq->rt_runtime = RUNTIME_INF; in __disable_runtime()
743 rt_rq->rt_throttled = 0; in __disable_runtime()
744 raw_spin_unlock(&rt_rq->rt_runtime_lock); in __disable_runtime()
745 raw_spin_unlock(&rt_b->rt_runtime_lock); in __disable_runtime()
766 raw_spin_lock(&rt_b->rt_runtime_lock); in __enable_runtime()
767 raw_spin_lock(&rt_rq->rt_runtime_lock); in __enable_runtime()
768 rt_rq->rt_runtime = rt_b->rt_runtime; in __enable_runtime()
769 rt_rq->rt_time = 0; in __enable_runtime()
770 rt_rq->rt_throttled = 0; in __enable_runtime()
771 raw_spin_unlock(&rt_rq->rt_runtime_lock); in __enable_runtime()
772 raw_spin_unlock(&rt_b->rt_runtime_lock); in __enable_runtime()
781 if (rt_rq->rt_time > rt_rq->rt_runtime) { in balance_runtime()
782 raw_spin_unlock(&rt_rq->rt_runtime_lock); in balance_runtime()
784 raw_spin_lock(&rt_rq->rt_runtime_lock); in balance_runtime()
818 * When span == cpu_online_mask, taking each rq->lock in do_sched_rt_period_timer()
819 * can be time-consuming. Try to avoid it when possible. in do_sched_rt_period_timer()
821 raw_spin_lock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
822 if (!sched_feat(RT_RUNTIME_SHARE) && rt_rq->rt_runtime != RUNTIME_INF) in do_sched_rt_period_timer()
823 rt_rq->rt_runtime = rt_b->rt_runtime; in do_sched_rt_period_timer()
824 skip = !rt_rq->rt_time && !rt_rq->rt_nr_running; in do_sched_rt_period_timer()
825 raw_spin_unlock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
832 if (rt_rq->rt_time) { in do_sched_rt_period_timer()
835 raw_spin_lock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
836 if (rt_rq->rt_throttled) in do_sched_rt_period_timer()
838 runtime = rt_rq->rt_runtime; in do_sched_rt_period_timer()
839 rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime); in do_sched_rt_period_timer()
840 if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) { in do_sched_rt_period_timer()
841 rt_rq->rt_throttled = 0; in do_sched_rt_period_timer()
851 if (rt_rq->rt_nr_running && rq->curr == rq->idle) in do_sched_rt_period_timer()
854 if (rt_rq->rt_time || rt_rq->rt_nr_running) in do_sched_rt_period_timer()
856 raw_spin_unlock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
857 } else if (rt_rq->rt_nr_running) { in do_sched_rt_period_timer()
862 if (rt_rq->rt_throttled) in do_sched_rt_period_timer()
870 if (!throttled && (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)) in do_sched_rt_period_timer()
880 if (rt_rq->rt_throttled) in sched_rt_runtime_exceeded()
891 if (rt_rq->rt_time > runtime) { in sched_rt_runtime_exceeded()
898 if (likely(rt_b->rt_runtime)) { in sched_rt_runtime_exceeded()
899 rt_rq->rt_throttled = 1; in sched_rt_runtime_exceeded()
907 rt_rq->rt_time = 0; in sched_rt_runtime_exceeded()
924 for ((void) iter, rt_rq = &rq->rt; rt_rq; rt_rq = NULL)
938 if (!rt_rq->rt_nr_running) in sched_rt_rq_enqueue()
947 dequeue_top_rt_rq(rt_rq, rt_rq->rt_nr_running); in sched_rt_rq_dequeue()
963 return &cpu_rq(cpu)->rt; in sched_rt_period_rt_rq()
979 return rt_rq->highest_prio.curr; in rt_se_prio()
982 return rt_task_of(rt_se)->prio; in rt_se_prio()
991 struct task_struct *curr = rq->curr; in update_curr_rt()
994 if (curr->sched_class != &rt_sched_class) in update_curr_rt()
1002 struct sched_rt_entity *rt_se = &curr->rt; in update_curr_rt()
1012 raw_spin_lock(&rt_rq->rt_runtime_lock); in update_curr_rt()
1013 rt_rq->rt_time += delta_exec; in update_curr_rt()
1017 raw_spin_unlock(&rt_rq->rt_runtime_lock); in update_curr_rt()
1030 BUG_ON(&rq->rt != rt_rq); in dequeue_top_rt_rq()
1032 if (!rt_rq->rt_queued) in dequeue_top_rt_rq()
1035 BUG_ON(!rq->nr_running); in dequeue_top_rt_rq()
1038 rt_rq->rt_queued = 0; in dequeue_top_rt_rq()
1047 BUG_ON(&rq->rt != rt_rq); in enqueue_top_rt_rq()
1049 if (rt_rq->rt_queued) in enqueue_top_rt_rq()
1055 if (rt_rq->rt_nr_running) { in enqueue_top_rt_rq()
1056 add_nr_running(rq, rt_rq->rt_nr_running); in enqueue_top_rt_rq()
1057 rt_rq->rt_queued = 1; in enqueue_top_rt_rq()
1075 if (&rq->rt != rt_rq) in inc_rt_prio_smp()
1078 if (rq->online && prio < prev_prio) in inc_rt_prio_smp()
1079 cpupri_set(&rq->rd->cpupri, rq->cpu, prio); in inc_rt_prio_smp()
1091 if (&rq->rt != rt_rq) in dec_rt_prio_smp()
1094 if (rq->online && rt_rq->highest_prio.curr != prev_prio) in dec_rt_prio_smp()
1095 cpupri_set(&rq->rd->cpupri, rq->cpu, rt_rq->highest_prio.curr); in dec_rt_prio_smp()
1111 int prev_prio = rt_rq->highest_prio.curr; in inc_rt_prio()
1114 rt_rq->highest_prio.curr = prio; in inc_rt_prio()
1122 int prev_prio = rt_rq->highest_prio.curr; in dec_rt_prio()
1124 if (rt_rq->rt_nr_running) { in dec_rt_prio()
1130 * we may have some re-computation to do in dec_rt_prio()
1133 struct rt_prio_array *array = &rt_rq->active; in dec_rt_prio()
1135 rt_rq->highest_prio.curr = in dec_rt_prio()
1136 sched_find_first_bit(array->bitmap); in dec_rt_prio()
1140 rt_rq->highest_prio.curr = MAX_RT_PRIO-1; in dec_rt_prio()
1159 rt_rq->rt_nr_boosted++; in inc_rt_group()
1161 if (rt_rq->tg) in inc_rt_group()
1162 start_rt_bandwidth(&rt_rq->tg->rt_bandwidth); in inc_rt_group()
1169 rt_rq->rt_nr_boosted--; in dec_rt_group()
1171 WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted); in dec_rt_group()
1192 return group_rq->rt_nr_running; in rt_se_nr_running()
1204 return group_rq->rr_nr_running; in rt_se_rr_nr_running()
1208 return (tsk->policy == SCHED_RR) ? 1 : 0; in rt_se_rr_nr_running()
1217 rt_rq->rt_nr_running += rt_se_nr_running(rt_se); in inc_rt_tasks()
1218 rt_rq->rr_nr_running += rt_se_rr_nr_running(rt_se); in inc_rt_tasks()
1228 WARN_ON(!rt_rq->rt_nr_running); in dec_rt_tasks()
1229 rt_rq->rt_nr_running -= rt_se_nr_running(rt_se); in dec_rt_tasks()
1230 rt_rq->rr_nr_running -= rt_se_rr_nr_running(rt_se); in dec_rt_tasks()
1237 * Change rt_se->run_list location unless SAVE && !MOVE
1251 list_del_init(&rt_se->run_list); in __delist_rt_entity()
1253 if (list_empty(array->queue + rt_se_prio(rt_se))) in __delist_rt_entity()
1254 __clear_bit(rt_se_prio(rt_se), array->bitmap); in __delist_rt_entity()
1256 rt_se->on_list = 0; in __delist_rt_entity()
1268 return &rt_task_of(rt_se)->stats; in __schedstats_from_rt_se()
1354 state = READ_ONCE(p->__state); in update_stats_dequeue_rt()
1356 __schedstat_set(p->stats.sleep_start, in update_stats_dequeue_rt()
1360 __schedstat_set(p->stats.block_start, in update_stats_dequeue_rt()
1368 struct rt_prio_array *array = &rt_rq->active; in __enqueue_rt_entity()
1370 struct list_head *queue = array->queue + rt_se_prio(rt_se); in __enqueue_rt_entity()
1378 if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running)) { in __enqueue_rt_entity()
1379 if (rt_se->on_list) in __enqueue_rt_entity()
1385 WARN_ON_ONCE(rt_se->on_list); in __enqueue_rt_entity()
1387 list_add(&rt_se->run_list, queue); in __enqueue_rt_entity()
1389 list_add_tail(&rt_se->run_list, queue); in __enqueue_rt_entity()
1391 __set_bit(rt_se_prio(rt_se), array->bitmap); in __enqueue_rt_entity()
1392 rt_se->on_list = 1; in __enqueue_rt_entity()
1394 rt_se->on_rq = 1; in __enqueue_rt_entity()
1402 struct rt_prio_array *array = &rt_rq->active; in __dequeue_rt_entity()
1405 WARN_ON_ONCE(!rt_se->on_list); in __dequeue_rt_entity()
1408 rt_se->on_rq = 0; in __dequeue_rt_entity()
1415 * entries, we must remove entries top - down.
1423 rt_se->back = back; in dequeue_rt_stack()
1427 rt_nr_running = rt_rq_of_se(back)->rt_nr_running; in dequeue_rt_stack()
1429 for (rt_se = back; rt_se; rt_se = rt_se->back) { in dequeue_rt_stack()
1446 enqueue_top_rt_rq(&rq->rt); in enqueue_rt_entity()
1460 if (rt_rq && rt_rq->rt_nr_running) in dequeue_rt_entity()
1463 enqueue_top_rt_rq(&rq->rt); in dequeue_rt_entity()
1472 struct sched_rt_entity *rt_se = &p->rt; in enqueue_task_rt()
1475 rt_se->timeout = 0; in enqueue_task_rt()
1482 if (!task_current(rq, p) && p->nr_cpus_allowed > 1) in enqueue_task_rt()
1488 struct sched_rt_entity *rt_se = &p->rt; in dequeue_task_rt()
1506 struct rt_prio_array *array = &rt_rq->active; in requeue_rt_entity()
1507 struct list_head *queue = array->queue + rt_se_prio(rt_se); in requeue_rt_entity()
1510 list_move(&rt_se->run_list, queue); in requeue_rt_entity()
1512 list_move_tail(&rt_se->run_list, queue); in requeue_rt_entity()
1518 struct sched_rt_entity *rt_se = &p->rt; in requeue_task_rt()
1529 requeue_task_rt(rq, rq->curr, 0); in yield_task_rt()
1542 /* For anything but wake ups, just return the task_cpu */ in select_task_rq_rt()
1549 curr = READ_ONCE(rq->curr); /* unlocked access */ in select_task_rq_rt()
1568 * post-schedule router will push the preempted task away in select_task_rq_rt()
1570 * This test is optimistic, if we get it wrong the load-balancer in select_task_rq_rt()
1574 * requirement of the task - which is only important on heterogeneous in select_task_rq_rt()
1579 (curr->nr_cpus_allowed < 2 || curr->prio <= p->prio); in select_task_rq_rt()
1588 if (!test && target != -1 && !rt_task_fits_capacity(p, target)) in select_task_rq_rt()
1595 if (target != -1 && in select_task_rq_rt()
1596 p->prio < cpu_rq(target)->rt.highest_prio.curr) in select_task_rq_rt()
1613 if (rq->curr->nr_cpus_allowed == 1 || in check_preempt_equal_prio()
1614 !cpupri_find(&rq->rd->cpupri, rq->curr, NULL)) in check_preempt_equal_prio()
1621 if (p->nr_cpus_allowed != 1 && in check_preempt_equal_prio()
1622 cpupri_find(&rq->rd->cpupri, p, NULL)) in check_preempt_equal_prio()
1636 if (!on_rt_rq(&p->rt) && need_pull_rt_task(rq, p)) { in balance_rt()
1639 * picked for load-balance and preemption/IRQs are still in balance_rt()
1657 if (p->prio < rq->curr->prio) { in wakeup_preempt_rt()
1666 * - the newly woken task is of equal priority to the current task in wakeup_preempt_rt()
1667 * - the newly woken task is non-migratable while current is migratable in wakeup_preempt_rt()
1668 * - current will be preempted on the next reschedule in wakeup_preempt_rt()
1672 * to move current somewhere else, making room for our non-migratable in wakeup_preempt_rt()
1675 if (p->prio == rq->curr->prio && !test_tsk_need_resched(rq->curr)) in wakeup_preempt_rt()
1682 struct sched_rt_entity *rt_se = &p->rt; in set_next_task_rt()
1683 struct rt_rq *rt_rq = &rq->rt; in set_next_task_rt()
1685 p->se.exec_start = rq_clock_task(rq); in set_next_task_rt()
1686 if (on_rt_rq(&p->rt)) in set_next_task_rt()
1700 if (rq->curr->sched_class != &rt_sched_class) in set_next_task_rt()
1708 struct rt_prio_array *array = &rt_rq->active; in pick_next_rt_entity()
1713 idx = sched_find_first_bit(array->bitmap); in pick_next_rt_entity()
1716 queue = array->queue + idx; in pick_next_rt_entity()
1719 next = list_entry(queue->next, struct sched_rt_entity, run_list); in pick_next_rt_entity()
1727 struct rt_rq *rt_rq = &rq->rt; in _pick_next_task_rt()
1753 struct sched_rt_entity *rt_se = &p->rt; in put_prev_task_rt()
1754 struct rt_rq *rt_rq = &rq->rt; in put_prev_task_rt()
1756 if (on_rt_rq(&p->rt)) in put_prev_task_rt()
1767 if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1) in put_prev_task_rt()
1779 cpumask_test_cpu(cpu, &p->cpus_mask)) in pick_rt_task()
1791 struct plist_head *head = &rq->rt.pushable_tasks; in pick_highest_pushable_task()
1817 return -1; in find_lowest_rq()
1819 if (task->nr_cpus_allowed == 1) in find_lowest_rq()
1820 return -1; /* No other targets possible */ in find_lowest_rq()
1828 ret = cpupri_find_fitness(&task_rq(task)->rd->cpupri, in find_lowest_rq()
1833 ret = cpupri_find(&task_rq(task)->rd->cpupri, in find_lowest_rq()
1838 return -1; /* No targets found */ in find_lowest_rq()
1846 * it is most likely cache-hot in that location. in find_lowest_rq()
1856 this_cpu = -1; /* Skip this_cpu opt if not among lowest */ in find_lowest_rq()
1860 if (sd->flags & SD_WAKE_AFFINE) { in find_lowest_rq()
1867 if (this_cpu != -1 && in find_lowest_rq()
1888 if (this_cpu != -1) in find_lowest_rq()
1895 return -1; in find_lowest_rq()
1908 if ((cpu == -1) || (cpu == rq->cpu)) in find_lock_lowest_rq()
1913 if (lowest_rq->rt.highest_prio.curr <= task->prio) { in find_lock_lowest_rq()
1935 !cpumask_test_cpu(lowest_rq->cpu, &task->cpus_mask) || in find_lock_lowest_rq()
1948 if (lowest_rq->rt.highest_prio.curr > task->prio) in find_lock_lowest_rq()
1966 p = plist_first_entry(&rq->rt.pushable_tasks, in pick_next_pushable_task()
1969 BUG_ON(rq->cpu != task_cpu(p)); in pick_next_pushable_task()
1971 BUG_ON(p->nr_cpus_allowed <= 1); in pick_next_pushable_task()
1984 static int push_rt_task(struct rq *rq, bool pull) in push_rt_task() argument
1990 if (!rq->rt.overloaded) in push_rt_task()
2003 if (unlikely(next_task->prio < rq->curr->prio)) { in push_rt_task()
2012 if (!pull || rq->push_busy) in push_rt_task()
2024 if (rq->curr->sched_class != &rt_sched_class) in push_rt_task()
2027 cpu = find_lowest_rq(rq->curr); in push_rt_task()
2028 if (cpu == -1 || cpu == rq->cpu) in push_rt_task()
2041 stop_one_cpu_nowait(rq->cpu, push_cpu_stop, in push_rt_task()
2042 push_task, &rq->push_work); in push_rt_task()
2050 if (WARN_ON(next_task == rq->curr)) in push_rt_task()
2061 * find_lock_lowest_rq releases rq->lock in push_rt_task()
2065 * run-queue and is also still the next task eligible for in push_rt_task()
2072 * eligible task, but we failed to find a run-queue in push_rt_task()
2074 * other CPUs will pull from us when ready. in push_rt_task()
2092 set_task_cpu(next_task, lowest_rq->cpu); in push_rt_task()
2119 * up that may be able to run one of its non-running queued RT tasks.
2160 * When starting the IPI RT pushing, the rto_cpu is set to -1, in rto_next_cpu()
2174 /* When rto_cpu is -1 this acts like cpumask_first() */ in rto_next_cpu()
2175 cpu = cpumask_next(rd->rto_cpu, rd->rto_mask); in rto_next_cpu()
2177 rd->rto_cpu = cpu; in rto_next_cpu()
2182 rd->rto_cpu = -1; in rto_next_cpu()
2190 next = atomic_read_acquire(&rd->rto_loop_next); in rto_next_cpu()
2192 if (rd->rto_loop == next) in rto_next_cpu()
2195 rd->rto_loop = next; in rto_next_cpu()
2198 return -1; in rto_next_cpu()
2213 int cpu = -1; in tell_cpu_to_push()
2216 atomic_inc(&rq->rd->rto_loop_next); in tell_cpu_to_push()
2219 if (!rto_start_trylock(&rq->rd->rto_loop_start)) in tell_cpu_to_push()
2222 raw_spin_lock(&rq->rd->rto_lock); in tell_cpu_to_push()
2230 if (rq->rd->rto_cpu < 0) in tell_cpu_to_push()
2231 cpu = rto_next_cpu(rq->rd); in tell_cpu_to_push()
2233 raw_spin_unlock(&rq->rd->rto_lock); in tell_cpu_to_push()
2235 rto_start_unlock(&rq->rd->rto_loop_start); in tell_cpu_to_push()
2239 sched_get_rd(rq->rd); in tell_cpu_to_push()
2240 irq_work_queue_on(&rq->rd->rto_push_work, cpu); in tell_cpu_to_push()
2265 raw_spin_lock(&rd->rto_lock); in rto_push_irq_work_func()
2270 raw_spin_unlock(&rd->rto_lock); in rto_push_irq_work_func()
2278 irq_work_queue_on(&rd->rto_push_work, cpu); in rto_push_irq_work_func()
2284 int this_cpu = this_rq->cpu, cpu; in pull_rt_task()
2301 cpumask_test_cpu(this_rq->cpu, this_rq->rd->rto_mask)) in pull_rt_task()
2311 for_each_cpu(cpu, this_rq->rd->rto_mask) { in pull_rt_task()
2318 * Don't bother taking the src_rq->lock if the next highest in pull_rt_task()
2319 * task is known to be lower-priority than our current task. in pull_rt_task()
2324 if (src_rq->rt.highest_prio.next >= in pull_rt_task()
2325 this_rq->rt.highest_prio.curr) in pull_rt_task()
2337 * We can pull only a task, which is pushable in pull_rt_task()
2344 * the to-be-scheduled task? in pull_rt_task()
2346 if (p && (p->prio < this_rq->rt.highest_prio.curr)) { in pull_rt_task()
2347 WARN_ON(p == src_rq->curr); in pull_rt_task()
2354 * had a chance to schedule. We only pull in pull_rt_task()
2358 if (p->prio < src_rq->curr->prio) in pull_rt_task()
2382 stop_one_cpu_nowait(src_rq->cpu, push_cpu_stop, in pull_rt_task()
2383 push_task, &src_rq->push_work); in pull_rt_task()
2400 !test_tsk_need_resched(rq->curr) && in task_woken_rt()
2401 p->nr_cpus_allowed > 1 && in task_woken_rt()
2402 (dl_task(rq->curr) || rt_task(rq->curr)) && in task_woken_rt()
2403 (rq->curr->nr_cpus_allowed < 2 || in task_woken_rt()
2404 rq->curr->prio <= p->prio); in task_woken_rt()
2410 /* Assumes rq->lock is held */
2413 if (rq->rt.overloaded) in rq_online_rt()
2418 cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr); in rq_online_rt()
2421 /* Assumes rq->lock is held */
2424 if (rq->rt.overloaded) in rq_offline_rt()
2429 cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID); in rq_offline_rt()
2434 * that we might want to pull RT tasks from other runqueues.
2445 if (!task_on_rq_queued(p) || rq->rt.rt_nr_running) in switched_from_rt()
2485 if (p->nr_cpus_allowed > 1 && rq->rt.overloaded) in switched_to_rt()
2488 if (p->prio < rq->curr->prio && cpu_online(cpu_of(rq))) in switched_to_rt()
2495 * us to initiate a push or pull.
2507 * may need to pull tasks to this runqueue. in prio_changed_rt()
2509 if (oldprio < p->prio) in prio_changed_rt()
2516 if (p->prio > rq->rt.highest_prio.curr) in prio_changed_rt()
2520 if (oldprio < p->prio) in prio_changed_rt()
2529 if (p->prio < rq->curr->prio) in prio_changed_rt()
2546 if (p->rt.watchdog_stamp != jiffies) { in watchdog()
2547 p->rt.timeout++; in watchdog()
2548 p->rt.watchdog_stamp = jiffies; in watchdog()
2552 if (p->rt.timeout > next) { in watchdog()
2553 posix_cputimers_rt_watchdog(&p->posix_cputimers, in watchdog()
2554 p->se.sum_exec_runtime); in watchdog()
2572 struct sched_rt_entity *rt_se = &p->rt; in task_tick_rt()
2580 * RR tasks need a special form of time-slice management. in task_tick_rt()
2583 if (p->policy != SCHED_RR) in task_tick_rt()
2586 if (--p->rt.time_slice) in task_tick_rt()
2589 p->rt.time_slice = sched_rr_timeslice; in task_tick_rt()
2596 if (rt_se->run_list.prev != rt_se->run_list.next) { in task_tick_rt()
2609 if (task->policy == SCHED_RR) in get_rr_interval_rt()
2621 rt_rq = task_group(p)->rt_rq[cpu]; in task_is_throttled_rt()
2623 rt_rq = &cpu_rq(cpu)->rt; in task_is_throttled_rt()
2689 css_task_iter_start(&tg->css, 0, &it); in tg_has_rt_tasks()
2710 period = ktime_to_ns(tg->rt_bandwidth.rt_period); in tg_rt_schedulable()
2711 runtime = tg->rt_bandwidth.rt_runtime; in tg_rt_schedulable()
2713 if (tg == d->tg) { in tg_rt_schedulable()
2714 period = d->rt_period; in tg_rt_schedulable()
2715 runtime = d->rt_runtime; in tg_rt_schedulable()
2722 return -EINVAL; in tg_rt_schedulable()
2728 tg->rt_bandwidth.rt_runtime && tg_has_rt_tasks(tg)) in tg_rt_schedulable()
2729 return -EBUSY; in tg_rt_schedulable()
2737 return -EINVAL; in tg_rt_schedulable()
2742 list_for_each_entry_rcu(child, &tg->children, siblings) { in tg_rt_schedulable()
2743 period = ktime_to_ns(child->rt_bandwidth.rt_period); in tg_rt_schedulable()
2744 runtime = child->rt_bandwidth.rt_runtime; in tg_rt_schedulable()
2746 if (child == d->tg) { in tg_rt_schedulable()
2747 period = d->rt_period; in tg_rt_schedulable()
2748 runtime = d->rt_runtime; in tg_rt_schedulable()
2755 return -EINVAL; in tg_rt_schedulable()
2787 return -EINVAL; in tg_set_rt_bandwidth()
2791 return -EINVAL; in tg_set_rt_bandwidth()
2797 return -EINVAL; in tg_set_rt_bandwidth()
2804 raw_spin_lock_irq(&tg->rt_bandwidth.rt_runtime_lock); in tg_set_rt_bandwidth()
2805 tg->rt_bandwidth.rt_period = ns_to_ktime(rt_period); in tg_set_rt_bandwidth()
2806 tg->rt_bandwidth.rt_runtime = rt_runtime; in tg_set_rt_bandwidth()
2809 struct rt_rq *rt_rq = tg->rt_rq[i]; in tg_set_rt_bandwidth()
2811 raw_spin_lock(&rt_rq->rt_runtime_lock); in tg_set_rt_bandwidth()
2812 rt_rq->rt_runtime = rt_runtime; in tg_set_rt_bandwidth()
2813 raw_spin_unlock(&rt_rq->rt_runtime_lock); in tg_set_rt_bandwidth()
2815 raw_spin_unlock_irq(&tg->rt_bandwidth.rt_runtime_lock); in tg_set_rt_bandwidth()
2826 rt_period = ktime_to_ns(tg->rt_bandwidth.rt_period); in sched_group_set_rt_runtime()
2831 return -EINVAL; in sched_group_set_rt_runtime()
2840 if (tg->rt_bandwidth.rt_runtime == RUNTIME_INF) in sched_group_rt_runtime()
2841 return -1; in sched_group_rt_runtime()
2843 rt_runtime_us = tg->rt_bandwidth.rt_runtime; in sched_group_rt_runtime()
2853 return -EINVAL; in sched_group_set_rt_period()
2856 rt_runtime = tg->rt_bandwidth.rt_runtime; in sched_group_set_rt_period()
2865 rt_period_us = ktime_to_ns(tg->rt_bandwidth.rt_period); in sched_group_rt_period()
2885 /* Don't accept real-time tasks when there is no way for them to run */ in sched_rt_can_attach()
2886 if (rt_task(tsk) && tg->rt_bandwidth.rt_runtime == 0) in sched_rt_can_attach()
2909 return -EINVAL; in sched_rt_global_validate()
2967 * Also, writing zero resets the time-slice to default: in sched_rr_handler()