Lines Matching +full:acquisition +full:- +full:time +full:- +full:ns
1 // SPDX-License-Identifier: GPL-2.0
43 #include <linux/memory-tiers.h>
61 * The initial- and re-scaling of tunables is configurable
65 * SCHED_TUNABLESCALING_NONE - unscaled, always *1
66 * SCHED_TUNABLESCALING_LOG - scaled logarithmical, *1+ilog(ncpus)
67 * SCHED_TUNABLESCALING_LINEAR - scaled linear, *ncpus
74 * Minimal preemption granularity for CPU-bound tasks:
108 return -cpu; in arch_asym_cpu_priority()
129 * Amount of runtime to allocate from global (tg) to local (per-cfs_rq) pool
130 * each time a cfs_rq requests quota.
134 * we will always only issue the remaining available time.
188 lw->weight += inc; in update_load_add()
189 lw->inv_weight = 0; in update_load_add()
194 lw->weight -= dec; in update_load_sub()
195 lw->inv_weight = 0; in update_load_sub()
200 lw->weight = w; in update_load_set()
201 lw->inv_weight = 0; in update_load_set()
208 * so pick a second-best guess by going with the log2 of the
256 if (likely(lw->inv_weight)) in __update_inv_weight()
259 w = scale_load_down(lw->weight); in __update_inv_weight()
262 lw->inv_weight = 1; in __update_inv_weight()
264 lw->inv_weight = WMULT_CONST; in __update_inv_weight()
266 lw->inv_weight = WMULT_CONST / w; in __update_inv_weight()
272 * (delta_exec * (weight * lw->inv_weight)) >> WMULT_SHIFT
292 shift -= fs; in __calc_delta()
296 fact = mul_u32_u32(fact, lw->inv_weight); in __calc_delta()
301 shift -= fs; in __calc_delta()
313 if (unlikely(se->load.weight != NICE_0_LOAD)) in calc_delta_fair()
314 delta = __calc_delta(delta, NICE_0_LOAD, &se->load); in calc_delta_fair()
329 for (; se; se = se->parent)
336 if (cfs_rq->on_list) in list_add_leaf_cfs_rq()
337 return rq->tmp_alone_branch == &rq->leaf_cfs_rq_list; in list_add_leaf_cfs_rq()
339 cfs_rq->on_list = 1; in list_add_leaf_cfs_rq()
344 * enqueued. The fact that we always enqueue bottom-up in list_add_leaf_cfs_rq()
350 if (cfs_rq->tg->parent && in list_add_leaf_cfs_rq()
351 cfs_rq->tg->parent->cfs_rq[cpu]->on_list) { in list_add_leaf_cfs_rq()
358 list_add_tail_rcu(&cfs_rq->leaf_cfs_rq_list, in list_add_leaf_cfs_rq()
359 &(cfs_rq->tg->parent->cfs_rq[cpu]->leaf_cfs_rq_list)); in list_add_leaf_cfs_rq()
365 rq->tmp_alone_branch = &rq->leaf_cfs_rq_list; in list_add_leaf_cfs_rq()
369 if (!cfs_rq->tg->parent) { in list_add_leaf_cfs_rq()
374 list_add_tail_rcu(&cfs_rq->leaf_cfs_rq_list, in list_add_leaf_cfs_rq()
375 &rq->leaf_cfs_rq_list); in list_add_leaf_cfs_rq()
380 rq->tmp_alone_branch = &rq->leaf_cfs_rq_list; in list_add_leaf_cfs_rq()
390 list_add_rcu(&cfs_rq->leaf_cfs_rq_list, rq->tmp_alone_branch); in list_add_leaf_cfs_rq()
395 rq->tmp_alone_branch = &cfs_rq->leaf_cfs_rq_list; in list_add_leaf_cfs_rq()
401 if (cfs_rq->on_list) { in list_del_leaf_cfs_rq()
408 * to the prev element but it will point to rq->leaf_cfs_rq_list in list_del_leaf_cfs_rq()
411 if (rq->tmp_alone_branch == &cfs_rq->leaf_cfs_rq_list) in list_del_leaf_cfs_rq()
412 rq->tmp_alone_branch = cfs_rq->leaf_cfs_rq_list.prev; in list_del_leaf_cfs_rq()
414 list_del_rcu(&cfs_rq->leaf_cfs_rq_list); in list_del_leaf_cfs_rq()
415 cfs_rq->on_list = 0; in list_del_leaf_cfs_rq()
421 SCHED_WARN_ON(rq->tmp_alone_branch != &rq->leaf_cfs_rq_list); in assert_list_leaf_cfs_rq()
426 list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list, \
433 if (se->cfs_rq == pse->cfs_rq) in is_same_group()
434 return se->cfs_rq; in is_same_group()
441 return se->parent; in parent_entity()
457 se_depth = (*se)->depth; in find_matching_se()
458 pse_depth = (*pse)->depth; in find_matching_se()
461 se_depth--; in find_matching_se()
466 pse_depth--; in find_matching_se()
478 return tg->idle > 0; in tg_is_idle()
483 return cfs_rq->idle > 0; in cfs_rq_is_idle()
512 for (cfs_rq = &rq->cfs, pos = NULL; cfs_rq; cfs_rq = pos)
550 s64 delta = (s64)(vruntime - max_vruntime); in max_vruntime()
559 s64 delta = (s64)(vruntime - min_vruntime); in min_vruntime()
569 return (s64)(a->vruntime - b->vruntime) < 0; in entity_before()
574 return (s64)(se->vruntime - cfs_rq->min_vruntime); in entity_key()
581 * Compute virtual time from the per-task service numbers:
589 * lag_i = S - s_i = w_i * (V - v_i)
591 * Where S is the ideal service time and V is it's virtual time counterpart.
595 * \Sum w_i * (V - v_i) = 0
596 * \Sum w_i * V - w_i * v_i = 0
599 * se->vruntime):
602 * V = -------------- = --------------
609 * virtual time has non-continguous motion equivalent to:
611 * V +-= lag_i / W
618 * Substitute: v_i == (v_i - v0) + v0
620 * \Sum ((v_i - v0) + v0) * w_i \Sum (v_i - v0) * w_i
621 * V = ---------------------------- = --------------------- + v0
626 * v0 := cfs_rq->min_vruntime
627 * \Sum (v_i - v0) * w_i := cfs_rq->avg_vruntime
628 * \Sum w_i := cfs_rq->avg_load
631 * the per-task service, these deltas: (v_i - v), will be in the order of the
641 unsigned long weight = scale_load_down(se->load.weight); in avg_vruntime_add()
644 cfs_rq->avg_vruntime += key * weight; in avg_vruntime_add()
645 cfs_rq->avg_load += weight; in avg_vruntime_add()
651 unsigned long weight = scale_load_down(se->load.weight); in avg_vruntime_sub()
654 cfs_rq->avg_vruntime -= key * weight; in avg_vruntime_sub()
655 cfs_rq->avg_load -= weight; in avg_vruntime_sub()
662 * v' = v + d ==> avg_vruntime' = avg_runtime - d*avg_load in avg_vruntime_update()
664 cfs_rq->avg_vruntime -= cfs_rq->avg_load * delta; in avg_vruntime_update()
673 struct sched_entity *curr = cfs_rq->curr; in avg_vruntime()
674 s64 avg = cfs_rq->avg_vruntime; in avg_vruntime()
675 long load = cfs_rq->avg_load; in avg_vruntime()
677 if (curr && curr->on_rq) { in avg_vruntime()
678 unsigned long weight = scale_load_down(curr->load.weight); in avg_vruntime()
687 avg -= (load - 1); in avg_vruntime()
691 return cfs_rq->min_vruntime + avg; in avg_vruntime()
695 * lag_i = S - s_i = w_i * (V - v_i)
698 * is possible -- by addition/removal/reweight to the tree -- to move V around
706 * -r_max < lag < max(r_max, q)
714 SCHED_WARN_ON(!se->on_rq); in update_entity_lag()
715 lag = avg_vruntime(cfs_rq) - se->vruntime; in update_entity_lag()
717 limit = calc_delta_fair(max_t(u64, 2*se->slice, TICK_NSEC), se); in update_entity_lag()
718 se->vlag = clamp(lag, -limit, limit); in update_entity_lag()
725 * lag_i = S - s_i = w_i*(V - v_i)
727 * lag_i >= 0 -> V >= v_i
729 * \Sum (v_i - v)*w_i
730 * V = ------------------ + v
733 * lag_i >= 0 -> \Sum (v_i - v)*w_i >= (v_i - v)*(\Sum w_i)
735 * Note: using 'avg_vruntime() > se->vruntime' is inacurate due
740 struct sched_entity *curr = cfs_rq->curr; in entity_eligible()
741 s64 avg = cfs_rq->avg_vruntime; in entity_eligible()
742 long load = cfs_rq->avg_load; in entity_eligible()
744 if (curr && curr->on_rq) { in entity_eligible()
745 unsigned long weight = scale_load_down(curr->load.weight); in entity_eligible()
756 u64 min_vruntime = cfs_rq->min_vruntime; in __update_min_vruntime()
760 s64 delta = (s64)(vruntime - min_vruntime); in __update_min_vruntime()
771 struct sched_entity *curr = cfs_rq->curr; in update_min_vruntime()
773 u64 vruntime = cfs_rq->min_vruntime; in update_min_vruntime()
776 if (curr->on_rq) in update_min_vruntime()
777 vruntime = curr->vruntime; in update_min_vruntime()
784 vruntime = se->vruntime; in update_min_vruntime()
786 vruntime = min_vruntime(vruntime, se->vruntime); in update_min_vruntime()
789 /* ensure we never gain time by being placed backwards. */ in update_min_vruntime()
790 u64_u32_store(cfs_rq->min_vruntime, in update_min_vruntime()
799 #define deadline_gt(field, lse, rse) ({ (s64)((lse)->field - (rse)->field) > 0; })
806 se->min_deadline = rse->min_deadline; in __update_min_deadline()
811 * se->min_deadline = min(se->deadline, left->min_deadline, right->min_deadline)
815 u64 old_min_deadline = se->min_deadline; in min_deadline_update()
816 struct rb_node *node = &se->run_node; in min_deadline_update()
818 se->min_deadline = se->deadline; in min_deadline_update()
819 __update_min_deadline(se, node->rb_right); in min_deadline_update()
820 __update_min_deadline(se, node->rb_left); in min_deadline_update()
822 return se->min_deadline == old_min_deadline; in min_deadline_update()
829 * Enqueue an entity into the rb-tree:
834 se->min_deadline = se->deadline; in __enqueue_entity()
835 rb_add_augmented_cached(&se->run_node, &cfs_rq->tasks_timeline, in __enqueue_entity()
841 rb_erase_augmented_cached(&se->run_node, &cfs_rq->tasks_timeline, in __dequeue_entity()
848 struct rb_node *left = rb_first_cached(&cfs_rq->tasks_timeline); in __pick_first_entity()
867 * We can do this in O(log n) time due to an augmented RB-tree. The
871 * se->min_deadline = min(se->deadline, se->{left,right}->min_deadline)
877 struct rb_node *node = cfs_rq->tasks_timeline.rb_root.rb_node; in __pick_eevdf()
878 struct sched_entity *curr = cfs_rq->curr; in __pick_eevdf()
882 if (curr && (!curr->on_rq || !entity_eligible(cfs_rq, curr))) in __pick_eevdf()
887 * Once selected, run a task until it either becomes non-eligible or in __pick_eevdf()
890 if (sched_feat(RUN_TO_PARITY) && curr && curr->vlag == curr->deadline) in __pick_eevdf()
900 node = node->rb_left; in __pick_eevdf()
914 if (node->rb_left) { in __pick_eevdf()
915 struct sched_entity *left = __node_2_se(node->rb_left); in __pick_eevdf()
925 if (left->min_deadline == se->min_deadline) in __pick_eevdf()
930 if (se->deadline == se->min_deadline) in __pick_eevdf()
934 node = node->rb_right; in __pick_eevdf()
941 if (!best_left || (s64)(best_left->min_deadline - best->deadline) > 0) in __pick_eevdf()
948 node = &best_left->run_node; in __pick_eevdf()
953 if (se->deadline == se->min_deadline) in __pick_eevdf()
957 if (node->rb_left && in __pick_eevdf()
958 __node_2_se(node->rb_left)->min_deadline == se->min_deadline) { in __pick_eevdf()
959 node = node->rb_left; in __pick_eevdf()
964 node = node->rb_right; in __pick_eevdf()
987 struct rb_node *last = rb_last(&cfs_rq->tasks_timeline.rb_root); in __pick_last_entity()
1021 if ((s64)(se->vruntime - se->deadline) < 0) in update_deadline()
1025 * For EEVDF the virtual time slope is determined by w_i (iow. in update_deadline()
1026 * nice) while the request time r_i is determined by in update_deadline()
1029 se->slice = sysctl_sched_base_slice; in update_deadline()
1034 se->deadline = se->vruntime + calc_delta_fair(se->slice, se); in update_deadline()
1039 if (cfs_rq->nr_running > 1) { in update_deadline()
1052 /* Give new sched_entity start runnable values to heavy its load in infant time */
1055 struct sched_avg *sa = &se->avg; in init_entity_runnable_average()
1066 sa->load_avg = scale_load_down(se->load.weight); in init_entity_runnable_average()
1075 * util_avg = cfs_rq->util_avg / (cfs_rq->load_avg + 1) * se.load.weight
1084 * util_avg_cap = (cpu_scale - cfs_rq->avg.util_avg) / 2^n
1099 struct sched_entity *se = &p->se; in post_init_entity_util_avg()
1101 struct sched_avg *sa = &se->avg; in post_init_entity_util_avg()
1103 long cap = (long)(cpu_scale - cfs_rq->avg.util_avg) / 2; in post_init_entity_util_avg()
1105 if (p->sched_class != &fair_sched_class) { in post_init_entity_util_avg()
1116 se->avg.last_update_time = cfs_rq_clock_pelt(cfs_rq); in post_init_entity_util_avg()
1121 if (cfs_rq->avg.util_avg != 0) { in post_init_entity_util_avg()
1122 sa->util_avg = cfs_rq->avg.util_avg * se->load.weight; in post_init_entity_util_avg()
1123 sa->util_avg /= (cfs_rq->avg.load_avg + 1); in post_init_entity_util_avg()
1125 if (sa->util_avg > cap) in post_init_entity_util_avg()
1126 sa->util_avg = cap; in post_init_entity_util_avg()
1128 sa->util_avg = cap; in post_init_entity_util_avg()
1132 sa->runnable_avg = sa->util_avg; in post_init_entity_util_avg()
1152 struct sched_entity *curr = cfs_rq->curr; in update_curr()
1159 delta_exec = now - curr->exec_start; in update_curr()
1163 curr->exec_start = now; in update_curr()
1169 __schedstat_set(stats->exec_max, in update_curr()
1170 max(delta_exec, stats->exec_max)); in update_curr()
1173 curr->sum_exec_runtime += delta_exec; in update_curr()
1174 schedstat_add(cfs_rq->exec_clock, delta_exec); in update_curr()
1176 curr->vruntime += calc_delta_fair(delta_exec, curr); in update_curr()
1183 trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime); in update_curr()
1193 update_curr(cfs_rq_of(&rq->curr->se)); in update_curr_fair()
1226 * maybe already in the runqueue, the se->statistics.wait_start in update_stats_wait_end_fair()
1230 if (unlikely(!schedstat_val(stats->wait_start))) in update_stats_wait_end_fair()
1257 * Task is being enqueued - update stats:
1269 if (se != cfs_rq->curr) in update_stats_enqueue_fair()
1287 if (se != cfs_rq->curr) in update_stats_dequeue_fair()
1295 state = READ_ONCE(tsk->__state); in update_stats_dequeue_fair()
1297 __schedstat_set(tsk->stats.sleep_start, in update_stats_dequeue_fair()
1300 __schedstat_set(tsk->stats.block_start, in update_stats_dequeue_fair()
1306 * We are picking a new current task - update its stats:
1314 se->exec_start = rq_clock_task(rq_of(cfs_rq)); in update_stats_curr_start()
1367 * Approximate time to scan a full NUMA task in ms. The task scan period is
1406 * ->numa_group (see struct task_struct for locking rules).
1410 return rcu_dereference_check(p->numa_group, p == current || in deref_task_numa_group()
1411 (lockdep_is_held(__rq_lockp(task_rq(p))) && !READ_ONCE(p->on_cpu))); in deref_task_numa_group()
1416 return rcu_dereference_protected(p->numa_group, p == current); in deref_curr_numa_group()
1428 * Calculations based on RSS as non-present and empty pages are skipped in task_nr_scan_windows()
1432 nr_scan_pages = sysctl_numa_balancing_scan_size << (20 - PAGE_SHIFT); in task_nr_scan_windows()
1433 rss = get_mm_rss(p->mm); in task_nr_scan_windows()
1466 ng = rcu_dereference(p->numa_group); in task_scan_start()
1471 period *= refcount_read(&ng->refcount); in task_scan_start()
1496 period *= refcount_read(&ng->refcount); in task_scan_max()
1508 rq->nr_numa_running += (p->numa_preferred_nid != NUMA_NO_NODE); in account_numa_enqueue()
1509 rq->nr_preferred_running += (p->numa_preferred_nid == task_node(p)); in account_numa_enqueue()
1514 rq->nr_numa_running -= (p->numa_preferred_nid != NUMA_NO_NODE); in account_numa_dequeue()
1515 rq->nr_preferred_running -= (p->numa_preferred_nid == task_node(p)); in account_numa_dequeue()
1533 ng = rcu_dereference(p->numa_group); in task_numa_group_id()
1535 gid = ng->gid; in task_numa_group_id()
1554 if (!p->numa_faults) in task_faults()
1557 return p->numa_faults[task_faults_idx(NUMA_MEM, nid, 0)] + in task_faults()
1558 p->numa_faults[task_faults_idx(NUMA_MEM, nid, 1)]; in task_faults()
1568 return ng->faults[task_faults_idx(NUMA_MEM, nid, 0)] + in group_faults()
1569 ng->faults[task_faults_idx(NUMA_MEM, nid, 1)]; in group_faults()
1574 return group->faults[task_faults_idx(NUMA_CPU, nid, 0)] + in group_faults_cpu()
1575 group->faults[task_faults_idx(NUMA_CPU, nid, 1)]; in group_faults_cpu()
1584 faults += ng->faults[task_faults_idx(NUMA_MEM, node, 1)]; in group_faults_priv()
1596 faults += ng->faults[task_faults_idx(NUMA_MEM, node, 0)]; in group_faults_shared()
1604 * considered part of a numa group's pseudo-interleaving set. Migrations
1611 return group_faults_cpu(ng, nid) * ACTIVE_NODE_FRACTION > ng->max_faults_cpu; in numa_is_active_node()
1670 faults *= (max_dist - dist); in score_nearby_nodes()
1671 faults /= (max_dist - LOCAL_DISTANCE); in score_nearby_nodes()
1691 if (!p->numa_faults) in task_weight()
1694 total_faults = p->total_numa_faults; in task_weight()
1714 total_faults = ng->total_faults; in group_weight()
1727 * used to record scan time instead of CPU and PID. When tiering mode
1728 * is disabled at run time, the scan time (in cpupid) will be
1750 pgdat->node_present_pages >> 4); in pgdat_free_space_enough()
1751 for (z = pgdat->nr_zones - 1; z >= 0; z--) { in pgdat_free_space_enough()
1752 struct zone *zone = pgdat->node_zones + z; in pgdat_free_space_enough()
1767 * time will be recorded in struct page in addition to make page
1772 * hint page fault latency = hint page fault time - scan time
1779 int last_time, time; in numa_hint_fault_latency() local
1781 time = jiffies_to_msecs(jiffies); in numa_hint_fault_latency()
1782 last_time = xchg_page_access_time(page, time); in numa_hint_fault_latency()
1784 return (time - last_time) & PAGE_ACCESS_TIME_MASK; in numa_hint_fault_latency()
1801 start = pgdat->nbp_rl_start; in numa_promotion_rate_limit()
1802 if (now - start > MSEC_PER_SEC && in numa_promotion_rate_limit()
1803 cmpxchg(&pgdat->nbp_rl_start, start, now) == start) in numa_promotion_rate_limit()
1804 pgdat->nbp_rl_nr_cand = nr_cand; in numa_promotion_rate_limit()
1805 if (nr_cand - pgdat->nbp_rl_nr_cand >= rate_limit) in numa_promotion_rate_limit()
1821 start = pgdat->nbp_th_start; in numa_promotion_adjust_threshold()
1822 if (now - start > th_period && in numa_promotion_adjust_threshold()
1823 cmpxchg(&pgdat->nbp_th_start, start, now) == start) { in numa_promotion_adjust_threshold()
1827 diff_cand = nr_cand - pgdat->nbp_th_nr_cand; in numa_promotion_adjust_threshold()
1829 th = pgdat->nbp_threshold ? : ref_th; in numa_promotion_adjust_threshold()
1831 th = max(th - unit_th, unit_th); in numa_promotion_adjust_threshold()
1834 pgdat->nbp_th_nr_cand = nr_cand; in numa_promotion_adjust_threshold()
1835 pgdat->nbp_threshold = th; in numa_promotion_adjust_threshold()
1859 pgdat->nbp_threshold = 0; in should_numa_migrate_memory()
1865 (20 - PAGE_SHIFT); in should_numa_migrate_memory()
1868 th = pgdat->nbp_threshold ? : def_th; in should_numa_migrate_memory()
1877 this_cpupid = cpu_pid_to_cpupid(dst_cpu, current->pid); in should_numa_migrate_memory()
1887 * two full passes of the "multi-stage node selection" test that is in should_numa_migrate_memory()
1890 if ((p->numa_preferred_nid == NUMA_NO_NODE || p->numa_scan_seq <= 4) && in should_numa_migrate_memory()
1895 * Multi-stage node selection is used in conjunction with a periodic in should_numa_migrate_memory()
1896 * migration fault to build a temporal task<->page relation. By using in should_numa_migrate_memory()
1897 * a two-stage filter we remove short/unlikely relations. in should_numa_migrate_memory()
1901 * page (n_t) (in a given time-span) to a probability. in should_numa_migrate_memory()
1909 * act on an unlikely task<->page relation. in should_numa_migrate_memory()
1919 /* A shared fault, but p->numa_group has not been set up yet. */ in should_numa_migrate_memory()
1936 * --------------- * - > --------------- in should_numa_migrate_memory()
1996 struct numa_stats *ns) in numa_classify() argument
1998 if ((ns->nr_running > ns->weight) && in numa_classify()
1999 (((ns->compute_capacity * 100) < (ns->util * imbalance_pct)) || in numa_classify()
2000 ((ns->compute_capacity * imbalance_pct) < (ns->runnable * 100)))) in numa_classify()
2003 if ((ns->nr_running < ns->weight) || in numa_classify()
2004 (((ns->compute_capacity * 100) > (ns->util * imbalance_pct)) && in numa_classify()
2005 ((ns->compute_capacity * imbalance_pct) > (ns->runnable * 100)))) in numa_classify()
2043 struct numa_stats *ns, int nid, in update_numa_stats() argument
2046 int cpu, idle_core = -1; in update_numa_stats()
2048 memset(ns, 0, sizeof(*ns)); in update_numa_stats()
2049 ns->idle_cpu = -1; in update_numa_stats()
2055 ns->load += cpu_load(rq); in update_numa_stats()
2056 ns->runnable += cpu_runnable(rq); in update_numa_stats()
2057 ns->util += cpu_util_cfs(cpu); in update_numa_stats()
2058 ns->nr_running += rq->cfs.h_nr_running; in update_numa_stats()
2059 ns->compute_capacity += capacity_of(cpu); in update_numa_stats()
2061 if (find_idle && idle_core < 0 && !rq->nr_running && idle_cpu(cpu)) { in update_numa_stats()
2062 if (READ_ONCE(rq->numa_migrate_on) || in update_numa_stats()
2063 !cpumask_test_cpu(cpu, env->p->cpus_ptr)) in update_numa_stats()
2066 if (ns->idle_cpu == -1) in update_numa_stats()
2067 ns->idle_cpu = cpu; in update_numa_stats()
2074 ns->weight = cpumask_weight(cpumask_of_node(nid)); in update_numa_stats()
2076 ns->node_type = numa_classify(env->imbalance_pct, ns); in update_numa_stats()
2079 ns->idle_cpu = idle_core; in update_numa_stats()
2085 struct rq *rq = cpu_rq(env->dst_cpu); in task_numa_assign()
2087 /* Check if run-queue part of active NUMA balance. */ in task_numa_assign()
2088 if (env->best_cpu != env->dst_cpu && xchg(&rq->numa_migrate_on, 1)) { in task_numa_assign()
2090 int start = env->dst_cpu; in task_numa_assign()
2093 for_each_cpu_wrap(cpu, cpumask_of_node(env->dst_nid), start + 1) { in task_numa_assign()
2094 if (cpu == env->best_cpu || !idle_cpu(cpu) || in task_numa_assign()
2095 !cpumask_test_cpu(cpu, env->p->cpus_ptr)) { in task_numa_assign()
2099 env->dst_cpu = cpu; in task_numa_assign()
2100 rq = cpu_rq(env->dst_cpu); in task_numa_assign()
2101 if (!xchg(&rq->numa_migrate_on, 1)) in task_numa_assign()
2111 * Clear previous best_cpu/rq numa-migrate flag, since task now in task_numa_assign()
2114 if (env->best_cpu != -1 && env->best_cpu != env->dst_cpu) { in task_numa_assign()
2115 rq = cpu_rq(env->best_cpu); in task_numa_assign()
2116 WRITE_ONCE(rq->numa_migrate_on, 0); in task_numa_assign()
2119 if (env->best_task) in task_numa_assign()
2120 put_task_struct(env->best_task); in task_numa_assign()
2124 env->best_task = p; in task_numa_assign()
2125 env->best_imp = imp; in task_numa_assign()
2126 env->best_cpu = env->dst_cpu; in task_numa_assign()
2140 * ------------ vs --------- in load_too_imbalanced()
2143 src_capacity = env->src_stats.compute_capacity; in load_too_imbalanced()
2144 dst_capacity = env->dst_stats.compute_capacity; in load_too_imbalanced()
2146 imb = abs(dst_load * src_capacity - src_load * dst_capacity); in load_too_imbalanced()
2148 orig_src_load = env->src_stats.load; in load_too_imbalanced()
2149 orig_dst_load = env->dst_stats.load; in load_too_imbalanced()
2151 old_imb = abs(orig_dst_load * src_capacity - orig_src_load * dst_capacity); in load_too_imbalanced()
2173 struct numa_group *cur_ng, *p_ng = deref_curr_numa_group(env->p); in task_numa_compare()
2174 struct rq *dst_rq = cpu_rq(env->dst_cpu); in task_numa_compare()
2178 int dist = env->dist; in task_numa_compare()
2183 if (READ_ONCE(dst_rq->numa_migrate_on)) in task_numa_compare()
2187 cur = rcu_dereference(dst_rq->curr); in task_numa_compare()
2188 if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur))) in task_numa_compare()
2193 * end try selecting ourselves (current == env->p) as a swap candidate. in task_numa_compare()
2195 if (cur == env->p) { in task_numa_compare()
2201 if (maymove && moveimp >= env->best_imp) in task_numa_compare()
2208 if (!cpumask_test_cpu(env->src_cpu, cur->cpus_ptr)) in task_numa_compare()
2215 if (env->best_task && in task_numa_compare()
2216 env->best_task->numa_preferred_nid == env->src_nid && in task_numa_compare()
2217 cur->numa_preferred_nid != env->src_nid) { in task_numa_compare()
2231 cur_ng = rcu_dereference(cur->numa_group); in task_numa_compare()
2239 if (env->dst_stats.node_type == node_has_spare) in task_numa_compare()
2242 imp = taskimp + task_weight(cur, env->src_nid, dist) - in task_numa_compare()
2243 task_weight(cur, env->dst_nid, dist); in task_numa_compare()
2249 imp -= imp / 16; in task_numa_compare()
2256 imp += group_weight(cur, env->src_nid, dist) - in task_numa_compare()
2257 group_weight(cur, env->dst_nid, dist); in task_numa_compare()
2259 imp += task_weight(cur, env->src_nid, dist) - in task_numa_compare()
2260 task_weight(cur, env->dst_nid, dist); in task_numa_compare()
2264 if (cur->numa_preferred_nid == env->dst_nid) in task_numa_compare()
2265 imp -= imp / 16; in task_numa_compare()
2273 if (cur->numa_preferred_nid == env->src_nid) in task_numa_compare()
2276 if (maymove && moveimp > imp && moveimp > env->best_imp) { in task_numa_compare()
2286 if (env->best_task && cur->numa_preferred_nid == env->src_nid && in task_numa_compare()
2287 env->best_task->numa_preferred_nid != env->src_nid) { in task_numa_compare()
2297 if (imp < SMALLIMP || imp <= env->best_imp + SMALLIMP / 2) in task_numa_compare()
2303 load = task_h_load(env->p) - task_h_load(cur); in task_numa_compare()
2307 dst_load = env->dst_stats.load + load; in task_numa_compare()
2308 src_load = env->src_stats.load - load; in task_numa_compare()
2316 int cpu = env->dst_stats.idle_cpu; in task_numa_compare()
2320 cpu = env->dst_cpu; in task_numa_compare()
2326 if (!idle_cpu(cpu) && env->best_cpu >= 0 && in task_numa_compare()
2327 idle_cpu(env->best_cpu)) { in task_numa_compare()
2328 cpu = env->best_cpu; in task_numa_compare()
2331 env->dst_cpu = cpu; in task_numa_compare()
2341 if (maymove && !cur && env->best_cpu >= 0 && idle_cpu(env->best_cpu)) in task_numa_compare()
2348 if (!maymove && env->best_task && in task_numa_compare()
2349 env->best_task->numa_preferred_nid == env->src_nid) { in task_numa_compare()
2368 if (env->dst_stats.node_type == node_has_spare) { in task_numa_find_cpu()
2378 src_running = env->src_stats.nr_running - 1; in task_numa_find_cpu()
2379 dst_running = env->dst_stats.nr_running + 1; in task_numa_find_cpu()
2380 imbalance = max(0, dst_running - src_running); in task_numa_find_cpu()
2382 env->imb_numa_nr); in task_numa_find_cpu()
2387 if (env->dst_stats.idle_cpu >= 0) { in task_numa_find_cpu()
2388 env->dst_cpu = env->dst_stats.idle_cpu; in task_numa_find_cpu()
2396 * If the improvement from just moving env->p direction is better in task_numa_find_cpu()
2399 load = task_h_load(env->p); in task_numa_find_cpu()
2400 dst_load = env->dst_stats.load + load; in task_numa_find_cpu()
2401 src_load = env->src_stats.load - load; in task_numa_find_cpu()
2405 for_each_cpu(cpu, cpumask_of_node(env->dst_nid)) { in task_numa_find_cpu()
2407 if (!cpumask_test_cpu(cpu, env->p->cpus_ptr)) in task_numa_find_cpu()
2410 env->dst_cpu = cpu; in task_numa_find_cpu()
2428 .best_cpu = -1, in task_numa_migrate()
2442 * random movement of tasks -- counter the numa conditions we're trying in task_numa_migrate()
2448 env.imbalance_pct = 100 + (sd->imbalance_pct - 100) / 2; in task_numa_migrate()
2449 env.imb_numa_nr = sd->imb_numa_nr; in task_numa_migrate()
2461 return -EINVAL; in task_numa_migrate()
2464 env.dst_nid = p->numa_preferred_nid; in task_numa_migrate()
2469 taskimp = task_weight(p, env.dst_nid, dist) - taskweight; in task_numa_migrate()
2470 groupimp = group_weight(p, env.dst_nid, dist) - groupweight; in task_numa_migrate()
2478 * - there is no space available on the preferred_nid in task_numa_migrate()
2479 * - the task is part of a numa_group that is interleaved across in task_numa_migrate()
2484 if (env.best_cpu == -1 || (ng && ng->active_nodes > 1)) { in task_numa_migrate()
2486 if (nid == env.src_nid || nid == p->numa_preferred_nid) in task_numa_migrate()
2497 taskimp = task_weight(p, nid, dist) - taskweight; in task_numa_migrate()
2498 groupimp = group_weight(p, nid, dist) - groupweight; in task_numa_migrate()
2518 if (env.best_cpu == -1) in task_numa_migrate()
2523 if (nid != p->numa_preferred_nid) in task_numa_migrate()
2528 if (env.best_cpu == -1) { in task_numa_migrate()
2529 trace_sched_stick_numa(p, env.src_cpu, NULL, -1); in task_numa_migrate()
2530 return -EAGAIN; in task_numa_migrate()
2536 WRITE_ONCE(best_rq->numa_migrate_on, 0); in task_numa_migrate()
2543 WRITE_ONCE(best_rq->numa_migrate_on, 0); in task_numa_migrate()
2557 if (unlikely(p->numa_preferred_nid == NUMA_NO_NODE || !p->numa_faults)) in numa_migrate_preferred()
2561 interval = min(interval, msecs_to_jiffies(p->numa_scan_period) / 16); in numa_migrate_preferred()
2562 p->numa_migrate_retry = jiffies + interval; in numa_migrate_preferred()
2565 if (task_node(p) == p->numa_preferred_nid) in numa_migrate_preferred()
2595 numa_group->max_faults_cpu = max_faults; in numa_group_count_active_nodes()
2596 numa_group->active_nodes = active_nodes; in numa_group_count_active_nodes()
2622 unsigned long remote = p->numa_faults_locality[0]; in update_task_scan_period()
2623 unsigned long local = p->numa_faults_locality[1]; in update_task_scan_period()
2632 if (local + shared == 0 || p->numa_faults_locality[2]) { in update_task_scan_period()
2633 p->numa_scan_period = min(p->numa_scan_period_max, in update_task_scan_period()
2634 p->numa_scan_period << 1); in update_task_scan_period()
2636 p->mm->numa_next_scan = jiffies + in update_task_scan_period()
2637 msecs_to_jiffies(p->numa_scan_period); in update_task_scan_period()
2648 period_slot = DIV_ROUND_UP(p->numa_scan_period, NUMA_PERIOD_SLOTS); in update_task_scan_period()
2657 int slot = ps_ratio - NUMA_PERIOD_THRESHOLD; in update_task_scan_period()
2667 int slot = lr_ratio - NUMA_PERIOD_THRESHOLD; in update_task_scan_period()
2673 * Private memory faults exceed (SLOTS-THRESHOLD)/SLOTS, in update_task_scan_period()
2678 diff = -(NUMA_PERIOD_THRESHOLD - ratio) * period_slot; in update_task_scan_period()
2681 p->numa_scan_period = clamp(p->numa_scan_period + diff, in update_task_scan_period()
2683 memset(p->numa_faults_locality, 0, sizeof(p->numa_faults_locality)); in update_task_scan_period()
2687 * Get the fraction of time the task has been running since the last
2690 * from the dozens-of-seconds NUMA balancing period. Use the scheduler
2696 /* Use the start of this time slice to avoid calculations. */ in numa_get_avg_runtime()
2697 now = p->se.exec_start; in numa_get_avg_runtime()
2698 runtime = p->se.sum_exec_runtime; in numa_get_avg_runtime()
2700 if (p->last_task_numa_placement) { in numa_get_avg_runtime()
2701 delta = runtime - p->last_sum_exec_runtime; in numa_get_avg_runtime()
2702 *period = now - p->last_task_numa_placement; in numa_get_avg_runtime()
2704 /* Avoid time going backwards, prevent potential divide error: */ in numa_get_avg_runtime()
2708 delta = p->se.avg.load_sum; in numa_get_avg_runtime()
2712 p->last_sum_exec_runtime = runtime; in numa_get_avg_runtime()
2713 p->last_task_numa_placement = now; in numa_get_avg_runtime()
2763 for (dist = sched_max_numa_distance; dist > LOCAL_DISTANCE; dist--) { in preferred_group_nid()
2817 * The p->mm->numa_scan_seq field gets updated without in task_numa_placement()
2821 seq = READ_ONCE(p->mm->numa_scan_seq); in task_numa_placement()
2822 if (p->numa_scan_seq == seq) in task_numa_placement()
2824 p->numa_scan_seq = seq; in task_numa_placement()
2825 p->numa_scan_period_max = task_scan_max(p); in task_numa_placement()
2827 total_faults = p->numa_faults_locality[0] + in task_numa_placement()
2828 p->numa_faults_locality[1]; in task_numa_placement()
2834 group_lock = &ng->lock; in task_numa_placement()
2854 diff = p->numa_faults[membuf_idx] - p->numa_faults[mem_idx] / 2; in task_numa_placement()
2855 fault_types[priv] += p->numa_faults[membuf_idx]; in task_numa_placement()
2856 p->numa_faults[membuf_idx] = 0; in task_numa_placement()
2862 * little over-all impact on throughput, and thus their in task_numa_placement()
2866 f_weight = (f_weight * p->numa_faults[cpubuf_idx]) / in task_numa_placement()
2868 f_diff = f_weight - p->numa_faults[cpu_idx] / 2; in task_numa_placement()
2869 p->numa_faults[cpubuf_idx] = 0; in task_numa_placement()
2871 p->numa_faults[mem_idx] += diff; in task_numa_placement()
2872 p->numa_faults[cpu_idx] += f_diff; in task_numa_placement()
2873 faults += p->numa_faults[mem_idx]; in task_numa_placement()
2874 p->total_numa_faults += diff; in task_numa_placement()
2883 ng->faults[mem_idx] += diff; in task_numa_placement()
2884 ng->faults[cpu_idx] += f_diff; in task_numa_placement()
2885 ng->total_faults += diff; in task_numa_placement()
2886 group_faults += ng->faults[mem_idx]; in task_numa_placement()
2901 /* Cannot migrate task to CPU-less node */ in task_numa_placement()
2924 if (max_nid != p->numa_preferred_nid) in task_numa_placement()
2933 return refcount_inc_not_zero(&grp->refcount); in get_numa_group()
2938 if (refcount_dec_and_test(&grp->refcount)) in put_numa_group()
2960 refcount_set(&grp->refcount, 1); in task_numa_group()
2961 grp->active_nodes = 1; in task_numa_group()
2962 grp->max_faults_cpu = 0; in task_numa_group()
2963 spin_lock_init(&grp->lock); in task_numa_group()
2964 grp->gid = p->pid; in task_numa_group()
2967 grp->faults[i] = p->numa_faults[i]; in task_numa_group()
2969 grp->total_faults = p->total_numa_faults; in task_numa_group()
2971 grp->nr_tasks++; in task_numa_group()
2972 rcu_assign_pointer(p->numa_group, grp); in task_numa_group()
2976 tsk = READ_ONCE(cpu_rq(cpu)->curr); in task_numa_group()
2981 grp = rcu_dereference(tsk->numa_group); in task_numa_group()
2993 if (my_grp->nr_tasks > grp->nr_tasks) in task_numa_group()
2997 * Tie-break on the grp address. in task_numa_group()
2999 if (my_grp->nr_tasks == grp->nr_tasks && my_grp > grp) in task_numa_group()
3003 if (tsk->mm == current->mm) in task_numa_group()
3022 double_lock_irq(&my_grp->lock, &grp->lock); in task_numa_group()
3025 my_grp->faults[i] -= p->numa_faults[i]; in task_numa_group()
3026 grp->faults[i] += p->numa_faults[i]; in task_numa_group()
3028 my_grp->total_faults -= p->total_numa_faults; in task_numa_group()
3029 grp->total_faults += p->total_numa_faults; in task_numa_group()
3031 my_grp->nr_tasks--; in task_numa_group()
3032 grp->nr_tasks++; in task_numa_group()
3034 spin_unlock(&my_grp->lock); in task_numa_group()
3035 spin_unlock_irq(&grp->lock); in task_numa_group()
3037 rcu_assign_pointer(p->numa_group, grp); in task_numa_group()
3052 * reset the data back to default state without freeing ->numa_faults.
3057 struct numa_group *grp = rcu_dereference_raw(p->numa_group); in task_numa_free()
3058 unsigned long *numa_faults = p->numa_faults; in task_numa_free()
3066 spin_lock_irqsave(&grp->lock, flags); in task_numa_free()
3068 grp->faults[i] -= p->numa_faults[i]; in task_numa_free()
3069 grp->total_faults -= p->total_numa_faults; in task_numa_free()
3071 grp->nr_tasks--; in task_numa_free()
3072 spin_unlock_irqrestore(&grp->lock, flags); in task_numa_free()
3073 RCU_INIT_POINTER(p->numa_group, NULL); in task_numa_free()
3078 p->numa_faults = NULL; in task_numa_free()
3081 p->total_numa_faults = 0; in task_numa_free()
3103 if (!p->mm) in task_numa_fault()
3115 /* Allocate buffer to track faults on a per-node basis */ in task_numa_fault()
3116 if (unlikely(!p->numa_faults)) { in task_numa_fault()
3117 int size = sizeof(*p->numa_faults) * in task_numa_fault()
3120 p->numa_faults = kzalloc(size, GFP_KERNEL|__GFP_NOWARN); in task_numa_fault()
3121 if (!p->numa_faults) in task_numa_fault()
3124 p->total_numa_faults = 0; in task_numa_fault()
3125 memset(p->numa_faults_locality, 0, sizeof(p->numa_faults_locality)); in task_numa_fault()
3132 if (unlikely(last_cpupid == (-1 & LAST_CPUPID_MASK))) { in task_numa_fault()
3147 if (!priv && !local && ng && ng->active_nodes > 1 && in task_numa_fault()
3156 if (time_after(jiffies, p->numa_migrate_retry)) { in task_numa_fault()
3162 p->numa_pages_migrated += pages; in task_numa_fault()
3164 p->numa_faults_locality[2] += pages; in task_numa_fault()
3166 p->numa_faults[task_faults_idx(NUMA_MEMBUF, mem_node, priv)] += pages; in task_numa_fault()
3167 p->numa_faults[task_faults_idx(NUMA_CPUBUF, cpu_node, priv)] += pages; in task_numa_fault()
3168 p->numa_faults_locality[local] += pages; in task_numa_fault()
3174 * We only did a read acquisition of the mmap sem, so in reset_ptenuma_scan()
3175 * p->mm->numa_scan_seq is written to without exclusive access in reset_ptenuma_scan()
3181 WRITE_ONCE(p->mm->numa_scan_seq, READ_ONCE(p->mm->numa_scan_seq) + 1); in reset_ptenuma_scan()
3182 p->mm->numa_scan_offset = 0; in reset_ptenuma_scan()
3194 if (READ_ONCE(current->mm->numa_scan_seq) < 2) in vma_is_accessed()
3197 pids = vma->numab_state->access_pids[0] | vma->numab_state->access_pids[1]; in vma_is_accessed()
3198 return test_bit(hash_32(current->pid, ilog2(BITS_PER_LONG)), &pids); in vma_is_accessed()
3211 struct mm_struct *mm = p->mm; in task_numa_work()
3212 u64 runtime = p->se.sum_exec_runtime; in task_numa_work()
3221 work->next = work; in task_numa_work()
3225 * NOTE: make sure not to dereference p->mm before this check, in task_numa_work()
3227 * without p->mm even though we still had it when we enqueued this in task_numa_work()
3230 if (p->flags & PF_EXITING) in task_numa_work()
3233 if (!mm->numa_next_scan) { in task_numa_work()
3234 mm->numa_next_scan = now + in task_numa_work()
3241 migrate = mm->numa_next_scan; in task_numa_work()
3245 if (p->numa_scan_period == 0) { in task_numa_work()
3246 p->numa_scan_period_max = task_scan_max(p); in task_numa_work()
3247 p->numa_scan_period = task_scan_start(p); in task_numa_work()
3250 next_scan = now + msecs_to_jiffies(p->numa_scan_period); in task_numa_work()
3251 if (!try_cmpxchg(&mm->numa_next_scan, &migrate, next_scan)) in task_numa_work()
3256 * the next time around. in task_numa_work()
3258 p->node_stamp += 2 * TICK_NSEC; in task_numa_work()
3260 start = mm->numa_scan_offset; in task_numa_work()
3262 pages <<= 20 - PAGE_SHIFT; /* MB in pages */ in task_numa_work()
3281 is_vm_hugetlb_page(vma) || (vma->vm_flags & VM_MIXEDMAP)) { in task_numa_work()
3288 * hinting faults in read-only file-backed mappings or the vdso in task_numa_work()
3291 if (!vma->vm_mm || in task_numa_work()
3292 (vma->vm_file && (vma->vm_flags & (VM_READ|VM_WRITE)) == (VM_READ))) in task_numa_work()
3302 /* Initialise new per-VMA NUMAB state. */ in task_numa_work()
3303 if (!vma->numab_state) { in task_numa_work()
3304 vma->numab_state = kzalloc(sizeof(struct vma_numab_state), in task_numa_work()
3306 if (!vma->numab_state) in task_numa_work()
3309 vma->numab_state->next_scan = now + in task_numa_work()
3313 vma->numab_state->next_pid_reset = vma->numab_state->next_scan + in task_numa_work()
3321 if (mm->numa_scan_seq && time_before(jiffies, in task_numa_work()
3322 vma->numab_state->next_scan)) in task_numa_work()
3333 if (mm->numa_scan_seq && in task_numa_work()
3334 time_after(jiffies, vma->numab_state->next_pid_reset)) { in task_numa_work()
3335 vma->numab_state->next_pid_reset = vma->numab_state->next_pid_reset + in task_numa_work()
3337 vma->numab_state->access_pids[0] = READ_ONCE(vma->numab_state->access_pids[1]); in task_numa_work()
3338 vma->numab_state->access_pids[1] = 0; in task_numa_work()
3342 start = max(start, vma->vm_start); in task_numa_work()
3344 end = min(end, vma->vm_end); in task_numa_work()
3350 * is not already pte-numa. If the VMA contains in task_numa_work()
3356 pages -= (end - start) >> PAGE_SHIFT; in task_numa_work()
3357 virtpages -= (end - start) >> PAGE_SHIFT; in task_numa_work()
3364 } while (end != vma->vm_end); in task_numa_work()
3375 mm->numa_scan_offset = start; in task_numa_work()
3381 * Make sure tasks use at least 32x as much time to run other code in task_numa_work()
3386 if (unlikely(p->se.sum_exec_runtime != runtime)) { in task_numa_work()
3387 u64 diff = p->se.sum_exec_runtime - runtime; in task_numa_work()
3388 p->node_stamp += 32 * diff; in task_numa_work()
3395 struct mm_struct *mm = p->mm; in init_numa_balancing()
3398 mm_users = atomic_read(&mm->mm_users); in init_numa_balancing()
3400 mm->numa_next_scan = jiffies + msecs_to_jiffies(sysctl_numa_balancing_scan_delay); in init_numa_balancing()
3401 mm->numa_scan_seq = 0; in init_numa_balancing()
3404 p->node_stamp = 0; in init_numa_balancing()
3405 p->numa_scan_seq = mm ? mm->numa_scan_seq : 0; in init_numa_balancing()
3406 p->numa_scan_period = sysctl_numa_balancing_scan_delay; in init_numa_balancing()
3407 p->numa_migrate_retry = 0; in init_numa_balancing()
3409 p->numa_work.next = &p->numa_work; in init_numa_balancing()
3410 p->numa_faults = NULL; in init_numa_balancing()
3411 p->numa_pages_migrated = 0; in init_numa_balancing()
3412 p->total_numa_faults = 0; in init_numa_balancing()
3413 RCU_INIT_POINTER(p->numa_group, NULL); in init_numa_balancing()
3414 p->last_task_numa_placement = 0; in init_numa_balancing()
3415 p->last_sum_exec_runtime = 0; in init_numa_balancing()
3417 init_task_work(&p->numa_work, task_numa_work); in init_numa_balancing()
3421 p->numa_preferred_nid = NUMA_NO_NODE; in init_numa_balancing()
3433 current->numa_scan_period * mm_users * NSEC_PER_MSEC); in init_numa_balancing()
3435 p->node_stamp = delay; in init_numa_balancing()
3444 struct callback_head *work = &curr->numa_work; in task_tick_numa()
3450 if (!curr->mm || (curr->flags & (PF_EXITING | PF_KTHREAD)) || work->next != work) in task_tick_numa()
3459 now = curr->se.sum_exec_runtime; in task_tick_numa()
3460 period = (u64)curr->numa_scan_period * NSEC_PER_MSEC; in task_tick_numa()
3462 if (now > curr->node_stamp + period) { in task_tick_numa()
3463 if (!curr->node_stamp) in task_tick_numa()
3464 curr->numa_scan_period = task_scan_start(curr); in task_tick_numa()
3465 curr->node_stamp += period; in task_tick_numa()
3467 if (!time_before(jiffies, curr->mm->numa_next_scan)) in task_tick_numa()
3480 if (!p->mm || !p->numa_faults || (p->flags & PF_EXITING)) in update_scan_period()
3489 * is pulled cross-node due to wakeups or load balancing. in update_scan_period()
3491 if (p->numa_scan_seq) { in update_scan_period()
3497 if (dst_nid == p->numa_preferred_nid || in update_scan_period()
3498 (p->numa_preferred_nid != NUMA_NO_NODE && in update_scan_period()
3499 src_nid != p->numa_preferred_nid)) in update_scan_period()
3503 p->numa_scan_period = task_scan_start(p); in update_scan_period()
3528 update_load_add(&cfs_rq->load, se->load.weight); in account_entity_enqueue()
3534 list_add(&se->group_node, &rq->cfs_tasks); in account_entity_enqueue()
3537 cfs_rq->nr_running++; in account_entity_enqueue()
3539 cfs_rq->idle_nr_running++; in account_entity_enqueue()
3545 update_load_sub(&cfs_rq->load, se->load.weight); in account_entity_dequeue()
3549 list_del_init(&se->group_node); in account_entity_dequeue()
3552 cfs_rq->nr_running--; in account_entity_dequeue()
3554 cfs_rq->idle_nr_running--; in account_entity_dequeue()
3560 * Explicitly do a load-store to ensure the intermediate value never hits
3580 * Explicitly do a load-store to ensure the intermediate value never hits
3588 res = var - val; \
3597 * A variant of sub_positive(), which does not use explicit load-store
3602 *ptr -= min_t(typeof(*ptr), *ptr, _val); \
3609 cfs_rq->avg.load_avg += se->avg.load_avg; in enqueue_load_avg()
3610 cfs_rq->avg.load_sum += se_weight(se) * se->avg.load_sum; in enqueue_load_avg()
3616 sub_positive(&cfs_rq->avg.load_avg, se->avg.load_avg); in dequeue_load_avg()
3617 sub_positive(&cfs_rq->avg.load_sum, se_weight(se) * se->avg.load_sum); in dequeue_load_avg()
3619 cfs_rq->avg.load_sum = max_t(u32, cfs_rq->avg.load_sum, in dequeue_load_avg()
3620 cfs_rq->avg.load_avg * PELT_MIN_DIVIDER); in dequeue_load_avg()
3632 unsigned long old_weight = se->load.weight; in reweight_entity()
3634 if (se->on_rq) { in reweight_entity()
3635 /* commit outstanding execution time */ in reweight_entity()
3636 if (cfs_rq->curr == se) in reweight_entity()
3640 update_load_sub(&cfs_rq->load, se->load.weight); in reweight_entity()
3644 update_load_set(&se->load, weight); in reweight_entity()
3646 if (!se->on_rq) { in reweight_entity()
3648 * Because we keep se->vlag = V - v_i, while: lag_i = w_i*(V - v_i), in reweight_entity()
3649 * we need to scale se->vlag when w_i changes. in reweight_entity()
3651 se->vlag = div_s64(se->vlag * old_weight, weight); in reweight_entity()
3653 s64 deadline = se->deadline - se->vruntime; in reweight_entity()
3655 * When the weight changes, the virtual time slope changes and in reweight_entity()
3659 se->deadline = se->vruntime + deadline; in reweight_entity()
3660 if (se != cfs_rq->curr) in reweight_entity()
3661 min_deadline_cb_propagate(&se->run_node, NULL); in reweight_entity()
3666 u32 divider = get_pelt_divider(&se->avg); in reweight_entity()
3668 se->avg.load_avg = div_u64(se_weight(se) * se->avg.load_sum, divider); in reweight_entity()
3673 if (se->on_rq) { in reweight_entity()
3674 update_load_add(&cfs_rq->load, se->load.weight); in reweight_entity()
3675 if (cfs_rq->curr != se) in reweight_entity()
3682 struct sched_entity *se = &p->se; in reweight_task()
3684 struct load_weight *load = &se->load; in reweight_task()
3688 load->inv_weight = sched_prio_to_wmult[prio]; in reweight_task()
3702 * tg->weight * grq->load.weight
3703 * ge->load.weight = ----------------------------- (1)
3704 * \Sum grq->load.weight
3712 * grq->load.weight -> grq->avg.load_avg (2)
3716 * tg->weight * grq->avg.load_avg
3717 * ge->load.weight = ------------------------------ (3)
3718 * tg->load_avg
3720 * Where: tg->load_avg ~= \Sum grq->avg.load_avg
3724 * The problem with it is that because the average is slow -- it was designed
3725 * to be exactly that of course -- this leads to transients in boundary
3727 * one task. It takes time for our CPU's grq->avg.load_avg to build up,
3732 * tg->weight * grq->load.weight
3733 * ge->load.weight = ----------------------------- = tg->weight (4)
3734 * grp->load.weight
3741 * ge->load.weight =
3743 * tg->weight * grq->load.weight
3744 * --------------------------------------------------- (5)
3745 * tg->load_avg - grq->avg.load_avg + grq->load.weight
3747 * But because grq->load.weight can drop to 0, resulting in a divide by zero,
3748 * we need to use grq->avg.load_avg as its lower bound, which then gives:
3751 * tg->weight * grq->load.weight
3752 * ge->load.weight = ----------------------------- (6)
3757 * tg_load_avg' = tg->load_avg - grq->avg.load_avg +
3758 * max(grq->load.weight, grq->avg.load_avg)
3762 * overestimates the ge->load.weight and therefore:
3764 * \Sum ge->load.weight >= tg->weight
3771 struct task_group *tg = cfs_rq->tg; in calc_group_shares()
3773 tg_shares = READ_ONCE(tg->shares); in calc_group_shares()
3775 load = max(scale_load_down(cfs_rq->load.weight), cfs_rq->avg.load_avg); in calc_group_shares()
3777 tg_weight = atomic_long_read(&tg->load_avg); in calc_group_shares()
3780 tg_weight -= cfs_rq->tg_load_avg_contrib; in calc_group_shares()
3788 * MIN_SHARES has to be unscaled here to support per-CPU partitioning in calc_group_shares()
3789 * of a group with small tg->shares value. It is a floor value which is in calc_group_shares()
3793 * E.g. on 64-bit for a group with tg->shares of scale_load(15)=15*1024 in calc_group_shares()
3794 * on an 8-core system with 8 tasks each runnable on one CPU shares has in calc_group_shares()
3819 shares = READ_ONCE(gcfs_rq->tg->shares); in update_cfs_group()
3821 if (likely(se->load.weight == shares)) in update_cfs_group()
3840 if (&rq->cfs == cfs_rq) { in cfs_rq_util_change()
3850 * As is, the util number is not freq-invariant (we'd have to in cfs_rq_util_change()
3862 if (sa->load_sum) in load_avg_is_decayed()
3865 if (sa->util_sum) in load_avg_is_decayed()
3868 if (sa->runnable_sum) in load_avg_is_decayed()
3876 SCHED_WARN_ON(sa->load_avg || in load_avg_is_decayed()
3877 sa->util_avg || in load_avg_is_decayed()
3878 sa->runnable_avg); in load_avg_is_decayed()
3885 return u64_u32_load_copy(cfs_rq->avg.last_update_time, in cfs_rq_last_update_time()
3886 cfs_rq->last_update_time_copy); in cfs_rq_last_update_time()
3892 * bottom-up, we only have to test whether the cfs_rq before us on the list
3902 if (cfs_rq->on_list) { in child_cfs_rq_on_list()
3903 prev = cfs_rq->leaf_cfs_rq_list.prev; in child_cfs_rq_on_list()
3907 prev = rq->tmp_alone_branch; in child_cfs_rq_on_list()
3912 return (prev_cfs_rq->tg->parent == cfs_rq->tg); in child_cfs_rq_on_list()
3917 if (cfs_rq->load.weight) in cfs_rq_is_decayed()
3920 if (!load_avg_is_decayed(&cfs_rq->avg)) in cfs_rq_is_decayed()
3930 * update_tg_load_avg - update the tg's load avg
3933 * This function 'ensures': tg->load_avg := \Sum tg->cfs_rq[]->avg.load.
3934 * However, because tg->load_avg is a global value there are performance
3945 long delta = cfs_rq->avg.load_avg - cfs_rq->tg_load_avg_contrib; in update_tg_load_avg()
3950 if (cfs_rq->tg == &root_task_group) in update_tg_load_avg()
3953 if (abs(delta) > cfs_rq->tg_load_avg_contrib / 64) { in update_tg_load_avg()
3954 atomic_long_add(delta, &cfs_rq->tg->load_avg); in update_tg_load_avg()
3955 cfs_rq->tg_load_avg_contrib = cfs_rq->avg.load_avg; in update_tg_load_avg()
3961 * caller only guarantees p->pi_lock is held; no other assumptions,
3962 * including the state of rq->lock, should be made.
3974 * We are supposed to update the task to "current" time, then its up to in set_task_rq_fair()
3976 * getting what current time is, so simply throw away the out-of-date in set_task_rq_fair()
3977 * time. This will result in the wakee task is less decayed, but giving in set_task_rq_fair()
3980 if (!(se->avg.last_update_time && prev)) in set_task_rq_fair()
3987 se->avg.last_update_time = n_last_update_time; in set_task_rq_fair()
3995 * ge->avg == grq->avg (1)
4006 * ge->avg.load_avg = ge->load.weight * ge->avg.runnable_avg (2)
4011 * grq->avg.load_avg = grq->load.weight * grq->avg.runnable_avg (3)
4015 * ge->avg.runnable_avg == grq->avg.runnable_avg
4019 * ge->load.weight * grq->avg.load_avg
4020 * ge->avg.load_avg = ----------------------------------- (4)
4021 * grq->load.weight
4034 * Another reason this doesn't work is that runnable isn't a 0-sum entity.
4035 * Imagine a rq with 2 tasks that each are runnable 2/3 of the time. Then the
4038 * align the rq as a whole would be runnable 2/3 of the time. If however we
4045 * ge->avg.running_sum <= ge->avg.runnable_sum <= LOAD_AVG_MAX
4052 * grq->avg.runnable_sum = grq->avg.load_sum / grq->load.weight
4060 long delta_sum, delta_avg = gcfs_rq->avg.util_avg - se->avg.util_avg; in update_tg_cfs_util()
4068 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in update_tg_cfs_util()
4071 divider = get_pelt_divider(&cfs_rq->avg); in update_tg_cfs_util()
4075 se->avg.util_avg = gcfs_rq->avg.util_avg; in update_tg_cfs_util()
4076 new_sum = se->avg.util_avg * divider; in update_tg_cfs_util()
4077 delta_sum = (long)new_sum - (long)se->avg.util_sum; in update_tg_cfs_util()
4078 se->avg.util_sum = new_sum; in update_tg_cfs_util()
4081 add_positive(&cfs_rq->avg.util_avg, delta_avg); in update_tg_cfs_util()
4082 add_positive(&cfs_rq->avg.util_sum, delta_sum); in update_tg_cfs_util()
4085 cfs_rq->avg.util_sum = max_t(u32, cfs_rq->avg.util_sum, in update_tg_cfs_util()
4086 cfs_rq->avg.util_avg * PELT_MIN_DIVIDER); in update_tg_cfs_util()
4092 long delta_sum, delta_avg = gcfs_rq->avg.runnable_avg - se->avg.runnable_avg; in update_tg_cfs_runnable()
4100 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in update_tg_cfs_runnable()
4103 divider = get_pelt_divider(&cfs_rq->avg); in update_tg_cfs_runnable()
4106 se->avg.runnable_avg = gcfs_rq->avg.runnable_avg; in update_tg_cfs_runnable()
4107 new_sum = se->avg.runnable_avg * divider; in update_tg_cfs_runnable()
4108 delta_sum = (long)new_sum - (long)se->avg.runnable_sum; in update_tg_cfs_runnable()
4109 se->avg.runnable_sum = new_sum; in update_tg_cfs_runnable()
4112 add_positive(&cfs_rq->avg.runnable_avg, delta_avg); in update_tg_cfs_runnable()
4113 add_positive(&cfs_rq->avg.runnable_sum, delta_sum); in update_tg_cfs_runnable()
4115 cfs_rq->avg.runnable_sum = max_t(u32, cfs_rq->avg.runnable_sum, in update_tg_cfs_runnable()
4116 cfs_rq->avg.runnable_avg * PELT_MIN_DIVIDER); in update_tg_cfs_runnable()
4122 long delta_avg, running_sum, runnable_sum = gcfs_rq->prop_runnable_sum; in update_tg_cfs_load()
4131 gcfs_rq->prop_runnable_sum = 0; in update_tg_cfs_load()
4134 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in update_tg_cfs_load()
4137 divider = get_pelt_divider(&cfs_rq->avg); in update_tg_cfs_load()
4144 runnable_sum += se->avg.load_sum; in update_tg_cfs_load()
4151 if (scale_load_down(gcfs_rq->load.weight)) { in update_tg_cfs_load()
4152 load_sum = div_u64(gcfs_rq->avg.load_sum, in update_tg_cfs_load()
4153 scale_load_down(gcfs_rq->load.weight)); in update_tg_cfs_load()
4157 runnable_sum = min(se->avg.load_sum, load_sum); in update_tg_cfs_load()
4166 running_sum = se->avg.util_sum >> SCHED_CAPACITY_SHIFT; in update_tg_cfs_load()
4172 delta_avg = load_avg - se->avg.load_avg; in update_tg_cfs_load()
4176 delta_sum = load_sum - (s64)se_weight(se) * se->avg.load_sum; in update_tg_cfs_load()
4178 se->avg.load_sum = runnable_sum; in update_tg_cfs_load()
4179 se->avg.load_avg = load_avg; in update_tg_cfs_load()
4180 add_positive(&cfs_rq->avg.load_avg, delta_avg); in update_tg_cfs_load()
4181 add_positive(&cfs_rq->avg.load_sum, delta_sum); in update_tg_cfs_load()
4183 cfs_rq->avg.load_sum = max_t(u32, cfs_rq->avg.load_sum, in update_tg_cfs_load()
4184 cfs_rq->avg.load_avg * PELT_MIN_DIVIDER); in update_tg_cfs_load()
4189 cfs_rq->propagate = 1; in add_tg_cfs_propagate()
4190 cfs_rq->prop_runnable_sum += runnable_sum; in add_tg_cfs_propagate()
4202 if (!gcfs_rq->propagate) in propagate_entity_load_avg()
4205 gcfs_rq->propagate = 0; in propagate_entity_load_avg()
4209 add_tg_cfs_propagate(cfs_rq, gcfs_rq->prop_runnable_sum); in propagate_entity_load_avg()
4233 if (se->avg.load_avg || se->avg.util_avg) in skip_blocked_update()
4240 if (gcfs_rq->propagate) in skip_blocked_update()
4246 * waste of time to try to decay it: in skip_blocked_update()
4272 if (load_avg_is_decayed(&se->avg)) in migrate_se_pelt_lag()
4279 is_idle = is_idle_task(rcu_dereference(rq->curr)); in migrate_se_pelt_lag()
4284 * time. Hence, limiting to the case where the source CPU is idle and in migrate_se_pelt_lag()
4296 * - cfs->throttled_clock_pelt_time@cfs_rq_idle in migrate_se_pelt_lag()
4299 * = rq_clock_pelt()@rq_idle - rq_clock_pelt()@cfs_rq_idle in migrate_se_pelt_lag()
4302 * = sched_clock_cpu() - rq_clock()@rq_idle in migrate_se_pelt_lag()
4306 * now = rq_clock_pelt()@rq_idle - cfs->throttled_clock_pelt_time + in migrate_se_pelt_lag()
4307 * sched_clock_cpu() - rq_clock()@rq_idle in migrate_se_pelt_lag()
4309 * rq_clock_pelt()@rq_idle is rq->clock_pelt_idle in migrate_se_pelt_lag()
4310 * rq_clock()@rq_idle is rq->clock_idle in migrate_se_pelt_lag()
4311 * cfs->throttled_clock_pelt_time@cfs_rq_idle in migrate_se_pelt_lag()
4312 * is cfs_rq->throttled_pelt_idle in migrate_se_pelt_lag()
4316 throttled = u64_u32_load(cfs_rq->throttled_pelt_idle); in migrate_se_pelt_lag()
4321 now = u64_u32_load(rq->clock_pelt_idle); in migrate_se_pelt_lag()
4331 now -= throttled; in migrate_se_pelt_lag()
4334 * cfs_rq->avg.last_update_time is more recent than our in migrate_se_pelt_lag()
4339 now += sched_clock_cpu(cpu_of(rq)) - u64_u32_load(rq->clock_idle); in migrate_se_pelt_lag()
4348 * update_cfs_rq_load_avg - update the cfs_rq's load/util averages
4349 * @now: current time, as per cfs_rq_clock_pelt()
4355 * cfs_rq->avg is used for task_h_load() and update_cfs_share() for example.
4359 * Since both these conditions indicate a changed cfs_rq->avg.load we should
4366 struct sched_avg *sa = &cfs_rq->avg; in update_cfs_rq_load_avg()
4369 if (cfs_rq->removed.nr) { in update_cfs_rq_load_avg()
4371 u32 divider = get_pelt_divider(&cfs_rq->avg); in update_cfs_rq_load_avg()
4373 raw_spin_lock(&cfs_rq->removed.lock); in update_cfs_rq_load_avg()
4374 swap(cfs_rq->removed.util_avg, removed_util); in update_cfs_rq_load_avg()
4375 swap(cfs_rq->removed.load_avg, removed_load); in update_cfs_rq_load_avg()
4376 swap(cfs_rq->removed.runnable_avg, removed_runnable); in update_cfs_rq_load_avg()
4377 cfs_rq->removed.nr = 0; in update_cfs_rq_load_avg()
4378 raw_spin_unlock(&cfs_rq->removed.lock); in update_cfs_rq_load_avg()
4381 sub_positive(&sa->load_avg, r); in update_cfs_rq_load_avg()
4382 sub_positive(&sa->load_sum, r * divider); in update_cfs_rq_load_avg()
4383 /* See sa->util_sum below */ in update_cfs_rq_load_avg()
4384 sa->load_sum = max_t(u32, sa->load_sum, sa->load_avg * PELT_MIN_DIVIDER); in update_cfs_rq_load_avg()
4387 sub_positive(&sa->util_avg, r); in update_cfs_rq_load_avg()
4388 sub_positive(&sa->util_sum, r * divider); in update_cfs_rq_load_avg()
4390 * Because of rounding, se->util_sum might ends up being +1 more than in update_cfs_rq_load_avg()
4391 * cfs->util_sum. Although this is not a problem by itself, detaching in update_cfs_rq_load_avg()
4393 * util_avg (~1ms) can make cfs->util_sum becoming null whereas in update_cfs_rq_load_avg()
4400 sa->util_sum = max_t(u32, sa->util_sum, sa->util_avg * PELT_MIN_DIVIDER); in update_cfs_rq_load_avg()
4403 sub_positive(&sa->runnable_avg, r); in update_cfs_rq_load_avg()
4404 sub_positive(&sa->runnable_sum, r * divider); in update_cfs_rq_load_avg()
4405 /* See sa->util_sum above */ in update_cfs_rq_load_avg()
4406 sa->runnable_sum = max_t(u32, sa->runnable_sum, in update_cfs_rq_load_avg()
4407 sa->runnable_avg * PELT_MIN_DIVIDER); in update_cfs_rq_load_avg()
4414 -(long)(removed_runnable * divider) >> SCHED_CAPACITY_SHIFT); in update_cfs_rq_load_avg()
4420 u64_u32_store_copy(sa->last_update_time, in update_cfs_rq_load_avg()
4421 cfs_rq->last_update_time_copy, in update_cfs_rq_load_avg()
4422 sa->last_update_time); in update_cfs_rq_load_avg()
4427 * attach_entity_load_avg - attach this entity to its cfs_rq load avg
4432 * cfs_rq->avg.last_update_time being current.
4437 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in attach_entity_load_avg()
4440 u32 divider = get_pelt_divider(&cfs_rq->avg); in attach_entity_load_avg()
4449 se->avg.last_update_time = cfs_rq->avg.last_update_time; in attach_entity_load_avg()
4450 se->avg.period_contrib = cfs_rq->avg.period_contrib; in attach_entity_load_avg()
4458 se->avg.util_sum = se->avg.util_avg * divider; in attach_entity_load_avg()
4460 se->avg.runnable_sum = se->avg.runnable_avg * divider; in attach_entity_load_avg()
4462 se->avg.load_sum = se->avg.load_avg * divider; in attach_entity_load_avg()
4463 if (se_weight(se) < se->avg.load_sum) in attach_entity_load_avg()
4464 se->avg.load_sum = div_u64(se->avg.load_sum, se_weight(se)); in attach_entity_load_avg()
4466 se->avg.load_sum = 1; in attach_entity_load_avg()
4469 cfs_rq->avg.util_avg += se->avg.util_avg; in attach_entity_load_avg()
4470 cfs_rq->avg.util_sum += se->avg.util_sum; in attach_entity_load_avg()
4471 cfs_rq->avg.runnable_avg += se->avg.runnable_avg; in attach_entity_load_avg()
4472 cfs_rq->avg.runnable_sum += se->avg.runnable_sum; in attach_entity_load_avg()
4474 add_tg_cfs_propagate(cfs_rq, se->avg.load_sum); in attach_entity_load_avg()
4482 * detach_entity_load_avg - detach this entity from its cfs_rq load avg
4487 * cfs_rq->avg.last_update_time being current.
4492 sub_positive(&cfs_rq->avg.util_avg, se->avg.util_avg); in detach_entity_load_avg()
4493 sub_positive(&cfs_rq->avg.util_sum, se->avg.util_sum); in detach_entity_load_avg()
4495 cfs_rq->avg.util_sum = max_t(u32, cfs_rq->avg.util_sum, in detach_entity_load_avg()
4496 cfs_rq->avg.util_avg * PELT_MIN_DIVIDER); in detach_entity_load_avg()
4498 sub_positive(&cfs_rq->avg.runnable_avg, se->avg.runnable_avg); in detach_entity_load_avg()
4499 sub_positive(&cfs_rq->avg.runnable_sum, se->avg.runnable_sum); in detach_entity_load_avg()
4501 cfs_rq->avg.runnable_sum = max_t(u32, cfs_rq->avg.runnable_sum, in detach_entity_load_avg()
4502 cfs_rq->avg.runnable_avg * PELT_MIN_DIVIDER); in detach_entity_load_avg()
4504 add_tg_cfs_propagate(cfs_rq, -se->avg.load_sum); in detach_entity_load_avg()
4529 if (se->avg.last_update_time && !(flags & SKIP_AGE_LOAD)) in update_load_avg()
4535 if (!se->avg.last_update_time && (flags & DO_ATTACH)) { in update_load_avg()
4585 * tasks cannot exit without having gone through wake_up_new_task() -> in remove_entity_load_avg()
4592 raw_spin_lock_irqsave(&cfs_rq->removed.lock, flags); in remove_entity_load_avg()
4593 ++cfs_rq->removed.nr; in remove_entity_load_avg()
4594 cfs_rq->removed.util_avg += se->avg.util_avg; in remove_entity_load_avg()
4595 cfs_rq->removed.load_avg += se->avg.load_avg; in remove_entity_load_avg()
4596 cfs_rq->removed.runnable_avg += se->avg.runnable_avg; in remove_entity_load_avg()
4597 raw_spin_unlock_irqrestore(&cfs_rq->removed.lock, flags); in remove_entity_load_avg()
4602 return cfs_rq->avg.runnable_avg; in cfs_rq_runnable_avg()
4607 return cfs_rq->avg.load_avg; in cfs_rq_load_avg()
4614 return READ_ONCE(p->se.avg.util_avg); in task_util()
4619 struct util_est ue = READ_ONCE(p->se.avg.util_est); in _task_util_est()
4654 enqueued = cfs_rq->avg.util_est.enqueued; in util_est_enqueue()
4656 WRITE_ONCE(cfs_rq->avg.util_est.enqueued, enqueued); in util_est_enqueue()
4670 enqueued = cfs_rq->avg.util_est.enqueued; in util_est_dequeue()
4671 enqueued -= min_t(unsigned int, enqueued, _task_util_est(p)); in util_est_dequeue()
4672 WRITE_ONCE(cfs_rq->avg.util_est.enqueued, enqueued); in util_est_dequeue()
4683 * abs(x) < y := (unsigned)(x + y - 1) < (2 * y - 1)
4689 return ((unsigned int)(value + margin - 1) < (2 * margin - 1)); in within_margin()
4710 * If the PELT values haven't changed since enqueue time, in util_est_update()
4713 ue = p->se.avg.util_est; in util_est_update()
4735 last_ewma_diff = ue.enqueued - ue.ewma; in util_est_update()
4736 last_enqueued_diff -= ue.enqueued; in util_est_update()
4746 * we cannot grant there is idle time in this CPU. in util_est_update()
4759 * ewma(t) = w * task_util(p) + (1-w) * ewma(t-1) in util_est_update()
4760 * = w * task_util(p) + ewma(t-1) - w * ewma(t-1) in util_est_update()
4761 * = w * (task_util(p) - ewma(t-1)) + ewma(t-1) in util_est_update()
4762 * = w * ( last_ewma_diff ) + ewma(t-1) in util_est_update()
4763 * = w * (last_ewma_diff + ewma(t-1) / w) in util_est_update()
4773 WRITE_ONCE(p->se.avg.util_est, ue); in util_est_update()
4775 trace_sched_util_est_se_tp(&p->se); in util_est_update()
4816 capacity_orig_thermal = capacity_orig - arch_scale_thermal_pressure(cpu); in util_fits_cpu()
4832 * +---------------------------------------- in util_fits_cpu()
4870 * +---------------------------------------- in util_fits_cpu()
4892 return -1; in util_fits_cpu()
4914 if (!p || p->nr_cpus_allowed == 1) { in update_misfit_status()
4915 rq->misfit_task_load = 0; in update_misfit_status()
4920 rq->misfit_task_load = 0; in update_misfit_status()
4928 rq->misfit_task_load = max_t(unsigned long, task_h_load(p), 1); in update_misfit_status()
4979 se->slice = sysctl_sched_base_slice; in place_entity()
4980 vslice = calc_delta_fair(se->slice, se); in place_entity()
4985 * will move 'time' backwards, this can screw around with the lag of in place_entity()
4990 if (sched_feat(PLACE_LAG) && cfs_rq->nr_running) { in place_entity()
4991 struct sched_entity *curr = cfs_rq->curr; in place_entity()
4994 lag = se->vlag; in place_entity()
5004 * lag_i = S - s_i = w_i * (V - v_i) in place_entity()
5009 * vl_i = V - v_i <=> v_i = V - vl_i in place_entity()
5021 * = (W*V + w_i*(V - vl_i)) / (W + w_i) in place_entity()
5022 * = (W*V + w_i*V - w_i*vl_i) / (W + w_i) in place_entity()
5023 * = (V*(W + w_i) - w_i*l) / (W + w_i) in place_entity()
5024 * = V - w_i*vl_i / (W + w_i) in place_entity()
5028 * vl'_i = V' - v_i in place_entity()
5029 * = V - w_i*vl_i / (W + w_i) - (V - vl_i) in place_entity()
5030 * = vl_i - w_i*vl_i / (W + w_i) in place_entity()
5040 * vl'_i = vl_i - w_i*vl_i / (W + w_i) in place_entity()
5041 * = ((W + w_i)*vl_i - w_i*vl_i) / (W + w_i) in place_entity()
5043 * (W + w_i)*vl'_i = (W + w_i)*vl_i - w_i*vl_i in place_entity()
5048 load = cfs_rq->avg_load; in place_entity()
5049 if (curr && curr->on_rq) in place_entity()
5050 load += scale_load_down(curr->load.weight); in place_entity()
5052 lag *= load + scale_load_down(se->load.weight); in place_entity()
5058 se->vruntime = vruntime - lag; in place_entity()
5071 se->deadline = se->vruntime + vslice; in place_entity()
5082 bool curr = cfs_rq->curr == se; in enqueue_entity()
5095 * - Update loads to have both entity and cfs_rq synced with now. in enqueue_entity()
5096 * - For group_entity, update its runnable_weight to reflect the new in enqueue_entity()
5098 * - For group_entity, update its weight to reflect the new share of in enqueue_entity()
5100 * - Add its new weight to cfs_rq->load.weight in enqueue_entity()
5106 * but update_cfs_group() here will re-adjust the weight and have to in enqueue_entity()
5112 * XXX now that the entity has been re-weighted, and it's lag adjusted, in enqueue_entity()
5122 se->exec_start = 0; in enqueue_entity()
5128 se->on_rq = 1; in enqueue_entity()
5130 if (cfs_rq->nr_running == 1) { in enqueue_entity()
5138 if (cfs_rq_throttled(cfs_rq) && !cfs_rq->throttled_clock) in enqueue_entity()
5139 cfs_rq->throttled_clock = rq_clock(rq); in enqueue_entity()
5140 if (!cfs_rq->throttled_clock_self) in enqueue_entity()
5141 cfs_rq->throttled_clock_self = rq_clock(rq); in enqueue_entity()
5151 if (cfs_rq->next != se) in __clear_buddies_next()
5154 cfs_rq->next = NULL; in __clear_buddies_next()
5160 if (cfs_rq->next == se) in clear_buddies()
5175 * Update run-time statistics of the 'current'. in dequeue_entity()
5181 * - Update loads to have both entity and cfs_rq synced with now. in dequeue_entity()
5182 * - For group_entity, update its runnable_weight to reflect the new in dequeue_entity()
5184 * - Subtract its previous weight from cfs_rq->load.weight. in dequeue_entity()
5185 * - For group entity, update its weight to reflect the new share in dequeue_entity()
5196 if (se != cfs_rq->curr) in dequeue_entity()
5198 se->on_rq = 0; in dequeue_entity()
5210 * further than we started -- ie. we'll be penalized. in dequeue_entity()
5215 if (cfs_rq->nr_running == 0) in dequeue_entity()
5225 if (se->on_rq) { in set_next_entity()
5228 * a CPU. So account for the time it spent waiting on the in set_next_entity()
5238 se->vlag = se->deadline; in set_next_entity()
5242 cfs_rq->curr = se; in set_next_entity()
5247 * when there are only lesser-weight tasks around): in set_next_entity()
5250 rq_of(cfs_rq)->cfs.load.weight >= 2*se->load.weight) { in set_next_entity()
5254 __schedstat_set(stats->slice_max, in set_next_entity()
5255 max((u64)stats->slice_max, in set_next_entity()
5256 se->sum_exec_runtime - se->prev_sum_exec_runtime)); in set_next_entity()
5259 se->prev_sum_exec_runtime = se->sum_exec_runtime; in set_next_entity()
5276 cfs_rq->next && entity_eligible(cfs_rq, cfs_rq->next)) in pick_next_entity()
5277 return cfs_rq->next; in pick_next_entity()
5290 if (prev->on_rq) in put_prev_entity()
5296 if (prev->on_rq) { in put_prev_entity()
5303 cfs_rq->curr = NULL; in put_prev_entity()
5310 * Update run-time statistics of the 'current'. in entity_tick()
5333 hrtimer_active(&rq_of(cfs_rq)->hrtick_timer)) in entity_tick()
5388 * directly instead of rq->clock to avoid adding additional synchronization
5389 * around rq->lock.
5391 * requires cfs_b->lock
5397 if (unlikely(cfs_b->quota == RUNTIME_INF)) in __refill_cfs_bandwidth_runtime()
5400 cfs_b->runtime += cfs_b->quota; in __refill_cfs_bandwidth_runtime()
5401 runtime = cfs_b->runtime_snap - cfs_b->runtime; in __refill_cfs_bandwidth_runtime()
5403 cfs_b->burst_time += runtime; in __refill_cfs_bandwidth_runtime()
5404 cfs_b->nr_burst++; in __refill_cfs_bandwidth_runtime()
5407 cfs_b->runtime = min(cfs_b->runtime, cfs_b->quota + cfs_b->burst); in __refill_cfs_bandwidth_runtime()
5408 cfs_b->runtime_snap = cfs_b->runtime; in __refill_cfs_bandwidth_runtime()
5413 return &tg->cfs_bandwidth; in tg_cfs_bandwidth()
5422 lockdep_assert_held(&cfs_b->lock); in __assign_cfs_rq_runtime()
5425 min_amount = target_runtime - cfs_rq->runtime_remaining; in __assign_cfs_rq_runtime()
5427 if (cfs_b->quota == RUNTIME_INF) in __assign_cfs_rq_runtime()
5432 if (cfs_b->runtime > 0) { in __assign_cfs_rq_runtime()
5433 amount = min(cfs_b->runtime, min_amount); in __assign_cfs_rq_runtime()
5434 cfs_b->runtime -= amount; in __assign_cfs_rq_runtime()
5435 cfs_b->idle = 0; in __assign_cfs_rq_runtime()
5439 cfs_rq->runtime_remaining += amount; in __assign_cfs_rq_runtime()
5441 return cfs_rq->runtime_remaining > 0; in __assign_cfs_rq_runtime()
5447 struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg); in assign_cfs_rq_runtime()
5450 raw_spin_lock(&cfs_b->lock); in assign_cfs_rq_runtime()
5452 raw_spin_unlock(&cfs_b->lock); in assign_cfs_rq_runtime()
5460 cfs_rq->runtime_remaining -= delta_exec; in __account_cfs_rq_runtime()
5462 if (likely(cfs_rq->runtime_remaining > 0)) in __account_cfs_rq_runtime()
5465 if (cfs_rq->throttled) in __account_cfs_rq_runtime()
5471 if (!assign_cfs_rq_runtime(cfs_rq) && likely(cfs_rq->curr)) in __account_cfs_rq_runtime()
5478 if (!cfs_bandwidth_used() || !cfs_rq->runtime_enabled) in account_cfs_rq_runtime()
5486 return cfs_bandwidth_used() && cfs_rq->throttled; in cfs_rq_throttled()
5492 return cfs_bandwidth_used() && cfs_rq->throttle_count; in throttled_hierarchy()
5498 * load-balance operations.
5505 src_cfs_rq = tg->cfs_rq[src_cpu]; in throttled_lb_pair()
5506 dest_cfs_rq = tg->cfs_rq[dest_cpu]; in throttled_lb_pair()
5515 struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; in tg_unthrottle_up()
5517 cfs_rq->throttle_count--; in tg_unthrottle_up()
5518 if (!cfs_rq->throttle_count) { in tg_unthrottle_up()
5519 cfs_rq->throttled_clock_pelt_time += rq_clock_pelt(rq) - in tg_unthrottle_up()
5520 cfs_rq->throttled_clock_pelt; in tg_unthrottle_up()
5526 if (cfs_rq->throttled_clock_self) { in tg_unthrottle_up()
5527 u64 delta = rq_clock(rq) - cfs_rq->throttled_clock_self; in tg_unthrottle_up()
5529 cfs_rq->throttled_clock_self = 0; in tg_unthrottle_up()
5534 cfs_rq->throttled_clock_self_time += delta; in tg_unthrottle_up()
5544 struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; in tg_throttle_down()
5546 /* group is entering throttled state, stop time */ in tg_throttle_down()
5547 if (!cfs_rq->throttle_count) { in tg_throttle_down()
5548 cfs_rq->throttled_clock_pelt = rq_clock_pelt(rq); in tg_throttle_down()
5551 SCHED_WARN_ON(cfs_rq->throttled_clock_self); in tg_throttle_down()
5552 if (cfs_rq->nr_running) in tg_throttle_down()
5553 cfs_rq->throttled_clock_self = rq_clock(rq); in tg_throttle_down()
5555 cfs_rq->throttle_count++; in tg_throttle_down()
5563 struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg); in throttle_cfs_rq()
5567 raw_spin_lock(&cfs_b->lock); in throttle_cfs_rq()
5576 * for 1ns of runtime rather than just check cfs_b. in throttle_cfs_rq()
5580 list_add_tail_rcu(&cfs_rq->throttled_list, in throttle_cfs_rq()
5581 &cfs_b->throttled_cfs_rq); in throttle_cfs_rq()
5583 raw_spin_unlock(&cfs_b->lock); in throttle_cfs_rq()
5588 se = cfs_rq->tg->se[cpu_of(rq_of(cfs_rq))]; in throttle_cfs_rq()
5592 walk_tg_tree_from(cfs_rq->tg, tg_throttle_down, tg_nop, (void *)rq); in throttle_cfs_rq()
5595 task_delta = cfs_rq->h_nr_running; in throttle_cfs_rq()
5596 idle_task_delta = cfs_rq->idle_h_nr_running; in throttle_cfs_rq()
5599 /* throttled entity or throttle-on-deactivate */ in throttle_cfs_rq()
5600 if (!se->on_rq) in throttle_cfs_rq()
5606 idle_task_delta = cfs_rq->h_nr_running; in throttle_cfs_rq()
5608 qcfs_rq->h_nr_running -= task_delta; in throttle_cfs_rq()
5609 qcfs_rq->idle_h_nr_running -= idle_task_delta; in throttle_cfs_rq()
5611 if (qcfs_rq->load.weight) { in throttle_cfs_rq()
5612 /* Avoid re-evaluating load for this entity: */ in throttle_cfs_rq()
5620 /* throttled entity or throttle-on-deactivate */ in throttle_cfs_rq()
5621 if (!se->on_rq) in throttle_cfs_rq()
5628 idle_task_delta = cfs_rq->h_nr_running; in throttle_cfs_rq()
5630 qcfs_rq->h_nr_running -= task_delta; in throttle_cfs_rq()
5631 qcfs_rq->idle_h_nr_running -= idle_task_delta; in throttle_cfs_rq()
5640 * throttled-list. rq->lock protects completion. in throttle_cfs_rq()
5642 cfs_rq->throttled = 1; in throttle_cfs_rq()
5643 SCHED_WARN_ON(cfs_rq->throttled_clock); in throttle_cfs_rq()
5644 if (cfs_rq->nr_running) in throttle_cfs_rq()
5645 cfs_rq->throttled_clock = rq_clock(rq); in throttle_cfs_rq()
5652 struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg); in unthrottle_cfs_rq()
5656 se = cfs_rq->tg->se[cpu_of(rq)]; in unthrottle_cfs_rq()
5658 cfs_rq->throttled = 0; in unthrottle_cfs_rq()
5662 raw_spin_lock(&cfs_b->lock); in unthrottle_cfs_rq()
5663 if (cfs_rq->throttled_clock) { in unthrottle_cfs_rq()
5664 cfs_b->throttled_time += rq_clock(rq) - cfs_rq->throttled_clock; in unthrottle_cfs_rq()
5665 cfs_rq->throttled_clock = 0; in unthrottle_cfs_rq()
5667 list_del_rcu(&cfs_rq->throttled_list); in unthrottle_cfs_rq()
5668 raw_spin_unlock(&cfs_b->lock); in unthrottle_cfs_rq()
5671 walk_tg_tree_from(cfs_rq->tg, tg_nop, tg_unthrottle_up, (void *)rq); in unthrottle_cfs_rq()
5673 if (!cfs_rq->load.weight) { in unthrottle_cfs_rq()
5674 if (!cfs_rq->on_list) in unthrottle_cfs_rq()
5687 task_delta = cfs_rq->h_nr_running; in unthrottle_cfs_rq()
5688 idle_task_delta = cfs_rq->idle_h_nr_running; in unthrottle_cfs_rq()
5692 if (se->on_rq) in unthrottle_cfs_rq()
5697 idle_task_delta = cfs_rq->h_nr_running; in unthrottle_cfs_rq()
5699 qcfs_rq->h_nr_running += task_delta; in unthrottle_cfs_rq()
5700 qcfs_rq->idle_h_nr_running += idle_task_delta; in unthrottle_cfs_rq()
5714 idle_task_delta = cfs_rq->h_nr_running; in unthrottle_cfs_rq()
5716 qcfs_rq->h_nr_running += task_delta; in unthrottle_cfs_rq()
5717 qcfs_rq->idle_h_nr_running += idle_task_delta; in unthrottle_cfs_rq()
5731 if (rq->curr == rq->idle && rq->cfs.nr_running) in unthrottle_cfs_rq()
5761 list_for_each_entry_safe(cursor, tmp, &rq->cfsb_csd_list, in __cfsb_csd_unthrottle()
5763 list_del_init(&cursor->throttled_csd_list); in __cfsb_csd_unthrottle()
5786 if (SCHED_WARN_ON(!list_empty(&cfs_rq->throttled_csd_list))) in __unthrottle_cfs_rq_async()
5789 first = list_empty(&rq->cfsb_csd_list); in __unthrottle_cfs_rq_async()
5790 list_add_tail(&cfs_rq->throttled_csd_list, &rq->cfsb_csd_list); in __unthrottle_cfs_rq_async()
5792 smp_call_function_single_async(cpu_of(rq), &rq->cfsb_csd); in __unthrottle_cfs_rq_async()
5806 cfs_rq->runtime_remaining <= 0)) in unthrottle_cfs_rq_async()
5823 list_for_each_entry_rcu(cfs_rq, &cfs_b->throttled_cfs_rq, in distribute_cfs_runtime()
5838 if (!list_empty(&cfs_rq->throttled_csd_list)) in distribute_cfs_runtime()
5843 SCHED_WARN_ON(cfs_rq->runtime_remaining > 0); in distribute_cfs_runtime()
5845 raw_spin_lock(&cfs_b->lock); in distribute_cfs_runtime()
5846 runtime = -cfs_rq->runtime_remaining + 1; in distribute_cfs_runtime()
5847 if (runtime > cfs_b->runtime) in distribute_cfs_runtime()
5848 runtime = cfs_b->runtime; in distribute_cfs_runtime()
5849 cfs_b->runtime -= runtime; in distribute_cfs_runtime()
5850 remaining = cfs_b->runtime; in distribute_cfs_runtime()
5851 raw_spin_unlock(&cfs_b->lock); in distribute_cfs_runtime()
5853 cfs_rq->runtime_remaining += runtime; in distribute_cfs_runtime()
5856 if (cfs_rq->runtime_remaining > 0) { in distribute_cfs_runtime()
5885 * period the timer is deactivated until scheduling resumes; cfs_b->idle is
5893 if (cfs_b->quota == RUNTIME_INF) in do_sched_cfs_period_timer()
5896 throttled = !list_empty(&cfs_b->throttled_cfs_rq); in do_sched_cfs_period_timer()
5897 cfs_b->nr_periods += overrun; in do_sched_cfs_period_timer()
5899 /* Refill extra burst quota even if cfs_b->idle */ in do_sched_cfs_period_timer()
5906 if (cfs_b->idle && !throttled) in do_sched_cfs_period_timer()
5911 cfs_b->idle = 1; in do_sched_cfs_period_timer()
5916 cfs_b->nr_throttled += overrun; in do_sched_cfs_period_timer()
5919 * This check is repeated as we release cfs_b->lock while we unthrottle. in do_sched_cfs_period_timer()
5921 while (throttled && cfs_b->runtime > 0) { in do_sched_cfs_period_timer()
5922 raw_spin_unlock_irqrestore(&cfs_b->lock, flags); in do_sched_cfs_period_timer()
5923 /* we can't nest cfs_b->lock while distributing bandwidth */ in do_sched_cfs_period_timer()
5925 raw_spin_lock_irqsave(&cfs_b->lock, flags); in do_sched_cfs_period_timer()
5934 cfs_b->idle = 0; in do_sched_cfs_period_timer()
5944 /* minimum remaining period time to redistribute slack quota */
5952 * Requires cfs_b->lock for hrtimer_expires_remaining to be safe against the
5958 struct hrtimer *refresh_timer = &cfs_b->period_timer; in runtime_refresh_within()
5961 /* if the call-back is running a quota refresh is already occurring */ in runtime_refresh_within()
5982 if (cfs_b->slack_started) in start_cfs_slack_bandwidth()
5984 cfs_b->slack_started = true; in start_cfs_slack_bandwidth()
5986 hrtimer_start(&cfs_b->slack_timer, in start_cfs_slack_bandwidth()
5994 struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg); in __return_cfs_rq_runtime()
5995 s64 slack_runtime = cfs_rq->runtime_remaining - min_cfs_rq_runtime; in __return_cfs_rq_runtime()
6000 raw_spin_lock(&cfs_b->lock); in __return_cfs_rq_runtime()
6001 if (cfs_b->quota != RUNTIME_INF) { in __return_cfs_rq_runtime()
6002 cfs_b->runtime += slack_runtime; in __return_cfs_rq_runtime()
6004 /* we are under rq->lock, defer unthrottling using a timer */ in __return_cfs_rq_runtime()
6005 if (cfs_b->runtime > sched_cfs_bandwidth_slice() && in __return_cfs_rq_runtime()
6006 !list_empty(&cfs_b->throttled_cfs_rq)) in __return_cfs_rq_runtime()
6009 raw_spin_unlock(&cfs_b->lock); in __return_cfs_rq_runtime()
6012 cfs_rq->runtime_remaining -= slack_runtime; in __return_cfs_rq_runtime()
6020 if (!cfs_rq->runtime_enabled || cfs_rq->nr_running) in return_cfs_rq_runtime()
6028 * it's necessary to juggle rq->locks to unthrottle their respective cfs_rqs.
6036 raw_spin_lock_irqsave(&cfs_b->lock, flags); in do_sched_cfs_slack_timer()
6037 cfs_b->slack_started = false; in do_sched_cfs_slack_timer()
6040 raw_spin_unlock_irqrestore(&cfs_b->lock, flags); in do_sched_cfs_slack_timer()
6044 if (cfs_b->quota != RUNTIME_INF && cfs_b->runtime > slice) in do_sched_cfs_slack_timer()
6045 runtime = cfs_b->runtime; in do_sched_cfs_slack_timer()
6047 raw_spin_unlock_irqrestore(&cfs_b->lock, flags); in do_sched_cfs_slack_timer()
6058 * runtime as update_curr() throttling can not trigger until it's on-rq.
6065 /* an active group must be handled by the update_curr()->put() path */ in check_enqueue_throttle()
6066 if (!cfs_rq->runtime_enabled || cfs_rq->curr) in check_enqueue_throttle()
6075 if (cfs_rq->runtime_remaining <= 0) in check_enqueue_throttle()
6086 if (!tg->parent) in sync_throttle()
6089 cfs_rq = tg->cfs_rq[cpu]; in sync_throttle()
6090 pcfs_rq = tg->parent->cfs_rq[cpu]; in sync_throttle()
6092 cfs_rq->throttle_count = pcfs_rq->throttle_count; in sync_throttle()
6093 cfs_rq->throttled_clock_pelt = rq_clock_pelt(cpu_rq(cpu)); in sync_throttle()
6102 if (likely(!cfs_rq->runtime_enabled || cfs_rq->runtime_remaining > 0)) in check_cfs_rq_runtime()
6136 raw_spin_lock_irqsave(&cfs_b->lock, flags); in sched_cfs_period_timer()
6138 overrun = hrtimer_forward_now(timer, cfs_b->period); in sched_cfs_period_timer()
6145 u64 new, old = ktime_to_ns(cfs_b->period); in sched_cfs_period_timer()
6154 cfs_b->period = ns_to_ktime(new); in sched_cfs_period_timer()
6155 cfs_b->quota *= 2; in sched_cfs_period_timer()
6156 cfs_b->burst *= 2; in sched_cfs_period_timer()
6162 div_u64(cfs_b->quota, NSEC_PER_USEC)); in sched_cfs_period_timer()
6168 div_u64(cfs_b->quota, NSEC_PER_USEC)); in sched_cfs_period_timer()
6176 cfs_b->period_active = 0; in sched_cfs_period_timer()
6177 raw_spin_unlock_irqrestore(&cfs_b->lock, flags); in sched_cfs_period_timer()
6184 raw_spin_lock_init(&cfs_b->lock); in init_cfs_bandwidth()
6185 cfs_b->runtime = 0; in init_cfs_bandwidth()
6186 cfs_b->quota = RUNTIME_INF; in init_cfs_bandwidth()
6187 cfs_b->period = ns_to_ktime(default_cfs_period()); in init_cfs_bandwidth()
6188 cfs_b->burst = 0; in init_cfs_bandwidth()
6189 cfs_b->hierarchical_quota = parent ? parent->hierarchical_quota : RUNTIME_INF; in init_cfs_bandwidth()
6191 INIT_LIST_HEAD(&cfs_b->throttled_cfs_rq); in init_cfs_bandwidth()
6192 hrtimer_init(&cfs_b->period_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED); in init_cfs_bandwidth()
6193 cfs_b->period_timer.function = sched_cfs_period_timer; in init_cfs_bandwidth()
6196 hrtimer_set_expires(&cfs_b->period_timer, in init_cfs_bandwidth()
6197 get_random_u32_below(cfs_b->period)); in init_cfs_bandwidth()
6198 hrtimer_init(&cfs_b->slack_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in init_cfs_bandwidth()
6199 cfs_b->slack_timer.function = sched_cfs_slack_timer; in init_cfs_bandwidth()
6200 cfs_b->slack_started = false; in init_cfs_bandwidth()
6205 cfs_rq->runtime_enabled = 0; in init_cfs_rq_runtime()
6206 INIT_LIST_HEAD(&cfs_rq->throttled_list); in init_cfs_rq_runtime()
6208 INIT_LIST_HEAD(&cfs_rq->throttled_csd_list); in init_cfs_rq_runtime()
6214 lockdep_assert_held(&cfs_b->lock); in start_cfs_bandwidth()
6216 if (cfs_b->period_active) in start_cfs_bandwidth()
6219 cfs_b->period_active = 1; in start_cfs_bandwidth()
6220 hrtimer_forward_now(&cfs_b->period_timer, cfs_b->period); in start_cfs_bandwidth()
6221 hrtimer_start_expires(&cfs_b->period_timer, HRTIMER_MODE_ABS_PINNED); in start_cfs_bandwidth()
6229 if (!cfs_b->throttled_cfs_rq.next) in destroy_cfs_bandwidth()
6232 hrtimer_cancel(&cfs_b->period_timer); in destroy_cfs_bandwidth()
6233 hrtimer_cancel(&cfs_b->slack_timer); in destroy_cfs_bandwidth()
6250 if (list_empty(&rq->cfsb_csd_list)) in destroy_cfs_bandwidth()
6276 struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth; in update_runtime_enabled()
6277 struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; in update_runtime_enabled()
6279 raw_spin_lock(&cfs_b->lock); in update_runtime_enabled()
6280 cfs_rq->runtime_enabled = cfs_b->quota != RUNTIME_INF; in update_runtime_enabled()
6281 raw_spin_unlock(&cfs_b->lock); in update_runtime_enabled()
6302 struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; in unthrottle_offline_cfs_rqs()
6304 if (!cfs_rq->runtime_enabled) in unthrottle_offline_cfs_rqs()
6311 cfs_rq->runtime_remaining = 1; in unthrottle_offline_cfs_rqs()
6316 cfs_rq->runtime_enabled = 0; in unthrottle_offline_cfs_rqs()
6333 if (cfs_rq->runtime_enabled || in cfs_task_bw_constrained()
6334 tg_cfs_bandwidth(cfs_rq->tg)->hierarchical_quota != RUNTIME_INF) in cfs_task_bw_constrained()
6352 if (rq->nr_running != 1) in sched_fair_update_stop_tick()
6426 struct sched_entity *se = &p->se; in hrtick_start_fair()
6430 if (rq->cfs.h_nr_running > 1) { in hrtick_start_fair()
6431 u64 ran = se->sum_exec_runtime - se->prev_sum_exec_runtime; in hrtick_start_fair()
6432 u64 slice = se->slice; in hrtick_start_fair()
6433 s64 delta = slice - ran; in hrtick_start_fair()
6451 struct task_struct *curr = rq->curr; in hrtick_update()
6453 if (!hrtick_enabled_fair(rq) || curr->sched_class != &fair_sched_class) in hrtick_update()
6481 if (!READ_ONCE(rq->rd->overutilized) && cpu_overutilized(rq->cpu)) { in update_overutilized_status()
6482 WRITE_ONCE(rq->rd->overutilized, SG_OVERUTILIZED); in update_overutilized_status()
6483 trace_sched_overutilized_tp(rq->rd, SG_OVERUTILIZED); in update_overutilized_status()
6493 return unlikely(rq->nr_running == rq->cfs.idle_h_nr_running && in sched_idle_rq()
6494 rq->nr_running); in sched_idle_rq()
6513 struct sched_entity *se = &p->se; in enqueue_task_fair()
6523 util_est_enqueue(&rq->cfs, p); in enqueue_task_fair()
6530 if (p->in_iowait) in enqueue_task_fair()
6534 if (se->on_rq) in enqueue_task_fair()
6539 cfs_rq->h_nr_running++; in enqueue_task_fair()
6540 cfs_rq->idle_h_nr_running += idle_h_nr_running; in enqueue_task_fair()
6559 cfs_rq->h_nr_running++; in enqueue_task_fair()
6560 cfs_rq->idle_h_nr_running += idle_h_nr_running; in enqueue_task_fair()
6606 struct sched_entity *se = &p->se; in dequeue_task_fair()
6611 util_est_dequeue(&rq->cfs, p); in dequeue_task_fair()
6617 cfs_rq->h_nr_running--; in dequeue_task_fair()
6618 cfs_rq->idle_h_nr_running -= idle_h_nr_running; in dequeue_task_fair()
6628 if (cfs_rq->load.weight) { in dequeue_task_fair()
6629 /* Avoid re-evaluating load for this entity: */ in dequeue_task_fair()
6649 cfs_rq->h_nr_running--; in dequeue_task_fair()
6650 cfs_rq->idle_h_nr_running -= idle_h_nr_running; in dequeue_task_fair()
6666 rq->next_balance = jiffies; in dequeue_task_fair()
6669 util_est_update(&rq->cfs, p, task_sleep); in dequeue_task_fair()
6695 return cfs_rq_load_avg(&rq->cfs); in cpu_load()
6699 * cpu_load_without - compute CPU load without any contributions from *p
6717 if (cpu_of(rq) != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in cpu_load_without()
6720 cfs_rq = &rq->cfs; in cpu_load_without()
6721 load = READ_ONCE(cfs_rq->avg.load_avg); in cpu_load_without()
6731 return cfs_rq_runnable_avg(&rq->cfs); in cpu_runnable()
6740 if (cpu_of(rq) != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in cpu_runnable_without()
6743 cfs_rq = &rq->cfs; in cpu_runnable_without()
6744 runnable = READ_ONCE(cfs_rq->avg.runnable_avg); in cpu_runnable_without()
6747 lsub_positive(&runnable, p->se.avg.runnable_avg); in cpu_runnable_without()
6754 return cpu_rq(cpu)->cpu_capacity; in capacity_of()
6760 * Only decay a single time; tasks that have less then 1 wakeup per in record_wakee()
6763 if (time_after(jiffies, current->wakee_flip_decay_ts + HZ)) { in record_wakee()
6764 current->wakee_flips >>= 1; in record_wakee()
6765 current->wakee_flip_decay_ts = jiffies; in record_wakee()
6768 if (current->last_wakee != p) { in record_wakee()
6769 current->last_wakee = p; in record_wakee()
6770 current->wakee_flips++; in record_wakee()
6775 * Detect M:N waker/wakee relationships via a switching-frequency heuristic.
6785 * non-monogamous, with partner count exceeding socket size.
6793 unsigned int master = current->wakee_flips; in wake_wide()
6794 unsigned int slave = p->wakee_flips; in wake_wide()
6809 * wake_affine_idle() - only considers 'now', it check if the waking CPU is
6810 * cache-affine and is (or will be) idle.
6812 * wake_affine_weight() - considers the weight to reflect the average
6834 if (sync && cpu_rq(this_cpu)->nr_running == 1) in wake_affine_idle()
6858 this_eff_load -= current_load; in wake_affine_weight()
6869 prev_eff_load -= task_load; in wake_affine_weight()
6871 prev_eff_load *= 100 + (sd->imbalance_pct - 100) / 2; in wake_affine_weight()
6897 schedstat_inc(p->stats.nr_wakeups_affine_attempts); in wake_affine()
6901 schedstat_inc(sd->ttwu_move_affine); in wake_affine()
6902 schedstat_inc(p->stats.nr_wakeups_affine); in wake_affine()
6910 * find_idlest_group_cpu - find the idlest CPU among the CPUs in the group.
6919 int shallowest_idle_cpu = -1; in find_idlest_group_cpu()
6923 if (group->group_weight == 1) in find_idlest_group_cpu()
6927 for_each_cpu_and(i, sched_group_span(group), p->cpus_ptr) { in find_idlest_group_cpu()
6938 if (idle && idle->exit_latency < min_exit_latency) { in find_idlest_group_cpu()
6944 min_exit_latency = idle->exit_latency; in find_idlest_group_cpu()
6945 latest_idle_timestamp = rq->idle_stamp; in find_idlest_group_cpu()
6947 } else if ((!idle || idle->exit_latency == min_exit_latency) && in find_idlest_group_cpu()
6948 rq->idle_stamp > latest_idle_timestamp) { in find_idlest_group_cpu()
6954 latest_idle_timestamp = rq->idle_stamp; in find_idlest_group_cpu()
6957 } else if (shallowest_idle_cpu == -1) { in find_idlest_group_cpu()
6966 return shallowest_idle_cpu != -1 ? shallowest_idle_cpu : least_loaded_cpu; in find_idlest_group_cpu()
6974 if (!cpumask_intersects(sched_domain_span(sd), p->cpus_ptr)) in find_idlest_cpu()
6982 sync_entity_load_avg(&p->se); in find_idlest_cpu()
6989 if (!(sd->flags & sd_flag)) { in find_idlest_cpu()
6990 sd = sd->child; in find_idlest_cpu()
6996 sd = sd->child; in find_idlest_cpu()
7003 sd = sd->child; in find_idlest_cpu()
7009 weight = sd->span_weight; in find_idlest_cpu()
7012 if (weight <= tmp->span_weight) in find_idlest_cpu()
7014 if (tmp->flags & sd_flag) in find_idlest_cpu()
7028 return -1; in __select_idle_cpu()
7041 WRITE_ONCE(sds->has_idle_cores, val); in set_idle_cores()
7050 return READ_ONCE(sds->has_idle_cores); in test_idle_cores()
7057 * information in sd_llc_shared->has_idle_cores.
7087 * sd_llc->shared->has_idle_cores and enabled through update_idle_core() above.
7097 if (*idle_cpu == -1) { in select_idle_core()
7098 if (sched_idle_cpu(cpu) && cpumask_test_cpu(cpu, p->cpus_ptr)) { in select_idle_core()
7106 if (*idle_cpu == -1 && cpumask_test_cpu(cpu, p->cpus_ptr)) in select_idle_core()
7114 return -1; in select_idle_core()
7124 for_each_cpu_and(cpu, cpu_smt_mask(target), p->cpus_ptr) { in select_idle_smt()
7131 return -1; in select_idle_smt()
7152 return -1; in select_idle_smt()
7159 * comparing the average scan cost (tracked in sd->avg_scan_cost) against the
7160 * average idle time for this rq (as found in rq->avg_idle).
7165 int i, cpu, idle_cpu = -1, nr = INT_MAX; in select_idle_cpu()
7170 u64 time = 0; in select_idle_cpu() local
7172 cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr); in select_idle_cpu()
7180 return -1; in select_idle_cpu()
7185 * predicted idle time. in select_idle_cpu()
7187 if (unlikely(this_rq->wake_stamp < now)) { in select_idle_cpu()
7188 while (this_rq->wake_stamp < now && this_rq->wake_avg_idle) { in select_idle_cpu()
7189 this_rq->wake_stamp++; in select_idle_cpu()
7190 this_rq->wake_avg_idle >>= 1; in select_idle_cpu()
7194 avg_idle = this_rq->wake_avg_idle; in select_idle_cpu()
7195 avg_cost = this_sd->avg_scan_cost + 1; in select_idle_cpu()
7197 span_avg = sd->span_weight * avg_idle; in select_idle_cpu()
7203 time = cpu_clock(this); in select_idle_cpu()
7209 /* because !--nr is the condition to stop scan */ in select_idle_cpu()
7210 nr = READ_ONCE(sd_share->nr_idle_scan) + 1; in select_idle_cpu()
7213 return -1; in select_idle_cpu()
7224 if (!--nr) in select_idle_cpu()
7225 return -1; in select_idle_cpu()
7236 time = cpu_clock(this) - time; in select_idle_cpu()
7240 * idle time. in select_idle_cpu()
7242 this_rq->wake_avg_idle -= min(this_rq->wake_avg_idle, time); in select_idle_cpu()
7244 update_avg(&this_sd->avg_scan_cost, time); in select_idle_cpu()
7260 int cpu, best_cpu = -1; in select_idle_capacity()
7264 cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr); in select_idle_capacity()
7286 cpu_cap = capacity_orig_of(cpu) - thermal_load_avg(cpu_rq(cpu)); in select_idle_capacity()
7289 * First, select CPU which fits better (-1 being better than 0). in select_idle_capacity()
7333 sync_entity_load_avg(&p->se); in select_idle_sibling()
7340 * per-cpu select_rq_mask usage in select_idle_sibling()
7357 * Allow a per-cpu kthread to stack with the wakee if the in select_idle_sibling()
7360 * per-cpu kthread that is now complete and the wakeup is in select_idle_sibling()
7367 this_rq()->nr_running <= 1 && in select_idle_sibling()
7373 recent_used_cpu = p->recent_used_cpu; in select_idle_sibling()
7374 p->recent_used_cpu = prev; in select_idle_sibling()
7379 cpumask_test_cpu(recent_used_cpu, p->cpus_ptr) && in select_idle_sibling()
7426 * cpu_util() - Estimates the amount of CPU capacity used by CFS tasks.
7429 * @dst_cpu: CPU @p migrates to, -1 if @p moves from @cpu or @p == NULL
7435 * CPU utilization is the sum of running time of runnable tasks plus the
7436 * recent utilization of currently non-runnable tasks on that CPU.
7444 * previously-executed tasks, which helps better deduce how busy a CPU will
7445 * be when a long-sleeping task wakes up. The contribution to CPU utilization
7446 * of such a task would be significantly decayed at this point of time.
7459 * could be seen as over-utilized even though CPU1 has 20% of spare CPU
7462 * after task migrations (scheduler-driven DVFS).
7469 struct cfs_rq *cfs_rq = &cpu_rq(cpu)->cfs; in cpu_util()
7470 unsigned long util = READ_ONCE(cfs_rq->avg.util_avg); in cpu_util()
7474 runnable = READ_ONCE(cfs_rq->avg.runnable_avg); in cpu_util()
7479 * If @dst_cpu is -1 or @p migrates from @cpu to @dst_cpu remove its in cpu_util()
7492 util_est = READ_ONCE(cfs_rq->avg.util_est.enqueued); in cpu_util()
7495 * During wake-up @p isn't enqueued yet and doesn't contribute in cpu_util()
7496 * to any cpu_rq(cpu)->cfs.avg.util_est.enqueued. in cpu_util()
7500 * During exec (@dst_cpu = -1) @p is enqueued and does in cpu_util()
7501 * contribute to cpu_rq(cpu)->cfs.util_est.enqueued. in cpu_util()
7510 * p->on_rq = TASK_ON_RQ_MIGRATING; in cpu_util()
7511 * -------------------------------- A in cpu_util()
7513 * dequeue_task_fair() + Race Time in cpu_util()
7515 * -------------------------------- B in cpu_util()
7533 return cpu_util(cpu, NULL, -1, 0); in cpu_util_cfs()
7538 return cpu_util(cpu, NULL, -1, 1); in cpu_util_cfs_boost()
7557 if (cpu != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in cpu_util_without()
7560 return cpu_util(cpu, p, -1, 0); in cpu_util_without()
7564 * energy_env - Utilization landscape for energy estimation.
7570 * @pd_cap: Entire perf domain capacity. (pd->nr_cpus * cpu_cap).
7580 * Compute the task busy time for compute_energy(). This time cannot be
7596 eenv->task_busy_time = busy_time; in eenv_task_busy_time()
7600 * Compute the perf_domain (PD) busy time for compute_energy(). Based on the
7610 * - A stable PD utilization, no matter which CPU of that PD we want to place
7613 * - A fair comparison between CPUs as the task contribution (task_util())
7617 * Set @eenv busy time for the PD that spans @pd_cpus. This busy time can't
7618 * exceed @eenv->pd_cap.
7628 unsigned long util = cpu_util(cpu, p, -1, 0); in eenv_pd_busy_time()
7633 eenv->pd_busy_time = min(eenv->pd_cap, busy_time); in eenv_pd_busy_time()
7640 * Returns the maximum utilization among @eenv->cpus. This utilization can't
7641 * exceed @eenv->cpu_cap.
7666 return min(max_util, eenv->cpu_cap); in eenv_pd_max_util()
7679 unsigned long busy_time = eenv->pd_busy_time; in compute_energy()
7682 busy_time = min(eenv->pd_cap, busy_time + eenv->task_busy_time); in compute_energy()
7684 return em_cpu_energy(pd->em_pd, max_util, busy_time, eenv->cpu_cap); in compute_energy()
7688 * find_energy_efficient_cpu(): Find most energy-efficient target CPU for the
7692 * out which of the CPU candidates is the most energy-efficient.
7709 * cluster-packing, and spreading inside a cluster. That should at least be
7716 * NOTE: Forkees are not accepted in the energy-aware wake-up path because
7720 * to be energy-inefficient in some use-cases. The alternative would be to
7723 * other use-cases too. So, until someone finds a better way to solve this,
7724 * let's keep things simple by re-using the existing slow path.
7732 struct root_domain *rd = this_rq()->rd; in find_energy_efficient_cpu()
7733 int cpu, best_energy_cpu, target = -1; in find_energy_efficient_cpu()
7734 int prev_fits = -1, best_fits = -1; in find_energy_efficient_cpu()
7742 pd = rcu_dereference(rd->pd); in find_energy_efficient_cpu()
7743 if (!pd || READ_ONCE(rd->overutilized)) in find_energy_efficient_cpu()
7747 * Energy-aware wake-up happens on the lowest sched_domain starting in find_energy_efficient_cpu()
7752 sd = sd->parent; in find_energy_efficient_cpu()
7758 sync_entity_load_avg(&p->se); in find_energy_efficient_cpu()
7764 for (; pd; pd = pd->next) { in find_energy_efficient_cpu()
7770 int max_spare_cap_cpu = -1; in find_energy_efficient_cpu()
7772 int fits, max_fits = -1; in find_energy_efficient_cpu()
7782 cpu_thermal_cap -= arch_scale_thermal_pressure(cpu); in find_energy_efficient_cpu()
7795 if (!cpumask_test_cpu(cpu, p->cpus_ptr)) in find_energy_efficient_cpu()
7814 * max-aggregated uclamp_{min, max}. in find_energy_efficient_cpu()
7851 base_energy = compute_energy(&eenv, pd, cpus, p, -1); in find_energy_efficient_cpu()
7860 prev_delta -= base_energy; in find_energy_efficient_cpu()
7884 cur_delta -= base_energy; in find_energy_efficient_cpu()
7928 int sync = (wake_flags & WF_SYNC) && !(current->flags & PF_EXITING); in select_task_rq_fair()
7937 * required for stable ->cpus_allowed in select_task_rq_fair()
7939 lockdep_assert_held(&p->pi_lock); in select_task_rq_fair()
7944 cpumask_test_cpu(cpu, p->cpus_ptr)) in select_task_rq_fair()
7954 want_affine = !wake_wide(p) && cpumask_test_cpu(cpu, p->cpus_ptr); in select_task_rq_fair()
7963 if (want_affine && (tmp->flags & SD_WAKE_AFFINE) && in select_task_rq_fair()
7977 if (tmp->flags & sd_flag) in select_task_rq_fair()
7997 * cfs_rq_of(p) references at time of call are still valid and identify the
7998 * previous CPU. The caller guarantees p->pi_lock or task_rq(p)->lock is held.
8002 struct sched_entity *se = &p->se; in migrate_task_rq_fair()
8010 * updated in a while, a substantial idle time will be missed, in migrate_task_rq_fair()
8011 * leading to an inflation after wake-up on the new rq. in migrate_task_rq_fair()
8013 * Estimate the missing time from the cfs_rq last_update_time in migrate_task_rq_fair()
8021 se->avg.last_update_time = 0; in migrate_task_rq_fair()
8028 remove_entity_load_avg(&p->se); in task_dead_fair()
8034 if (rq->nr_running) in balance_fair()
8044 if (SCHED_WARN_ON(!se->on_rq)) in set_next_buddy()
8048 cfs_rq_of(se)->next = se; in set_next_buddy()
8057 struct task_struct *curr = rq->curr; in check_preempt_wakeup()
8058 struct sched_entity *se = &curr->se, *pse = &p->se; in check_preempt_wakeup()
8070 * next-buddy nomination below. in check_preempt_wakeup()
8084 * Note: this also catches the edge-case of curr being in a throttled in check_preempt_wakeup()
8093 /* Idle tasks are by definition preempted by non-idle tasks. */ in check_preempt_wakeup()
8099 * Batch and idle tasks do not preempt non-idle tasks (their preemption in check_preempt_wakeup()
8102 if (unlikely(p->policy != SCHED_NORMAL) || !sched_feat(WAKEUP_PREEMPTION)) in check_preempt_wakeup()
8112 * Preempt an idle group in favor of a non-idle group (and don't preempt in check_preempt_wakeup()
8142 cfs_rq = &rq->cfs; in pick_task_fair()
8143 if (!cfs_rq->nr_running) in pick_task_fair()
8147 struct sched_entity *curr = cfs_rq->curr; in pick_task_fair()
8151 if (curr->on_rq) in pick_task_fair()
8171 struct cfs_rq *cfs_rq = &rq->cfs; in pick_next_task_fair()
8181 if (!prev || prev->sched_class != &fair_sched_class) in pick_next_task_fair()
8193 struct sched_entity *curr = cfs_rq->curr; in pick_next_task_fair()
8197 * have to consider cfs_rq->curr. If it is still a runnable in pick_next_task_fair()
8202 if (curr->on_rq) in pick_next_task_fair()
8214 cfs_rq = &rq->cfs; in pick_next_task_fair()
8216 if (!cfs_rq->nr_running) in pick_next_task_fair()
8235 struct sched_entity *pse = &prev->se; in pick_next_task_fair()
8238 int se_depth = se->depth; in pick_next_task_fair()
8239 int pse_depth = pse->depth; in pick_next_task_fair()
8276 list_move(&p->se.group_node, &rq->cfs_tasks); in pick_next_task_fair()
8294 * Because newidle_balance() releases (and re-acquires) rq->lock, it is in pick_next_task_fair()
8296 * must re-start the pick_next_entity() loop. in pick_next_task_fair()
8323 struct sched_entity *se = &prev->se; in put_prev_task_fair()
8337 struct task_struct *curr = rq->curr; in yield_task_fair()
8339 struct sched_entity *se = &curr->se; in yield_task_fair()
8344 if (unlikely(rq->nr_running == 1)) in yield_task_fair()
8351 * Update run-time statistics of the 'current'. in yield_task_fair()
8361 se->deadline += calc_delta_fair(se->slice, se); in yield_task_fair()
8366 struct sched_entity *se = &p->se; in yield_to_task_fair()
8369 if (!se->on_rq || throttled_hierarchy(cfs_rq_of(se))) in yield_to_task_fair()
8382 * Fair scheduling class load-balancing methods.
8386 * The purpose of load-balancing is to achieve the same basic fairness the
8387 * per-CPU scheduler provides, namely provide a proportional amount of compute
8388 * time to each task. This is expressed in the following equation:
8392 * Where W_i,n is the n-th weight average for CPU i. The instantaneous weight
8397 * Where w_i,j is the weight of the j-th runnable task on CPU i. This weight
8403 * W'_i,n = (2^n - 1) / 2^n * W_i,n + 1 / 2^n * W_i,0 (3)
8406 * fraction of 'recent' time available for SCHED_OTHER task execution. But it
8412 * imb_i,j = max{ avg(W/C), W_i/C_i } - min{ avg(W/C), W_j/C_j } (4)
8419 * - infeasible weights;
8420 * - local vs global optima in the discrete case. ]
8430 * of load-balance at each level inv. proportional to the number of CPUs in
8436 * \Sum { --- * --- * 2^i } = O(n) (5)
8438 * `- size of each group
8439 * | | `- number of CPUs doing load-balance
8440 * | `- freq
8441 * `- sum over all levels
8473 * time.
8483 * W_i,0 = \Sum_j \Prod_k w_k * ----- (9)
8490 * w_i,j,k is the weight of the j-th runnable task in the k-th cgroup on CPU i.
8572 /* The set of CPUs under consideration for load-balancing */
8587 * Is this task likely cache-hot:
8593 lockdep_assert_rq_held(env->src_rq); in task_hot()
8595 if (p->sched_class != &fair_sched_class) in task_hot()
8602 if (env->sd->flags & SD_SHARE_CPUCAPACITY) in task_hot()
8608 if (sched_feat(CACHE_HOT_BUDDY) && env->dst_rq->nr_running && in task_hot()
8609 (&p->se == cfs_rq_of(&p->se)->next)) in task_hot()
8612 if (sysctl_sched_migration_cost == -1) in task_hot()
8619 if (!sched_core_cookie_match(cpu_rq(env->dst_cpu), p)) in task_hot()
8625 delta = rq_clock_task(env->src_rq) - p->se.exec_start; in task_hot()
8634 * Returns -1, if task migration is not affected by locality.
8638 struct numa_group *numa_group = rcu_dereference(p->numa_group); in migrate_degrades_locality()
8643 return -1; in migrate_degrades_locality()
8645 if (!p->numa_faults || !(env->sd->flags & SD_NUMA)) in migrate_degrades_locality()
8646 return -1; in migrate_degrades_locality()
8648 src_nid = cpu_to_node(env->src_cpu); in migrate_degrades_locality()
8649 dst_nid = cpu_to_node(env->dst_cpu); in migrate_degrades_locality()
8652 return -1; in migrate_degrades_locality()
8655 if (src_nid == p->numa_preferred_nid) { in migrate_degrades_locality()
8656 if (env->src_rq->nr_running > env->src_rq->nr_preferred_running) in migrate_degrades_locality()
8659 return -1; in migrate_degrades_locality()
8663 if (dst_nid == p->numa_preferred_nid) in migrate_degrades_locality()
8667 if (env->idle == CPU_IDLE) in migrate_degrades_locality()
8668 return -1; in migrate_degrades_locality()
8686 return -1; in migrate_degrades_locality()
8691 * can_migrate_task - may task p from runqueue rq be migrated to this_cpu?
8698 lockdep_assert_rq_held(env->src_rq); in can_migrate_task()
8705 * 4) are cache-hot on their current CPU. in can_migrate_task()
8707 if (throttled_lb_pair(task_group(p), env->src_cpu, env->dst_cpu)) in can_migrate_task()
8714 if (!cpumask_test_cpu(env->dst_cpu, p->cpus_ptr)) { in can_migrate_task()
8717 schedstat_inc(p->stats.nr_failed_migrations_affine); in can_migrate_task()
8719 env->flags |= LBF_SOME_PINNED; in can_migrate_task()
8727 * - for NEWLY_IDLE in can_migrate_task()
8728 * - if we have already computed one in current iteration in can_migrate_task()
8729 * - if it's an active balance in can_migrate_task()
8731 if (env->idle == CPU_NEWLY_IDLE || in can_migrate_task()
8732 env->flags & (LBF_DST_PINNED | LBF_ACTIVE_LB)) in can_migrate_task()
8735 /* Prevent to re-select dst_cpu via env's CPUs: */ in can_migrate_task()
8736 for_each_cpu_and(cpu, env->dst_grpmask, env->cpus) { in can_migrate_task()
8737 if (cpumask_test_cpu(cpu, p->cpus_ptr)) { in can_migrate_task()
8738 env->flags |= LBF_DST_PINNED; in can_migrate_task()
8739 env->new_dst_cpu = cpu; in can_migrate_task()
8748 env->flags &= ~LBF_ALL_PINNED; in can_migrate_task()
8750 if (task_on_cpu(env->src_rq, p)) { in can_migrate_task()
8751 schedstat_inc(p->stats.nr_failed_migrations_running); in can_migrate_task()
8762 if (env->flags & LBF_ACTIVE_LB) in can_migrate_task()
8766 if (tsk_cache_hot == -1) in can_migrate_task()
8770 env->sd->nr_balance_failed > env->sd->cache_nice_tries) { in can_migrate_task()
8772 schedstat_inc(env->sd->lb_hot_gained[env->idle]); in can_migrate_task()
8773 schedstat_inc(p->stats.nr_forced_migrations); in can_migrate_task()
8778 schedstat_inc(p->stats.nr_failed_migrations_hot); in can_migrate_task()
8783 * detach_task() -- detach the task for the migration specified in env
8787 lockdep_assert_rq_held(env->src_rq); in detach_task()
8789 deactivate_task(env->src_rq, p, DEQUEUE_NOCLOCK); in detach_task()
8790 set_task_cpu(p, env->dst_cpu); in detach_task()
8794 * detach_one_task() -- tries to dequeue exactly one task from env->src_rq, as
8803 lockdep_assert_rq_held(env->src_rq); in detach_one_task()
8806 &env->src_rq->cfs_tasks, se.group_node) { in detach_one_task()
8814 * lb_gained[env->idle] is updated (other is detach_tasks) in detach_one_task()
8818 schedstat_inc(env->sd->lb_gained[env->idle]); in detach_one_task()
8825 * detach_tasks() -- tries to detach up to imbalance load/util/tasks from
8832 struct list_head *tasks = &env->src_rq->cfs_tasks; in detach_tasks()
8837 lockdep_assert_rq_held(env->src_rq); in detach_tasks()
8843 if (env->src_rq->nr_running <= 1) { in detach_tasks()
8844 env->flags &= ~LBF_ALL_PINNED; in detach_tasks()
8848 if (env->imbalance <= 0) in detach_tasks()
8856 if (env->idle != CPU_NOT_IDLE && env->src_rq->nr_running <= 1) in detach_tasks()
8859 env->loop++; in detach_tasks()
8864 if (env->loop > env->loop_max && in detach_tasks()
8865 !(env->flags & LBF_ALL_PINNED)) in detach_tasks()
8869 if (env->loop > env->loop_break) { in detach_tasks()
8870 env->loop_break += SCHED_NR_MIGRATE_BREAK; in detach_tasks()
8871 env->flags |= LBF_NEED_BREAK; in detach_tasks()
8880 switch (env->migration_type) { in detach_tasks()
8885 * value. Make sure that env->imbalance decreases in detach_tasks()
8892 load < 16 && !env->sd->nr_balance_failed) in detach_tasks()
8901 if (shr_bound(load, env->sd->nr_balance_failed) > env->imbalance) in detach_tasks()
8904 env->imbalance -= load; in detach_tasks()
8910 if (util > env->imbalance) in detach_tasks()
8913 env->imbalance -= util; in detach_tasks()
8917 env->imbalance--; in detach_tasks()
8922 if (task_fits_cpu(p, env->src_cpu)) in detach_tasks()
8925 env->imbalance = 0; in detach_tasks()
8930 list_add(&p->se.group_node, &env->tasks); in detach_tasks()
8940 if (env->idle == CPU_NEWLY_IDLE) in detach_tasks()
8948 if (env->imbalance <= 0) in detach_tasks()
8953 list_move(&p->se.group_node, tasks); in detach_tasks()
8961 schedstat_add(env->sd->lb_gained[env->idle], detached); in detach_tasks()
8967 * attach_task() -- attach the task detached by detach_task() to its new rq.
8979 * attach_one_task() -- attaches the task returned from detach_one_task() to
8993 * attach_tasks() -- attaches all tasks detached by detach_tasks() to their
8998 struct list_head *tasks = &env->tasks; in attach_tasks()
9002 rq_lock(env->dst_rq, &rf); in attach_tasks()
9003 update_rq_clock(env->dst_rq); in attach_tasks()
9007 list_del_init(&p->se.group_node); in attach_tasks()
9009 attach_task(env->dst_rq, p); in attach_tasks()
9012 rq_unlock(env->dst_rq, &rf); in attach_tasks()
9018 if (cfs_rq->avg.load_avg) in cfs_rq_has_blocked()
9021 if (cfs_rq->avg.util_avg) in cfs_rq_has_blocked()
9029 if (READ_ONCE(rq->avg_rt.util_avg)) in others_have_blocked()
9032 if (READ_ONCE(rq->avg_dl.util_avg)) in others_have_blocked()
9039 if (READ_ONCE(rq->avg_irq.util_avg)) in others_have_blocked()
9048 WRITE_ONCE(rq->last_blocked_load_update_tick, jiffies); in update_blocked_load_tick()
9054 rq->has_blocked_load = 0; in update_blocked_load_status()
9074 curr_class = rq->curr->sched_class; in __update_blocked_others()
9107 if (cfs_rq->nr_running == 0) in __update_blocked_fair()
9110 if (cfs_rq == &rq->cfs) in __update_blocked_fair()
9115 se = cfs_rq->tg->se[cpu]; in __update_blocked_fair()
9136 * This needs to be done in a top-down fashion because the load of a child
9142 struct sched_entity *se = cfs_rq->tg->se[cpu_of(rq)]; in update_cfs_rq_h_load()
9146 if (cfs_rq->last_h_load_update == now) in update_cfs_rq_h_load()
9149 WRITE_ONCE(cfs_rq->h_load_next, NULL); in update_cfs_rq_h_load()
9152 WRITE_ONCE(cfs_rq->h_load_next, se); in update_cfs_rq_h_load()
9153 if (cfs_rq->last_h_load_update == now) in update_cfs_rq_h_load()
9158 cfs_rq->h_load = cfs_rq_load_avg(cfs_rq); in update_cfs_rq_h_load()
9159 cfs_rq->last_h_load_update = now; in update_cfs_rq_h_load()
9162 while ((se = READ_ONCE(cfs_rq->h_load_next)) != NULL) { in update_cfs_rq_h_load()
9163 load = cfs_rq->h_load; in update_cfs_rq_h_load()
9164 load = div64_ul(load * se->avg.load_avg, in update_cfs_rq_h_load()
9167 cfs_rq->h_load = load; in update_cfs_rq_h_load()
9168 cfs_rq->last_h_load_update = now; in update_cfs_rq_h_load()
9177 return div64_ul(p->se.avg.load_avg * cfs_rq->h_load, in task_h_load()
9183 struct cfs_rq *cfs_rq = &rq->cfs; in __update_blocked_fair()
9195 return p->se.avg.load_avg; in task_h_load()
9221 * sg_lb_stats - stats of a sched_group required for load_balancing
9228 unsigned long group_runnable; /* Total runnable time over the CPUs of the group */
9244 * sd_lb_stats - Structure to store the statistics of a sched_domain
9298 used = READ_ONCE(rq->avg_rt.util_avg); in scale_rt_capacity()
9299 used += READ_ONCE(rq->avg_dl.util_avg); in scale_rt_capacity()
9305 free = max - used; in scale_rt_capacity()
9313 struct sched_group *sdg = sd->groups; in update_cpu_capacity()
9315 cpu_rq(cpu)->cpu_capacity_orig = arch_scale_cpu_capacity(cpu); in update_cpu_capacity()
9320 cpu_rq(cpu)->cpu_capacity = capacity; in update_cpu_capacity()
9323 sdg->sgc->capacity = capacity; in update_cpu_capacity()
9324 sdg->sgc->min_capacity = capacity; in update_cpu_capacity()
9325 sdg->sgc->max_capacity = capacity; in update_cpu_capacity()
9330 struct sched_domain *child = sd->child; in update_group_capacity()
9331 struct sched_group *group, *sdg = sd->groups; in update_group_capacity()
9335 interval = msecs_to_jiffies(sd->balance_interval); in update_group_capacity()
9337 sdg->sgc->next_update = jiffies + interval; in update_group_capacity()
9348 if (child->flags & SD_OVERLAP) { in update_group_capacity()
9367 group = child->groups; in update_group_capacity()
9369 struct sched_group_capacity *sgc = group->sgc; in update_group_capacity()
9371 capacity += sgc->capacity; in update_group_capacity()
9372 min_capacity = min(sgc->min_capacity, min_capacity); in update_group_capacity()
9373 max_capacity = max(sgc->max_capacity, max_capacity); in update_group_capacity()
9374 group = group->next; in update_group_capacity()
9375 } while (group != child->groups); in update_group_capacity()
9378 sdg->sgc->capacity = capacity; in update_group_capacity()
9379 sdg->sgc->min_capacity = min_capacity; in update_group_capacity()
9380 sdg->sgc->max_capacity = max_capacity; in update_group_capacity()
9391 return ((rq->cpu_capacity * sd->imbalance_pct) < in check_cpu_capacity()
9392 (rq->cpu_capacity_orig * 100)); in check_cpu_capacity()
9402 return rq->misfit_task_load && in check_misfit_status()
9403 (rq->cpu_capacity_orig < rq->rd->max_cpu_capacity || in check_misfit_status()
9409 * groups is inadequate due to ->cpus_ptr constraints.
9418 * If we were to balance group-wise we'd place two tasks in the first group and
9438 return group->sgc->imbalance; in sg_imbalanced()
9456 if (sgs->sum_nr_running < sgs->group_weight) in group_has_capacity()
9459 if ((sgs->group_capacity * imbalance_pct) < in group_has_capacity()
9460 (sgs->group_runnable * 100)) in group_has_capacity()
9463 if ((sgs->group_capacity * 100) > in group_has_capacity()
9464 (sgs->group_util * imbalance_pct)) in group_has_capacity()
9481 if (sgs->sum_nr_running <= sgs->group_weight) in group_is_overloaded()
9484 if ((sgs->group_capacity * 100) < in group_is_overloaded()
9485 (sgs->group_util * imbalance_pct)) in group_is_overloaded()
9488 if ((sgs->group_capacity * imbalance_pct) < in group_is_overloaded()
9489 (sgs->group_runnable * 100)) in group_is_overloaded()
9506 if (sgs->group_asym_packing) in group_classify()
9509 if (sgs->group_smt_balance) in group_classify()
9512 if (sgs->group_misfit_task_load) in group_classify()
9522 * sched_use_asym_prio - Check whether asym_packing priority must be used
9537 return sd->flags & SD_SHARE_CPUCAPACITY || is_core_idle(cpu); in sched_use_asym_prio()
9541 * sched_asym - Check if the destination CPU can do asym_packing load balance
9543 * @sds: Load-balancing data with statistics of the local group
9544 * @sgs: Load-balancing statistics of the candidate busiest group
9566 if (!sched_use_asym_prio(env->sd, env->dst_cpu)) in sched_asym()
9573 if (group->flags & SD_SHARE_CPUCAPACITY) { in sched_asym()
9574 if (sgs->group_weight - sgs->idle_cpus != 1) in sched_asym()
9578 return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu); in sched_asym()
9588 return (sg1->flags & SD_SHARE_CPUCAPACITY) != in smt_vs_nonsmt_groups()
9589 (sg2->flags & SD_SHARE_CPUCAPACITY); in smt_vs_nonsmt_groups()
9595 if (env->idle == CPU_NOT_IDLE) in smt_balance()
9604 if (group->flags & SD_SHARE_CPUCAPACITY && in smt_balance()
9605 sgs->sum_h_nr_running > 1) in smt_balance()
9619 if (env->idle == CPU_NOT_IDLE || !busiest->sum_nr_running) in sibling_imbalance()
9622 ncores_busiest = sds->busiest->cores; in sibling_imbalance()
9623 ncores_local = sds->local->cores; in sibling_imbalance()
9626 imbalance = busiest->sum_nr_running; in sibling_imbalance()
9627 lsub_positive(&imbalance, local->sum_nr_running); in sibling_imbalance()
9632 imbalance = ncores_local * busiest->sum_nr_running; in sibling_imbalance()
9633 lsub_positive(&imbalance, ncores_busiest * local->sum_nr_running); in sibling_imbalance()
9639 if (imbalance <= 1 && local->sum_nr_running == 0 && in sibling_imbalance()
9640 busiest->sum_nr_running > 1) in sibling_imbalance()
9653 if (rq->cfs.h_nr_running != 1) in sched_reduced_capacity()
9660 * update_sg_lb_stats - Update sched_group's statistics for load balancing.
9662 * @sds: Load-balancing data with statistics of the local group.
9677 local_group = group == sds->local; in update_sg_lb_stats()
9679 for_each_cpu_and(i, sched_group_span(group), env->cpus) { in update_sg_lb_stats()
9683 sgs->group_load += load; in update_sg_lb_stats()
9684 sgs->group_util += cpu_util_cfs(i); in update_sg_lb_stats()
9685 sgs->group_runnable += cpu_runnable(rq); in update_sg_lb_stats()
9686 sgs->sum_h_nr_running += rq->cfs.h_nr_running; in update_sg_lb_stats()
9688 nr_running = rq->nr_running; in update_sg_lb_stats()
9689 sgs->sum_nr_running += nr_running; in update_sg_lb_stats()
9698 sgs->nr_numa_running += rq->nr_numa_running; in update_sg_lb_stats()
9699 sgs->nr_preferred_running += rq->nr_preferred_running; in update_sg_lb_stats()
9705 sgs->idle_cpus++; in update_sg_lb_stats()
9713 if (env->sd->flags & SD_ASYM_CPUCAPACITY) { in update_sg_lb_stats()
9715 if (sgs->group_misfit_task_load < rq->misfit_task_load) { in update_sg_lb_stats()
9716 sgs->group_misfit_task_load = rq->misfit_task_load; in update_sg_lb_stats()
9719 } else if ((env->idle != CPU_NOT_IDLE) && in update_sg_lb_stats()
9720 sched_reduced_capacity(rq, env->sd)) { in update_sg_lb_stats()
9722 if (sgs->group_misfit_task_load < load) in update_sg_lb_stats()
9723 sgs->group_misfit_task_load = load; in update_sg_lb_stats()
9727 sgs->group_capacity = group->sgc->capacity; in update_sg_lb_stats()
9729 sgs->group_weight = group->group_weight; in update_sg_lb_stats()
9732 if (!local_group && env->sd->flags & SD_ASYM_PACKING && in update_sg_lb_stats()
9733 env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running && in update_sg_lb_stats()
9735 sgs->group_asym_packing = 1; in update_sg_lb_stats()
9740 sgs->group_smt_balance = 1; in update_sg_lb_stats()
9742 sgs->group_type = group_classify(env->sd->imbalance_pct, group, sgs); in update_sg_lb_stats()
9745 if (sgs->group_type == group_overloaded) in update_sg_lb_stats()
9746 sgs->avg_load = (sgs->group_load * SCHED_CAPACITY_SCALE) / in update_sg_lb_stats()
9747 sgs->group_capacity; in update_sg_lb_stats()
9751 * update_sd_pick_busiest - return 1 on busiest group
9768 struct sg_lb_stats *busiest = &sds->busiest_stat; in update_sd_pick_busiest()
9771 if (!sgs->sum_h_nr_running) in update_sd_pick_busiest()
9780 if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && in update_sd_pick_busiest()
9781 (sgs->group_type == group_misfit_task) && in update_sd_pick_busiest()
9782 (!capacity_greater(capacity_of(env->dst_cpu), sg->sgc->max_capacity) || in update_sd_pick_busiest()
9783 sds->local_stat.group_type != group_has_spare)) in update_sd_pick_busiest()
9786 if (sgs->group_type > busiest->group_type) in update_sd_pick_busiest()
9789 if (sgs->group_type < busiest->group_type) in update_sd_pick_busiest()
9797 switch (sgs->group_type) { in update_sd_pick_busiest()
9800 if (sgs->avg_load <= busiest->avg_load) in update_sd_pick_busiest()
9813 if (sched_asym_prefer(sg->asym_prefer_cpu, sds->busiest->asym_prefer_cpu)) in update_sd_pick_busiest()
9822 if (sgs->group_misfit_task_load < busiest->group_misfit_task_load) in update_sd_pick_busiest()
9831 if (sgs->idle_cpus != 0 || busiest->idle_cpus != 0) in update_sd_pick_busiest()
9849 if (sgs->avg_load < busiest->avg_load) in update_sd_pick_busiest()
9852 if (sgs->avg_load == busiest->avg_load) { in update_sd_pick_busiest()
9854 * SMT sched groups need more help than non-SMT groups. in update_sd_pick_busiest()
9857 if (sds->busiest->flags & SD_SHARE_CPUCAPACITY) in update_sd_pick_busiest()
9869 if (smt_vs_nonsmt_groups(sds->busiest, sg)) { in update_sd_pick_busiest()
9870 if (sg->flags & SD_SHARE_CPUCAPACITY && sgs->sum_h_nr_running <= 1) in update_sd_pick_busiest()
9884 if (sgs->idle_cpus > busiest->idle_cpus) in update_sd_pick_busiest()
9886 else if ((sgs->idle_cpus == busiest->idle_cpus) && in update_sd_pick_busiest()
9887 (sgs->sum_nr_running <= busiest->sum_nr_running)) in update_sd_pick_busiest()
9895 * per-CPU capacity. Migrating tasks to less capable CPUs may harm in update_sd_pick_busiest()
9899 if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && in update_sd_pick_busiest()
9900 (sgs->group_type <= group_fully_busy) && in update_sd_pick_busiest()
9901 (capacity_greater(sg->sgc->min_capacity, capacity_of(env->dst_cpu)))) in update_sd_pick_busiest()
9910 if (sgs->sum_h_nr_running > sgs->nr_numa_running) in fbq_classify_group()
9912 if (sgs->sum_h_nr_running > sgs->nr_preferred_running) in fbq_classify_group()
9919 if (rq->nr_running > rq->nr_numa_running) in fbq_classify_rq()
9921 if (rq->nr_running > rq->nr_preferred_running) in fbq_classify_rq()
9941 * task_running_on_cpu - return 1 if @p is running on @cpu.
9947 if (cpu != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in task_running_on_cpu()
9957 * idle_cpu_without - would a given CPU be idle without p ?
9967 if (rq->curr != rq->idle && rq->curr != p) in idle_cpu_without()
9971 * rq->nr_running can't be used but an updated version without the in idle_cpu_without()
9977 if (rq->ttwu_pending) in idle_cpu_without()
9985 * update_sg_wakeup_stats - Update sched_group's statistics for wakeup.
10001 if (sd->flags & SD_ASYM_CPUCAPACITY) in update_sg_wakeup_stats()
10002 sgs->group_misfit_task_load = 1; in update_sg_wakeup_stats()
10008 sgs->group_load += cpu_load_without(rq, p); in update_sg_wakeup_stats()
10009 sgs->group_util += cpu_util_without(i, p); in update_sg_wakeup_stats()
10010 sgs->group_runnable += cpu_runnable_without(rq, p); in update_sg_wakeup_stats()
10012 sgs->sum_h_nr_running += rq->cfs.h_nr_running - local; in update_sg_wakeup_stats()
10014 nr_running = rq->nr_running - local; in update_sg_wakeup_stats()
10015 sgs->sum_nr_running += nr_running; in update_sg_wakeup_stats()
10021 sgs->idle_cpus++; in update_sg_wakeup_stats()
10024 if (sd->flags & SD_ASYM_CPUCAPACITY && in update_sg_wakeup_stats()
10025 sgs->group_misfit_task_load && in update_sg_wakeup_stats()
10027 sgs->group_misfit_task_load = 0; in update_sg_wakeup_stats()
10031 sgs->group_capacity = group->sgc->capacity; in update_sg_wakeup_stats()
10033 sgs->group_weight = group->group_weight; in update_sg_wakeup_stats()
10035 sgs->group_type = group_classify(sd->imbalance_pct, group, sgs); in update_sg_wakeup_stats()
10041 if (sgs->group_type == group_fully_busy || in update_sg_wakeup_stats()
10042 sgs->group_type == group_overloaded) in update_sg_wakeup_stats()
10043 sgs->avg_load = (sgs->group_load * SCHED_CAPACITY_SCALE) / in update_sg_wakeup_stats()
10044 sgs->group_capacity; in update_sg_wakeup_stats()
10052 if (sgs->group_type < idlest_sgs->group_type) in update_pick_idlest()
10055 if (sgs->group_type > idlest_sgs->group_type) in update_pick_idlest()
10063 switch (sgs->group_type) { in update_pick_idlest()
10067 if (idlest_sgs->avg_load <= sgs->avg_load) in update_pick_idlest()
10079 if (idlest->sgc->max_capacity >= group->sgc->max_capacity) in update_pick_idlest()
10085 if (idlest_sgs->idle_cpus > sgs->idle_cpus) in update_pick_idlest()
10089 if (idlest_sgs->idle_cpus == sgs->idle_cpus && in update_pick_idlest()
10090 idlest_sgs->group_util <= sgs->group_util) in update_pick_idlest()
10108 struct sched_group *idlest = NULL, *local = NULL, *group = sd->groups; in find_idlest_group()
10122 p->cpus_ptr)) in find_idlest_group()
10146 } while (group = group->next, group != sd->groups); in find_idlest_group()
10177 (sd->imbalance_pct-100) / 100; in find_idlest_group()
10184 * cross-domain, add imbalance to the load on the remote node in find_idlest_group()
10188 if ((sd->flags & SD_NUMA) && in find_idlest_group()
10199 if (100 * local_sgs.avg_load <= sd->imbalance_pct * idlest_sgs.avg_load) in find_idlest_group()
10211 if (local->sgc->max_capacity >= idlest->sgc->max_capacity) in find_idlest_group()
10217 if (sd->flags & SD_NUMA) { in find_idlest_group()
10218 int imb_numa_nr = sd->imb_numa_nr; in find_idlest_group()
10225 if (cpu_to_node(this_cpu) == p->numa_preferred_nid) in find_idlest_group()
10229 if (cpu_to_node(idlest_cpu) == p->numa_preferred_nid) in find_idlest_group()
10241 if (p->nr_cpus_allowed != NR_CPUS) { in find_idlest_group()
10244 cpumask_and(cpus, sched_group_span(local), p->cpus_ptr); in find_idlest_group()
10245 imb_numa_nr = min(cpumask_weight(cpus), sd->imb_numa_nr); in find_idlest_group()
10248 imbalance = abs(local_sgs.idle_cpus - idlest_sgs.idle_cpus); in find_idlest_group()
10285 if (!sched_feat(SIS_UTIL) || env->idle == CPU_NEWLY_IDLE) in update_idle_cpu_scan()
10288 llc_weight = per_cpu(sd_llc_size, env->dst_cpu); in update_idle_cpu_scan()
10289 if (env->sd->span_weight != llc_weight) in update_idle_cpu_scan()
10292 sd_share = rcu_dereference(per_cpu(sd_llc_shared, env->dst_cpu)); in update_idle_cpu_scan()
10302 * let y = SCHED_CAPACITY_SCALE - p * x^2 [1] in update_idle_cpu_scan()
10320 * y = SCHED_CAPACITY_SCALE - in update_idle_cpu_scan()
10329 pct = env->sd->imbalance_pct; in update_idle_cpu_scan()
10333 y = SCHED_CAPACITY_SCALE - tmp; in update_idle_cpu_scan()
10338 if ((int)y != sd_share->nr_idle_scan) in update_idle_cpu_scan()
10339 WRITE_ONCE(sd_share->nr_idle_scan, (int)y); in update_idle_cpu_scan()
10343 * update_sd_lb_stats - Update sched_domain's statistics for load balancing.
10350 struct sched_group *sg = env->sd->groups; in update_sd_lb_stats()
10351 struct sg_lb_stats *local = &sds->local_stat; in update_sd_lb_stats()
10360 local_group = cpumask_test_cpu(env->dst_cpu, sched_group_span(sg)); in update_sd_lb_stats()
10362 sds->local = sg; in update_sd_lb_stats()
10365 if (env->idle != CPU_NEWLY_IDLE || in update_sd_lb_stats()
10366 time_after_eq(jiffies, sg->sgc->next_update)) in update_sd_lb_stats()
10367 update_group_capacity(env->sd, env->dst_cpu); in update_sd_lb_stats()
10377 sds->busiest = sg; in update_sd_lb_stats()
10378 sds->busiest_stat = *sgs; in update_sd_lb_stats()
10383 sds->total_load += sgs->group_load; in update_sd_lb_stats()
10384 sds->total_capacity += sgs->group_capacity; in update_sd_lb_stats()
10386 sum_util += sgs->group_util; in update_sd_lb_stats()
10387 sg = sg->next; in update_sd_lb_stats()
10388 } while (sg != env->sd->groups); in update_sd_lb_stats()
10395 if (sds->busiest) in update_sd_lb_stats()
10396 sds->prefer_sibling = !!(sds->busiest->flags & SD_PREFER_SIBLING); in update_sd_lb_stats()
10399 if (env->sd->flags & SD_NUMA) in update_sd_lb_stats()
10400 env->fbq_type = fbq_classify_group(&sds->busiest_stat); in update_sd_lb_stats()
10402 if (!env->sd->parent) { in update_sd_lb_stats()
10403 struct root_domain *rd = env->dst_rq->rd; in update_sd_lb_stats()
10406 WRITE_ONCE(rd->overload, sg_status & SG_OVERLOAD); in update_sd_lb_stats()
10408 /* Update over-utilization (tipping point, U >= 0) indicator */ in update_sd_lb_stats()
10409 WRITE_ONCE(rd->overutilized, sg_status & SG_OVERUTILIZED); in update_sd_lb_stats()
10412 struct root_domain *rd = env->dst_rq->rd; in update_sd_lb_stats()
10414 WRITE_ONCE(rd->overutilized, SG_OVERUTILIZED); in update_sd_lb_stats()
10422 * calculate_imbalance - Calculate the amount of imbalance present within the
10431 local = &sds->local_stat; in calculate_imbalance()
10432 busiest = &sds->busiest_stat; in calculate_imbalance()
10434 if (busiest->group_type == group_misfit_task) { in calculate_imbalance()
10435 if (env->sd->flags & SD_ASYM_CPUCAPACITY) { in calculate_imbalance()
10437 env->migration_type = migrate_misfit; in calculate_imbalance()
10438 env->imbalance = 1; in calculate_imbalance()
10444 env->migration_type = migrate_load; in calculate_imbalance()
10445 env->imbalance = busiest->group_misfit_task_load; in calculate_imbalance()
10450 if (busiest->group_type == group_asym_packing) { in calculate_imbalance()
10455 env->migration_type = migrate_task; in calculate_imbalance()
10456 env->imbalance = busiest->sum_h_nr_running; in calculate_imbalance()
10460 if (busiest->group_type == group_smt_balance) { in calculate_imbalance()
10462 env->migration_type = migrate_task; in calculate_imbalance()
10463 env->imbalance = 1; in calculate_imbalance()
10467 if (busiest->group_type == group_imbalanced) { in calculate_imbalance()
10469 * In the group_imb case we cannot rely on group-wide averages in calculate_imbalance()
10470 * to ensure CPU-load equilibrium, try to move any task to fix in calculate_imbalance()
10474 env->migration_type = migrate_task; in calculate_imbalance()
10475 env->imbalance = 1; in calculate_imbalance()
10483 if (local->group_type == group_has_spare) { in calculate_imbalance()
10484 if ((busiest->group_type > group_fully_busy) && in calculate_imbalance()
10485 !(env->sd->flags & SD_SHARE_PKG_RESOURCES)) { in calculate_imbalance()
10494 env->migration_type = migrate_util; in calculate_imbalance()
10495 env->imbalance = max(local->group_capacity, local->group_util) - in calculate_imbalance()
10496 local->group_util; in calculate_imbalance()
10505 if (env->idle != CPU_NOT_IDLE && env->imbalance == 0) { in calculate_imbalance()
10506 env->migration_type = migrate_task; in calculate_imbalance()
10507 env->imbalance = 1; in calculate_imbalance()
10513 if (busiest->group_weight == 1 || sds->prefer_sibling) { in calculate_imbalance()
10518 env->migration_type = migrate_task; in calculate_imbalance()
10519 env->imbalance = sibling_imbalance(env, sds, busiest, local); in calculate_imbalance()
10526 env->migration_type = migrate_task; in calculate_imbalance()
10527 env->imbalance = max_t(long, 0, in calculate_imbalance()
10528 (local->idle_cpus - busiest->idle_cpus)); in calculate_imbalance()
10533 if (env->sd->flags & SD_NUMA) { in calculate_imbalance()
10534 env->imbalance = adjust_numa_imbalance(env->imbalance, in calculate_imbalance()
10535 local->sum_nr_running + 1, in calculate_imbalance()
10536 env->sd->imb_numa_nr); in calculate_imbalance()
10541 env->imbalance >>= 1; in calculate_imbalance()
10550 if (local->group_type < group_overloaded) { in calculate_imbalance()
10556 local->avg_load = (local->group_load * SCHED_CAPACITY_SCALE) / in calculate_imbalance()
10557 local->group_capacity; in calculate_imbalance()
10563 if (local->avg_load >= busiest->avg_load) { in calculate_imbalance()
10564 env->imbalance = 0; in calculate_imbalance()
10568 sds->avg_load = (sds->total_load * SCHED_CAPACITY_SCALE) / in calculate_imbalance()
10569 sds->total_capacity; in calculate_imbalance()
10575 if (local->avg_load >= sds->avg_load) { in calculate_imbalance()
10576 env->imbalance = 0; in calculate_imbalance()
10586 * below the average load. At the same time, we also don't want to in calculate_imbalance()
10590 env->migration_type = migrate_load; in calculate_imbalance()
10591 env->imbalance = min( in calculate_imbalance()
10592 (busiest->avg_load - sds->avg_load) * busiest->group_capacity, in calculate_imbalance()
10593 (sds->avg_load - local->avg_load) * local->group_capacity in calculate_imbalance()
10620 * find_busiest_group - Returns the busiest group within the sched_domain
10627 * Return: - The busiest group if imbalance exists.
10649 if (busiest->group_type == group_misfit_task) in find_busiest_group()
10653 struct root_domain *rd = env->dst_rq->rd; in find_busiest_group()
10655 if (rcu_dereference(rd->pd) && !READ_ONCE(rd->overutilized)) in find_busiest_group()
10660 if (busiest->group_type == group_asym_packing) in find_busiest_group()
10668 if (busiest->group_type == group_imbalanced) in find_busiest_group()
10676 if (local->group_type > busiest->group_type) in find_busiest_group()
10683 if (local->group_type == group_overloaded) { in find_busiest_group()
10688 if (local->avg_load >= busiest->avg_load) in find_busiest_group()
10699 if (local->avg_load >= sds.avg_load) in find_busiest_group()
10706 if (100 * busiest->avg_load <= in find_busiest_group()
10707 env->sd->imbalance_pct * local->avg_load) in find_busiest_group()
10715 if (sds.prefer_sibling && local->group_type == group_has_spare && in find_busiest_group()
10719 if (busiest->group_type != group_overloaded) { in find_busiest_group()
10720 if (env->idle == CPU_NOT_IDLE) { in find_busiest_group()
10729 if (busiest->group_type == group_smt_balance && in find_busiest_group()
10735 if (busiest->group_weight > 1 && in find_busiest_group()
10736 local->idle_cpus <= (busiest->idle_cpus + 1)) { in find_busiest_group()
10749 if (busiest->sum_h_nr_running == 1) { in find_busiest_group()
10760 return env->imbalance ? sds.busiest : NULL; in find_busiest_group()
10763 env->imbalance = 0; in find_busiest_group()
10768 * find_busiest_queue - find the busiest runqueue among the CPUs in the group.
10778 for_each_cpu_and(i, sched_group_span(group), env->cpus) { in find_busiest_queue()
10788 * - regular: there are !numa tasks in find_busiest_queue()
10789 * - remote: there are numa tasks that run on the 'wrong' node in find_busiest_queue()
10790 * - all: there is no distinction in find_busiest_queue()
10805 if (rt > env->fbq_type) in find_busiest_queue()
10808 nr_running = rq->cfs.h_nr_running; in find_busiest_queue()
10816 * eventually lead to active_balancing high->low capacity. in find_busiest_queue()
10817 * Higher per-CPU capacity is considered better than balancing in find_busiest_queue()
10820 if (env->sd->flags & SD_ASYM_CPUCAPACITY && in find_busiest_queue()
10821 !capacity_greater(capacity_of(env->dst_cpu), capacity) && in find_busiest_queue()
10832 if ((env->sd->flags & SD_ASYM_PACKING) && in find_busiest_queue()
10833 sched_use_asym_prio(env->sd, i) && in find_busiest_queue()
10834 sched_asym_prefer(i, env->dst_cpu) && in find_busiest_queue()
10838 switch (env->migration_type) { in find_busiest_queue()
10846 if (nr_running == 1 && load > env->imbalance && in find_busiest_queue()
10847 !check_cpu_capacity(rq, env->sd)) in find_busiest_queue()
10899 if (rq->misfit_task_load > busiest_load) { in find_busiest_queue()
10900 busiest_load = rq->misfit_task_load; in find_busiest_queue()
10931 return env->idle != CPU_NOT_IDLE && (env->sd->flags & SD_ASYM_PACKING) && in asym_active_balance()
10932 sched_use_asym_prio(env->sd, env->dst_cpu) && in asym_active_balance()
10933 (sched_asym_prefer(env->dst_cpu, env->src_cpu) || in asym_active_balance()
10934 !sched_use_asym_prio(env->sd, env->src_cpu)); in asym_active_balance()
10940 struct sched_domain *sd = env->sd; in imbalanced_active_balance()
10947 if ((env->migration_type == migrate_task) && in imbalanced_active_balance()
10948 (sd->nr_balance_failed > sd->cache_nice_tries+2)) in imbalanced_active_balance()
10956 struct sched_domain *sd = env->sd; in need_active_balance()
10970 if ((env->idle != CPU_NOT_IDLE) && in need_active_balance()
10971 (env->src_rq->cfs.h_nr_running == 1)) { in need_active_balance()
10972 if ((check_cpu_capacity(env->src_rq, sd)) && in need_active_balance()
10973 (capacity_of(env->src_cpu)*sd->imbalance_pct < capacity_of(env->dst_cpu)*100)) in need_active_balance()
10977 if (env->migration_type == migrate_misfit) in need_active_balance()
10988 struct sched_group *sg = env->sd->groups; in should_we_balance()
10989 int cpu, idle_smt = -1; in should_we_balance()
10995 if (!cpumask_test_cpu(env->dst_cpu, env->cpus)) in should_we_balance()
11005 if (env->idle == CPU_NEWLY_IDLE) { in should_we_balance()
11006 if (env->dst_rq->nr_running > 0 || env->dst_rq->ttwu_pending) in should_we_balance()
11013 for_each_cpu_and(cpu, swb_cpus, env->cpus) { in should_we_balance()
11022 if (!(env->sd->flags & SD_SHARE_CPUCAPACITY) && !is_core_idle(cpu)) { in should_we_balance()
11023 if (idle_smt == -1) in should_we_balance()
11037 return cpu == env->dst_cpu; in should_we_balance()
11040 if (idle_smt == env->dst_cpu) in should_we_balance()
11044 return group_balance_cpu(sg) == env->dst_cpu; in should_we_balance()
11056 struct sched_domain *sd_parent = sd->parent; in load_balance()
11065 .dst_grpmask = group_balance_mask(sd->groups), in load_balance()
11075 schedstat_inc(sd->lb_count[idle]); in load_balance()
11085 schedstat_inc(sd->lb_nobusyg[idle]); in load_balance()
11091 schedstat_inc(sd->lb_nobusyq[idle]); in load_balance()
11097 schedstat_add(sd->lb_imbalance[idle], env.imbalance); in load_balance()
11099 env.src_cpu = busiest->cpu; in load_balance()
11105 if (busiest->nr_running > 1) { in load_balance()
11108 * an imbalance but busiest->nr_running <= 1, the group is in load_balance()
11112 env.loop_max = min(sysctl_sched_nr_migrate, busiest->nr_running); in load_balance()
11119 * cur_ld_moved - load moved in current iteration in load_balance()
11120 * ld_moved - cumulative load moved across iterations in load_balance()
11127 * unlock busiest->lock, and we are able to be sure in load_balance()
11144 if (env.loop < busiest->nr_running) in load_balance()
11158 * nohz-idle), we now have balance_cpu in a position to move in load_balance()
11161 * _independently_ and at _same_ time to move some load to in load_balance()
11169 /* Prevent to re-select dst_cpu via env's CPUs */ in load_balance()
11189 int *group_imbalance = &sd_parent->groups->sgc->imbalance; in load_balance()
11216 schedstat_inc(sd->lb_failed[idle]); in load_balance()
11224 sd->nr_balance_failed++; in load_balance()
11236 if (!cpumask_test_cpu(this_cpu, busiest->curr->cpus_ptr)) { in load_balance()
11245 * ->active_balance synchronizes accesses to in load_balance()
11246 * ->active_balance_work. Once set, it's cleared in load_balance()
11249 if (!busiest->active_balance) { in load_balance()
11250 busiest->active_balance = 1; in load_balance()
11251 busiest->push_cpu = this_cpu; in load_balance()
11259 &busiest->active_balance_work); in load_balance()
11263 sd->nr_balance_failed = 0; in load_balance()
11268 sd->balance_interval = sd->min_interval; in load_balance()
11280 int *group_imbalance = &sd_parent->groups->sgc->imbalance; in load_balance()
11292 schedstat_inc(sd->lb_balanced[idle]); in load_balance()
11294 sd->nr_balance_failed = 0; in load_balance()
11302 * skyrocketing in a short amount of time. Skip the balance_interval in load_balance()
11310 sd->balance_interval < MAX_PINNED_INTERVAL) || in load_balance()
11311 sd->balance_interval < sd->max_interval) in load_balance()
11312 sd->balance_interval *= 2; in load_balance()
11320 unsigned long interval = sd->balance_interval; in get_sd_balance_interval()
11323 interval *= sd->busy_factor; in get_sd_balance_interval()
11334 interval -= 1; in get_sd_balance_interval()
11348 next = sd->last_balance + interval; in update_next_balance()
11364 int target_cpu = busiest_rq->push_cpu; in active_load_balance_cpu_stop()
11372 * Between queueing the stop-work and running it is a hole in which in active_load_balance_cpu_stop()
11381 !busiest_rq->active_balance)) in active_load_balance_cpu_stop()
11385 if (busiest_rq->nr_running <= 1) in active_load_balance_cpu_stop()
11391 * Bjorn Helgaas on a 128-CPU setup. in active_load_balance_cpu_stop()
11407 .src_cpu = busiest_rq->cpu, in active_load_balance_cpu_stop()
11413 schedstat_inc(sd->alb_count); in active_load_balance_cpu_stop()
11418 schedstat_inc(sd->alb_pushed); in active_load_balance_cpu_stop()
11420 sd->nr_balance_failed = 0; in active_load_balance_cpu_stop()
11422 schedstat_inc(sd->alb_failed); in active_load_balance_cpu_stop()
11427 busiest_rq->active_balance = 0; in active_load_balance_cpu_stop()
11442 * This trades load-balance latency on larger machines for less cross talk.
11451 if (cost > sd->max_newidle_lb_cost) { in update_newidle_cost()
11456 sd->max_newidle_lb_cost = cost; in update_newidle_cost()
11457 sd->last_decay_max_lb_cost = jiffies; in update_newidle_cost()
11458 } else if (time_after(jiffies, sd->last_decay_max_lb_cost + HZ)) { in update_newidle_cost()
11464 sd->max_newidle_lb_cost = (sd->max_newidle_lb_cost * 253) / 256; in update_newidle_cost()
11465 sd->last_decay_max_lb_cost = jiffies; in update_newidle_cost()
11482 int cpu = rq->cpu; in rebalance_domains()
11486 /* Earliest time when we have to do rebalance again */ in rebalance_domains()
11499 max_cost += sd->max_newidle_lb_cost; in rebalance_domains()
11514 need_serialize = sd->flags & SD_SERIALIZE; in rebalance_domains()
11520 if (time_after_eq(jiffies, sd->last_balance + interval)) { in rebalance_domains()
11524 * env->dst_cpu, so we can't know our idle in rebalance_domains()
11530 sd->last_balance = jiffies; in rebalance_domains()
11536 if (time_after(next_balance, sd->last_balance + interval)) { in rebalance_domains()
11537 next_balance = sd->last_balance + interval; in rebalance_domains()
11543 * Ensure the rq-wide value also decays but keep it at a in rebalance_domains()
11544 * reasonable floor to avoid funnies with rq->avg_idle. in rebalance_domains()
11546 rq->max_idle_balance_cost = in rebalance_domains()
11557 rq->next_balance = next_balance; in rebalance_domains()
11563 return unlikely(!rcu_dereference_sched(rq->sd)); in on_null_domain()
11569 * - When one of the busy CPUs notice that there may be an idle rebalancing
11572 * - HK_TYPE_MISC CPUs are used for this task, because HK_TYPE_SCHED not set
11596 * Kick a CPU to do the nohz balancing, if it is time for it. We pick any
11628 smp_call_function_single_async(ilb_cpu, &cpu_rq(ilb_cpu)->nohz_csd); in kick_ilb()
11640 int nr_busy, i, cpu = rq->cpu; in nohz_balancer_kick()
11643 if (unlikely(rq->idle_balance)) in nohz_balancer_kick()
11666 if (rq->nr_running >= 2) { in nohz_balancer_kick()
11673 sd = rcu_dereference(rq->sd); in nohz_balancer_kick()
11680 if (rq->cfs.h_nr_running >= 1 && check_cpu_capacity(rq, sd)) { in nohz_balancer_kick()
11730 * increase the overall cache use), we need some less-loaded LLC in nohz_balancer_kick()
11734 * the others are - so just get a nohz balance going if it looks in nohz_balancer_kick()
11737 nr_busy = atomic_read(&sds->nr_busy_cpus); in nohz_balancer_kick()
11760 if (!sd || !sd->nohz_idle) in set_cpu_sd_state_busy()
11762 sd->nohz_idle = 0; in set_cpu_sd_state_busy()
11764 atomic_inc(&sd->shared->nr_busy_cpus); in set_cpu_sd_state_busy()
11773 if (likely(!rq->nohz_tick_stopped)) in nohz_balance_exit_idle()
11776 rq->nohz_tick_stopped = 0; in nohz_balance_exit_idle()
11777 cpumask_clear_cpu(rq->cpu, nohz.idle_cpus_mask); in nohz_balance_exit_idle()
11780 set_cpu_sd_state_busy(rq->cpu); in nohz_balance_exit_idle()
11790 if (!sd || sd->nohz_idle) in set_cpu_sd_state_idle()
11792 sd->nohz_idle = 1; in set_cpu_sd_state_idle()
11794 atomic_dec(&sd->shared->nr_busy_cpus); in set_cpu_sd_state_idle()
11818 * Can be set safely without rq->lock held in nohz_balance_enter_idle()
11820 * rq->lock is held during the check and the clear in nohz_balance_enter_idle()
11822 rq->has_blocked_load = 1; in nohz_balance_enter_idle()
11830 if (rq->nohz_tick_stopped) in nohz_balance_enter_idle()
11837 rq->nohz_tick_stopped = 1; in nohz_balance_enter_idle()
11854 * Each time a cpu enter idle, we assume that it has blocked load and in nohz_balance_enter_idle()
11862 unsigned int cpu = rq->cpu; in update_nohz_stats()
11864 if (!rq->has_blocked_load) in update_nohz_stats()
11870 if (!time_after(jiffies, READ_ONCE(rq->last_blocked_load_update_tick))) in update_nohz_stats()
11875 return rq->has_blocked_load; in update_nohz_stats()
11885 /* Earliest time when we have to do rebalance again */ in _nohz_idle_balance()
11890 int this_cpu = this_rq->cpu; in _nohz_idle_balance()
11898 * the has_blocked flag. If a cpu enters idle in the mean time, it will in _nohz_idle_balance()
11944 * If time for next balance is due, in _nohz_idle_balance()
11947 if (time_after_eq(jiffies, rq->next_balance)) { in _nohz_idle_balance()
11958 if (time_after(next_balance, rq->next_balance)) { in _nohz_idle_balance()
11959 next_balance = rq->next_balance; in _nohz_idle_balance()
11988 unsigned int flags = this_rq->nohz_idle_balance; in nohz_idle_balance()
11993 this_rq->nohz_idle_balance = 0; in nohz_idle_balance()
12023 int this_cpu = this_rq->cpu; in nohz_newidle_balance()
12032 /* Will wake up very soon. No time for doing anything else*/ in nohz_newidle_balance()
12033 if (this_rq->avg_idle < sysctl_sched_migration_cost) in nohz_newidle_balance()
12064 * < 0 - we released the lock and there are !fair tasks present
12065 * 0 - failed, no new tasks
12066 * > 0 - success, new (fair) tasks present
12071 int this_cpu = this_rq->cpu; in newidle_balance()
12082 if (this_rq->ttwu_pending) in newidle_balance()
12087 * measure the duration of idle_balance() as idle time. in newidle_balance()
12089 this_rq->idle_stamp = rq_clock(this_rq); in newidle_balance()
12099 * for load-balance and preemption/IRQs are still disabled avoiding in newidle_balance()
12101 * re-start the picking loop. in newidle_balance()
12106 sd = rcu_dereference_check_sched_domain(this_rq->sd); in newidle_balance()
12108 if (!READ_ONCE(this_rq->rd->overload) || in newidle_balance()
12109 (sd && this_rq->avg_idle < sd->max_newidle_lb_cost)) { in newidle_balance()
12131 if (this_rq->avg_idle < curr_cost + sd->max_newidle_lb_cost) in newidle_balance()
12134 if (sd->flags & SD_BALANCE_NEWIDLE) { in newidle_balance()
12141 domain_cost = t1 - t0; in newidle_balance()
12152 if (pulled_task || this_rq->nr_running > 0 || in newidle_balance()
12153 this_rq->ttwu_pending) in newidle_balance()
12160 if (curr_cost > this_rq->max_idle_balance_cost) in newidle_balance()
12161 this_rq->max_idle_balance_cost = curr_cost; in newidle_balance()
12168 if (this_rq->cfs.h_nr_running && !pulled_task) in newidle_balance()
12172 if (this_rq->nr_running != this_rq->cfs.h_nr_running) in newidle_balance()
12173 pulled_task = -1; in newidle_balance()
12177 if (time_after(this_rq->next_balance, next_balance)) in newidle_balance()
12178 this_rq->next_balance = next_balance; in newidle_balance()
12181 this_rq->idle_stamp = 0; in newidle_balance()
12197 enum cpu_idle_type idle = this_rq->idle_balance ? in run_rebalance_domains()
12212 update_blocked_averages(this_rq->cpu); in run_rebalance_domains()
12217 * Trigger the SCHED_SOFTIRQ if it is time to do periodic load balancing.
12228 if (time_after_eq(jiffies, rq->next_balance)) in trigger_load_balance()
12255 u64 rtime = se->sum_exec_runtime - se->prev_sum_exec_runtime; in __entity_slice_used()
12256 u64 slice = se->slice; in __entity_slice_used()
12278 * MIN_NR_TASKS_DURING_FORCEIDLE - 1 tasks and use that to check in task_tick_core()
12281 if (rq->core->core_forceidle_count && rq->cfs.nr_running == 1 && in task_tick_core()
12282 __entity_slice_used(&curr->se, MIN_NR_TASKS_DURING_FORCEIDLE)) in task_tick_core()
12287 * se_fi_update - Update the cfs_rq->min_vruntime_fi in a CFS hierarchy if needed.
12296 if (cfs_rq->forceidle_seq == fi_seq) in se_fi_update()
12298 cfs_rq->forceidle_seq = fi_seq; in se_fi_update()
12301 cfs_rq->min_vruntime_fi = cfs_rq->min_vruntime; in se_fi_update()
12307 struct sched_entity *se = &p->se; in task_vruntime_update()
12309 if (p->sched_class != &fair_sched_class) in task_vruntime_update()
12312 se_fi_update(se, rq->core->core_forceidle_seq, in_fi); in task_vruntime_update()
12319 const struct sched_entity *sea = &a->se; in cfs_prio_less()
12320 const struct sched_entity *seb = &b->se; in cfs_prio_less()
12325 SCHED_WARN_ON(task_rq(b)->core != rq->core); in cfs_prio_less()
12332 while (sea->cfs_rq->tg != seb->cfs_rq->tg) { in cfs_prio_less()
12333 int sea_depth = sea->depth; in cfs_prio_less()
12334 int seb_depth = seb->depth; in cfs_prio_less()
12342 se_fi_update(sea, rq->core->core_forceidle_seq, in_fi); in cfs_prio_less()
12343 se_fi_update(seb, rq->core->core_forceidle_seq, in_fi); in cfs_prio_less()
12345 cfs_rqa = sea->cfs_rq; in cfs_prio_less()
12346 cfs_rqb = seb->cfs_rq; in cfs_prio_less()
12348 cfs_rqa = &task_rq(a)->cfs; in cfs_prio_less()
12349 cfs_rqb = &task_rq(b)->cfs; in cfs_prio_less()
12357 delta = (s64)(sea->vruntime - seb->vruntime) + in cfs_prio_less()
12358 (s64)(cfs_rqb->min_vruntime_fi - cfs_rqa->min_vruntime_fi); in cfs_prio_less()
12368 cfs_rq = task_group(p)->cfs_rq[cpu]; in task_is_throttled_fair()
12370 cfs_rq = &cpu_rq(cpu)->cfs; in task_is_throttled_fair()
12389 struct sched_entity *se = &curr->se; in task_tick_fair()
12407 * - child not yet on the tasklist
12408 * - preemption disabled
12412 struct sched_entity *se = &p->se, *curr; in task_fork_fair()
12421 curr = cfs_rq->curr; in task_fork_fair()
12438 if (rq->cfs.nr_running == 1) in prio_changed_fair()
12447 if (p->prio > oldprio) in prio_changed_fair()
12469 se = se->parent; in propagate_entity_cfs_rq()
12494 * - A forked task which hasn't been woken up by wake_up_new_task(). in detach_entity_cfs_rq()
12495 * - A task which has been woken up by try_to_wake_up() but is in detach_entity_cfs_rq()
12498 if (!se->avg.last_update_time) in detach_entity_cfs_rq()
12522 struct sched_entity *se = &p->se; in detach_task_cfs_rq()
12529 struct sched_entity *se = &p->se; in attach_task_cfs_rq()
12558 * This routine is mostly called to set cfs_rq->curr field when a task
12563 struct sched_entity *se = &p->se; in set_next_task_fair()
12571 list_move(&se->group_node, &rq->cfs_tasks); in set_next_task_fair()
12586 cfs_rq->tasks_timeline = RB_ROOT_CACHED; in init_cfs_rq()
12587 u64_u32_store(cfs_rq->min_vruntime, (u64)(-(1LL << 20))); in init_cfs_rq()
12589 raw_spin_lock_init(&cfs_rq->removed.lock); in init_cfs_rq()
12600 if (READ_ONCE(p->__state) == TASK_NEW) in task_change_group_fair()
12606 /* Tell se's cfs_rq has been changed -- migrated */ in task_change_group_fair()
12607 p->se.avg.last_update_time = 0; in task_change_group_fair()
12618 if (tg->cfs_rq) in free_fair_sched_group()
12619 kfree(tg->cfs_rq[i]); in free_fair_sched_group()
12620 if (tg->se) in free_fair_sched_group()
12621 kfree(tg->se[i]); in free_fair_sched_group()
12624 kfree(tg->cfs_rq); in free_fair_sched_group()
12625 kfree(tg->se); in free_fair_sched_group()
12634 tg->cfs_rq = kcalloc(nr_cpu_ids, sizeof(cfs_rq), GFP_KERNEL); in alloc_fair_sched_group()
12635 if (!tg->cfs_rq) in alloc_fair_sched_group()
12637 tg->se = kcalloc(nr_cpu_ids, sizeof(se), GFP_KERNEL); in alloc_fair_sched_group()
12638 if (!tg->se) in alloc_fair_sched_group()
12641 tg->shares = NICE_0_LOAD; in alloc_fair_sched_group()
12657 init_tg_cfs_entry(tg, cfs_rq, se, i, parent->se[i]); in alloc_fair_sched_group()
12678 se = tg->se[i]; in online_fair_sched_group()
12696 if (tg->se[cpu]) in unregister_fair_sched_group()
12697 remove_entity_load_avg(tg->se[cpu]); in unregister_fair_sched_group()
12701 * check on_list without danger of it being re-added. in unregister_fair_sched_group()
12703 if (!tg->cfs_rq[cpu]->on_list) in unregister_fair_sched_group()
12709 list_del_leaf_cfs_rq(tg->cfs_rq[cpu]); in unregister_fair_sched_group()
12720 cfs_rq->tg = tg; in init_tg_cfs_entry()
12721 cfs_rq->rq = rq; in init_tg_cfs_entry()
12724 tg->cfs_rq[cpu] = cfs_rq; in init_tg_cfs_entry()
12725 tg->se[cpu] = se; in init_tg_cfs_entry()
12732 se->cfs_rq = &rq->cfs; in init_tg_cfs_entry()
12733 se->depth = 0; in init_tg_cfs_entry()
12735 se->cfs_rq = parent->my_q; in init_tg_cfs_entry()
12736 se->depth = parent->depth + 1; in init_tg_cfs_entry()
12739 se->my_q = cfs_rq; in init_tg_cfs_entry()
12741 update_load_set(&se->load, NICE_0_LOAD); in init_tg_cfs_entry()
12742 se->parent = parent; in init_tg_cfs_entry()
12756 if (!tg->se[0]) in __sched_group_set_shares()
12757 return -EINVAL; in __sched_group_set_shares()
12761 if (tg->shares == shares) in __sched_group_set_shares()
12764 tg->shares = shares; in __sched_group_set_shares()
12767 struct sched_entity *se = tg->se[i]; in __sched_group_set_shares()
12789 ret = -EINVAL; in sched_group_set_shares()
12802 return -EINVAL; in sched_group_set_idle()
12805 return -EINVAL; in sched_group_set_idle()
12809 if (tg->idle == idle) { in sched_group_set_idle()
12814 tg->idle = idle; in sched_group_set_idle()
12818 struct sched_entity *se = tg->se[i]; in sched_group_set_idle()
12819 struct cfs_rq *parent_cfs_rq, *grp_cfs_rq = tg->cfs_rq[i]; in sched_group_set_idle()
12826 grp_cfs_rq->idle = idle; in sched_group_set_idle()
12830 if (se->on_rq) { in sched_group_set_idle()
12833 parent_cfs_rq->idle_nr_running++; in sched_group_set_idle()
12835 parent_cfs_rq->idle_nr_running--; in sched_group_set_idle()
12838 idle_task_delta = grp_cfs_rq->h_nr_running - in sched_group_set_idle()
12839 grp_cfs_rq->idle_h_nr_running; in sched_group_set_idle()
12841 idle_task_delta *= -1; in sched_group_set_idle()
12846 if (!se->on_rq) in sched_group_set_idle()
12849 cfs_rq->idle_h_nr_running += idle_task_delta; in sched_group_set_idle()
12888 struct sched_entity *se = &task->se; in get_rr_interval_fair()
12892 * Time slice is 0 for SCHED_OTHER tasks that are on an otherwise in get_rr_interval_fair()
12895 if (rq->cfs.load.weight) in get_rr_interval_fair()
12896 rr_interval = NS_TO_JIFFIES(se->slice); in get_rr_interval_fair()
12973 ng = rcu_dereference(p->numa_group); in show_numa_stats()
12975 if (p->numa_faults) { in show_numa_stats()
12976 tsf = p->numa_faults[task_faults_idx(NUMA_MEM, node, 0)]; in show_numa_stats()
12977 tpf = p->numa_faults[task_faults_idx(NUMA_MEM, node, 1)]; in show_numa_stats()
12980 gsf = ng->faults[task_faults_idx(NUMA_MEM, node, 0)], in show_numa_stats()
12981 gpf = ng->faults[task_faults_idx(NUMA_MEM, node, 1)]; in show_numa_stats()
13002 INIT_CSD(&cpu_rq(i)->cfsb_csd, __cfsb_csd_unthrottle, cpu_rq(i)); in init_sched_fair_class()
13003 INIT_LIST_HEAD(&cpu_rq(i)->cfsb_csd_list); in init_sched_fair_class()