Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Scheduler internal types and methods:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include <linux/sched/autogroup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/sched/clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/sched/coredump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/sched/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/sched/cputime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/sched/deadline.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/sched/hotplug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/sched/idle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/sched/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/sched/isolation.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/sched/jobctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/sched/loadavg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/sched/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/sched/nohz.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/sched/numa_balancing.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/sched/prio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/sched/rt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/sched/smt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/sched/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/sched/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/sched/topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/sched/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/sched/wake_q.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/sched/xacct.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <uapi/linux/sched/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/binfmts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/context_tracking.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/cpuidle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/cpuset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/delayacct.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/energy_model.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/init_task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/kprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/membarrier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/migrate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <linux/prefetch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <linux/profile.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <linux/psi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <linux/rcupdate_wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include <linux/stop_machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include <linux/swait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include <linux/task_work.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #include <linux/tsacct_kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #include <linux/android_vendor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #include <linux/android_kabi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #include <asm/tlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #include <asm-generic/vmlinux.lds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #include <soc/rockchip/rockchip_performance.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #ifdef CONFIG_PARAVIRT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) # include <asm/paravirt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #include "cpupri.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #include "cpudeadline.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #include <trace/events/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #ifdef CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) # define SCHED_WARN_ON(x)	WARN_ONCE(x, #x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) # define SCHED_WARN_ON(x)	({ (void)(x), 0; })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) struct rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) struct cpuidle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) /* task_struct::on_rq states: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #define TASK_ON_RQ_QUEUED	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #define TASK_ON_RQ_MIGRATING	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) extern __read_mostly int scheduler_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) extern unsigned long calc_load_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) extern atomic_long_t calc_load_tasks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) extern void calc_global_load_tick(struct rq *this_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) extern long calc_load_fold_active(struct rq *this_rq, long adjust);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) extern void call_trace_sched_update_nr_running(struct rq *rq, int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  * Helpers for converting nanosecond timing to jiffy resolution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) #define NS_TO_JIFFIES(TIME)	((unsigned long)(TIME) / (NSEC_PER_SEC / HZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  * Increase resolution of nice-level calculations for 64-bit architectures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  * The extra resolution improves shares distribution and load balancing of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  * low-weight task groups (eg. nice +19 on an autogroup), deeper taskgroup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  * hierarchies, especially on larger systems. This is not a user-visible change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  * and does not change the user-interface for setting shares/weights.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)  * We increase resolution only if we have enough bits to allow this increased
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119)  * resolution (i.e. 64-bit). The costs for increasing resolution when 32-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120)  * are pretty high and the returns do not justify the increased costs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122)  * Really only required when CONFIG_FAIR_GROUP_SCHED=y is also set, but to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)  * increase coverage and consistency always enable it on 64-bit platforms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) # define NICE_0_LOAD_SHIFT	(SCHED_FIXEDPOINT_SHIFT + SCHED_FIXEDPOINT_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) # define scale_load(w)		((w) << SCHED_FIXEDPOINT_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) # define scale_load_down(w) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	unsigned long __w = (w); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	if (__w) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 		__w = max(2UL, __w >> SCHED_FIXEDPOINT_SHIFT); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	__w; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) # define NICE_0_LOAD_SHIFT	(SCHED_FIXEDPOINT_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) # define scale_load(w)		(w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) # define scale_load_down(w)	(w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142)  * Task weight (visible to users) and its load (invisible to users) have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143)  * independent resolution, but they should be well calibrated. We use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144)  * scale_load() and scale_load_down(w) to convert between them. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145)  * following must be true:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147)  *  scale_load(sched_prio_to_weight[USER_PRIO(NICE_TO_PRIO(0))]) == NICE_0_LOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) #define NICE_0_LOAD		(1L << NICE_0_LOAD_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153)  * Single value that decides SCHED_DEADLINE internal math precision.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154)  * 10 -> just above 1us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155)  * 9  -> just above 0.5us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #define DL_SCALE		10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160)  * Single value that denotes runtime == period, ie unlimited time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) #define RUNTIME_INF		((u64)~0ULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) static inline int idle_policy(int policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	return policy == SCHED_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) static inline int fair_policy(int policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	return policy == SCHED_NORMAL || policy == SCHED_BATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) static inline int rt_policy(int policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	return policy == SCHED_FIFO || policy == SCHED_RR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) static inline int dl_policy(int policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	return policy == SCHED_DEADLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) static inline bool valid_policy(int policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	return idle_policy(policy) || fair_policy(policy) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		rt_policy(policy) || dl_policy(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) static inline int task_has_idle_policy(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	return idle_policy(p->policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) static inline int task_has_rt_policy(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	return rt_policy(p->policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) static inline int task_has_dl_policy(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	return dl_policy(p->policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) #define cap_scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) static inline void update_avg(u64 *avg, u64 sample)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	s64 diff = sample - *avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	*avg += diff / 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212)  * Shifting a value by an exponent greater *or equal* to the size of said value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213)  * is UB; cap at size-1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) #define shr_bound(val, shift)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	(val >> min_t(typeof(shift), shift, BITS_PER_TYPE(typeof(val)) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  * !! For sched_setattr_nocheck() (kernel) only !!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  * This is actually gross. :(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)  * It is used to make schedutil kworker(s) higher priority than SCHED_DEADLINE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224)  * tasks, but still be able to sleep. We need this on platforms that cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225)  * atomically change clock frequency. Remove once fast switching will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226)  * available on such platforms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228)  * SUGOV stands for SchedUtil GOVernor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) #define SCHED_FLAG_SUGOV	0x10000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) #define SCHED_DL_FLAGS (SCHED_FLAG_RECLAIM | SCHED_FLAG_DL_OVERRUN | SCHED_FLAG_SUGOV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) static inline bool dl_entity_is_special(struct sched_dl_entity *dl_se)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) #ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	return unlikely(dl_se->flags & SCHED_FLAG_SUGOV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244)  * Tells if entity @a should preempt entity @b.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) dl_entity_preempt(struct sched_dl_entity *a, struct sched_dl_entity *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	return dl_entity_is_special(a) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	       dl_time_before(a->deadline, b->deadline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254)  * This is the priority-queue data structure of the RT scheduling class:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) struct rt_prio_array {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	DECLARE_BITMAP(bitmap, MAX_RT_PRIO+1); /* include 1 bit for delimiter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	struct list_head queue[MAX_RT_PRIO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) struct rt_bandwidth {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	/* nests inside the rq lock: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	raw_spinlock_t		rt_runtime_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	ktime_t			rt_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	u64			rt_runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	struct hrtimer		rt_period_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	unsigned int		rt_period_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) void __dl_clear_params(struct task_struct *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) struct dl_bandwidth {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	raw_spinlock_t		dl_runtime_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	u64			dl_runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	u64			dl_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) static inline int dl_bandwidth_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	return sysctl_sched_rt_runtime >= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284)  * To keep the bandwidth of -deadline tasks under control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  * we need some place where:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286)  *  - store the maximum -deadline bandwidth of each cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287)  *  - cache the fraction of bandwidth that is currently allocated in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)  *    each root domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)  * This is all done in the data structure below. It is similar to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291)  * one used for RT-throttling (rt_bandwidth), with the main difference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292)  * that, since here we are only interested in admission control, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293)  * do not decrease any runtime while the group "executes", neither we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294)  * need a timer to replenish it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296)  * With respect to SMP, bandwidth is given on a per root domain basis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297)  * meaning that:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298)  *  - bw (< 100%) is the deadline bandwidth of each CPU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299)  *  - total_bw is the currently allocated bandwidth in each root domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) struct dl_bw {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	raw_spinlock_t		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	u64			bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	u64			total_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) static inline void __dl_update(struct dl_bw *dl_b, s64 bw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) void __dl_sub(struct dl_bw *dl_b, u64 tsk_bw, int cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	dl_b->total_bw -= tsk_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	__dl_update(dl_b, (s32)tsk_bw / cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) void __dl_add(struct dl_bw *dl_b, u64 tsk_bw, int cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	dl_b->total_bw += tsk_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	__dl_update(dl_b, -((s32)tsk_bw / cpus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) static inline bool __dl_overflow(struct dl_bw *dl_b, unsigned long cap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 				 u64 old_bw, u64 new_bw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	return dl_b->bw != -1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	       cap_scale(dl_b->bw, cap) < dl_b->total_bw - old_bw + new_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331)  * Verify the fitness of task @p to run on @cpu taking into account the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332)  * CPU original capacity and the runtime/deadline ratio of the task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334)  * The function will return true if the CPU original capacity of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335)  * @cpu scaled by SCHED_CAPACITY_SCALE >= runtime/deadline ratio of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336)  * task and false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) static inline bool dl_task_fits_capacity(struct task_struct *p, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	unsigned long cap = arch_scale_cpu_capacity(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	return cap_scale(p->dl.dl_deadline, cap) >= p->dl.dl_runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) extern void init_dl_bw(struct dl_bw *dl_b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) extern int  sched_dl_global_validate(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) extern void sched_dl_do_global(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) extern int  sched_dl_overflow(struct task_struct *p, int policy, const struct sched_attr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) extern void __setparam_dl(struct task_struct *p, const struct sched_attr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) extern void __getparam_dl(struct task_struct *p, struct sched_attr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) extern bool __checkparam_dl(const struct sched_attr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) extern bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) extern int  dl_task_can_attach(struct task_struct *p, const struct cpumask *cs_cpus_allowed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) extern int  dl_cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) extern bool dl_cpu_busy(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) #ifdef CONFIG_CGROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) #include <linux/cgroup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) #include <linux/psi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) struct cfs_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) struct rt_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) extern struct list_head task_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) struct cfs_bandwidth {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) #ifdef CONFIG_CFS_BANDWIDTH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	raw_spinlock_t		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	ktime_t			period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	u64			quota;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	u64			runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	s64			hierarchical_quota;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	u8			idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	u8			period_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	u8			slack_started;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	struct hrtimer		period_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	struct hrtimer		slack_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	struct list_head	throttled_cfs_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	/* Statistics: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	int			nr_periods;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	int			nr_throttled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	u64			throttled_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) /* Task group related information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) struct task_group {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	struct cgroup_subsys_state css;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	/* schedulable entities of this group on each CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	struct sched_entity	**se;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	/* runqueue "owned" by this group on each CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	struct cfs_rq		**cfs_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	unsigned long		shares;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) #ifdef	CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	 * load_avg can be heavily contended at clock tick time, so put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	 * it in its own cacheline separated from the fields above which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	 * will also be accessed at each tick.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	atomic_long_t		load_avg ____cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) #ifdef CONFIG_RT_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	struct sched_rt_entity	**rt_se;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	struct rt_rq		**rt_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	struct rt_bandwidth	rt_bandwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	struct rcu_head		rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	struct list_head	list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	struct task_group	*parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	struct list_head	siblings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	struct list_head	children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) #ifdef CONFIG_SCHED_AUTOGROUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	struct autogroup	*autogroup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	struct cfs_bandwidth	cfs_bandwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) #ifdef CONFIG_UCLAMP_TASK_GROUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	/* The two decimal precision [%] value requested from user-space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	unsigned int		uclamp_pct[UCLAMP_CNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	/* Clamp values requested for a task group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	struct uclamp_se	uclamp_req[UCLAMP_CNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	/* Effective clamp values used for a task group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	struct uclamp_se	uclamp[UCLAMP_CNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	/* Latency-sensitive flag used for a task group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	unsigned int		latency_sensitive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	ANDROID_VENDOR_DATA_ARRAY(1, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	ANDROID_KABI_RESERVE(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	ANDROID_KABI_RESERVE(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	ANDROID_KABI_RESERVE(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) #define ROOT_TASK_GROUP_LOAD	NICE_0_LOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)  * A weight of 0 or 1 can cause arithmetics problems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454)  * A weight of a cfs_rq is the sum of weights of which entities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455)  * are queued on this cfs_rq, so a weight of a entity should not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456)  * too large, so as the shares value of a task group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457)  * (The default weight is 1024 - so there's no practical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458)  *  limitation from this.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) #define MIN_SHARES		(1UL <<  1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) #define MAX_SHARES		(1UL << 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) typedef int (*tg_visitor)(struct task_group *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) extern int walk_tg_tree_from(struct task_group *from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 			     tg_visitor down, tg_visitor up, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470)  * Iterate the full tree, calling @down when first entering a node and @up when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471)  * leaving it for the final time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473)  * Caller must hold rcu_lock or sufficient equivalent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) static inline int walk_tg_tree(tg_visitor down, tg_visitor up, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	return walk_tg_tree_from(&root_task_group, down, up, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) extern int tg_nop(struct task_group *tg, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) extern void free_fair_sched_group(struct task_group *tg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) extern int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) extern void online_fair_sched_group(struct task_group *tg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) extern void unregister_fair_sched_group(struct task_group *tg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) extern void init_tg_cfs_entry(struct task_group *tg, struct cfs_rq *cfs_rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			struct sched_entity *se, int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			struct sched_entity *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) extern void init_cfs_bandwidth(struct cfs_bandwidth *cfs_b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) extern void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) extern void start_cfs_bandwidth(struct cfs_bandwidth *cfs_b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) extern void unthrottle_cfs_rq(struct cfs_rq *cfs_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) extern void free_rt_sched_group(struct task_group *tg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) extern int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) extern void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		struct sched_rt_entity *rt_se, int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		struct sched_rt_entity *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) extern int sched_group_set_rt_runtime(struct task_group *tg, long rt_runtime_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) extern int sched_group_set_rt_period(struct task_group *tg, u64 rt_period_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) extern long sched_group_rt_runtime(struct task_group *tg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) extern long sched_group_rt_period(struct task_group *tg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) extern struct task_group *sched_create_group(struct task_group *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) extern void sched_online_group(struct task_group *tg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 			       struct task_group *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) extern void sched_destroy_group(struct task_group *tg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) extern void sched_offline_group(struct task_group *tg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) extern void sched_move_task(struct task_struct *tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) extern void set_task_rq_fair(struct sched_entity *se,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 			     struct cfs_rq *prev, struct cfs_rq *next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) #else /* !CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) static inline void set_task_rq_fair(struct sched_entity *se,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			     struct cfs_rq *prev, struct cfs_rq *next) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) #endif /* CONFIG_FAIR_GROUP_SCHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) #else /* CONFIG_CGROUP_SCHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) struct cfs_bandwidth { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) #endif	/* CONFIG_CGROUP_SCHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) /* CFS-related fields in a runqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) struct cfs_rq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	struct load_weight	load;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	unsigned int		nr_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	unsigned int		h_nr_running;      /* SCHED_{NORMAL,BATCH,IDLE} */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	unsigned int		idle_h_nr_running; /* SCHED_IDLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	u64			exec_clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	u64			min_vruntime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) #ifndef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	u64			min_vruntime_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	struct rb_root_cached	tasks_timeline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	 * 'curr' points to currently running entity on this cfs_rq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	 * It is set to NULL otherwise (i.e when none are currently running).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	struct sched_entity	*curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	struct sched_entity	*next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	struct sched_entity	*last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	struct sched_entity	*skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) #ifdef	CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	unsigned int		nr_spread_over;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	 * CFS load tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	struct sched_avg	avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) #ifndef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	u64			load_last_update_time_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		raw_spinlock_t	lock ____cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		int		nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		unsigned long	load_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		unsigned long	util_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		unsigned long	runnable_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	} removed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	unsigned long		tg_load_avg_contrib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	long			propagate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	long			prop_runnable_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	 *   h_load = weight * f(tg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	 * Where f(tg) is the recursive weight fraction assigned to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	 * this group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	unsigned long		h_load;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	u64			last_h_load_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	struct sched_entity	*h_load_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) #endif /* CONFIG_FAIR_GROUP_SCHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	struct rq		*rq;	/* CPU runqueue to which this cfs_rq is attached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	 * leaf cfs_rqs are those that hold tasks (lowest schedulable entity in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	 * a hierarchy). Non-leaf lrqs hold other higher schedulable entities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	 * (like users, containers etc.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	 * leaf_cfs_rq_list ties together list of leaf cfs_rq's in a CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	 * This list is used during load balance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	int			on_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	struct list_head	leaf_cfs_rq_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	struct task_group	*tg;	/* group that "owns" this runqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) #ifdef CONFIG_CFS_BANDWIDTH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	int			runtime_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	s64			runtime_remaining;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	u64			throttled_clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	u64			throttled_clock_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	u64			throttled_clock_task_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	int			throttled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	int			throttle_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	struct list_head	throttled_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) #endif /* CONFIG_CFS_BANDWIDTH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	ANDROID_VENDOR_DATA_ARRAY(1, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) #endif /* CONFIG_FAIR_GROUP_SCHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) static inline int rt_bandwidth_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	return sysctl_sched_rt_runtime >= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) /* RT IPI pull logic requires IRQ_WORK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) #if defined(CONFIG_IRQ_WORK) && defined(CONFIG_SMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) # define HAVE_RT_PUSH_IPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) /* Real-Time classes' related field in a runqueue: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) struct rt_rq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	struct rt_prio_array	active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	unsigned int		rt_nr_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	unsigned int		rr_nr_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		int		curr; /* highest queued rt task prio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		int		next; /* next highest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	} highest_prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	unsigned long		rt_nr_migratory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	unsigned long		rt_nr_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	int			overloaded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	struct plist_head	pushable_tasks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	int			rt_queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	int			rt_throttled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	u64			rt_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	u64			rt_runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	/* Nests inside the rq lock: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	raw_spinlock_t		rt_runtime_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) #ifdef CONFIG_RT_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	unsigned long		rt_nr_boosted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	struct rq		*rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	struct task_group	*tg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) static inline bool rt_rq_is_runnable(struct rt_rq *rt_rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	return rt_rq->rt_queued && rt_rq->rt_nr_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) /* Deadline class' related fields in a runqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) struct dl_rq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	/* runqueue is an rbtree, ordered by deadline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	struct rb_root_cached	root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	unsigned long		dl_nr_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	 * Deadline values of the currently executing and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	 * earliest ready task on this rq. Caching these facilitates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	 * the decision whether or not a ready but not running task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	 * should migrate somewhere else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		u64		curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		u64		next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	} earliest_dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	unsigned long		dl_nr_migratory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	int			overloaded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	 * Tasks on this rq that can be pushed away. They are kept in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	 * an rb-tree, ordered by tasks' deadlines, with caching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	 * of the leftmost (earliest deadline) element.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	struct rb_root_cached	pushable_dl_tasks_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	struct dl_bw		dl_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	 * "Active utilization" for this runqueue: increased when a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	 * task wakes up (becomes TASK_RUNNING) and decreased when a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	 * task blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	u64			running_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	 * Utilization of the tasks "assigned" to this runqueue (including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	 * the tasks that are in runqueue and the tasks that executed on this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	 * CPU and blocked). Increased when a task moves to this runqueue, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	 * decreased when the task moves away (migrates, changes scheduling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	 * policy, or terminates).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	 * This is needed to compute the "inactive utilization" for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	 * runqueue (inactive utilization = this_bw - running_bw).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	u64			this_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	u64			extra_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	 * Inverse of the fraction of CPU utilization that can be reclaimed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	 * by the GRUB algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	u64			bw_ratio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) /* An entity is a task if it doesn't "own" a runqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) #define entity_is_task(se)	(!se->my_q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) static inline void se_update_runnable(struct sched_entity *se)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	if (!entity_is_task(se))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		se->runnable_weight = se->my_q->h_nr_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) static inline long se_runnable(struct sched_entity *se)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	if (entity_is_task(se))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		return !!se->on_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		return se->runnable_weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) #define entity_is_task(se)	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) static inline void se_update_runnable(struct sched_entity *se) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) static inline long se_runnable(struct sched_entity *se)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	return !!se->on_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763)  * XXX we want to get rid of these helpers and use the full load resolution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) static inline long se_weight(struct sched_entity *se)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	return scale_load_down(se->load.weight);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) static inline bool sched_asym_prefer(int a, int b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	return arch_asym_cpu_priority(a) > arch_asym_cpu_priority(b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) struct perf_domain {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	struct em_perf_domain *em_pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	struct perf_domain *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) /* Scheduling group status flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) #define SG_OVERLOAD		0x1 /* More than one runnable task on a CPU. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) #define SG_OVERUTILIZED		0x2 /* One or more CPUs are over-utilized. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787)  * We add the notion of a root-domain which will be used to define per-domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788)  * variables. Each exclusive cpuset essentially defines an island domain by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789)  * fully partitioning the member CPUs from any other cpuset. Whenever a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790)  * exclusive cpuset is created, we also create and attach a new root-domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791)  * object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) struct root_domain {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	atomic_t		refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	atomic_t		rto_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	struct rcu_head		rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	cpumask_var_t		span;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	cpumask_var_t		online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	 * Indicate pullable load on at least one CPU, e.g:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	 * - More than one runnable task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	 * - Running task is misfit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	int			overload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	/* Indicate one or more cpus over-utilized (tipping point) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	int			overutilized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	 * The bit corresponding to a CPU gets set here if such CPU has more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	 * than one runnable -deadline task (as it is below for RT tasks).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	cpumask_var_t		dlo_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	atomic_t		dlo_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	struct dl_bw		dl_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	struct cpudl		cpudl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) #ifdef HAVE_RT_PUSH_IPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	 * For IPI pull requests, loop across the rto_mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	struct irq_work		rto_push_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	raw_spinlock_t		rto_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	/* These are only updated and read within rto_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	int			rto_loop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	int			rto_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	/* These atomics are updated outside of a lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	atomic_t		rto_loop_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	atomic_t		rto_loop_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	 * The "RT overload" flag: it gets set if a CPU has more than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	 * one runnable RT task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	cpumask_var_t		rto_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	struct cpupri		cpupri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	unsigned long		max_cpu_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	 * NULL-terminated list of performance domains intersecting with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	 * CPUs of the rd. Protected by RCU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	struct perf_domain __rcu *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	ANDROID_VENDOR_DATA_ARRAY(1, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	ANDROID_KABI_RESERVE(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	ANDROID_KABI_RESERVE(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	ANDROID_KABI_RESERVE(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) extern void init_defrootdomain(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) extern int sched_init_domains(const struct cpumask *cpu_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) extern void rq_attach_root(struct rq *rq, struct root_domain *rd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) extern void sched_get_rd(struct root_domain *rd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) extern void sched_put_rd(struct root_domain *rd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) #ifdef HAVE_RT_PUSH_IPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) extern void rto_push_irq_work_func(struct irq_work *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) extern struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) #ifdef CONFIG_UCLAMP_TASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870)  * struct uclamp_bucket - Utilization clamp bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)  * @value: utilization clamp value for tasks on this clamp bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872)  * @tasks: number of RUNNABLE tasks on this clamp bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874)  * Keep track of how many tasks are RUNNABLE for a given utilization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875)  * clamp value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) struct uclamp_bucket {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	unsigned long value : bits_per(SCHED_CAPACITY_SCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	unsigned long tasks : BITS_PER_LONG - bits_per(SCHED_CAPACITY_SCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883)  * struct uclamp_rq - rq's utilization clamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884)  * @value: currently active clamp values for a rq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885)  * @bucket: utilization clamp buckets affecting a rq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887)  * Keep track of RUNNABLE tasks on a rq to aggregate their clamp values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888)  * A clamp value is affecting a rq when there is at least one task RUNNABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889)  * (or actually running) with that value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891)  * There are up to UCLAMP_CNT possible different clamp values, currently there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892)  * are only two: minimum utilization and maximum utilization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894)  * All utilization clamping values are MAX aggregated, since:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895)  * - for util_min: we want to run the CPU at least at the max of the minimum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896)  *   utilization required by its currently RUNNABLE tasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897)  * - for util_max: we want to allow the CPU to run up to the max of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898)  *   maximum utilization allowed by its currently RUNNABLE tasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900)  * Since on each system we expect only a limited number of different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901)  * utilization clamp values (UCLAMP_BUCKETS), use a simple array to track
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902)  * the metrics required to compute all the per-rq utilization clamp values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) struct uclamp_rq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	unsigned int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	struct uclamp_bucket bucket[UCLAMP_BUCKETS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) DECLARE_STATIC_KEY_FALSE(sched_uclamp_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) #endif /* CONFIG_UCLAMP_TASK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913)  * This is the main, per-CPU runqueue data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915)  * Locking rule: those places that want to lock multiple runqueues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916)  * (such as the load balancing or the thread migration code), lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917)  * acquire operations must be ordered by ascending &runqueue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) struct rq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	/* runqueue lock: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	raw_spinlock_t		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	 * nr_running and cpu_load should be in the same cacheline because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	 * remote CPUs use both these fields when doing load calculation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	unsigned int		nr_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) #ifdef CONFIG_NUMA_BALANCING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	unsigned int		nr_numa_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	unsigned int		nr_preferred_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	unsigned int		numa_migrate_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) #ifdef CONFIG_NO_HZ_COMMON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	unsigned long		last_blocked_load_update_tick;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	unsigned int		has_blocked_load;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	call_single_data_t	nohz_csd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	unsigned int		nohz_tick_stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	atomic_t		nohz_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) #endif /* CONFIG_NO_HZ_COMMON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	unsigned int		ttwu_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	u64			nr_switches;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) #ifdef CONFIG_UCLAMP_TASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	/* Utilization clamp values based on CPU's RUNNABLE tasks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	struct uclamp_rq	uclamp[UCLAMP_CNT] ____cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	unsigned int		uclamp_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) #define UCLAMP_FLAG_IDLE 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	struct cfs_rq		cfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	struct rt_rq		rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	struct dl_rq		dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	/* list of leaf cfs_rq on this CPU: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	struct list_head	leaf_cfs_rq_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	struct list_head	*tmp_alone_branch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) #endif /* CONFIG_FAIR_GROUP_SCHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	 * This is part of a global counter where only the total sum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	 * over all CPUs matters. A task can increase this counter on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	 * one CPU and if it got migrated afterwards it may decrease
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	 * it on another CPU. Always updated under the runqueue lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	unsigned long		nr_uninterruptible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	struct task_struct __rcu	*curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	struct task_struct	*idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	struct task_struct	*stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	unsigned long		next_balance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	struct mm_struct	*prev_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	unsigned int		clock_update_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	u64			clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	/* Ensure that all clocks are in the same cache line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	u64			clock_task ____cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	u64			clock_pelt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	unsigned long		lost_idle_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	atomic_t		nr_iowait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) #ifdef CONFIG_MEMBARRIER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	int membarrier_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	struct root_domain		*rd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	struct sched_domain __rcu	*sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	unsigned long		cpu_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	unsigned long		cpu_capacity_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	struct callback_head	*balance_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	unsigned char		nohz_idle_balance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	unsigned char		idle_balance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	unsigned long		misfit_task_load;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	/* For active balancing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	int			active_balance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	int			push_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	struct cpu_stop_work	active_balance_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	/* CPU of this runqueue: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	int			cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	int			online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	struct list_head cfs_tasks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	struct sched_avg	avg_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	struct sched_avg	avg_dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) #ifdef CONFIG_HAVE_SCHED_AVG_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	struct sched_avg	avg_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) #ifdef CONFIG_SCHED_THERMAL_PRESSURE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	struct sched_avg	avg_thermal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	u64			idle_stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	u64			avg_idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	/* This is used to determine avg_idle's max value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	u64			max_idle_balance_cost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) #endif /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) #ifdef CONFIG_IRQ_TIME_ACCOUNTING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	u64			prev_irq_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) #ifdef CONFIG_PARAVIRT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	u64			prev_steal_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	u64			prev_steal_time_rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	/* calc_load related fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	unsigned long		calc_load_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	long			calc_load_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) #ifdef CONFIG_SCHED_HRTICK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	call_single_data_t	hrtick_csd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	struct hrtimer		hrtick_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	ktime_t 		hrtick_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) #ifdef CONFIG_SCHEDSTATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	/* latency stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	struct sched_info	rq_sched_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	unsigned long long	rq_cpu_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	/* could above be rq->cfs_rq.exec_clock + rq->rt_rq.rt_runtime ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	/* sys_sched_yield() stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	unsigned int		yld_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	/* schedule() stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	unsigned int		sched_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	unsigned int		sched_goidle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	/* try_to_wake_up() stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	unsigned int		ttwu_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	unsigned int		ttwu_local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	struct cpu_stop_work	drain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	struct cpu_stop_done	drain_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) #ifdef CONFIG_CPU_IDLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	/* Must be inspected within a rcu lock section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	struct cpuidle_state	*idle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	ANDROID_VENDOR_DATA_ARRAY(1, 96);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	ANDROID_OEM_DATA_ARRAY(1, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	ANDROID_KABI_RESERVE(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	ANDROID_KABI_RESERVE(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	ANDROID_KABI_RESERVE(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) /* CPU runqueue to which this cfs_rq is attached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) static inline struct rq *rq_of(struct cfs_rq *cfs_rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	return cfs_rq->rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) static inline struct rq *rq_of(struct cfs_rq *cfs_rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	return container_of(cfs_rq, struct rq, cfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) static inline int cpu_of(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	return rq->cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) #ifdef CONFIG_SCHED_SMT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) extern void __update_idle_core(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static inline void update_idle_core(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	if (static_branch_unlikely(&sched_smt_present))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		__update_idle_core(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) static inline void update_idle_core(struct rq *rq) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) #define cpu_rq(cpu)		(&per_cpu(runqueues, (cpu)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) #define this_rq()		this_cpu_ptr(&runqueues)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) #define task_rq(p)		cpu_rq(task_cpu(p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) #define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) #define raw_rq()		raw_cpu_ptr(&runqueues)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) extern void update_rq_clock(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) static inline u64 __rq_clock_broken(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	return READ_ONCE(rq->clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)  * rq::clock_update_flags bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)  * %RQCF_REQ_SKIP - will request skipping of clock update on the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)  *  call to __schedule(). This is an optimisation to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)  *  neighbouring rq clock updates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)  * %RQCF_ACT_SKIP - is set from inside of __schedule() when skipping is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)  *  in effect and calls to update_rq_clock() are being ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)  * %RQCF_UPDATED - is a debug flag that indicates whether a call has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)  *  made to update_rq_clock() since the last time rq::lock was pinned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)  * If inside of __schedule(), clock_update_flags will have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)  * shifted left (a left shift is a cheap operation for the fast path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)  * to promote %RQCF_REQ_SKIP to %RQCF_ACT_SKIP), so you must use,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)  *	if (rq-clock_update_flags >= RQCF_UPDATED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)  * to check if %RQCF_UPADTED is set. It'll never be shifted more than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)  * one position though, because the next rq_unpin_lock() will shift it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)  * back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) #define RQCF_REQ_SKIP		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) #define RQCF_ACT_SKIP		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) #define RQCF_UPDATED		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) static inline void assert_clock_updated(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	 * The only reason for not seeing a clock update since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	 * last rq_pin_lock() is if we're currently skipping updates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	SCHED_WARN_ON(rq->clock_update_flags < RQCF_ACT_SKIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) static inline u64 rq_clock(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	lockdep_assert_held(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	assert_clock_updated(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	return rq->clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) static inline u64 rq_clock_task(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	lockdep_assert_held(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	assert_clock_updated(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	return rq->clock_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)  * By default the decay is the default pelt decay period.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)  * The decay shift can change the decay period in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)  * multiples of 32.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)  *  Decay shift		Decay period(ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)  *	0			32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)  *	1			64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)  *	2			128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)  *	3			256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)  *	4			512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) extern int sched_thermal_decay_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) static inline u64 rq_clock_thermal(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	return rq_clock_task(rq) >> sched_thermal_decay_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) static inline void rq_clock_skip_update(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	lockdep_assert_held(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	rq->clock_update_flags |= RQCF_REQ_SKIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)  * See rt task throttling, which is the only time a skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)  * request is cancelled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) static inline void rq_clock_cancel_skipupdate(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	lockdep_assert_held(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	rq->clock_update_flags &= ~RQCF_REQ_SKIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) struct rq_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	struct pin_cookie cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) #ifdef CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	 * A copy of (rq::clock_update_flags & RQCF_UPDATED) for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	 * current pin context is stashed here in case it needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	 * restored in rq_repin_lock().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	unsigned int clock_update_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)  * Lockdep annotation that avoids accidental unlocks; it's like a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)  * sticky/continuous lockdep_assert_held().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)  * This avoids code that has access to 'struct rq *rq' (basically everything in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)  * the scheduler) from accidentally unlocking the rq if they do not also have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)  * copy of the (on-stack) 'struct rq_flags rf'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)  * Also see Documentation/locking/lockdep-design.rst.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) static inline void rq_pin_lock(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	rf->cookie = lockdep_pin_lock(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) #ifdef CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	rq->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	rf->clock_update_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) static inline void rq_unpin_lock(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) #ifdef CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	if (rq->clock_update_flags > RQCF_ACT_SKIP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 		rf->clock_update_flags = RQCF_UPDATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	lockdep_unpin_lock(&rq->lock, rf->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) static inline void rq_repin_lock(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	lockdep_repin_lock(&rq->lock, rf->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) #ifdef CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	 * Restore the value we stashed in @rf for this pin context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	rq->clock_update_flags |= rf->clock_update_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) struct rq *__task_rq_lock(struct task_struct *p, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	__acquires(rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) struct rq *task_rq_lock(struct task_struct *p, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	__acquires(p->pi_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	__acquires(rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) static inline void __task_rq_unlock(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	__releases(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	rq_unpin_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	raw_spin_unlock(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) task_rq_unlock(struct rq *rq, struct task_struct *p, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	__releases(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	__releases(p->pi_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	rq_unpin_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	raw_spin_unlock(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	raw_spin_unlock_irqrestore(&p->pi_lock, rf->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) rq_lock_irqsave(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	__acquires(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	raw_spin_lock_irqsave(&rq->lock, rf->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	rq_pin_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) rq_lock_irq(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	__acquires(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	raw_spin_lock_irq(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	rq_pin_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) rq_lock(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	__acquires(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	raw_spin_lock(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	rq_pin_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) rq_relock(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	__acquires(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	raw_spin_lock(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	rq_repin_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) rq_unlock_irqrestore(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	__releases(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	rq_unpin_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	raw_spin_unlock_irqrestore(&rq->lock, rf->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) rq_unlock_irq(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	__releases(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	rq_unpin_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	raw_spin_unlock_irq(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) rq_unlock(struct rq *rq, struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	__releases(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	rq_unpin_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	raw_spin_unlock(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) static inline struct rq *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) this_rq_lock_irq(struct rq_flags *rf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	__acquires(rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	struct rq *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	rq = this_rq();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	rq_lock(rq, rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	return rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) #ifdef CONFIG_NUMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) enum numa_topology_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	NUMA_DIRECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	NUMA_GLUELESS_MESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	NUMA_BACKPLANE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) extern enum numa_topology_type sched_numa_topology_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) extern int sched_max_numa_distance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) extern bool find_numa_distance(int distance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) extern void sched_init_numa(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) extern void sched_domains_numa_masks_set(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) extern void sched_domains_numa_masks_clear(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) extern int sched_numa_find_closest(const struct cpumask *cpus, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) static inline void sched_init_numa(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) static inline void sched_domains_numa_masks_set(unsigned int cpu) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) static inline void sched_domains_numa_masks_clear(unsigned int cpu) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) static inline int sched_numa_find_closest(const struct cpumask *cpus, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	return nr_cpu_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) #ifdef CONFIG_NUMA_BALANCING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) /* The regions in numa_faults array from task_struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) enum numa_faults_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	NUMA_MEM = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	NUMA_CPU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	NUMA_MEMBUF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	NUMA_CPUBUF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) extern void sched_setnuma(struct task_struct *p, int node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) extern int migrate_task_to(struct task_struct *p, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) extern void init_numa_balancing(unsigned long clone_flags, struct task_struct *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) init_numa_balancing(unsigned long clone_flags, struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) #endif /* CONFIG_NUMA_BALANCING */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) extern int migrate_swap(struct task_struct *p, struct task_struct *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 			int cpu, int scpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) queue_balance_callback(struct rq *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 		       struct callback_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 		       void (*func)(struct rq *rq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	lockdep_assert_held(&rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	if (unlikely(head->next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	head->func = (void (*)(struct callback_head *))func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	head->next = rq->balance_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	rq->balance_callback = head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) #define rcu_dereference_check_sched_domain(p) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	rcu_dereference_check((p), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 			      lockdep_is_held(&sched_domains_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)  * The domain tree (rq->sd) is protected by RCU's quiescent state transition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444)  * See destroy_sched_domains: call_rcu for details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)  * The domain tree of any CPU may only be accessed from within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)  * preempt-disabled sections.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) #define for_each_domain(cpu, __sd) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	for (__sd = rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 			__sd; __sd = __sd->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)  * highest_flag_domain - Return highest sched_domain containing flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455)  * @cpu:	The CPU whose highest level of sched domain is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)  *		be returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)  * @flag:	The flag to check for the highest sched_domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)  *		for the given CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)  * Returns the highest sched_domain of a CPU which contains the given flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) static inline struct sched_domain *highest_flag_domain(int cpu, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	struct sched_domain *sd, *hsd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	for_each_domain(cpu, sd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		if (!(sd->flags & flag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		hsd = sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	return hsd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) static inline struct sched_domain *lowest_flag_domain(int cpu, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	struct sched_domain *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	for_each_domain(cpu, sd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		if (sd->flags & flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	return sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) DECLARE_PER_CPU(struct sched_domain __rcu *, sd_llc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) DECLARE_PER_CPU(int, sd_llc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) DECLARE_PER_CPU(int, sd_llc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) DECLARE_PER_CPU(struct sched_domain_shared __rcu *, sd_llc_shared);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) DECLARE_PER_CPU(struct sched_domain __rcu *, sd_numa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_packing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) extern struct static_key_false sched_asym_cpucapacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) struct sched_group_capacity {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	atomic_t		ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	 * CPU capacity of this group, SCHED_CAPACITY_SCALE being max capacity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	 * for a single CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	unsigned long		capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	unsigned long		min_capacity;		/* Min per-CPU capacity in group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	unsigned long		max_capacity;		/* Max per-CPU capacity in group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	unsigned long		next_update;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	int			imbalance;		/* XXX unrelated to capacity but shared group state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) #ifdef CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	int			id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	unsigned long		cpumask[];		/* Balance mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) struct sched_group {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	struct sched_group	*next;			/* Must be a circular list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	atomic_t		ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	unsigned int		group_weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	struct sched_group_capacity *sgc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	int			asym_prefer_cpu;	/* CPU of highest priority in group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	 * The CPUs this group covers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	 * NOTE: this field is variable length. (Allocated dynamically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	 * by attaching extra space to the end of the structure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	 * depending on how many CPUs the kernel has booted up with)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	unsigned long		cpumask[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) static inline struct cpumask *sched_group_span(struct sched_group *sg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	return to_cpumask(sg->cpumask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)  * See build_balance_mask().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) static inline struct cpumask *group_balance_mask(struct sched_group *sg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	return to_cpumask(sg->sgc->cpumask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)  * group_first_cpu - Returns the first CPU in the cpumask of a sched_group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)  * @group: The group whose first CPU is to be returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) static inline unsigned int group_first_cpu(struct sched_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	return cpumask_first(sched_group_span(group));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) extern int group_balance_cpu(struct sched_group *sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) void register_sched_domain_sysctl(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) void dirty_sched_domain_sysctl(int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) void unregister_sched_domain_sysctl(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) static inline void register_sched_domain_sysctl(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) static inline void dirty_sched_domain_sysctl(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) static inline void unregister_sched_domain_sysctl(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) extern void flush_smp_call_function_from_idle(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) #else /* !CONFIG_SMP: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) static inline void flush_smp_call_function_from_idle(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) #include "stats.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) #include "autogroup.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) #ifdef CONFIG_CGROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)  * Return the group to which this tasks belongs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587)  * We cannot use task_css() and friends because the cgroup subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)  * changes that value before the cgroup_subsys::attach() method is called,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)  * therefore we cannot pin it and might observe the wrong value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591)  * The same is true for autogroup's p->signal->autogroup->tg, the autogroup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)  * core changes this before calling sched_move_task().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)  * Instead we use a 'copy' which is updated from sched_move_task() while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595)  * holding both task_struct::pi_lock and rq::lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) static inline struct task_group *task_group(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	return p->sched_task_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) #if defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	struct task_group *tg = task_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	set_task_rq_fair(&p->se, p->se.cfs_rq, tg->cfs_rq[cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	p->se.cfs_rq = tg->cfs_rq[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	p->se.parent = tg->se[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) #ifdef CONFIG_RT_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	p->rt.rt_rq  = tg->rt_rq[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	p->rt.parent = tg->rt_se[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) #else /* CONFIG_CGROUP_SCHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) static inline struct task_group *task_group(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) #endif /* CONFIG_CGROUP_SCHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	set_task_rq(p, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	 * After ->cpu is set up to a new value, task_rq_lock(p, ...) can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	 * successfully executed on another CPU. We must ensure that updates of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	 * per-task data have been completed by this moment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) #ifdef CONFIG_THREAD_INFO_IN_TASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	WRITE_ONCE(p->cpu, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	WRITE_ONCE(task_thread_info(p)->cpu, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	p->wake_cpu = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)  * Tunables that become constants when CONFIG_SCHED_DEBUG is off:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) #ifdef CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) # include <linux/static_key.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) # define const_debug __read_mostly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) # define const_debug const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) #define SCHED_FEAT(name, enabled)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	__SCHED_FEAT_##name ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) #include "features.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	__SCHED_FEAT_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) #undef SCHED_FEAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) #ifdef CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)  * To support run-time toggling of sched features, all the translation units
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)  * (but core.c) reference the sysctl_sched_features defined in core.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) extern const_debug unsigned int sysctl_sched_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) #ifdef CONFIG_JUMP_LABEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) #define SCHED_FEAT(name, enabled)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) static __always_inline bool static_branch_##name(struct static_key *key) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	return static_key_##enabled(key);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) #include "features.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) #undef SCHED_FEAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) extern const char * const sched_feat_names[__SCHED_FEAT_NR];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) #define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) #else /* !CONFIG_JUMP_LABEL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) #define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) #endif /* CONFIG_JUMP_LABEL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) #else /* !SCHED_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)  * Each translation unit has its own copy of sysctl_sched_features to allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)  * constants propagation at compile time and compiler optimization based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)  * features default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) #define SCHED_FEAT(name, enabled)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	(1UL << __SCHED_FEAT_##name) * enabled |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) static const_debug __maybe_unused unsigned int sysctl_sched_features =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) #include "features.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) #undef SCHED_FEAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) #define sched_feat(x) !!(sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) #endif /* SCHED_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) extern struct static_key_false sched_numa_balancing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) extern struct static_key_false sched_schedstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) static inline u64 global_rt_period(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	return (u64)sysctl_sched_rt_period * NSEC_PER_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) static inline u64 global_rt_runtime(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	if (sysctl_sched_rt_runtime < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 		return RUNTIME_INF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) static inline int task_current(struct rq *rq, struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	return rq->curr == p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) static inline int task_running(struct rq *rq, struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	return p->on_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	return task_current(rq, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) static inline int task_on_rq_queued(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	return p->on_rq == TASK_ON_RQ_QUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) static inline int task_on_rq_migrating(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	return READ_ONCE(p->on_rq) == TASK_ON_RQ_MIGRATING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)  * wake flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) #define WF_SYNC			0x01		/* Waker goes to sleep after wakeup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) #define WF_FORK			0x02		/* Child wakeup after fork */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) #define WF_MIGRATED		0x04		/* Internal use, task got migrated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) #define WF_ON_CPU		0x08		/* Wakee is on_cpu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) #define WF_ANDROID_VENDOR	0x1000		/* Vendor specific for Android */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767)  * To aid in avoiding the subversion of "niceness" due to uneven distribution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)  * of tasks with abnormal "nice" values across CPUs the contribution that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)  * each task makes to its run queue's load is weighted according to its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)  * scheduling class and "nice" value. For SCHED_NORMAL tasks this is just a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)  * scaled version of the new time slice allocation that they receive on time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772)  * slice expiry etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) #define WEIGHT_IDLEPRIO		3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) #define WMULT_IDLEPRIO		1431655765
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) extern const int		sched_prio_to_weight[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) extern const u32		sched_prio_to_wmult[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)  * {de,en}queue flags:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)  * DEQUEUE_SLEEP  - task is no longer runnable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)  * ENQUEUE_WAKEUP - task just became runnable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)  * SAVE/RESTORE - an otherwise spurious dequeue/enqueue, done to ensure tasks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)  *                are in a known state which allows modification. Such pairs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)  *                should preserve as much state as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)  * MOVE - paired with SAVE/RESTORE, explicitly does not preserve the location
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)  *        in the runqueue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)  * ENQUEUE_HEAD      - place at front of runqueue (tail if not specified)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795)  * ENQUEUE_REPLENISH - CBS (replenish runtime and postpone deadline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)  * ENQUEUE_MIGRATED  - the task was migrated during wakeup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) #define DEQUEUE_SLEEP		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) #define DEQUEUE_SAVE		0x02 /* Matches ENQUEUE_RESTORE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) #define DEQUEUE_MOVE		0x04 /* Matches ENQUEUE_MOVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) #define DEQUEUE_NOCLOCK		0x08 /* Matches ENQUEUE_NOCLOCK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) #define ENQUEUE_WAKEUP		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) #define ENQUEUE_RESTORE		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) #define ENQUEUE_MOVE		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) #define ENQUEUE_NOCLOCK		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) #define ENQUEUE_HEAD		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) #define ENQUEUE_REPLENISH	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) #define ENQUEUE_MIGRATED	0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) #define ENQUEUE_MIGRATED	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) #define ENQUEUE_WAKEUP_SYNC	0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) #define RETRY_TASK		((void *)-1UL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) struct sched_class {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) #ifdef CONFIG_UCLAMP_TASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	int uclamp_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	void (*yield_task)   (struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	bool (*yield_to_task)(struct rq *rq, struct task_struct *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	void (*check_preempt_curr)(struct rq *rq, struct task_struct *p, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	struct task_struct *(*pick_next_task)(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	void (*put_prev_task)(struct rq *rq, struct task_struct *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	void (*set_next_task)(struct rq *rq, struct task_struct *p, bool first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	int (*balance)(struct rq *rq, struct task_struct *prev, struct rq_flags *rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	int  (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 	void (*migrate_task_rq)(struct task_struct *p, int new_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	void (*task_woken)(struct rq *this_rq, struct task_struct *task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	void (*set_cpus_allowed)(struct task_struct *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 				 const struct cpumask *newmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	void (*rq_online)(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	void (*rq_offline)(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	void (*task_tick)(struct rq *rq, struct task_struct *p, int queued);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	void (*task_fork)(struct task_struct *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	void (*task_dead)(struct task_struct *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	 * The switched_from() call is allowed to drop rq->lock, therefore we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	 * cannot assume the switched_from/switched_to pair is serliazed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 	 * rq->lock. They are however serialized by p->pi_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	void (*switched_from)(struct rq *this_rq, struct task_struct *task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 	void (*switched_to)  (struct rq *this_rq, struct task_struct *task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 			      int oldprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	unsigned int (*get_rr_interval)(struct rq *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 					struct task_struct *task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	void (*update_curr)(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) #define TASK_SET_GROUP		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) #define TASK_MOVE_GROUP		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) #ifdef CONFIG_FAIR_GROUP_SCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	void (*task_change_group)(struct task_struct *p, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) } __aligned(STRUCT_ALIGNMENT); /* STRUCT_ALIGN(), vmlinux.lds.h */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	WARN_ON_ONCE(rq->curr != prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	prev->sched_class->put_prev_task(rq, prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) static inline void set_next_task(struct rq *rq, struct task_struct *next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	WARN_ON_ONCE(rq->curr != next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	next->sched_class->set_next_task(rq, next, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) /* Defined in include/asm-generic/vmlinux.lds.h */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) extern struct sched_class __begin_sched_classes[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) extern struct sched_class __end_sched_classes[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) #define sched_class_highest (__end_sched_classes - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) #define sched_class_lowest  (__begin_sched_classes - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) #define for_class_range(class, _from, _to) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	for (class = (_from); class != (_to); class--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) #define for_each_class(class) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	for_class_range(class, sched_class_highest, sched_class_lowest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) extern const struct sched_class stop_sched_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) extern const struct sched_class dl_sched_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) extern const struct sched_class rt_sched_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) extern const struct sched_class fair_sched_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) extern const struct sched_class idle_sched_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) static inline bool sched_stop_runnable(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 	return rq->stop && task_on_rq_queued(rq->stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) static inline bool sched_dl_runnable(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	return rq->dl.dl_nr_running > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) static inline bool sched_rt_runnable(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 	return rq->rt.rt_queued > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) static inline bool sched_fair_runnable(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	return rq->cfs.nr_running > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) extern struct task_struct *pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) extern struct task_struct *pick_next_task_idle(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) extern void update_group_capacity(struct sched_domain *sd, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) extern void trigger_load_balance(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) extern void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) extern unsigned long __read_mostly max_load_balance_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) #ifdef CONFIG_CPU_IDLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) static inline void idle_set_state(struct rq *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 				  struct cpuidle_state *idle_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	rq->idle_state = idle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) static inline struct cpuidle_state *idle_get_state(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 	SCHED_WARN_ON(!rcu_read_lock_held());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	return rq->idle_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) static inline void idle_set_state(struct rq *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 				  struct cpuidle_state *idle_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) static inline struct cpuidle_state *idle_get_state(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) extern void schedule_idle(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) extern void sysrq_sched_debug_show(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) extern void sched_init_granularity(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) extern void update_max_interval(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) extern void init_sched_dl_class(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) extern void init_sched_rt_class(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) extern void init_sched_fair_class(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) extern void reweight_task(struct task_struct *p, int prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) extern void resched_curr(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) extern void resched_cpu(int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) extern struct rt_bandwidth def_rt_bandwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) extern struct dl_bandwidth def_dl_bandwidth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) extern void init_dl_bandwidth(struct dl_bandwidth *dl_b, u64 period, u64 runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) extern void init_dl_task_timer(struct sched_dl_entity *dl_se);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) extern void init_dl_inactive_task_timer(struct sched_dl_entity *dl_se);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) #define BW_SHIFT		20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) #define BW_UNIT			(1 << BW_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) #define RATIO_SHIFT		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) #define MAX_BW_BITS		(64 - BW_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) #define MAX_BW			((1ULL << MAX_BW_BITS) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) unsigned long to_ratio(u64 period, u64 runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) extern void init_entity_runnable_average(struct sched_entity *se);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) extern void post_init_entity_util_avg(struct task_struct *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) #ifdef CONFIG_NO_HZ_FULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) extern bool sched_can_stop_tick(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) extern int __init sched_tick_offload_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009)  * Tick may be needed by tasks in the runqueue depending on their policy and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010)  * requirements. If tick is needed, lets send the target an IPI to kick it out of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)  * nohz mode if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) static inline void sched_update_tick_dependency(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	int cpu = cpu_of(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	if (!tick_nohz_full_cpu(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 	if (sched_can_stop_tick(rq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 		tick_nohz_dep_clear_cpu(cpu, TICK_DEP_BIT_SCHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 		tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) static inline int sched_tick_offload_init(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) static inline void sched_update_tick_dependency(struct rq *rq) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) static inline void add_nr_running(struct rq *rq, unsigned count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	unsigned prev_nr = rq->nr_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	rq->nr_running = prev_nr + count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	if (trace_sched_update_nr_running_tp_enabled()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 		call_trace_sched_update_nr_running(rq, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	if (prev_nr < 2 && rq->nr_running >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 		if (!READ_ONCE(rq->rd->overload))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 			WRITE_ONCE(rq->rd->overload, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	sched_update_tick_dependency(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) static inline void sub_nr_running(struct rq *rq, unsigned count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 	rq->nr_running -= count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 	if (trace_sched_update_nr_running_tp_enabled()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 		call_trace_sched_update_nr_running(rq, -count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 	/* Check if we still need preemption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 	sched_update_tick_dependency(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) extern void activate_task(struct rq *rq, struct task_struct *p, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) extern void deactivate_task(struct rq *rq, struct task_struct *p, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) extern void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) extern const_debug unsigned int sysctl_sched_nr_migrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) extern const_debug unsigned int sysctl_sched_migration_cost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) #ifdef CONFIG_SCHED_HRTICK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071)  * Use hrtick when:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)  *  - enabled by features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073)  *  - hrtimer is actually high res
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) static inline int hrtick_enabled(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	if (!sched_feat(HRTICK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	if (!cpu_active(cpu_of(rq)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 	return hrtimer_is_hres_active(&rq->hrtick_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) void hrtick_start(struct rq *rq, u64 delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) static inline int hrtick_enabled(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) #endif /* CONFIG_SCHED_HRTICK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) #ifndef arch_scale_freq_tick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) static __always_inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) void arch_scale_freq_tick(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) #ifndef arch_scale_freq_capacity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)  * arch_scale_freq_capacity - get the frequency scale factor of a given CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105)  * @cpu: the CPU in question.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107)  * Return: the frequency scale factor normalized against SCHED_CAPACITY_SCALE, i.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109)  *     f_curr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110)  *     ------ * SCHED_CAPACITY_SCALE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111)  *     f_max
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) static __always_inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) unsigned long arch_scale_freq_capacity(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 	return SCHED_CAPACITY_SCALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) #ifdef CONFIG_PREEMPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) static inline void double_rq_lock(struct rq *rq1, struct rq *rq2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126)  * fair double_lock_balance: Safely acquires both rq->locks in a fair
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)  * way at the expense of forcing extra atomic operations in all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128)  * invocations.  This assures that the double_lock is acquired using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129)  * same underlying policy as the spinlock_t on this architecture, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)  * reduces latency compared to the unfair variant below.  However, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131)  * also adds more overhead and therefore may reduce throughput.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 	__releases(this_rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 	__acquires(busiest->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	__acquires(this_rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	raw_spin_unlock(&this_rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	double_rq_lock(this_rq, busiest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146)  * Unfair double_lock_balance: Optimizes throughput at the expense of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147)  * latency by eliminating extra atomic operations when the locks are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148)  * already in proper order on entry.  This favors lower CPU-ids and will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)  * grant the double lock to lower CPUs over higher ids under contention,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)  * regardless of entry order into the function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	__releases(this_rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	__acquires(busiest->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	__acquires(this_rq->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 	if (unlikely(!raw_spin_trylock(&busiest->lock))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 		if (busiest < this_rq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 			raw_spin_unlock(&this_rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 			raw_spin_lock(&busiest->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 			raw_spin_lock_nested(&this_rq->lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 					      SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 			ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 			raw_spin_lock_nested(&busiest->lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 					      SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) #endif /* CONFIG_PREEMPTION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176)  * double_lock_balance - lock the busiest runqueue, this_rq is locked already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) static inline int double_lock_balance(struct rq *this_rq, struct rq *busiest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	if (unlikely(!irqs_disabled())) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		/* printk() doesn't work well under rq->lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		raw_spin_unlock(&this_rq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 		BUG_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 	return _double_lock_balance(this_rq, busiest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) static inline void double_unlock_balance(struct rq *this_rq, struct rq *busiest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 	__releases(busiest->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 	raw_spin_unlock(&busiest->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 	lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) static inline void double_lock(spinlock_t *l1, spinlock_t *l2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 	if (l1 > l2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 		swap(l1, l2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	spin_lock(l1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 	spin_lock_nested(l2, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) static inline void double_lock_irq(spinlock_t *l1, spinlock_t *l2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	if (l1 > l2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 		swap(l1, l2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 	spin_lock_irq(l1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	spin_lock_nested(l2, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) static inline void double_raw_lock(raw_spinlock_t *l1, raw_spinlock_t *l2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 	if (l1 > l2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 		swap(l1, l2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 	raw_spin_lock(l1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 	raw_spin_lock_nested(l2, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224)  * double_rq_lock - safely lock two runqueues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226)  * Note this does not disable interrupts like task_rq_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227)  * you need to do so manually before calling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) static inline void double_rq_lock(struct rq *rq1, struct rq *rq2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 	__acquires(rq1->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 	__acquires(rq2->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	BUG_ON(!irqs_disabled());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 	if (rq1 == rq2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 		raw_spin_lock(&rq1->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 		__acquire(rq2->lock);	/* Fake it out ;) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 		if (rq1 < rq2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 			raw_spin_lock(&rq1->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 			raw_spin_lock_nested(&rq2->lock, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 			raw_spin_lock(&rq2->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 			raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)  * double_rq_unlock - safely unlock two runqueues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251)  * Note this does not restore interrupts like task_rq_unlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)  * you need to do so manually after calling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	__releases(rq1->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 	__releases(rq2->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 	raw_spin_unlock(&rq1->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	if (rq1 != rq2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 		raw_spin_unlock(&rq2->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 		__release(rq2->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) extern void set_rq_online (struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) extern void set_rq_offline(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) extern bool sched_smp_initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) #else /* CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272)  * double_rq_lock - safely lock two runqueues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274)  * Note this does not disable interrupts like task_rq_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)  * you need to do so manually before calling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) static inline void double_rq_lock(struct rq *rq1, struct rq *rq2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 	__acquires(rq1->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 	__acquires(rq2->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 	BUG_ON(!irqs_disabled());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 	BUG_ON(rq1 != rq2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 	raw_spin_lock(&rq1->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	__acquire(rq2->lock);	/* Fake it out ;) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)  * double_rq_unlock - safely unlock two runqueues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)  * Note this does not restore interrupts like task_rq_unlock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291)  * you need to do so manually after calling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) static inline void double_rq_unlock(struct rq *rq1, struct rq *rq2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 	__releases(rq1->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 	__releases(rq2->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	BUG_ON(rq1 != rq2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 	raw_spin_unlock(&rq1->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	__release(rq2->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) extern struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) extern struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) #ifdef	CONFIG_SCHED_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) extern bool sched_debug_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) extern void print_cfs_stats(struct seq_file *m, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) extern void print_rt_stats(struct seq_file *m, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) extern void print_dl_stats(struct seq_file *m, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) extern void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) extern void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) extern void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) #ifdef CONFIG_NUMA_BALANCING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) extern void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) show_numa_stats(struct task_struct *p, struct seq_file *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) extern void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) print_numa_stats(struct seq_file *m, int node, unsigned long tsf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	unsigned long tpf, unsigned long gsf, unsigned long gpf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) #endif /* CONFIG_NUMA_BALANCING */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) #endif /* CONFIG_SCHED_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) extern void init_cfs_rq(struct cfs_rq *cfs_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) extern void init_rt_rq(struct rt_rq *rt_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) extern void init_dl_rq(struct dl_rq *dl_rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) extern void cfs_bandwidth_usage_inc(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) extern void cfs_bandwidth_usage_dec(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) #ifdef CONFIG_NO_HZ_COMMON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) #define NOHZ_BALANCE_KICK_BIT	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) #define NOHZ_STATS_KICK_BIT	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) #define NOHZ_BALANCE_KICK	BIT(NOHZ_BALANCE_KICK_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) #define NOHZ_STATS_KICK		BIT(NOHZ_STATS_KICK_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) #define NOHZ_KICK_MASK	(NOHZ_BALANCE_KICK | NOHZ_STATS_KICK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) #define nohz_flags(cpu)	(&cpu_rq(cpu)->nohz_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) extern void nohz_balance_exit_idle(struct rq *rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) static inline void nohz_balance_exit_idle(struct rq *rq) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) void __dl_update(struct dl_bw *dl_b, s64 bw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 	struct root_domain *rd = container_of(dl_b, struct root_domain, dl_bw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 			 "sched RCU must be held");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	for_each_cpu_and(i, rd->span, cpu_active_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 		struct rq *rq = cpu_rq(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 		rq->dl.extra_bw += bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) void __dl_update(struct dl_bw *dl_b, s64 bw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	struct dl_rq *dl = container_of(dl_b, struct dl_rq, dl_bw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 	dl->extra_bw += bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) #ifdef CONFIG_IRQ_TIME_ACCOUNTING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) struct irqtime {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 	u64			total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 	u64			tick_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 	u64			irq_start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	struct u64_stats_sync	sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) DECLARE_PER_CPU(struct irqtime, cpu_irqtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386)  * Returns the irqtime minus the softirq time computed by ksoftirqd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387)  * Otherwise ksoftirqd's sum_exec_runtime is substracted its own runtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388)  * and never move forward.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) static inline u64 irq_time_read(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 	struct irqtime *irqtime = &per_cpu(cpu_irqtime, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 	unsigned int seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 	u64 total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 		seq = __u64_stats_fetch_begin(&irqtime->sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 		total = irqtime->total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 	} while (__u64_stats_fetch_retry(&irqtime->sync, seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	return total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) #endif /* CONFIG_IRQ_TIME_ACCOUNTING */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) #ifdef CONFIG_CPU_FREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) DECLARE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409)  * cpufreq_update_util - Take a note about CPU utilization changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410)  * @rq: Runqueue to carry out the update for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411)  * @flags: Update reason flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413)  * This function is called by the scheduler on the CPU whose utilization is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414)  * being updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416)  * It can only be called from RCU-sched read-side critical sections.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)  * The way cpufreq is currently arranged requires it to evaluate the CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)  * performance state (frequency/voltage) on a regular basis to prevent it from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)  * being stuck in a completely inadequate performance level for too long.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)  * That is not guaranteed to happen if the updates are only triggered from CFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422)  * and DL, though, because they may not be coming in if only RT tasks are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423)  * active all the time (or there are RT tasks only).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425)  * As a workaround for that issue, this function is called periodically by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426)  * RT sched class to trigger extra cpufreq updates to prevent it from stalling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427)  * but that really is a band-aid.  Going forward it should be replaced with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428)  * solutions targeted more specifically at RT tasks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) static inline void cpufreq_update_util(struct rq *rq, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	struct update_util_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	data = rcu_dereference_sched(*per_cpu_ptr(&cpufreq_update_util_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 						  cpu_of(rq)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 	if (data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 		data->func(data, rq_clock(rq), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) #endif /* CONFIG_CPU_FREQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) #ifdef CONFIG_UCLAMP_TASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) unsigned long uclamp_eff_value(struct task_struct *p, enum uclamp_id clamp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447)  * uclamp_rq_util_with - clamp @util with @rq and @p effective uclamp values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448)  * @rq:		The rq to clamp against. Must not be NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449)  * @util:	The util value to clamp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450)  * @p:		The task to clamp against. Can be NULL if you want to clamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451)  *		against @rq only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453)  * Clamps the passed @util to the max(@rq, @p) effective uclamp values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455)  * If sched_uclamp_used static key is disabled, then just return the util
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456)  * without any clamping since uclamp aggregation at the rq level in the fast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457)  * path is disabled, rendering this operation a NOP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459)  * Use uclamp_eff_value() if you don't care about uclamp values at rq level. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460)  * will return the correct effective uclamp value of the task even if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461)  * static key is disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) static __always_inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) unsigned long uclamp_rq_util_with(struct rq *rq, unsigned long util,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 				  struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 	unsigned long min_util = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 	unsigned long max_util = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 	if (!static_branch_likely(&sched_uclamp_used))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 		return util;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 	if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 		min_util = uclamp_eff_value(p, UCLAMP_MIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 		max_util = uclamp_eff_value(p, UCLAMP_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 		 * Ignore last runnable task's max clamp, as this task will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 		 * reset it. Similarly, no need to read the rq's min clamp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 		if (rq->uclamp_flags & UCLAMP_FLAG_IDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 	min_util = max_t(unsigned long, min_util, READ_ONCE(rq->uclamp[UCLAMP_MIN].value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 	max_util = max_t(unsigned long, max_util, READ_ONCE(rq->uclamp[UCLAMP_MAX].value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 	 * Since CPU's {min,max}_util clamps are MAX aggregated considering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 	 * RUNNABLE tasks with _different_ clamps, we can end up with an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 	 * inversion. Fix it now when the clamps are applied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 	if (unlikely(min_util >= max_util))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 		return min_util;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 	return clamp(util, min_util, max_util);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) static inline bool uclamp_boosted(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 	return uclamp_eff_value(p, UCLAMP_MIN) > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505)  * When uclamp is compiled in, the aggregation at rq level is 'turned off'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506)  * by default in the fast path and only gets turned on once userspace performs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507)  * an operation that requires it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509)  * Returns true if userspace opted-in to use uclamp and aggregation at rq level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510)  * hence is active.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) static inline bool uclamp_is_used(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 	return static_branch_likely(&sched_uclamp_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) #else /* CONFIG_UCLAMP_TASK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) unsigned long uclamp_rq_util_with(struct rq *rq, unsigned long util,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 				  struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 	return util;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) static inline bool uclamp_boosted(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) static inline bool uclamp_is_used(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) #endif /* CONFIG_UCLAMP_TASK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) #ifdef CONFIG_UCLAMP_TASK_GROUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) static inline bool uclamp_latency_sensitive(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 	struct cgroup_subsys_state *css = task_css(p, cpu_cgrp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 	struct task_group *tg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 	if (!css)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 	tg = container_of(css, struct task_group, css);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 	return tg->latency_sensitive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) static inline bool uclamp_latency_sensitive(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) #endif /* CONFIG_UCLAMP_TASK_GROUP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) #ifdef arch_scale_freq_capacity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) # ifndef arch_scale_freq_invariant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) #  define arch_scale_freq_invariant()	true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) # define arch_scale_freq_invariant()	false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) static inline unsigned long capacity_orig_of(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 	return cpu_rq(cpu)->cpu_capacity_orig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570)  * enum schedutil_type - CPU utilization type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571)  * @FREQUENCY_UTIL:	Utilization used to select frequency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)  * @ENERGY_UTIL:	Utilization used during energy calculation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)  * The utilization signals of all scheduling classes (CFS/RT/DL) and IRQ time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575)  * need to be aggregated differently depending on the usage made of them. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576)  * enum is used within schedutil_freq_util() to differentiate the types of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577)  * utilization expected by the callers, and adjust the aggregation accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) enum schedutil_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 	FREQUENCY_UTIL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 	ENERGY_UTIL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) #ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 				 unsigned long max, enum schedutil_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 				 struct task_struct *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) static inline unsigned long cpu_bw_dl(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 	return (rq->dl.running_bw * SCHED_CAPACITY_SCALE) >> BW_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) static inline unsigned long cpu_util_dl(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	return READ_ONCE(rq->avg_dl.util_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) static inline unsigned long cpu_util_cfs(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 	unsigned long util = READ_ONCE(rq->cfs.avg.util_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 	if (sched_feat(UTIL_EST)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 		util = max_t(unsigned long, util,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 			     READ_ONCE(rq->cfs.avg.util_est.enqueued));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 	return util;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) static inline unsigned long cpu_util_rt(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 	return READ_ONCE(rq->avg_rt.util_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) #else /* CONFIG_CPU_FREQ_GOV_SCHEDUTIL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) static inline unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 				 unsigned long max, enum schedutil_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 				 struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) #endif /* CONFIG_CPU_FREQ_GOV_SCHEDUTIL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) #ifdef CONFIG_HAVE_SCHED_AVG_IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) static inline unsigned long cpu_util_irq(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	return rq->avg_irq.util_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) unsigned long scale_irq_capacity(unsigned long util, unsigned long irq, unsigned long max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 	util *= (max - irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 	util /= max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 	return util;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) static inline unsigned long cpu_util_irq(struct rq *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) unsigned long scale_irq_capacity(unsigned long util, unsigned long irq, unsigned long max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 	return util;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) #define perf_domain_span(pd) (to_cpumask(((pd)->em_pd->cpus)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) DECLARE_STATIC_KEY_FALSE(sched_energy_present);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) static inline bool sched_energy_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 	return static_branch_unlikely(&sched_energy_present);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) #else /* ! (CONFIG_ENERGY_MODEL && CONFIG_CPU_FREQ_GOV_SCHEDUTIL) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) #define perf_domain_span(pd) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) static inline bool sched_energy_enabled(void) { return false; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) #endif /* CONFIG_ENERGY_MODEL && CONFIG_CPU_FREQ_GOV_SCHEDUTIL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) #ifdef CONFIG_MEMBARRIER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)  * The scheduler provides memory barriers required by membarrier between:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674)  * - prior user-space memory accesses and store to rq->membarrier_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675)  * - store to rq->membarrier_state and following user-space memory accesses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676)  * In the same way it provides those guarantees around store to rq->curr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) static inline void membarrier_switch_mm(struct rq *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 					struct mm_struct *prev_mm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 					struct mm_struct *next_mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 	int membarrier_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 	if (prev_mm == next_mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 	membarrier_state = atomic_read(&next_mm->membarrier_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 	if (READ_ONCE(rq->membarrier_state) == membarrier_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 	WRITE_ONCE(rq->membarrier_state, membarrier_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) static inline void membarrier_switch_mm(struct rq *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 					struct mm_struct *prev_mm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 					struct mm_struct *next_mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) static inline bool is_per_cpu_kthread(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 	if (!(p->flags & PF_KTHREAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 	if (p->nr_cpus_allowed != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) void swake_up_all_locked(struct swait_queue_head *q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718)  * task_may_not_preempt - check whether a task may not be preemptible soon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) #ifdef CONFIG_RT_SOFTINT_OPTIMIZATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) extern bool task_may_not_preempt(struct task_struct *task, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) static inline bool task_may_not_preempt(struct task_struct *task, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) #endif /* CONFIG_RT_SOFTINT_OPTIMIZATION */