Lines Matching +full:avg +full:- +full:samples
1 // SPDX-License-Identifier: GPL-2.0
26 * Targeted preemption latency for CPU-bound tasks:
29 * 'timeslice length' - timeslices in CFS are of variable length
30 * and have no persistent notion like in traditional, time-slice
34 * run vmstat and monitor the context-switches (cs) field)
42 * The initial- and re-scaling of tunables is configurable
46 * SCHED_TUNABLESCALING_NONE - unscaled, always *1
47 * SCHED_TUNABLESCALING_LOG - scaled logarithmical, *1+ilog(ncpus)
48 * SCHED_TUNABLESCALING_LINEAR - scaled linear, *ncpus
55 * Minimal preemption granularity for CPU-bound tasks:
74 * SCHED_OTHER wake-up granularity.
77 * and reduces their over-scheduling. Synchronous workloads will still
106 return -cpu; in arch_asym_cpu_priority()
120 * Amount of runtime to allocate from global (tg) to local (per-cfs_rq) pool
134 lw->weight += inc; in update_load_add()
135 lw->inv_weight = 0; in update_load_add()
140 lw->weight -= dec; in update_load_sub()
141 lw->inv_weight = 0; in update_load_sub()
146 lw->weight = w; in update_load_set()
147 lw->inv_weight = 0; in update_load_set()
154 * so pick a second-best guess by going with the log2 of the
204 if (likely(lw->inv_weight)) in __update_inv_weight()
207 w = scale_load_down(lw->weight); in __update_inv_weight()
210 lw->inv_weight = 1; in __update_inv_weight()
212 lw->inv_weight = WMULT_CONST; in __update_inv_weight()
214 lw->inv_weight = WMULT_CONST / w; in __update_inv_weight()
220 * (delta_exec * (weight * lw->inv_weight)) >> WMULT_SHIFT
239 shift--; in __calc_delta()
243 fact = mul_u32_u32(fact, lw->inv_weight); in __calc_delta()
247 shift--; in __calc_delta()
269 for (; se; se = se->parent)
273 return p->se.cfs_rq; in task_cfs_rq()
279 return se->cfs_rq; in cfs_rq_of()
285 return grp->my_q; in group_cfs_rq()
293 if (cfs_rq && task_group_is_autogroup(cfs_rq->tg)) in cfs_rq_tg_path()
294 autogroup_path(cfs_rq->tg, path, len); in cfs_rq_tg_path()
295 else if (cfs_rq && cfs_rq->tg->css.cgroup) in cfs_rq_tg_path()
296 cgroup_path(cfs_rq->tg->css.cgroup, path, len); in cfs_rq_tg_path()
306 if (cfs_rq->on_list) in list_add_leaf_cfs_rq()
307 return rq->tmp_alone_branch == &rq->leaf_cfs_rq_list; in list_add_leaf_cfs_rq()
309 cfs_rq->on_list = 1; in list_add_leaf_cfs_rq()
314 * enqueued. The fact that we always enqueue bottom-up in list_add_leaf_cfs_rq()
320 if (cfs_rq->tg->parent && in list_add_leaf_cfs_rq()
321 cfs_rq->tg->parent->cfs_rq[cpu]->on_list) { in list_add_leaf_cfs_rq()
328 list_add_tail_rcu(&cfs_rq->leaf_cfs_rq_list, in list_add_leaf_cfs_rq()
329 &(cfs_rq->tg->parent->cfs_rq[cpu]->leaf_cfs_rq_list)); in list_add_leaf_cfs_rq()
335 rq->tmp_alone_branch = &rq->leaf_cfs_rq_list; in list_add_leaf_cfs_rq()
339 if (!cfs_rq->tg->parent) { in list_add_leaf_cfs_rq()
344 list_add_tail_rcu(&cfs_rq->leaf_cfs_rq_list, in list_add_leaf_cfs_rq()
345 &rq->leaf_cfs_rq_list); in list_add_leaf_cfs_rq()
350 rq->tmp_alone_branch = &rq->leaf_cfs_rq_list; in list_add_leaf_cfs_rq()
360 list_add_rcu(&cfs_rq->leaf_cfs_rq_list, rq->tmp_alone_branch); in list_add_leaf_cfs_rq()
365 rq->tmp_alone_branch = &cfs_rq->leaf_cfs_rq_list; in list_add_leaf_cfs_rq()
371 if (cfs_rq->on_list) { in list_del_leaf_cfs_rq()
378 * to the prev element but it will point to rq->leaf_cfs_rq_list in list_del_leaf_cfs_rq()
381 if (rq->tmp_alone_branch == &cfs_rq->leaf_cfs_rq_list) in list_del_leaf_cfs_rq()
382 rq->tmp_alone_branch = cfs_rq->leaf_cfs_rq_list.prev; in list_del_leaf_cfs_rq()
384 list_del_rcu(&cfs_rq->leaf_cfs_rq_list); in list_del_leaf_cfs_rq()
385 cfs_rq->on_list = 0; in list_del_leaf_cfs_rq()
391 SCHED_WARN_ON(rq->tmp_alone_branch != &rq->leaf_cfs_rq_list); in assert_list_leaf_cfs_rq()
396 list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list, \
403 if (se->cfs_rq == pse->cfs_rq) in is_same_group()
404 return se->cfs_rq; in is_same_group()
411 return se->parent; in parent_entity()
427 se_depth = (*se)->depth; in find_matching_se()
428 pse_depth = (*pse)->depth; in find_matching_se()
431 se_depth--; in find_matching_se()
436 pse_depth--; in find_matching_se()
458 return &task_rq(p)->cfs; in task_cfs_rq()
466 return &rq->cfs; in cfs_rq_of()
495 for (cfs_rq = &rq->cfs, pos = NULL; cfs_rq; cfs_rq = pos)
518 s64 delta = (s64)(vruntime - max_vruntime); in max_vruntime()
527 s64 delta = (s64)(vruntime - min_vruntime); in min_vruntime()
537 return (s64)(a->vruntime - b->vruntime) < 0; in entity_before()
542 struct sched_entity *curr = cfs_rq->curr; in update_min_vruntime()
543 struct rb_node *leftmost = rb_first_cached(&cfs_rq->tasks_timeline); in update_min_vruntime()
545 u64 vruntime = cfs_rq->min_vruntime; in update_min_vruntime()
548 if (curr->on_rq) in update_min_vruntime()
549 vruntime = curr->vruntime; in update_min_vruntime()
554 if (leftmost) { /* non-empty tree */ in update_min_vruntime()
559 vruntime = se->vruntime; in update_min_vruntime()
561 vruntime = min_vruntime(vruntime, se->vruntime); in update_min_vruntime()
565 cfs_rq->min_vruntime = max_vruntime(cfs_rq->min_vruntime, vruntime); in update_min_vruntime()
568 cfs_rq->min_vruntime_copy = cfs_rq->min_vruntime; in update_min_vruntime()
573 * Enqueue an entity into the rb-tree:
577 struct rb_node **link = &cfs_rq->tasks_timeline.rb_root.rb_node; in __enqueue_entity()
593 link = &parent->rb_left; in __enqueue_entity()
595 link = &parent->rb_right; in __enqueue_entity()
600 rb_link_node(&se->run_node, parent, link); in __enqueue_entity()
601 rb_insert_color_cached(&se->run_node, in __enqueue_entity()
602 &cfs_rq->tasks_timeline, leftmost); in __enqueue_entity()
607 rb_erase_cached(&se->run_node, &cfs_rq->tasks_timeline); in __dequeue_entity()
612 struct rb_node *left = rb_first_cached(&cfs_rq->tasks_timeline); in __pick_first_entity()
622 struct rb_node *next = rb_next(&se->run_node); in __pick_next_entity()
633 struct rb_node *last = rb_last(&cfs_rq->tasks_timeline.rb_root); in __pick_last_entity()
673 if (unlikely(se->load.weight != NICE_0_LOAD)) in calc_delta_fair()
674 delta = __calc_delta(delta, NICE_0_LOAD, &se->load); in calc_delta_fair()
696 * We calculate the wall-time slice from the period by taking a part
703 u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq); in sched_slice()
710 load = &cfs_rq->load; in sched_slice()
712 if (unlikely(!se->on_rq)) { in sched_slice()
713 lw = cfs_rq->load; in sched_slice()
715 update_load_add(&lw, se->load.weight); in sched_slice()
718 slice = __calc_delta(slice, se->load.weight, load); in sched_slice()
724 * We calculate the vruntime slice of a to-be-inserted task.
743 struct sched_avg *sa = &se->avg; in init_entity_runnable_average()
754 sa->load_avg = scale_load_down(se->load.weight); in init_entity_runnable_average()
765 * util_avg = cfs_rq->util_avg / (cfs_rq->load_avg + 1) * se.load.weight
774 * util_avg_cap = (cpu_scale - cfs_rq->avg.util_avg) / 2^n
789 struct sched_entity *se = &p->se; in post_init_entity_util_avg()
791 struct sched_avg *sa = &se->avg; in post_init_entity_util_avg()
793 long cap = (long)(cpu_scale - cfs_rq->avg.util_avg) / 2; in post_init_entity_util_avg()
796 if (cfs_rq->avg.util_avg != 0) { in post_init_entity_util_avg()
797 sa->util_avg = cfs_rq->avg.util_avg * se->load.weight; in post_init_entity_util_avg()
798 sa->util_avg /= (cfs_rq->avg.load_avg + 1); in post_init_entity_util_avg()
800 if (sa->util_avg > cap) in post_init_entity_util_avg()
801 sa->util_avg = cap; in post_init_entity_util_avg()
803 sa->util_avg = cap; in post_init_entity_util_avg()
807 sa->runnable_avg = sa->util_avg; in post_init_entity_util_avg()
809 if (p->sched_class != &fair_sched_class) { in post_init_entity_util_avg()
820 se->avg.last_update_time = cfs_rq_clock_pelt(cfs_rq); in post_init_entity_util_avg()
844 struct sched_entity *curr = cfs_rq->curr; in update_curr()
851 delta_exec = now - curr->exec_start; in update_curr()
855 curr->exec_start = now; in update_curr()
857 schedstat_set(curr->statistics.exec_max, in update_curr()
858 max(delta_exec, curr->statistics.exec_max)); in update_curr()
860 curr->sum_exec_runtime += delta_exec; in update_curr()
861 schedstat_add(cfs_rq->exec_clock, delta_exec); in update_curr()
863 curr->vruntime += calc_delta_fair(delta_exec, curr); in update_curr()
869 trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime); in update_curr()
879 update_curr(cfs_rq_of(&rq->curr->se)); in update_curr_fair()
891 prev_wait_start = schedstat_val(se->statistics.wait_start); in update_stats_wait_start()
895 wait_start -= prev_wait_start; in update_stats_wait_start()
897 __schedstat_set(se->statistics.wait_start, wait_start); in update_stats_wait_start()
909 delta = rq_clock(rq_of(cfs_rq)) - schedstat_val(se->statistics.wait_start); in update_stats_wait_end()
919 __schedstat_set(se->statistics.wait_start, delta); in update_stats_wait_end()
925 __schedstat_set(se->statistics.wait_max, in update_stats_wait_end()
926 max(schedstat_val(se->statistics.wait_max), delta)); in update_stats_wait_end()
927 __schedstat_inc(se->statistics.wait_count); in update_stats_wait_end()
928 __schedstat_add(se->statistics.wait_sum, delta); in update_stats_wait_end()
929 __schedstat_set(se->statistics.wait_start, 0); in update_stats_wait_end()
941 sleep_start = schedstat_val(se->statistics.sleep_start); in update_stats_enqueue_sleeper()
942 block_start = schedstat_val(se->statistics.block_start); in update_stats_enqueue_sleeper()
948 u64 delta = rq_clock(rq_of(cfs_rq)) - sleep_start; in update_stats_enqueue_sleeper()
953 if (unlikely(delta > schedstat_val(se->statistics.sleep_max))) in update_stats_enqueue_sleeper()
954 __schedstat_set(se->statistics.sleep_max, delta); in update_stats_enqueue_sleeper()
956 __schedstat_set(se->statistics.sleep_start, 0); in update_stats_enqueue_sleeper()
957 __schedstat_add(se->statistics.sum_sleep_runtime, delta); in update_stats_enqueue_sleeper()
965 u64 delta = rq_clock(rq_of(cfs_rq)) - block_start; in update_stats_enqueue_sleeper()
970 if (unlikely(delta > schedstat_val(se->statistics.block_max))) in update_stats_enqueue_sleeper()
971 __schedstat_set(se->statistics.block_max, delta); in update_stats_enqueue_sleeper()
973 __schedstat_set(se->statistics.block_start, 0); in update_stats_enqueue_sleeper()
974 __schedstat_add(se->statistics.sum_sleep_runtime, delta); in update_stats_enqueue_sleeper()
977 if (tsk->in_iowait) { in update_stats_enqueue_sleeper()
978 __schedstat_add(se->statistics.iowait_sum, delta); in update_stats_enqueue_sleeper()
979 __schedstat_inc(se->statistics.iowait_count); in update_stats_enqueue_sleeper()
987 * 20 to get a milliseconds-range estimation of the in update_stats_enqueue_sleeper()
1001 * Task is being enqueued - update stats:
1013 if (se != cfs_rq->curr) in update_stats_enqueue()
1031 if (se != cfs_rq->curr) in update_stats_dequeue()
1037 if (tsk->state & TASK_INTERRUPTIBLE) in update_stats_dequeue()
1038 __schedstat_set(se->statistics.sleep_start, in update_stats_dequeue()
1040 if (tsk->state & TASK_UNINTERRUPTIBLE) in update_stats_dequeue()
1041 __schedstat_set(se->statistics.block_start, in update_stats_dequeue()
1047 * We are picking a new current task - update its stats:
1055 se->exec_start = rq_clock_task(rq_of(cfs_rq)); in update_stats_curr_start()
1099 * ->numa_group (see struct task_struct for locking rules).
1103 return rcu_dereference_check(p->numa_group, p == current || in deref_task_numa_group()
1104 (lockdep_is_held(&task_rq(p)->lock) && !READ_ONCE(p->on_cpu))); in deref_task_numa_group()
1109 return rcu_dereference_protected(p->numa_group, p == current); in deref_curr_numa_group()
1121 * Calculations based on RSS as non-present and empty pages are skipped in task_nr_scan_windows()
1125 nr_scan_pages = sysctl_numa_balancing_scan_size << (20 - PAGE_SHIFT); in task_nr_scan_windows()
1126 rss = get_mm_rss(p->mm); in task_nr_scan_windows()
1159 ng = rcu_dereference(p->numa_group); in task_scan_start()
1164 period *= refcount_read(&ng->refcount); in task_scan_start()
1189 period *= refcount_read(&ng->refcount); in task_scan_max()
1201 rq->nr_numa_running += (p->numa_preferred_nid != NUMA_NO_NODE); in account_numa_enqueue()
1202 rq->nr_preferred_running += (p->numa_preferred_nid == task_node(p)); in account_numa_enqueue()
1207 rq->nr_numa_running -= (p->numa_preferred_nid != NUMA_NO_NODE); in account_numa_dequeue()
1208 rq->nr_preferred_running -= (p->numa_preferred_nid == task_node(p)); in account_numa_dequeue()
1226 ng = rcu_dereference(p->numa_group); in task_numa_group_id()
1228 gid = ng->gid; in task_numa_group_id()
1247 if (!p->numa_faults) in task_faults()
1250 return p->numa_faults[task_faults_idx(NUMA_MEM, nid, 0)] + in task_faults()
1251 p->numa_faults[task_faults_idx(NUMA_MEM, nid, 1)]; in task_faults()
1261 return ng->faults[task_faults_idx(NUMA_MEM, nid, 0)] + in group_faults()
1262 ng->faults[task_faults_idx(NUMA_MEM, nid, 1)]; in group_faults()
1267 return group->faults_cpu[task_faults_idx(NUMA_MEM, nid, 0)] + in group_faults_cpu()
1268 group->faults_cpu[task_faults_idx(NUMA_MEM, nid, 1)]; in group_faults_cpu()
1277 faults += ng->faults[task_faults_idx(NUMA_MEM, node, 1)]; in group_faults_priv()
1289 faults += ng->faults[task_faults_idx(NUMA_MEM, node, 0)]; in group_faults_shared()
1297 * considered part of a numa group's pseudo-interleaving set. Migrations
1304 return group_faults_cpu(ng, nid) * ACTIVE_NODE_FRACTION > ng->max_faults_cpu; in numa_is_active_node()
1362 faults *= (sched_max_numa_distance - dist); in score_nearby_nodes()
1363 faults /= (sched_max_numa_distance - LOCAL_DISTANCE); in score_nearby_nodes()
1383 if (!p->numa_faults) in task_weight()
1386 total_faults = p->total_numa_faults; in task_weight()
1406 total_faults = ng->total_faults; in group_weight()
1424 this_cpupid = cpu_pid_to_cpupid(dst_cpu, current->pid); in should_numa_migrate_memory()
1430 * two full passes of the "multi-stage node selection" test that is in should_numa_migrate_memory()
1433 if ((p->numa_preferred_nid == NUMA_NO_NODE || p->numa_scan_seq <= 4) && in should_numa_migrate_memory()
1438 * Multi-stage node selection is used in conjunction with a periodic in should_numa_migrate_memory()
1439 * migration fault to build a temporal task<->page relation. By using in should_numa_migrate_memory()
1440 * a two-stage filter we remove short/unlikely relations. in should_numa_migrate_memory()
1444 * page (n_t) (in a given time-span) to a probability. in should_numa_migrate_memory()
1447 * same result twice in a row, given these samples are fully in should_numa_migrate_memory()
1452 * act on an unlikely task<->page relation. in should_numa_migrate_memory()
1462 /* A shared fault, but p->numa_group has not been set up yet. */ in should_numa_migrate_memory()
1479 * --------------- * - > --------------- in should_numa_migrate_memory()
1559 if ((ns->nr_running > ns->weight) && in numa_classify()
1560 (((ns->compute_capacity * 100) < (ns->util * imbalance_pct)) || in numa_classify()
1561 ((ns->compute_capacity * imbalance_pct) < (ns->runnable * 100)))) in numa_classify()
1564 if ((ns->nr_running < ns->weight) || in numa_classify()
1565 (((ns->compute_capacity * 100) > (ns->util * imbalance_pct)) && in numa_classify()
1566 ((ns->compute_capacity * imbalance_pct) > (ns->runnable * 100)))) in numa_classify()
1607 int cpu, idle_core = -1; in update_numa_stats()
1610 ns->idle_cpu = -1; in update_numa_stats()
1616 ns->load += cpu_load(rq); in update_numa_stats()
1617 ns->runnable += cpu_runnable(rq); in update_numa_stats()
1618 ns->util += cpu_util(cpu); in update_numa_stats()
1619 ns->nr_running += rq->cfs.h_nr_running; in update_numa_stats()
1620 ns->compute_capacity += capacity_of(cpu); in update_numa_stats()
1622 if (find_idle && !rq->nr_running && idle_cpu(cpu)) { in update_numa_stats()
1623 if (READ_ONCE(rq->numa_migrate_on) || in update_numa_stats()
1624 !cpumask_test_cpu(cpu, env->p->cpus_ptr)) in update_numa_stats()
1627 if (ns->idle_cpu == -1) in update_numa_stats()
1628 ns->idle_cpu = cpu; in update_numa_stats()
1635 ns->weight = cpumask_weight(cpumask_of_node(nid)); in update_numa_stats()
1637 ns->node_type = numa_classify(env->imbalance_pct, ns); in update_numa_stats()
1640 ns->idle_cpu = idle_core; in update_numa_stats()
1646 struct rq *rq = cpu_rq(env->dst_cpu); in task_numa_assign()
1648 /* Check if run-queue part of active NUMA balance. */ in task_numa_assign()
1649 if (env->best_cpu != env->dst_cpu && xchg(&rq->numa_migrate_on, 1)) { in task_numa_assign()
1651 int start = env->dst_cpu; in task_numa_assign()
1654 for_each_cpu_wrap(cpu, cpumask_of_node(env->dst_nid), start) { in task_numa_assign()
1655 if (cpu == env->best_cpu || !idle_cpu(cpu) || in task_numa_assign()
1656 !cpumask_test_cpu(cpu, env->p->cpus_ptr)) { in task_numa_assign()
1660 env->dst_cpu = cpu; in task_numa_assign()
1661 rq = cpu_rq(env->dst_cpu); in task_numa_assign()
1662 if (!xchg(&rq->numa_migrate_on, 1)) in task_numa_assign()
1672 * Clear previous best_cpu/rq numa-migrate flag, since task now in task_numa_assign()
1675 if (env->best_cpu != -1 && env->best_cpu != env->dst_cpu) { in task_numa_assign()
1676 rq = cpu_rq(env->best_cpu); in task_numa_assign()
1677 WRITE_ONCE(rq->numa_migrate_on, 0); in task_numa_assign()
1680 if (env->best_task) in task_numa_assign()
1681 put_task_struct(env->best_task); in task_numa_assign()
1685 env->best_task = p; in task_numa_assign()
1686 env->best_imp = imp; in task_numa_assign()
1687 env->best_cpu = env->dst_cpu; in task_numa_assign()
1701 * ------------ vs --------- in load_too_imbalanced()
1704 src_capacity = env->src_stats.compute_capacity; in load_too_imbalanced()
1705 dst_capacity = env->dst_stats.compute_capacity; in load_too_imbalanced()
1707 imb = abs(dst_load * src_capacity - src_load * dst_capacity); in load_too_imbalanced()
1709 orig_src_load = env->src_stats.load; in load_too_imbalanced()
1710 orig_dst_load = env->dst_stats.load; in load_too_imbalanced()
1712 old_imb = abs(orig_dst_load * src_capacity - orig_src_load * dst_capacity); in load_too_imbalanced()
1734 struct numa_group *cur_ng, *p_ng = deref_curr_numa_group(env->p); in task_numa_compare()
1735 struct rq *dst_rq = cpu_rq(env->dst_cpu); in task_numa_compare()
1739 int dist = env->dist; in task_numa_compare()
1744 if (READ_ONCE(dst_rq->numa_migrate_on)) in task_numa_compare()
1748 cur = rcu_dereference(dst_rq->curr); in task_numa_compare()
1749 if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur))) in task_numa_compare()
1754 * end try selecting ourselves (current == env->p) as a swap candidate. in task_numa_compare()
1756 if (cur == env->p) { in task_numa_compare()
1762 if (maymove && moveimp >= env->best_imp) in task_numa_compare()
1769 if (!cpumask_test_cpu(env->src_cpu, cur->cpus_ptr)) in task_numa_compare()
1776 if (env->best_task && in task_numa_compare()
1777 env->best_task->numa_preferred_nid == env->src_nid && in task_numa_compare()
1778 cur->numa_preferred_nid != env->src_nid) { in task_numa_compare()
1792 cur_ng = rcu_dereference(cur->numa_group); in task_numa_compare()
1794 imp = taskimp + task_weight(cur, env->src_nid, dist) - in task_numa_compare()
1795 task_weight(cur, env->dst_nid, dist); in task_numa_compare()
1801 imp -= imp / 16; in task_numa_compare()
1808 imp += group_weight(cur, env->src_nid, dist) - in task_numa_compare()
1809 group_weight(cur, env->dst_nid, dist); in task_numa_compare()
1811 imp += task_weight(cur, env->src_nid, dist) - in task_numa_compare()
1812 task_weight(cur, env->dst_nid, dist); in task_numa_compare()
1816 if (cur->numa_preferred_nid == env->dst_nid) in task_numa_compare()
1817 imp -= imp / 16; in task_numa_compare()
1825 if (cur->numa_preferred_nid == env->src_nid) in task_numa_compare()
1828 if (maymove && moveimp > imp && moveimp > env->best_imp) { in task_numa_compare()
1838 if (env->best_task && cur->numa_preferred_nid == env->src_nid && in task_numa_compare()
1839 env->best_task->numa_preferred_nid != env->src_nid) { in task_numa_compare()
1849 if (imp < SMALLIMP || imp <= env->best_imp + SMALLIMP / 2) in task_numa_compare()
1855 load = task_h_load(env->p) - task_h_load(cur); in task_numa_compare()
1859 dst_load = env->dst_stats.load + load; in task_numa_compare()
1860 src_load = env->src_stats.load - load; in task_numa_compare()
1868 int cpu = env->dst_stats.idle_cpu; in task_numa_compare()
1872 cpu = env->dst_cpu; in task_numa_compare()
1878 if (!idle_cpu(cpu) && env->best_cpu >= 0 && in task_numa_compare()
1879 idle_cpu(env->best_cpu)) { in task_numa_compare()
1880 cpu = env->best_cpu; in task_numa_compare()
1883 env->dst_cpu = cpu; in task_numa_compare()
1893 if (maymove && !cur && env->best_cpu >= 0 && idle_cpu(env->best_cpu)) in task_numa_compare()
1900 if (!maymove && env->best_task && in task_numa_compare()
1901 env->best_task->numa_preferred_nid == env->src_nid) { in task_numa_compare()
1920 if (env->dst_stats.node_type == node_has_spare) { in task_numa_find_cpu()
1930 src_running = env->src_stats.nr_running - 1; in task_numa_find_cpu()
1931 dst_running = env->dst_stats.nr_running + 1; in task_numa_find_cpu()
1932 imbalance = max(0, dst_running - src_running); in task_numa_find_cpu()
1938 if (env->dst_stats.idle_cpu >= 0) { in task_numa_find_cpu()
1939 env->dst_cpu = env->dst_stats.idle_cpu; in task_numa_find_cpu()
1947 * If the improvement from just moving env->p direction is better in task_numa_find_cpu()
1950 load = task_h_load(env->p); in task_numa_find_cpu()
1951 dst_load = env->dst_stats.load + load; in task_numa_find_cpu()
1952 src_load = env->src_stats.load - load; in task_numa_find_cpu()
1956 for_each_cpu(cpu, cpumask_of_node(env->dst_nid)) { in task_numa_find_cpu()
1958 if (!cpumask_test_cpu(cpu, env->p->cpus_ptr)) in task_numa_find_cpu()
1961 env->dst_cpu = cpu; in task_numa_find_cpu()
1979 .best_cpu = -1, in task_numa_migrate()
1993 * random movement of tasks -- counter the numa conditions we're trying in task_numa_migrate()
1999 env.imbalance_pct = 100 + (sd->imbalance_pct - 100) / 2; in task_numa_migrate()
2010 return -EINVAL; in task_numa_migrate()
2013 env.dst_nid = p->numa_preferred_nid; in task_numa_migrate()
2018 taskimp = task_weight(p, env.dst_nid, dist) - taskweight; in task_numa_migrate()
2019 groupimp = group_weight(p, env.dst_nid, dist) - groupweight; in task_numa_migrate()
2027 * - there is no space available on the preferred_nid in task_numa_migrate()
2028 * - the task is part of a numa_group that is interleaved across in task_numa_migrate()
2033 if (env.best_cpu == -1 || (ng && ng->active_nodes > 1)) { in task_numa_migrate()
2035 if (nid == env.src_nid || nid == p->numa_preferred_nid) in task_numa_migrate()
2046 taskimp = task_weight(p, nid, dist) - taskweight; in task_numa_migrate()
2047 groupimp = group_weight(p, nid, dist) - groupweight; in task_numa_migrate()
2067 if (env.best_cpu == -1) in task_numa_migrate()
2072 if (nid != p->numa_preferred_nid) in task_numa_migrate()
2077 if (env.best_cpu == -1) { in task_numa_migrate()
2078 trace_sched_stick_numa(p, env.src_cpu, NULL, -1); in task_numa_migrate()
2079 return -EAGAIN; in task_numa_migrate()
2085 WRITE_ONCE(best_rq->numa_migrate_on, 0); in task_numa_migrate()
2092 WRITE_ONCE(best_rq->numa_migrate_on, 0); in task_numa_migrate()
2106 if (unlikely(p->numa_preferred_nid == NUMA_NO_NODE || !p->numa_faults)) in numa_migrate_preferred()
2110 interval = min(interval, msecs_to_jiffies(p->numa_scan_period) / 16); in numa_migrate_preferred()
2111 p->numa_migrate_retry = jiffies + interval; in numa_migrate_preferred()
2114 if (task_node(p) == p->numa_preferred_nid) in numa_migrate_preferred()
2144 numa_group->max_faults_cpu = max_faults; in numa_group_count_active_nodes()
2145 numa_group->active_nodes = active_nodes; in numa_group_count_active_nodes()
2171 unsigned long remote = p->numa_faults_locality[0]; in update_task_scan_period()
2172 unsigned long local = p->numa_faults_locality[1]; in update_task_scan_period()
2181 if (local + shared == 0 || p->numa_faults_locality[2]) { in update_task_scan_period()
2182 p->numa_scan_period = min(p->numa_scan_period_max, in update_task_scan_period()
2183 p->numa_scan_period << 1); in update_task_scan_period()
2185 p->mm->numa_next_scan = jiffies + in update_task_scan_period()
2186 msecs_to_jiffies(p->numa_scan_period); in update_task_scan_period()
2197 period_slot = DIV_ROUND_UP(p->numa_scan_period, NUMA_PERIOD_SLOTS); in update_task_scan_period()
2206 int slot = ps_ratio - NUMA_PERIOD_THRESHOLD; in update_task_scan_period()
2216 int slot = lr_ratio - NUMA_PERIOD_THRESHOLD; in update_task_scan_period()
2222 * Private memory faults exceed (SLOTS-THRESHOLD)/SLOTS, in update_task_scan_period()
2227 diff = -(NUMA_PERIOD_THRESHOLD - ratio) * period_slot; in update_task_scan_period()
2230 p->numa_scan_period = clamp(p->numa_scan_period + diff, in update_task_scan_period()
2232 memset(p->numa_faults_locality, 0, sizeof(p->numa_faults_locality)); in update_task_scan_period()
2239 * from the dozens-of-seconds NUMA balancing period. Use the scheduler
2246 now = p->se.exec_start; in numa_get_avg_runtime()
2247 runtime = p->se.sum_exec_runtime; in numa_get_avg_runtime()
2249 if (p->last_task_numa_placement) { in numa_get_avg_runtime()
2250 delta = runtime - p->last_sum_exec_runtime; in numa_get_avg_runtime()
2251 *period = now - p->last_task_numa_placement; in numa_get_avg_runtime()
2257 delta = p->se.avg.load_sum; in numa_get_avg_runtime()
2261 p->last_sum_exec_runtime = runtime; in numa_get_avg_runtime()
2262 p->last_task_numa_placement = now; in numa_get_avg_runtime()
2312 for (dist = sched_max_numa_distance; dist > LOCAL_DISTANCE; dist--) { in preferred_group_nid()
2366 * The p->mm->numa_scan_seq field gets updated without in task_numa_placement()
2370 seq = READ_ONCE(p->mm->numa_scan_seq); in task_numa_placement()
2371 if (p->numa_scan_seq == seq) in task_numa_placement()
2373 p->numa_scan_seq = seq; in task_numa_placement()
2374 p->numa_scan_period_max = task_scan_max(p); in task_numa_placement()
2376 total_faults = p->numa_faults_locality[0] + in task_numa_placement()
2377 p->numa_faults_locality[1]; in task_numa_placement()
2383 group_lock = &ng->lock; in task_numa_placement()
2403 diff = p->numa_faults[membuf_idx] - p->numa_faults[mem_idx] / 2; in task_numa_placement()
2404 fault_types[priv] += p->numa_faults[membuf_idx]; in task_numa_placement()
2405 p->numa_faults[membuf_idx] = 0; in task_numa_placement()
2411 * little over-all impact on throughput, and thus their in task_numa_placement()
2415 f_weight = (f_weight * p->numa_faults[cpubuf_idx]) / in task_numa_placement()
2417 f_diff = f_weight - p->numa_faults[cpu_idx] / 2; in task_numa_placement()
2418 p->numa_faults[cpubuf_idx] = 0; in task_numa_placement()
2420 p->numa_faults[mem_idx] += diff; in task_numa_placement()
2421 p->numa_faults[cpu_idx] += f_diff; in task_numa_placement()
2422 faults += p->numa_faults[mem_idx]; in task_numa_placement()
2423 p->total_numa_faults += diff; in task_numa_placement()
2432 ng->faults[mem_idx] += diff; in task_numa_placement()
2433 ng->faults_cpu[mem_idx] += f_diff; in task_numa_placement()
2434 ng->total_faults += diff; in task_numa_placement()
2435 group_faults += ng->faults[mem_idx]; in task_numa_placement()
2458 if (max_nid != p->numa_preferred_nid) in task_numa_placement()
2467 return refcount_inc_not_zero(&grp->refcount); in get_numa_group()
2472 if (refcount_dec_and_test(&grp->refcount)) in put_numa_group()
2493 refcount_set(&grp->refcount, 1); in task_numa_group()
2494 grp->active_nodes = 1; in task_numa_group()
2495 grp->max_faults_cpu = 0; in task_numa_group()
2496 spin_lock_init(&grp->lock); in task_numa_group()
2497 grp->gid = p->pid; in task_numa_group()
2499 grp->faults_cpu = grp->faults + NR_NUMA_HINT_FAULT_TYPES * in task_numa_group()
2503 grp->faults[i] = p->numa_faults[i]; in task_numa_group()
2505 grp->total_faults = p->total_numa_faults; in task_numa_group()
2507 grp->nr_tasks++; in task_numa_group()
2508 rcu_assign_pointer(p->numa_group, grp); in task_numa_group()
2512 tsk = READ_ONCE(cpu_rq(cpu)->curr); in task_numa_group()
2517 grp = rcu_dereference(tsk->numa_group); in task_numa_group()
2529 if (my_grp->nr_tasks > grp->nr_tasks) in task_numa_group()
2533 * Tie-break on the grp address. in task_numa_group()
2535 if (my_grp->nr_tasks == grp->nr_tasks && my_grp > grp) in task_numa_group()
2539 if (tsk->mm == current->mm) in task_numa_group()
2558 double_lock_irq(&my_grp->lock, &grp->lock); in task_numa_group()
2561 my_grp->faults[i] -= p->numa_faults[i]; in task_numa_group()
2562 grp->faults[i] += p->numa_faults[i]; in task_numa_group()
2564 my_grp->total_faults -= p->total_numa_faults; in task_numa_group()
2565 grp->total_faults += p->total_numa_faults; in task_numa_group()
2567 my_grp->nr_tasks--; in task_numa_group()
2568 grp->nr_tasks++; in task_numa_group()
2570 spin_unlock(&my_grp->lock); in task_numa_group()
2571 spin_unlock_irq(&grp->lock); in task_numa_group()
2573 rcu_assign_pointer(p->numa_group, grp); in task_numa_group()
2588 * reset the data back to default state without freeing ->numa_faults.
2593 struct numa_group *grp = rcu_dereference_raw(p->numa_group); in task_numa_free()
2594 unsigned long *numa_faults = p->numa_faults; in task_numa_free()
2602 spin_lock_irqsave(&grp->lock, flags); in task_numa_free()
2604 grp->faults[i] -= p->numa_faults[i]; in task_numa_free()
2605 grp->total_faults -= p->total_numa_faults; in task_numa_free()
2607 grp->nr_tasks--; in task_numa_free()
2608 spin_unlock_irqrestore(&grp->lock, flags); in task_numa_free()
2609 RCU_INIT_POINTER(p->numa_group, NULL); in task_numa_free()
2614 p->numa_faults = NULL; in task_numa_free()
2617 p->total_numa_faults = 0; in task_numa_free()
2639 if (!p->mm) in task_numa_fault()
2642 /* Allocate buffer to track faults on a per-node basis */ in task_numa_fault()
2643 if (unlikely(!p->numa_faults)) { in task_numa_fault()
2644 int size = sizeof(*p->numa_faults) * in task_numa_fault()
2647 p->numa_faults = kzalloc(size, GFP_KERNEL|__GFP_NOWARN); in task_numa_fault()
2648 if (!p->numa_faults) in task_numa_fault()
2651 p->total_numa_faults = 0; in task_numa_fault()
2652 memset(p->numa_faults_locality, 0, sizeof(p->numa_faults_locality)); in task_numa_fault()
2659 if (unlikely(last_cpupid == (-1 & LAST_CPUPID_MASK))) { in task_numa_fault()
2674 if (!priv && !local && ng && ng->active_nodes > 1 && in task_numa_fault()
2683 if (time_after(jiffies, p->numa_migrate_retry)) { in task_numa_fault()
2689 p->numa_pages_migrated += pages; in task_numa_fault()
2691 p->numa_faults_locality[2] += pages; in task_numa_fault()
2693 p->numa_faults[task_faults_idx(NUMA_MEMBUF, mem_node, priv)] += pages; in task_numa_fault()
2694 p->numa_faults[task_faults_idx(NUMA_CPUBUF, cpu_node, priv)] += pages; in task_numa_fault()
2695 p->numa_faults_locality[local] += pages; in task_numa_fault()
2702 * p->mm->numa_scan_seq is written to without exclusive access in reset_ptenuma_scan()
2708 WRITE_ONCE(p->mm->numa_scan_seq, READ_ONCE(p->mm->numa_scan_seq) + 1); in reset_ptenuma_scan()
2709 p->mm->numa_scan_offset = 0; in reset_ptenuma_scan()
2720 struct mm_struct *mm = p->mm; in task_numa_work()
2721 u64 runtime = p->se.sum_exec_runtime; in task_numa_work()
2729 work->next = work; in task_numa_work()
2733 * NOTE: make sure not to dereference p->mm before this check, in task_numa_work()
2735 * without p->mm even though we still had it when we enqueued this in task_numa_work()
2738 if (p->flags & PF_EXITING) in task_numa_work()
2741 if (!mm->numa_next_scan) { in task_numa_work()
2742 mm->numa_next_scan = now + in task_numa_work()
2749 migrate = mm->numa_next_scan; in task_numa_work()
2753 if (p->numa_scan_period == 0) { in task_numa_work()
2754 p->numa_scan_period_max = task_scan_max(p); in task_numa_work()
2755 p->numa_scan_period = task_scan_start(p); in task_numa_work()
2758 next_scan = now + msecs_to_jiffies(p->numa_scan_period); in task_numa_work()
2759 if (cmpxchg(&mm->numa_next_scan, migrate, next_scan) != migrate) in task_numa_work()
2766 p->node_stamp += 2 * TICK_NSEC; in task_numa_work()
2768 start = mm->numa_scan_offset; in task_numa_work()
2770 pages <<= 20 - PAGE_SHIFT; /* MB in pages */ in task_numa_work()
2782 vma = mm->mmap; in task_numa_work()
2784 for (; vma; vma = vma->vm_next) { in task_numa_work()
2786 is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_MIXEDMAP)) { in task_numa_work()
2793 * hinting faults in read-only file-backed mappings or the vdso in task_numa_work()
2796 if (!vma->vm_mm || in task_numa_work()
2797 (vma->vm_file && (vma->vm_flags & (VM_READ|VM_WRITE)) == (VM_READ))) in task_numa_work()
2808 start = max(start, vma->vm_start); in task_numa_work()
2810 end = min(end, vma->vm_end); in task_numa_work()
2816 * is not already pte-numa. If the VMA contains in task_numa_work()
2822 pages -= (end - start) >> PAGE_SHIFT; in task_numa_work()
2823 virtpages -= (end - start) >> PAGE_SHIFT; in task_numa_work()
2830 } while (end != vma->vm_end); in task_numa_work()
2841 mm->numa_scan_offset = start; in task_numa_work()
2852 if (unlikely(p->se.sum_exec_runtime != runtime)) { in task_numa_work()
2853 u64 diff = p->se.sum_exec_runtime - runtime; in task_numa_work()
2854 p->node_stamp += 32 * diff; in task_numa_work()
2861 struct mm_struct *mm = p->mm; in init_numa_balancing()
2864 mm_users = atomic_read(&mm->mm_users); in init_numa_balancing()
2866 mm->numa_next_scan = jiffies + msecs_to_jiffies(sysctl_numa_balancing_scan_delay); in init_numa_balancing()
2867 mm->numa_scan_seq = 0; in init_numa_balancing()
2870 p->node_stamp = 0; in init_numa_balancing()
2871 p->numa_scan_seq = mm ? mm->numa_scan_seq : 0; in init_numa_balancing()
2872 p->numa_scan_period = sysctl_numa_balancing_scan_delay; in init_numa_balancing()
2874 p->numa_work.next = &p->numa_work; in init_numa_balancing()
2875 p->numa_faults = NULL; in init_numa_balancing()
2876 RCU_INIT_POINTER(p->numa_group, NULL); in init_numa_balancing()
2877 p->last_task_numa_placement = 0; in init_numa_balancing()
2878 p->last_sum_exec_runtime = 0; in init_numa_balancing()
2880 init_task_work(&p->numa_work, task_numa_work); in init_numa_balancing()
2884 p->numa_preferred_nid = NUMA_NO_NODE; in init_numa_balancing()
2896 current->numa_scan_period * mm_users * NSEC_PER_MSEC); in init_numa_balancing()
2898 p->node_stamp = delay; in init_numa_balancing()
2907 struct callback_head *work = &curr->numa_work; in task_tick_numa()
2913 if ((curr->flags & (PF_EXITING | PF_KTHREAD)) || work->next != work) in task_tick_numa()
2922 now = curr->se.sum_exec_runtime; in task_tick_numa()
2923 period = (u64)curr->numa_scan_period * NSEC_PER_MSEC; in task_tick_numa()
2925 if (now > curr->node_stamp + period) { in task_tick_numa()
2926 if (!curr->node_stamp) in task_tick_numa()
2927 curr->numa_scan_period = task_scan_start(curr); in task_tick_numa()
2928 curr->node_stamp += period; in task_tick_numa()
2930 if (!time_before(jiffies, curr->mm->numa_next_scan)) in task_tick_numa()
2943 if (!p->mm || !p->numa_faults || (p->flags & PF_EXITING)) in update_scan_period()
2952 * is pulled cross-node due to wakeups or load balancing. in update_scan_period()
2954 if (p->numa_scan_seq) { in update_scan_period()
2960 if (dst_nid == p->numa_preferred_nid || in update_scan_period()
2961 (p->numa_preferred_nid != NUMA_NO_NODE && in update_scan_period()
2962 src_nid != p->numa_preferred_nid)) in update_scan_period()
2966 p->numa_scan_period = task_scan_start(p); in update_scan_period()
2991 update_load_add(&cfs_rq->load, se->load.weight); in account_entity_enqueue()
2997 list_add(&se->group_node, &rq->cfs_tasks); in account_entity_enqueue()
3000 cfs_rq->nr_running++; in account_entity_enqueue()
3006 update_load_sub(&cfs_rq->load, se->load.weight); in account_entity_dequeue()
3010 list_del_init(&se->group_node); in account_entity_dequeue()
3013 cfs_rq->nr_running--; in account_entity_dequeue()
3019 * Explicitly do a load-store to ensure the intermediate value never hits
3039 * Explicitly do a load-store to ensure the intermediate value never hits
3047 res = var - val; \
3056 * A variant of sub_positive(), which does not use explicit load-store
3061 *ptr -= min_t(typeof(*ptr), *ptr, _val); \
3068 cfs_rq->avg.load_avg += se->avg.load_avg; in enqueue_load_avg()
3069 cfs_rq->avg.load_sum += se_weight(se) * se->avg.load_sum; in enqueue_load_avg()
3075 sub_positive(&cfs_rq->avg.load_avg, se->avg.load_avg); in dequeue_load_avg()
3076 sub_positive(&cfs_rq->avg.load_sum, se_weight(se) * se->avg.load_sum); in dequeue_load_avg()
3088 if (se->on_rq) { in reweight_entity()
3090 if (cfs_rq->curr == se) in reweight_entity()
3092 update_load_sub(&cfs_rq->load, se->load.weight); in reweight_entity()
3096 update_load_set(&se->load, weight); in reweight_entity()
3100 u32 divider = get_pelt_divider(&se->avg); in reweight_entity()
3102 se->avg.load_avg = div_u64(se_weight(se) * se->avg.load_sum, divider); in reweight_entity()
3107 if (se->on_rq) in reweight_entity()
3108 update_load_add(&cfs_rq->load, se->load.weight); in reweight_entity()
3114 struct sched_entity *se = &p->se; in reweight_task()
3116 struct load_weight *load = &se->load; in reweight_task()
3120 load->inv_weight = sched_prio_to_wmult[prio]; in reweight_task()
3132 * tg->weight * grq->load.weight
3133 * ge->load.weight = ----------------------------- (1)
3134 * \Sum grq->load.weight
3142 * grq->load.weight -> grq->avg.load_avg (2)
3146 * tg->weight * grq->avg.load_avg
3147 * ge->load.weight = ------------------------------ (3)
3148 * tg->load_avg
3150 * Where: tg->load_avg ~= \Sum grq->avg.load_avg
3154 * The problem with it is that because the average is slow -- it was designed
3155 * to be exactly that of course -- this leads to transients in boundary
3157 * one task. It takes time for our CPU's grq->avg.load_avg to build up,
3162 * tg->weight * grq->load.weight
3163 * ge->load.weight = ----------------------------- = tg->weight (4)
3164 * grp->load.weight
3171 * ge->load.weight =
3173 * tg->weight * grq->load.weight
3174 * --------------------------------------------------- (5)
3175 * tg->load_avg - grq->avg.load_avg + grq->load.weight
3177 * But because grq->load.weight can drop to 0, resulting in a divide by zero,
3178 * we need to use grq->avg.load_avg as its lower bound, which then gives:
3181 * tg->weight * grq->load.weight
3182 * ge->load.weight = ----------------------------- (6)
3187 * tg_load_avg' = tg->load_avg - grq->avg.load_avg +
3188 * max(grq->load.weight, grq->avg.load_avg)
3192 * overestimates the ge->load.weight and therefore:
3194 * \Sum ge->load.weight >= tg->weight
3201 struct task_group *tg = cfs_rq->tg; in calc_group_shares()
3203 tg_shares = READ_ONCE(tg->shares); in calc_group_shares()
3205 load = max(scale_load_down(cfs_rq->load.weight), cfs_rq->avg.load_avg); in calc_group_shares()
3207 tg_weight = atomic_long_read(&tg->load_avg); in calc_group_shares()
3210 tg_weight -= cfs_rq->tg_load_avg_contrib; in calc_group_shares()
3218 * MIN_SHARES has to be unscaled here to support per-CPU partitioning in calc_group_shares()
3219 * of a group with small tg->shares value. It is a floor value which is in calc_group_shares()
3223 * E.g. on 64-bit for a group with tg->shares of scale_load(15)=15*1024 in calc_group_shares()
3224 * on an 8-core system with 8 tasks each runnable on one CPU shares has in calc_group_shares()
3251 shares = READ_ONCE(gcfs_rq->tg->shares); in update_cfs_group()
3253 if (likely(se->load.weight == shares)) in update_cfs_group()
3272 if (&rq->cfs == cfs_rq) { in cfs_rq_util_change()
3282 * As is, the util number is not freq-invariant (we'd have to in cfs_rq_util_change()
3294 * update_tg_load_avg - update the tg's load avg
3295 * @cfs_rq: the cfs_rq whose avg changed
3297 * This function 'ensures': tg->load_avg := \Sum tg->cfs_rq[]->avg.load.
3298 * However, because tg->load_avg is a global value there are performance
3309 long delta = cfs_rq->avg.load_avg - cfs_rq->tg_load_avg_contrib; in update_tg_load_avg()
3314 if (cfs_rq->tg == &root_task_group) in update_tg_load_avg()
3317 if (abs(delta) > cfs_rq->tg_load_avg_contrib / 64) { in update_tg_load_avg()
3318 atomic_long_add(delta, &cfs_rq->tg->load_avg); in update_tg_load_avg()
3319 cfs_rq->tg_load_avg_contrib = cfs_rq->avg.load_avg; in update_tg_load_avg()
3325 * caller only guarantees p->pi_lock is held; no other assumptions,
3326 * including the state of rq->lock, should be made.
3340 * getting what current time is, so simply throw away the out-of-date in set_task_rq_fair()
3344 if (!(se->avg.last_update_time && prev)) in set_task_rq_fair()
3353 p_last_update_time_copy = prev->load_last_update_time_copy; in set_task_rq_fair()
3354 n_last_update_time_copy = next->load_last_update_time_copy; in set_task_rq_fair()
3358 p_last_update_time = prev->avg.last_update_time; in set_task_rq_fair()
3359 n_last_update_time = next->avg.last_update_time; in set_task_rq_fair()
3365 p_last_update_time = prev->avg.last_update_time; in set_task_rq_fair()
3366 n_last_update_time = next->avg.last_update_time; in set_task_rq_fair()
3369 se->avg.last_update_time = n_last_update_time; in set_task_rq_fair()
3378 * ge->avg == grq->avg (1)
3389 * ge->avg.load_avg = ge->load.weight * ge->avg.runnable_avg (2)
3394 * grq->avg.load_avg = grq->load.weight * grq->avg.runnable_avg (3)
3398 * ge->avg.runnable_avg == grq->avg.runnable_avg
3402 * ge->load.weight * grq->avg.load_avg
3403 * ge->avg.load_avg = ----------------------------------- (4)
3404 * grq->load.weight
3417 * Another reason this doesn't work is that runnable isn't a 0-sum entity.
3428 * ge->avg.running_sum <= ge->avg.runnable_sum <= LOAD_AVG_MAX
3435 * grq->avg.runnable_sum = grq->avg.load_sum / grq->load.weight
3444 long delta = gcfs_rq->avg.util_avg - se->avg.util_avg; in update_tg_cfs_util()
3452 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in update_tg_cfs_util()
3455 divider = get_pelt_divider(&cfs_rq->avg); in update_tg_cfs_util()
3458 se->avg.util_avg = gcfs_rq->avg.util_avg; in update_tg_cfs_util()
3459 se->avg.util_sum = se->avg.util_avg * divider; in update_tg_cfs_util()
3462 add_positive(&cfs_rq->avg.util_avg, delta); in update_tg_cfs_util()
3463 cfs_rq->avg.util_sum = cfs_rq->avg.util_avg * divider; in update_tg_cfs_util()
3469 long delta = gcfs_rq->avg.runnable_avg - se->avg.runnable_avg; in update_tg_cfs_runnable()
3477 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in update_tg_cfs_runnable()
3480 divider = get_pelt_divider(&cfs_rq->avg); in update_tg_cfs_runnable()
3483 se->avg.runnable_avg = gcfs_rq->avg.runnable_avg; in update_tg_cfs_runnable()
3484 se->avg.runnable_sum = se->avg.runnable_avg * divider; in update_tg_cfs_runnable()
3487 add_positive(&cfs_rq->avg.runnable_avg, delta); in update_tg_cfs_runnable()
3488 cfs_rq->avg.runnable_sum = cfs_rq->avg.runnable_avg * divider; in update_tg_cfs_runnable()
3494 long delta_avg, running_sum, runnable_sum = gcfs_rq->prop_runnable_sum; in update_tg_cfs_load()
3503 gcfs_rq->prop_runnable_sum = 0; in update_tg_cfs_load()
3506 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in update_tg_cfs_load()
3509 divider = get_pelt_divider(&cfs_rq->avg); in update_tg_cfs_load()
3516 runnable_sum += se->avg.load_sum; in update_tg_cfs_load()
3523 if (scale_load_down(gcfs_rq->load.weight)) { in update_tg_cfs_load()
3524 load_sum = div_s64(gcfs_rq->avg.load_sum, in update_tg_cfs_load()
3525 scale_load_down(gcfs_rq->load.weight)); in update_tg_cfs_load()
3529 runnable_sum = min(se->avg.load_sum, load_sum); in update_tg_cfs_load()
3538 running_sum = se->avg.util_sum >> SCHED_CAPACITY_SHIFT; in update_tg_cfs_load()
3544 delta_sum = load_sum - (s64)se_weight(se) * se->avg.load_sum; in update_tg_cfs_load()
3545 delta_avg = load_avg - se->avg.load_avg; in update_tg_cfs_load()
3547 se->avg.load_sum = runnable_sum; in update_tg_cfs_load()
3548 se->avg.load_avg = load_avg; in update_tg_cfs_load()
3549 add_positive(&cfs_rq->avg.load_avg, delta_avg); in update_tg_cfs_load()
3550 add_positive(&cfs_rq->avg.load_sum, delta_sum); in update_tg_cfs_load()
3555 cfs_rq->propagate = 1; in add_tg_cfs_propagate()
3556 cfs_rq->prop_runnable_sum += runnable_sum; in add_tg_cfs_propagate()
3568 if (!gcfs_rq->propagate) in propagate_entity_load_avg()
3571 gcfs_rq->propagate = 0; in propagate_entity_load_avg()
3575 add_tg_cfs_propagate(cfs_rq, gcfs_rq->prop_runnable_sum); in propagate_entity_load_avg()
3599 if (se->avg.load_avg || se->avg.util_avg) in skip_blocked_update()
3606 if (gcfs_rq->propagate) in skip_blocked_update()
3631 * update_cfs_rq_load_avg - update the cfs_rq's load/util averages
3635 * The cfs_rq avg is the direct sum of all its entities (blocked and runnable)
3636 * avg. The immediate corollary is that all (fair) tasks must be attached, see
3639 * cfs_rq->avg is used for task_h_load() and update_cfs_share() for example.
3643 * Since both these conditions indicate a changed cfs_rq->avg.load we should
3650 struct sched_avg *sa = &cfs_rq->avg; in update_cfs_rq_load_avg()
3653 if (cfs_rq->removed.nr) { in update_cfs_rq_load_avg()
3655 u32 divider = get_pelt_divider(&cfs_rq->avg); in update_cfs_rq_load_avg()
3657 raw_spin_lock(&cfs_rq->removed.lock); in update_cfs_rq_load_avg()
3658 swap(cfs_rq->removed.util_avg, removed_util); in update_cfs_rq_load_avg()
3659 swap(cfs_rq->removed.load_avg, removed_load); in update_cfs_rq_load_avg()
3660 swap(cfs_rq->removed.runnable_avg, removed_runnable); in update_cfs_rq_load_avg()
3661 cfs_rq->removed.nr = 0; in update_cfs_rq_load_avg()
3662 raw_spin_unlock(&cfs_rq->removed.lock); in update_cfs_rq_load_avg()
3665 sub_positive(&sa->load_avg, r); in update_cfs_rq_load_avg()
3666 sub_positive(&sa->load_sum, r * divider); in update_cfs_rq_load_avg()
3669 sub_positive(&sa->util_avg, r); in update_cfs_rq_load_avg()
3670 sub_positive(&sa->util_sum, r * divider); in update_cfs_rq_load_avg()
3673 sub_positive(&sa->runnable_avg, r); in update_cfs_rq_load_avg()
3674 sub_positive(&sa->runnable_sum, r * divider); in update_cfs_rq_load_avg()
3681 -(long)(removed_runnable * divider) >> SCHED_CAPACITY_SHIFT); in update_cfs_rq_load_avg()
3690 cfs_rq->load_last_update_time_copy = sa->last_update_time; in update_cfs_rq_load_avg()
3697 * attach_entity_load_avg - attach this entity to its cfs_rq load avg
3702 * cfs_rq->avg.last_update_time being current.
3707 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in attach_entity_load_avg()
3710 u32 divider = get_pelt_divider(&cfs_rq->avg); in attach_entity_load_avg()
3719 se->avg.last_update_time = cfs_rq->avg.last_update_time; in attach_entity_load_avg()
3720 se->avg.period_contrib = cfs_rq->avg.period_contrib; in attach_entity_load_avg()
3728 se->avg.util_sum = se->avg.util_avg * divider; in attach_entity_load_avg()
3730 se->avg.runnable_sum = se->avg.runnable_avg * divider; in attach_entity_load_avg()
3732 se->avg.load_sum = divider; in attach_entity_load_avg()
3734 se->avg.load_sum = in attach_entity_load_avg()
3735 div_u64(se->avg.load_avg * se->avg.load_sum, se_weight(se)); in attach_entity_load_avg()
3739 cfs_rq->avg.util_avg += se->avg.util_avg; in attach_entity_load_avg()
3740 cfs_rq->avg.util_sum += se->avg.util_sum; in attach_entity_load_avg()
3741 cfs_rq->avg.runnable_avg += se->avg.runnable_avg; in attach_entity_load_avg()
3742 cfs_rq->avg.runnable_sum += se->avg.runnable_sum; in attach_entity_load_avg()
3744 add_tg_cfs_propagate(cfs_rq, se->avg.load_sum); in attach_entity_load_avg()
3752 * detach_entity_load_avg - detach this entity from its cfs_rq load avg
3757 * cfs_rq->avg.last_update_time being current.
3762 sub_positive(&cfs_rq->avg.util_avg, se->avg.util_avg); in detach_entity_load_avg()
3763 sub_positive(&cfs_rq->avg.util_sum, se->avg.util_sum); in detach_entity_load_avg()
3764 sub_positive(&cfs_rq->avg.runnable_avg, se->avg.runnable_avg); in detach_entity_load_avg()
3765 sub_positive(&cfs_rq->avg.runnable_sum, se->avg.runnable_sum); in detach_entity_load_avg()
3767 add_tg_cfs_propagate(cfs_rq, -se->avg.load_sum); in detach_entity_load_avg()
3791 if (se->avg.last_update_time && !(flags & SKIP_AGE_LOAD)) in update_load_avg()
3797 if (!se->avg.last_update_time && (flags & DO_ATTACH)) { in update_load_avg()
3824 last_update_time_copy = cfs_rq->load_last_update_time_copy; in cfs_rq_last_update_time()
3826 last_update_time = cfs_rq->avg.last_update_time; in cfs_rq_last_update_time()
3834 return cfs_rq->avg.last_update_time; in cfs_rq_last_update_time()
3839 * Synchronize entity load avg of dequeued entity without locking
3861 * tasks cannot exit without having gone through wake_up_new_task() -> in remove_entity_load_avg()
3868 raw_spin_lock_irqsave(&cfs_rq->removed.lock, flags); in remove_entity_load_avg()
3869 ++cfs_rq->removed.nr; in remove_entity_load_avg()
3870 cfs_rq->removed.util_avg += se->avg.util_avg; in remove_entity_load_avg()
3871 cfs_rq->removed.load_avg += se->avg.load_avg; in remove_entity_load_avg()
3872 cfs_rq->removed.runnable_avg += se->avg.runnable_avg; in remove_entity_load_avg()
3873 raw_spin_unlock_irqrestore(&cfs_rq->removed.lock, flags); in remove_entity_load_avg()
3878 return cfs_rq->avg.runnable_avg; in cfs_rq_runnable_avg()
3883 return cfs_rq->avg.load_avg; in cfs_rq_load_avg()
3890 return READ_ONCE(p->se.avg.util_avg); in task_util()
3895 struct util_est ue = READ_ONCE(p->se.avg.util_est); in _task_util_est()
3928 enqueued = cfs_rq->avg.util_est.enqueued; in util_est_enqueue()
3930 WRITE_ONCE(cfs_rq->avg.util_est.enqueued, enqueued); in util_est_enqueue()
3939 * abs(x) < y := (unsigned)(x + y - 1) < (2 * y - 1)
3945 return ((unsigned int)(value + margin - 1) < (2 * margin - 1)); in within_margin()
3959 ue.enqueued = cfs_rq->avg.util_est.enqueued; in util_est_dequeue()
3960 ue.enqueued -= min_t(unsigned int, ue.enqueued, _task_util_est(p)); in util_est_dequeue()
3961 WRITE_ONCE(cfs_rq->avg.util_est.enqueued, ue.enqueued); in util_est_dequeue()
3976 ue = p->se.avg.util_est; in util_est_dequeue()
3996 last_ewma_diff = ue.enqueued - ue.ewma; in util_est_dequeue()
4016 * ewma(t) = w * task_util(p) + (1-w) * ewma(t-1) in util_est_dequeue()
4017 * = w * task_util(p) + ewma(t-1) - w * ewma(t-1) in util_est_dequeue()
4018 * = w * (task_util(p) - ewma(t-1)) + ewma(t-1) in util_est_dequeue()
4019 * = w * ( last_ewma_diff ) + ewma(t-1) in util_est_dequeue()
4020 * = w * (last_ewma_diff + ewma(t-1) / w) in util_est_dequeue()
4022 * Where 'w' is the weight of new samples, which is configured to be in util_est_dequeue()
4029 WRITE_ONCE(p->se.avg.util_est, ue); in util_est_dequeue()
4031 trace_sched_util_est_se_tp(&p->se); in util_est_dequeue()
4045 rq->misfit_task_load = 0; in update_misfit_status()
4050 rq->misfit_task_load = 0; in update_misfit_status()
4058 rq->misfit_task_load = max_t(unsigned long, task_h_load(p), 1); in update_misfit_status()
4097 s64 d = se->vruntime - cfs_rq->min_vruntime; in check_spread()
4100 d = -d; in check_spread()
4103 schedstat_inc(cfs_rq->nr_spread_over); in check_spread()
4110 u64 vruntime = cfs_rq->min_vruntime; in place_entity()
4132 vruntime -= thresh; in place_entity()
4136 se->vruntime = max_vruntime(se->vruntime, vruntime); in place_entity()
4169 * vruntime -= min_vruntime
4177 * min_vruntime are up-to-date.
4181 * ->migrate_task_rq_fair() (p->state == TASK_WAKING)
4182 * vruntime -= min_vruntime
4189 * this way we don't have the most up-to-date min_vruntime on the originating
4190 * CPU and an up-to-date min_vruntime on the destination CPU.
4197 bool curr = cfs_rq->curr == se; in enqueue_entity()
4204 se->vruntime += cfs_rq->min_vruntime; in enqueue_entity()
4215 se->vruntime += cfs_rq->min_vruntime; in enqueue_entity()
4219 * - Update loads to have both entity and cfs_rq synced with now. in enqueue_entity()
4220 * - Add its load to cfs_rq->runnable_avg in enqueue_entity()
4221 * - For group_entity, update its weight to reflect the new share of in enqueue_entity()
4223 * - Add its new weight to cfs_rq->load.weight in enqueue_entity()
4238 se->on_rq = 1; in enqueue_entity()
4242 * because of a parent been throttled but cfs->nr_running > 1. Try to in enqueue_entity()
4245 if (cfs_rq->nr_running == 1 || cfs_bandwidth_used()) in enqueue_entity()
4248 if (cfs_rq->nr_running == 1) in enqueue_entity()
4256 if (cfs_rq->last != se) in __clear_buddies_last()
4259 cfs_rq->last = NULL; in __clear_buddies_last()
4267 if (cfs_rq->next != se) in __clear_buddies_next()
4270 cfs_rq->next = NULL; in __clear_buddies_next()
4278 if (cfs_rq->skip != se) in __clear_buddies_skip()
4281 cfs_rq->skip = NULL; in __clear_buddies_skip()
4287 if (cfs_rq->last == se) in clear_buddies()
4290 if (cfs_rq->next == se) in clear_buddies()
4293 if (cfs_rq->skip == se) in clear_buddies()
4303 * Update run-time statistics of the 'current'. in dequeue_entity()
4309 * - Update loads to have both entity and cfs_rq synced with now. in dequeue_entity()
4310 * - Subtract its load from the cfs_rq->runnable_avg. in dequeue_entity()
4311 * - Subtract its previous weight from cfs_rq->load.weight. in dequeue_entity()
4312 * - For group entity, update its weight to reflect the new share in dequeue_entity()
4322 if (se != cfs_rq->curr) in dequeue_entity()
4324 se->on_rq = 0; in dequeue_entity()
4334 se->vruntime -= cfs_rq->min_vruntime; in dequeue_entity()
4345 * further than we started -- ie. we'll be penalized. in dequeue_entity()
4362 delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime; in check_preempt_tick()
4367 * re-elected due to buddy favours. in check_preempt_tick()
4382 delta = curr->vruntime - se->vruntime; in check_preempt_tick()
4395 if (se->on_rq) { in set_next_entity()
4407 cfs_rq->curr = se; in set_next_entity()
4412 * when there are only lesser-weight tasks around): in set_next_entity()
4415 rq_of(cfs_rq)->cfs.load.weight >= 2*se->load.weight) { in set_next_entity()
4416 schedstat_set(se->statistics.slice_max, in set_next_entity()
4417 max((u64)schedstat_val(se->statistics.slice_max), in set_next_entity()
4418 se->sum_exec_runtime - se->prev_sum_exec_runtime)); in set_next_entity()
4421 se->prev_sum_exec_runtime = se->sum_exec_runtime; in set_next_entity()
4453 if (cfs_rq->skip == se) { in pick_next_entity()
4468 if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) { in pick_next_entity()
4472 se = cfs_rq->next; in pick_next_entity()
4473 } else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) { in pick_next_entity()
4477 se = cfs_rq->last; in pick_next_entity()
4493 if (prev->on_rq) in put_prev_entity()
4501 if (prev->on_rq) { in put_prev_entity()
4508 cfs_rq->curr = NULL; in put_prev_entity()
4515 * Update run-time statistics of the 'current'. in entity_tick()
4538 hrtimer_active(&rq_of(cfs_rq)->hrtick_timer)) in entity_tick()
4542 if (cfs_rq->nr_running > 1) in entity_tick()
4596 * directly instead of rq->clock to avoid adding additional synchronization
4597 * around rq->lock.
4599 * requires cfs_b->lock
4603 if (cfs_b->quota != RUNTIME_INF) in __refill_cfs_bandwidth_runtime()
4604 cfs_b->runtime = cfs_b->quota; in __refill_cfs_bandwidth_runtime()
4609 return &tg->cfs_bandwidth; in tg_cfs_bandwidth()
4618 lockdep_assert_held(&cfs_b->lock); in __assign_cfs_rq_runtime()
4621 min_amount = target_runtime - cfs_rq->runtime_remaining; in __assign_cfs_rq_runtime()
4623 if (cfs_b->quota == RUNTIME_INF) in __assign_cfs_rq_runtime()
4628 if (cfs_b->runtime > 0) { in __assign_cfs_rq_runtime()
4629 amount = min(cfs_b->runtime, min_amount); in __assign_cfs_rq_runtime()
4630 cfs_b->runtime -= amount; in __assign_cfs_rq_runtime()
4631 cfs_b->idle = 0; in __assign_cfs_rq_runtime()
4635 cfs_rq->runtime_remaining += amount; in __assign_cfs_rq_runtime()
4637 return cfs_rq->runtime_remaining > 0; in __assign_cfs_rq_runtime()
4643 struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg); in assign_cfs_rq_runtime()
4646 raw_spin_lock(&cfs_b->lock); in assign_cfs_rq_runtime()
4648 raw_spin_unlock(&cfs_b->lock); in assign_cfs_rq_runtime()
4656 cfs_rq->runtime_remaining -= delta_exec; in __account_cfs_rq_runtime()
4658 if (likely(cfs_rq->runtime_remaining > 0)) in __account_cfs_rq_runtime()
4661 if (cfs_rq->throttled) in __account_cfs_rq_runtime()
4667 if (!assign_cfs_rq_runtime(cfs_rq) && likely(cfs_rq->curr)) in __account_cfs_rq_runtime()
4674 if (!cfs_bandwidth_used() || !cfs_rq->runtime_enabled) in account_cfs_rq_runtime()
4682 return cfs_bandwidth_used() && cfs_rq->throttled; in cfs_rq_throttled()
4688 return cfs_bandwidth_used() && cfs_rq->throttle_count; in throttled_hierarchy()
4694 * load-balance operations.
4701 src_cfs_rq = tg->cfs_rq[src_cpu]; in throttled_lb_pair()
4702 dest_cfs_rq = tg->cfs_rq[dest_cpu]; in throttled_lb_pair()
4711 struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; in tg_unthrottle_up()
4713 cfs_rq->throttle_count--; in tg_unthrottle_up()
4714 if (!cfs_rq->throttle_count) { in tg_unthrottle_up()
4715 cfs_rq->throttled_clock_task_time += rq_clock_task(rq) - in tg_unthrottle_up()
4716 cfs_rq->throttled_clock_task; in tg_unthrottle_up()
4719 if (cfs_rq->nr_running >= 1) in tg_unthrottle_up()
4729 struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; in tg_throttle_down()
4732 if (!cfs_rq->throttle_count) { in tg_throttle_down()
4733 cfs_rq->throttled_clock_task = rq_clock_task(rq); in tg_throttle_down()
4736 cfs_rq->throttle_count++; in tg_throttle_down()
4744 struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg); in throttle_cfs_rq()
4748 raw_spin_lock(&cfs_b->lock); in throttle_cfs_rq()
4761 list_add_tail_rcu(&cfs_rq->throttled_list, in throttle_cfs_rq()
4762 &cfs_b->throttled_cfs_rq); in throttle_cfs_rq()
4764 raw_spin_unlock(&cfs_b->lock); in throttle_cfs_rq()
4769 se = cfs_rq->tg->se[cpu_of(rq_of(cfs_rq))]; in throttle_cfs_rq()
4773 walk_tg_tree_from(cfs_rq->tg, tg_throttle_down, tg_nop, (void *)rq); in throttle_cfs_rq()
4776 task_delta = cfs_rq->h_nr_running; in throttle_cfs_rq()
4777 idle_task_delta = cfs_rq->idle_h_nr_running; in throttle_cfs_rq()
4780 /* throttled entity or throttle-on-deactivate */ in throttle_cfs_rq()
4781 if (!se->on_rq) in throttle_cfs_rq()
4791 qcfs_rq->h_nr_running -= task_delta; in throttle_cfs_rq()
4792 qcfs_rq->idle_h_nr_running -= idle_task_delta; in throttle_cfs_rq()
4794 if (qcfs_rq->load.weight) in throttle_cfs_rq()
4803 * throttled-list. rq->lock protects completion. in throttle_cfs_rq()
4805 cfs_rq->throttled = 1; in throttle_cfs_rq()
4806 cfs_rq->throttled_clock = rq_clock(rq); in throttle_cfs_rq()
4813 struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg); in unthrottle_cfs_rq()
4817 se = cfs_rq->tg->se[cpu_of(rq)]; in unthrottle_cfs_rq()
4819 cfs_rq->throttled = 0; in unthrottle_cfs_rq()
4823 raw_spin_lock(&cfs_b->lock); in unthrottle_cfs_rq()
4824 cfs_b->throttled_time += rq_clock(rq) - cfs_rq->throttled_clock; in unthrottle_cfs_rq()
4825 list_del_rcu(&cfs_rq->throttled_list); in unthrottle_cfs_rq()
4826 raw_spin_unlock(&cfs_b->lock); in unthrottle_cfs_rq()
4829 walk_tg_tree_from(cfs_rq->tg, tg_nop, tg_unthrottle_up, (void *)rq); in unthrottle_cfs_rq()
4831 if (!cfs_rq->load.weight) in unthrottle_cfs_rq()
4834 task_delta = cfs_rq->h_nr_running; in unthrottle_cfs_rq()
4835 idle_task_delta = cfs_rq->idle_h_nr_running; in unthrottle_cfs_rq()
4837 if (se->on_rq) in unthrottle_cfs_rq()
4842 cfs_rq->h_nr_running += task_delta; in unthrottle_cfs_rq()
4843 cfs_rq->idle_h_nr_running += idle_task_delta; in unthrottle_cfs_rq()
4856 cfs_rq->h_nr_running += task_delta; in unthrottle_cfs_rq()
4857 cfs_rq->idle_h_nr_running += idle_task_delta; in unthrottle_cfs_rq()
4891 if (rq->curr == rq->idle && rq->cfs.nr_running) in unthrottle_cfs_rq()
4901 list_for_each_entry_rcu(cfs_rq, &cfs_b->throttled_cfs_rq, in distribute_cfs_runtime()
4911 SCHED_WARN_ON(cfs_rq->runtime_remaining > 0); in distribute_cfs_runtime()
4913 raw_spin_lock(&cfs_b->lock); in distribute_cfs_runtime()
4914 runtime = -cfs_rq->runtime_remaining + 1; in distribute_cfs_runtime()
4915 if (runtime > cfs_b->runtime) in distribute_cfs_runtime()
4916 runtime = cfs_b->runtime; in distribute_cfs_runtime()
4917 cfs_b->runtime -= runtime; in distribute_cfs_runtime()
4918 remaining = cfs_b->runtime; in distribute_cfs_runtime()
4919 raw_spin_unlock(&cfs_b->lock); in distribute_cfs_runtime()
4921 cfs_rq->runtime_remaining += runtime; in distribute_cfs_runtime()
4924 if (cfs_rq->runtime_remaining > 0) in distribute_cfs_runtime()
4939 * period the timer is deactivated until scheduling resumes; cfs_b->idle is
4947 if (cfs_b->quota == RUNTIME_INF) in do_sched_cfs_period_timer()
4950 throttled = !list_empty(&cfs_b->throttled_cfs_rq); in do_sched_cfs_period_timer()
4951 cfs_b->nr_periods += overrun; in do_sched_cfs_period_timer()
4957 if (cfs_b->idle && !throttled) in do_sched_cfs_period_timer()
4964 cfs_b->idle = 1; in do_sched_cfs_period_timer()
4969 cfs_b->nr_throttled += overrun; in do_sched_cfs_period_timer()
4972 * This check is repeated as we release cfs_b->lock while we unthrottle. in do_sched_cfs_period_timer()
4974 while (throttled && cfs_b->runtime > 0) { in do_sched_cfs_period_timer()
4975 raw_spin_unlock_irqrestore(&cfs_b->lock, flags); in do_sched_cfs_period_timer()
4976 /* we can't nest cfs_b->lock while distributing bandwidth */ in do_sched_cfs_period_timer()
4978 raw_spin_lock_irqsave(&cfs_b->lock, flags); in do_sched_cfs_period_timer()
4980 throttled = !list_empty(&cfs_b->throttled_cfs_rq); in do_sched_cfs_period_timer()
4989 cfs_b->idle = 0; in do_sched_cfs_period_timer()
5007 * Requires cfs_b->lock for hrtimer_expires_remaining to be safe against the
5013 struct hrtimer *refresh_timer = &cfs_b->period_timer; in runtime_refresh_within()
5016 /* if the call-back is running a quota refresh is already occurring */ in runtime_refresh_within()
5037 if (cfs_b->slack_started) in start_cfs_slack_bandwidth()
5039 cfs_b->slack_started = true; in start_cfs_slack_bandwidth()
5041 hrtimer_start(&cfs_b->slack_timer, in start_cfs_slack_bandwidth()
5049 struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg); in __return_cfs_rq_runtime()
5050 s64 slack_runtime = cfs_rq->runtime_remaining - min_cfs_rq_runtime; in __return_cfs_rq_runtime()
5055 raw_spin_lock(&cfs_b->lock); in __return_cfs_rq_runtime()
5056 if (cfs_b->quota != RUNTIME_INF) { in __return_cfs_rq_runtime()
5057 cfs_b->runtime += slack_runtime; in __return_cfs_rq_runtime()
5059 /* we are under rq->lock, defer unthrottling using a timer */ in __return_cfs_rq_runtime()
5060 if (cfs_b->runtime > sched_cfs_bandwidth_slice() && in __return_cfs_rq_runtime()
5061 !list_empty(&cfs_b->throttled_cfs_rq)) in __return_cfs_rq_runtime()
5064 raw_spin_unlock(&cfs_b->lock); in __return_cfs_rq_runtime()
5067 cfs_rq->runtime_remaining -= slack_runtime; in __return_cfs_rq_runtime()
5075 if (!cfs_rq->runtime_enabled || cfs_rq->nr_running) in return_cfs_rq_runtime()
5083 * it's necessary to juggle rq->locks to unthrottle their respective cfs_rqs.
5091 raw_spin_lock_irqsave(&cfs_b->lock, flags); in do_sched_cfs_slack_timer()
5092 cfs_b->slack_started = false; in do_sched_cfs_slack_timer()
5095 raw_spin_unlock_irqrestore(&cfs_b->lock, flags); in do_sched_cfs_slack_timer()
5099 if (cfs_b->quota != RUNTIME_INF && cfs_b->runtime > slice) in do_sched_cfs_slack_timer()
5100 runtime = cfs_b->runtime; in do_sched_cfs_slack_timer()
5102 raw_spin_unlock_irqrestore(&cfs_b->lock, flags); in do_sched_cfs_slack_timer()
5109 raw_spin_lock_irqsave(&cfs_b->lock, flags); in do_sched_cfs_slack_timer()
5110 raw_spin_unlock_irqrestore(&cfs_b->lock, flags); in do_sched_cfs_slack_timer()
5116 * runtime as update_curr() throttling can not not trigger until it's on-rq.
5123 /* an active group must be handled by the update_curr()->put() path */ in check_enqueue_throttle()
5124 if (!cfs_rq->runtime_enabled || cfs_rq->curr) in check_enqueue_throttle()
5133 if (cfs_rq->runtime_remaining <= 0) in check_enqueue_throttle()
5144 if (!tg->parent) in sync_throttle()
5147 cfs_rq = tg->cfs_rq[cpu]; in sync_throttle()
5148 pcfs_rq = tg->parent->cfs_rq[cpu]; in sync_throttle()
5150 cfs_rq->throttle_count = pcfs_rq->throttle_count; in sync_throttle()
5151 cfs_rq->throttled_clock_task = rq_clock_task(cpu_rq(cpu)); in sync_throttle()
5160 if (likely(!cfs_rq->runtime_enabled || cfs_rq->runtime_remaining > 0)) in check_cfs_rq_runtime()
5194 raw_spin_lock_irqsave(&cfs_b->lock, flags); in sched_cfs_period_timer()
5196 overrun = hrtimer_forward_now(timer, cfs_b->period); in sched_cfs_period_timer()
5203 u64 new, old = ktime_to_ns(cfs_b->period); in sched_cfs_period_timer()
5212 cfs_b->period = ns_to_ktime(new); in sched_cfs_period_timer()
5213 cfs_b->quota *= 2; in sched_cfs_period_timer()
5219 div_u64(cfs_b->quota, NSEC_PER_USEC)); in sched_cfs_period_timer()
5225 div_u64(cfs_b->quota, NSEC_PER_USEC)); in sched_cfs_period_timer()
5233 cfs_b->period_active = 0; in sched_cfs_period_timer()
5234 raw_spin_unlock_irqrestore(&cfs_b->lock, flags); in sched_cfs_period_timer()
5241 raw_spin_lock_init(&cfs_b->lock); in init_cfs_bandwidth()
5242 cfs_b->runtime = 0; in init_cfs_bandwidth()
5243 cfs_b->quota = RUNTIME_INF; in init_cfs_bandwidth()
5244 cfs_b->period = ns_to_ktime(default_cfs_period()); in init_cfs_bandwidth()
5246 INIT_LIST_HEAD(&cfs_b->throttled_cfs_rq); in init_cfs_bandwidth()
5247 hrtimer_init(&cfs_b->period_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED); in init_cfs_bandwidth()
5248 cfs_b->period_timer.function = sched_cfs_period_timer; in init_cfs_bandwidth()
5249 hrtimer_init(&cfs_b->slack_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in init_cfs_bandwidth()
5250 cfs_b->slack_timer.function = sched_cfs_slack_timer; in init_cfs_bandwidth()
5251 cfs_b->slack_started = false; in init_cfs_bandwidth()
5256 cfs_rq->runtime_enabled = 0; in init_cfs_rq_runtime()
5257 INIT_LIST_HEAD(&cfs_rq->throttled_list); in init_cfs_rq_runtime()
5262 lockdep_assert_held(&cfs_b->lock); in start_cfs_bandwidth()
5264 if (cfs_b->period_active) in start_cfs_bandwidth()
5267 cfs_b->period_active = 1; in start_cfs_bandwidth()
5268 hrtimer_forward_now(&cfs_b->period_timer, cfs_b->period); in start_cfs_bandwidth()
5269 hrtimer_start_expires(&cfs_b->period_timer, HRTIMER_MODE_ABS_PINNED); in start_cfs_bandwidth()
5275 if (!cfs_b->throttled_cfs_rq.next) in destroy_cfs_bandwidth()
5278 hrtimer_cancel(&cfs_b->period_timer); in destroy_cfs_bandwidth()
5279 hrtimer_cancel(&cfs_b->slack_timer); in destroy_cfs_bandwidth()
5294 lockdep_assert_held(&rq->lock); in update_runtime_enabled()
5298 struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth; in update_runtime_enabled()
5299 struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; in update_runtime_enabled()
5301 raw_spin_lock(&cfs_b->lock); in update_runtime_enabled()
5302 cfs_rq->runtime_enabled = cfs_b->quota != RUNTIME_INF; in update_runtime_enabled()
5303 raw_spin_unlock(&cfs_b->lock); in update_runtime_enabled()
5313 lockdep_assert_held(&rq->lock); in unthrottle_offline_cfs_rqs()
5317 struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; in unthrottle_offline_cfs_rqs()
5319 if (!cfs_rq->runtime_enabled) in unthrottle_offline_cfs_rqs()
5326 cfs_rq->runtime_remaining = 1; in unthrottle_offline_cfs_rqs()
5331 cfs_rq->runtime_enabled = 0; in unthrottle_offline_cfs_rqs()
5391 struct sched_entity *se = &p->se; in hrtick_start_fair()
5396 if (rq->cfs.h_nr_running > 1) { in hrtick_start_fair()
5398 u64 ran = se->sum_exec_runtime - se->prev_sum_exec_runtime; in hrtick_start_fair()
5399 s64 delta = slice - ran; in hrtick_start_fair()
5402 if (rq->curr == p) in hrtick_start_fair()
5417 struct task_struct *curr = rq->curr; in hrtick_update()
5419 if (!hrtick_enabled(rq) || curr->sched_class != &fair_sched_class) in hrtick_update()
5422 if (cfs_rq_of(&curr->se)->nr_running < sched_nr_latency) in hrtick_update()
5446 if (!READ_ONCE(rq->rd->overutilized) && cpu_overutilized(rq->cpu)) { in update_overutilized_status()
5447 WRITE_ONCE(rq->rd->overutilized, SG_OVERUTILIZED); in update_overutilized_status()
5448 trace_sched_overutilized_tp(rq->rd, SG_OVERUTILIZED); in update_overutilized_status()
5458 return unlikely(rq->nr_running == rq->cfs.idle_h_nr_running && in sched_idle_rq()
5459 rq->nr_running); in sched_idle_rq()
5478 struct sched_entity *se = &p->se; in enqueue_task_fair()
5488 util_est_enqueue(&rq->cfs, p); in enqueue_task_fair()
5495 if (p->in_iowait) in enqueue_task_fair()
5499 if (se->on_rq) in enqueue_task_fair()
5504 cfs_rq->h_nr_running++; in enqueue_task_fair()
5505 cfs_rq->idle_h_nr_running += idle_h_nr_running; in enqueue_task_fair()
5521 cfs_rq->h_nr_running++; in enqueue_task_fair()
5522 cfs_rq->idle_h_nr_running += idle_h_nr_running; in enqueue_task_fair()
5587 struct sched_entity *se = &p->se; in dequeue_task_fair()
5596 cfs_rq->h_nr_running--; in dequeue_task_fair()
5597 cfs_rq->idle_h_nr_running -= idle_h_nr_running; in dequeue_task_fair()
5604 if (cfs_rq->load.weight) { in dequeue_task_fair()
5605 /* Avoid re-evaluating load for this entity: */ in dequeue_task_fair()
5625 cfs_rq->h_nr_running--; in dequeue_task_fair()
5626 cfs_rq->idle_h_nr_running -= idle_h_nr_running; in dequeue_task_fair()
5639 rq->next_balance = jiffies; in dequeue_task_fair()
5642 util_est_dequeue(&rq->cfs, p, task_sleep); in dequeue_task_fair()
5666 return cfs_rq_load_avg(&rq->cfs); in cpu_load()
5670 * cpu_load_without - compute CPU load without any contributions from *p
5688 if (cpu_of(rq) != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in cpu_load_without()
5691 cfs_rq = &rq->cfs; in cpu_load_without()
5692 load = READ_ONCE(cfs_rq->avg.load_avg); in cpu_load_without()
5702 return cfs_rq_runnable_avg(&rq->cfs); in cpu_runnable()
5711 if (cpu_of(rq) != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in cpu_runnable_without()
5714 cfs_rq = &rq->cfs; in cpu_runnable_without()
5715 runnable = READ_ONCE(cfs_rq->avg.runnable_avg); in cpu_runnable_without()
5718 lsub_positive(&runnable, p->se.avg.runnable_avg); in cpu_runnable_without()
5725 return cpu_rq(cpu)->cpu_capacity; in capacity_of()
5734 if (time_after(jiffies, current->wakee_flip_decay_ts + HZ)) { in record_wakee()
5735 current->wakee_flips >>= 1; in record_wakee()
5736 current->wakee_flip_decay_ts = jiffies; in record_wakee()
5739 if (current->last_wakee != p) { in record_wakee()
5740 current->last_wakee = p; in record_wakee()
5741 current->wakee_flips++; in record_wakee()
5746 * Detect M:N waker/wakee relationships via a switching-frequency heuristic.
5756 * non-monogamous, with partner count exceeding socket size.
5764 unsigned int master = current->wakee_flips; in wake_wide()
5765 unsigned int slave = p->wakee_flips; in wake_wide()
5780 * wake_affine_idle() - only considers 'now', it check if the waking CPU is
5781 * cache-affine and is (or will be) idle.
5783 * wake_affine_weight() - considers the weight to reflect the average
5805 if (sync && cpu_rq(this_cpu)->nr_running == 1) in wake_affine_idle()
5826 this_eff_load -= current_load; in wake_affine_weight()
5837 prev_eff_load -= task_load; in wake_affine_weight()
5839 prev_eff_load *= 100 + (sd->imbalance_pct - 100) / 2; in wake_affine_weight()
5865 schedstat_inc(p->se.statistics.nr_wakeups_affine_attempts); in wake_affine()
5869 schedstat_inc(sd->ttwu_move_affine); in wake_affine()
5870 schedstat_inc(p->se.statistics.nr_wakeups_affine); in wake_affine()
5878 * find_idlest_group_cpu - find the idlest CPU among the CPUs in the group.
5887 int shallowest_idle_cpu = -1; in find_idlest_group_cpu()
5891 if (group->group_weight == 1) in find_idlest_group_cpu()
5895 for_each_cpu_and(i, sched_group_span(group), p->cpus_ptr) { in find_idlest_group_cpu()
5902 if (idle && idle->exit_latency < min_exit_latency) { in find_idlest_group_cpu()
5908 min_exit_latency = idle->exit_latency; in find_idlest_group_cpu()
5909 latest_idle_timestamp = rq->idle_stamp; in find_idlest_group_cpu()
5911 } else if ((!idle || idle->exit_latency == min_exit_latency) && in find_idlest_group_cpu()
5912 rq->idle_stamp > latest_idle_timestamp) { in find_idlest_group_cpu()
5918 latest_idle_timestamp = rq->idle_stamp; in find_idlest_group_cpu()
5921 } else if (shallowest_idle_cpu == -1) { in find_idlest_group_cpu()
5930 return shallowest_idle_cpu != -1 ? shallowest_idle_cpu : least_loaded_cpu; in find_idlest_group_cpu()
5938 if (!cpumask_intersects(sched_domain_span(sd), p->cpus_ptr)) in find_idlest_cpu()
5946 sync_entity_load_avg(&p->se); in find_idlest_cpu()
5953 if (!(sd->flags & sd_flag)) { in find_idlest_cpu()
5954 sd = sd->child; in find_idlest_cpu()
5960 sd = sd->child; in find_idlest_cpu()
5967 sd = sd->child; in find_idlest_cpu()
5973 weight = sd->span_weight; in find_idlest_cpu()
5976 if (weight <= tmp->span_weight) in find_idlest_cpu()
5978 if (tmp->flags & sd_flag) in find_idlest_cpu()
5996 WRITE_ONCE(sds->has_idle_cores, val); in set_idle_cores()
6005 return READ_ONCE(sds->has_idle_cores); in test_idle_cores()
6012 * information in sd_llc_shared->has_idle_cores.
6042 * sd_llc->shared->has_idle_cores and enabled through update_idle_core() above.
6050 return -1; in select_idle_core()
6053 return -1; in select_idle_core()
6055 cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr); in select_idle_core()
6077 return -1; in select_idle_core()
6088 return -1; in select_idle_smt()
6091 if (!cpumask_test_cpu(cpu, p->cpus_ptr) || in select_idle_smt()
6098 return -1; in select_idle_smt()
6105 return -1; in select_idle_core()
6110 return -1; in select_idle_smt()
6117 * comparing the average scan cost (tracked in sd->avg_scan_cost) against the
6118 * average idle time for this rq (as found in rq->avg_idle).
6131 return -1; in select_idle_cpu()
6137 avg_idle = this_rq()->avg_idle / 512; in select_idle_cpu()
6138 avg_cost = this_sd->avg_scan_cost + 1; in select_idle_cpu()
6141 return -1; in select_idle_cpu()
6144 u64 span_avg = sd->span_weight * avg_idle; in select_idle_cpu()
6153 cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr); in select_idle_cpu()
6156 if (!--nr) in select_idle_cpu()
6157 return -1; in select_idle_cpu()
6162 time = cpu_clock(this) - time; in select_idle_cpu()
6163 update_avg(&this_sd->avg_scan_cost, time); in select_idle_cpu()
6177 int cpu, best_cpu = -1; in select_idle_capacity()
6181 cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr); in select_idle_capacity()
6224 sync_entity_load_avg(&p->se); in select_idle_sibling()
6241 * Allow a per-cpu kthread to stack with the wakee if the in select_idle_sibling()
6244 * per-cpu kthread that is now complete and the wakeup is in select_idle_sibling()
6250 this_rq()->nr_running <= 1) { in select_idle_sibling()
6255 recent_used_cpu = p->recent_used_cpu; in select_idle_sibling()
6260 cpumask_test_cpu(p->recent_used_cpu, p->cpus_ptr) && in select_idle_sibling()
6266 p->recent_used_cpu = prev; in select_idle_sibling()
6317 * cfs_rq.avg.util_avg is the sum of running time of runnable tasks plus the
6318 * recent utilization of currently non-runnable tasks on a CPU. It represents
6327 * cfs_rq.avg.util_avg and the sum of the estimated utilization of the tasks
6334 * Nevertheless, cfs_rq.avg.util_avg can be higher than capacity_curr or even
6336 * cfs.avg.util_avg or just after migrating tasks and new task wakeups until
6343 * migrations (scheduler-driven DVFS).
6352 cfs_rq = &cpu_rq(cpu)->cfs; in cpu_util()
6353 util = READ_ONCE(cfs_rq->avg.util_avg); in cpu_util()
6356 util = max(util, READ_ONCE(cfs_rq->avg.util_est.enqueued)); in cpu_util()
6380 if (cpu != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in cpu_util_without()
6383 cfs_rq = &cpu_rq(cpu)->cfs; in cpu_util_without()
6384 util = READ_ONCE(cfs_rq->avg.util_avg); in cpu_util_without()
6395 * cpu_util_without = (cpu_util - task_util) = 0 in cpu_util_without()
6402 * cpu_util_without = (cpu_util - task_util) >= 0 in cpu_util_without()
6417 READ_ONCE(cfs_rq->avg.util_est.enqueued); in cpu_util_without()
6425 * p->on_rq = TASK_ON_RQ_MIGRATING; in cpu_util_without()
6426 * ---------------------------------- A in cpu_util_without()
6430 * ---------------------------------- B in cpu_util_without()
6456 struct cfs_rq *cfs_rq = &cpu_rq(cpu)->cfs; in cpu_util_next()
6457 unsigned long util_est, util = READ_ONCE(cfs_rq->avg.util_avg); in cpu_util_next()
6471 util_est = READ_ONCE(cfs_rq->avg.util_est.enqueued); in cpu_util_next()
6474 * During wake-up, the task isn't enqueued yet and doesn't in cpu_util_next()
6475 * appear in the cfs_rq->avg.util_est.enqueued of any rq, in cpu_util_next()
6537 return em_cpu_energy(pd->em_pd, max_util, sum_util); in compute_energy()
6541 * find_energy_efficient_cpu(): Find most energy-efficient target CPU for the
6545 * out which of the CPU candidates is the most energy-efficient.
6562 * cluster-packing, and spreading inside a cluster. That should at least be
6569 * NOTE: Forkees are not accepted in the energy-aware wake-up path because
6573 * to be energy-inefficient in some use-cases. The alternative would be to
6576 * other use-cases too. So, until someone finds a better way to solve this,
6577 * let's keep things simple by re-using the existing slow path.
6582 struct root_domain *rd = cpu_rq(smp_processor_id())->rd; in find_energy_efficient_cpu()
6589 pd = rcu_dereference(rd->pd); in find_energy_efficient_cpu()
6590 if (!pd || READ_ONCE(rd->overutilized)) in find_energy_efficient_cpu()
6594 * Energy-aware wake-up happens on the lowest sched_domain starting in find_energy_efficient_cpu()
6599 sd = sd->parent; in find_energy_efficient_cpu()
6603 sync_entity_load_avg(&p->se); in find_energy_efficient_cpu()
6607 for (; pd; pd = pd->next) { in find_energy_efficient_cpu()
6610 int max_spare_cap_cpu = -1; in find_energy_efficient_cpu()
6613 base_energy_pd = compute_energy(p, -1, pd); in find_energy_efficient_cpu()
6617 if (!cpumask_test_cpu(cpu, p->cpus_ptr)) in find_energy_efficient_cpu()
6639 prev_delta -= base_energy_pd; in find_energy_efficient_cpu()
6656 cur_delta -= base_energy_pd; in find_energy_efficient_cpu()
6673 if ((prev_delta - best_delta) > ((prev_delta + base_energy) >> 4)) in find_energy_efficient_cpu()
6681 return -1; in find_energy_efficient_cpu()
6703 int sync = (wake_flags & WF_SYNC) && !(current->flags & PF_EXITING); in select_task_rq_fair()
6715 want_affine = !wake_wide(p) && cpumask_test_cpu(cpu, p->cpus_ptr); in select_task_rq_fair()
6724 if (want_affine && (tmp->flags & SD_WAKE_AFFINE) && in select_task_rq_fair()
6733 if (tmp->flags & sd_flag) in select_task_rq_fair()
6748 current->recent_used_cpu = cpu; in select_task_rq_fair()
6760 * previous CPU. The caller guarantees p->pi_lock or task_rq(p)->lock is held.
6767 * min_vruntime -- the latter is done by enqueue_entity() when placing in migrate_task_rq_fair()
6770 if (p->state == TASK_WAKING) { in migrate_task_rq_fair()
6771 struct sched_entity *se = &p->se; in migrate_task_rq_fair()
6779 min_vruntime_copy = cfs_rq->min_vruntime_copy; in migrate_task_rq_fair()
6781 min_vruntime = cfs_rq->min_vruntime; in migrate_task_rq_fair()
6784 min_vruntime = cfs_rq->min_vruntime; in migrate_task_rq_fair()
6787 se->vruntime -= min_vruntime; in migrate_task_rq_fair()
6790 if (p->on_rq == TASK_ON_RQ_MIGRATING) { in migrate_task_rq_fair()
6793 * rq->lock and can modify state directly. in migrate_task_rq_fair()
6795 lockdep_assert_held(&task_rq(p)->lock); in migrate_task_rq_fair()
6796 detach_entity_cfs_rq(&p->se); in migrate_task_rq_fair()
6803 * throw away the out-of-date time. This will result in the in migrate_task_rq_fair()
6807 remove_entity_load_avg(&p->se); in migrate_task_rq_fair()
6811 p->se.avg.last_update_time = 0; in migrate_task_rq_fair()
6814 p->se.exec_start = 0; in migrate_task_rq_fair()
6821 remove_entity_load_avg(&p->se); in task_dead_fair()
6827 if (rq->nr_running) in balance_fair()
6839 * Since its curr running now, convert the gran from real-time in wakeup_gran()
6840 * to virtual-time in his units. in wakeup_gran()
6861 * |<--->|c
6863 * w(c, s1) = -1
6871 s64 gran, vdiff = curr->vruntime - se->vruntime; in wakeup_preempt_entity()
6874 return -1; in wakeup_preempt_entity()
6889 if (SCHED_WARN_ON(!se->on_rq)) in set_last_buddy()
6891 cfs_rq_of(se)->last = se; in set_last_buddy()
6901 if (SCHED_WARN_ON(!se->on_rq)) in set_next_buddy()
6903 cfs_rq_of(se)->next = se; in set_next_buddy()
6910 cfs_rq_of(se)->skip = se; in set_skip_buddy()
6918 struct task_struct *curr = rq->curr; in check_preempt_wakeup()
6919 struct sched_entity *se = &curr->se, *pse = &p->se; in check_preempt_wakeup()
6921 int scale = cfs_rq->nr_running >= sched_nr_latency; in check_preempt_wakeup()
6931 * next-buddy nomination below. in check_preempt_wakeup()
6945 * Note: this also catches the edge-case of curr being in a throttled in check_preempt_wakeup()
6954 /* Idle tasks are by definition preempted by non-idle tasks. */ in check_preempt_wakeup()
6960 * Batch and idle tasks do not preempt non-idle tasks (their preemption in check_preempt_wakeup()
6963 if (unlikely(p->policy != SCHED_NORMAL) || !sched_feat(WAKEUP_PREEMPTION)) in check_preempt_wakeup()
6986 * with schedule on the ->pre_schedule() or idle_balance() in check_preempt_wakeup()
6992 if (unlikely(!se->on_rq || curr == rq->idle)) in check_preempt_wakeup()
7002 struct cfs_rq *cfs_rq = &rq->cfs; in pick_next_task_fair()
7012 if (!prev || prev->sched_class != &fair_sched_class) in pick_next_task_fair()
7024 struct sched_entity *curr = cfs_rq->curr; in pick_next_task_fair()
7028 * have to consider cfs_rq->curr. If it is still a runnable in pick_next_task_fair()
7033 if (curr->on_rq) in pick_next_task_fair()
7045 cfs_rq = &rq->cfs; in pick_next_task_fair()
7047 if (!cfs_rq->nr_running) in pick_next_task_fair()
7066 struct sched_entity *pse = &prev->se; in pick_next_task_fair()
7069 int se_depth = se->depth; in pick_next_task_fair()
7070 int pse_depth = pse->depth; in pick_next_task_fair()
7107 list_move(&p->se.group_node, &rq->cfs_tasks); in pick_next_task_fair()
7124 * Because newidle_balance() releases (and re-acquires) rq->lock, it is in pick_next_task_fair()
7126 * must re-start the pick_next_entity() loop. in pick_next_task_fair()
7153 struct sched_entity *se = &prev->se; in put_prev_task_fair()
7165 * The magic of dealing with the ->skip buddy is in pick_next_entity.
7169 struct task_struct *curr = rq->curr; in yield_task_fair()
7171 struct sched_entity *se = &curr->se; in yield_task_fair()
7176 if (unlikely(rq->nr_running == 1)) in yield_task_fair()
7181 if (curr->policy != SCHED_BATCH) { in yield_task_fair()
7184 * Update run-time statistics of the 'current'. in yield_task_fair()
7200 struct sched_entity *se = &p->se; in yield_to_task_fair()
7203 if (!se->on_rq || throttled_hierarchy(cfs_rq_of(se))) in yield_to_task_fair()
7216 * Fair scheduling class load-balancing methods.
7220 * The purpose of load-balancing is to achieve the same basic fairness the
7221 * per-CPU scheduler provides, namely provide a proportional amount of compute
7226 * Where W_i,n is the n-th weight average for CPU i. The instantaneous weight
7231 * Where w_i,j is the weight of the j-th runnable task on CPU i. This weight
7237 * W'_i,n = (2^n - 1) / 2^n * W_i,n + 1 / 2^n * W_i,0 (3)
7246 * imb_i,j = max{ avg(W/C), W_i/C_i } - min{ avg(W/C), W_j/C_j } (4)
7253 * - infeasible weights;
7254 * - local vs global optima in the discrete case. ]
7264 * of load-balance at each level inv. proportional to the number of CPUs in
7270 * \Sum { --- * --- * 2^i } = O(n) (5)
7272 * `- size of each group
7273 * | | `- number of CPUs doing load-balance
7274 * | `- freq
7275 * `- sum over all levels
7317 * W_i,0 = \Sum_j \Prod_k w_k * ----- (9)
7324 * w_i,j,k is the weight of the j-th runnable task in the k-th cgroup on CPU i.
7402 /* The set of CPUs under consideration for load-balancing */
7417 * Is this task likely cache-hot:
7423 lockdep_assert_held(&env->src_rq->lock); in task_hot()
7425 if (p->sched_class != &fair_sched_class) in task_hot()
7432 if (env->sd->flags & SD_SHARE_CPUCAPACITY) in task_hot()
7438 if (sched_feat(CACHE_HOT_BUDDY) && env->dst_rq->nr_running && in task_hot()
7439 (&p->se == cfs_rq_of(&p->se)->next || in task_hot()
7440 &p->se == cfs_rq_of(&p->se)->last)) in task_hot()
7443 if (sysctl_sched_migration_cost == -1) in task_hot()
7448 delta = rq_clock_task(env->src_rq) - p->se.exec_start; in task_hot()
7457 * Returns -1, if task migration is not affected by locality.
7461 struct numa_group *numa_group = rcu_dereference(p->numa_group); in migrate_degrades_locality()
7466 return -1; in migrate_degrades_locality()
7468 if (!p->numa_faults || !(env->sd->flags & SD_NUMA)) in migrate_degrades_locality()
7469 return -1; in migrate_degrades_locality()
7471 src_nid = cpu_to_node(env->src_cpu); in migrate_degrades_locality()
7472 dst_nid = cpu_to_node(env->dst_cpu); in migrate_degrades_locality()
7475 return -1; in migrate_degrades_locality()
7478 if (src_nid == p->numa_preferred_nid) { in migrate_degrades_locality()
7479 if (env->src_rq->nr_running > env->src_rq->nr_preferred_running) in migrate_degrades_locality()
7482 return -1; in migrate_degrades_locality()
7486 if (dst_nid == p->numa_preferred_nid) in migrate_degrades_locality()
7490 if (env->idle == CPU_IDLE) in migrate_degrades_locality()
7491 return -1; in migrate_degrades_locality()
7509 return -1; in migrate_degrades_locality()
7514 * can_migrate_task - may task p from runqueue rq be migrated to this_cpu?
7521 lockdep_assert_held(&env->src_rq->lock); in can_migrate_task()
7528 * 4) are cache-hot on their current CPU. in can_migrate_task()
7530 if (throttled_lb_pair(task_group(p), env->src_cpu, env->dst_cpu)) in can_migrate_task()
7533 if (!cpumask_test_cpu(env->dst_cpu, p->cpus_ptr)) { in can_migrate_task()
7536 schedstat_inc(p->se.statistics.nr_failed_migrations_affine); in can_migrate_task()
7538 env->flags |= LBF_SOME_PINNED; in can_migrate_task()
7548 if (env->idle == CPU_NEWLY_IDLE || (env->flags & LBF_DST_PINNED)) in can_migrate_task()
7551 /* Prevent to re-select dst_cpu via env's CPUs: */ in can_migrate_task()
7552 for_each_cpu_and(cpu, env->dst_grpmask, env->cpus) { in can_migrate_task()
7553 if (cpumask_test_cpu(cpu, p->cpus_ptr)) { in can_migrate_task()
7554 env->flags |= LBF_DST_PINNED; in can_migrate_task()
7555 env->new_dst_cpu = cpu; in can_migrate_task()
7564 env->flags &= ~LBF_ALL_PINNED; in can_migrate_task()
7566 if (task_running(env->src_rq, p)) { in can_migrate_task()
7567 schedstat_inc(p->se.statistics.nr_failed_migrations_running); in can_migrate_task()
7578 if (tsk_cache_hot == -1) in can_migrate_task()
7582 env->sd->nr_balance_failed > env->sd->cache_nice_tries) { in can_migrate_task()
7584 schedstat_inc(env->sd->lb_hot_gained[env->idle]); in can_migrate_task()
7585 schedstat_inc(p->se.statistics.nr_forced_migrations); in can_migrate_task()
7590 schedstat_inc(p->se.statistics.nr_failed_migrations_hot); in can_migrate_task()
7595 * detach_task() -- detach the task for the migration specified in env
7599 lockdep_assert_held(&env->src_rq->lock); in detach_task()
7601 deactivate_task(env->src_rq, p, DEQUEUE_NOCLOCK); in detach_task()
7602 set_task_cpu(p, env->dst_cpu); in detach_task()
7606 * detach_one_task() -- tries to dequeue exactly one task from env->src_rq, as
7615 lockdep_assert_held(&env->src_rq->lock); in detach_one_task()
7618 &env->src_rq->cfs_tasks, se.group_node) { in detach_one_task()
7626 * lb_gained[env->idle] is updated (other is detach_tasks) in detach_one_task()
7630 schedstat_inc(env->sd->lb_gained[env->idle]); in detach_one_task()
7639 * detach_tasks() -- tries to detach up to imbalance load/util/tasks from
7646 struct list_head *tasks = &env->src_rq->cfs_tasks; in detach_tasks()
7651 lockdep_assert_held(&env->src_rq->lock); in detach_tasks()
7653 if (env->imbalance <= 0) in detach_tasks()
7661 if (env->idle != CPU_NOT_IDLE && env->src_rq->nr_running <= 1) in detach_tasks()
7666 env->loop++; in detach_tasks()
7668 if (env->loop > env->loop_max) in detach_tasks()
7672 if (env->loop > env->loop_break) { in detach_tasks()
7673 env->loop_break += sched_nr_migrate_break; in detach_tasks()
7674 env->flags |= LBF_NEED_BREAK; in detach_tasks()
7681 switch (env->migration_type) { in detach_tasks()
7686 * value. Make sure that env->imbalance decreases in detach_tasks()
7693 load < 16 && !env->sd->nr_balance_failed) in detach_tasks()
7703 if ((load >> env->sd->nr_balance_failed) > env->imbalance) in detach_tasks()
7706 env->imbalance -= load; in detach_tasks()
7712 if (util > env->imbalance) in detach_tasks()
7715 env->imbalance -= util; in detach_tasks()
7719 env->imbalance--; in detach_tasks()
7724 if (task_fits_capacity(p, capacity_of(env->src_cpu))) in detach_tasks()
7727 env->imbalance = 0; in detach_tasks()
7732 list_add(&p->se.group_node, &env->tasks); in detach_tasks()
7742 if (env->idle == CPU_NEWLY_IDLE) in detach_tasks()
7750 if (env->imbalance <= 0) in detach_tasks()
7755 list_move(&p->se.group_node, tasks); in detach_tasks()
7763 schedstat_add(env->sd->lb_gained[env->idle], detached); in detach_tasks()
7769 * attach_task() -- attach the task detached by detach_task() to its new rq.
7773 lockdep_assert_held(&rq->lock); in attach_task()
7781 * attach_one_task() -- attaches the task returned from detach_one_task() to
7795 * attach_tasks() -- attaches all tasks detached by detach_tasks() to their
7800 struct list_head *tasks = &env->tasks; in attach_tasks()
7804 rq_lock(env->dst_rq, &rf); in attach_tasks()
7805 update_rq_clock(env->dst_rq); in attach_tasks()
7809 list_del_init(&p->se.group_node); in attach_tasks()
7811 attach_task(env->dst_rq, p); in attach_tasks()
7814 rq_unlock(env->dst_rq, &rf); in attach_tasks()
7820 if (cfs_rq->avg.load_avg) in cfs_rq_has_blocked()
7823 if (cfs_rq->avg.util_avg) in cfs_rq_has_blocked()
7831 if (READ_ONCE(rq->avg_rt.util_avg)) in others_have_blocked()
7834 if (READ_ONCE(rq->avg_dl.util_avg)) in others_have_blocked()
7841 if (READ_ONCE(rq->avg_irq.util_avg)) in others_have_blocked()
7850 rq->last_blocked_load_update_tick = jiffies; in update_blocked_load_status()
7853 rq->has_blocked_load = 0; in update_blocked_load_status()
7872 curr_class = rq->curr->sched_class; in __update_blocked_others()
7891 if (cfs_rq->load.weight) in cfs_rq_is_decayed()
7894 if (cfs_rq->avg.load_sum) in cfs_rq_is_decayed()
7897 if (cfs_rq->avg.util_sum) in cfs_rq_is_decayed()
7900 if (cfs_rq->avg.runnable_sum) in cfs_rq_is_decayed()
7922 if (cfs_rq == &rq->cfs) in __update_blocked_fair()
7927 se = cfs_rq->tg->se[cpu]; in __update_blocked_fair()
7948 * This needs to be done in a top-down fashion because the load of a child
7954 struct sched_entity *se = cfs_rq->tg->se[cpu_of(rq)]; in update_cfs_rq_h_load()
7958 if (cfs_rq->last_h_load_update == now) in update_cfs_rq_h_load()
7961 WRITE_ONCE(cfs_rq->h_load_next, NULL); in update_cfs_rq_h_load()
7964 WRITE_ONCE(cfs_rq->h_load_next, se); in update_cfs_rq_h_load()
7965 if (cfs_rq->last_h_load_update == now) in update_cfs_rq_h_load()
7970 cfs_rq->h_load = cfs_rq_load_avg(cfs_rq); in update_cfs_rq_h_load()
7971 cfs_rq->last_h_load_update = now; in update_cfs_rq_h_load()
7974 while ((se = READ_ONCE(cfs_rq->h_load_next)) != NULL) { in update_cfs_rq_h_load()
7975 load = cfs_rq->h_load; in update_cfs_rq_h_load()
7976 load = div64_ul(load * se->avg.load_avg, in update_cfs_rq_h_load()
7979 cfs_rq->h_load = load; in update_cfs_rq_h_load()
7980 cfs_rq->last_h_load_update = now; in update_cfs_rq_h_load()
7989 return div64_ul(p->se.avg.load_avg * cfs_rq->h_load, in task_h_load()
7995 struct cfs_rq *cfs_rq = &rq->cfs; in __update_blocked_fair()
8007 return p->se.avg.load_avg; in task_h_load()
8032 * sg_lb_stats - stats of a sched_group required for load_balancing
8035 unsigned long avg_load; /*Avg load across the CPUs of the group */
8054 * sd_lb_stats - Structure to store the statistics of a sched_domain
8108 used = READ_ONCE(rq->avg_rt.util_avg); in scale_rt_capacity()
8109 used += READ_ONCE(rq->avg_dl.util_avg); in scale_rt_capacity()
8115 free = max - used; in scale_rt_capacity()
8123 struct sched_group *sdg = sd->groups; in update_cpu_capacity()
8125 cpu_rq(cpu)->cpu_capacity_orig = arch_scale_cpu_capacity(cpu); in update_cpu_capacity()
8130 cpu_rq(cpu)->cpu_capacity = capacity; in update_cpu_capacity()
8133 sdg->sgc->capacity = capacity; in update_cpu_capacity()
8134 sdg->sgc->min_capacity = capacity; in update_cpu_capacity()
8135 sdg->sgc->max_capacity = capacity; in update_cpu_capacity()
8140 struct sched_domain *child = sd->child; in update_group_capacity()
8141 struct sched_group *group, *sdg = sd->groups; in update_group_capacity()
8145 interval = msecs_to_jiffies(sd->balance_interval); in update_group_capacity()
8147 sdg->sgc->next_update = jiffies + interval; in update_group_capacity()
8158 if (child->flags & SD_OVERLAP) { in update_group_capacity()
8177 group = child->groups; in update_group_capacity()
8179 struct sched_group_capacity *sgc = group->sgc; in update_group_capacity()
8181 capacity += sgc->capacity; in update_group_capacity()
8182 min_capacity = min(sgc->min_capacity, min_capacity); in update_group_capacity()
8183 max_capacity = max(sgc->max_capacity, max_capacity); in update_group_capacity()
8184 group = group->next; in update_group_capacity()
8185 } while (group != child->groups); in update_group_capacity()
8188 sdg->sgc->capacity = capacity; in update_group_capacity()
8189 sdg->sgc->min_capacity = min_capacity; in update_group_capacity()
8190 sdg->sgc->max_capacity = max_capacity; in update_group_capacity()
8201 return ((rq->cpu_capacity * sd->imbalance_pct) < in check_cpu_capacity()
8202 (rq->cpu_capacity_orig * 100)); in check_cpu_capacity()
8212 return rq->misfit_task_load && in check_misfit_status()
8213 (rq->cpu_capacity_orig < rq->rd->max_cpu_capacity || in check_misfit_status()
8219 * groups is inadequate due to ->cpus_ptr constraints.
8228 * If we were to balance group-wise we'd place two tasks in the first group and
8248 return group->sgc->imbalance; in sg_imbalanced()
8266 if (sgs->sum_nr_running < sgs->group_weight) in group_has_capacity()
8269 if ((sgs->group_capacity * imbalance_pct) < in group_has_capacity()
8270 (sgs->group_runnable * 100)) in group_has_capacity()
8273 if ((sgs->group_capacity * 100) > in group_has_capacity()
8274 (sgs->group_util * imbalance_pct)) in group_has_capacity()
8291 if (sgs->sum_nr_running <= sgs->group_weight) in group_is_overloaded()
8294 if ((sgs->group_capacity * 100) < in group_is_overloaded()
8295 (sgs->group_util * imbalance_pct)) in group_is_overloaded()
8298 if ((sgs->group_capacity * imbalance_pct) < in group_is_overloaded()
8299 (sgs->group_runnable * 100)) in group_is_overloaded()
8307 * per-CPU capacity than sched_group ref.
8312 return fits_capacity(sg->sgc->min_capacity, ref->sgc->min_capacity); in group_smaller_min_cpu_capacity()
8317 * per-CPU capacity_orig than sched_group ref.
8322 return fits_capacity(sg->sgc->max_capacity, ref->sgc->max_capacity); in group_smaller_max_cpu_capacity()
8336 if (sgs->group_asym_packing) in group_classify()
8339 if (sgs->group_misfit_task_load) in group_classify()
8351 unsigned int cpu = rq->cpu; in update_nohz_stats()
8353 if (!rq->has_blocked_load) in update_nohz_stats()
8359 if (!force && !time_after(jiffies, rq->last_blocked_load_update_tick)) in update_nohz_stats()
8364 return rq->has_blocked_load; in update_nohz_stats()
8371 * update_sg_lb_stats - Update sched_group's statistics for load balancing.
8386 local_group = cpumask_test_cpu(env->dst_cpu, sched_group_span(group)); in update_sg_lb_stats()
8388 for_each_cpu_and(i, sched_group_span(group), env->cpus) { in update_sg_lb_stats()
8391 if ((env->flags & LBF_NOHZ_STATS) && update_nohz_stats(rq, false)) in update_sg_lb_stats()
8392 env->flags |= LBF_NOHZ_AGAIN; in update_sg_lb_stats()
8394 sgs->group_load += cpu_load(rq); in update_sg_lb_stats()
8395 sgs->group_util += cpu_util(i); in update_sg_lb_stats()
8396 sgs->group_runnable += cpu_runnable(rq); in update_sg_lb_stats()
8397 sgs->sum_h_nr_running += rq->cfs.h_nr_running; in update_sg_lb_stats()
8399 nr_running = rq->nr_running; in update_sg_lb_stats()
8400 sgs->sum_nr_running += nr_running; in update_sg_lb_stats()
8409 sgs->nr_numa_running += rq->nr_numa_running; in update_sg_lb_stats()
8410 sgs->nr_preferred_running += rq->nr_preferred_running; in update_sg_lb_stats()
8416 sgs->idle_cpus++; in update_sg_lb_stats()
8425 if (env->sd->flags & SD_ASYM_CPUCAPACITY && in update_sg_lb_stats()
8426 sgs->group_misfit_task_load < rq->misfit_task_load) { in update_sg_lb_stats()
8427 sgs->group_misfit_task_load = rq->misfit_task_load; in update_sg_lb_stats()
8433 if (env->sd->flags & SD_ASYM_PACKING && in update_sg_lb_stats()
8434 env->idle != CPU_NOT_IDLE && in update_sg_lb_stats()
8435 sgs->sum_h_nr_running && in update_sg_lb_stats()
8436 sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu)) { in update_sg_lb_stats()
8437 sgs->group_asym_packing = 1; in update_sg_lb_stats()
8440 sgs->group_capacity = group->sgc->capacity; in update_sg_lb_stats()
8442 sgs->group_weight = group->group_weight; in update_sg_lb_stats()
8444 sgs->group_type = group_classify(env->sd->imbalance_pct, group, sgs); in update_sg_lb_stats()
8447 if (sgs->group_type == group_overloaded) in update_sg_lb_stats()
8448 sgs->avg_load = (sgs->group_load * SCHED_CAPACITY_SCALE) / in update_sg_lb_stats()
8449 sgs->group_capacity; in update_sg_lb_stats()
8453 * update_sd_pick_busiest - return 1 on busiest group
8470 struct sg_lb_stats *busiest = &sds->busiest_stat; in update_sd_pick_busiest()
8473 if (!sgs->sum_h_nr_running) in update_sd_pick_busiest()
8482 if (sgs->group_type == group_misfit_task && in update_sd_pick_busiest()
8483 (!group_smaller_max_cpu_capacity(sg, sds->local) || in update_sd_pick_busiest()
8484 sds->local_stat.group_type != group_has_spare)) in update_sd_pick_busiest()
8487 if (sgs->group_type > busiest->group_type) in update_sd_pick_busiest()
8490 if (sgs->group_type < busiest->group_type) in update_sd_pick_busiest()
8498 switch (sgs->group_type) { in update_sd_pick_busiest()
8501 if (sgs->avg_load <= busiest->avg_load) in update_sd_pick_busiest()
8514 if (sched_asym_prefer(sg->asym_prefer_cpu, sds->busiest->asym_prefer_cpu)) in update_sd_pick_busiest()
8523 if (sgs->group_misfit_task_load < busiest->group_misfit_task_load) in update_sd_pick_busiest()
8538 if (sgs->avg_load <= busiest->avg_load) in update_sd_pick_busiest()
8550 if (sgs->idle_cpus > busiest->idle_cpus) in update_sd_pick_busiest()
8552 else if ((sgs->idle_cpus == busiest->idle_cpus) && in update_sd_pick_busiest()
8553 (sgs->sum_nr_running <= busiest->sum_nr_running)) in update_sd_pick_busiest()
8561 * per-CPU capacity. Migrating tasks to less capable CPUs may harm in update_sd_pick_busiest()
8565 if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && in update_sd_pick_busiest()
8566 (sgs->group_type <= group_fully_busy) && in update_sd_pick_busiest()
8567 (group_smaller_min_cpu_capacity(sds->local, sg))) in update_sd_pick_busiest()
8576 if (sgs->sum_h_nr_running > sgs->nr_numa_running) in fbq_classify_group()
8578 if (sgs->sum_h_nr_running > sgs->nr_preferred_running) in fbq_classify_group()
8585 if (rq->nr_running > rq->nr_numa_running) in fbq_classify_rq()
8587 if (rq->nr_running > rq->nr_preferred_running) in fbq_classify_rq()
8607 * task_running_on_cpu - return 1 if @p is running on @cpu.
8613 if (cpu != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in task_running_on_cpu()
8623 * idle_cpu_without - would a given CPU be idle without p ?
8633 if (rq->curr != rq->idle && rq->curr != p) in idle_cpu_without()
8637 * rq->nr_running can't be used but an updated version without the in idle_cpu_without()
8643 if (rq->ttwu_pending) in idle_cpu_without()
8651 * update_sg_wakeup_stats - Update sched_group's statistics for wakeup.
8670 sgs->group_load += cpu_load_without(rq, p); in update_sg_wakeup_stats()
8671 sgs->group_util += cpu_util_without(i, p); in update_sg_wakeup_stats()
8672 sgs->group_runnable += cpu_runnable_without(rq, p); in update_sg_wakeup_stats()
8674 sgs->sum_h_nr_running += rq->cfs.h_nr_running - local; in update_sg_wakeup_stats()
8676 nr_running = rq->nr_running - local; in update_sg_wakeup_stats()
8677 sgs->sum_nr_running += nr_running; in update_sg_wakeup_stats()
8683 sgs->idle_cpus++; in update_sg_wakeup_stats()
8688 if (sd->flags & SD_ASYM_CPUCAPACITY && in update_sg_wakeup_stats()
8689 !task_fits_capacity(p, group->sgc->max_capacity)) { in update_sg_wakeup_stats()
8690 sgs->group_misfit_task_load = 1; in update_sg_wakeup_stats()
8693 sgs->group_capacity = group->sgc->capacity; in update_sg_wakeup_stats()
8695 sgs->group_weight = group->group_weight; in update_sg_wakeup_stats()
8697 sgs->group_type = group_classify(sd->imbalance_pct, group, sgs); in update_sg_wakeup_stats()
8703 if (sgs->group_type == group_fully_busy || in update_sg_wakeup_stats()
8704 sgs->group_type == group_overloaded) in update_sg_wakeup_stats()
8705 sgs->avg_load = (sgs->group_load * SCHED_CAPACITY_SCALE) / in update_sg_wakeup_stats()
8706 sgs->group_capacity; in update_sg_wakeup_stats()
8714 if (sgs->group_type < idlest_sgs->group_type) in update_pick_idlest()
8717 if (sgs->group_type > idlest_sgs->group_type) in update_pick_idlest()
8725 switch (sgs->group_type) { in update_pick_idlest()
8729 if (idlest_sgs->avg_load <= sgs->avg_load) in update_pick_idlest()
8740 if (idlest->sgc->max_capacity >= group->sgc->max_capacity) in update_pick_idlest()
8746 if (idlest_sgs->idle_cpus > sgs->idle_cpus) in update_pick_idlest()
8750 if (idlest_sgs->idle_cpus == sgs->idle_cpus && in update_pick_idlest()
8751 idlest_sgs->group_util <= sgs->group_util) in update_pick_idlest()
8769 struct sched_group *idlest = NULL, *local = NULL, *group = sd->groups; in find_idlest_group()
8779 (sd->imbalance_pct-100) / 100; in find_idlest_group()
8786 p->cpus_ptr)) in find_idlest_group()
8806 } while (group = group->next, group != sd->groups); in find_idlest_group()
8839 * cross-domain, add imbalance to the load on the remote node in find_idlest_group()
8843 if ((sd->flags & SD_NUMA) && in find_idlest_group()
8854 if (100 * local_sgs.avg_load <= sd->imbalance_pct * idlest_sgs.avg_load) in find_idlest_group()
8865 if (local->sgc->max_capacity >= idlest->sgc->max_capacity) in find_idlest_group()
8870 if (sd->flags & SD_NUMA) { in find_idlest_group()
8877 if (cpu_to_node(this_cpu) == p->numa_preferred_nid) in find_idlest_group()
8881 if (cpu_to_node(idlest_cpu) == p->numa_preferred_nid) in find_idlest_group()
8909 * update_sd_lb_stats - Update sched_domain's statistics for load balancing.
8916 struct sched_domain *child = env->sd->child; in update_sd_lb_stats()
8917 struct sched_group *sg = env->sd->groups; in update_sd_lb_stats()
8918 struct sg_lb_stats *local = &sds->local_stat; in update_sd_lb_stats()
8923 if (env->idle == CPU_NEWLY_IDLE && READ_ONCE(nohz.has_blocked)) in update_sd_lb_stats()
8924 env->flags |= LBF_NOHZ_STATS; in update_sd_lb_stats()
8931 local_group = cpumask_test_cpu(env->dst_cpu, sched_group_span(sg)); in update_sd_lb_stats()
8933 sds->local = sg; in update_sd_lb_stats()
8936 if (env->idle != CPU_NEWLY_IDLE || in update_sd_lb_stats()
8937 time_after_eq(jiffies, sg->sgc->next_update)) in update_sd_lb_stats()
8938 update_group_capacity(env->sd, env->dst_cpu); in update_sd_lb_stats()
8948 sds->busiest = sg; in update_sd_lb_stats()
8949 sds->busiest_stat = *sgs; in update_sd_lb_stats()
8954 sds->total_load += sgs->group_load; in update_sd_lb_stats()
8955 sds->total_capacity += sgs->group_capacity; in update_sd_lb_stats()
8957 sg = sg->next; in update_sd_lb_stats()
8958 } while (sg != env->sd->groups); in update_sd_lb_stats()
8961 sds->prefer_sibling = child && child->flags & SD_PREFER_SIBLING; in update_sd_lb_stats()
8964 if ((env->flags & LBF_NOHZ_AGAIN) && in update_sd_lb_stats()
8965 cpumask_subset(nohz.idle_cpus_mask, sched_domain_span(env->sd))) { in update_sd_lb_stats()
8972 if (env->sd->flags & SD_NUMA) in update_sd_lb_stats()
8973 env->fbq_type = fbq_classify_group(&sds->busiest_stat); in update_sd_lb_stats()
8975 if (!env->sd->parent) { in update_sd_lb_stats()
8976 struct root_domain *rd = env->dst_rq->rd; in update_sd_lb_stats()
8979 WRITE_ONCE(rd->overload, sg_status & SG_OVERLOAD); in update_sd_lb_stats()
8981 /* Update over-utilization (tipping point, U >= 0) indicator */ in update_sd_lb_stats()
8982 WRITE_ONCE(rd->overutilized, sg_status & SG_OVERUTILIZED); in update_sd_lb_stats()
8985 struct root_domain *rd = env->dst_rq->rd; in update_sd_lb_stats()
8987 WRITE_ONCE(rd->overutilized, SG_OVERUTILIZED); in update_sd_lb_stats()
9008 * calculate_imbalance - Calculate the amount of imbalance present within the
9017 local = &sds->local_stat; in calculate_imbalance()
9018 busiest = &sds->busiest_stat; in calculate_imbalance()
9020 if (busiest->group_type == group_misfit_task) { in calculate_imbalance()
9022 env->migration_type = migrate_misfit; in calculate_imbalance()
9023 env->imbalance = 1; in calculate_imbalance()
9027 if (busiest->group_type == group_asym_packing) { in calculate_imbalance()
9032 env->migration_type = migrate_task; in calculate_imbalance()
9033 env->imbalance = busiest->sum_h_nr_running; in calculate_imbalance()
9037 if (busiest->group_type == group_imbalanced) { in calculate_imbalance()
9039 * In the group_imb case we cannot rely on group-wide averages in calculate_imbalance()
9040 * to ensure CPU-load equilibrium, try to move any task to fix in calculate_imbalance()
9044 env->migration_type = migrate_task; in calculate_imbalance()
9045 env->imbalance = 1; in calculate_imbalance()
9053 if (local->group_type == group_has_spare) { in calculate_imbalance()
9054 if ((busiest->group_type > group_fully_busy) && in calculate_imbalance()
9055 !(env->sd->flags & SD_SHARE_PKG_RESOURCES)) { in calculate_imbalance()
9064 env->migration_type = migrate_util; in calculate_imbalance()
9065 env->imbalance = max(local->group_capacity, local->group_util) - in calculate_imbalance()
9066 local->group_util; in calculate_imbalance()
9075 if (env->idle != CPU_NOT_IDLE && env->imbalance == 0) { in calculate_imbalance()
9076 env->migration_type = migrate_task; in calculate_imbalance()
9077 env->imbalance = 1; in calculate_imbalance()
9083 if (busiest->group_weight == 1 || sds->prefer_sibling) { in calculate_imbalance()
9084 unsigned int nr_diff = busiest->sum_nr_running; in calculate_imbalance()
9089 env->migration_type = migrate_task; in calculate_imbalance()
9090 lsub_positive(&nr_diff, local->sum_nr_running); in calculate_imbalance()
9091 env->imbalance = nr_diff >> 1; in calculate_imbalance()
9098 env->migration_type = migrate_task; in calculate_imbalance()
9099 env->imbalance = max_t(long, 0, (local->idle_cpus - in calculate_imbalance()
9100 busiest->idle_cpus) >> 1); in calculate_imbalance()
9104 if (env->sd->flags & SD_NUMA) in calculate_imbalance()
9105 env->imbalance = adjust_numa_imbalance(env->imbalance, in calculate_imbalance()
9106 busiest->sum_nr_running); in calculate_imbalance()
9115 if (local->group_type < group_overloaded) { in calculate_imbalance()
9121 local->avg_load = (local->group_load * SCHED_CAPACITY_SCALE) / in calculate_imbalance()
9122 local->group_capacity; in calculate_imbalance()
9124 sds->avg_load = (sds->total_load * SCHED_CAPACITY_SCALE) / in calculate_imbalance()
9125 sds->total_capacity; in calculate_imbalance()
9130 if (local->avg_load >= busiest->avg_load) { in calculate_imbalance()
9131 env->imbalance = 0; in calculate_imbalance()
9144 env->migration_type = migrate_load; in calculate_imbalance()
9145 env->imbalance = min( in calculate_imbalance()
9146 (busiest->avg_load - sds->avg_load) * busiest->group_capacity, in calculate_imbalance()
9147 (sds->avg_load - local->avg_load) * local->group_capacity in calculate_imbalance()
9174 * find_busiest_group - Returns the busiest group within the sched_domain
9182 * Return: - The busiest group if imbalance exists.
9198 struct root_domain *rd = env->dst_rq->rd; in find_busiest_group()
9200 if (rcu_dereference(rd->pd) && !READ_ONCE(rd->overutilized)) in find_busiest_group()
9211 /* Misfit tasks should be dealt with regardless of the avg load */ in find_busiest_group()
9212 if (busiest->group_type == group_misfit_task) in find_busiest_group()
9216 if (busiest->group_type == group_asym_packing) in find_busiest_group()
9224 if (busiest->group_type == group_imbalanced) in find_busiest_group()
9231 if (local->group_type > busiest->group_type) in find_busiest_group()
9238 if (local->group_type == group_overloaded) { in find_busiest_group()
9243 if (local->avg_load >= busiest->avg_load) in find_busiest_group()
9254 if (local->avg_load >= sds.avg_load) in find_busiest_group()
9261 if (100 * busiest->avg_load <= in find_busiest_group()
9262 env->sd->imbalance_pct * local->avg_load) in find_busiest_group()
9267 if (sds.prefer_sibling && local->group_type == group_has_spare && in find_busiest_group()
9268 busiest->sum_nr_running > local->sum_nr_running + 1) in find_busiest_group()
9271 if (busiest->group_type != group_overloaded) { in find_busiest_group()
9272 if (env->idle == CPU_NOT_IDLE) in find_busiest_group()
9280 if (busiest->group_weight > 1 && in find_busiest_group()
9281 local->idle_cpus <= (busiest->idle_cpus + 1)) in find_busiest_group()
9293 if (busiest->sum_h_nr_running == 1) in find_busiest_group()
9303 return env->imbalance ? sds.busiest : NULL; in find_busiest_group()
9306 env->imbalance = 0; in find_busiest_group()
9311 * find_busiest_queue - find the busiest runqueue among the CPUs in the group.
9321 for_each_cpu_and(i, sched_group_span(group), env->cpus) { in find_busiest_queue()
9331 * - regular: there are !numa tasks in find_busiest_queue()
9332 * - remote: there are numa tasks that run on the 'wrong' node in find_busiest_queue()
9333 * - all: there is no distinction in find_busiest_queue()
9348 if (rt > env->fbq_type) in find_busiest_queue()
9352 nr_running = rq->cfs.h_nr_running; in find_busiest_queue()
9356 * eventually lead to active_balancing high->low capacity. in find_busiest_queue()
9357 * Higher per-CPU capacity is considered better than balancing in find_busiest_queue()
9360 if (env->sd->flags & SD_ASYM_CPUCAPACITY && in find_busiest_queue()
9361 capacity_of(env->dst_cpu) < capacity && in find_busiest_queue()
9365 switch (env->migration_type) { in find_busiest_queue()
9373 if (nr_running == 1 && load > env->imbalance && in find_busiest_queue()
9374 !check_cpu_capacity(rq, env->sd)) in find_busiest_queue()
9426 if (rq->misfit_task_load > busiest_load) { in find_busiest_queue()
9427 busiest_load = rq->misfit_task_load; in find_busiest_queue()
9453 return env->idle != CPU_NOT_IDLE && (env->sd->flags & SD_ASYM_PACKING) && in asym_active_balance()
9454 sched_asym_prefer(env->dst_cpu, env->src_cpu); in asym_active_balance()
9460 struct sched_domain *sd = env->sd; in voluntary_active_balance()
9471 if ((env->idle != CPU_NOT_IDLE) && in voluntary_active_balance()
9472 (env->src_rq->cfs.h_nr_running == 1)) { in voluntary_active_balance()
9473 if ((check_cpu_capacity(env->src_rq, sd)) && in voluntary_active_balance()
9474 (capacity_of(env->src_cpu)*sd->imbalance_pct < capacity_of(env->dst_cpu)*100)) in voluntary_active_balance()
9478 if (env->migration_type == migrate_misfit) in voluntary_active_balance()
9486 struct sched_domain *sd = env->sd; in need_active_balance()
9491 return unlikely(sd->nr_balance_failed > sd->cache_nice_tries+2); in need_active_balance()
9498 struct sched_group *sg = env->sd->groups; in should_we_balance()
9505 if (!cpumask_test_cpu(env->dst_cpu, env->cpus)) in should_we_balance()
9512 if (env->idle == CPU_NEWLY_IDLE) in should_we_balance()
9516 for_each_cpu_and(cpu, group_balance_mask(sg), env->cpus) { in should_we_balance()
9521 return cpu == env->dst_cpu; in should_we_balance()
9525 return group_balance_cpu(sg) == env->dst_cpu; in should_we_balance()
9537 struct sched_domain *sd_parent = sd->parent; in load_balance()
9547 .dst_grpmask = sched_group_span(sd->groups), in load_balance()
9557 schedstat_inc(sd->lb_count[idle]); in load_balance()
9567 schedstat_inc(sd->lb_nobusyg[idle]); in load_balance()
9573 schedstat_inc(sd->lb_nobusyq[idle]); in load_balance()
9579 schedstat_add(sd->lb_imbalance[idle], env.imbalance); in load_balance()
9581 env.src_cpu = busiest->cpu; in load_balance()
9585 if (busiest->nr_running > 1) { in load_balance()
9588 * an imbalance but busiest->nr_running <= 1, the group is in load_balance()
9593 env.loop_max = min(sysctl_sched_nr_migrate, busiest->nr_running); in load_balance()
9600 * cur_ld_moved - load moved in current iteration in load_balance()
9601 * ld_moved - cumulative load moved across iterations in load_balance()
9608 * unlock busiest->lock, and we are able to be sure in load_balance()
9637 * nohz-idle), we now have balance_cpu in a position to move in load_balance()
9648 /* Prevent to re-select dst_cpu via env's CPUs */ in load_balance()
9668 int *group_imbalance = &sd_parent->groups->sgc->imbalance; in load_balance()
9695 schedstat_inc(sd->lb_failed[idle]); in load_balance()
9703 sd->nr_balance_failed++; in load_balance()
9708 raw_spin_lock_irqsave(&busiest->lock, flags); in load_balance()
9715 if (!cpumask_test_cpu(this_cpu, busiest->curr->cpus_ptr)) { in load_balance()
9716 raw_spin_unlock_irqrestore(&busiest->lock, in load_balance()
9723 * ->active_balance synchronizes accesses to in load_balance()
9724 * ->active_balance_work. Once set, it's cleared in load_balance()
9727 if (!busiest->active_balance) { in load_balance()
9728 busiest->active_balance = 1; in load_balance()
9729 busiest->push_cpu = this_cpu; in load_balance()
9732 raw_spin_unlock_irqrestore(&busiest->lock, flags); in load_balance()
9737 &busiest->active_balance_work); in load_balance()
9741 sd->nr_balance_failed = sd->cache_nice_tries+1; in load_balance()
9744 sd->nr_balance_failed = 0; in load_balance()
9748 sd->balance_interval = sd->min_interval; in load_balance()
9756 if (sd->balance_interval < sd->max_interval) in load_balance()
9757 sd->balance_interval *= 2; in load_balance()
9769 int *group_imbalance = &sd_parent->groups->sgc->imbalance; in load_balance()
9781 schedstat_inc(sd->lb_balanced[idle]); in load_balance()
9783 sd->nr_balance_failed = 0; in load_balance()
9799 sd->balance_interval < MAX_PINNED_INTERVAL) || in load_balance()
9800 sd->balance_interval < sd->max_interval) in load_balance()
9801 sd->balance_interval *= 2; in load_balance()
9809 unsigned long interval = sd->balance_interval; in get_sd_balance_interval()
9812 interval *= sd->busy_factor; in get_sd_balance_interval()
9823 interval -= 1; in get_sd_balance_interval()
9837 next = sd->last_balance + interval; in update_next_balance()
9853 int target_cpu = busiest_rq->push_cpu; in active_load_balance_cpu_stop()
9861 * Between queueing the stop-work and running it is a hole in which in active_load_balance_cpu_stop()
9870 !busiest_rq->active_balance)) in active_load_balance_cpu_stop()
9874 if (busiest_rq->nr_running <= 1) in active_load_balance_cpu_stop()
9880 * Bjorn Helgaas on a 128-CPU setup. in active_load_balance_cpu_stop()
9896 .src_cpu = busiest_rq->cpu, in active_load_balance_cpu_stop()
9908 schedstat_inc(sd->alb_count); in active_load_balance_cpu_stop()
9913 schedstat_inc(sd->alb_pushed); in active_load_balance_cpu_stop()
9915 sd->nr_balance_failed = 0; in active_load_balance_cpu_stop()
9917 schedstat_inc(sd->alb_failed); in active_load_balance_cpu_stop()
9922 busiest_rq->active_balance = 0; in active_load_balance_cpu_stop()
9937 * This trades load-balance latency on larger machines for less cross talk.
9953 int cpu = rq->cpu; in rebalance_domains()
9969 if (time_after(jiffies, sd->next_decay_max_lb_cost)) { in rebalance_domains()
9970 sd->max_newidle_lb_cost = in rebalance_domains()
9971 (sd->max_newidle_lb_cost * 253) / 256; in rebalance_domains()
9972 sd->next_decay_max_lb_cost = jiffies + HZ; in rebalance_domains()
9975 max_cost += sd->max_newidle_lb_cost; in rebalance_domains()
9990 need_serialize = sd->flags & SD_SERIALIZE; in rebalance_domains()
9996 if (time_after_eq(jiffies, sd->last_balance + interval)) { in rebalance_domains()
10000 * env->dst_cpu, so we can't know our idle in rebalance_domains()
10006 sd->last_balance = jiffies; in rebalance_domains()
10012 if (time_after(next_balance, sd->last_balance + interval)) { in rebalance_domains()
10013 next_balance = sd->last_balance + interval; in rebalance_domains()
10019 * Ensure the rq-wide value also decays but keep it at a in rebalance_domains()
10020 * reasonable floor to avoid funnies with rq->avg_idle. in rebalance_domains()
10022 rq->max_idle_balance_cost = in rebalance_domains()
10033 rq->next_balance = next_balance; in rebalance_domains()
10044 if ((idle == CPU_IDLE) && time_after(nohz.next_balance, rq->next_balance)) in rebalance_domains()
10045 nohz.next_balance = rq->next_balance; in rebalance_domains()
10052 return unlikely(!rcu_dereference_sched(rq->sd)); in on_null_domain()
10058 * - When one of the busy CPUs notice that there may be an idle rebalancing
10061 * - HK_FLAG_MISC CPUs are used for this task, because HK_FLAG_SCHED not set
10111 smp_call_function_single_async(ilb_cpu, &cpu_rq(ilb_cpu)->nohz_csd); in kick_ilb()
10123 int nr_busy, i, cpu = rq->cpu; in nohz_balancer_kick()
10126 if (unlikely(rq->idle_balance)) in nohz_balancer_kick()
10149 if (rq->nr_running >= 2) { in nohz_balancer_kick()
10156 sd = rcu_dereference(rq->sd); in nohz_balancer_kick()
10163 if (rq->cfs.h_nr_running >= 1 && check_cpu_capacity(rq, sd)) { in nohz_balancer_kick()
10209 * increase the overall cache use), we need some less-loaded LLC in nohz_balancer_kick()
10213 * the others are - so just get a nohz balance going if it looks in nohz_balancer_kick()
10216 nr_busy = atomic_read(&sds->nr_busy_cpus); in nohz_balancer_kick()
10236 if (!sd || !sd->nohz_idle) in set_cpu_sd_state_busy()
10238 sd->nohz_idle = 0; in set_cpu_sd_state_busy()
10240 atomic_inc(&sd->shared->nr_busy_cpus); in set_cpu_sd_state_busy()
10249 if (likely(!rq->nohz_tick_stopped)) in nohz_balance_exit_idle()
10252 rq->nohz_tick_stopped = 0; in nohz_balance_exit_idle()
10253 cpumask_clear_cpu(rq->cpu, nohz.idle_cpus_mask); in nohz_balance_exit_idle()
10256 set_cpu_sd_state_busy(rq->cpu); in nohz_balance_exit_idle()
10266 if (!sd || sd->nohz_idle) in set_cpu_sd_state_idle()
10268 sd->nohz_idle = 1; in set_cpu_sd_state_idle()
10270 atomic_dec(&sd->shared->nr_busy_cpus); in set_cpu_sd_state_idle()
10294 * Can be set safely without rq->lock held in nohz_balance_enter_idle()
10296 * rq->lock is held during the check and the clear in nohz_balance_enter_idle()
10298 rq->has_blocked_load = 1; in nohz_balance_enter_idle()
10306 if (rq->nohz_tick_stopped) in nohz_balance_enter_idle()
10313 rq->nohz_tick_stopped = 1; in nohz_balance_enter_idle()
10350 int this_cpu = this_rq->cpu; in _nohz_idle_balance()
10395 if (time_after_eq(jiffies, rq->next_balance)) { in _nohz_idle_balance()
10406 if (time_after(next_balance, rq->next_balance)) { in _nohz_idle_balance()
10407 next_balance = rq->next_balance; in _nohz_idle_balance()
10423 has_blocked_load |= this_rq->has_blocked_load; in _nohz_idle_balance()
10449 unsigned int flags = this_rq->nohz_idle_balance; in nohz_idle_balance()
10454 this_rq->nohz_idle_balance = 0; in nohz_idle_balance()
10466 int this_cpu = this_rq->cpu; in nohz_newidle_balance()
10476 if (this_rq->avg_idle < sysctl_sched_migration_cost) in nohz_newidle_balance()
10484 raw_spin_unlock(&this_rq->lock); in nohz_newidle_balance()
10493 raw_spin_lock(&this_rq->lock); in nohz_newidle_balance()
10512 * < 0 - we released the lock and there are !fair tasks present
10513 * 0 - failed, no new tasks
10514 * > 0 - success, new (fair) tasks present
10519 int this_cpu = this_rq->cpu; in newidle_balance()
10529 this_rq->idle_stamp = rq_clock(this_rq); in newidle_balance()
10539 * for load-balance and preemption/IRQs are still disabled avoiding in newidle_balance()
10541 * re-start the picking loop. in newidle_balance()
10545 if (this_rq->avg_idle < sysctl_sched_migration_cost || in newidle_balance()
10546 !READ_ONCE(this_rq->rd->overload)) { in newidle_balance()
10549 sd = rcu_dereference_check_sched_domain(this_rq->sd); in newidle_balance()
10559 raw_spin_unlock(&this_rq->lock); in newidle_balance()
10567 if (this_rq->avg_idle < curr_cost + sd->max_newidle_lb_cost) { in newidle_balance()
10572 if (sd->flags & SD_BALANCE_NEWIDLE) { in newidle_balance()
10579 domain_cost = sched_clock_cpu(this_cpu) - t0; in newidle_balance()
10580 if (domain_cost > sd->max_newidle_lb_cost) in newidle_balance()
10581 sd->max_newidle_lb_cost = domain_cost; in newidle_balance()
10592 if (pulled_task || this_rq->nr_running > 0) in newidle_balance()
10597 raw_spin_lock(&this_rq->lock); in newidle_balance()
10599 if (curr_cost > this_rq->max_idle_balance_cost) in newidle_balance()
10600 this_rq->max_idle_balance_cost = curr_cost; in newidle_balance()
10608 if (this_rq->cfs.h_nr_running && !pulled_task) in newidle_balance()
10612 if (time_after(this_rq->next_balance, next_balance)) in newidle_balance()
10613 this_rq->next_balance = next_balance; in newidle_balance()
10616 if (this_rq->nr_running != this_rq->cfs.h_nr_running) in newidle_balance()
10617 pulled_task = -1; in newidle_balance()
10620 this_rq->idle_stamp = 0; in newidle_balance()
10634 enum cpu_idle_type idle = this_rq->idle_balance ? in run_rebalance_domains()
10649 update_blocked_averages(this_rq->cpu); in run_rebalance_domains()
10662 if (time_after_eq(jiffies, rq->next_balance)) in trigger_load_balance()
10696 struct sched_entity *se = &curr->se; in task_tick_fair()
10712 * - child not yet on the tasklist
10713 * - preemption disabled
10718 struct sched_entity *se = &p->se, *curr; in task_fork_fair()
10726 curr = cfs_rq->curr; in task_fork_fair()
10729 se->vruntime = curr->vruntime; in task_fork_fair()
10738 swap(curr->vruntime, se->vruntime); in task_fork_fair()
10742 se->vruntime -= cfs_rq->min_vruntime; in task_fork_fair()
10756 if (rq->cfs.nr_running == 1) in prio_changed_fair()
10764 if (rq->curr == p) { in prio_changed_fair()
10765 if (p->prio > oldprio) in prio_changed_fair()
10773 struct sched_entity *se = &p->se; in vruntime_normalized()
10780 if (p->on_rq) in vruntime_normalized()
10787 * - A forked child which is waiting for being woken up by in vruntime_normalized()
10789 * - A task which has been woken up by try_to_wake_up() and in vruntime_normalized()
10792 if (!se->sum_exec_runtime || in vruntime_normalized()
10793 (p->state == TASK_WAKING && p->sched_remote_wakeup)) in vruntime_normalized()
10809 se = se->parent; in propagate_entity_cfs_rq()
10841 * Since the real-depth could have been changed (only FAIR in attach_entity_cfs_rq()
10844 se->depth = se->parent ? se->parent->depth + 1 : 0; in attach_entity_cfs_rq()
10856 struct sched_entity *se = &p->se; in detach_task_cfs_rq()
10865 se->vruntime -= cfs_rq->min_vruntime; in detach_task_cfs_rq()
10873 struct sched_entity *se = &p->se; in attach_task_cfs_rq()
10879 se->vruntime += cfs_rq->min_vruntime; in attach_task_cfs_rq()
10897 if (rq->curr == p) in switched_to_fair()
10906 * This routine is mostly called to set cfs_rq->curr field when a task
10911 struct sched_entity *se = &p->se; in set_next_task_fair()
10919 list_move(&se->group_node, &rq->cfs_tasks); in set_next_task_fair()
10934 cfs_rq->tasks_timeline = RB_ROOT_CACHED; in init_cfs_rq()
10935 cfs_rq->min_vruntime = (u64)(-(1LL << 20)); in init_cfs_rq()
10937 cfs_rq->min_vruntime_copy = cfs_rq->min_vruntime; in init_cfs_rq()
10940 raw_spin_lock_init(&cfs_rq->removed.lock); in init_cfs_rq()
10947 struct sched_entity *se = &p->se; in task_set_group_fair()
10950 se->depth = se->parent ? se->parent->depth + 1 : 0; in task_set_group_fair()
10959 /* Tell se's cfs_rq has been changed -- migrated */ in task_move_group_fair()
10960 p->se.avg.last_update_time = 0; in task_move_group_fair()
10985 if (tg->cfs_rq) in free_fair_sched_group()
10986 kfree(tg->cfs_rq[i]); in free_fair_sched_group()
10987 if (tg->se) in free_fair_sched_group()
10988 kfree(tg->se[i]); in free_fair_sched_group()
10991 kfree(tg->cfs_rq); in free_fair_sched_group()
10992 kfree(tg->se); in free_fair_sched_group()
11001 tg->cfs_rq = kcalloc(nr_cpu_ids, sizeof(cfs_rq), GFP_KERNEL); in alloc_fair_sched_group()
11002 if (!tg->cfs_rq) in alloc_fair_sched_group()
11004 tg->se = kcalloc(nr_cpu_ids, sizeof(se), GFP_KERNEL); in alloc_fair_sched_group()
11005 if (!tg->se) in alloc_fair_sched_group()
11008 tg->shares = NICE_0_LOAD; in alloc_fair_sched_group()
11024 init_tg_cfs_entry(tg, cfs_rq, se, i, parent->se[i]); in alloc_fair_sched_group()
11045 se = tg->se[i]; in online_fair_sched_group()
11061 if (tg->se[cpu]) in unregister_fair_sched_group()
11062 remove_entity_load_avg(tg->se[cpu]); in unregister_fair_sched_group()
11066 * check on_list without danger of it being re-added. in unregister_fair_sched_group()
11068 if (!tg->cfs_rq[cpu]->on_list) in unregister_fair_sched_group()
11073 raw_spin_lock_irqsave(&rq->lock, flags); in unregister_fair_sched_group()
11074 list_del_leaf_cfs_rq(tg->cfs_rq[cpu]); in unregister_fair_sched_group()
11075 raw_spin_unlock_irqrestore(&rq->lock, flags); in unregister_fair_sched_group()
11085 cfs_rq->tg = tg; in init_tg_cfs_entry()
11086 cfs_rq->rq = rq; in init_tg_cfs_entry()
11089 tg->cfs_rq[cpu] = cfs_rq; in init_tg_cfs_entry()
11090 tg->se[cpu] = se; in init_tg_cfs_entry()
11097 se->cfs_rq = &rq->cfs; in init_tg_cfs_entry()
11098 se->depth = 0; in init_tg_cfs_entry()
11100 se->cfs_rq = parent->my_q; in init_tg_cfs_entry()
11101 se->depth = parent->depth + 1; in init_tg_cfs_entry()
11104 se->my_q = cfs_rq; in init_tg_cfs_entry()
11106 update_load_set(&se->load, NICE_0_LOAD); in init_tg_cfs_entry()
11107 se->parent = parent; in init_tg_cfs_entry()
11119 if (!tg->se[0]) in sched_group_set_shares()
11120 return -EINVAL; in sched_group_set_shares()
11125 if (tg->shares == shares) in sched_group_set_shares()
11128 tg->shares = shares; in sched_group_set_shares()
11131 struct sched_entity *se = tg->se[i]; in sched_group_set_shares()
11166 struct sched_entity *se = &task->se; in get_rr_interval_fair()
11173 if (rq->cfs.load.weight) in get_rr_interval_fair()
11246 ng = rcu_dereference(p->numa_group); in show_numa_stats()
11248 if (p->numa_faults) { in show_numa_stats()
11249 tsf = p->numa_faults[task_faults_idx(NUMA_MEM, node, 0)]; in show_numa_stats()
11250 tpf = p->numa_faults[task_faults_idx(NUMA_MEM, node, 1)]; in show_numa_stats()
11253 gsf = ng->faults[task_faults_idx(NUMA_MEM, node, 0)], in show_numa_stats()
11254 gpf = ng->faults[task_faults_idx(NUMA_MEM, node, 1)]; in show_numa_stats()
11284 return cfs_rq ? &cfs_rq->avg : NULL; in sched_trace_cfs_rq_avg()
11307 return cfs_rq ? cpu_of(rq_of(cfs_rq)) : -1; in sched_trace_cfs_rq_cpu()
11314 return rq ? &rq->avg_rt : NULL; in sched_trace_rq_avg_rt()
11324 return rq ? &rq->avg_dl : NULL; in sched_trace_rq_avg_dl()
11334 return rq ? &rq->avg_irq : NULL; in sched_trace_rq_avg_irq()
11343 return rq ? cpu_of(rq) : -1; in sched_trace_rq_cpu()
11351 rq->cpu_capacity in sched_trace_rq_cpu_capacity()
11355 : -1; in sched_trace_rq_cpu_capacity()
11362 return rd ? rd->span : NULL; in sched_trace_rd_span()
11371 return rq ? rq->nr_running : -1; in sched_trace_rq_nr_running()