xref: /linux/include/linux/sched.h (revision c7af7877eeacfeaaf6a1b6f54c481292ef116837)
11da177e4SLinus Torvalds #ifndef _LINUX_SCHED_H
21da177e4SLinus Torvalds #define _LINUX_SCHED_H
31da177e4SLinus Torvalds 
4607ca46eSDavid Howells #include <uapi/linux/sched.h>
5b7b3c76aSDavid Woodhouse 
65c228079SDongsheng Yang #include <linux/sched/prio.h>
75c228079SDongsheng Yang 
81da177e4SLinus Torvalds #include <linux/capability.h>
9b69339baSIngo Molnar #include <linux/mutex.h>
10fb00aca4SPeter Zijlstra #include <linux/plist.h>
11c92ff1bdSMartin Schwidefsky #include <linux/mm_types.h>
121da177e4SLinus Torvalds #include <asm/ptrace.h>
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #include <linux/sem.h>
15ab602f79SJack Miller #include <linux/shm.h>
161da177e4SLinus Torvalds #include <linux/signal.h>
17f361bf4aSIngo Molnar #include <linux/signal_types.h>
181da177e4SLinus Torvalds #include <linux/pid.h>
191da177e4SLinus Torvalds #include <linux/seccomp.h>
2005725f7eSJiri Pirko #include <linux/rculist.h>
2123f78d4aSIngo Molnar #include <linux/rtmutex.h>
221da177e4SLinus Torvalds 
23a3b6714eSDavid Woodhouse #include <linux/resource.h>
24a3b6714eSDavid Woodhouse #include <linux/hrtimer.h>
255c9a8750SDmitry Vyukov #include <linux/kcov.h>
267c3ab738SAndrew Morton #include <linux/task_io_accounting.h>
279745512cSArjan van de Ven #include <linux/latencytop.h>
289e2b2dc4SDavid Howells #include <linux/cred.h>
2921caf2fcSMing Lei #include <linux/gfp.h>
30fd771233SIngo Molnar #include <linux/topology.h>
31d4311ff1SAaron Tomlin #include <linux/magic.h>
327d7efec3STejun Heo #include <linux/cgroup-defs.h>
33a3b6714eSDavid Woodhouse 
3470b8157eSIngo Molnar #include <asm/current.h>
3570b8157eSIngo Molnar 
36*c7af7877SIngo Molnar /* task_struct member predeclarations: */
37*c7af7877SIngo Molnar struct audit_context;
38*c7af7877SIngo Molnar struct autogroup;
39*c7af7877SIngo Molnar struct backing_dev_info;
40*c7af7877SIngo Molnar struct bio_list;
41*c7af7877SIngo Molnar struct blk_plug;
42*c7af7877SIngo Molnar struct cfs_rq;
43*c7af7877SIngo Molnar struct filename;
44*c7af7877SIngo Molnar struct fs_struct;
45*c7af7877SIngo Molnar struct futex_pi_state;
46*c7af7877SIngo Molnar struct io_context;
47*c7af7877SIngo Molnar struct mempolicy;
48*c7af7877SIngo Molnar struct nameidata;
49*c7af7877SIngo Molnar struct nsproxy;
50*c7af7877SIngo Molnar struct perf_event_context;
51*c7af7877SIngo Molnar struct pid_namespace;
52*c7af7877SIngo Molnar struct pipe_inode_info;
53*c7af7877SIngo Molnar struct rcu_node;
54*c7af7877SIngo Molnar struct reclaim_state;
55*c7af7877SIngo Molnar struct robust_list_head;
56e2d1e2aeSIngo Molnar struct sched_attr;
57e2d1e2aeSIngo Molnar struct sched_param;
5843ae34cbSIngo Molnar struct seq_file;
59*c7af7877SIngo Molnar struct sighand_struct;
60*c7af7877SIngo Molnar struct signal_struct;
61*c7af7877SIngo Molnar struct task_delay_info;
624cf86d77SIngo Molnar struct task_group;
63*c7af7877SIngo Molnar struct task_struct;
64*c7af7877SIngo Molnar struct uts_namespace;
651da177e4SLinus Torvalds 
664a8342d2SLinus Torvalds /*
674a8342d2SLinus Torvalds  * Task state bitmask. NOTE! These bits are also
684a8342d2SLinus Torvalds  * encoded in fs/proc/array.c: get_task_state().
694a8342d2SLinus Torvalds  *
704a8342d2SLinus Torvalds  * We have two separate sets of flags: task->state
714a8342d2SLinus Torvalds  * is about runnability, while task->exit_state are
724a8342d2SLinus Torvalds  * about the task exiting. Confusing, but this way
734a8342d2SLinus Torvalds  * modifying one set can't modify the other one by
744a8342d2SLinus Torvalds  * mistake.
754a8342d2SLinus Torvalds  */
761da177e4SLinus Torvalds #define TASK_RUNNING		0
771da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE	1
781da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE	2
79f021a3c2SMatthew Wilcox #define __TASK_STOPPED		4
80f021a3c2SMatthew Wilcox #define __TASK_TRACED		8
814a8342d2SLinus Torvalds /* in tsk->exit_state */
82ad86622bSOleg Nesterov #define EXIT_DEAD		16
83ad86622bSOleg Nesterov #define EXIT_ZOMBIE		32
84abd50b39SOleg Nesterov #define EXIT_TRACE		(EXIT_ZOMBIE | EXIT_DEAD)
854a8342d2SLinus Torvalds /* in tsk->state again */
86af927232SMike Galbraith #define TASK_DEAD		64
87f021a3c2SMatthew Wilcox #define TASK_WAKEKILL		128
88e9c84311SPeter Zijlstra #define TASK_WAKING		256
89f2530dc7SThomas Gleixner #define TASK_PARKED		512
9080ed87c8SPeter Zijlstra #define TASK_NOLOAD		1024
917dc603c9SPeter Zijlstra #define TASK_NEW		2048
927dc603c9SPeter Zijlstra #define TASK_STATE_MAX		4096
93f021a3c2SMatthew Wilcox 
947dc603c9SPeter Zijlstra #define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWPNn"
9573342151SPeter Zijlstra 
96642fa448SDavidlohr Bueso /* Convenience macros for the sake of set_current_state */
97f021a3c2SMatthew Wilcox #define TASK_KILLABLE		(TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
98f021a3c2SMatthew Wilcox #define TASK_STOPPED		(TASK_WAKEKILL | __TASK_STOPPED)
99f021a3c2SMatthew Wilcox #define TASK_TRACED		(TASK_WAKEKILL | __TASK_TRACED)
1001da177e4SLinus Torvalds 
10180ed87c8SPeter Zijlstra #define TASK_IDLE		(TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
10280ed87c8SPeter Zijlstra 
10392a1f4bcSMatthew Wilcox /* Convenience macros for the sake of wake_up */
10492a1f4bcSMatthew Wilcox #define TASK_NORMAL		(TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
105f021a3c2SMatthew Wilcox #define TASK_ALL		(TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
10692a1f4bcSMatthew Wilcox 
10792a1f4bcSMatthew Wilcox /* get_task_state() */
10892a1f4bcSMatthew Wilcox #define TASK_REPORT		(TASK_RUNNING | TASK_INTERRUPTIBLE | \
109f021a3c2SMatthew Wilcox 				 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
11074e37200SOleg Nesterov 				 __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD)
11192a1f4bcSMatthew Wilcox 
112f021a3c2SMatthew Wilcox #define task_is_traced(task)	((task->state & __TASK_TRACED) != 0)
113f021a3c2SMatthew Wilcox #define task_is_stopped(task)	((task->state & __TASK_STOPPED) != 0)
11492a1f4bcSMatthew Wilcox #define task_is_stopped_or_traced(task)	\
115f021a3c2SMatthew Wilcox 			((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
11692a1f4bcSMatthew Wilcox #define task_contributes_to_load(task)	\
117e3c8ca83SNathan Lynch 				((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
11880ed87c8SPeter Zijlstra 				 (task->flags & PF_FROZEN) == 0 && \
11980ed87c8SPeter Zijlstra 				 (task->state & TASK_NOLOAD) == 0)
1201da177e4SLinus Torvalds 
1218eb23b9fSPeter Zijlstra #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
1228eb23b9fSPeter Zijlstra 
1238eb23b9fSPeter Zijlstra #define __set_current_state(state_value)			\
1248eb23b9fSPeter Zijlstra 	do {							\
1258eb23b9fSPeter Zijlstra 		current->task_state_change = _THIS_IP_;		\
1268eb23b9fSPeter Zijlstra 		current->state = (state_value);			\
1278eb23b9fSPeter Zijlstra 	} while (0)
1288eb23b9fSPeter Zijlstra #define set_current_state(state_value)				\
1298eb23b9fSPeter Zijlstra 	do {							\
1308eb23b9fSPeter Zijlstra 		current->task_state_change = _THIS_IP_;		\
131b92b8b35SPeter Zijlstra 		smp_store_mb(current->state, (state_value));	\
1328eb23b9fSPeter Zijlstra 	} while (0)
1338eb23b9fSPeter Zijlstra 
1348eb23b9fSPeter Zijlstra #else
135498d0c57SAndrew Morton /*
136498d0c57SAndrew Morton  * set_current_state() includes a barrier so that the write of current->state
137498d0c57SAndrew Morton  * is correctly serialised wrt the caller's subsequent test of whether to
138498d0c57SAndrew Morton  * actually sleep:
139498d0c57SAndrew Morton  *
140a2250238SPeter Zijlstra  *   for (;;) {
141498d0c57SAndrew Morton  *	set_current_state(TASK_UNINTERRUPTIBLE);
142a2250238SPeter Zijlstra  *	if (!need_sleep)
143a2250238SPeter Zijlstra  *		break;
144498d0c57SAndrew Morton  *
145a2250238SPeter Zijlstra  *	schedule();
146a2250238SPeter Zijlstra  *   }
147a2250238SPeter Zijlstra  *   __set_current_state(TASK_RUNNING);
148a2250238SPeter Zijlstra  *
149a2250238SPeter Zijlstra  * If the caller does not need such serialisation (because, for instance, the
150a2250238SPeter Zijlstra  * condition test and condition change and wakeup are under the same lock) then
151a2250238SPeter Zijlstra  * use __set_current_state().
152a2250238SPeter Zijlstra  *
153a2250238SPeter Zijlstra  * The above is typically ordered against the wakeup, which does:
154a2250238SPeter Zijlstra  *
155a2250238SPeter Zijlstra  *	need_sleep = false;
156a2250238SPeter Zijlstra  *	wake_up_state(p, TASK_UNINTERRUPTIBLE);
157a2250238SPeter Zijlstra  *
158a2250238SPeter Zijlstra  * Where wake_up_state() (and all other wakeup primitives) imply enough
159a2250238SPeter Zijlstra  * barriers to order the store of the variable against wakeup.
160a2250238SPeter Zijlstra  *
161a2250238SPeter Zijlstra  * Wakeup will do: if (@state & p->state) p->state = TASK_RUNNING, that is,
162a2250238SPeter Zijlstra  * once it observes the TASK_UNINTERRUPTIBLE store the waking CPU can issue a
163a2250238SPeter Zijlstra  * TASK_RUNNING store which can collide with __set_current_state(TASK_RUNNING).
164a2250238SPeter Zijlstra  *
165a2250238SPeter Zijlstra  * This is obviously fine, since they both store the exact same value.
166a2250238SPeter Zijlstra  *
167a2250238SPeter Zijlstra  * Also see the comments of try_to_wake_up().
168498d0c57SAndrew Morton  */
1691da177e4SLinus Torvalds #define __set_current_state(state_value)		\
1701da177e4SLinus Torvalds 	do { current->state = (state_value); } while (0)
1711da177e4SLinus Torvalds #define set_current_state(state_value)			\
172b92b8b35SPeter Zijlstra 	smp_store_mb(current->state, (state_value))
1731da177e4SLinus Torvalds 
1748eb23b9fSPeter Zijlstra #endif
1758eb23b9fSPeter Zijlstra 
1761da177e4SLinus Torvalds /* Task command name length */
1771da177e4SLinus Torvalds #define TASK_COMM_LEN 16
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds extern void sched_init(void);
1801da177e4SLinus Torvalds extern void sched_init_smp(void);
1811da177e4SLinus Torvalds 
1823fa0818bSRik van Riel extern cpumask_var_t cpu_isolated_map;
1833fa0818bSRik van Riel 
18489f19f04SAndrew Morton extern int runqueue_is_locked(int cpu);
185017730c1SIngo Molnar 
1861da177e4SLinus Torvalds extern void cpu_init (void);
1871da177e4SLinus Torvalds extern void trap_init(void);
1881da177e4SLinus Torvalds extern void update_process_times(int user);
1891da177e4SLinus Torvalds extern void scheduler_tick(void);
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds #define	MAX_SCHEDULE_TIMEOUT	LONG_MAX
192b3c97528SHarvey Harrison extern signed long schedule_timeout(signed long timeout);
19364ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout);
194294d5cc2SMatthew Wilcox extern signed long schedule_timeout_killable(signed long timeout);
19564ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout);
19669b27bafSAndrew Morton extern signed long schedule_timeout_idle(signed long timeout);
1971da177e4SLinus Torvalds asmlinkage void schedule(void);
198c5491ea7SThomas Gleixner extern void schedule_preempt_disabled(void);
1991da177e4SLinus Torvalds 
20010ab5643STejun Heo extern int __must_check io_schedule_prepare(void);
20110ab5643STejun Heo extern void io_schedule_finish(int token);
2029cff8adeSNeilBrown extern long io_schedule_timeout(long timeout);
20310ab5643STejun Heo extern void io_schedule(void);
2049cff8adeSNeilBrown 
205f06febc9SFrank Mayhar /**
2069d7fb042SPeter Zijlstra  * struct prev_cputime - snaphsot of system and user cputime
207d37f761dSFrederic Weisbecker  * @utime: time spent in user mode
208d37f761dSFrederic Weisbecker  * @stime: time spent in system mode
2099d7fb042SPeter Zijlstra  * @lock: protects the above two fields
210d37f761dSFrederic Weisbecker  *
2119d7fb042SPeter Zijlstra  * Stores previous user/system time values such that we can guarantee
2129d7fb042SPeter Zijlstra  * monotonicity.
213d37f761dSFrederic Weisbecker  */
2149d7fb042SPeter Zijlstra struct prev_cputime {
2159d7fb042SPeter Zijlstra #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
2165613fda9SFrederic Weisbecker 	u64 utime;
2175613fda9SFrederic Weisbecker 	u64 stime;
2189d7fb042SPeter Zijlstra 	raw_spinlock_t lock;
2199d7fb042SPeter Zijlstra #endif
220d37f761dSFrederic Weisbecker };
221d37f761dSFrederic Weisbecker 
2229d7fb042SPeter Zijlstra static inline void prev_cputime_init(struct prev_cputime *prev)
2239d7fb042SPeter Zijlstra {
2249d7fb042SPeter Zijlstra #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
2259d7fb042SPeter Zijlstra 	prev->utime = prev->stime = 0;
2269d7fb042SPeter Zijlstra 	raw_spin_lock_init(&prev->lock);
2279d7fb042SPeter Zijlstra #endif
2289d7fb042SPeter Zijlstra }
2299d7fb042SPeter Zijlstra 
230d37f761dSFrederic Weisbecker /**
231f06febc9SFrank Mayhar  * struct task_cputime - collected CPU time counts
2325613fda9SFrederic Weisbecker  * @utime:		time spent in user mode, in nanoseconds
2335613fda9SFrederic Weisbecker  * @stime:		time spent in kernel mode, in nanoseconds
234f06febc9SFrank Mayhar  * @sum_exec_runtime:	total time spent on the CPU, in nanoseconds
235f06febc9SFrank Mayhar  *
2369d7fb042SPeter Zijlstra  * This structure groups together three kinds of CPU time that are tracked for
2379d7fb042SPeter Zijlstra  * threads and thread groups.  Most things considering CPU time want to group
2389d7fb042SPeter Zijlstra  * these counts together and treat all three of them in parallel.
239f06febc9SFrank Mayhar  */
240f06febc9SFrank Mayhar struct task_cputime {
2415613fda9SFrederic Weisbecker 	u64 utime;
2425613fda9SFrederic Weisbecker 	u64 stime;
243f06febc9SFrank Mayhar 	unsigned long long sum_exec_runtime;
244f06febc9SFrank Mayhar };
2459d7fb042SPeter Zijlstra 
246f06febc9SFrank Mayhar /* Alternate field names when used to cache expirations. */
247f06febc9SFrank Mayhar #define virt_exp	utime
2489d7fb042SPeter Zijlstra #define prof_exp	stime
249f06febc9SFrank Mayhar #define sched_exp	sum_exec_runtime
250f06febc9SFrank Mayhar 
251971e8a98SJason Low /*
252971e8a98SJason Low  * This is the atomic variant of task_cputime, which can be used for
253971e8a98SJason Low  * storing and updating task_cputime statistics without locking.
254971e8a98SJason Low  */
255971e8a98SJason Low struct task_cputime_atomic {
256971e8a98SJason Low 	atomic64_t utime;
257971e8a98SJason Low 	atomic64_t stime;
258971e8a98SJason Low 	atomic64_t sum_exec_runtime;
259971e8a98SJason Low };
260971e8a98SJason Low 
261971e8a98SJason Low #define INIT_CPUTIME_ATOMIC \
262971e8a98SJason Low 	(struct task_cputime_atomic) {				\
263971e8a98SJason Low 		.utime = ATOMIC64_INIT(0),			\
264971e8a98SJason Low 		.stime = ATOMIC64_INIT(0),			\
265971e8a98SJason Low 		.sum_exec_runtime = ATOMIC64_INIT(0),		\
266971e8a98SJason Low 	}
267971e8a98SJason Low 
268609ca066SPeter Zijlstra #define PREEMPT_DISABLED	(PREEMPT_DISABLE_OFFSET + PREEMPT_ENABLED)
269a233f112SPeter Zijlstra 
270c99e6efeSPeter Zijlstra /*
27187dcbc06SPeter Zijlstra  * Disable preemption until the scheduler is running -- use an unconditional
27287dcbc06SPeter Zijlstra  * value so that it also works on !PREEMPT_COUNT kernels.
273d86ee480SPeter Zijlstra  *
27487dcbc06SPeter Zijlstra  * Reset by start_kernel()->sched_init()->init_idle()->init_idle_preempt_count().
275c99e6efeSPeter Zijlstra  */
27687dcbc06SPeter Zijlstra #define INIT_PREEMPT_COUNT	PREEMPT_OFFSET
277c99e6efeSPeter Zijlstra 
278609ca066SPeter Zijlstra /*
279609ca066SPeter Zijlstra  * Initial preempt_count value; reflects the preempt_count schedule invariant
280609ca066SPeter Zijlstra  * which states that during context switches:
281609ca066SPeter Zijlstra  *
282609ca066SPeter Zijlstra  *    preempt_count() == 2*PREEMPT_DISABLE_OFFSET
283609ca066SPeter Zijlstra  *
284609ca066SPeter Zijlstra  * Note: PREEMPT_DISABLE_OFFSET is 0 for !PREEMPT_COUNT kernels.
285609ca066SPeter Zijlstra  * Note: See finish_task_switch().
286609ca066SPeter Zijlstra  */
287609ca066SPeter Zijlstra #define FORK_PREEMPT_COUNT	(2*PREEMPT_DISABLE_OFFSET + PREEMPT_ENABLED)
2884cd4c1b4SPeter Zijlstra 
289f06febc9SFrank Mayhar /**
290f06febc9SFrank Mayhar  * struct thread_group_cputimer - thread group interval timer counts
291920ce39fSJason Low  * @cputime_atomic:	atomic thread group interval timers.
292d5c373ebSJason Low  * @running:		true when there are timers running and
293d5c373ebSJason Low  *			@cputime_atomic receives updates.
294c8d75aa4SJason Low  * @checking_timer:	true when a thread in the group is in the
295c8d75aa4SJason Low  *			process of checking for thread group timers.
296f06febc9SFrank Mayhar  *
297f06febc9SFrank Mayhar  * This structure contains the version of task_cputime, above, that is
2984cd4c1b4SPeter Zijlstra  * used for thread group CPU timer calculations.
299f06febc9SFrank Mayhar  */
3004cd4c1b4SPeter Zijlstra struct thread_group_cputimer {
30171107445SJason Low 	struct task_cputime_atomic cputime_atomic;
302d5c373ebSJason Low 	bool running;
303c8d75aa4SJason Low 	bool checking_timer;
304f06febc9SFrank Mayhar };
305f06febc9SFrank Mayhar 
3064714d1d3SBen Blum #include <linux/rwsem.h>
3071da177e4SLinus Torvalds 
308f6db8347SNaveen N. Rao #ifdef CONFIG_SCHED_INFO
3091da177e4SLinus Torvalds struct sched_info {
3101da177e4SLinus Torvalds 	/* cumulative counters */
3112d72376bSIngo Molnar 	unsigned long pcount;	      /* # of times run on this cpu */
3129c2c4802SKen Chen 	unsigned long long run_delay; /* time spent waiting on a runqueue */
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds 	/* timestamps */
315172ba844SBalbir Singh 	unsigned long long last_arrival,/* when we last ran on a cpu */
3161da177e4SLinus Torvalds 			   last_queued;	/* when we were last queued to run */
3171da177e4SLinus Torvalds };
318f6db8347SNaveen N. Rao #endif /* CONFIG_SCHED_INFO */
3191da177e4SLinus Torvalds 
32052f17b6cSChandra Seetharaman static inline int sched_info_on(void)
32152f17b6cSChandra Seetharaman {
32252f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS
32352f17b6cSChandra Seetharaman 	return 1;
32452f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT)
32552f17b6cSChandra Seetharaman 	extern int delayacct_on;
32652f17b6cSChandra Seetharaman 	return delayacct_on;
32752f17b6cSChandra Seetharaman #else
32852f17b6cSChandra Seetharaman 	return 0;
329ca74e92bSShailabh Nagar #endif
33052f17b6cSChandra Seetharaman }
331ca74e92bSShailabh Nagar 
332cb251765SMel Gorman #ifdef CONFIG_SCHEDSTATS
333cb251765SMel Gorman void force_schedstat_enabled(void);
334cb251765SMel Gorman #endif
335cb251765SMel Gorman 
3361da177e4SLinus Torvalds /*
3376ecdd749SYuyang Du  * Integer metrics need fixed point arithmetic, e.g., sched/fair
3386ecdd749SYuyang Du  * has a few: load, load_avg, util_avg, freq, and capacity.
3396ecdd749SYuyang Du  *
3406ecdd749SYuyang Du  * We define a basic fixed point arithmetic range, and then formalize
3416ecdd749SYuyang Du  * all these metrics based on that basic range.
3426ecdd749SYuyang Du  */
3436ecdd749SYuyang Du # define SCHED_FIXEDPOINT_SHIFT	10
3446ecdd749SYuyang Du # define SCHED_FIXEDPOINT_SCALE	(1L << SCHED_FIXEDPOINT_SHIFT)
3456ecdd749SYuyang Du 
346383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
34736c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t);
348383f2835SChen, Kenneth W #else
349383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { }
350383f2835SChen, Kenneth W #endif
3511da177e4SLinus Torvalds 
35220b8a59fSIngo Molnar struct load_weight {
3539dbdb155SPeter Zijlstra 	unsigned long weight;
3549dbdb155SPeter Zijlstra 	u32 inv_weight;
35520b8a59fSIngo Molnar };
35620b8a59fSIngo Molnar 
3579d89c257SYuyang Du /*
3587b595334SYuyang Du  * The load_avg/util_avg accumulates an infinite geometric series
3597b595334SYuyang Du  * (see __update_load_avg() in kernel/sched/fair.c).
3607b595334SYuyang Du  *
3617b595334SYuyang Du  * [load_avg definition]
3627b595334SYuyang Du  *
3637b595334SYuyang Du  *   load_avg = runnable% * scale_load_down(load)
3647b595334SYuyang Du  *
3657b595334SYuyang Du  * where runnable% is the time ratio that a sched_entity is runnable.
3667b595334SYuyang Du  * For cfs_rq, it is the aggregated load_avg of all runnable and
3679d89c257SYuyang Du  * blocked sched_entities.
3687b595334SYuyang Du  *
3697b595334SYuyang Du  * load_avg may also take frequency scaling into account:
3707b595334SYuyang Du  *
3717b595334SYuyang Du  *   load_avg = runnable% * scale_load_down(load) * freq%
3727b595334SYuyang Du  *
3737b595334SYuyang Du  * where freq% is the CPU frequency normalized to the highest frequency.
3747b595334SYuyang Du  *
3757b595334SYuyang Du  * [util_avg definition]
3767b595334SYuyang Du  *
3777b595334SYuyang Du  *   util_avg = running% * SCHED_CAPACITY_SCALE
3787b595334SYuyang Du  *
3797b595334SYuyang Du  * where running% is the time ratio that a sched_entity is running on
3807b595334SYuyang Du  * a CPU. For cfs_rq, it is the aggregated util_avg of all runnable
3817b595334SYuyang Du  * and blocked sched_entities.
3827b595334SYuyang Du  *
3837b595334SYuyang Du  * util_avg may also factor frequency scaling and CPU capacity scaling:
3847b595334SYuyang Du  *
3857b595334SYuyang Du  *   util_avg = running% * SCHED_CAPACITY_SCALE * freq% * capacity%
3867b595334SYuyang Du  *
3877b595334SYuyang Du  * where freq% is the same as above, and capacity% is the CPU capacity
3887b595334SYuyang Du  * normalized to the greatest capacity (due to uarch differences, etc).
3897b595334SYuyang Du  *
3907b595334SYuyang Du  * N.B., the above ratios (runnable%, running%, freq%, and capacity%)
3917b595334SYuyang Du  * themselves are in the range of [0, 1]. To do fixed point arithmetics,
3927b595334SYuyang Du  * we therefore scale them to as large a range as necessary. This is for
3937b595334SYuyang Du  * example reflected by util_avg's SCHED_CAPACITY_SCALE.
3947b595334SYuyang Du  *
3957b595334SYuyang Du  * [Overflow issue]
3967b595334SYuyang Du  *
3977b595334SYuyang Du  * The 64-bit load_sum can have 4353082796 (=2^64/47742/88761) entities
3987b595334SYuyang Du  * with the highest load (=88761), always runnable on a single cfs_rq,
3997b595334SYuyang Du  * and should not overflow as the number already hits PID_MAX_LIMIT.
4007b595334SYuyang Du  *
4017b595334SYuyang Du  * For all other cases (including 32-bit kernels), struct load_weight's
4027b595334SYuyang Du  * weight will overflow first before we do, because:
4037b595334SYuyang Du  *
4047b595334SYuyang Du  *    Max(load_avg) <= Max(load.weight)
4057b595334SYuyang Du  *
4067b595334SYuyang Du  * Then it is the load_weight's responsibility to consider overflow
4077b595334SYuyang Du  * issues.
4089d89c257SYuyang Du  */
4099d85f21cSPaul Turner struct sched_avg {
4109d89c257SYuyang Du 	u64 last_update_time, load_sum;
4119d89c257SYuyang Du 	u32 util_sum, period_contrib;
4129d89c257SYuyang Du 	unsigned long load_avg, util_avg;
4139d85f21cSPaul Turner };
4149d85f21cSPaul Turner 
41594c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS
41641acab88SLucas De Marchi struct sched_statistics {
41794c18227SIngo Molnar 	u64			wait_start;
41894c18227SIngo Molnar 	u64			wait_max;
4196d082592SArjan van de Ven 	u64			wait_count;
4206d082592SArjan van de Ven 	u64			wait_sum;
4218f0dfc34SArjan van de Ven 	u64			iowait_count;
4228f0dfc34SArjan van de Ven 	u64			iowait_sum;
42394c18227SIngo Molnar 
42494c18227SIngo Molnar 	u64			sleep_start;
42520b8a59fSIngo Molnar 	u64			sleep_max;
42694c18227SIngo Molnar 	s64			sum_sleep_runtime;
42794c18227SIngo Molnar 
42894c18227SIngo Molnar 	u64			block_start;
42920b8a59fSIngo Molnar 	u64			block_max;
43020b8a59fSIngo Molnar 	u64			exec_max;
431eba1ed4bSIngo Molnar 	u64			slice_max;
432cc367732SIngo Molnar 
433cc367732SIngo Molnar 	u64			nr_migrations_cold;
434cc367732SIngo Molnar 	u64			nr_failed_migrations_affine;
435cc367732SIngo Molnar 	u64			nr_failed_migrations_running;
436cc367732SIngo Molnar 	u64			nr_failed_migrations_hot;
437cc367732SIngo Molnar 	u64			nr_forced_migrations;
438cc367732SIngo Molnar 
439cc367732SIngo Molnar 	u64			nr_wakeups;
440cc367732SIngo Molnar 	u64			nr_wakeups_sync;
441cc367732SIngo Molnar 	u64			nr_wakeups_migrate;
442cc367732SIngo Molnar 	u64			nr_wakeups_local;
443cc367732SIngo Molnar 	u64			nr_wakeups_remote;
444cc367732SIngo Molnar 	u64			nr_wakeups_affine;
445cc367732SIngo Molnar 	u64			nr_wakeups_affine_attempts;
446cc367732SIngo Molnar 	u64			nr_wakeups_passive;
447cc367732SIngo Molnar 	u64			nr_wakeups_idle;
44841acab88SLucas De Marchi };
44941acab88SLucas De Marchi #endif
45041acab88SLucas De Marchi 
45141acab88SLucas De Marchi struct sched_entity {
45241acab88SLucas De Marchi 	struct load_weight	load;		/* for load-balancing */
45341acab88SLucas De Marchi 	struct rb_node		run_node;
45441acab88SLucas De Marchi 	struct list_head	group_node;
45541acab88SLucas De Marchi 	unsigned int		on_rq;
45641acab88SLucas De Marchi 
45741acab88SLucas De Marchi 	u64			exec_start;
45841acab88SLucas De Marchi 	u64			sum_exec_runtime;
45941acab88SLucas De Marchi 	u64			vruntime;
46041acab88SLucas De Marchi 	u64			prev_sum_exec_runtime;
46141acab88SLucas De Marchi 
46241acab88SLucas De Marchi 	u64			nr_migrations;
46341acab88SLucas De Marchi 
46441acab88SLucas De Marchi #ifdef CONFIG_SCHEDSTATS
46541acab88SLucas De Marchi 	struct sched_statistics statistics;
46694c18227SIngo Molnar #endif
46794c18227SIngo Molnar 
46820b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED
469fed14d45SPeter Zijlstra 	int			depth;
47020b8a59fSIngo Molnar 	struct sched_entity	*parent;
47120b8a59fSIngo Molnar 	/* rq on which this entity is (to be) queued: */
47220b8a59fSIngo Molnar 	struct cfs_rq		*cfs_rq;
47320b8a59fSIngo Molnar 	/* rq "owned" by this entity/group: */
47420b8a59fSIngo Molnar 	struct cfs_rq		*my_q;
47520b8a59fSIngo Molnar #endif
4768bd75c77SClark Williams 
477141965c7SAlex Shi #ifdef CONFIG_SMP
4785a107804SJiri Olsa 	/*
4795a107804SJiri Olsa 	 * Per entity load average tracking.
4805a107804SJiri Olsa 	 *
4815a107804SJiri Olsa 	 * Put into separate cache line so it does not
4825a107804SJiri Olsa 	 * collide with read-mostly values above.
4835a107804SJiri Olsa 	 */
4845a107804SJiri Olsa 	struct sched_avg	avg ____cacheline_aligned_in_smp;
4859d85f21cSPaul Turner #endif
48620b8a59fSIngo Molnar };
48770b97a7fSIngo Molnar 
488fa717060SPeter Zijlstra struct sched_rt_entity {
489fa717060SPeter Zijlstra 	struct list_head run_list;
49078f2c7dbSPeter Zijlstra 	unsigned long timeout;
49157d2aa00SYing Xue 	unsigned long watchdog_stamp;
492bee367edSRichard Kennedy 	unsigned int time_slice;
493ff77e468SPeter Zijlstra 	unsigned short on_rq;
494ff77e468SPeter Zijlstra 	unsigned short on_list;
4956f505b16SPeter Zijlstra 
49658d6c2d7SPeter Zijlstra 	struct sched_rt_entity *back;
497052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED
4986f505b16SPeter Zijlstra 	struct sched_rt_entity	*parent;
4996f505b16SPeter Zijlstra 	/* rq on which this entity is (to be) queued: */
5006f505b16SPeter Zijlstra 	struct rt_rq		*rt_rq;
5016f505b16SPeter Zijlstra 	/* rq "owned" by this entity/group: */
5026f505b16SPeter Zijlstra 	struct rt_rq		*my_q;
5036f505b16SPeter Zijlstra #endif
504fa717060SPeter Zijlstra };
505fa717060SPeter Zijlstra 
506aab03e05SDario Faggioli struct sched_dl_entity {
507aab03e05SDario Faggioli 	struct rb_node	rb_node;
508aab03e05SDario Faggioli 
509aab03e05SDario Faggioli 	/*
510aab03e05SDario Faggioli 	 * Original scheduling parameters. Copied here from sched_attr
5114027d080Sxiaofeng.yan 	 * during sched_setattr(), they will remain the same until
5124027d080Sxiaofeng.yan 	 * the next sched_setattr().
513aab03e05SDario Faggioli 	 */
514aab03e05SDario Faggioli 	u64 dl_runtime;		/* maximum runtime for each instance	*/
515aab03e05SDario Faggioli 	u64 dl_deadline;	/* relative deadline of each instance	*/
516755378a4SHarald Gustafsson 	u64 dl_period;		/* separation of two instances (period) */
517332ac17eSDario Faggioli 	u64 dl_bw;		/* dl_runtime / dl_deadline		*/
518aab03e05SDario Faggioli 
519aab03e05SDario Faggioli 	/*
520aab03e05SDario Faggioli 	 * Actual scheduling parameters. Initialized with the values above,
521aab03e05SDario Faggioli 	 * they are continously updated during task execution. Note that
522aab03e05SDario Faggioli 	 * the remaining runtime could be < 0 in case we are in overrun.
523aab03e05SDario Faggioli 	 */
524aab03e05SDario Faggioli 	s64 runtime;		/* remaining runtime for this instance	*/
525aab03e05SDario Faggioli 	u64 deadline;		/* absolute deadline for this instance	*/
526aab03e05SDario Faggioli 	unsigned int flags;	/* specifying the scheduler behaviour	*/
527aab03e05SDario Faggioli 
528aab03e05SDario Faggioli 	/*
529aab03e05SDario Faggioli 	 * Some bool flags:
530aab03e05SDario Faggioli 	 *
531aab03e05SDario Faggioli 	 * @dl_throttled tells if we exhausted the runtime. If so, the
532aab03e05SDario Faggioli 	 * task has to wait for a replenishment to be performed at the
533aab03e05SDario Faggioli 	 * next firing of dl_timer.
534aab03e05SDario Faggioli 	 *
5352d3d891dSDario Faggioli 	 * @dl_boosted tells if we are boosted due to DI. If so we are
5362d3d891dSDario Faggioli 	 * outside bandwidth enforcement mechanism (but only until we
5375bfd126eSJuri Lelli 	 * exit the critical section);
5385bfd126eSJuri Lelli 	 *
5395bfd126eSJuri Lelli 	 * @dl_yielded tells if task gave up the cpu before consuming
5405bfd126eSJuri Lelli 	 * all its available runtime during the last job.
541aab03e05SDario Faggioli 	 */
54272f9f3fdSLuca Abeni 	int dl_throttled, dl_boosted, dl_yielded;
543aab03e05SDario Faggioli 
544aab03e05SDario Faggioli 	/*
545aab03e05SDario Faggioli 	 * Bandwidth enforcement timer. Each -deadline task has its
546aab03e05SDario Faggioli 	 * own bandwidth to be enforced, thus we need one timer per task.
547aab03e05SDario Faggioli 	 */
548aab03e05SDario Faggioli 	struct hrtimer dl_timer;
549aab03e05SDario Faggioli };
5508bd75c77SClark Williams 
5511d082fd0SPaul E. McKenney union rcu_special {
5521d082fd0SPaul E. McKenney 	struct {
5538203d6d0SPaul E. McKenney 		u8 blocked;
5548203d6d0SPaul E. McKenney 		u8 need_qs;
5558203d6d0SPaul E. McKenney 		u8 exp_need_qs;
5568203d6d0SPaul E. McKenney 		u8 pad;	/* Otherwise the compiler can store garbage here. */
5578203d6d0SPaul E. McKenney 	} b; /* Bits. */
5588203d6d0SPaul E. McKenney 	u32 s; /* Set of bits. */
5591d082fd0SPaul E. McKenney };
56086848966SPaul E. McKenney 
5618dc85d54SPeter Zijlstra enum perf_event_task_context {
5628dc85d54SPeter Zijlstra 	perf_invalid_context = -1,
5638dc85d54SPeter Zijlstra 	perf_hw_context = 0,
56489a1e187SPeter Zijlstra 	perf_sw_context,
5658dc85d54SPeter Zijlstra 	perf_nr_task_contexts,
5668dc85d54SPeter Zijlstra };
5678dc85d54SPeter Zijlstra 
568eb61baf6SIngo Molnar struct wake_q_node {
569eb61baf6SIngo Molnar 	struct wake_q_node *next;
570eb61baf6SIngo Molnar };
571eb61baf6SIngo Molnar 
57272b252aeSMel Gorman /* Track pages that require TLB flushes */
57372b252aeSMel Gorman struct tlbflush_unmap_batch {
57472b252aeSMel Gorman 	/*
57572b252aeSMel Gorman 	 * Each bit set is a CPU that potentially has a TLB entry for one of
57672b252aeSMel Gorman 	 * the PFNs being flushed. See set_tlb_ubc_flush_pending().
57772b252aeSMel Gorman 	 */
57872b252aeSMel Gorman 	struct cpumask cpumask;
57972b252aeSMel Gorman 
58072b252aeSMel Gorman 	/* True if any bit in cpumask is set */
58172b252aeSMel Gorman 	bool flush_required;
582d950c947SMel Gorman 
583d950c947SMel Gorman 	/*
584d950c947SMel Gorman 	 * If true then the PTE was dirty when unmapped. The entry must be
585d950c947SMel Gorman 	 * flushed before IO is initiated or a stale TLB entry potentially
586d950c947SMel Gorman 	 * allows an update without redirtying the page.
587d950c947SMel Gorman 	 */
588d950c947SMel Gorman 	bool writable;
58972b252aeSMel Gorman };
59072b252aeSMel Gorman 
5911da177e4SLinus Torvalds struct task_struct {
592c65eacbeSAndy Lutomirski #ifdef CONFIG_THREAD_INFO_IN_TASK
593c65eacbeSAndy Lutomirski 	/*
594c65eacbeSAndy Lutomirski 	 * For reasons of header soup (see current_thread_info()), this
595c65eacbeSAndy Lutomirski 	 * must be the first element of task_struct.
596c65eacbeSAndy Lutomirski 	 */
597c65eacbeSAndy Lutomirski 	struct thread_info thread_info;
598c65eacbeSAndy Lutomirski #endif
5991da177e4SLinus Torvalds 	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
600f7e4217bSRoman Zippel 	void *stack;
6011da177e4SLinus Torvalds 	atomic_t usage;
60297dc32cdSWilliam Cohen 	unsigned int flags;	/* per process flags, defined below */
60397dc32cdSWilliam Cohen 	unsigned int ptrace;
6041da177e4SLinus Torvalds 
6052dd73a4fSPeter Williams #ifdef CONFIG_SMP
606fa14ff4aSPeter Zijlstra 	struct llist_node wake_entry;
6073ca7a440SPeter Zijlstra 	int on_cpu;
608c65eacbeSAndy Lutomirski #ifdef CONFIG_THREAD_INFO_IN_TASK
609c65eacbeSAndy Lutomirski 	unsigned int cpu;	/* current CPU */
610c65eacbeSAndy Lutomirski #endif
61163b0e9edSMike Galbraith 	unsigned int wakee_flips;
61262470419SMichael Wang 	unsigned long wakee_flip_decay_ts;
61363b0e9edSMike Galbraith 	struct task_struct *last_wakee;
614ac66f547SPeter Zijlstra 
615ac66f547SPeter Zijlstra 	int wake_cpu;
6164866cde0SNick Piggin #endif
617fd2f4419SPeter Zijlstra 	int on_rq;
61850e645a8SIngo Molnar 
619b29739f9SIngo Molnar 	int prio, static_prio, normal_prio;
620c7aceabaSRichard Kennedy 	unsigned int rt_priority;
6215522d5d5SIngo Molnar 	const struct sched_class *sched_class;
62220b8a59fSIngo Molnar 	struct sched_entity se;
623fa717060SPeter Zijlstra 	struct sched_rt_entity rt;
6248323f26cSPeter Zijlstra #ifdef CONFIG_CGROUP_SCHED
6258323f26cSPeter Zijlstra 	struct task_group *sched_task_group;
6268323f26cSPeter Zijlstra #endif
627aab03e05SDario Faggioli 	struct sched_dl_entity dl;
6281da177e4SLinus Torvalds 
629e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS
630e107be36SAvi Kivity 	/* list of struct preempt_notifier: */
631e107be36SAvi Kivity 	struct hlist_head preempt_notifiers;
632e107be36SAvi Kivity #endif
633e107be36SAvi Kivity 
6346c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE
6352056a782SJens Axboe 	unsigned int btrace_seq;
6366c5c9341SAlexey Dobriyan #endif
6371da177e4SLinus Torvalds 
63897dc32cdSWilliam Cohen 	unsigned int policy;
63929baa747SPeter Zijlstra 	int nr_cpus_allowed;
6401da177e4SLinus Torvalds 	cpumask_t cpus_allowed;
6411da177e4SLinus Torvalds 
642a57eb940SPaul E. McKenney #ifdef CONFIG_PREEMPT_RCU
643e260be67SPaul E. McKenney 	int rcu_read_lock_nesting;
6441d082fd0SPaul E. McKenney 	union rcu_special rcu_read_unlock_special;
645f41d911fSPaul E. McKenney 	struct list_head rcu_node_entry;
646a57eb940SPaul E. McKenney 	struct rcu_node *rcu_blocked_node;
64728f6569aSPranith Kumar #endif /* #ifdef CONFIG_PREEMPT_RCU */
6488315f422SPaul E. McKenney #ifdef CONFIG_TASKS_RCU
6498315f422SPaul E. McKenney 	unsigned long rcu_tasks_nvcsw;
6508315f422SPaul E. McKenney 	bool rcu_tasks_holdout;
6518315f422SPaul E. McKenney 	struct list_head rcu_tasks_holdout_list;
652176f8f7aSPaul E. McKenney 	int rcu_tasks_idle_cpu;
6538315f422SPaul E. McKenney #endif /* #ifdef CONFIG_TASKS_RCU */
654e260be67SPaul E. McKenney 
655f6db8347SNaveen N. Rao #ifdef CONFIG_SCHED_INFO
6561da177e4SLinus Torvalds 	struct sched_info sched_info;
6571da177e4SLinus Torvalds #endif
6581da177e4SLinus Torvalds 
6591da177e4SLinus Torvalds 	struct list_head tasks;
660806c09a7SDario Faggioli #ifdef CONFIG_SMP
661917b627dSGregory Haskins 	struct plist_node pushable_tasks;
6621baca4ceSJuri Lelli 	struct rb_node pushable_dl_tasks;
663806c09a7SDario Faggioli #endif
6641da177e4SLinus Torvalds 
6651da177e4SLinus Torvalds 	struct mm_struct *mm, *active_mm;
666314ff785SIngo Molnar 
667314ff785SIngo Molnar 	/* Per-thread vma caching: */
668314ff785SIngo Molnar 	struct vmacache vmacache;
669314ff785SIngo Molnar 
67034e55232SKAMEZAWA Hiroyuki #if defined(SPLIT_RSS_COUNTING)
67134e55232SKAMEZAWA Hiroyuki 	struct task_rss_stat	rss_stat;
67234e55232SKAMEZAWA Hiroyuki #endif
6731da177e4SLinus Torvalds /* task state */
67497dc32cdSWilliam Cohen 	int exit_state;
6751da177e4SLinus Torvalds 	int exit_code, exit_signal;
6761da177e4SLinus Torvalds 	int pdeath_signal;  /*  The signal sent when the parent dies  */
677e7cc4173SPalmer Dabbelt 	unsigned long jobctl;	/* JOBCTL_*, siglock protected */
6789b89f6baSAndrei Epure 
6799b89f6baSAndrei Epure 	/* Used for emulating ABI behavior of previous Linux versions */
68097dc32cdSWilliam Cohen 	unsigned int personality;
6819b89f6baSAndrei Epure 
682be958bdcSPeter Zijlstra 	/* scheduler bits, serialized by scheduler locks */
683ca94c442SLennart Poettering 	unsigned sched_reset_on_fork:1;
684a8e4f2eaSPeter Zijlstra 	unsigned sched_contributes_to_load:1;
685ff303e66SPeter Zijlstra 	unsigned sched_migrated:1;
686b7e7ade3SPeter Zijlstra 	unsigned sched_remote_wakeup:1;
687be958bdcSPeter Zijlstra 	unsigned :0; /* force alignment to the next boundary */
688be958bdcSPeter Zijlstra 
689be958bdcSPeter Zijlstra 	/* unserialized, strictly 'current' */
690be958bdcSPeter Zijlstra 	unsigned in_execve:1; /* bit to tell LSMs we're in execve */
691be958bdcSPeter Zijlstra 	unsigned in_iowait:1;
6927e781418SAndy Lutomirski #if !defined(TIF_RESTORE_SIGMASK)
6937e781418SAndy Lutomirski 	unsigned restore_sigmask:1;
6947e781418SAndy Lutomirski #endif
695626ebc41STejun Heo #ifdef CONFIG_MEMCG
696626ebc41STejun Heo 	unsigned memcg_may_oom:1;
697127424c8SJohannes Weiner #ifndef CONFIG_SLOB
6986f185c29SVladimir Davydov 	unsigned memcg_kmem_skip_account:1;
6996f185c29SVladimir Davydov #endif
700127424c8SJohannes Weiner #endif
701ff303e66SPeter Zijlstra #ifdef CONFIG_COMPAT_BRK
702ff303e66SPeter Zijlstra 	unsigned brk_randomized:1;
703ff303e66SPeter Zijlstra #endif
7046f185c29SVladimir Davydov 
7051d4457f9SKees Cook 	unsigned long atomic_flags; /* Flags needing atomic access. */
7061d4457f9SKees Cook 
707f56141e3SAndy Lutomirski 	struct restart_block restart_block;
708f56141e3SAndy Lutomirski 
7091da177e4SLinus Torvalds 	pid_t pid;
7101da177e4SLinus Torvalds 	pid_t tgid;
7110a425405SArjan van de Ven 
7121314562aSHiroshi Shimamoto #ifdef CONFIG_CC_STACKPROTECTOR
7130a425405SArjan van de Ven 	/* Canary value for the -fstack-protector gcc feature */
7140a425405SArjan van de Ven 	unsigned long stack_canary;
7151314562aSHiroshi Shimamoto #endif
7161da177e4SLinus Torvalds 	/*
7171da177e4SLinus Torvalds 	 * pointers to (original) parent process, youngest child, younger sibling,
7181da177e4SLinus Torvalds 	 * older sibling, respectively.  (p->father can be replaced with
719f470021aSRoland McGrath 	 * p->real_parent->pid)
7201da177e4SLinus Torvalds 	 */
721abd63bc3SKees Cook 	struct task_struct __rcu *real_parent; /* real parent process */
722abd63bc3SKees Cook 	struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
7231da177e4SLinus Torvalds 	/*
724f470021aSRoland McGrath 	 * children/sibling forms the list of my natural children
7251da177e4SLinus Torvalds 	 */
7261da177e4SLinus Torvalds 	struct list_head children;	/* list of my children */
7271da177e4SLinus Torvalds 	struct list_head sibling;	/* linkage in my parent's children list */
7281da177e4SLinus Torvalds 	struct task_struct *group_leader;	/* threadgroup leader */
7291da177e4SLinus Torvalds 
730f470021aSRoland McGrath 	/*
731f470021aSRoland McGrath 	 * ptraced is the list of tasks this task is using ptrace on.
732f470021aSRoland McGrath 	 * This includes both natural children and PTRACE_ATTACH targets.
733f470021aSRoland McGrath 	 * p->ptrace_entry is p's link on the p->parent->ptraced list.
734f470021aSRoland McGrath 	 */
735f470021aSRoland McGrath 	struct list_head ptraced;
736f470021aSRoland McGrath 	struct list_head ptrace_entry;
737f470021aSRoland McGrath 
7381da177e4SLinus Torvalds 	/* PID/PID hash table linkage. */
73992476d7fSEric W. Biederman 	struct pid_link pids[PIDTYPE_MAX];
74047e65328SOleg Nesterov 	struct list_head thread_group;
7410c740d0aSOleg Nesterov 	struct list_head thread_node;
7421da177e4SLinus Torvalds 
7431da177e4SLinus Torvalds 	struct completion *vfork_done;		/* for vfork() */
7441da177e4SLinus Torvalds 	int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
7451da177e4SLinus Torvalds 	int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */
7461da177e4SLinus Torvalds 
7475613fda9SFrederic Weisbecker 	u64 utime, stime;
74840565b5aSStanislaw Gruszka #ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
7495613fda9SFrederic Weisbecker 	u64 utimescaled, stimescaled;
75040565b5aSStanislaw Gruszka #endif
75116a6d9beSFrederic Weisbecker 	u64 gtime;
7529d7fb042SPeter Zijlstra 	struct prev_cputime prev_cputime;
7536a61671bSFrederic Weisbecker #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
754b7ce2277SFrederic Weisbecker 	seqcount_t vtime_seqcount;
7556a61671bSFrederic Weisbecker 	unsigned long long vtime_snap;
7566a61671bSFrederic Weisbecker 	enum {
7577098c1eaSFrederic Weisbecker 		/* Task is sleeping or running in a CPU with VTIME inactive */
7587098c1eaSFrederic Weisbecker 		VTIME_INACTIVE = 0,
7597098c1eaSFrederic Weisbecker 		/* Task runs in userspace in a CPU with VTIME active */
7606a61671bSFrederic Weisbecker 		VTIME_USER,
7617098c1eaSFrederic Weisbecker 		/* Task runs in kernelspace in a CPU with VTIME active */
7626a61671bSFrederic Weisbecker 		VTIME_SYS,
7636a61671bSFrederic Weisbecker 	} vtime_snap_whence;
7646a61671bSFrederic Weisbecker #endif
765d027d45dSFrederic Weisbecker 
766d027d45dSFrederic Weisbecker #ifdef CONFIG_NO_HZ_FULL
767f009a7a7SFrederic Weisbecker 	atomic_t tick_dep_mask;
768d027d45dSFrederic Weisbecker #endif
7691da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw; /* context switch counts */
770ccbf62d8SThomas Gleixner 	u64 start_time;		/* monotonic time in nsec */
77157e0be04SThomas Gleixner 	u64 real_start_time;	/* boot based time in nsec */
7721da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
7731da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt;
7741da177e4SLinus Torvalds 
775b18b6a9cSNicolas Pitre #ifdef CONFIG_POSIX_TIMERS
776f06febc9SFrank Mayhar 	struct task_cputime cputime_expires;
7771da177e4SLinus Torvalds 	struct list_head cpu_timers[3];
778b18b6a9cSNicolas Pitre #endif
7791da177e4SLinus Torvalds 
7801da177e4SLinus Torvalds /* process credentials */
78164b875f7SEric W. Biederman 	const struct cred __rcu *ptracer_cred; /* Tracer's credentials at attach */
7821b0ba1c9SArnd Bergmann 	const struct cred __rcu *real_cred; /* objective and real subjective task
7833b11a1deSDavid Howells 					 * credentials (COW) */
7841b0ba1c9SArnd Bergmann 	const struct cred __rcu *cred;	/* effective (overridable) subjective task
7853b11a1deSDavid Howells 					 * credentials (COW) */
78636772092SPaolo 'Blaisorblade' Giarrusso 	char comm[TASK_COMM_LEN]; /* executable name excluding path
78736772092SPaolo 'Blaisorblade' Giarrusso 				     - access with [gs]et_task_comm (which lock
78836772092SPaolo 'Blaisorblade' Giarrusso 				       it with task_lock())
789221af7f8SLinus Torvalds 				     - initialized normally by setup_new_exec */
7901da177e4SLinus Torvalds /* file system info */
791756daf26SNeilBrown 	struct nameidata *nameidata;
7923d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC
7931da177e4SLinus Torvalds /* ipc stuff */
7941da177e4SLinus Torvalds 	struct sysv_sem sysvsem;
795ab602f79SJack Miller 	struct sysv_shm sysvshm;
7963d5b6fccSAlexey Dobriyan #endif
797e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
79882a1fcb9SIngo Molnar /* hung task detection */
79982a1fcb9SIngo Molnar 	unsigned long last_switch_count;
80082a1fcb9SIngo Molnar #endif
8011da177e4SLinus Torvalds /* filesystem information */
8021da177e4SLinus Torvalds 	struct fs_struct *fs;
8031da177e4SLinus Torvalds /* open file information */
8041da177e4SLinus Torvalds 	struct files_struct *files;
8051651e14eSSerge E. Hallyn /* namespaces */
806ab516013SSerge E. Hallyn 	struct nsproxy *nsproxy;
8071da177e4SLinus Torvalds /* signal handlers */
8081da177e4SLinus Torvalds 	struct signal_struct *signal;
8091da177e4SLinus Torvalds 	struct sighand_struct *sighand;
8101da177e4SLinus Torvalds 
8111da177e4SLinus Torvalds 	sigset_t blocked, real_blocked;
812f3de272bSRoland McGrath 	sigset_t saved_sigmask;	/* restored if set_restore_sigmask() was used */
8131da177e4SLinus Torvalds 	struct sigpending pending;
8141da177e4SLinus Torvalds 
8151da177e4SLinus Torvalds 	unsigned long sas_ss_sp;
8161da177e4SLinus Torvalds 	size_t sas_ss_size;
8172a742138SStas Sergeev 	unsigned sas_ss_flags;
8182e01fabeSOleg Nesterov 
81967d12145SAl Viro 	struct callback_head *task_works;
820e73f8959SOleg Nesterov 
8211da177e4SLinus Torvalds 	struct audit_context *audit_context;
822bfef93a5SAl Viro #ifdef CONFIG_AUDITSYSCALL
823e1760bd5SEric W. Biederman 	kuid_t loginuid;
8244746ec5bSEric Paris 	unsigned int sessionid;
825bfef93a5SAl Viro #endif
826932ecebbSWill Drewry 	struct seccomp seccomp;
8271da177e4SLinus Torvalds 
8281da177e4SLinus Torvalds /* Thread group tracking */
8291da177e4SLinus Torvalds    	u32 parent_exec_id;
8301da177e4SLinus Torvalds    	u32 self_exec_id;
83158568d2aSMiao Xie /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
83258568d2aSMiao Xie  * mempolicy */
8331da177e4SLinus Torvalds 	spinlock_t alloc_lock;
8341da177e4SLinus Torvalds 
835b29739f9SIngo Molnar 	/* Protection of the PI data structures: */
8361d615482SThomas Gleixner 	raw_spinlock_t pi_lock;
837b29739f9SIngo Molnar 
83876751049SPeter Zijlstra 	struct wake_q_node wake_q;
83976751049SPeter Zijlstra 
84023f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
84123f78d4aSIngo Molnar 	/* PI waiters blocked on a rt_mutex held by this task */
842fb00aca4SPeter Zijlstra 	struct rb_root pi_waiters;
843fb00aca4SPeter Zijlstra 	struct rb_node *pi_waiters_leftmost;
84423f78d4aSIngo Molnar 	/* Deadlock detection and priority inheritance handling */
84523f78d4aSIngo Molnar 	struct rt_mutex_waiter *pi_blocked_on;
84623f78d4aSIngo Molnar #endif
84723f78d4aSIngo Molnar 
848408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES
849408894eeSIngo Molnar 	/* mutex deadlock detection */
850408894eeSIngo Molnar 	struct mutex_waiter *blocked_on;
851408894eeSIngo Molnar #endif
852de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS
853de30a2b3SIngo Molnar 	unsigned int irq_events;
854de30a2b3SIngo Molnar 	unsigned long hardirq_enable_ip;
855de30a2b3SIngo Molnar 	unsigned long hardirq_disable_ip;
856fa1452e8SHiroshi Shimamoto 	unsigned int hardirq_enable_event;
857de30a2b3SIngo Molnar 	unsigned int hardirq_disable_event;
858fa1452e8SHiroshi Shimamoto 	int hardirqs_enabled;
859de30a2b3SIngo Molnar 	int hardirq_context;
860fa1452e8SHiroshi Shimamoto 	unsigned long softirq_disable_ip;
861fa1452e8SHiroshi Shimamoto 	unsigned long softirq_enable_ip;
862fa1452e8SHiroshi Shimamoto 	unsigned int softirq_disable_event;
863fa1452e8SHiroshi Shimamoto 	unsigned int softirq_enable_event;
864fa1452e8SHiroshi Shimamoto 	int softirqs_enabled;
865de30a2b3SIngo Molnar 	int softirq_context;
866de30a2b3SIngo Molnar #endif
867fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP
868bdb9441eSPeter Zijlstra # define MAX_LOCK_DEPTH 48UL
869fbb9ce95SIngo Molnar 	u64 curr_chain_key;
870fbb9ce95SIngo Molnar 	int lockdep_depth;
871fbb9ce95SIngo Molnar 	unsigned int lockdep_recursion;
872c7aceabaSRichard Kennedy 	struct held_lock held_locks[MAX_LOCK_DEPTH];
873cf40bd16SNick Piggin 	gfp_t lockdep_reclaim_gfp;
874fbb9ce95SIngo Molnar #endif
875c6d30853SAndrey Ryabinin #ifdef CONFIG_UBSAN
876c6d30853SAndrey Ryabinin 	unsigned int in_ubsan;
877c6d30853SAndrey Ryabinin #endif
878408894eeSIngo Molnar 
8791da177e4SLinus Torvalds /* journalling filesystem info */
8801da177e4SLinus Torvalds 	void *journal_info;
8811da177e4SLinus Torvalds 
882d89d8796SNeil Brown /* stacked block device info */
883bddd87c7SAkinobu Mita 	struct bio_list *bio_list;
884d89d8796SNeil Brown 
88573c10101SJens Axboe #ifdef CONFIG_BLOCK
88673c10101SJens Axboe /* stack plugging */
88773c10101SJens Axboe 	struct blk_plug *plug;
88873c10101SJens Axboe #endif
88973c10101SJens Axboe 
8901da177e4SLinus Torvalds /* VM state */
8911da177e4SLinus Torvalds 	struct reclaim_state *reclaim_state;
8921da177e4SLinus Torvalds 
8931da177e4SLinus Torvalds 	struct backing_dev_info *backing_dev_info;
8941da177e4SLinus Torvalds 
8951da177e4SLinus Torvalds 	struct io_context *io_context;
8961da177e4SLinus Torvalds 
8971da177e4SLinus Torvalds 	unsigned long ptrace_message;
8981da177e4SLinus Torvalds 	siginfo_t *last_siginfo; /* For ptrace use.  */
8997c3ab738SAndrew Morton 	struct task_io_accounting ioac;
9008f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT)
9011da177e4SLinus Torvalds 	u64 acct_rss_mem1;	/* accumulated rss usage */
9021da177e4SLinus Torvalds 	u64 acct_vm_mem1;	/* accumulated virtual memory usage */
903605dc2b3SFrederic Weisbecker 	u64 acct_timexpd;	/* stime + utime since last update */
9041da177e4SLinus Torvalds #endif
9051da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS
90658568d2aSMiao Xie 	nodemask_t mems_allowed;	/* Protected by alloc_lock */
907cc9a6c87SMel Gorman 	seqcount_t mems_allowed_seq;	/* Seqence no to catch updates */
908825a46afSPaul Jackson 	int cpuset_mem_spread_rotor;
9096adef3ebSJack Steiner 	int cpuset_slab_spread_rotor;
9101da177e4SLinus Torvalds #endif
911ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS
912817929ecSPaul Menage 	/* Control Group info protected by css_set_lock */
9132c392b8cSArnd Bergmann 	struct css_set __rcu *cgroups;
914817929ecSPaul Menage 	/* cg_list protected by css_set_lock and tsk->alloc_lock */
915817929ecSPaul Menage 	struct list_head cg_list;
916ddbcc7e8SPaul Menage #endif
917e02737d5SFenghua Yu #ifdef CONFIG_INTEL_RDT_A
918e02737d5SFenghua Yu 	int closid;
919e02737d5SFenghua Yu #endif
92042b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX
9210771dfefSIngo Molnar 	struct robust_list_head __user *robust_list;
92234f192c6SIngo Molnar #ifdef CONFIG_COMPAT
92334f192c6SIngo Molnar 	struct compat_robust_list_head __user *compat_robust_list;
92434f192c6SIngo Molnar #endif
925c87e2837SIngo Molnar 	struct list_head pi_state_list;
926c87e2837SIngo Molnar 	struct futex_pi_state *pi_state_cache;
92742b2dd0aSAlexey Dobriyan #endif
928cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS
9298dc85d54SPeter Zijlstra 	struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
930cdd6c482SIngo Molnar 	struct mutex perf_event_mutex;
931cdd6c482SIngo Molnar 	struct list_head perf_event_list;
932a63eaf34SPaul Mackerras #endif
9338f47b187SThomas Gleixner #ifdef CONFIG_DEBUG_PREEMPT
9348f47b187SThomas Gleixner 	unsigned long preempt_disable_ip;
9358f47b187SThomas Gleixner #endif
936c7aceabaSRichard Kennedy #ifdef CONFIG_NUMA
93758568d2aSMiao Xie 	struct mempolicy *mempolicy;	/* Protected by alloc_lock */
938c7aceabaSRichard Kennedy 	short il_next;
939207205a2SEric Dumazet 	short pref_node_fork;
940c7aceabaSRichard Kennedy #endif
941cbee9f88SPeter Zijlstra #ifdef CONFIG_NUMA_BALANCING
942cbee9f88SPeter Zijlstra 	int numa_scan_seq;
943cbee9f88SPeter Zijlstra 	unsigned int numa_scan_period;
944598f0ec0SMel Gorman 	unsigned int numa_scan_period_max;
945de1c9ce6SRik van Riel 	int numa_preferred_nid;
9466b9a7460SMel Gorman 	unsigned long numa_migrate_retry;
947cbee9f88SPeter Zijlstra 	u64 node_stamp;			/* migration stamp  */
9487e2703e6SRik van Riel 	u64 last_task_numa_placement;
9497e2703e6SRik van Riel 	u64 last_sum_exec_runtime;
950cbee9f88SPeter Zijlstra 	struct callback_head numa_work;
951f809ca9aSMel Gorman 
9528c8a743cSPeter Zijlstra 	struct list_head numa_entry;
9538c8a743cSPeter Zijlstra 	struct numa_group *numa_group;
9548c8a743cSPeter Zijlstra 
955745d6147SMel Gorman 	/*
95644dba3d5SIulia Manda 	 * numa_faults is an array split into four regions:
95744dba3d5SIulia Manda 	 * faults_memory, faults_cpu, faults_memory_buffer, faults_cpu_buffer
95844dba3d5SIulia Manda 	 * in this precise order.
95944dba3d5SIulia Manda 	 *
96044dba3d5SIulia Manda 	 * faults_memory: Exponential decaying average of faults on a per-node
96144dba3d5SIulia Manda 	 * basis. Scheduling placement decisions are made based on these
96244dba3d5SIulia Manda 	 * counts. The values remain static for the duration of a PTE scan.
96344dba3d5SIulia Manda 	 * faults_cpu: Track the nodes the process was running on when a NUMA
96444dba3d5SIulia Manda 	 * hinting fault was incurred.
96544dba3d5SIulia Manda 	 * faults_memory_buffer and faults_cpu_buffer: Record faults per node
96644dba3d5SIulia Manda 	 * during the current scan window. When the scan completes, the counts
96744dba3d5SIulia Manda 	 * in faults_memory and faults_cpu decay and these values are copied.
968745d6147SMel Gorman 	 */
96944dba3d5SIulia Manda 	unsigned long *numa_faults;
97083e1d2cdSMel Gorman 	unsigned long total_numa_faults;
971745d6147SMel Gorman 
972745d6147SMel Gorman 	/*
97304bb2f94SRik van Riel 	 * numa_faults_locality tracks if faults recorded during the last
974074c2381SMel Gorman 	 * scan window were remote/local or failed to migrate. The task scan
975074c2381SMel Gorman 	 * period is adapted based on the locality of the faults with different
976074c2381SMel Gorman 	 * weights depending on whether they were shared or private faults
97704bb2f94SRik van Riel 	 */
978074c2381SMel Gorman 	unsigned long numa_faults_locality[3];
97904bb2f94SRik van Riel 
980b32e86b4SIngo Molnar 	unsigned long numa_pages_migrated;
981cbee9f88SPeter Zijlstra #endif /* CONFIG_NUMA_BALANCING */
982cbee9f88SPeter Zijlstra 
98372b252aeSMel Gorman #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
98472b252aeSMel Gorman 	struct tlbflush_unmap_batch tlb_ubc;
98572b252aeSMel Gorman #endif
98672b252aeSMel Gorman 
987e56d0903SIngo Molnar 	struct rcu_head rcu;
988b92ce558SJens Axboe 
989b92ce558SJens Axboe 	/*
990b92ce558SJens Axboe 	 * cache last used pipe for splice
991b92ce558SJens Axboe 	 */
992b92ce558SJens Axboe 	struct pipe_inode_info *splice_pipe;
9935640f768SEric Dumazet 
9945640f768SEric Dumazet 	struct page_frag task_frag;
9955640f768SEric Dumazet 
996ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT
997ca74e92bSShailabh Nagar 	struct task_delay_info		*delays;
998ca74e92bSShailabh Nagar #endif
99947913d4eSIngo Molnar 
1000f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION
1001f4f154fdSAkinobu Mita 	int make_it_fail;
1002f4f154fdSAkinobu Mita #endif
10039d823e8fSWu Fengguang 	/*
10049d823e8fSWu Fengguang 	 * when (nr_dirtied >= nr_dirtied_pause), it's time to call
10059d823e8fSWu Fengguang 	 * balance_dirty_pages() for some dirty throttling pause
10069d823e8fSWu Fengguang 	 */
10079d823e8fSWu Fengguang 	int nr_dirtied;
10089d823e8fSWu Fengguang 	int nr_dirtied_pause;
100983712358SWu Fengguang 	unsigned long dirty_paused_when; /* start of a write-and-pause period */
10109d823e8fSWu Fengguang 
10119745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
10129745512cSArjan van de Ven 	int latency_record_count;
10139745512cSArjan van de Ven 	struct latency_record latency_record[LT_SAVECOUNT];
10149745512cSArjan van de Ven #endif
10156976675dSArjan van de Ven 	/*
10166976675dSArjan van de Ven 	 * time slack values; these are used to round up poll() and
10176976675dSArjan van de Ven 	 * select() etc timeout values. These are in nanoseconds.
10186976675dSArjan van de Ven 	 */
1019da8b44d5SJohn Stultz 	u64 timer_slack_ns;
1020da8b44d5SJohn Stultz 	u64 default_timer_slack_ns;
1021f8d570a4SDavid Miller 
10220b24beccSAndrey Ryabinin #ifdef CONFIG_KASAN
10230b24beccSAndrey Ryabinin 	unsigned int kasan_depth;
10240b24beccSAndrey Ryabinin #endif
1025fb52607aSFrederic Weisbecker #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10263ad2f3fbSDaniel Mack 	/* Index of current stored address in ret_stack */
1027f201ae23SFrederic Weisbecker 	int curr_ret_stack;
1028f201ae23SFrederic Weisbecker 	/* Stack of return addresses for return function tracing */
1029f201ae23SFrederic Weisbecker 	struct ftrace_ret_stack	*ret_stack;
10308aef2d28SSteven Rostedt 	/* time stamp for last schedule */
10318aef2d28SSteven Rostedt 	unsigned long long ftrace_timestamp;
1032f201ae23SFrederic Weisbecker 	/*
1033f201ae23SFrederic Weisbecker 	 * Number of functions that haven't been traced
1034f201ae23SFrederic Weisbecker 	 * because of depth overrun.
1035f201ae23SFrederic Weisbecker 	 */
1036f201ae23SFrederic Weisbecker 	atomic_t trace_overrun;
1037380c4b14SFrederic Weisbecker 	/* Pause for the tracing */
1038380c4b14SFrederic Weisbecker 	atomic_t tracing_graph_pause;
1039f201ae23SFrederic Weisbecker #endif
1040ea4e2bc4SSteven Rostedt #ifdef CONFIG_TRACING
1041ea4e2bc4SSteven Rostedt 	/* state flags for use by tracers */
1042ea4e2bc4SSteven Rostedt 	unsigned long trace;
1043b1cff0adSSteven Rostedt 	/* bitmask and counter of trace recursion */
1044261842b7SSteven Rostedt 	unsigned long trace_recursion;
1045261842b7SSteven Rostedt #endif /* CONFIG_TRACING */
10465c9a8750SDmitry Vyukov #ifdef CONFIG_KCOV
10475c9a8750SDmitry Vyukov 	/* Coverage collection mode enabled for this task (0 if disabled). */
10485c9a8750SDmitry Vyukov 	enum kcov_mode kcov_mode;
10495c9a8750SDmitry Vyukov 	/* Size of the kcov_area. */
10505c9a8750SDmitry Vyukov 	unsigned	kcov_size;
10515c9a8750SDmitry Vyukov 	/* Buffer for coverage collection. */
10525c9a8750SDmitry Vyukov 	void		*kcov_area;
10535c9a8750SDmitry Vyukov 	/* kcov desciptor wired with this task or NULL. */
10545c9a8750SDmitry Vyukov 	struct kcov	*kcov;
10555c9a8750SDmitry Vyukov #endif
10566f185c29SVladimir Davydov #ifdef CONFIG_MEMCG
1057626ebc41STejun Heo 	struct mem_cgroup *memcg_in_oom;
1058626ebc41STejun Heo 	gfp_t memcg_oom_gfp_mask;
1059626ebc41STejun Heo 	int memcg_oom_order;
1060b23afb93STejun Heo 
1061b23afb93STejun Heo 	/* number of pages to reclaim on returning to userland */
1062b23afb93STejun Heo 	unsigned int memcg_nr_pages_over_high;
1063569b846dSKAMEZAWA Hiroyuki #endif
10640326f5a9SSrikar Dronamraju #ifdef CONFIG_UPROBES
10650326f5a9SSrikar Dronamraju 	struct uprobe_task *utask;
10660326f5a9SSrikar Dronamraju #endif
1067cafe5635SKent Overstreet #if defined(CONFIG_BCACHE) || defined(CONFIG_BCACHE_MODULE)
1068cafe5635SKent Overstreet 	unsigned int	sequential_io;
1069cafe5635SKent Overstreet 	unsigned int	sequential_io_avg;
1070cafe5635SKent Overstreet #endif
10718eb23b9fSPeter Zijlstra #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
10728eb23b9fSPeter Zijlstra 	unsigned long	task_state_change;
10738eb23b9fSPeter Zijlstra #endif
10748bcbde54SDavid Hildenbrand 	int pagefault_disabled;
107503049269SMichal Hocko #ifdef CONFIG_MMU
107629c696e1SVladimir Davydov 	struct task_struct *oom_reaper_list;
107703049269SMichal Hocko #endif
1078ba14a194SAndy Lutomirski #ifdef CONFIG_VMAP_STACK
1079ba14a194SAndy Lutomirski 	struct vm_struct *stack_vm_area;
1080ba14a194SAndy Lutomirski #endif
108168f24b08SAndy Lutomirski #ifdef CONFIG_THREAD_INFO_IN_TASK
108268f24b08SAndy Lutomirski 	/* A live task holds one reference. */
108368f24b08SAndy Lutomirski 	atomic_t stack_refcount;
108468f24b08SAndy Lutomirski #endif
10850c8c0f03SDave Hansen /* CPU-specific state of this task */
10860c8c0f03SDave Hansen 	struct thread_struct thread;
10870c8c0f03SDave Hansen /*
10880c8c0f03SDave Hansen  * WARNING: on x86, 'thread_struct' contains a variable-sized
10890c8c0f03SDave Hansen  * structure.  It *MUST* be at the end of 'task_struct'.
10900c8c0f03SDave Hansen  *
10910c8c0f03SDave Hansen  * Do not put anything below here!
10920c8c0f03SDave Hansen  */
10931da177e4SLinus Torvalds };
10941da177e4SLinus Torvalds 
1095e868171aSAlexey Dobriyan static inline struct pid *task_pid(struct task_struct *task)
109622c935f4SEric W. Biederman {
109722c935f4SEric W. Biederman 	return task->pids[PIDTYPE_PID].pid;
109822c935f4SEric W. Biederman }
109922c935f4SEric W. Biederman 
1100e868171aSAlexey Dobriyan static inline struct pid *task_tgid(struct task_struct *task)
110122c935f4SEric W. Biederman {
110222c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PID].pid;
110322c935f4SEric W. Biederman }
110422c935f4SEric W. Biederman 
11056dda81f4SOleg Nesterov /*
11066dda81f4SOleg Nesterov  * Without tasklist or rcu lock it is not safe to dereference
11076dda81f4SOleg Nesterov  * the result of task_pgrp/task_session even if task == current,
11086dda81f4SOleg Nesterov  * we can race with another thread doing sys_setsid/sys_setpgid.
11096dda81f4SOleg Nesterov  */
1110e868171aSAlexey Dobriyan static inline struct pid *task_pgrp(struct task_struct *task)
111122c935f4SEric W. Biederman {
111222c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PGID].pid;
111322c935f4SEric W. Biederman }
111422c935f4SEric W. Biederman 
1115e868171aSAlexey Dobriyan static inline struct pid *task_session(struct task_struct *task)
111622c935f4SEric W. Biederman {
111722c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_SID].pid;
111822c935f4SEric W. Biederman }
111922c935f4SEric W. Biederman 
11207af57294SPavel Emelyanov /*
11217af57294SPavel Emelyanov  * the helpers to get the task's different pids as they are seen
11227af57294SPavel Emelyanov  * from various namespaces
11237af57294SPavel Emelyanov  *
11247af57294SPavel Emelyanov  * task_xid_nr()     : global id, i.e. the id seen from the init namespace;
112544c4e1b2SEric W. Biederman  * task_xid_vnr()    : virtual id, i.e. the id seen from the pid namespace of
112644c4e1b2SEric W. Biederman  *                     current.
11277af57294SPavel Emelyanov  * task_xid_nr_ns()  : id seen from the ns specified;
11287af57294SPavel Emelyanov  *
11297af57294SPavel Emelyanov  * set_task_vxid()   : assigns a virtual id to a task;
11307af57294SPavel Emelyanov  *
11317af57294SPavel Emelyanov  * see also pid_nr() etc in include/linux/pid.h
11327af57294SPavel Emelyanov  */
113352ee2dfdSOleg Nesterov pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
113452ee2dfdSOleg Nesterov 			struct pid_namespace *ns);
11357af57294SPavel Emelyanov 
1136e868171aSAlexey Dobriyan static inline pid_t task_pid_nr(struct task_struct *tsk)
11377af57294SPavel Emelyanov {
11387af57294SPavel Emelyanov 	return tsk->pid;
11397af57294SPavel Emelyanov }
11407af57294SPavel Emelyanov 
114152ee2dfdSOleg Nesterov static inline pid_t task_pid_nr_ns(struct task_struct *tsk,
114252ee2dfdSOleg Nesterov 					struct pid_namespace *ns)
114352ee2dfdSOleg Nesterov {
114452ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
114552ee2dfdSOleg Nesterov }
11467af57294SPavel Emelyanov 
11477af57294SPavel Emelyanov static inline pid_t task_pid_vnr(struct task_struct *tsk)
11487af57294SPavel Emelyanov {
114952ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
11507af57294SPavel Emelyanov }
11517af57294SPavel Emelyanov 
11527af57294SPavel Emelyanov 
1153e868171aSAlexey Dobriyan static inline pid_t task_tgid_nr(struct task_struct *tsk)
11547af57294SPavel Emelyanov {
11557af57294SPavel Emelyanov 	return tsk->tgid;
11567af57294SPavel Emelyanov }
11577af57294SPavel Emelyanov 
11582f2a3a46SPavel Emelyanov pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
11597af57294SPavel Emelyanov 
11607af57294SPavel Emelyanov static inline pid_t task_tgid_vnr(struct task_struct *tsk)
11617af57294SPavel Emelyanov {
11627af57294SPavel Emelyanov 	return pid_vnr(task_tgid(tsk));
11637af57294SPavel Emelyanov }
11647af57294SPavel Emelyanov 
11657af57294SPavel Emelyanov 
116680e0b6e8SRichard Guy Briggs static inline int pid_alive(const struct task_struct *p);
1167ad36d282SRichard Guy Briggs static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)
1168ad36d282SRichard Guy Briggs {
1169ad36d282SRichard Guy Briggs 	pid_t pid = 0;
1170ad36d282SRichard Guy Briggs 
1171ad36d282SRichard Guy Briggs 	rcu_read_lock();
1172ad36d282SRichard Guy Briggs 	if (pid_alive(tsk))
1173ad36d282SRichard Guy Briggs 		pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);
1174ad36d282SRichard Guy Briggs 	rcu_read_unlock();
1175ad36d282SRichard Guy Briggs 
1176ad36d282SRichard Guy Briggs 	return pid;
1177ad36d282SRichard Guy Briggs }
1178ad36d282SRichard Guy Briggs 
1179ad36d282SRichard Guy Briggs static inline pid_t task_ppid_nr(const struct task_struct *tsk)
1180ad36d282SRichard Guy Briggs {
1181ad36d282SRichard Guy Briggs 	return task_ppid_nr_ns(tsk, &init_pid_ns);
1182ad36d282SRichard Guy Briggs }
1183ad36d282SRichard Guy Briggs 
118452ee2dfdSOleg Nesterov static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk,
118552ee2dfdSOleg Nesterov 					struct pid_namespace *ns)
11867af57294SPavel Emelyanov {
118752ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
11887af57294SPavel Emelyanov }
11897af57294SPavel Emelyanov 
11907af57294SPavel Emelyanov static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
11917af57294SPavel Emelyanov {
119252ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
11937af57294SPavel Emelyanov }
11947af57294SPavel Emelyanov 
11957af57294SPavel Emelyanov 
119652ee2dfdSOleg Nesterov static inline pid_t task_session_nr_ns(struct task_struct *tsk,
119752ee2dfdSOleg Nesterov 					struct pid_namespace *ns)
11987af57294SPavel Emelyanov {
119952ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
12007af57294SPavel Emelyanov }
12017af57294SPavel Emelyanov 
12027af57294SPavel Emelyanov static inline pid_t task_session_vnr(struct task_struct *tsk)
12037af57294SPavel Emelyanov {
120452ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
12057af57294SPavel Emelyanov }
12067af57294SPavel Emelyanov 
12071b0f7ffdSOleg Nesterov /* obsolete, do not use */
12081b0f7ffdSOleg Nesterov static inline pid_t task_pgrp_nr(struct task_struct *tsk)
12091b0f7ffdSOleg Nesterov {
12101b0f7ffdSOleg Nesterov 	return task_pgrp_nr_ns(tsk, &init_pid_ns);
12111b0f7ffdSOleg Nesterov }
12127af57294SPavel Emelyanov 
12131da177e4SLinus Torvalds /**
12141da177e4SLinus Torvalds  * pid_alive - check that a task structure is not stale
12151da177e4SLinus Torvalds  * @p: Task structure to be checked.
12161da177e4SLinus Torvalds  *
12171da177e4SLinus Torvalds  * Test if a process is not yet dead (at most zombie state)
12181da177e4SLinus Torvalds  * If pid_alive fails, then pointers within the task structure
12191da177e4SLinus Torvalds  * can be stale and must not be dereferenced.
1220e69f6186SYacine Belkadi  *
1221e69f6186SYacine Belkadi  * Return: 1 if the process is alive. 0 otherwise.
12221da177e4SLinus Torvalds  */
1223ad36d282SRichard Guy Briggs static inline int pid_alive(const struct task_struct *p)
12241da177e4SLinus Torvalds {
122592476d7fSEric W. Biederman 	return p->pids[PIDTYPE_PID].pid != NULL;
12261da177e4SLinus Torvalds }
12271da177e4SLinus Torvalds 
1228f400e198SSukadev Bhattiprolu /**
1229570f5241SSergey Senozhatsky  * is_global_init - check if a task structure is init. Since init
1230570f5241SSergey Senozhatsky  * is free to have sub-threads we need to check tgid.
12313260259fSHenne  * @tsk: Task structure to be checked.
12323260259fSHenne  *
12333260259fSHenne  * Check if a task structure is the first user space task the kernel created.
1234e69f6186SYacine Belkadi  *
1235e69f6186SYacine Belkadi  * Return: 1 if the task structure is init. 0 otherwise.
1236f400e198SSukadev Bhattiprolu  */
1237e868171aSAlexey Dobriyan static inline int is_global_init(struct task_struct *tsk)
1238b461cc03SPavel Emelyanov {
1239570f5241SSergey Senozhatsky 	return task_tgid_nr(tsk) == 1;
1240b461cc03SPavel Emelyanov }
1241b460cbc5SSerge E. Hallyn 
12429ec52099SCedric Le Goater extern struct pid *cad_pid;
12439ec52099SCedric Le Goater 
12441da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk);
12451da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
1246e56d0903SIngo Molnar 
1247158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t);
1248e56d0903SIngo Molnar 
1249e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t)
1250e56d0903SIngo Molnar {
1251e56d0903SIngo Molnar 	if (atomic_dec_and_test(&t->usage))
12528c7904a0SEric W. Biederman 		__put_task_struct(t);
1253e56d0903SIngo Molnar }
12541da177e4SLinus Torvalds 
1255150593bfSOleg Nesterov struct task_struct *task_rcu_dereference(struct task_struct **ptask);
1256150593bfSOleg Nesterov struct task_struct *try_get_task_struct(struct task_struct **ptask);
1257150593bfSOleg Nesterov 
12586a61671bSFrederic Weisbecker #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
12596a61671bSFrederic Weisbecker extern void task_cputime(struct task_struct *t,
12605613fda9SFrederic Weisbecker 			 u64 *utime, u64 *stime);
126116a6d9beSFrederic Weisbecker extern u64 task_gtime(struct task_struct *t);
12626a61671bSFrederic Weisbecker #else
12636fac4829SFrederic Weisbecker static inline void task_cputime(struct task_struct *t,
12645613fda9SFrederic Weisbecker 				u64 *utime, u64 *stime)
12656fac4829SFrederic Weisbecker {
12666fac4829SFrederic Weisbecker 	*utime = t->utime;
12676fac4829SFrederic Weisbecker 	*stime = t->stime;
12686fac4829SFrederic Weisbecker }
12696fac4829SFrederic Weisbecker 
127016a6d9beSFrederic Weisbecker static inline u64 task_gtime(struct task_struct *t)
12716a61671bSFrederic Weisbecker {
12726a61671bSFrederic Weisbecker 	return t->gtime;
12736a61671bSFrederic Weisbecker }
12746a61671bSFrederic Weisbecker #endif
127540565b5aSStanislaw Gruszka 
127640565b5aSStanislaw Gruszka #ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
1277b31dc66aSJens Axboe static inline void task_cputime_scaled(struct task_struct *t,
12785613fda9SFrederic Weisbecker 				       u64 *utimescaled,
12795613fda9SFrederic Weisbecker 				       u64 *stimescaled)
1280b31dc66aSJens Axboe {
12814db96cf0SAndi Kleen 	*utimescaled = t->utimescaled;
128261a87122SThomas Gleixner 	*stimescaled = t->stimescaled;
128358a69cb4STejun Heo }
128440565b5aSStanislaw Gruszka #else
128540565b5aSStanislaw Gruszka static inline void task_cputime_scaled(struct task_struct *t,
12865613fda9SFrederic Weisbecker 				       u64 *utimescaled,
12875613fda9SFrederic Weisbecker 				       u64 *stimescaled)
12881da177e4SLinus Torvalds {
128940565b5aSStanislaw Gruszka 	task_cputime(t, utimescaled, stimescaled);
12901da177e4SLinus Torvalds }
12911da177e4SLinus Torvalds #endif
129240565b5aSStanislaw Gruszka 
12935613fda9SFrederic Weisbecker extern void task_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st);
12945613fda9SFrederic Weisbecker extern void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st);
12951da177e4SLinus Torvalds 
12961da177e4SLinus Torvalds /*
12971da177e4SLinus Torvalds  * Per process flags
12981da177e4SLinus Torvalds  */
1299c1de45caSPeter Zijlstra #define PF_IDLE		0x00000002	/* I am an IDLE thread */
13001da177e4SLinus Torvalds #define PF_EXITING	0x00000004	/* getting shut down */
13011da177e4SLinus Torvalds #define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
13021da177e4SLinus Torvalds #define PF_VCPU		0x00000010	/* I'm a virtual CPU */
13031da177e4SLinus Torvalds #define PF_WQ_WORKER	0x00000020	/* I'm a workqueue worker */
13041da177e4SLinus Torvalds #define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
13051da177e4SLinus Torvalds #define PF_MCE_PROCESS  0x00000080      /* process policy on mce errors */
13061da177e4SLinus Torvalds #define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
13071da177e4SLinus Torvalds #define PF_DUMPCORE	0x00000200	/* dumped core */
13081da177e4SLinus Torvalds #define PF_SIGNALED	0x00000400	/* killed by a signal */
13091da177e4SLinus Torvalds #define PF_MEMALLOC	0x00000800	/* Allocating memory */
13101da177e4SLinus Torvalds #define PF_NPROC_EXCEEDED 0x00001000	/* set_user noticed that RLIMIT_NPROC was exceeded */
13111da177e4SLinus Torvalds #define PF_USED_MATH	0x00002000	/* if unset the fpu must be initialized before use */
13121da177e4SLinus Torvalds #define PF_USED_ASYNC	0x00004000	/* used async_schedule*(), used by module init */
13131da177e4SLinus Torvalds #define PF_NOFREEZE	0x00008000	/* this thread should not be frozen */
13141da177e4SLinus Torvalds #define PF_FROZEN	0x00010000	/* frozen for system suspend */
13151da177e4SLinus Torvalds #define PF_FSTRANS	0x00020000	/* inside a filesystem transaction */
13161da177e4SLinus Torvalds #define PF_KSWAPD	0x00040000	/* I am kswapd */
131721caf2fcSMing Lei #define PF_MEMALLOC_NOIO 0x00080000	/* Allocating memory without IO involved */
13181da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000	/* Throttle me less: I clean memory */
13191da177e4SLinus Torvalds #define PF_KTHREAD	0x00200000	/* I am a kernel thread */
13201da177e4SLinus Torvalds #define PF_RANDOMIZE	0x00400000	/* randomize virtual address space */
13211da177e4SLinus Torvalds #define PF_SWAPWRITE	0x00800000	/* Allowed to write to swap */
132214a40ffcSTejun Heo #define PF_NO_SETAFFINITY 0x04000000	/* Userland is not allowed to meddle with cpus_allowed */
13231da177e4SLinus Torvalds #define PF_MCE_EARLY    0x08000000      /* Early kill for mce process policy */
13241da177e4SLinus Torvalds #define PF_MUTEX_TESTER	0x20000000	/* Thread belongs to the rt mutex tester */
13251da177e4SLinus Torvalds #define PF_FREEZER_SKIP	0x40000000	/* Freezer should not count it as freezable */
13262b44c4dbSColin Cross #define PF_SUSPEND_TASK 0x80000000      /* this thread called freeze_processes and should not be frozen */
13271da177e4SLinus Torvalds 
13281da177e4SLinus Torvalds /*
13291da177e4SLinus Torvalds  * Only the _current_ task can read/write to tsk->flags, but other
13301da177e4SLinus Torvalds  * tasks can access tsk->flags in readonly mode for example
13311da177e4SLinus Torvalds  * with tsk_used_math (like during threaded core dumping).
13321da177e4SLinus Torvalds  * There is however an exception to this rule during ptrace
13331da177e4SLinus Torvalds  * or during fork: the ptracer task is allowed to write to the
13341da177e4SLinus Torvalds  * child->flags of its traced child (same goes for fork, the parent
13351da177e4SLinus Torvalds  * can write to the child->flags), because we're guaranteed the
13361da177e4SLinus Torvalds  * child is not running and in turn not changing child->flags
13371da177e4SLinus Torvalds  * at the same time the parent does it.
13381da177e4SLinus Torvalds  */
13391da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
13401da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
13411da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current)
13421da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current)
13431da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \
13441da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
13451da177e4SLinus Torvalds #define conditional_used_math(condition) \
13461da177e4SLinus Torvalds 	conditional_stopped_child_used_math(condition, current)
13471da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \
13481da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
13491da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
13501da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
13511da177e4SLinus Torvalds #define used_math() tsk_used_math(current)
13521da177e4SLinus Torvalds 
13531d4457f9SKees Cook /* Per-process atomic flags. */
1354a2b86f77SZefan Li #define PFA_NO_NEW_PRIVS 0	/* May not gain new privileges. */
13552ad654bcSZefan Li #define PFA_SPREAD_PAGE  1      /* Spread page cache over cpuset */
13562ad654bcSZefan Li #define PFA_SPREAD_SLAB  2      /* Spread some slab caches over cpuset */
135777ed2c57STetsuo Handa #define PFA_LMK_WAITING  3      /* Lowmemorykiller is waiting */
13581d4457f9SKees Cook 
13591d4457f9SKees Cook 
1360e0e5070bSZefan Li #define TASK_PFA_TEST(name, func)					\
1361e0e5070bSZefan Li 	static inline bool task_##func(struct task_struct *p)		\
1362e0e5070bSZefan Li 	{ return test_bit(PFA_##name, &p->atomic_flags); }
1363e0e5070bSZefan Li #define TASK_PFA_SET(name, func)					\
1364e0e5070bSZefan Li 	static inline void task_set_##func(struct task_struct *p)	\
1365e0e5070bSZefan Li 	{ set_bit(PFA_##name, &p->atomic_flags); }
1366e0e5070bSZefan Li #define TASK_PFA_CLEAR(name, func)					\
1367e0e5070bSZefan Li 	static inline void task_clear_##func(struct task_struct *p)	\
1368e0e5070bSZefan Li 	{ clear_bit(PFA_##name, &p->atomic_flags); }
13691d4457f9SKees Cook 
1370e0e5070bSZefan Li TASK_PFA_TEST(NO_NEW_PRIVS, no_new_privs)
1371e0e5070bSZefan Li TASK_PFA_SET(NO_NEW_PRIVS, no_new_privs)
13721d4457f9SKees Cook 
13732ad654bcSZefan Li TASK_PFA_TEST(SPREAD_PAGE, spread_page)
13742ad654bcSZefan Li TASK_PFA_SET(SPREAD_PAGE, spread_page)
13752ad654bcSZefan Li TASK_PFA_CLEAR(SPREAD_PAGE, spread_page)
13762ad654bcSZefan Li 
13772ad654bcSZefan Li TASK_PFA_TEST(SPREAD_SLAB, spread_slab)
13782ad654bcSZefan Li TASK_PFA_SET(SPREAD_SLAB, spread_slab)
13792ad654bcSZefan Li TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab)
1380544b2c91STejun Heo 
138177ed2c57STetsuo Handa TASK_PFA_TEST(LMK_WAITING, lmk_waiting)
138277ed2c57STetsuo Handa TASK_PFA_SET(LMK_WAITING, lmk_waiting)
138377ed2c57STetsuo Handa 
1384907aed48SMel Gorman static inline void tsk_restore_flags(struct task_struct *task,
1385907aed48SMel Gorman 				unsigned long orig_flags, unsigned long flags)
1386907aed48SMel Gorman {
1387907aed48SMel Gorman 	task->flags &= ~flags;
1388907aed48SMel Gorman 	task->flags |= orig_flags & flags;
1389907aed48SMel Gorman }
1390907aed48SMel Gorman 
1391f82f8042SJuri Lelli extern int cpuset_cpumask_can_shrink(const struct cpumask *cur,
1392f82f8042SJuri Lelli 				     const struct cpumask *trial);
13937f51412aSJuri Lelli extern int task_can_attach(struct task_struct *p,
13947f51412aSJuri Lelli 			   const struct cpumask *cs_cpus_allowed);
13951da177e4SLinus Torvalds #ifdef CONFIG_SMP
13961e1b6c51SKOSAKI Motohiro extern void do_set_cpus_allowed(struct task_struct *p,
13971e1b6c51SKOSAKI Motohiro 			       const struct cpumask *new_mask);
13981e1b6c51SKOSAKI Motohiro 
1399cd8ba7cdSMike Travis extern int set_cpus_allowed_ptr(struct task_struct *p,
140096f874e2SRusty Russell 				const struct cpumask *new_mask);
14011da177e4SLinus Torvalds #else
14021e1b6c51SKOSAKI Motohiro static inline void do_set_cpus_allowed(struct task_struct *p,
14031e1b6c51SKOSAKI Motohiro 				      const struct cpumask *new_mask)
14041e1b6c51SKOSAKI Motohiro {
14051e1b6c51SKOSAKI Motohiro }
1406cd8ba7cdSMike Travis static inline int set_cpus_allowed_ptr(struct task_struct *p,
140796f874e2SRusty Russell 				       const struct cpumask *new_mask)
14081da177e4SLinus Torvalds {
140996f874e2SRusty Russell 	if (!cpumask_test_cpu(0, new_mask))
14101da177e4SLinus Torvalds 		return -EINVAL;
14111da177e4SLinus Torvalds 	return 0;
14121da177e4SLinus Torvalds }
14131da177e4SLinus Torvalds #endif
1414e0ad9556SRusty Russell 
14156d0d2878SChristian Borntraeger #ifndef cpu_relax_yield
14166d0d2878SChristian Borntraeger #define cpu_relax_yield() cpu_relax()
14176d0d2878SChristian Borntraeger #endif
14186d0d2878SChristian Borntraeger 
141936c8b586SIngo Molnar extern unsigned long long
142041b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task);
14211da177e4SLinus Torvalds 
14221da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */
14231da177e4SLinus Torvalds #ifdef CONFIG_SMP
14241da177e4SLinus Torvalds extern void sched_exec(void);
14251da177e4SLinus Torvalds #else
14261da177e4SLinus Torvalds #define sched_exec()   {}
14271da177e4SLinus Torvalds #endif
14281da177e4SLinus Torvalds 
1429fa93384fSDan Carpenter extern int yield_to(struct task_struct *p, bool preempt);
143036c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice);
143136c8b586SIngo Molnar extern int task_prio(const struct task_struct *p);
1432d0ea0268SDongsheng Yang /**
1433d0ea0268SDongsheng Yang  * task_nice - return the nice value of a given task.
1434d0ea0268SDongsheng Yang  * @p: the task in question.
1435d0ea0268SDongsheng Yang  *
1436d0ea0268SDongsheng Yang  * Return: The nice value [ -20 ... 0 ... 19 ].
1437d0ea0268SDongsheng Yang  */
1438d0ea0268SDongsheng Yang static inline int task_nice(const struct task_struct *p)
1439d0ea0268SDongsheng Yang {
1440d0ea0268SDongsheng Yang 	return PRIO_TO_NICE((p)->static_prio);
1441d0ea0268SDongsheng Yang }
144236c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice);
144336c8b586SIngo Molnar extern int task_curr(const struct task_struct *p);
14441da177e4SLinus Torvalds extern int idle_cpu(int cpu);
1445fe7de49fSKOSAKI Motohiro extern int sched_setscheduler(struct task_struct *, int,
1446fe7de49fSKOSAKI Motohiro 			      const struct sched_param *);
1447961ccdddSRusty Russell extern int sched_setscheduler_nocheck(struct task_struct *, int,
1448fe7de49fSKOSAKI Motohiro 				      const struct sched_param *);
1449d50dde5aSDario Faggioli extern int sched_setattr(struct task_struct *,
1450d50dde5aSDario Faggioli 			 const struct sched_attr *);
145136c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu);
1452c4f30608SPaul E. McKenney /**
1453c4f30608SPaul E. McKenney  * is_idle_task - is the specified task an idle task?
1454fa757281SRandy Dunlap  * @p: the task in question.
1455e69f6186SYacine Belkadi  *
1456e69f6186SYacine Belkadi  * Return: 1 if @p is an idle task. 0 otherwise.
1457c4f30608SPaul E. McKenney  */
14587061ca3bSPaul E. McKenney static inline bool is_idle_task(const struct task_struct *p)
1459c4f30608SPaul E. McKenney {
1460c1de45caSPeter Zijlstra 	return !!(p->flags & PF_IDLE);
1461c4f30608SPaul E. McKenney }
146236c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu);
1463a458ae2eSPeter Zijlstra extern void ia64_set_curr_task(int cpu, struct task_struct *p);
14641da177e4SLinus Torvalds 
14651da177e4SLinus Torvalds void yield(void);
14661da177e4SLinus Torvalds 
14671da177e4SLinus Torvalds union thread_union {
1468c65eacbeSAndy Lutomirski #ifndef CONFIG_THREAD_INFO_IN_TASK
14691da177e4SLinus Torvalds 	struct thread_info thread_info;
1470c65eacbeSAndy Lutomirski #endif
14711da177e4SLinus Torvalds 	unsigned long stack[THREAD_SIZE/sizeof(long)];
14721da177e4SLinus Torvalds };
14731da177e4SLinus Torvalds 
14741da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END
14751da177e4SLinus Torvalds static inline int kstack_end(void *addr)
14761da177e4SLinus Torvalds {
14771da177e4SLinus Torvalds 	/* Reliable end of stack detection:
14781da177e4SLinus Torvalds 	 * Some APM bios versions misalign the stack
14791da177e4SLinus Torvalds 	 */
14801da177e4SLinus Torvalds 	return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
14811da177e4SLinus Torvalds }
14821da177e4SLinus Torvalds #endif
14831da177e4SLinus Torvalds 
14841da177e4SLinus Torvalds extern union thread_union init_thread_union;
14851da177e4SLinus Torvalds extern struct task_struct init_task;
14861da177e4SLinus Torvalds 
1487198fe21bSPavel Emelyanov extern struct pid_namespace init_pid_ns;
1488198fe21bSPavel Emelyanov 
1489198fe21bSPavel Emelyanov /*
1490198fe21bSPavel Emelyanov  * find a task by one of its numerical ids
1491198fe21bSPavel Emelyanov  *
1492198fe21bSPavel Emelyanov  * find_task_by_pid_ns():
1493198fe21bSPavel Emelyanov  *      finds a task by its pid in the specified namespace
1494228ebcbeSPavel Emelyanov  * find_task_by_vpid():
1495228ebcbeSPavel Emelyanov  *      finds a task by its virtual pid
1496198fe21bSPavel Emelyanov  *
1497e49859e7SPavel Emelyanov  * see also find_vpid() etc in include/linux/pid.h
1498198fe21bSPavel Emelyanov  */
1499198fe21bSPavel Emelyanov 
1500228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_vpid(pid_t nr);
1501228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid_ns(pid_t nr,
1502228ebcbeSPavel Emelyanov 		struct pid_namespace *ns);
1503198fe21bSPavel Emelyanov 
1504b3c97528SHarvey Harrison extern int wake_up_state(struct task_struct *tsk, unsigned int state);
1505b3c97528SHarvey Harrison extern int wake_up_process(struct task_struct *tsk);
15063e51e3edSSamir Bellabes extern void wake_up_new_task(struct task_struct *tsk);
15071da177e4SLinus Torvalds #ifdef CONFIG_SMP
15081da177e4SLinus Torvalds  extern void kick_process(struct task_struct *tsk);
15091da177e4SLinus Torvalds #else
15101da177e4SLinus Torvalds  static inline void kick_process(struct task_struct *tsk) { }
15111da177e4SLinus Torvalds #endif
15121da177e4SLinus Torvalds 
15131da177e4SLinus Torvalds extern void exit_files(struct task_struct *);
1514cbaffba1SOleg Nesterov 
15151da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *);
15161da177e4SLinus Torvalds 
1517c4ad8f98SLinus Torvalds extern int do_execve(struct filename *,
1518d7627467SDavid Howells 		     const char __user * const __user *,
1519da3d4c5fSAl Viro 		     const char __user * const __user *);
152051f39a1fSDavid Drysdale extern int do_execveat(int, struct filename *,
152151f39a1fSDavid Drysdale 		       const char __user * const __user *,
152251f39a1fSDavid Drysdale 		       const char __user * const __user *,
152351f39a1fSDavid Drysdale 		       int);
15241da177e4SLinus Torvalds 
152582b89778SAdrian Hunter extern void __set_task_comm(struct task_struct *tsk, const char *from, bool exec);
152682b89778SAdrian Hunter static inline void set_task_comm(struct task_struct *tsk, const char *from)
152782b89778SAdrian Hunter {
152882b89778SAdrian Hunter 	__set_task_comm(tsk, from, false);
152982b89778SAdrian Hunter }
153059714d65SAndrew Morton extern char *get_task_comm(char *to, struct task_struct *tsk);
15311da177e4SLinus Torvalds 
15321da177e4SLinus Torvalds #ifdef CONFIG_SMP
1533317f3941SPeter Zijlstra void scheduler_ipi(void);
153485ba2d86SRoland McGrath extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
15351da177e4SLinus Torvalds #else
1536184748ccSPeter Zijlstra static inline void scheduler_ipi(void) { }
153785ba2d86SRoland McGrath static inline unsigned long wait_task_inactive(struct task_struct *p,
153885ba2d86SRoland McGrath 					       long match_state)
153985ba2d86SRoland McGrath {
154085ba2d86SRoland McGrath 	return 1;
154185ba2d86SRoland McGrath }
15421da177e4SLinus Torvalds #endif
15431da177e4SLinus Torvalds 
15441da177e4SLinus Torvalds /*
1545260ea101SEric W. Biederman  * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
154622e2c507SJens Axboe  * subscriptions and synchronises with wait4().  Also used in procfs.  Also
1547ddbcc7e8SPaul Menage  * pins the final release of task.io_context.  Also protects ->cpuset and
1548d68b46feSOleg Nesterov  * ->cgroup.subsys[]. And ->vfork_done.
15491da177e4SLinus Torvalds  *
15501da177e4SLinus Torvalds  * Nests both inside and outside of read_lock(&tasklist_lock).
15511da177e4SLinus Torvalds  * It must not be nested with write_lock_irq(&tasklist_lock),
15521da177e4SLinus Torvalds  * neither inside nor outside.
15531da177e4SLinus Torvalds  */
15541da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p)
15551da177e4SLinus Torvalds {
15561da177e4SLinus Torvalds 	spin_lock(&p->alloc_lock);
15571da177e4SLinus Torvalds }
15581da177e4SLinus Torvalds 
15591da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p)
15601da177e4SLinus Torvalds {
15611da177e4SLinus Torvalds 	spin_unlock(&p->alloc_lock);
15621da177e4SLinus Torvalds }
15631da177e4SLinus Torvalds 
1564c65eacbeSAndy Lutomirski #ifdef CONFIG_THREAD_INFO_IN_TASK
1565c65eacbeSAndy Lutomirski 
1566c65eacbeSAndy Lutomirski static inline struct thread_info *task_thread_info(struct task_struct *task)
1567c65eacbeSAndy Lutomirski {
1568c65eacbeSAndy Lutomirski 	return &task->thread_info;
1569c65eacbeSAndy Lutomirski }
1570c6c314a6SAndy Lutomirski 
1571c6c314a6SAndy Lutomirski /*
1572c6c314a6SAndy Lutomirski  * When accessing the stack of a non-current task that might exit, use
1573c6c314a6SAndy Lutomirski  * try_get_task_stack() instead.  task_stack_page will return a pointer
1574c6c314a6SAndy Lutomirski  * that could get freed out from under you.
1575c6c314a6SAndy Lutomirski  */
1576c65eacbeSAndy Lutomirski static inline void *task_stack_page(const struct task_struct *task)
1577c65eacbeSAndy Lutomirski {
1578c65eacbeSAndy Lutomirski 	return task->stack;
1579c65eacbeSAndy Lutomirski }
1580c6c314a6SAndy Lutomirski 
1581c65eacbeSAndy Lutomirski #define setup_thread_stack(new,old)	do { } while(0)
1582c6c314a6SAndy Lutomirski 
1583c65eacbeSAndy Lutomirski static inline unsigned long *end_of_stack(const struct task_struct *task)
1584c65eacbeSAndy Lutomirski {
1585c65eacbeSAndy Lutomirski 	return task->stack;
1586c65eacbeSAndy Lutomirski }
1587c65eacbeSAndy Lutomirski 
1588c65eacbeSAndy Lutomirski #elif !defined(__HAVE_THREAD_FUNCTIONS)
1589f037360fSAl Viro 
1590f7e4217bSRoman Zippel #define task_thread_info(task)	((struct thread_info *)(task)->stack)
1591c65eacbeSAndy Lutomirski #define task_stack_page(task)	((void *)(task)->stack)
1592a1261f54SAl Viro 
159310ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
159410ebffdeSAl Viro {
159510ebffdeSAl Viro 	*task_thread_info(p) = *task_thread_info(org);
159610ebffdeSAl Viro 	task_thread_info(p)->task = p;
159710ebffdeSAl Viro }
159810ebffdeSAl Viro 
15996a40281aSChuck Ebbert /*
16006a40281aSChuck Ebbert  * Return the address of the last usable long on the stack.
16016a40281aSChuck Ebbert  *
16026a40281aSChuck Ebbert  * When the stack grows down, this is just above the thread
16036a40281aSChuck Ebbert  * info struct. Going any lower will corrupt the threadinfo.
16046a40281aSChuck Ebbert  *
16056a40281aSChuck Ebbert  * When the stack grows up, this is the highest address.
16066a40281aSChuck Ebbert  * Beyond that position, we corrupt data on the next page.
16076a40281aSChuck Ebbert  */
160810ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p)
160910ebffdeSAl Viro {
16106a40281aSChuck Ebbert #ifdef CONFIG_STACK_GROWSUP
16116a40281aSChuck Ebbert 	return (unsigned long *)((unsigned long)task_thread_info(p) + THREAD_SIZE) - 1;
16126a40281aSChuck Ebbert #else
1613f7e4217bSRoman Zippel 	return (unsigned long *)(task_thread_info(p) + 1);
16146a40281aSChuck Ebbert #endif
161510ebffdeSAl Viro }
161610ebffdeSAl Viro 
1617f037360fSAl Viro #endif
1618c6c314a6SAndy Lutomirski 
161968f24b08SAndy Lutomirski #ifdef CONFIG_THREAD_INFO_IN_TASK
162068f24b08SAndy Lutomirski static inline void *try_get_task_stack(struct task_struct *tsk)
162168f24b08SAndy Lutomirski {
162268f24b08SAndy Lutomirski 	return atomic_inc_not_zero(&tsk->stack_refcount) ?
162368f24b08SAndy Lutomirski 		task_stack_page(tsk) : NULL;
162468f24b08SAndy Lutomirski }
162568f24b08SAndy Lutomirski 
162668f24b08SAndy Lutomirski extern void put_task_stack(struct task_struct *tsk);
162768f24b08SAndy Lutomirski #else
1628c6c314a6SAndy Lutomirski static inline void *try_get_task_stack(struct task_struct *tsk)
1629c6c314a6SAndy Lutomirski {
1630c6c314a6SAndy Lutomirski 	return task_stack_page(tsk);
1631c6c314a6SAndy Lutomirski }
1632c6c314a6SAndy Lutomirski 
1633c6c314a6SAndy Lutomirski static inline void put_task_stack(struct task_struct *tsk) {}
163468f24b08SAndy Lutomirski #endif
1635c6c314a6SAndy Lutomirski 
1636a70857e4SAaron Tomlin #define task_stack_end_corrupted(task) \
1637a70857e4SAaron Tomlin 		(*(end_of_stack(task)) != STACK_END_MAGIC)
1638f037360fSAl Viro 
16398b05c7e6SFUJITA Tomonori static inline int object_is_on_stack(void *obj)
16408b05c7e6SFUJITA Tomonori {
16418b05c7e6SFUJITA Tomonori 	void *stack = task_stack_page(current);
16428b05c7e6SFUJITA Tomonori 
16438b05c7e6SFUJITA Tomonori 	return (obj >= stack) && (obj < (stack + THREAD_SIZE));
16448b05c7e6SFUJITA Tomonori }
16458b05c7e6SFUJITA Tomonori 
1646b235beeaSLinus Torvalds extern void thread_stack_cache_init(void);
16478c9843e5SBenjamin Herrenschmidt 
16487c9f8861SEric Sandeen #ifdef CONFIG_DEBUG_STACK_USAGE
16497c9f8861SEric Sandeen static inline unsigned long stack_not_used(struct task_struct *p)
16507c9f8861SEric Sandeen {
16517c9f8861SEric Sandeen 	unsigned long *n = end_of_stack(p);
16527c9f8861SEric Sandeen 
16537c9f8861SEric Sandeen 	do { 	/* Skip over canary */
16546c31da34SHelge Deller # ifdef CONFIG_STACK_GROWSUP
16556c31da34SHelge Deller 		n--;
16566c31da34SHelge Deller # else
16577c9f8861SEric Sandeen 		n++;
16586c31da34SHelge Deller # endif
16597c9f8861SEric Sandeen 	} while (!*n);
16607c9f8861SEric Sandeen 
16616c31da34SHelge Deller # ifdef CONFIG_STACK_GROWSUP
16626c31da34SHelge Deller 	return (unsigned long)end_of_stack(p) - (unsigned long)n;
16636c31da34SHelge Deller # else
16647c9f8861SEric Sandeen 	return (unsigned long)n - (unsigned long)end_of_stack(p);
16656c31da34SHelge Deller # endif
16667c9f8861SEric Sandeen }
16677c9f8861SEric Sandeen #endif
1668d4311ff1SAaron Tomlin extern void set_task_stack_end_magic(struct task_struct *tsk);
16697c9f8861SEric Sandeen 
16701da177e4SLinus Torvalds /* set thread flags in other task's structures
16711da177e4SLinus Torvalds  * - see asm/thread_info.h for TIF_xxxx flags available
16721da177e4SLinus Torvalds  */
16731da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
16741da177e4SLinus Torvalds {
1675a1261f54SAl Viro 	set_ti_thread_flag(task_thread_info(tsk), flag);
16761da177e4SLinus Torvalds }
16771da177e4SLinus Torvalds 
16781da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
16791da177e4SLinus Torvalds {
1680a1261f54SAl Viro 	clear_ti_thread_flag(task_thread_info(tsk), flag);
16811da177e4SLinus Torvalds }
16821da177e4SLinus Torvalds 
16831da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
16841da177e4SLinus Torvalds {
1685a1261f54SAl Viro 	return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
16861da177e4SLinus Torvalds }
16871da177e4SLinus Torvalds 
16881da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
16891da177e4SLinus Torvalds {
1690a1261f54SAl Viro 	return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
16911da177e4SLinus Torvalds }
16921da177e4SLinus Torvalds 
16931da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
16941da177e4SLinus Torvalds {
1695a1261f54SAl Viro 	return test_ti_thread_flag(task_thread_info(tsk), flag);
16961da177e4SLinus Torvalds }
16971da177e4SLinus Torvalds 
16981da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk)
16991da177e4SLinus Torvalds {
17001da177e4SLinus Torvalds 	set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
17011da177e4SLinus Torvalds }
17021da177e4SLinus Torvalds 
17031da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk)
17041da177e4SLinus Torvalds {
17051da177e4SLinus Torvalds 	clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
17061da177e4SLinus Torvalds }
17071da177e4SLinus Torvalds 
17088ae121acSGregory Haskins static inline int test_tsk_need_resched(struct task_struct *tsk)
17098ae121acSGregory Haskins {
17108ae121acSGregory Haskins 	return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
17118ae121acSGregory Haskins }
17128ae121acSGregory Haskins 
17131da177e4SLinus Torvalds /*
17141da177e4SLinus Torvalds  * cond_resched() and cond_resched_lock(): latency reduction via
17151da177e4SLinus Torvalds  * explicit rescheduling in places that are safe. The return
17161da177e4SLinus Torvalds  * value indicates whether a reschedule was done in fact.
17171da177e4SLinus Torvalds  * cond_resched_lock() will drop the spinlock before scheduling,
17181da177e4SLinus Torvalds  * cond_resched_softirq() will enable bhs before scheduling.
17191da177e4SLinus Torvalds  */
172035a773a0SPeter Zijlstra #ifndef CONFIG_PREEMPT
1721c3921ab7SLinus Torvalds extern int _cond_resched(void);
172235a773a0SPeter Zijlstra #else
172335a773a0SPeter Zijlstra static inline int _cond_resched(void) { return 0; }
172435a773a0SPeter Zijlstra #endif
17256f80bd98SFrederic Weisbecker 
1726613afbf8SFrederic Weisbecker #define cond_resched() ({			\
17273427445aSPeter Zijlstra 	___might_sleep(__FILE__, __LINE__, 0);	\
1728613afbf8SFrederic Weisbecker 	_cond_resched();			\
1729613afbf8SFrederic Weisbecker })
17306f80bd98SFrederic Weisbecker 
1731613afbf8SFrederic Weisbecker extern int __cond_resched_lock(spinlock_t *lock);
1732613afbf8SFrederic Weisbecker 
1733613afbf8SFrederic Weisbecker #define cond_resched_lock(lock) ({				\
17343427445aSPeter Zijlstra 	___might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);\
1735613afbf8SFrederic Weisbecker 	__cond_resched_lock(lock);				\
1736613afbf8SFrederic Weisbecker })
1737613afbf8SFrederic Weisbecker 
1738613afbf8SFrederic Weisbecker extern int __cond_resched_softirq(void);
1739613afbf8SFrederic Weisbecker 
1740613afbf8SFrederic Weisbecker #define cond_resched_softirq() ({					\
17413427445aSPeter Zijlstra 	___might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET);	\
1742613afbf8SFrederic Weisbecker 	__cond_resched_softirq();					\
1743613afbf8SFrederic Weisbecker })
17441da177e4SLinus Torvalds 
1745f6f3c437SSimon Horman static inline void cond_resched_rcu(void)
1746f6f3c437SSimon Horman {
1747f6f3c437SSimon Horman #if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
1748f6f3c437SSimon Horman 	rcu_read_unlock();
1749f6f3c437SSimon Horman 	cond_resched();
1750f6f3c437SSimon Horman 	rcu_read_lock();
1751f6f3c437SSimon Horman #endif
1752f6f3c437SSimon Horman }
1753f6f3c437SSimon Horman 
17541da177e4SLinus Torvalds /*
17551da177e4SLinus Torvalds  * Does a critical section need to be broken due to another
175695c354feSNick Piggin  * task waiting?: (technically does not depend on CONFIG_PREEMPT,
175795c354feSNick Piggin  * but a general need for low latency)
17581da177e4SLinus Torvalds  */
175995c354feSNick Piggin static inline int spin_needbreak(spinlock_t *lock)
17601da177e4SLinus Torvalds {
176195c354feSNick Piggin #ifdef CONFIG_PREEMPT
176295c354feSNick Piggin 	return spin_is_contended(lock);
176395c354feSNick Piggin #else
17641da177e4SLinus Torvalds 	return 0;
176595c354feSNick Piggin #endif
17661da177e4SLinus Torvalds }
17671da177e4SLinus Torvalds 
176875f93fedSPeter Zijlstra static __always_inline bool need_resched(void)
176975f93fedSPeter Zijlstra {
177075f93fedSPeter Zijlstra 	return unlikely(tif_need_resched());
177175f93fedSPeter Zijlstra }
177275f93fedSPeter Zijlstra 
1773ee761f62SThomas Gleixner /*
1774f06febc9SFrank Mayhar  * Thread group CPU time accounting.
1775f06febc9SFrank Mayhar  */
17764cd4c1b4SPeter Zijlstra void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
17774da94d49SPeter Zijlstra void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
1778f06febc9SFrank Mayhar 
1779f06febc9SFrank Mayhar /*
17801da177e4SLinus Torvalds  * Wrappers for p->thread_info->cpu access. No-op on UP.
17811da177e4SLinus Torvalds  */
17821da177e4SLinus Torvalds #ifdef CONFIG_SMP
17831da177e4SLinus Torvalds 
17841da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
17851da177e4SLinus Torvalds {
1786c65eacbeSAndy Lutomirski #ifdef CONFIG_THREAD_INFO_IN_TASK
1787c65eacbeSAndy Lutomirski 	return p->cpu;
1788c65eacbeSAndy Lutomirski #else
1789a1261f54SAl Viro 	return task_thread_info(p)->cpu;
1790c65eacbeSAndy Lutomirski #endif
17911da177e4SLinus Torvalds }
17921da177e4SLinus Torvalds 
1793b32e86b4SIngo Molnar static inline int task_node(const struct task_struct *p)
1794b32e86b4SIngo Molnar {
1795b32e86b4SIngo Molnar 	return cpu_to_node(task_cpu(p));
1796b32e86b4SIngo Molnar }
1797b32e86b4SIngo Molnar 
1798c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
17991da177e4SLinus Torvalds 
18001da177e4SLinus Torvalds #else
18011da177e4SLinus Torvalds 
18021da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
18031da177e4SLinus Torvalds {
18041da177e4SLinus Torvalds 	return 0;
18051da177e4SLinus Torvalds }
18061da177e4SLinus Torvalds 
18071da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
18081da177e4SLinus Torvalds {
18091da177e4SLinus Torvalds }
18101da177e4SLinus Torvalds 
18111da177e4SLinus Torvalds #endif /* CONFIG_SMP */
18121da177e4SLinus Torvalds 
1813d9345c65SPan Xinhui /*
1814d9345c65SPan Xinhui  * In order to reduce various lock holder preemption latencies provide an
1815d9345c65SPan Xinhui  * interface to see if a vCPU is currently running or not.
1816d9345c65SPan Xinhui  *
1817d9345c65SPan Xinhui  * This allows us to terminate optimistic spin loops and block, analogous to
1818d9345c65SPan Xinhui  * the native optimistic spin heuristic of testing if the lock owner task is
1819d9345c65SPan Xinhui  * running or not.
1820d9345c65SPan Xinhui  */
1821d9345c65SPan Xinhui #ifndef vcpu_is_preempted
1822d9345c65SPan Xinhui # define vcpu_is_preempted(cpu)	false
1823d9345c65SPan Xinhui #endif
1824d9345c65SPan Xinhui 
182596f874e2SRusty Russell extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
182696f874e2SRusty Russell extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
18275c45bf27SSiddha, Suresh B 
18287c941438SDhaval Giani #ifdef CONFIG_CGROUP_SCHED
182907e06b01SYong Zhang extern struct task_group root_task_group;
18308323f26cSPeter Zijlstra #endif /* CONFIG_CGROUP_SCHED */
18319b5b7751SSrivatsa Vaddagiri 
183254e99124SDhaval Giani extern int task_can_switch_user(struct user_struct *up,
183354e99124SDhaval Giani 					struct task_struct *tsk);
183454e99124SDhaval Giani 
183582455257SDave Hansen #ifndef TASK_SIZE_OF
183682455257SDave Hansen #define TASK_SIZE_OF(tsk)	TASK_SIZE
183782455257SDave Hansen #endif
183882455257SDave Hansen 
18391da177e4SLinus Torvalds #endif
1840