Lines Matching +full:irq +full:- +full:push +full:- +full:pull
1 // SPDX-License-Identifier: GPL-2.0
3 * Real-Time Scheduling Class (mapped to the SCHED_FIFO and SCHED_RR
15 * period over which we measure -rt task CPU usage in us.
73 array = &rt_rq->active; in init_rt_rq()
75 INIT_LIST_HEAD(array->queue + i); in init_rt_rq()
76 __clear_bit(i, array->bitmap); in init_rt_rq()
79 __set_bit(MAX_RT_PRIO, array->bitmap); in init_rt_rq()
81 rt_rq->highest_prio.curr = MAX_RT_PRIO-1; in init_rt_rq()
82 rt_rq->highest_prio.next = MAX_RT_PRIO-1; in init_rt_rq()
83 rt_rq->overloaded = 0; in init_rt_rq()
84 plist_head_init(&rt_rq->pushable_tasks); in init_rt_rq()
86 rt_rq->rt_queued = 0; in init_rt_rq()
89 rt_rq->rt_time = 0; in init_rt_rq()
90 rt_rq->rt_throttled = 0; in init_rt_rq()
91 rt_rq->rt_runtime = 0; in init_rt_rq()
92 raw_spin_lock_init(&rt_rq->rt_runtime_lock); in init_rt_rq()
93 rt_rq->tg = &root_task_group; in init_rt_rq()
108 raw_spin_lock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
110 overrun = hrtimer_forward_now(timer, rt_b->rt_period); in sched_rt_period_timer()
114 raw_spin_unlock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
116 raw_spin_lock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
119 rt_b->rt_period_active = 0; in sched_rt_period_timer()
120 raw_spin_unlock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
127 rt_b->rt_period = ns_to_ktime(period); in init_rt_bandwidth()
128 rt_b->rt_runtime = runtime; in init_rt_bandwidth()
130 raw_spin_lock_init(&rt_b->rt_runtime_lock); in init_rt_bandwidth()
132 hrtimer_setup(&rt_b->rt_period_timer, sched_rt_period_timer, CLOCK_MONOTONIC, in init_rt_bandwidth()
138 raw_spin_lock(&rt_b->rt_runtime_lock); in do_start_rt_bandwidth()
139 if (!rt_b->rt_period_active) { in do_start_rt_bandwidth()
140 rt_b->rt_period_active = 1; in do_start_rt_bandwidth()
149 hrtimer_forward_now(&rt_b->rt_period_timer, ns_to_ktime(0)); in do_start_rt_bandwidth()
150 hrtimer_start_expires(&rt_b->rt_period_timer, in do_start_rt_bandwidth()
153 raw_spin_unlock(&rt_b->rt_runtime_lock); in do_start_rt_bandwidth()
158 if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF) in start_rt_bandwidth()
166 hrtimer_cancel(&rt_b->rt_period_timer); in destroy_rt_bandwidth()
169 #define rt_entity_is_task(rt_se) (!(rt_se)->my_q)
180 /* Cannot fold with non-CONFIG_RT_GROUP_SCHED version, layout */ in rq_of_rt_rq()
181 WARN_ON(!rt_group_sched_enabled() && rt_rq->tg != &root_task_group); in rq_of_rt_rq()
182 return rt_rq->rq; in rq_of_rt_rq()
187 WARN_ON(!rt_group_sched_enabled() && rt_se->rt_rq->tg != &root_task_group); in rt_rq_of_se()
188 return rt_se->rt_rq; in rt_rq_of_se()
193 struct rt_rq *rt_rq = rt_se->rt_rq; in rq_of_rt_se()
195 WARN_ON(!rt_group_sched_enabled() && rt_rq->tg != &root_task_group); in rq_of_rt_se()
196 return rt_rq->rq; in rq_of_rt_se()
204 if (tg->rt_se) in unregister_rt_sched_group()
205 destroy_rt_bandwidth(&tg->rt_bandwidth); in unregister_rt_sched_group()
216 if (tg->rt_rq) in free_rt_sched_group()
217 kfree(tg->rt_rq[i]); in free_rt_sched_group()
218 if (tg->rt_se) in free_rt_sched_group()
219 kfree(tg->rt_se[i]); in free_rt_sched_group()
222 kfree(tg->rt_rq); in free_rt_sched_group()
223 kfree(tg->rt_se); in free_rt_sched_group()
232 rt_rq->highest_prio.curr = MAX_RT_PRIO-1; in init_tg_rt_entry()
233 rt_rq->rt_nr_boosted = 0; in init_tg_rt_entry()
234 rt_rq->rq = rq; in init_tg_rt_entry()
235 rt_rq->tg = tg; in init_tg_rt_entry()
237 tg->rt_rq[cpu] = rt_rq; in init_tg_rt_entry()
238 tg->rt_se[cpu] = rt_se; in init_tg_rt_entry()
244 rt_se->rt_rq = &rq->rt; in init_tg_rt_entry()
246 rt_se->rt_rq = parent->my_q; in init_tg_rt_entry()
248 rt_se->my_q = rt_rq; in init_tg_rt_entry()
249 rt_se->parent = parent; in init_tg_rt_entry()
250 INIT_LIST_HEAD(&rt_se->run_list); in init_tg_rt_entry()
262 tg->rt_rq = kcalloc(nr_cpu_ids, sizeof(rt_rq), GFP_KERNEL); in alloc_rt_sched_group()
263 if (!tg->rt_rq) in alloc_rt_sched_group()
265 tg->rt_se = kcalloc(nr_cpu_ids, sizeof(rt_se), GFP_KERNEL); in alloc_rt_sched_group()
266 if (!tg->rt_se) in alloc_rt_sched_group()
269 init_rt_bandwidth(&tg->rt_bandwidth, ktime_to_ns(global_rt_period()), 0); in alloc_rt_sched_group()
283 rt_rq->rt_runtime = tg->rt_bandwidth.rt_runtime; in alloc_rt_sched_group()
284 init_tg_rt_entry(tg, rt_rq, rt_se, i, parent->rt_se[i]); in alloc_rt_sched_group()
320 return &rq->rt; in rt_rq_of_se()
335 /* Try to pull RT tasks here if we lower this rq's prio */ in need_pull_rt_task()
336 return rq->online && rq->rt.highest_prio.curr > prev->prio; in need_pull_rt_task()
341 return atomic_read(&rq->rd->rto_count); in rt_overloaded()
346 if (!rq->online) in rt_set_overload()
349 cpumask_set_cpu(rq->cpu, rq->rd->rto_mask); in rt_set_overload()
360 atomic_inc(&rq->rd->rto_count); in rt_set_overload()
365 if (!rq->online) in rt_clear_overload()
369 atomic_dec(&rq->rd->rto_count); in rt_clear_overload()
370 cpumask_clear_cpu(rq->cpu, rq->rd->rto_mask); in rt_clear_overload()
375 return !plist_head_empty(&rq->rt.pushable_tasks); in has_pushable_tasks()
389 queue_balance_callback(rq, &per_cpu(rt_push_head, rq->cpu), push_rt_tasks); in rt_queue_push_tasks()
394 queue_balance_callback(rq, &per_cpu(rt_pull_head, rq->cpu), pull_rt_task); in rt_queue_pull_task()
399 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); in enqueue_pushable_task()
400 plist_node_init(&p->pushable_tasks, p->prio); in enqueue_pushable_task()
401 plist_add(&p->pushable_tasks, &rq->rt.pushable_tasks); in enqueue_pushable_task()
404 if (p->prio < rq->rt.highest_prio.next) in enqueue_pushable_task()
405 rq->rt.highest_prio.next = p->prio; in enqueue_pushable_task()
407 if (!rq->rt.overloaded) { in enqueue_pushable_task()
409 rq->rt.overloaded = 1; in enqueue_pushable_task()
415 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); in dequeue_pushable_task()
419 p = plist_first_entry(&rq->rt.pushable_tasks, in dequeue_pushable_task()
421 rq->rt.highest_prio.next = p->prio; in dequeue_pushable_task()
423 rq->rt.highest_prio.next = MAX_RT_PRIO-1; in dequeue_pushable_task()
425 if (rq->rt.overloaded) { in dequeue_pushable_task()
427 rq->rt.overloaded = 0; in dequeue_pushable_task()
437 return rt_se->on_rq; in on_rt_rq()
446 * is higher than the capacity of a @cpu. For non-heterogeneous system this
483 return rt_rq->rt_runtime; in sched_rt_runtime()
488 return ktime_to_ns(rt_rq->tg->rt_bandwidth.rt_period); in sched_rt_period()
501 tg = list_entry_rcu(tg->list.next, in next_task_group()
503 } while (&tg->list != &task_groups && task_group_is_autogroup(tg)); in next_task_group()
505 if (&tg->list == &task_groups) in next_task_group()
513 iter && (rt_rq = iter->rt_rq[cpu_of(rq)]); \
517 for (; rt_se; rt_se = rt_se->parent)
521 return rt_se->my_q; in group_rt_rq()
529 struct task_struct *donor = rq_of_rt_rq(rt_rq)->donor; in sched_rt_rq_enqueue()
535 rt_se = rt_rq->tg->rt_se[cpu]; in sched_rt_rq_enqueue()
537 if (rt_rq->rt_nr_running) { in sched_rt_rq_enqueue()
543 if (rt_rq->highest_prio.curr < donor->prio) in sched_rt_rq_enqueue()
553 rt_se = rt_rq->tg->rt_se[cpu]; in sched_rt_rq_dequeue()
556 dequeue_top_rt_rq(rt_rq, rt_rq->rt_nr_running); in sched_rt_rq_dequeue()
566 return rt_rq->rt_throttled && !rt_rq->rt_nr_boosted; in rt_rq_throttled()
575 return !!rt_rq->rt_nr_boosted; in rt_se_boosted()
578 return p->prio != p->normal_prio; in rt_se_boosted()
583 return this_rq()->rd->span; in sched_rt_period_mask()
589 return container_of(rt_b, struct task_group, rt_bandwidth)->rt_rq[cpu]; in sched_rt_period_rt_rq()
594 return &rt_rq->tg->rt_bandwidth; in sched_rt_bandwidth()
601 return (hrtimer_active(&rt_b->rt_period_timer) || in sched_rt_bandwidth_account()
602 rt_rq->rt_time < rt_b->rt_runtime); in sched_rt_bandwidth_account()
611 struct root_domain *rd = rq_of_rt_rq(rt_rq)->rd; in do_balance_runtime()
615 weight = cpumask_weight(rd->span); in do_balance_runtime()
617 raw_spin_lock(&rt_b->rt_runtime_lock); in do_balance_runtime()
618 rt_period = ktime_to_ns(rt_b->rt_period); in do_balance_runtime()
619 for_each_cpu(i, rd->span) { in do_balance_runtime()
626 raw_spin_lock(&iter->rt_runtime_lock); in do_balance_runtime()
632 if (iter->rt_runtime == RUNTIME_INF) in do_balance_runtime()
639 diff = iter->rt_runtime - iter->rt_time; in do_balance_runtime()
642 if (rt_rq->rt_runtime + diff > rt_period) in do_balance_runtime()
643 diff = rt_period - rt_rq->rt_runtime; in do_balance_runtime()
644 iter->rt_runtime -= diff; in do_balance_runtime()
645 rt_rq->rt_runtime += diff; in do_balance_runtime()
646 if (rt_rq->rt_runtime == rt_period) { in do_balance_runtime()
647 raw_spin_unlock(&iter->rt_runtime_lock); in do_balance_runtime()
652 raw_spin_unlock(&iter->rt_runtime_lock); in do_balance_runtime()
654 raw_spin_unlock(&rt_b->rt_runtime_lock); in do_balance_runtime()
662 struct root_domain *rd = rq->rd; in __disable_runtime()
674 raw_spin_lock(&rt_b->rt_runtime_lock); in __disable_runtime()
675 raw_spin_lock(&rt_rq->rt_runtime_lock); in __disable_runtime()
681 if (rt_rq->rt_runtime == RUNTIME_INF || in __disable_runtime()
682 rt_rq->rt_runtime == rt_b->rt_runtime) in __disable_runtime()
684 raw_spin_unlock(&rt_rq->rt_runtime_lock); in __disable_runtime()
691 want = rt_b->rt_runtime - rt_rq->rt_runtime; in __disable_runtime()
696 for_each_cpu(i, rd->span) { in __disable_runtime()
703 if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF) in __disable_runtime()
706 raw_spin_lock(&iter->rt_runtime_lock); in __disable_runtime()
708 diff = min_t(s64, iter->rt_runtime, want); in __disable_runtime()
709 iter->rt_runtime -= diff; in __disable_runtime()
710 want -= diff; in __disable_runtime()
712 iter->rt_runtime -= want; in __disable_runtime()
713 want -= want; in __disable_runtime()
715 raw_spin_unlock(&iter->rt_runtime_lock); in __disable_runtime()
721 raw_spin_lock(&rt_rq->rt_runtime_lock); in __disable_runtime()
723 * We cannot be left wanting - that would mean some runtime in __disable_runtime()
730 * runtime - in which case borrowing doesn't make sense. in __disable_runtime()
732 rt_rq->rt_runtime = RUNTIME_INF; in __disable_runtime()
733 rt_rq->rt_throttled = 0; in __disable_runtime()
734 raw_spin_unlock(&rt_rq->rt_runtime_lock); in __disable_runtime()
735 raw_spin_unlock(&rt_b->rt_runtime_lock); in __disable_runtime()
756 raw_spin_lock(&rt_b->rt_runtime_lock); in __enable_runtime()
757 raw_spin_lock(&rt_rq->rt_runtime_lock); in __enable_runtime()
758 rt_rq->rt_runtime = rt_b->rt_runtime; in __enable_runtime()
759 rt_rq->rt_time = 0; in __enable_runtime()
760 rt_rq->rt_throttled = 0; in __enable_runtime()
761 raw_spin_unlock(&rt_rq->rt_runtime_lock); in __enable_runtime()
762 raw_spin_unlock(&rt_b->rt_runtime_lock); in __enable_runtime()
771 if (rt_rq->rt_time > rt_rq->rt_runtime) { in balance_runtime()
772 raw_spin_unlock(&rt_rq->rt_runtime_lock); in balance_runtime()
774 raw_spin_lock(&rt_rq->rt_runtime_lock); in balance_runtime()
805 * When span == cpu_online_mask, taking each rq->lock in do_sched_rt_period_timer()
806 * can be time-consuming. Try to avoid it when possible. in do_sched_rt_period_timer()
808 raw_spin_lock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
809 if (!sched_feat(RT_RUNTIME_SHARE) && rt_rq->rt_runtime != RUNTIME_INF) in do_sched_rt_period_timer()
810 rt_rq->rt_runtime = rt_b->rt_runtime; in do_sched_rt_period_timer()
811 skip = !rt_rq->rt_time && !rt_rq->rt_nr_running; in do_sched_rt_period_timer()
812 raw_spin_unlock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
819 if (rt_rq->rt_time) { in do_sched_rt_period_timer()
822 raw_spin_lock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
823 if (rt_rq->rt_throttled) in do_sched_rt_period_timer()
825 runtime = rt_rq->rt_runtime; in do_sched_rt_period_timer()
826 rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime); in do_sched_rt_period_timer()
827 if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) { in do_sched_rt_period_timer()
828 rt_rq->rt_throttled = 0; in do_sched_rt_period_timer()
838 if (rt_rq->rt_nr_running && rq->curr == rq->idle) in do_sched_rt_period_timer()
841 if (rt_rq->rt_time || rt_rq->rt_nr_running) in do_sched_rt_period_timer()
843 raw_spin_unlock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
844 } else if (rt_rq->rt_nr_running) { in do_sched_rt_period_timer()
849 if (rt_rq->rt_throttled) in do_sched_rt_period_timer()
857 if (!throttled && (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)) in do_sched_rt_period_timer()
867 if (rt_rq->rt_throttled) in sched_rt_runtime_exceeded()
878 if (rt_rq->rt_time > runtime) { in sched_rt_runtime_exceeded()
885 if (likely(rt_b->rt_runtime)) { in sched_rt_runtime_exceeded()
886 rt_rq->rt_throttled = 1; in sched_rt_runtime_exceeded()
894 rt_rq->rt_time = 0; in sched_rt_runtime_exceeded()
911 for ((void) iter, rt_rq = &rq->rt; rt_rq; rt_rq = NULL)
925 if (!rt_rq->rt_nr_running) in sched_rt_rq_enqueue()
934 dequeue_top_rt_rq(rt_rq, rt_rq->rt_nr_running); in sched_rt_rq_dequeue()
950 return &cpu_rq(cpu)->rt; in sched_rt_period_rt_rq()
964 return rt_rq->highest_prio.curr; in rt_se_prio()
967 return rt_task_of(rt_se)->prio; in rt_se_prio()
976 struct task_struct *donor = rq->donor; in update_curr_rt()
979 if (donor->sched_class != &rt_sched_class) in update_curr_rt()
987 struct sched_rt_entity *rt_se = &donor->rt; in update_curr_rt()
997 raw_spin_lock(&rt_rq->rt_runtime_lock); in update_curr_rt()
998 rt_rq->rt_time += delta_exec; in update_curr_rt()
1002 raw_spin_unlock(&rt_rq->rt_runtime_lock); in update_curr_rt()
1015 BUG_ON(&rq->rt != rt_rq); in dequeue_top_rt_rq()
1017 if (!rt_rq->rt_queued) in dequeue_top_rt_rq()
1020 BUG_ON(!rq->nr_running); in dequeue_top_rt_rq()
1023 rt_rq->rt_queued = 0; in dequeue_top_rt_rq()
1032 BUG_ON(&rq->rt != rt_rq); in enqueue_top_rt_rq()
1034 if (rt_rq->rt_queued) in enqueue_top_rt_rq()
1040 if (rt_rq->rt_nr_running) { in enqueue_top_rt_rq()
1041 add_nr_running(rq, rt_rq->rt_nr_running); in enqueue_top_rt_rq()
1042 rt_rq->rt_queued = 1; in enqueue_top_rt_rq()
1057 if (IS_ENABLED(CONFIG_RT_GROUP_SCHED) && &rq->rt != rt_rq) in inc_rt_prio_smp()
1060 if (rq->online && prio < prev_prio) in inc_rt_prio_smp()
1061 cpupri_set(&rq->rd->cpupri, rq->cpu, prio); in inc_rt_prio_smp()
1072 if (IS_ENABLED(CONFIG_RT_GROUP_SCHED) && &rq->rt != rt_rq) in dec_rt_prio_smp()
1075 if (rq->online && rt_rq->highest_prio.curr != prev_prio) in dec_rt_prio_smp()
1076 cpupri_set(&rq->rd->cpupri, rq->cpu, rt_rq->highest_prio.curr); in dec_rt_prio_smp()
1082 int prev_prio = rt_rq->highest_prio.curr; in inc_rt_prio()
1085 rt_rq->highest_prio.curr = prio; in inc_rt_prio()
1093 int prev_prio = rt_rq->highest_prio.curr; in dec_rt_prio()
1095 if (rt_rq->rt_nr_running) { in dec_rt_prio()
1101 * we may have some re-computation to do in dec_rt_prio()
1104 struct rt_prio_array *array = &rt_rq->active; in dec_rt_prio()
1106 rt_rq->highest_prio.curr = in dec_rt_prio()
1107 sched_find_first_bit(array->bitmap); in dec_rt_prio()
1111 rt_rq->highest_prio.curr = MAX_RT_PRIO-1; in dec_rt_prio()
1123 rt_rq->rt_nr_boosted++; in inc_rt_group()
1125 start_rt_bandwidth(&rt_rq->tg->rt_bandwidth); in inc_rt_group()
1132 rt_rq->rt_nr_boosted--; in dec_rt_group()
1134 WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted); in dec_rt_group()
1155 return group_rq->rt_nr_running; in rt_se_nr_running()
1167 return group_rq->rr_nr_running; in rt_se_rr_nr_running()
1171 return (tsk->policy == SCHED_RR) ? 1 : 0; in rt_se_rr_nr_running()
1180 rt_rq->rt_nr_running += rt_se_nr_running(rt_se); in inc_rt_tasks()
1181 rt_rq->rr_nr_running += rt_se_rr_nr_running(rt_se); in inc_rt_tasks()
1191 WARN_ON(!rt_rq->rt_nr_running); in dec_rt_tasks()
1192 rt_rq->rt_nr_running -= rt_se_nr_running(rt_se); in dec_rt_tasks()
1193 rt_rq->rr_nr_running -= rt_se_rr_nr_running(rt_se); in dec_rt_tasks()
1200 * Change rt_se->run_list location unless SAVE && !MOVE
1214 list_del_init(&rt_se->run_list); in __delist_rt_entity()
1216 if (list_empty(array->queue + rt_se_prio(rt_se))) in __delist_rt_entity()
1217 __clear_bit(rt_se_prio(rt_se), array->bitmap); in __delist_rt_entity()
1219 rt_se->on_list = 0; in __delist_rt_entity()
1229 return &rt_task_of(rt_se)->stats; in __schedstats_from_rt_se()
1315 state = READ_ONCE(p->__state); in update_stats_dequeue_rt()
1317 __schedstat_set(p->stats.sleep_start, in update_stats_dequeue_rt()
1321 __schedstat_set(p->stats.block_start, in update_stats_dequeue_rt()
1329 struct rt_prio_array *array = &rt_rq->active; in __enqueue_rt_entity()
1331 struct list_head *queue = array->queue + rt_se_prio(rt_se); in __enqueue_rt_entity()
1339 if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running)) { in __enqueue_rt_entity()
1340 if (rt_se->on_list) in __enqueue_rt_entity()
1346 WARN_ON_ONCE(rt_se->on_list); in __enqueue_rt_entity()
1348 list_add(&rt_se->run_list, queue); in __enqueue_rt_entity()
1350 list_add_tail(&rt_se->run_list, queue); in __enqueue_rt_entity()
1352 __set_bit(rt_se_prio(rt_se), array->bitmap); in __enqueue_rt_entity()
1353 rt_se->on_list = 1; in __enqueue_rt_entity()
1355 rt_se->on_rq = 1; in __enqueue_rt_entity()
1363 struct rt_prio_array *array = &rt_rq->active; in __dequeue_rt_entity()
1366 WARN_ON_ONCE(!rt_se->on_list); in __dequeue_rt_entity()
1369 rt_se->on_rq = 0; in __dequeue_rt_entity()
1376 * entries, we must remove entries top - down.
1384 rt_se->back = back; in dequeue_rt_stack()
1388 rt_nr_running = rt_rq_of_se(back)->rt_nr_running; in dequeue_rt_stack()
1390 for (rt_se = back; rt_se; rt_se = rt_se->back) { in dequeue_rt_stack()
1407 enqueue_top_rt_rq(&rq->rt); in enqueue_rt_entity()
1421 if (rt_rq && rt_rq->rt_nr_running) in dequeue_rt_entity()
1424 enqueue_top_rt_rq(&rq->rt); in dequeue_rt_entity()
1433 struct sched_rt_entity *rt_se = &p->rt; in enqueue_task_rt()
1436 rt_se->timeout = 0; in enqueue_task_rt()
1446 if (!task_current(rq, p) && p->nr_cpus_allowed > 1) in enqueue_task_rt()
1452 struct sched_rt_entity *rt_se = &p->rt; in dequeue_task_rt()
1470 struct rt_prio_array *array = &rt_rq->active; in requeue_rt_entity()
1471 struct list_head *queue = array->queue + rt_se_prio(rt_se); in requeue_rt_entity()
1474 list_move(&rt_se->run_list, queue); in requeue_rt_entity()
1476 list_move_tail(&rt_se->run_list, queue); in requeue_rt_entity()
1482 struct sched_rt_entity *rt_se = &p->rt; in requeue_task_rt()
1493 requeue_task_rt(rq, rq->curr, 0); in yield_task_rt()
1512 curr = READ_ONCE(rq->curr); /* unlocked access */ in select_task_rq_rt()
1513 donor = READ_ONCE(rq->donor); in select_task_rq_rt()
1532 * post-schedule router will push the preempted task away in select_task_rq_rt()
1534 * This test is optimistic, if we get it wrong the load-balancer in select_task_rq_rt()
1538 * requirement of the task - which is only important on heterogeneous in select_task_rq_rt()
1543 (curr->nr_cpus_allowed < 2 || donor->prio <= p->prio); in select_task_rq_rt()
1552 if (!test && target != -1 && !rt_task_fits_capacity(p, target)) in select_task_rq_rt()
1559 if (target != -1 && in select_task_rq_rt()
1560 p->prio < cpu_rq(target)->rt.highest_prio.curr) in select_task_rq_rt()
1573 if (rq->curr->nr_cpus_allowed == 1 || in check_preempt_equal_prio()
1574 !cpupri_find(&rq->rd->cpupri, rq->donor, NULL)) in check_preempt_equal_prio()
1581 if (p->nr_cpus_allowed != 1 && in check_preempt_equal_prio()
1582 cpupri_find(&rq->rd->cpupri, p, NULL)) in check_preempt_equal_prio()
1588 * to try and push the current task away: in check_preempt_equal_prio()
1596 if (!on_rt_rq(&p->rt) && need_pull_rt_task(rq, p)) { in balance_rt()
1599 * picked for load-balance and preemption/IRQs are still in balance_rt()
1616 struct task_struct *donor = rq->donor; in wakeup_preempt_rt()
1618 if (p->prio < donor->prio) { in wakeup_preempt_rt()
1626 * - the newly woken task is of equal priority to the current task in wakeup_preempt_rt()
1627 * - the newly woken task is non-migratable while current is migratable in wakeup_preempt_rt()
1628 * - current will be preempted on the next reschedule in wakeup_preempt_rt()
1631 * cpu. If so, we will reschedule to allow the push logic to try in wakeup_preempt_rt()
1632 * to move current somewhere else, making room for our non-migratable in wakeup_preempt_rt()
1635 if (p->prio == donor->prio && !test_tsk_need_resched(rq->curr)) in wakeup_preempt_rt()
1641 struct sched_rt_entity *rt_se = &p->rt; in set_next_task_rt()
1642 struct rt_rq *rt_rq = &rq->rt; in set_next_task_rt()
1644 p->se.exec_start = rq_clock_task(rq); in set_next_task_rt()
1645 if (on_rt_rq(&p->rt)) in set_next_task_rt()
1659 if (rq->donor->sched_class != &rt_sched_class) in set_next_task_rt()
1667 struct rt_prio_array *array = &rt_rq->active; in pick_next_rt_entity()
1672 idx = sched_find_first_bit(array->bitmap); in pick_next_rt_entity()
1675 queue = array->queue + idx; in pick_next_rt_entity()
1678 next = list_entry(queue->next, struct sched_rt_entity, run_list); in pick_next_rt_entity()
1686 struct rt_rq *rt_rq = &rq->rt; in _pick_next_task_rt()
1712 struct sched_rt_entity *rt_se = &p->rt; in put_prev_task_rt()
1713 struct rt_rq *rt_rq = &rq->rt; in put_prev_task_rt()
1715 if (on_rt_rq(&p->rt)) in put_prev_task_rt()
1728 if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1) in put_prev_task_rt()
1741 struct plist_head *head = &rq->rt.pushable_tasks; in pick_highest_pushable_task()
1767 return -1; in find_lowest_rq()
1769 if (task->nr_cpus_allowed == 1) in find_lowest_rq()
1770 return -1; /* No other targets possible */ in find_lowest_rq()
1778 ret = cpupri_find_fitness(&task_rq(task)->rd->cpupri, in find_lowest_rq()
1783 ret = cpupri_find(&task_rq(task)->rd->cpupri, in find_lowest_rq()
1788 return -1; /* No targets found */ in find_lowest_rq()
1796 * it is most likely cache-hot in that location. in find_lowest_rq()
1806 this_cpu = -1; /* Skip this_cpu opt if not among lowest */ in find_lowest_rq()
1810 if (sd->flags & SD_WAKE_AFFINE) { in find_lowest_rq()
1817 if (this_cpu != -1 && in find_lowest_rq()
1838 if (this_cpu != -1) in find_lowest_rq()
1845 return -1; in find_lowest_rq()
1855 p = plist_first_entry(&rq->rt.pushable_tasks, in pick_next_pushable_task()
1858 BUG_ON(rq->cpu != task_cpu(p)); in pick_next_pushable_task()
1861 BUG_ON(p->nr_cpus_allowed <= 1); in pick_next_pushable_task()
1879 if ((cpu == -1) || (cpu == rq->cpu)) in find_lock_lowest_rq()
1884 if (lowest_rq->rt.highest_prio.curr <= task->prio) { in find_lock_lowest_rq()
1907 !cpumask_test_cpu(lowest_rq->cpu, &task->cpus_mask) || in find_lock_lowest_rq()
1917 if (lowest_rq->rt.highest_prio.curr > task->prio) in find_lock_lowest_rq()
1933 static int push_rt_task(struct rq *rq, bool pull) in push_rt_task() argument
1939 if (!rq->rt.overloaded) in push_rt_task()
1952 if (unlikely(next_task->prio < rq->donor->prio)) { in push_rt_task()
1961 if (!pull || rq->push_busy) in push_rt_task()
1973 if (rq->donor->sched_class != &rt_sched_class) in push_rt_task()
1976 cpu = find_lowest_rq(rq->curr); in push_rt_task()
1977 if (cpu == -1 || cpu == rq->cpu) in push_rt_task()
1983 * to this other CPU, instead attempt to push the current in push_rt_task()
1990 stop_one_cpu_nowait(rq->cpu, push_cpu_stop, in push_rt_task()
1991 push_task, &rq->push_work); in push_rt_task()
1999 if (WARN_ON(next_task == rq->curr)) in push_rt_task()
2010 * find_lock_lowest_rq releases rq->lock in push_rt_task()
2014 * run-queue and is also still the next task eligible for in push_rt_task()
2021 * eligible task, but we failed to find a run-queue in push_rt_task()
2022 * to push it to. Do not retry in this case, since in push_rt_task()
2023 * other CPUs will pull from us when ready. in push_rt_task()
2066 * up that may be able to run one of its non-running queued RT tasks.
2072 * CPUs, sending an IPI to the CPUs to have them push off the overloaded
2080 * Each root domain has its own IRQ work function that can iterate over
2083 * their priority, there's a single IRQ work iterator that will try to
2084 * push off RT tasks that are waiting to run.
2087 * IRQ work iterator that will jump to each CPU with overloaded RT tasks.
2095 * rt_loop_next variable. This will make sure that the IRQ work iterator
2107 * When starting the IPI RT pushing, the rto_cpu is set to -1, in rto_next_cpu()
2121 /* When rto_cpu is -1 this acts like cpumask_first() */ in rto_next_cpu()
2122 cpu = cpumask_next(rd->rto_cpu, rd->rto_mask); in rto_next_cpu()
2124 rd->rto_cpu = cpu; in rto_next_cpu()
2129 rd->rto_cpu = -1; in rto_next_cpu()
2137 next = atomic_read_acquire(&rd->rto_loop_next); in rto_next_cpu()
2139 if (rd->rto_loop == next) in rto_next_cpu()
2142 rd->rto_loop = next; in rto_next_cpu()
2145 return -1; in rto_next_cpu()
2160 int cpu = -1; in tell_cpu_to_push()
2163 atomic_inc(&rq->rd->rto_loop_next); in tell_cpu_to_push()
2166 if (!rto_start_trylock(&rq->rd->rto_loop_start)) in tell_cpu_to_push()
2169 raw_spin_lock(&rq->rd->rto_lock); in tell_cpu_to_push()
2177 if (rq->rd->rto_cpu < 0) in tell_cpu_to_push()
2178 cpu = rto_next_cpu(rq->rd); in tell_cpu_to_push()
2180 raw_spin_unlock(&rq->rd->rto_lock); in tell_cpu_to_push()
2182 rto_start_unlock(&rq->rd->rto_loop_start); in tell_cpu_to_push()
2186 sched_get_rd(rq->rd); in tell_cpu_to_push()
2187 irq_work_queue_on(&rq->rd->rto_push_work, cpu); in tell_cpu_to_push()
2203 * When it gets updated, a check is made if a push is possible. in rto_push_irq_work_func()
2212 raw_spin_lock(&rd->rto_lock); in rto_push_irq_work_func()
2217 raw_spin_unlock(&rd->rto_lock); in rto_push_irq_work_func()
2225 irq_work_queue_on(&rd->rto_push_work, cpu); in rto_push_irq_work_func()
2231 int this_cpu = this_rq->cpu, cpu; in pull_rt_task()
2248 cpumask_test_cpu(this_rq->cpu, this_rq->rd->rto_mask)) in pull_rt_task()
2258 for_each_cpu(cpu, this_rq->rd->rto_mask) { in pull_rt_task()
2265 * Don't bother taking the src_rq->lock if the next highest in pull_rt_task()
2266 * task is known to be lower-priority than our current task. in pull_rt_task()
2268 * logically higher, the src_rq will push this task away. in pull_rt_task()
2271 if (src_rq->rt.highest_prio.next >= in pull_rt_task()
2272 this_rq->rt.highest_prio.curr) in pull_rt_task()
2284 * We can pull only a task, which is pushable in pull_rt_task()
2291 * the to-be-scheduled task? in pull_rt_task()
2293 if (p && (p->prio < this_rq->rt.highest_prio.curr)) { in pull_rt_task()
2294 WARN_ON(p == src_rq->curr); in pull_rt_task()
2301 * had a chance to schedule. We only pull in pull_rt_task()
2305 if (p->prio < src_rq->donor->prio) in pull_rt_task()
2327 stop_one_cpu_nowait(src_rq->cpu, push_cpu_stop, in pull_rt_task()
2328 push_task, &src_rq->push_work); in pull_rt_task()
2340 * try to push tasks away now
2345 !test_tsk_need_resched(rq->curr) && in task_woken_rt()
2346 p->nr_cpus_allowed > 1 && in task_woken_rt()
2347 (dl_task(rq->donor) || rt_task(rq->donor)) && in task_woken_rt()
2348 (rq->curr->nr_cpus_allowed < 2 || in task_woken_rt()
2349 rq->donor->prio <= p->prio); in task_woken_rt()
2355 /* Assumes rq->lock is held */
2358 if (rq->rt.overloaded) in rq_online_rt()
2363 cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr); in rq_online_rt()
2366 /* Assumes rq->lock is held */
2369 if (rq->rt.overloaded) in rq_offline_rt()
2374 cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID); in rq_offline_rt()
2379 * that we might want to pull RT tasks from other runqueues.
2390 if (!task_on_rq_queued(p) || rq->rt.rt_nr_running) in switched_from_rt()
2408 * with RT tasks. In this case we try to push them off to
2428 if (p->nr_cpus_allowed > 1 && rq->rt.overloaded) in switched_to_rt()
2430 if (p->prio < rq->donor->prio && cpu_online(cpu_of(rq))) in switched_to_rt()
2437 * us to initiate a push or pull.
2448 * may need to pull tasks to this runqueue. in prio_changed_rt()
2450 if (oldprio < p->prio) in prio_changed_rt()
2457 if (p->prio > rq->rt.highest_prio.curr) in prio_changed_rt()
2465 if (p->prio < rq->donor->prio) in prio_changed_rt()
2482 if (p->rt.watchdog_stamp != jiffies) { in watchdog()
2483 p->rt.timeout++; in watchdog()
2484 p->rt.watchdog_stamp = jiffies; in watchdog()
2488 if (p->rt.timeout > next) { in watchdog()
2489 posix_cputimers_rt_watchdog(&p->posix_cputimers, in watchdog()
2490 p->se.sum_exec_runtime); in watchdog()
2508 struct sched_rt_entity *rt_se = &p->rt; in task_tick_rt()
2516 * RR tasks need a special form of time-slice management. in task_tick_rt()
2519 if (p->policy != SCHED_RR) in task_tick_rt()
2522 if (--p->rt.time_slice) in task_tick_rt()
2525 p->rt.time_slice = sched_rr_timeslice; in task_tick_rt()
2532 if (rt_se->run_list.prev != rt_se->run_list.next) { in task_tick_rt()
2545 if (task->policy == SCHED_RR) in get_rr_interval_rt()
2557 rt_rq = task_group(p)->rt_rq[cpu]; in task_is_throttled_rt()
2558 WARN_ON(!rt_group_sched_enabled() && rt_rq->tg != &root_task_group); in task_is_throttled_rt()
2560 rt_rq = &cpu_rq(cpu)->rt; in task_is_throttled_rt()
2624 css_task_iter_start(&tg->css, 0, &it); in tg_has_rt_tasks()
2645 period = ktime_to_ns(tg->rt_bandwidth.rt_period); in tg_rt_schedulable()
2646 runtime = tg->rt_bandwidth.rt_runtime; in tg_rt_schedulable()
2648 if (tg == d->tg) { in tg_rt_schedulable()
2649 period = d->rt_period; in tg_rt_schedulable()
2650 runtime = d->rt_runtime; in tg_rt_schedulable()
2657 return -EINVAL; in tg_rt_schedulable()
2663 tg->rt_bandwidth.rt_runtime && tg_has_rt_tasks(tg)) in tg_rt_schedulable()
2664 return -EBUSY; in tg_rt_schedulable()
2667 return -EBUSY; in tg_rt_schedulable()
2675 return -EINVAL; in tg_rt_schedulable()
2680 list_for_each_entry_rcu(child, &tg->children, siblings) { in tg_rt_schedulable()
2681 period = ktime_to_ns(child->rt_bandwidth.rt_period); in tg_rt_schedulable()
2682 runtime = child->rt_bandwidth.rt_runtime; in tg_rt_schedulable()
2684 if (child == d->tg) { in tg_rt_schedulable()
2685 period = d->rt_period; in tg_rt_schedulable()
2686 runtime = d->rt_runtime; in tg_rt_schedulable()
2693 return -EINVAL; in tg_rt_schedulable()
2725 return -EINVAL; in tg_set_rt_bandwidth()
2729 return -EINVAL; in tg_set_rt_bandwidth()
2735 return -EINVAL; in tg_set_rt_bandwidth()
2742 raw_spin_lock_irq(&tg->rt_bandwidth.rt_runtime_lock); in tg_set_rt_bandwidth()
2743 tg->rt_bandwidth.rt_period = ns_to_ktime(rt_period); in tg_set_rt_bandwidth()
2744 tg->rt_bandwidth.rt_runtime = rt_runtime; in tg_set_rt_bandwidth()
2747 struct rt_rq *rt_rq = tg->rt_rq[i]; in tg_set_rt_bandwidth()
2749 raw_spin_lock(&rt_rq->rt_runtime_lock); in tg_set_rt_bandwidth()
2750 rt_rq->rt_runtime = rt_runtime; in tg_set_rt_bandwidth()
2751 raw_spin_unlock(&rt_rq->rt_runtime_lock); in tg_set_rt_bandwidth()
2753 raw_spin_unlock_irq(&tg->rt_bandwidth.rt_runtime_lock); in tg_set_rt_bandwidth()
2764 rt_period = ktime_to_ns(tg->rt_bandwidth.rt_period); in sched_group_set_rt_runtime()
2769 return -EINVAL; in sched_group_set_rt_runtime()
2778 if (tg->rt_bandwidth.rt_runtime == RUNTIME_INF) in sched_group_rt_runtime()
2779 return -1; in sched_group_rt_runtime()
2781 rt_runtime_us = tg->rt_bandwidth.rt_runtime; in sched_group_rt_runtime()
2791 return -EINVAL; in sched_group_set_rt_period()
2794 rt_runtime = tg->rt_bandwidth.rt_runtime; in sched_group_set_rt_period()
2803 rt_period_us = ktime_to_ns(tg->rt_bandwidth.rt_period); in sched_group_rt_period()
2823 /* Don't accept real-time tasks when there is no way for them to run */ in sched_rt_can_attach()
2824 if (rt_group_sched_enabled() && rt_task(tsk) && tg->rt_bandwidth.rt_runtime == 0) in sched_rt_can_attach()
2847 return -EINVAL; in sched_rt_global_validate()
2913 * Also, writing zero resets the time-slice to default: in sched_rr_handler()