Lines Matching full:se

261 static inline struct task_struct *task_of(struct sched_entity *se)  in task_of()  argument
263 SCHED_WARN_ON(!entity_is_task(se)); in task_of()
264 return container_of(se, struct task_struct, se); in task_of()
268 #define for_each_sched_entity(se) \ argument
269 for (; se; se = se->parent)
273 return p->se.cfs_rq; in task_cfs_rq()
277 static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se) in cfs_rq_of() argument
279 return se->cfs_rq; in cfs_rq_of()
401 is_same_group(struct sched_entity *se, struct sched_entity *pse) in is_same_group() argument
403 if (se->cfs_rq == pse->cfs_rq) in is_same_group()
404 return se->cfs_rq; in is_same_group()
409 static inline struct sched_entity *parent_entity(struct sched_entity *se) in parent_entity() argument
411 return se->parent; in parent_entity()
415 find_matching_se(struct sched_entity **se, struct sched_entity **pse) in find_matching_se() argument
427 se_depth = (*se)->depth; in find_matching_se()
432 *se = parent_entity(*se); in find_matching_se()
440 while (!is_same_group(*se, *pse)) { in find_matching_se()
441 *se = parent_entity(*se); in find_matching_se()
448 static inline struct task_struct *task_of(struct sched_entity *se) in task_of() argument
450 return container_of(se, struct task_struct, se); in task_of()
453 #define for_each_sched_entity(se) \ argument
454 for (; se; se = NULL)
461 static inline struct cfs_rq *cfs_rq_of(struct sched_entity *se) in cfs_rq_of() argument
463 struct task_struct *p = task_of(se); in cfs_rq_of()
497 static inline struct sched_entity *parent_entity(struct sched_entity *se) in parent_entity() argument
503 find_matching_se(struct sched_entity **se, struct sched_entity **pse) in find_matching_se() argument
555 struct sched_entity *se; in update_min_vruntime() local
556 se = rb_entry(leftmost, struct sched_entity, run_node); in update_min_vruntime()
559 vruntime = se->vruntime; in update_min_vruntime()
561 vruntime = min_vruntime(vruntime, se->vruntime); in update_min_vruntime()
575 static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) in __enqueue_entity() argument
592 if (entity_before(se, entry)) { in __enqueue_entity()
600 rb_link_node(&se->run_node, parent, link); in __enqueue_entity()
601 rb_insert_color_cached(&se->run_node, in __enqueue_entity()
605 static void __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) in __dequeue_entity() argument
607 rb_erase_cached(&se->run_node, &cfs_rq->tasks_timeline); in __dequeue_entity()
620 static struct sched_entity *__pick_next_entity(struct sched_entity *se) in __pick_next_entity() argument
622 struct rb_node *next = rb_next(&se->run_node); in __pick_next_entity()
671 static inline u64 calc_delta_fair(u64 delta, struct sched_entity *se) in calc_delta_fair() argument
673 if (unlikely(se->load.weight != NICE_0_LOAD)) in calc_delta_fair()
674 delta = __calc_delta(delta, NICE_0_LOAD, &se->load); in calc_delta_fair()
701 static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) in sched_slice() argument
703 u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq); in sched_slice()
705 for_each_sched_entity(se) { in sched_slice()
709 cfs_rq = cfs_rq_of(se); in sched_slice()
712 if (unlikely(!se->on_rq)) { in sched_slice()
715 update_load_add(&lw, se->load.weight); in sched_slice()
718 slice = __calc_delta(slice, se->load.weight, load); in sched_slice()
728 static u64 sched_vslice(struct cfs_rq *cfs_rq, struct sched_entity *se) in sched_vslice() argument
730 return calc_delta_fair(sched_slice(cfs_rq, se), se); in sched_vslice()
741 void init_entity_runnable_average(struct sched_entity *se) in init_entity_runnable_average() argument
743 struct sched_avg *sa = &se->avg; in init_entity_runnable_average()
753 if (entity_is_task(se)) in init_entity_runnable_average()
754 sa->load_avg = scale_load_down(se->load.weight); in init_entity_runnable_average()
759 static void attach_entity_cfs_rq(struct sched_entity *se);
765 * util_avg = cfs_rq->util_avg / (cfs_rq->load_avg + 1) * se.load.weight
789 struct sched_entity *se = &p->se; in post_init_entity_util_avg() local
790 struct cfs_rq *cfs_rq = cfs_rq_of(se); in post_init_entity_util_avg()
791 struct sched_avg *sa = &se->avg; in post_init_entity_util_avg()
797 sa->util_avg = cfs_rq->avg.util_avg * se->load.weight; in post_init_entity_util_avg()
814 attach_entity_load_avg(cfs_rq, se); in post_init_entity_util_avg()
820 se->avg.last_update_time = cfs_rq_clock_pelt(cfs_rq); in post_init_entity_util_avg()
824 attach_entity_cfs_rq(se); in post_init_entity_util_avg()
828 void init_entity_runnable_average(struct sched_entity *se) in init_entity_runnable_average() argument
879 update_curr(cfs_rq_of(&rq->curr->se)); in update_curr_fair()
883 update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se) in update_stats_wait_start() argument
891 prev_wait_start = schedstat_val(se->statistics.wait_start); in update_stats_wait_start()
893 if (entity_is_task(se) && task_on_rq_migrating(task_of(se)) && in update_stats_wait_start()
897 __schedstat_set(se->statistics.wait_start, wait_start); in update_stats_wait_start()
901 update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se) in update_stats_wait_end() argument
909 delta = rq_clock(rq_of(cfs_rq)) - schedstat_val(se->statistics.wait_start); in update_stats_wait_end()
911 if (entity_is_task(se)) { in update_stats_wait_end()
912 p = task_of(se); in update_stats_wait_end()
919 __schedstat_set(se->statistics.wait_start, delta); in update_stats_wait_end()
925 __schedstat_set(se->statistics.wait_max, in update_stats_wait_end()
926 max(schedstat_val(se->statistics.wait_max), delta)); in update_stats_wait_end()
927 __schedstat_inc(se->statistics.wait_count); in update_stats_wait_end()
928 __schedstat_add(se->statistics.wait_sum, delta); in update_stats_wait_end()
929 __schedstat_set(se->statistics.wait_start, 0); in update_stats_wait_end()
933 update_stats_enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) in update_stats_enqueue_sleeper() argument
941 sleep_start = schedstat_val(se->statistics.sleep_start); in update_stats_enqueue_sleeper()
942 block_start = schedstat_val(se->statistics.block_start); in update_stats_enqueue_sleeper()
944 if (entity_is_task(se)) in update_stats_enqueue_sleeper()
945 tsk = task_of(se); in update_stats_enqueue_sleeper()
953 if (unlikely(delta > schedstat_val(se->statistics.sleep_max))) in update_stats_enqueue_sleeper()
954 __schedstat_set(se->statistics.sleep_max, delta); in update_stats_enqueue_sleeper()
956 __schedstat_set(se->statistics.sleep_start, 0); in update_stats_enqueue_sleeper()
957 __schedstat_add(se->statistics.sum_sleep_runtime, delta); in update_stats_enqueue_sleeper()
970 if (unlikely(delta > schedstat_val(se->statistics.block_max))) in update_stats_enqueue_sleeper()
971 __schedstat_set(se->statistics.block_max, delta); in update_stats_enqueue_sleeper()
973 __schedstat_set(se->statistics.block_start, 0); in update_stats_enqueue_sleeper()
974 __schedstat_add(se->statistics.sum_sleep_runtime, delta); in update_stats_enqueue_sleeper()
978 __schedstat_add(se->statistics.iowait_sum, delta); in update_stats_enqueue_sleeper()
979 __schedstat_inc(se->statistics.iowait_count); in update_stats_enqueue_sleeper()
1004 update_stats_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) in update_stats_enqueue() argument
1013 if (se != cfs_rq->curr) in update_stats_enqueue()
1014 update_stats_wait_start(cfs_rq, se); in update_stats_enqueue()
1017 update_stats_enqueue_sleeper(cfs_rq, se); in update_stats_enqueue()
1021 update_stats_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) in update_stats_dequeue() argument
1031 if (se != cfs_rq->curr) in update_stats_dequeue()
1032 update_stats_wait_end(cfs_rq, se); in update_stats_dequeue()
1034 if ((flags & DEQUEUE_SLEEP) && entity_is_task(se)) { in update_stats_dequeue()
1035 struct task_struct *tsk = task_of(se); in update_stats_dequeue()
1038 __schedstat_set(se->statistics.sleep_start, in update_stats_dequeue()
1041 __schedstat_set(se->statistics.block_start, in update_stats_dequeue()
1050 update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se) in update_stats_curr_start() argument
1055 se->exec_start = rq_clock_task(rq_of(cfs_rq)); in update_stats_curr_start()
2246 now = p->se.exec_start; in numa_get_avg_runtime()
2247 runtime = p->se.sum_exec_runtime; in numa_get_avg_runtime()
2257 delta = p->se.avg.load_sum; in numa_get_avg_runtime()
2721 u64 runtime = p->se.sum_exec_runtime; in task_numa_work()
2852 if (unlikely(p->se.sum_exec_runtime != runtime)) { in task_numa_work()
2853 u64 diff = p->se.sum_exec_runtime - runtime; in task_numa_work()
2922 now = curr->se.sum_exec_runtime; in task_tick_numa()
2989 account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se) in account_entity_enqueue() argument
2991 update_load_add(&cfs_rq->load, se->load.weight); in account_entity_enqueue()
2993 if (entity_is_task(se)) { in account_entity_enqueue()
2996 account_numa_enqueue(rq, task_of(se)); in account_entity_enqueue()
2997 list_add(&se->group_node, &rq->cfs_tasks); in account_entity_enqueue()
3004 account_entity_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se) in account_entity_dequeue() argument
3006 update_load_sub(&cfs_rq->load, se->load.weight); in account_entity_dequeue()
3008 if (entity_is_task(se)) { in account_entity_dequeue()
3009 account_numa_dequeue(rq_of(cfs_rq), task_of(se)); in account_entity_dequeue()
3010 list_del_init(&se->group_node); in account_entity_dequeue()
3066 enqueue_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) in enqueue_load_avg() argument
3068 cfs_rq->avg.load_avg += se->avg.load_avg; in enqueue_load_avg()
3069 cfs_rq->avg.load_sum += se_weight(se) * se->avg.load_sum; in enqueue_load_avg()
3073 dequeue_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) in dequeue_load_avg() argument
3075 sub_positive(&cfs_rq->avg.load_avg, se->avg.load_avg); in dequeue_load_avg()
3076 sub_positive(&cfs_rq->avg.load_sum, se_weight(se) * se->avg.load_sum); in dequeue_load_avg()
3080 enqueue_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) { } in enqueue_load_avg() argument
3082 dequeue_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) { } in dequeue_load_avg() argument
3085 static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, in reweight_entity() argument
3088 if (se->on_rq) { in reweight_entity()
3090 if (cfs_rq->curr == se) in reweight_entity()
3092 update_load_sub(&cfs_rq->load, se->load.weight); in reweight_entity()
3094 dequeue_load_avg(cfs_rq, se); in reweight_entity()
3096 update_load_set(&se->load, weight); in reweight_entity()
3100 u32 divider = get_pelt_divider(&se->avg); in reweight_entity()
3102 se->avg.load_avg = div_u64(se_weight(se) * se->avg.load_sum, divider); in reweight_entity()
3106 enqueue_load_avg(cfs_rq, se); in reweight_entity()
3107 if (se->on_rq) in reweight_entity()
3108 update_load_add(&cfs_rq->load, se->load.weight); in reweight_entity()
3114 struct sched_entity *se = &p->se; in reweight_task() local
3115 struct cfs_rq *cfs_rq = cfs_rq_of(se); in reweight_task()
3116 struct load_weight *load = &se->load; in reweight_task()
3119 reweight_entity(cfs_rq, se, weight); in reweight_task()
3239 static void update_cfs_group(struct sched_entity *se) in update_cfs_group() argument
3241 struct cfs_rq *gcfs_rq = group_cfs_rq(se); in update_cfs_group()
3253 if (likely(se->load.weight == shares)) in update_cfs_group()
3259 reweight_entity(cfs_rq_of(se), se, shares); in update_cfs_group()
3263 static inline void update_cfs_group(struct sched_entity *se) in update_cfs_group() argument
3328 void set_task_rq_fair(struct sched_entity *se, in set_task_rq_fair() argument
3344 if (!(se->avg.last_update_time && prev)) in set_task_rq_fair()
3368 __update_load_avg_blocked_se(p_last_update_time, se); in set_task_rq_fair()
3369 se->avg.last_update_time = n_last_update_time; in set_task_rq_fair()
3442 update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) in update_tg_cfs_util() argument
3444 long delta = gcfs_rq->avg.util_avg - se->avg.util_avg; in update_tg_cfs_util()
3452 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in update_tg_cfs_util()
3458 se->avg.util_avg = gcfs_rq->avg.util_avg; in update_tg_cfs_util()
3459 se->avg.util_sum = se->avg.util_avg * divider; in update_tg_cfs_util()
3467 update_tg_cfs_runnable(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) in update_tg_cfs_runnable() argument
3469 long delta = gcfs_rq->avg.runnable_avg - se->avg.runnable_avg; in update_tg_cfs_runnable()
3477 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in update_tg_cfs_runnable()
3483 se->avg.runnable_avg = gcfs_rq->avg.runnable_avg; in update_tg_cfs_runnable()
3484 se->avg.runnable_sum = se->avg.runnable_avg * divider; in update_tg_cfs_runnable()
3492 update_tg_cfs_load(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq) in update_tg_cfs_load() argument
3506 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in update_tg_cfs_load()
3516 runnable_sum += se->avg.load_sum; in update_tg_cfs_load()
3528 /* But make sure to not inflate se's runnable */ in update_tg_cfs_load()
3529 runnable_sum = min(se->avg.load_sum, load_sum); in update_tg_cfs_load()
3538 running_sum = se->avg.util_sum >> SCHED_CAPACITY_SHIFT; in update_tg_cfs_load()
3541 load_sum = (s64)se_weight(se) * runnable_sum; in update_tg_cfs_load()
3544 delta_sum = load_sum - (s64)se_weight(se) * se->avg.load_sum; in update_tg_cfs_load()
3545 delta_avg = load_avg - se->avg.load_avg; in update_tg_cfs_load()
3547 se->avg.load_sum = runnable_sum; in update_tg_cfs_load()
3548 se->avg.load_avg = load_avg; in update_tg_cfs_load()
3560 static inline int propagate_entity_load_avg(struct sched_entity *se) in propagate_entity_load_avg() argument
3564 if (entity_is_task(se)) in propagate_entity_load_avg()
3567 gcfs_rq = group_cfs_rq(se); in propagate_entity_load_avg()
3573 cfs_rq = cfs_rq_of(se); in propagate_entity_load_avg()
3577 update_tg_cfs_util(cfs_rq, se, gcfs_rq); in propagate_entity_load_avg()
3578 update_tg_cfs_runnable(cfs_rq, se, gcfs_rq); in propagate_entity_load_avg()
3579 update_tg_cfs_load(cfs_rq, se, gcfs_rq); in propagate_entity_load_avg()
3582 trace_pelt_se_tp(se); in propagate_entity_load_avg()
3591 static inline bool skip_blocked_update(struct sched_entity *se) in skip_blocked_update() argument
3593 struct cfs_rq *gcfs_rq = group_cfs_rq(se); in skip_blocked_update()
3599 if (se->avg.load_avg || se->avg.util_avg) in skip_blocked_update()
3621 static inline int propagate_entity_load_avg(struct sched_entity *se) in propagate_entity_load_avg() argument
3699 * @se: sched_entity to attach
3704 static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) in attach_entity_load_avg() argument
3707 * cfs_rq->avg.period_contrib can be used for both cfs_rq and se. in attach_entity_load_avg()
3713 * When we attach the @se to the @cfs_rq, we must align the decay in attach_entity_load_avg()
3719 se->avg.last_update_time = cfs_rq->avg.last_update_time; in attach_entity_load_avg()
3720 se->avg.period_contrib = cfs_rq->avg.period_contrib; in attach_entity_load_avg()
3728 se->avg.util_sum = se->avg.util_avg * divider; in attach_entity_load_avg()
3730 se->avg.runnable_sum = se->avg.runnable_avg * divider; in attach_entity_load_avg()
3732 se->avg.load_sum = divider; in attach_entity_load_avg()
3733 if (se_weight(se)) { in attach_entity_load_avg()
3734 se->avg.load_sum = in attach_entity_load_avg()
3735 div_u64(se->avg.load_avg * se->avg.load_sum, se_weight(se)); in attach_entity_load_avg()
3738 enqueue_load_avg(cfs_rq, se); in attach_entity_load_avg()
3739 cfs_rq->avg.util_avg += se->avg.util_avg; in attach_entity_load_avg()
3740 cfs_rq->avg.util_sum += se->avg.util_sum; in attach_entity_load_avg()
3741 cfs_rq->avg.runnable_avg += se->avg.runnable_avg; in attach_entity_load_avg()
3742 cfs_rq->avg.runnable_sum += se->avg.runnable_sum; in attach_entity_load_avg()
3744 add_tg_cfs_propagate(cfs_rq, se->avg.load_sum); in attach_entity_load_avg()
3754 * @se: sched_entity to detach
3759 static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) in detach_entity_load_avg() argument
3761 dequeue_load_avg(cfs_rq, se); in detach_entity_load_avg()
3762 sub_positive(&cfs_rq->avg.util_avg, se->avg.util_avg); in detach_entity_load_avg()
3763 sub_positive(&cfs_rq->avg.util_sum, se->avg.util_sum); in detach_entity_load_avg()
3764 sub_positive(&cfs_rq->avg.runnable_avg, se->avg.runnable_avg); in detach_entity_load_avg()
3765 sub_positive(&cfs_rq->avg.runnable_sum, se->avg.runnable_sum); in detach_entity_load_avg()
3767 add_tg_cfs_propagate(cfs_rq, -se->avg.load_sum); in detach_entity_load_avg()
3782 static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) in update_load_avg() argument
3791 if (se->avg.last_update_time && !(flags & SKIP_AGE_LOAD)) in update_load_avg()
3792 __update_load_avg_se(now, cfs_rq, se); in update_load_avg()
3795 decayed |= propagate_entity_load_avg(se); in update_load_avg()
3797 if (!se->avg.last_update_time && (flags & DO_ATTACH)) { in update_load_avg()
3806 attach_entity_load_avg(cfs_rq, se); in update_load_avg()
3842 static void sync_entity_load_avg(struct sched_entity *se) in sync_entity_load_avg() argument
3844 struct cfs_rq *cfs_rq = cfs_rq_of(se); in sync_entity_load_avg()
3848 __update_load_avg_blocked_se(last_update_time, se); in sync_entity_load_avg()
3855 static void remove_entity_load_avg(struct sched_entity *se) in remove_entity_load_avg() argument
3857 struct cfs_rq *cfs_rq = cfs_rq_of(se); in remove_entity_load_avg()
3866 sync_entity_load_avg(se); in remove_entity_load_avg()
3870 cfs_rq->removed.util_avg += se->avg.util_avg; in remove_entity_load_avg()
3871 cfs_rq->removed.load_avg += se->avg.load_avg; in remove_entity_load_avg()
3872 cfs_rq->removed.runnable_avg += se->avg.runnable_avg; in remove_entity_load_avg()
3890 return READ_ONCE(p->se.avg.util_avg); in task_util()
3895 struct util_est ue = READ_ONCE(p->se.avg.util_est); in _task_util_est()
3976 ue = p->se.avg.util_est; in util_est_dequeue()
4029 WRITE_ONCE(p->se.avg.util_est, ue); in util_est_dequeue()
4031 trace_sched_util_est_se_tp(&p->se); in util_est_dequeue()
4067 static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int not_used1) in update_load_avg() argument
4072 static inline void remove_entity_load_avg(struct sched_entity *se) {} in remove_entity_load_avg() argument
4075 attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) {} in attach_entity_load_avg() argument
4077 detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) {} in detach_entity_load_avg() argument
4094 static void check_spread(struct cfs_rq *cfs_rq, struct sched_entity *se) in check_spread() argument
4097 s64 d = se->vruntime - cfs_rq->min_vruntime; in check_spread()
4108 place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) in place_entity() argument
4119 vruntime += sched_vslice(cfs_rq, se); in place_entity()
4136 se->vruntime = max_vruntime(se->vruntime, vruntime); in place_entity()
4194 enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) in enqueue_entity() argument
4197 bool curr = cfs_rq->curr == se; in enqueue_entity()
4204 se->vruntime += cfs_rq->min_vruntime; in enqueue_entity()
4215 se->vruntime += cfs_rq->min_vruntime; in enqueue_entity()
4225 update_load_avg(cfs_rq, se, UPDATE_TG | DO_ATTACH); in enqueue_entity()
4226 se_update_runnable(se); in enqueue_entity()
4227 update_cfs_group(se); in enqueue_entity()
4228 account_entity_enqueue(cfs_rq, se); in enqueue_entity()
4231 place_entity(cfs_rq, se, 0); in enqueue_entity()
4234 update_stats_enqueue(cfs_rq, se, flags); in enqueue_entity()
4235 check_spread(cfs_rq, se); in enqueue_entity()
4237 __enqueue_entity(cfs_rq, se); in enqueue_entity()
4238 se->on_rq = 1; in enqueue_entity()
4252 static void __clear_buddies_last(struct sched_entity *se) in __clear_buddies_last() argument
4254 for_each_sched_entity(se) { in __clear_buddies_last()
4255 struct cfs_rq *cfs_rq = cfs_rq_of(se); in __clear_buddies_last()
4256 if (cfs_rq->last != se) in __clear_buddies_last()
4263 static void __clear_buddies_next(struct sched_entity *se) in __clear_buddies_next() argument
4265 for_each_sched_entity(se) { in __clear_buddies_next()
4266 struct cfs_rq *cfs_rq = cfs_rq_of(se); in __clear_buddies_next()
4267 if (cfs_rq->next != se) in __clear_buddies_next()
4274 static void __clear_buddies_skip(struct sched_entity *se) in __clear_buddies_skip() argument
4276 for_each_sched_entity(se) { in __clear_buddies_skip()
4277 struct cfs_rq *cfs_rq = cfs_rq_of(se); in __clear_buddies_skip()
4278 if (cfs_rq->skip != se) in __clear_buddies_skip()
4285 static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) in clear_buddies() argument
4287 if (cfs_rq->last == se) in clear_buddies()
4288 __clear_buddies_last(se); in clear_buddies()
4290 if (cfs_rq->next == se) in clear_buddies()
4291 __clear_buddies_next(se); in clear_buddies()
4293 if (cfs_rq->skip == se) in clear_buddies()
4294 __clear_buddies_skip(se); in clear_buddies()
4300 dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) in dequeue_entity() argument
4315 update_load_avg(cfs_rq, se, UPDATE_TG); in dequeue_entity()
4316 se_update_runnable(se); in dequeue_entity()
4318 update_stats_dequeue(cfs_rq, se, flags); in dequeue_entity()
4320 clear_buddies(cfs_rq, se); in dequeue_entity()
4322 if (se != cfs_rq->curr) in dequeue_entity()
4323 __dequeue_entity(cfs_rq, se); in dequeue_entity()
4324 se->on_rq = 0; in dequeue_entity()
4325 account_entity_dequeue(cfs_rq, se); in dequeue_entity()
4329 * min_vruntime if @se is the one holding it back. But before doing in dequeue_entity()
4330 * update_min_vruntime() again, which will discount @se's position and in dequeue_entity()
4334 se->vruntime -= cfs_rq->min_vruntime; in dequeue_entity()
4339 update_cfs_group(se); in dequeue_entity()
4342 * Now advance min_vruntime if @se was the entity holding it back, in dequeue_entity()
4358 struct sched_entity *se; in check_preempt_tick() local
4381 se = __pick_first_entity(cfs_rq); in check_preempt_tick()
4382 delta = curr->vruntime - se->vruntime; in check_preempt_tick()
4392 set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) in set_next_entity() argument
4395 if (se->on_rq) { in set_next_entity()
4401 update_stats_wait_end(cfs_rq, se); in set_next_entity()
4402 __dequeue_entity(cfs_rq, se); in set_next_entity()
4403 update_load_avg(cfs_rq, se, UPDATE_TG); in set_next_entity()
4406 update_stats_curr_start(cfs_rq, se); in set_next_entity()
4407 cfs_rq->curr = se; in set_next_entity()
4415 rq_of(cfs_rq)->cfs.load.weight >= 2*se->load.weight) { in set_next_entity()
4416 schedstat_set(se->statistics.slice_max, in set_next_entity()
4417 max((u64)schedstat_val(se->statistics.slice_max), in set_next_entity()
4418 se->sum_exec_runtime - se->prev_sum_exec_runtime)); in set_next_entity()
4421 se->prev_sum_exec_runtime = se->sum_exec_runtime; in set_next_entity()
4425 wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se);
4438 struct sched_entity *se; in pick_next_entity() local
4447 se = left; /* ideally we run the leftmost entity */ in pick_next_entity()
4453 if (cfs_rq->skip == se) { in pick_next_entity()
4456 if (se == curr) { in pick_next_entity()
4459 second = __pick_next_entity(se); in pick_next_entity()
4465 se = second; in pick_next_entity()
4472 se = cfs_rq->next; in pick_next_entity()
4477 se = cfs_rq->last; in pick_next_entity()
4480 clear_buddies(cfs_rq, se); in pick_next_entity()
4482 return se; in pick_next_entity()
4745 struct sched_entity *se; in throttle_cfs_rq() local
4769 se = cfs_rq->tg->se[cpu_of(rq_of(cfs_rq))]; in throttle_cfs_rq()
4778 for_each_sched_entity(se) { in throttle_cfs_rq()
4779 struct cfs_rq *qcfs_rq = cfs_rq_of(se); in throttle_cfs_rq()
4781 if (!se->on_rq) in throttle_cfs_rq()
4785 dequeue_entity(qcfs_rq, se, DEQUEUE_SLEEP); in throttle_cfs_rq()
4787 update_load_avg(qcfs_rq, se, 0); in throttle_cfs_rq()
4788 se_update_runnable(se); in throttle_cfs_rq()
4798 if (!se) in throttle_cfs_rq()
4814 struct sched_entity *se; in unthrottle_cfs_rq() local
4817 se = cfs_rq->tg->se[cpu_of(rq)]; in unthrottle_cfs_rq()
4836 for_each_sched_entity(se) { in unthrottle_cfs_rq()
4837 if (se->on_rq) in unthrottle_cfs_rq()
4839 cfs_rq = cfs_rq_of(se); in unthrottle_cfs_rq()
4840 enqueue_entity(cfs_rq, se, ENQUEUE_WAKEUP); in unthrottle_cfs_rq()
4850 for_each_sched_entity(se) { in unthrottle_cfs_rq()
4851 cfs_rq = cfs_rq_of(se); in unthrottle_cfs_rq()
4853 update_load_avg(cfs_rq, se, UPDATE_TG); in unthrottle_cfs_rq()
4854 se_update_runnable(se); in unthrottle_cfs_rq()
4872 /* At this point se is NULL and we are at root level*/ in unthrottle_cfs_rq()
4881 for_each_sched_entity(se) { in unthrottle_cfs_rq()
4882 cfs_rq = cfs_rq_of(se); in unthrottle_cfs_rq()
5391 struct sched_entity *se = &p->se; in hrtick_start_fair() local
5392 struct cfs_rq *cfs_rq = cfs_rq_of(se); in hrtick_start_fair()
5397 u64 slice = sched_slice(cfs_rq, se); in hrtick_start_fair()
5398 u64 ran = se->sum_exec_runtime - se->prev_sum_exec_runtime; in hrtick_start_fair()
5422 if (cfs_rq_of(&curr->se)->nr_running < sched_nr_latency) in hrtick_update()
5478 struct sched_entity *se = &p->se; in enqueue_task_fair() local
5498 for_each_sched_entity(se) { in enqueue_task_fair()
5499 if (se->on_rq) in enqueue_task_fair()
5501 cfs_rq = cfs_rq_of(se); in enqueue_task_fair()
5502 enqueue_entity(cfs_rq, se, flags); in enqueue_task_fair()
5514 for_each_sched_entity(se) { in enqueue_task_fair()
5515 cfs_rq = cfs_rq_of(se); in enqueue_task_fair()
5517 update_load_avg(cfs_rq, se, UPDATE_TG); in enqueue_task_fair()
5518 se_update_runnable(se); in enqueue_task_fair()
5519 update_cfs_group(se); in enqueue_task_fair()
5536 /* At this point se is NULL and we are at root level*/ in enqueue_task_fair()
5564 for_each_sched_entity(se) { in enqueue_task_fair()
5565 cfs_rq = cfs_rq_of(se); in enqueue_task_fair()
5577 static void set_next_buddy(struct sched_entity *se);
5587 struct sched_entity *se = &p->se; in dequeue_task_fair() local
5592 for_each_sched_entity(se) { in dequeue_task_fair()
5593 cfs_rq = cfs_rq_of(se); in dequeue_task_fair()
5594 dequeue_entity(cfs_rq, se, flags); in dequeue_task_fair()
5606 se = parent_entity(se); in dequeue_task_fair()
5611 if (task_sleep && se && !throttled_hierarchy(cfs_rq)) in dequeue_task_fair()
5612 set_next_buddy(se); in dequeue_task_fair()
5618 for_each_sched_entity(se) { in dequeue_task_fair()
5619 cfs_rq = cfs_rq_of(se); in dequeue_task_fair()
5621 update_load_avg(cfs_rq, se, UPDATE_TG); in dequeue_task_fair()
5622 se_update_runnable(se); in dequeue_task_fair()
5623 update_cfs_group(se); in dequeue_task_fair()
5634 /* At this point se is NULL and we are at root level*/ in dequeue_task_fair()
5688 if (cpu_of(rq) != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in cpu_load_without()
5711 if (cpu_of(rq) != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in cpu_runnable_without()
5718 lsub_positive(&runnable, p->se.avg.runnable_avg); in cpu_runnable_without()
5865 schedstat_inc(p->se.statistics.nr_wakeups_affine_attempts); in wake_affine()
5870 schedstat_inc(p->se.statistics.nr_wakeups_affine); in wake_affine()
5946 sync_entity_load_avg(&p->se); in find_idlest_cpu()
6224 sync_entity_load_avg(&p->se); in select_idle_sibling()
6380 if (cpu != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in cpu_util_without()
6603 sync_entity_load_avg(&p->se); in find_energy_efficient_cpu()
6755 static void detach_entity_cfs_rq(struct sched_entity *se);
6771 struct sched_entity *se = &p->se; in migrate_task_rq_fair() local
6772 struct cfs_rq *cfs_rq = cfs_rq_of(se); in migrate_task_rq_fair()
6787 se->vruntime -= min_vruntime; in migrate_task_rq_fair()
6796 detach_entity_cfs_rq(&p->se); in migrate_task_rq_fair()
6807 remove_entity_load_avg(&p->se); in migrate_task_rq_fair()
6811 p->se.avg.last_update_time = 0; in migrate_task_rq_fair()
6814 p->se.exec_start = 0; in migrate_task_rq_fair()
6821 remove_entity_load_avg(&p->se); in task_dead_fair()
6834 static unsigned long wakeup_gran(struct sched_entity *se) in wakeup_gran() argument
6842 * By using 'se' instead of 'curr' we penalize light tasks, so in wakeup_gran()
6843 * they get preempted easier. That is, if 'se' < 'curr' then in wakeup_gran()
6845 * lighter, if otoh 'se' > 'curr' then the resulting gran will in wakeup_gran()
6851 return calc_delta_fair(gran, se); in wakeup_gran()
6855 * Should 'se' preempt 'curr'.
6869 wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se) in wakeup_preempt_entity() argument
6871 s64 gran, vdiff = curr->vruntime - se->vruntime; in wakeup_preempt_entity()
6876 gran = wakeup_gran(se); in wakeup_preempt_entity()
6883 static void set_last_buddy(struct sched_entity *se) in set_last_buddy() argument
6885 if (entity_is_task(se) && unlikely(task_has_idle_policy(task_of(se)))) in set_last_buddy()
6888 for_each_sched_entity(se) { in set_last_buddy()
6889 if (SCHED_WARN_ON(!se->on_rq)) in set_last_buddy()
6891 cfs_rq_of(se)->last = se; in set_last_buddy()
6895 static void set_next_buddy(struct sched_entity *se) in set_next_buddy() argument
6897 if (entity_is_task(se) && unlikely(task_has_idle_policy(task_of(se)))) in set_next_buddy()
6900 for_each_sched_entity(se) { in set_next_buddy()
6901 if (SCHED_WARN_ON(!se->on_rq)) in set_next_buddy()
6903 cfs_rq_of(se)->next = se; in set_next_buddy()
6907 static void set_skip_buddy(struct sched_entity *se) in set_skip_buddy() argument
6909 for_each_sched_entity(se) in set_skip_buddy()
6910 cfs_rq_of(se)->skip = se; in set_skip_buddy()
6919 struct sched_entity *se = &curr->se, *pse = &p->se; in check_preempt_wakeup() local
6924 if (unlikely(se == pse)) in check_preempt_wakeup()
6966 find_matching_se(&se, &pse); in check_preempt_wakeup()
6967 update_curr(cfs_rq_of(se)); in check_preempt_wakeup()
6969 if (wakeup_preempt_entity(se, pse) == 1) { in check_preempt_wakeup()
6992 if (unlikely(!se->on_rq || curr == rq->idle)) in check_preempt_wakeup()
6995 if (sched_feat(LAST_BUDDY) && scale && entity_is_task(se)) in check_preempt_wakeup()
6996 set_last_buddy(se); in check_preempt_wakeup()
7003 struct sched_entity *se; in pick_next_task_fair() local
7054 se = pick_next_entity(cfs_rq, curr); in pick_next_task_fair()
7055 cfs_rq = group_cfs_rq(se); in pick_next_task_fair()
7058 p = task_of(se); in pick_next_task_fair()
7066 struct sched_entity *pse = &prev->se; in pick_next_task_fair()
7068 while (!(cfs_rq = is_same_group(se, pse))) { in pick_next_task_fair()
7069 int se_depth = se->depth; in pick_next_task_fair()
7077 set_next_entity(cfs_rq_of(se), se); in pick_next_task_fair()
7078 se = parent_entity(se); in pick_next_task_fair()
7083 set_next_entity(cfs_rq, se); in pick_next_task_fair()
7093 se = pick_next_entity(cfs_rq, NULL); in pick_next_task_fair()
7094 set_next_entity(cfs_rq, se); in pick_next_task_fair()
7095 cfs_rq = group_cfs_rq(se); in pick_next_task_fair()
7098 p = task_of(se); in pick_next_task_fair()
7107 list_move(&p->se.group_node, &rq->cfs_tasks); in pick_next_task_fair()
7153 struct sched_entity *se = &prev->se; in put_prev_task_fair() local
7156 for_each_sched_entity(se) { in put_prev_task_fair()
7157 cfs_rq = cfs_rq_of(se); in put_prev_task_fair()
7158 put_prev_entity(cfs_rq, se); in put_prev_task_fair()
7171 struct sched_entity *se = &curr->se; in yield_task_fair() local
7179 clear_buddies(cfs_rq, se); in yield_task_fair()
7195 set_skip_buddy(se); in yield_task_fair()
7200 struct sched_entity *se = &p->se; in yield_to_task_fair() local
7203 if (!se->on_rq || throttled_hierarchy(cfs_rq_of(se))) in yield_to_task_fair()
7207 set_next_buddy(se); in yield_to_task_fair()
7439 (&p->se == cfs_rq_of(&p->se)->next || in task_hot()
7440 &p->se == cfs_rq_of(&p->se)->last)) in task_hot()
7448 delta = rq_clock_task(env->src_rq) - p->se.exec_start; in task_hot()
7536 schedstat_inc(p->se.statistics.nr_failed_migrations_affine); in can_migrate_task()
7567 schedstat_inc(p->se.statistics.nr_failed_migrations_running); in can_migrate_task()
7585 schedstat_inc(p->se.statistics.nr_forced_migrations); in can_migrate_task()
7590 schedstat_inc(p->se.statistics.nr_failed_migrations_hot); in can_migrate_task()
7618 &env->src_rq->cfs_tasks, se.group_node) { in detach_one_task()
7664 p = list_last_entry(tasks, struct task_struct, se.group_node); in detach_tasks()
7732 list_add(&p->se.group_node, &env->tasks); in detach_tasks()
7755 list_move(&p->se.group_node, tasks); in detach_tasks()
7808 p = list_first_entry(tasks, struct task_struct, se.group_node); in attach_tasks()
7809 list_del_init(&p->se.group_node); in attach_tasks()
7917 struct sched_entity *se; in __update_blocked_fair() local
7927 se = cfs_rq->tg->se[cpu]; in __update_blocked_fair()
7928 if (se && !skip_blocked_update(se)) in __update_blocked_fair()
7929 update_load_avg(cfs_rq_of(se), se, 0); in __update_blocked_fair()
7954 struct sched_entity *se = cfs_rq->tg->se[cpu_of(rq)]; in update_cfs_rq_h_load() local
7962 for_each_sched_entity(se) { in update_cfs_rq_h_load()
7963 cfs_rq = cfs_rq_of(se); in update_cfs_rq_h_load()
7964 WRITE_ONCE(cfs_rq->h_load_next, se); in update_cfs_rq_h_load()
7969 if (!se) { in update_cfs_rq_h_load()
7974 while ((se = READ_ONCE(cfs_rq->h_load_next)) != NULL) { in update_cfs_rq_h_load()
7976 load = div64_ul(load * se->avg.load_avg, in update_cfs_rq_h_load()
7978 cfs_rq = group_cfs_rq(se); in update_cfs_rq_h_load()
7989 return div64_ul(p->se.avg.load_avg * cfs_rq->h_load, in task_h_load()
8007 return p->se.avg.load_avg; in task_h_load()
8613 if (cpu != task_cpu(p) || !READ_ONCE(p->se.avg.last_update_time)) in task_running_on_cpu()
10696 struct sched_entity *se = &curr->se; in task_tick_fair() local
10698 for_each_sched_entity(se) { in task_tick_fair()
10699 cfs_rq = cfs_rq_of(se); in task_tick_fair()
10700 entity_tick(cfs_rq, se, queued); in task_tick_fair()
10718 struct sched_entity *se = &p->se, *curr; in task_fork_fair() local
10729 se->vruntime = curr->vruntime; in task_fork_fair()
10731 place_entity(cfs_rq, se, 1); in task_fork_fair()
10733 if (sysctl_sched_child_runs_first && curr && entity_before(curr, se)) { in task_fork_fair()
10738 swap(curr->vruntime, se->vruntime); in task_fork_fair()
10742 se->vruntime -= cfs_rq->min_vruntime; in task_fork_fair()
10773 struct sched_entity *se = &p->se; in vruntime_normalized() local
10792 if (!se->sum_exec_runtime || in vruntime_normalized()
10804 static void propagate_entity_cfs_rq(struct sched_entity *se) in propagate_entity_cfs_rq() argument
10809 se = se->parent; in propagate_entity_cfs_rq()
10811 for_each_sched_entity(se) { in propagate_entity_cfs_rq()
10812 cfs_rq = cfs_rq_of(se); in propagate_entity_cfs_rq()
10817 update_load_avg(cfs_rq, se, UPDATE_TG); in propagate_entity_cfs_rq()
10821 static void propagate_entity_cfs_rq(struct sched_entity *se) { } in propagate_entity_cfs_rq() argument
10824 static void detach_entity_cfs_rq(struct sched_entity *se) in detach_entity_cfs_rq() argument
10826 struct cfs_rq *cfs_rq = cfs_rq_of(se); in detach_entity_cfs_rq()
10829 update_load_avg(cfs_rq, se, 0); in detach_entity_cfs_rq()
10830 detach_entity_load_avg(cfs_rq, se); in detach_entity_cfs_rq()
10832 propagate_entity_cfs_rq(se); in detach_entity_cfs_rq()
10835 static void attach_entity_cfs_rq(struct sched_entity *se) in attach_entity_cfs_rq() argument
10837 struct cfs_rq *cfs_rq = cfs_rq_of(se); in attach_entity_cfs_rq()
10844 se->depth = se->parent ? se->parent->depth + 1 : 0; in attach_entity_cfs_rq()
10848 update_load_avg(cfs_rq, se, sched_feat(ATTACH_AGE_LOAD) ? 0 : SKIP_AGE_LOAD); in attach_entity_cfs_rq()
10849 attach_entity_load_avg(cfs_rq, se); in attach_entity_cfs_rq()
10851 propagate_entity_cfs_rq(se); in attach_entity_cfs_rq()
10856 struct sched_entity *se = &p->se; in detach_task_cfs_rq() local
10857 struct cfs_rq *cfs_rq = cfs_rq_of(se); in detach_task_cfs_rq()
10864 place_entity(cfs_rq, se, 0); in detach_task_cfs_rq()
10865 se->vruntime -= cfs_rq->min_vruntime; in detach_task_cfs_rq()
10868 detach_entity_cfs_rq(se); in detach_task_cfs_rq()
10873 struct sched_entity *se = &p->se; in attach_task_cfs_rq() local
10874 struct cfs_rq *cfs_rq = cfs_rq_of(se); in attach_task_cfs_rq()
10876 attach_entity_cfs_rq(se); in attach_task_cfs_rq()
10879 se->vruntime += cfs_rq->min_vruntime; in attach_task_cfs_rq()
10911 struct sched_entity *se = &p->se; in set_next_task_fair() local
10919 list_move(&se->group_node, &rq->cfs_tasks); in set_next_task_fair()
10923 for_each_sched_entity(se) { in set_next_task_fair()
10924 struct cfs_rq *cfs_rq = cfs_rq_of(se); in set_next_task_fair()
10926 set_next_entity(cfs_rq, se); in set_next_task_fair()
10947 struct sched_entity *se = &p->se; in task_set_group_fair() local
10950 se->depth = se->parent ? se->parent->depth + 1 : 0; in task_set_group_fair()
10959 /* Tell se's cfs_rq has been changed -- migrated */ in task_move_group_fair()
10960 p->se.avg.last_update_time = 0; in task_move_group_fair()
10987 if (tg->se) in free_fair_sched_group()
10988 kfree(tg->se[i]); in free_fair_sched_group()
10992 kfree(tg->se); in free_fair_sched_group()
10997 struct sched_entity *se; in alloc_fair_sched_group() local
11004 tg->se = kcalloc(nr_cpu_ids, sizeof(se), GFP_KERNEL); in alloc_fair_sched_group()
11005 if (!tg->se) in alloc_fair_sched_group()
11018 se = kzalloc_node(sizeof(struct sched_entity), in alloc_fair_sched_group()
11020 if (!se) in alloc_fair_sched_group()
11024 init_tg_cfs_entry(tg, cfs_rq, se, i, parent->se[i]); in alloc_fair_sched_group()
11025 init_entity_runnable_average(se); in alloc_fair_sched_group()
11038 struct sched_entity *se; in online_fair_sched_group() local
11045 se = tg->se[i]; in online_fair_sched_group()
11048 attach_entity_cfs_rq(se); in online_fair_sched_group()
11061 if (tg->se[cpu]) in unregister_fair_sched_group()
11062 remove_entity_load_avg(tg->se[cpu]); in unregister_fair_sched_group()
11080 struct sched_entity *se, int cpu, in init_tg_cfs_entry() argument
11090 tg->se[cpu] = se; in init_tg_cfs_entry()
11092 /* se could be NULL for root_task_group */ in init_tg_cfs_entry()
11093 if (!se) in init_tg_cfs_entry()
11097 se->cfs_rq = &rq->cfs; in init_tg_cfs_entry()
11098 se->depth = 0; in init_tg_cfs_entry()
11100 se->cfs_rq = parent->my_q; in init_tg_cfs_entry()
11101 se->depth = parent->depth + 1; in init_tg_cfs_entry()
11104 se->my_q = cfs_rq; in init_tg_cfs_entry()
11106 update_load_set(&se->load, NICE_0_LOAD); in init_tg_cfs_entry()
11107 se->parent = parent; in init_tg_cfs_entry()
11119 if (!tg->se[0]) in sched_group_set_shares()
11131 struct sched_entity *se = tg->se[i]; in sched_group_set_shares() local
11137 for_each_sched_entity(se) { in sched_group_set_shares()
11138 update_load_avg(cfs_rq_of(se), se, UPDATE_TG); in sched_group_set_shares()
11139 update_cfs_group(se); in sched_group_set_shares()
11166 struct sched_entity *se = &task->se; in get_rr_interval_fair() local
11174 rr_interval = NS_TO_JIFFIES(sched_slice(cfs_rq_of(se), se)); in get_rr_interval_fair()