xref: /linux/include/linux/sched.h (revision 868489660dabc0c28087cca3dbc1adbbc398c6fe)
11da177e4SLinus Torvalds #ifndef _LINUX_SCHED_H
21da177e4SLinus Torvalds #define _LINUX_SCHED_H
31da177e4SLinus Torvalds 
4b7b3c76aSDavid Woodhouse /*
5b7b3c76aSDavid Woodhouse  * cloning flags:
6b7b3c76aSDavid Woodhouse  */
7b7b3c76aSDavid Woodhouse #define CSIGNAL		0x000000ff	/* signal mask to be sent at exit */
8b7b3c76aSDavid Woodhouse #define CLONE_VM	0x00000100	/* set if VM shared between processes */
9b7b3c76aSDavid Woodhouse #define CLONE_FS	0x00000200	/* set if fs info shared between processes */
10b7b3c76aSDavid Woodhouse #define CLONE_FILES	0x00000400	/* set if open files shared between processes */
11b7b3c76aSDavid Woodhouse #define CLONE_SIGHAND	0x00000800	/* set if signal handlers and blocked signals shared */
12b7b3c76aSDavid Woodhouse #define CLONE_PTRACE	0x00002000	/* set if we want to let tracing continue on the child too */
13b7b3c76aSDavid Woodhouse #define CLONE_VFORK	0x00004000	/* set if the parent wants the child to wake it up on mm_release */
14b7b3c76aSDavid Woodhouse #define CLONE_PARENT	0x00008000	/* set if we want to have the same parent as the cloner */
15b7b3c76aSDavid Woodhouse #define CLONE_THREAD	0x00010000	/* Same thread group? */
16b7b3c76aSDavid Woodhouse #define CLONE_NEWNS	0x00020000	/* New namespace group? */
17b7b3c76aSDavid Woodhouse #define CLONE_SYSVSEM	0x00040000	/* share system V SEM_UNDO semantics */
18b7b3c76aSDavid Woodhouse #define CLONE_SETTLS	0x00080000	/* create a new TLS for the child */
19b7b3c76aSDavid Woodhouse #define CLONE_PARENT_SETTID	0x00100000	/* set the TID in the parent */
20b7b3c76aSDavid Woodhouse #define CLONE_CHILD_CLEARTID	0x00200000	/* clear the TID in the child */
21b7b3c76aSDavid Woodhouse #define CLONE_DETACHED		0x00400000	/* Unused, ignored */
22b7b3c76aSDavid Woodhouse #define CLONE_UNTRACED		0x00800000	/* set if the tracing process can't force CLONE_PTRACE on this clone */
23b7b3c76aSDavid Woodhouse #define CLONE_CHILD_SETTID	0x01000000	/* set the TID in the child */
24b7b3c76aSDavid Woodhouse #define CLONE_STOPPED		0x02000000	/* Start in stopped state */
25071df104SSerge E. Hallyn #define CLONE_NEWUTS		0x04000000	/* New utsname group? */
2625b21cb2SKirill Korotaev #define CLONE_NEWIPC		0x08000000	/* New ipcs */
2777ec739dSSerge E. Hallyn #define CLONE_NEWUSER		0x10000000	/* New user namespace */
2830e49c26SPavel Emelyanov #define CLONE_NEWPID		0x20000000	/* New pid namespace */
29169e3674SEric W. Biederman #define CLONE_NEWNET		0x40000000	/* New network namespace */
30fadad878SJens Axboe #define CLONE_IO		0x80000000	/* Clone io context */
31b7b3c76aSDavid Woodhouse 
32b7b3c76aSDavid Woodhouse /*
33b7b3c76aSDavid Woodhouse  * Scheduling policies
34b7b3c76aSDavid Woodhouse  */
35b7b3c76aSDavid Woodhouse #define SCHED_NORMAL		0
36b7b3c76aSDavid Woodhouse #define SCHED_FIFO		1
37b7b3c76aSDavid Woodhouse #define SCHED_RR		2
38b7b3c76aSDavid Woodhouse #define SCHED_BATCH		3
390e6aca43SIngo Molnar /* SCHED_ISO: reserved but not implemented yet */
400e6aca43SIngo Molnar #define SCHED_IDLE		5
41b7b3c76aSDavid Woodhouse 
42a3b6714eSDavid Woodhouse #ifdef __KERNEL__
43b7b3c76aSDavid Woodhouse 
44b7b3c76aSDavid Woodhouse struct sched_param {
45b7b3c76aSDavid Woodhouse 	int sched_priority;
46b7b3c76aSDavid Woodhouse };
47b7b3c76aSDavid Woodhouse 
481da177e4SLinus Torvalds #include <asm/param.h>	/* for HZ */
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #include <linux/capability.h>
511da177e4SLinus Torvalds #include <linux/threads.h>
521da177e4SLinus Torvalds #include <linux/kernel.h>
531da177e4SLinus Torvalds #include <linux/types.h>
541da177e4SLinus Torvalds #include <linux/timex.h>
551da177e4SLinus Torvalds #include <linux/jiffies.h>
561da177e4SLinus Torvalds #include <linux/rbtree.h>
571da177e4SLinus Torvalds #include <linux/thread_info.h>
581da177e4SLinus Torvalds #include <linux/cpumask.h>
591da177e4SLinus Torvalds #include <linux/errno.h>
601da177e4SLinus Torvalds #include <linux/nodemask.h>
61c92ff1bdSMartin Schwidefsky #include <linux/mm_types.h>
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds #include <asm/system.h>
641da177e4SLinus Torvalds #include <asm/page.h>
651da177e4SLinus Torvalds #include <asm/ptrace.h>
661da177e4SLinus Torvalds #include <asm/cputime.h>
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds #include <linux/smp.h>
691da177e4SLinus Torvalds #include <linux/sem.h>
701da177e4SLinus Torvalds #include <linux/signal.h>
715ad4e53bSAl Viro #include <linux/path.h>
721da177e4SLinus Torvalds #include <linux/compiler.h>
731da177e4SLinus Torvalds #include <linux/completion.h>
741da177e4SLinus Torvalds #include <linux/pid.h>
751da177e4SLinus Torvalds #include <linux/percpu.h>
761da177e4SLinus Torvalds #include <linux/topology.h>
773e26c149SPeter Zijlstra #include <linux/proportions.h>
781da177e4SLinus Torvalds #include <linux/seccomp.h>
79e56d0903SIngo Molnar #include <linux/rcupdate.h>
8005725f7eSJiri Pirko #include <linux/rculist.h>
8123f78d4aSIngo Molnar #include <linux/rtmutex.h>
821da177e4SLinus Torvalds 
83a3b6714eSDavid Woodhouse #include <linux/time.h>
84a3b6714eSDavid Woodhouse #include <linux/param.h>
85a3b6714eSDavid Woodhouse #include <linux/resource.h>
86a3b6714eSDavid Woodhouse #include <linux/timer.h>
87a3b6714eSDavid Woodhouse #include <linux/hrtimer.h>
887c3ab738SAndrew Morton #include <linux/task_io_accounting.h>
895cb350baSDhaval Giani #include <linux/kobject.h>
909745512cSArjan van de Ven #include <linux/latencytop.h>
919e2b2dc4SDavid Howells #include <linux/cred.h>
92a3b6714eSDavid Woodhouse 
93a3b6714eSDavid Woodhouse #include <asm/processor.h>
9436d57ac4SH. J. Lu 
951da177e4SLinus Torvalds struct exec_domain;
96c87e2837SIngo Molnar struct futex_pi_state;
97286100a6SAlexey Dobriyan struct robust_list_head;
98d89d8796SNeil Brown struct bio;
995ad4e53bSAl Viro struct fs_struct;
100e2b371f0SMarkus Metzger struct bts_context;
101a63eaf34SPaul Mackerras struct perf_counter_context;
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds /*
1041da177e4SLinus Torvalds  * List of flags we want to share for kernel threads,
1051da177e4SLinus Torvalds  * if only because they are not used by them anyway.
1061da177e4SLinus Torvalds  */
1071da177e4SLinus Torvalds #define CLONE_KERNEL	(CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds /*
1101da177e4SLinus Torvalds  * These are the constant used to fake the fixed-point load-average
1111da177e4SLinus Torvalds  * counting. Some notes:
1121da177e4SLinus Torvalds  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
1131da177e4SLinus Torvalds  *    a load-average precision of 10 bits integer + 11 bits fractional
1141da177e4SLinus Torvalds  *  - if you want to count load-averages more often, you need more
1151da177e4SLinus Torvalds  *    precision, or rounding will get you. With 2-second counting freq,
1161da177e4SLinus Torvalds  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
1171da177e4SLinus Torvalds  *    11 bit fractions.
1181da177e4SLinus Torvalds  */
1191da177e4SLinus Torvalds extern unsigned long avenrun[];		/* Load averages */
1202d02494fSThomas Gleixner extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds #define FSHIFT		11		/* nr of bits of precision */
1231da177e4SLinus Torvalds #define FIXED_1		(1<<FSHIFT)	/* 1.0 as fixed-point */
1240c2043abSLinus Torvalds #define LOAD_FREQ	(5*HZ+1)	/* 5 sec intervals */
1251da177e4SLinus Torvalds #define EXP_1		1884		/* 1/exp(5sec/1min) as fixed-point */
1261da177e4SLinus Torvalds #define EXP_5		2014		/* 1/exp(5sec/5min) */
1271da177e4SLinus Torvalds #define EXP_15		2037		/* 1/exp(5sec/15min) */
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \
1301da177e4SLinus Torvalds 	load *= exp; \
1311da177e4SLinus Torvalds 	load += n*(FIXED_1-exp); \
1321da177e4SLinus Torvalds 	load >>= FSHIFT;
1331da177e4SLinus Torvalds 
1341da177e4SLinus Torvalds extern unsigned long total_forks;
1351da177e4SLinus Torvalds extern int nr_threads;
1361da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts);
1371da177e4SLinus Torvalds extern int nr_processes(void);
1381da177e4SLinus Torvalds extern unsigned long nr_running(void);
1391da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void);
1401da177e4SLinus Torvalds extern unsigned long nr_iowait(void);
141dce48a84SThomas Gleixner extern void calc_global_load(void);
14223a185caSPaul Mackerras extern u64 cpu_nr_migrations(int cpu);
1431da177e4SLinus Torvalds 
1447e49fcceSSteven Rostedt extern unsigned long get_parent_ip(unsigned long addr);
1457e49fcceSSteven Rostedt 
14643ae34cbSIngo Molnar struct seq_file;
14743ae34cbSIngo Molnar struct cfs_rq;
1484cf86d77SIngo Molnar struct task_group;
14943ae34cbSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
15043ae34cbSIngo Molnar extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
15143ae34cbSIngo Molnar extern void proc_sched_set_task(struct task_struct *p);
15243ae34cbSIngo Molnar extern void
1535cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
15443ae34cbSIngo Molnar #else
15543ae34cbSIngo Molnar static inline void
15643ae34cbSIngo Molnar proc_sched_show_task(struct task_struct *p, struct seq_file *m)
15743ae34cbSIngo Molnar {
15843ae34cbSIngo Molnar }
15943ae34cbSIngo Molnar static inline void proc_sched_set_task(struct task_struct *p)
16043ae34cbSIngo Molnar {
16143ae34cbSIngo Molnar }
16243ae34cbSIngo Molnar static inline void
1635cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
16443ae34cbSIngo Molnar {
16543ae34cbSIngo Molnar }
16643ae34cbSIngo Molnar #endif
1671da177e4SLinus Torvalds 
168690229a0SIngo Molnar extern unsigned long long time_sync_thresh;
169690229a0SIngo Molnar 
1704a8342d2SLinus Torvalds /*
1714a8342d2SLinus Torvalds  * Task state bitmask. NOTE! These bits are also
1724a8342d2SLinus Torvalds  * encoded in fs/proc/array.c: get_task_state().
1734a8342d2SLinus Torvalds  *
1744a8342d2SLinus Torvalds  * We have two separate sets of flags: task->state
1754a8342d2SLinus Torvalds  * is about runnability, while task->exit_state are
1764a8342d2SLinus Torvalds  * about the task exiting. Confusing, but this way
1774a8342d2SLinus Torvalds  * modifying one set can't modify the other one by
1784a8342d2SLinus Torvalds  * mistake.
1794a8342d2SLinus Torvalds  */
1801da177e4SLinus Torvalds #define TASK_RUNNING		0
1811da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE	1
1821da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE	2
183f021a3c2SMatthew Wilcox #define __TASK_STOPPED		4
184f021a3c2SMatthew Wilcox #define __TASK_TRACED		8
1854a8342d2SLinus Torvalds /* in tsk->exit_state */
1864a8342d2SLinus Torvalds #define EXIT_ZOMBIE		16
1874a8342d2SLinus Torvalds #define EXIT_DEAD		32
1884a8342d2SLinus Torvalds /* in tsk->state again */
189af927232SMike Galbraith #define TASK_DEAD		64
190f021a3c2SMatthew Wilcox #define TASK_WAKEKILL		128
191f021a3c2SMatthew Wilcox 
192f021a3c2SMatthew Wilcox /* Convenience macros for the sake of set_task_state */
193f021a3c2SMatthew Wilcox #define TASK_KILLABLE		(TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
194f021a3c2SMatthew Wilcox #define TASK_STOPPED		(TASK_WAKEKILL | __TASK_STOPPED)
195f021a3c2SMatthew Wilcox #define TASK_TRACED		(TASK_WAKEKILL | __TASK_TRACED)
1961da177e4SLinus Torvalds 
19792a1f4bcSMatthew Wilcox /* Convenience macros for the sake of wake_up */
19892a1f4bcSMatthew Wilcox #define TASK_NORMAL		(TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
199f021a3c2SMatthew Wilcox #define TASK_ALL		(TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
20092a1f4bcSMatthew Wilcox 
20192a1f4bcSMatthew Wilcox /* get_task_state() */
20292a1f4bcSMatthew Wilcox #define TASK_REPORT		(TASK_RUNNING | TASK_INTERRUPTIBLE | \
203f021a3c2SMatthew Wilcox 				 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
204f021a3c2SMatthew Wilcox 				 __TASK_TRACED)
20592a1f4bcSMatthew Wilcox 
206f021a3c2SMatthew Wilcox #define task_is_traced(task)	((task->state & __TASK_TRACED) != 0)
207f021a3c2SMatthew Wilcox #define task_is_stopped(task)	((task->state & __TASK_STOPPED) != 0)
20892a1f4bcSMatthew Wilcox #define task_is_stopped_or_traced(task)	\
209f021a3c2SMatthew Wilcox 			((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
21092a1f4bcSMatthew Wilcox #define task_contributes_to_load(task)	\
211e3c8ca83SNathan Lynch 				((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
2126301cb95SThomas Gleixner 				 (task->flags & PF_FREEZING) == 0)
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds #define __set_task_state(tsk, state_value)		\
2151da177e4SLinus Torvalds 	do { (tsk)->state = (state_value); } while (0)
2161da177e4SLinus Torvalds #define set_task_state(tsk, state_value)		\
2171da177e4SLinus Torvalds 	set_mb((tsk)->state, (state_value))
2181da177e4SLinus Torvalds 
219498d0c57SAndrew Morton /*
220498d0c57SAndrew Morton  * set_current_state() includes a barrier so that the write of current->state
221498d0c57SAndrew Morton  * is correctly serialised wrt the caller's subsequent test of whether to
222498d0c57SAndrew Morton  * actually sleep:
223498d0c57SAndrew Morton  *
224498d0c57SAndrew Morton  *	set_current_state(TASK_UNINTERRUPTIBLE);
225498d0c57SAndrew Morton  *	if (do_i_need_to_sleep())
226498d0c57SAndrew Morton  *		schedule();
227498d0c57SAndrew Morton  *
228498d0c57SAndrew Morton  * If the caller does not need such serialisation then use __set_current_state()
229498d0c57SAndrew Morton  */
2301da177e4SLinus Torvalds #define __set_current_state(state_value)			\
2311da177e4SLinus Torvalds 	do { current->state = (state_value); } while (0)
2321da177e4SLinus Torvalds #define set_current_state(state_value)		\
2331da177e4SLinus Torvalds 	set_mb(current->state, (state_value))
2341da177e4SLinus Torvalds 
2351da177e4SLinus Torvalds /* Task command name length */
2361da177e4SLinus Torvalds #define TASK_COMM_LEN 16
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds #include <linux/spinlock.h>
2391da177e4SLinus Torvalds 
2401da177e4SLinus Torvalds /*
2411da177e4SLinus Torvalds  * This serializes "schedule()" and also protects
2421da177e4SLinus Torvalds  * the run-queue from deletions/modifications (but
2431da177e4SLinus Torvalds  * _adding_ to the beginning of the run-queue has
2441da177e4SLinus Torvalds  * a separate lock).
2451da177e4SLinus Torvalds  */
2461da177e4SLinus Torvalds extern rwlock_t tasklist_lock;
2471da177e4SLinus Torvalds extern spinlock_t mmlist_lock;
2481da177e4SLinus Torvalds 
24936c8b586SIngo Molnar struct task_struct;
2501da177e4SLinus Torvalds 
2511da177e4SLinus Torvalds extern void sched_init(void);
2521da177e4SLinus Torvalds extern void sched_init_smp(void);
2532d07b255SHarvey Harrison extern asmlinkage void schedule_tail(struct task_struct *prev);
25436c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu);
2551df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle);
2561da177e4SLinus Torvalds 
257017730c1SIngo Molnar extern int runqueue_is_locked(void);
258ad474cacSOleg Nesterov extern void task_rq_unlock_wait(struct task_struct *p);
259017730c1SIngo Molnar 
2606a7b3dc3SRusty Russell extern cpumask_var_t nohz_cpu_mask;
26146cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
26246cb4b7cSSiddha, Suresh B extern int select_nohz_load_balancer(int cpu);
263eea08f32SArun R Bharadwaj extern int get_nohz_load_balancer(void);
26446cb4b7cSSiddha, Suresh B #else
26546cb4b7cSSiddha, Suresh B static inline int select_nohz_load_balancer(int cpu)
26646cb4b7cSSiddha, Suresh B {
26746cb4b7cSSiddha, Suresh B 	return 0;
26846cb4b7cSSiddha, Suresh B }
26946cb4b7cSSiddha, Suresh B #endif
2701da177e4SLinus Torvalds 
271e59e2ae2SIngo Molnar /*
27239bc89fdSIngo Molnar  * Only dump TASK_* tasks. (0 for all tasks)
273e59e2ae2SIngo Molnar  */
274e59e2ae2SIngo Molnar extern void show_state_filter(unsigned long state_filter);
275e59e2ae2SIngo Molnar 
276e59e2ae2SIngo Molnar static inline void show_state(void)
277e59e2ae2SIngo Molnar {
27839bc89fdSIngo Molnar 	show_state_filter(0);
279e59e2ae2SIngo Molnar }
280e59e2ae2SIngo Molnar 
2811da177e4SLinus Torvalds extern void show_regs(struct pt_regs *);
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds /*
2841da177e4SLinus Torvalds  * TASK is a pointer to the task whose backtrace we want to see (or NULL for current
2851da177e4SLinus Torvalds  * task), SP is the stack pointer of the first frame that should be shown in the back
2861da177e4SLinus Torvalds  * trace (or NULL if the entire call-chain of the task should be shown).
2871da177e4SLinus Torvalds  */
2881da177e4SLinus Torvalds extern void show_stack(struct task_struct *task, unsigned long *sp);
2891da177e4SLinus Torvalds 
2901da177e4SLinus Torvalds void io_schedule(void);
2911da177e4SLinus Torvalds long io_schedule_timeout(long timeout);
2921da177e4SLinus Torvalds 
2931da177e4SLinus Torvalds extern void cpu_init (void);
2941da177e4SLinus Torvalds extern void trap_init(void);
2951da177e4SLinus Torvalds extern void update_process_times(int user);
2961da177e4SLinus Torvalds extern void scheduler_tick(void);
2971da177e4SLinus Torvalds 
29882a1fcb9SIngo Molnar extern void sched_show_task(struct task_struct *p);
29982a1fcb9SIngo Molnar 
3008446f1d3SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP
3016687a97dSIngo Molnar extern void softlockup_tick(void);
3028446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void);
30304c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void);
304baf48f65SMandeep Singh Baines extern int proc_dosoftlockup_thresh(struct ctl_table *table, int write,
305baf48f65SMandeep Singh Baines 				    struct file *filp, void __user *buffer,
306baf48f65SMandeep Singh Baines 				    size_t *lenp, loff_t *ppos);
3079c44bc03SIngo Molnar extern unsigned int  softlockup_panic;
3089383d967SDimitri Sivanich extern int softlockup_thresh;
3098446f1d3SIngo Molnar #else
3106687a97dSIngo Molnar static inline void softlockup_tick(void)
3118446f1d3SIngo Molnar {
3128446f1d3SIngo Molnar }
3138446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void)
3148446f1d3SIngo Molnar {
3158446f1d3SIngo Molnar }
31604c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void)
31704c9167fSJeremy Fitzhardinge {
31804c9167fSJeremy Fitzhardinge }
3198446f1d3SIngo Molnar #endif
3208446f1d3SIngo Molnar 
321e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
322e162b39aSMandeep Singh Baines extern unsigned int  sysctl_hung_task_panic;
323e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_check_count;
324e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_timeout_secs;
325e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_warnings;
326e162b39aSMandeep Singh Baines extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
327e162b39aSMandeep Singh Baines 					 struct file *filp, void __user *buffer,
328e162b39aSMandeep Singh Baines 					 size_t *lenp, loff_t *ppos);
329e162b39aSMandeep Singh Baines #endif
3308446f1d3SIngo Molnar 
3311da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */
3321da177e4SLinus Torvalds #define __sched		__attribute__((__section__(".sched.text")))
333deaf2227SIngo Molnar 
334deaf2227SIngo Molnar /* Linker adds these: start and end of __sched functions */
335deaf2227SIngo Molnar extern char __sched_text_start[], __sched_text_end[];
336deaf2227SIngo Molnar 
3371da177e4SLinus Torvalds /* Is this address in the __sched functions? */
3381da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr);
3391da177e4SLinus Torvalds 
3401da177e4SLinus Torvalds #define	MAX_SCHEDULE_TIMEOUT	LONG_MAX
341b3c97528SHarvey Harrison extern signed long schedule_timeout(signed long timeout);
34264ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout);
343294d5cc2SMatthew Wilcox extern signed long schedule_timeout_killable(signed long timeout);
34464ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout);
34541719b03SPeter Zijlstra asmlinkage void __schedule(void);
3461da177e4SLinus Torvalds asmlinkage void schedule(void);
3470d66bf6dSPeter Zijlstra extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
3481da177e4SLinus Torvalds 
349ab516013SSerge E. Hallyn struct nsproxy;
350acce292cSCedric Le Goater struct user_namespace;
3511da177e4SLinus Torvalds 
352341c87bfSKAMEZAWA Hiroyuki /*
353341c87bfSKAMEZAWA Hiroyuki  * Default maximum number of active map areas, this limits the number of vmas
354341c87bfSKAMEZAWA Hiroyuki  * per mm struct. Users can overwrite this number by sysctl but there is a
355341c87bfSKAMEZAWA Hiroyuki  * problem.
356341c87bfSKAMEZAWA Hiroyuki  *
357341c87bfSKAMEZAWA Hiroyuki  * When a program's coredump is generated as ELF format, a section is created
358341c87bfSKAMEZAWA Hiroyuki  * per a vma. In ELF, the number of sections is represented in unsigned short.
359341c87bfSKAMEZAWA Hiroyuki  * This means the number of sections should be smaller than 65535 at coredump.
360341c87bfSKAMEZAWA Hiroyuki  * Because the kernel adds some informative sections to a image of program at
361341c87bfSKAMEZAWA Hiroyuki  * generating coredump, we need some margin. The number of extra sections is
362341c87bfSKAMEZAWA Hiroyuki  * 1-3 now and depends on arch. We use "5" as safe margin, here.
363341c87bfSKAMEZAWA Hiroyuki  */
364341c87bfSKAMEZAWA Hiroyuki #define MAPCOUNT_ELF_CORE_MARGIN	(5)
365341c87bfSKAMEZAWA Hiroyuki #define DEFAULT_MAX_MAP_COUNT	(USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
3661da177e4SLinus Torvalds 
3671da177e4SLinus Torvalds extern int sysctl_max_map_count;
3681da177e4SLinus Torvalds 
3691da177e4SLinus Torvalds #include <linux/aio.h>
3701da177e4SLinus Torvalds 
3711da177e4SLinus Torvalds extern unsigned long
3721da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
3731da177e4SLinus Torvalds 		       unsigned long, unsigned long);
3741da177e4SLinus Torvalds extern unsigned long
3751da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
3761da177e4SLinus Torvalds 			  unsigned long len, unsigned long pgoff,
3771da177e4SLinus Torvalds 			  unsigned long flags);
3781363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long);
3791363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
3801da177e4SLinus Torvalds 
381f7d0b926SJeremy Fitzhardinge #if USE_SPLIT_PTLOCKS
382f412ac08SHugh Dickins /*
383f412ac08SHugh Dickins  * The mm counters are not protected by its page_table_lock,
384f412ac08SHugh Dickins  * so must be incremented atomically.
385f412ac08SHugh Dickins  */
386d3cb4871SChristoph Lameter #define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
387d3cb4871SChristoph Lameter #define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
388d3cb4871SChristoph Lameter #define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
389d3cb4871SChristoph Lameter #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
390d3cb4871SChristoph Lameter #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
391f412ac08SHugh Dickins 
392f7d0b926SJeremy Fitzhardinge #else  /* !USE_SPLIT_PTLOCKS */
393f412ac08SHugh Dickins /*
394f412ac08SHugh Dickins  * The mm counters are protected by its page_table_lock,
395f412ac08SHugh Dickins  * so can be incremented directly.
396f412ac08SHugh Dickins  */
3971da177e4SLinus Torvalds #define set_mm_counter(mm, member, value) (mm)->_##member = (value)
3981da177e4SLinus Torvalds #define get_mm_counter(mm, member) ((mm)->_##member)
3991da177e4SLinus Torvalds #define add_mm_counter(mm, member, value) (mm)->_##member += (value)
4001da177e4SLinus Torvalds #define inc_mm_counter(mm, member) (mm)->_##member++
4011da177e4SLinus Torvalds #define dec_mm_counter(mm, member) (mm)->_##member--
4024294621fSHugh Dickins 
403f7d0b926SJeremy Fitzhardinge #endif /* !USE_SPLIT_PTLOCKS */
404f412ac08SHugh Dickins 
405f412ac08SHugh Dickins #define get_mm_rss(mm)					\
406f412ac08SHugh Dickins 	(get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
407365e9c87SHugh Dickins #define update_hiwater_rss(mm)	do {			\
408365e9c87SHugh Dickins 	unsigned long _rss = get_mm_rss(mm);		\
409365e9c87SHugh Dickins 	if ((mm)->hiwater_rss < _rss)			\
410365e9c87SHugh Dickins 		(mm)->hiwater_rss = _rss;		\
411365e9c87SHugh Dickins } while (0)
412365e9c87SHugh Dickins #define update_hiwater_vm(mm)	do {			\
413365e9c87SHugh Dickins 	if ((mm)->hiwater_vm < (mm)->total_vm)		\
414365e9c87SHugh Dickins 		(mm)->hiwater_vm = (mm)->total_vm;	\
415365e9c87SHugh Dickins } while (0)
416365e9c87SHugh Dickins 
4179de1581eSOleg Nesterov static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm)
4189de1581eSOleg Nesterov {
4199de1581eSOleg Nesterov 	return max(mm->hiwater_rss, get_mm_rss(mm));
4209de1581eSOleg Nesterov }
4219de1581eSOleg Nesterov 
4229de1581eSOleg Nesterov static inline unsigned long get_mm_hiwater_vm(struct mm_struct *mm)
4239de1581eSOleg Nesterov {
4249de1581eSOleg Nesterov 	return max(mm->hiwater_vm, mm->total_vm);
4259de1581eSOleg Nesterov }
426901608d9SOleg Nesterov 
4276c5d5238SKawai, Hidehiro extern void set_dumpable(struct mm_struct *mm, int value);
4286c5d5238SKawai, Hidehiro extern int get_dumpable(struct mm_struct *mm);
4296c5d5238SKawai, Hidehiro 
4306c5d5238SKawai, Hidehiro /* mm flags */
4313cb4a0bbSKawai, Hidehiro /* dumpable bits */
4326c5d5238SKawai, Hidehiro #define MMF_DUMPABLE      0  /* core dump is permitted */
4336c5d5238SKawai, Hidehiro #define MMF_DUMP_SECURELY 1  /* core file is readable only by root */
4343cb4a0bbSKawai, Hidehiro #define MMF_DUMPABLE_BITS 2
4353cb4a0bbSKawai, Hidehiro 
4363cb4a0bbSKawai, Hidehiro /* coredump filter bits */
4373cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_PRIVATE	2
4383cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_SHARED	3
4393cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_PRIVATE	4
4403cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_SHARED	5
44182df3973SRoland McGrath #define MMF_DUMP_ELF_HEADERS	6
442e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_PRIVATE 7
443e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_SHARED  8
4443cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_SHIFT	MMF_DUMPABLE_BITS
445e575f111SKOSAKI Motohiro #define MMF_DUMP_FILTER_BITS	7
4463cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_MASK \
4473cb4a0bbSKawai, Hidehiro 	(((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
4483cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_DEFAULT \
449e575f111SKOSAKI Motohiro 	((1 << MMF_DUMP_ANON_PRIVATE) |	(1 << MMF_DUMP_ANON_SHARED) |\
450656eb2cdSRoland McGrath 	 (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
451656eb2cdSRoland McGrath 
452656eb2cdSRoland McGrath #ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
453656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF	(1 << MMF_DUMP_ELF_HEADERS)
454656eb2cdSRoland McGrath #else
455656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF	0
456656eb2cdSRoland McGrath #endif
4576c5d5238SKawai, Hidehiro 
4581da177e4SLinus Torvalds struct sighand_struct {
4591da177e4SLinus Torvalds 	atomic_t		count;
4601da177e4SLinus Torvalds 	struct k_sigaction	action[_NSIG];
4611da177e4SLinus Torvalds 	spinlock_t		siglock;
462b8fceee1SDavide Libenzi 	wait_queue_head_t	signalfd_wqh;
4631da177e4SLinus Torvalds };
4641da177e4SLinus Torvalds 
4650e464814SKaiGai Kohei struct pacct_struct {
466f6ec29a4SKaiGai Kohei 	int			ac_flag;
467f6ec29a4SKaiGai Kohei 	long			ac_exitcode;
4680e464814SKaiGai Kohei 	unsigned long		ac_mem;
46977787bfbSKaiGai Kohei 	cputime_t		ac_utime, ac_stime;
47077787bfbSKaiGai Kohei 	unsigned long		ac_minflt, ac_majflt;
4710e464814SKaiGai Kohei };
4720e464814SKaiGai Kohei 
473f06febc9SFrank Mayhar /**
474f06febc9SFrank Mayhar  * struct task_cputime - collected CPU time counts
475f06febc9SFrank Mayhar  * @utime:		time spent in user mode, in &cputime_t units
476f06febc9SFrank Mayhar  * @stime:		time spent in kernel mode, in &cputime_t units
477f06febc9SFrank Mayhar  * @sum_exec_runtime:	total time spent on the CPU, in nanoseconds
478f06febc9SFrank Mayhar  *
479f06febc9SFrank Mayhar  * This structure groups together three kinds of CPU time that are
480f06febc9SFrank Mayhar  * tracked for threads and thread groups.  Most things considering
481f06febc9SFrank Mayhar  * CPU time want to group these counts together and treat all three
482f06febc9SFrank Mayhar  * of them in parallel.
483f06febc9SFrank Mayhar  */
484f06febc9SFrank Mayhar struct task_cputime {
485f06febc9SFrank Mayhar 	cputime_t utime;
486f06febc9SFrank Mayhar 	cputime_t stime;
487f06febc9SFrank Mayhar 	unsigned long long sum_exec_runtime;
488f06febc9SFrank Mayhar };
489f06febc9SFrank Mayhar /* Alternate field names when used to cache expirations. */
490f06febc9SFrank Mayhar #define prof_exp	stime
491f06febc9SFrank Mayhar #define virt_exp	utime
492f06febc9SFrank Mayhar #define sched_exp	sum_exec_runtime
493f06febc9SFrank Mayhar 
4944cd4c1b4SPeter Zijlstra #define INIT_CPUTIME	\
4954cd4c1b4SPeter Zijlstra 	(struct task_cputime) {					\
4964cd4c1b4SPeter Zijlstra 		.utime = cputime_zero,				\
4974cd4c1b4SPeter Zijlstra 		.stime = cputime_zero,				\
4984cd4c1b4SPeter Zijlstra 		.sum_exec_runtime = 0,				\
4994cd4c1b4SPeter Zijlstra 	}
5004cd4c1b4SPeter Zijlstra 
501c99e6efeSPeter Zijlstra /*
502c99e6efeSPeter Zijlstra  * Disable preemption until the scheduler is running.
503c99e6efeSPeter Zijlstra  * Reset by start_kernel()->sched_init()->init_idle().
504d86ee480SPeter Zijlstra  *
505d86ee480SPeter Zijlstra  * We include PREEMPT_ACTIVE to avoid cond_resched() from working
506d86ee480SPeter Zijlstra  * before the scheduler is active -- see should_resched().
507c99e6efeSPeter Zijlstra  */
508d86ee480SPeter Zijlstra #define INIT_PREEMPT_COUNT	(1 + PREEMPT_ACTIVE)
509c99e6efeSPeter Zijlstra 
510f06febc9SFrank Mayhar /**
5114cd4c1b4SPeter Zijlstra  * struct thread_group_cputimer - thread group interval timer counts
5124cd4c1b4SPeter Zijlstra  * @cputime:		thread group interval timers.
5134cd4c1b4SPeter Zijlstra  * @running:		non-zero when there are timers running and
5144cd4c1b4SPeter Zijlstra  * 			@cputime receives updates.
5154cd4c1b4SPeter Zijlstra  * @lock:		lock for fields in this struct.
516f06febc9SFrank Mayhar  *
517f06febc9SFrank Mayhar  * This structure contains the version of task_cputime, above, that is
5184cd4c1b4SPeter Zijlstra  * used for thread group CPU timer calculations.
519f06febc9SFrank Mayhar  */
5204cd4c1b4SPeter Zijlstra struct thread_group_cputimer {
5214cd4c1b4SPeter Zijlstra 	struct task_cputime cputime;
5224cd4c1b4SPeter Zijlstra 	int running;
5234cd4c1b4SPeter Zijlstra 	spinlock_t lock;
524f06febc9SFrank Mayhar };
525f06febc9SFrank Mayhar 
5261da177e4SLinus Torvalds /*
5271da177e4SLinus Torvalds  * NOTE! "signal_struct" does not have it's own
5281da177e4SLinus Torvalds  * locking, because a shared signal_struct always
5291da177e4SLinus Torvalds  * implies a shared sighand_struct, so locking
5301da177e4SLinus Torvalds  * sighand_struct is always a proper superset of
5311da177e4SLinus Torvalds  * the locking of signal_struct.
5321da177e4SLinus Torvalds  */
5331da177e4SLinus Torvalds struct signal_struct {
5341da177e4SLinus Torvalds 	atomic_t		count;
5351da177e4SLinus Torvalds 	atomic_t		live;
5361da177e4SLinus Torvalds 
5371da177e4SLinus Torvalds 	wait_queue_head_t	wait_chldexit;	/* for wait4() */
5381da177e4SLinus Torvalds 
5391da177e4SLinus Torvalds 	/* current thread group signal load-balancing target: */
54036c8b586SIngo Molnar 	struct task_struct	*curr_target;
5411da177e4SLinus Torvalds 
5421da177e4SLinus Torvalds 	/* shared signal handling: */
5431da177e4SLinus Torvalds 	struct sigpending	shared_pending;
5441da177e4SLinus Torvalds 
5451da177e4SLinus Torvalds 	/* thread group exit support */
5461da177e4SLinus Torvalds 	int			group_exit_code;
5471da177e4SLinus Torvalds 	/* overloaded:
5481da177e4SLinus Torvalds 	 * - notify group_exit_task when ->count is equal to notify_count
5491da177e4SLinus Torvalds 	 * - everyone except group_exit_task is stopped during signal delivery
5501da177e4SLinus Torvalds 	 *   of fatal signals, group_exit_task processes the signal.
5511da177e4SLinus Torvalds 	 */
5521da177e4SLinus Torvalds 	int			notify_count;
55307dd20e0SRichard Kennedy 	struct task_struct	*group_exit_task;
5541da177e4SLinus Torvalds 
5551da177e4SLinus Torvalds 	/* thread group stop support, overloads group_exit_code too */
5561da177e4SLinus Torvalds 	int			group_stop_count;
5571da177e4SLinus Torvalds 	unsigned int		flags; /* see SIGNAL_* flags below */
5581da177e4SLinus Torvalds 
5591da177e4SLinus Torvalds 	/* POSIX.1b Interval Timers */
5601da177e4SLinus Torvalds 	struct list_head posix_timers;
5611da177e4SLinus Torvalds 
5621da177e4SLinus Torvalds 	/* ITIMER_REAL timer for the process */
5632ff678b8SThomas Gleixner 	struct hrtimer real_timer;
564fea9d175SOleg Nesterov 	struct pid *leader_pid;
5652ff678b8SThomas Gleixner 	ktime_t it_real_incr;
5661da177e4SLinus Torvalds 
5671da177e4SLinus Torvalds 	/* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
5681da177e4SLinus Torvalds 	cputime_t it_prof_expires, it_virt_expires;
5691da177e4SLinus Torvalds 	cputime_t it_prof_incr, it_virt_incr;
5701da177e4SLinus Torvalds 
571f06febc9SFrank Mayhar 	/*
5724cd4c1b4SPeter Zijlstra 	 * Thread group totals for process CPU timers.
5734cd4c1b4SPeter Zijlstra 	 * See thread_group_cputimer(), et al, for details.
574f06febc9SFrank Mayhar 	 */
5754cd4c1b4SPeter Zijlstra 	struct thread_group_cputimer cputimer;
576f06febc9SFrank Mayhar 
577f06febc9SFrank Mayhar 	/* Earliest-expiration cache. */
578f06febc9SFrank Mayhar 	struct task_cputime cputime_expires;
579f06febc9SFrank Mayhar 
580f06febc9SFrank Mayhar 	struct list_head cpu_timers[3];
581f06febc9SFrank Mayhar 
582ab521dc0SEric W. Biederman 	struct pid *tty_old_pgrp;
5831ec320afSCedric Le Goater 
5841da177e4SLinus Torvalds 	/* boolean value for session group leader */
5851da177e4SLinus Torvalds 	int leader;
5861da177e4SLinus Torvalds 
5871da177e4SLinus Torvalds 	struct tty_struct *tty; /* NULL if no tty */
5881da177e4SLinus Torvalds 
5891da177e4SLinus Torvalds 	/*
5901da177e4SLinus Torvalds 	 * Cumulative resource counters for dead threads in the group,
5911da177e4SLinus Torvalds 	 * and for reaped dead child processes forked by this group.
5921da177e4SLinus Torvalds 	 * Live threads maintain their own counters and add to these
5931da177e4SLinus Torvalds 	 * in __exit_signal, except for the group leader.
5941da177e4SLinus Torvalds 	 */
59532bd671dSPeter Zijlstra 	cputime_t utime, stime, cutime, cstime;
5969ac52315SLaurent Vivier 	cputime_t gtime;
5979ac52315SLaurent Vivier 	cputime_t cgtime;
5981da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
5991da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
6006eaeeabaSEric Dumazet 	unsigned long inblock, oublock, cinblock, coublock;
601940389b8SAndrea Righi 	struct task_io_accounting ioac;
6021da177e4SLinus Torvalds 
6031da177e4SLinus Torvalds 	/*
60432bd671dSPeter Zijlstra 	 * Cumulative ns of schedule CPU time fo dead threads in the
60532bd671dSPeter Zijlstra 	 * group, not including a zombie group leader, (This only differs
60632bd671dSPeter Zijlstra 	 * from jiffies_to_ns(utime + stime) if sched_clock uses something
60732bd671dSPeter Zijlstra 	 * other than jiffies.)
60832bd671dSPeter Zijlstra 	 */
60932bd671dSPeter Zijlstra 	unsigned long long sum_sched_runtime;
61032bd671dSPeter Zijlstra 
61132bd671dSPeter Zijlstra 	/*
6121da177e4SLinus Torvalds 	 * We don't bother to synchronize most readers of this at all,
6131da177e4SLinus Torvalds 	 * because there is no reader checking a limit that actually needs
6141da177e4SLinus Torvalds 	 * to get both rlim_cur and rlim_max atomically, and either one
6151da177e4SLinus Torvalds 	 * alone is a single word that can safely be read normally.
6161da177e4SLinus Torvalds 	 * getrlimit/setrlimit use task_lock(current->group_leader) to
6171da177e4SLinus Torvalds 	 * protect this instead of the siglock, because they really
6181da177e4SLinus Torvalds 	 * have no need to disable irqs.
6191da177e4SLinus Torvalds 	 */
6201da177e4SLinus Torvalds 	struct rlimit rlim[RLIM_NLIMITS];
6211da177e4SLinus Torvalds 
6220e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT
6230e464814SKaiGai Kohei 	struct pacct_struct pacct;	/* per-process accounting information */
6240e464814SKaiGai Kohei #endif
625ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS
626ad4ecbcbSShailabh Nagar 	struct taskstats *stats;
627ad4ecbcbSShailabh Nagar #endif
628522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT
629522ed776SMiloslav Trmac 	unsigned audit_tty;
630522ed776SMiloslav Trmac 	struct tty_audit_buf *tty_audit_buf;
631522ed776SMiloslav Trmac #endif
6321da177e4SLinus Torvalds };
6331da177e4SLinus Torvalds 
6344866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */
6354866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
6364866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW
6374866cde0SNick Piggin #endif
6384866cde0SNick Piggin 
6391da177e4SLinus Torvalds /*
6401da177e4SLinus Torvalds  * Bits in flags field of signal_struct.
6411da177e4SLinus Torvalds  */
6421da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED	0x00000001 /* job control stop in effect */
6431da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED	0x00000002 /* stop signal dequeued */
6441da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED	0x00000004 /* SIGCONT since WCONTINUED reap */
6451da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT	0x00000008 /* group exit in progress */
646e4420551SOleg Nesterov /*
647e4420551SOleg Nesterov  * Pending notifications to parent.
648e4420551SOleg Nesterov  */
649e4420551SOleg Nesterov #define SIGNAL_CLD_STOPPED	0x00000010
650e4420551SOleg Nesterov #define SIGNAL_CLD_CONTINUED	0x00000020
651e4420551SOleg Nesterov #define SIGNAL_CLD_MASK		(SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
6521da177e4SLinus Torvalds 
653fae5fa44SOleg Nesterov #define SIGNAL_UNKILLABLE	0x00000040 /* for init: ignore fatal signals */
654fae5fa44SOleg Nesterov 
655ed5d2cacSOleg Nesterov /* If true, all threads except ->group_exit_task have pending SIGKILL */
656ed5d2cacSOleg Nesterov static inline int signal_group_exit(const struct signal_struct *sig)
657ed5d2cacSOleg Nesterov {
658ed5d2cacSOleg Nesterov 	return	(sig->flags & SIGNAL_GROUP_EXIT) ||
659ed5d2cacSOleg Nesterov 		(sig->group_exit_task != NULL);
660ed5d2cacSOleg Nesterov }
661ed5d2cacSOleg Nesterov 
6621da177e4SLinus Torvalds /*
6631da177e4SLinus Torvalds  * Some day this will be a full-fledged user tracking system..
6641da177e4SLinus Torvalds  */
6651da177e4SLinus Torvalds struct user_struct {
6661da177e4SLinus Torvalds 	atomic_t __count;	/* reference count */
6671da177e4SLinus Torvalds 	atomic_t processes;	/* How many processes does this user have? */
6681da177e4SLinus Torvalds 	atomic_t files;		/* How many open files does this user have? */
6691da177e4SLinus Torvalds 	atomic_t sigpending;	/* How many pending signals does this user have? */
6702d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
6710eeca283SRobert Love 	atomic_t inotify_watches; /* How many inotify watches does this user have? */
6720eeca283SRobert Love 	atomic_t inotify_devs;	/* How many inotify devs does this user have opened? */
6730eeca283SRobert Love #endif
6747ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
6757ef9964eSDavide Libenzi 	atomic_t epoll_watches;	/* The number of file descriptors currently watched */
6767ef9964eSDavide Libenzi #endif
677970a8645SAlexey Dobriyan #ifdef CONFIG_POSIX_MQUEUE
6781da177e4SLinus Torvalds 	/* protected by mq_lock	*/
6791da177e4SLinus Torvalds 	unsigned long mq_bytes;	/* How many bytes can be allocated to mqueue? */
680970a8645SAlexey Dobriyan #endif
6811da177e4SLinus Torvalds 	unsigned long locked_shm; /* How many pages of mlocked shm ? */
6821da177e4SLinus Torvalds 
6831da177e4SLinus Torvalds #ifdef CONFIG_KEYS
6841da177e4SLinus Torvalds 	struct key *uid_keyring;	/* UID specific keyring */
6851da177e4SLinus Torvalds 	struct key *session_keyring;	/* UID's default session keyring */
6861da177e4SLinus Torvalds #endif
6871da177e4SLinus Torvalds 
6881da177e4SLinus Torvalds 	/* Hash table maintenance information */
689735de223SPavel Emelyanov 	struct hlist_node uidhash_node;
6901da177e4SLinus Torvalds 	uid_t uid;
69118b6e041SSerge Hallyn 	struct user_namespace *user_ns;
69224e377a8SSrivatsa Vaddagiri 
693052f1dc7SPeter Zijlstra #ifdef CONFIG_USER_SCHED
6944cf86d77SIngo Molnar 	struct task_group *tg;
695b1a8c172SDhaval Giani #ifdef CONFIG_SYSFS
696eb41d946SKay Sievers 	struct kobject kobj;
6973959214fSKay Sievers 	struct delayed_work work;
69824e377a8SSrivatsa Vaddagiri #endif
699b1a8c172SDhaval Giani #endif
700789f90fcSPeter Zijlstra 
701789f90fcSPeter Zijlstra #ifdef CONFIG_PERF_COUNTERS
702789f90fcSPeter Zijlstra 	atomic_long_t locked_vm;
703789f90fcSPeter Zijlstra #endif
7041da177e4SLinus Torvalds };
7051da177e4SLinus Torvalds 
706eb41d946SKay Sievers extern int uids_sysfs_init(void);
7075cb350baSDhaval Giani 
7081da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t);
7091da177e4SLinus Torvalds 
7101da177e4SLinus Torvalds extern struct user_struct root_user;
7111da177e4SLinus Torvalds #define INIT_USER (&root_user)
7121da177e4SLinus Torvalds 
713b6dff3ecSDavid Howells 
7141da177e4SLinus Torvalds struct backing_dev_info;
7151da177e4SLinus Torvalds struct reclaim_state;
7161da177e4SLinus Torvalds 
71752f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
7181da177e4SLinus Torvalds struct sched_info {
7191da177e4SLinus Torvalds 	/* cumulative counters */
7202d72376bSIngo Molnar 	unsigned long pcount;	      /* # of times run on this cpu */
7219c2c4802SKen Chen 	unsigned long long run_delay; /* time spent waiting on a runqueue */
7221da177e4SLinus Torvalds 
7231da177e4SLinus Torvalds 	/* timestamps */
724172ba844SBalbir Singh 	unsigned long long last_arrival,/* when we last ran on a cpu */
7251da177e4SLinus Torvalds 			   last_queued;	/* when we were last queued to run */
726b8efb561SIngo Molnar #ifdef CONFIG_SCHEDSTATS
727b8efb561SIngo Molnar 	/* BKL stats */
728480b9434SKen Chen 	unsigned int bkl_count;
729b8efb561SIngo Molnar #endif
7301da177e4SLinus Torvalds };
73152f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
7321da177e4SLinus Torvalds 
733ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT
734ca74e92bSShailabh Nagar struct task_delay_info {
735ca74e92bSShailabh Nagar 	spinlock_t	lock;
736ca74e92bSShailabh Nagar 	unsigned int	flags;	/* Private per-task flags */
737ca74e92bSShailabh Nagar 
738ca74e92bSShailabh Nagar 	/* For each stat XXX, add following, aligned appropriately
739ca74e92bSShailabh Nagar 	 *
740ca74e92bSShailabh Nagar 	 * struct timespec XXX_start, XXX_end;
741ca74e92bSShailabh Nagar 	 * u64 XXX_delay;
742ca74e92bSShailabh Nagar 	 * u32 XXX_count;
743ca74e92bSShailabh Nagar 	 *
744ca74e92bSShailabh Nagar 	 * Atomicity of updates to XXX_delay, XXX_count protected by
745ca74e92bSShailabh Nagar 	 * single lock above (split into XXX_lock if contention is an issue).
746ca74e92bSShailabh Nagar 	 */
7470ff92245SShailabh Nagar 
7480ff92245SShailabh Nagar 	/*
7490ff92245SShailabh Nagar 	 * XXX_count is incremented on every XXX operation, the delay
7500ff92245SShailabh Nagar 	 * associated with the operation is added to XXX_delay.
7510ff92245SShailabh Nagar 	 * XXX_delay contains the accumulated delay time in nanoseconds.
7520ff92245SShailabh Nagar 	 */
7530ff92245SShailabh Nagar 	struct timespec blkio_start, blkio_end;	/* Shared by blkio, swapin */
7540ff92245SShailabh Nagar 	u64 blkio_delay;	/* wait for sync block io completion */
7550ff92245SShailabh Nagar 	u64 swapin_delay;	/* wait for swapin block io completion */
7560ff92245SShailabh Nagar 	u32 blkio_count;	/* total count of the number of sync block */
7570ff92245SShailabh Nagar 				/* io operations performed */
7580ff92245SShailabh Nagar 	u32 swapin_count;	/* total count of the number of swapin block */
7590ff92245SShailabh Nagar 				/* io operations performed */
760873b4771SKeika Kobayashi 
761873b4771SKeika Kobayashi 	struct timespec freepages_start, freepages_end;
762873b4771SKeika Kobayashi 	u64 freepages_delay;	/* wait for memory reclaim */
763873b4771SKeika Kobayashi 	u32 freepages_count;	/* total count of memory reclaim */
764ca74e92bSShailabh Nagar };
76552f17b6cSChandra Seetharaman #endif	/* CONFIG_TASK_DELAY_ACCT */
76652f17b6cSChandra Seetharaman 
76752f17b6cSChandra Seetharaman static inline int sched_info_on(void)
76852f17b6cSChandra Seetharaman {
76952f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS
77052f17b6cSChandra Seetharaman 	return 1;
77152f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT)
77252f17b6cSChandra Seetharaman 	extern int delayacct_on;
77352f17b6cSChandra Seetharaman 	return delayacct_on;
77452f17b6cSChandra Seetharaman #else
77552f17b6cSChandra Seetharaman 	return 0;
776ca74e92bSShailabh Nagar #endif
77752f17b6cSChandra Seetharaman }
778ca74e92bSShailabh Nagar 
779d15bcfdbSIngo Molnar enum cpu_idle_type {
780d15bcfdbSIngo Molnar 	CPU_IDLE,
781d15bcfdbSIngo Molnar 	CPU_NOT_IDLE,
782d15bcfdbSIngo Molnar 	CPU_NEWLY_IDLE,
783d15bcfdbSIngo Molnar 	CPU_MAX_IDLE_TYPES
7841da177e4SLinus Torvalds };
7851da177e4SLinus Torvalds 
7861da177e4SLinus Torvalds /*
7871da177e4SLinus Torvalds  * sched-domains (multiprocessor balancing) declarations:
7881da177e4SLinus Torvalds  */
7899aa7b369SIngo Molnar 
7909aa7b369SIngo Molnar /*
7919aa7b369SIngo Molnar  * Increase resolution of nice-level calculations:
7929aa7b369SIngo Molnar  */
7939aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT	10
7949aa7b369SIngo Molnar #define SCHED_LOAD_SCALE	(1L << SCHED_LOAD_SHIFT)
7959aa7b369SIngo Molnar 
796f8700df7SSuresh Siddha #define SCHED_LOAD_SCALE_FUZZ	SCHED_LOAD_SCALE
7971da177e4SLinus Torvalds 
7982dd73a4fSPeter Williams #ifdef CONFIG_SMP
7991da177e4SLinus Torvalds #define SD_LOAD_BALANCE		1	/* Do load balancing on this domain. */
8001da177e4SLinus Torvalds #define SD_BALANCE_NEWIDLE	2	/* Balance when about to become idle */
8011da177e4SLinus Torvalds #define SD_BALANCE_EXEC		4	/* Balance on exec */
802147cbb4bSNick Piggin #define SD_BALANCE_FORK		8	/* Balance on fork, clone */
803147cbb4bSNick Piggin #define SD_WAKE_IDLE		16	/* Wake to idle CPU on task wakeup */
804147cbb4bSNick Piggin #define SD_WAKE_AFFINE		32	/* Wake task to waking CPU */
805147cbb4bSNick Piggin #define SD_WAKE_BALANCE		64	/* Perform balancing at task wakeup */
806147cbb4bSNick Piggin #define SD_SHARE_CPUPOWER	128	/* Domain members share cpu power */
8075c45bf27SSiddha, Suresh B #define SD_POWERSAVINGS_BALANCE	256	/* Balance for power savings */
80889c4710eSSiddha, Suresh B #define SD_SHARE_PKG_RESOURCES	512	/* Domain members share cpu pkg resources */
80908c183f3SChristoph Lameter #define SD_SERIALIZE		1024	/* Only a single load balancing instance */
8101d3504fcSHidetoshi Seto #define SD_WAKE_IDLE_FAR	2048	/* Gain latency sacrificing cache hit */
8115c45bf27SSiddha, Suresh B 
812afb8a9b7SGautham R Shenoy enum powersavings_balance_level {
813afb8a9b7SGautham R Shenoy 	POWERSAVINGS_BALANCE_NONE = 0,  /* No power saving load balance */
814afb8a9b7SGautham R Shenoy 	POWERSAVINGS_BALANCE_BASIC,	/* Fill one thread/core/package
815afb8a9b7SGautham R Shenoy 					 * first for long running threads
816afb8a9b7SGautham R Shenoy 					 */
817afb8a9b7SGautham R Shenoy 	POWERSAVINGS_BALANCE_WAKEUP,	/* Also bias task wakeups to semi-idle
818afb8a9b7SGautham R Shenoy 					 * cpu package for power savings
819afb8a9b7SGautham R Shenoy 					 */
820afb8a9b7SGautham R Shenoy 	MAX_POWERSAVINGS_BALANCE_LEVELS
821afb8a9b7SGautham R Shenoy };
82289c4710eSSiddha, Suresh B 
823716707b2SVaidyanathan Srinivasan extern int sched_mc_power_savings, sched_smt_power_savings;
82489c4710eSSiddha, Suresh B 
825716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_mc_power(void)
826716707b2SVaidyanathan Srinivasan {
827716707b2SVaidyanathan Srinivasan 	if (sched_smt_power_savings)
828716707b2SVaidyanathan Srinivasan 		return SD_POWERSAVINGS_BALANCE;
8295c45bf27SSiddha, Suresh B 
830716707b2SVaidyanathan Srinivasan 	return 0;
831716707b2SVaidyanathan Srinivasan }
832716707b2SVaidyanathan Srinivasan 
833716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_package_power(void)
834716707b2SVaidyanathan Srinivasan {
835716707b2SVaidyanathan Srinivasan 	if (sched_mc_power_savings | sched_smt_power_savings)
836716707b2SVaidyanathan Srinivasan 		return SD_POWERSAVINGS_BALANCE;
837716707b2SVaidyanathan Srinivasan 
838716707b2SVaidyanathan Srinivasan 	return 0;
839716707b2SVaidyanathan Srinivasan }
8401da177e4SLinus Torvalds 
841100fdaeeSVaidyanathan Srinivasan /*
842100fdaeeSVaidyanathan Srinivasan  * Optimise SD flags for power savings:
843100fdaeeSVaidyanathan Srinivasan  * SD_BALANCE_NEWIDLE helps agressive task consolidation and power savings.
844100fdaeeSVaidyanathan Srinivasan  * Keep default SD flags if sched_{smt,mc}_power_saving=0
845100fdaeeSVaidyanathan Srinivasan  */
846100fdaeeSVaidyanathan Srinivasan 
847100fdaeeSVaidyanathan Srinivasan static inline int sd_power_saving_flags(void)
848100fdaeeSVaidyanathan Srinivasan {
849100fdaeeSVaidyanathan Srinivasan 	if (sched_mc_power_savings | sched_smt_power_savings)
850100fdaeeSVaidyanathan Srinivasan 		return SD_BALANCE_NEWIDLE;
851100fdaeeSVaidyanathan Srinivasan 
852100fdaeeSVaidyanathan Srinivasan 	return 0;
853100fdaeeSVaidyanathan Srinivasan }
8541da177e4SLinus Torvalds 
8551da177e4SLinus Torvalds struct sched_group {
8561da177e4SLinus Torvalds 	struct sched_group *next;	/* Must be a circular list */
8571da177e4SLinus Torvalds 
8581da177e4SLinus Torvalds 	/*
8591da177e4SLinus Torvalds 	 * CPU power of this group, SCHED_LOAD_SCALE being max power for a
8601da177e4SLinus Torvalds 	 * single CPU. This is read only (except for setup, hotplug CPU).
8615517d86bSEric Dumazet 	 * Note : Never change cpu_power without recompute its reciprocal
8621da177e4SLinus Torvalds 	 */
8635517d86bSEric Dumazet 	unsigned int __cpu_power;
8645517d86bSEric Dumazet 	/*
8655517d86bSEric Dumazet 	 * reciprocal value of cpu_power to avoid expensive divides
8665517d86bSEric Dumazet 	 * (see include/linux/reciprocal_div.h)
8675517d86bSEric Dumazet 	 */
8685517d86bSEric Dumazet 	u32 reciprocal_cpu_power;
8696c99e9adSRusty Russell 
8704200efd9SIngo Molnar 	/*
8714200efd9SIngo Molnar 	 * The CPUs this group covers.
8724200efd9SIngo Molnar 	 *
8734200efd9SIngo Molnar 	 * NOTE: this field is variable length. (Allocated dynamically
8744200efd9SIngo Molnar 	 * by attaching extra space to the end of the structure,
8754200efd9SIngo Molnar 	 * depending on how many CPUs the kernel has booted up with)
8764200efd9SIngo Molnar 	 *
8774200efd9SIngo Molnar 	 * It is also be embedded into static data structures at build
8784200efd9SIngo Molnar 	 * time. (See 'struct static_sched_group' in kernel/sched.c)
8794200efd9SIngo Molnar 	 */
8804200efd9SIngo Molnar 	unsigned long cpumask[0];
8811da177e4SLinus Torvalds };
8821da177e4SLinus Torvalds 
883758b2cdcSRusty Russell static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
884758b2cdcSRusty Russell {
8856c99e9adSRusty Russell 	return to_cpumask(sg->cpumask);
886758b2cdcSRusty Russell }
887758b2cdcSRusty Russell 
8881d3504fcSHidetoshi Seto enum sched_domain_level {
8891d3504fcSHidetoshi Seto 	SD_LV_NONE = 0,
8901d3504fcSHidetoshi Seto 	SD_LV_SIBLING,
8911d3504fcSHidetoshi Seto 	SD_LV_MC,
8921d3504fcSHidetoshi Seto 	SD_LV_CPU,
8931d3504fcSHidetoshi Seto 	SD_LV_NODE,
8941d3504fcSHidetoshi Seto 	SD_LV_ALLNODES,
8951d3504fcSHidetoshi Seto 	SD_LV_MAX
8961d3504fcSHidetoshi Seto };
8971d3504fcSHidetoshi Seto 
8981d3504fcSHidetoshi Seto struct sched_domain_attr {
8991d3504fcSHidetoshi Seto 	int relax_domain_level;
9001d3504fcSHidetoshi Seto };
9011d3504fcSHidetoshi Seto 
9021d3504fcSHidetoshi Seto #define SD_ATTR_INIT	(struct sched_domain_attr) {	\
9031d3504fcSHidetoshi Seto 	.relax_domain_level = -1,			\
9041d3504fcSHidetoshi Seto }
9051d3504fcSHidetoshi Seto 
9061da177e4SLinus Torvalds struct sched_domain {
9071da177e4SLinus Torvalds 	/* These fields must be setup */
9081da177e4SLinus Torvalds 	struct sched_domain *parent;	/* top domain must be null terminated */
9091a848870SSiddha, Suresh B 	struct sched_domain *child;	/* bottom domain must be null terminated */
9101da177e4SLinus Torvalds 	struct sched_group *groups;	/* the balancing groups of the domain */
9111da177e4SLinus Torvalds 	unsigned long min_interval;	/* Minimum balance interval ms */
9121da177e4SLinus Torvalds 	unsigned long max_interval;	/* Maximum balance interval ms */
9131da177e4SLinus Torvalds 	unsigned int busy_factor;	/* less balancing by factor if busy */
9141da177e4SLinus Torvalds 	unsigned int imbalance_pct;	/* No balance until over watermark */
9151da177e4SLinus Torvalds 	unsigned int cache_nice_tries;	/* Leave cache hot tasks for # tries */
9167897986bSNick Piggin 	unsigned int busy_idx;
9177897986bSNick Piggin 	unsigned int idle_idx;
9187897986bSNick Piggin 	unsigned int newidle_idx;
9197897986bSNick Piggin 	unsigned int wake_idx;
920147cbb4bSNick Piggin 	unsigned int forkexec_idx;
9211da177e4SLinus Torvalds 	int flags;			/* See SD_* */
9221d3504fcSHidetoshi Seto 	enum sched_domain_level level;
9231da177e4SLinus Torvalds 
9241da177e4SLinus Torvalds 	/* Runtime fields. */
9251da177e4SLinus Torvalds 	unsigned long last_balance;	/* init to jiffies. units in jiffies */
9261da177e4SLinus Torvalds 	unsigned int balance_interval;	/* initialise to 1. units in ms. */
9271da177e4SLinus Torvalds 	unsigned int nr_balance_failed; /* initialise to 0 */
9281da177e4SLinus Torvalds 
9292398f2c6SPeter Zijlstra 	u64 last_update;
9302398f2c6SPeter Zijlstra 
9311da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS
9321da177e4SLinus Torvalds 	/* load_balance() stats */
933480b9434SKen Chen 	unsigned int lb_count[CPU_MAX_IDLE_TYPES];
934480b9434SKen Chen 	unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
935480b9434SKen Chen 	unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
936480b9434SKen Chen 	unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
937480b9434SKen Chen 	unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
938480b9434SKen Chen 	unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
939480b9434SKen Chen 	unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
940480b9434SKen Chen 	unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
9411da177e4SLinus Torvalds 
9421da177e4SLinus Torvalds 	/* Active load balancing */
943480b9434SKen Chen 	unsigned int alb_count;
944480b9434SKen Chen 	unsigned int alb_failed;
945480b9434SKen Chen 	unsigned int alb_pushed;
9461da177e4SLinus Torvalds 
94768767a0aSNick Piggin 	/* SD_BALANCE_EXEC stats */
948480b9434SKen Chen 	unsigned int sbe_count;
949480b9434SKen Chen 	unsigned int sbe_balanced;
950480b9434SKen Chen 	unsigned int sbe_pushed;
9511da177e4SLinus Torvalds 
95268767a0aSNick Piggin 	/* SD_BALANCE_FORK stats */
953480b9434SKen Chen 	unsigned int sbf_count;
954480b9434SKen Chen 	unsigned int sbf_balanced;
955480b9434SKen Chen 	unsigned int sbf_pushed;
95668767a0aSNick Piggin 
9571da177e4SLinus Torvalds 	/* try_to_wake_up() stats */
958480b9434SKen Chen 	unsigned int ttwu_wake_remote;
959480b9434SKen Chen 	unsigned int ttwu_move_affine;
960480b9434SKen Chen 	unsigned int ttwu_move_balance;
9611da177e4SLinus Torvalds #endif
962a5d8c348SIngo Molnar #ifdef CONFIG_SCHED_DEBUG
963a5d8c348SIngo Molnar 	char *name;
964a5d8c348SIngo Molnar #endif
9656c99e9adSRusty Russell 
9664200efd9SIngo Molnar 	/*
9674200efd9SIngo Molnar 	 * Span of all CPUs in this domain.
9684200efd9SIngo Molnar 	 *
9694200efd9SIngo Molnar 	 * NOTE: this field is variable length. (Allocated dynamically
9704200efd9SIngo Molnar 	 * by attaching extra space to the end of the structure,
9714200efd9SIngo Molnar 	 * depending on how many CPUs the kernel has booted up with)
9724200efd9SIngo Molnar 	 *
9734200efd9SIngo Molnar 	 * It is also be embedded into static data structures at build
9744200efd9SIngo Molnar 	 * time. (See 'struct static_sched_domain' in kernel/sched.c)
9754200efd9SIngo Molnar 	 */
9764200efd9SIngo Molnar 	unsigned long span[0];
9771da177e4SLinus Torvalds };
9781da177e4SLinus Torvalds 
979758b2cdcSRusty Russell static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
980758b2cdcSRusty Russell {
9816c99e9adSRusty Russell 	return to_cpumask(sd->span);
982758b2cdcSRusty Russell }
983758b2cdcSRusty Russell 
98496f874e2SRusty Russell extern void partition_sched_domains(int ndoms_new, struct cpumask *doms_new,
9851d3504fcSHidetoshi Seto 				    struct sched_domain_attr *dattr_new);
986029190c5SPaul Jackson 
98706aaf76aSIngo Molnar /* Test a flag in parent sched domain */
98806aaf76aSIngo Molnar static inline int test_sd_parent(struct sched_domain *sd, int flag)
98906aaf76aSIngo Molnar {
99006aaf76aSIngo Molnar 	if (sd->parent && (sd->parent->flags & flag))
99106aaf76aSIngo Molnar 		return 1;
99206aaf76aSIngo Molnar 
99306aaf76aSIngo Molnar 	return 0;
99406aaf76aSIngo Molnar }
9951da177e4SLinus Torvalds 
9961b427c15SIngo Molnar #else /* CONFIG_SMP */
9971da177e4SLinus Torvalds 
9981b427c15SIngo Molnar struct sched_domain_attr;
9991b427c15SIngo Molnar 
10001b427c15SIngo Molnar static inline void
100196f874e2SRusty Russell partition_sched_domains(int ndoms_new, struct cpumask *doms_new,
10021b427c15SIngo Molnar 			struct sched_domain_attr *dattr_new)
1003d02c7a8cSCon Kolivas {
1004d02c7a8cSCon Kolivas }
10051b427c15SIngo Molnar #endif	/* !CONFIG_SMP */
10061da177e4SLinus Torvalds 
10071da177e4SLinus Torvalds struct io_context;			/* See blkdev.h */
10081da177e4SLinus Torvalds 
10091da177e4SLinus Torvalds 
1010383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
101136c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t);
1012383f2835SChen, Kenneth W #else
1013383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { }
1014383f2835SChen, Kenneth W #endif
10151da177e4SLinus Torvalds 
10161da177e4SLinus Torvalds struct audit_context;		/* See audit.c */
10171da177e4SLinus Torvalds struct mempolicy;
1018b92ce558SJens Axboe struct pipe_inode_info;
10194865ecf1SSerge E. Hallyn struct uts_namespace;
10201da177e4SLinus Torvalds 
102120b8a59fSIngo Molnar struct rq;
102220b8a59fSIngo Molnar struct sched_domain;
102320b8a59fSIngo Molnar 
102420b8a59fSIngo Molnar struct sched_class {
10255522d5d5SIngo Molnar 	const struct sched_class *next;
102620b8a59fSIngo Molnar 
1027fd390f6aSIngo Molnar 	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup);
1028f02231e5SIngo Molnar 	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep);
10294530d7abSDmitry Adamushko 	void (*yield_task) (struct rq *rq);
103020b8a59fSIngo Molnar 
103115afe09bSPeter Zijlstra 	void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int sync);
103220b8a59fSIngo Molnar 
1033fb8d4724SIngo Molnar 	struct task_struct * (*pick_next_task) (struct rq *rq);
103431ee529cSIngo Molnar 	void (*put_prev_task) (struct rq *rq, struct task_struct *p);
103520b8a59fSIngo Molnar 
1036681f3e68SPeter Williams #ifdef CONFIG_SMP
10374ce72a2cSLi Zefan 	int  (*select_task_rq)(struct task_struct *p, int sync);
10384ce72a2cSLi Zefan 
103943010659SPeter Williams 	unsigned long (*load_balance) (struct rq *this_rq, int this_cpu,
1040e1d1484fSPeter Williams 			struct rq *busiest, unsigned long max_load_move,
104120b8a59fSIngo Molnar 			struct sched_domain *sd, enum cpu_idle_type idle,
1042a4ac01c3SPeter Williams 			int *all_pinned, int *this_best_prio);
104320b8a59fSIngo Molnar 
1044e1d1484fSPeter Williams 	int (*move_one_task) (struct rq *this_rq, int this_cpu,
1045e1d1484fSPeter Williams 			      struct rq *busiest, struct sched_domain *sd,
1046e1d1484fSPeter Williams 			      enum cpu_idle_type idle);
10479a897c5aSSteven Rostedt 	void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
1048967fc046SGregory Haskins 	int (*needs_post_schedule) (struct rq *this_rq);
10499a897c5aSSteven Rostedt 	void (*post_schedule) (struct rq *this_rq);
10509a897c5aSSteven Rostedt 	void (*task_wake_up) (struct rq *this_rq, struct task_struct *task);
1051e1d1484fSPeter Williams 
1052cd8ba7cdSMike Travis 	void (*set_cpus_allowed)(struct task_struct *p,
105396f874e2SRusty Russell 				 const struct cpumask *newmask);
105457d885feSGregory Haskins 
10551f11eb6aSGregory Haskins 	void (*rq_online)(struct rq *rq);
10561f11eb6aSGregory Haskins 	void (*rq_offline)(struct rq *rq);
10574ce72a2cSLi Zefan #endif
10584ce72a2cSLi Zefan 
10594ce72a2cSLi Zefan 	void (*set_curr_task) (struct rq *rq);
10604ce72a2cSLi Zefan 	void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
10614ce72a2cSLi Zefan 	void (*task_new) (struct rq *rq, struct task_struct *p);
1062cb469845SSteven Rostedt 
1063cb469845SSteven Rostedt 	void (*switched_from) (struct rq *this_rq, struct task_struct *task,
1064cb469845SSteven Rostedt 			       int running);
1065cb469845SSteven Rostedt 	void (*switched_to) (struct rq *this_rq, struct task_struct *task,
1066cb469845SSteven Rostedt 			     int running);
1067cb469845SSteven Rostedt 	void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
1068cb469845SSteven Rostedt 			     int oldprio, int running);
1069810b3817SPeter Zijlstra 
1070810b3817SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED
1071810b3817SPeter Zijlstra 	void (*moved_group) (struct task_struct *p);
1072810b3817SPeter Zijlstra #endif
107320b8a59fSIngo Molnar };
107420b8a59fSIngo Molnar 
107520b8a59fSIngo Molnar struct load_weight {
107620b8a59fSIngo Molnar 	unsigned long weight, inv_weight;
107720b8a59fSIngo Molnar };
107820b8a59fSIngo Molnar 
107920b8a59fSIngo Molnar /*
108020b8a59fSIngo Molnar  * CFS stats for a schedulable entity (task, task-group etc)
108120b8a59fSIngo Molnar  *
108220b8a59fSIngo Molnar  * Current field usage histogram:
108320b8a59fSIngo Molnar  *
108420b8a59fSIngo Molnar  *     4 se->block_start
108520b8a59fSIngo Molnar  *     4 se->run_node
108620b8a59fSIngo Molnar  *     4 se->sleep_start
108720b8a59fSIngo Molnar  *     6 se->load.weight
108820b8a59fSIngo Molnar  */
108920b8a59fSIngo Molnar struct sched_entity {
109020b8a59fSIngo Molnar 	struct load_weight	load;		/* for load-balancing */
109120b8a59fSIngo Molnar 	struct rb_node		run_node;
10924a55bd5eSPeter Zijlstra 	struct list_head	group_node;
109320b8a59fSIngo Molnar 	unsigned int		on_rq;
109420b8a59fSIngo Molnar 
109520b8a59fSIngo Molnar 	u64			exec_start;
109694c18227SIngo Molnar 	u64			sum_exec_runtime;
1097e9acbff6SIngo Molnar 	u64			vruntime;
1098f6cf891cSIngo Molnar 	u64			prev_sum_exec_runtime;
109994c18227SIngo Molnar 
11004ae7d5ceSIngo Molnar 	u64			last_wakeup;
11014ae7d5ceSIngo Molnar 	u64			avg_overlap;
11024ae7d5ceSIngo Molnar 
11036c594c21SIngo Molnar 	u64			nr_migrations;
11046c594c21SIngo Molnar 
110534cb6135SIngo Molnar 	u64			start_runtime;
110634cb6135SIngo Molnar 	u64			avg_wakeup;
110734cb6135SIngo Molnar 
110894c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS
110994c18227SIngo Molnar 	u64			wait_start;
111094c18227SIngo Molnar 	u64			wait_max;
11116d082592SArjan van de Ven 	u64			wait_count;
11126d082592SArjan van de Ven 	u64			wait_sum;
111394c18227SIngo Molnar 
111494c18227SIngo Molnar 	u64			sleep_start;
111520b8a59fSIngo Molnar 	u64			sleep_max;
111694c18227SIngo Molnar 	s64			sum_sleep_runtime;
111794c18227SIngo Molnar 
111894c18227SIngo Molnar 	u64			block_start;
111920b8a59fSIngo Molnar 	u64			block_max;
112020b8a59fSIngo Molnar 	u64			exec_max;
1121eba1ed4bSIngo Molnar 	u64			slice_max;
1122cc367732SIngo Molnar 
1123cc367732SIngo Molnar 	u64			nr_migrations_cold;
1124cc367732SIngo Molnar 	u64			nr_failed_migrations_affine;
1125cc367732SIngo Molnar 	u64			nr_failed_migrations_running;
1126cc367732SIngo Molnar 	u64			nr_failed_migrations_hot;
1127cc367732SIngo Molnar 	u64			nr_forced_migrations;
1128cc367732SIngo Molnar 	u64			nr_forced2_migrations;
1129cc367732SIngo Molnar 
1130cc367732SIngo Molnar 	u64			nr_wakeups;
1131cc367732SIngo Molnar 	u64			nr_wakeups_sync;
1132cc367732SIngo Molnar 	u64			nr_wakeups_migrate;
1133cc367732SIngo Molnar 	u64			nr_wakeups_local;
1134cc367732SIngo Molnar 	u64			nr_wakeups_remote;
1135cc367732SIngo Molnar 	u64			nr_wakeups_affine;
1136cc367732SIngo Molnar 	u64			nr_wakeups_affine_attempts;
1137cc367732SIngo Molnar 	u64			nr_wakeups_passive;
1138cc367732SIngo Molnar 	u64			nr_wakeups_idle;
113994c18227SIngo Molnar #endif
114094c18227SIngo Molnar 
114120b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED
114220b8a59fSIngo Molnar 	struct sched_entity	*parent;
114320b8a59fSIngo Molnar 	/* rq on which this entity is (to be) queued: */
114420b8a59fSIngo Molnar 	struct cfs_rq		*cfs_rq;
114520b8a59fSIngo Molnar 	/* rq "owned" by this entity/group: */
114620b8a59fSIngo Molnar 	struct cfs_rq		*my_q;
114720b8a59fSIngo Molnar #endif
114820b8a59fSIngo Molnar };
114970b97a7fSIngo Molnar 
1150fa717060SPeter Zijlstra struct sched_rt_entity {
1151fa717060SPeter Zijlstra 	struct list_head run_list;
115278f2c7dbSPeter Zijlstra 	unsigned long timeout;
1153bee367edSRichard Kennedy 	unsigned int time_slice;
11546f505b16SPeter Zijlstra 	int nr_cpus_allowed;
11556f505b16SPeter Zijlstra 
115658d6c2d7SPeter Zijlstra 	struct sched_rt_entity *back;
1157052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED
11586f505b16SPeter Zijlstra 	struct sched_rt_entity	*parent;
11596f505b16SPeter Zijlstra 	/* rq on which this entity is (to be) queued: */
11606f505b16SPeter Zijlstra 	struct rt_rq		*rt_rq;
11616f505b16SPeter Zijlstra 	/* rq "owned" by this entity/group: */
11626f505b16SPeter Zijlstra 	struct rt_rq		*my_q;
11636f505b16SPeter Zijlstra #endif
1164fa717060SPeter Zijlstra };
1165fa717060SPeter Zijlstra 
1166*86848966SPaul E. McKenney struct rcu_node;
1167*86848966SPaul E. McKenney 
11681da177e4SLinus Torvalds struct task_struct {
11691da177e4SLinus Torvalds 	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
1170f7e4217bSRoman Zippel 	void *stack;
11711da177e4SLinus Torvalds 	atomic_t usage;
117297dc32cdSWilliam Cohen 	unsigned int flags;	/* per process flags, defined below */
117397dc32cdSWilliam Cohen 	unsigned int ptrace;
11741da177e4SLinus Torvalds 
117536772092SPaolo 'Blaisorblade' Giarrusso 	int lock_depth;		/* BKL lock depth */
11761da177e4SLinus Torvalds 
11772dd73a4fSPeter Williams #ifdef CONFIG_SMP
11782dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW
11794866cde0SNick Piggin 	int oncpu;
11804866cde0SNick Piggin #endif
11812dd73a4fSPeter Williams #endif
118250e645a8SIngo Molnar 
1183b29739f9SIngo Molnar 	int prio, static_prio, normal_prio;
1184c7aceabaSRichard Kennedy 	unsigned int rt_priority;
11855522d5d5SIngo Molnar 	const struct sched_class *sched_class;
118620b8a59fSIngo Molnar 	struct sched_entity se;
1187fa717060SPeter Zijlstra 	struct sched_rt_entity rt;
11881da177e4SLinus Torvalds 
1189e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS
1190e107be36SAvi Kivity 	/* list of struct preempt_notifier: */
1191e107be36SAvi Kivity 	struct hlist_head preempt_notifiers;
1192e107be36SAvi Kivity #endif
1193e107be36SAvi Kivity 
119418796aa0SAlexey Dobriyan 	/*
119518796aa0SAlexey Dobriyan 	 * fpu_counter contains the number of consecutive context switches
119618796aa0SAlexey Dobriyan 	 * that the FPU is used. If this is over a threshold, the lazy fpu
119718796aa0SAlexey Dobriyan 	 * saving becomes unlazy to save the trap. This is an unsigned char
119818796aa0SAlexey Dobriyan 	 * so that after 256 times the counter wraps and the behavior turns
119918796aa0SAlexey Dobriyan 	 * lazy again; this to deal with bursty apps that only use FPU for
120018796aa0SAlexey Dobriyan 	 * a short time
120118796aa0SAlexey Dobriyan 	 */
120218796aa0SAlexey Dobriyan 	unsigned char fpu_counter;
12036c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE
12042056a782SJens Axboe 	unsigned int btrace_seq;
12056c5c9341SAlexey Dobriyan #endif
12061da177e4SLinus Torvalds 
120797dc32cdSWilliam Cohen 	unsigned int policy;
12081da177e4SLinus Torvalds 	cpumask_t cpus_allowed;
12091da177e4SLinus Torvalds 
1210f41d911fSPaul E. McKenney #ifdef CONFIG_TREE_PREEMPT_RCU
1211f41d911fSPaul E. McKenney 	int rcu_read_lock_nesting;
1212f41d911fSPaul E. McKenney 	char rcu_read_unlock_special;
1213*86848966SPaul E. McKenney 	struct rcu_node *rcu_blocked_node;
1214f41d911fSPaul E. McKenney 	struct list_head rcu_node_entry;
1215f41d911fSPaul E. McKenney #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
1216f41d911fSPaul E. McKenney 
121752f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
12181da177e4SLinus Torvalds 	struct sched_info sched_info;
12191da177e4SLinus Torvalds #endif
12201da177e4SLinus Torvalds 
12211da177e4SLinus Torvalds 	struct list_head tasks;
1222917b627dSGregory Haskins 	struct plist_node pushable_tasks;
12231da177e4SLinus Torvalds 
12241da177e4SLinus Torvalds 	struct mm_struct *mm, *active_mm;
12251da177e4SLinus Torvalds 
12261da177e4SLinus Torvalds /* task state */
12271da177e4SLinus Torvalds 	struct linux_binfmt *binfmt;
122897dc32cdSWilliam Cohen 	int exit_state;
12291da177e4SLinus Torvalds 	int exit_code, exit_signal;
12301da177e4SLinus Torvalds 	int pdeath_signal;  /*  The signal sent when the parent dies  */
12311da177e4SLinus Torvalds 	/* ??? */
123297dc32cdSWilliam Cohen 	unsigned int personality;
12331da177e4SLinus Torvalds 	unsigned did_exec:1;
1234f9ce1f1cSKentaro Takeda 	unsigned in_execve:1;	/* Tell the LSMs that the process is doing an
1235f9ce1f1cSKentaro Takeda 				 * execve */
12361da177e4SLinus Torvalds 	pid_t pid;
12371da177e4SLinus Torvalds 	pid_t tgid;
12380a425405SArjan van de Ven 
12390a425405SArjan van de Ven 	/* Canary value for the -fstack-protector gcc feature */
12400a425405SArjan van de Ven 	unsigned long stack_canary;
1241e0032087SIngo Molnar 
12421da177e4SLinus Torvalds 	/*
12431da177e4SLinus Torvalds 	 * pointers to (original) parent process, youngest child, younger sibling,
12441da177e4SLinus Torvalds 	 * older sibling, respectively.  (p->father can be replaced with
1245f470021aSRoland McGrath 	 * p->real_parent->pid)
12461da177e4SLinus Torvalds 	 */
1247f470021aSRoland McGrath 	struct task_struct *real_parent; /* real parent process */
1248f470021aSRoland McGrath 	struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports */
12491da177e4SLinus Torvalds 	/*
1250f470021aSRoland McGrath 	 * children/sibling forms the list of my natural children
12511da177e4SLinus Torvalds 	 */
12521da177e4SLinus Torvalds 	struct list_head children;	/* list of my children */
12531da177e4SLinus Torvalds 	struct list_head sibling;	/* linkage in my parent's children list */
12541da177e4SLinus Torvalds 	struct task_struct *group_leader;	/* threadgroup leader */
12551da177e4SLinus Torvalds 
1256f470021aSRoland McGrath 	/*
1257f470021aSRoland McGrath 	 * ptraced is the list of tasks this task is using ptrace on.
1258f470021aSRoland McGrath 	 * This includes both natural children and PTRACE_ATTACH targets.
1259f470021aSRoland McGrath 	 * p->ptrace_entry is p's link on the p->parent->ptraced list.
1260f470021aSRoland McGrath 	 */
1261f470021aSRoland McGrath 	struct list_head ptraced;
1262f470021aSRoland McGrath 	struct list_head ptrace_entry;
1263f470021aSRoland McGrath 
1264ca0002a1SMarkus Metzger 	/*
1265ca0002a1SMarkus Metzger 	 * This is the tracer handle for the ptrace BTS extension.
1266ca0002a1SMarkus Metzger 	 * This field actually belongs to the ptracer task.
1267ca0002a1SMarkus Metzger 	 */
1268e2b371f0SMarkus Metzger 	struct bts_context *bts;
1269ca0002a1SMarkus Metzger 
12701da177e4SLinus Torvalds 	/* PID/PID hash table linkage. */
127192476d7fSEric W. Biederman 	struct pid_link pids[PIDTYPE_MAX];
127247e65328SOleg Nesterov 	struct list_head thread_group;
12731da177e4SLinus Torvalds 
12741da177e4SLinus Torvalds 	struct completion *vfork_done;		/* for vfork() */
12751da177e4SLinus Torvalds 	int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
12761da177e4SLinus Torvalds 	int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */
12771da177e4SLinus Torvalds 
1278c66f08beSMichael Neuling 	cputime_t utime, stime, utimescaled, stimescaled;
12799ac52315SLaurent Vivier 	cputime_t gtime;
12809301899bSBalbir Singh 	cputime_t prev_utime, prev_stime;
12811da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw; /* context switch counts */
1282924b42d5STomas Janousek 	struct timespec start_time; 		/* monotonic time */
1283924b42d5STomas Janousek 	struct timespec real_start_time;	/* boot based time */
12841da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
12851da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt;
12861da177e4SLinus Torvalds 
1287f06febc9SFrank Mayhar 	struct task_cputime cputime_expires;
12881da177e4SLinus Torvalds 	struct list_head cpu_timers[3];
12891da177e4SLinus Torvalds 
12901da177e4SLinus Torvalds /* process credentials */
12913b11a1deSDavid Howells 	const struct cred *real_cred;	/* objective and real subjective task
12923b11a1deSDavid Howells 					 * credentials (COW) */
12933b11a1deSDavid Howells 	const struct cred *cred;	/* effective (overridable) subjective task
12943b11a1deSDavid Howells 					 * credentials (COW) */
12955e751e99SDavid Howells 	struct mutex cred_guard_mutex;	/* guard against foreign influences on
12965e751e99SDavid Howells 					 * credential calculations
12975e751e99SDavid Howells 					 * (notably. ptrace) */
1298b6dff3ecSDavid Howells 
129936772092SPaolo 'Blaisorblade' Giarrusso 	char comm[TASK_COMM_LEN]; /* executable name excluding path
130036772092SPaolo 'Blaisorblade' Giarrusso 				     - access with [gs]et_task_comm (which lock
130136772092SPaolo 'Blaisorblade' Giarrusso 				       it with task_lock())
130236772092SPaolo 'Blaisorblade' Giarrusso 				     - initialized normally by flush_old_exec */
13031da177e4SLinus Torvalds /* file system info */
13041da177e4SLinus Torvalds 	int link_count, total_link_count;
13053d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC
13061da177e4SLinus Torvalds /* ipc stuff */
13071da177e4SLinus Torvalds 	struct sysv_sem sysvsem;
13083d5b6fccSAlexey Dobriyan #endif
1309e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
131082a1fcb9SIngo Molnar /* hung task detection */
131182a1fcb9SIngo Molnar 	unsigned long last_switch_count;
131282a1fcb9SIngo Molnar #endif
13131da177e4SLinus Torvalds /* CPU-specific state of this task */
13141da177e4SLinus Torvalds 	struct thread_struct thread;
13151da177e4SLinus Torvalds /* filesystem information */
13161da177e4SLinus Torvalds 	struct fs_struct *fs;
13171da177e4SLinus Torvalds /* open file information */
13181da177e4SLinus Torvalds 	struct files_struct *files;
13191651e14eSSerge E. Hallyn /* namespaces */
1320ab516013SSerge E. Hallyn 	struct nsproxy *nsproxy;
13211da177e4SLinus Torvalds /* signal handlers */
13221da177e4SLinus Torvalds 	struct signal_struct *signal;
13231da177e4SLinus Torvalds 	struct sighand_struct *sighand;
13241da177e4SLinus Torvalds 
13251da177e4SLinus Torvalds 	sigset_t blocked, real_blocked;
1326f3de272bSRoland McGrath 	sigset_t saved_sigmask;	/* restored if set_restore_sigmask() was used */
13271da177e4SLinus Torvalds 	struct sigpending pending;
13281da177e4SLinus Torvalds 
13291da177e4SLinus Torvalds 	unsigned long sas_ss_sp;
13301da177e4SLinus Torvalds 	size_t sas_ss_size;
13311da177e4SLinus Torvalds 	int (*notifier)(void *priv);
13321da177e4SLinus Torvalds 	void *notifier_data;
13331da177e4SLinus Torvalds 	sigset_t *notifier_mask;
13341da177e4SLinus Torvalds 	struct audit_context *audit_context;
1335bfef93a5SAl Viro #ifdef CONFIG_AUDITSYSCALL
1336bfef93a5SAl Viro 	uid_t loginuid;
13374746ec5bSEric Paris 	unsigned int sessionid;
1338bfef93a5SAl Viro #endif
13391da177e4SLinus Torvalds 	seccomp_t seccomp;
13401da177e4SLinus Torvalds 
13411da177e4SLinus Torvalds /* Thread group tracking */
13421da177e4SLinus Torvalds    	u32 parent_exec_id;
13431da177e4SLinus Torvalds    	u32 self_exec_id;
134458568d2aSMiao Xie /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
134558568d2aSMiao Xie  * mempolicy */
13461da177e4SLinus Torvalds 	spinlock_t alloc_lock;
13471da177e4SLinus Torvalds 
13483aa551c9SThomas Gleixner #ifdef CONFIG_GENERIC_HARDIRQS
13493aa551c9SThomas Gleixner 	/* IRQ handler threads */
13503aa551c9SThomas Gleixner 	struct irqaction *irqaction;
13513aa551c9SThomas Gleixner #endif
13523aa551c9SThomas Gleixner 
1353b29739f9SIngo Molnar 	/* Protection of the PI data structures: */
1354b29739f9SIngo Molnar 	spinlock_t pi_lock;
1355b29739f9SIngo Molnar 
135623f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
135723f78d4aSIngo Molnar 	/* PI waiters blocked on a rt_mutex held by this task */
135823f78d4aSIngo Molnar 	struct plist_head pi_waiters;
135923f78d4aSIngo Molnar 	/* Deadlock detection and priority inheritance handling */
136023f78d4aSIngo Molnar 	struct rt_mutex_waiter *pi_blocked_on;
136123f78d4aSIngo Molnar #endif
136223f78d4aSIngo Molnar 
1363408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES
1364408894eeSIngo Molnar 	/* mutex deadlock detection */
1365408894eeSIngo Molnar 	struct mutex_waiter *blocked_on;
1366408894eeSIngo Molnar #endif
1367de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS
1368de30a2b3SIngo Molnar 	unsigned int irq_events;
1369de30a2b3SIngo Molnar 	int hardirqs_enabled;
1370de30a2b3SIngo Molnar 	unsigned long hardirq_enable_ip;
1371de30a2b3SIngo Molnar 	unsigned int hardirq_enable_event;
1372de30a2b3SIngo Molnar 	unsigned long hardirq_disable_ip;
1373de30a2b3SIngo Molnar 	unsigned int hardirq_disable_event;
1374de30a2b3SIngo Molnar 	int softirqs_enabled;
1375de30a2b3SIngo Molnar 	unsigned long softirq_disable_ip;
1376de30a2b3SIngo Molnar 	unsigned int softirq_disable_event;
1377de30a2b3SIngo Molnar 	unsigned long softirq_enable_ip;
1378de30a2b3SIngo Molnar 	unsigned int softirq_enable_event;
1379de30a2b3SIngo Molnar 	int hardirq_context;
1380de30a2b3SIngo Molnar 	int softirq_context;
1381de30a2b3SIngo Molnar #endif
1382fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP
1383bdb9441eSPeter Zijlstra # define MAX_LOCK_DEPTH 48UL
1384fbb9ce95SIngo Molnar 	u64 curr_chain_key;
1385fbb9ce95SIngo Molnar 	int lockdep_depth;
1386fbb9ce95SIngo Molnar 	unsigned int lockdep_recursion;
1387c7aceabaSRichard Kennedy 	struct held_lock held_locks[MAX_LOCK_DEPTH];
1388cf40bd16SNick Piggin 	gfp_t lockdep_reclaim_gfp;
1389fbb9ce95SIngo Molnar #endif
1390408894eeSIngo Molnar 
13911da177e4SLinus Torvalds /* journalling filesystem info */
13921da177e4SLinus Torvalds 	void *journal_info;
13931da177e4SLinus Torvalds 
1394d89d8796SNeil Brown /* stacked block device info */
1395d89d8796SNeil Brown 	struct bio *bio_list, **bio_tail;
1396d89d8796SNeil Brown 
13971da177e4SLinus Torvalds /* VM state */
13981da177e4SLinus Torvalds 	struct reclaim_state *reclaim_state;
13991da177e4SLinus Torvalds 
14001da177e4SLinus Torvalds 	struct backing_dev_info *backing_dev_info;
14011da177e4SLinus Torvalds 
14021da177e4SLinus Torvalds 	struct io_context *io_context;
14031da177e4SLinus Torvalds 
14041da177e4SLinus Torvalds 	unsigned long ptrace_message;
14051da177e4SLinus Torvalds 	siginfo_t *last_siginfo; /* For ptrace use.  */
14067c3ab738SAndrew Morton 	struct task_io_accounting ioac;
14078f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT)
14081da177e4SLinus Torvalds 	u64 acct_rss_mem1;	/* accumulated rss usage */
14091da177e4SLinus Torvalds 	u64 acct_vm_mem1;	/* accumulated virtual memory usage */
141049b5cf34SJonathan Lim 	cputime_t acct_timexpd;	/* stime + utime since last update */
14111da177e4SLinus Torvalds #endif
14121da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS
141358568d2aSMiao Xie 	nodemask_t mems_allowed;	/* Protected by alloc_lock */
1414825a46afSPaul Jackson 	int cpuset_mem_spread_rotor;
14151da177e4SLinus Torvalds #endif
1416ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS
1417817929ecSPaul Menage 	/* Control Group info protected by css_set_lock */
1418817929ecSPaul Menage 	struct css_set *cgroups;
1419817929ecSPaul Menage 	/* cg_list protected by css_set_lock and tsk->alloc_lock */
1420817929ecSPaul Menage 	struct list_head cg_list;
1421ddbcc7e8SPaul Menage #endif
142242b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX
14230771dfefSIngo Molnar 	struct robust_list_head __user *robust_list;
142434f192c6SIngo Molnar #ifdef CONFIG_COMPAT
142534f192c6SIngo Molnar 	struct compat_robust_list_head __user *compat_robust_list;
142634f192c6SIngo Molnar #endif
1427c87e2837SIngo Molnar 	struct list_head pi_state_list;
1428c87e2837SIngo Molnar 	struct futex_pi_state *pi_state_cache;
142942b2dd0aSAlexey Dobriyan #endif
1430a63eaf34SPaul Mackerras #ifdef CONFIG_PERF_COUNTERS
1431a63eaf34SPaul Mackerras 	struct perf_counter_context *perf_counter_ctxp;
1432082ff5a2SPeter Zijlstra 	struct mutex perf_counter_mutex;
1433082ff5a2SPeter Zijlstra 	struct list_head perf_counter_list;
1434a63eaf34SPaul Mackerras #endif
1435c7aceabaSRichard Kennedy #ifdef CONFIG_NUMA
143658568d2aSMiao Xie 	struct mempolicy *mempolicy;	/* Protected by alloc_lock */
1437c7aceabaSRichard Kennedy 	short il_next;
1438c7aceabaSRichard Kennedy #endif
143922e2c507SJens Axboe 	atomic_t fs_excl;	/* holding fs exclusive resources */
1440e56d0903SIngo Molnar 	struct rcu_head rcu;
1441b92ce558SJens Axboe 
1442b92ce558SJens Axboe 	/*
1443b92ce558SJens Axboe 	 * cache last used pipe for splice
1444b92ce558SJens Axboe 	 */
1445b92ce558SJens Axboe 	struct pipe_inode_info *splice_pipe;
1446ca74e92bSShailabh Nagar #ifdef	CONFIG_TASK_DELAY_ACCT
1447ca74e92bSShailabh Nagar 	struct task_delay_info *delays;
1448ca74e92bSShailabh Nagar #endif
1449f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION
1450f4f154fdSAkinobu Mita 	int make_it_fail;
1451f4f154fdSAkinobu Mita #endif
14523e26c149SPeter Zijlstra 	struct prop_local_single dirties;
14539745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
14549745512cSArjan van de Ven 	int latency_record_count;
14559745512cSArjan van de Ven 	struct latency_record latency_record[LT_SAVECOUNT];
14569745512cSArjan van de Ven #endif
14576976675dSArjan van de Ven 	/*
14586976675dSArjan van de Ven 	 * time slack values; these are used to round up poll() and
14596976675dSArjan van de Ven 	 * select() etc timeout values. These are in nanoseconds.
14606976675dSArjan van de Ven 	 */
14616976675dSArjan van de Ven 	unsigned long timer_slack_ns;
14626976675dSArjan van de Ven 	unsigned long default_timer_slack_ns;
1463f8d570a4SDavid Miller 
1464f8d570a4SDavid Miller 	struct list_head	*scm_work_list;
1465fb52607aSFrederic Weisbecker #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1466f201ae23SFrederic Weisbecker 	/* Index of current stored adress in ret_stack */
1467f201ae23SFrederic Weisbecker 	int curr_ret_stack;
1468f201ae23SFrederic Weisbecker 	/* Stack of return addresses for return function tracing */
1469f201ae23SFrederic Weisbecker 	struct ftrace_ret_stack	*ret_stack;
14708aef2d28SSteven Rostedt 	/* time stamp for last schedule */
14718aef2d28SSteven Rostedt 	unsigned long long ftrace_timestamp;
1472f201ae23SFrederic Weisbecker 	/*
1473f201ae23SFrederic Weisbecker 	 * Number of functions that haven't been traced
1474f201ae23SFrederic Weisbecker 	 * because of depth overrun.
1475f201ae23SFrederic Weisbecker 	 */
1476f201ae23SFrederic Weisbecker 	atomic_t trace_overrun;
1477380c4b14SFrederic Weisbecker 	/* Pause for the tracing */
1478380c4b14SFrederic Weisbecker 	atomic_t tracing_graph_pause;
1479f201ae23SFrederic Weisbecker #endif
1480ea4e2bc4SSteven Rostedt #ifdef CONFIG_TRACING
1481ea4e2bc4SSteven Rostedt 	/* state flags for use by tracers */
1482ea4e2bc4SSteven Rostedt 	unsigned long trace;
1483261842b7SSteven Rostedt 	/* bitmask of trace recursion */
1484261842b7SSteven Rostedt 	unsigned long trace_recursion;
1485261842b7SSteven Rostedt #endif /* CONFIG_TRACING */
14861da177e4SLinus Torvalds };
14871da177e4SLinus Torvalds 
148876e6eee0SRusty Russell /* Future-safe accessor for struct task_struct's cpus_allowed. */
148976e6eee0SRusty Russell #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
149076e6eee0SRusty Russell 
1491e05606d3SIngo Molnar /*
1492e05606d3SIngo Molnar  * Priority of a process goes from 0..MAX_PRIO-1, valid RT
1493e05606d3SIngo Molnar  * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
1494e05606d3SIngo Molnar  * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
1495e05606d3SIngo Molnar  * values are inverted: lower p->prio value means higher priority.
1496e05606d3SIngo Molnar  *
1497e05606d3SIngo Molnar  * The MAX_USER_RT_PRIO value allows the actual maximum
1498e05606d3SIngo Molnar  * RT priority to be separate from the value exported to
1499e05606d3SIngo Molnar  * user-space.  This allows kernel threads to set their
1500e05606d3SIngo Molnar  * priority to a value higher than any user task. Note:
1501e05606d3SIngo Molnar  * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
1502e05606d3SIngo Molnar  */
1503e05606d3SIngo Molnar 
1504e05606d3SIngo Molnar #define MAX_USER_RT_PRIO	100
1505e05606d3SIngo Molnar #define MAX_RT_PRIO		MAX_USER_RT_PRIO
1506e05606d3SIngo Molnar 
1507e05606d3SIngo Molnar #define MAX_PRIO		(MAX_RT_PRIO + 40)
1508e05606d3SIngo Molnar #define DEFAULT_PRIO		(MAX_RT_PRIO + 20)
1509e05606d3SIngo Molnar 
1510e05606d3SIngo Molnar static inline int rt_prio(int prio)
1511e05606d3SIngo Molnar {
1512e05606d3SIngo Molnar 	if (unlikely(prio < MAX_RT_PRIO))
1513e05606d3SIngo Molnar 		return 1;
1514e05606d3SIngo Molnar 	return 0;
1515e05606d3SIngo Molnar }
1516e05606d3SIngo Molnar 
1517e868171aSAlexey Dobriyan static inline int rt_task(struct task_struct *p)
1518e05606d3SIngo Molnar {
1519e05606d3SIngo Molnar 	return rt_prio(p->prio);
1520e05606d3SIngo Molnar }
1521e05606d3SIngo Molnar 
1522e868171aSAlexey Dobriyan static inline struct pid *task_pid(struct task_struct *task)
152322c935f4SEric W. Biederman {
152422c935f4SEric W. Biederman 	return task->pids[PIDTYPE_PID].pid;
152522c935f4SEric W. Biederman }
152622c935f4SEric W. Biederman 
1527e868171aSAlexey Dobriyan static inline struct pid *task_tgid(struct task_struct *task)
152822c935f4SEric W. Biederman {
152922c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PID].pid;
153022c935f4SEric W. Biederman }
153122c935f4SEric W. Biederman 
15326dda81f4SOleg Nesterov /*
15336dda81f4SOleg Nesterov  * Without tasklist or rcu lock it is not safe to dereference
15346dda81f4SOleg Nesterov  * the result of task_pgrp/task_session even if task == current,
15356dda81f4SOleg Nesterov  * we can race with another thread doing sys_setsid/sys_setpgid.
15366dda81f4SOleg Nesterov  */
1537e868171aSAlexey Dobriyan static inline struct pid *task_pgrp(struct task_struct *task)
153822c935f4SEric W. Biederman {
153922c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PGID].pid;
154022c935f4SEric W. Biederman }
154122c935f4SEric W. Biederman 
1542e868171aSAlexey Dobriyan static inline struct pid *task_session(struct task_struct *task)
154322c935f4SEric W. Biederman {
154422c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_SID].pid;
154522c935f4SEric W. Biederman }
154622c935f4SEric W. Biederman 
15477af57294SPavel Emelyanov struct pid_namespace;
15487af57294SPavel Emelyanov 
15497af57294SPavel Emelyanov /*
15507af57294SPavel Emelyanov  * the helpers to get the task's different pids as they are seen
15517af57294SPavel Emelyanov  * from various namespaces
15527af57294SPavel Emelyanov  *
15537af57294SPavel Emelyanov  * task_xid_nr()     : global id, i.e. the id seen from the init namespace;
155444c4e1b2SEric W. Biederman  * task_xid_vnr()    : virtual id, i.e. the id seen from the pid namespace of
155544c4e1b2SEric W. Biederman  *                     current.
15567af57294SPavel Emelyanov  * task_xid_nr_ns()  : id seen from the ns specified;
15577af57294SPavel Emelyanov  *
15587af57294SPavel Emelyanov  * set_task_vxid()   : assigns a virtual id to a task;
15597af57294SPavel Emelyanov  *
15607af57294SPavel Emelyanov  * see also pid_nr() etc in include/linux/pid.h
15617af57294SPavel Emelyanov  */
156252ee2dfdSOleg Nesterov pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
156352ee2dfdSOleg Nesterov 			struct pid_namespace *ns);
15647af57294SPavel Emelyanov 
1565e868171aSAlexey Dobriyan static inline pid_t task_pid_nr(struct task_struct *tsk)
15667af57294SPavel Emelyanov {
15677af57294SPavel Emelyanov 	return tsk->pid;
15687af57294SPavel Emelyanov }
15697af57294SPavel Emelyanov 
157052ee2dfdSOleg Nesterov static inline pid_t task_pid_nr_ns(struct task_struct *tsk,
157152ee2dfdSOleg Nesterov 					struct pid_namespace *ns)
157252ee2dfdSOleg Nesterov {
157352ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
157452ee2dfdSOleg Nesterov }
15757af57294SPavel Emelyanov 
15767af57294SPavel Emelyanov static inline pid_t task_pid_vnr(struct task_struct *tsk)
15777af57294SPavel Emelyanov {
157852ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
15797af57294SPavel Emelyanov }
15807af57294SPavel Emelyanov 
15817af57294SPavel Emelyanov 
1582e868171aSAlexey Dobriyan static inline pid_t task_tgid_nr(struct task_struct *tsk)
15837af57294SPavel Emelyanov {
15847af57294SPavel Emelyanov 	return tsk->tgid;
15857af57294SPavel Emelyanov }
15867af57294SPavel Emelyanov 
15872f2a3a46SPavel Emelyanov pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
15887af57294SPavel Emelyanov 
15897af57294SPavel Emelyanov static inline pid_t task_tgid_vnr(struct task_struct *tsk)
15907af57294SPavel Emelyanov {
15917af57294SPavel Emelyanov 	return pid_vnr(task_tgid(tsk));
15927af57294SPavel Emelyanov }
15937af57294SPavel Emelyanov 
15947af57294SPavel Emelyanov 
159552ee2dfdSOleg Nesterov static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk,
159652ee2dfdSOleg Nesterov 					struct pid_namespace *ns)
15977af57294SPavel Emelyanov {
159852ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
15997af57294SPavel Emelyanov }
16007af57294SPavel Emelyanov 
16017af57294SPavel Emelyanov static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
16027af57294SPavel Emelyanov {
160352ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
16047af57294SPavel Emelyanov }
16057af57294SPavel Emelyanov 
16067af57294SPavel Emelyanov 
160752ee2dfdSOleg Nesterov static inline pid_t task_session_nr_ns(struct task_struct *tsk,
160852ee2dfdSOleg Nesterov 					struct pid_namespace *ns)
16097af57294SPavel Emelyanov {
161052ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
16117af57294SPavel Emelyanov }
16127af57294SPavel Emelyanov 
16137af57294SPavel Emelyanov static inline pid_t task_session_vnr(struct task_struct *tsk)
16147af57294SPavel Emelyanov {
161552ee2dfdSOleg Nesterov 	return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
16167af57294SPavel Emelyanov }
16177af57294SPavel Emelyanov 
16181b0f7ffdSOleg Nesterov /* obsolete, do not use */
16191b0f7ffdSOleg Nesterov static inline pid_t task_pgrp_nr(struct task_struct *tsk)
16201b0f7ffdSOleg Nesterov {
16211b0f7ffdSOleg Nesterov 	return task_pgrp_nr_ns(tsk, &init_pid_ns);
16221b0f7ffdSOleg Nesterov }
16237af57294SPavel Emelyanov 
16241da177e4SLinus Torvalds /**
16251da177e4SLinus Torvalds  * pid_alive - check that a task structure is not stale
16261da177e4SLinus Torvalds  * @p: Task structure to be checked.
16271da177e4SLinus Torvalds  *
16281da177e4SLinus Torvalds  * Test if a process is not yet dead (at most zombie state)
16291da177e4SLinus Torvalds  * If pid_alive fails, then pointers within the task structure
16301da177e4SLinus Torvalds  * can be stale and must not be dereferenced.
16311da177e4SLinus Torvalds  */
1632e868171aSAlexey Dobriyan static inline int pid_alive(struct task_struct *p)
16331da177e4SLinus Torvalds {
163492476d7fSEric W. Biederman 	return p->pids[PIDTYPE_PID].pid != NULL;
16351da177e4SLinus Torvalds }
16361da177e4SLinus Torvalds 
1637f400e198SSukadev Bhattiprolu /**
1638b460cbc5SSerge E. Hallyn  * is_global_init - check if a task structure is init
16393260259fSHenne  * @tsk: Task structure to be checked.
16403260259fSHenne  *
16413260259fSHenne  * Check if a task structure is the first user space task the kernel created.
1642f400e198SSukadev Bhattiprolu  */
1643e868171aSAlexey Dobriyan static inline int is_global_init(struct task_struct *tsk)
1644b461cc03SPavel Emelyanov {
1645b461cc03SPavel Emelyanov 	return tsk->pid == 1;
1646b461cc03SPavel Emelyanov }
1647b460cbc5SSerge E. Hallyn 
1648b460cbc5SSerge E. Hallyn /*
1649b460cbc5SSerge E. Hallyn  * is_container_init:
1650b460cbc5SSerge E. Hallyn  * check whether in the task is init in its own pid namespace.
1651b460cbc5SSerge E. Hallyn  */
1652b461cc03SPavel Emelyanov extern int is_container_init(struct task_struct *tsk);
1653f400e198SSukadev Bhattiprolu 
16549ec52099SCedric Le Goater extern struct pid *cad_pid;
16559ec52099SCedric Le Goater 
16561da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk);
16571da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
1658e56d0903SIngo Molnar 
1659158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t);
1660e56d0903SIngo Molnar 
1661e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t)
1662e56d0903SIngo Molnar {
1663e56d0903SIngo Molnar 	if (atomic_dec_and_test(&t->usage))
16648c7904a0SEric W. Biederman 		__put_task_struct(t);
1665e56d0903SIngo Molnar }
16661da177e4SLinus Torvalds 
166749048622SBalbir Singh extern cputime_t task_utime(struct task_struct *p);
166849048622SBalbir Singh extern cputime_t task_stime(struct task_struct *p);
166949048622SBalbir Singh extern cputime_t task_gtime(struct task_struct *p);
167049048622SBalbir Singh 
16711da177e4SLinus Torvalds /*
16721da177e4SLinus Torvalds  * Per process flags
16731da177e4SLinus Torvalds  */
16741da177e4SLinus Torvalds #define PF_ALIGNWARN	0x00000001	/* Print alignment warning msgs */
16751da177e4SLinus Torvalds 					/* Not implemented yet, only for 486*/
16761da177e4SLinus Torvalds #define PF_STARTING	0x00000002	/* being created */
16771da177e4SLinus Torvalds #define PF_EXITING	0x00000004	/* getting shut down */
1678778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
167994886b84SLaurent Vivier #define PF_VCPU		0x00000010	/* I'm a virtual CPU */
16801da177e4SLinus Torvalds #define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
16811da177e4SLinus Torvalds #define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
16821da177e4SLinus Torvalds #define PF_DUMPCORE	0x00000200	/* dumped core */
16831da177e4SLinus Torvalds #define PF_SIGNALED	0x00000400	/* killed by a signal */
16841da177e4SLinus Torvalds #define PF_MEMALLOC	0x00000800	/* Allocating memory */
16851da177e4SLinus Torvalds #define PF_FLUSHER	0x00001000	/* responsible for disk writeback */
16861da177e4SLinus Torvalds #define PF_USED_MATH	0x00002000	/* if unset the fpu must be initialized before use */
16876301cb95SThomas Gleixner #define PF_FREEZING	0x00004000	/* freeze in progress. do not account to load */
16881da177e4SLinus Torvalds #define PF_NOFREEZE	0x00008000	/* this thread should not be frozen */
16891da177e4SLinus Torvalds #define PF_FROZEN	0x00010000	/* frozen for system suspend */
16901da177e4SLinus Torvalds #define PF_FSTRANS	0x00020000	/* inside a filesystem transaction */
16911da177e4SLinus Torvalds #define PF_KSWAPD	0x00040000	/* I am kswapd */
16921da177e4SLinus Torvalds #define PF_SWAPOFF	0x00080000	/* I am in swapoff */
16931da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000	/* Throttle me less: I clean memory */
1694246bb0b1SOleg Nesterov #define PF_KTHREAD	0x00200000	/* I am a kernel thread */
1695b31dc66aSJens Axboe #define PF_RANDOMIZE	0x00400000	/* randomize virtual address space */
1696b31dc66aSJens Axboe #define PF_SWAPWRITE	0x00800000	/* Allowed to write to swap */
1697b31dc66aSJens Axboe #define PF_SPREAD_PAGE	0x01000000	/* Spread page cache over cpuset */
1698b31dc66aSJens Axboe #define PF_SPREAD_SLAB	0x02000000	/* Spread some slab caches over cpuset */
16999985b0baSDavid Rientjes #define PF_THREAD_BOUND	0x04000000	/* Thread bound to specific cpu */
1700c61afb18SPaul Jackson #define PF_MEMPOLICY	0x10000000	/* Non-default NUMA mempolicy */
170161a87122SThomas Gleixner #define PF_MUTEX_TESTER	0x20000000	/* Thread belongs to the rt mutex tester */
1702ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP	0x40000000	/* Freezer should not count it as freezeable */
1703ebb12db5SRafael J. Wysocki #define PF_FREEZER_NOSIG 0x80000000	/* Freezer won't send signals to it */
17041da177e4SLinus Torvalds 
17051da177e4SLinus Torvalds /*
17061da177e4SLinus Torvalds  * Only the _current_ task can read/write to tsk->flags, but other
17071da177e4SLinus Torvalds  * tasks can access tsk->flags in readonly mode for example
17081da177e4SLinus Torvalds  * with tsk_used_math (like during threaded core dumping).
17091da177e4SLinus Torvalds  * There is however an exception to this rule during ptrace
17101da177e4SLinus Torvalds  * or during fork: the ptracer task is allowed to write to the
17111da177e4SLinus Torvalds  * child->flags of its traced child (same goes for fork, the parent
17121da177e4SLinus Torvalds  * can write to the child->flags), because we're guaranteed the
17131da177e4SLinus Torvalds  * child is not running and in turn not changing child->flags
17141da177e4SLinus Torvalds  * at the same time the parent does it.
17151da177e4SLinus Torvalds  */
17161da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
17171da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
17181da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current)
17191da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current)
17201da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \
17211da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
17221da177e4SLinus Torvalds #define conditional_used_math(condition) \
17231da177e4SLinus Torvalds 	conditional_stopped_child_used_math(condition, current)
17241da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \
17251da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
17261da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
17271da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
17281da177e4SLinus Torvalds #define used_math() tsk_used_math(current)
17291da177e4SLinus Torvalds 
1730f41d911fSPaul E. McKenney #ifdef CONFIG_TREE_PREEMPT_RCU
1731f41d911fSPaul E. McKenney 
1732f41d911fSPaul E. McKenney #define RCU_READ_UNLOCK_BLOCKED (1 << 0) /* blocked while in RCU read-side. */
1733f41d911fSPaul E. McKenney #define RCU_READ_UNLOCK_NEED_QS (1 << 1) /* RCU core needs CPU response. */
1734f41d911fSPaul E. McKenney #define RCU_READ_UNLOCK_GOT_QS  (1 << 2) /* CPU has responded to RCU core. */
1735f41d911fSPaul E. McKenney 
1736f41d911fSPaul E. McKenney static inline void rcu_copy_process(struct task_struct *p)
1737f41d911fSPaul E. McKenney {
1738f41d911fSPaul E. McKenney 	p->rcu_read_lock_nesting = 0;
1739f41d911fSPaul E. McKenney 	p->rcu_read_unlock_special = 0;
1740dd5d19baSPaul E. McKenney 	p->rcu_blocked_node = NULL;
1741f41d911fSPaul E. McKenney 	INIT_LIST_HEAD(&p->rcu_node_entry);
1742f41d911fSPaul E. McKenney }
1743f41d911fSPaul E. McKenney 
1744f41d911fSPaul E. McKenney #else
1745f41d911fSPaul E. McKenney 
1746f41d911fSPaul E. McKenney static inline void rcu_copy_process(struct task_struct *p)
1747f41d911fSPaul E. McKenney {
1748f41d911fSPaul E. McKenney }
1749f41d911fSPaul E. McKenney 
1750f41d911fSPaul E. McKenney #endif
1751f41d911fSPaul E. McKenney 
17521da177e4SLinus Torvalds #ifdef CONFIG_SMP
1753cd8ba7cdSMike Travis extern int set_cpus_allowed_ptr(struct task_struct *p,
175496f874e2SRusty Russell 				const struct cpumask *new_mask);
17551da177e4SLinus Torvalds #else
1756cd8ba7cdSMike Travis static inline int set_cpus_allowed_ptr(struct task_struct *p,
175796f874e2SRusty Russell 				       const struct cpumask *new_mask)
17581da177e4SLinus Torvalds {
175996f874e2SRusty Russell 	if (!cpumask_test_cpu(0, new_mask))
17601da177e4SLinus Torvalds 		return -EINVAL;
17611da177e4SLinus Torvalds 	return 0;
17621da177e4SLinus Torvalds }
17631da177e4SLinus Torvalds #endif
1764cd8ba7cdSMike Travis static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
1765cd8ba7cdSMike Travis {
1766cd8ba7cdSMike Travis 	return set_cpus_allowed_ptr(p, &new_mask);
1767cd8ba7cdSMike Travis }
17681da177e4SLinus Torvalds 
1769b342501cSIngo Molnar /*
1770b342501cSIngo Molnar  * Architectures can set this to 1 if they have specified
1771b342501cSIngo Molnar  * CONFIG_HAVE_UNSTABLE_SCHED_CLOCK in their arch Kconfig,
1772b342501cSIngo Molnar  * but then during bootup it turns out that sched_clock()
1773b342501cSIngo Molnar  * is reliable after all:
1774b342501cSIngo Molnar  */
1775b342501cSIngo Molnar #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
1776b342501cSIngo Molnar extern int sched_clock_stable;
1777b342501cSIngo Molnar #endif
1778b342501cSIngo Molnar 
17791da177e4SLinus Torvalds extern unsigned long long sched_clock(void);
1780e436d800SIngo Molnar 
1781c1955a3dSPeter Zijlstra extern void sched_clock_init(void);
1782c1955a3dSPeter Zijlstra extern u64 sched_clock_cpu(int cpu);
1783c1955a3dSPeter Zijlstra 
17843e51f33fSPeter Zijlstra #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
17853e51f33fSPeter Zijlstra static inline void sched_clock_tick(void)
17863e51f33fSPeter Zijlstra {
17873e51f33fSPeter Zijlstra }
17883e51f33fSPeter Zijlstra 
17893e51f33fSPeter Zijlstra static inline void sched_clock_idle_sleep_event(void)
17903e51f33fSPeter Zijlstra {
17913e51f33fSPeter Zijlstra }
17923e51f33fSPeter Zijlstra 
17933e51f33fSPeter Zijlstra static inline void sched_clock_idle_wakeup_event(u64 delta_ns)
17943e51f33fSPeter Zijlstra {
17953e51f33fSPeter Zijlstra }
17963e51f33fSPeter Zijlstra #else
17973e51f33fSPeter Zijlstra extern void sched_clock_tick(void);
17983e51f33fSPeter Zijlstra extern void sched_clock_idle_sleep_event(void);
17993e51f33fSPeter Zijlstra extern void sched_clock_idle_wakeup_event(u64 delta_ns);
18003e51f33fSPeter Zijlstra #endif
18013e51f33fSPeter Zijlstra 
1802e436d800SIngo Molnar /*
1803e436d800SIngo Molnar  * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
1804e436d800SIngo Molnar  * clock constructed from sched_clock():
1805e436d800SIngo Molnar  */
1806e436d800SIngo Molnar extern unsigned long long cpu_clock(int cpu);
1807e436d800SIngo Molnar 
180836c8b586SIngo Molnar extern unsigned long long
180941b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task);
1810f06febc9SFrank Mayhar extern unsigned long long thread_group_sched_runtime(struct task_struct *task);
18111da177e4SLinus Torvalds 
18121da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */
18131da177e4SLinus Torvalds #ifdef CONFIG_SMP
18141da177e4SLinus Torvalds extern void sched_exec(void);
18151da177e4SLinus Torvalds #else
18161da177e4SLinus Torvalds #define sched_exec()   {}
18171da177e4SLinus Torvalds #endif
18181da177e4SLinus Torvalds 
18192aa44d05SIngo Molnar extern void sched_clock_idle_sleep_event(void);
18202aa44d05SIngo Molnar extern void sched_clock_idle_wakeup_event(u64 delta_ns);
1821bb29ab26SIngo Molnar 
18221da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU
18231da177e4SLinus Torvalds extern void idle_task_exit(void);
18241da177e4SLinus Torvalds #else
18251da177e4SLinus Torvalds static inline void idle_task_exit(void) {}
18261da177e4SLinus Torvalds #endif
18271da177e4SLinus Torvalds 
18281da177e4SLinus Torvalds extern void sched_idle_next(void);
1829b29739f9SIngo Molnar 
183006d8308cSThomas Gleixner #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
183106d8308cSThomas Gleixner extern void wake_up_idle_cpu(int cpu);
183206d8308cSThomas Gleixner #else
183306d8308cSThomas Gleixner static inline void wake_up_idle_cpu(int cpu) { }
183406d8308cSThomas Gleixner #endif
183506d8308cSThomas Gleixner 
183621805085SPeter Zijlstra extern unsigned int sysctl_sched_latency;
1837b2be5e96SPeter Zijlstra extern unsigned int sysctl_sched_min_granularity;
1838bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity;
183947fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_ratelimit;
184047fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_thresh;
184147fea2adSJaswinder Singh Rajput #ifdef CONFIG_SCHED_DEBUG
1842bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first;
1843bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_features;
1844da84d961SIngo Molnar extern unsigned int sysctl_sched_migration_cost;
1845b82d9fddSPeter Zijlstra extern unsigned int sysctl_sched_nr_migrate;
1846cd1bb94bSArun R Bharadwaj extern unsigned int sysctl_timer_migration;
1847b2be5e96SPeter Zijlstra 
1848b2be5e96SPeter Zijlstra int sched_nr_latency_handler(struct ctl_table *table, int write,
1849b2be5e96SPeter Zijlstra 		struct file *file, void __user *buffer, size_t *length,
1850b2be5e96SPeter Zijlstra 		loff_t *ppos);
18512bd8e6d4SIngo Molnar #endif
1852eea08f32SArun R Bharadwaj #ifdef CONFIG_SCHED_DEBUG
1853eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void)
1854eea08f32SArun R Bharadwaj {
1855eea08f32SArun R Bharadwaj 	return sysctl_timer_migration;
1856eea08f32SArun R Bharadwaj }
1857eea08f32SArun R Bharadwaj #else
1858eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void)
1859eea08f32SArun R Bharadwaj {
1860eea08f32SArun R Bharadwaj 	return 1;
1861eea08f32SArun R Bharadwaj }
1862eea08f32SArun R Bharadwaj #endif
18639f0c1e56SPeter Zijlstra extern unsigned int sysctl_sched_rt_period;
18649f0c1e56SPeter Zijlstra extern int sysctl_sched_rt_runtime;
18652bd8e6d4SIngo Molnar 
1866d0b27fa7SPeter Zijlstra int sched_rt_handler(struct ctl_table *table, int write,
1867d0b27fa7SPeter Zijlstra 		struct file *filp, void __user *buffer, size_t *lenp,
1868d0b27fa7SPeter Zijlstra 		loff_t *ppos);
1869d0b27fa7SPeter Zijlstra 
18702bd8e6d4SIngo Molnar extern unsigned int sysctl_sched_compat_yield;
1871bf0f6f24SIngo Molnar 
1872b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES
187336c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p);
187436c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio);
187536c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p);
1876b29739f9SIngo Molnar #else
1877e868171aSAlexey Dobriyan static inline int rt_mutex_getprio(struct task_struct *p)
1878b29739f9SIngo Molnar {
1879b29739f9SIngo Molnar 	return p->normal_prio;
1880b29739f9SIngo Molnar }
188195e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p)		do { } while (0)
1882b29739f9SIngo Molnar #endif
1883b29739f9SIngo Molnar 
188436c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice);
188536c8b586SIngo Molnar extern int task_prio(const struct task_struct *p);
188636c8b586SIngo Molnar extern int task_nice(const struct task_struct *p);
188736c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice);
188836c8b586SIngo Molnar extern int task_curr(const struct task_struct *p);
18891da177e4SLinus Torvalds extern int idle_cpu(int cpu);
18901da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
1891961ccdddSRusty Russell extern int sched_setscheduler_nocheck(struct task_struct *, int,
1892961ccdddSRusty Russell 				      struct sched_param *);
189336c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu);
189436c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu);
189536c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p);
18961da177e4SLinus Torvalds 
18971da177e4SLinus Torvalds void yield(void);
18981da177e4SLinus Torvalds 
18991da177e4SLinus Torvalds /*
19001da177e4SLinus Torvalds  * The default (Linux) execution domain.
19011da177e4SLinus Torvalds  */
19021da177e4SLinus Torvalds extern struct exec_domain	default_exec_domain;
19031da177e4SLinus Torvalds 
19041da177e4SLinus Torvalds union thread_union {
19051da177e4SLinus Torvalds 	struct thread_info thread_info;
19061da177e4SLinus Torvalds 	unsigned long stack[THREAD_SIZE/sizeof(long)];
19071da177e4SLinus Torvalds };
19081da177e4SLinus Torvalds 
19091da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END
19101da177e4SLinus Torvalds static inline int kstack_end(void *addr)
19111da177e4SLinus Torvalds {
19121da177e4SLinus Torvalds 	/* Reliable end of stack detection:
19131da177e4SLinus Torvalds 	 * Some APM bios versions misalign the stack
19141da177e4SLinus Torvalds 	 */
19151da177e4SLinus Torvalds 	return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
19161da177e4SLinus Torvalds }
19171da177e4SLinus Torvalds #endif
19181da177e4SLinus Torvalds 
19191da177e4SLinus Torvalds extern union thread_union init_thread_union;
19201da177e4SLinus Torvalds extern struct task_struct init_task;
19211da177e4SLinus Torvalds 
19221da177e4SLinus Torvalds extern struct   mm_struct init_mm;
19231da177e4SLinus Torvalds 
1924198fe21bSPavel Emelyanov extern struct pid_namespace init_pid_ns;
1925198fe21bSPavel Emelyanov 
1926198fe21bSPavel Emelyanov /*
1927198fe21bSPavel Emelyanov  * find a task by one of its numerical ids
1928198fe21bSPavel Emelyanov  *
1929198fe21bSPavel Emelyanov  * find_task_by_pid_ns():
1930198fe21bSPavel Emelyanov  *      finds a task by its pid in the specified namespace
1931228ebcbeSPavel Emelyanov  * find_task_by_vpid():
1932228ebcbeSPavel Emelyanov  *      finds a task by its virtual pid
1933198fe21bSPavel Emelyanov  *
1934e49859e7SPavel Emelyanov  * see also find_vpid() etc in include/linux/pid.h
1935198fe21bSPavel Emelyanov  */
1936198fe21bSPavel Emelyanov 
1937228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_vpid(pid_t nr);
1938228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid_ns(pid_t nr,
1939228ebcbeSPavel Emelyanov 		struct pid_namespace *ns);
1940198fe21bSPavel Emelyanov 
19418520d7c7SOleg Nesterov extern void __set_special_pids(struct pid *pid);
19421da177e4SLinus Torvalds 
19431da177e4SLinus Torvalds /* per-UID process charging. */
1944acce292cSCedric Le Goater extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
19451da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u)
19461da177e4SLinus Torvalds {
19471da177e4SLinus Torvalds 	atomic_inc(&u->__count);
19481da177e4SLinus Torvalds 	return u;
19491da177e4SLinus Torvalds }
19501da177e4SLinus Torvalds extern void free_uid(struct user_struct *);
195128f300d2SPavel Emelyanov extern void release_uids(struct user_namespace *ns);
19521da177e4SLinus Torvalds 
19531da177e4SLinus Torvalds #include <asm/current.h>
19541da177e4SLinus Torvalds 
19553171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks);
19561da177e4SLinus Torvalds 
1957b3c97528SHarvey Harrison extern int wake_up_state(struct task_struct *tsk, unsigned int state);
1958b3c97528SHarvey Harrison extern int wake_up_process(struct task_struct *tsk);
1959b3c97528SHarvey Harrison extern void wake_up_new_task(struct task_struct *tsk,
1960b3c97528SHarvey Harrison 				unsigned long clone_flags);
19611da177e4SLinus Torvalds #ifdef CONFIG_SMP
19621da177e4SLinus Torvalds  extern void kick_process(struct task_struct *tsk);
19631da177e4SLinus Torvalds #else
19641da177e4SLinus Torvalds  static inline void kick_process(struct task_struct *tsk) { }
19651da177e4SLinus Torvalds #endif
1966ad46c2c4SIngo Molnar extern void sched_fork(struct task_struct *p, int clone_flags);
1967ad46c2c4SIngo Molnar extern void sched_dead(struct task_struct *p);
19681da177e4SLinus Torvalds 
19691da177e4SLinus Torvalds extern void proc_caches_init(void);
19701da177e4SLinus Torvalds extern void flush_signals(struct task_struct *);
19713bcac026SDavid Howells extern void __flush_signals(struct task_struct *);
197210ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *);
19731da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default);
19741da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
19751da177e4SLinus Torvalds 
19761da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
19771da177e4SLinus Torvalds {
19781da177e4SLinus Torvalds 	unsigned long flags;
19791da177e4SLinus Torvalds 	int ret;
19801da177e4SLinus Torvalds 
19811da177e4SLinus Torvalds 	spin_lock_irqsave(&tsk->sighand->siglock, flags);
19821da177e4SLinus Torvalds 	ret = dequeue_signal(tsk, mask, info);
19831da177e4SLinus Torvalds 	spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
19841da177e4SLinus Torvalds 
19851da177e4SLinus Torvalds 	return ret;
19861da177e4SLinus Torvalds }
19871da177e4SLinus Torvalds 
19881da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv,
19891da177e4SLinus Torvalds 			      sigset_t *mask);
19901da177e4SLinus Torvalds extern void unblock_all_signals(void);
19911da177e4SLinus Torvalds extern void release_task(struct task_struct * p);
19921da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *);
19931da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *);
19941da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *);
1995c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
1996c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
19972425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32);
1998c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv);
1999c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv);
2000c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t);
20012b2a1ff6SRoland McGrath extern int do_notify_parent(struct task_struct *, int);
20021da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *);
20031da177e4SLinus Torvalds extern void force_sig_specific(int, struct task_struct *);
20041da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int);
20051da177e4SLinus Torvalds extern void zap_other_threads(struct task_struct *p);
20061da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void);
20071da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *);
2008ac5c2153SOleg Nesterov extern int send_sigqueue(struct sigqueue *,  struct task_struct *, int group);
20099ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
20101da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
20111da177e4SLinus Torvalds 
20129ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv)
20139ec52099SCedric Le Goater {
20149ec52099SCedric Le Goater 	return kill_pid(cad_pid, sig, priv);
20159ec52099SCedric Le Goater }
20169ec52099SCedric Le Goater 
20171da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info.  */
20181da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0)
20191da177e4SLinus Torvalds #define SEND_SIG_PRIV	((struct siginfo *) 1)
20201da177e4SLinus Torvalds #define SEND_SIG_FORCED	((struct siginfo *) 2)
20211da177e4SLinus Torvalds 
2022621d3121SOleg Nesterov static inline int is_si_special(const struct siginfo *info)
2023621d3121SOleg Nesterov {
2024621d3121SOleg Nesterov 	return info <= SEND_SIG_FORCED;
2025621d3121SOleg Nesterov }
2026621d3121SOleg Nesterov 
20271da177e4SLinus Torvalds /* True if we are on the alternate signal stack.  */
20281da177e4SLinus Torvalds 
20291da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp)
20301da177e4SLinus Torvalds {
20311da177e4SLinus Torvalds 	return (sp - current->sas_ss_sp < current->sas_ss_size);
20321da177e4SLinus Torvalds }
20331da177e4SLinus Torvalds 
20341da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp)
20351da177e4SLinus Torvalds {
20361da177e4SLinus Torvalds 	return (current->sas_ss_size == 0 ? SS_DISABLE
20371da177e4SLinus Torvalds 		: on_sig_stack(sp) ? SS_ONSTACK : 0);
20381da177e4SLinus Torvalds }
20391da177e4SLinus Torvalds 
20401da177e4SLinus Torvalds /*
20411da177e4SLinus Torvalds  * Routines for handling mm_structs
20421da177e4SLinus Torvalds  */
20431da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void);
20441da177e4SLinus Torvalds 
20451da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */
2046b3c97528SHarvey Harrison extern void __mmdrop(struct mm_struct *);
20471da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm)
20481da177e4SLinus Torvalds {
20496fb43d7bSIngo Molnar 	if (unlikely(atomic_dec_and_test(&mm->mm_count)))
20501da177e4SLinus Torvalds 		__mmdrop(mm);
20511da177e4SLinus Torvalds }
20521da177e4SLinus Torvalds 
20531da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */
20541da177e4SLinus Torvalds extern void mmput(struct mm_struct *);
20551da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */
20561da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task);
20571da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */
20581da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *);
2059402b0862SCarsten Otte /* Allocate a new mm structure and copy contents from tsk->mm */
2060402b0862SCarsten Otte extern struct mm_struct *dup_mm(struct task_struct *tsk);
20611da177e4SLinus Torvalds 
20626f2c55b8SAlexey Dobriyan extern int copy_thread(unsigned long, unsigned long, unsigned long,
20636f2c55b8SAlexey Dobriyan 			struct task_struct *, struct pt_regs *);
20641da177e4SLinus Torvalds extern void flush_thread(void);
20651da177e4SLinus Torvalds extern void exit_thread(void);
20661da177e4SLinus Torvalds 
20671da177e4SLinus Torvalds extern void exit_files(struct task_struct *);
20686b3934efSOleg Nesterov extern void __cleanup_signal(struct signal_struct *);
2069a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *);
2070cbaffba1SOleg Nesterov 
20711da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *);
2072cbaffba1SOleg Nesterov extern void flush_itimer_signals(void);
20731da177e4SLinus Torvalds 
20741da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int);
20751da177e4SLinus Torvalds 
20761da177e4SLinus Torvalds extern void daemonize(const char *, ...);
20771da177e4SLinus Torvalds extern int allow_signal(int);
20781da177e4SLinus Torvalds extern int disallow_signal(int);
20791da177e4SLinus Torvalds 
20801da177e4SLinus Torvalds extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
20811da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
208236c8b586SIngo Molnar struct task_struct *fork_idle(int);
20831da177e4SLinus Torvalds 
20841da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from);
208559714d65SAndrew Morton extern char *get_task_comm(char *to, struct task_struct *tsk);
20861da177e4SLinus Torvalds 
20871da177e4SLinus Torvalds #ifdef CONFIG_SMP
2088a26b89f0SMarkus Metzger extern void wait_task_context_switch(struct task_struct *p);
208985ba2d86SRoland McGrath extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
20901da177e4SLinus Torvalds #else
2091a26b89f0SMarkus Metzger static inline void wait_task_context_switch(struct task_struct *p) {}
209285ba2d86SRoland McGrath static inline unsigned long wait_task_inactive(struct task_struct *p,
209385ba2d86SRoland McGrath 					       long match_state)
209485ba2d86SRoland McGrath {
209585ba2d86SRoland McGrath 	return 1;
209685ba2d86SRoland McGrath }
20971da177e4SLinus Torvalds #endif
20981da177e4SLinus Torvalds 
209905725f7eSJiri Pirko #define next_task(p) \
210005725f7eSJiri Pirko 	list_entry_rcu((p)->tasks.next, struct task_struct, tasks)
21011da177e4SLinus Torvalds 
21021da177e4SLinus Torvalds #define for_each_process(p) \
21031da177e4SLinus Torvalds 	for (p = &init_task ; (p = next_task(p)) != &init_task ; )
21041da177e4SLinus Torvalds 
2105d84f4f99SDavid Howells extern bool is_single_threaded(struct task_struct *);
2106d84f4f99SDavid Howells 
21071da177e4SLinus Torvalds /*
21081da177e4SLinus Torvalds  * Careful: do_each_thread/while_each_thread is a double loop so
21091da177e4SLinus Torvalds  *          'break' will not work as expected - use goto instead.
21101da177e4SLinus Torvalds  */
21111da177e4SLinus Torvalds #define do_each_thread(g, t) \
21121da177e4SLinus Torvalds 	for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
21131da177e4SLinus Torvalds 
21141da177e4SLinus Torvalds #define while_each_thread(g, t) \
21151da177e4SLinus Torvalds 	while ((t = next_thread(t)) != g)
21161da177e4SLinus Torvalds 
2117de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */
2118de12a787SEric W. Biederman #define thread_group_leader(p)	(p == p->group_leader)
21191da177e4SLinus Torvalds 
21200804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process
21210804ef4bSEric W. Biederman  * to have the pid of the thread group leader without actually being
21220804ef4bSEric W. Biederman  * the thread group leader.  For iteration through the pids in proc
21230804ef4bSEric W. Biederman  * all we care about is that we have a task with the appropriate
21240804ef4bSEric W. Biederman  * pid, we don't actually care if we have the right task.
21250804ef4bSEric W. Biederman  */
2126e868171aSAlexey Dobriyan static inline int has_group_leader_pid(struct task_struct *p)
21270804ef4bSEric W. Biederman {
21280804ef4bSEric W. Biederman 	return p->pid == p->tgid;
21290804ef4bSEric W. Biederman }
21300804ef4bSEric W. Biederman 
2131bac0abd6SPavel Emelyanov static inline
2132bac0abd6SPavel Emelyanov int same_thread_group(struct task_struct *p1, struct task_struct *p2)
2133bac0abd6SPavel Emelyanov {
2134bac0abd6SPavel Emelyanov 	return p1->tgid == p2->tgid;
2135bac0abd6SPavel Emelyanov }
2136bac0abd6SPavel Emelyanov 
213736c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p)
213847e65328SOleg Nesterov {
213905725f7eSJiri Pirko 	return list_entry_rcu(p->thread_group.next,
214036c8b586SIngo Molnar 			      struct task_struct, thread_group);
214147e65328SOleg Nesterov }
214247e65328SOleg Nesterov 
2143e868171aSAlexey Dobriyan static inline int thread_group_empty(struct task_struct *p)
21441da177e4SLinus Torvalds {
214547e65328SOleg Nesterov 	return list_empty(&p->thread_group);
21461da177e4SLinus Torvalds }
21471da177e4SLinus Torvalds 
21481da177e4SLinus Torvalds #define delay_group_leader(p) \
21491da177e4SLinus Torvalds 		(thread_group_leader(p) && !thread_group_empty(p))
21501da177e4SLinus Torvalds 
215139c626aeSOleg Nesterov static inline int task_detached(struct task_struct *p)
215239c626aeSOleg Nesterov {
215339c626aeSOleg Nesterov 	return p->exit_signal == -1;
215439c626aeSOleg Nesterov }
215539c626aeSOleg Nesterov 
21561da177e4SLinus Torvalds /*
2157260ea101SEric W. Biederman  * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
215822e2c507SJens Axboe  * subscriptions and synchronises with wait4().  Also used in procfs.  Also
2159ddbcc7e8SPaul Menage  * pins the final release of task.io_context.  Also protects ->cpuset and
2160ddbcc7e8SPaul Menage  * ->cgroup.subsys[].
21611da177e4SLinus Torvalds  *
21621da177e4SLinus Torvalds  * Nests both inside and outside of read_lock(&tasklist_lock).
21631da177e4SLinus Torvalds  * It must not be nested with write_lock_irq(&tasklist_lock),
21641da177e4SLinus Torvalds  * neither inside nor outside.
21651da177e4SLinus Torvalds  */
21661da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p)
21671da177e4SLinus Torvalds {
21681da177e4SLinus Torvalds 	spin_lock(&p->alloc_lock);
21691da177e4SLinus Torvalds }
21701da177e4SLinus Torvalds 
21711da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p)
21721da177e4SLinus Torvalds {
21731da177e4SLinus Torvalds 	spin_unlock(&p->alloc_lock);
21741da177e4SLinus Torvalds }
21751da177e4SLinus Torvalds 
2176f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
2177f63ee72eSOleg Nesterov 							unsigned long *flags);
2178f63ee72eSOleg Nesterov 
2179f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk,
2180f63ee72eSOleg Nesterov 						unsigned long *flags)
2181f63ee72eSOleg Nesterov {
2182f63ee72eSOleg Nesterov 	spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
2183f63ee72eSOleg Nesterov }
2184f63ee72eSOleg Nesterov 
2185f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS
2186f037360fSAl Viro 
2187f7e4217bSRoman Zippel #define task_thread_info(task)	((struct thread_info *)(task)->stack)
2188f7e4217bSRoman Zippel #define task_stack_page(task)	((task)->stack)
2189a1261f54SAl Viro 
219010ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
219110ebffdeSAl Viro {
219210ebffdeSAl Viro 	*task_thread_info(p) = *task_thread_info(org);
219310ebffdeSAl Viro 	task_thread_info(p)->task = p;
219410ebffdeSAl Viro }
219510ebffdeSAl Viro 
219610ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p)
219710ebffdeSAl Viro {
2198f7e4217bSRoman Zippel 	return (unsigned long *)(task_thread_info(p) + 1);
219910ebffdeSAl Viro }
220010ebffdeSAl Viro 
2201f037360fSAl Viro #endif
2202f037360fSAl Viro 
22038b05c7e6SFUJITA Tomonori static inline int object_is_on_stack(void *obj)
22048b05c7e6SFUJITA Tomonori {
22058b05c7e6SFUJITA Tomonori 	void *stack = task_stack_page(current);
22068b05c7e6SFUJITA Tomonori 
22078b05c7e6SFUJITA Tomonori 	return (obj >= stack) && (obj < (stack + THREAD_SIZE));
22088b05c7e6SFUJITA Tomonori }
22098b05c7e6SFUJITA Tomonori 
22108c9843e5SBenjamin Herrenschmidt extern void thread_info_cache_init(void);
22118c9843e5SBenjamin Herrenschmidt 
22127c9f8861SEric Sandeen #ifdef CONFIG_DEBUG_STACK_USAGE
22137c9f8861SEric Sandeen static inline unsigned long stack_not_used(struct task_struct *p)
22147c9f8861SEric Sandeen {
22157c9f8861SEric Sandeen 	unsigned long *n = end_of_stack(p);
22167c9f8861SEric Sandeen 
22177c9f8861SEric Sandeen 	do { 	/* Skip over canary */
22187c9f8861SEric Sandeen 		n++;
22197c9f8861SEric Sandeen 	} while (!*n);
22207c9f8861SEric Sandeen 
22217c9f8861SEric Sandeen 	return (unsigned long)n - (unsigned long)end_of_stack(p);
22227c9f8861SEric Sandeen }
22237c9f8861SEric Sandeen #endif
22247c9f8861SEric Sandeen 
22251da177e4SLinus Torvalds /* set thread flags in other task's structures
22261da177e4SLinus Torvalds  * - see asm/thread_info.h for TIF_xxxx flags available
22271da177e4SLinus Torvalds  */
22281da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
22291da177e4SLinus Torvalds {
2230a1261f54SAl Viro 	set_ti_thread_flag(task_thread_info(tsk), flag);
22311da177e4SLinus Torvalds }
22321da177e4SLinus Torvalds 
22331da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
22341da177e4SLinus Torvalds {
2235a1261f54SAl Viro 	clear_ti_thread_flag(task_thread_info(tsk), flag);
22361da177e4SLinus Torvalds }
22371da177e4SLinus Torvalds 
22381da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
22391da177e4SLinus Torvalds {
2240a1261f54SAl Viro 	return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
22411da177e4SLinus Torvalds }
22421da177e4SLinus Torvalds 
22431da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
22441da177e4SLinus Torvalds {
2245a1261f54SAl Viro 	return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
22461da177e4SLinus Torvalds }
22471da177e4SLinus Torvalds 
22481da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
22491da177e4SLinus Torvalds {
2250a1261f54SAl Viro 	return test_ti_thread_flag(task_thread_info(tsk), flag);
22511da177e4SLinus Torvalds }
22521da177e4SLinus Torvalds 
22531da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk)
22541da177e4SLinus Torvalds {
22551da177e4SLinus Torvalds 	set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
22561da177e4SLinus Torvalds }
22571da177e4SLinus Torvalds 
22581da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk)
22591da177e4SLinus Torvalds {
22601da177e4SLinus Torvalds 	clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
22611da177e4SLinus Torvalds }
22621da177e4SLinus Torvalds 
22638ae121acSGregory Haskins static inline int test_tsk_need_resched(struct task_struct *tsk)
22648ae121acSGregory Haskins {
22658ae121acSGregory Haskins 	return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
22668ae121acSGregory Haskins }
22678ae121acSGregory Haskins 
2268690cc3ffSEric W. Biederman static inline int restart_syscall(void)
2269690cc3ffSEric W. Biederman {
2270690cc3ffSEric W. Biederman 	set_tsk_thread_flag(current, TIF_SIGPENDING);
2271690cc3ffSEric W. Biederman 	return -ERESTARTNOINTR;
2272690cc3ffSEric W. Biederman }
2273690cc3ffSEric W. Biederman 
22741da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p)
22751da177e4SLinus Torvalds {
22761da177e4SLinus Torvalds 	return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
22771da177e4SLinus Torvalds }
22781da177e4SLinus Torvalds 
2279b3c97528SHarvey Harrison extern int __fatal_signal_pending(struct task_struct *p);
2280f776d12dSMatthew Wilcox 
2281f776d12dSMatthew Wilcox static inline int fatal_signal_pending(struct task_struct *p)
2282f776d12dSMatthew Wilcox {
2283f776d12dSMatthew Wilcox 	return signal_pending(p) && __fatal_signal_pending(p);
2284f776d12dSMatthew Wilcox }
2285f776d12dSMatthew Wilcox 
228616882c1eSOleg Nesterov static inline int signal_pending_state(long state, struct task_struct *p)
228716882c1eSOleg Nesterov {
228816882c1eSOleg Nesterov 	if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
228916882c1eSOleg Nesterov 		return 0;
229016882c1eSOleg Nesterov 	if (!signal_pending(p))
229116882c1eSOleg Nesterov 		return 0;
229216882c1eSOleg Nesterov 
229316882c1eSOleg Nesterov 	return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
229416882c1eSOleg Nesterov }
229516882c1eSOleg Nesterov 
22961da177e4SLinus Torvalds static inline int need_resched(void)
22971da177e4SLinus Torvalds {
22989404ef02SLinus Torvalds 	return unlikely(test_thread_flag(TIF_NEED_RESCHED));
22991da177e4SLinus Torvalds }
23001da177e4SLinus Torvalds 
23011da177e4SLinus Torvalds /*
23021da177e4SLinus Torvalds  * cond_resched() and cond_resched_lock(): latency reduction via
23031da177e4SLinus Torvalds  * explicit rescheduling in places that are safe. The return
23041da177e4SLinus Torvalds  * value indicates whether a reschedule was done in fact.
23051da177e4SLinus Torvalds  * cond_resched_lock() will drop the spinlock before scheduling,
23061da177e4SLinus Torvalds  * cond_resched_softirq() will enable bhs before scheduling.
23071da177e4SLinus Torvalds  */
2308c3921ab7SLinus Torvalds extern int _cond_resched(void);
2309c714a534SLinus Torvalds #ifdef CONFIG_PREEMPT_BKL
231002b67cc3SHerbert Xu static inline int cond_resched(void)
231102b67cc3SHerbert Xu {
231202b67cc3SHerbert Xu 	return 0;
231302b67cc3SHerbert Xu }
231402b67cc3SHerbert Xu #else
231502b67cc3SHerbert Xu static inline int cond_resched(void)
231602b67cc3SHerbert Xu {
231702b67cc3SHerbert Xu 	return _cond_resched();
231802b67cc3SHerbert Xu }
231902b67cc3SHerbert Xu #endif
23201da177e4SLinus Torvalds extern int cond_resched_lock(spinlock_t * lock);
23211da177e4SLinus Torvalds extern int cond_resched_softirq(void);
2322c3921ab7SLinus Torvalds static inline int cond_resched_bkl(void)
2323c3921ab7SLinus Torvalds {
2324c3921ab7SLinus Torvalds 	return _cond_resched();
2325c3921ab7SLinus Torvalds }
23261da177e4SLinus Torvalds 
23271da177e4SLinus Torvalds /*
23281da177e4SLinus Torvalds  * Does a critical section need to be broken due to another
232995c354feSNick Piggin  * task waiting?: (technically does not depend on CONFIG_PREEMPT,
233095c354feSNick Piggin  * but a general need for low latency)
23311da177e4SLinus Torvalds  */
233295c354feSNick Piggin static inline int spin_needbreak(spinlock_t *lock)
23331da177e4SLinus Torvalds {
233495c354feSNick Piggin #ifdef CONFIG_PREEMPT
233595c354feSNick Piggin 	return spin_is_contended(lock);
233695c354feSNick Piggin #else
23371da177e4SLinus Torvalds 	return 0;
233895c354feSNick Piggin #endif
23391da177e4SLinus Torvalds }
23401da177e4SLinus Torvalds 
23417bb44adeSRoland McGrath /*
2342f06febc9SFrank Mayhar  * Thread group CPU time accounting.
2343f06febc9SFrank Mayhar  */
23444cd4c1b4SPeter Zijlstra void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
23454da94d49SPeter Zijlstra void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
2346f06febc9SFrank Mayhar 
2347f06febc9SFrank Mayhar static inline void thread_group_cputime_init(struct signal_struct *sig)
2348f06febc9SFrank Mayhar {
23494cd4c1b4SPeter Zijlstra 	sig->cputimer.cputime = INIT_CPUTIME;
23504cd4c1b4SPeter Zijlstra 	spin_lock_init(&sig->cputimer.lock);
23514cd4c1b4SPeter Zijlstra 	sig->cputimer.running = 0;
2352f06febc9SFrank Mayhar }
2353f06febc9SFrank Mayhar 
2354f06febc9SFrank Mayhar static inline void thread_group_cputime_free(struct signal_struct *sig)
2355f06febc9SFrank Mayhar {
2356f06febc9SFrank Mayhar }
2357f06febc9SFrank Mayhar 
2358f06febc9SFrank Mayhar /*
23597bb44adeSRoland McGrath  * Reevaluate whether the task has signals pending delivery.
23607bb44adeSRoland McGrath  * Wake the task if so.
23617bb44adeSRoland McGrath  * This is required every time the blocked sigset_t changes.
23627bb44adeSRoland McGrath  * callers must hold sighand->siglock.
23637bb44adeSRoland McGrath  */
23647bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t);
23651da177e4SLinus Torvalds extern void recalc_sigpending(void);
23661da177e4SLinus Torvalds 
23671da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped);
23681da177e4SLinus Torvalds 
23691da177e4SLinus Torvalds /*
23701da177e4SLinus Torvalds  * Wrappers for p->thread_info->cpu access. No-op on UP.
23711da177e4SLinus Torvalds  */
23721da177e4SLinus Torvalds #ifdef CONFIG_SMP
23731da177e4SLinus Torvalds 
23741da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
23751da177e4SLinus Torvalds {
2376a1261f54SAl Viro 	return task_thread_info(p)->cpu;
23771da177e4SLinus Torvalds }
23781da177e4SLinus Torvalds 
2379c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
23801da177e4SLinus Torvalds 
23811da177e4SLinus Torvalds #else
23821da177e4SLinus Torvalds 
23831da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
23841da177e4SLinus Torvalds {
23851da177e4SLinus Torvalds 	return 0;
23861da177e4SLinus Torvalds }
23871da177e4SLinus Torvalds 
23881da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
23891da177e4SLinus Torvalds {
23901da177e4SLinus Torvalds }
23911da177e4SLinus Torvalds 
23921da177e4SLinus Torvalds #endif /* CONFIG_SMP */
23931da177e4SLinus Torvalds 
23941da177e4SLinus Torvalds extern void arch_pick_mmap_layout(struct mm_struct *mm);
23951da177e4SLinus Torvalds 
23961a3c3034SIngo Molnar #ifdef CONFIG_TRACING
23971a3c3034SIngo Molnar extern void
23981a3c3034SIngo Molnar __trace_special(void *__tr, void *__data,
23991a3c3034SIngo Molnar 		unsigned long arg1, unsigned long arg2, unsigned long arg3);
24001da177e4SLinus Torvalds #else
24011a3c3034SIngo Molnar static inline void
24021a3c3034SIngo Molnar __trace_special(void *__tr, void *__data,
24031a3c3034SIngo Molnar 		unsigned long arg1, unsigned long arg2, unsigned long arg3)
24041da177e4SLinus Torvalds {
24051da177e4SLinus Torvalds }
24061da177e4SLinus Torvalds #endif
24071da177e4SLinus Torvalds 
240896f874e2SRusty Russell extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
240996f874e2SRusty Russell extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
24105c45bf27SSiddha, Suresh B 
24111da177e4SLinus Torvalds extern void normalize_rt_tasks(void);
24121da177e4SLinus Torvalds 
2413052f1dc7SPeter Zijlstra #ifdef CONFIG_GROUP_SCHED
24149b5b7751SSrivatsa Vaddagiri 
24154cf86d77SIngo Molnar extern struct task_group init_task_group;
2416eff766a6SPeter Zijlstra #ifdef CONFIG_USER_SCHED
2417eff766a6SPeter Zijlstra extern struct task_group root_task_group;
24186c415b92SArun R Bharadwaj extern void set_tg_uid(struct user_struct *user);
2419eff766a6SPeter Zijlstra #endif
24209b5b7751SSrivatsa Vaddagiri 
2421ec7dc8acSDhaval Giani extern struct task_group *sched_create_group(struct task_group *parent);
24224cf86d77SIngo Molnar extern void sched_destroy_group(struct task_group *tg);
24239b5b7751SSrivatsa Vaddagiri extern void sched_move_task(struct task_struct *tsk);
2424052f1dc7SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED
24254cf86d77SIngo Molnar extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
24265cb350baSDhaval Giani extern unsigned long sched_group_shares(struct task_group *tg);
2427052f1dc7SPeter Zijlstra #endif
2428052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED
24299f0c1e56SPeter Zijlstra extern int sched_group_set_rt_runtime(struct task_group *tg,
24309f0c1e56SPeter Zijlstra 				      long rt_runtime_us);
24319f0c1e56SPeter Zijlstra extern long sched_group_rt_runtime(struct task_group *tg);
2432d0b27fa7SPeter Zijlstra extern int sched_group_set_rt_period(struct task_group *tg,
2433d0b27fa7SPeter Zijlstra 				      long rt_period_us);
2434d0b27fa7SPeter Zijlstra extern long sched_group_rt_period(struct task_group *tg);
243554e99124SDhaval Giani extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk);
2436052f1dc7SPeter Zijlstra #endif
24379b5b7751SSrivatsa Vaddagiri #endif
24389b5b7751SSrivatsa Vaddagiri 
243954e99124SDhaval Giani extern int task_can_switch_user(struct user_struct *up,
244054e99124SDhaval Giani 					struct task_struct *tsk);
244154e99124SDhaval Giani 
24424b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT
24434b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
24444b98d11bSAlexey Dobriyan {
2445940389b8SAndrea Righi 	tsk->ioac.rchar += amt;
24464b98d11bSAlexey Dobriyan }
24474b98d11bSAlexey Dobriyan 
24484b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
24494b98d11bSAlexey Dobriyan {
2450940389b8SAndrea Righi 	tsk->ioac.wchar += amt;
24514b98d11bSAlexey Dobriyan }
24524b98d11bSAlexey Dobriyan 
24534b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
24544b98d11bSAlexey Dobriyan {
2455940389b8SAndrea Righi 	tsk->ioac.syscr++;
24564b98d11bSAlexey Dobriyan }
24574b98d11bSAlexey Dobriyan 
24584b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
24594b98d11bSAlexey Dobriyan {
2460940389b8SAndrea Righi 	tsk->ioac.syscw++;
24614b98d11bSAlexey Dobriyan }
24624b98d11bSAlexey Dobriyan #else
24634b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
24644b98d11bSAlexey Dobriyan {
24654b98d11bSAlexey Dobriyan }
24664b98d11bSAlexey Dobriyan 
24674b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
24684b98d11bSAlexey Dobriyan {
24694b98d11bSAlexey Dobriyan }
24704b98d11bSAlexey Dobriyan 
24714b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
24724b98d11bSAlexey Dobriyan {
24734b98d11bSAlexey Dobriyan }
24744b98d11bSAlexey Dobriyan 
24754b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
24764b98d11bSAlexey Dobriyan {
24774b98d11bSAlexey Dobriyan }
24784b98d11bSAlexey Dobriyan #endif
24794b98d11bSAlexey Dobriyan 
248082455257SDave Hansen #ifndef TASK_SIZE_OF
248182455257SDave Hansen #define TASK_SIZE_OF(tsk)	TASK_SIZE
248282455257SDave Hansen #endif
248382455257SDave Hansen 
24840793a61dSThomas Gleixner /*
24850793a61dSThomas Gleixner  * Call the function if the target task is executing on a CPU right now:
24860793a61dSThomas Gleixner  */
24870793a61dSThomas Gleixner extern void task_oncpu_function_call(struct task_struct *p,
24880793a61dSThomas Gleixner 				     void (*func) (void *info), void *info);
24890793a61dSThomas Gleixner 
24900793a61dSThomas Gleixner 
2491cf475ad2SBalbir Singh #ifdef CONFIG_MM_OWNER
2492cf475ad2SBalbir Singh extern void mm_update_next_owner(struct mm_struct *mm);
2493cf475ad2SBalbir Singh extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p);
2494cf475ad2SBalbir Singh #else
2495cf475ad2SBalbir Singh static inline void mm_update_next_owner(struct mm_struct *mm)
2496cf475ad2SBalbir Singh {
2497cf475ad2SBalbir Singh }
2498cf475ad2SBalbir Singh 
2499cf475ad2SBalbir Singh static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p)
2500cf475ad2SBalbir Singh {
2501cf475ad2SBalbir Singh }
2502cf475ad2SBalbir Singh #endif /* CONFIG_MM_OWNER */
2503cf475ad2SBalbir Singh 
25047c731e0aSSteven Rostedt #define TASK_STATE_TO_CHAR_STR "RSDTtZX"
25057c731e0aSSteven Rostedt 
25061da177e4SLinus Torvalds #endif /* __KERNEL__ */
25071da177e4SLinus Torvalds 
25081da177e4SLinus Torvalds #endif
2509