xref: /OK3568_Linux_fs/kernel/include/linux/sched.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _LINUX_SCHED_H
3*4882a593Smuzhiyun #define _LINUX_SCHED_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun /*
6*4882a593Smuzhiyun  * Define 'struct task_struct' and provide the main scheduler
7*4882a593Smuzhiyun  * APIs (schedule(), wakeup variants, etc.)
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <uapi/linux/sched.h>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <asm/current.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <linux/pid.h>
15*4882a593Smuzhiyun #include <linux/sem.h>
16*4882a593Smuzhiyun #include <linux/shm.h>
17*4882a593Smuzhiyun #include <linux/kcov.h>
18*4882a593Smuzhiyun #include <linux/mutex.h>
19*4882a593Smuzhiyun #include <linux/plist.h>
20*4882a593Smuzhiyun #include <linux/hrtimer.h>
21*4882a593Smuzhiyun #include <linux/irqflags.h>
22*4882a593Smuzhiyun #include <linux/seccomp.h>
23*4882a593Smuzhiyun #include <linux/nodemask.h>
24*4882a593Smuzhiyun #include <linux/rcupdate.h>
25*4882a593Smuzhiyun #include <linux/refcount.h>
26*4882a593Smuzhiyun #include <linux/resource.h>
27*4882a593Smuzhiyun #include <linux/latencytop.h>
28*4882a593Smuzhiyun #include <linux/sched/prio.h>
29*4882a593Smuzhiyun #include <linux/sched/types.h>
30*4882a593Smuzhiyun #include <linux/signal_types.h>
31*4882a593Smuzhiyun #include <linux/mm_types_task.h>
32*4882a593Smuzhiyun #include <linux/task_io_accounting.h>
33*4882a593Smuzhiyun #include <linux/posix-timers.h>
34*4882a593Smuzhiyun #include <linux/rseq.h>
35*4882a593Smuzhiyun #include <linux/seqlock.h>
36*4882a593Smuzhiyun #include <linux/kcsan.h>
37*4882a593Smuzhiyun #include <linux/android_vendor.h>
38*4882a593Smuzhiyun #include <linux/android_kabi.h>
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /* task_struct member predeclarations (sorted alphabetically): */
41*4882a593Smuzhiyun struct audit_context;
42*4882a593Smuzhiyun struct backing_dev_info;
43*4882a593Smuzhiyun struct bio_list;
44*4882a593Smuzhiyun struct blk_plug;
45*4882a593Smuzhiyun struct capture_control;
46*4882a593Smuzhiyun struct cfs_rq;
47*4882a593Smuzhiyun struct fs_struct;
48*4882a593Smuzhiyun struct futex_pi_state;
49*4882a593Smuzhiyun struct io_context;
50*4882a593Smuzhiyun struct mempolicy;
51*4882a593Smuzhiyun struct nameidata;
52*4882a593Smuzhiyun struct nsproxy;
53*4882a593Smuzhiyun struct perf_event_context;
54*4882a593Smuzhiyun struct pid_namespace;
55*4882a593Smuzhiyun struct pipe_inode_info;
56*4882a593Smuzhiyun struct rcu_node;
57*4882a593Smuzhiyun struct reclaim_state;
58*4882a593Smuzhiyun struct robust_list_head;
59*4882a593Smuzhiyun struct root_domain;
60*4882a593Smuzhiyun struct rq;
61*4882a593Smuzhiyun struct sched_attr;
62*4882a593Smuzhiyun struct sched_param;
63*4882a593Smuzhiyun struct seq_file;
64*4882a593Smuzhiyun struct sighand_struct;
65*4882a593Smuzhiyun struct signal_struct;
66*4882a593Smuzhiyun struct task_delay_info;
67*4882a593Smuzhiyun struct task_group;
68*4882a593Smuzhiyun struct io_uring_task;
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /*
71*4882a593Smuzhiyun  * Task state bitmask. NOTE! These bits are also
72*4882a593Smuzhiyun  * encoded in fs/proc/array.c: get_task_state().
73*4882a593Smuzhiyun  *
74*4882a593Smuzhiyun  * We have two separate sets of flags: task->state
75*4882a593Smuzhiyun  * is about runnability, while task->exit_state are
76*4882a593Smuzhiyun  * about the task exiting. Confusing, but this way
77*4882a593Smuzhiyun  * modifying one set can't modify the other one by
78*4882a593Smuzhiyun  * mistake.
79*4882a593Smuzhiyun  */
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /* Used in tsk->state: */
82*4882a593Smuzhiyun #define TASK_RUNNING			0x0000
83*4882a593Smuzhiyun #define TASK_INTERRUPTIBLE		0x0001
84*4882a593Smuzhiyun #define TASK_UNINTERRUPTIBLE		0x0002
85*4882a593Smuzhiyun #define __TASK_STOPPED			0x0004
86*4882a593Smuzhiyun #define __TASK_TRACED			0x0008
87*4882a593Smuzhiyun /* Used in tsk->exit_state: */
88*4882a593Smuzhiyun #define EXIT_DEAD			0x0010
89*4882a593Smuzhiyun #define EXIT_ZOMBIE			0x0020
90*4882a593Smuzhiyun #define EXIT_TRACE			(EXIT_ZOMBIE | EXIT_DEAD)
91*4882a593Smuzhiyun /* Used in tsk->state again: */
92*4882a593Smuzhiyun #define TASK_PARKED			0x0040
93*4882a593Smuzhiyun #define TASK_DEAD			0x0080
94*4882a593Smuzhiyun #define TASK_WAKEKILL			0x0100
95*4882a593Smuzhiyun #define TASK_WAKING			0x0200
96*4882a593Smuzhiyun #define TASK_NOLOAD			0x0400
97*4882a593Smuzhiyun #define TASK_NEW			0x0800
98*4882a593Smuzhiyun #define TASK_STATE_MAX			0x1000
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun /* Convenience macros for the sake of set_current_state: */
101*4882a593Smuzhiyun #define TASK_KILLABLE			(TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
102*4882a593Smuzhiyun #define TASK_STOPPED			(TASK_WAKEKILL | __TASK_STOPPED)
103*4882a593Smuzhiyun #define TASK_TRACED			(TASK_WAKEKILL | __TASK_TRACED)
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun #define TASK_IDLE			(TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun /* Convenience macros for the sake of wake_up(): */
108*4882a593Smuzhiyun #define TASK_NORMAL			(TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun /* get_task_state(): */
111*4882a593Smuzhiyun #define TASK_REPORT			(TASK_RUNNING | TASK_INTERRUPTIBLE | \
112*4882a593Smuzhiyun 					 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
113*4882a593Smuzhiyun 					 __TASK_TRACED | EXIT_DEAD | EXIT_ZOMBIE | \
114*4882a593Smuzhiyun 					 TASK_PARKED)
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun #define task_is_traced(task)		((task->state & __TASK_TRACED) != 0)
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun #define task_is_stopped(task)		((task->state & __TASK_STOPPED) != 0)
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun #define task_is_stopped_or_traced(task)	((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /*
125*4882a593Smuzhiyun  * Special states are those that do not use the normal wait-loop pattern. See
126*4882a593Smuzhiyun  * the comment with set_special_state().
127*4882a593Smuzhiyun  */
128*4882a593Smuzhiyun #define is_special_task_state(state)				\
129*4882a593Smuzhiyun 	((state) & (__TASK_STOPPED | __TASK_TRACED | TASK_PARKED | TASK_DEAD))
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun #define __set_current_state(state_value)			\
132*4882a593Smuzhiyun 	do {							\
133*4882a593Smuzhiyun 		WARN_ON_ONCE(is_special_task_state(state_value));\
134*4882a593Smuzhiyun 		current->task_state_change = _THIS_IP_;		\
135*4882a593Smuzhiyun 		current->state = (state_value);			\
136*4882a593Smuzhiyun 	} while (0)
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun #define set_current_state(state_value)				\
139*4882a593Smuzhiyun 	do {							\
140*4882a593Smuzhiyun 		WARN_ON_ONCE(is_special_task_state(state_value));\
141*4882a593Smuzhiyun 		current->task_state_change = _THIS_IP_;		\
142*4882a593Smuzhiyun 		smp_store_mb(current->state, (state_value));	\
143*4882a593Smuzhiyun 	} while (0)
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun #define set_special_state(state_value)					\
146*4882a593Smuzhiyun 	do {								\
147*4882a593Smuzhiyun 		unsigned long flags; /* may shadow */			\
148*4882a593Smuzhiyun 		WARN_ON_ONCE(!is_special_task_state(state_value));	\
149*4882a593Smuzhiyun 		raw_spin_lock_irqsave(&current->pi_lock, flags);	\
150*4882a593Smuzhiyun 		current->task_state_change = _THIS_IP_;			\
151*4882a593Smuzhiyun 		current->state = (state_value);				\
152*4882a593Smuzhiyun 		raw_spin_unlock_irqrestore(&current->pi_lock, flags);	\
153*4882a593Smuzhiyun 	} while (0)
154*4882a593Smuzhiyun #else
155*4882a593Smuzhiyun /*
156*4882a593Smuzhiyun  * set_current_state() includes a barrier so that the write of current->state
157*4882a593Smuzhiyun  * is correctly serialised wrt the caller's subsequent test of whether to
158*4882a593Smuzhiyun  * actually sleep:
159*4882a593Smuzhiyun  *
160*4882a593Smuzhiyun  *   for (;;) {
161*4882a593Smuzhiyun  *	set_current_state(TASK_UNINTERRUPTIBLE);
162*4882a593Smuzhiyun  *	if (CONDITION)
163*4882a593Smuzhiyun  *	   break;
164*4882a593Smuzhiyun  *
165*4882a593Smuzhiyun  *	schedule();
166*4882a593Smuzhiyun  *   }
167*4882a593Smuzhiyun  *   __set_current_state(TASK_RUNNING);
168*4882a593Smuzhiyun  *
169*4882a593Smuzhiyun  * If the caller does not need such serialisation (because, for instance, the
170*4882a593Smuzhiyun  * CONDITION test and condition change and wakeup are under the same lock) then
171*4882a593Smuzhiyun  * use __set_current_state().
172*4882a593Smuzhiyun  *
173*4882a593Smuzhiyun  * The above is typically ordered against the wakeup, which does:
174*4882a593Smuzhiyun  *
175*4882a593Smuzhiyun  *   CONDITION = 1;
176*4882a593Smuzhiyun  *   wake_up_state(p, TASK_UNINTERRUPTIBLE);
177*4882a593Smuzhiyun  *
178*4882a593Smuzhiyun  * where wake_up_state()/try_to_wake_up() executes a full memory barrier before
179*4882a593Smuzhiyun  * accessing p->state.
180*4882a593Smuzhiyun  *
181*4882a593Smuzhiyun  * Wakeup will do: if (@state & p->state) p->state = TASK_RUNNING, that is,
182*4882a593Smuzhiyun  * once it observes the TASK_UNINTERRUPTIBLE store the waking CPU can issue a
183*4882a593Smuzhiyun  * TASK_RUNNING store which can collide with __set_current_state(TASK_RUNNING).
184*4882a593Smuzhiyun  *
185*4882a593Smuzhiyun  * However, with slightly different timing the wakeup TASK_RUNNING store can
186*4882a593Smuzhiyun  * also collide with the TASK_UNINTERRUPTIBLE store. Losing that store is not
187*4882a593Smuzhiyun  * a problem either because that will result in one extra go around the loop
188*4882a593Smuzhiyun  * and our @cond test will save the day.
189*4882a593Smuzhiyun  *
190*4882a593Smuzhiyun  * Also see the comments of try_to_wake_up().
191*4882a593Smuzhiyun  */
192*4882a593Smuzhiyun #define __set_current_state(state_value)				\
193*4882a593Smuzhiyun 	current->state = (state_value)
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun #define set_current_state(state_value)					\
196*4882a593Smuzhiyun 	smp_store_mb(current->state, (state_value))
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun /*
199*4882a593Smuzhiyun  * set_special_state() should be used for those states when the blocking task
200*4882a593Smuzhiyun  * can not use the regular condition based wait-loop. In that case we must
201*4882a593Smuzhiyun  * serialize against wakeups such that any possible in-flight TASK_RUNNING stores
202*4882a593Smuzhiyun  * will not collide with our state change.
203*4882a593Smuzhiyun  */
204*4882a593Smuzhiyun #define set_special_state(state_value)					\
205*4882a593Smuzhiyun 	do {								\
206*4882a593Smuzhiyun 		unsigned long flags; /* may shadow */			\
207*4882a593Smuzhiyun 		raw_spin_lock_irqsave(&current->pi_lock, flags);	\
208*4882a593Smuzhiyun 		current->state = (state_value);				\
209*4882a593Smuzhiyun 		raw_spin_unlock_irqrestore(&current->pi_lock, flags);	\
210*4882a593Smuzhiyun 	} while (0)
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun #endif
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun /* Task command name length: */
215*4882a593Smuzhiyun #define TASK_COMM_LEN			16
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun extern void scheduler_tick(void);
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun #define	MAX_SCHEDULE_TIMEOUT		LONG_MAX
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun extern long schedule_timeout(long timeout);
222*4882a593Smuzhiyun extern long schedule_timeout_interruptible(long timeout);
223*4882a593Smuzhiyun extern long schedule_timeout_killable(long timeout);
224*4882a593Smuzhiyun extern long schedule_timeout_uninterruptible(long timeout);
225*4882a593Smuzhiyun extern long schedule_timeout_idle(long timeout);
226*4882a593Smuzhiyun asmlinkage void schedule(void);
227*4882a593Smuzhiyun extern void schedule_preempt_disabled(void);
228*4882a593Smuzhiyun asmlinkage void preempt_schedule_irq(void);
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun extern int __must_check io_schedule_prepare(void);
231*4882a593Smuzhiyun extern void io_schedule_finish(int token);
232*4882a593Smuzhiyun extern long io_schedule_timeout(long timeout);
233*4882a593Smuzhiyun extern void io_schedule(void);
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun /**
236*4882a593Smuzhiyun  * struct prev_cputime - snapshot of system and user cputime
237*4882a593Smuzhiyun  * @utime: time spent in user mode
238*4882a593Smuzhiyun  * @stime: time spent in system mode
239*4882a593Smuzhiyun  * @lock: protects the above two fields
240*4882a593Smuzhiyun  *
241*4882a593Smuzhiyun  * Stores previous user/system time values such that we can guarantee
242*4882a593Smuzhiyun  * monotonicity.
243*4882a593Smuzhiyun  */
244*4882a593Smuzhiyun struct prev_cputime {
245*4882a593Smuzhiyun #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
246*4882a593Smuzhiyun 	u64				utime;
247*4882a593Smuzhiyun 	u64				stime;
248*4882a593Smuzhiyun 	raw_spinlock_t			lock;
249*4882a593Smuzhiyun #endif
250*4882a593Smuzhiyun };
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun enum vtime_state {
253*4882a593Smuzhiyun 	/* Task is sleeping or running in a CPU with VTIME inactive: */
254*4882a593Smuzhiyun 	VTIME_INACTIVE = 0,
255*4882a593Smuzhiyun 	/* Task is idle */
256*4882a593Smuzhiyun 	VTIME_IDLE,
257*4882a593Smuzhiyun 	/* Task runs in kernelspace in a CPU with VTIME active: */
258*4882a593Smuzhiyun 	VTIME_SYS,
259*4882a593Smuzhiyun 	/* Task runs in userspace in a CPU with VTIME active: */
260*4882a593Smuzhiyun 	VTIME_USER,
261*4882a593Smuzhiyun 	/* Task runs as guests in a CPU with VTIME active: */
262*4882a593Smuzhiyun 	VTIME_GUEST,
263*4882a593Smuzhiyun };
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun struct vtime {
266*4882a593Smuzhiyun 	seqcount_t		seqcount;
267*4882a593Smuzhiyun 	unsigned long long	starttime;
268*4882a593Smuzhiyun 	enum vtime_state	state;
269*4882a593Smuzhiyun 	unsigned int		cpu;
270*4882a593Smuzhiyun 	u64			utime;
271*4882a593Smuzhiyun 	u64			stime;
272*4882a593Smuzhiyun 	u64			gtime;
273*4882a593Smuzhiyun };
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun /*
276*4882a593Smuzhiyun  * Utilization clamp constraints.
277*4882a593Smuzhiyun  * @UCLAMP_MIN:	Minimum utilization
278*4882a593Smuzhiyun  * @UCLAMP_MAX:	Maximum utilization
279*4882a593Smuzhiyun  * @UCLAMP_CNT:	Utilization clamp constraints count
280*4882a593Smuzhiyun  */
281*4882a593Smuzhiyun enum uclamp_id {
282*4882a593Smuzhiyun 	UCLAMP_MIN = 0,
283*4882a593Smuzhiyun 	UCLAMP_MAX,
284*4882a593Smuzhiyun 	UCLAMP_CNT
285*4882a593Smuzhiyun };
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun #ifdef CONFIG_SMP
288*4882a593Smuzhiyun extern struct root_domain def_root_domain;
289*4882a593Smuzhiyun extern struct mutex sched_domains_mutex;
290*4882a593Smuzhiyun #endif
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun struct sched_info {
293*4882a593Smuzhiyun #ifdef CONFIG_SCHED_INFO
294*4882a593Smuzhiyun 	/* Cumulative counters: */
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun 	/* # of times we have run on this CPU: */
297*4882a593Smuzhiyun 	unsigned long			pcount;
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun 	/* Time spent waiting on a runqueue: */
300*4882a593Smuzhiyun 	unsigned long long		run_delay;
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun 	/* Timestamps: */
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun 	/* When did we last run on a CPU? */
305*4882a593Smuzhiyun 	unsigned long long		last_arrival;
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun 	/* When were we last queued to run? */
308*4882a593Smuzhiyun 	unsigned long long		last_queued;
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun #endif /* CONFIG_SCHED_INFO */
311*4882a593Smuzhiyun };
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun /*
314*4882a593Smuzhiyun  * Integer metrics need fixed point arithmetic, e.g., sched/fair
315*4882a593Smuzhiyun  * has a few: load, load_avg, util_avg, freq, and capacity.
316*4882a593Smuzhiyun  *
317*4882a593Smuzhiyun  * We define a basic fixed point arithmetic range, and then formalize
318*4882a593Smuzhiyun  * all these metrics based on that basic range.
319*4882a593Smuzhiyun  */
320*4882a593Smuzhiyun # define SCHED_FIXEDPOINT_SHIFT		10
321*4882a593Smuzhiyun # define SCHED_FIXEDPOINT_SCALE		(1L << SCHED_FIXEDPOINT_SHIFT)
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun /* Increase resolution of cpu_capacity calculations */
324*4882a593Smuzhiyun # define SCHED_CAPACITY_SHIFT		SCHED_FIXEDPOINT_SHIFT
325*4882a593Smuzhiyun # define SCHED_CAPACITY_SCALE		(1L << SCHED_CAPACITY_SHIFT)
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun struct load_weight {
328*4882a593Smuzhiyun 	unsigned long			weight;
329*4882a593Smuzhiyun 	u32				inv_weight;
330*4882a593Smuzhiyun };
331*4882a593Smuzhiyun 
332*4882a593Smuzhiyun /**
333*4882a593Smuzhiyun  * struct util_est - Estimation utilization of FAIR tasks
334*4882a593Smuzhiyun  * @enqueued: instantaneous estimated utilization of a task/cpu
335*4882a593Smuzhiyun  * @ewma:     the Exponential Weighted Moving Average (EWMA)
336*4882a593Smuzhiyun  *            utilization of a task
337*4882a593Smuzhiyun  *
338*4882a593Smuzhiyun  * Support data structure to track an Exponential Weighted Moving Average
339*4882a593Smuzhiyun  * (EWMA) of a FAIR task's utilization. New samples are added to the moving
340*4882a593Smuzhiyun  * average each time a task completes an activation. Sample's weight is chosen
341*4882a593Smuzhiyun  * so that the EWMA will be relatively insensitive to transient changes to the
342*4882a593Smuzhiyun  * task's workload.
343*4882a593Smuzhiyun  *
344*4882a593Smuzhiyun  * The enqueued attribute has a slightly different meaning for tasks and cpus:
345*4882a593Smuzhiyun  * - task:   the task's util_avg at last task dequeue time
346*4882a593Smuzhiyun  * - cfs_rq: the sum of util_est.enqueued for each RUNNABLE task on that CPU
347*4882a593Smuzhiyun  * Thus, the util_est.enqueued of a task represents the contribution on the
348*4882a593Smuzhiyun  * estimated utilization of the CPU where that task is currently enqueued.
349*4882a593Smuzhiyun  *
350*4882a593Smuzhiyun  * Only for tasks we track a moving average of the past instantaneous
351*4882a593Smuzhiyun  * estimated utilization. This allows to absorb sporadic drops in utilization
352*4882a593Smuzhiyun  * of an otherwise almost periodic task.
353*4882a593Smuzhiyun  *
354*4882a593Smuzhiyun  * The UTIL_AVG_UNCHANGED flag is used to synchronize util_est with util_avg
355*4882a593Smuzhiyun  * updates. When a task is dequeued, its util_est should not be updated if its
356*4882a593Smuzhiyun  * util_avg has not been updated in the meantime.
357*4882a593Smuzhiyun  * This information is mapped into the MSB bit of util_est.enqueued at dequeue
358*4882a593Smuzhiyun  * time. Since max value of util_est.enqueued for a task is 1024 (PELT util_avg
359*4882a593Smuzhiyun  * for a task) it is safe to use MSB.
360*4882a593Smuzhiyun  */
361*4882a593Smuzhiyun struct util_est {
362*4882a593Smuzhiyun 	unsigned int			enqueued;
363*4882a593Smuzhiyun 	unsigned int			ewma;
364*4882a593Smuzhiyun #define UTIL_EST_WEIGHT_SHIFT		2
365*4882a593Smuzhiyun #define UTIL_AVG_UNCHANGED		0x80000000
366*4882a593Smuzhiyun } __attribute__((__aligned__(sizeof(u64))));
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun /*
369*4882a593Smuzhiyun  * The load/runnable/util_avg accumulates an infinite geometric series
370*4882a593Smuzhiyun  * (see __update_load_avg_cfs_rq() in kernel/sched/pelt.c).
371*4882a593Smuzhiyun  *
372*4882a593Smuzhiyun  * [load_avg definition]
373*4882a593Smuzhiyun  *
374*4882a593Smuzhiyun  *   load_avg = runnable% * scale_load_down(load)
375*4882a593Smuzhiyun  *
376*4882a593Smuzhiyun  * [runnable_avg definition]
377*4882a593Smuzhiyun  *
378*4882a593Smuzhiyun  *   runnable_avg = runnable% * SCHED_CAPACITY_SCALE
379*4882a593Smuzhiyun  *
380*4882a593Smuzhiyun  * [util_avg definition]
381*4882a593Smuzhiyun  *
382*4882a593Smuzhiyun  *   util_avg = running% * SCHED_CAPACITY_SCALE
383*4882a593Smuzhiyun  *
384*4882a593Smuzhiyun  * where runnable% is the time ratio that a sched_entity is runnable and
385*4882a593Smuzhiyun  * running% the time ratio that a sched_entity is running.
386*4882a593Smuzhiyun  *
387*4882a593Smuzhiyun  * For cfs_rq, they are the aggregated values of all runnable and blocked
388*4882a593Smuzhiyun  * sched_entities.
389*4882a593Smuzhiyun  *
390*4882a593Smuzhiyun  * The load/runnable/util_avg doesn't directly factor frequency scaling and CPU
391*4882a593Smuzhiyun  * capacity scaling. The scaling is done through the rq_clock_pelt that is used
392*4882a593Smuzhiyun  * for computing those signals (see update_rq_clock_pelt())
393*4882a593Smuzhiyun  *
394*4882a593Smuzhiyun  * N.B., the above ratios (runnable% and running%) themselves are in the
395*4882a593Smuzhiyun  * range of [0, 1]. To do fixed point arithmetics, we therefore scale them
396*4882a593Smuzhiyun  * to as large a range as necessary. This is for example reflected by
397*4882a593Smuzhiyun  * util_avg's SCHED_CAPACITY_SCALE.
398*4882a593Smuzhiyun  *
399*4882a593Smuzhiyun  * [Overflow issue]
400*4882a593Smuzhiyun  *
401*4882a593Smuzhiyun  * The 64-bit load_sum can have 4353082796 (=2^64/47742/88761) entities
402*4882a593Smuzhiyun  * with the highest load (=88761), always runnable on a single cfs_rq,
403*4882a593Smuzhiyun  * and should not overflow as the number already hits PID_MAX_LIMIT.
404*4882a593Smuzhiyun  *
405*4882a593Smuzhiyun  * For all other cases (including 32-bit kernels), struct load_weight's
406*4882a593Smuzhiyun  * weight will overflow first before we do, because:
407*4882a593Smuzhiyun  *
408*4882a593Smuzhiyun  *    Max(load_avg) <= Max(load.weight)
409*4882a593Smuzhiyun  *
410*4882a593Smuzhiyun  * Then it is the load_weight's responsibility to consider overflow
411*4882a593Smuzhiyun  * issues.
412*4882a593Smuzhiyun  */
413*4882a593Smuzhiyun struct sched_avg {
414*4882a593Smuzhiyun 	u64				last_update_time;
415*4882a593Smuzhiyun 	u64				load_sum;
416*4882a593Smuzhiyun 	u64				runnable_sum;
417*4882a593Smuzhiyun 	u32				util_sum;
418*4882a593Smuzhiyun 	u32				period_contrib;
419*4882a593Smuzhiyun 	unsigned long			load_avg;
420*4882a593Smuzhiyun 	unsigned long			runnable_avg;
421*4882a593Smuzhiyun 	unsigned long			util_avg;
422*4882a593Smuzhiyun 	struct util_est			util_est;
423*4882a593Smuzhiyun } ____cacheline_aligned;
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun struct sched_statistics {
426*4882a593Smuzhiyun #ifdef CONFIG_SCHEDSTATS
427*4882a593Smuzhiyun 	u64				wait_start;
428*4882a593Smuzhiyun 	u64				wait_max;
429*4882a593Smuzhiyun 	u64				wait_count;
430*4882a593Smuzhiyun 	u64				wait_sum;
431*4882a593Smuzhiyun 	u64				iowait_count;
432*4882a593Smuzhiyun 	u64				iowait_sum;
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun 	u64				sleep_start;
435*4882a593Smuzhiyun 	u64				sleep_max;
436*4882a593Smuzhiyun 	s64				sum_sleep_runtime;
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun 	u64				block_start;
439*4882a593Smuzhiyun 	u64				block_max;
440*4882a593Smuzhiyun 	u64				exec_max;
441*4882a593Smuzhiyun 	u64				slice_max;
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun 	u64				nr_migrations_cold;
444*4882a593Smuzhiyun 	u64				nr_failed_migrations_affine;
445*4882a593Smuzhiyun 	u64				nr_failed_migrations_running;
446*4882a593Smuzhiyun 	u64				nr_failed_migrations_hot;
447*4882a593Smuzhiyun 	u64				nr_forced_migrations;
448*4882a593Smuzhiyun 
449*4882a593Smuzhiyun 	u64				nr_wakeups;
450*4882a593Smuzhiyun 	u64				nr_wakeups_sync;
451*4882a593Smuzhiyun 	u64				nr_wakeups_migrate;
452*4882a593Smuzhiyun 	u64				nr_wakeups_local;
453*4882a593Smuzhiyun 	u64				nr_wakeups_remote;
454*4882a593Smuzhiyun 	u64				nr_wakeups_affine;
455*4882a593Smuzhiyun 	u64				nr_wakeups_affine_attempts;
456*4882a593Smuzhiyun 	u64				nr_wakeups_passive;
457*4882a593Smuzhiyun 	u64				nr_wakeups_idle;
458*4882a593Smuzhiyun #endif
459*4882a593Smuzhiyun };
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun struct sched_entity {
462*4882a593Smuzhiyun 	/* For load-balancing: */
463*4882a593Smuzhiyun 	struct load_weight		load;
464*4882a593Smuzhiyun 	struct rb_node			run_node;
465*4882a593Smuzhiyun 	struct list_head		group_node;
466*4882a593Smuzhiyun 	unsigned int			on_rq;
467*4882a593Smuzhiyun 
468*4882a593Smuzhiyun 	u64				exec_start;
469*4882a593Smuzhiyun 	u64				sum_exec_runtime;
470*4882a593Smuzhiyun 	u64				vruntime;
471*4882a593Smuzhiyun 	u64				prev_sum_exec_runtime;
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun 	u64				nr_migrations;
474*4882a593Smuzhiyun 
475*4882a593Smuzhiyun 	struct sched_statistics		statistics;
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun #ifdef CONFIG_FAIR_GROUP_SCHED
478*4882a593Smuzhiyun 	int				depth;
479*4882a593Smuzhiyun 	struct sched_entity		*parent;
480*4882a593Smuzhiyun 	/* rq on which this entity is (to be) queued: */
481*4882a593Smuzhiyun 	struct cfs_rq			*cfs_rq;
482*4882a593Smuzhiyun 	/* rq "owned" by this entity/group: */
483*4882a593Smuzhiyun 	struct cfs_rq			*my_q;
484*4882a593Smuzhiyun 	/* cached value of my_q->h_nr_running */
485*4882a593Smuzhiyun 	unsigned long			runnable_weight;
486*4882a593Smuzhiyun #endif
487*4882a593Smuzhiyun 
488*4882a593Smuzhiyun #ifdef CONFIG_SMP
489*4882a593Smuzhiyun 	/*
490*4882a593Smuzhiyun 	 * Per entity load average tracking.
491*4882a593Smuzhiyun 	 *
492*4882a593Smuzhiyun 	 * Put into separate cache line so it does not
493*4882a593Smuzhiyun 	 * collide with read-mostly values above.
494*4882a593Smuzhiyun 	 */
495*4882a593Smuzhiyun 	struct sched_avg		avg;
496*4882a593Smuzhiyun #endif
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
499*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(2);
500*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(3);
501*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(4);
502*4882a593Smuzhiyun };
503*4882a593Smuzhiyun 
504*4882a593Smuzhiyun struct sched_rt_entity {
505*4882a593Smuzhiyun 	struct list_head		run_list;
506*4882a593Smuzhiyun 	unsigned long			timeout;
507*4882a593Smuzhiyun 	unsigned long			watchdog_stamp;
508*4882a593Smuzhiyun 	unsigned int			time_slice;
509*4882a593Smuzhiyun 	unsigned short			on_rq;
510*4882a593Smuzhiyun 	unsigned short			on_list;
511*4882a593Smuzhiyun 
512*4882a593Smuzhiyun 	struct sched_rt_entity		*back;
513*4882a593Smuzhiyun #ifdef CONFIG_RT_GROUP_SCHED
514*4882a593Smuzhiyun 	struct sched_rt_entity		*parent;
515*4882a593Smuzhiyun 	/* rq on which this entity is (to be) queued: */
516*4882a593Smuzhiyun 	struct rt_rq			*rt_rq;
517*4882a593Smuzhiyun 	/* rq "owned" by this entity/group: */
518*4882a593Smuzhiyun 	struct rt_rq			*my_q;
519*4882a593Smuzhiyun #endif
520*4882a593Smuzhiyun 
521*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
522*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(2);
523*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(3);
524*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(4);
525*4882a593Smuzhiyun } __randomize_layout;
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun struct sched_dl_entity {
528*4882a593Smuzhiyun 	struct rb_node			rb_node;
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun 	/*
531*4882a593Smuzhiyun 	 * Original scheduling parameters. Copied here from sched_attr
532*4882a593Smuzhiyun 	 * during sched_setattr(), they will remain the same until
533*4882a593Smuzhiyun 	 * the next sched_setattr().
534*4882a593Smuzhiyun 	 */
535*4882a593Smuzhiyun 	u64				dl_runtime;	/* Maximum runtime for each instance	*/
536*4882a593Smuzhiyun 	u64				dl_deadline;	/* Relative deadline of each instance	*/
537*4882a593Smuzhiyun 	u64				dl_period;	/* Separation of two instances (period) */
538*4882a593Smuzhiyun 	u64				dl_bw;		/* dl_runtime / dl_period		*/
539*4882a593Smuzhiyun 	u64				dl_density;	/* dl_runtime / dl_deadline		*/
540*4882a593Smuzhiyun 
541*4882a593Smuzhiyun 	/*
542*4882a593Smuzhiyun 	 * Actual scheduling parameters. Initialized with the values above,
543*4882a593Smuzhiyun 	 * they are continuously updated during task execution. Note that
544*4882a593Smuzhiyun 	 * the remaining runtime could be < 0 in case we are in overrun.
545*4882a593Smuzhiyun 	 */
546*4882a593Smuzhiyun 	s64				runtime;	/* Remaining runtime for this instance	*/
547*4882a593Smuzhiyun 	u64				deadline;	/* Absolute deadline for this instance	*/
548*4882a593Smuzhiyun 	unsigned int			flags;		/* Specifying the scheduler behaviour	*/
549*4882a593Smuzhiyun 
550*4882a593Smuzhiyun 	/*
551*4882a593Smuzhiyun 	 * Some bool flags:
552*4882a593Smuzhiyun 	 *
553*4882a593Smuzhiyun 	 * @dl_throttled tells if we exhausted the runtime. If so, the
554*4882a593Smuzhiyun 	 * task has to wait for a replenishment to be performed at the
555*4882a593Smuzhiyun 	 * next firing of dl_timer.
556*4882a593Smuzhiyun 	 *
557*4882a593Smuzhiyun 	 * @dl_yielded tells if task gave up the CPU before consuming
558*4882a593Smuzhiyun 	 * all its available runtime during the last job.
559*4882a593Smuzhiyun 	 *
560*4882a593Smuzhiyun 	 * @dl_non_contending tells if the task is inactive while still
561*4882a593Smuzhiyun 	 * contributing to the active utilization. In other words, it
562*4882a593Smuzhiyun 	 * indicates if the inactive timer has been armed and its handler
563*4882a593Smuzhiyun 	 * has not been executed yet. This flag is useful to avoid race
564*4882a593Smuzhiyun 	 * conditions between the inactive timer handler and the wakeup
565*4882a593Smuzhiyun 	 * code.
566*4882a593Smuzhiyun 	 *
567*4882a593Smuzhiyun 	 * @dl_overrun tells if the task asked to be informed about runtime
568*4882a593Smuzhiyun 	 * overruns.
569*4882a593Smuzhiyun 	 */
570*4882a593Smuzhiyun 	unsigned int			dl_throttled      : 1;
571*4882a593Smuzhiyun 	unsigned int			dl_yielded        : 1;
572*4882a593Smuzhiyun 	unsigned int			dl_non_contending : 1;
573*4882a593Smuzhiyun 	unsigned int			dl_overrun	  : 1;
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun 	/*
576*4882a593Smuzhiyun 	 * Bandwidth enforcement timer. Each -deadline task has its
577*4882a593Smuzhiyun 	 * own bandwidth to be enforced, thus we need one timer per task.
578*4882a593Smuzhiyun 	 */
579*4882a593Smuzhiyun 	struct hrtimer			dl_timer;
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun 	/*
582*4882a593Smuzhiyun 	 * Inactive timer, responsible for decreasing the active utilization
583*4882a593Smuzhiyun 	 * at the "0-lag time". When a -deadline task blocks, it contributes
584*4882a593Smuzhiyun 	 * to GRUB's active utilization until the "0-lag time", hence a
585*4882a593Smuzhiyun 	 * timer is needed to decrease the active utilization at the correct
586*4882a593Smuzhiyun 	 * time.
587*4882a593Smuzhiyun 	 */
588*4882a593Smuzhiyun 	struct hrtimer inactive_timer;
589*4882a593Smuzhiyun 
590*4882a593Smuzhiyun #ifdef CONFIG_RT_MUTEXES
591*4882a593Smuzhiyun 	/*
592*4882a593Smuzhiyun 	 * Priority Inheritance. When a DEADLINE scheduling entity is boosted
593*4882a593Smuzhiyun 	 * pi_se points to the donor, otherwise points to the dl_se it belongs
594*4882a593Smuzhiyun 	 * to (the original one/itself).
595*4882a593Smuzhiyun 	 */
596*4882a593Smuzhiyun 	struct sched_dl_entity *pi_se;
597*4882a593Smuzhiyun #endif
598*4882a593Smuzhiyun };
599*4882a593Smuzhiyun 
600*4882a593Smuzhiyun #ifdef CONFIG_UCLAMP_TASK
601*4882a593Smuzhiyun /* Number of utilization clamp buckets (shorter alias) */
602*4882a593Smuzhiyun #define UCLAMP_BUCKETS CONFIG_UCLAMP_BUCKETS_COUNT
603*4882a593Smuzhiyun 
604*4882a593Smuzhiyun /*
605*4882a593Smuzhiyun  * Utilization clamp for a scheduling entity
606*4882a593Smuzhiyun  * @value:		clamp value "assigned" to a se
607*4882a593Smuzhiyun  * @bucket_id:		bucket index corresponding to the "assigned" value
608*4882a593Smuzhiyun  * @active:		the se is currently refcounted in a rq's bucket
609*4882a593Smuzhiyun  * @user_defined:	the requested clamp value comes from user-space
610*4882a593Smuzhiyun  *
611*4882a593Smuzhiyun  * The bucket_id is the index of the clamp bucket matching the clamp value
612*4882a593Smuzhiyun  * which is pre-computed and stored to avoid expensive integer divisions from
613*4882a593Smuzhiyun  * the fast path.
614*4882a593Smuzhiyun  *
615*4882a593Smuzhiyun  * The active bit is set whenever a task has got an "effective" value assigned,
616*4882a593Smuzhiyun  * which can be different from the clamp value "requested" from user-space.
617*4882a593Smuzhiyun  * This allows to know a task is refcounted in the rq's bucket corresponding
618*4882a593Smuzhiyun  * to the "effective" bucket_id.
619*4882a593Smuzhiyun  *
620*4882a593Smuzhiyun  * The user_defined bit is set whenever a task has got a task-specific clamp
621*4882a593Smuzhiyun  * value requested from userspace, i.e. the system defaults apply to this task
622*4882a593Smuzhiyun  * just as a restriction. This allows to relax default clamps when a less
623*4882a593Smuzhiyun  * restrictive task-specific value has been requested, thus allowing to
624*4882a593Smuzhiyun  * implement a "nice" semantic. For example, a task running with a 20%
625*4882a593Smuzhiyun  * default boost can still drop its own boosting to 0%.
626*4882a593Smuzhiyun  */
627*4882a593Smuzhiyun struct uclamp_se {
628*4882a593Smuzhiyun 	unsigned int value		: bits_per(SCHED_CAPACITY_SCALE);
629*4882a593Smuzhiyun 	unsigned int bucket_id		: bits_per(UCLAMP_BUCKETS);
630*4882a593Smuzhiyun 	unsigned int active		: 1;
631*4882a593Smuzhiyun 	unsigned int user_defined	: 1;
632*4882a593Smuzhiyun };
633*4882a593Smuzhiyun #endif /* CONFIG_UCLAMP_TASK */
634*4882a593Smuzhiyun 
635*4882a593Smuzhiyun union rcu_special {
636*4882a593Smuzhiyun 	struct {
637*4882a593Smuzhiyun 		u8			blocked;
638*4882a593Smuzhiyun 		u8			need_qs;
639*4882a593Smuzhiyun 		u8			exp_hint; /* Hint for performance. */
640*4882a593Smuzhiyun 		u8			need_mb; /* Readers need smp_mb(). */
641*4882a593Smuzhiyun 	} b; /* Bits. */
642*4882a593Smuzhiyun 	u32 s; /* Set of bits. */
643*4882a593Smuzhiyun };
644*4882a593Smuzhiyun 
645*4882a593Smuzhiyun enum perf_event_task_context {
646*4882a593Smuzhiyun 	perf_invalid_context = -1,
647*4882a593Smuzhiyun 	perf_hw_context = 0,
648*4882a593Smuzhiyun 	perf_sw_context,
649*4882a593Smuzhiyun 	perf_nr_task_contexts,
650*4882a593Smuzhiyun };
651*4882a593Smuzhiyun 
652*4882a593Smuzhiyun struct wake_q_node {
653*4882a593Smuzhiyun 	struct wake_q_node *next;
654*4882a593Smuzhiyun };
655*4882a593Smuzhiyun 
656*4882a593Smuzhiyun struct task_struct {
657*4882a593Smuzhiyun #ifdef CONFIG_THREAD_INFO_IN_TASK
658*4882a593Smuzhiyun 	/*
659*4882a593Smuzhiyun 	 * For reasons of header soup (see current_thread_info()), this
660*4882a593Smuzhiyun 	 * must be the first element of task_struct.
661*4882a593Smuzhiyun 	 */
662*4882a593Smuzhiyun 	struct thread_info		thread_info;
663*4882a593Smuzhiyun #endif
664*4882a593Smuzhiyun 	/* -1 unrunnable, 0 runnable, >0 stopped: */
665*4882a593Smuzhiyun 	volatile long			state;
666*4882a593Smuzhiyun 
667*4882a593Smuzhiyun 	/*
668*4882a593Smuzhiyun 	 * This begins the randomizable portion of task_struct. Only
669*4882a593Smuzhiyun 	 * scheduling-critical items should be added above here.
670*4882a593Smuzhiyun 	 */
671*4882a593Smuzhiyun 	randomized_struct_fields_start
672*4882a593Smuzhiyun 
673*4882a593Smuzhiyun 	void				*stack;
674*4882a593Smuzhiyun 	refcount_t			usage;
675*4882a593Smuzhiyun 	/* Per task flags (PF_*), defined further below: */
676*4882a593Smuzhiyun 	unsigned int			flags;
677*4882a593Smuzhiyun 	unsigned int			ptrace;
678*4882a593Smuzhiyun 
679*4882a593Smuzhiyun #ifdef CONFIG_SMP
680*4882a593Smuzhiyun 	int				on_cpu;
681*4882a593Smuzhiyun 	struct __call_single_node	wake_entry;
682*4882a593Smuzhiyun #ifdef CONFIG_THREAD_INFO_IN_TASK
683*4882a593Smuzhiyun 	/* Current CPU: */
684*4882a593Smuzhiyun 	unsigned int			cpu;
685*4882a593Smuzhiyun #endif
686*4882a593Smuzhiyun 	unsigned int			wakee_flips;
687*4882a593Smuzhiyun 	unsigned long			wakee_flip_decay_ts;
688*4882a593Smuzhiyun 	struct task_struct		*last_wakee;
689*4882a593Smuzhiyun 
690*4882a593Smuzhiyun 	/*
691*4882a593Smuzhiyun 	 * recent_used_cpu is initially set as the last CPU used by a task
692*4882a593Smuzhiyun 	 * that wakes affine another task. Waker/wakee relationships can
693*4882a593Smuzhiyun 	 * push tasks around a CPU where each wakeup moves to the next one.
694*4882a593Smuzhiyun 	 * Tracking a recently used CPU allows a quick search for a recently
695*4882a593Smuzhiyun 	 * used CPU that may be idle.
696*4882a593Smuzhiyun 	 */
697*4882a593Smuzhiyun 	int				recent_used_cpu;
698*4882a593Smuzhiyun 	int				wake_cpu;
699*4882a593Smuzhiyun #endif
700*4882a593Smuzhiyun 	int				on_rq;
701*4882a593Smuzhiyun 
702*4882a593Smuzhiyun 	int				prio;
703*4882a593Smuzhiyun 	int				static_prio;
704*4882a593Smuzhiyun 	int				normal_prio;
705*4882a593Smuzhiyun 	unsigned int			rt_priority;
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun 	const struct sched_class	*sched_class;
708*4882a593Smuzhiyun 	struct sched_entity		se;
709*4882a593Smuzhiyun 	struct sched_rt_entity		rt;
710*4882a593Smuzhiyun #ifdef CONFIG_CGROUP_SCHED
711*4882a593Smuzhiyun 	struct task_group		*sched_task_group;
712*4882a593Smuzhiyun #endif
713*4882a593Smuzhiyun 	struct sched_dl_entity		dl;
714*4882a593Smuzhiyun 
715*4882a593Smuzhiyun #ifdef CONFIG_UCLAMP_TASK
716*4882a593Smuzhiyun 	/*
717*4882a593Smuzhiyun 	 * Clamp values requested for a scheduling entity.
718*4882a593Smuzhiyun 	 * Must be updated with task_rq_lock() held.
719*4882a593Smuzhiyun 	 */
720*4882a593Smuzhiyun 	struct uclamp_se		uclamp_req[UCLAMP_CNT];
721*4882a593Smuzhiyun 	/*
722*4882a593Smuzhiyun 	 * Effective clamp values used for a scheduling entity.
723*4882a593Smuzhiyun 	 * Must be updated with task_rq_lock() held.
724*4882a593Smuzhiyun 	 */
725*4882a593Smuzhiyun 	struct uclamp_se		uclamp[UCLAMP_CNT];
726*4882a593Smuzhiyun #endif
727*4882a593Smuzhiyun 
728*4882a593Smuzhiyun #ifdef CONFIG_HOTPLUG_CPU
729*4882a593Smuzhiyun 	struct list_head		percpu_kthread_node;
730*4882a593Smuzhiyun #endif
731*4882a593Smuzhiyun 
732*4882a593Smuzhiyun #ifdef CONFIG_PREEMPT_NOTIFIERS
733*4882a593Smuzhiyun 	/* List of struct preempt_notifier: */
734*4882a593Smuzhiyun 	struct hlist_head		preempt_notifiers;
735*4882a593Smuzhiyun #endif
736*4882a593Smuzhiyun 
737*4882a593Smuzhiyun #ifdef CONFIG_BLK_DEV_IO_TRACE
738*4882a593Smuzhiyun 	unsigned int			btrace_seq;
739*4882a593Smuzhiyun #endif
740*4882a593Smuzhiyun 
741*4882a593Smuzhiyun 	unsigned int			policy;
742*4882a593Smuzhiyun 	int				nr_cpus_allowed;
743*4882a593Smuzhiyun 	const cpumask_t			*cpus_ptr;
744*4882a593Smuzhiyun 	cpumask_t			cpus_mask;
745*4882a593Smuzhiyun 
746*4882a593Smuzhiyun #ifdef CONFIG_PREEMPT_RCU
747*4882a593Smuzhiyun 	int				rcu_read_lock_nesting;
748*4882a593Smuzhiyun 	union rcu_special		rcu_read_unlock_special;
749*4882a593Smuzhiyun 	struct list_head		rcu_node_entry;
750*4882a593Smuzhiyun 	struct rcu_node			*rcu_blocked_node;
751*4882a593Smuzhiyun #endif /* #ifdef CONFIG_PREEMPT_RCU */
752*4882a593Smuzhiyun 
753*4882a593Smuzhiyun #ifdef CONFIG_TASKS_RCU
754*4882a593Smuzhiyun 	unsigned long			rcu_tasks_nvcsw;
755*4882a593Smuzhiyun 	u8				rcu_tasks_holdout;
756*4882a593Smuzhiyun 	u8				rcu_tasks_idx;
757*4882a593Smuzhiyun 	int				rcu_tasks_idle_cpu;
758*4882a593Smuzhiyun 	struct list_head		rcu_tasks_holdout_list;
759*4882a593Smuzhiyun #endif /* #ifdef CONFIG_TASKS_RCU */
760*4882a593Smuzhiyun 
761*4882a593Smuzhiyun #ifdef CONFIG_TASKS_TRACE_RCU
762*4882a593Smuzhiyun 	int				trc_reader_nesting;
763*4882a593Smuzhiyun 	int				trc_ipi_to_cpu;
764*4882a593Smuzhiyun 	union rcu_special		trc_reader_special;
765*4882a593Smuzhiyun 	bool				trc_reader_checked;
766*4882a593Smuzhiyun 	struct list_head		trc_holdout_list;
767*4882a593Smuzhiyun #endif /* #ifdef CONFIG_TASKS_TRACE_RCU */
768*4882a593Smuzhiyun 
769*4882a593Smuzhiyun 	struct sched_info		sched_info;
770*4882a593Smuzhiyun 
771*4882a593Smuzhiyun 	struct list_head		tasks;
772*4882a593Smuzhiyun #ifdef CONFIG_SMP
773*4882a593Smuzhiyun 	struct plist_node		pushable_tasks;
774*4882a593Smuzhiyun 	struct rb_node			pushable_dl_tasks;
775*4882a593Smuzhiyun #endif
776*4882a593Smuzhiyun 
777*4882a593Smuzhiyun 	struct mm_struct		*mm;
778*4882a593Smuzhiyun 	struct mm_struct		*active_mm;
779*4882a593Smuzhiyun 
780*4882a593Smuzhiyun 	/* Per-thread vma caching: */
781*4882a593Smuzhiyun 	struct vmacache			vmacache;
782*4882a593Smuzhiyun 
783*4882a593Smuzhiyun #ifdef SPLIT_RSS_COUNTING
784*4882a593Smuzhiyun 	struct task_rss_stat		rss_stat;
785*4882a593Smuzhiyun #endif
786*4882a593Smuzhiyun 	int				exit_state;
787*4882a593Smuzhiyun 	int				exit_code;
788*4882a593Smuzhiyun 	int				exit_signal;
789*4882a593Smuzhiyun 	/* The signal sent when the parent dies: */
790*4882a593Smuzhiyun 	int				pdeath_signal;
791*4882a593Smuzhiyun 	/* JOBCTL_*, siglock protected: */
792*4882a593Smuzhiyun 	unsigned long			jobctl;
793*4882a593Smuzhiyun 
794*4882a593Smuzhiyun 	/* Used for emulating ABI behavior of previous Linux versions: */
795*4882a593Smuzhiyun 	unsigned int			personality;
796*4882a593Smuzhiyun 
797*4882a593Smuzhiyun 	/* Scheduler bits, serialized by scheduler locks: */
798*4882a593Smuzhiyun 	unsigned			sched_reset_on_fork:1;
799*4882a593Smuzhiyun 	unsigned			sched_contributes_to_load:1;
800*4882a593Smuzhiyun 	unsigned			sched_migrated:1;
801*4882a593Smuzhiyun #ifdef CONFIG_PSI
802*4882a593Smuzhiyun 	unsigned			sched_psi_wake_requeue:1;
803*4882a593Smuzhiyun #endif
804*4882a593Smuzhiyun 
805*4882a593Smuzhiyun 	/* Force alignment to the next boundary: */
806*4882a593Smuzhiyun 	unsigned			:0;
807*4882a593Smuzhiyun 
808*4882a593Smuzhiyun 	/* Unserialized, strictly 'current' */
809*4882a593Smuzhiyun 
810*4882a593Smuzhiyun 	/*
811*4882a593Smuzhiyun 	 * This field must not be in the scheduler word above due to wakelist
812*4882a593Smuzhiyun 	 * queueing no longer being serialized by p->on_cpu. However:
813*4882a593Smuzhiyun 	 *
814*4882a593Smuzhiyun 	 * p->XXX = X;			ttwu()
815*4882a593Smuzhiyun 	 * schedule()			  if (p->on_rq && ..) // false
816*4882a593Smuzhiyun 	 *   smp_mb__after_spinlock();	  if (smp_load_acquire(&p->on_cpu) && //true
817*4882a593Smuzhiyun 	 *   deactivate_task()		      ttwu_queue_wakelist())
818*4882a593Smuzhiyun 	 *     p->on_rq = 0;			p->sched_remote_wakeup = Y;
819*4882a593Smuzhiyun 	 *
820*4882a593Smuzhiyun 	 * guarantees all stores of 'current' are visible before
821*4882a593Smuzhiyun 	 * ->sched_remote_wakeup gets used, so it can be in this word.
822*4882a593Smuzhiyun 	 */
823*4882a593Smuzhiyun 	unsigned			sched_remote_wakeup:1;
824*4882a593Smuzhiyun 
825*4882a593Smuzhiyun 	/* Bit to tell LSMs we're in execve(): */
826*4882a593Smuzhiyun 	unsigned			in_execve:1;
827*4882a593Smuzhiyun 	unsigned			in_iowait:1;
828*4882a593Smuzhiyun #ifndef TIF_RESTORE_SIGMASK
829*4882a593Smuzhiyun 	unsigned			restore_sigmask:1;
830*4882a593Smuzhiyun #endif
831*4882a593Smuzhiyun #ifdef CONFIG_MEMCG
832*4882a593Smuzhiyun 	unsigned			in_user_fault:1;
833*4882a593Smuzhiyun #endif
834*4882a593Smuzhiyun #ifdef CONFIG_COMPAT_BRK
835*4882a593Smuzhiyun 	unsigned			brk_randomized:1;
836*4882a593Smuzhiyun #endif
837*4882a593Smuzhiyun #ifdef CONFIG_CGROUPS
838*4882a593Smuzhiyun 	/* disallow userland-initiated cgroup migration */
839*4882a593Smuzhiyun 	unsigned			no_cgroup_migration:1;
840*4882a593Smuzhiyun 	/* task is frozen/stopped (used by the cgroup freezer) */
841*4882a593Smuzhiyun 	unsigned			frozen:1;
842*4882a593Smuzhiyun #endif
843*4882a593Smuzhiyun #ifdef CONFIG_BLK_CGROUP
844*4882a593Smuzhiyun 	unsigned			use_memdelay:1;
845*4882a593Smuzhiyun #endif
846*4882a593Smuzhiyun #ifdef CONFIG_PSI
847*4882a593Smuzhiyun 	/* Stalled due to lack of memory */
848*4882a593Smuzhiyun 	unsigned			in_memstall:1;
849*4882a593Smuzhiyun #endif
850*4882a593Smuzhiyun 
851*4882a593Smuzhiyun 	unsigned long			atomic_flags; /* Flags requiring atomic access. */
852*4882a593Smuzhiyun 
853*4882a593Smuzhiyun 	struct restart_block		restart_block;
854*4882a593Smuzhiyun 
855*4882a593Smuzhiyun 	pid_t				pid;
856*4882a593Smuzhiyun 	pid_t				tgid;
857*4882a593Smuzhiyun 
858*4882a593Smuzhiyun #ifdef CONFIG_STACKPROTECTOR
859*4882a593Smuzhiyun 	/* Canary value for the -fstack-protector GCC feature: */
860*4882a593Smuzhiyun 	unsigned long			stack_canary;
861*4882a593Smuzhiyun #endif
862*4882a593Smuzhiyun 	/*
863*4882a593Smuzhiyun 	 * Pointers to the (original) parent process, youngest child, younger sibling,
864*4882a593Smuzhiyun 	 * older sibling, respectively.  (p->father can be replaced with
865*4882a593Smuzhiyun 	 * p->real_parent->pid)
866*4882a593Smuzhiyun 	 */
867*4882a593Smuzhiyun 
868*4882a593Smuzhiyun 	/* Real parent process: */
869*4882a593Smuzhiyun 	struct task_struct __rcu	*real_parent;
870*4882a593Smuzhiyun 
871*4882a593Smuzhiyun 	/* Recipient of SIGCHLD, wait4() reports: */
872*4882a593Smuzhiyun 	struct task_struct __rcu	*parent;
873*4882a593Smuzhiyun 
874*4882a593Smuzhiyun 	/*
875*4882a593Smuzhiyun 	 * Children/sibling form the list of natural children:
876*4882a593Smuzhiyun 	 */
877*4882a593Smuzhiyun 	struct list_head		children;
878*4882a593Smuzhiyun 	struct list_head		sibling;
879*4882a593Smuzhiyun 	struct task_struct		*group_leader;
880*4882a593Smuzhiyun 
881*4882a593Smuzhiyun 	/*
882*4882a593Smuzhiyun 	 * 'ptraced' is the list of tasks this task is using ptrace() on.
883*4882a593Smuzhiyun 	 *
884*4882a593Smuzhiyun 	 * This includes both natural children and PTRACE_ATTACH targets.
885*4882a593Smuzhiyun 	 * 'ptrace_entry' is this task's link on the p->parent->ptraced list.
886*4882a593Smuzhiyun 	 */
887*4882a593Smuzhiyun 	struct list_head		ptraced;
888*4882a593Smuzhiyun 	struct list_head		ptrace_entry;
889*4882a593Smuzhiyun 
890*4882a593Smuzhiyun 	/* PID/PID hash table linkage. */
891*4882a593Smuzhiyun 	struct pid			*thread_pid;
892*4882a593Smuzhiyun 	struct hlist_node		pid_links[PIDTYPE_MAX];
893*4882a593Smuzhiyun 	struct list_head		thread_group;
894*4882a593Smuzhiyun 	struct list_head		thread_node;
895*4882a593Smuzhiyun 
896*4882a593Smuzhiyun 	struct completion		*vfork_done;
897*4882a593Smuzhiyun 
898*4882a593Smuzhiyun 	/* CLONE_CHILD_SETTID: */
899*4882a593Smuzhiyun 	int __user			*set_child_tid;
900*4882a593Smuzhiyun 
901*4882a593Smuzhiyun 	/* CLONE_CHILD_CLEARTID: */
902*4882a593Smuzhiyun 	int __user			*clear_child_tid;
903*4882a593Smuzhiyun 
904*4882a593Smuzhiyun 	u64				utime;
905*4882a593Smuzhiyun 	u64				stime;
906*4882a593Smuzhiyun #ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
907*4882a593Smuzhiyun 	u64				utimescaled;
908*4882a593Smuzhiyun 	u64				stimescaled;
909*4882a593Smuzhiyun #endif
910*4882a593Smuzhiyun 	u64				gtime;
911*4882a593Smuzhiyun #ifdef CONFIG_CPU_FREQ_TIMES
912*4882a593Smuzhiyun 	u64				*time_in_state;
913*4882a593Smuzhiyun 	unsigned int			max_state;
914*4882a593Smuzhiyun #endif
915*4882a593Smuzhiyun 	struct prev_cputime		prev_cputime;
916*4882a593Smuzhiyun #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
917*4882a593Smuzhiyun 	struct vtime			vtime;
918*4882a593Smuzhiyun #endif
919*4882a593Smuzhiyun 
920*4882a593Smuzhiyun #ifdef CONFIG_NO_HZ_FULL
921*4882a593Smuzhiyun 	atomic_t			tick_dep_mask;
922*4882a593Smuzhiyun #endif
923*4882a593Smuzhiyun 	/* Context switch counts: */
924*4882a593Smuzhiyun 	unsigned long			nvcsw;
925*4882a593Smuzhiyun 	unsigned long			nivcsw;
926*4882a593Smuzhiyun 
927*4882a593Smuzhiyun 	/* Monotonic time in nsecs: */
928*4882a593Smuzhiyun 	u64				start_time;
929*4882a593Smuzhiyun 
930*4882a593Smuzhiyun 	/* Boot based time in nsecs: */
931*4882a593Smuzhiyun 	u64				start_boottime;
932*4882a593Smuzhiyun 
933*4882a593Smuzhiyun 	/* MM fault and swap info: this can arguably be seen as either mm-specific or thread-specific: */
934*4882a593Smuzhiyun 	unsigned long			min_flt;
935*4882a593Smuzhiyun 	unsigned long			maj_flt;
936*4882a593Smuzhiyun 
937*4882a593Smuzhiyun 	/* Empty if CONFIG_POSIX_CPUTIMERS=n */
938*4882a593Smuzhiyun 	struct posix_cputimers		posix_cputimers;
939*4882a593Smuzhiyun 
940*4882a593Smuzhiyun #ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK
941*4882a593Smuzhiyun 	struct posix_cputimers_work	posix_cputimers_work;
942*4882a593Smuzhiyun #endif
943*4882a593Smuzhiyun 
944*4882a593Smuzhiyun 	/* Process credentials: */
945*4882a593Smuzhiyun 
946*4882a593Smuzhiyun 	/* Tracer's credentials at attach: */
947*4882a593Smuzhiyun 	const struct cred __rcu		*ptracer_cred;
948*4882a593Smuzhiyun 
949*4882a593Smuzhiyun 	/* Objective and real subjective task credentials (COW): */
950*4882a593Smuzhiyun 	const struct cred __rcu		*real_cred;
951*4882a593Smuzhiyun 
952*4882a593Smuzhiyun 	/* Effective (overridable) subjective task credentials (COW): */
953*4882a593Smuzhiyun 	const struct cred __rcu		*cred;
954*4882a593Smuzhiyun 
955*4882a593Smuzhiyun #ifdef CONFIG_KEYS
956*4882a593Smuzhiyun 	/* Cached requested key. */
957*4882a593Smuzhiyun 	struct key			*cached_requested_key;
958*4882a593Smuzhiyun #endif
959*4882a593Smuzhiyun 
960*4882a593Smuzhiyun 	/*
961*4882a593Smuzhiyun 	 * executable name, excluding path.
962*4882a593Smuzhiyun 	 *
963*4882a593Smuzhiyun 	 * - normally initialized setup_new_exec()
964*4882a593Smuzhiyun 	 * - access it with [gs]et_task_comm()
965*4882a593Smuzhiyun 	 * - lock it with task_lock()
966*4882a593Smuzhiyun 	 */
967*4882a593Smuzhiyun 	char				comm[TASK_COMM_LEN];
968*4882a593Smuzhiyun 
969*4882a593Smuzhiyun 	struct nameidata		*nameidata;
970*4882a593Smuzhiyun 
971*4882a593Smuzhiyun #ifdef CONFIG_SYSVIPC
972*4882a593Smuzhiyun 	struct sysv_sem			sysvsem;
973*4882a593Smuzhiyun 	struct sysv_shm			sysvshm;
974*4882a593Smuzhiyun #endif
975*4882a593Smuzhiyun #ifdef CONFIG_DETECT_HUNG_TASK
976*4882a593Smuzhiyun 	unsigned long			last_switch_count;
977*4882a593Smuzhiyun 	unsigned long			last_switch_time;
978*4882a593Smuzhiyun #endif
979*4882a593Smuzhiyun 	/* Filesystem information: */
980*4882a593Smuzhiyun 	struct fs_struct		*fs;
981*4882a593Smuzhiyun 
982*4882a593Smuzhiyun 	/* Open file information: */
983*4882a593Smuzhiyun 	struct files_struct		*files;
984*4882a593Smuzhiyun 
985*4882a593Smuzhiyun #ifdef CONFIG_IO_URING
986*4882a593Smuzhiyun 	struct io_uring_task		*io_uring;
987*4882a593Smuzhiyun #endif
988*4882a593Smuzhiyun 
989*4882a593Smuzhiyun 	/* Namespaces: */
990*4882a593Smuzhiyun 	struct nsproxy			*nsproxy;
991*4882a593Smuzhiyun 
992*4882a593Smuzhiyun 	/* Signal handlers: */
993*4882a593Smuzhiyun 	struct signal_struct		*signal;
994*4882a593Smuzhiyun 	struct sighand_struct __rcu		*sighand;
995*4882a593Smuzhiyun 	sigset_t			blocked;
996*4882a593Smuzhiyun 	sigset_t			real_blocked;
997*4882a593Smuzhiyun 	/* Restored if set_restore_sigmask() was used: */
998*4882a593Smuzhiyun 	sigset_t			saved_sigmask;
999*4882a593Smuzhiyun 	struct sigpending		pending;
1000*4882a593Smuzhiyun 	unsigned long			sas_ss_sp;
1001*4882a593Smuzhiyun 	size_t				sas_ss_size;
1002*4882a593Smuzhiyun 	unsigned int			sas_ss_flags;
1003*4882a593Smuzhiyun 
1004*4882a593Smuzhiyun 	struct callback_head		*task_works;
1005*4882a593Smuzhiyun 
1006*4882a593Smuzhiyun #ifdef CONFIG_AUDIT
1007*4882a593Smuzhiyun #ifdef CONFIG_AUDITSYSCALL
1008*4882a593Smuzhiyun 	struct audit_context		*audit_context;
1009*4882a593Smuzhiyun #endif
1010*4882a593Smuzhiyun 	kuid_t				loginuid;
1011*4882a593Smuzhiyun 	unsigned int			sessionid;
1012*4882a593Smuzhiyun #endif
1013*4882a593Smuzhiyun 	struct seccomp			seccomp;
1014*4882a593Smuzhiyun 
1015*4882a593Smuzhiyun 	/* Thread group tracking: */
1016*4882a593Smuzhiyun 	u64				parent_exec_id;
1017*4882a593Smuzhiyun 	u64				self_exec_id;
1018*4882a593Smuzhiyun 
1019*4882a593Smuzhiyun 	/* Protection against (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed, mempolicy: */
1020*4882a593Smuzhiyun 	spinlock_t			alloc_lock;
1021*4882a593Smuzhiyun 
1022*4882a593Smuzhiyun 	/* Protection of the PI data structures: */
1023*4882a593Smuzhiyun 	raw_spinlock_t			pi_lock;
1024*4882a593Smuzhiyun 
1025*4882a593Smuzhiyun 	struct wake_q_node		wake_q;
1026*4882a593Smuzhiyun 	int				wake_q_count;
1027*4882a593Smuzhiyun 
1028*4882a593Smuzhiyun #ifdef CONFIG_RT_MUTEXES
1029*4882a593Smuzhiyun 	/* PI waiters blocked on a rt_mutex held by this task: */
1030*4882a593Smuzhiyun 	struct rb_root_cached		pi_waiters;
1031*4882a593Smuzhiyun 	/* Updated under owner's pi_lock and rq lock */
1032*4882a593Smuzhiyun 	struct task_struct		*pi_top_task;
1033*4882a593Smuzhiyun 	/* Deadlock detection and priority inheritance handling: */
1034*4882a593Smuzhiyun 	struct rt_mutex_waiter		*pi_blocked_on;
1035*4882a593Smuzhiyun #endif
1036*4882a593Smuzhiyun 
1037*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_MUTEXES
1038*4882a593Smuzhiyun 	/* Mutex deadlock detection: */
1039*4882a593Smuzhiyun 	struct mutex_waiter		*blocked_on;
1040*4882a593Smuzhiyun #endif
1041*4882a593Smuzhiyun 
1042*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
1043*4882a593Smuzhiyun 	int				non_block_count;
1044*4882a593Smuzhiyun #endif
1045*4882a593Smuzhiyun 
1046*4882a593Smuzhiyun #ifdef CONFIG_TRACE_IRQFLAGS
1047*4882a593Smuzhiyun 	struct irqtrace_events		irqtrace;
1048*4882a593Smuzhiyun 	unsigned int			hardirq_threaded;
1049*4882a593Smuzhiyun 	u64				hardirq_chain_key;
1050*4882a593Smuzhiyun 	int				softirqs_enabled;
1051*4882a593Smuzhiyun 	int				softirq_context;
1052*4882a593Smuzhiyun 	int				irq_config;
1053*4882a593Smuzhiyun #endif
1054*4882a593Smuzhiyun 
1055*4882a593Smuzhiyun #ifdef CONFIG_LOCKDEP
1056*4882a593Smuzhiyun # define MAX_LOCK_DEPTH			48UL
1057*4882a593Smuzhiyun 	u64				curr_chain_key;
1058*4882a593Smuzhiyun 	int				lockdep_depth;
1059*4882a593Smuzhiyun 	unsigned int			lockdep_recursion;
1060*4882a593Smuzhiyun 	struct held_lock		held_locks[MAX_LOCK_DEPTH];
1061*4882a593Smuzhiyun #endif
1062*4882a593Smuzhiyun 
1063*4882a593Smuzhiyun #if defined(CONFIG_UBSAN) && !defined(CONFIG_UBSAN_TRAP)
1064*4882a593Smuzhiyun 	unsigned int			in_ubsan;
1065*4882a593Smuzhiyun #endif
1066*4882a593Smuzhiyun 
1067*4882a593Smuzhiyun 	/* Journalling filesystem info: */
1068*4882a593Smuzhiyun 	void				*journal_info;
1069*4882a593Smuzhiyun 
1070*4882a593Smuzhiyun 	/* Stacked block device info: */
1071*4882a593Smuzhiyun 	struct bio_list			*bio_list;
1072*4882a593Smuzhiyun 
1073*4882a593Smuzhiyun #ifdef CONFIG_BLOCK
1074*4882a593Smuzhiyun 	/* Stack plugging: */
1075*4882a593Smuzhiyun 	struct blk_plug			*plug;
1076*4882a593Smuzhiyun #endif
1077*4882a593Smuzhiyun 
1078*4882a593Smuzhiyun 	/* VM state: */
1079*4882a593Smuzhiyun 	struct reclaim_state		*reclaim_state;
1080*4882a593Smuzhiyun 
1081*4882a593Smuzhiyun 	struct backing_dev_info		*backing_dev_info;
1082*4882a593Smuzhiyun 
1083*4882a593Smuzhiyun 	struct io_context		*io_context;
1084*4882a593Smuzhiyun 
1085*4882a593Smuzhiyun #ifdef CONFIG_COMPACTION
1086*4882a593Smuzhiyun 	struct capture_control		*capture_control;
1087*4882a593Smuzhiyun #endif
1088*4882a593Smuzhiyun 	/* Ptrace state: */
1089*4882a593Smuzhiyun 	unsigned long			ptrace_message;
1090*4882a593Smuzhiyun 	kernel_siginfo_t		*last_siginfo;
1091*4882a593Smuzhiyun 
1092*4882a593Smuzhiyun 	struct task_io_accounting	ioac;
1093*4882a593Smuzhiyun #ifdef CONFIG_PSI
1094*4882a593Smuzhiyun 	/* Pressure stall state */
1095*4882a593Smuzhiyun 	unsigned int			psi_flags;
1096*4882a593Smuzhiyun #endif
1097*4882a593Smuzhiyun #ifdef CONFIG_TASK_XACCT
1098*4882a593Smuzhiyun 	/* Accumulated RSS usage: */
1099*4882a593Smuzhiyun 	u64				acct_rss_mem1;
1100*4882a593Smuzhiyun 	/* Accumulated virtual memory usage: */
1101*4882a593Smuzhiyun 	u64				acct_vm_mem1;
1102*4882a593Smuzhiyun 	/* stime + utime since last update: */
1103*4882a593Smuzhiyun 	u64				acct_timexpd;
1104*4882a593Smuzhiyun #endif
1105*4882a593Smuzhiyun #ifdef CONFIG_CPUSETS
1106*4882a593Smuzhiyun 	/* Protected by ->alloc_lock: */
1107*4882a593Smuzhiyun 	nodemask_t			mems_allowed;
1108*4882a593Smuzhiyun 	/* Seqence number to catch updates: */
1109*4882a593Smuzhiyun 	seqcount_spinlock_t		mems_allowed_seq;
1110*4882a593Smuzhiyun 	int				cpuset_mem_spread_rotor;
1111*4882a593Smuzhiyun 	int				cpuset_slab_spread_rotor;
1112*4882a593Smuzhiyun #endif
1113*4882a593Smuzhiyun #ifdef CONFIG_CGROUPS
1114*4882a593Smuzhiyun 	/* Control Group info protected by css_set_lock: */
1115*4882a593Smuzhiyun 	struct css_set __rcu		*cgroups;
1116*4882a593Smuzhiyun 	/* cg_list protected by css_set_lock and tsk->alloc_lock: */
1117*4882a593Smuzhiyun 	struct list_head		cg_list;
1118*4882a593Smuzhiyun #endif
1119*4882a593Smuzhiyun #ifdef CONFIG_X86_CPU_RESCTRL
1120*4882a593Smuzhiyun 	u32				closid;
1121*4882a593Smuzhiyun 	u32				rmid;
1122*4882a593Smuzhiyun #endif
1123*4882a593Smuzhiyun #ifdef CONFIG_FUTEX
1124*4882a593Smuzhiyun 	struct robust_list_head __user	*robust_list;
1125*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
1126*4882a593Smuzhiyun 	struct compat_robust_list_head __user *compat_robust_list;
1127*4882a593Smuzhiyun #endif
1128*4882a593Smuzhiyun 	struct list_head		pi_state_list;
1129*4882a593Smuzhiyun 	struct futex_pi_state		*pi_state_cache;
1130*4882a593Smuzhiyun 	struct mutex			futex_exit_mutex;
1131*4882a593Smuzhiyun 	unsigned int			futex_state;
1132*4882a593Smuzhiyun #endif
1133*4882a593Smuzhiyun #ifdef CONFIG_PERF_EVENTS
1134*4882a593Smuzhiyun 	struct perf_event_context	*perf_event_ctxp[perf_nr_task_contexts];
1135*4882a593Smuzhiyun 	struct mutex			perf_event_mutex;
1136*4882a593Smuzhiyun 	struct list_head		perf_event_list;
1137*4882a593Smuzhiyun #endif
1138*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_PREEMPT
1139*4882a593Smuzhiyun 	unsigned long			preempt_disable_ip;
1140*4882a593Smuzhiyun #endif
1141*4882a593Smuzhiyun #ifdef CONFIG_NUMA
1142*4882a593Smuzhiyun 	/* Protected by alloc_lock: */
1143*4882a593Smuzhiyun 	struct mempolicy		*mempolicy;
1144*4882a593Smuzhiyun 	short				il_prev;
1145*4882a593Smuzhiyun 	short				pref_node_fork;
1146*4882a593Smuzhiyun #endif
1147*4882a593Smuzhiyun #ifdef CONFIG_NUMA_BALANCING
1148*4882a593Smuzhiyun 	int				numa_scan_seq;
1149*4882a593Smuzhiyun 	unsigned int			numa_scan_period;
1150*4882a593Smuzhiyun 	unsigned int			numa_scan_period_max;
1151*4882a593Smuzhiyun 	int				numa_preferred_nid;
1152*4882a593Smuzhiyun 	unsigned long			numa_migrate_retry;
1153*4882a593Smuzhiyun 	/* Migration stamp: */
1154*4882a593Smuzhiyun 	u64				node_stamp;
1155*4882a593Smuzhiyun 	u64				last_task_numa_placement;
1156*4882a593Smuzhiyun 	u64				last_sum_exec_runtime;
1157*4882a593Smuzhiyun 	struct callback_head		numa_work;
1158*4882a593Smuzhiyun 
1159*4882a593Smuzhiyun 	/*
1160*4882a593Smuzhiyun 	 * This pointer is only modified for current in syscall and
1161*4882a593Smuzhiyun 	 * pagefault context (and for tasks being destroyed), so it can be read
1162*4882a593Smuzhiyun 	 * from any of the following contexts:
1163*4882a593Smuzhiyun 	 *  - RCU read-side critical section
1164*4882a593Smuzhiyun 	 *  - current->numa_group from everywhere
1165*4882a593Smuzhiyun 	 *  - task's runqueue locked, task not running
1166*4882a593Smuzhiyun 	 */
1167*4882a593Smuzhiyun 	struct numa_group __rcu		*numa_group;
1168*4882a593Smuzhiyun 
1169*4882a593Smuzhiyun 	/*
1170*4882a593Smuzhiyun 	 * numa_faults is an array split into four regions:
1171*4882a593Smuzhiyun 	 * faults_memory, faults_cpu, faults_memory_buffer, faults_cpu_buffer
1172*4882a593Smuzhiyun 	 * in this precise order.
1173*4882a593Smuzhiyun 	 *
1174*4882a593Smuzhiyun 	 * faults_memory: Exponential decaying average of faults on a per-node
1175*4882a593Smuzhiyun 	 * basis. Scheduling placement decisions are made based on these
1176*4882a593Smuzhiyun 	 * counts. The values remain static for the duration of a PTE scan.
1177*4882a593Smuzhiyun 	 * faults_cpu: Track the nodes the process was running on when a NUMA
1178*4882a593Smuzhiyun 	 * hinting fault was incurred.
1179*4882a593Smuzhiyun 	 * faults_memory_buffer and faults_cpu_buffer: Record faults per node
1180*4882a593Smuzhiyun 	 * during the current scan window. When the scan completes, the counts
1181*4882a593Smuzhiyun 	 * in faults_memory and faults_cpu decay and these values are copied.
1182*4882a593Smuzhiyun 	 */
1183*4882a593Smuzhiyun 	unsigned long			*numa_faults;
1184*4882a593Smuzhiyun 	unsigned long			total_numa_faults;
1185*4882a593Smuzhiyun 
1186*4882a593Smuzhiyun 	/*
1187*4882a593Smuzhiyun 	 * numa_faults_locality tracks if faults recorded during the last
1188*4882a593Smuzhiyun 	 * scan window were remote/local or failed to migrate. The task scan
1189*4882a593Smuzhiyun 	 * period is adapted based on the locality of the faults with different
1190*4882a593Smuzhiyun 	 * weights depending on whether they were shared or private faults
1191*4882a593Smuzhiyun 	 */
1192*4882a593Smuzhiyun 	unsigned long			numa_faults_locality[3];
1193*4882a593Smuzhiyun 
1194*4882a593Smuzhiyun 	unsigned long			numa_pages_migrated;
1195*4882a593Smuzhiyun #endif /* CONFIG_NUMA_BALANCING */
1196*4882a593Smuzhiyun 
1197*4882a593Smuzhiyun #ifdef CONFIG_RSEQ
1198*4882a593Smuzhiyun 	struct rseq __user *rseq;
1199*4882a593Smuzhiyun 	u32 rseq_sig;
1200*4882a593Smuzhiyun 	/*
1201*4882a593Smuzhiyun 	 * RmW on rseq_event_mask must be performed atomically
1202*4882a593Smuzhiyun 	 * with respect to preemption.
1203*4882a593Smuzhiyun 	 */
1204*4882a593Smuzhiyun 	unsigned long rseq_event_mask;
1205*4882a593Smuzhiyun #endif
1206*4882a593Smuzhiyun 
1207*4882a593Smuzhiyun 	struct tlbflush_unmap_batch	tlb_ubc;
1208*4882a593Smuzhiyun 
1209*4882a593Smuzhiyun 	union {
1210*4882a593Smuzhiyun 		refcount_t		rcu_users;
1211*4882a593Smuzhiyun 		struct rcu_head		rcu;
1212*4882a593Smuzhiyun 	};
1213*4882a593Smuzhiyun 
1214*4882a593Smuzhiyun 	/* Cache last used pipe for splice(): */
1215*4882a593Smuzhiyun 	struct pipe_inode_info		*splice_pipe;
1216*4882a593Smuzhiyun 
1217*4882a593Smuzhiyun 	struct page_frag		task_frag;
1218*4882a593Smuzhiyun 
1219*4882a593Smuzhiyun #ifdef CONFIG_TASK_DELAY_ACCT
1220*4882a593Smuzhiyun 	struct task_delay_info		*delays;
1221*4882a593Smuzhiyun #endif
1222*4882a593Smuzhiyun 
1223*4882a593Smuzhiyun #ifdef CONFIG_FAULT_INJECTION
1224*4882a593Smuzhiyun 	int				make_it_fail;
1225*4882a593Smuzhiyun 	unsigned int			fail_nth;
1226*4882a593Smuzhiyun #endif
1227*4882a593Smuzhiyun 	/*
1228*4882a593Smuzhiyun 	 * When (nr_dirtied >= nr_dirtied_pause), it's time to call
1229*4882a593Smuzhiyun 	 * balance_dirty_pages() for a dirty throttling pause:
1230*4882a593Smuzhiyun 	 */
1231*4882a593Smuzhiyun 	int				nr_dirtied;
1232*4882a593Smuzhiyun 	int				nr_dirtied_pause;
1233*4882a593Smuzhiyun 	/* Start of a write-and-pause period: */
1234*4882a593Smuzhiyun 	unsigned long			dirty_paused_when;
1235*4882a593Smuzhiyun 
1236*4882a593Smuzhiyun #ifdef CONFIG_LATENCYTOP
1237*4882a593Smuzhiyun 	int				latency_record_count;
1238*4882a593Smuzhiyun 	struct latency_record		latency_record[LT_SAVECOUNT];
1239*4882a593Smuzhiyun #endif
1240*4882a593Smuzhiyun 	/*
1241*4882a593Smuzhiyun 	 * Time slack values; these are used to round up poll() and
1242*4882a593Smuzhiyun 	 * select() etc timeout values. These are in nanoseconds.
1243*4882a593Smuzhiyun 	 */
1244*4882a593Smuzhiyun 	u64				timer_slack_ns;
1245*4882a593Smuzhiyun 	u64				default_timer_slack_ns;
1246*4882a593Smuzhiyun 
1247*4882a593Smuzhiyun #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
1248*4882a593Smuzhiyun 	unsigned int			kasan_depth;
1249*4882a593Smuzhiyun #endif
1250*4882a593Smuzhiyun 
1251*4882a593Smuzhiyun #ifdef CONFIG_KCSAN
1252*4882a593Smuzhiyun 	struct kcsan_ctx		kcsan_ctx;
1253*4882a593Smuzhiyun #ifdef CONFIG_TRACE_IRQFLAGS
1254*4882a593Smuzhiyun 	struct irqtrace_events		kcsan_save_irqtrace;
1255*4882a593Smuzhiyun #endif
1256*4882a593Smuzhiyun #endif
1257*4882a593Smuzhiyun 
1258*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_KUNIT)
1259*4882a593Smuzhiyun 	struct kunit			*kunit_test;
1260*4882a593Smuzhiyun #endif
1261*4882a593Smuzhiyun 
1262*4882a593Smuzhiyun #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1263*4882a593Smuzhiyun 	/* Index of current stored address in ret_stack: */
1264*4882a593Smuzhiyun 	int				curr_ret_stack;
1265*4882a593Smuzhiyun 	int				curr_ret_depth;
1266*4882a593Smuzhiyun 
1267*4882a593Smuzhiyun 	/* Stack of return addresses for return function tracing: */
1268*4882a593Smuzhiyun 	struct ftrace_ret_stack		*ret_stack;
1269*4882a593Smuzhiyun 
1270*4882a593Smuzhiyun 	/* Timestamp for last schedule: */
1271*4882a593Smuzhiyun 	unsigned long long		ftrace_timestamp;
1272*4882a593Smuzhiyun 
1273*4882a593Smuzhiyun 	/*
1274*4882a593Smuzhiyun 	 * Number of functions that haven't been traced
1275*4882a593Smuzhiyun 	 * because of depth overrun:
1276*4882a593Smuzhiyun 	 */
1277*4882a593Smuzhiyun 	atomic_t			trace_overrun;
1278*4882a593Smuzhiyun 
1279*4882a593Smuzhiyun 	/* Pause tracing: */
1280*4882a593Smuzhiyun 	atomic_t			tracing_graph_pause;
1281*4882a593Smuzhiyun #endif
1282*4882a593Smuzhiyun 
1283*4882a593Smuzhiyun #ifdef CONFIG_TRACING
1284*4882a593Smuzhiyun 	/* State flags for use by tracers: */
1285*4882a593Smuzhiyun 	unsigned long			trace;
1286*4882a593Smuzhiyun 
1287*4882a593Smuzhiyun 	/* Bitmask and counter of trace recursion: */
1288*4882a593Smuzhiyun 	unsigned long			trace_recursion;
1289*4882a593Smuzhiyun #endif /* CONFIG_TRACING */
1290*4882a593Smuzhiyun 
1291*4882a593Smuzhiyun #ifdef CONFIG_KCOV
1292*4882a593Smuzhiyun 	/* See kernel/kcov.c for more details. */
1293*4882a593Smuzhiyun 
1294*4882a593Smuzhiyun 	/* Coverage collection mode enabled for this task (0 if disabled): */
1295*4882a593Smuzhiyun 	unsigned int			kcov_mode;
1296*4882a593Smuzhiyun 
1297*4882a593Smuzhiyun 	/* Size of the kcov_area: */
1298*4882a593Smuzhiyun 	unsigned int			kcov_size;
1299*4882a593Smuzhiyun 
1300*4882a593Smuzhiyun 	/* Buffer for coverage collection: */
1301*4882a593Smuzhiyun 	void				*kcov_area;
1302*4882a593Smuzhiyun 
1303*4882a593Smuzhiyun 	/* KCOV descriptor wired with this task or NULL: */
1304*4882a593Smuzhiyun 	struct kcov			*kcov;
1305*4882a593Smuzhiyun 
1306*4882a593Smuzhiyun 	/* KCOV common handle for remote coverage collection: */
1307*4882a593Smuzhiyun 	u64				kcov_handle;
1308*4882a593Smuzhiyun 
1309*4882a593Smuzhiyun 	/* KCOV sequence number: */
1310*4882a593Smuzhiyun 	int				kcov_sequence;
1311*4882a593Smuzhiyun 
1312*4882a593Smuzhiyun 	/* Collect coverage from softirq context: */
1313*4882a593Smuzhiyun 	unsigned int			kcov_softirq;
1314*4882a593Smuzhiyun #endif
1315*4882a593Smuzhiyun 
1316*4882a593Smuzhiyun #ifdef CONFIG_MEMCG
1317*4882a593Smuzhiyun 	struct mem_cgroup		*memcg_in_oom;
1318*4882a593Smuzhiyun 	gfp_t				memcg_oom_gfp_mask;
1319*4882a593Smuzhiyun 	int				memcg_oom_order;
1320*4882a593Smuzhiyun 
1321*4882a593Smuzhiyun 	/* Number of pages to reclaim on returning to userland: */
1322*4882a593Smuzhiyun 	unsigned int			memcg_nr_pages_over_high;
1323*4882a593Smuzhiyun 
1324*4882a593Smuzhiyun 	/* Used by memcontrol for targeted memcg charge: */
1325*4882a593Smuzhiyun 	struct mem_cgroup		*active_memcg;
1326*4882a593Smuzhiyun #endif
1327*4882a593Smuzhiyun 
1328*4882a593Smuzhiyun #ifdef CONFIG_BLK_CGROUP
1329*4882a593Smuzhiyun 	struct request_queue		*throttle_queue;
1330*4882a593Smuzhiyun #endif
1331*4882a593Smuzhiyun 
1332*4882a593Smuzhiyun #ifdef CONFIG_UPROBES
1333*4882a593Smuzhiyun 	struct uprobe_task		*utask;
1334*4882a593Smuzhiyun #endif
1335*4882a593Smuzhiyun #if defined(CONFIG_BCACHE) || defined(CONFIG_BCACHE_MODULE)
1336*4882a593Smuzhiyun 	unsigned int			sequential_io;
1337*4882a593Smuzhiyun 	unsigned int			sequential_io_avg;
1338*4882a593Smuzhiyun #endif
1339*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
1340*4882a593Smuzhiyun 	unsigned long			task_state_change;
1341*4882a593Smuzhiyun #endif
1342*4882a593Smuzhiyun 	int				pagefault_disabled;
1343*4882a593Smuzhiyun #ifdef CONFIG_MMU
1344*4882a593Smuzhiyun 	struct task_struct		*oom_reaper_list;
1345*4882a593Smuzhiyun #endif
1346*4882a593Smuzhiyun #ifdef CONFIG_VMAP_STACK
1347*4882a593Smuzhiyun 	struct vm_struct		*stack_vm_area;
1348*4882a593Smuzhiyun #endif
1349*4882a593Smuzhiyun #ifdef CONFIG_THREAD_INFO_IN_TASK
1350*4882a593Smuzhiyun 	/* A live task holds one reference: */
1351*4882a593Smuzhiyun 	refcount_t			stack_refcount;
1352*4882a593Smuzhiyun #endif
1353*4882a593Smuzhiyun #ifdef CONFIG_LIVEPATCH
1354*4882a593Smuzhiyun 	int patch_state;
1355*4882a593Smuzhiyun #endif
1356*4882a593Smuzhiyun #ifdef CONFIG_SECURITY
1357*4882a593Smuzhiyun 	/* Used by LSM modules for access restriction: */
1358*4882a593Smuzhiyun 	void				*security;
1359*4882a593Smuzhiyun #endif
1360*4882a593Smuzhiyun 
1361*4882a593Smuzhiyun #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
1362*4882a593Smuzhiyun 	unsigned long			lowest_stack;
1363*4882a593Smuzhiyun 	unsigned long			prev_lowest_stack;
1364*4882a593Smuzhiyun #endif
1365*4882a593Smuzhiyun 
1366*4882a593Smuzhiyun #ifdef CONFIG_X86_MCE
1367*4882a593Smuzhiyun 	void __user			*mce_vaddr;
1368*4882a593Smuzhiyun 	__u64				mce_kflags;
1369*4882a593Smuzhiyun 	u64				mce_addr;
1370*4882a593Smuzhiyun 	__u64				mce_ripv : 1,
1371*4882a593Smuzhiyun 					mce_whole_page : 1,
1372*4882a593Smuzhiyun 					__mce_reserved : 62;
1373*4882a593Smuzhiyun 	struct callback_head		mce_kill_me;
1374*4882a593Smuzhiyun 	int				mce_count;
1375*4882a593Smuzhiyun #endif
1376*4882a593Smuzhiyun 	ANDROID_VENDOR_DATA_ARRAY(1, 64);
1377*4882a593Smuzhiyun 	ANDROID_OEM_DATA_ARRAY(1, 32);
1378*4882a593Smuzhiyun 
1379*4882a593Smuzhiyun 	/* PF_IO_WORKER */
1380*4882a593Smuzhiyun 	ANDROID_KABI_USE(1, void *pf_io_worker);
1381*4882a593Smuzhiyun 
1382*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(2);
1383*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(3);
1384*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(4);
1385*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(5);
1386*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(6);
1387*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(7);
1388*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(8);
1389*4882a593Smuzhiyun 
1390*4882a593Smuzhiyun 	/*
1391*4882a593Smuzhiyun 	 * New fields for task_struct should be added above here, so that
1392*4882a593Smuzhiyun 	 * they are included in the randomized portion of task_struct.
1393*4882a593Smuzhiyun 	 */
1394*4882a593Smuzhiyun 	randomized_struct_fields_end
1395*4882a593Smuzhiyun 
1396*4882a593Smuzhiyun 	/* CPU-specific state of this task: */
1397*4882a593Smuzhiyun 	struct thread_struct		thread;
1398*4882a593Smuzhiyun 
1399*4882a593Smuzhiyun 	/*
1400*4882a593Smuzhiyun 	 * WARNING: on x86, 'thread_struct' contains a variable-sized
1401*4882a593Smuzhiyun 	 * structure.  It *MUST* be at the end of 'task_struct'.
1402*4882a593Smuzhiyun 	 *
1403*4882a593Smuzhiyun 	 * Do not put anything below here!
1404*4882a593Smuzhiyun 	 */
1405*4882a593Smuzhiyun };
1406*4882a593Smuzhiyun 
task_pid(struct task_struct * task)1407*4882a593Smuzhiyun static inline struct pid *task_pid(struct task_struct *task)
1408*4882a593Smuzhiyun {
1409*4882a593Smuzhiyun 	return task->thread_pid;
1410*4882a593Smuzhiyun }
1411*4882a593Smuzhiyun 
1412*4882a593Smuzhiyun /*
1413*4882a593Smuzhiyun  * the helpers to get the task's different pids as they are seen
1414*4882a593Smuzhiyun  * from various namespaces
1415*4882a593Smuzhiyun  *
1416*4882a593Smuzhiyun  * task_xid_nr()     : global id, i.e. the id seen from the init namespace;
1417*4882a593Smuzhiyun  * task_xid_vnr()    : virtual id, i.e. the id seen from the pid namespace of
1418*4882a593Smuzhiyun  *                     current.
1419*4882a593Smuzhiyun  * task_xid_nr_ns()  : id seen from the ns specified;
1420*4882a593Smuzhiyun  *
1421*4882a593Smuzhiyun  * see also pid_nr() etc in include/linux/pid.h
1422*4882a593Smuzhiyun  */
1423*4882a593Smuzhiyun pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, struct pid_namespace *ns);
1424*4882a593Smuzhiyun 
task_pid_nr(struct task_struct * tsk)1425*4882a593Smuzhiyun static inline pid_t task_pid_nr(struct task_struct *tsk)
1426*4882a593Smuzhiyun {
1427*4882a593Smuzhiyun 	return tsk->pid;
1428*4882a593Smuzhiyun }
1429*4882a593Smuzhiyun 
task_pid_nr_ns(struct task_struct * tsk,struct pid_namespace * ns)1430*4882a593Smuzhiyun static inline pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
1431*4882a593Smuzhiyun {
1432*4882a593Smuzhiyun 	return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
1433*4882a593Smuzhiyun }
1434*4882a593Smuzhiyun 
task_pid_vnr(struct task_struct * tsk)1435*4882a593Smuzhiyun static inline pid_t task_pid_vnr(struct task_struct *tsk)
1436*4882a593Smuzhiyun {
1437*4882a593Smuzhiyun 	return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
1438*4882a593Smuzhiyun }
1439*4882a593Smuzhiyun 
1440*4882a593Smuzhiyun 
task_tgid_nr(struct task_struct * tsk)1441*4882a593Smuzhiyun static inline pid_t task_tgid_nr(struct task_struct *tsk)
1442*4882a593Smuzhiyun {
1443*4882a593Smuzhiyun 	return tsk->tgid;
1444*4882a593Smuzhiyun }
1445*4882a593Smuzhiyun 
1446*4882a593Smuzhiyun /**
1447*4882a593Smuzhiyun  * pid_alive - check that a task structure is not stale
1448*4882a593Smuzhiyun  * @p: Task structure to be checked.
1449*4882a593Smuzhiyun  *
1450*4882a593Smuzhiyun  * Test if a process is not yet dead (at most zombie state)
1451*4882a593Smuzhiyun  * If pid_alive fails, then pointers within the task structure
1452*4882a593Smuzhiyun  * can be stale and must not be dereferenced.
1453*4882a593Smuzhiyun  *
1454*4882a593Smuzhiyun  * Return: 1 if the process is alive. 0 otherwise.
1455*4882a593Smuzhiyun  */
pid_alive(const struct task_struct * p)1456*4882a593Smuzhiyun static inline int pid_alive(const struct task_struct *p)
1457*4882a593Smuzhiyun {
1458*4882a593Smuzhiyun 	return p->thread_pid != NULL;
1459*4882a593Smuzhiyun }
1460*4882a593Smuzhiyun 
task_pgrp_nr_ns(struct task_struct * tsk,struct pid_namespace * ns)1461*4882a593Smuzhiyun static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
1462*4882a593Smuzhiyun {
1463*4882a593Smuzhiyun 	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
1464*4882a593Smuzhiyun }
1465*4882a593Smuzhiyun 
task_pgrp_vnr(struct task_struct * tsk)1466*4882a593Smuzhiyun static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
1467*4882a593Smuzhiyun {
1468*4882a593Smuzhiyun 	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
1469*4882a593Smuzhiyun }
1470*4882a593Smuzhiyun 
1471*4882a593Smuzhiyun 
task_session_nr_ns(struct task_struct * tsk,struct pid_namespace * ns)1472*4882a593Smuzhiyun static inline pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
1473*4882a593Smuzhiyun {
1474*4882a593Smuzhiyun 	return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
1475*4882a593Smuzhiyun }
1476*4882a593Smuzhiyun 
task_session_vnr(struct task_struct * tsk)1477*4882a593Smuzhiyun static inline pid_t task_session_vnr(struct task_struct *tsk)
1478*4882a593Smuzhiyun {
1479*4882a593Smuzhiyun 	return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
1480*4882a593Smuzhiyun }
1481*4882a593Smuzhiyun 
task_tgid_nr_ns(struct task_struct * tsk,struct pid_namespace * ns)1482*4882a593Smuzhiyun static inline pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
1483*4882a593Smuzhiyun {
1484*4882a593Smuzhiyun 	return __task_pid_nr_ns(tsk, PIDTYPE_TGID, ns);
1485*4882a593Smuzhiyun }
1486*4882a593Smuzhiyun 
task_tgid_vnr(struct task_struct * tsk)1487*4882a593Smuzhiyun static inline pid_t task_tgid_vnr(struct task_struct *tsk)
1488*4882a593Smuzhiyun {
1489*4882a593Smuzhiyun 	return __task_pid_nr_ns(tsk, PIDTYPE_TGID, NULL);
1490*4882a593Smuzhiyun }
1491*4882a593Smuzhiyun 
task_ppid_nr_ns(const struct task_struct * tsk,struct pid_namespace * ns)1492*4882a593Smuzhiyun static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)
1493*4882a593Smuzhiyun {
1494*4882a593Smuzhiyun 	pid_t pid = 0;
1495*4882a593Smuzhiyun 
1496*4882a593Smuzhiyun 	rcu_read_lock();
1497*4882a593Smuzhiyun 	if (pid_alive(tsk))
1498*4882a593Smuzhiyun 		pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);
1499*4882a593Smuzhiyun 	rcu_read_unlock();
1500*4882a593Smuzhiyun 
1501*4882a593Smuzhiyun 	return pid;
1502*4882a593Smuzhiyun }
1503*4882a593Smuzhiyun 
task_ppid_nr(const struct task_struct * tsk)1504*4882a593Smuzhiyun static inline pid_t task_ppid_nr(const struct task_struct *tsk)
1505*4882a593Smuzhiyun {
1506*4882a593Smuzhiyun 	return task_ppid_nr_ns(tsk, &init_pid_ns);
1507*4882a593Smuzhiyun }
1508*4882a593Smuzhiyun 
1509*4882a593Smuzhiyun /* Obsolete, do not use: */
task_pgrp_nr(struct task_struct * tsk)1510*4882a593Smuzhiyun static inline pid_t task_pgrp_nr(struct task_struct *tsk)
1511*4882a593Smuzhiyun {
1512*4882a593Smuzhiyun 	return task_pgrp_nr_ns(tsk, &init_pid_ns);
1513*4882a593Smuzhiyun }
1514*4882a593Smuzhiyun 
1515*4882a593Smuzhiyun #define TASK_REPORT_IDLE	(TASK_REPORT + 1)
1516*4882a593Smuzhiyun #define TASK_REPORT_MAX		(TASK_REPORT_IDLE << 1)
1517*4882a593Smuzhiyun 
task_state_index(struct task_struct * tsk)1518*4882a593Smuzhiyun static inline unsigned int task_state_index(struct task_struct *tsk)
1519*4882a593Smuzhiyun {
1520*4882a593Smuzhiyun 	unsigned int tsk_state = READ_ONCE(tsk->state);
1521*4882a593Smuzhiyun 	unsigned int state = (tsk_state | tsk->exit_state) & TASK_REPORT;
1522*4882a593Smuzhiyun 
1523*4882a593Smuzhiyun 	BUILD_BUG_ON_NOT_POWER_OF_2(TASK_REPORT_MAX);
1524*4882a593Smuzhiyun 
1525*4882a593Smuzhiyun 	if (tsk_state == TASK_IDLE)
1526*4882a593Smuzhiyun 		state = TASK_REPORT_IDLE;
1527*4882a593Smuzhiyun 
1528*4882a593Smuzhiyun 	return fls(state);
1529*4882a593Smuzhiyun }
1530*4882a593Smuzhiyun 
task_index_to_char(unsigned int state)1531*4882a593Smuzhiyun static inline char task_index_to_char(unsigned int state)
1532*4882a593Smuzhiyun {
1533*4882a593Smuzhiyun 	static const char state_char[] = "RSDTtXZPI";
1534*4882a593Smuzhiyun 
1535*4882a593Smuzhiyun 	BUILD_BUG_ON(1 + ilog2(TASK_REPORT_MAX) != sizeof(state_char) - 1);
1536*4882a593Smuzhiyun 
1537*4882a593Smuzhiyun 	return state_char[state];
1538*4882a593Smuzhiyun }
1539*4882a593Smuzhiyun 
task_state_to_char(struct task_struct * tsk)1540*4882a593Smuzhiyun static inline char task_state_to_char(struct task_struct *tsk)
1541*4882a593Smuzhiyun {
1542*4882a593Smuzhiyun 	return task_index_to_char(task_state_index(tsk));
1543*4882a593Smuzhiyun }
1544*4882a593Smuzhiyun 
1545*4882a593Smuzhiyun /**
1546*4882a593Smuzhiyun  * is_global_init - check if a task structure is init. Since init
1547*4882a593Smuzhiyun  * is free to have sub-threads we need to check tgid.
1548*4882a593Smuzhiyun  * @tsk: Task structure to be checked.
1549*4882a593Smuzhiyun  *
1550*4882a593Smuzhiyun  * Check if a task structure is the first user space task the kernel created.
1551*4882a593Smuzhiyun  *
1552*4882a593Smuzhiyun  * Return: 1 if the task structure is init. 0 otherwise.
1553*4882a593Smuzhiyun  */
is_global_init(struct task_struct * tsk)1554*4882a593Smuzhiyun static inline int is_global_init(struct task_struct *tsk)
1555*4882a593Smuzhiyun {
1556*4882a593Smuzhiyun 	return task_tgid_nr(tsk) == 1;
1557*4882a593Smuzhiyun }
1558*4882a593Smuzhiyun 
1559*4882a593Smuzhiyun extern struct pid *cad_pid;
1560*4882a593Smuzhiyun 
1561*4882a593Smuzhiyun /*
1562*4882a593Smuzhiyun  * Per process flags
1563*4882a593Smuzhiyun  */
1564*4882a593Smuzhiyun #define PF_VCPU			0x00000001	/* I'm a virtual CPU */
1565*4882a593Smuzhiyun #define PF_IDLE			0x00000002	/* I am an IDLE thread */
1566*4882a593Smuzhiyun #define PF_EXITING		0x00000004	/* Getting shut down */
1567*4882a593Smuzhiyun #define PF_IO_WORKER		0x00000010	/* Task is an IO worker */
1568*4882a593Smuzhiyun #define PF_WQ_WORKER		0x00000020	/* I'm a workqueue worker */
1569*4882a593Smuzhiyun #define PF_FORKNOEXEC		0x00000040	/* Forked but didn't exec */
1570*4882a593Smuzhiyun #define PF_MCE_PROCESS		0x00000080      /* Process policy on mce errors */
1571*4882a593Smuzhiyun #define PF_SUPERPRIV		0x00000100	/* Used super-user privileges */
1572*4882a593Smuzhiyun #define PF_DUMPCORE		0x00000200	/* Dumped core */
1573*4882a593Smuzhiyun #define PF_SIGNALED		0x00000400	/* Killed by a signal */
1574*4882a593Smuzhiyun #define PF_MEMALLOC		0x00000800	/* Allocating memory */
1575*4882a593Smuzhiyun #define PF_NPROC_EXCEEDED	0x00001000	/* set_user() noticed that RLIMIT_NPROC was exceeded */
1576*4882a593Smuzhiyun #define PF_USED_MATH		0x00002000	/* If unset the fpu must be initialized before use */
1577*4882a593Smuzhiyun #define PF_NOFREEZE		0x00008000	/* This thread should not be frozen */
1578*4882a593Smuzhiyun #define PF_FROZEN		0x00010000	/* Frozen for system suspend */
1579*4882a593Smuzhiyun #define PF_KSWAPD		0x00020000	/* I am kswapd */
1580*4882a593Smuzhiyun #define PF_MEMALLOC_NOFS	0x00040000	/* All allocation requests will inherit GFP_NOFS */
1581*4882a593Smuzhiyun #define PF_MEMALLOC_NOIO	0x00080000	/* All allocation requests will inherit GFP_NOIO */
1582*4882a593Smuzhiyun #define PF_LOCAL_THROTTLE	0x00100000	/* Throttle writes only against the bdi I write to,
1583*4882a593Smuzhiyun 						 * I am cleaning dirty pages from some other bdi. */
1584*4882a593Smuzhiyun #define PF_KTHREAD		0x00200000	/* I am a kernel thread */
1585*4882a593Smuzhiyun #define PF_RANDOMIZE		0x00400000	/* Randomize virtual address space */
1586*4882a593Smuzhiyun #define PF_SWAPWRITE		0x00800000	/* Allowed to write to swap */
1587*4882a593Smuzhiyun #define PF_NO_SETAFFINITY	0x04000000	/* Userland is not allowed to meddle with cpus_mask */
1588*4882a593Smuzhiyun #define PF_MCE_EARLY		0x08000000      /* Early kill for mce process policy */
1589*4882a593Smuzhiyun #define PF_MEMALLOC_NOCMA	0x10000000	/* All allocation request will have _GFP_MOVABLE cleared */
1590*4882a593Smuzhiyun #define PF_FREEZER_SKIP		0x40000000	/* Freezer should not count it as freezable */
1591*4882a593Smuzhiyun #define PF_SUSPEND_TASK		0x80000000      /* This thread called freeze_processes() and should not be frozen */
1592*4882a593Smuzhiyun 
1593*4882a593Smuzhiyun /*
1594*4882a593Smuzhiyun  * Only the _current_ task can read/write to tsk->flags, but other
1595*4882a593Smuzhiyun  * tasks can access tsk->flags in readonly mode for example
1596*4882a593Smuzhiyun  * with tsk_used_math (like during threaded core dumping).
1597*4882a593Smuzhiyun  * There is however an exception to this rule during ptrace
1598*4882a593Smuzhiyun  * or during fork: the ptracer task is allowed to write to the
1599*4882a593Smuzhiyun  * child->flags of its traced child (same goes for fork, the parent
1600*4882a593Smuzhiyun  * can write to the child->flags), because we're guaranteed the
1601*4882a593Smuzhiyun  * child is not running and in turn not changing child->flags
1602*4882a593Smuzhiyun  * at the same time the parent does it.
1603*4882a593Smuzhiyun  */
1604*4882a593Smuzhiyun #define clear_stopped_child_used_math(child)	do { (child)->flags &= ~PF_USED_MATH; } while (0)
1605*4882a593Smuzhiyun #define set_stopped_child_used_math(child)	do { (child)->flags |= PF_USED_MATH; } while (0)
1606*4882a593Smuzhiyun #define clear_used_math()			clear_stopped_child_used_math(current)
1607*4882a593Smuzhiyun #define set_used_math()				set_stopped_child_used_math(current)
1608*4882a593Smuzhiyun 
1609*4882a593Smuzhiyun #define conditional_stopped_child_used_math(condition, child) \
1610*4882a593Smuzhiyun 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
1611*4882a593Smuzhiyun 
1612*4882a593Smuzhiyun #define conditional_used_math(condition)	conditional_stopped_child_used_math(condition, current)
1613*4882a593Smuzhiyun 
1614*4882a593Smuzhiyun #define copy_to_stopped_child_used_math(child) \
1615*4882a593Smuzhiyun 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
1616*4882a593Smuzhiyun 
1617*4882a593Smuzhiyun /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
1618*4882a593Smuzhiyun #define tsk_used_math(p)			((p)->flags & PF_USED_MATH)
1619*4882a593Smuzhiyun #define used_math()				tsk_used_math(current)
1620*4882a593Smuzhiyun 
is_percpu_thread(void)1621*4882a593Smuzhiyun static __always_inline bool is_percpu_thread(void)
1622*4882a593Smuzhiyun {
1623*4882a593Smuzhiyun #ifdef CONFIG_SMP
1624*4882a593Smuzhiyun 	return (current->flags & PF_NO_SETAFFINITY) &&
1625*4882a593Smuzhiyun 		(current->nr_cpus_allowed  == 1);
1626*4882a593Smuzhiyun #else
1627*4882a593Smuzhiyun 	return true;
1628*4882a593Smuzhiyun #endif
1629*4882a593Smuzhiyun }
1630*4882a593Smuzhiyun 
1631*4882a593Smuzhiyun /* Per-process atomic flags. */
1632*4882a593Smuzhiyun #define PFA_NO_NEW_PRIVS		0	/* May not gain new privileges. */
1633*4882a593Smuzhiyun #define PFA_SPREAD_PAGE			1	/* Spread page cache over cpuset */
1634*4882a593Smuzhiyun #define PFA_SPREAD_SLAB			2	/* Spread some slab caches over cpuset */
1635*4882a593Smuzhiyun #define PFA_SPEC_SSB_DISABLE		3	/* Speculative Store Bypass disabled */
1636*4882a593Smuzhiyun #define PFA_SPEC_SSB_FORCE_DISABLE	4	/* Speculative Store Bypass force disabled*/
1637*4882a593Smuzhiyun #define PFA_SPEC_IB_DISABLE		5	/* Indirect branch speculation restricted */
1638*4882a593Smuzhiyun #define PFA_SPEC_IB_FORCE_DISABLE	6	/* Indirect branch speculation permanently restricted */
1639*4882a593Smuzhiyun #define PFA_SPEC_SSB_NOEXEC		7	/* Speculative Store Bypass clear on execve() */
1640*4882a593Smuzhiyun 
1641*4882a593Smuzhiyun #define TASK_PFA_TEST(name, func)					\
1642*4882a593Smuzhiyun 	static inline bool task_##func(struct task_struct *p)		\
1643*4882a593Smuzhiyun 	{ return test_bit(PFA_##name, &p->atomic_flags); }
1644*4882a593Smuzhiyun 
1645*4882a593Smuzhiyun #define TASK_PFA_SET(name, func)					\
1646*4882a593Smuzhiyun 	static inline void task_set_##func(struct task_struct *p)	\
1647*4882a593Smuzhiyun 	{ set_bit(PFA_##name, &p->atomic_flags); }
1648*4882a593Smuzhiyun 
1649*4882a593Smuzhiyun #define TASK_PFA_CLEAR(name, func)					\
1650*4882a593Smuzhiyun 	static inline void task_clear_##func(struct task_struct *p)	\
1651*4882a593Smuzhiyun 	{ clear_bit(PFA_##name, &p->atomic_flags); }
1652*4882a593Smuzhiyun 
TASK_PFA_TEST(NO_NEW_PRIVS,no_new_privs)1653*4882a593Smuzhiyun TASK_PFA_TEST(NO_NEW_PRIVS, no_new_privs)
1654*4882a593Smuzhiyun TASK_PFA_SET(NO_NEW_PRIVS, no_new_privs)
1655*4882a593Smuzhiyun 
1656*4882a593Smuzhiyun TASK_PFA_TEST(SPREAD_PAGE, spread_page)
1657*4882a593Smuzhiyun TASK_PFA_SET(SPREAD_PAGE, spread_page)
1658*4882a593Smuzhiyun TASK_PFA_CLEAR(SPREAD_PAGE, spread_page)
1659*4882a593Smuzhiyun 
1660*4882a593Smuzhiyun TASK_PFA_TEST(SPREAD_SLAB, spread_slab)
1661*4882a593Smuzhiyun TASK_PFA_SET(SPREAD_SLAB, spread_slab)
1662*4882a593Smuzhiyun TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab)
1663*4882a593Smuzhiyun 
1664*4882a593Smuzhiyun TASK_PFA_TEST(SPEC_SSB_DISABLE, spec_ssb_disable)
1665*4882a593Smuzhiyun TASK_PFA_SET(SPEC_SSB_DISABLE, spec_ssb_disable)
1666*4882a593Smuzhiyun TASK_PFA_CLEAR(SPEC_SSB_DISABLE, spec_ssb_disable)
1667*4882a593Smuzhiyun 
1668*4882a593Smuzhiyun TASK_PFA_TEST(SPEC_SSB_NOEXEC, spec_ssb_noexec)
1669*4882a593Smuzhiyun TASK_PFA_SET(SPEC_SSB_NOEXEC, spec_ssb_noexec)
1670*4882a593Smuzhiyun TASK_PFA_CLEAR(SPEC_SSB_NOEXEC, spec_ssb_noexec)
1671*4882a593Smuzhiyun 
1672*4882a593Smuzhiyun TASK_PFA_TEST(SPEC_SSB_FORCE_DISABLE, spec_ssb_force_disable)
1673*4882a593Smuzhiyun TASK_PFA_SET(SPEC_SSB_FORCE_DISABLE, spec_ssb_force_disable)
1674*4882a593Smuzhiyun 
1675*4882a593Smuzhiyun TASK_PFA_TEST(SPEC_IB_DISABLE, spec_ib_disable)
1676*4882a593Smuzhiyun TASK_PFA_SET(SPEC_IB_DISABLE, spec_ib_disable)
1677*4882a593Smuzhiyun TASK_PFA_CLEAR(SPEC_IB_DISABLE, spec_ib_disable)
1678*4882a593Smuzhiyun 
1679*4882a593Smuzhiyun TASK_PFA_TEST(SPEC_IB_FORCE_DISABLE, spec_ib_force_disable)
1680*4882a593Smuzhiyun TASK_PFA_SET(SPEC_IB_FORCE_DISABLE, spec_ib_force_disable)
1681*4882a593Smuzhiyun 
1682*4882a593Smuzhiyun static inline void
1683*4882a593Smuzhiyun current_restore_flags(unsigned long orig_flags, unsigned long flags)
1684*4882a593Smuzhiyun {
1685*4882a593Smuzhiyun 	current->flags &= ~flags;
1686*4882a593Smuzhiyun 	current->flags |= orig_flags & flags;
1687*4882a593Smuzhiyun }
1688*4882a593Smuzhiyun 
1689*4882a593Smuzhiyun extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
1690*4882a593Smuzhiyun extern int task_can_attach(struct task_struct *p, const struct cpumask *cs_effective_cpus);
1691*4882a593Smuzhiyun 
1692*4882a593Smuzhiyun #ifdef CONFIG_RT_SOFTINT_OPTIMIZATION
1693*4882a593Smuzhiyun extern bool cpupri_check_rt(void);
1694*4882a593Smuzhiyun #else
cpupri_check_rt(void)1695*4882a593Smuzhiyun static inline bool cpupri_check_rt(void)
1696*4882a593Smuzhiyun {
1697*4882a593Smuzhiyun 	return false;
1698*4882a593Smuzhiyun }
1699*4882a593Smuzhiyun #endif
1700*4882a593Smuzhiyun 
1701*4882a593Smuzhiyun #ifdef CONFIG_SMP
1702*4882a593Smuzhiyun extern void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask);
1703*4882a593Smuzhiyun extern int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask);
1704*4882a593Smuzhiyun extern void force_compatible_cpus_allowed_ptr(struct task_struct *p);
1705*4882a593Smuzhiyun #else
do_set_cpus_allowed(struct task_struct * p,const struct cpumask * new_mask)1706*4882a593Smuzhiyun static inline void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
1707*4882a593Smuzhiyun {
1708*4882a593Smuzhiyun }
set_cpus_allowed_ptr(struct task_struct * p,const struct cpumask * new_mask)1709*4882a593Smuzhiyun static inline int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask)
1710*4882a593Smuzhiyun {
1711*4882a593Smuzhiyun 	if (!cpumask_test_cpu(0, new_mask))
1712*4882a593Smuzhiyun 		return -EINVAL;
1713*4882a593Smuzhiyun 	return 0;
1714*4882a593Smuzhiyun }
1715*4882a593Smuzhiyun #endif
1716*4882a593Smuzhiyun 
1717*4882a593Smuzhiyun extern int yield_to(struct task_struct *p, bool preempt);
1718*4882a593Smuzhiyun extern void set_user_nice(struct task_struct *p, long nice);
1719*4882a593Smuzhiyun extern int task_prio(const struct task_struct *p);
1720*4882a593Smuzhiyun 
1721*4882a593Smuzhiyun /**
1722*4882a593Smuzhiyun  * task_nice - return the nice value of a given task.
1723*4882a593Smuzhiyun  * @p: the task in question.
1724*4882a593Smuzhiyun  *
1725*4882a593Smuzhiyun  * Return: The nice value [ -20 ... 0 ... 19 ].
1726*4882a593Smuzhiyun  */
task_nice(const struct task_struct * p)1727*4882a593Smuzhiyun static inline int task_nice(const struct task_struct *p)
1728*4882a593Smuzhiyun {
1729*4882a593Smuzhiyun 	return PRIO_TO_NICE((p)->static_prio);
1730*4882a593Smuzhiyun }
1731*4882a593Smuzhiyun 
1732*4882a593Smuzhiyun extern int can_nice(const struct task_struct *p, const int nice);
1733*4882a593Smuzhiyun extern int task_curr(const struct task_struct *p);
1734*4882a593Smuzhiyun extern int idle_cpu(int cpu);
1735*4882a593Smuzhiyun extern int available_idle_cpu(int cpu);
1736*4882a593Smuzhiyun extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *);
1737*4882a593Smuzhiyun extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *);
1738*4882a593Smuzhiyun extern void sched_set_fifo(struct task_struct *p);
1739*4882a593Smuzhiyun extern void sched_set_fifo_low(struct task_struct *p);
1740*4882a593Smuzhiyun extern void sched_set_normal(struct task_struct *p, int nice);
1741*4882a593Smuzhiyun extern int sched_setattr(struct task_struct *, const struct sched_attr *);
1742*4882a593Smuzhiyun extern int sched_setattr_nocheck(struct task_struct *, const struct sched_attr *);
1743*4882a593Smuzhiyun extern struct task_struct *idle_task(int cpu);
1744*4882a593Smuzhiyun 
1745*4882a593Smuzhiyun /**
1746*4882a593Smuzhiyun  * is_idle_task - is the specified task an idle task?
1747*4882a593Smuzhiyun  * @p: the task in question.
1748*4882a593Smuzhiyun  *
1749*4882a593Smuzhiyun  * Return: 1 if @p is an idle task. 0 otherwise.
1750*4882a593Smuzhiyun  */
is_idle_task(const struct task_struct * p)1751*4882a593Smuzhiyun static __always_inline bool is_idle_task(const struct task_struct *p)
1752*4882a593Smuzhiyun {
1753*4882a593Smuzhiyun 	return !!(p->flags & PF_IDLE);
1754*4882a593Smuzhiyun }
1755*4882a593Smuzhiyun 
1756*4882a593Smuzhiyun extern struct task_struct *curr_task(int cpu);
1757*4882a593Smuzhiyun extern void ia64_set_curr_task(int cpu, struct task_struct *p);
1758*4882a593Smuzhiyun 
1759*4882a593Smuzhiyun void yield(void);
1760*4882a593Smuzhiyun 
1761*4882a593Smuzhiyun union thread_union {
1762*4882a593Smuzhiyun #ifndef CONFIG_ARCH_TASK_STRUCT_ON_STACK
1763*4882a593Smuzhiyun 	struct task_struct task;
1764*4882a593Smuzhiyun #endif
1765*4882a593Smuzhiyun #ifndef CONFIG_THREAD_INFO_IN_TASK
1766*4882a593Smuzhiyun 	struct thread_info thread_info;
1767*4882a593Smuzhiyun #endif
1768*4882a593Smuzhiyun 	unsigned long stack[THREAD_SIZE/sizeof(long)];
1769*4882a593Smuzhiyun };
1770*4882a593Smuzhiyun 
1771*4882a593Smuzhiyun #ifndef CONFIG_THREAD_INFO_IN_TASK
1772*4882a593Smuzhiyun extern struct thread_info init_thread_info;
1773*4882a593Smuzhiyun #endif
1774*4882a593Smuzhiyun 
1775*4882a593Smuzhiyun extern unsigned long init_stack[THREAD_SIZE / sizeof(unsigned long)];
1776*4882a593Smuzhiyun 
1777*4882a593Smuzhiyun #ifdef CONFIG_THREAD_INFO_IN_TASK
task_thread_info(struct task_struct * task)1778*4882a593Smuzhiyun static inline struct thread_info *task_thread_info(struct task_struct *task)
1779*4882a593Smuzhiyun {
1780*4882a593Smuzhiyun 	return &task->thread_info;
1781*4882a593Smuzhiyun }
1782*4882a593Smuzhiyun #elif !defined(__HAVE_THREAD_FUNCTIONS)
1783*4882a593Smuzhiyun # define task_thread_info(task)	((struct thread_info *)(task)->stack)
1784*4882a593Smuzhiyun #endif
1785*4882a593Smuzhiyun 
1786*4882a593Smuzhiyun /*
1787*4882a593Smuzhiyun  * find a task by one of its numerical ids
1788*4882a593Smuzhiyun  *
1789*4882a593Smuzhiyun  * find_task_by_pid_ns():
1790*4882a593Smuzhiyun  *      finds a task by its pid in the specified namespace
1791*4882a593Smuzhiyun  * find_task_by_vpid():
1792*4882a593Smuzhiyun  *      finds a task by its virtual pid
1793*4882a593Smuzhiyun  *
1794*4882a593Smuzhiyun  * see also find_vpid() etc in include/linux/pid.h
1795*4882a593Smuzhiyun  */
1796*4882a593Smuzhiyun 
1797*4882a593Smuzhiyun extern struct task_struct *find_task_by_vpid(pid_t nr);
1798*4882a593Smuzhiyun extern struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns);
1799*4882a593Smuzhiyun 
1800*4882a593Smuzhiyun /*
1801*4882a593Smuzhiyun  * find a task by its virtual pid and get the task struct
1802*4882a593Smuzhiyun  */
1803*4882a593Smuzhiyun extern struct task_struct *find_get_task_by_vpid(pid_t nr);
1804*4882a593Smuzhiyun 
1805*4882a593Smuzhiyun extern int wake_up_state(struct task_struct *tsk, unsigned int state);
1806*4882a593Smuzhiyun extern int wake_up_process(struct task_struct *tsk);
1807*4882a593Smuzhiyun extern void wake_up_new_task(struct task_struct *tsk);
1808*4882a593Smuzhiyun 
1809*4882a593Smuzhiyun #ifdef CONFIG_SMP
1810*4882a593Smuzhiyun extern void kick_process(struct task_struct *tsk);
1811*4882a593Smuzhiyun #else
kick_process(struct task_struct * tsk)1812*4882a593Smuzhiyun static inline void kick_process(struct task_struct *tsk) { }
1813*4882a593Smuzhiyun #endif
1814*4882a593Smuzhiyun 
1815*4882a593Smuzhiyun extern void __set_task_comm(struct task_struct *tsk, const char *from, bool exec);
1816*4882a593Smuzhiyun 
set_task_comm(struct task_struct * tsk,const char * from)1817*4882a593Smuzhiyun static inline void set_task_comm(struct task_struct *tsk, const char *from)
1818*4882a593Smuzhiyun {
1819*4882a593Smuzhiyun 	__set_task_comm(tsk, from, false);
1820*4882a593Smuzhiyun }
1821*4882a593Smuzhiyun 
1822*4882a593Smuzhiyun extern char *__get_task_comm(char *to, size_t len, struct task_struct *tsk);
1823*4882a593Smuzhiyun #define get_task_comm(buf, tsk) ({			\
1824*4882a593Smuzhiyun 	BUILD_BUG_ON(sizeof(buf) != TASK_COMM_LEN);	\
1825*4882a593Smuzhiyun 	__get_task_comm(buf, sizeof(buf), tsk);		\
1826*4882a593Smuzhiyun })
1827*4882a593Smuzhiyun 
1828*4882a593Smuzhiyun #ifdef CONFIG_SMP
scheduler_ipi(void)1829*4882a593Smuzhiyun static __always_inline void scheduler_ipi(void)
1830*4882a593Smuzhiyun {
1831*4882a593Smuzhiyun 	/*
1832*4882a593Smuzhiyun 	 * Fold TIF_NEED_RESCHED into the preempt_count; anybody setting
1833*4882a593Smuzhiyun 	 * TIF_NEED_RESCHED remotely (for the first time) will also send
1834*4882a593Smuzhiyun 	 * this IPI.
1835*4882a593Smuzhiyun 	 */
1836*4882a593Smuzhiyun 	preempt_fold_need_resched();
1837*4882a593Smuzhiyun }
1838*4882a593Smuzhiyun extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
1839*4882a593Smuzhiyun #else
scheduler_ipi(void)1840*4882a593Smuzhiyun static inline void scheduler_ipi(void) { }
wait_task_inactive(struct task_struct * p,long match_state)1841*4882a593Smuzhiyun static inline unsigned long wait_task_inactive(struct task_struct *p, long match_state)
1842*4882a593Smuzhiyun {
1843*4882a593Smuzhiyun 	return 1;
1844*4882a593Smuzhiyun }
1845*4882a593Smuzhiyun #endif
1846*4882a593Smuzhiyun 
1847*4882a593Smuzhiyun /*
1848*4882a593Smuzhiyun  * Set thread flags in other task's structures.
1849*4882a593Smuzhiyun  * See asm/thread_info.h for TIF_xxxx flags available:
1850*4882a593Smuzhiyun  */
set_tsk_thread_flag(struct task_struct * tsk,int flag)1851*4882a593Smuzhiyun static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
1852*4882a593Smuzhiyun {
1853*4882a593Smuzhiyun 	set_ti_thread_flag(task_thread_info(tsk), flag);
1854*4882a593Smuzhiyun }
1855*4882a593Smuzhiyun 
clear_tsk_thread_flag(struct task_struct * tsk,int flag)1856*4882a593Smuzhiyun static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
1857*4882a593Smuzhiyun {
1858*4882a593Smuzhiyun 	clear_ti_thread_flag(task_thread_info(tsk), flag);
1859*4882a593Smuzhiyun }
1860*4882a593Smuzhiyun 
update_tsk_thread_flag(struct task_struct * tsk,int flag,bool value)1861*4882a593Smuzhiyun static inline void update_tsk_thread_flag(struct task_struct *tsk, int flag,
1862*4882a593Smuzhiyun 					  bool value)
1863*4882a593Smuzhiyun {
1864*4882a593Smuzhiyun 	update_ti_thread_flag(task_thread_info(tsk), flag, value);
1865*4882a593Smuzhiyun }
1866*4882a593Smuzhiyun 
test_and_set_tsk_thread_flag(struct task_struct * tsk,int flag)1867*4882a593Smuzhiyun static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
1868*4882a593Smuzhiyun {
1869*4882a593Smuzhiyun 	return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
1870*4882a593Smuzhiyun }
1871*4882a593Smuzhiyun 
test_and_clear_tsk_thread_flag(struct task_struct * tsk,int flag)1872*4882a593Smuzhiyun static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
1873*4882a593Smuzhiyun {
1874*4882a593Smuzhiyun 	return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
1875*4882a593Smuzhiyun }
1876*4882a593Smuzhiyun 
test_tsk_thread_flag(struct task_struct * tsk,int flag)1877*4882a593Smuzhiyun static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
1878*4882a593Smuzhiyun {
1879*4882a593Smuzhiyun 	return test_ti_thread_flag(task_thread_info(tsk), flag);
1880*4882a593Smuzhiyun }
1881*4882a593Smuzhiyun 
set_tsk_need_resched(struct task_struct * tsk)1882*4882a593Smuzhiyun static inline void set_tsk_need_resched(struct task_struct *tsk)
1883*4882a593Smuzhiyun {
1884*4882a593Smuzhiyun 	set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
1885*4882a593Smuzhiyun }
1886*4882a593Smuzhiyun 
clear_tsk_need_resched(struct task_struct * tsk)1887*4882a593Smuzhiyun static inline void clear_tsk_need_resched(struct task_struct *tsk)
1888*4882a593Smuzhiyun {
1889*4882a593Smuzhiyun 	clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
1890*4882a593Smuzhiyun }
1891*4882a593Smuzhiyun 
test_tsk_need_resched(struct task_struct * tsk)1892*4882a593Smuzhiyun static inline int test_tsk_need_resched(struct task_struct *tsk)
1893*4882a593Smuzhiyun {
1894*4882a593Smuzhiyun 	return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
1895*4882a593Smuzhiyun }
1896*4882a593Smuzhiyun 
1897*4882a593Smuzhiyun /*
1898*4882a593Smuzhiyun  * cond_resched() and cond_resched_lock(): latency reduction via
1899*4882a593Smuzhiyun  * explicit rescheduling in places that are safe. The return
1900*4882a593Smuzhiyun  * value indicates whether a reschedule was done in fact.
1901*4882a593Smuzhiyun  * cond_resched_lock() will drop the spinlock before scheduling,
1902*4882a593Smuzhiyun  */
1903*4882a593Smuzhiyun #ifndef CONFIG_PREEMPTION
1904*4882a593Smuzhiyun extern int _cond_resched(void);
1905*4882a593Smuzhiyun #else
_cond_resched(void)1906*4882a593Smuzhiyun static inline int _cond_resched(void) { return 0; }
1907*4882a593Smuzhiyun #endif
1908*4882a593Smuzhiyun 
1909*4882a593Smuzhiyun #define cond_resched() ({			\
1910*4882a593Smuzhiyun 	___might_sleep(__FILE__, __LINE__, 0);	\
1911*4882a593Smuzhiyun 	_cond_resched();			\
1912*4882a593Smuzhiyun })
1913*4882a593Smuzhiyun 
1914*4882a593Smuzhiyun extern int __cond_resched_lock(spinlock_t *lock);
1915*4882a593Smuzhiyun 
1916*4882a593Smuzhiyun #define cond_resched_lock(lock) ({				\
1917*4882a593Smuzhiyun 	___might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);\
1918*4882a593Smuzhiyun 	__cond_resched_lock(lock);				\
1919*4882a593Smuzhiyun })
1920*4882a593Smuzhiyun 
cond_resched_rcu(void)1921*4882a593Smuzhiyun static inline void cond_resched_rcu(void)
1922*4882a593Smuzhiyun {
1923*4882a593Smuzhiyun #if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
1924*4882a593Smuzhiyun 	rcu_read_unlock();
1925*4882a593Smuzhiyun 	cond_resched();
1926*4882a593Smuzhiyun 	rcu_read_lock();
1927*4882a593Smuzhiyun #endif
1928*4882a593Smuzhiyun }
1929*4882a593Smuzhiyun 
1930*4882a593Smuzhiyun /*
1931*4882a593Smuzhiyun  * Does a critical section need to be broken due to another
1932*4882a593Smuzhiyun  * task waiting?: (technically does not depend on CONFIG_PREEMPTION,
1933*4882a593Smuzhiyun  * but a general need for low latency)
1934*4882a593Smuzhiyun  */
spin_needbreak(spinlock_t * lock)1935*4882a593Smuzhiyun static inline int spin_needbreak(spinlock_t *lock)
1936*4882a593Smuzhiyun {
1937*4882a593Smuzhiyun #ifdef CONFIG_PREEMPTION
1938*4882a593Smuzhiyun 	return spin_is_contended(lock);
1939*4882a593Smuzhiyun #else
1940*4882a593Smuzhiyun 	return 0;
1941*4882a593Smuzhiyun #endif
1942*4882a593Smuzhiyun }
1943*4882a593Smuzhiyun 
need_resched(void)1944*4882a593Smuzhiyun static __always_inline bool need_resched(void)
1945*4882a593Smuzhiyun {
1946*4882a593Smuzhiyun 	return unlikely(tif_need_resched());
1947*4882a593Smuzhiyun }
1948*4882a593Smuzhiyun 
1949*4882a593Smuzhiyun /*
1950*4882a593Smuzhiyun  * Wrappers for p->thread_info->cpu access. No-op on UP.
1951*4882a593Smuzhiyun  */
1952*4882a593Smuzhiyun #ifdef CONFIG_SMP
1953*4882a593Smuzhiyun 
task_cpu(const struct task_struct * p)1954*4882a593Smuzhiyun static inline unsigned int task_cpu(const struct task_struct *p)
1955*4882a593Smuzhiyun {
1956*4882a593Smuzhiyun #ifdef CONFIG_THREAD_INFO_IN_TASK
1957*4882a593Smuzhiyun 	return READ_ONCE(p->cpu);
1958*4882a593Smuzhiyun #else
1959*4882a593Smuzhiyun 	return READ_ONCE(task_thread_info(p)->cpu);
1960*4882a593Smuzhiyun #endif
1961*4882a593Smuzhiyun }
1962*4882a593Smuzhiyun 
1963*4882a593Smuzhiyun extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
1964*4882a593Smuzhiyun 
1965*4882a593Smuzhiyun #else
1966*4882a593Smuzhiyun 
task_cpu(const struct task_struct * p)1967*4882a593Smuzhiyun static inline unsigned int task_cpu(const struct task_struct *p)
1968*4882a593Smuzhiyun {
1969*4882a593Smuzhiyun 	return 0;
1970*4882a593Smuzhiyun }
1971*4882a593Smuzhiyun 
set_task_cpu(struct task_struct * p,unsigned int cpu)1972*4882a593Smuzhiyun static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
1973*4882a593Smuzhiyun {
1974*4882a593Smuzhiyun }
1975*4882a593Smuzhiyun 
1976*4882a593Smuzhiyun #endif /* CONFIG_SMP */
1977*4882a593Smuzhiyun 
1978*4882a593Smuzhiyun /*
1979*4882a593Smuzhiyun  * In order to reduce various lock holder preemption latencies provide an
1980*4882a593Smuzhiyun  * interface to see if a vCPU is currently running or not.
1981*4882a593Smuzhiyun  *
1982*4882a593Smuzhiyun  * This allows us to terminate optimistic spin loops and block, analogous to
1983*4882a593Smuzhiyun  * the native optimistic spin heuristic of testing if the lock owner task is
1984*4882a593Smuzhiyun  * running or not.
1985*4882a593Smuzhiyun  */
1986*4882a593Smuzhiyun #ifndef vcpu_is_preempted
vcpu_is_preempted(int cpu)1987*4882a593Smuzhiyun static inline bool vcpu_is_preempted(int cpu)
1988*4882a593Smuzhiyun {
1989*4882a593Smuzhiyun 	return false;
1990*4882a593Smuzhiyun }
1991*4882a593Smuzhiyun #endif
1992*4882a593Smuzhiyun 
1993*4882a593Smuzhiyun extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
1994*4882a593Smuzhiyun extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
1995*4882a593Smuzhiyun 
1996*4882a593Smuzhiyun #ifndef TASK_SIZE_OF
1997*4882a593Smuzhiyun #define TASK_SIZE_OF(tsk)	TASK_SIZE
1998*4882a593Smuzhiyun #endif
1999*4882a593Smuzhiyun 
2000*4882a593Smuzhiyun #ifdef CONFIG_RSEQ
2001*4882a593Smuzhiyun 
2002*4882a593Smuzhiyun /*
2003*4882a593Smuzhiyun  * Map the event mask on the user-space ABI enum rseq_cs_flags
2004*4882a593Smuzhiyun  * for direct mask checks.
2005*4882a593Smuzhiyun  */
2006*4882a593Smuzhiyun enum rseq_event_mask_bits {
2007*4882a593Smuzhiyun 	RSEQ_EVENT_PREEMPT_BIT	= RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT,
2008*4882a593Smuzhiyun 	RSEQ_EVENT_SIGNAL_BIT	= RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT,
2009*4882a593Smuzhiyun 	RSEQ_EVENT_MIGRATE_BIT	= RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT,
2010*4882a593Smuzhiyun };
2011*4882a593Smuzhiyun 
2012*4882a593Smuzhiyun enum rseq_event_mask {
2013*4882a593Smuzhiyun 	RSEQ_EVENT_PREEMPT	= (1U << RSEQ_EVENT_PREEMPT_BIT),
2014*4882a593Smuzhiyun 	RSEQ_EVENT_SIGNAL	= (1U << RSEQ_EVENT_SIGNAL_BIT),
2015*4882a593Smuzhiyun 	RSEQ_EVENT_MIGRATE	= (1U << RSEQ_EVENT_MIGRATE_BIT),
2016*4882a593Smuzhiyun };
2017*4882a593Smuzhiyun 
rseq_set_notify_resume(struct task_struct * t)2018*4882a593Smuzhiyun static inline void rseq_set_notify_resume(struct task_struct *t)
2019*4882a593Smuzhiyun {
2020*4882a593Smuzhiyun 	if (t->rseq)
2021*4882a593Smuzhiyun 		set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
2022*4882a593Smuzhiyun }
2023*4882a593Smuzhiyun 
2024*4882a593Smuzhiyun void __rseq_handle_notify_resume(struct ksignal *sig, struct pt_regs *regs);
2025*4882a593Smuzhiyun 
rseq_handle_notify_resume(struct ksignal * ksig,struct pt_regs * regs)2026*4882a593Smuzhiyun static inline void rseq_handle_notify_resume(struct ksignal *ksig,
2027*4882a593Smuzhiyun 					     struct pt_regs *regs)
2028*4882a593Smuzhiyun {
2029*4882a593Smuzhiyun 	if (current->rseq)
2030*4882a593Smuzhiyun 		__rseq_handle_notify_resume(ksig, regs);
2031*4882a593Smuzhiyun }
2032*4882a593Smuzhiyun 
rseq_signal_deliver(struct ksignal * ksig,struct pt_regs * regs)2033*4882a593Smuzhiyun static inline void rseq_signal_deliver(struct ksignal *ksig,
2034*4882a593Smuzhiyun 				       struct pt_regs *regs)
2035*4882a593Smuzhiyun {
2036*4882a593Smuzhiyun 	preempt_disable();
2037*4882a593Smuzhiyun 	__set_bit(RSEQ_EVENT_SIGNAL_BIT, &current->rseq_event_mask);
2038*4882a593Smuzhiyun 	preempt_enable();
2039*4882a593Smuzhiyun 	rseq_handle_notify_resume(ksig, regs);
2040*4882a593Smuzhiyun }
2041*4882a593Smuzhiyun 
2042*4882a593Smuzhiyun /* rseq_preempt() requires preemption to be disabled. */
rseq_preempt(struct task_struct * t)2043*4882a593Smuzhiyun static inline void rseq_preempt(struct task_struct *t)
2044*4882a593Smuzhiyun {
2045*4882a593Smuzhiyun 	__set_bit(RSEQ_EVENT_PREEMPT_BIT, &t->rseq_event_mask);
2046*4882a593Smuzhiyun 	rseq_set_notify_resume(t);
2047*4882a593Smuzhiyun }
2048*4882a593Smuzhiyun 
2049*4882a593Smuzhiyun /* rseq_migrate() requires preemption to be disabled. */
rseq_migrate(struct task_struct * t)2050*4882a593Smuzhiyun static inline void rseq_migrate(struct task_struct *t)
2051*4882a593Smuzhiyun {
2052*4882a593Smuzhiyun 	__set_bit(RSEQ_EVENT_MIGRATE_BIT, &t->rseq_event_mask);
2053*4882a593Smuzhiyun 	rseq_set_notify_resume(t);
2054*4882a593Smuzhiyun }
2055*4882a593Smuzhiyun 
2056*4882a593Smuzhiyun /*
2057*4882a593Smuzhiyun  * If parent process has a registered restartable sequences area, the
2058*4882a593Smuzhiyun  * child inherits. Unregister rseq for a clone with CLONE_VM set.
2059*4882a593Smuzhiyun  */
rseq_fork(struct task_struct * t,unsigned long clone_flags)2060*4882a593Smuzhiyun static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags)
2061*4882a593Smuzhiyun {
2062*4882a593Smuzhiyun 	if (clone_flags & CLONE_VM) {
2063*4882a593Smuzhiyun 		t->rseq = NULL;
2064*4882a593Smuzhiyun 		t->rseq_sig = 0;
2065*4882a593Smuzhiyun 		t->rseq_event_mask = 0;
2066*4882a593Smuzhiyun 	} else {
2067*4882a593Smuzhiyun 		t->rseq = current->rseq;
2068*4882a593Smuzhiyun 		t->rseq_sig = current->rseq_sig;
2069*4882a593Smuzhiyun 		t->rseq_event_mask = current->rseq_event_mask;
2070*4882a593Smuzhiyun 	}
2071*4882a593Smuzhiyun }
2072*4882a593Smuzhiyun 
rseq_execve(struct task_struct * t)2073*4882a593Smuzhiyun static inline void rseq_execve(struct task_struct *t)
2074*4882a593Smuzhiyun {
2075*4882a593Smuzhiyun 	t->rseq = NULL;
2076*4882a593Smuzhiyun 	t->rseq_sig = 0;
2077*4882a593Smuzhiyun 	t->rseq_event_mask = 0;
2078*4882a593Smuzhiyun }
2079*4882a593Smuzhiyun 
2080*4882a593Smuzhiyun #else
2081*4882a593Smuzhiyun 
rseq_set_notify_resume(struct task_struct * t)2082*4882a593Smuzhiyun static inline void rseq_set_notify_resume(struct task_struct *t)
2083*4882a593Smuzhiyun {
2084*4882a593Smuzhiyun }
rseq_handle_notify_resume(struct ksignal * ksig,struct pt_regs * regs)2085*4882a593Smuzhiyun static inline void rseq_handle_notify_resume(struct ksignal *ksig,
2086*4882a593Smuzhiyun 					     struct pt_regs *regs)
2087*4882a593Smuzhiyun {
2088*4882a593Smuzhiyun }
rseq_signal_deliver(struct ksignal * ksig,struct pt_regs * regs)2089*4882a593Smuzhiyun static inline void rseq_signal_deliver(struct ksignal *ksig,
2090*4882a593Smuzhiyun 				       struct pt_regs *regs)
2091*4882a593Smuzhiyun {
2092*4882a593Smuzhiyun }
rseq_preempt(struct task_struct * t)2093*4882a593Smuzhiyun static inline void rseq_preempt(struct task_struct *t)
2094*4882a593Smuzhiyun {
2095*4882a593Smuzhiyun }
rseq_migrate(struct task_struct * t)2096*4882a593Smuzhiyun static inline void rseq_migrate(struct task_struct *t)
2097*4882a593Smuzhiyun {
2098*4882a593Smuzhiyun }
rseq_fork(struct task_struct * t,unsigned long clone_flags)2099*4882a593Smuzhiyun static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags)
2100*4882a593Smuzhiyun {
2101*4882a593Smuzhiyun }
rseq_execve(struct task_struct * t)2102*4882a593Smuzhiyun static inline void rseq_execve(struct task_struct *t)
2103*4882a593Smuzhiyun {
2104*4882a593Smuzhiyun }
2105*4882a593Smuzhiyun 
2106*4882a593Smuzhiyun #endif
2107*4882a593Smuzhiyun 
2108*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_RSEQ
2109*4882a593Smuzhiyun 
2110*4882a593Smuzhiyun void rseq_syscall(struct pt_regs *regs);
2111*4882a593Smuzhiyun 
2112*4882a593Smuzhiyun #else
2113*4882a593Smuzhiyun 
rseq_syscall(struct pt_regs * regs)2114*4882a593Smuzhiyun static inline void rseq_syscall(struct pt_regs *regs)
2115*4882a593Smuzhiyun {
2116*4882a593Smuzhiyun }
2117*4882a593Smuzhiyun 
2118*4882a593Smuzhiyun #endif
2119*4882a593Smuzhiyun 
2120*4882a593Smuzhiyun const struct sched_avg *sched_trace_cfs_rq_avg(struct cfs_rq *cfs_rq);
2121*4882a593Smuzhiyun char *sched_trace_cfs_rq_path(struct cfs_rq *cfs_rq, char *str, int len);
2122*4882a593Smuzhiyun int sched_trace_cfs_rq_cpu(struct cfs_rq *cfs_rq);
2123*4882a593Smuzhiyun 
2124*4882a593Smuzhiyun const struct sched_avg *sched_trace_rq_avg_rt(struct rq *rq);
2125*4882a593Smuzhiyun const struct sched_avg *sched_trace_rq_avg_dl(struct rq *rq);
2126*4882a593Smuzhiyun const struct sched_avg *sched_trace_rq_avg_irq(struct rq *rq);
2127*4882a593Smuzhiyun 
2128*4882a593Smuzhiyun int sched_trace_rq_cpu(struct rq *rq);
2129*4882a593Smuzhiyun int sched_trace_rq_cpu_capacity(struct rq *rq);
2130*4882a593Smuzhiyun int sched_trace_rq_nr_running(struct rq *rq);
2131*4882a593Smuzhiyun 
2132*4882a593Smuzhiyun const struct cpumask *sched_trace_rd_span(struct root_domain *rd);
2133*4882a593Smuzhiyun 
2134*4882a593Smuzhiyun #endif
2135