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
16 * period over which we measure -rt task CPU usage in us.
73 raw_spin_lock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
75 overrun = hrtimer_forward_now(timer, rt_b->rt_period); in sched_rt_period_timer()
79 raw_spin_unlock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
81 raw_spin_lock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
84 rt_b->rt_period_active = 0; in sched_rt_period_timer()
85 raw_spin_unlock(&rt_b->rt_runtime_lock); in sched_rt_period_timer()
92 rt_b->rt_period = ns_to_ktime(period); in init_rt_bandwidth()
93 rt_b->rt_runtime = runtime; in init_rt_bandwidth()
95 raw_spin_lock_init(&rt_b->rt_runtime_lock); in init_rt_bandwidth()
97 hrtimer_init(&rt_b->rt_period_timer, CLOCK_MONOTONIC, in init_rt_bandwidth()
99 rt_b->rt_period_timer.function = sched_rt_period_timer; in init_rt_bandwidth()
104 raw_spin_lock(&rt_b->rt_runtime_lock); in do_start_rt_bandwidth()
105 if (!rt_b->rt_period_active) { in do_start_rt_bandwidth()
106 rt_b->rt_period_active = 1; in do_start_rt_bandwidth()
115 hrtimer_forward_now(&rt_b->rt_period_timer, ns_to_ktime(0)); in do_start_rt_bandwidth()
116 hrtimer_start_expires(&rt_b->rt_period_timer, in do_start_rt_bandwidth()
119 raw_spin_unlock(&rt_b->rt_runtime_lock); in do_start_rt_bandwidth()
124 if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF) in start_rt_bandwidth()
135 array = &rt_rq->active; in init_rt_rq()
137 INIT_LIST_HEAD(array->queue + i); in init_rt_rq()
138 __clear_bit(i, array->bitmap); in init_rt_rq()
141 __set_bit(MAX_RT_PRIO, array->bitmap); in init_rt_rq()
144 rt_rq->highest_prio.curr = MAX_RT_PRIO-1; in init_rt_rq()
145 rt_rq->highest_prio.next = MAX_RT_PRIO-1; in init_rt_rq()
146 rt_rq->rt_nr_migratory = 0; in init_rt_rq()
147 rt_rq->overloaded = 0; in init_rt_rq()
148 plist_head_init(&rt_rq->pushable_tasks); in init_rt_rq()
151 rt_rq->rt_queued = 0; in init_rt_rq()
153 rt_rq->rt_time = 0; in init_rt_rq()
154 rt_rq->rt_throttled = 0; in init_rt_rq()
155 rt_rq->rt_runtime = 0; in init_rt_rq()
156 raw_spin_lock_init(&rt_rq->rt_runtime_lock); in init_rt_rq()
162 hrtimer_cancel(&rt_b->rt_period_timer); in destroy_rt_bandwidth()
165 #define rt_entity_is_task(rt_se) (!(rt_se)->my_q)
177 return rt_rq->rq; in rq_of_rt_rq()
182 return rt_se->rt_rq; in rt_rq_of_se()
187 struct rt_rq *rt_rq = rt_se->rt_rq; in rq_of_rt_se()
189 return rt_rq->rq; in rq_of_rt_se()
194 if (tg->rt_se) in unregister_rt_sched_group()
195 destroy_rt_bandwidth(&tg->rt_bandwidth); in unregister_rt_sched_group()
204 if (tg->rt_rq) in free_rt_sched_group()
205 kfree(tg->rt_rq[i]); in free_rt_sched_group()
206 if (tg->rt_se) in free_rt_sched_group()
207 kfree(tg->rt_se[i]); in free_rt_sched_group()
210 kfree(tg->rt_rq); in free_rt_sched_group()
211 kfree(tg->rt_se); in free_rt_sched_group()
220 rt_rq->highest_prio.curr = MAX_RT_PRIO-1; in init_tg_rt_entry()
221 rt_rq->rt_nr_boosted = 0; in init_tg_rt_entry()
222 rt_rq->rq = rq; in init_tg_rt_entry()
223 rt_rq->tg = tg; in init_tg_rt_entry()
225 tg->rt_rq[cpu] = rt_rq; in init_tg_rt_entry()
226 tg->rt_se[cpu] = rt_se; in init_tg_rt_entry()
232 rt_se->rt_rq = &rq->rt; in init_tg_rt_entry()
234 rt_se->rt_rq = parent->my_q; in init_tg_rt_entry()
236 rt_se->my_q = rt_rq; in init_tg_rt_entry()
237 rt_se->parent = parent; in init_tg_rt_entry()
238 INIT_LIST_HEAD(&rt_se->run_list); in init_tg_rt_entry()
247 tg->rt_rq = kcalloc(nr_cpu_ids, sizeof(rt_rq), GFP_KERNEL); in alloc_rt_sched_group()
248 if (!tg->rt_rq) in alloc_rt_sched_group()
250 tg->rt_se = kcalloc(nr_cpu_ids, sizeof(rt_se), GFP_KERNEL); in alloc_rt_sched_group()
251 if (!tg->rt_se) in alloc_rt_sched_group()
254 init_rt_bandwidth(&tg->rt_bandwidth, in alloc_rt_sched_group()
269 rt_rq->rt_runtime = tg->rt_bandwidth.rt_runtime; in alloc_rt_sched_group()
270 init_tg_rt_entry(tg, rt_rq, rt_se, i, parent->rt_se[i]); in alloc_rt_sched_group()
306 return &rq->rt; in rt_rq_of_se()
323 /* Try to pull RT tasks here if we lower this rq's prio */ in need_pull_rt_task()
324 return rq->online && rq->rt.highest_prio.curr > prev->prio; in need_pull_rt_task()
329 return atomic_read(&rq->rd->rto_count); in rt_overloaded()
334 if (!rq->online) in rt_set_overload()
337 cpumask_set_cpu(rq->cpu, rq->rd->rto_mask); in rt_set_overload()
348 atomic_inc(&rq->rd->rto_count); in rt_set_overload()
353 if (!rq->online) in rt_clear_overload()
357 atomic_dec(&rq->rd->rto_count); in rt_clear_overload()
358 cpumask_clear_cpu(rq->cpu, rq->rd->rto_mask); in rt_clear_overload()
363 if (rt_rq->rt_nr_migratory && rt_rq->rt_nr_total > 1) { in update_rt_migration()
364 if (!rt_rq->overloaded) { in update_rt_migration()
366 rt_rq->overloaded = 1; in update_rt_migration()
368 } else if (rt_rq->overloaded) { in update_rt_migration()
370 rt_rq->overloaded = 0; in update_rt_migration()
382 rt_rq = &rq_of_rt_rq(rt_rq)->rt; in inc_rt_migration()
384 rt_rq->rt_nr_total++; in inc_rt_migration()
385 if (p->nr_cpus_allowed > 1) in inc_rt_migration()
386 rt_rq->rt_nr_migratory++; in inc_rt_migration()
399 rt_rq = &rq_of_rt_rq(rt_rq)->rt; in dec_rt_migration()
401 rt_rq->rt_nr_total--; in dec_rt_migration()
402 if (p->nr_cpus_allowed > 1) in dec_rt_migration()
403 rt_rq->rt_nr_migratory--; in dec_rt_migration()
410 return !plist_head_empty(&rq->rt.pushable_tasks); in has_pushable_tasks()
424 queue_balance_callback(rq, &per_cpu(rt_push_head, rq->cpu), push_rt_tasks); in rt_queue_push_tasks()
429 queue_balance_callback(rq, &per_cpu(rt_pull_head, rq->cpu), pull_rt_task); in rt_queue_pull_task()
434 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); in enqueue_pushable_task()
435 plist_node_init(&p->pushable_tasks, p->prio); in enqueue_pushable_task()
436 plist_add(&p->pushable_tasks, &rq->rt.pushable_tasks); in enqueue_pushable_task()
439 if (p->prio < rq->rt.highest_prio.next) in enqueue_pushable_task()
440 rq->rt.highest_prio.next = p->prio; in enqueue_pushable_task()
445 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); in dequeue_pushable_task()
449 p = plist_first_entry(&rq->rt.pushable_tasks, in dequeue_pushable_task()
451 rq->rt.highest_prio.next = p->prio; in dequeue_pushable_task()
453 rq->rt.highest_prio.next = MAX_RT_PRIO-1; in dequeue_pushable_task()
487 return rt_se->on_rq; in on_rt_rq()
496 * is higher than the capacity of a @cpu. For non-heterogeneous system this
533 if (!rt_rq->tg) in sched_rt_runtime()
536 return rt_rq->rt_runtime; in sched_rt_runtime()
541 return ktime_to_ns(rt_rq->tg->rt_bandwidth.rt_period); in sched_rt_period()
549 tg = list_entry_rcu(tg->list.next, in next_task_group()
551 } while (&tg->list != &task_groups && task_group_is_autogroup(tg)); in next_task_group()
553 if (&tg->list == &task_groups) in next_task_group()
562 (rt_rq = iter->rt_rq[cpu_of(rq)]);)
565 for (; rt_se; rt_se = rt_se->parent)
569 return rt_se->my_q; in group_rt_rq()
577 struct task_struct *curr = rq_of_rt_rq(rt_rq)->curr; in sched_rt_rq_enqueue()
583 rt_se = rt_rq->tg->rt_se[cpu]; in sched_rt_rq_enqueue()
585 if (rt_rq->rt_nr_running) { in sched_rt_rq_enqueue()
591 if (rt_rq->highest_prio.curr < curr->prio) in sched_rt_rq_enqueue()
601 rt_se = rt_rq->tg->rt_se[cpu]; in sched_rt_rq_dequeue()
604 dequeue_top_rt_rq(rt_rq, rt_rq->rt_nr_running); in sched_rt_rq_dequeue()
614 return rt_rq->rt_throttled && !rt_rq->rt_nr_boosted; in rt_rq_throttled()
623 return !!rt_rq->rt_nr_boosted; in rt_se_boosted()
626 return p->prio != p->normal_prio; in rt_se_boosted()
632 return this_rq()->rd->span; in sched_rt_period_mask()
644 return container_of(rt_b, struct task_group, rt_bandwidth)->rt_rq[cpu]; in sched_rt_period_rt_rq()
649 return &rt_rq->tg->rt_bandwidth; in sched_rt_bandwidth()
656 return rt_rq->rt_runtime; in sched_rt_runtime()
667 for ((void) iter, rt_rq = &rq->rt; rt_rq; rt_rq = NULL)
681 if (!rt_rq->rt_nr_running) in sched_rt_rq_enqueue()
690 dequeue_top_rt_rq(rt_rq, rt_rq->rt_nr_running); in sched_rt_rq_dequeue()
695 return rt_rq->rt_throttled; in rt_rq_throttled()
706 return &cpu_rq(cpu)->rt; in sched_rt_period_rt_rq()
720 return (hrtimer_active(&rt_b->rt_period_timer) || in sched_rt_bandwidth_account()
721 rt_rq->rt_time < rt_b->rt_runtime); in sched_rt_bandwidth_account()
731 struct root_domain *rd = rq_of_rt_rq(rt_rq)->rd; in do_balance_runtime()
735 weight = cpumask_weight(rd->span); in do_balance_runtime()
737 raw_spin_lock(&rt_b->rt_runtime_lock); in do_balance_runtime()
738 rt_period = ktime_to_ns(rt_b->rt_period); in do_balance_runtime()
739 for_each_cpu(i, rd->span) { in do_balance_runtime()
746 raw_spin_lock(&iter->rt_runtime_lock); in do_balance_runtime()
752 if (iter->rt_runtime == RUNTIME_INF) in do_balance_runtime()
759 diff = iter->rt_runtime - iter->rt_time; in do_balance_runtime()
762 if (rt_rq->rt_runtime + diff > rt_period) in do_balance_runtime()
763 diff = rt_period - rt_rq->rt_runtime; in do_balance_runtime()
764 iter->rt_runtime -= diff; in do_balance_runtime()
765 rt_rq->rt_runtime += diff; in do_balance_runtime()
766 if (rt_rq->rt_runtime == rt_period) { in do_balance_runtime()
767 raw_spin_unlock(&iter->rt_runtime_lock); in do_balance_runtime()
772 raw_spin_unlock(&iter->rt_runtime_lock); in do_balance_runtime()
774 raw_spin_unlock(&rt_b->rt_runtime_lock); in do_balance_runtime()
782 struct root_domain *rd = rq->rd; in __disable_runtime()
794 raw_spin_lock(&rt_b->rt_runtime_lock); in __disable_runtime()
795 raw_spin_lock(&rt_rq->rt_runtime_lock); in __disable_runtime()
801 if (rt_rq->rt_runtime == RUNTIME_INF || in __disable_runtime()
802 rt_rq->rt_runtime == rt_b->rt_runtime) in __disable_runtime()
804 raw_spin_unlock(&rt_rq->rt_runtime_lock); in __disable_runtime()
811 want = rt_b->rt_runtime - rt_rq->rt_runtime; in __disable_runtime()
816 for_each_cpu(i, rd->span) { in __disable_runtime()
823 if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF) in __disable_runtime()
826 raw_spin_lock(&iter->rt_runtime_lock); in __disable_runtime()
828 diff = min_t(s64, iter->rt_runtime, want); in __disable_runtime()
829 iter->rt_runtime -= diff; in __disable_runtime()
830 want -= diff; in __disable_runtime()
832 iter->rt_runtime -= want; in __disable_runtime()
833 want -= want; in __disable_runtime()
835 raw_spin_unlock(&iter->rt_runtime_lock); in __disable_runtime()
841 raw_spin_lock(&rt_rq->rt_runtime_lock); in __disable_runtime()
843 * We cannot be left wanting - that would mean some runtime in __disable_runtime()
850 * runtime - in which case borrowing doesn't make sense. in __disable_runtime()
852 rt_rq->rt_runtime = RUNTIME_INF; in __disable_runtime()
853 rt_rq->rt_throttled = 0; in __disable_runtime()
854 raw_spin_unlock(&rt_rq->rt_runtime_lock); in __disable_runtime()
855 raw_spin_unlock(&rt_b->rt_runtime_lock); in __disable_runtime()
876 raw_spin_lock(&rt_b->rt_runtime_lock); in __enable_runtime()
877 raw_spin_lock(&rt_rq->rt_runtime_lock); in __enable_runtime()
878 rt_rq->rt_runtime = rt_b->rt_runtime; in __enable_runtime()
879 rt_rq->rt_time = 0; in __enable_runtime()
880 rt_rq->rt_throttled = 0; in __enable_runtime()
881 raw_spin_unlock(&rt_rq->rt_runtime_lock); in __enable_runtime()
882 raw_spin_unlock(&rt_b->rt_runtime_lock); in __enable_runtime()
891 if (rt_rq->rt_time > rt_rq->rt_runtime) { in balance_runtime()
892 raw_spin_unlock(&rt_rq->rt_runtime_lock); in balance_runtime()
894 raw_spin_lock(&rt_rq->rt_runtime_lock); in balance_runtime()
928 * When span == cpu_online_mask, taking each rq->lock in do_sched_rt_period_timer()
929 * can be time-consuming. Try to avoid it when possible. in do_sched_rt_period_timer()
931 raw_spin_lock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
932 if (!sched_feat(RT_RUNTIME_SHARE) && rt_rq->rt_runtime != RUNTIME_INF) in do_sched_rt_period_timer()
933 rt_rq->rt_runtime = rt_b->rt_runtime; in do_sched_rt_period_timer()
934 skip = !rt_rq->rt_time && !rt_rq->rt_nr_running; in do_sched_rt_period_timer()
935 raw_spin_unlock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
942 if (rt_rq->rt_time) { in do_sched_rt_period_timer()
945 raw_spin_lock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
946 if (rt_rq->rt_throttled) in do_sched_rt_period_timer()
948 runtime = rt_rq->rt_runtime; in do_sched_rt_period_timer()
949 rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime); in do_sched_rt_period_timer()
950 if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) { in do_sched_rt_period_timer()
951 rt_rq->rt_throttled = 0; in do_sched_rt_period_timer()
961 if (rt_rq->rt_nr_running && rq->curr == rq->idle) in do_sched_rt_period_timer()
964 if (rt_rq->rt_time || rt_rq->rt_nr_running) in do_sched_rt_period_timer()
966 raw_spin_unlock(&rt_rq->rt_runtime_lock); in do_sched_rt_period_timer()
967 } else if (rt_rq->rt_nr_running) { in do_sched_rt_period_timer()
972 if (rt_rq->rt_throttled) in do_sched_rt_period_timer()
980 if (!throttled && (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)) in do_sched_rt_period_timer()
992 return rt_rq->highest_prio.curr; in rt_se_prio()
995 return rt_task_of(rt_se)->prio; in rt_se_prio()
1002 if (rt_rq->rt_throttled) in sched_rt_runtime_exceeded()
1013 if (rt_rq->rt_time > runtime) { in sched_rt_runtime_exceeded()
1020 if (likely(rt_b->rt_runtime)) { in sched_rt_runtime_exceeded()
1021 rt_rq->rt_throttled = 1; in sched_rt_runtime_exceeded()
1029 rt_rq->rt_time = 0; in sched_rt_runtime_exceeded()
1047 struct task_struct *curr = rq->curr; in update_curr_rt()
1048 struct sched_rt_entity *rt_se = &curr->rt; in update_curr_rt()
1052 if (curr->sched_class != &rt_sched_class) in update_curr_rt()
1056 delta_exec = now - curr->se.exec_start; in update_curr_rt()
1060 schedstat_set(curr->stats.exec_max, in update_curr_rt()
1061 max(curr->stats.exec_max, delta_exec)); in update_curr_rt()
1075 raw_spin_lock(&rt_rq->rt_runtime_lock); in update_curr_rt()
1076 rt_rq->rt_time += delta_exec; in update_curr_rt()
1080 raw_spin_unlock(&rt_rq->rt_runtime_lock); in update_curr_rt()
1092 BUG_ON(&rq->rt != rt_rq); in dequeue_top_rt_rq()
1094 if (!rt_rq->rt_queued) in dequeue_top_rt_rq()
1097 BUG_ON(!rq->nr_running); in dequeue_top_rt_rq()
1100 rt_rq->rt_queued = 0; in dequeue_top_rt_rq()
1109 BUG_ON(&rq->rt != rt_rq); in enqueue_top_rt_rq()
1111 if (rt_rq->rt_queued) in enqueue_top_rt_rq()
1117 if (rt_rq->rt_nr_running) { in enqueue_top_rt_rq()
1118 add_nr_running(rq, rt_rq->rt_nr_running); in enqueue_top_rt_rq()
1119 rt_rq->rt_queued = 1; in enqueue_top_rt_rq()
1137 if (&rq->rt != rt_rq) in inc_rt_prio_smp()
1140 if (rq->online && prio < prev_prio) in inc_rt_prio_smp()
1141 cpupri_set(&rq->rd->cpupri, rq->cpu, prio); in inc_rt_prio_smp()
1153 if (&rq->rt != rt_rq) in dec_rt_prio_smp()
1156 if (rq->online && rt_rq->highest_prio.curr != prev_prio) in dec_rt_prio_smp()
1157 cpupri_set(&rq->rd->cpupri, rq->cpu, rt_rq->highest_prio.curr); in dec_rt_prio_smp()
1173 int prev_prio = rt_rq->highest_prio.curr; in inc_rt_prio()
1176 rt_rq->highest_prio.curr = prio; in inc_rt_prio()
1184 int prev_prio = rt_rq->highest_prio.curr; in dec_rt_prio()
1186 if (rt_rq->rt_nr_running) { in dec_rt_prio()
1195 struct rt_prio_array *array = &rt_rq->active; in dec_rt_prio()
1197 rt_rq->highest_prio.curr = in dec_rt_prio()
1198 sched_find_first_bit(array->bitmap); in dec_rt_prio()
1202 rt_rq->highest_prio.curr = MAX_RT_PRIO-1; in dec_rt_prio()
1221 rt_rq->rt_nr_boosted++; in inc_rt_group()
1223 if (rt_rq->tg) in inc_rt_group()
1224 start_rt_bandwidth(&rt_rq->tg->rt_bandwidth); in inc_rt_group()
1231 rt_rq->rt_nr_boosted--; in dec_rt_group()
1233 WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted); in dec_rt_group()
1255 return group_rq->rt_nr_running; in rt_se_nr_running()
1267 return group_rq->rr_nr_running; in rt_se_rr_nr_running()
1271 return (tsk->policy == SCHED_RR) ? 1 : 0; in rt_se_rr_nr_running()
1280 rt_rq->rt_nr_running += rt_se_nr_running(rt_se); in inc_rt_tasks()
1281 rt_rq->rr_nr_running += rt_se_rr_nr_running(rt_se); in inc_rt_tasks()
1292 WARN_ON(!rt_rq->rt_nr_running); in dec_rt_tasks()
1293 rt_rq->rt_nr_running -= rt_se_nr_running(rt_se); in dec_rt_tasks()
1294 rt_rq->rr_nr_running -= rt_se_rr_nr_running(rt_se); in dec_rt_tasks()
1302 * Change rt_se->run_list location unless SAVE && !MOVE
1316 list_del_init(&rt_se->run_list); in __delist_rt_entity()
1318 if (list_empty(array->queue + rt_se_prio(rt_se))) in __delist_rt_entity()
1319 __clear_bit(rt_se_prio(rt_se), array->bitmap); in __delist_rt_entity()
1321 rt_se->on_list = 0; in __delist_rt_entity()
1333 return &rt_task_of(rt_se)->stats; in __schedstats_from_rt_se()
1419 state = READ_ONCE(p->__state); in update_stats_dequeue_rt()
1421 __schedstat_set(p->stats.sleep_start, in update_stats_dequeue_rt()
1425 __schedstat_set(p->stats.block_start, in update_stats_dequeue_rt()
1433 struct rt_prio_array *array = &rt_rq->active; in __enqueue_rt_entity()
1435 struct list_head *queue = array->queue + rt_se_prio(rt_se); in __enqueue_rt_entity()
1443 if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running)) { in __enqueue_rt_entity()
1444 if (rt_se->on_list) in __enqueue_rt_entity()
1450 WARN_ON_ONCE(rt_se->on_list); in __enqueue_rt_entity()
1452 list_add(&rt_se->run_list, queue); in __enqueue_rt_entity()
1454 list_add_tail(&rt_se->run_list, queue); in __enqueue_rt_entity()
1456 __set_bit(rt_se_prio(rt_se), array->bitmap); in __enqueue_rt_entity()
1457 rt_se->on_list = 1; in __enqueue_rt_entity()
1459 rt_se->on_rq = 1; in __enqueue_rt_entity()
1467 struct rt_prio_array *array = &rt_rq->active; in __dequeue_rt_entity()
1470 WARN_ON_ONCE(!rt_se->on_list); in __dequeue_rt_entity()
1473 rt_se->on_rq = 0; in __dequeue_rt_entity()
1480 * entries, we must remove entries top - down.
1488 rt_se->back = back; in dequeue_rt_stack()
1492 rt_nr_running = rt_rq_of_se(back)->rt_nr_running; in dequeue_rt_stack()
1494 for (rt_se = back; rt_se; rt_se = rt_se->back) { in dequeue_rt_stack()
1511 enqueue_top_rt_rq(&rq->rt); in enqueue_rt_entity()
1525 if (rt_rq && rt_rq->rt_nr_running) in dequeue_rt_entity()
1528 enqueue_top_rt_rq(&rq->rt); in dequeue_rt_entity()
1537 struct sched_rt_entity *rt_se = &p->rt; in enqueue_task_rt()
1540 rt_se->timeout = 0; in enqueue_task_rt()
1547 if (!task_current(rq, p) && p->nr_cpus_allowed > 1) in enqueue_task_rt()
1553 struct sched_rt_entity *rt_se = &p->rt; in dequeue_task_rt()
1569 struct rt_prio_array *array = &rt_rq->active; in requeue_rt_entity()
1570 struct list_head *queue = array->queue + rt_se_prio(rt_se); in requeue_rt_entity()
1573 list_move(&rt_se->run_list, queue); in requeue_rt_entity()
1575 list_move_tail(&rt_se->run_list, queue); in requeue_rt_entity()
1581 struct sched_rt_entity *rt_se = &p->rt; in requeue_task_rt()
1592 requeue_task_rt(rq, rq->curr, 0); in yield_task_rt()
1605 /* For anything but wake ups, just return the task_cpu */ in select_task_rq_rt()
1612 curr = READ_ONCE(rq->curr); /* unlocked access */ in select_task_rq_rt()
1631 * post-schedule router will push the preempted task away in select_task_rq_rt()
1633 * This test is optimistic, if we get it wrong the load-balancer in select_task_rq_rt()
1637 * requirement of the task - which is only important on heterogeneous in select_task_rq_rt()
1642 (curr->nr_cpus_allowed < 2 || curr->prio <= p->prio); in select_task_rq_rt()
1651 if (!test && target != -1 && !rt_task_fits_capacity(p, target)) in select_task_rq_rt()
1658 if (target != -1 && in select_task_rq_rt()
1659 p->prio < cpu_rq(target)->rt.highest_prio.curr) in select_task_rq_rt()
1676 if (rq->curr->nr_cpus_allowed == 1 || in check_preempt_equal_prio()
1677 !cpupri_find(&rq->rd->cpupri, rq->curr, NULL)) in check_preempt_equal_prio()
1684 if (p->nr_cpus_allowed != 1 && in check_preempt_equal_prio()
1685 cpupri_find(&rq->rd->cpupri, p, NULL)) in check_preempt_equal_prio()
1699 if (!on_rt_rq(&p->rt) && need_pull_rt_task(rq, p)) { in balance_rt()
1702 * picked for load-balance and preemption/IRQs are still in balance_rt()
1720 if (p->prio < rq->curr->prio) { in check_preempt_curr_rt()
1729 * - the newly woken task is of equal priority to the current task in check_preempt_curr_rt()
1730 * - the newly woken task is non-migratable while current is migratable in check_preempt_curr_rt()
1731 * - current will be preempted on the next reschedule in check_preempt_curr_rt()
1735 * to move current somewhere else, making room for our non-migratable in check_preempt_curr_rt()
1738 if (p->prio == rq->curr->prio && !test_tsk_need_resched(rq->curr)) in check_preempt_curr_rt()
1745 struct sched_rt_entity *rt_se = &p->rt; in set_next_task_rt()
1746 struct rt_rq *rt_rq = &rq->rt; in set_next_task_rt()
1748 p->se.exec_start = rq_clock_task(rq); in set_next_task_rt()
1749 if (on_rt_rq(&p->rt)) in set_next_task_rt()
1763 if (rq->curr->sched_class != &rt_sched_class) in set_next_task_rt()
1771 struct rt_prio_array *array = &rt_rq->active; in pick_next_rt_entity()
1776 idx = sched_find_first_bit(array->bitmap); in pick_next_rt_entity()
1779 queue = array->queue + idx; in pick_next_rt_entity()
1782 next = list_entry(queue->next, struct sched_rt_entity, run_list); in pick_next_rt_entity()
1790 struct rt_rq *rt_rq = &rq->rt; in _pick_next_task_rt()
1826 struct sched_rt_entity *rt_se = &p->rt; in put_prev_task_rt()
1827 struct rt_rq *rt_rq = &rq->rt; in put_prev_task_rt()
1829 if (on_rt_rq(&p->rt)) in put_prev_task_rt()
1840 if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1) in put_prev_task_rt()
1852 cpumask_test_cpu(cpu, &p->cpus_mask)) in pick_rt_task()
1864 struct plist_head *head = &rq->rt.pushable_tasks; in pick_highest_pushable_task()
1890 return -1; in find_lowest_rq()
1892 if (task->nr_cpus_allowed == 1) in find_lowest_rq()
1893 return -1; /* No other targets possible */ in find_lowest_rq()
1901 ret = cpupri_find_fitness(&task_rq(task)->rd->cpupri, in find_lowest_rq()
1906 ret = cpupri_find(&task_rq(task)->rd->cpupri, in find_lowest_rq()
1911 return -1; /* No targets found */ in find_lowest_rq()
1919 * it is most likely cache-hot in that location. in find_lowest_rq()
1929 this_cpu = -1; /* Skip this_cpu opt if not among lowest */ in find_lowest_rq()
1933 if (sd->flags & SD_WAKE_AFFINE) { in find_lowest_rq()
1940 if (this_cpu != -1 && in find_lowest_rq()
1961 if (this_cpu != -1) in find_lowest_rq()
1968 return -1; in find_lowest_rq()
1981 if ((cpu == -1) || (cpu == rq->cpu)) in find_lock_lowest_rq()
1986 if (lowest_rq->rt.highest_prio.curr <= task->prio) { in find_lock_lowest_rq()
2008 !cpumask_test_cpu(lowest_rq->cpu, &task->cpus_mask) || in find_lock_lowest_rq()
2021 if (lowest_rq->rt.highest_prio.curr > task->prio) in find_lock_lowest_rq()
2039 p = plist_first_entry(&rq->rt.pushable_tasks, in pick_next_pushable_task()
2042 BUG_ON(rq->cpu != task_cpu(p)); in pick_next_pushable_task()
2044 BUG_ON(p->nr_cpus_allowed <= 1); in pick_next_pushable_task()
2057 static int push_rt_task(struct rq *rq, bool pull) in push_rt_task() argument
2063 if (!rq->rt.overloaded) in push_rt_task()
2076 if (unlikely(next_task->prio < rq->curr->prio)) { in push_rt_task()
2085 if (!pull || rq->push_busy) in push_rt_task()
2097 if (rq->curr->sched_class != &rt_sched_class) in push_rt_task()
2100 cpu = find_lowest_rq(rq->curr); in push_rt_task()
2101 if (cpu == -1 || cpu == rq->cpu) in push_rt_task()
2113 stop_one_cpu_nowait(rq->cpu, push_cpu_stop, in push_rt_task()
2114 push_task, &rq->push_work); in push_rt_task()
2121 if (WARN_ON(next_task == rq->curr)) in push_rt_task()
2132 * find_lock_lowest_rq releases rq->lock in push_rt_task()
2136 * run-queue and is also still the next task eligible for in push_rt_task()
2143 * eligible task, but we failed to find a run-queue in push_rt_task()
2145 * other CPUs will pull from us when ready. in push_rt_task()
2163 set_task_cpu(next_task, lowest_rq->cpu); in push_rt_task()
2190 * up that may be able to run one of its non-running queued RT tasks.
2231 * When starting the IPI RT pushing, the rto_cpu is set to -1, in rto_next_cpu()
2245 /* When rto_cpu is -1 this acts like cpumask_first() */ in rto_next_cpu()
2246 cpu = cpumask_next(rd->rto_cpu, rd->rto_mask); in rto_next_cpu()
2248 rd->rto_cpu = cpu; in rto_next_cpu()
2253 rd->rto_cpu = -1; in rto_next_cpu()
2261 next = atomic_read_acquire(&rd->rto_loop_next); in rto_next_cpu()
2263 if (rd->rto_loop == next) in rto_next_cpu()
2266 rd->rto_loop = next; in rto_next_cpu()
2269 return -1; in rto_next_cpu()
2284 int cpu = -1; in tell_cpu_to_push()
2287 atomic_inc(&rq->rd->rto_loop_next); in tell_cpu_to_push()
2290 if (!rto_start_trylock(&rq->rd->rto_loop_start)) in tell_cpu_to_push()
2293 raw_spin_lock(&rq->rd->rto_lock); in tell_cpu_to_push()
2301 if (rq->rd->rto_cpu < 0) in tell_cpu_to_push()
2302 cpu = rto_next_cpu(rq->rd); in tell_cpu_to_push()
2304 raw_spin_unlock(&rq->rd->rto_lock); in tell_cpu_to_push()
2306 rto_start_unlock(&rq->rd->rto_loop_start); in tell_cpu_to_push()
2310 sched_get_rd(rq->rd); in tell_cpu_to_push()
2311 irq_work_queue_on(&rq->rd->rto_push_work, cpu); in tell_cpu_to_push()
2336 raw_spin_lock(&rd->rto_lock); in rto_push_irq_work_func()
2341 raw_spin_unlock(&rd->rto_lock); in rto_push_irq_work_func()
2349 irq_work_queue_on(&rd->rto_push_work, cpu); in rto_push_irq_work_func()
2355 int this_cpu = this_rq->cpu, cpu; in pull_rt_task()
2372 cpumask_test_cpu(this_rq->cpu, this_rq->rd->rto_mask)) in pull_rt_task()
2382 for_each_cpu(cpu, this_rq->rd->rto_mask) { in pull_rt_task()
2389 * Don't bother taking the src_rq->lock if the next highest in pull_rt_task()
2390 * task is known to be lower-priority than our current task. in pull_rt_task()
2395 if (src_rq->rt.highest_prio.next >= in pull_rt_task()
2396 this_rq->rt.highest_prio.curr) in pull_rt_task()
2408 * We can pull only a task, which is pushable in pull_rt_task()
2415 * the to-be-scheduled task? in pull_rt_task()
2417 if (p && (p->prio < this_rq->rt.highest_prio.curr)) { in pull_rt_task()
2418 WARN_ON(p == src_rq->curr); in pull_rt_task()
2425 * had a chance to schedule. We only pull in pull_rt_task()
2429 if (p->prio < src_rq->curr->prio) in pull_rt_task()
2452 stop_one_cpu_nowait(src_rq->cpu, push_cpu_stop, in pull_rt_task()
2453 push_task, &src_rq->push_work); in pull_rt_task()
2469 !test_tsk_need_resched(rq->curr) && in task_woken_rt()
2470 p->nr_cpus_allowed > 1 && in task_woken_rt()
2471 (dl_task(rq->curr) || rt_task(rq->curr)) && in task_woken_rt()
2472 (rq->curr->nr_cpus_allowed < 2 || in task_woken_rt()
2473 rq->curr->prio <= p->prio); in task_woken_rt()
2479 /* Assumes rq->lock is held */
2482 if (rq->rt.overloaded) in rq_online_rt()
2487 cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr); in rq_online_rt()
2490 /* Assumes rq->lock is held */
2493 if (rq->rt.overloaded) in rq_offline_rt()
2498 cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID); in rq_offline_rt()
2503 * that we might want to pull RT tasks from other runqueues.
2514 if (!task_on_rq_queued(p) || rq->rt.rt_nr_running) in switched_from_rt()
2554 if (p->nr_cpus_allowed > 1 && rq->rt.overloaded) in switched_to_rt()
2557 if (p->prio < rq->curr->prio && cpu_online(cpu_of(rq))) in switched_to_rt()
2564 * us to initiate a push or pull.
2576 * may need to pull tasks to this runqueue. in prio_changed_rt()
2578 if (oldprio < p->prio) in prio_changed_rt()
2585 if (p->prio > rq->rt.highest_prio.curr) in prio_changed_rt()
2589 if (oldprio < p->prio) in prio_changed_rt()
2598 if (p->prio < rq->curr->prio) in prio_changed_rt()
2615 if (p->rt.watchdog_stamp != jiffies) { in watchdog()
2616 p->rt.timeout++; in watchdog()
2617 p->rt.watchdog_stamp = jiffies; in watchdog()
2621 if (p->rt.timeout > next) { in watchdog()
2622 posix_cputimers_rt_watchdog(&p->posix_cputimers, in watchdog()
2623 p->se.sum_exec_runtime); in watchdog()
2641 struct sched_rt_entity *rt_se = &p->rt; in task_tick_rt()
2652 if (p->policy != SCHED_RR) in task_tick_rt()
2655 if (--p->rt.time_slice) in task_tick_rt()
2658 p->rt.time_slice = sched_rr_timeslice; in task_tick_rt()
2665 if (rt_se->run_list.prev != rt_se->run_list.next) { in task_tick_rt()
2678 if (task->policy == SCHED_RR) in get_rr_interval_rt()
2690 rt_rq = task_group(p)->rt_rq[cpu]; in task_is_throttled_rt()
2692 rt_rq = &cpu_rq(cpu)->rt; in task_is_throttled_rt()
2759 css_task_iter_start(&tg->css, 0, &it); in tg_has_rt_tasks()
2780 period = ktime_to_ns(tg->rt_bandwidth.rt_period); in tg_rt_schedulable()
2781 runtime = tg->rt_bandwidth.rt_runtime; in tg_rt_schedulable()
2783 if (tg == d->tg) { in tg_rt_schedulable()
2784 period = d->rt_period; in tg_rt_schedulable()
2785 runtime = d->rt_runtime; in tg_rt_schedulable()
2792 return -EINVAL; in tg_rt_schedulable()
2798 tg->rt_bandwidth.rt_runtime && tg_has_rt_tasks(tg)) in tg_rt_schedulable()
2799 return -EBUSY; in tg_rt_schedulable()
2807 return -EINVAL; in tg_rt_schedulable()
2812 list_for_each_entry_rcu(child, &tg->children, siblings) { in tg_rt_schedulable()
2813 period = ktime_to_ns(child->rt_bandwidth.rt_period); in tg_rt_schedulable()
2814 runtime = child->rt_bandwidth.rt_runtime; in tg_rt_schedulable()
2816 if (child == d->tg) { in tg_rt_schedulable()
2817 period = d->rt_period; in tg_rt_schedulable()
2818 runtime = d->rt_runtime; in tg_rt_schedulable()
2825 return -EINVAL; in tg_rt_schedulable()
2857 return -EINVAL; in tg_set_rt_bandwidth()
2861 return -EINVAL; in tg_set_rt_bandwidth()
2867 return -EINVAL; in tg_set_rt_bandwidth()
2874 raw_spin_lock_irq(&tg->rt_bandwidth.rt_runtime_lock); in tg_set_rt_bandwidth()
2875 tg->rt_bandwidth.rt_period = ns_to_ktime(rt_period); in tg_set_rt_bandwidth()
2876 tg->rt_bandwidth.rt_runtime = rt_runtime; in tg_set_rt_bandwidth()
2879 struct rt_rq *rt_rq = tg->rt_rq[i]; in tg_set_rt_bandwidth()
2881 raw_spin_lock(&rt_rq->rt_runtime_lock); in tg_set_rt_bandwidth()
2882 rt_rq->rt_runtime = rt_runtime; in tg_set_rt_bandwidth()
2883 raw_spin_unlock(&rt_rq->rt_runtime_lock); in tg_set_rt_bandwidth()
2885 raw_spin_unlock_irq(&tg->rt_bandwidth.rt_runtime_lock); in tg_set_rt_bandwidth()
2896 rt_period = ktime_to_ns(tg->rt_bandwidth.rt_period); in sched_group_set_rt_runtime()
2901 return -EINVAL; in sched_group_set_rt_runtime()
2910 if (tg->rt_bandwidth.rt_runtime == RUNTIME_INF) in sched_group_rt_runtime()
2911 return -1; in sched_group_rt_runtime()
2913 rt_runtime_us = tg->rt_bandwidth.rt_runtime; in sched_group_rt_runtime()
2923 return -EINVAL; in sched_group_set_rt_period()
2926 rt_runtime = tg->rt_bandwidth.rt_runtime; in sched_group_set_rt_period()
2935 rt_period_us = ktime_to_ns(tg->rt_bandwidth.rt_period); in sched_group_rt_period()
2956 if (rt_task(tsk) && tg->rt_bandwidth.rt_runtime == 0) in sched_rt_can_attach()
2972 struct rt_rq *rt_rq = &cpu_rq(i)->rt; in sched_rt_global_constraints()
2974 raw_spin_lock(&rt_rq->rt_runtime_lock); in sched_rt_global_constraints()
2975 rt_rq->rt_runtime = global_rt_runtime(); in sched_rt_global_constraints()
2976 raw_spin_unlock(&rt_rq->rt_runtime_lock); in sched_rt_global_constraints()
2989 return -EINVAL; in sched_rt_global_validate()
2995 return -EINVAL; in sched_rt_global_validate()