xref: /linux/include/linux/sched.h (revision e162b39a368f0401e41b558f430c354d12a85b37)
11da177e4SLinus Torvalds #ifndef _LINUX_SCHED_H
21da177e4SLinus Torvalds #define _LINUX_SCHED_H
31da177e4SLinus Torvalds 
4b7b3c76aSDavid Woodhouse /*
5b7b3c76aSDavid Woodhouse  * cloning flags:
6b7b3c76aSDavid Woodhouse  */
7b7b3c76aSDavid Woodhouse #define CSIGNAL		0x000000ff	/* signal mask to be sent at exit */
8b7b3c76aSDavid Woodhouse #define CLONE_VM	0x00000100	/* set if VM shared between processes */
9b7b3c76aSDavid Woodhouse #define CLONE_FS	0x00000200	/* set if fs info shared between processes */
10b7b3c76aSDavid Woodhouse #define CLONE_FILES	0x00000400	/* set if open files shared between processes */
11b7b3c76aSDavid Woodhouse #define CLONE_SIGHAND	0x00000800	/* set if signal handlers and blocked signals shared */
12b7b3c76aSDavid Woodhouse #define CLONE_PTRACE	0x00002000	/* set if we want to let tracing continue on the child too */
13b7b3c76aSDavid Woodhouse #define CLONE_VFORK	0x00004000	/* set if the parent wants the child to wake it up on mm_release */
14b7b3c76aSDavid Woodhouse #define CLONE_PARENT	0x00008000	/* set if we want to have the same parent as the cloner */
15b7b3c76aSDavid Woodhouse #define CLONE_THREAD	0x00010000	/* Same thread group? */
16b7b3c76aSDavid Woodhouse #define CLONE_NEWNS	0x00020000	/* New namespace group? */
17b7b3c76aSDavid Woodhouse #define CLONE_SYSVSEM	0x00040000	/* share system V SEM_UNDO semantics */
18b7b3c76aSDavid Woodhouse #define CLONE_SETTLS	0x00080000	/* create a new TLS for the child */
19b7b3c76aSDavid Woodhouse #define CLONE_PARENT_SETTID	0x00100000	/* set the TID in the parent */
20b7b3c76aSDavid Woodhouse #define CLONE_CHILD_CLEARTID	0x00200000	/* clear the TID in the child */
21b7b3c76aSDavid Woodhouse #define CLONE_DETACHED		0x00400000	/* Unused, ignored */
22b7b3c76aSDavid Woodhouse #define CLONE_UNTRACED		0x00800000	/* set if the tracing process can't force CLONE_PTRACE on this clone */
23b7b3c76aSDavid Woodhouse #define CLONE_CHILD_SETTID	0x01000000	/* set the TID in the child */
24b7b3c76aSDavid Woodhouse #define CLONE_STOPPED		0x02000000	/* Start in stopped state */
25071df104SSerge E. Hallyn #define CLONE_NEWUTS		0x04000000	/* New utsname group? */
2625b21cb2SKirill Korotaev #define CLONE_NEWIPC		0x08000000	/* New ipcs */
2777ec739dSSerge E. Hallyn #define CLONE_NEWUSER		0x10000000	/* New user namespace */
2830e49c26SPavel Emelyanov #define CLONE_NEWPID		0x20000000	/* New pid namespace */
29169e3674SEric W. Biederman #define CLONE_NEWNET		0x40000000	/* New network namespace */
30fadad878SJens Axboe #define CLONE_IO		0x80000000	/* Clone io context */
31b7b3c76aSDavid Woodhouse 
32b7b3c76aSDavid Woodhouse /*
33b7b3c76aSDavid Woodhouse  * Scheduling policies
34b7b3c76aSDavid Woodhouse  */
35b7b3c76aSDavid Woodhouse #define SCHED_NORMAL		0
36b7b3c76aSDavid Woodhouse #define SCHED_FIFO		1
37b7b3c76aSDavid Woodhouse #define SCHED_RR		2
38b7b3c76aSDavid Woodhouse #define SCHED_BATCH		3
390e6aca43SIngo Molnar /* SCHED_ISO: reserved but not implemented yet */
400e6aca43SIngo Molnar #define SCHED_IDLE		5
41b7b3c76aSDavid Woodhouse 
42a3b6714eSDavid Woodhouse #ifdef __KERNEL__
43b7b3c76aSDavid Woodhouse 
44b7b3c76aSDavid Woodhouse struct sched_param {
45b7b3c76aSDavid Woodhouse 	int sched_priority;
46b7b3c76aSDavid Woodhouse };
47b7b3c76aSDavid Woodhouse 
481da177e4SLinus Torvalds #include <asm/param.h>	/* for HZ */
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #include <linux/capability.h>
511da177e4SLinus Torvalds #include <linux/threads.h>
521da177e4SLinus Torvalds #include <linux/kernel.h>
531da177e4SLinus Torvalds #include <linux/types.h>
541da177e4SLinus Torvalds #include <linux/timex.h>
551da177e4SLinus Torvalds #include <linux/jiffies.h>
561da177e4SLinus Torvalds #include <linux/rbtree.h>
571da177e4SLinus Torvalds #include <linux/thread_info.h>
581da177e4SLinus Torvalds #include <linux/cpumask.h>
591da177e4SLinus Torvalds #include <linux/errno.h>
601da177e4SLinus Torvalds #include <linux/nodemask.h>
61c92ff1bdSMartin Schwidefsky #include <linux/mm_types.h>
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds #include <asm/system.h>
641da177e4SLinus Torvalds #include <asm/page.h>
651da177e4SLinus Torvalds #include <asm/ptrace.h>
661da177e4SLinus Torvalds #include <asm/cputime.h>
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds #include <linux/smp.h>
691da177e4SLinus Torvalds #include <linux/sem.h>
701da177e4SLinus Torvalds #include <linux/signal.h>
711da177e4SLinus Torvalds #include <linux/fs_struct.h>
721da177e4SLinus Torvalds #include <linux/compiler.h>
731da177e4SLinus Torvalds #include <linux/completion.h>
741da177e4SLinus Torvalds #include <linux/pid.h>
751da177e4SLinus Torvalds #include <linux/percpu.h>
761da177e4SLinus Torvalds #include <linux/topology.h>
773e26c149SPeter Zijlstra #include <linux/proportions.h>
781da177e4SLinus Torvalds #include <linux/seccomp.h>
79e56d0903SIngo Molnar #include <linux/rcupdate.h>
8023f78d4aSIngo Molnar #include <linux/rtmutex.h>
811da177e4SLinus Torvalds 
82a3b6714eSDavid Woodhouse #include <linux/time.h>
83a3b6714eSDavid Woodhouse #include <linux/param.h>
84a3b6714eSDavid Woodhouse #include <linux/resource.h>
85a3b6714eSDavid Woodhouse #include <linux/timer.h>
86a3b6714eSDavid Woodhouse #include <linux/hrtimer.h>
877c3ab738SAndrew Morton #include <linux/task_io_accounting.h>
885cb350baSDhaval Giani #include <linux/kobject.h>
899745512cSArjan van de Ven #include <linux/latencytop.h>
909e2b2dc4SDavid Howells #include <linux/cred.h>
91a3b6714eSDavid Woodhouse 
92a3b6714eSDavid Woodhouse #include <asm/processor.h>
9336d57ac4SH. J. Lu 
9478fb7466SPavel Emelianov struct mem_cgroup;
951da177e4SLinus Torvalds struct exec_domain;
96c87e2837SIngo Molnar struct futex_pi_state;
97286100a6SAlexey Dobriyan struct robust_list_head;
98d89d8796SNeil Brown struct bio;
99ca0002a1SMarkus Metzger struct bts_tracer;
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds /*
1021da177e4SLinus Torvalds  * List of flags we want to share for kernel threads,
1031da177e4SLinus Torvalds  * if only because they are not used by them anyway.
1041da177e4SLinus Torvalds  */
1051da177e4SLinus Torvalds #define CLONE_KERNEL	(CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds /*
1081da177e4SLinus Torvalds  * These are the constant used to fake the fixed-point load-average
1091da177e4SLinus Torvalds  * counting. Some notes:
1101da177e4SLinus Torvalds  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
1111da177e4SLinus Torvalds  *    a load-average precision of 10 bits integer + 11 bits fractional
1121da177e4SLinus Torvalds  *  - if you want to count load-averages more often, you need more
1131da177e4SLinus Torvalds  *    precision, or rounding will get you. With 2-second counting freq,
1141da177e4SLinus Torvalds  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
1151da177e4SLinus Torvalds  *    11 bit fractions.
1161da177e4SLinus Torvalds  */
1171da177e4SLinus Torvalds extern unsigned long avenrun[];		/* Load averages */
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds #define FSHIFT		11		/* nr of bits of precision */
1201da177e4SLinus Torvalds #define FIXED_1		(1<<FSHIFT)	/* 1.0 as fixed-point */
1210c2043abSLinus Torvalds #define LOAD_FREQ	(5*HZ+1)	/* 5 sec intervals */
1221da177e4SLinus Torvalds #define EXP_1		1884		/* 1/exp(5sec/1min) as fixed-point */
1231da177e4SLinus Torvalds #define EXP_5		2014		/* 1/exp(5sec/5min) */
1241da177e4SLinus Torvalds #define EXP_15		2037		/* 1/exp(5sec/15min) */
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \
1271da177e4SLinus Torvalds 	load *= exp; \
1281da177e4SLinus Torvalds 	load += n*(FIXED_1-exp); \
1291da177e4SLinus Torvalds 	load >>= FSHIFT;
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds extern unsigned long total_forks;
1321da177e4SLinus Torvalds extern int nr_threads;
1331da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts);
1341da177e4SLinus Torvalds extern int nr_processes(void);
1351da177e4SLinus Torvalds extern unsigned long nr_running(void);
1361da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void);
137db1b1fefSJack Steiner extern unsigned long nr_active(void);
1381da177e4SLinus Torvalds extern unsigned long nr_iowait(void);
1391da177e4SLinus Torvalds 
14043ae34cbSIngo Molnar struct seq_file;
14143ae34cbSIngo Molnar struct cfs_rq;
1424cf86d77SIngo Molnar struct task_group;
14343ae34cbSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
14443ae34cbSIngo Molnar extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
14543ae34cbSIngo Molnar extern void proc_sched_set_task(struct task_struct *p);
14643ae34cbSIngo Molnar extern void
1475cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
14843ae34cbSIngo Molnar #else
14943ae34cbSIngo Molnar static inline void
15043ae34cbSIngo Molnar proc_sched_show_task(struct task_struct *p, struct seq_file *m)
15143ae34cbSIngo Molnar {
15243ae34cbSIngo Molnar }
15343ae34cbSIngo Molnar static inline void proc_sched_set_task(struct task_struct *p)
15443ae34cbSIngo Molnar {
15543ae34cbSIngo Molnar }
15643ae34cbSIngo Molnar static inline void
1575cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
15843ae34cbSIngo Molnar {
15943ae34cbSIngo Molnar }
16043ae34cbSIngo Molnar #endif
1611da177e4SLinus Torvalds 
162690229a0SIngo Molnar extern unsigned long long time_sync_thresh;
163690229a0SIngo Molnar 
1644a8342d2SLinus Torvalds /*
1654a8342d2SLinus Torvalds  * Task state bitmask. NOTE! These bits are also
1664a8342d2SLinus Torvalds  * encoded in fs/proc/array.c: get_task_state().
1674a8342d2SLinus Torvalds  *
1684a8342d2SLinus Torvalds  * We have two separate sets of flags: task->state
1694a8342d2SLinus Torvalds  * is about runnability, while task->exit_state are
1704a8342d2SLinus Torvalds  * about the task exiting. Confusing, but this way
1714a8342d2SLinus Torvalds  * modifying one set can't modify the other one by
1724a8342d2SLinus Torvalds  * mistake.
1734a8342d2SLinus Torvalds  */
1741da177e4SLinus Torvalds #define TASK_RUNNING		0
1751da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE	1
1761da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE	2
177f021a3c2SMatthew Wilcox #define __TASK_STOPPED		4
178f021a3c2SMatthew Wilcox #define __TASK_TRACED		8
1794a8342d2SLinus Torvalds /* in tsk->exit_state */
1804a8342d2SLinus Torvalds #define EXIT_ZOMBIE		16
1814a8342d2SLinus Torvalds #define EXIT_DEAD		32
1824a8342d2SLinus Torvalds /* in tsk->state again */
183af927232SMike Galbraith #define TASK_DEAD		64
184f021a3c2SMatthew Wilcox #define TASK_WAKEKILL		128
185f021a3c2SMatthew Wilcox 
186f021a3c2SMatthew Wilcox /* Convenience macros for the sake of set_task_state */
187f021a3c2SMatthew Wilcox #define TASK_KILLABLE		(TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
188f021a3c2SMatthew Wilcox #define TASK_STOPPED		(TASK_WAKEKILL | __TASK_STOPPED)
189f021a3c2SMatthew Wilcox #define TASK_TRACED		(TASK_WAKEKILL | __TASK_TRACED)
1901da177e4SLinus Torvalds 
19192a1f4bcSMatthew Wilcox /* Convenience macros for the sake of wake_up */
19292a1f4bcSMatthew Wilcox #define TASK_NORMAL		(TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
193f021a3c2SMatthew Wilcox #define TASK_ALL		(TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
19492a1f4bcSMatthew Wilcox 
19592a1f4bcSMatthew Wilcox /* get_task_state() */
19692a1f4bcSMatthew Wilcox #define TASK_REPORT		(TASK_RUNNING | TASK_INTERRUPTIBLE | \
197f021a3c2SMatthew Wilcox 				 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
198f021a3c2SMatthew Wilcox 				 __TASK_TRACED)
19992a1f4bcSMatthew Wilcox 
200f021a3c2SMatthew Wilcox #define task_is_traced(task)	((task->state & __TASK_TRACED) != 0)
201f021a3c2SMatthew Wilcox #define task_is_stopped(task)	((task->state & __TASK_STOPPED) != 0)
20292a1f4bcSMatthew Wilcox #define task_is_stopped_or_traced(task)	\
203f021a3c2SMatthew Wilcox 			((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
20492a1f4bcSMatthew Wilcox #define task_contributes_to_load(task)	\
20592a1f4bcSMatthew Wilcox 				((task->state & TASK_UNINTERRUPTIBLE) != 0)
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds #define __set_task_state(tsk, state_value)		\
2081da177e4SLinus Torvalds 	do { (tsk)->state = (state_value); } while (0)
2091da177e4SLinus Torvalds #define set_task_state(tsk, state_value)		\
2101da177e4SLinus Torvalds 	set_mb((tsk)->state, (state_value))
2111da177e4SLinus Torvalds 
212498d0c57SAndrew Morton /*
213498d0c57SAndrew Morton  * set_current_state() includes a barrier so that the write of current->state
214498d0c57SAndrew Morton  * is correctly serialised wrt the caller's subsequent test of whether to
215498d0c57SAndrew Morton  * actually sleep:
216498d0c57SAndrew Morton  *
217498d0c57SAndrew Morton  *	set_current_state(TASK_UNINTERRUPTIBLE);
218498d0c57SAndrew Morton  *	if (do_i_need_to_sleep())
219498d0c57SAndrew Morton  *		schedule();
220498d0c57SAndrew Morton  *
221498d0c57SAndrew Morton  * If the caller does not need such serialisation then use __set_current_state()
222498d0c57SAndrew Morton  */
2231da177e4SLinus Torvalds #define __set_current_state(state_value)			\
2241da177e4SLinus Torvalds 	do { current->state = (state_value); } while (0)
2251da177e4SLinus Torvalds #define set_current_state(state_value)		\
2261da177e4SLinus Torvalds 	set_mb(current->state, (state_value))
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds /* Task command name length */
2291da177e4SLinus Torvalds #define TASK_COMM_LEN 16
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds #include <linux/spinlock.h>
2321da177e4SLinus Torvalds 
2331da177e4SLinus Torvalds /*
2341da177e4SLinus Torvalds  * This serializes "schedule()" and also protects
2351da177e4SLinus Torvalds  * the run-queue from deletions/modifications (but
2361da177e4SLinus Torvalds  * _adding_ to the beginning of the run-queue has
2371da177e4SLinus Torvalds  * a separate lock).
2381da177e4SLinus Torvalds  */
2391da177e4SLinus Torvalds extern rwlock_t tasklist_lock;
2401da177e4SLinus Torvalds extern spinlock_t mmlist_lock;
2411da177e4SLinus Torvalds 
24236c8b586SIngo Molnar struct task_struct;
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds extern void sched_init(void);
2451da177e4SLinus Torvalds extern void sched_init_smp(void);
2462d07b255SHarvey Harrison extern asmlinkage void schedule_tail(struct task_struct *prev);
24736c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu);
2481df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle);
2491da177e4SLinus Torvalds 
250017730c1SIngo Molnar extern int runqueue_is_locked(void);
251ad474cacSOleg Nesterov extern void task_rq_unlock_wait(struct task_struct *p);
252017730c1SIngo Molnar 
2536a7b3dc3SRusty Russell extern cpumask_var_t nohz_cpu_mask;
25446cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
25546cb4b7cSSiddha, Suresh B extern int select_nohz_load_balancer(int cpu);
25646cb4b7cSSiddha, Suresh B #else
25746cb4b7cSSiddha, Suresh B static inline int select_nohz_load_balancer(int cpu)
25846cb4b7cSSiddha, Suresh B {
25946cb4b7cSSiddha, Suresh B 	return 0;
26046cb4b7cSSiddha, Suresh B }
26146cb4b7cSSiddha, Suresh B #endif
2621da177e4SLinus Torvalds 
263e59e2ae2SIngo Molnar /*
26439bc89fdSIngo Molnar  * Only dump TASK_* tasks. (0 for all tasks)
265e59e2ae2SIngo Molnar  */
266e59e2ae2SIngo Molnar extern void show_state_filter(unsigned long state_filter);
267e59e2ae2SIngo Molnar 
268e59e2ae2SIngo Molnar static inline void show_state(void)
269e59e2ae2SIngo Molnar {
27039bc89fdSIngo Molnar 	show_state_filter(0);
271e59e2ae2SIngo Molnar }
272e59e2ae2SIngo Molnar 
2731da177e4SLinus Torvalds extern void show_regs(struct pt_regs *);
2741da177e4SLinus Torvalds 
2751da177e4SLinus Torvalds /*
2761da177e4SLinus Torvalds  * TASK is a pointer to the task whose backtrace we want to see (or NULL for current
2771da177e4SLinus Torvalds  * task), SP is the stack pointer of the first frame that should be shown in the back
2781da177e4SLinus Torvalds  * trace (or NULL if the entire call-chain of the task should be shown).
2791da177e4SLinus Torvalds  */
2801da177e4SLinus Torvalds extern void show_stack(struct task_struct *task, unsigned long *sp);
2811da177e4SLinus Torvalds 
2821da177e4SLinus Torvalds void io_schedule(void);
2831da177e4SLinus Torvalds long io_schedule_timeout(long timeout);
2841da177e4SLinus Torvalds 
2851da177e4SLinus Torvalds extern void cpu_init (void);
2861da177e4SLinus Torvalds extern void trap_init(void);
2871da177e4SLinus Torvalds extern void update_process_times(int user);
2881da177e4SLinus Torvalds extern void scheduler_tick(void);
2891da177e4SLinus Torvalds 
29082a1fcb9SIngo Molnar extern void sched_show_task(struct task_struct *p);
29182a1fcb9SIngo Molnar 
2928446f1d3SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP
2936687a97dSIngo Molnar extern void softlockup_tick(void);
2948446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void);
29504c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void);
296baf48f65SMandeep Singh Baines extern int proc_dosoftlockup_thresh(struct ctl_table *table, int write,
297baf48f65SMandeep Singh Baines 				    struct file *filp, void __user *buffer,
298baf48f65SMandeep Singh Baines 				    size_t *lenp, loff_t *ppos);
2999c44bc03SIngo Molnar extern unsigned int  softlockup_panic;
3009383d967SDimitri Sivanich extern int softlockup_thresh;
3018446f1d3SIngo Molnar #else
3026687a97dSIngo Molnar static inline void softlockup_tick(void)
3038446f1d3SIngo Molnar {
3048446f1d3SIngo Molnar }
3058446f1d3SIngo Molnar static inline void spawn_softlockup_task(void)
3068446f1d3SIngo Molnar {
3078446f1d3SIngo Molnar }
3088446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void)
3098446f1d3SIngo Molnar {
3108446f1d3SIngo Molnar }
31104c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void)
31204c9167fSJeremy Fitzhardinge {
31304c9167fSJeremy Fitzhardinge }
3148446f1d3SIngo Molnar #endif
3158446f1d3SIngo Molnar 
316*e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
317*e162b39aSMandeep Singh Baines extern unsigned int  sysctl_hung_task_panic;
318*e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_check_count;
319*e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_timeout_secs;
320*e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_warnings;
321*e162b39aSMandeep Singh Baines extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
322*e162b39aSMandeep Singh Baines 					 struct file *filp, void __user *buffer,
323*e162b39aSMandeep Singh Baines 					 size_t *lenp, loff_t *ppos);
324*e162b39aSMandeep Singh Baines #endif
3258446f1d3SIngo Molnar 
3261da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */
3271da177e4SLinus Torvalds #define __sched		__attribute__((__section__(".sched.text")))
328deaf2227SIngo Molnar 
329deaf2227SIngo Molnar /* Linker adds these: start and end of __sched functions */
330deaf2227SIngo Molnar extern char __sched_text_start[], __sched_text_end[];
331deaf2227SIngo Molnar 
3321da177e4SLinus Torvalds /* Is this address in the __sched functions? */
3331da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr);
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds #define	MAX_SCHEDULE_TIMEOUT	LONG_MAX
336b3c97528SHarvey Harrison extern signed long schedule_timeout(signed long timeout);
33764ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout);
338294d5cc2SMatthew Wilcox extern signed long schedule_timeout_killable(signed long timeout);
33964ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout);
3401da177e4SLinus Torvalds asmlinkage void schedule(void);
3411da177e4SLinus Torvalds 
342ab516013SSerge E. Hallyn struct nsproxy;
343acce292cSCedric Le Goater struct user_namespace;
3441da177e4SLinus Torvalds 
3451da177e4SLinus Torvalds /* Maximum number of active map areas.. This is a random (large) number */
3461da177e4SLinus Torvalds #define DEFAULT_MAX_MAP_COUNT	65536
3471da177e4SLinus Torvalds 
3481da177e4SLinus Torvalds extern int sysctl_max_map_count;
3491da177e4SLinus Torvalds 
3501da177e4SLinus Torvalds #include <linux/aio.h>
3511da177e4SLinus Torvalds 
3521da177e4SLinus Torvalds extern unsigned long
3531da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
3541da177e4SLinus Torvalds 		       unsigned long, unsigned long);
3551da177e4SLinus Torvalds extern unsigned long
3561da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
3571da177e4SLinus Torvalds 			  unsigned long len, unsigned long pgoff,
3581da177e4SLinus Torvalds 			  unsigned long flags);
3591363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long);
3601363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
3611da177e4SLinus Torvalds 
362f7d0b926SJeremy Fitzhardinge #if USE_SPLIT_PTLOCKS
363f412ac08SHugh Dickins /*
364f412ac08SHugh Dickins  * The mm counters are not protected by its page_table_lock,
365f412ac08SHugh Dickins  * so must be incremented atomically.
366f412ac08SHugh Dickins  */
367d3cb4871SChristoph Lameter #define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
368d3cb4871SChristoph Lameter #define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
369d3cb4871SChristoph Lameter #define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
370d3cb4871SChristoph Lameter #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
371d3cb4871SChristoph Lameter #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
372f412ac08SHugh Dickins 
373f7d0b926SJeremy Fitzhardinge #else  /* !USE_SPLIT_PTLOCKS */
374f412ac08SHugh Dickins /*
375f412ac08SHugh Dickins  * The mm counters are protected by its page_table_lock,
376f412ac08SHugh Dickins  * so can be incremented directly.
377f412ac08SHugh Dickins  */
3781da177e4SLinus Torvalds #define set_mm_counter(mm, member, value) (mm)->_##member = (value)
3791da177e4SLinus Torvalds #define get_mm_counter(mm, member) ((mm)->_##member)
3801da177e4SLinus Torvalds #define add_mm_counter(mm, member, value) (mm)->_##member += (value)
3811da177e4SLinus Torvalds #define inc_mm_counter(mm, member) (mm)->_##member++
3821da177e4SLinus Torvalds #define dec_mm_counter(mm, member) (mm)->_##member--
3834294621fSHugh Dickins 
384f7d0b926SJeremy Fitzhardinge #endif /* !USE_SPLIT_PTLOCKS */
385f412ac08SHugh Dickins 
386f412ac08SHugh Dickins #define get_mm_rss(mm)					\
387f412ac08SHugh Dickins 	(get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
388365e9c87SHugh Dickins #define update_hiwater_rss(mm)	do {			\
389365e9c87SHugh Dickins 	unsigned long _rss = get_mm_rss(mm);		\
390365e9c87SHugh Dickins 	if ((mm)->hiwater_rss < _rss)			\
391365e9c87SHugh Dickins 		(mm)->hiwater_rss = _rss;		\
392365e9c87SHugh Dickins } while (0)
393365e9c87SHugh Dickins #define update_hiwater_vm(mm)	do {			\
394365e9c87SHugh Dickins 	if ((mm)->hiwater_vm < (mm)->total_vm)		\
395365e9c87SHugh Dickins 		(mm)->hiwater_vm = (mm)->total_vm;	\
396365e9c87SHugh Dickins } while (0)
397365e9c87SHugh Dickins 
398901608d9SOleg Nesterov #define get_mm_hiwater_rss(mm)	max((mm)->hiwater_rss, get_mm_rss(mm))
399901608d9SOleg Nesterov #define get_mm_hiwater_vm(mm)	max((mm)->hiwater_vm, (mm)->total_vm)
400901608d9SOleg Nesterov 
4016c5d5238SKawai, Hidehiro extern void set_dumpable(struct mm_struct *mm, int value);
4026c5d5238SKawai, Hidehiro extern int get_dumpable(struct mm_struct *mm);
4036c5d5238SKawai, Hidehiro 
4046c5d5238SKawai, Hidehiro /* mm flags */
4053cb4a0bbSKawai, Hidehiro /* dumpable bits */
4066c5d5238SKawai, Hidehiro #define MMF_DUMPABLE      0  /* core dump is permitted */
4076c5d5238SKawai, Hidehiro #define MMF_DUMP_SECURELY 1  /* core file is readable only by root */
4083cb4a0bbSKawai, Hidehiro #define MMF_DUMPABLE_BITS 2
4093cb4a0bbSKawai, Hidehiro 
4103cb4a0bbSKawai, Hidehiro /* coredump filter bits */
4113cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_PRIVATE	2
4123cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_SHARED	3
4133cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_PRIVATE	4
4143cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_SHARED	5
41582df3973SRoland McGrath #define MMF_DUMP_ELF_HEADERS	6
416e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_PRIVATE 7
417e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_SHARED  8
4183cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_SHIFT	MMF_DUMPABLE_BITS
419e575f111SKOSAKI Motohiro #define MMF_DUMP_FILTER_BITS	7
4203cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_MASK \
4213cb4a0bbSKawai, Hidehiro 	(((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
4223cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_DEFAULT \
423e575f111SKOSAKI Motohiro 	((1 << MMF_DUMP_ANON_PRIVATE) |	(1 << MMF_DUMP_ANON_SHARED) |\
424656eb2cdSRoland McGrath 	 (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
425656eb2cdSRoland McGrath 
426656eb2cdSRoland McGrath #ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
427656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF	(1 << MMF_DUMP_ELF_HEADERS)
428656eb2cdSRoland McGrath #else
429656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF	0
430656eb2cdSRoland McGrath #endif
4316c5d5238SKawai, Hidehiro 
4321da177e4SLinus Torvalds struct sighand_struct {
4331da177e4SLinus Torvalds 	atomic_t		count;
4341da177e4SLinus Torvalds 	struct k_sigaction	action[_NSIG];
4351da177e4SLinus Torvalds 	spinlock_t		siglock;
436b8fceee1SDavide Libenzi 	wait_queue_head_t	signalfd_wqh;
4371da177e4SLinus Torvalds };
4381da177e4SLinus Torvalds 
4390e464814SKaiGai Kohei struct pacct_struct {
440f6ec29a4SKaiGai Kohei 	int			ac_flag;
441f6ec29a4SKaiGai Kohei 	long			ac_exitcode;
4420e464814SKaiGai Kohei 	unsigned long		ac_mem;
44377787bfbSKaiGai Kohei 	cputime_t		ac_utime, ac_stime;
44477787bfbSKaiGai Kohei 	unsigned long		ac_minflt, ac_majflt;
4450e464814SKaiGai Kohei };
4460e464814SKaiGai Kohei 
447f06febc9SFrank Mayhar /**
448f06febc9SFrank Mayhar  * struct task_cputime - collected CPU time counts
449f06febc9SFrank Mayhar  * @utime:		time spent in user mode, in &cputime_t units
450f06febc9SFrank Mayhar  * @stime:		time spent in kernel mode, in &cputime_t units
451f06febc9SFrank Mayhar  * @sum_exec_runtime:	total time spent on the CPU, in nanoseconds
452f06febc9SFrank Mayhar  *
453f06febc9SFrank Mayhar  * This structure groups together three kinds of CPU time that are
454f06febc9SFrank Mayhar  * tracked for threads and thread groups.  Most things considering
455f06febc9SFrank Mayhar  * CPU time want to group these counts together and treat all three
456f06febc9SFrank Mayhar  * of them in parallel.
457f06febc9SFrank Mayhar  */
458f06febc9SFrank Mayhar struct task_cputime {
459f06febc9SFrank Mayhar 	cputime_t utime;
460f06febc9SFrank Mayhar 	cputime_t stime;
461f06febc9SFrank Mayhar 	unsigned long long sum_exec_runtime;
462f06febc9SFrank Mayhar };
463f06febc9SFrank Mayhar /* Alternate field names when used to cache expirations. */
464f06febc9SFrank Mayhar #define prof_exp	stime
465f06febc9SFrank Mayhar #define virt_exp	utime
466f06febc9SFrank Mayhar #define sched_exp	sum_exec_runtime
467f06febc9SFrank Mayhar 
468f06febc9SFrank Mayhar /**
469f06febc9SFrank Mayhar  * struct thread_group_cputime - thread group interval timer counts
470f06febc9SFrank Mayhar  * @totals:		thread group interval timers; substructure for
471f06febc9SFrank Mayhar  *			uniprocessor kernel, per-cpu for SMP kernel.
472f06febc9SFrank Mayhar  *
473f06febc9SFrank Mayhar  * This structure contains the version of task_cputime, above, that is
474f06febc9SFrank Mayhar  * used for thread group CPU clock calculations.
475f06febc9SFrank Mayhar  */
476f06febc9SFrank Mayhar struct thread_group_cputime {
477f06febc9SFrank Mayhar 	struct task_cputime *totals;
478f06febc9SFrank Mayhar };
479f06febc9SFrank Mayhar 
4801da177e4SLinus Torvalds /*
4811da177e4SLinus Torvalds  * NOTE! "signal_struct" does not have it's own
4821da177e4SLinus Torvalds  * locking, because a shared signal_struct always
4831da177e4SLinus Torvalds  * implies a shared sighand_struct, so locking
4841da177e4SLinus Torvalds  * sighand_struct is always a proper superset of
4851da177e4SLinus Torvalds  * the locking of signal_struct.
4861da177e4SLinus Torvalds  */
4871da177e4SLinus Torvalds struct signal_struct {
4881da177e4SLinus Torvalds 	atomic_t		count;
4891da177e4SLinus Torvalds 	atomic_t		live;
4901da177e4SLinus Torvalds 
4911da177e4SLinus Torvalds 	wait_queue_head_t	wait_chldexit;	/* for wait4() */
4921da177e4SLinus Torvalds 
4931da177e4SLinus Torvalds 	/* current thread group signal load-balancing target: */
49436c8b586SIngo Molnar 	struct task_struct	*curr_target;
4951da177e4SLinus Torvalds 
4961da177e4SLinus Torvalds 	/* shared signal handling: */
4971da177e4SLinus Torvalds 	struct sigpending	shared_pending;
4981da177e4SLinus Torvalds 
4991da177e4SLinus Torvalds 	/* thread group exit support */
5001da177e4SLinus Torvalds 	int			group_exit_code;
5011da177e4SLinus Torvalds 	/* overloaded:
5021da177e4SLinus Torvalds 	 * - notify group_exit_task when ->count is equal to notify_count
5031da177e4SLinus Torvalds 	 * - everyone except group_exit_task is stopped during signal delivery
5041da177e4SLinus Torvalds 	 *   of fatal signals, group_exit_task processes the signal.
5051da177e4SLinus Torvalds 	 */
5061da177e4SLinus Torvalds 	int			notify_count;
50707dd20e0SRichard Kennedy 	struct task_struct	*group_exit_task;
5081da177e4SLinus Torvalds 
5091da177e4SLinus Torvalds 	/* thread group stop support, overloads group_exit_code too */
5101da177e4SLinus Torvalds 	int			group_stop_count;
5111da177e4SLinus Torvalds 	unsigned int		flags; /* see SIGNAL_* flags below */
5121da177e4SLinus Torvalds 
5131da177e4SLinus Torvalds 	/* POSIX.1b Interval Timers */
5141da177e4SLinus Torvalds 	struct list_head posix_timers;
5151da177e4SLinus Torvalds 
5161da177e4SLinus Torvalds 	/* ITIMER_REAL timer for the process */
5172ff678b8SThomas Gleixner 	struct hrtimer real_timer;
518fea9d175SOleg Nesterov 	struct pid *leader_pid;
5192ff678b8SThomas Gleixner 	ktime_t it_real_incr;
5201da177e4SLinus Torvalds 
5211da177e4SLinus Torvalds 	/* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
5221da177e4SLinus Torvalds 	cputime_t it_prof_expires, it_virt_expires;
5231da177e4SLinus Torvalds 	cputime_t it_prof_incr, it_virt_incr;
5241da177e4SLinus Torvalds 
525f06febc9SFrank Mayhar 	/*
526f06febc9SFrank Mayhar 	 * Thread group totals for process CPU clocks.
527f06febc9SFrank Mayhar 	 * See thread_group_cputime(), et al, for details.
528f06febc9SFrank Mayhar 	 */
529f06febc9SFrank Mayhar 	struct thread_group_cputime cputime;
530f06febc9SFrank Mayhar 
531f06febc9SFrank Mayhar 	/* Earliest-expiration cache. */
532f06febc9SFrank Mayhar 	struct task_cputime cputime_expires;
533f06febc9SFrank Mayhar 
534f06febc9SFrank Mayhar 	struct list_head cpu_timers[3];
535f06febc9SFrank Mayhar 
5361da177e4SLinus Torvalds 	/* job control IDs */
5379a2e7057SPavel Emelyanov 
5389a2e7057SPavel Emelyanov 	/*
5399a2e7057SPavel Emelyanov 	 * pgrp and session fields are deprecated.
5409a2e7057SPavel Emelyanov 	 * use the task_session_Xnr and task_pgrp_Xnr routines below
5419a2e7057SPavel Emelyanov 	 */
5429a2e7057SPavel Emelyanov 
5439a2e7057SPavel Emelyanov 	union {
5449a2e7057SPavel Emelyanov 		pid_t pgrp __deprecated;
5459a2e7057SPavel Emelyanov 		pid_t __pgrp;
5469a2e7057SPavel Emelyanov 	};
5479a2e7057SPavel Emelyanov 
548ab521dc0SEric W. Biederman 	struct pid *tty_old_pgrp;
5491ec320afSCedric Le Goater 
5501ec320afSCedric Le Goater 	union {
5511ec320afSCedric Le Goater 		pid_t session __deprecated;
5521ec320afSCedric Le Goater 		pid_t __session;
5531ec320afSCedric Le Goater 	};
5541ec320afSCedric Le Goater 
5551da177e4SLinus Torvalds 	/* boolean value for session group leader */
5561da177e4SLinus Torvalds 	int leader;
5571da177e4SLinus Torvalds 
5581da177e4SLinus Torvalds 	struct tty_struct *tty; /* NULL if no tty */
5591da177e4SLinus Torvalds 
5601da177e4SLinus Torvalds 	/*
5611da177e4SLinus Torvalds 	 * Cumulative resource counters for dead threads in the group,
5621da177e4SLinus Torvalds 	 * and for reaped dead child processes forked by this group.
5631da177e4SLinus Torvalds 	 * Live threads maintain their own counters and add to these
5641da177e4SLinus Torvalds 	 * in __exit_signal, except for the group leader.
5651da177e4SLinus Torvalds 	 */
566f06febc9SFrank Mayhar 	cputime_t cutime, cstime;
5679ac52315SLaurent Vivier 	cputime_t gtime;
5689ac52315SLaurent Vivier 	cputime_t cgtime;
5691da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
5701da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
5716eaeeabaSEric Dumazet 	unsigned long inblock, oublock, cinblock, coublock;
572940389b8SAndrea Righi 	struct task_io_accounting ioac;
5731da177e4SLinus Torvalds 
5741da177e4SLinus Torvalds 	/*
5751da177e4SLinus Torvalds 	 * We don't bother to synchronize most readers of this at all,
5761da177e4SLinus Torvalds 	 * because there is no reader checking a limit that actually needs
5771da177e4SLinus Torvalds 	 * to get both rlim_cur and rlim_max atomically, and either one
5781da177e4SLinus Torvalds 	 * alone is a single word that can safely be read normally.
5791da177e4SLinus Torvalds 	 * getrlimit/setrlimit use task_lock(current->group_leader) to
5801da177e4SLinus Torvalds 	 * protect this instead of the siglock, because they really
5811da177e4SLinus Torvalds 	 * have no need to disable irqs.
5821da177e4SLinus Torvalds 	 */
5831da177e4SLinus Torvalds 	struct rlimit rlim[RLIM_NLIMITS];
5841da177e4SLinus Torvalds 
5850e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT
5860e464814SKaiGai Kohei 	struct pacct_struct pacct;	/* per-process accounting information */
5870e464814SKaiGai Kohei #endif
588ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS
589ad4ecbcbSShailabh Nagar 	struct taskstats *stats;
590ad4ecbcbSShailabh Nagar #endif
591522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT
592522ed776SMiloslav Trmac 	unsigned audit_tty;
593522ed776SMiloslav Trmac 	struct tty_audit_buf *tty_audit_buf;
594522ed776SMiloslav Trmac #endif
5951da177e4SLinus Torvalds };
5961da177e4SLinus Torvalds 
5974866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */
5984866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
5994866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW
6004866cde0SNick Piggin #endif
6014866cde0SNick Piggin 
6021da177e4SLinus Torvalds /*
6031da177e4SLinus Torvalds  * Bits in flags field of signal_struct.
6041da177e4SLinus Torvalds  */
6051da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED	0x00000001 /* job control stop in effect */
6061da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED	0x00000002 /* stop signal dequeued */
6071da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED	0x00000004 /* SIGCONT since WCONTINUED reap */
6081da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT	0x00000008 /* group exit in progress */
609e4420551SOleg Nesterov /*
610e4420551SOleg Nesterov  * Pending notifications to parent.
611e4420551SOleg Nesterov  */
612e4420551SOleg Nesterov #define SIGNAL_CLD_STOPPED	0x00000010
613e4420551SOleg Nesterov #define SIGNAL_CLD_CONTINUED	0x00000020
614e4420551SOleg Nesterov #define SIGNAL_CLD_MASK		(SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
6151da177e4SLinus Torvalds 
616fae5fa44SOleg Nesterov #define SIGNAL_UNKILLABLE	0x00000040 /* for init: ignore fatal signals */
617fae5fa44SOleg Nesterov 
618ed5d2cacSOleg Nesterov /* If true, all threads except ->group_exit_task have pending SIGKILL */
619ed5d2cacSOleg Nesterov static inline int signal_group_exit(const struct signal_struct *sig)
620ed5d2cacSOleg Nesterov {
621ed5d2cacSOleg Nesterov 	return	(sig->flags & SIGNAL_GROUP_EXIT) ||
622ed5d2cacSOleg Nesterov 		(sig->group_exit_task != NULL);
623ed5d2cacSOleg Nesterov }
624ed5d2cacSOleg Nesterov 
6251da177e4SLinus Torvalds /*
6261da177e4SLinus Torvalds  * Some day this will be a full-fledged user tracking system..
6271da177e4SLinus Torvalds  */
6281da177e4SLinus Torvalds struct user_struct {
6291da177e4SLinus Torvalds 	atomic_t __count;	/* reference count */
6301da177e4SLinus Torvalds 	atomic_t processes;	/* How many processes does this user have? */
6311da177e4SLinus Torvalds 	atomic_t files;		/* How many open files does this user have? */
6321da177e4SLinus Torvalds 	atomic_t sigpending;	/* How many pending signals does this user have? */
6332d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
6340eeca283SRobert Love 	atomic_t inotify_watches; /* How many inotify watches does this user have? */
6350eeca283SRobert Love 	atomic_t inotify_devs;	/* How many inotify devs does this user have opened? */
6360eeca283SRobert Love #endif
6377ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
6387ef9964eSDavide Libenzi 	atomic_t epoll_devs;	/* The number of epoll descriptors currently open */
6397ef9964eSDavide Libenzi 	atomic_t epoll_watches;	/* The number of file descriptors currently watched */
6407ef9964eSDavide Libenzi #endif
641970a8645SAlexey Dobriyan #ifdef CONFIG_POSIX_MQUEUE
6421da177e4SLinus Torvalds 	/* protected by mq_lock	*/
6431da177e4SLinus Torvalds 	unsigned long mq_bytes;	/* How many bytes can be allocated to mqueue? */
644970a8645SAlexey Dobriyan #endif
6451da177e4SLinus Torvalds 	unsigned long locked_shm; /* How many pages of mlocked shm ? */
6461da177e4SLinus Torvalds 
6471da177e4SLinus Torvalds #ifdef CONFIG_KEYS
6481da177e4SLinus Torvalds 	struct key *uid_keyring;	/* UID specific keyring */
6491da177e4SLinus Torvalds 	struct key *session_keyring;	/* UID's default session keyring */
6501da177e4SLinus Torvalds #endif
6511da177e4SLinus Torvalds 
6521da177e4SLinus Torvalds 	/* Hash table maintenance information */
653735de223SPavel Emelyanov 	struct hlist_node uidhash_node;
6541da177e4SLinus Torvalds 	uid_t uid;
65518b6e041SSerge Hallyn 	struct user_namespace *user_ns;
65624e377a8SSrivatsa Vaddagiri 
657052f1dc7SPeter Zijlstra #ifdef CONFIG_USER_SCHED
6584cf86d77SIngo Molnar 	struct task_group *tg;
659b1a8c172SDhaval Giani #ifdef CONFIG_SYSFS
660eb41d946SKay Sievers 	struct kobject kobj;
6615cb350baSDhaval Giani 	struct work_struct work;
66224e377a8SSrivatsa Vaddagiri #endif
663b1a8c172SDhaval Giani #endif
6641da177e4SLinus Torvalds };
6651da177e4SLinus Torvalds 
666eb41d946SKay Sievers extern int uids_sysfs_init(void);
6675cb350baSDhaval Giani 
6681da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t);
6691da177e4SLinus Torvalds 
6701da177e4SLinus Torvalds extern struct user_struct root_user;
6711da177e4SLinus Torvalds #define INIT_USER (&root_user)
6721da177e4SLinus Torvalds 
673b6dff3ecSDavid Howells 
6741da177e4SLinus Torvalds struct backing_dev_info;
6751da177e4SLinus Torvalds struct reclaim_state;
6761da177e4SLinus Torvalds 
67752f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
6781da177e4SLinus Torvalds struct sched_info {
6791da177e4SLinus Torvalds 	/* cumulative counters */
6802d72376bSIngo Molnar 	unsigned long pcount;	      /* # of times run on this cpu */
6819c2c4802SKen Chen 	unsigned long long run_delay; /* time spent waiting on a runqueue */
6821da177e4SLinus Torvalds 
6831da177e4SLinus Torvalds 	/* timestamps */
684172ba844SBalbir Singh 	unsigned long long last_arrival,/* when we last ran on a cpu */
6851da177e4SLinus Torvalds 			   last_queued;	/* when we were last queued to run */
686b8efb561SIngo Molnar #ifdef CONFIG_SCHEDSTATS
687b8efb561SIngo Molnar 	/* BKL stats */
688480b9434SKen Chen 	unsigned int bkl_count;
689b8efb561SIngo Molnar #endif
6901da177e4SLinus Torvalds };
69152f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
6921da177e4SLinus Torvalds 
693ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT
694ca74e92bSShailabh Nagar struct task_delay_info {
695ca74e92bSShailabh Nagar 	spinlock_t	lock;
696ca74e92bSShailabh Nagar 	unsigned int	flags;	/* Private per-task flags */
697ca74e92bSShailabh Nagar 
698ca74e92bSShailabh Nagar 	/* For each stat XXX, add following, aligned appropriately
699ca74e92bSShailabh Nagar 	 *
700ca74e92bSShailabh Nagar 	 * struct timespec XXX_start, XXX_end;
701ca74e92bSShailabh Nagar 	 * u64 XXX_delay;
702ca74e92bSShailabh Nagar 	 * u32 XXX_count;
703ca74e92bSShailabh Nagar 	 *
704ca74e92bSShailabh Nagar 	 * Atomicity of updates to XXX_delay, XXX_count protected by
705ca74e92bSShailabh Nagar 	 * single lock above (split into XXX_lock if contention is an issue).
706ca74e92bSShailabh Nagar 	 */
7070ff92245SShailabh Nagar 
7080ff92245SShailabh Nagar 	/*
7090ff92245SShailabh Nagar 	 * XXX_count is incremented on every XXX operation, the delay
7100ff92245SShailabh Nagar 	 * associated with the operation is added to XXX_delay.
7110ff92245SShailabh Nagar 	 * XXX_delay contains the accumulated delay time in nanoseconds.
7120ff92245SShailabh Nagar 	 */
7130ff92245SShailabh Nagar 	struct timespec blkio_start, blkio_end;	/* Shared by blkio, swapin */
7140ff92245SShailabh Nagar 	u64 blkio_delay;	/* wait for sync block io completion */
7150ff92245SShailabh Nagar 	u64 swapin_delay;	/* wait for swapin block io completion */
7160ff92245SShailabh Nagar 	u32 blkio_count;	/* total count of the number of sync block */
7170ff92245SShailabh Nagar 				/* io operations performed */
7180ff92245SShailabh Nagar 	u32 swapin_count;	/* total count of the number of swapin block */
7190ff92245SShailabh Nagar 				/* io operations performed */
720873b4771SKeika Kobayashi 
721873b4771SKeika Kobayashi 	struct timespec freepages_start, freepages_end;
722873b4771SKeika Kobayashi 	u64 freepages_delay;	/* wait for memory reclaim */
723873b4771SKeika Kobayashi 	u32 freepages_count;	/* total count of memory reclaim */
724ca74e92bSShailabh Nagar };
72552f17b6cSChandra Seetharaman #endif	/* CONFIG_TASK_DELAY_ACCT */
72652f17b6cSChandra Seetharaman 
72752f17b6cSChandra Seetharaman static inline int sched_info_on(void)
72852f17b6cSChandra Seetharaman {
72952f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS
73052f17b6cSChandra Seetharaman 	return 1;
73152f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT)
73252f17b6cSChandra Seetharaman 	extern int delayacct_on;
73352f17b6cSChandra Seetharaman 	return delayacct_on;
73452f17b6cSChandra Seetharaman #else
73552f17b6cSChandra Seetharaman 	return 0;
736ca74e92bSShailabh Nagar #endif
73752f17b6cSChandra Seetharaman }
738ca74e92bSShailabh Nagar 
739d15bcfdbSIngo Molnar enum cpu_idle_type {
740d15bcfdbSIngo Molnar 	CPU_IDLE,
741d15bcfdbSIngo Molnar 	CPU_NOT_IDLE,
742d15bcfdbSIngo Molnar 	CPU_NEWLY_IDLE,
743d15bcfdbSIngo Molnar 	CPU_MAX_IDLE_TYPES
7441da177e4SLinus Torvalds };
7451da177e4SLinus Torvalds 
7461da177e4SLinus Torvalds /*
7471da177e4SLinus Torvalds  * sched-domains (multiprocessor balancing) declarations:
7481da177e4SLinus Torvalds  */
7499aa7b369SIngo Molnar 
7509aa7b369SIngo Molnar /*
7519aa7b369SIngo Molnar  * Increase resolution of nice-level calculations:
7529aa7b369SIngo Molnar  */
7539aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT	10
7549aa7b369SIngo Molnar #define SCHED_LOAD_SCALE	(1L << SCHED_LOAD_SHIFT)
7559aa7b369SIngo Molnar 
756f8700df7SSuresh Siddha #define SCHED_LOAD_SCALE_FUZZ	SCHED_LOAD_SCALE
7571da177e4SLinus Torvalds 
7582dd73a4fSPeter Williams #ifdef CONFIG_SMP
7591da177e4SLinus Torvalds #define SD_LOAD_BALANCE		1	/* Do load balancing on this domain. */
7601da177e4SLinus Torvalds #define SD_BALANCE_NEWIDLE	2	/* Balance when about to become idle */
7611da177e4SLinus Torvalds #define SD_BALANCE_EXEC		4	/* Balance on exec */
762147cbb4bSNick Piggin #define SD_BALANCE_FORK		8	/* Balance on fork, clone */
763147cbb4bSNick Piggin #define SD_WAKE_IDLE		16	/* Wake to idle CPU on task wakeup */
764147cbb4bSNick Piggin #define SD_WAKE_AFFINE		32	/* Wake task to waking CPU */
765147cbb4bSNick Piggin #define SD_WAKE_BALANCE		64	/* Perform balancing at task wakeup */
766147cbb4bSNick Piggin #define SD_SHARE_CPUPOWER	128	/* Domain members share cpu power */
7675c45bf27SSiddha, Suresh B #define SD_POWERSAVINGS_BALANCE	256	/* Balance for power savings */
76889c4710eSSiddha, Suresh B #define SD_SHARE_PKG_RESOURCES	512	/* Domain members share cpu pkg resources */
76908c183f3SChristoph Lameter #define SD_SERIALIZE		1024	/* Only a single load balancing instance */
7701d3504fcSHidetoshi Seto #define SD_WAKE_IDLE_FAR	2048	/* Gain latency sacrificing cache hit */
7715c45bf27SSiddha, Suresh B 
772afb8a9b7SGautham R Shenoy enum powersavings_balance_level {
773afb8a9b7SGautham R Shenoy 	POWERSAVINGS_BALANCE_NONE = 0,  /* No power saving load balance */
774afb8a9b7SGautham R Shenoy 	POWERSAVINGS_BALANCE_BASIC,	/* Fill one thread/core/package
775afb8a9b7SGautham R Shenoy 					 * first for long running threads
776afb8a9b7SGautham R Shenoy 					 */
777afb8a9b7SGautham R Shenoy 	POWERSAVINGS_BALANCE_WAKEUP,	/* Also bias task wakeups to semi-idle
778afb8a9b7SGautham R Shenoy 					 * cpu package for power savings
779afb8a9b7SGautham R Shenoy 					 */
780afb8a9b7SGautham R Shenoy 	MAX_POWERSAVINGS_BALANCE_LEVELS
781afb8a9b7SGautham R Shenoy };
78289c4710eSSiddha, Suresh B 
783716707b2SVaidyanathan Srinivasan extern int sched_mc_power_savings, sched_smt_power_savings;
78489c4710eSSiddha, Suresh B 
785716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_mc_power(void)
786716707b2SVaidyanathan Srinivasan {
787716707b2SVaidyanathan Srinivasan 	if (sched_smt_power_savings)
788716707b2SVaidyanathan Srinivasan 		return SD_POWERSAVINGS_BALANCE;
7895c45bf27SSiddha, Suresh B 
790716707b2SVaidyanathan Srinivasan 	return 0;
791716707b2SVaidyanathan Srinivasan }
792716707b2SVaidyanathan Srinivasan 
793716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_package_power(void)
794716707b2SVaidyanathan Srinivasan {
795716707b2SVaidyanathan Srinivasan 	if (sched_mc_power_savings | sched_smt_power_savings)
796716707b2SVaidyanathan Srinivasan 		return SD_POWERSAVINGS_BALANCE;
797716707b2SVaidyanathan Srinivasan 
798716707b2SVaidyanathan Srinivasan 	return 0;
799716707b2SVaidyanathan Srinivasan }
8001da177e4SLinus Torvalds 
801100fdaeeSVaidyanathan Srinivasan /*
802100fdaeeSVaidyanathan Srinivasan  * Optimise SD flags for power savings:
803100fdaeeSVaidyanathan Srinivasan  * SD_BALANCE_NEWIDLE helps agressive task consolidation and power savings.
804100fdaeeSVaidyanathan Srinivasan  * Keep default SD flags if sched_{smt,mc}_power_saving=0
805100fdaeeSVaidyanathan Srinivasan  */
806100fdaeeSVaidyanathan Srinivasan 
807100fdaeeSVaidyanathan Srinivasan static inline int sd_power_saving_flags(void)
808100fdaeeSVaidyanathan Srinivasan {
809100fdaeeSVaidyanathan Srinivasan 	if (sched_mc_power_savings | sched_smt_power_savings)
810100fdaeeSVaidyanathan Srinivasan 		return SD_BALANCE_NEWIDLE;
811100fdaeeSVaidyanathan Srinivasan 
812100fdaeeSVaidyanathan Srinivasan 	return 0;
813100fdaeeSVaidyanathan Srinivasan }
8141da177e4SLinus Torvalds 
8151da177e4SLinus Torvalds struct sched_group {
8161da177e4SLinus Torvalds 	struct sched_group *next;	/* Must be a circular list */
8171da177e4SLinus Torvalds 
8181da177e4SLinus Torvalds 	/*
8191da177e4SLinus Torvalds 	 * CPU power of this group, SCHED_LOAD_SCALE being max power for a
8201da177e4SLinus Torvalds 	 * single CPU. This is read only (except for setup, hotplug CPU).
8215517d86bSEric Dumazet 	 * Note : Never change cpu_power without recompute its reciprocal
8221da177e4SLinus Torvalds 	 */
8235517d86bSEric Dumazet 	unsigned int __cpu_power;
8245517d86bSEric Dumazet 	/*
8255517d86bSEric Dumazet 	 * reciprocal value of cpu_power to avoid expensive divides
8265517d86bSEric Dumazet 	 * (see include/linux/reciprocal_div.h)
8275517d86bSEric Dumazet 	 */
8285517d86bSEric Dumazet 	u32 reciprocal_cpu_power;
8296c99e9adSRusty Russell 
8306c99e9adSRusty Russell 	unsigned long cpumask[];
8311da177e4SLinus Torvalds };
8321da177e4SLinus Torvalds 
833758b2cdcSRusty Russell static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
834758b2cdcSRusty Russell {
8356c99e9adSRusty Russell 	return to_cpumask(sg->cpumask);
836758b2cdcSRusty Russell }
837758b2cdcSRusty Russell 
8381d3504fcSHidetoshi Seto enum sched_domain_level {
8391d3504fcSHidetoshi Seto 	SD_LV_NONE = 0,
8401d3504fcSHidetoshi Seto 	SD_LV_SIBLING,
8411d3504fcSHidetoshi Seto 	SD_LV_MC,
8421d3504fcSHidetoshi Seto 	SD_LV_CPU,
8431d3504fcSHidetoshi Seto 	SD_LV_NODE,
8441d3504fcSHidetoshi Seto 	SD_LV_ALLNODES,
8451d3504fcSHidetoshi Seto 	SD_LV_MAX
8461d3504fcSHidetoshi Seto };
8471d3504fcSHidetoshi Seto 
8481d3504fcSHidetoshi Seto struct sched_domain_attr {
8491d3504fcSHidetoshi Seto 	int relax_domain_level;
8501d3504fcSHidetoshi Seto };
8511d3504fcSHidetoshi Seto 
8521d3504fcSHidetoshi Seto #define SD_ATTR_INIT	(struct sched_domain_attr) {	\
8531d3504fcSHidetoshi Seto 	.relax_domain_level = -1,			\
8541d3504fcSHidetoshi Seto }
8551d3504fcSHidetoshi Seto 
8561da177e4SLinus Torvalds struct sched_domain {
8571da177e4SLinus Torvalds 	/* These fields must be setup */
8581da177e4SLinus Torvalds 	struct sched_domain *parent;	/* top domain must be null terminated */
8591a848870SSiddha, Suresh B 	struct sched_domain *child;	/* bottom domain must be null terminated */
8601da177e4SLinus Torvalds 	struct sched_group *groups;	/* the balancing groups of the domain */
8611da177e4SLinus Torvalds 	unsigned long min_interval;	/* Minimum balance interval ms */
8621da177e4SLinus Torvalds 	unsigned long max_interval;	/* Maximum balance interval ms */
8631da177e4SLinus Torvalds 	unsigned int busy_factor;	/* less balancing by factor if busy */
8641da177e4SLinus Torvalds 	unsigned int imbalance_pct;	/* No balance until over watermark */
8651da177e4SLinus Torvalds 	unsigned int cache_nice_tries;	/* Leave cache hot tasks for # tries */
8667897986bSNick Piggin 	unsigned int busy_idx;
8677897986bSNick Piggin 	unsigned int idle_idx;
8687897986bSNick Piggin 	unsigned int newidle_idx;
8697897986bSNick Piggin 	unsigned int wake_idx;
870147cbb4bSNick Piggin 	unsigned int forkexec_idx;
8711da177e4SLinus Torvalds 	int flags;			/* See SD_* */
8721d3504fcSHidetoshi Seto 	enum sched_domain_level level;
8731da177e4SLinus Torvalds 
8741da177e4SLinus Torvalds 	/* Runtime fields. */
8751da177e4SLinus Torvalds 	unsigned long last_balance;	/* init to jiffies. units in jiffies */
8761da177e4SLinus Torvalds 	unsigned int balance_interval;	/* initialise to 1. units in ms. */
8771da177e4SLinus Torvalds 	unsigned int nr_balance_failed; /* initialise to 0 */
8781da177e4SLinus Torvalds 
8792398f2c6SPeter Zijlstra 	u64 last_update;
8802398f2c6SPeter Zijlstra 
8811da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS
8821da177e4SLinus Torvalds 	/* load_balance() stats */
883480b9434SKen Chen 	unsigned int lb_count[CPU_MAX_IDLE_TYPES];
884480b9434SKen Chen 	unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
885480b9434SKen Chen 	unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
886480b9434SKen Chen 	unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
887480b9434SKen Chen 	unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
888480b9434SKen Chen 	unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
889480b9434SKen Chen 	unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
890480b9434SKen Chen 	unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
8911da177e4SLinus Torvalds 
8921da177e4SLinus Torvalds 	/* Active load balancing */
893480b9434SKen Chen 	unsigned int alb_count;
894480b9434SKen Chen 	unsigned int alb_failed;
895480b9434SKen Chen 	unsigned int alb_pushed;
8961da177e4SLinus Torvalds 
89768767a0aSNick Piggin 	/* SD_BALANCE_EXEC stats */
898480b9434SKen Chen 	unsigned int sbe_count;
899480b9434SKen Chen 	unsigned int sbe_balanced;
900480b9434SKen Chen 	unsigned int sbe_pushed;
9011da177e4SLinus Torvalds 
90268767a0aSNick Piggin 	/* SD_BALANCE_FORK stats */
903480b9434SKen Chen 	unsigned int sbf_count;
904480b9434SKen Chen 	unsigned int sbf_balanced;
905480b9434SKen Chen 	unsigned int sbf_pushed;
90668767a0aSNick Piggin 
9071da177e4SLinus Torvalds 	/* try_to_wake_up() stats */
908480b9434SKen Chen 	unsigned int ttwu_wake_remote;
909480b9434SKen Chen 	unsigned int ttwu_move_affine;
910480b9434SKen Chen 	unsigned int ttwu_move_balance;
9111da177e4SLinus Torvalds #endif
912a5d8c348SIngo Molnar #ifdef CONFIG_SCHED_DEBUG
913a5d8c348SIngo Molnar 	char *name;
914a5d8c348SIngo Molnar #endif
9156c99e9adSRusty Russell 
9166c99e9adSRusty Russell 	/* span of all CPUs in this domain */
9176c99e9adSRusty Russell 	unsigned long span[];
9181da177e4SLinus Torvalds };
9191da177e4SLinus Torvalds 
920758b2cdcSRusty Russell static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
921758b2cdcSRusty Russell {
9226c99e9adSRusty Russell 	return to_cpumask(sd->span);
923758b2cdcSRusty Russell }
924758b2cdcSRusty Russell 
92596f874e2SRusty Russell extern void partition_sched_domains(int ndoms_new, struct cpumask *doms_new,
9261d3504fcSHidetoshi Seto 				    struct sched_domain_attr *dattr_new);
927029190c5SPaul Jackson 
92806aaf76aSIngo Molnar /* Test a flag in parent sched domain */
92906aaf76aSIngo Molnar static inline int test_sd_parent(struct sched_domain *sd, int flag)
93006aaf76aSIngo Molnar {
93106aaf76aSIngo Molnar 	if (sd->parent && (sd->parent->flags & flag))
93206aaf76aSIngo Molnar 		return 1;
93306aaf76aSIngo Molnar 
93406aaf76aSIngo Molnar 	return 0;
93506aaf76aSIngo Molnar }
93606aaf76aSIngo Molnar 
9371b427c15SIngo Molnar #else /* CONFIG_SMP */
9381b427c15SIngo Molnar 
9391b427c15SIngo Molnar struct sched_domain_attr;
9401b427c15SIngo Molnar 
9411b427c15SIngo Molnar static inline void
94296f874e2SRusty Russell partition_sched_domains(int ndoms_new, struct cpumask *doms_new,
9431b427c15SIngo Molnar 			struct sched_domain_attr *dattr_new)
9441b427c15SIngo Molnar {
9451b427c15SIngo Molnar }
9461b427c15SIngo Molnar #endif	/* !CONFIG_SMP */
9471da177e4SLinus Torvalds 
9481da177e4SLinus Torvalds struct io_context;			/* See blkdev.h */
9491da177e4SLinus Torvalds 
9501da177e4SLinus Torvalds 
951383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
95236c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t);
953383f2835SChen, Kenneth W #else
954383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { }
955383f2835SChen, Kenneth W #endif
9561da177e4SLinus Torvalds 
9571da177e4SLinus Torvalds struct audit_context;		/* See audit.c */
9581da177e4SLinus Torvalds struct mempolicy;
959b92ce558SJens Axboe struct pipe_inode_info;
9604865ecf1SSerge E. Hallyn struct uts_namespace;
9611da177e4SLinus Torvalds 
96220b8a59fSIngo Molnar struct rq;
96320b8a59fSIngo Molnar struct sched_domain;
96420b8a59fSIngo Molnar 
96520b8a59fSIngo Molnar struct sched_class {
9665522d5d5SIngo Molnar 	const struct sched_class *next;
96720b8a59fSIngo Molnar 
968fd390f6aSIngo Molnar 	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup);
969f02231e5SIngo Molnar 	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep);
9704530d7abSDmitry Adamushko 	void (*yield_task) (struct rq *rq);
97120b8a59fSIngo Molnar 
97215afe09bSPeter Zijlstra 	void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int sync);
97320b8a59fSIngo Molnar 
974fb8d4724SIngo Molnar 	struct task_struct * (*pick_next_task) (struct rq *rq);
97531ee529cSIngo Molnar 	void (*put_prev_task) (struct rq *rq, struct task_struct *p);
97620b8a59fSIngo Molnar 
977681f3e68SPeter Williams #ifdef CONFIG_SMP
9784ce72a2cSLi Zefan 	int  (*select_task_rq)(struct task_struct *p, int sync);
9794ce72a2cSLi Zefan 
98043010659SPeter Williams 	unsigned long (*load_balance) (struct rq *this_rq, int this_cpu,
981e1d1484fSPeter Williams 			struct rq *busiest, unsigned long max_load_move,
98220b8a59fSIngo Molnar 			struct sched_domain *sd, enum cpu_idle_type idle,
983a4ac01c3SPeter Williams 			int *all_pinned, int *this_best_prio);
98420b8a59fSIngo Molnar 
985e1d1484fSPeter Williams 	int (*move_one_task) (struct rq *this_rq, int this_cpu,
986e1d1484fSPeter Williams 			      struct rq *busiest, struct sched_domain *sd,
987e1d1484fSPeter Williams 			      enum cpu_idle_type idle);
9889a897c5aSSteven Rostedt 	void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
9899a897c5aSSteven Rostedt 	void (*post_schedule) (struct rq *this_rq);
9909a897c5aSSteven Rostedt 	void (*task_wake_up) (struct rq *this_rq, struct task_struct *task);
991e1d1484fSPeter Williams 
992cd8ba7cdSMike Travis 	void (*set_cpus_allowed)(struct task_struct *p,
99396f874e2SRusty Russell 				 const struct cpumask *newmask);
99457d885feSGregory Haskins 
9951f11eb6aSGregory Haskins 	void (*rq_online)(struct rq *rq);
9961f11eb6aSGregory Haskins 	void (*rq_offline)(struct rq *rq);
9974ce72a2cSLi Zefan #endif
9984ce72a2cSLi Zefan 
9994ce72a2cSLi Zefan 	void (*set_curr_task) (struct rq *rq);
10004ce72a2cSLi Zefan 	void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
10014ce72a2cSLi Zefan 	void (*task_new) (struct rq *rq, struct task_struct *p);
1002cb469845SSteven Rostedt 
1003cb469845SSteven Rostedt 	void (*switched_from) (struct rq *this_rq, struct task_struct *task,
1004cb469845SSteven Rostedt 			       int running);
1005cb469845SSteven Rostedt 	void (*switched_to) (struct rq *this_rq, struct task_struct *task,
1006cb469845SSteven Rostedt 			     int running);
1007cb469845SSteven Rostedt 	void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
1008cb469845SSteven Rostedt 			     int oldprio, int running);
1009810b3817SPeter Zijlstra 
1010810b3817SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED
1011810b3817SPeter Zijlstra 	void (*moved_group) (struct task_struct *p);
1012810b3817SPeter Zijlstra #endif
101320b8a59fSIngo Molnar };
101420b8a59fSIngo Molnar 
101520b8a59fSIngo Molnar struct load_weight {
101620b8a59fSIngo Molnar 	unsigned long weight, inv_weight;
101720b8a59fSIngo Molnar };
101820b8a59fSIngo Molnar 
101920b8a59fSIngo Molnar /*
102020b8a59fSIngo Molnar  * CFS stats for a schedulable entity (task, task-group etc)
102120b8a59fSIngo Molnar  *
102220b8a59fSIngo Molnar  * Current field usage histogram:
102320b8a59fSIngo Molnar  *
102420b8a59fSIngo Molnar  *     4 se->block_start
102520b8a59fSIngo Molnar  *     4 se->run_node
102620b8a59fSIngo Molnar  *     4 se->sleep_start
102720b8a59fSIngo Molnar  *     6 se->load.weight
102820b8a59fSIngo Molnar  */
102920b8a59fSIngo Molnar struct sched_entity {
103020b8a59fSIngo Molnar 	struct load_weight	load;		/* for load-balancing */
103120b8a59fSIngo Molnar 	struct rb_node		run_node;
10324a55bd5eSPeter Zijlstra 	struct list_head	group_node;
103320b8a59fSIngo Molnar 	unsigned int		on_rq;
103420b8a59fSIngo Molnar 
103520b8a59fSIngo Molnar 	u64			exec_start;
103694c18227SIngo Molnar 	u64			sum_exec_runtime;
1037e9acbff6SIngo Molnar 	u64			vruntime;
1038f6cf891cSIngo Molnar 	u64			prev_sum_exec_runtime;
103994c18227SIngo Molnar 
10404ae7d5ceSIngo Molnar 	u64			last_wakeup;
10414ae7d5ceSIngo Molnar 	u64			avg_overlap;
10424ae7d5ceSIngo Molnar 
104394c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS
104494c18227SIngo Molnar 	u64			wait_start;
104594c18227SIngo Molnar 	u64			wait_max;
10466d082592SArjan van de Ven 	u64			wait_count;
10476d082592SArjan van de Ven 	u64			wait_sum;
104894c18227SIngo Molnar 
104994c18227SIngo Molnar 	u64			sleep_start;
105020b8a59fSIngo Molnar 	u64			sleep_max;
105194c18227SIngo Molnar 	s64			sum_sleep_runtime;
105294c18227SIngo Molnar 
105394c18227SIngo Molnar 	u64			block_start;
105420b8a59fSIngo Molnar 	u64			block_max;
105520b8a59fSIngo Molnar 	u64			exec_max;
1056eba1ed4bSIngo Molnar 	u64			slice_max;
1057cc367732SIngo Molnar 
1058cc367732SIngo Molnar 	u64			nr_migrations;
1059cc367732SIngo Molnar 	u64			nr_migrations_cold;
1060cc367732SIngo Molnar 	u64			nr_failed_migrations_affine;
1061cc367732SIngo Molnar 	u64			nr_failed_migrations_running;
1062cc367732SIngo Molnar 	u64			nr_failed_migrations_hot;
1063cc367732SIngo Molnar 	u64			nr_forced_migrations;
1064cc367732SIngo Molnar 	u64			nr_forced2_migrations;
1065cc367732SIngo Molnar 
1066cc367732SIngo Molnar 	u64			nr_wakeups;
1067cc367732SIngo Molnar 	u64			nr_wakeups_sync;
1068cc367732SIngo Molnar 	u64			nr_wakeups_migrate;
1069cc367732SIngo Molnar 	u64			nr_wakeups_local;
1070cc367732SIngo Molnar 	u64			nr_wakeups_remote;
1071cc367732SIngo Molnar 	u64			nr_wakeups_affine;
1072cc367732SIngo Molnar 	u64			nr_wakeups_affine_attempts;
1073cc367732SIngo Molnar 	u64			nr_wakeups_passive;
1074cc367732SIngo Molnar 	u64			nr_wakeups_idle;
107594c18227SIngo Molnar #endif
107694c18227SIngo Molnar 
107720b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED
107820b8a59fSIngo Molnar 	struct sched_entity	*parent;
107920b8a59fSIngo Molnar 	/* rq on which this entity is (to be) queued: */
108020b8a59fSIngo Molnar 	struct cfs_rq		*cfs_rq;
108120b8a59fSIngo Molnar 	/* rq "owned" by this entity/group: */
108220b8a59fSIngo Molnar 	struct cfs_rq		*my_q;
108320b8a59fSIngo Molnar #endif
108420b8a59fSIngo Molnar };
108570b97a7fSIngo Molnar 
1086fa717060SPeter Zijlstra struct sched_rt_entity {
1087fa717060SPeter Zijlstra 	struct list_head run_list;
108878f2c7dbSPeter Zijlstra 	unsigned long timeout;
1089bee367edSRichard Kennedy 	unsigned int time_slice;
10906f505b16SPeter Zijlstra 	int nr_cpus_allowed;
10916f505b16SPeter Zijlstra 
109258d6c2d7SPeter Zijlstra 	struct sched_rt_entity *back;
1093052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED
10946f505b16SPeter Zijlstra 	struct sched_rt_entity	*parent;
10956f505b16SPeter Zijlstra 	/* rq on which this entity is (to be) queued: */
10966f505b16SPeter Zijlstra 	struct rt_rq		*rt_rq;
10976f505b16SPeter Zijlstra 	/* rq "owned" by this entity/group: */
10986f505b16SPeter Zijlstra 	struct rt_rq		*my_q;
10996f505b16SPeter Zijlstra #endif
1100fa717060SPeter Zijlstra };
1101fa717060SPeter Zijlstra 
11021da177e4SLinus Torvalds struct task_struct {
11031da177e4SLinus Torvalds 	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
1104f7e4217bSRoman Zippel 	void *stack;
11051da177e4SLinus Torvalds 	atomic_t usage;
110697dc32cdSWilliam Cohen 	unsigned int flags;	/* per process flags, defined below */
110797dc32cdSWilliam Cohen 	unsigned int ptrace;
11081da177e4SLinus Torvalds 
110936772092SPaolo 'Blaisorblade' Giarrusso 	int lock_depth;		/* BKL lock depth */
11101da177e4SLinus Torvalds 
11112dd73a4fSPeter Williams #ifdef CONFIG_SMP
11122dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW
11134866cde0SNick Piggin 	int oncpu;
11144866cde0SNick Piggin #endif
11152dd73a4fSPeter Williams #endif
111650e645a8SIngo Molnar 
1117b29739f9SIngo Molnar 	int prio, static_prio, normal_prio;
1118c7aceabaSRichard Kennedy 	unsigned int rt_priority;
11195522d5d5SIngo Molnar 	const struct sched_class *sched_class;
112020b8a59fSIngo Molnar 	struct sched_entity se;
1121fa717060SPeter Zijlstra 	struct sched_rt_entity rt;
11221da177e4SLinus Torvalds 
1123e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS
1124e107be36SAvi Kivity 	/* list of struct preempt_notifier: */
1125e107be36SAvi Kivity 	struct hlist_head preempt_notifiers;
1126e107be36SAvi Kivity #endif
1127e107be36SAvi Kivity 
112818796aa0SAlexey Dobriyan 	/*
112918796aa0SAlexey Dobriyan 	 * fpu_counter contains the number of consecutive context switches
113018796aa0SAlexey Dobriyan 	 * that the FPU is used. If this is over a threshold, the lazy fpu
113118796aa0SAlexey Dobriyan 	 * saving becomes unlazy to save the trap. This is an unsigned char
113218796aa0SAlexey Dobriyan 	 * so that after 256 times the counter wraps and the behavior turns
113318796aa0SAlexey Dobriyan 	 * lazy again; this to deal with bursty apps that only use FPU for
113418796aa0SAlexey Dobriyan 	 * a short time
113518796aa0SAlexey Dobriyan 	 */
113618796aa0SAlexey Dobriyan 	unsigned char fpu_counter;
113718796aa0SAlexey Dobriyan 	s8 oomkilladj; /* OOM kill score adjustment (bit shift). */
11386c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE
11392056a782SJens Axboe 	unsigned int btrace_seq;
11406c5c9341SAlexey Dobriyan #endif
11411da177e4SLinus Torvalds 
114297dc32cdSWilliam Cohen 	unsigned int policy;
11431da177e4SLinus Torvalds 	cpumask_t cpus_allowed;
11441da177e4SLinus Torvalds 
1145e260be67SPaul E. McKenney #ifdef CONFIG_PREEMPT_RCU
1146e260be67SPaul E. McKenney 	int rcu_read_lock_nesting;
1147e260be67SPaul E. McKenney 	int rcu_flipctr_idx;
1148e260be67SPaul E. McKenney #endif /* #ifdef CONFIG_PREEMPT_RCU */
1149e260be67SPaul E. McKenney 
115052f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
11511da177e4SLinus Torvalds 	struct sched_info sched_info;
11521da177e4SLinus Torvalds #endif
11531da177e4SLinus Torvalds 
11541da177e4SLinus Torvalds 	struct list_head tasks;
11551da177e4SLinus Torvalds 
11561da177e4SLinus Torvalds 	struct mm_struct *mm, *active_mm;
11571da177e4SLinus Torvalds 
11581da177e4SLinus Torvalds /* task state */
11591da177e4SLinus Torvalds 	struct linux_binfmt *binfmt;
116097dc32cdSWilliam Cohen 	int exit_state;
11611da177e4SLinus Torvalds 	int exit_code, exit_signal;
11621da177e4SLinus Torvalds 	int pdeath_signal;  /*  The signal sent when the parent dies  */
11631da177e4SLinus Torvalds 	/* ??? */
116497dc32cdSWilliam Cohen 	unsigned int personality;
11651da177e4SLinus Torvalds 	unsigned did_exec:1;
11661da177e4SLinus Torvalds 	pid_t pid;
11671da177e4SLinus Torvalds 	pid_t tgid;
11680a425405SArjan van de Ven 
11690a425405SArjan van de Ven #ifdef CONFIG_CC_STACKPROTECTOR
11700a425405SArjan van de Ven 	/* Canary value for the -fstack-protector gcc feature */
11710a425405SArjan van de Ven 	unsigned long stack_canary;
11720a425405SArjan van de Ven #endif
11731da177e4SLinus Torvalds 	/*
11741da177e4SLinus Torvalds 	 * pointers to (original) parent process, youngest child, younger sibling,
11751da177e4SLinus Torvalds 	 * older sibling, respectively.  (p->father can be replaced with
1176f470021aSRoland McGrath 	 * p->real_parent->pid)
11771da177e4SLinus Torvalds 	 */
1178f470021aSRoland McGrath 	struct task_struct *real_parent; /* real parent process */
1179f470021aSRoland McGrath 	struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports */
11801da177e4SLinus Torvalds 	/*
1181f470021aSRoland McGrath 	 * children/sibling forms the list of my natural children
11821da177e4SLinus Torvalds 	 */
11831da177e4SLinus Torvalds 	struct list_head children;	/* list of my children */
11841da177e4SLinus Torvalds 	struct list_head sibling;	/* linkage in my parent's children list */
11851da177e4SLinus Torvalds 	struct task_struct *group_leader;	/* threadgroup leader */
11861da177e4SLinus Torvalds 
1187f470021aSRoland McGrath 	/*
1188f470021aSRoland McGrath 	 * ptraced is the list of tasks this task is using ptrace on.
1189f470021aSRoland McGrath 	 * This includes both natural children and PTRACE_ATTACH targets.
1190f470021aSRoland McGrath 	 * p->ptrace_entry is p's link on the p->parent->ptraced list.
1191f470021aSRoland McGrath 	 */
1192f470021aSRoland McGrath 	struct list_head ptraced;
1193f470021aSRoland McGrath 	struct list_head ptrace_entry;
1194f470021aSRoland McGrath 
1195ca0002a1SMarkus Metzger #ifdef CONFIG_X86_PTRACE_BTS
1196ca0002a1SMarkus Metzger 	/*
1197ca0002a1SMarkus Metzger 	 * This is the tracer handle for the ptrace BTS extension.
1198ca0002a1SMarkus Metzger 	 * This field actually belongs to the ptracer task.
1199ca0002a1SMarkus Metzger 	 */
1200ca0002a1SMarkus Metzger 	struct bts_tracer *bts;
12016abb11aeSMarkus Metzger 	/*
12026abb11aeSMarkus Metzger 	 * The buffer to hold the BTS data.
12036abb11aeSMarkus Metzger 	 */
12046abb11aeSMarkus Metzger 	void *bts_buffer;
1205c2724775SMarkus Metzger 	size_t bts_size;
1206ca0002a1SMarkus Metzger #endif /* CONFIG_X86_PTRACE_BTS */
1207ca0002a1SMarkus Metzger 
12081da177e4SLinus Torvalds 	/* PID/PID hash table linkage. */
120992476d7fSEric W. Biederman 	struct pid_link pids[PIDTYPE_MAX];
121047e65328SOleg Nesterov 	struct list_head thread_group;
12111da177e4SLinus Torvalds 
12121da177e4SLinus Torvalds 	struct completion *vfork_done;		/* for vfork() */
12131da177e4SLinus Torvalds 	int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
12141da177e4SLinus Torvalds 	int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */
12151da177e4SLinus Torvalds 
1216c66f08beSMichael Neuling 	cputime_t utime, stime, utimescaled, stimescaled;
12179ac52315SLaurent Vivier 	cputime_t gtime;
12189301899bSBalbir Singh 	cputime_t prev_utime, prev_stime;
12191da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw; /* context switch counts */
1220924b42d5STomas Janousek 	struct timespec start_time; 		/* monotonic time */
1221924b42d5STomas Janousek 	struct timespec real_start_time;	/* boot based time */
12221da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
12231da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt;
12241da177e4SLinus Torvalds 
1225f06febc9SFrank Mayhar 	struct task_cputime cputime_expires;
12261da177e4SLinus Torvalds 	struct list_head cpu_timers[3];
12271da177e4SLinus Torvalds 
12281da177e4SLinus Torvalds /* process credentials */
12293b11a1deSDavid Howells 	const struct cred *real_cred;	/* objective and real subjective task
12303b11a1deSDavid Howells 					 * credentials (COW) */
12313b11a1deSDavid Howells 	const struct cred *cred;	/* effective (overridable) subjective task
12323b11a1deSDavid Howells 					 * credentials (COW) */
1233d84f4f99SDavid Howells 	struct mutex cred_exec_mutex;	/* execve vs ptrace cred calculation mutex */
1234b6dff3ecSDavid Howells 
123536772092SPaolo 'Blaisorblade' Giarrusso 	char comm[TASK_COMM_LEN]; /* executable name excluding path
123636772092SPaolo 'Blaisorblade' Giarrusso 				     - access with [gs]et_task_comm (which lock
123736772092SPaolo 'Blaisorblade' Giarrusso 				       it with task_lock())
123836772092SPaolo 'Blaisorblade' Giarrusso 				     - initialized normally by flush_old_exec */
12391da177e4SLinus Torvalds /* file system info */
12401da177e4SLinus Torvalds 	int link_count, total_link_count;
12413d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC
12421da177e4SLinus Torvalds /* ipc stuff */
12431da177e4SLinus Torvalds 	struct sysv_sem sysvsem;
12443d5b6fccSAlexey Dobriyan #endif
1245*e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
124682a1fcb9SIngo Molnar /* hung task detection */
124782a1fcb9SIngo Molnar 	unsigned long last_switch_timestamp;
124882a1fcb9SIngo Molnar 	unsigned long last_switch_count;
124982a1fcb9SIngo Molnar #endif
12501da177e4SLinus Torvalds /* CPU-specific state of this task */
12511da177e4SLinus Torvalds 	struct thread_struct thread;
12521da177e4SLinus Torvalds /* filesystem information */
12531da177e4SLinus Torvalds 	struct fs_struct *fs;
12541da177e4SLinus Torvalds /* open file information */
12551da177e4SLinus Torvalds 	struct files_struct *files;
12561651e14eSSerge E. Hallyn /* namespaces */
1257ab516013SSerge E. Hallyn 	struct nsproxy *nsproxy;
12581da177e4SLinus Torvalds /* signal handlers */
12591da177e4SLinus Torvalds 	struct signal_struct *signal;
12601da177e4SLinus Torvalds 	struct sighand_struct *sighand;
12611da177e4SLinus Torvalds 
12621da177e4SLinus Torvalds 	sigset_t blocked, real_blocked;
1263f3de272bSRoland McGrath 	sigset_t saved_sigmask;	/* restored if set_restore_sigmask() was used */
12641da177e4SLinus Torvalds 	struct sigpending pending;
12651da177e4SLinus Torvalds 
12661da177e4SLinus Torvalds 	unsigned long sas_ss_sp;
12671da177e4SLinus Torvalds 	size_t sas_ss_size;
12681da177e4SLinus Torvalds 	int (*notifier)(void *priv);
12691da177e4SLinus Torvalds 	void *notifier_data;
12701da177e4SLinus Torvalds 	sigset_t *notifier_mask;
12711da177e4SLinus Torvalds 	struct audit_context *audit_context;
1272bfef93a5SAl Viro #ifdef CONFIG_AUDITSYSCALL
1273bfef93a5SAl Viro 	uid_t loginuid;
12744746ec5bSEric Paris 	unsigned int sessionid;
1275bfef93a5SAl Viro #endif
12761da177e4SLinus Torvalds 	seccomp_t seccomp;
12771da177e4SLinus Torvalds 
12781da177e4SLinus Torvalds /* Thread group tracking */
12791da177e4SLinus Torvalds    	u32 parent_exec_id;
12801da177e4SLinus Torvalds    	u32 self_exec_id;
12811da177e4SLinus Torvalds /* Protection of (de-)allocation: mm, files, fs, tty, keyrings */
12821da177e4SLinus Torvalds 	spinlock_t alloc_lock;
12831da177e4SLinus Torvalds 
1284b29739f9SIngo Molnar 	/* Protection of the PI data structures: */
1285b29739f9SIngo Molnar 	spinlock_t pi_lock;
1286b29739f9SIngo Molnar 
128723f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
128823f78d4aSIngo Molnar 	/* PI waiters blocked on a rt_mutex held by this task */
128923f78d4aSIngo Molnar 	struct plist_head pi_waiters;
129023f78d4aSIngo Molnar 	/* Deadlock detection and priority inheritance handling */
129123f78d4aSIngo Molnar 	struct rt_mutex_waiter *pi_blocked_on;
129223f78d4aSIngo Molnar #endif
129323f78d4aSIngo Molnar 
1294408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES
1295408894eeSIngo Molnar 	/* mutex deadlock detection */
1296408894eeSIngo Molnar 	struct mutex_waiter *blocked_on;
1297408894eeSIngo Molnar #endif
1298de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS
1299de30a2b3SIngo Molnar 	unsigned int irq_events;
1300de30a2b3SIngo Molnar 	int hardirqs_enabled;
1301de30a2b3SIngo Molnar 	unsigned long hardirq_enable_ip;
1302de30a2b3SIngo Molnar 	unsigned int hardirq_enable_event;
1303de30a2b3SIngo Molnar 	unsigned long hardirq_disable_ip;
1304de30a2b3SIngo Molnar 	unsigned int hardirq_disable_event;
1305de30a2b3SIngo Molnar 	int softirqs_enabled;
1306de30a2b3SIngo Molnar 	unsigned long softirq_disable_ip;
1307de30a2b3SIngo Molnar 	unsigned int softirq_disable_event;
1308de30a2b3SIngo Molnar 	unsigned long softirq_enable_ip;
1309de30a2b3SIngo Molnar 	unsigned int softirq_enable_event;
1310de30a2b3SIngo Molnar 	int hardirq_context;
1311de30a2b3SIngo Molnar 	int softirq_context;
1312de30a2b3SIngo Molnar #endif
1313fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP
1314bdb9441eSPeter Zijlstra # define MAX_LOCK_DEPTH 48UL
1315fbb9ce95SIngo Molnar 	u64 curr_chain_key;
1316fbb9ce95SIngo Molnar 	int lockdep_depth;
1317fbb9ce95SIngo Molnar 	unsigned int lockdep_recursion;
1318c7aceabaSRichard Kennedy 	struct held_lock held_locks[MAX_LOCK_DEPTH];
1319fbb9ce95SIngo Molnar #endif
1320408894eeSIngo Molnar 
13211da177e4SLinus Torvalds /* journalling filesystem info */
13221da177e4SLinus Torvalds 	void *journal_info;
13231da177e4SLinus Torvalds 
1324d89d8796SNeil Brown /* stacked block device info */
1325d89d8796SNeil Brown 	struct bio *bio_list, **bio_tail;
1326d89d8796SNeil Brown 
13271da177e4SLinus Torvalds /* VM state */
13281da177e4SLinus Torvalds 	struct reclaim_state *reclaim_state;
13291da177e4SLinus Torvalds 
13301da177e4SLinus Torvalds 	struct backing_dev_info *backing_dev_info;
13311da177e4SLinus Torvalds 
13321da177e4SLinus Torvalds 	struct io_context *io_context;
13331da177e4SLinus Torvalds 
13341da177e4SLinus Torvalds 	unsigned long ptrace_message;
13351da177e4SLinus Torvalds 	siginfo_t *last_siginfo; /* For ptrace use.  */
1336940389b8SAndrea Righi 	struct task_io_accounting ioac;
13378f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT)
13381da177e4SLinus Torvalds 	u64 acct_rss_mem1;	/* accumulated rss usage */
13391da177e4SLinus Torvalds 	u64 acct_vm_mem1;	/* accumulated virtual memory usage */
134049b5cf34SJonathan Lim 	cputime_t acct_timexpd;	/* stime + utime since last update */
13411da177e4SLinus Torvalds #endif
13421da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS
13431da177e4SLinus Torvalds 	nodemask_t mems_allowed;
13441da177e4SLinus Torvalds 	int cpuset_mems_generation;
1345825a46afSPaul Jackson 	int cpuset_mem_spread_rotor;
13461da177e4SLinus Torvalds #endif
1347ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS
1348817929ecSPaul Menage 	/* Control Group info protected by css_set_lock */
1349817929ecSPaul Menage 	struct css_set *cgroups;
1350817929ecSPaul Menage 	/* cg_list protected by css_set_lock and tsk->alloc_lock */
1351817929ecSPaul Menage 	struct list_head cg_list;
1352ddbcc7e8SPaul Menage #endif
135342b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX
13540771dfefSIngo Molnar 	struct robust_list_head __user *robust_list;
135534f192c6SIngo Molnar #ifdef CONFIG_COMPAT
135634f192c6SIngo Molnar 	struct compat_robust_list_head __user *compat_robust_list;
135734f192c6SIngo Molnar #endif
1358c87e2837SIngo Molnar 	struct list_head pi_state_list;
1359c87e2837SIngo Molnar 	struct futex_pi_state *pi_state_cache;
136042b2dd0aSAlexey Dobriyan #endif
1361c7aceabaSRichard Kennedy #ifdef CONFIG_NUMA
1362c7aceabaSRichard Kennedy 	struct mempolicy *mempolicy;
1363c7aceabaSRichard Kennedy 	short il_next;
1364c7aceabaSRichard Kennedy #endif
136522e2c507SJens Axboe 	atomic_t fs_excl;	/* holding fs exclusive resources */
1366e56d0903SIngo Molnar 	struct rcu_head rcu;
1367b92ce558SJens Axboe 
1368b92ce558SJens Axboe 	/*
1369b92ce558SJens Axboe 	 * cache last used pipe for splice
1370b92ce558SJens Axboe 	 */
1371b92ce558SJens Axboe 	struct pipe_inode_info *splice_pipe;
1372ca74e92bSShailabh Nagar #ifdef	CONFIG_TASK_DELAY_ACCT
1373ca74e92bSShailabh Nagar 	struct task_delay_info *delays;
1374ca74e92bSShailabh Nagar #endif
1375f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION
1376f4f154fdSAkinobu Mita 	int make_it_fail;
1377f4f154fdSAkinobu Mita #endif
13783e26c149SPeter Zijlstra 	struct prop_local_single dirties;
13799745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
13809745512cSArjan van de Ven 	int latency_record_count;
13819745512cSArjan van de Ven 	struct latency_record latency_record[LT_SAVECOUNT];
13829745512cSArjan van de Ven #endif
13836976675dSArjan van de Ven 	/*
13846976675dSArjan van de Ven 	 * time slack values; these are used to round up poll() and
13856976675dSArjan van de Ven 	 * select() etc timeout values. These are in nanoseconds.
13866976675dSArjan van de Ven 	 */
13876976675dSArjan van de Ven 	unsigned long timer_slack_ns;
13886976675dSArjan van de Ven 	unsigned long default_timer_slack_ns;
1389f8d570a4SDavid Miller 
1390f8d570a4SDavid Miller 	struct list_head	*scm_work_list;
1391fb52607aSFrederic Weisbecker #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1392f201ae23SFrederic Weisbecker 	/* Index of current stored adress in ret_stack */
1393f201ae23SFrederic Weisbecker 	int curr_ret_stack;
1394f201ae23SFrederic Weisbecker 	/* Stack of return addresses for return function tracing */
1395f201ae23SFrederic Weisbecker 	struct ftrace_ret_stack	*ret_stack;
1396f201ae23SFrederic Weisbecker 	/*
1397f201ae23SFrederic Weisbecker 	 * Number of functions that haven't been traced
1398f201ae23SFrederic Weisbecker 	 * because of depth overrun.
1399f201ae23SFrederic Weisbecker 	 */
1400f201ae23SFrederic Weisbecker 	atomic_t trace_overrun;
1401380c4b14SFrederic Weisbecker 	/* Pause for the tracing */
1402380c4b14SFrederic Weisbecker 	atomic_t tracing_graph_pause;
1403f201ae23SFrederic Weisbecker #endif
1404ea4e2bc4SSteven Rostedt #ifdef CONFIG_TRACING
1405ea4e2bc4SSteven Rostedt 	/* state flags for use by tracers */
1406ea4e2bc4SSteven Rostedt 	unsigned long trace;
1407ea4e2bc4SSteven Rostedt #endif
14081da177e4SLinus Torvalds };
14091da177e4SLinus Torvalds 
1410e05606d3SIngo Molnar /*
1411e05606d3SIngo Molnar  * Priority of a process goes from 0..MAX_PRIO-1, valid RT
1412e05606d3SIngo Molnar  * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
1413e05606d3SIngo Molnar  * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
1414e05606d3SIngo Molnar  * values are inverted: lower p->prio value means higher priority.
1415e05606d3SIngo Molnar  *
1416e05606d3SIngo Molnar  * The MAX_USER_RT_PRIO value allows the actual maximum
1417e05606d3SIngo Molnar  * RT priority to be separate from the value exported to
1418e05606d3SIngo Molnar  * user-space.  This allows kernel threads to set their
1419e05606d3SIngo Molnar  * priority to a value higher than any user task. Note:
1420e05606d3SIngo Molnar  * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
1421e05606d3SIngo Molnar  */
1422e05606d3SIngo Molnar 
1423e05606d3SIngo Molnar #define MAX_USER_RT_PRIO	100
1424e05606d3SIngo Molnar #define MAX_RT_PRIO		MAX_USER_RT_PRIO
1425e05606d3SIngo Molnar 
1426e05606d3SIngo Molnar #define MAX_PRIO		(MAX_RT_PRIO + 40)
1427e05606d3SIngo Molnar #define DEFAULT_PRIO		(MAX_RT_PRIO + 20)
1428e05606d3SIngo Molnar 
1429e05606d3SIngo Molnar static inline int rt_prio(int prio)
1430e05606d3SIngo Molnar {
1431e05606d3SIngo Molnar 	if (unlikely(prio < MAX_RT_PRIO))
1432e05606d3SIngo Molnar 		return 1;
1433e05606d3SIngo Molnar 	return 0;
1434e05606d3SIngo Molnar }
1435e05606d3SIngo Molnar 
1436e868171aSAlexey Dobriyan static inline int rt_task(struct task_struct *p)
1437e05606d3SIngo Molnar {
1438e05606d3SIngo Molnar 	return rt_prio(p->prio);
1439e05606d3SIngo Molnar }
1440e05606d3SIngo Molnar 
1441a47afb0fSPavel Emelianov static inline void set_task_session(struct task_struct *tsk, pid_t session)
1442937949d9SCedric Le Goater {
1443a47afb0fSPavel Emelianov 	tsk->signal->__session = session;
1444937949d9SCedric Le Goater }
1445937949d9SCedric Le Goater 
14469a2e7057SPavel Emelyanov static inline void set_task_pgrp(struct task_struct *tsk, pid_t pgrp)
14479a2e7057SPavel Emelyanov {
14489a2e7057SPavel Emelyanov 	tsk->signal->__pgrp = pgrp;
14499a2e7057SPavel Emelyanov }
14509a2e7057SPavel Emelyanov 
1451e868171aSAlexey Dobriyan static inline struct pid *task_pid(struct task_struct *task)
145222c935f4SEric W. Biederman {
145322c935f4SEric W. Biederman 	return task->pids[PIDTYPE_PID].pid;
145422c935f4SEric W. Biederman }
145522c935f4SEric W. Biederman 
1456e868171aSAlexey Dobriyan static inline struct pid *task_tgid(struct task_struct *task)
145722c935f4SEric W. Biederman {
145822c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PID].pid;
145922c935f4SEric W. Biederman }
146022c935f4SEric W. Biederman 
1461e868171aSAlexey Dobriyan static inline struct pid *task_pgrp(struct task_struct *task)
146222c935f4SEric W. Biederman {
146322c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PGID].pid;
146422c935f4SEric W. Biederman }
146522c935f4SEric W. Biederman 
1466e868171aSAlexey Dobriyan static inline struct pid *task_session(struct task_struct *task)
146722c935f4SEric W. Biederman {
146822c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_SID].pid;
146922c935f4SEric W. Biederman }
147022c935f4SEric W. Biederman 
14717af57294SPavel Emelyanov struct pid_namespace;
14727af57294SPavel Emelyanov 
14737af57294SPavel Emelyanov /*
14747af57294SPavel Emelyanov  * the helpers to get the task's different pids as they are seen
14757af57294SPavel Emelyanov  * from various namespaces
14767af57294SPavel Emelyanov  *
14777af57294SPavel Emelyanov  * task_xid_nr()     : global id, i.e. the id seen from the init namespace;
147844c4e1b2SEric W. Biederman  * task_xid_vnr()    : virtual id, i.e. the id seen from the pid namespace of
147944c4e1b2SEric W. Biederman  *                     current.
14807af57294SPavel Emelyanov  * task_xid_nr_ns()  : id seen from the ns specified;
14817af57294SPavel Emelyanov  *
14827af57294SPavel Emelyanov  * set_task_vxid()   : assigns a virtual id to a task;
14837af57294SPavel Emelyanov  *
14847af57294SPavel Emelyanov  * see also pid_nr() etc in include/linux/pid.h
14857af57294SPavel Emelyanov  */
14867af57294SPavel Emelyanov 
1487e868171aSAlexey Dobriyan static inline pid_t task_pid_nr(struct task_struct *tsk)
14887af57294SPavel Emelyanov {
14897af57294SPavel Emelyanov 	return tsk->pid;
14907af57294SPavel Emelyanov }
14917af57294SPavel Emelyanov 
14922f2a3a46SPavel Emelyanov pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
14937af57294SPavel Emelyanov 
14947af57294SPavel Emelyanov static inline pid_t task_pid_vnr(struct task_struct *tsk)
14957af57294SPavel Emelyanov {
14967af57294SPavel Emelyanov 	return pid_vnr(task_pid(tsk));
14977af57294SPavel Emelyanov }
14987af57294SPavel Emelyanov 
14997af57294SPavel Emelyanov 
1500e868171aSAlexey Dobriyan static inline pid_t task_tgid_nr(struct task_struct *tsk)
15017af57294SPavel Emelyanov {
15027af57294SPavel Emelyanov 	return tsk->tgid;
15037af57294SPavel Emelyanov }
15047af57294SPavel Emelyanov 
15052f2a3a46SPavel Emelyanov pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
15067af57294SPavel Emelyanov 
15077af57294SPavel Emelyanov static inline pid_t task_tgid_vnr(struct task_struct *tsk)
15087af57294SPavel Emelyanov {
15097af57294SPavel Emelyanov 	return pid_vnr(task_tgid(tsk));
15107af57294SPavel Emelyanov }
15117af57294SPavel Emelyanov 
15127af57294SPavel Emelyanov 
1513e868171aSAlexey Dobriyan static inline pid_t task_pgrp_nr(struct task_struct *tsk)
15147af57294SPavel Emelyanov {
15159a2e7057SPavel Emelyanov 	return tsk->signal->__pgrp;
15167af57294SPavel Emelyanov }
15177af57294SPavel Emelyanov 
15182f2a3a46SPavel Emelyanov pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
15197af57294SPavel Emelyanov 
15207af57294SPavel Emelyanov static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
15217af57294SPavel Emelyanov {
15227af57294SPavel Emelyanov 	return pid_vnr(task_pgrp(tsk));
15237af57294SPavel Emelyanov }
15247af57294SPavel Emelyanov 
15257af57294SPavel Emelyanov 
1526e868171aSAlexey Dobriyan static inline pid_t task_session_nr(struct task_struct *tsk)
15277af57294SPavel Emelyanov {
15287af57294SPavel Emelyanov 	return tsk->signal->__session;
15297af57294SPavel Emelyanov }
15307af57294SPavel Emelyanov 
15312f2a3a46SPavel Emelyanov pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
15327af57294SPavel Emelyanov 
15337af57294SPavel Emelyanov static inline pid_t task_session_vnr(struct task_struct *tsk)
15347af57294SPavel Emelyanov {
15357af57294SPavel Emelyanov 	return pid_vnr(task_session(tsk));
15367af57294SPavel Emelyanov }
15377af57294SPavel Emelyanov 
15387af57294SPavel Emelyanov 
15391da177e4SLinus Torvalds /**
15401da177e4SLinus Torvalds  * pid_alive - check that a task structure is not stale
15411da177e4SLinus Torvalds  * @p: Task structure to be checked.
15421da177e4SLinus Torvalds  *
15431da177e4SLinus Torvalds  * Test if a process is not yet dead (at most zombie state)
15441da177e4SLinus Torvalds  * If pid_alive fails, then pointers within the task structure
15451da177e4SLinus Torvalds  * can be stale and must not be dereferenced.
15461da177e4SLinus Torvalds  */
1547e868171aSAlexey Dobriyan static inline int pid_alive(struct task_struct *p)
15481da177e4SLinus Torvalds {
154992476d7fSEric W. Biederman 	return p->pids[PIDTYPE_PID].pid != NULL;
15501da177e4SLinus Torvalds }
15511da177e4SLinus Torvalds 
1552f400e198SSukadev Bhattiprolu /**
1553b460cbc5SSerge E. Hallyn  * is_global_init - check if a task structure is init
15543260259fSHenne  * @tsk: Task structure to be checked.
15553260259fSHenne  *
15563260259fSHenne  * Check if a task structure is the first user space task the kernel created.
1557f400e198SSukadev Bhattiprolu  */
1558e868171aSAlexey Dobriyan static inline int is_global_init(struct task_struct *tsk)
1559b461cc03SPavel Emelyanov {
1560b461cc03SPavel Emelyanov 	return tsk->pid == 1;
1561b461cc03SPavel Emelyanov }
1562b460cbc5SSerge E. Hallyn 
1563b460cbc5SSerge E. Hallyn /*
1564b460cbc5SSerge E. Hallyn  * is_container_init:
1565b460cbc5SSerge E. Hallyn  * check whether in the task is init in its own pid namespace.
1566b460cbc5SSerge E. Hallyn  */
1567b461cc03SPavel Emelyanov extern int is_container_init(struct task_struct *tsk);
1568f400e198SSukadev Bhattiprolu 
15699ec52099SCedric Le Goater extern struct pid *cad_pid;
15709ec52099SCedric Le Goater 
15711da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk);
15721da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
1573e56d0903SIngo Molnar 
1574158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t);
1575e56d0903SIngo Molnar 
1576e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t)
1577e56d0903SIngo Molnar {
1578e56d0903SIngo Molnar 	if (atomic_dec_and_test(&t->usage))
15798c7904a0SEric W. Biederman 		__put_task_struct(t);
1580e56d0903SIngo Molnar }
15811da177e4SLinus Torvalds 
158249048622SBalbir Singh extern cputime_t task_utime(struct task_struct *p);
158349048622SBalbir Singh extern cputime_t task_stime(struct task_struct *p);
158449048622SBalbir Singh extern cputime_t task_gtime(struct task_struct *p);
158549048622SBalbir Singh 
15861da177e4SLinus Torvalds /*
15871da177e4SLinus Torvalds  * Per process flags
15881da177e4SLinus Torvalds  */
15891da177e4SLinus Torvalds #define PF_ALIGNWARN	0x00000001	/* Print alignment warning msgs */
15901da177e4SLinus Torvalds 					/* Not implemented yet, only for 486*/
15911da177e4SLinus Torvalds #define PF_STARTING	0x00000002	/* being created */
15921da177e4SLinus Torvalds #define PF_EXITING	0x00000004	/* getting shut down */
1593778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
159494886b84SLaurent Vivier #define PF_VCPU		0x00000010	/* I'm a virtual CPU */
15951da177e4SLinus Torvalds #define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
15961da177e4SLinus Torvalds #define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
15971da177e4SLinus Torvalds #define PF_DUMPCORE	0x00000200	/* dumped core */
15981da177e4SLinus Torvalds #define PF_SIGNALED	0x00000400	/* killed by a signal */
15991da177e4SLinus Torvalds #define PF_MEMALLOC	0x00000800	/* Allocating memory */
16001da177e4SLinus Torvalds #define PF_FLUSHER	0x00001000	/* responsible for disk writeback */
16011da177e4SLinus Torvalds #define PF_USED_MATH	0x00002000	/* if unset the fpu must be initialized before use */
16021da177e4SLinus Torvalds #define PF_NOFREEZE	0x00008000	/* this thread should not be frozen */
16031da177e4SLinus Torvalds #define PF_FROZEN	0x00010000	/* frozen for system suspend */
16041da177e4SLinus Torvalds #define PF_FSTRANS	0x00020000	/* inside a filesystem transaction */
16051da177e4SLinus Torvalds #define PF_KSWAPD	0x00040000	/* I am kswapd */
16061da177e4SLinus Torvalds #define PF_SWAPOFF	0x00080000	/* I am in swapoff */
16071da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000	/* Throttle me less: I clean memory */
1608246bb0b1SOleg Nesterov #define PF_KTHREAD	0x00200000	/* I am a kernel thread */
1609b31dc66aSJens Axboe #define PF_RANDOMIZE	0x00400000	/* randomize virtual address space */
1610b31dc66aSJens Axboe #define PF_SWAPWRITE	0x00800000	/* Allowed to write to swap */
1611b31dc66aSJens Axboe #define PF_SPREAD_PAGE	0x01000000	/* Spread page cache over cpuset */
1612b31dc66aSJens Axboe #define PF_SPREAD_SLAB	0x02000000	/* Spread some slab caches over cpuset */
16139985b0baSDavid Rientjes #define PF_THREAD_BOUND	0x04000000	/* Thread bound to specific cpu */
1614c61afb18SPaul Jackson #define PF_MEMPOLICY	0x10000000	/* Non-default NUMA mempolicy */
161561a87122SThomas Gleixner #define PF_MUTEX_TESTER	0x20000000	/* Thread belongs to the rt mutex tester */
1616ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP	0x40000000	/* Freezer should not count it as freezeable */
1617ebb12db5SRafael J. Wysocki #define PF_FREEZER_NOSIG 0x80000000	/* Freezer won't send signals to it */
16181da177e4SLinus Torvalds 
16191da177e4SLinus Torvalds /*
16201da177e4SLinus Torvalds  * Only the _current_ task can read/write to tsk->flags, but other
16211da177e4SLinus Torvalds  * tasks can access tsk->flags in readonly mode for example
16221da177e4SLinus Torvalds  * with tsk_used_math (like during threaded core dumping).
16231da177e4SLinus Torvalds  * There is however an exception to this rule during ptrace
16241da177e4SLinus Torvalds  * or during fork: the ptracer task is allowed to write to the
16251da177e4SLinus Torvalds  * child->flags of its traced child (same goes for fork, the parent
16261da177e4SLinus Torvalds  * can write to the child->flags), because we're guaranteed the
16271da177e4SLinus Torvalds  * child is not running and in turn not changing child->flags
16281da177e4SLinus Torvalds  * at the same time the parent does it.
16291da177e4SLinus Torvalds  */
16301da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
16311da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
16321da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current)
16331da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current)
16341da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \
16351da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
16361da177e4SLinus Torvalds #define conditional_used_math(condition) \
16371da177e4SLinus Torvalds 	conditional_stopped_child_used_math(condition, current)
16381da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \
16391da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
16401da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
16411da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
16421da177e4SLinus Torvalds #define used_math() tsk_used_math(current)
16431da177e4SLinus Torvalds 
16441da177e4SLinus Torvalds #ifdef CONFIG_SMP
1645cd8ba7cdSMike Travis extern int set_cpus_allowed_ptr(struct task_struct *p,
164696f874e2SRusty Russell 				const struct cpumask *new_mask);
16471da177e4SLinus Torvalds #else
1648cd8ba7cdSMike Travis static inline int set_cpus_allowed_ptr(struct task_struct *p,
164996f874e2SRusty Russell 				       const struct cpumask *new_mask)
16501da177e4SLinus Torvalds {
165196f874e2SRusty Russell 	if (!cpumask_test_cpu(0, new_mask))
16521da177e4SLinus Torvalds 		return -EINVAL;
16531da177e4SLinus Torvalds 	return 0;
16541da177e4SLinus Torvalds }
16551da177e4SLinus Torvalds #endif
1656cd8ba7cdSMike Travis static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
1657cd8ba7cdSMike Travis {
1658cd8ba7cdSMike Travis 	return set_cpus_allowed_ptr(p, &new_mask);
1659cd8ba7cdSMike Travis }
16601da177e4SLinus Torvalds 
16611da177e4SLinus Torvalds extern unsigned long long sched_clock(void);
1662e436d800SIngo Molnar 
1663c1955a3dSPeter Zijlstra extern void sched_clock_init(void);
1664c1955a3dSPeter Zijlstra extern u64 sched_clock_cpu(int cpu);
1665c1955a3dSPeter Zijlstra 
16663e51f33fSPeter Zijlstra #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
16673e51f33fSPeter Zijlstra static inline void sched_clock_tick(void)
16683e51f33fSPeter Zijlstra {
16693e51f33fSPeter Zijlstra }
16703e51f33fSPeter Zijlstra 
16713e51f33fSPeter Zijlstra static inline void sched_clock_idle_sleep_event(void)
16723e51f33fSPeter Zijlstra {
16733e51f33fSPeter Zijlstra }
16743e51f33fSPeter Zijlstra 
16753e51f33fSPeter Zijlstra static inline void sched_clock_idle_wakeup_event(u64 delta_ns)
16763e51f33fSPeter Zijlstra {
16773e51f33fSPeter Zijlstra }
1678e4e4e534SIngo Molnar #else
16793e51f33fSPeter Zijlstra extern void sched_clock_tick(void);
16803e51f33fSPeter Zijlstra extern void sched_clock_idle_sleep_event(void);
16813e51f33fSPeter Zijlstra extern void sched_clock_idle_wakeup_event(u64 delta_ns);
16823e51f33fSPeter Zijlstra #endif
16833e51f33fSPeter Zijlstra 
1684e436d800SIngo Molnar /*
1685e436d800SIngo Molnar  * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
1686e436d800SIngo Molnar  * clock constructed from sched_clock():
1687e436d800SIngo Molnar  */
1688e436d800SIngo Molnar extern unsigned long long cpu_clock(int cpu);
1689e436d800SIngo Molnar 
169036c8b586SIngo Molnar extern unsigned long long
169141b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task);
1692f06febc9SFrank Mayhar extern unsigned long long thread_group_sched_runtime(struct task_struct *task);
16931da177e4SLinus Torvalds 
16941da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */
16951da177e4SLinus Torvalds #ifdef CONFIG_SMP
16961da177e4SLinus Torvalds extern void sched_exec(void);
16971da177e4SLinus Torvalds #else
16981da177e4SLinus Torvalds #define sched_exec()   {}
16991da177e4SLinus Torvalds #endif
17001da177e4SLinus Torvalds 
17012aa44d05SIngo Molnar extern void sched_clock_idle_sleep_event(void);
17022aa44d05SIngo Molnar extern void sched_clock_idle_wakeup_event(u64 delta_ns);
1703bb29ab26SIngo Molnar 
17041da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU
17051da177e4SLinus Torvalds extern void idle_task_exit(void);
17061da177e4SLinus Torvalds #else
17071da177e4SLinus Torvalds static inline void idle_task_exit(void) {}
17081da177e4SLinus Torvalds #endif
17091da177e4SLinus Torvalds 
17101da177e4SLinus Torvalds extern void sched_idle_next(void);
1711b29739f9SIngo Molnar 
171206d8308cSThomas Gleixner #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
171306d8308cSThomas Gleixner extern void wake_up_idle_cpu(int cpu);
171406d8308cSThomas Gleixner #else
171506d8308cSThomas Gleixner static inline void wake_up_idle_cpu(int cpu) { }
171606d8308cSThomas Gleixner #endif
171706d8308cSThomas Gleixner 
171821805085SPeter Zijlstra extern unsigned int sysctl_sched_latency;
1719b2be5e96SPeter Zijlstra extern unsigned int sysctl_sched_min_granularity;
1720bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity;
172147fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_ratelimit;
172247fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_thresh;
172347fea2adSJaswinder Singh Rajput #ifdef CONFIG_SCHED_DEBUG
1724bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first;
1725bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_features;
1726da84d961SIngo Molnar extern unsigned int sysctl_sched_migration_cost;
1727b82d9fddSPeter Zijlstra extern unsigned int sysctl_sched_nr_migrate;
1728b2be5e96SPeter Zijlstra 
1729b2be5e96SPeter Zijlstra int sched_nr_latency_handler(struct ctl_table *table, int write,
1730b2be5e96SPeter Zijlstra 		struct file *file, void __user *buffer, size_t *length,
1731b2be5e96SPeter Zijlstra 		loff_t *ppos);
17322bd8e6d4SIngo Molnar #endif
17339f0c1e56SPeter Zijlstra extern unsigned int sysctl_sched_rt_period;
17349f0c1e56SPeter Zijlstra extern int sysctl_sched_rt_runtime;
17352bd8e6d4SIngo Molnar 
1736d0b27fa7SPeter Zijlstra int sched_rt_handler(struct ctl_table *table, int write,
1737d0b27fa7SPeter Zijlstra 		struct file *filp, void __user *buffer, size_t *lenp,
1738d0b27fa7SPeter Zijlstra 		loff_t *ppos);
1739d0b27fa7SPeter Zijlstra 
17402bd8e6d4SIngo Molnar extern unsigned int sysctl_sched_compat_yield;
1741bf0f6f24SIngo Molnar 
1742b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES
174336c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p);
174436c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio);
174536c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p);
1746b29739f9SIngo Molnar #else
1747e868171aSAlexey Dobriyan static inline int rt_mutex_getprio(struct task_struct *p)
1748b29739f9SIngo Molnar {
1749b29739f9SIngo Molnar 	return p->normal_prio;
1750b29739f9SIngo Molnar }
175195e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p)		do { } while (0)
1752b29739f9SIngo Molnar #endif
1753b29739f9SIngo Molnar 
175436c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice);
175536c8b586SIngo Molnar extern int task_prio(const struct task_struct *p);
175636c8b586SIngo Molnar extern int task_nice(const struct task_struct *p);
175736c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice);
175836c8b586SIngo Molnar extern int task_curr(const struct task_struct *p);
17591da177e4SLinus Torvalds extern int idle_cpu(int cpu);
17601da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
1761961ccdddSRusty Russell extern int sched_setscheduler_nocheck(struct task_struct *, int,
1762961ccdddSRusty Russell 				      struct sched_param *);
176336c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu);
176436c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu);
176536c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p);
17661da177e4SLinus Torvalds 
17671da177e4SLinus Torvalds void yield(void);
17681da177e4SLinus Torvalds 
17691da177e4SLinus Torvalds /*
17701da177e4SLinus Torvalds  * The default (Linux) execution domain.
17711da177e4SLinus Torvalds  */
17721da177e4SLinus Torvalds extern struct exec_domain	default_exec_domain;
17731da177e4SLinus Torvalds 
17741da177e4SLinus Torvalds union thread_union {
17751da177e4SLinus Torvalds 	struct thread_info thread_info;
17761da177e4SLinus Torvalds 	unsigned long stack[THREAD_SIZE/sizeof(long)];
17771da177e4SLinus Torvalds };
17781da177e4SLinus Torvalds 
17791da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END
17801da177e4SLinus Torvalds static inline int kstack_end(void *addr)
17811da177e4SLinus Torvalds {
17821da177e4SLinus Torvalds 	/* Reliable end of stack detection:
17831da177e4SLinus Torvalds 	 * Some APM bios versions misalign the stack
17841da177e4SLinus Torvalds 	 */
17851da177e4SLinus Torvalds 	return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
17861da177e4SLinus Torvalds }
17871da177e4SLinus Torvalds #endif
17881da177e4SLinus Torvalds 
17891da177e4SLinus Torvalds extern union thread_union init_thread_union;
17901da177e4SLinus Torvalds extern struct task_struct init_task;
17911da177e4SLinus Torvalds 
17921da177e4SLinus Torvalds extern struct   mm_struct init_mm;
17931da177e4SLinus Torvalds 
1794198fe21bSPavel Emelyanov extern struct pid_namespace init_pid_ns;
1795198fe21bSPavel Emelyanov 
1796198fe21bSPavel Emelyanov /*
1797198fe21bSPavel Emelyanov  * find a task by one of its numerical ids
1798198fe21bSPavel Emelyanov  *
1799198fe21bSPavel Emelyanov  * find_task_by_pid_type_ns():
1800198fe21bSPavel Emelyanov  *      it is the most generic call - it finds a task by all id,
1801198fe21bSPavel Emelyanov  *      type and namespace specified
1802198fe21bSPavel Emelyanov  * find_task_by_pid_ns():
1803198fe21bSPavel Emelyanov  *      finds a task by its pid in the specified namespace
1804228ebcbeSPavel Emelyanov  * find_task_by_vpid():
1805228ebcbeSPavel Emelyanov  *      finds a task by its virtual pid
1806198fe21bSPavel Emelyanov  *
1807e49859e7SPavel Emelyanov  * see also find_vpid() etc in include/linux/pid.h
1808198fe21bSPavel Emelyanov  */
1809198fe21bSPavel Emelyanov 
1810198fe21bSPavel Emelyanov extern struct task_struct *find_task_by_pid_type_ns(int type, int pid,
1811198fe21bSPavel Emelyanov 		struct pid_namespace *ns);
1812198fe21bSPavel Emelyanov 
1813228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_vpid(pid_t nr);
1814228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid_ns(pid_t nr,
1815228ebcbeSPavel Emelyanov 		struct pid_namespace *ns);
1816198fe21bSPavel Emelyanov 
18178520d7c7SOleg Nesterov extern void __set_special_pids(struct pid *pid);
18181da177e4SLinus Torvalds 
18191da177e4SLinus Torvalds /* per-UID process charging. */
1820acce292cSCedric Le Goater extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
18211da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u)
18221da177e4SLinus Torvalds {
18231da177e4SLinus Torvalds 	atomic_inc(&u->__count);
18241da177e4SLinus Torvalds 	return u;
18251da177e4SLinus Torvalds }
18261da177e4SLinus Torvalds extern void free_uid(struct user_struct *);
182728f300d2SPavel Emelyanov extern void release_uids(struct user_namespace *ns);
18281da177e4SLinus Torvalds 
18291da177e4SLinus Torvalds #include <asm/current.h>
18301da177e4SLinus Torvalds 
18313171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks);
18321da177e4SLinus Torvalds 
1833b3c97528SHarvey Harrison extern int wake_up_state(struct task_struct *tsk, unsigned int state);
1834b3c97528SHarvey Harrison extern int wake_up_process(struct task_struct *tsk);
1835b3c97528SHarvey Harrison extern void wake_up_new_task(struct task_struct *tsk,
1836b3c97528SHarvey Harrison 				unsigned long clone_flags);
18371da177e4SLinus Torvalds #ifdef CONFIG_SMP
18381da177e4SLinus Torvalds  extern void kick_process(struct task_struct *tsk);
18391da177e4SLinus Torvalds #else
18401da177e4SLinus Torvalds  static inline void kick_process(struct task_struct *tsk) { }
18411da177e4SLinus Torvalds #endif
1842ad46c2c4SIngo Molnar extern void sched_fork(struct task_struct *p, int clone_flags);
1843ad46c2c4SIngo Molnar extern void sched_dead(struct task_struct *p);
18441da177e4SLinus Torvalds 
18451da177e4SLinus Torvalds extern void proc_caches_init(void);
18461da177e4SLinus Torvalds extern void flush_signals(struct task_struct *);
184710ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *);
18481da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default);
18491da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
18501da177e4SLinus Torvalds 
18511da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
18521da177e4SLinus Torvalds {
18531da177e4SLinus Torvalds 	unsigned long flags;
18541da177e4SLinus Torvalds 	int ret;
18551da177e4SLinus Torvalds 
18561da177e4SLinus Torvalds 	spin_lock_irqsave(&tsk->sighand->siglock, flags);
18571da177e4SLinus Torvalds 	ret = dequeue_signal(tsk, mask, info);
18581da177e4SLinus Torvalds 	spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
18591da177e4SLinus Torvalds 
18601da177e4SLinus Torvalds 	return ret;
18611da177e4SLinus Torvalds }
18621da177e4SLinus Torvalds 
18631da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv,
18641da177e4SLinus Torvalds 			      sigset_t *mask);
18651da177e4SLinus Torvalds extern void unblock_all_signals(void);
18661da177e4SLinus Torvalds extern void release_task(struct task_struct * p);
18671da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *);
18681da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *);
18691da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *);
1870c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
1871c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
18722425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32);
1873c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv);
1874c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv);
1875c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t);
18762b2a1ff6SRoland McGrath extern int do_notify_parent(struct task_struct *, int);
18771da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *);
18781da177e4SLinus Torvalds extern void force_sig_specific(int, struct task_struct *);
18791da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int);
18801da177e4SLinus Torvalds extern void zap_other_threads(struct task_struct *p);
18811da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void);
18821da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *);
1883ac5c2153SOleg Nesterov extern int send_sigqueue(struct sigqueue *,  struct task_struct *, int group);
18849ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
18851da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
18861da177e4SLinus Torvalds 
18879ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv)
18889ec52099SCedric Le Goater {
18899ec52099SCedric Le Goater 	return kill_pid(cad_pid, sig, priv);
18909ec52099SCedric Le Goater }
18919ec52099SCedric Le Goater 
18921da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info.  */
18931da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0)
18941da177e4SLinus Torvalds #define SEND_SIG_PRIV	((struct siginfo *) 1)
18951da177e4SLinus Torvalds #define SEND_SIG_FORCED	((struct siginfo *) 2)
18961da177e4SLinus Torvalds 
1897621d3121SOleg Nesterov static inline int is_si_special(const struct siginfo *info)
1898621d3121SOleg Nesterov {
1899621d3121SOleg Nesterov 	return info <= SEND_SIG_FORCED;
1900621d3121SOleg Nesterov }
1901621d3121SOleg Nesterov 
19021da177e4SLinus Torvalds /* True if we are on the alternate signal stack.  */
19031da177e4SLinus Torvalds 
19041da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp)
19051da177e4SLinus Torvalds {
19061da177e4SLinus Torvalds 	return (sp - current->sas_ss_sp < current->sas_ss_size);
19071da177e4SLinus Torvalds }
19081da177e4SLinus Torvalds 
19091da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp)
19101da177e4SLinus Torvalds {
19111da177e4SLinus Torvalds 	return (current->sas_ss_size == 0 ? SS_DISABLE
19121da177e4SLinus Torvalds 		: on_sig_stack(sp) ? SS_ONSTACK : 0);
19131da177e4SLinus Torvalds }
19141da177e4SLinus Torvalds 
19151da177e4SLinus Torvalds /*
19161da177e4SLinus Torvalds  * Routines for handling mm_structs
19171da177e4SLinus Torvalds  */
19181da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void);
19191da177e4SLinus Torvalds 
19201da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */
1921b3c97528SHarvey Harrison extern void __mmdrop(struct mm_struct *);
19221da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm)
19231da177e4SLinus Torvalds {
19246fb43d7bSIngo Molnar 	if (unlikely(atomic_dec_and_test(&mm->mm_count)))
19251da177e4SLinus Torvalds 		__mmdrop(mm);
19261da177e4SLinus Torvalds }
19271da177e4SLinus Torvalds 
19281da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */
19291da177e4SLinus Torvalds extern void mmput(struct mm_struct *);
19301da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */
19311da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task);
19321da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */
19331da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *);
1934402b0862SCarsten Otte /* Allocate a new mm structure and copy contents from tsk->mm */
1935402b0862SCarsten Otte extern struct mm_struct *dup_mm(struct task_struct *tsk);
19361da177e4SLinus Torvalds 
19371da177e4SLinus Torvalds extern int  copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
19381da177e4SLinus Torvalds extern void flush_thread(void);
19391da177e4SLinus Torvalds extern void exit_thread(void);
19401da177e4SLinus Torvalds 
19411da177e4SLinus Torvalds extern void exit_files(struct task_struct *);
19426b3934efSOleg Nesterov extern void __cleanup_signal(struct signal_struct *);
1943a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *);
1944cbaffba1SOleg Nesterov 
19451da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *);
1946cbaffba1SOleg Nesterov extern void flush_itimer_signals(void);
19471da177e4SLinus Torvalds 
19481da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int);
19491da177e4SLinus Torvalds 
19501da177e4SLinus Torvalds extern void daemonize(const char *, ...);
19511da177e4SLinus Torvalds extern int allow_signal(int);
19521da177e4SLinus Torvalds extern int disallow_signal(int);
19531da177e4SLinus Torvalds 
19541da177e4SLinus Torvalds extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
19551da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
195636c8b586SIngo Molnar struct task_struct *fork_idle(int);
19571da177e4SLinus Torvalds 
19581da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from);
195959714d65SAndrew Morton extern char *get_task_comm(char *to, struct task_struct *tsk);
19601da177e4SLinus Torvalds 
19611da177e4SLinus Torvalds #ifdef CONFIG_SMP
196285ba2d86SRoland McGrath extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
19631da177e4SLinus Torvalds #else
196485ba2d86SRoland McGrath static inline unsigned long wait_task_inactive(struct task_struct *p,
196585ba2d86SRoland McGrath 					       long match_state)
196685ba2d86SRoland McGrath {
196785ba2d86SRoland McGrath 	return 1;
196885ba2d86SRoland McGrath }
19691da177e4SLinus Torvalds #endif
19701da177e4SLinus Torvalds 
19715e85d4abSEric W. Biederman #define next_task(p)	list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks)
19721da177e4SLinus Torvalds 
19731da177e4SLinus Torvalds #define for_each_process(p) \
19741da177e4SLinus Torvalds 	for (p = &init_task ; (p = next_task(p)) != &init_task ; )
19751da177e4SLinus Torvalds 
1976d84f4f99SDavid Howells extern bool is_single_threaded(struct task_struct *);
1977d84f4f99SDavid Howells 
19781da177e4SLinus Torvalds /*
19791da177e4SLinus Torvalds  * Careful: do_each_thread/while_each_thread is a double loop so
19801da177e4SLinus Torvalds  *          'break' will not work as expected - use goto instead.
19811da177e4SLinus Torvalds  */
19821da177e4SLinus Torvalds #define do_each_thread(g, t) \
19831da177e4SLinus Torvalds 	for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
19841da177e4SLinus Torvalds 
19851da177e4SLinus Torvalds #define while_each_thread(g, t) \
19861da177e4SLinus Torvalds 	while ((t = next_thread(t)) != g)
19871da177e4SLinus Torvalds 
1988de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */
1989de12a787SEric W. Biederman #define thread_group_leader(p)	(p == p->group_leader)
19901da177e4SLinus Torvalds 
19910804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process
19920804ef4bSEric W. Biederman  * to have the pid of the thread group leader without actually being
19930804ef4bSEric W. Biederman  * the thread group leader.  For iteration through the pids in proc
19940804ef4bSEric W. Biederman  * all we care about is that we have a task with the appropriate
19950804ef4bSEric W. Biederman  * pid, we don't actually care if we have the right task.
19960804ef4bSEric W. Biederman  */
1997e868171aSAlexey Dobriyan static inline int has_group_leader_pid(struct task_struct *p)
19980804ef4bSEric W. Biederman {
19990804ef4bSEric W. Biederman 	return p->pid == p->tgid;
20000804ef4bSEric W. Biederman }
20010804ef4bSEric W. Biederman 
2002bac0abd6SPavel Emelyanov static inline
2003bac0abd6SPavel Emelyanov int same_thread_group(struct task_struct *p1, struct task_struct *p2)
2004bac0abd6SPavel Emelyanov {
2005bac0abd6SPavel Emelyanov 	return p1->tgid == p2->tgid;
2006bac0abd6SPavel Emelyanov }
2007bac0abd6SPavel Emelyanov 
200836c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p)
200947e65328SOleg Nesterov {
201047e65328SOleg Nesterov 	return list_entry(rcu_dereference(p->thread_group.next),
201136c8b586SIngo Molnar 			  struct task_struct, thread_group);
201247e65328SOleg Nesterov }
201347e65328SOleg Nesterov 
2014e868171aSAlexey Dobriyan static inline int thread_group_empty(struct task_struct *p)
20151da177e4SLinus Torvalds {
201647e65328SOleg Nesterov 	return list_empty(&p->thread_group);
20171da177e4SLinus Torvalds }
20181da177e4SLinus Torvalds 
20191da177e4SLinus Torvalds #define delay_group_leader(p) \
20201da177e4SLinus Torvalds 		(thread_group_leader(p) && !thread_group_empty(p))
20211da177e4SLinus Torvalds 
20221da177e4SLinus Torvalds /*
2023260ea101SEric W. Biederman  * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
202422e2c507SJens Axboe  * subscriptions and synchronises with wait4().  Also used in procfs.  Also
2025ddbcc7e8SPaul Menage  * pins the final release of task.io_context.  Also protects ->cpuset and
2026ddbcc7e8SPaul Menage  * ->cgroup.subsys[].
20271da177e4SLinus Torvalds  *
20281da177e4SLinus Torvalds  * Nests both inside and outside of read_lock(&tasklist_lock).
20291da177e4SLinus Torvalds  * It must not be nested with write_lock_irq(&tasklist_lock),
20301da177e4SLinus Torvalds  * neither inside nor outside.
20311da177e4SLinus Torvalds  */
20321da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p)
20331da177e4SLinus Torvalds {
20341da177e4SLinus Torvalds 	spin_lock(&p->alloc_lock);
20351da177e4SLinus Torvalds }
20361da177e4SLinus Torvalds 
20371da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p)
20381da177e4SLinus Torvalds {
20391da177e4SLinus Torvalds 	spin_unlock(&p->alloc_lock);
20401da177e4SLinus Torvalds }
20411da177e4SLinus Torvalds 
2042f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
2043f63ee72eSOleg Nesterov 							unsigned long *flags);
2044f63ee72eSOleg Nesterov 
2045f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk,
2046f63ee72eSOleg Nesterov 						unsigned long *flags)
2047f63ee72eSOleg Nesterov {
2048f63ee72eSOleg Nesterov 	spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
2049f63ee72eSOleg Nesterov }
2050f63ee72eSOleg Nesterov 
2051f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS
2052f037360fSAl Viro 
2053f7e4217bSRoman Zippel #define task_thread_info(task)	((struct thread_info *)(task)->stack)
2054f7e4217bSRoman Zippel #define task_stack_page(task)	((task)->stack)
2055a1261f54SAl Viro 
205610ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
205710ebffdeSAl Viro {
205810ebffdeSAl Viro 	*task_thread_info(p) = *task_thread_info(org);
205910ebffdeSAl Viro 	task_thread_info(p)->task = p;
206010ebffdeSAl Viro }
206110ebffdeSAl Viro 
206210ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p)
206310ebffdeSAl Viro {
2064f7e4217bSRoman Zippel 	return (unsigned long *)(task_thread_info(p) + 1);
206510ebffdeSAl Viro }
206610ebffdeSAl Viro 
2067f037360fSAl Viro #endif
2068f037360fSAl Viro 
20698b05c7e6SFUJITA Tomonori static inline int object_is_on_stack(void *obj)
20708b05c7e6SFUJITA Tomonori {
20718b05c7e6SFUJITA Tomonori 	void *stack = task_stack_page(current);
20728b05c7e6SFUJITA Tomonori 
20738b05c7e6SFUJITA Tomonori 	return (obj >= stack) && (obj < (stack + THREAD_SIZE));
20748b05c7e6SFUJITA Tomonori }
20758b05c7e6SFUJITA Tomonori 
20768c9843e5SBenjamin Herrenschmidt extern void thread_info_cache_init(void);
20778c9843e5SBenjamin Herrenschmidt 
20781da177e4SLinus Torvalds /* set thread flags in other task's structures
20791da177e4SLinus Torvalds  * - see asm/thread_info.h for TIF_xxxx flags available
20801da177e4SLinus Torvalds  */
20811da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
20821da177e4SLinus Torvalds {
2083a1261f54SAl Viro 	set_ti_thread_flag(task_thread_info(tsk), flag);
20841da177e4SLinus Torvalds }
20851da177e4SLinus Torvalds 
20861da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
20871da177e4SLinus Torvalds {
2088a1261f54SAl Viro 	clear_ti_thread_flag(task_thread_info(tsk), flag);
20891da177e4SLinus Torvalds }
20901da177e4SLinus Torvalds 
20911da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
20921da177e4SLinus Torvalds {
2093a1261f54SAl Viro 	return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
20941da177e4SLinus Torvalds }
20951da177e4SLinus Torvalds 
20961da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
20971da177e4SLinus Torvalds {
2098a1261f54SAl Viro 	return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
20991da177e4SLinus Torvalds }
21001da177e4SLinus Torvalds 
21011da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
21021da177e4SLinus Torvalds {
2103a1261f54SAl Viro 	return test_ti_thread_flag(task_thread_info(tsk), flag);
21041da177e4SLinus Torvalds }
21051da177e4SLinus Torvalds 
21061da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk)
21071da177e4SLinus Torvalds {
21081da177e4SLinus Torvalds 	set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
21091da177e4SLinus Torvalds }
21101da177e4SLinus Torvalds 
21111da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk)
21121da177e4SLinus Torvalds {
21131da177e4SLinus Torvalds 	clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
21141da177e4SLinus Torvalds }
21151da177e4SLinus Torvalds 
21168ae121acSGregory Haskins static inline int test_tsk_need_resched(struct task_struct *tsk)
21178ae121acSGregory Haskins {
21188ae121acSGregory Haskins 	return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
21198ae121acSGregory Haskins }
21208ae121acSGregory Haskins 
21211da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p)
21221da177e4SLinus Torvalds {
21231da177e4SLinus Torvalds 	return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
21241da177e4SLinus Torvalds }
21251da177e4SLinus Torvalds 
2126b3c97528SHarvey Harrison extern int __fatal_signal_pending(struct task_struct *p);
2127f776d12dSMatthew Wilcox 
2128f776d12dSMatthew Wilcox static inline int fatal_signal_pending(struct task_struct *p)
2129f776d12dSMatthew Wilcox {
2130f776d12dSMatthew Wilcox 	return signal_pending(p) && __fatal_signal_pending(p);
2131f776d12dSMatthew Wilcox }
2132f776d12dSMatthew Wilcox 
213316882c1eSOleg Nesterov static inline int signal_pending_state(long state, struct task_struct *p)
213416882c1eSOleg Nesterov {
213516882c1eSOleg Nesterov 	if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
213616882c1eSOleg Nesterov 		return 0;
213716882c1eSOleg Nesterov 	if (!signal_pending(p))
213816882c1eSOleg Nesterov 		return 0;
213916882c1eSOleg Nesterov 
214016882c1eSOleg Nesterov 	return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
214116882c1eSOleg Nesterov }
214216882c1eSOleg Nesterov 
21431da177e4SLinus Torvalds static inline int need_resched(void)
21441da177e4SLinus Torvalds {
21459404ef02SLinus Torvalds 	return unlikely(test_thread_flag(TIF_NEED_RESCHED));
21461da177e4SLinus Torvalds }
21471da177e4SLinus Torvalds 
21481da177e4SLinus Torvalds /*
21491da177e4SLinus Torvalds  * cond_resched() and cond_resched_lock(): latency reduction via
21501da177e4SLinus Torvalds  * explicit rescheduling in places that are safe. The return
21511da177e4SLinus Torvalds  * value indicates whether a reschedule was done in fact.
21521da177e4SLinus Torvalds  * cond_resched_lock() will drop the spinlock before scheduling,
21531da177e4SLinus Torvalds  * cond_resched_softirq() will enable bhs before scheduling.
21541da177e4SLinus Torvalds  */
2155c3921ab7SLinus Torvalds extern int _cond_resched(void);
2156c714a534SLinus Torvalds #ifdef CONFIG_PREEMPT_BKL
215702b67cc3SHerbert Xu static inline int cond_resched(void)
215802b67cc3SHerbert Xu {
215902b67cc3SHerbert Xu 	return 0;
216002b67cc3SHerbert Xu }
216102b67cc3SHerbert Xu #else
216202b67cc3SHerbert Xu static inline int cond_resched(void)
216302b67cc3SHerbert Xu {
216402b67cc3SHerbert Xu 	return _cond_resched();
216502b67cc3SHerbert Xu }
216602b67cc3SHerbert Xu #endif
21671da177e4SLinus Torvalds extern int cond_resched_lock(spinlock_t * lock);
21681da177e4SLinus Torvalds extern int cond_resched_softirq(void);
2169c3921ab7SLinus Torvalds static inline int cond_resched_bkl(void)
2170c3921ab7SLinus Torvalds {
2171c3921ab7SLinus Torvalds 	return _cond_resched();
2172c3921ab7SLinus Torvalds }
21731da177e4SLinus Torvalds 
21741da177e4SLinus Torvalds /*
21751da177e4SLinus Torvalds  * Does a critical section need to be broken due to another
217695c354feSNick Piggin  * task waiting?: (technically does not depend on CONFIG_PREEMPT,
217795c354feSNick Piggin  * but a general need for low latency)
21781da177e4SLinus Torvalds  */
217995c354feSNick Piggin static inline int spin_needbreak(spinlock_t *lock)
21801da177e4SLinus Torvalds {
218195c354feSNick Piggin #ifdef CONFIG_PREEMPT
218295c354feSNick Piggin 	return spin_is_contended(lock);
218395c354feSNick Piggin #else
21841da177e4SLinus Torvalds 	return 0;
218595c354feSNick Piggin #endif
21861da177e4SLinus Torvalds }
21871da177e4SLinus Torvalds 
21887bb44adeSRoland McGrath /*
2189f06febc9SFrank Mayhar  * Thread group CPU time accounting.
2190f06febc9SFrank Mayhar  */
2191f06febc9SFrank Mayhar 
2192bb34d92fSFrank Mayhar extern int thread_group_cputime_alloc(struct task_struct *);
2193bb34d92fSFrank Mayhar extern void thread_group_cputime(struct task_struct *, struct task_cputime *);
2194f06febc9SFrank Mayhar 
2195f06febc9SFrank Mayhar static inline void thread_group_cputime_init(struct signal_struct *sig)
2196f06febc9SFrank Mayhar {
2197f06febc9SFrank Mayhar 	sig->cputime.totals = NULL;
2198f06febc9SFrank Mayhar }
2199f06febc9SFrank Mayhar 
2200bb34d92fSFrank Mayhar static inline int thread_group_cputime_clone_thread(struct task_struct *curr)
2201f06febc9SFrank Mayhar {
2202f06febc9SFrank Mayhar 	if (curr->signal->cputime.totals)
2203f06febc9SFrank Mayhar 		return 0;
2204bb34d92fSFrank Mayhar 	return thread_group_cputime_alloc(curr);
2205f06febc9SFrank Mayhar }
2206f06febc9SFrank Mayhar 
2207f06febc9SFrank Mayhar static inline void thread_group_cputime_free(struct signal_struct *sig)
2208f06febc9SFrank Mayhar {
2209f06febc9SFrank Mayhar 	free_percpu(sig->cputime.totals);
2210f06febc9SFrank Mayhar }
2211f06febc9SFrank Mayhar 
2212f06febc9SFrank Mayhar /*
22137bb44adeSRoland McGrath  * Reevaluate whether the task has signals pending delivery.
22147bb44adeSRoland McGrath  * Wake the task if so.
22157bb44adeSRoland McGrath  * This is required every time the blocked sigset_t changes.
22167bb44adeSRoland McGrath  * callers must hold sighand->siglock.
22177bb44adeSRoland McGrath  */
22187bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t);
22191da177e4SLinus Torvalds extern void recalc_sigpending(void);
22201da177e4SLinus Torvalds 
22211da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped);
22221da177e4SLinus Torvalds 
22231da177e4SLinus Torvalds /*
22241da177e4SLinus Torvalds  * Wrappers for p->thread_info->cpu access. No-op on UP.
22251da177e4SLinus Torvalds  */
22261da177e4SLinus Torvalds #ifdef CONFIG_SMP
22271da177e4SLinus Torvalds 
22281da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
22291da177e4SLinus Torvalds {
2230a1261f54SAl Viro 	return task_thread_info(p)->cpu;
22311da177e4SLinus Torvalds }
22321da177e4SLinus Torvalds 
2233c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
22341da177e4SLinus Torvalds 
22351da177e4SLinus Torvalds #else
22361da177e4SLinus Torvalds 
22371da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
22381da177e4SLinus Torvalds {
22391da177e4SLinus Torvalds 	return 0;
22401da177e4SLinus Torvalds }
22411da177e4SLinus Torvalds 
22421da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
22431da177e4SLinus Torvalds {
22441da177e4SLinus Torvalds }
22451da177e4SLinus Torvalds 
22461da177e4SLinus Torvalds #endif /* CONFIG_SMP */
22471da177e4SLinus Torvalds 
22481da177e4SLinus Torvalds extern void arch_pick_mmap_layout(struct mm_struct *mm);
22491da177e4SLinus Torvalds 
22501a3c3034SIngo Molnar #ifdef CONFIG_TRACING
22511a3c3034SIngo Molnar extern void
22521a3c3034SIngo Molnar __trace_special(void *__tr, void *__data,
22531a3c3034SIngo Molnar 		unsigned long arg1, unsigned long arg2, unsigned long arg3);
22541a3c3034SIngo Molnar #else
22551a3c3034SIngo Molnar static inline void
22561a3c3034SIngo Molnar __trace_special(void *__tr, void *__data,
22571a3c3034SIngo Molnar 		unsigned long arg1, unsigned long arg2, unsigned long arg3)
22581a3c3034SIngo Molnar {
22591a3c3034SIngo Molnar }
22601a3c3034SIngo Molnar #endif
22611a3c3034SIngo Molnar 
226296f874e2SRusty Russell extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
226396f874e2SRusty Russell extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
22645c45bf27SSiddha, Suresh B 
22651da177e4SLinus Torvalds extern void normalize_rt_tasks(void);
22661da177e4SLinus Torvalds 
2267052f1dc7SPeter Zijlstra #ifdef CONFIG_GROUP_SCHED
22689b5b7751SSrivatsa Vaddagiri 
22694cf86d77SIngo Molnar extern struct task_group init_task_group;
2270eff766a6SPeter Zijlstra #ifdef CONFIG_USER_SCHED
2271eff766a6SPeter Zijlstra extern struct task_group root_task_group;
22726c415b92SArun R Bharadwaj extern void set_tg_uid(struct user_struct *user);
2273eff766a6SPeter Zijlstra #endif
22749b5b7751SSrivatsa Vaddagiri 
2275ec7dc8acSDhaval Giani extern struct task_group *sched_create_group(struct task_group *parent);
22764cf86d77SIngo Molnar extern void sched_destroy_group(struct task_group *tg);
22779b5b7751SSrivatsa Vaddagiri extern void sched_move_task(struct task_struct *tsk);
2278052f1dc7SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED
22794cf86d77SIngo Molnar extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
22805cb350baSDhaval Giani extern unsigned long sched_group_shares(struct task_group *tg);
2281052f1dc7SPeter Zijlstra #endif
2282052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED
22839f0c1e56SPeter Zijlstra extern int sched_group_set_rt_runtime(struct task_group *tg,
22849f0c1e56SPeter Zijlstra 				      long rt_runtime_us);
22859f0c1e56SPeter Zijlstra extern long sched_group_rt_runtime(struct task_group *tg);
2286d0b27fa7SPeter Zijlstra extern int sched_group_set_rt_period(struct task_group *tg,
2287d0b27fa7SPeter Zijlstra 				      long rt_period_us);
2288d0b27fa7SPeter Zijlstra extern long sched_group_rt_period(struct task_group *tg);
2289052f1dc7SPeter Zijlstra #endif
22909b5b7751SSrivatsa Vaddagiri #endif
22919b5b7751SSrivatsa Vaddagiri 
22924b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT
22934b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
22944b98d11bSAlexey Dobriyan {
2295940389b8SAndrea Righi 	tsk->ioac.rchar += amt;
22964b98d11bSAlexey Dobriyan }
22974b98d11bSAlexey Dobriyan 
22984b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
22994b98d11bSAlexey Dobriyan {
2300940389b8SAndrea Righi 	tsk->ioac.wchar += amt;
23014b98d11bSAlexey Dobriyan }
23024b98d11bSAlexey Dobriyan 
23034b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
23044b98d11bSAlexey Dobriyan {
2305940389b8SAndrea Righi 	tsk->ioac.syscr++;
23064b98d11bSAlexey Dobriyan }
23074b98d11bSAlexey Dobriyan 
23084b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
23094b98d11bSAlexey Dobriyan {
2310940389b8SAndrea Righi 	tsk->ioac.syscw++;
23114b98d11bSAlexey Dobriyan }
23124b98d11bSAlexey Dobriyan #else
23134b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
23144b98d11bSAlexey Dobriyan {
23154b98d11bSAlexey Dobriyan }
23164b98d11bSAlexey Dobriyan 
23174b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
23184b98d11bSAlexey Dobriyan {
23194b98d11bSAlexey Dobriyan }
23204b98d11bSAlexey Dobriyan 
23214b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
23224b98d11bSAlexey Dobriyan {
23234b98d11bSAlexey Dobriyan }
23244b98d11bSAlexey Dobriyan 
23254b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
23264b98d11bSAlexey Dobriyan {
23274b98d11bSAlexey Dobriyan }
23284b98d11bSAlexey Dobriyan #endif
23294b98d11bSAlexey Dobriyan 
233082455257SDave Hansen #ifndef TASK_SIZE_OF
233182455257SDave Hansen #define TASK_SIZE_OF(tsk)	TASK_SIZE
233282455257SDave Hansen #endif
233382455257SDave Hansen 
2334cf475ad2SBalbir Singh #ifdef CONFIG_MM_OWNER
2335cf475ad2SBalbir Singh extern void mm_update_next_owner(struct mm_struct *mm);
2336cf475ad2SBalbir Singh extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p);
2337cf475ad2SBalbir Singh #else
2338cf475ad2SBalbir Singh static inline void mm_update_next_owner(struct mm_struct *mm)
2339cf475ad2SBalbir Singh {
2340cf475ad2SBalbir Singh }
2341cf475ad2SBalbir Singh 
2342cf475ad2SBalbir Singh static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p)
2343cf475ad2SBalbir Singh {
2344cf475ad2SBalbir Singh }
2345cf475ad2SBalbir Singh #endif /* CONFIG_MM_OWNER */
2346cf475ad2SBalbir Singh 
23477c731e0aSSteven Rostedt #define TASK_STATE_TO_CHAR_STR "RSDTtZX"
23487c731e0aSSteven Rostedt 
23491da177e4SLinus Torvalds #endif /* __KERNEL__ */
23501da177e4SLinus Torvalds 
23511da177e4SLinus Torvalds #endif
2352