xref: /linux/include/linux/sched.h (revision 21aa9af03d06cb1d19a3738e5cf12acff984e69b)
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
41ca94c442SLennart Poettering /* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
42ca94c442SLennart Poettering #define SCHED_RESET_ON_FORK     0x40000000
43b7b3c76aSDavid Woodhouse 
44a3b6714eSDavid Woodhouse #ifdef __KERNEL__
45b7b3c76aSDavid Woodhouse 
46b7b3c76aSDavid Woodhouse struct sched_param {
47b7b3c76aSDavid Woodhouse 	int sched_priority;
48b7b3c76aSDavid Woodhouse };
49b7b3c76aSDavid Woodhouse 
501da177e4SLinus Torvalds #include <asm/param.h>	/* for HZ */
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds #include <linux/capability.h>
531da177e4SLinus Torvalds #include <linux/threads.h>
541da177e4SLinus Torvalds #include <linux/kernel.h>
551da177e4SLinus Torvalds #include <linux/types.h>
561da177e4SLinus Torvalds #include <linux/timex.h>
571da177e4SLinus Torvalds #include <linux/jiffies.h>
581da177e4SLinus Torvalds #include <linux/rbtree.h>
591da177e4SLinus Torvalds #include <linux/thread_info.h>
601da177e4SLinus Torvalds #include <linux/cpumask.h>
611da177e4SLinus Torvalds #include <linux/errno.h>
621da177e4SLinus Torvalds #include <linux/nodemask.h>
63c92ff1bdSMartin Schwidefsky #include <linux/mm_types.h>
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds #include <asm/system.h>
661da177e4SLinus Torvalds #include <asm/page.h>
671da177e4SLinus Torvalds #include <asm/ptrace.h>
681da177e4SLinus Torvalds #include <asm/cputime.h>
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds #include <linux/smp.h>
711da177e4SLinus Torvalds #include <linux/sem.h>
721da177e4SLinus Torvalds #include <linux/signal.h>
735ad4e53bSAl Viro #include <linux/path.h>
741da177e4SLinus Torvalds #include <linux/compiler.h>
751da177e4SLinus Torvalds #include <linux/completion.h>
761da177e4SLinus Torvalds #include <linux/pid.h>
771da177e4SLinus Torvalds #include <linux/percpu.h>
781da177e4SLinus Torvalds #include <linux/topology.h>
793e26c149SPeter Zijlstra #include <linux/proportions.h>
801da177e4SLinus Torvalds #include <linux/seccomp.h>
81e56d0903SIngo Molnar #include <linux/rcupdate.h>
8205725f7eSJiri Pirko #include <linux/rculist.h>
8323f78d4aSIngo Molnar #include <linux/rtmutex.h>
841da177e4SLinus Torvalds 
85a3b6714eSDavid Woodhouse #include <linux/time.h>
86a3b6714eSDavid Woodhouse #include <linux/param.h>
87a3b6714eSDavid Woodhouse #include <linux/resource.h>
88a3b6714eSDavid Woodhouse #include <linux/timer.h>
89a3b6714eSDavid Woodhouse #include <linux/hrtimer.h>
907c3ab738SAndrew Morton #include <linux/task_io_accounting.h>
915cb350baSDhaval Giani #include <linux/kobject.h>
929745512cSArjan van de Ven #include <linux/latencytop.h>
939e2b2dc4SDavid Howells #include <linux/cred.h>
94a3b6714eSDavid Woodhouse 
95a3b6714eSDavid Woodhouse #include <asm/processor.h>
9636d57ac4SH. J. Lu 
971da177e4SLinus Torvalds struct exec_domain;
98c87e2837SIngo Molnar struct futex_pi_state;
99286100a6SAlexey Dobriyan struct robust_list_head;
100bddd87c7SAkinobu Mita struct bio_list;
1015ad4e53bSAl Viro struct fs_struct;
102cdd6c482SIngo Molnar struct perf_event_context;
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds /*
1051da177e4SLinus Torvalds  * List of flags we want to share for kernel threads,
1061da177e4SLinus Torvalds  * if only because they are not used by them anyway.
1071da177e4SLinus Torvalds  */
1081da177e4SLinus Torvalds #define CLONE_KERNEL	(CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds /*
1111da177e4SLinus Torvalds  * These are the constant used to fake the fixed-point load-average
1121da177e4SLinus Torvalds  * counting. Some notes:
1131da177e4SLinus Torvalds  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
1141da177e4SLinus Torvalds  *    a load-average precision of 10 bits integer + 11 bits fractional
1151da177e4SLinus Torvalds  *  - if you want to count load-averages more often, you need more
1161da177e4SLinus Torvalds  *    precision, or rounding will get you. With 2-second counting freq,
1171da177e4SLinus Torvalds  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
1181da177e4SLinus Torvalds  *    11 bit fractions.
1191da177e4SLinus Torvalds  */
1201da177e4SLinus Torvalds extern unsigned long avenrun[];		/* Load averages */
1212d02494fSThomas Gleixner extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds #define FSHIFT		11		/* nr of bits of precision */
1241da177e4SLinus Torvalds #define FIXED_1		(1<<FSHIFT)	/* 1.0 as fixed-point */
1250c2043abSLinus Torvalds #define LOAD_FREQ	(5*HZ+1)	/* 5 sec intervals */
1261da177e4SLinus Torvalds #define EXP_1		1884		/* 1/exp(5sec/1min) as fixed-point */
1271da177e4SLinus Torvalds #define EXP_5		2014		/* 1/exp(5sec/5min) */
1281da177e4SLinus Torvalds #define EXP_15		2037		/* 1/exp(5sec/15min) */
1291da177e4SLinus Torvalds 
1301da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \
1311da177e4SLinus Torvalds 	load *= exp; \
1321da177e4SLinus Torvalds 	load += n*(FIXED_1-exp); \
1331da177e4SLinus Torvalds 	load >>= FSHIFT;
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds extern unsigned long total_forks;
1361da177e4SLinus Torvalds extern int nr_threads;
1371da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts);
1381da177e4SLinus Torvalds extern int nr_processes(void);
1391da177e4SLinus Torvalds extern unsigned long nr_running(void);
1401da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void);
1411da177e4SLinus Torvalds extern unsigned long nr_iowait(void);
14269d25870SArjan van de Ven extern unsigned long nr_iowait_cpu(void);
14369d25870SArjan van de Ven extern unsigned long this_cpu_load(void);
14469d25870SArjan van de Ven 
14569d25870SArjan van de Ven 
146dce48a84SThomas Gleixner extern void calc_global_load(void);
1471da177e4SLinus Torvalds 
1487e49fcceSSteven Rostedt extern unsigned long get_parent_ip(unsigned long addr);
1497e49fcceSSteven Rostedt 
15043ae34cbSIngo Molnar struct seq_file;
15143ae34cbSIngo Molnar struct cfs_rq;
1524cf86d77SIngo Molnar struct task_group;
15343ae34cbSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
15443ae34cbSIngo Molnar extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
15543ae34cbSIngo Molnar extern void proc_sched_set_task(struct task_struct *p);
15643ae34cbSIngo Molnar extern void
1575cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
15843ae34cbSIngo Molnar #else
15943ae34cbSIngo Molnar static inline void
16043ae34cbSIngo Molnar proc_sched_show_task(struct task_struct *p, struct seq_file *m)
16143ae34cbSIngo Molnar {
16243ae34cbSIngo Molnar }
16343ae34cbSIngo Molnar static inline void proc_sched_set_task(struct task_struct *p)
16443ae34cbSIngo Molnar {
16543ae34cbSIngo Molnar }
16643ae34cbSIngo Molnar static inline void
1675cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
16843ae34cbSIngo Molnar {
16943ae34cbSIngo Molnar }
17043ae34cbSIngo Molnar #endif
1711da177e4SLinus Torvalds 
1724a8342d2SLinus Torvalds /*
1734a8342d2SLinus Torvalds  * Task state bitmask. NOTE! These bits are also
1744a8342d2SLinus Torvalds  * encoded in fs/proc/array.c: get_task_state().
1754a8342d2SLinus Torvalds  *
1764a8342d2SLinus Torvalds  * We have two separate sets of flags: task->state
1774a8342d2SLinus Torvalds  * is about runnability, while task->exit_state are
1784a8342d2SLinus Torvalds  * about the task exiting. Confusing, but this way
1794a8342d2SLinus Torvalds  * modifying one set can't modify the other one by
1804a8342d2SLinus Torvalds  * mistake.
1814a8342d2SLinus Torvalds  */
1821da177e4SLinus Torvalds #define TASK_RUNNING		0
1831da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE	1
1841da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE	2
185f021a3c2SMatthew Wilcox #define __TASK_STOPPED		4
186f021a3c2SMatthew Wilcox #define __TASK_TRACED		8
1874a8342d2SLinus Torvalds /* in tsk->exit_state */
1884a8342d2SLinus Torvalds #define EXIT_ZOMBIE		16
1894a8342d2SLinus Torvalds #define EXIT_DEAD		32
1904a8342d2SLinus Torvalds /* in tsk->state again */
191af927232SMike Galbraith #define TASK_DEAD		64
192f021a3c2SMatthew Wilcox #define TASK_WAKEKILL		128
193e9c84311SPeter Zijlstra #define TASK_WAKING		256
194e1781538SPeter Zijlstra #define TASK_STATE_MAX		512
195f021a3c2SMatthew Wilcox 
19644d90df6SPeter Zijlstra #define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW"
19773342151SPeter Zijlstra 
198e1781538SPeter Zijlstra extern char ___assert_task_state[1 - 2*!!(
199e1781538SPeter Zijlstra 		sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)];
200f021a3c2SMatthew Wilcox 
201f021a3c2SMatthew Wilcox /* Convenience macros for the sake of set_task_state */
202f021a3c2SMatthew Wilcox #define TASK_KILLABLE		(TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
203f021a3c2SMatthew Wilcox #define TASK_STOPPED		(TASK_WAKEKILL | __TASK_STOPPED)
204f021a3c2SMatthew Wilcox #define TASK_TRACED		(TASK_WAKEKILL | __TASK_TRACED)
2051da177e4SLinus Torvalds 
20692a1f4bcSMatthew Wilcox /* Convenience macros for the sake of wake_up */
20792a1f4bcSMatthew Wilcox #define TASK_NORMAL		(TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
208f021a3c2SMatthew Wilcox #define TASK_ALL		(TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
20992a1f4bcSMatthew Wilcox 
21092a1f4bcSMatthew Wilcox /* get_task_state() */
21192a1f4bcSMatthew Wilcox #define TASK_REPORT		(TASK_RUNNING | TASK_INTERRUPTIBLE | \
212f021a3c2SMatthew Wilcox 				 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
213f021a3c2SMatthew Wilcox 				 __TASK_TRACED)
21492a1f4bcSMatthew Wilcox 
215f021a3c2SMatthew Wilcox #define task_is_traced(task)	((task->state & __TASK_TRACED) != 0)
216f021a3c2SMatthew Wilcox #define task_is_stopped(task)	((task->state & __TASK_STOPPED) != 0)
21792a1f4bcSMatthew Wilcox #define task_is_stopped_or_traced(task)	\
218f021a3c2SMatthew Wilcox 			((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
21992a1f4bcSMatthew Wilcox #define task_contributes_to_load(task)	\
220e3c8ca83SNathan Lynch 				((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
2216301cb95SThomas Gleixner 				 (task->flags & PF_FREEZING) == 0)
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds #define __set_task_state(tsk, state_value)		\
2241da177e4SLinus Torvalds 	do { (tsk)->state = (state_value); } while (0)
2251da177e4SLinus Torvalds #define set_task_state(tsk, state_value)		\
2261da177e4SLinus Torvalds 	set_mb((tsk)->state, (state_value))
2271da177e4SLinus Torvalds 
228498d0c57SAndrew Morton /*
229498d0c57SAndrew Morton  * set_current_state() includes a barrier so that the write of current->state
230498d0c57SAndrew Morton  * is correctly serialised wrt the caller's subsequent test of whether to
231498d0c57SAndrew Morton  * actually sleep:
232498d0c57SAndrew Morton  *
233498d0c57SAndrew Morton  *	set_current_state(TASK_UNINTERRUPTIBLE);
234498d0c57SAndrew Morton  *	if (do_i_need_to_sleep())
235498d0c57SAndrew Morton  *		schedule();
236498d0c57SAndrew Morton  *
237498d0c57SAndrew Morton  * If the caller does not need such serialisation then use __set_current_state()
238498d0c57SAndrew Morton  */
2391da177e4SLinus Torvalds #define __set_current_state(state_value)			\
2401da177e4SLinus Torvalds 	do { current->state = (state_value); } while (0)
2411da177e4SLinus Torvalds #define set_current_state(state_value)		\
2421da177e4SLinus Torvalds 	set_mb(current->state, (state_value))
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds /* Task command name length */
2451da177e4SLinus Torvalds #define TASK_COMM_LEN 16
2461da177e4SLinus Torvalds 
2471da177e4SLinus Torvalds #include <linux/spinlock.h>
2481da177e4SLinus Torvalds 
2491da177e4SLinus Torvalds /*
2501da177e4SLinus Torvalds  * This serializes "schedule()" and also protects
2511da177e4SLinus Torvalds  * the run-queue from deletions/modifications (but
2521da177e4SLinus Torvalds  * _adding_ to the beginning of the run-queue has
2531da177e4SLinus Torvalds  * a separate lock).
2541da177e4SLinus Torvalds  */
2551da177e4SLinus Torvalds extern rwlock_t tasklist_lock;
2561da177e4SLinus Torvalds extern spinlock_t mmlist_lock;
2571da177e4SLinus Torvalds 
25836c8b586SIngo Molnar struct task_struct;
2591da177e4SLinus Torvalds 
260db1466b3SPaul E. McKenney #ifdef CONFIG_PROVE_RCU
261db1466b3SPaul E. McKenney extern int lockdep_tasklist_lock_is_held(void);
262db1466b3SPaul E. McKenney #endif /* #ifdef CONFIG_PROVE_RCU */
263db1466b3SPaul E. McKenney 
2641da177e4SLinus Torvalds extern void sched_init(void);
2651da177e4SLinus Torvalds extern void sched_init_smp(void);
2662d07b255SHarvey Harrison extern asmlinkage void schedule_tail(struct task_struct *prev);
26736c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu);
2681df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle);
2691da177e4SLinus Torvalds 
27089f19f04SAndrew Morton extern int runqueue_is_locked(int cpu);
271017730c1SIngo Molnar 
2726a7b3dc3SRusty Russell extern cpumask_var_t nohz_cpu_mask;
27346cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
27446cb4b7cSSiddha, Suresh B extern int select_nohz_load_balancer(int cpu);
275eea08f32SArun R Bharadwaj extern int get_nohz_load_balancer(void);
27639c0cbe2SMike Galbraith extern int nohz_ratelimit(int cpu);
27746cb4b7cSSiddha, Suresh B #else
27846cb4b7cSSiddha, Suresh B static inline int select_nohz_load_balancer(int cpu)
27946cb4b7cSSiddha, Suresh B {
28046cb4b7cSSiddha, Suresh B 	return 0;
28146cb4b7cSSiddha, Suresh B }
28239c0cbe2SMike Galbraith 
28339c0cbe2SMike Galbraith static inline int nohz_ratelimit(int cpu)
28439c0cbe2SMike Galbraith {
28539c0cbe2SMike Galbraith 	return 0;
28639c0cbe2SMike Galbraith }
28746cb4b7cSSiddha, Suresh B #endif
2881da177e4SLinus Torvalds 
289e59e2ae2SIngo Molnar /*
29039bc89fdSIngo Molnar  * Only dump TASK_* tasks. (0 for all tasks)
291e59e2ae2SIngo Molnar  */
292e59e2ae2SIngo Molnar extern void show_state_filter(unsigned long state_filter);
293e59e2ae2SIngo Molnar 
294e59e2ae2SIngo Molnar static inline void show_state(void)
295e59e2ae2SIngo Molnar {
29639bc89fdSIngo Molnar 	show_state_filter(0);
297e59e2ae2SIngo Molnar }
298e59e2ae2SIngo Molnar 
2991da177e4SLinus Torvalds extern void show_regs(struct pt_regs *);
3001da177e4SLinus Torvalds 
3011da177e4SLinus Torvalds /*
3021da177e4SLinus Torvalds  * TASK is a pointer to the task whose backtrace we want to see (or NULL for current
3031da177e4SLinus Torvalds  * task), SP is the stack pointer of the first frame that should be shown in the back
3041da177e4SLinus Torvalds  * trace (or NULL if the entire call-chain of the task should be shown).
3051da177e4SLinus Torvalds  */
3061da177e4SLinus Torvalds extern void show_stack(struct task_struct *task, unsigned long *sp);
3071da177e4SLinus Torvalds 
3081da177e4SLinus Torvalds void io_schedule(void);
3091da177e4SLinus Torvalds long io_schedule_timeout(long timeout);
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds extern void cpu_init (void);
3121da177e4SLinus Torvalds extern void trap_init(void);
3131da177e4SLinus Torvalds extern void update_process_times(int user);
3141da177e4SLinus Torvalds extern void scheduler_tick(void);
3151da177e4SLinus Torvalds 
31682a1fcb9SIngo Molnar extern void sched_show_task(struct task_struct *p);
31782a1fcb9SIngo Molnar 
3188446f1d3SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP
3196687a97dSIngo Molnar extern void softlockup_tick(void);
3208446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void);
321d6ad3e28SJason Wessel extern void touch_softlockup_watchdog_sync(void);
32204c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void);
323baf48f65SMandeep Singh Baines extern int proc_dosoftlockup_thresh(struct ctl_table *table, int write,
3248d65af78SAlexey Dobriyan 				    void __user *buffer,
325baf48f65SMandeep Singh Baines 				    size_t *lenp, loff_t *ppos);
3269c44bc03SIngo Molnar extern unsigned int  softlockup_panic;
3279383d967SDimitri Sivanich extern int softlockup_thresh;
3288446f1d3SIngo Molnar #else
3296687a97dSIngo Molnar static inline void softlockup_tick(void)
3308446f1d3SIngo Molnar {
3318446f1d3SIngo Molnar }
3328446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void)
3338446f1d3SIngo Molnar {
3348446f1d3SIngo Molnar }
335d6ad3e28SJason Wessel static inline void touch_softlockup_watchdog_sync(void)
336d6ad3e28SJason Wessel {
337d6ad3e28SJason Wessel }
33804c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void)
33904c9167fSJeremy Fitzhardinge {
34004c9167fSJeremy Fitzhardinge }
3418446f1d3SIngo Molnar #endif
3428446f1d3SIngo Molnar 
343e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
344e162b39aSMandeep Singh Baines extern unsigned int  sysctl_hung_task_panic;
345e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_check_count;
346e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_timeout_secs;
347e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_warnings;
348e162b39aSMandeep Singh Baines extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
3498d65af78SAlexey Dobriyan 					 void __user *buffer,
350e162b39aSMandeep Singh Baines 					 size_t *lenp, loff_t *ppos);
351e162b39aSMandeep Singh Baines #endif
3528446f1d3SIngo Molnar 
3531da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */
3541da177e4SLinus Torvalds #define __sched		__attribute__((__section__(".sched.text")))
355deaf2227SIngo Molnar 
356deaf2227SIngo Molnar /* Linker adds these: start and end of __sched functions */
357deaf2227SIngo Molnar extern char __sched_text_start[], __sched_text_end[];
358deaf2227SIngo Molnar 
3591da177e4SLinus Torvalds /* Is this address in the __sched functions? */
3601da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr);
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds #define	MAX_SCHEDULE_TIMEOUT	LONG_MAX
363b3c97528SHarvey Harrison extern signed long schedule_timeout(signed long timeout);
36464ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout);
365294d5cc2SMatthew Wilcox extern signed long schedule_timeout_killable(signed long timeout);
36664ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout);
3671da177e4SLinus Torvalds asmlinkage void schedule(void);
3680d66bf6dSPeter Zijlstra extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
3691da177e4SLinus Torvalds 
370ab516013SSerge E. Hallyn struct nsproxy;
371acce292cSCedric Le Goater struct user_namespace;
3721da177e4SLinus Torvalds 
373341c87bfSKAMEZAWA Hiroyuki /*
374341c87bfSKAMEZAWA Hiroyuki  * Default maximum number of active map areas, this limits the number of vmas
375341c87bfSKAMEZAWA Hiroyuki  * per mm struct. Users can overwrite this number by sysctl but there is a
376341c87bfSKAMEZAWA Hiroyuki  * problem.
377341c87bfSKAMEZAWA Hiroyuki  *
378341c87bfSKAMEZAWA Hiroyuki  * When a program's coredump is generated as ELF format, a section is created
379341c87bfSKAMEZAWA Hiroyuki  * per a vma. In ELF, the number of sections is represented in unsigned short.
380341c87bfSKAMEZAWA Hiroyuki  * This means the number of sections should be smaller than 65535 at coredump.
381341c87bfSKAMEZAWA Hiroyuki  * Because the kernel adds some informative sections to a image of program at
382341c87bfSKAMEZAWA Hiroyuki  * generating coredump, we need some margin. The number of extra sections is
383341c87bfSKAMEZAWA Hiroyuki  * 1-3 now and depends on arch. We use "5" as safe margin, here.
384341c87bfSKAMEZAWA Hiroyuki  */
385341c87bfSKAMEZAWA Hiroyuki #define MAPCOUNT_ELF_CORE_MARGIN	(5)
3864be929beSAlexey Dobriyan #define DEFAULT_MAX_MAP_COUNT	(USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
3871da177e4SLinus Torvalds 
3881da177e4SLinus Torvalds extern int sysctl_max_map_count;
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds #include <linux/aio.h>
3911da177e4SLinus Torvalds 
392efc1a3b1SDavid Howells #ifdef CONFIG_MMU
393efc1a3b1SDavid Howells extern void arch_pick_mmap_layout(struct mm_struct *mm);
3941da177e4SLinus Torvalds extern unsigned long
3951da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
3961da177e4SLinus Torvalds 		       unsigned long, unsigned long);
3971da177e4SLinus Torvalds extern unsigned long
3981da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
3991da177e4SLinus Torvalds 			  unsigned long len, unsigned long pgoff,
4001da177e4SLinus Torvalds 			  unsigned long flags);
4011363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long);
4021363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
403efc1a3b1SDavid Howells #else
404efc1a3b1SDavid Howells static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
405efc1a3b1SDavid Howells #endif
4061da177e4SLinus Torvalds 
407901608d9SOleg Nesterov 
4086c5d5238SKawai, Hidehiro extern void set_dumpable(struct mm_struct *mm, int value);
4096c5d5238SKawai, Hidehiro extern int get_dumpable(struct mm_struct *mm);
4106c5d5238SKawai, Hidehiro 
4116c5d5238SKawai, Hidehiro /* mm flags */
4123cb4a0bbSKawai, Hidehiro /* dumpable bits */
4136c5d5238SKawai, Hidehiro #define MMF_DUMPABLE      0  /* core dump is permitted */
4146c5d5238SKawai, Hidehiro #define MMF_DUMP_SECURELY 1  /* core file is readable only by root */
415f8af4da3SHugh Dickins 
4163cb4a0bbSKawai, Hidehiro #define MMF_DUMPABLE_BITS 2
417f8af4da3SHugh Dickins #define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1)
4183cb4a0bbSKawai, Hidehiro 
4193cb4a0bbSKawai, Hidehiro /* coredump filter bits */
4203cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_PRIVATE	2
4213cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_SHARED	3
4223cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_PRIVATE	4
4233cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_SHARED	5
42482df3973SRoland McGrath #define MMF_DUMP_ELF_HEADERS	6
425e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_PRIVATE 7
426e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_SHARED  8
427f8af4da3SHugh Dickins 
4283cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_SHIFT	MMF_DUMPABLE_BITS
429e575f111SKOSAKI Motohiro #define MMF_DUMP_FILTER_BITS	7
4303cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_MASK \
4313cb4a0bbSKawai, Hidehiro 	(((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
4323cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_DEFAULT \
433e575f111SKOSAKI Motohiro 	((1 << MMF_DUMP_ANON_PRIVATE) |	(1 << MMF_DUMP_ANON_SHARED) |\
434656eb2cdSRoland McGrath 	 (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
435656eb2cdSRoland McGrath 
436656eb2cdSRoland McGrath #ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
437656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF	(1 << MMF_DUMP_ELF_HEADERS)
438656eb2cdSRoland McGrath #else
439656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF	0
440656eb2cdSRoland McGrath #endif
441f8af4da3SHugh Dickins 					/* leave room for more dump flags */
442f8af4da3SHugh Dickins #define MMF_VM_MERGEABLE	16	/* KSM may merge identical pages */
443f8af4da3SHugh Dickins 
444f8af4da3SHugh Dickins #define MMF_INIT_MASK		(MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK)
4456c5d5238SKawai, Hidehiro 
4461da177e4SLinus Torvalds struct sighand_struct {
4471da177e4SLinus Torvalds 	atomic_t		count;
4481da177e4SLinus Torvalds 	struct k_sigaction	action[_NSIG];
4491da177e4SLinus Torvalds 	spinlock_t		siglock;
450b8fceee1SDavide Libenzi 	wait_queue_head_t	signalfd_wqh;
4511da177e4SLinus Torvalds };
4521da177e4SLinus Torvalds 
4530e464814SKaiGai Kohei struct pacct_struct {
454f6ec29a4SKaiGai Kohei 	int			ac_flag;
455f6ec29a4SKaiGai Kohei 	long			ac_exitcode;
4560e464814SKaiGai Kohei 	unsigned long		ac_mem;
45777787bfbSKaiGai Kohei 	cputime_t		ac_utime, ac_stime;
45877787bfbSKaiGai Kohei 	unsigned long		ac_minflt, ac_majflt;
4590e464814SKaiGai Kohei };
4600e464814SKaiGai Kohei 
46142c4ab41SStanislaw Gruszka struct cpu_itimer {
46242c4ab41SStanislaw Gruszka 	cputime_t expires;
46342c4ab41SStanislaw Gruszka 	cputime_t incr;
4648356b5f9SStanislaw Gruszka 	u32 error;
4658356b5f9SStanislaw Gruszka 	u32 incr_error;
46642c4ab41SStanislaw Gruszka };
46742c4ab41SStanislaw Gruszka 
468f06febc9SFrank Mayhar /**
469f06febc9SFrank Mayhar  * struct task_cputime - collected CPU time counts
470f06febc9SFrank Mayhar  * @utime:		time spent in user mode, in &cputime_t units
471f06febc9SFrank Mayhar  * @stime:		time spent in kernel mode, in &cputime_t units
472f06febc9SFrank Mayhar  * @sum_exec_runtime:	total time spent on the CPU, in nanoseconds
473f06febc9SFrank Mayhar  *
474f06febc9SFrank Mayhar  * This structure groups together three kinds of CPU time that are
475f06febc9SFrank Mayhar  * tracked for threads and thread groups.  Most things considering
476f06febc9SFrank Mayhar  * CPU time want to group these counts together and treat all three
477f06febc9SFrank Mayhar  * of them in parallel.
478f06febc9SFrank Mayhar  */
479f06febc9SFrank Mayhar struct task_cputime {
480f06febc9SFrank Mayhar 	cputime_t utime;
481f06febc9SFrank Mayhar 	cputime_t stime;
482f06febc9SFrank Mayhar 	unsigned long long sum_exec_runtime;
483f06febc9SFrank Mayhar };
484f06febc9SFrank Mayhar /* Alternate field names when used to cache expirations. */
485f06febc9SFrank Mayhar #define prof_exp	stime
486f06febc9SFrank Mayhar #define virt_exp	utime
487f06febc9SFrank Mayhar #define sched_exp	sum_exec_runtime
488f06febc9SFrank Mayhar 
4894cd4c1b4SPeter Zijlstra #define INIT_CPUTIME	\
4904cd4c1b4SPeter Zijlstra 	(struct task_cputime) {					\
4914cd4c1b4SPeter Zijlstra 		.utime = cputime_zero,				\
4924cd4c1b4SPeter Zijlstra 		.stime = cputime_zero,				\
4934cd4c1b4SPeter Zijlstra 		.sum_exec_runtime = 0,				\
4944cd4c1b4SPeter Zijlstra 	}
4954cd4c1b4SPeter Zijlstra 
496c99e6efeSPeter Zijlstra /*
497c99e6efeSPeter Zijlstra  * Disable preemption until the scheduler is running.
498c99e6efeSPeter Zijlstra  * Reset by start_kernel()->sched_init()->init_idle().
499d86ee480SPeter Zijlstra  *
500d86ee480SPeter Zijlstra  * We include PREEMPT_ACTIVE to avoid cond_resched() from working
501d86ee480SPeter Zijlstra  * before the scheduler is active -- see should_resched().
502c99e6efeSPeter Zijlstra  */
503d86ee480SPeter Zijlstra #define INIT_PREEMPT_COUNT	(1 + PREEMPT_ACTIVE)
504c99e6efeSPeter Zijlstra 
505f06febc9SFrank Mayhar /**
5064cd4c1b4SPeter Zijlstra  * struct thread_group_cputimer - thread group interval timer counts
5074cd4c1b4SPeter Zijlstra  * @cputime:		thread group interval timers.
5084cd4c1b4SPeter Zijlstra  * @running:		non-zero when there are timers running and
5094cd4c1b4SPeter Zijlstra  * 			@cputime receives updates.
5104cd4c1b4SPeter Zijlstra  * @lock:		lock for fields in this struct.
511f06febc9SFrank Mayhar  *
512f06febc9SFrank Mayhar  * This structure contains the version of task_cputime, above, that is
5134cd4c1b4SPeter Zijlstra  * used for thread group CPU timer calculations.
514f06febc9SFrank Mayhar  */
5154cd4c1b4SPeter Zijlstra struct thread_group_cputimer {
5164cd4c1b4SPeter Zijlstra 	struct task_cputime cputime;
5174cd4c1b4SPeter Zijlstra 	int running;
5184cd4c1b4SPeter Zijlstra 	spinlock_t lock;
519f06febc9SFrank Mayhar };
520f06febc9SFrank Mayhar 
5211da177e4SLinus Torvalds /*
5221da177e4SLinus Torvalds  * NOTE! "signal_struct" does not have it's own
5231da177e4SLinus Torvalds  * locking, because a shared signal_struct always
5241da177e4SLinus Torvalds  * implies a shared sighand_struct, so locking
5251da177e4SLinus Torvalds  * sighand_struct is always a proper superset of
5261da177e4SLinus Torvalds  * the locking of signal_struct.
5271da177e4SLinus Torvalds  */
5281da177e4SLinus Torvalds struct signal_struct {
529ea6d290cSOleg Nesterov 	atomic_t		sigcnt;
5301da177e4SLinus Torvalds 	atomic_t		live;
531b3ac022cSOleg Nesterov 	int			nr_threads;
5321da177e4SLinus Torvalds 
5331da177e4SLinus Torvalds 	wait_queue_head_t	wait_chldexit;	/* for wait4() */
5341da177e4SLinus Torvalds 
5351da177e4SLinus Torvalds 	/* current thread group signal load-balancing target: */
53636c8b586SIngo Molnar 	struct task_struct	*curr_target;
5371da177e4SLinus Torvalds 
5381da177e4SLinus Torvalds 	/* shared signal handling: */
5391da177e4SLinus Torvalds 	struct sigpending	shared_pending;
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds 	/* thread group exit support */
5421da177e4SLinus Torvalds 	int			group_exit_code;
5431da177e4SLinus Torvalds 	/* overloaded:
5441da177e4SLinus Torvalds 	 * - notify group_exit_task when ->count is equal to notify_count
5451da177e4SLinus Torvalds 	 * - everyone except group_exit_task is stopped during signal delivery
5461da177e4SLinus Torvalds 	 *   of fatal signals, group_exit_task processes the signal.
5471da177e4SLinus Torvalds 	 */
5481da177e4SLinus Torvalds 	int			notify_count;
54907dd20e0SRichard Kennedy 	struct task_struct	*group_exit_task;
5501da177e4SLinus Torvalds 
5511da177e4SLinus Torvalds 	/* thread group stop support, overloads group_exit_code too */
5521da177e4SLinus Torvalds 	int			group_stop_count;
5531da177e4SLinus Torvalds 	unsigned int		flags; /* see SIGNAL_* flags below */
5541da177e4SLinus Torvalds 
5551da177e4SLinus Torvalds 	/* POSIX.1b Interval Timers */
5561da177e4SLinus Torvalds 	struct list_head posix_timers;
5571da177e4SLinus Torvalds 
5581da177e4SLinus Torvalds 	/* ITIMER_REAL timer for the process */
5592ff678b8SThomas Gleixner 	struct hrtimer real_timer;
560fea9d175SOleg Nesterov 	struct pid *leader_pid;
5612ff678b8SThomas Gleixner 	ktime_t it_real_incr;
5621da177e4SLinus Torvalds 
56342c4ab41SStanislaw Gruszka 	/*
56442c4ab41SStanislaw Gruszka 	 * ITIMER_PROF and ITIMER_VIRTUAL timers for the process, we use
56542c4ab41SStanislaw Gruszka 	 * CPUCLOCK_PROF and CPUCLOCK_VIRT for indexing array as these
56642c4ab41SStanislaw Gruszka 	 * values are defined to 0 and 1 respectively
56742c4ab41SStanislaw Gruszka 	 */
56842c4ab41SStanislaw Gruszka 	struct cpu_itimer it[2];
5691da177e4SLinus Torvalds 
570f06febc9SFrank Mayhar 	/*
5714cd4c1b4SPeter Zijlstra 	 * Thread group totals for process CPU timers.
5724cd4c1b4SPeter Zijlstra 	 * See thread_group_cputimer(), et al, for details.
573f06febc9SFrank Mayhar 	 */
5744cd4c1b4SPeter Zijlstra 	struct thread_group_cputimer cputimer;
575f06febc9SFrank Mayhar 
576f06febc9SFrank Mayhar 	/* Earliest-expiration cache. */
577f06febc9SFrank Mayhar 	struct task_cputime cputime_expires;
578f06febc9SFrank Mayhar 
579f06febc9SFrank Mayhar 	struct list_head cpu_timers[3];
580f06febc9SFrank Mayhar 
581ab521dc0SEric W. Biederman 	struct pid *tty_old_pgrp;
5821ec320afSCedric Le Goater 
5831da177e4SLinus Torvalds 	/* boolean value for session group leader */
5841da177e4SLinus Torvalds 	int leader;
5851da177e4SLinus Torvalds 
5861da177e4SLinus Torvalds 	struct tty_struct *tty; /* NULL if no tty */
5871da177e4SLinus Torvalds 
5881da177e4SLinus Torvalds 	/*
5891da177e4SLinus Torvalds 	 * Cumulative resource counters for dead threads in the group,
5901da177e4SLinus Torvalds 	 * and for reaped dead child processes forked by this group.
5911da177e4SLinus Torvalds 	 * Live threads maintain their own counters and add to these
5921da177e4SLinus Torvalds 	 * in __exit_signal, except for the group leader.
5931da177e4SLinus Torvalds 	 */
59432bd671dSPeter Zijlstra 	cputime_t utime, stime, cutime, cstime;
5959ac52315SLaurent Vivier 	cputime_t gtime;
5969ac52315SLaurent Vivier 	cputime_t cgtime;
5970cf55e1eSHidetoshi Seto #ifndef CONFIG_VIRT_CPU_ACCOUNTING
5980cf55e1eSHidetoshi Seto 	cputime_t prev_utime, prev_stime;
5990cf55e1eSHidetoshi Seto #endif
6001da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
6011da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
6026eaeeabaSEric Dumazet 	unsigned long inblock, oublock, cinblock, coublock;
6031f10206cSJiri Pirko 	unsigned long maxrss, cmaxrss;
604940389b8SAndrea Righi 	struct task_io_accounting ioac;
6051da177e4SLinus Torvalds 
6061da177e4SLinus Torvalds 	/*
60732bd671dSPeter Zijlstra 	 * Cumulative ns of schedule CPU time fo dead threads in the
60832bd671dSPeter Zijlstra 	 * group, not including a zombie group leader, (This only differs
60932bd671dSPeter Zijlstra 	 * from jiffies_to_ns(utime + stime) if sched_clock uses something
61032bd671dSPeter Zijlstra 	 * other than jiffies.)
61132bd671dSPeter Zijlstra 	 */
61232bd671dSPeter Zijlstra 	unsigned long long sum_sched_runtime;
61332bd671dSPeter Zijlstra 
61432bd671dSPeter Zijlstra 	/*
6151da177e4SLinus Torvalds 	 * We don't bother to synchronize most readers of this at all,
6161da177e4SLinus Torvalds 	 * because there is no reader checking a limit that actually needs
6171da177e4SLinus Torvalds 	 * to get both rlim_cur and rlim_max atomically, and either one
6181da177e4SLinus Torvalds 	 * alone is a single word that can safely be read normally.
6191da177e4SLinus Torvalds 	 * getrlimit/setrlimit use task_lock(current->group_leader) to
6201da177e4SLinus Torvalds 	 * protect this instead of the siglock, because they really
6211da177e4SLinus Torvalds 	 * have no need to disable irqs.
6221da177e4SLinus Torvalds 	 */
6231da177e4SLinus Torvalds 	struct rlimit rlim[RLIM_NLIMITS];
6241da177e4SLinus Torvalds 
6250e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT
6260e464814SKaiGai Kohei 	struct pacct_struct pacct;	/* per-process accounting information */
6270e464814SKaiGai Kohei #endif
628ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS
629ad4ecbcbSShailabh Nagar 	struct taskstats *stats;
630ad4ecbcbSShailabh Nagar #endif
631522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT
632522ed776SMiloslav Trmac 	unsigned audit_tty;
633522ed776SMiloslav Trmac 	struct tty_audit_buf *tty_audit_buf;
634522ed776SMiloslav Trmac #endif
63528b83c51SKOSAKI Motohiro 
63628b83c51SKOSAKI Motohiro 	int oom_adj;	/* OOM kill score adjustment (bit shift) */
6371da177e4SLinus Torvalds };
6381da177e4SLinus Torvalds 
6394866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */
6404866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
6414866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW
6424866cde0SNick Piggin #endif
6434866cde0SNick Piggin 
6441da177e4SLinus Torvalds /*
6451da177e4SLinus Torvalds  * Bits in flags field of signal_struct.
6461da177e4SLinus Torvalds  */
6471da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED	0x00000001 /* job control stop in effect */
6481da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED	0x00000002 /* stop signal dequeued */
6491da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED	0x00000004 /* SIGCONT since WCONTINUED reap */
6501da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT	0x00000008 /* group exit in progress */
651e4420551SOleg Nesterov /*
652e4420551SOleg Nesterov  * Pending notifications to parent.
653e4420551SOleg Nesterov  */
654e4420551SOleg Nesterov #define SIGNAL_CLD_STOPPED	0x00000010
655e4420551SOleg Nesterov #define SIGNAL_CLD_CONTINUED	0x00000020
656e4420551SOleg Nesterov #define SIGNAL_CLD_MASK		(SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
6571da177e4SLinus Torvalds 
658fae5fa44SOleg Nesterov #define SIGNAL_UNKILLABLE	0x00000040 /* for init: ignore fatal signals */
659fae5fa44SOleg Nesterov 
660ed5d2cacSOleg Nesterov /* If true, all threads except ->group_exit_task have pending SIGKILL */
661ed5d2cacSOleg Nesterov static inline int signal_group_exit(const struct signal_struct *sig)
662ed5d2cacSOleg Nesterov {
663ed5d2cacSOleg Nesterov 	return	(sig->flags & SIGNAL_GROUP_EXIT) ||
664ed5d2cacSOleg Nesterov 		(sig->group_exit_task != NULL);
665ed5d2cacSOleg Nesterov }
666ed5d2cacSOleg Nesterov 
6671da177e4SLinus Torvalds /*
6681da177e4SLinus Torvalds  * Some day this will be a full-fledged user tracking system..
6691da177e4SLinus Torvalds  */
6701da177e4SLinus Torvalds struct user_struct {
6711da177e4SLinus Torvalds 	atomic_t __count;	/* reference count */
6721da177e4SLinus Torvalds 	atomic_t processes;	/* How many processes does this user have? */
6731da177e4SLinus Torvalds 	atomic_t files;		/* How many open files does this user have? */
6741da177e4SLinus Torvalds 	atomic_t sigpending;	/* How many pending signals does this user have? */
6752d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
6760eeca283SRobert Love 	atomic_t inotify_watches; /* How many inotify watches does this user have? */
6770eeca283SRobert Love 	atomic_t inotify_devs;	/* How many inotify devs does this user have opened? */
6780eeca283SRobert Love #endif
6797ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
6807ef9964eSDavide Libenzi 	atomic_t epoll_watches;	/* The number of file descriptors currently watched */
6817ef9964eSDavide Libenzi #endif
682970a8645SAlexey Dobriyan #ifdef CONFIG_POSIX_MQUEUE
6831da177e4SLinus Torvalds 	/* protected by mq_lock	*/
6841da177e4SLinus Torvalds 	unsigned long mq_bytes;	/* How many bytes can be allocated to mqueue? */
685970a8645SAlexey Dobriyan #endif
6861da177e4SLinus Torvalds 	unsigned long locked_shm; /* How many pages of mlocked shm ? */
6871da177e4SLinus Torvalds 
6881da177e4SLinus Torvalds #ifdef CONFIG_KEYS
6891da177e4SLinus Torvalds 	struct key *uid_keyring;	/* UID specific keyring */
6901da177e4SLinus Torvalds 	struct key *session_keyring;	/* UID's default session keyring */
6911da177e4SLinus Torvalds #endif
6921da177e4SLinus Torvalds 
6931da177e4SLinus Torvalds 	/* Hash table maintenance information */
694735de223SPavel Emelyanov 	struct hlist_node uidhash_node;
6951da177e4SLinus Torvalds 	uid_t uid;
69618b6e041SSerge Hallyn 	struct user_namespace *user_ns;
69724e377a8SSrivatsa Vaddagiri 
698cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS
699789f90fcSPeter Zijlstra 	atomic_long_t locked_vm;
700789f90fcSPeter Zijlstra #endif
7011da177e4SLinus Torvalds };
7021da177e4SLinus Torvalds 
703eb41d946SKay Sievers extern int uids_sysfs_init(void);
7045cb350baSDhaval Giani 
7051da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t);
7061da177e4SLinus Torvalds 
7071da177e4SLinus Torvalds extern struct user_struct root_user;
7081da177e4SLinus Torvalds #define INIT_USER (&root_user)
7091da177e4SLinus Torvalds 
710b6dff3ecSDavid Howells 
7111da177e4SLinus Torvalds struct backing_dev_info;
7121da177e4SLinus Torvalds struct reclaim_state;
7131da177e4SLinus Torvalds 
71452f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
7151da177e4SLinus Torvalds struct sched_info {
7161da177e4SLinus Torvalds 	/* cumulative counters */
7172d72376bSIngo Molnar 	unsigned long pcount;	      /* # of times run on this cpu */
7189c2c4802SKen Chen 	unsigned long long run_delay; /* time spent waiting on a runqueue */
7191da177e4SLinus Torvalds 
7201da177e4SLinus Torvalds 	/* timestamps */
721172ba844SBalbir Singh 	unsigned long long last_arrival,/* when we last ran on a cpu */
7221da177e4SLinus Torvalds 			   last_queued;	/* when we were last queued to run */
723b8efb561SIngo Molnar #ifdef CONFIG_SCHEDSTATS
724b8efb561SIngo Molnar 	/* BKL stats */
725480b9434SKen Chen 	unsigned int bkl_count;
726b8efb561SIngo Molnar #endif
7271da177e4SLinus Torvalds };
72852f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
7291da177e4SLinus Torvalds 
730ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT
731ca74e92bSShailabh Nagar struct task_delay_info {
732ca74e92bSShailabh Nagar 	spinlock_t	lock;
733ca74e92bSShailabh Nagar 	unsigned int	flags;	/* Private per-task flags */
734ca74e92bSShailabh Nagar 
735ca74e92bSShailabh Nagar 	/* For each stat XXX, add following, aligned appropriately
736ca74e92bSShailabh Nagar 	 *
737ca74e92bSShailabh Nagar 	 * struct timespec XXX_start, XXX_end;
738ca74e92bSShailabh Nagar 	 * u64 XXX_delay;
739ca74e92bSShailabh Nagar 	 * u32 XXX_count;
740ca74e92bSShailabh Nagar 	 *
741ca74e92bSShailabh Nagar 	 * Atomicity of updates to XXX_delay, XXX_count protected by
742ca74e92bSShailabh Nagar 	 * single lock above (split into XXX_lock if contention is an issue).
743ca74e92bSShailabh Nagar 	 */
7440ff92245SShailabh Nagar 
7450ff92245SShailabh Nagar 	/*
7460ff92245SShailabh Nagar 	 * XXX_count is incremented on every XXX operation, the delay
7470ff92245SShailabh Nagar 	 * associated with the operation is added to XXX_delay.
7480ff92245SShailabh Nagar 	 * XXX_delay contains the accumulated delay time in nanoseconds.
7490ff92245SShailabh Nagar 	 */
7500ff92245SShailabh Nagar 	struct timespec blkio_start, blkio_end;	/* Shared by blkio, swapin */
7510ff92245SShailabh Nagar 	u64 blkio_delay;	/* wait for sync block io completion */
7520ff92245SShailabh Nagar 	u64 swapin_delay;	/* wait for swapin block io completion */
7530ff92245SShailabh Nagar 	u32 blkio_count;	/* total count of the number of sync block */
7540ff92245SShailabh Nagar 				/* io operations performed */
7550ff92245SShailabh Nagar 	u32 swapin_count;	/* total count of the number of swapin block */
7560ff92245SShailabh Nagar 				/* io operations performed */
757873b4771SKeika Kobayashi 
758873b4771SKeika Kobayashi 	struct timespec freepages_start, freepages_end;
759873b4771SKeika Kobayashi 	u64 freepages_delay;	/* wait for memory reclaim */
760873b4771SKeika Kobayashi 	u32 freepages_count;	/* total count of memory reclaim */
761ca74e92bSShailabh Nagar };
76252f17b6cSChandra Seetharaman #endif	/* CONFIG_TASK_DELAY_ACCT */
76352f17b6cSChandra Seetharaman 
76452f17b6cSChandra Seetharaman static inline int sched_info_on(void)
76552f17b6cSChandra Seetharaman {
76652f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS
76752f17b6cSChandra Seetharaman 	return 1;
76852f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT)
76952f17b6cSChandra Seetharaman 	extern int delayacct_on;
77052f17b6cSChandra Seetharaman 	return delayacct_on;
77152f17b6cSChandra Seetharaman #else
77252f17b6cSChandra Seetharaman 	return 0;
773ca74e92bSShailabh Nagar #endif
77452f17b6cSChandra Seetharaman }
775ca74e92bSShailabh Nagar 
776d15bcfdbSIngo Molnar enum cpu_idle_type {
777d15bcfdbSIngo Molnar 	CPU_IDLE,
778d15bcfdbSIngo Molnar 	CPU_NOT_IDLE,
779d15bcfdbSIngo Molnar 	CPU_NEWLY_IDLE,
780d15bcfdbSIngo Molnar 	CPU_MAX_IDLE_TYPES
7811da177e4SLinus Torvalds };
7821da177e4SLinus Torvalds 
7831da177e4SLinus Torvalds /*
7841da177e4SLinus Torvalds  * sched-domains (multiprocessor balancing) declarations:
7851da177e4SLinus Torvalds  */
7869aa7b369SIngo Molnar 
7879aa7b369SIngo Molnar /*
7889aa7b369SIngo Molnar  * Increase resolution of nice-level calculations:
7899aa7b369SIngo Molnar  */
7909aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT	10
7919aa7b369SIngo Molnar #define SCHED_LOAD_SCALE	(1L << SCHED_LOAD_SHIFT)
7929aa7b369SIngo Molnar 
793f8700df7SSuresh Siddha #define SCHED_LOAD_SCALE_FUZZ	SCHED_LOAD_SCALE
7941da177e4SLinus Torvalds 
7952dd73a4fSPeter Williams #ifdef CONFIG_SMP
796b5d978e0SPeter Zijlstra #define SD_LOAD_BALANCE		0x0001	/* Do load balancing on this domain. */
797b5d978e0SPeter Zijlstra #define SD_BALANCE_NEWIDLE	0x0002	/* Balance when about to become idle */
798b5d978e0SPeter Zijlstra #define SD_BALANCE_EXEC		0x0004	/* Balance on exec */
799b5d978e0SPeter Zijlstra #define SD_BALANCE_FORK		0x0008	/* Balance on fork, clone */
800c88d5910SPeter Zijlstra #define SD_BALANCE_WAKE		0x0010  /* Balance on wakeup */
801b5d978e0SPeter Zijlstra #define SD_WAKE_AFFINE		0x0020	/* Wake task to waking CPU */
80259abf026SPeter Zijlstra #define SD_PREFER_LOCAL		0x0040  /* Prefer to keep tasks local to this domain */
803b5d978e0SPeter Zijlstra #define SD_SHARE_CPUPOWER	0x0080	/* Domain members share cpu power */
804b5d978e0SPeter Zijlstra #define SD_POWERSAVINGS_BALANCE	0x0100	/* Balance for power savings */
805b5d978e0SPeter Zijlstra #define SD_SHARE_PKG_RESOURCES	0x0200	/* Domain members share cpu pkg resources */
806b5d978e0SPeter Zijlstra #define SD_SERIALIZE		0x0400	/* Only a single load balancing instance */
807c88d5910SPeter Zijlstra 
808b5d978e0SPeter Zijlstra #define SD_PREFER_SIBLING	0x1000	/* Prefer to place tasks in a sibling domain */
8095c45bf27SSiddha, Suresh B 
810afb8a9b7SGautham R Shenoy enum powersavings_balance_level {
811afb8a9b7SGautham R Shenoy 	POWERSAVINGS_BALANCE_NONE = 0,  /* No power saving load balance */
812afb8a9b7SGautham R Shenoy 	POWERSAVINGS_BALANCE_BASIC,	/* Fill one thread/core/package
813afb8a9b7SGautham R Shenoy 					 * first for long running threads
814afb8a9b7SGautham R Shenoy 					 */
815afb8a9b7SGautham R Shenoy 	POWERSAVINGS_BALANCE_WAKEUP,	/* Also bias task wakeups to semi-idle
816afb8a9b7SGautham R Shenoy 					 * cpu package for power savings
817afb8a9b7SGautham R Shenoy 					 */
818afb8a9b7SGautham R Shenoy 	MAX_POWERSAVINGS_BALANCE_LEVELS
819afb8a9b7SGautham R Shenoy };
82089c4710eSSiddha, Suresh B 
821716707b2SVaidyanathan Srinivasan extern int sched_mc_power_savings, sched_smt_power_savings;
82289c4710eSSiddha, Suresh B 
823716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_mc_power(void)
824716707b2SVaidyanathan Srinivasan {
825716707b2SVaidyanathan Srinivasan 	if (sched_smt_power_savings)
826716707b2SVaidyanathan Srinivasan 		return SD_POWERSAVINGS_BALANCE;
8275c45bf27SSiddha, Suresh B 
82828f53181SVaidyanathan Srinivasan 	if (!sched_mc_power_savings)
829b5d978e0SPeter Zijlstra 		return SD_PREFER_SIBLING;
83028f53181SVaidyanathan Srinivasan 
83128f53181SVaidyanathan Srinivasan 	return 0;
832716707b2SVaidyanathan Srinivasan }
833716707b2SVaidyanathan Srinivasan 
834716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_package_power(void)
835716707b2SVaidyanathan Srinivasan {
836716707b2SVaidyanathan Srinivasan 	if (sched_mc_power_savings | sched_smt_power_savings)
837716707b2SVaidyanathan Srinivasan 		return SD_POWERSAVINGS_BALANCE;
838716707b2SVaidyanathan Srinivasan 
839b5d978e0SPeter Zijlstra 	return SD_PREFER_SIBLING;
840716707b2SVaidyanathan Srinivasan }
841147cbb4bSNick Piggin 
842100fdaeeSVaidyanathan Srinivasan /*
843100fdaeeSVaidyanathan Srinivasan  * Optimise SD flags for power savings:
844100fdaeeSVaidyanathan Srinivasan  * SD_BALANCE_NEWIDLE helps agressive task consolidation and power savings.
845100fdaeeSVaidyanathan Srinivasan  * Keep default SD flags if sched_{smt,mc}_power_saving=0
846100fdaeeSVaidyanathan Srinivasan  */
847100fdaeeSVaidyanathan Srinivasan 
848100fdaeeSVaidyanathan Srinivasan static inline int sd_power_saving_flags(void)
849100fdaeeSVaidyanathan Srinivasan {
850100fdaeeSVaidyanathan Srinivasan 	if (sched_mc_power_savings | sched_smt_power_savings)
851100fdaeeSVaidyanathan Srinivasan 		return SD_BALANCE_NEWIDLE;
852100fdaeeSVaidyanathan Srinivasan 
853100fdaeeSVaidyanathan Srinivasan 	return 0;
854100fdaeeSVaidyanathan Srinivasan }
8551da177e4SLinus Torvalds 
8561da177e4SLinus Torvalds struct sched_group {
8571da177e4SLinus Torvalds 	struct sched_group *next;	/* Must be a circular list */
8581da177e4SLinus Torvalds 
8591da177e4SLinus Torvalds 	/*
8601da177e4SLinus Torvalds 	 * CPU power of this group, SCHED_LOAD_SCALE being max power for a
86118a3885fSPeter Zijlstra 	 * single CPU.
8621da177e4SLinus Torvalds 	 */
86318a3885fSPeter Zijlstra 	unsigned int cpu_power;
8646c99e9adSRusty Russell 
8654200efd9SIngo Molnar 	/*
8664200efd9SIngo Molnar 	 * The CPUs this group covers.
8674200efd9SIngo Molnar 	 *
8684200efd9SIngo Molnar 	 * NOTE: this field is variable length. (Allocated dynamically
8694200efd9SIngo Molnar 	 * by attaching extra space to the end of the structure,
8704200efd9SIngo Molnar 	 * depending on how many CPUs the kernel has booted up with)
8714200efd9SIngo Molnar 	 *
8724200efd9SIngo Molnar 	 * It is also be embedded into static data structures at build
8734200efd9SIngo Molnar 	 * time. (See 'struct static_sched_group' in kernel/sched.c)
8744200efd9SIngo Molnar 	 */
8754200efd9SIngo Molnar 	unsigned long cpumask[0];
8761da177e4SLinus Torvalds };
8771da177e4SLinus Torvalds 
878758b2cdcSRusty Russell static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
879758b2cdcSRusty Russell {
8806c99e9adSRusty Russell 	return to_cpumask(sg->cpumask);
881758b2cdcSRusty Russell }
882758b2cdcSRusty Russell 
8831d3504fcSHidetoshi Seto enum sched_domain_level {
8841d3504fcSHidetoshi Seto 	SD_LV_NONE = 0,
8851d3504fcSHidetoshi Seto 	SD_LV_SIBLING,
8861d3504fcSHidetoshi Seto 	SD_LV_MC,
8871d3504fcSHidetoshi Seto 	SD_LV_CPU,
8881d3504fcSHidetoshi Seto 	SD_LV_NODE,
8891d3504fcSHidetoshi Seto 	SD_LV_ALLNODES,
8901d3504fcSHidetoshi Seto 	SD_LV_MAX
8911d3504fcSHidetoshi Seto };
8921d3504fcSHidetoshi Seto 
8931d3504fcSHidetoshi Seto struct sched_domain_attr {
8941d3504fcSHidetoshi Seto 	int relax_domain_level;
8951d3504fcSHidetoshi Seto };
8961d3504fcSHidetoshi Seto 
8971d3504fcSHidetoshi Seto #define SD_ATTR_INIT	(struct sched_domain_attr) {	\
8981d3504fcSHidetoshi Seto 	.relax_domain_level = -1,			\
8991d3504fcSHidetoshi Seto }
9001d3504fcSHidetoshi Seto 
9011da177e4SLinus Torvalds struct sched_domain {
9021da177e4SLinus Torvalds 	/* These fields must be setup */
9031da177e4SLinus Torvalds 	struct sched_domain *parent;	/* top domain must be null terminated */
9041a848870SSiddha, Suresh B 	struct sched_domain *child;	/* bottom domain must be null terminated */
9051da177e4SLinus Torvalds 	struct sched_group *groups;	/* the balancing groups of the domain */
9061da177e4SLinus Torvalds 	unsigned long min_interval;	/* Minimum balance interval ms */
9071da177e4SLinus Torvalds 	unsigned long max_interval;	/* Maximum balance interval ms */
9081da177e4SLinus Torvalds 	unsigned int busy_factor;	/* less balancing by factor if busy */
9091da177e4SLinus Torvalds 	unsigned int imbalance_pct;	/* No balance until over watermark */
9101da177e4SLinus Torvalds 	unsigned int cache_nice_tries;	/* Leave cache hot tasks for # tries */
9117897986bSNick Piggin 	unsigned int busy_idx;
9127897986bSNick Piggin 	unsigned int idle_idx;
9137897986bSNick Piggin 	unsigned int newidle_idx;
9147897986bSNick Piggin 	unsigned int wake_idx;
915147cbb4bSNick Piggin 	unsigned int forkexec_idx;
916a52bfd73SPeter Zijlstra 	unsigned int smt_gain;
9171da177e4SLinus Torvalds 	int flags;			/* See SD_* */
9181d3504fcSHidetoshi Seto 	enum sched_domain_level level;
9191da177e4SLinus Torvalds 
9201da177e4SLinus Torvalds 	/* Runtime fields. */
9211da177e4SLinus Torvalds 	unsigned long last_balance;	/* init to jiffies. units in jiffies */
9221da177e4SLinus Torvalds 	unsigned int balance_interval;	/* initialise to 1. units in ms. */
9231da177e4SLinus Torvalds 	unsigned int nr_balance_failed; /* initialise to 0 */
9241da177e4SLinus Torvalds 
9252398f2c6SPeter Zijlstra 	u64 last_update;
9262398f2c6SPeter Zijlstra 
9271da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS
9281da177e4SLinus Torvalds 	/* load_balance() stats */
929480b9434SKen Chen 	unsigned int lb_count[CPU_MAX_IDLE_TYPES];
930480b9434SKen Chen 	unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
931480b9434SKen Chen 	unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
932480b9434SKen Chen 	unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
933480b9434SKen Chen 	unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
934480b9434SKen Chen 	unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
935480b9434SKen Chen 	unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
936480b9434SKen Chen 	unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
9371da177e4SLinus Torvalds 
9381da177e4SLinus Torvalds 	/* Active load balancing */
939480b9434SKen Chen 	unsigned int alb_count;
940480b9434SKen Chen 	unsigned int alb_failed;
941480b9434SKen Chen 	unsigned int alb_pushed;
9421da177e4SLinus Torvalds 
94368767a0aSNick Piggin 	/* SD_BALANCE_EXEC stats */
944480b9434SKen Chen 	unsigned int sbe_count;
945480b9434SKen Chen 	unsigned int sbe_balanced;
946480b9434SKen Chen 	unsigned int sbe_pushed;
9471da177e4SLinus Torvalds 
94868767a0aSNick Piggin 	/* SD_BALANCE_FORK stats */
949480b9434SKen Chen 	unsigned int sbf_count;
950480b9434SKen Chen 	unsigned int sbf_balanced;
951480b9434SKen Chen 	unsigned int sbf_pushed;
95268767a0aSNick Piggin 
9531da177e4SLinus Torvalds 	/* try_to_wake_up() stats */
954480b9434SKen Chen 	unsigned int ttwu_wake_remote;
955480b9434SKen Chen 	unsigned int ttwu_move_affine;
956480b9434SKen Chen 	unsigned int ttwu_move_balance;
9571da177e4SLinus Torvalds #endif
958a5d8c348SIngo Molnar #ifdef CONFIG_SCHED_DEBUG
959a5d8c348SIngo Molnar 	char *name;
960a5d8c348SIngo Molnar #endif
9616c99e9adSRusty Russell 
962669c55e9SPeter Zijlstra 	unsigned int span_weight;
9634200efd9SIngo Molnar 	/*
9644200efd9SIngo Molnar 	 * Span of all CPUs in this domain.
9654200efd9SIngo Molnar 	 *
9664200efd9SIngo Molnar 	 * NOTE: this field is variable length. (Allocated dynamically
9674200efd9SIngo Molnar 	 * by attaching extra space to the end of the structure,
9684200efd9SIngo Molnar 	 * depending on how many CPUs the kernel has booted up with)
9694200efd9SIngo Molnar 	 *
9704200efd9SIngo Molnar 	 * It is also be embedded into static data structures at build
9714200efd9SIngo Molnar 	 * time. (See 'struct static_sched_domain' in kernel/sched.c)
9724200efd9SIngo Molnar 	 */
9734200efd9SIngo Molnar 	unsigned long span[0];
9741da177e4SLinus Torvalds };
9751da177e4SLinus Torvalds 
976758b2cdcSRusty Russell static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
977758b2cdcSRusty Russell {
9786c99e9adSRusty Russell 	return to_cpumask(sd->span);
979758b2cdcSRusty Russell }
980758b2cdcSRusty Russell 
981acc3f5d7SRusty Russell extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
9821d3504fcSHidetoshi Seto 				    struct sched_domain_attr *dattr_new);
983029190c5SPaul Jackson 
984acc3f5d7SRusty Russell /* Allocate an array of sched domains, for partition_sched_domains(). */
985acc3f5d7SRusty Russell cpumask_var_t *alloc_sched_domains(unsigned int ndoms);
986acc3f5d7SRusty Russell void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms);
987acc3f5d7SRusty Russell 
98806aaf76aSIngo Molnar /* Test a flag in parent sched domain */
98906aaf76aSIngo Molnar static inline int test_sd_parent(struct sched_domain *sd, int flag)
99006aaf76aSIngo Molnar {
99106aaf76aSIngo Molnar 	if (sd->parent && (sd->parent->flags & flag))
99206aaf76aSIngo Molnar 		return 1;
99306aaf76aSIngo Molnar 
99406aaf76aSIngo Molnar 	return 0;
99506aaf76aSIngo Molnar }
9961da177e4SLinus Torvalds 
99747fe38fcSPeter Zijlstra unsigned long default_scale_freq_power(struct sched_domain *sd, int cpu);
99847fe38fcSPeter Zijlstra unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu);
99947fe38fcSPeter Zijlstra 
10001b427c15SIngo Molnar #else /* CONFIG_SMP */
10011da177e4SLinus Torvalds 
10021b427c15SIngo Molnar struct sched_domain_attr;
10031b427c15SIngo Molnar 
10041b427c15SIngo Molnar static inline void
1005acc3f5d7SRusty Russell partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
10061b427c15SIngo Molnar 			struct sched_domain_attr *dattr_new)
1007d02c7a8cSCon Kolivas {
1008d02c7a8cSCon Kolivas }
10091b427c15SIngo Molnar #endif	/* !CONFIG_SMP */
10101da177e4SLinus Torvalds 
101147fe38fcSPeter Zijlstra 
10121da177e4SLinus Torvalds struct io_context;			/* See blkdev.h */
10131da177e4SLinus Torvalds 
10141da177e4SLinus Torvalds 
1015383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
101636c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t);
1017383f2835SChen, Kenneth W #else
1018383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { }
1019383f2835SChen, Kenneth W #endif
10201da177e4SLinus Torvalds 
10211da177e4SLinus Torvalds struct audit_context;		/* See audit.c */
10221da177e4SLinus Torvalds struct mempolicy;
1023b92ce558SJens Axboe struct pipe_inode_info;
10244865ecf1SSerge E. Hallyn struct uts_namespace;
10251da177e4SLinus Torvalds 
102620b8a59fSIngo Molnar struct rq;
102720b8a59fSIngo Molnar struct sched_domain;
102820b8a59fSIngo Molnar 
10297d478721SPeter Zijlstra /*
10307d478721SPeter Zijlstra  * wake flags
10317d478721SPeter Zijlstra  */
10327d478721SPeter Zijlstra #define WF_SYNC		0x01		/* waker goes to sleep after wakup */
1033a7558e01SPeter Zijlstra #define WF_FORK		0x02		/* child wakeup after fork */
10347d478721SPeter Zijlstra 
1035371fd7e7SPeter Zijlstra #define ENQUEUE_WAKEUP		1
1036371fd7e7SPeter Zijlstra #define ENQUEUE_WAKING		2
1037371fd7e7SPeter Zijlstra #define ENQUEUE_HEAD		4
1038371fd7e7SPeter Zijlstra 
1039371fd7e7SPeter Zijlstra #define DEQUEUE_SLEEP		1
1040371fd7e7SPeter Zijlstra 
104120b8a59fSIngo Molnar struct sched_class {
10425522d5d5SIngo Molnar 	const struct sched_class *next;
104320b8a59fSIngo Molnar 
1044371fd7e7SPeter Zijlstra 	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
1045371fd7e7SPeter Zijlstra 	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
10464530d7abSDmitry Adamushko 	void (*yield_task) (struct rq *rq);
104720b8a59fSIngo Molnar 
10487d478721SPeter Zijlstra 	void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
104920b8a59fSIngo Molnar 
1050fb8d4724SIngo Molnar 	struct task_struct * (*pick_next_task) (struct rq *rq);
105131ee529cSIngo Molnar 	void (*put_prev_task) (struct rq *rq, struct task_struct *p);
105220b8a59fSIngo Molnar 
1053681f3e68SPeter Williams #ifdef CONFIG_SMP
10540017d735SPeter Zijlstra 	int  (*select_task_rq)(struct rq *rq, struct task_struct *p,
10550017d735SPeter Zijlstra 			       int sd_flag, int flags);
10564ce72a2cSLi Zefan 
10579a897c5aSSteven Rostedt 	void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
10589a897c5aSSteven Rostedt 	void (*post_schedule) (struct rq *this_rq);
1059efbbd05aSPeter Zijlstra 	void (*task_waking) (struct rq *this_rq, struct task_struct *task);
1060efbbd05aSPeter Zijlstra 	void (*task_woken) (struct rq *this_rq, struct task_struct *task);
1061e1d1484fSPeter Williams 
1062cd8ba7cdSMike Travis 	void (*set_cpus_allowed)(struct task_struct *p,
106396f874e2SRusty Russell 				 const struct cpumask *newmask);
106457d885feSGregory Haskins 
10651f11eb6aSGregory Haskins 	void (*rq_online)(struct rq *rq);
10661f11eb6aSGregory Haskins 	void (*rq_offline)(struct rq *rq);
10674ce72a2cSLi Zefan #endif
10684ce72a2cSLi Zefan 
10694ce72a2cSLi Zefan 	void (*set_curr_task) (struct rq *rq);
10704ce72a2cSLi Zefan 	void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
1071cd29fe6fSPeter Zijlstra 	void (*task_fork) (struct task_struct *p);
1072cb469845SSteven Rostedt 
1073cb469845SSteven Rostedt 	void (*switched_from) (struct rq *this_rq, struct task_struct *task,
1074cb469845SSteven Rostedt 			       int running);
1075cb469845SSteven Rostedt 	void (*switched_to) (struct rq *this_rq, struct task_struct *task,
1076cb469845SSteven Rostedt 			     int running);
1077cb469845SSteven Rostedt 	void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
1078cb469845SSteven Rostedt 			     int oldprio, int running);
1079810b3817SPeter Zijlstra 
1080dba091b9SThomas Gleixner 	unsigned int (*get_rr_interval) (struct rq *rq,
1081dba091b9SThomas Gleixner 					 struct task_struct *task);
10820d721ceaSPeter Williams 
1083810b3817SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED
108488ec22d3SPeter Zijlstra 	void (*moved_group) (struct task_struct *p, int on_rq);
1085810b3817SPeter Zijlstra #endif
108620b8a59fSIngo Molnar };
108720b8a59fSIngo Molnar 
108820b8a59fSIngo Molnar struct load_weight {
108920b8a59fSIngo Molnar 	unsigned long weight, inv_weight;
109020b8a59fSIngo Molnar };
109120b8a59fSIngo Molnar 
109294c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS
109341acab88SLucas De Marchi struct sched_statistics {
109494c18227SIngo Molnar 	u64			wait_start;
109594c18227SIngo Molnar 	u64			wait_max;
10966d082592SArjan van de Ven 	u64			wait_count;
10976d082592SArjan van de Ven 	u64			wait_sum;
10988f0dfc34SArjan van de Ven 	u64			iowait_count;
10998f0dfc34SArjan van de Ven 	u64			iowait_sum;
110094c18227SIngo Molnar 
110194c18227SIngo Molnar 	u64			sleep_start;
110220b8a59fSIngo Molnar 	u64			sleep_max;
110394c18227SIngo Molnar 	s64			sum_sleep_runtime;
110494c18227SIngo Molnar 
110594c18227SIngo Molnar 	u64			block_start;
110620b8a59fSIngo Molnar 	u64			block_max;
110720b8a59fSIngo Molnar 	u64			exec_max;
1108eba1ed4bSIngo Molnar 	u64			slice_max;
1109cc367732SIngo Molnar 
1110cc367732SIngo Molnar 	u64			nr_migrations_cold;
1111cc367732SIngo Molnar 	u64			nr_failed_migrations_affine;
1112cc367732SIngo Molnar 	u64			nr_failed_migrations_running;
1113cc367732SIngo Molnar 	u64			nr_failed_migrations_hot;
1114cc367732SIngo Molnar 	u64			nr_forced_migrations;
1115cc367732SIngo Molnar 
1116cc367732SIngo Molnar 	u64			nr_wakeups;
1117cc367732SIngo Molnar 	u64			nr_wakeups_sync;
1118cc367732SIngo Molnar 	u64			nr_wakeups_migrate;
1119cc367732SIngo Molnar 	u64			nr_wakeups_local;
1120cc367732SIngo Molnar 	u64			nr_wakeups_remote;
1121cc367732SIngo Molnar 	u64			nr_wakeups_affine;
1122cc367732SIngo Molnar 	u64			nr_wakeups_affine_attempts;
1123cc367732SIngo Molnar 	u64			nr_wakeups_passive;
1124cc367732SIngo Molnar 	u64			nr_wakeups_idle;
112541acab88SLucas De Marchi };
112641acab88SLucas De Marchi #endif
112741acab88SLucas De Marchi 
112841acab88SLucas De Marchi struct sched_entity {
112941acab88SLucas De Marchi 	struct load_weight	load;		/* for load-balancing */
113041acab88SLucas De Marchi 	struct rb_node		run_node;
113141acab88SLucas De Marchi 	struct list_head	group_node;
113241acab88SLucas De Marchi 	unsigned int		on_rq;
113341acab88SLucas De Marchi 
113441acab88SLucas De Marchi 	u64			exec_start;
113541acab88SLucas De Marchi 	u64			sum_exec_runtime;
113641acab88SLucas De Marchi 	u64			vruntime;
113741acab88SLucas De Marchi 	u64			prev_sum_exec_runtime;
113841acab88SLucas De Marchi 
113941acab88SLucas De Marchi 	u64			nr_migrations;
114041acab88SLucas De Marchi 
114141acab88SLucas De Marchi #ifdef CONFIG_SCHEDSTATS
114241acab88SLucas De Marchi 	struct sched_statistics statistics;
114394c18227SIngo Molnar #endif
114494c18227SIngo Molnar 
114520b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED
114620b8a59fSIngo Molnar 	struct sched_entity	*parent;
114720b8a59fSIngo Molnar 	/* rq on which this entity is (to be) queued: */
114820b8a59fSIngo Molnar 	struct cfs_rq		*cfs_rq;
114920b8a59fSIngo Molnar 	/* rq "owned" by this entity/group: */
115020b8a59fSIngo Molnar 	struct cfs_rq		*my_q;
115120b8a59fSIngo Molnar #endif
115220b8a59fSIngo Molnar };
115370b97a7fSIngo Molnar 
1154fa717060SPeter Zijlstra struct sched_rt_entity {
1155fa717060SPeter Zijlstra 	struct list_head run_list;
115678f2c7dbSPeter Zijlstra 	unsigned long timeout;
1157bee367edSRichard Kennedy 	unsigned int time_slice;
11586f505b16SPeter Zijlstra 	int nr_cpus_allowed;
11596f505b16SPeter Zijlstra 
116058d6c2d7SPeter Zijlstra 	struct sched_rt_entity *back;
1161052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED
11626f505b16SPeter Zijlstra 	struct sched_rt_entity	*parent;
11636f505b16SPeter Zijlstra 	/* rq on which this entity is (to be) queued: */
11646f505b16SPeter Zijlstra 	struct rt_rq		*rt_rq;
11656f505b16SPeter Zijlstra 	/* rq "owned" by this entity/group: */
11666f505b16SPeter Zijlstra 	struct rt_rq		*my_q;
11676f505b16SPeter Zijlstra #endif
1168fa717060SPeter Zijlstra };
1169fa717060SPeter Zijlstra 
117086848966SPaul E. McKenney struct rcu_node;
117186848966SPaul E. McKenney 
11721da177e4SLinus Torvalds struct task_struct {
11731da177e4SLinus Torvalds 	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
1174f7e4217bSRoman Zippel 	void *stack;
11751da177e4SLinus Torvalds 	atomic_t usage;
117697dc32cdSWilliam Cohen 	unsigned int flags;	/* per process flags, defined below */
117797dc32cdSWilliam Cohen 	unsigned int ptrace;
11781da177e4SLinus Torvalds 
117936772092SPaolo 'Blaisorblade' Giarrusso 	int lock_depth;		/* BKL lock depth */
11801da177e4SLinus Torvalds 
11812dd73a4fSPeter Williams #ifdef CONFIG_SMP
11822dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW
11834866cde0SNick Piggin 	int oncpu;
11844866cde0SNick Piggin #endif
11852dd73a4fSPeter Williams #endif
118650e645a8SIngo Molnar 
1187b29739f9SIngo Molnar 	int prio, static_prio, normal_prio;
1188c7aceabaSRichard Kennedy 	unsigned int rt_priority;
11895522d5d5SIngo Molnar 	const struct sched_class *sched_class;
119020b8a59fSIngo Molnar 	struct sched_entity se;
1191fa717060SPeter Zijlstra 	struct sched_rt_entity rt;
11921da177e4SLinus Torvalds 
1193e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS
1194e107be36SAvi Kivity 	/* list of struct preempt_notifier: */
1195e107be36SAvi Kivity 	struct hlist_head preempt_notifiers;
1196e107be36SAvi Kivity #endif
1197e107be36SAvi Kivity 
119818796aa0SAlexey Dobriyan 	/*
119918796aa0SAlexey Dobriyan 	 * fpu_counter contains the number of consecutive context switches
120018796aa0SAlexey Dobriyan 	 * that the FPU is used. If this is over a threshold, the lazy fpu
120118796aa0SAlexey Dobriyan 	 * saving becomes unlazy to save the trap. This is an unsigned char
120218796aa0SAlexey Dobriyan 	 * so that after 256 times the counter wraps and the behavior turns
120318796aa0SAlexey Dobriyan 	 * lazy again; this to deal with bursty apps that only use FPU for
120418796aa0SAlexey Dobriyan 	 * a short time
120518796aa0SAlexey Dobriyan 	 */
120618796aa0SAlexey Dobriyan 	unsigned char fpu_counter;
12076c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE
12082056a782SJens Axboe 	unsigned int btrace_seq;
12096c5c9341SAlexey Dobriyan #endif
12101da177e4SLinus Torvalds 
121197dc32cdSWilliam Cohen 	unsigned int policy;
12121da177e4SLinus Torvalds 	cpumask_t cpus_allowed;
12131da177e4SLinus Torvalds 
1214f41d911fSPaul E. McKenney #ifdef CONFIG_TREE_PREEMPT_RCU
1215e260be67SPaul E. McKenney 	int rcu_read_lock_nesting;
1216f41d911fSPaul E. McKenney 	char rcu_read_unlock_special;
121786848966SPaul E. McKenney 	struct rcu_node *rcu_blocked_node;
1218f41d911fSPaul E. McKenney 	struct list_head rcu_node_entry;
1219f41d911fSPaul E. McKenney #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
1220e260be67SPaul E. McKenney 
122152f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
12221da177e4SLinus Torvalds 	struct sched_info sched_info;
12231da177e4SLinus Torvalds #endif
12241da177e4SLinus Torvalds 
12251da177e4SLinus Torvalds 	struct list_head tasks;
1226917b627dSGregory Haskins 	struct plist_node pushable_tasks;
12271da177e4SLinus Torvalds 
12281da177e4SLinus Torvalds 	struct mm_struct *mm, *active_mm;
122934e55232SKAMEZAWA Hiroyuki #if defined(SPLIT_RSS_COUNTING)
123034e55232SKAMEZAWA Hiroyuki 	struct task_rss_stat	rss_stat;
123134e55232SKAMEZAWA Hiroyuki #endif
12321da177e4SLinus Torvalds /* task state */
123397dc32cdSWilliam Cohen 	int exit_state;
12341da177e4SLinus Torvalds 	int exit_code, exit_signal;
12351da177e4SLinus Torvalds 	int pdeath_signal;  /*  The signal sent when the parent dies  */
12361da177e4SLinus Torvalds 	/* ??? */
123797dc32cdSWilliam Cohen 	unsigned int personality;
12381da177e4SLinus Torvalds 	unsigned did_exec:1;
1239f9ce1f1cSKentaro Takeda 	unsigned in_execve:1;	/* Tell the LSMs that the process is doing an
1240f9ce1f1cSKentaro Takeda 				 * execve */
12418f0dfc34SArjan van de Ven 	unsigned in_iowait:1;
12428f0dfc34SArjan van de Ven 
1243ca94c442SLennart Poettering 
1244ca94c442SLennart Poettering 	/* Revert to default priority/policy when forking */
1245ca94c442SLennart Poettering 	unsigned sched_reset_on_fork:1;
1246ca94c442SLennart Poettering 
12471da177e4SLinus Torvalds 	pid_t pid;
12481da177e4SLinus Torvalds 	pid_t tgid;
12490a425405SArjan van de Ven 
12501314562aSHiroshi Shimamoto #ifdef CONFIG_CC_STACKPROTECTOR
12510a425405SArjan van de Ven 	/* Canary value for the -fstack-protector gcc feature */
12520a425405SArjan van de Ven 	unsigned long stack_canary;
12531314562aSHiroshi Shimamoto #endif
1254e0032087SIngo Molnar 
12551da177e4SLinus Torvalds 	/*
12561da177e4SLinus Torvalds 	 * pointers to (original) parent process, youngest child, younger sibling,
12571da177e4SLinus Torvalds 	 * older sibling, respectively.  (p->father can be replaced with
1258f470021aSRoland McGrath 	 * p->real_parent->pid)
12591da177e4SLinus Torvalds 	 */
1260f470021aSRoland McGrath 	struct task_struct *real_parent; /* real parent process */
1261f470021aSRoland McGrath 	struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports */
12621da177e4SLinus Torvalds 	/*
1263f470021aSRoland McGrath 	 * children/sibling forms the list of my natural children
12641da177e4SLinus Torvalds 	 */
12651da177e4SLinus Torvalds 	struct list_head children;	/* list of my children */
12661da177e4SLinus Torvalds 	struct list_head sibling;	/* linkage in my parent's children list */
12671da177e4SLinus Torvalds 	struct task_struct *group_leader;	/* threadgroup leader */
12681da177e4SLinus Torvalds 
1269f470021aSRoland McGrath 	/*
1270f470021aSRoland McGrath 	 * ptraced is the list of tasks this task is using ptrace on.
1271f470021aSRoland McGrath 	 * This includes both natural children and PTRACE_ATTACH targets.
1272f470021aSRoland McGrath 	 * p->ptrace_entry is p's link on the p->parent->ptraced list.
1273f470021aSRoland McGrath 	 */
1274f470021aSRoland McGrath 	struct list_head ptraced;
1275f470021aSRoland McGrath 	struct list_head ptrace_entry;
1276f470021aSRoland McGrath 
12771da177e4SLinus Torvalds 	/* PID/PID hash table linkage. */
127892476d7fSEric W. Biederman 	struct pid_link pids[PIDTYPE_MAX];
127947e65328SOleg Nesterov 	struct list_head thread_group;
12801da177e4SLinus Torvalds 
12811da177e4SLinus Torvalds 	struct completion *vfork_done;		/* for vfork() */
12821da177e4SLinus Torvalds 	int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
12831da177e4SLinus Torvalds 	int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */
12841da177e4SLinus Torvalds 
1285c66f08beSMichael Neuling 	cputime_t utime, stime, utimescaled, stimescaled;
12869ac52315SLaurent Vivier 	cputime_t gtime;
1287d99ca3b9SHidetoshi Seto #ifndef CONFIG_VIRT_CPU_ACCOUNTING
12889301899bSBalbir Singh 	cputime_t prev_utime, prev_stime;
1289d99ca3b9SHidetoshi Seto #endif
12901da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw; /* context switch counts */
1291924b42d5STomas Janousek 	struct timespec start_time; 		/* monotonic time */
1292924b42d5STomas Janousek 	struct timespec real_start_time;	/* boot based time */
12931da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
12941da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt;
12951da177e4SLinus Torvalds 
1296f06febc9SFrank Mayhar 	struct task_cputime cputime_expires;
12971da177e4SLinus Torvalds 	struct list_head cpu_timers[3];
12981da177e4SLinus Torvalds 
12991da177e4SLinus Torvalds /* process credentials */
13003b11a1deSDavid Howells 	const struct cred *real_cred;	/* objective and real subjective task
13013b11a1deSDavid Howells 					 * credentials (COW) */
13023b11a1deSDavid Howells 	const struct cred *cred;	/* effective (overridable) subjective task
13033b11a1deSDavid Howells 					 * credentials (COW) */
13045e751e99SDavid Howells 	struct mutex cred_guard_mutex;	/* guard against foreign influences on
13055e751e99SDavid Howells 					 * credential calculations
13065e751e99SDavid Howells 					 * (notably. ptrace) */
1307ee18d64cSDavid Howells 	struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
1308b6dff3ecSDavid Howells 
130936772092SPaolo 'Blaisorblade' Giarrusso 	char comm[TASK_COMM_LEN]; /* executable name excluding path
131036772092SPaolo 'Blaisorblade' Giarrusso 				     - access with [gs]et_task_comm (which lock
131136772092SPaolo 'Blaisorblade' Giarrusso 				       it with task_lock())
1312221af7f8SLinus Torvalds 				     - initialized normally by setup_new_exec */
13131da177e4SLinus Torvalds /* file system info */
13141da177e4SLinus Torvalds 	int link_count, total_link_count;
13153d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC
13161da177e4SLinus Torvalds /* ipc stuff */
13171da177e4SLinus Torvalds 	struct sysv_sem sysvsem;
13183d5b6fccSAlexey Dobriyan #endif
1319e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
132082a1fcb9SIngo Molnar /* hung task detection */
132182a1fcb9SIngo Molnar 	unsigned long last_switch_count;
132282a1fcb9SIngo Molnar #endif
13231da177e4SLinus Torvalds /* CPU-specific state of this task */
13241da177e4SLinus Torvalds 	struct thread_struct thread;
13251da177e4SLinus Torvalds /* filesystem information */
13261da177e4SLinus Torvalds 	struct fs_struct *fs;
13271da177e4SLinus Torvalds /* open file information */
13281da177e4SLinus Torvalds 	struct files_struct *files;
13291651e14eSSerge E. Hallyn /* namespaces */
1330ab516013SSerge E. Hallyn 	struct nsproxy *nsproxy;
13311da177e4SLinus Torvalds /* signal handlers */
13321da177e4SLinus Torvalds 	struct signal_struct *signal;
13331da177e4SLinus Torvalds 	struct sighand_struct *sighand;
13341da177e4SLinus Torvalds 
13351da177e4SLinus Torvalds 	sigset_t blocked, real_blocked;
1336f3de272bSRoland McGrath 	sigset_t saved_sigmask;	/* restored if set_restore_sigmask() was used */
13371da177e4SLinus Torvalds 	struct sigpending pending;
13381da177e4SLinus Torvalds 
13391da177e4SLinus Torvalds 	unsigned long sas_ss_sp;
13401da177e4SLinus Torvalds 	size_t sas_ss_size;
13411da177e4SLinus Torvalds 	int (*notifier)(void *priv);
13421da177e4SLinus Torvalds 	void *notifier_data;
13431da177e4SLinus Torvalds 	sigset_t *notifier_mask;
13441da177e4SLinus Torvalds 	struct audit_context *audit_context;
1345bfef93a5SAl Viro #ifdef CONFIG_AUDITSYSCALL
1346bfef93a5SAl Viro 	uid_t loginuid;
13474746ec5bSEric Paris 	unsigned int sessionid;
1348bfef93a5SAl Viro #endif
13491da177e4SLinus Torvalds 	seccomp_t seccomp;
13501da177e4SLinus Torvalds 
13511da177e4SLinus Torvalds /* Thread group tracking */
13521da177e4SLinus Torvalds    	u32 parent_exec_id;
13531da177e4SLinus Torvalds    	u32 self_exec_id;
135458568d2aSMiao Xie /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
135558568d2aSMiao Xie  * mempolicy */
13561da177e4SLinus Torvalds 	spinlock_t alloc_lock;
13571da177e4SLinus Torvalds 
13583aa551c9SThomas Gleixner #ifdef CONFIG_GENERIC_HARDIRQS
13593aa551c9SThomas Gleixner 	/* IRQ handler threads */
13603aa551c9SThomas Gleixner 	struct irqaction *irqaction;
13613aa551c9SThomas Gleixner #endif
13623aa551c9SThomas Gleixner 
1363b29739f9SIngo Molnar 	/* Protection of the PI data structures: */
13641d615482SThomas Gleixner 	raw_spinlock_t pi_lock;
1365b29739f9SIngo Molnar 
136623f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
136723f78d4aSIngo Molnar 	/* PI waiters blocked on a rt_mutex held by this task */
136823f78d4aSIngo Molnar 	struct plist_head pi_waiters;
136923f78d4aSIngo Molnar 	/* Deadlock detection and priority inheritance handling */
137023f78d4aSIngo Molnar 	struct rt_mutex_waiter *pi_blocked_on;
137123f78d4aSIngo Molnar #endif
137223f78d4aSIngo Molnar 
1373408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES
1374408894eeSIngo Molnar 	/* mutex deadlock detection */
1375408894eeSIngo Molnar 	struct mutex_waiter *blocked_on;
1376408894eeSIngo Molnar #endif
1377de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS
1378de30a2b3SIngo Molnar 	unsigned int irq_events;
1379de30a2b3SIngo Molnar 	unsigned long hardirq_enable_ip;
1380de30a2b3SIngo Molnar 	unsigned long hardirq_disable_ip;
1381fa1452e8SHiroshi Shimamoto 	unsigned int hardirq_enable_event;
1382de30a2b3SIngo Molnar 	unsigned int hardirq_disable_event;
1383fa1452e8SHiroshi Shimamoto 	int hardirqs_enabled;
1384de30a2b3SIngo Molnar 	int hardirq_context;
1385fa1452e8SHiroshi Shimamoto 	unsigned long softirq_disable_ip;
1386fa1452e8SHiroshi Shimamoto 	unsigned long softirq_enable_ip;
1387fa1452e8SHiroshi Shimamoto 	unsigned int softirq_disable_event;
1388fa1452e8SHiroshi Shimamoto 	unsigned int softirq_enable_event;
1389fa1452e8SHiroshi Shimamoto 	int softirqs_enabled;
1390de30a2b3SIngo Molnar 	int softirq_context;
1391de30a2b3SIngo Molnar #endif
1392fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP
1393bdb9441eSPeter Zijlstra # define MAX_LOCK_DEPTH 48UL
1394fbb9ce95SIngo Molnar 	u64 curr_chain_key;
1395fbb9ce95SIngo Molnar 	int lockdep_depth;
1396fbb9ce95SIngo Molnar 	unsigned int lockdep_recursion;
1397c7aceabaSRichard Kennedy 	struct held_lock held_locks[MAX_LOCK_DEPTH];
1398cf40bd16SNick Piggin 	gfp_t lockdep_reclaim_gfp;
1399fbb9ce95SIngo Molnar #endif
1400408894eeSIngo Molnar 
14011da177e4SLinus Torvalds /* journalling filesystem info */
14021da177e4SLinus Torvalds 	void *journal_info;
14031da177e4SLinus Torvalds 
1404d89d8796SNeil Brown /* stacked block device info */
1405bddd87c7SAkinobu Mita 	struct bio_list *bio_list;
1406d89d8796SNeil Brown 
14071da177e4SLinus Torvalds /* VM state */
14081da177e4SLinus Torvalds 	struct reclaim_state *reclaim_state;
14091da177e4SLinus Torvalds 
14101da177e4SLinus Torvalds 	struct backing_dev_info *backing_dev_info;
14111da177e4SLinus Torvalds 
14121da177e4SLinus Torvalds 	struct io_context *io_context;
14131da177e4SLinus Torvalds 
14141da177e4SLinus Torvalds 	unsigned long ptrace_message;
14151da177e4SLinus Torvalds 	siginfo_t *last_siginfo; /* For ptrace use.  */
14167c3ab738SAndrew Morton 	struct task_io_accounting ioac;
14178f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT)
14181da177e4SLinus Torvalds 	u64 acct_rss_mem1;	/* accumulated rss usage */
14191da177e4SLinus Torvalds 	u64 acct_vm_mem1;	/* accumulated virtual memory usage */
142049b5cf34SJonathan Lim 	cputime_t acct_timexpd;	/* stime + utime since last update */
14211da177e4SLinus Torvalds #endif
14221da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS
142358568d2aSMiao Xie 	nodemask_t mems_allowed;	/* Protected by alloc_lock */
1424c0ff7453SMiao Xie 	int mems_allowed_change_disable;
1425825a46afSPaul Jackson 	int cpuset_mem_spread_rotor;
14266adef3ebSJack Steiner 	int cpuset_slab_spread_rotor;
14271da177e4SLinus Torvalds #endif
1428ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS
1429817929ecSPaul Menage 	/* Control Group info protected by css_set_lock */
1430817929ecSPaul Menage 	struct css_set *cgroups;
1431817929ecSPaul Menage 	/* cg_list protected by css_set_lock and tsk->alloc_lock */
1432817929ecSPaul Menage 	struct list_head cg_list;
1433ddbcc7e8SPaul Menage #endif
143442b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX
14350771dfefSIngo Molnar 	struct robust_list_head __user *robust_list;
143634f192c6SIngo Molnar #ifdef CONFIG_COMPAT
143734f192c6SIngo Molnar 	struct compat_robust_list_head __user *compat_robust_list;
143834f192c6SIngo Molnar #endif
1439c87e2837SIngo Molnar 	struct list_head pi_state_list;
1440c87e2837SIngo Molnar 	struct futex_pi_state *pi_state_cache;
144142b2dd0aSAlexey Dobriyan #endif
1442cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS
1443cdd6c482SIngo Molnar 	struct perf_event_context *perf_event_ctxp;
1444cdd6c482SIngo Molnar 	struct mutex perf_event_mutex;
1445cdd6c482SIngo Molnar 	struct list_head perf_event_list;
1446a63eaf34SPaul Mackerras #endif
1447c7aceabaSRichard Kennedy #ifdef CONFIG_NUMA
144858568d2aSMiao Xie 	struct mempolicy *mempolicy;	/* Protected by alloc_lock */
1449c7aceabaSRichard Kennedy 	short il_next;
1450c7aceabaSRichard Kennedy #endif
145122e2c507SJens Axboe 	atomic_t fs_excl;	/* holding fs exclusive resources */
1452e56d0903SIngo Molnar 	struct rcu_head rcu;
1453b92ce558SJens Axboe 
1454b92ce558SJens Axboe 	/*
1455b92ce558SJens Axboe 	 * cache last used pipe for splice
1456b92ce558SJens Axboe 	 */
1457b92ce558SJens Axboe 	struct pipe_inode_info *splice_pipe;
1458ca74e92bSShailabh Nagar #ifdef	CONFIG_TASK_DELAY_ACCT
1459ca74e92bSShailabh Nagar 	struct task_delay_info *delays;
1460ca74e92bSShailabh Nagar #endif
1461f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION
1462f4f154fdSAkinobu Mita 	int make_it_fail;
1463f4f154fdSAkinobu Mita #endif
14643e26c149SPeter Zijlstra 	struct prop_local_single dirties;
14659745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
14669745512cSArjan van de Ven 	int latency_record_count;
14679745512cSArjan van de Ven 	struct latency_record latency_record[LT_SAVECOUNT];
14689745512cSArjan van de Ven #endif
14696976675dSArjan van de Ven 	/*
14706976675dSArjan van de Ven 	 * time slack values; these are used to round up poll() and
14716976675dSArjan van de Ven 	 * select() etc timeout values. These are in nanoseconds.
14726976675dSArjan van de Ven 	 */
14736976675dSArjan van de Ven 	unsigned long timer_slack_ns;
14746976675dSArjan van de Ven 	unsigned long default_timer_slack_ns;
1475f8d570a4SDavid Miller 
1476f8d570a4SDavid Miller 	struct list_head	*scm_work_list;
1477fb52607aSFrederic Weisbecker #ifdef CONFIG_FUNCTION_GRAPH_TRACER
14783ad2f3fbSDaniel Mack 	/* Index of current stored address in ret_stack */
1479f201ae23SFrederic Weisbecker 	int curr_ret_stack;
1480f201ae23SFrederic Weisbecker 	/* Stack of return addresses for return function tracing */
1481f201ae23SFrederic Weisbecker 	struct ftrace_ret_stack	*ret_stack;
14828aef2d28SSteven Rostedt 	/* time stamp for last schedule */
14838aef2d28SSteven Rostedt 	unsigned long long ftrace_timestamp;
1484f201ae23SFrederic Weisbecker 	/*
1485f201ae23SFrederic Weisbecker 	 * Number of functions that haven't been traced
1486f201ae23SFrederic Weisbecker 	 * because of depth overrun.
1487f201ae23SFrederic Weisbecker 	 */
1488f201ae23SFrederic Weisbecker 	atomic_t trace_overrun;
1489380c4b14SFrederic Weisbecker 	/* Pause for the tracing */
1490380c4b14SFrederic Weisbecker 	atomic_t tracing_graph_pause;
1491f201ae23SFrederic Weisbecker #endif
1492ea4e2bc4SSteven Rostedt #ifdef CONFIG_TRACING
1493ea4e2bc4SSteven Rostedt 	/* state flags for use by tracers */
1494ea4e2bc4SSteven Rostedt 	unsigned long trace;
1495261842b7SSteven Rostedt 	/* bitmask of trace recursion */
1496261842b7SSteven Rostedt 	unsigned long trace_recursion;
1497261842b7SSteven Rostedt #endif /* CONFIG_TRACING */
1498569b846dSKAMEZAWA Hiroyuki #ifdef CONFIG_CGROUP_MEM_RES_CTLR /* memcg uses this to do batch job */
1499569b846dSKAMEZAWA Hiroyuki 	struct memcg_batch_info {
1500569b846dSKAMEZAWA Hiroyuki 		int do_batch;	/* incremented when batch uncharge started */
1501569b846dSKAMEZAWA Hiroyuki 		struct mem_cgroup *memcg; /* target memcg of uncharge */
1502569b846dSKAMEZAWA Hiroyuki 		unsigned long bytes; 		/* uncharged usage */
1503569b846dSKAMEZAWA Hiroyuki 		unsigned long memsw_bytes; /* uncharged mem+swap usage */
1504569b846dSKAMEZAWA Hiroyuki 	} memcg_batch;
1505569b846dSKAMEZAWA Hiroyuki #endif
15061da177e4SLinus Torvalds };
15071da177e4SLinus Torvalds 
150876e6eee0SRusty Russell /* Future-safe accessor for struct task_struct's cpus_allowed. */
1509a4636818SRusty Russell #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
151076e6eee0SRusty Russell 
1511e05606d3SIngo Molnar /*
1512e05606d3SIngo Molnar  * Priority of a process goes from 0..MAX_PRIO-1, valid RT
1513e05606d3SIngo Molnar  * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
1514e05606d3SIngo Molnar  * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
1515e05606d3SIngo Molnar  * values are inverted: lower p->prio value means higher priority.
1516e05606d3SIngo Molnar  *
1517e05606d3SIngo Molnar  * The MAX_USER_RT_PRIO value allows the actual maximum
1518e05606d3SIngo Molnar  * RT priority to be separate from the value exported to
1519e05606d3SIngo Molnar  * user-space.  This allows kernel threads to set their
1520e05606d3SIngo Molnar  * priority to a value higher than any user task. Note:
1521e05606d3SIngo Molnar  * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
1522e05606d3SIngo Molnar  */
1523e05606d3SIngo Molnar 
1524e05606d3SIngo Molnar #define MAX_USER_RT_PRIO	100
1525e05606d3SIngo Molnar #define MAX_RT_PRIO		MAX_USER_RT_PRIO
1526e05606d3SIngo Molnar 
1527e05606d3SIngo Molnar #define MAX_PRIO		(MAX_RT_PRIO + 40)
1528e05606d3SIngo Molnar #define DEFAULT_PRIO		(MAX_RT_PRIO + 20)
1529e05606d3SIngo Molnar 
1530e05606d3SIngo Molnar static inline int rt_prio(int prio)
1531e05606d3SIngo Molnar {
1532e05606d3SIngo Molnar 	if (unlikely(prio < MAX_RT_PRIO))
1533e05606d3SIngo Molnar 		return 1;
1534e05606d3SIngo Molnar 	return 0;
1535e05606d3SIngo Molnar }
1536e05606d3SIngo Molnar 
1537e868171aSAlexey Dobriyan static inline int rt_task(struct task_struct *p)
1538e05606d3SIngo Molnar {
1539e05606d3SIngo Molnar 	return rt_prio(p->prio);
1540e05606d3SIngo Molnar }
1541e05606d3SIngo Molnar 
1542e868171aSAlexey Dobriyan static inline struct pid *task_pid(struct task_struct *task)
154322c935f4SEric W. Biederman {
154422c935f4SEric W. Biederman 	return task->pids[PIDTYPE_PID].pid;
154522c935f4SEric W. Biederman }
154622c935f4SEric W. Biederman 
1547e868171aSAlexey Dobriyan static inline struct pid *task_tgid(struct task_struct *task)
154822c935f4SEric W. Biederman {
154922c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PID].pid;
155022c935f4SEric W. Biederman }
155122c935f4SEric W. Biederman 
15526dda81f4SOleg Nesterov /*
15536dda81f4SOleg Nesterov  * Without tasklist or rcu lock it is not safe to dereference
15546dda81f4SOleg Nesterov  * the result of task_pgrp/task_session even if task == current,
15556dda81f4SOleg Nesterov  * we can race with another thread doing sys_setsid/sys_setpgid.
15566dda81f4SOleg Nesterov  */
1557e868171aSAlexey Dobriyan static inline struct pid *task_pgrp(struct task_struct *task)
155822c935f4SEric W. Biederman {
155922c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PGID].pid;
156022c935f4SEric W. Biederman }
156122c935f4SEric W. Biederman 
1562e868171aSAlexey Dobriyan static inline struct pid *task_session(struct task_struct *task)
156322c935f4SEric W. Biederman {
156422c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_SID].pid;
156522c935f4SEric W. Biederman }
156622c935f4SEric W. Biederman 
15677af57294SPavel Emelyanov struct pid_namespace;
15687af57294SPavel Emelyanov 
15697af57294SPavel Emelyanov /*
15707af57294SPavel Emelyanov  * the helpers to get the task's different pids as they are seen
15717af57294SPavel Emelyanov  * from various namespaces
15727af57294SPavel Emelyanov  *
15737af57294SPavel Emelyanov  * task_xid_nr()     : global id, i.e. the id seen from the init namespace;
157444c4e1b2SEric W. Biederman  * task_xid_vnr()    : virtual id, i.e. the id seen from the pid namespace of
157544c4e1b2SEric W. Biederman  *                     current.
15767af57294SPavel Emelyanov  * task_xid_nr_ns()  : id seen from the ns specified;
15777af57294SPavel Emelyanov  *
15787af57294SPavel Emelyanov  * set_task_vxid()   : assigns a virtual id to a task;
15797af57294SPavel Emelyanov  *
15807af57294SPavel Emelyanov  * see also pid_nr() etc in include/linux/pid.h
15817af57294SPavel Emelyanov  */
158252ee2dfdSOleg Nesterov pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
158352ee2dfdSOleg Nesterov 			struct pid_namespace *ns);
15847af57294SPavel Emelyanov 
1585e868171aSAlexey Dobriyan static inline pid_t task_pid_nr(struct task_struct *tsk)
15867af57294SPavel Emelyanov {
15877af57294SPavel Emelyanov 	return tsk->pid;
15887af57294SPavel Emelyanov }
15897af57294SPavel Emelyanov 
159052ee2dfdSOleg Nesterov static inline pid_t task_pid_nr_ns(struct task_struct *tsk,
159152ee2dfdSOleg Nesterov 					struct pid_namespace *ns)
159252ee2dfdSOleg Nesterov {
159352ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
159452ee2dfdSOleg Nesterov }
15957af57294SPavel Emelyanov 
15967af57294SPavel Emelyanov static inline pid_t task_pid_vnr(struct task_struct *tsk)
15977af57294SPavel Emelyanov {
159852ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
15997af57294SPavel Emelyanov }
16007af57294SPavel Emelyanov 
16017af57294SPavel Emelyanov 
1602e868171aSAlexey Dobriyan static inline pid_t task_tgid_nr(struct task_struct *tsk)
16037af57294SPavel Emelyanov {
16047af57294SPavel Emelyanov 	return tsk->tgid;
16057af57294SPavel Emelyanov }
16067af57294SPavel Emelyanov 
16072f2a3a46SPavel Emelyanov pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
16087af57294SPavel Emelyanov 
16097af57294SPavel Emelyanov static inline pid_t task_tgid_vnr(struct task_struct *tsk)
16107af57294SPavel Emelyanov {
16117af57294SPavel Emelyanov 	return pid_vnr(task_tgid(tsk));
16127af57294SPavel Emelyanov }
16137af57294SPavel Emelyanov 
16147af57294SPavel Emelyanov 
161552ee2dfdSOleg Nesterov static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk,
161652ee2dfdSOleg Nesterov 					struct pid_namespace *ns)
16177af57294SPavel Emelyanov {
161852ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
16197af57294SPavel Emelyanov }
16207af57294SPavel Emelyanov 
16217af57294SPavel Emelyanov static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
16227af57294SPavel Emelyanov {
162352ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
16247af57294SPavel Emelyanov }
16257af57294SPavel Emelyanov 
16267af57294SPavel Emelyanov 
162752ee2dfdSOleg Nesterov static inline pid_t task_session_nr_ns(struct task_struct *tsk,
162852ee2dfdSOleg Nesterov 					struct pid_namespace *ns)
16297af57294SPavel Emelyanov {
163052ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
16317af57294SPavel Emelyanov }
16327af57294SPavel Emelyanov 
16337af57294SPavel Emelyanov static inline pid_t task_session_vnr(struct task_struct *tsk)
16347af57294SPavel Emelyanov {
163552ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
16367af57294SPavel Emelyanov }
16377af57294SPavel Emelyanov 
16381b0f7ffdSOleg Nesterov /* obsolete, do not use */
16391b0f7ffdSOleg Nesterov static inline pid_t task_pgrp_nr(struct task_struct *tsk)
16401b0f7ffdSOleg Nesterov {
16411b0f7ffdSOleg Nesterov 	return task_pgrp_nr_ns(tsk, &init_pid_ns);
16421b0f7ffdSOleg Nesterov }
16437af57294SPavel Emelyanov 
16441da177e4SLinus Torvalds /**
16451da177e4SLinus Torvalds  * pid_alive - check that a task structure is not stale
16461da177e4SLinus Torvalds  * @p: Task structure to be checked.
16471da177e4SLinus Torvalds  *
16481da177e4SLinus Torvalds  * Test if a process is not yet dead (at most zombie state)
16491da177e4SLinus Torvalds  * If pid_alive fails, then pointers within the task structure
16501da177e4SLinus Torvalds  * can be stale and must not be dereferenced.
16511da177e4SLinus Torvalds  */
1652e868171aSAlexey Dobriyan static inline int pid_alive(struct task_struct *p)
16531da177e4SLinus Torvalds {
165492476d7fSEric W. Biederman 	return p->pids[PIDTYPE_PID].pid != NULL;
16551da177e4SLinus Torvalds }
16561da177e4SLinus Torvalds 
1657f400e198SSukadev Bhattiprolu /**
1658b460cbc5SSerge E. Hallyn  * is_global_init - check if a task structure is init
16593260259fSHenne  * @tsk: Task structure to be checked.
16603260259fSHenne  *
16613260259fSHenne  * Check if a task structure is the first user space task the kernel created.
1662f400e198SSukadev Bhattiprolu  */
1663e868171aSAlexey Dobriyan static inline int is_global_init(struct task_struct *tsk)
1664b461cc03SPavel Emelyanov {
1665b461cc03SPavel Emelyanov 	return tsk->pid == 1;
1666b461cc03SPavel Emelyanov }
1667b460cbc5SSerge E. Hallyn 
1668b460cbc5SSerge E. Hallyn /*
1669b460cbc5SSerge E. Hallyn  * is_container_init:
1670b460cbc5SSerge E. Hallyn  * check whether in the task is init in its own pid namespace.
1671b460cbc5SSerge E. Hallyn  */
1672b461cc03SPavel Emelyanov extern int is_container_init(struct task_struct *tsk);
1673f400e198SSukadev Bhattiprolu 
16749ec52099SCedric Le Goater extern struct pid *cad_pid;
16759ec52099SCedric Le Goater 
16761da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk);
16771da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
1678e56d0903SIngo Molnar 
1679158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t);
1680e56d0903SIngo Molnar 
1681e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t)
1682e56d0903SIngo Molnar {
1683e56d0903SIngo Molnar 	if (atomic_dec_and_test(&t->usage))
16848c7904a0SEric W. Biederman 		__put_task_struct(t);
1685e56d0903SIngo Molnar }
16861da177e4SLinus Torvalds 
1687d180c5bcSHidetoshi Seto extern void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st);
16880cf55e1eSHidetoshi Seto extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st);
168949048622SBalbir Singh 
16901da177e4SLinus Torvalds /*
16911da177e4SLinus Torvalds  * Per process flags
16921da177e4SLinus Torvalds  */
16931da177e4SLinus Torvalds #define PF_ALIGNWARN	0x00000001	/* Print alignment warning msgs */
16941da177e4SLinus Torvalds 					/* Not implemented yet, only for 486*/
16951da177e4SLinus Torvalds #define PF_STARTING	0x00000002	/* being created */
16961da177e4SLinus Torvalds #define PF_EXITING	0x00000004	/* getting shut down */
1697778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
169894886b84SLaurent Vivier #define PF_VCPU		0x00000010	/* I'm a virtual CPU */
1699*21aa9af0STejun Heo #define PF_WQ_WORKER	0x00000020	/* I'm a workqueue worker */
17001da177e4SLinus Torvalds #define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
17014db96cf0SAndi Kleen #define PF_MCE_PROCESS  0x00000080      /* process policy on mce errors */
17021da177e4SLinus Torvalds #define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
17031da177e4SLinus Torvalds #define PF_DUMPCORE	0x00000200	/* dumped core */
17041da177e4SLinus Torvalds #define PF_SIGNALED	0x00000400	/* killed by a signal */
17051da177e4SLinus Torvalds #define PF_MEMALLOC	0x00000800	/* Allocating memory */
17061da177e4SLinus Torvalds #define PF_FLUSHER	0x00001000	/* responsible for disk writeback */
17071da177e4SLinus Torvalds #define PF_USED_MATH	0x00002000	/* if unset the fpu must be initialized before use */
17086301cb95SThomas Gleixner #define PF_FREEZING	0x00004000	/* freeze in progress. do not account to load */
17091da177e4SLinus Torvalds #define PF_NOFREEZE	0x00008000	/* this thread should not be frozen */
17101da177e4SLinus Torvalds #define PF_FROZEN	0x00010000	/* frozen for system suspend */
17111da177e4SLinus Torvalds #define PF_FSTRANS	0x00020000	/* inside a filesystem transaction */
17121da177e4SLinus Torvalds #define PF_KSWAPD	0x00040000	/* I am kswapd */
171335451beeSHugh Dickins #define PF_OOM_ORIGIN	0x00080000	/* Allocating much memory to others */
17141da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000	/* Throttle me less: I clean memory */
1715246bb0b1SOleg Nesterov #define PF_KTHREAD	0x00200000	/* I am a kernel thread */
1716b31dc66aSJens Axboe #define PF_RANDOMIZE	0x00400000	/* randomize virtual address space */
1717b31dc66aSJens Axboe #define PF_SWAPWRITE	0x00800000	/* Allowed to write to swap */
1718b31dc66aSJens Axboe #define PF_SPREAD_PAGE	0x01000000	/* Spread page cache over cpuset */
1719b31dc66aSJens Axboe #define PF_SPREAD_SLAB	0x02000000	/* Spread some slab caches over cpuset */
17209985b0baSDavid Rientjes #define PF_THREAD_BOUND	0x04000000	/* Thread bound to specific cpu */
17214db96cf0SAndi Kleen #define PF_MCE_EARLY    0x08000000      /* Early kill for mce process policy */
1722c61afb18SPaul Jackson #define PF_MEMPOLICY	0x10000000	/* Non-default NUMA mempolicy */
172361a87122SThomas Gleixner #define PF_MUTEX_TESTER	0x20000000	/* Thread belongs to the rt mutex tester */
1724ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP	0x40000000	/* Freezer should not count it as freezeable */
1725ebb12db5SRafael J. Wysocki #define PF_FREEZER_NOSIG 0x80000000	/* Freezer won't send signals to it */
17261da177e4SLinus Torvalds 
17271da177e4SLinus Torvalds /*
17281da177e4SLinus Torvalds  * Only the _current_ task can read/write to tsk->flags, but other
17291da177e4SLinus Torvalds  * tasks can access tsk->flags in readonly mode for example
17301da177e4SLinus Torvalds  * with tsk_used_math (like during threaded core dumping).
17311da177e4SLinus Torvalds  * There is however an exception to this rule during ptrace
17321da177e4SLinus Torvalds  * or during fork: the ptracer task is allowed to write to the
17331da177e4SLinus Torvalds  * child->flags of its traced child (same goes for fork, the parent
17341da177e4SLinus Torvalds  * can write to the child->flags), because we're guaranteed the
17351da177e4SLinus Torvalds  * child is not running and in turn not changing child->flags
17361da177e4SLinus Torvalds  * at the same time the parent does it.
17371da177e4SLinus Torvalds  */
17381da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
17391da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
17401da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current)
17411da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current)
17421da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \
17431da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
17441da177e4SLinus Torvalds #define conditional_used_math(condition) \
17451da177e4SLinus Torvalds 	conditional_stopped_child_used_math(condition, current)
17461da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \
17471da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
17481da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
17491da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
17501da177e4SLinus Torvalds #define used_math() tsk_used_math(current)
17511da177e4SLinus Torvalds 
1752f41d911fSPaul E. McKenney #ifdef CONFIG_TREE_PREEMPT_RCU
1753f41d911fSPaul E. McKenney 
1754f41d911fSPaul E. McKenney #define RCU_READ_UNLOCK_BLOCKED (1 << 0) /* blocked while in RCU read-side. */
1755f41d911fSPaul E. McKenney #define RCU_READ_UNLOCK_NEED_QS (1 << 1) /* RCU core needs CPU response. */
1756f41d911fSPaul E. McKenney 
1757f41d911fSPaul E. McKenney static inline void rcu_copy_process(struct task_struct *p)
1758f41d911fSPaul E. McKenney {
1759f41d911fSPaul E. McKenney 	p->rcu_read_lock_nesting = 0;
1760f41d911fSPaul E. McKenney 	p->rcu_read_unlock_special = 0;
1761dd5d19baSPaul E. McKenney 	p->rcu_blocked_node = NULL;
1762f41d911fSPaul E. McKenney 	INIT_LIST_HEAD(&p->rcu_node_entry);
1763f41d911fSPaul E. McKenney }
1764f41d911fSPaul E. McKenney 
1765f41d911fSPaul E. McKenney #else
1766f41d911fSPaul E. McKenney 
1767f41d911fSPaul E. McKenney static inline void rcu_copy_process(struct task_struct *p)
1768f41d911fSPaul E. McKenney {
1769f41d911fSPaul E. McKenney }
1770f41d911fSPaul E. McKenney 
1771f41d911fSPaul E. McKenney #endif
1772f41d911fSPaul E. McKenney 
17731da177e4SLinus Torvalds #ifdef CONFIG_SMP
1774cd8ba7cdSMike Travis extern int set_cpus_allowed_ptr(struct task_struct *p,
177596f874e2SRusty Russell 				const struct cpumask *new_mask);
17761da177e4SLinus Torvalds #else
1777cd8ba7cdSMike Travis static inline int set_cpus_allowed_ptr(struct task_struct *p,
177896f874e2SRusty Russell 				       const struct cpumask *new_mask)
17791da177e4SLinus Torvalds {
178096f874e2SRusty Russell 	if (!cpumask_test_cpu(0, new_mask))
17811da177e4SLinus Torvalds 		return -EINVAL;
17821da177e4SLinus Torvalds 	return 0;
17831da177e4SLinus Torvalds }
17841da177e4SLinus Torvalds #endif
1785e0ad9556SRusty Russell 
1786e0ad9556SRusty Russell #ifndef CONFIG_CPUMASK_OFFSTACK
1787cd8ba7cdSMike Travis static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
1788cd8ba7cdSMike Travis {
1789cd8ba7cdSMike Travis 	return set_cpus_allowed_ptr(p, &new_mask);
1790cd8ba7cdSMike Travis }
1791e0ad9556SRusty Russell #endif
17921da177e4SLinus Torvalds 
1793b342501cSIngo Molnar /*
1794b342501cSIngo Molnar  * Architectures can set this to 1 if they have specified
1795b342501cSIngo Molnar  * CONFIG_HAVE_UNSTABLE_SCHED_CLOCK in their arch Kconfig,
1796b342501cSIngo Molnar  * but then during bootup it turns out that sched_clock()
1797b342501cSIngo Molnar  * is reliable after all:
1798b342501cSIngo Molnar  */
1799b342501cSIngo Molnar #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
1800b342501cSIngo Molnar extern int sched_clock_stable;
1801b342501cSIngo Molnar #endif
1802b342501cSIngo Molnar 
18031bbfa6f2SMike Frysinger /* ftrace calls sched_clock() directly */
18041bbfa6f2SMike Frysinger extern unsigned long long notrace sched_clock(void);
1805e436d800SIngo Molnar 
1806c1955a3dSPeter Zijlstra extern void sched_clock_init(void);
1807c1955a3dSPeter Zijlstra extern u64 sched_clock_cpu(int cpu);
1808c1955a3dSPeter Zijlstra 
18093e51f33fSPeter Zijlstra #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
18103e51f33fSPeter Zijlstra static inline void sched_clock_tick(void)
18113e51f33fSPeter Zijlstra {
18123e51f33fSPeter Zijlstra }
18133e51f33fSPeter Zijlstra 
18143e51f33fSPeter Zijlstra static inline void sched_clock_idle_sleep_event(void)
18153e51f33fSPeter Zijlstra {
18163e51f33fSPeter Zijlstra }
18173e51f33fSPeter Zijlstra 
18183e51f33fSPeter Zijlstra static inline void sched_clock_idle_wakeup_event(u64 delta_ns)
18193e51f33fSPeter Zijlstra {
18203e51f33fSPeter Zijlstra }
18213e51f33fSPeter Zijlstra #else
18223e51f33fSPeter Zijlstra extern void sched_clock_tick(void);
18233e51f33fSPeter Zijlstra extern void sched_clock_idle_sleep_event(void);
18243e51f33fSPeter Zijlstra extern void sched_clock_idle_wakeup_event(u64 delta_ns);
18253e51f33fSPeter Zijlstra #endif
18263e51f33fSPeter Zijlstra 
1827e436d800SIngo Molnar /*
1828e436d800SIngo Molnar  * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
1829e436d800SIngo Molnar  * clock constructed from sched_clock():
1830e436d800SIngo Molnar  */
1831e436d800SIngo Molnar extern unsigned long long cpu_clock(int cpu);
1832e436d800SIngo Molnar 
183336c8b586SIngo Molnar extern unsigned long long
183441b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task);
1835f06febc9SFrank Mayhar extern unsigned long long thread_group_sched_runtime(struct task_struct *task);
18361da177e4SLinus Torvalds 
18371da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */
18381da177e4SLinus Torvalds #ifdef CONFIG_SMP
18391da177e4SLinus Torvalds extern void sched_exec(void);
18401da177e4SLinus Torvalds #else
18411da177e4SLinus Torvalds #define sched_exec()   {}
18421da177e4SLinus Torvalds #endif
18431da177e4SLinus Torvalds 
18442aa44d05SIngo Molnar extern void sched_clock_idle_sleep_event(void);
18452aa44d05SIngo Molnar extern void sched_clock_idle_wakeup_event(u64 delta_ns);
1846bb29ab26SIngo Molnar 
18471da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU
18486a1bdc1bSOleg Nesterov extern void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p);
18491da177e4SLinus Torvalds extern void idle_task_exit(void);
18501da177e4SLinus Torvalds #else
18511da177e4SLinus Torvalds static inline void idle_task_exit(void) {}
18521da177e4SLinus Torvalds #endif
18531da177e4SLinus Torvalds 
18541da177e4SLinus Torvalds extern void sched_idle_next(void);
1855b29739f9SIngo Molnar 
185606d8308cSThomas Gleixner #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
185706d8308cSThomas Gleixner extern void wake_up_idle_cpu(int cpu);
185806d8308cSThomas Gleixner #else
185906d8308cSThomas Gleixner static inline void wake_up_idle_cpu(int cpu) { }
186006d8308cSThomas Gleixner #endif
186106d8308cSThomas Gleixner 
186221805085SPeter Zijlstra extern unsigned int sysctl_sched_latency;
1863b2be5e96SPeter Zijlstra extern unsigned int sysctl_sched_min_granularity;
1864bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity;
186547fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_ratelimit;
186647fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_thresh;
1867bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first;
18681983a922SChristian Ehrhardt 
18691983a922SChristian Ehrhardt enum sched_tunable_scaling {
18701983a922SChristian Ehrhardt 	SCHED_TUNABLESCALING_NONE,
18711983a922SChristian Ehrhardt 	SCHED_TUNABLESCALING_LOG,
18721983a922SChristian Ehrhardt 	SCHED_TUNABLESCALING_LINEAR,
18731983a922SChristian Ehrhardt 	SCHED_TUNABLESCALING_END,
18741983a922SChristian Ehrhardt };
18751983a922SChristian Ehrhardt extern enum sched_tunable_scaling sysctl_sched_tunable_scaling;
18761983a922SChristian Ehrhardt 
18772bba22c5SMike Galbraith #ifdef CONFIG_SCHED_DEBUG
1878da84d961SIngo Molnar extern unsigned int sysctl_sched_migration_cost;
1879b82d9fddSPeter Zijlstra extern unsigned int sysctl_sched_nr_migrate;
1880e9e9250bSPeter Zijlstra extern unsigned int sysctl_sched_time_avg;
1881cd1bb94bSArun R Bharadwaj extern unsigned int sysctl_timer_migration;
1882b2be5e96SPeter Zijlstra 
18831983a922SChristian Ehrhardt int sched_proc_update_handler(struct ctl_table *table, int write,
18848d65af78SAlexey Dobriyan 		void __user *buffer, size_t *length,
1885b2be5e96SPeter Zijlstra 		loff_t *ppos);
18862bd8e6d4SIngo Molnar #endif
1887eea08f32SArun R Bharadwaj #ifdef CONFIG_SCHED_DEBUG
1888eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void)
1889eea08f32SArun R Bharadwaj {
1890eea08f32SArun R Bharadwaj 	return sysctl_timer_migration;
1891eea08f32SArun R Bharadwaj }
1892eea08f32SArun R Bharadwaj #else
1893eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void)
1894eea08f32SArun R Bharadwaj {
1895eea08f32SArun R Bharadwaj 	return 1;
1896eea08f32SArun R Bharadwaj }
1897eea08f32SArun R Bharadwaj #endif
18989f0c1e56SPeter Zijlstra extern unsigned int sysctl_sched_rt_period;
18999f0c1e56SPeter Zijlstra extern int sysctl_sched_rt_runtime;
19002bd8e6d4SIngo Molnar 
1901d0b27fa7SPeter Zijlstra int sched_rt_handler(struct ctl_table *table, int write,
19028d65af78SAlexey Dobriyan 		void __user *buffer, size_t *lenp,
1903d0b27fa7SPeter Zijlstra 		loff_t *ppos);
1904d0b27fa7SPeter Zijlstra 
19052bd8e6d4SIngo Molnar extern unsigned int sysctl_sched_compat_yield;
1906bf0f6f24SIngo Molnar 
1907b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES
190836c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p);
190936c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio);
191036c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p);
1911b29739f9SIngo Molnar #else
1912e868171aSAlexey Dobriyan static inline int rt_mutex_getprio(struct task_struct *p)
1913b29739f9SIngo Molnar {
1914b29739f9SIngo Molnar 	return p->normal_prio;
1915b29739f9SIngo Molnar }
191695e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p)		do { } while (0)
1917b29739f9SIngo Molnar #endif
1918b29739f9SIngo Molnar 
191936c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice);
192036c8b586SIngo Molnar extern int task_prio(const struct task_struct *p);
192136c8b586SIngo Molnar extern int task_nice(const struct task_struct *p);
192236c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice);
192336c8b586SIngo Molnar extern int task_curr(const struct task_struct *p);
19241da177e4SLinus Torvalds extern int idle_cpu(int cpu);
19251da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
1926961ccdddSRusty Russell extern int sched_setscheduler_nocheck(struct task_struct *, int,
1927961ccdddSRusty Russell 				      struct sched_param *);
192836c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu);
192936c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu);
193036c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p);
19311da177e4SLinus Torvalds 
19321da177e4SLinus Torvalds void yield(void);
19331da177e4SLinus Torvalds 
19341da177e4SLinus Torvalds /*
19351da177e4SLinus Torvalds  * The default (Linux) execution domain.
19361da177e4SLinus Torvalds  */
19371da177e4SLinus Torvalds extern struct exec_domain	default_exec_domain;
19381da177e4SLinus Torvalds 
19391da177e4SLinus Torvalds union thread_union {
19401da177e4SLinus Torvalds 	struct thread_info thread_info;
19411da177e4SLinus Torvalds 	unsigned long stack[THREAD_SIZE/sizeof(long)];
19421da177e4SLinus Torvalds };
19431da177e4SLinus Torvalds 
19441da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END
19451da177e4SLinus Torvalds static inline int kstack_end(void *addr)
19461da177e4SLinus Torvalds {
19471da177e4SLinus Torvalds 	/* Reliable end of stack detection:
19481da177e4SLinus Torvalds 	 * Some APM bios versions misalign the stack
19491da177e4SLinus Torvalds 	 */
19501da177e4SLinus Torvalds 	return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
19511da177e4SLinus Torvalds }
19521da177e4SLinus Torvalds #endif
19531da177e4SLinus Torvalds 
19541da177e4SLinus Torvalds extern union thread_union init_thread_union;
19551da177e4SLinus Torvalds extern struct task_struct init_task;
19561da177e4SLinus Torvalds 
19571da177e4SLinus Torvalds extern struct   mm_struct init_mm;
19581da177e4SLinus Torvalds 
1959198fe21bSPavel Emelyanov extern struct pid_namespace init_pid_ns;
1960198fe21bSPavel Emelyanov 
1961198fe21bSPavel Emelyanov /*
1962198fe21bSPavel Emelyanov  * find a task by one of its numerical ids
1963198fe21bSPavel Emelyanov  *
1964198fe21bSPavel Emelyanov  * find_task_by_pid_ns():
1965198fe21bSPavel Emelyanov  *      finds a task by its pid in the specified namespace
1966228ebcbeSPavel Emelyanov  * find_task_by_vpid():
1967228ebcbeSPavel Emelyanov  *      finds a task by its virtual pid
1968198fe21bSPavel Emelyanov  *
1969e49859e7SPavel Emelyanov  * see also find_vpid() etc in include/linux/pid.h
1970198fe21bSPavel Emelyanov  */
1971198fe21bSPavel Emelyanov 
1972228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_vpid(pid_t nr);
1973228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid_ns(pid_t nr,
1974228ebcbeSPavel Emelyanov 		struct pid_namespace *ns);
1975198fe21bSPavel Emelyanov 
19768520d7c7SOleg Nesterov extern void __set_special_pids(struct pid *pid);
19771da177e4SLinus Torvalds 
19781da177e4SLinus Torvalds /* per-UID process charging. */
1979acce292cSCedric Le Goater extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
19801da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u)
19811da177e4SLinus Torvalds {
19821da177e4SLinus Torvalds 	atomic_inc(&u->__count);
19831da177e4SLinus Torvalds 	return u;
19841da177e4SLinus Torvalds }
19851da177e4SLinus Torvalds extern void free_uid(struct user_struct *);
198628f300d2SPavel Emelyanov extern void release_uids(struct user_namespace *ns);
19871da177e4SLinus Torvalds 
19881da177e4SLinus Torvalds #include <asm/current.h>
19891da177e4SLinus Torvalds 
19903171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks);
19911da177e4SLinus Torvalds 
1992b3c97528SHarvey Harrison extern int wake_up_state(struct task_struct *tsk, unsigned int state);
1993b3c97528SHarvey Harrison extern int wake_up_process(struct task_struct *tsk);
1994b3c97528SHarvey Harrison extern void wake_up_new_task(struct task_struct *tsk,
1995b3c97528SHarvey Harrison 				unsigned long clone_flags);
19961da177e4SLinus Torvalds #ifdef CONFIG_SMP
19971da177e4SLinus Torvalds  extern void kick_process(struct task_struct *tsk);
19981da177e4SLinus Torvalds #else
19991da177e4SLinus Torvalds  static inline void kick_process(struct task_struct *tsk) { }
20001da177e4SLinus Torvalds #endif
2001ad46c2c4SIngo Molnar extern void sched_fork(struct task_struct *p, int clone_flags);
2002ad46c2c4SIngo Molnar extern void sched_dead(struct task_struct *p);
20031da177e4SLinus Torvalds 
20041da177e4SLinus Torvalds extern void proc_caches_init(void);
20051da177e4SLinus Torvalds extern void flush_signals(struct task_struct *);
20063bcac026SDavid Howells extern void __flush_signals(struct task_struct *);
200710ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *);
20081da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default);
20091da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
20101da177e4SLinus Torvalds 
20111da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
20121da177e4SLinus Torvalds {
20131da177e4SLinus Torvalds 	unsigned long flags;
20141da177e4SLinus Torvalds 	int ret;
20151da177e4SLinus Torvalds 
20161da177e4SLinus Torvalds 	spin_lock_irqsave(&tsk->sighand->siglock, flags);
20171da177e4SLinus Torvalds 	ret = dequeue_signal(tsk, mask, info);
20181da177e4SLinus Torvalds 	spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
20191da177e4SLinus Torvalds 
20201da177e4SLinus Torvalds 	return ret;
20211da177e4SLinus Torvalds }
20221da177e4SLinus Torvalds 
20231da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv,
20241da177e4SLinus Torvalds 			      sigset_t *mask);
20251da177e4SLinus Torvalds extern void unblock_all_signals(void);
20261da177e4SLinus Torvalds extern void release_task(struct task_struct * p);
20271da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *);
20281da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *);
20291da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *);
2030c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
2031c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
20322425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32);
2033c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv);
2034c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv);
2035c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t);
20362b2a1ff6SRoland McGrath extern int do_notify_parent(struct task_struct *, int);
2037a7f0765eSOleg Nesterov extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent);
20381da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *);
20391da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int);
204009faef11SOleg Nesterov extern int zap_other_threads(struct task_struct *p);
20411da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void);
20421da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *);
2043ac5c2153SOleg Nesterov extern int send_sigqueue(struct sigqueue *,  struct task_struct *, int group);
20449ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
20451da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
20461da177e4SLinus Torvalds 
20479ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv)
20489ec52099SCedric Le Goater {
20499ec52099SCedric Le Goater 	return kill_pid(cad_pid, sig, priv);
20509ec52099SCedric Le Goater }
20519ec52099SCedric Le Goater 
20521da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info.  */
20531da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0)
20541da177e4SLinus Torvalds #define SEND_SIG_PRIV	((struct siginfo *) 1)
20551da177e4SLinus Torvalds #define SEND_SIG_FORCED	((struct siginfo *) 2)
20561da177e4SLinus Torvalds 
20572a855dd0SSebastian Andrzej Siewior /*
20582a855dd0SSebastian Andrzej Siewior  * True if we are on the alternate signal stack.
20592a855dd0SSebastian Andrzej Siewior  */
20601da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp)
20611da177e4SLinus Torvalds {
20622a855dd0SSebastian Andrzej Siewior #ifdef CONFIG_STACK_GROWSUP
20632a855dd0SSebastian Andrzej Siewior 	return sp >= current->sas_ss_sp &&
20642a855dd0SSebastian Andrzej Siewior 		sp - current->sas_ss_sp < current->sas_ss_size;
20652a855dd0SSebastian Andrzej Siewior #else
20662a855dd0SSebastian Andrzej Siewior 	return sp > current->sas_ss_sp &&
20672a855dd0SSebastian Andrzej Siewior 		sp - current->sas_ss_sp <= current->sas_ss_size;
20682a855dd0SSebastian Andrzej Siewior #endif
20691da177e4SLinus Torvalds }
20701da177e4SLinus Torvalds 
20711da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp)
20721da177e4SLinus Torvalds {
20731da177e4SLinus Torvalds 	return (current->sas_ss_size == 0 ? SS_DISABLE
20741da177e4SLinus Torvalds 		: on_sig_stack(sp) ? SS_ONSTACK : 0);
20751da177e4SLinus Torvalds }
20761da177e4SLinus Torvalds 
20771da177e4SLinus Torvalds /*
20781da177e4SLinus Torvalds  * Routines for handling mm_structs
20791da177e4SLinus Torvalds  */
20801da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void);
20811da177e4SLinus Torvalds 
20821da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */
2083b3c97528SHarvey Harrison extern void __mmdrop(struct mm_struct *);
20841da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm)
20851da177e4SLinus Torvalds {
20866fb43d7bSIngo Molnar 	if (unlikely(atomic_dec_and_test(&mm->mm_count)))
20871da177e4SLinus Torvalds 		__mmdrop(mm);
20881da177e4SLinus Torvalds }
20891da177e4SLinus Torvalds 
20901da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */
20911da177e4SLinus Torvalds extern void mmput(struct mm_struct *);
20921da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */
20931da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task);
20941da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */
20951da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *);
2096402b0862SCarsten Otte /* Allocate a new mm structure and copy contents from tsk->mm */
2097402b0862SCarsten Otte extern struct mm_struct *dup_mm(struct task_struct *tsk);
20981da177e4SLinus Torvalds 
20996f2c55b8SAlexey Dobriyan extern int copy_thread(unsigned long, unsigned long, unsigned long,
21006f2c55b8SAlexey Dobriyan 			struct task_struct *, struct pt_regs *);
21011da177e4SLinus Torvalds extern void flush_thread(void);
21021da177e4SLinus Torvalds extern void exit_thread(void);
21031da177e4SLinus Torvalds 
21041da177e4SLinus Torvalds extern void exit_files(struct task_struct *);
2105a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *);
2106cbaffba1SOleg Nesterov 
21071da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *);
2108cbaffba1SOleg Nesterov extern void flush_itimer_signals(void);
21091da177e4SLinus Torvalds 
21101da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int);
21111da177e4SLinus Torvalds 
21121da177e4SLinus Torvalds extern void daemonize(const char *, ...);
21131da177e4SLinus Torvalds extern int allow_signal(int);
21141da177e4SLinus Torvalds extern int disallow_signal(int);
21151da177e4SLinus Torvalds 
21161da177e4SLinus Torvalds extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
21171da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
211836c8b586SIngo Molnar struct task_struct *fork_idle(int);
21191da177e4SLinus Torvalds 
21201da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from);
212159714d65SAndrew Morton extern char *get_task_comm(char *to, struct task_struct *tsk);
21221da177e4SLinus Torvalds 
21231da177e4SLinus Torvalds #ifdef CONFIG_SMP
212485ba2d86SRoland McGrath extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
21251da177e4SLinus Torvalds #else
212685ba2d86SRoland McGrath static inline unsigned long wait_task_inactive(struct task_struct *p,
212785ba2d86SRoland McGrath 					       long match_state)
212885ba2d86SRoland McGrath {
212985ba2d86SRoland McGrath 	return 1;
213085ba2d86SRoland McGrath }
21311da177e4SLinus Torvalds #endif
21321da177e4SLinus Torvalds 
213305725f7eSJiri Pirko #define next_task(p) \
213405725f7eSJiri Pirko 	list_entry_rcu((p)->tasks.next, struct task_struct, tasks)
21351da177e4SLinus Torvalds 
21361da177e4SLinus Torvalds #define for_each_process(p) \
21371da177e4SLinus Torvalds 	for (p = &init_task ; (p = next_task(p)) != &init_task ; )
21381da177e4SLinus Torvalds 
21395bb459bbSOleg Nesterov extern bool current_is_single_threaded(void);
2140d84f4f99SDavid Howells 
21411da177e4SLinus Torvalds /*
21421da177e4SLinus Torvalds  * Careful: do_each_thread/while_each_thread is a double loop so
21431da177e4SLinus Torvalds  *          'break' will not work as expected - use goto instead.
21441da177e4SLinus Torvalds  */
21451da177e4SLinus Torvalds #define do_each_thread(g, t) \
21461da177e4SLinus Torvalds 	for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
21471da177e4SLinus Torvalds 
21481da177e4SLinus Torvalds #define while_each_thread(g, t) \
21491da177e4SLinus Torvalds 	while ((t = next_thread(t)) != g)
21501da177e4SLinus Torvalds 
21517e49827cSOleg Nesterov static inline int get_nr_threads(struct task_struct *tsk)
21527e49827cSOleg Nesterov {
2153b3ac022cSOleg Nesterov 	return tsk->signal->nr_threads;
21547e49827cSOleg Nesterov }
21557e49827cSOleg Nesterov 
2156de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */
2157de12a787SEric W. Biederman #define thread_group_leader(p)	(p == p->group_leader)
21581da177e4SLinus Torvalds 
21590804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process
21600804ef4bSEric W. Biederman  * to have the pid of the thread group leader without actually being
21610804ef4bSEric W. Biederman  * the thread group leader.  For iteration through the pids in proc
21620804ef4bSEric W. Biederman  * all we care about is that we have a task with the appropriate
21630804ef4bSEric W. Biederman  * pid, we don't actually care if we have the right task.
21640804ef4bSEric W. Biederman  */
2165e868171aSAlexey Dobriyan static inline int has_group_leader_pid(struct task_struct *p)
21660804ef4bSEric W. Biederman {
21670804ef4bSEric W. Biederman 	return p->pid == p->tgid;
21680804ef4bSEric W. Biederman }
21690804ef4bSEric W. Biederman 
2170bac0abd6SPavel Emelyanov static inline
2171bac0abd6SPavel Emelyanov int same_thread_group(struct task_struct *p1, struct task_struct *p2)
2172bac0abd6SPavel Emelyanov {
2173bac0abd6SPavel Emelyanov 	return p1->tgid == p2->tgid;
2174bac0abd6SPavel Emelyanov }
2175bac0abd6SPavel Emelyanov 
217636c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p)
217747e65328SOleg Nesterov {
217805725f7eSJiri Pirko 	return list_entry_rcu(p->thread_group.next,
217936c8b586SIngo Molnar 			      struct task_struct, thread_group);
218047e65328SOleg Nesterov }
218147e65328SOleg Nesterov 
2182e868171aSAlexey Dobriyan static inline int thread_group_empty(struct task_struct *p)
21831da177e4SLinus Torvalds {
218447e65328SOleg Nesterov 	return list_empty(&p->thread_group);
21851da177e4SLinus Torvalds }
21861da177e4SLinus Torvalds 
21871da177e4SLinus Torvalds #define delay_group_leader(p) \
21881da177e4SLinus Torvalds 		(thread_group_leader(p) && !thread_group_empty(p))
21891da177e4SLinus Torvalds 
219039c626aeSOleg Nesterov static inline int task_detached(struct task_struct *p)
219139c626aeSOleg Nesterov {
219239c626aeSOleg Nesterov 	return p->exit_signal == -1;
219339c626aeSOleg Nesterov }
219439c626aeSOleg Nesterov 
21951da177e4SLinus Torvalds /*
2196260ea101SEric W. Biederman  * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
219722e2c507SJens Axboe  * subscriptions and synchronises with wait4().  Also used in procfs.  Also
2198ddbcc7e8SPaul Menage  * pins the final release of task.io_context.  Also protects ->cpuset and
2199ddbcc7e8SPaul Menage  * ->cgroup.subsys[].
22001da177e4SLinus Torvalds  *
22011da177e4SLinus Torvalds  * Nests both inside and outside of read_lock(&tasklist_lock).
22021da177e4SLinus Torvalds  * It must not be nested with write_lock_irq(&tasklist_lock),
22031da177e4SLinus Torvalds  * neither inside nor outside.
22041da177e4SLinus Torvalds  */
22051da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p)
22061da177e4SLinus Torvalds {
22071da177e4SLinus Torvalds 	spin_lock(&p->alloc_lock);
22081da177e4SLinus Torvalds }
22091da177e4SLinus Torvalds 
22101da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p)
22111da177e4SLinus Torvalds {
22121da177e4SLinus Torvalds 	spin_unlock(&p->alloc_lock);
22131da177e4SLinus Torvalds }
22141da177e4SLinus Torvalds 
2215f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
2216f63ee72eSOleg Nesterov 							unsigned long *flags);
2217f63ee72eSOleg Nesterov 
2218f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk,
2219f63ee72eSOleg Nesterov 						unsigned long *flags)
2220f63ee72eSOleg Nesterov {
2221f63ee72eSOleg Nesterov 	spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
2222f63ee72eSOleg Nesterov }
2223f63ee72eSOleg Nesterov 
2224f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS
2225f037360fSAl Viro 
2226f7e4217bSRoman Zippel #define task_thread_info(task)	((struct thread_info *)(task)->stack)
2227f7e4217bSRoman Zippel #define task_stack_page(task)	((task)->stack)
2228a1261f54SAl Viro 
222910ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
223010ebffdeSAl Viro {
223110ebffdeSAl Viro 	*task_thread_info(p) = *task_thread_info(org);
223210ebffdeSAl Viro 	task_thread_info(p)->task = p;
223310ebffdeSAl Viro }
223410ebffdeSAl Viro 
223510ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p)
223610ebffdeSAl Viro {
2237f7e4217bSRoman Zippel 	return (unsigned long *)(task_thread_info(p) + 1);
223810ebffdeSAl Viro }
223910ebffdeSAl Viro 
2240f037360fSAl Viro #endif
2241f037360fSAl Viro 
22428b05c7e6SFUJITA Tomonori static inline int object_is_on_stack(void *obj)
22438b05c7e6SFUJITA Tomonori {
22448b05c7e6SFUJITA Tomonori 	void *stack = task_stack_page(current);
22458b05c7e6SFUJITA Tomonori 
22468b05c7e6SFUJITA Tomonori 	return (obj >= stack) && (obj < (stack + THREAD_SIZE));
22478b05c7e6SFUJITA Tomonori }
22488b05c7e6SFUJITA Tomonori 
22498c9843e5SBenjamin Herrenschmidt extern void thread_info_cache_init(void);
22508c9843e5SBenjamin Herrenschmidt 
22517c9f8861SEric Sandeen #ifdef CONFIG_DEBUG_STACK_USAGE
22527c9f8861SEric Sandeen static inline unsigned long stack_not_used(struct task_struct *p)
22537c9f8861SEric Sandeen {
22547c9f8861SEric Sandeen 	unsigned long *n = end_of_stack(p);
22557c9f8861SEric Sandeen 
22567c9f8861SEric Sandeen 	do { 	/* Skip over canary */
22577c9f8861SEric Sandeen 		n++;
22587c9f8861SEric Sandeen 	} while (!*n);
22597c9f8861SEric Sandeen 
22607c9f8861SEric Sandeen 	return (unsigned long)n - (unsigned long)end_of_stack(p);
22617c9f8861SEric Sandeen }
22627c9f8861SEric Sandeen #endif
22637c9f8861SEric Sandeen 
22641da177e4SLinus Torvalds /* set thread flags in other task's structures
22651da177e4SLinus Torvalds  * - see asm/thread_info.h for TIF_xxxx flags available
22661da177e4SLinus Torvalds  */
22671da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
22681da177e4SLinus Torvalds {
2269a1261f54SAl Viro 	set_ti_thread_flag(task_thread_info(tsk), flag);
22701da177e4SLinus Torvalds }
22711da177e4SLinus Torvalds 
22721da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
22731da177e4SLinus Torvalds {
2274a1261f54SAl Viro 	clear_ti_thread_flag(task_thread_info(tsk), flag);
22751da177e4SLinus Torvalds }
22761da177e4SLinus Torvalds 
22771da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
22781da177e4SLinus Torvalds {
2279a1261f54SAl Viro 	return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
22801da177e4SLinus Torvalds }
22811da177e4SLinus Torvalds 
22821da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
22831da177e4SLinus Torvalds {
2284a1261f54SAl Viro 	return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
22851da177e4SLinus Torvalds }
22861da177e4SLinus Torvalds 
22871da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
22881da177e4SLinus Torvalds {
2289a1261f54SAl Viro 	return test_ti_thread_flag(task_thread_info(tsk), flag);
22901da177e4SLinus Torvalds }
22911da177e4SLinus Torvalds 
22921da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk)
22931da177e4SLinus Torvalds {
22941da177e4SLinus Torvalds 	set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
22951da177e4SLinus Torvalds }
22961da177e4SLinus Torvalds 
22971da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk)
22981da177e4SLinus Torvalds {
22991da177e4SLinus Torvalds 	clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
23001da177e4SLinus Torvalds }
23011da177e4SLinus Torvalds 
23028ae121acSGregory Haskins static inline int test_tsk_need_resched(struct task_struct *tsk)
23038ae121acSGregory Haskins {
23048ae121acSGregory Haskins 	return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
23058ae121acSGregory Haskins }
23068ae121acSGregory Haskins 
2307690cc3ffSEric W. Biederman static inline int restart_syscall(void)
2308690cc3ffSEric W. Biederman {
2309690cc3ffSEric W. Biederman 	set_tsk_thread_flag(current, TIF_SIGPENDING);
2310690cc3ffSEric W. Biederman 	return -ERESTARTNOINTR;
2311690cc3ffSEric W. Biederman }
2312690cc3ffSEric W. Biederman 
23131da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p)
23141da177e4SLinus Torvalds {
23151da177e4SLinus Torvalds 	return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
23161da177e4SLinus Torvalds }
23171da177e4SLinus Torvalds 
2318d9588725SRoland McGrath static inline int __fatal_signal_pending(struct task_struct *p)
2319d9588725SRoland McGrath {
2320d9588725SRoland McGrath 	return unlikely(sigismember(&p->pending.signal, SIGKILL));
2321d9588725SRoland McGrath }
2322f776d12dSMatthew Wilcox 
2323f776d12dSMatthew Wilcox static inline int fatal_signal_pending(struct task_struct *p)
2324f776d12dSMatthew Wilcox {
2325f776d12dSMatthew Wilcox 	return signal_pending(p) && __fatal_signal_pending(p);
2326f776d12dSMatthew Wilcox }
2327f776d12dSMatthew Wilcox 
232816882c1eSOleg Nesterov static inline int signal_pending_state(long state, struct task_struct *p)
232916882c1eSOleg Nesterov {
233016882c1eSOleg Nesterov 	if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
233116882c1eSOleg Nesterov 		return 0;
233216882c1eSOleg Nesterov 	if (!signal_pending(p))
233316882c1eSOleg Nesterov 		return 0;
233416882c1eSOleg Nesterov 
233516882c1eSOleg Nesterov 	return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
233616882c1eSOleg Nesterov }
233716882c1eSOleg Nesterov 
23381da177e4SLinus Torvalds static inline int need_resched(void)
23391da177e4SLinus Torvalds {
23409404ef02SLinus Torvalds 	return unlikely(test_thread_flag(TIF_NEED_RESCHED));
23411da177e4SLinus Torvalds }
23421da177e4SLinus Torvalds 
23431da177e4SLinus Torvalds /*
23441da177e4SLinus Torvalds  * cond_resched() and cond_resched_lock(): latency reduction via
23451da177e4SLinus Torvalds  * explicit rescheduling in places that are safe. The return
23461da177e4SLinus Torvalds  * value indicates whether a reschedule was done in fact.
23471da177e4SLinus Torvalds  * cond_resched_lock() will drop the spinlock before scheduling,
23481da177e4SLinus Torvalds  * cond_resched_softirq() will enable bhs before scheduling.
23491da177e4SLinus Torvalds  */
2350c3921ab7SLinus Torvalds extern int _cond_resched(void);
23516f80bd98SFrederic Weisbecker 
2352613afbf8SFrederic Weisbecker #define cond_resched() ({			\
2353613afbf8SFrederic Weisbecker 	__might_sleep(__FILE__, __LINE__, 0);	\
2354613afbf8SFrederic Weisbecker 	_cond_resched();			\
2355613afbf8SFrederic Weisbecker })
23566f80bd98SFrederic Weisbecker 
2357613afbf8SFrederic Weisbecker extern int __cond_resched_lock(spinlock_t *lock);
2358613afbf8SFrederic Weisbecker 
2359716a4234SFrederic Weisbecker #ifdef CONFIG_PREEMPT
2360716a4234SFrederic Weisbecker #define PREEMPT_LOCK_OFFSET	PREEMPT_OFFSET
236102b67cc3SHerbert Xu #else
2362716a4234SFrederic Weisbecker #define PREEMPT_LOCK_OFFSET	0
236302b67cc3SHerbert Xu #endif
2364716a4234SFrederic Weisbecker 
2365613afbf8SFrederic Weisbecker #define cond_resched_lock(lock) ({				\
2366716a4234SFrederic Weisbecker 	__might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);	\
2367613afbf8SFrederic Weisbecker 	__cond_resched_lock(lock);				\
2368613afbf8SFrederic Weisbecker })
2369613afbf8SFrederic Weisbecker 
2370613afbf8SFrederic Weisbecker extern int __cond_resched_softirq(void);
2371613afbf8SFrederic Weisbecker 
2372613afbf8SFrederic Weisbecker #define cond_resched_softirq() ({				\
2373613afbf8SFrederic Weisbecker 	__might_sleep(__FILE__, __LINE__, SOFTIRQ_OFFSET);	\
2374613afbf8SFrederic Weisbecker 	__cond_resched_softirq();				\
2375613afbf8SFrederic Weisbecker })
23761da177e4SLinus Torvalds 
23771da177e4SLinus Torvalds /*
23781da177e4SLinus Torvalds  * Does a critical section need to be broken due to another
237995c354feSNick Piggin  * task waiting?: (technically does not depend on CONFIG_PREEMPT,
238095c354feSNick Piggin  * but a general need for low latency)
23811da177e4SLinus Torvalds  */
238295c354feSNick Piggin static inline int spin_needbreak(spinlock_t *lock)
23831da177e4SLinus Torvalds {
238495c354feSNick Piggin #ifdef CONFIG_PREEMPT
238595c354feSNick Piggin 	return spin_is_contended(lock);
238695c354feSNick Piggin #else
23871da177e4SLinus Torvalds 	return 0;
238895c354feSNick Piggin #endif
23891da177e4SLinus Torvalds }
23901da177e4SLinus Torvalds 
23917bb44adeSRoland McGrath /*
2392f06febc9SFrank Mayhar  * Thread group CPU time accounting.
2393f06febc9SFrank Mayhar  */
23944cd4c1b4SPeter Zijlstra void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
23954da94d49SPeter Zijlstra void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
2396f06febc9SFrank Mayhar 
2397f06febc9SFrank Mayhar static inline void thread_group_cputime_init(struct signal_struct *sig)
2398f06febc9SFrank Mayhar {
23994cd4c1b4SPeter Zijlstra 	spin_lock_init(&sig->cputimer.lock);
2400f06febc9SFrank Mayhar }
2401f06febc9SFrank Mayhar 
2402f06febc9SFrank Mayhar /*
24037bb44adeSRoland McGrath  * Reevaluate whether the task has signals pending delivery.
24047bb44adeSRoland McGrath  * Wake the task if so.
24057bb44adeSRoland McGrath  * This is required every time the blocked sigset_t changes.
24067bb44adeSRoland McGrath  * callers must hold sighand->siglock.
24077bb44adeSRoland McGrath  */
24087bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t);
24091da177e4SLinus Torvalds extern void recalc_sigpending(void);
24101da177e4SLinus Torvalds 
24111da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped);
24121da177e4SLinus Torvalds 
24131da177e4SLinus Torvalds /*
24141da177e4SLinus Torvalds  * Wrappers for p->thread_info->cpu access. No-op on UP.
24151da177e4SLinus Torvalds  */
24161da177e4SLinus Torvalds #ifdef CONFIG_SMP
24171da177e4SLinus Torvalds 
24181da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
24191da177e4SLinus Torvalds {
2420a1261f54SAl Viro 	return task_thread_info(p)->cpu;
24211da177e4SLinus Torvalds }
24221da177e4SLinus Torvalds 
2423c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
24241da177e4SLinus Torvalds 
24251da177e4SLinus Torvalds #else
24261da177e4SLinus Torvalds 
24271da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
24281da177e4SLinus Torvalds {
24291da177e4SLinus Torvalds 	return 0;
24301da177e4SLinus Torvalds }
24311da177e4SLinus Torvalds 
24321da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
24331da177e4SLinus Torvalds {
24341da177e4SLinus Torvalds }
24351da177e4SLinus Torvalds 
24361da177e4SLinus Torvalds #endif /* CONFIG_SMP */
24371da177e4SLinus Torvalds 
24381a3c3034SIngo Molnar #ifdef CONFIG_TRACING
24391a3c3034SIngo Molnar extern void
24401a3c3034SIngo Molnar __trace_special(void *__tr, void *__data,
24411a3c3034SIngo Molnar 		unsigned long arg1, unsigned long arg2, unsigned long arg3);
24421da177e4SLinus Torvalds #else
24431a3c3034SIngo Molnar static inline void
24441a3c3034SIngo Molnar __trace_special(void *__tr, void *__data,
24451a3c3034SIngo Molnar 		unsigned long arg1, unsigned long arg2, unsigned long arg3)
24461da177e4SLinus Torvalds {
24471da177e4SLinus Torvalds }
24481da177e4SLinus Torvalds #endif
24491da177e4SLinus Torvalds 
245096f874e2SRusty Russell extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
245196f874e2SRusty Russell extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
24525c45bf27SSiddha, Suresh B 
24531da177e4SLinus Torvalds extern void normalize_rt_tasks(void);
24541da177e4SLinus Torvalds 
24557c941438SDhaval Giani #ifdef CONFIG_CGROUP_SCHED
24569b5b7751SSrivatsa Vaddagiri 
24574cf86d77SIngo Molnar extern struct task_group init_task_group;
24589b5b7751SSrivatsa Vaddagiri 
2459ec7dc8acSDhaval Giani extern struct task_group *sched_create_group(struct task_group *parent);
24604cf86d77SIngo Molnar extern void sched_destroy_group(struct task_group *tg);
24619b5b7751SSrivatsa Vaddagiri extern void sched_move_task(struct task_struct *tsk);
2462052f1dc7SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED
24634cf86d77SIngo Molnar extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
24645cb350baSDhaval Giani extern unsigned long sched_group_shares(struct task_group *tg);
2465052f1dc7SPeter Zijlstra #endif
2466052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED
24679f0c1e56SPeter Zijlstra extern int sched_group_set_rt_runtime(struct task_group *tg,
24689f0c1e56SPeter Zijlstra 				      long rt_runtime_us);
24699f0c1e56SPeter Zijlstra extern long sched_group_rt_runtime(struct task_group *tg);
2470d0b27fa7SPeter Zijlstra extern int sched_group_set_rt_period(struct task_group *tg,
2471d0b27fa7SPeter Zijlstra 				      long rt_period_us);
2472d0b27fa7SPeter Zijlstra extern long sched_group_rt_period(struct task_group *tg);
247354e99124SDhaval Giani extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk);
2474052f1dc7SPeter Zijlstra #endif
24759b5b7751SSrivatsa Vaddagiri #endif
24769b5b7751SSrivatsa Vaddagiri 
247754e99124SDhaval Giani extern int task_can_switch_user(struct user_struct *up,
247854e99124SDhaval Giani 					struct task_struct *tsk);
247954e99124SDhaval Giani 
24804b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT
24814b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
24824b98d11bSAlexey Dobriyan {
2483940389b8SAndrea Righi 	tsk->ioac.rchar += amt;
24844b98d11bSAlexey Dobriyan }
24854b98d11bSAlexey Dobriyan 
24864b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
24874b98d11bSAlexey Dobriyan {
2488940389b8SAndrea Righi 	tsk->ioac.wchar += amt;
24894b98d11bSAlexey Dobriyan }
24904b98d11bSAlexey Dobriyan 
24914b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
24924b98d11bSAlexey Dobriyan {
2493940389b8SAndrea Righi 	tsk->ioac.syscr++;
24944b98d11bSAlexey Dobriyan }
24954b98d11bSAlexey Dobriyan 
24964b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
24974b98d11bSAlexey Dobriyan {
2498940389b8SAndrea Righi 	tsk->ioac.syscw++;
24994b98d11bSAlexey Dobriyan }
25004b98d11bSAlexey Dobriyan #else
25014b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
25024b98d11bSAlexey Dobriyan {
25034b98d11bSAlexey Dobriyan }
25044b98d11bSAlexey Dobriyan 
25054b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
25064b98d11bSAlexey Dobriyan {
25074b98d11bSAlexey Dobriyan }
25084b98d11bSAlexey Dobriyan 
25094b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
25104b98d11bSAlexey Dobriyan {
25114b98d11bSAlexey Dobriyan }
25124b98d11bSAlexey Dobriyan 
25134b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
25144b98d11bSAlexey Dobriyan {
25154b98d11bSAlexey Dobriyan }
25164b98d11bSAlexey Dobriyan #endif
25174b98d11bSAlexey Dobriyan 
251882455257SDave Hansen #ifndef TASK_SIZE_OF
251982455257SDave Hansen #define TASK_SIZE_OF(tsk)	TASK_SIZE
252082455257SDave Hansen #endif
252182455257SDave Hansen 
25220793a61dSThomas Gleixner /*
25230793a61dSThomas Gleixner  * Call the function if the target task is executing on a CPU right now:
25240793a61dSThomas Gleixner  */
25250793a61dSThomas Gleixner extern void task_oncpu_function_call(struct task_struct *p,
25260793a61dSThomas Gleixner 				     void (*func) (void *info), void *info);
25270793a61dSThomas Gleixner 
25280793a61dSThomas Gleixner 
2529cf475ad2SBalbir Singh #ifdef CONFIG_MM_OWNER
2530cf475ad2SBalbir Singh extern void mm_update_next_owner(struct mm_struct *mm);
2531cf475ad2SBalbir Singh extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p);
2532cf475ad2SBalbir Singh #else
2533cf475ad2SBalbir Singh static inline void mm_update_next_owner(struct mm_struct *mm)
2534cf475ad2SBalbir Singh {
2535cf475ad2SBalbir Singh }
2536cf475ad2SBalbir Singh 
2537cf475ad2SBalbir Singh static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p)
2538cf475ad2SBalbir Singh {
2539cf475ad2SBalbir Singh }
2540cf475ad2SBalbir Singh #endif /* CONFIG_MM_OWNER */
2541cf475ad2SBalbir Singh 
25423e10e716SJiri Slaby static inline unsigned long task_rlimit(const struct task_struct *tsk,
25433e10e716SJiri Slaby 		unsigned int limit)
25443e10e716SJiri Slaby {
25453e10e716SJiri Slaby 	return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_cur);
25463e10e716SJiri Slaby }
25473e10e716SJiri Slaby 
25483e10e716SJiri Slaby static inline unsigned long task_rlimit_max(const struct task_struct *tsk,
25493e10e716SJiri Slaby 		unsigned int limit)
25503e10e716SJiri Slaby {
25513e10e716SJiri Slaby 	return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_max);
25523e10e716SJiri Slaby }
25533e10e716SJiri Slaby 
25543e10e716SJiri Slaby static inline unsigned long rlimit(unsigned int limit)
25553e10e716SJiri Slaby {
25563e10e716SJiri Slaby 	return task_rlimit(current, limit);
25573e10e716SJiri Slaby }
25583e10e716SJiri Slaby 
25593e10e716SJiri Slaby static inline unsigned long rlimit_max(unsigned int limit)
25603e10e716SJiri Slaby {
25613e10e716SJiri Slaby 	return task_rlimit_max(current, limit);
25623e10e716SJiri Slaby }
25633e10e716SJiri Slaby 
25641da177e4SLinus Torvalds #endif /* __KERNEL__ */
25651da177e4SLinus Torvalds 
25661da177e4SLinus Torvalds #endif
2567