xref: /linux/include/linux/sched.h (revision 78f2c7db6068fd6ef75b8c120f04a388848eacb5)
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 */
30b7b3c76aSDavid Woodhouse 
31b7b3c76aSDavid Woodhouse /*
32b7b3c76aSDavid Woodhouse  * Scheduling policies
33b7b3c76aSDavid Woodhouse  */
34b7b3c76aSDavid Woodhouse #define SCHED_NORMAL		0
35b7b3c76aSDavid Woodhouse #define SCHED_FIFO		1
36b7b3c76aSDavid Woodhouse #define SCHED_RR		2
37b7b3c76aSDavid Woodhouse #define SCHED_BATCH		3
380e6aca43SIngo Molnar /* SCHED_ISO: reserved but not implemented yet */
390e6aca43SIngo Molnar #define SCHED_IDLE		5
40b7b3c76aSDavid Woodhouse 
41a3b6714eSDavid Woodhouse #ifdef __KERNEL__
42b7b3c76aSDavid Woodhouse 
43b7b3c76aSDavid Woodhouse struct sched_param {
44b7b3c76aSDavid Woodhouse 	int sched_priority;
45b7b3c76aSDavid Woodhouse };
46b7b3c76aSDavid Woodhouse 
471da177e4SLinus Torvalds #include <asm/param.h>	/* for HZ */
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #include <linux/capability.h>
501da177e4SLinus Torvalds #include <linux/threads.h>
511da177e4SLinus Torvalds #include <linux/kernel.h>
521da177e4SLinus Torvalds #include <linux/types.h>
531da177e4SLinus Torvalds #include <linux/timex.h>
541da177e4SLinus Torvalds #include <linux/jiffies.h>
551da177e4SLinus Torvalds #include <linux/rbtree.h>
561da177e4SLinus Torvalds #include <linux/thread_info.h>
571da177e4SLinus Torvalds #include <linux/cpumask.h>
581da177e4SLinus Torvalds #include <linux/errno.h>
591da177e4SLinus Torvalds #include <linux/nodemask.h>
60c92ff1bdSMartin Schwidefsky #include <linux/mm_types.h>
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds #include <asm/system.h>
631da177e4SLinus Torvalds #include <asm/semaphore.h>
641da177e4SLinus Torvalds #include <asm/page.h>
651da177e4SLinus Torvalds #include <asm/ptrace.h>
661da177e4SLinus Torvalds #include <asm/cputime.h>
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds #include <linux/smp.h>
691da177e4SLinus Torvalds #include <linux/sem.h>
701da177e4SLinus Torvalds #include <linux/signal.h>
711da177e4SLinus Torvalds #include <linux/securebits.h>
721da177e4SLinus Torvalds #include <linux/fs_struct.h>
731da177e4SLinus Torvalds #include <linux/compiler.h>
741da177e4SLinus Torvalds #include <linux/completion.h>
751da177e4SLinus Torvalds #include <linux/pid.h>
761da177e4SLinus Torvalds #include <linux/percpu.h>
771da177e4SLinus Torvalds #include <linux/topology.h>
783e26c149SPeter Zijlstra #include <linux/proportions.h>
791da177e4SLinus Torvalds #include <linux/seccomp.h>
80e56d0903SIngo Molnar #include <linux/rcupdate.h>
810771dfefSIngo Molnar #include <linux/futex.h>
8223f78d4aSIngo Molnar #include <linux/rtmutex.h>
831da177e4SLinus Torvalds 
84a3b6714eSDavid Woodhouse #include <linux/time.h>
85a3b6714eSDavid Woodhouse #include <linux/param.h>
86a3b6714eSDavid Woodhouse #include <linux/resource.h>
87a3b6714eSDavid Woodhouse #include <linux/timer.h>
88a3b6714eSDavid Woodhouse #include <linux/hrtimer.h>
897c3ab738SAndrew Morton #include <linux/task_io_accounting.h>
905cb350baSDhaval Giani #include <linux/kobject.h>
91a3b6714eSDavid Woodhouse 
92a3b6714eSDavid Woodhouse #include <asm/processor.h>
9336d57ac4SH. J. Lu 
941da177e4SLinus Torvalds struct exec_domain;
95c87e2837SIngo Molnar struct futex_pi_state;
96d89d8796SNeil Brown struct bio;
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds /*
991da177e4SLinus Torvalds  * List of flags we want to share for kernel threads,
1001da177e4SLinus Torvalds  * if only because they are not used by them anyway.
1011da177e4SLinus Torvalds  */
1021da177e4SLinus Torvalds #define CLONE_KERNEL	(CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds /*
1051da177e4SLinus Torvalds  * These are the constant used to fake the fixed-point load-average
1061da177e4SLinus Torvalds  * counting. Some notes:
1071da177e4SLinus Torvalds  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
1081da177e4SLinus Torvalds  *    a load-average precision of 10 bits integer + 11 bits fractional
1091da177e4SLinus Torvalds  *  - if you want to count load-averages more often, you need more
1101da177e4SLinus Torvalds  *    precision, or rounding will get you. With 2-second counting freq,
1111da177e4SLinus Torvalds  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
1121da177e4SLinus Torvalds  *    11 bit fractions.
1131da177e4SLinus Torvalds  */
1141da177e4SLinus Torvalds extern unsigned long avenrun[];		/* Load averages */
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds #define FSHIFT		11		/* nr of bits of precision */
1171da177e4SLinus Torvalds #define FIXED_1		(1<<FSHIFT)	/* 1.0 as fixed-point */
1180c2043abSLinus Torvalds #define LOAD_FREQ	(5*HZ+1)	/* 5 sec intervals */
1191da177e4SLinus Torvalds #define EXP_1		1884		/* 1/exp(5sec/1min) as fixed-point */
1201da177e4SLinus Torvalds #define EXP_5		2014		/* 1/exp(5sec/5min) */
1211da177e4SLinus Torvalds #define EXP_15		2037		/* 1/exp(5sec/15min) */
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \
1241da177e4SLinus Torvalds 	load *= exp; \
1251da177e4SLinus Torvalds 	load += n*(FIXED_1-exp); \
1261da177e4SLinus Torvalds 	load >>= FSHIFT;
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds extern unsigned long total_forks;
1291da177e4SLinus Torvalds extern int nr_threads;
1301da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts);
1311da177e4SLinus Torvalds extern int nr_processes(void);
1321da177e4SLinus Torvalds extern unsigned long nr_running(void);
1331da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void);
134db1b1fefSJack Steiner extern unsigned long nr_active(void);
1351da177e4SLinus Torvalds extern unsigned long nr_iowait(void);
1362dd73a4fSPeter Williams extern unsigned long weighted_cpuload(const int cpu);
1371da177e4SLinus Torvalds 
13843ae34cbSIngo Molnar struct seq_file;
13943ae34cbSIngo Molnar struct cfs_rq;
1404cf86d77SIngo Molnar struct task_group;
14143ae34cbSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
14243ae34cbSIngo Molnar extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
14343ae34cbSIngo Molnar extern void proc_sched_set_task(struct task_struct *p);
14443ae34cbSIngo Molnar extern void
1455cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
14643ae34cbSIngo Molnar #else
14743ae34cbSIngo Molnar static inline void
14843ae34cbSIngo Molnar proc_sched_show_task(struct task_struct *p, struct seq_file *m)
14943ae34cbSIngo Molnar {
15043ae34cbSIngo Molnar }
15143ae34cbSIngo Molnar static inline void proc_sched_set_task(struct task_struct *p)
15243ae34cbSIngo Molnar {
15343ae34cbSIngo Molnar }
15443ae34cbSIngo Molnar static inline void
1555cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
15643ae34cbSIngo Molnar {
15743ae34cbSIngo Molnar }
15843ae34cbSIngo Molnar #endif
1591da177e4SLinus Torvalds 
1604a8342d2SLinus Torvalds /*
1614a8342d2SLinus Torvalds  * Task state bitmask. NOTE! These bits are also
1624a8342d2SLinus Torvalds  * encoded in fs/proc/array.c: get_task_state().
1634a8342d2SLinus Torvalds  *
1644a8342d2SLinus Torvalds  * We have two separate sets of flags: task->state
1654a8342d2SLinus Torvalds  * is about runnability, while task->exit_state are
1664a8342d2SLinus Torvalds  * about the task exiting. Confusing, but this way
1674a8342d2SLinus Torvalds  * modifying one set can't modify the other one by
1684a8342d2SLinus Torvalds  * mistake.
1694a8342d2SLinus Torvalds  */
1701da177e4SLinus Torvalds #define TASK_RUNNING		0
1711da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE	1
1721da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE	2
1734a8342d2SLinus Torvalds #define TASK_STOPPED		4
1744a8342d2SLinus Torvalds #define TASK_TRACED		8
1754a8342d2SLinus Torvalds /* in tsk->exit_state */
1764a8342d2SLinus Torvalds #define EXIT_ZOMBIE		16
1774a8342d2SLinus Torvalds #define EXIT_DEAD		32
1784a8342d2SLinus Torvalds /* in tsk->state again */
179af927232SMike Galbraith #define TASK_DEAD		64
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds #define __set_task_state(tsk, state_value)		\
1821da177e4SLinus Torvalds 	do { (tsk)->state = (state_value); } while (0)
1831da177e4SLinus Torvalds #define set_task_state(tsk, state_value)		\
1841da177e4SLinus Torvalds 	set_mb((tsk)->state, (state_value))
1851da177e4SLinus Torvalds 
186498d0c57SAndrew Morton /*
187498d0c57SAndrew Morton  * set_current_state() includes a barrier so that the write of current->state
188498d0c57SAndrew Morton  * is correctly serialised wrt the caller's subsequent test of whether to
189498d0c57SAndrew Morton  * actually sleep:
190498d0c57SAndrew Morton  *
191498d0c57SAndrew Morton  *	set_current_state(TASK_UNINTERRUPTIBLE);
192498d0c57SAndrew Morton  *	if (do_i_need_to_sleep())
193498d0c57SAndrew Morton  *		schedule();
194498d0c57SAndrew Morton  *
195498d0c57SAndrew Morton  * If the caller does not need such serialisation then use __set_current_state()
196498d0c57SAndrew Morton  */
1971da177e4SLinus Torvalds #define __set_current_state(state_value)			\
1981da177e4SLinus Torvalds 	do { current->state = (state_value); } while (0)
1991da177e4SLinus Torvalds #define set_current_state(state_value)		\
2001da177e4SLinus Torvalds 	set_mb(current->state, (state_value))
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds /* Task command name length */
2031da177e4SLinus Torvalds #define TASK_COMM_LEN 16
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds #include <linux/spinlock.h>
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds /*
2081da177e4SLinus Torvalds  * This serializes "schedule()" and also protects
2091da177e4SLinus Torvalds  * the run-queue from deletions/modifications (but
2101da177e4SLinus Torvalds  * _adding_ to the beginning of the run-queue has
2111da177e4SLinus Torvalds  * a separate lock).
2121da177e4SLinus Torvalds  */
2131da177e4SLinus Torvalds extern rwlock_t tasklist_lock;
2141da177e4SLinus Torvalds extern spinlock_t mmlist_lock;
2151da177e4SLinus Torvalds 
21636c8b586SIngo Molnar struct task_struct;
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds extern void sched_init(void);
2191da177e4SLinus Torvalds extern void sched_init_smp(void);
22036c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu);
2211df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle);
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds extern cpumask_t nohz_cpu_mask;
22446cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
22546cb4b7cSSiddha, Suresh B extern int select_nohz_load_balancer(int cpu);
22646cb4b7cSSiddha, Suresh B #else
22746cb4b7cSSiddha, Suresh B static inline int select_nohz_load_balancer(int cpu)
22846cb4b7cSSiddha, Suresh B {
22946cb4b7cSSiddha, Suresh B 	return 0;
23046cb4b7cSSiddha, Suresh B }
23146cb4b7cSSiddha, Suresh B #endif
2321da177e4SLinus Torvalds 
233e59e2ae2SIngo Molnar /*
23439bc89fdSIngo Molnar  * Only dump TASK_* tasks. (0 for all tasks)
235e59e2ae2SIngo Molnar  */
236e59e2ae2SIngo Molnar extern void show_state_filter(unsigned long state_filter);
237e59e2ae2SIngo Molnar 
238e59e2ae2SIngo Molnar static inline void show_state(void)
239e59e2ae2SIngo Molnar {
24039bc89fdSIngo Molnar 	show_state_filter(0);
241e59e2ae2SIngo Molnar }
242e59e2ae2SIngo Molnar 
2431da177e4SLinus Torvalds extern void show_regs(struct pt_regs *);
2441da177e4SLinus Torvalds 
2451da177e4SLinus Torvalds /*
2461da177e4SLinus Torvalds  * TASK is a pointer to the task whose backtrace we want to see (or NULL for current
2471da177e4SLinus Torvalds  * task), SP is the stack pointer of the first frame that should be shown in the back
2481da177e4SLinus Torvalds  * trace (or NULL if the entire call-chain of the task should be shown).
2491da177e4SLinus Torvalds  */
2501da177e4SLinus Torvalds extern void show_stack(struct task_struct *task, unsigned long *sp);
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds void io_schedule(void);
2531da177e4SLinus Torvalds long io_schedule_timeout(long timeout);
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds extern void cpu_init (void);
2561da177e4SLinus Torvalds extern void trap_init(void);
257fa13a5a1SPaul Mackerras extern void account_process_tick(struct task_struct *task, int user);
2581da177e4SLinus Torvalds extern void update_process_times(int user);
2591da177e4SLinus Torvalds extern void scheduler_tick(void);
2601da177e4SLinus Torvalds 
26182a1fcb9SIngo Molnar extern void sched_show_task(struct task_struct *p);
26282a1fcb9SIngo Molnar 
2638446f1d3SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP
2646687a97dSIngo Molnar extern void softlockup_tick(void);
2658446f1d3SIngo Molnar extern void spawn_softlockup_task(void);
2668446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void);
26704c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void);
268c4f3b63fSRavikiran G Thirumalai extern int softlockup_thresh;
26982a1fcb9SIngo Molnar extern unsigned long sysctl_hung_task_check_count;
27082a1fcb9SIngo Molnar extern unsigned long sysctl_hung_task_timeout_secs;
27182a1fcb9SIngo Molnar extern long sysctl_hung_task_warnings;
2728446f1d3SIngo Molnar #else
2736687a97dSIngo Molnar static inline void softlockup_tick(void)
2748446f1d3SIngo Molnar {
2758446f1d3SIngo Molnar }
2768446f1d3SIngo Molnar static inline void spawn_softlockup_task(void)
2778446f1d3SIngo Molnar {
2788446f1d3SIngo Molnar }
2798446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void)
2808446f1d3SIngo Molnar {
2818446f1d3SIngo Molnar }
28204c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void)
28304c9167fSJeremy Fitzhardinge {
28404c9167fSJeremy Fitzhardinge }
2858446f1d3SIngo Molnar #endif
2868446f1d3SIngo Molnar 
2878446f1d3SIngo Molnar 
2881da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */
2891da177e4SLinus Torvalds #define __sched		__attribute__((__section__(".sched.text")))
290deaf2227SIngo Molnar 
291deaf2227SIngo Molnar /* Linker adds these: start and end of __sched functions */
292deaf2227SIngo Molnar extern char __sched_text_start[], __sched_text_end[];
293deaf2227SIngo Molnar 
2941da177e4SLinus Torvalds /* Is this address in the __sched functions? */
2951da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr);
2961da177e4SLinus Torvalds 
2971da177e4SLinus Torvalds #define	MAX_SCHEDULE_TIMEOUT	LONG_MAX
2981da177e4SLinus Torvalds extern signed long FASTCALL(schedule_timeout(signed long timeout));
29964ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout);
30064ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout);
3011da177e4SLinus Torvalds asmlinkage void schedule(void);
3021da177e4SLinus Torvalds 
303ab516013SSerge E. Hallyn struct nsproxy;
304acce292cSCedric Le Goater struct user_namespace;
3051da177e4SLinus Torvalds 
3061da177e4SLinus Torvalds /* Maximum number of active map areas.. This is a random (large) number */
3071da177e4SLinus Torvalds #define DEFAULT_MAX_MAP_COUNT	65536
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds extern int sysctl_max_map_count;
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds #include <linux/aio.h>
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds extern unsigned long
3141da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
3151da177e4SLinus Torvalds 		       unsigned long, unsigned long);
3161da177e4SLinus Torvalds extern unsigned long
3171da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
3181da177e4SLinus Torvalds 			  unsigned long len, unsigned long pgoff,
3191da177e4SLinus Torvalds 			  unsigned long flags);
3201363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long);
3211363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
3221da177e4SLinus Torvalds 
323f412ac08SHugh Dickins #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
324f412ac08SHugh Dickins /*
325f412ac08SHugh Dickins  * The mm counters are not protected by its page_table_lock,
326f412ac08SHugh Dickins  * so must be incremented atomically.
327f412ac08SHugh Dickins  */
328d3cb4871SChristoph Lameter #define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
329d3cb4871SChristoph Lameter #define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
330d3cb4871SChristoph Lameter #define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
331d3cb4871SChristoph Lameter #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
332d3cb4871SChristoph Lameter #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
333f412ac08SHugh Dickins 
334f412ac08SHugh Dickins #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
335f412ac08SHugh Dickins /*
336f412ac08SHugh Dickins  * The mm counters are protected by its page_table_lock,
337f412ac08SHugh Dickins  * so can be incremented directly.
338f412ac08SHugh Dickins  */
3391da177e4SLinus Torvalds #define set_mm_counter(mm, member, value) (mm)->_##member = (value)
3401da177e4SLinus Torvalds #define get_mm_counter(mm, member) ((mm)->_##member)
3411da177e4SLinus Torvalds #define add_mm_counter(mm, member, value) (mm)->_##member += (value)
3421da177e4SLinus Torvalds #define inc_mm_counter(mm, member) (mm)->_##member++
3431da177e4SLinus Torvalds #define dec_mm_counter(mm, member) (mm)->_##member--
3444294621fSHugh Dickins 
345f412ac08SHugh Dickins #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
346f412ac08SHugh Dickins 
347f412ac08SHugh Dickins #define get_mm_rss(mm)					\
348f412ac08SHugh Dickins 	(get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
349365e9c87SHugh Dickins #define update_hiwater_rss(mm)	do {			\
350365e9c87SHugh Dickins 	unsigned long _rss = get_mm_rss(mm);		\
351365e9c87SHugh Dickins 	if ((mm)->hiwater_rss < _rss)			\
352365e9c87SHugh Dickins 		(mm)->hiwater_rss = _rss;		\
353365e9c87SHugh Dickins } while (0)
354365e9c87SHugh Dickins #define update_hiwater_vm(mm)	do {			\
355365e9c87SHugh Dickins 	if ((mm)->hiwater_vm < (mm)->total_vm)		\
356365e9c87SHugh Dickins 		(mm)->hiwater_vm = (mm)->total_vm;	\
357365e9c87SHugh Dickins } while (0)
358365e9c87SHugh Dickins 
3596c5d5238SKawai, Hidehiro extern void set_dumpable(struct mm_struct *mm, int value);
3606c5d5238SKawai, Hidehiro extern int get_dumpable(struct mm_struct *mm);
3616c5d5238SKawai, Hidehiro 
3626c5d5238SKawai, Hidehiro /* mm flags */
3633cb4a0bbSKawai, Hidehiro /* dumpable bits */
3646c5d5238SKawai, Hidehiro #define MMF_DUMPABLE      0  /* core dump is permitted */
3656c5d5238SKawai, Hidehiro #define MMF_DUMP_SECURELY 1  /* core file is readable only by root */
3663cb4a0bbSKawai, Hidehiro #define MMF_DUMPABLE_BITS 2
3673cb4a0bbSKawai, Hidehiro 
3683cb4a0bbSKawai, Hidehiro /* coredump filter bits */
3693cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_PRIVATE	2
3703cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_SHARED	3
3713cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_PRIVATE	4
3723cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_SHARED	5
37382df3973SRoland McGrath #define MMF_DUMP_ELF_HEADERS	6
3743cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_SHIFT	MMF_DUMPABLE_BITS
37582df3973SRoland McGrath #define MMF_DUMP_FILTER_BITS	5
3763cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_MASK \
3773cb4a0bbSKawai, Hidehiro 	(((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
3783cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_DEFAULT \
3793cb4a0bbSKawai, Hidehiro 	((1 << MMF_DUMP_ANON_PRIVATE) |	(1 << MMF_DUMP_ANON_SHARED))
3806c5d5238SKawai, Hidehiro 
3811da177e4SLinus Torvalds struct sighand_struct {
3821da177e4SLinus Torvalds 	atomic_t		count;
3831da177e4SLinus Torvalds 	struct k_sigaction	action[_NSIG];
3841da177e4SLinus Torvalds 	spinlock_t		siglock;
385b8fceee1SDavide Libenzi 	wait_queue_head_t	signalfd_wqh;
3861da177e4SLinus Torvalds };
3871da177e4SLinus Torvalds 
3880e464814SKaiGai Kohei struct pacct_struct {
389f6ec29a4SKaiGai Kohei 	int			ac_flag;
390f6ec29a4SKaiGai Kohei 	long			ac_exitcode;
3910e464814SKaiGai Kohei 	unsigned long		ac_mem;
39277787bfbSKaiGai Kohei 	cputime_t		ac_utime, ac_stime;
39377787bfbSKaiGai Kohei 	unsigned long		ac_minflt, ac_majflt;
3940e464814SKaiGai Kohei };
3950e464814SKaiGai Kohei 
3961da177e4SLinus Torvalds /*
3971da177e4SLinus Torvalds  * NOTE! "signal_struct" does not have it's own
3981da177e4SLinus Torvalds  * locking, because a shared signal_struct always
3991da177e4SLinus Torvalds  * implies a shared sighand_struct, so locking
4001da177e4SLinus Torvalds  * sighand_struct is always a proper superset of
4011da177e4SLinus Torvalds  * the locking of signal_struct.
4021da177e4SLinus Torvalds  */
4031da177e4SLinus Torvalds struct signal_struct {
4041da177e4SLinus Torvalds 	atomic_t		count;
4051da177e4SLinus Torvalds 	atomic_t		live;
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds 	wait_queue_head_t	wait_chldexit;	/* for wait4() */
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds 	/* current thread group signal load-balancing target: */
41036c8b586SIngo Molnar 	struct task_struct	*curr_target;
4111da177e4SLinus Torvalds 
4121da177e4SLinus Torvalds 	/* shared signal handling: */
4131da177e4SLinus Torvalds 	struct sigpending	shared_pending;
4141da177e4SLinus Torvalds 
4151da177e4SLinus Torvalds 	/* thread group exit support */
4161da177e4SLinus Torvalds 	int			group_exit_code;
4171da177e4SLinus Torvalds 	/* overloaded:
4181da177e4SLinus Torvalds 	 * - notify group_exit_task when ->count is equal to notify_count
4191da177e4SLinus Torvalds 	 * - everyone except group_exit_task is stopped during signal delivery
4201da177e4SLinus Torvalds 	 *   of fatal signals, group_exit_task processes the signal.
4211da177e4SLinus Torvalds 	 */
4221da177e4SLinus Torvalds 	struct task_struct	*group_exit_task;
4231da177e4SLinus Torvalds 	int			notify_count;
4241da177e4SLinus Torvalds 
4251da177e4SLinus Torvalds 	/* thread group stop support, overloads group_exit_code too */
4261da177e4SLinus Torvalds 	int			group_stop_count;
4271da177e4SLinus Torvalds 	unsigned int		flags; /* see SIGNAL_* flags below */
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds 	/* POSIX.1b Interval Timers */
4301da177e4SLinus Torvalds 	struct list_head posix_timers;
4311da177e4SLinus Torvalds 
4321da177e4SLinus Torvalds 	/* ITIMER_REAL timer for the process */
4332ff678b8SThomas Gleixner 	struct hrtimer real_timer;
43405cfb614SRoman Zippel 	struct task_struct *tsk;
4352ff678b8SThomas Gleixner 	ktime_t it_real_incr;
4361da177e4SLinus Torvalds 
4371da177e4SLinus Torvalds 	/* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
4381da177e4SLinus Torvalds 	cputime_t it_prof_expires, it_virt_expires;
4391da177e4SLinus Torvalds 	cputime_t it_prof_incr, it_virt_incr;
4401da177e4SLinus Torvalds 
4411da177e4SLinus Torvalds 	/* job control IDs */
4429a2e7057SPavel Emelyanov 
4439a2e7057SPavel Emelyanov 	/*
4449a2e7057SPavel Emelyanov 	 * pgrp and session fields are deprecated.
4459a2e7057SPavel Emelyanov 	 * use the task_session_Xnr and task_pgrp_Xnr routines below
4469a2e7057SPavel Emelyanov 	 */
4479a2e7057SPavel Emelyanov 
4489a2e7057SPavel Emelyanov 	union {
4499a2e7057SPavel Emelyanov 		pid_t pgrp __deprecated;
4509a2e7057SPavel Emelyanov 		pid_t __pgrp;
4519a2e7057SPavel Emelyanov 	};
4529a2e7057SPavel Emelyanov 
453ab521dc0SEric W. Biederman 	struct pid *tty_old_pgrp;
4541ec320afSCedric Le Goater 
4551ec320afSCedric Le Goater 	union {
4561ec320afSCedric Le Goater 		pid_t session __deprecated;
4571ec320afSCedric Le Goater 		pid_t __session;
4581ec320afSCedric Le Goater 	};
4591ec320afSCedric Le Goater 
4601da177e4SLinus Torvalds 	/* boolean value for session group leader */
4611da177e4SLinus Torvalds 	int leader;
4621da177e4SLinus Torvalds 
4631da177e4SLinus Torvalds 	struct tty_struct *tty; /* NULL if no tty */
4641da177e4SLinus Torvalds 
4651da177e4SLinus Torvalds 	/*
4661da177e4SLinus Torvalds 	 * Cumulative resource counters for dead threads in the group,
4671da177e4SLinus Torvalds 	 * and for reaped dead child processes forked by this group.
4681da177e4SLinus Torvalds 	 * Live threads maintain their own counters and add to these
4691da177e4SLinus Torvalds 	 * in __exit_signal, except for the group leader.
4701da177e4SLinus Torvalds 	 */
4711da177e4SLinus Torvalds 	cputime_t utime, stime, cutime, cstime;
4729ac52315SLaurent Vivier 	cputime_t gtime;
4739ac52315SLaurent Vivier 	cputime_t cgtime;
4741da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
4751da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
4766eaeeabaSEric Dumazet 	unsigned long inblock, oublock, cinblock, coublock;
4771da177e4SLinus Torvalds 
4781da177e4SLinus Torvalds 	/*
4791da177e4SLinus Torvalds 	 * Cumulative ns of scheduled CPU time for dead threads in the
4801da177e4SLinus Torvalds 	 * group, not including a zombie group leader.  (This only differs
4811da177e4SLinus Torvalds 	 * from jiffies_to_ns(utime + stime) if sched_clock uses something
4821da177e4SLinus Torvalds 	 * other than jiffies.)
4831da177e4SLinus Torvalds 	 */
48441b86e9cSIngo Molnar 	unsigned long long sum_sched_runtime;
4851da177e4SLinus Torvalds 
4861da177e4SLinus Torvalds 	/*
4871da177e4SLinus Torvalds 	 * We don't bother to synchronize most readers of this at all,
4881da177e4SLinus Torvalds 	 * because there is no reader checking a limit that actually needs
4891da177e4SLinus Torvalds 	 * to get both rlim_cur and rlim_max atomically, and either one
4901da177e4SLinus Torvalds 	 * alone is a single word that can safely be read normally.
4911da177e4SLinus Torvalds 	 * getrlimit/setrlimit use task_lock(current->group_leader) to
4921da177e4SLinus Torvalds 	 * protect this instead of the siglock, because they really
4931da177e4SLinus Torvalds 	 * have no need to disable irqs.
4941da177e4SLinus Torvalds 	 */
4951da177e4SLinus Torvalds 	struct rlimit rlim[RLIM_NLIMITS];
4961da177e4SLinus Torvalds 
4971da177e4SLinus Torvalds 	struct list_head cpu_timers[3];
4981da177e4SLinus Torvalds 
4991da177e4SLinus Torvalds 	/* keep the process-shared keyrings here so that they do the right
5001da177e4SLinus Torvalds 	 * thing in threads created with CLONE_THREAD */
5011da177e4SLinus Torvalds #ifdef CONFIG_KEYS
5021da177e4SLinus Torvalds 	struct key *session_keyring;	/* keyring inherited over fork */
5031da177e4SLinus Torvalds 	struct key *process_keyring;	/* keyring private to this process */
5041da177e4SLinus Torvalds #endif
5050e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT
5060e464814SKaiGai Kohei 	struct pacct_struct pacct;	/* per-process accounting information */
5070e464814SKaiGai Kohei #endif
508ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS
509ad4ecbcbSShailabh Nagar 	struct taskstats *stats;
510ad4ecbcbSShailabh Nagar #endif
511522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT
512522ed776SMiloslav Trmac 	unsigned audit_tty;
513522ed776SMiloslav Trmac 	struct tty_audit_buf *tty_audit_buf;
514522ed776SMiloslav Trmac #endif
5151da177e4SLinus Torvalds };
5161da177e4SLinus Torvalds 
5174866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */
5184866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
5194866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW
5204866cde0SNick Piggin #endif
5214866cde0SNick Piggin 
5221da177e4SLinus Torvalds /*
5231da177e4SLinus Torvalds  * Bits in flags field of signal_struct.
5241da177e4SLinus Torvalds  */
5251da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED	0x00000001 /* job control stop in effect */
5261da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED	0x00000002 /* stop signal dequeued */
5271da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED	0x00000004 /* SIGCONT since WCONTINUED reap */
5281da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT	0x00000008 /* group exit in progress */
5291da177e4SLinus Torvalds 
5301da177e4SLinus Torvalds /*
5311da177e4SLinus Torvalds  * Some day this will be a full-fledged user tracking system..
5321da177e4SLinus Torvalds  */
5331da177e4SLinus Torvalds struct user_struct {
5341da177e4SLinus Torvalds 	atomic_t __count;	/* reference count */
5351da177e4SLinus Torvalds 	atomic_t processes;	/* How many processes does this user have? */
5361da177e4SLinus Torvalds 	atomic_t files;		/* How many open files does this user have? */
5371da177e4SLinus Torvalds 	atomic_t sigpending;	/* How many pending signals does this user have? */
5382d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
5390eeca283SRobert Love 	atomic_t inotify_watches; /* How many inotify watches does this user have? */
5400eeca283SRobert Love 	atomic_t inotify_devs;	/* How many inotify devs does this user have opened? */
5410eeca283SRobert Love #endif
542970a8645SAlexey Dobriyan #ifdef CONFIG_POSIX_MQUEUE
5431da177e4SLinus Torvalds 	/* protected by mq_lock	*/
5441da177e4SLinus Torvalds 	unsigned long mq_bytes;	/* How many bytes can be allocated to mqueue? */
545970a8645SAlexey Dobriyan #endif
5461da177e4SLinus Torvalds 	unsigned long locked_shm; /* How many pages of mlocked shm ? */
5471da177e4SLinus Torvalds 
5481da177e4SLinus Torvalds #ifdef CONFIG_KEYS
5491da177e4SLinus Torvalds 	struct key *uid_keyring;	/* UID specific keyring */
5501da177e4SLinus Torvalds 	struct key *session_keyring;	/* UID's default session keyring */
5511da177e4SLinus Torvalds #endif
5521da177e4SLinus Torvalds 
5531da177e4SLinus Torvalds 	/* Hash table maintenance information */
554735de223SPavel Emelyanov 	struct hlist_node uidhash_node;
5551da177e4SLinus Torvalds 	uid_t uid;
55624e377a8SSrivatsa Vaddagiri 
55724e377a8SSrivatsa Vaddagiri #ifdef CONFIG_FAIR_USER_SCHED
5584cf86d77SIngo Molnar 	struct task_group *tg;
559b1a8c172SDhaval Giani #ifdef CONFIG_SYSFS
560eb41d946SKay Sievers 	struct kobject kobj;
5615cb350baSDhaval Giani 	struct work_struct work;
56224e377a8SSrivatsa Vaddagiri #endif
563b1a8c172SDhaval Giani #endif
5641da177e4SLinus Torvalds };
5651da177e4SLinus Torvalds 
566eb41d946SKay Sievers extern int uids_sysfs_init(void);
5675cb350baSDhaval Giani 
5681da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t);
5691da177e4SLinus Torvalds 
5701da177e4SLinus Torvalds extern struct user_struct root_user;
5711da177e4SLinus Torvalds #define INIT_USER (&root_user)
5721da177e4SLinus Torvalds 
5731da177e4SLinus Torvalds struct backing_dev_info;
5741da177e4SLinus Torvalds struct reclaim_state;
5751da177e4SLinus Torvalds 
57652f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
5771da177e4SLinus Torvalds struct sched_info {
5781da177e4SLinus Torvalds 	/* cumulative counters */
5792d72376bSIngo Molnar 	unsigned long pcount;	      /* # of times run on this cpu */
580172ba844SBalbir Singh 	unsigned long long cpu_time,  /* time spent on the cpu */
581172ba844SBalbir Singh 			   run_delay; /* time spent waiting on a runqueue */
5821da177e4SLinus Torvalds 
5831da177e4SLinus Torvalds 	/* timestamps */
584172ba844SBalbir Singh 	unsigned long long last_arrival,/* when we last ran on a cpu */
5851da177e4SLinus Torvalds 			   last_queued;	/* when we were last queued to run */
586b8efb561SIngo Molnar #ifdef CONFIG_SCHEDSTATS
587b8efb561SIngo Molnar 	/* BKL stats */
588480b9434SKen Chen 	unsigned int bkl_count;
589b8efb561SIngo Molnar #endif
5901da177e4SLinus Torvalds };
59152f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
5921da177e4SLinus Torvalds 
59352f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS
59415ad7cdcSHelge Deller extern const struct file_operations proc_schedstat_operations;
59552f17b6cSChandra Seetharaman #endif /* CONFIG_SCHEDSTATS */
5961da177e4SLinus Torvalds 
597ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT
598ca74e92bSShailabh Nagar struct task_delay_info {
599ca74e92bSShailabh Nagar 	spinlock_t	lock;
600ca74e92bSShailabh Nagar 	unsigned int	flags;	/* Private per-task flags */
601ca74e92bSShailabh Nagar 
602ca74e92bSShailabh Nagar 	/* For each stat XXX, add following, aligned appropriately
603ca74e92bSShailabh Nagar 	 *
604ca74e92bSShailabh Nagar 	 * struct timespec XXX_start, XXX_end;
605ca74e92bSShailabh Nagar 	 * u64 XXX_delay;
606ca74e92bSShailabh Nagar 	 * u32 XXX_count;
607ca74e92bSShailabh Nagar 	 *
608ca74e92bSShailabh Nagar 	 * Atomicity of updates to XXX_delay, XXX_count protected by
609ca74e92bSShailabh Nagar 	 * single lock above (split into XXX_lock if contention is an issue).
610ca74e92bSShailabh Nagar 	 */
6110ff92245SShailabh Nagar 
6120ff92245SShailabh Nagar 	/*
6130ff92245SShailabh Nagar 	 * XXX_count is incremented on every XXX operation, the delay
6140ff92245SShailabh Nagar 	 * associated with the operation is added to XXX_delay.
6150ff92245SShailabh Nagar 	 * XXX_delay contains the accumulated delay time in nanoseconds.
6160ff92245SShailabh Nagar 	 */
6170ff92245SShailabh Nagar 	struct timespec blkio_start, blkio_end;	/* Shared by blkio, swapin */
6180ff92245SShailabh Nagar 	u64 blkio_delay;	/* wait for sync block io completion */
6190ff92245SShailabh Nagar 	u64 swapin_delay;	/* wait for swapin block io completion */
6200ff92245SShailabh Nagar 	u32 blkio_count;	/* total count of the number of sync block */
6210ff92245SShailabh Nagar 				/* io operations performed */
6220ff92245SShailabh Nagar 	u32 swapin_count;	/* total count of the number of swapin block */
6230ff92245SShailabh Nagar 				/* io operations performed */
624ca74e92bSShailabh Nagar };
62552f17b6cSChandra Seetharaman #endif	/* CONFIG_TASK_DELAY_ACCT */
62652f17b6cSChandra Seetharaman 
62752f17b6cSChandra Seetharaman static inline int sched_info_on(void)
62852f17b6cSChandra Seetharaman {
62952f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS
63052f17b6cSChandra Seetharaman 	return 1;
63152f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT)
63252f17b6cSChandra Seetharaman 	extern int delayacct_on;
63352f17b6cSChandra Seetharaman 	return delayacct_on;
63452f17b6cSChandra Seetharaman #else
63552f17b6cSChandra Seetharaman 	return 0;
636ca74e92bSShailabh Nagar #endif
63752f17b6cSChandra Seetharaman }
638ca74e92bSShailabh Nagar 
639d15bcfdbSIngo Molnar enum cpu_idle_type {
640d15bcfdbSIngo Molnar 	CPU_IDLE,
641d15bcfdbSIngo Molnar 	CPU_NOT_IDLE,
642d15bcfdbSIngo Molnar 	CPU_NEWLY_IDLE,
643d15bcfdbSIngo Molnar 	CPU_MAX_IDLE_TYPES
6441da177e4SLinus Torvalds };
6451da177e4SLinus Torvalds 
6461da177e4SLinus Torvalds /*
6471da177e4SLinus Torvalds  * sched-domains (multiprocessor balancing) declarations:
6481da177e4SLinus Torvalds  */
6499aa7b369SIngo Molnar 
6509aa7b369SIngo Molnar /*
6519aa7b369SIngo Molnar  * Increase resolution of nice-level calculations:
6529aa7b369SIngo Molnar  */
6539aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT	10
6549aa7b369SIngo Molnar #define SCHED_LOAD_SCALE	(1L << SCHED_LOAD_SHIFT)
6559aa7b369SIngo Molnar 
656f8700df7SSuresh Siddha #define SCHED_LOAD_SCALE_FUZZ	SCHED_LOAD_SCALE
6571da177e4SLinus Torvalds 
6582dd73a4fSPeter Williams #ifdef CONFIG_SMP
6591da177e4SLinus Torvalds #define SD_LOAD_BALANCE		1	/* Do load balancing on this domain. */
6601da177e4SLinus Torvalds #define SD_BALANCE_NEWIDLE	2	/* Balance when about to become idle */
6611da177e4SLinus Torvalds #define SD_BALANCE_EXEC		4	/* Balance on exec */
662147cbb4bSNick Piggin #define SD_BALANCE_FORK		8	/* Balance on fork, clone */
663147cbb4bSNick Piggin #define SD_WAKE_IDLE		16	/* Wake to idle CPU on task wakeup */
664147cbb4bSNick Piggin #define SD_WAKE_AFFINE		32	/* Wake task to waking CPU */
665147cbb4bSNick Piggin #define SD_WAKE_BALANCE		64	/* Perform balancing at task wakeup */
666147cbb4bSNick Piggin #define SD_SHARE_CPUPOWER	128	/* Domain members share cpu power */
6675c45bf27SSiddha, Suresh B #define SD_POWERSAVINGS_BALANCE	256	/* Balance for power savings */
66889c4710eSSiddha, Suresh B #define SD_SHARE_PKG_RESOURCES	512	/* Domain members share cpu pkg resources */
66908c183f3SChristoph Lameter #define SD_SERIALIZE		1024	/* Only a single load balancing instance */
6705c45bf27SSiddha, Suresh B 
67189c4710eSSiddha, Suresh B #define BALANCE_FOR_MC_POWER	\
67289c4710eSSiddha, Suresh B 	(sched_smt_power_savings ? SD_POWERSAVINGS_BALANCE : 0)
67389c4710eSSiddha, Suresh B 
67489c4710eSSiddha, Suresh B #define BALANCE_FOR_PKG_POWER	\
67589c4710eSSiddha, Suresh B 	((sched_mc_power_savings || sched_smt_power_savings) ?	\
67689c4710eSSiddha, Suresh B 	 SD_POWERSAVINGS_BALANCE : 0)
67789c4710eSSiddha, Suresh B 
67889c4710eSSiddha, Suresh B #define test_sd_parent(sd, flag)	((sd->parent &&		\
67989c4710eSSiddha, Suresh B 					 (sd->parent->flags & flag)) ? 1 : 0)
6805c45bf27SSiddha, Suresh B 
6811da177e4SLinus Torvalds 
6821da177e4SLinus Torvalds struct sched_group {
6831da177e4SLinus Torvalds 	struct sched_group *next;	/* Must be a circular list */
6841da177e4SLinus Torvalds 	cpumask_t cpumask;
6851da177e4SLinus Torvalds 
6861da177e4SLinus Torvalds 	/*
6871da177e4SLinus Torvalds 	 * CPU power of this group, SCHED_LOAD_SCALE being max power for a
6881da177e4SLinus Torvalds 	 * single CPU. This is read only (except for setup, hotplug CPU).
6895517d86bSEric Dumazet 	 * Note : Never change cpu_power without recompute its reciprocal
6901da177e4SLinus Torvalds 	 */
6915517d86bSEric Dumazet 	unsigned int __cpu_power;
6925517d86bSEric Dumazet 	/*
6935517d86bSEric Dumazet 	 * reciprocal value of cpu_power to avoid expensive divides
6945517d86bSEric Dumazet 	 * (see include/linux/reciprocal_div.h)
6955517d86bSEric Dumazet 	 */
6965517d86bSEric Dumazet 	u32 reciprocal_cpu_power;
6971da177e4SLinus Torvalds };
6981da177e4SLinus Torvalds 
6991da177e4SLinus Torvalds struct sched_domain {
7001da177e4SLinus Torvalds 	/* These fields must be setup */
7011da177e4SLinus Torvalds 	struct sched_domain *parent;	/* top domain must be null terminated */
7021a848870SSiddha, Suresh B 	struct sched_domain *child;	/* bottom domain must be null terminated */
7031da177e4SLinus Torvalds 	struct sched_group *groups;	/* the balancing groups of the domain */
7041da177e4SLinus Torvalds 	cpumask_t span;			/* span of all CPUs in this domain */
7051da177e4SLinus Torvalds 	unsigned long min_interval;	/* Minimum balance interval ms */
7061da177e4SLinus Torvalds 	unsigned long max_interval;	/* Maximum balance interval ms */
7071da177e4SLinus Torvalds 	unsigned int busy_factor;	/* less balancing by factor if busy */
7081da177e4SLinus Torvalds 	unsigned int imbalance_pct;	/* No balance until over watermark */
7091da177e4SLinus Torvalds 	unsigned int cache_nice_tries;	/* Leave cache hot tasks for # tries */
7107897986bSNick Piggin 	unsigned int busy_idx;
7117897986bSNick Piggin 	unsigned int idle_idx;
7127897986bSNick Piggin 	unsigned int newidle_idx;
7137897986bSNick Piggin 	unsigned int wake_idx;
714147cbb4bSNick Piggin 	unsigned int forkexec_idx;
7151da177e4SLinus Torvalds 	int flags;			/* See SD_* */
7161da177e4SLinus Torvalds 
7171da177e4SLinus Torvalds 	/* Runtime fields. */
7181da177e4SLinus Torvalds 	unsigned long last_balance;	/* init to jiffies. units in jiffies */
7191da177e4SLinus Torvalds 	unsigned int balance_interval;	/* initialise to 1. units in ms. */
7201da177e4SLinus Torvalds 	unsigned int nr_balance_failed; /* initialise to 0 */
7211da177e4SLinus Torvalds 
7221da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS
7231da177e4SLinus Torvalds 	/* load_balance() stats */
724480b9434SKen Chen 	unsigned int lb_count[CPU_MAX_IDLE_TYPES];
725480b9434SKen Chen 	unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
726480b9434SKen Chen 	unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
727480b9434SKen Chen 	unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
728480b9434SKen Chen 	unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
729480b9434SKen Chen 	unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
730480b9434SKen Chen 	unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
731480b9434SKen Chen 	unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
7321da177e4SLinus Torvalds 
7331da177e4SLinus Torvalds 	/* Active load balancing */
734480b9434SKen Chen 	unsigned int alb_count;
735480b9434SKen Chen 	unsigned int alb_failed;
736480b9434SKen Chen 	unsigned int alb_pushed;
7371da177e4SLinus Torvalds 
73868767a0aSNick Piggin 	/* SD_BALANCE_EXEC stats */
739480b9434SKen Chen 	unsigned int sbe_count;
740480b9434SKen Chen 	unsigned int sbe_balanced;
741480b9434SKen Chen 	unsigned int sbe_pushed;
7421da177e4SLinus Torvalds 
74368767a0aSNick Piggin 	/* SD_BALANCE_FORK stats */
744480b9434SKen Chen 	unsigned int sbf_count;
745480b9434SKen Chen 	unsigned int sbf_balanced;
746480b9434SKen Chen 	unsigned int sbf_pushed;
74768767a0aSNick Piggin 
7481da177e4SLinus Torvalds 	/* try_to_wake_up() stats */
749480b9434SKen Chen 	unsigned int ttwu_wake_remote;
750480b9434SKen Chen 	unsigned int ttwu_move_affine;
751480b9434SKen Chen 	unsigned int ttwu_move_balance;
7521da177e4SLinus Torvalds #endif
7531da177e4SLinus Torvalds };
7541da177e4SLinus Torvalds 
755029190c5SPaul Jackson extern void partition_sched_domains(int ndoms_new, cpumask_t *doms_new);
756029190c5SPaul Jackson 
7571da177e4SLinus Torvalds #endif	/* CONFIG_SMP */
7581da177e4SLinus Torvalds 
759d02c7a8cSCon Kolivas /*
760d02c7a8cSCon Kolivas  * A runqueue laden with a single nice 0 task scores a weighted_cpuload of
761d02c7a8cSCon Kolivas  * SCHED_LOAD_SCALE. This function returns 1 if any cpu is laden with a
762d02c7a8cSCon Kolivas  * task of nice 0 or enough lower priority tasks to bring up the
763d02c7a8cSCon Kolivas  * weighted_cpuload
764d02c7a8cSCon Kolivas  */
765d02c7a8cSCon Kolivas static inline int above_background_load(void)
766d02c7a8cSCon Kolivas {
767d02c7a8cSCon Kolivas 	unsigned long cpu;
768d02c7a8cSCon Kolivas 
769d02c7a8cSCon Kolivas 	for_each_online_cpu(cpu) {
770d02c7a8cSCon Kolivas 		if (weighted_cpuload(cpu) >= SCHED_LOAD_SCALE)
771d02c7a8cSCon Kolivas 			return 1;
772d02c7a8cSCon Kolivas 	}
773d02c7a8cSCon Kolivas 	return 0;
774d02c7a8cSCon Kolivas }
7751da177e4SLinus Torvalds 
7761da177e4SLinus Torvalds struct io_context;			/* See blkdev.h */
7771da177e4SLinus Torvalds #define NGROUPS_SMALL		32
7781da177e4SLinus Torvalds #define NGROUPS_PER_BLOCK	((int)(PAGE_SIZE / sizeof(gid_t)))
7791da177e4SLinus Torvalds struct group_info {
7801da177e4SLinus Torvalds 	int ngroups;
7811da177e4SLinus Torvalds 	atomic_t usage;
7821da177e4SLinus Torvalds 	gid_t small_block[NGROUPS_SMALL];
7831da177e4SLinus Torvalds 	int nblocks;
7841da177e4SLinus Torvalds 	gid_t *blocks[0];
7851da177e4SLinus Torvalds };
7861da177e4SLinus Torvalds 
7871da177e4SLinus Torvalds /*
7881da177e4SLinus Torvalds  * get_group_info() must be called with the owning task locked (via task_lock())
7891da177e4SLinus Torvalds  * when task != current.  The reason being that the vast majority of callers are
7901da177e4SLinus Torvalds  * looking at current->group_info, which can not be changed except by the
7911da177e4SLinus Torvalds  * current task.  Changing current->group_info requires the task lock, too.
7921da177e4SLinus Torvalds  */
7931da177e4SLinus Torvalds #define get_group_info(group_info) do { \
7941da177e4SLinus Torvalds 	atomic_inc(&(group_info)->usage); \
7951da177e4SLinus Torvalds } while (0)
7961da177e4SLinus Torvalds 
7971da177e4SLinus Torvalds #define put_group_info(group_info) do { \
7981da177e4SLinus Torvalds 	if (atomic_dec_and_test(&(group_info)->usage)) \
7991da177e4SLinus Torvalds 		groups_free(group_info); \
8001da177e4SLinus Torvalds } while (0)
8011da177e4SLinus Torvalds 
8023e30148cSDavid Howells extern struct group_info *groups_alloc(int gidsetsize);
8033e30148cSDavid Howells extern void groups_free(struct group_info *group_info);
8043e30148cSDavid Howells extern int set_current_groups(struct group_info *group_info);
8053e30148cSDavid Howells extern int groups_search(struct group_info *group_info, gid_t grp);
8061da177e4SLinus Torvalds /* access the groups "array" with this macro */
8071da177e4SLinus Torvalds #define GROUP_AT(gi, i) \
8081da177e4SLinus Torvalds     ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK])
8091da177e4SLinus Torvalds 
810383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
81136c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t);
812383f2835SChen, Kenneth W #else
813383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { }
814383f2835SChen, Kenneth W #endif
8151da177e4SLinus Torvalds 
8161da177e4SLinus Torvalds struct audit_context;		/* See audit.c */
8171da177e4SLinus Torvalds struct mempolicy;
818b92ce558SJens Axboe struct pipe_inode_info;
8194865ecf1SSerge E. Hallyn struct uts_namespace;
8201da177e4SLinus Torvalds 
82120b8a59fSIngo Molnar struct rq;
82220b8a59fSIngo Molnar struct sched_domain;
82320b8a59fSIngo Molnar 
82420b8a59fSIngo Molnar struct sched_class {
8255522d5d5SIngo Molnar 	const struct sched_class *next;
82620b8a59fSIngo Molnar 
827fd390f6aSIngo Molnar 	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup);
828f02231e5SIngo Molnar 	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep);
8294530d7abSDmitry Adamushko 	void (*yield_task) (struct rq *rq);
830e7693a36SGregory Haskins 	int  (*select_task_rq)(struct task_struct *p, int sync);
83120b8a59fSIngo Molnar 
83220b8a59fSIngo Molnar 	void (*check_preempt_curr) (struct rq *rq, struct task_struct *p);
83320b8a59fSIngo Molnar 
834fb8d4724SIngo Molnar 	struct task_struct * (*pick_next_task) (struct rq *rq);
83531ee529cSIngo Molnar 	void (*put_prev_task) (struct rq *rq, struct task_struct *p);
83620b8a59fSIngo Molnar 
837681f3e68SPeter Williams #ifdef CONFIG_SMP
83843010659SPeter Williams 	unsigned long (*load_balance) (struct rq *this_rq, int this_cpu,
839e1d1484fSPeter Williams 			struct rq *busiest, unsigned long max_load_move,
84020b8a59fSIngo Molnar 			struct sched_domain *sd, enum cpu_idle_type idle,
841a4ac01c3SPeter Williams 			int *all_pinned, int *this_best_prio);
84220b8a59fSIngo Molnar 
843e1d1484fSPeter Williams 	int (*move_one_task) (struct rq *this_rq, int this_cpu,
844e1d1484fSPeter Williams 			      struct rq *busiest, struct sched_domain *sd,
845e1d1484fSPeter Williams 			      enum cpu_idle_type idle);
8469a897c5aSSteven Rostedt 	void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
8479a897c5aSSteven Rostedt 	void (*post_schedule) (struct rq *this_rq);
8489a897c5aSSteven Rostedt 	void (*task_wake_up) (struct rq *this_rq, struct task_struct *task);
849681f3e68SPeter Williams #endif
850e1d1484fSPeter Williams 
85183b699edSSrivatsa Vaddagiri 	void (*set_curr_task) (struct rq *rq);
85220b8a59fSIngo Molnar 	void (*task_tick) (struct rq *rq, struct task_struct *p);
853ee0827d8SIngo Molnar 	void (*task_new) (struct rq *rq, struct task_struct *p);
85473fe6aaeSGregory Haskins 	void (*set_cpus_allowed)(struct task_struct *p, cpumask_t *newmask);
85557d885feSGregory Haskins 
85657d885feSGregory Haskins 	void (*join_domain)(struct rq *rq);
85757d885feSGregory Haskins 	void (*leave_domain)(struct rq *rq);
858cb469845SSteven Rostedt 
859cb469845SSteven Rostedt 	void (*switched_from) (struct rq *this_rq, struct task_struct *task,
860cb469845SSteven Rostedt 			       int running);
861cb469845SSteven Rostedt 	void (*switched_to) (struct rq *this_rq, struct task_struct *task,
862cb469845SSteven Rostedt 			     int running);
863cb469845SSteven Rostedt 	void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
864cb469845SSteven Rostedt 			     int oldprio, int running);
86520b8a59fSIngo Molnar };
86620b8a59fSIngo Molnar 
86720b8a59fSIngo Molnar struct load_weight {
86820b8a59fSIngo Molnar 	unsigned long weight, inv_weight;
86920b8a59fSIngo Molnar };
87020b8a59fSIngo Molnar 
87120b8a59fSIngo Molnar /*
87220b8a59fSIngo Molnar  * CFS stats for a schedulable entity (task, task-group etc)
87320b8a59fSIngo Molnar  *
87420b8a59fSIngo Molnar  * Current field usage histogram:
87520b8a59fSIngo Molnar  *
87620b8a59fSIngo Molnar  *     4 se->block_start
87720b8a59fSIngo Molnar  *     4 se->run_node
87820b8a59fSIngo Molnar  *     4 se->sleep_start
87920b8a59fSIngo Molnar  *     6 se->load.weight
88020b8a59fSIngo Molnar  */
88120b8a59fSIngo Molnar struct sched_entity {
88220b8a59fSIngo Molnar 	struct load_weight	load;		/* for load-balancing */
88320b8a59fSIngo Molnar 	struct rb_node		run_node;
88420b8a59fSIngo Molnar 	unsigned int		on_rq;
88520b8a59fSIngo Molnar 
88620b8a59fSIngo Molnar 	u64			exec_start;
88794c18227SIngo Molnar 	u64			sum_exec_runtime;
888e9acbff6SIngo Molnar 	u64			vruntime;
889f6cf891cSIngo Molnar 	u64			prev_sum_exec_runtime;
89094c18227SIngo Molnar 
89194c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS
89294c18227SIngo Molnar 	u64			wait_start;
89394c18227SIngo Molnar 	u64			wait_max;
89494c18227SIngo Molnar 
89594c18227SIngo Molnar 	u64			sleep_start;
89620b8a59fSIngo Molnar 	u64			sleep_max;
89794c18227SIngo Molnar 	s64			sum_sleep_runtime;
89894c18227SIngo Molnar 
89994c18227SIngo Molnar 	u64			block_start;
90020b8a59fSIngo Molnar 	u64			block_max;
90120b8a59fSIngo Molnar 	u64			exec_max;
902eba1ed4bSIngo Molnar 	u64			slice_max;
903cc367732SIngo Molnar 
904cc367732SIngo Molnar 	u64			nr_migrations;
905cc367732SIngo Molnar 	u64			nr_migrations_cold;
906cc367732SIngo Molnar 	u64			nr_failed_migrations_affine;
907cc367732SIngo Molnar 	u64			nr_failed_migrations_running;
908cc367732SIngo Molnar 	u64			nr_failed_migrations_hot;
909cc367732SIngo Molnar 	u64			nr_forced_migrations;
910cc367732SIngo Molnar 	u64			nr_forced2_migrations;
911cc367732SIngo Molnar 
912cc367732SIngo Molnar 	u64			nr_wakeups;
913cc367732SIngo Molnar 	u64			nr_wakeups_sync;
914cc367732SIngo Molnar 	u64			nr_wakeups_migrate;
915cc367732SIngo Molnar 	u64			nr_wakeups_local;
916cc367732SIngo Molnar 	u64			nr_wakeups_remote;
917cc367732SIngo Molnar 	u64			nr_wakeups_affine;
918cc367732SIngo Molnar 	u64			nr_wakeups_affine_attempts;
919cc367732SIngo Molnar 	u64			nr_wakeups_passive;
920cc367732SIngo Molnar 	u64			nr_wakeups_idle;
92194c18227SIngo Molnar #endif
92294c18227SIngo Molnar 
92320b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED
92420b8a59fSIngo Molnar 	struct sched_entity	*parent;
92520b8a59fSIngo Molnar 	/* rq on which this entity is (to be) queued: */
92620b8a59fSIngo Molnar 	struct cfs_rq		*cfs_rq;
92720b8a59fSIngo Molnar 	/* rq "owned" by this entity/group: */
92820b8a59fSIngo Molnar 	struct cfs_rq		*my_q;
92920b8a59fSIngo Molnar #endif
93020b8a59fSIngo Molnar };
93170b97a7fSIngo Molnar 
932fa717060SPeter Zijlstra struct sched_rt_entity {
933fa717060SPeter Zijlstra 	struct list_head run_list;
934fa717060SPeter Zijlstra 	unsigned int time_slice;
935*78f2c7dbSPeter Zijlstra 	unsigned long timeout;
936fa717060SPeter Zijlstra };
937fa717060SPeter Zijlstra 
9381da177e4SLinus Torvalds struct task_struct {
9391da177e4SLinus Torvalds 	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
940f7e4217bSRoman Zippel 	void *stack;
9411da177e4SLinus Torvalds 	atomic_t usage;
94297dc32cdSWilliam Cohen 	unsigned int flags;	/* per process flags, defined below */
94397dc32cdSWilliam Cohen 	unsigned int ptrace;
9441da177e4SLinus Torvalds 
94536772092SPaolo 'Blaisorblade' Giarrusso 	int lock_depth;		/* BKL lock depth */
9461da177e4SLinus Torvalds 
9472dd73a4fSPeter Williams #ifdef CONFIG_SMP
9482dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW
9494866cde0SNick Piggin 	int oncpu;
9504866cde0SNick Piggin #endif
9512dd73a4fSPeter Williams #endif
95250e645a8SIngo Molnar 
953b29739f9SIngo Molnar 	int prio, static_prio, normal_prio;
9545522d5d5SIngo Molnar 	const struct sched_class *sched_class;
95520b8a59fSIngo Molnar 	struct sched_entity se;
956fa717060SPeter Zijlstra 	struct sched_rt_entity rt;
9571da177e4SLinus Torvalds 
958e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS
959e107be36SAvi Kivity 	/* list of struct preempt_notifier: */
960e107be36SAvi Kivity 	struct hlist_head preempt_notifiers;
961e107be36SAvi Kivity #endif
962e107be36SAvi Kivity 
96322e2c507SJens Axboe 	unsigned short ioprio;
96418796aa0SAlexey Dobriyan 	/*
96518796aa0SAlexey Dobriyan 	 * fpu_counter contains the number of consecutive context switches
96618796aa0SAlexey Dobriyan 	 * that the FPU is used. If this is over a threshold, the lazy fpu
96718796aa0SAlexey Dobriyan 	 * saving becomes unlazy to save the trap. This is an unsigned char
96818796aa0SAlexey Dobriyan 	 * so that after 256 times the counter wraps and the behavior turns
96918796aa0SAlexey Dobriyan 	 * lazy again; this to deal with bursty apps that only use FPU for
97018796aa0SAlexey Dobriyan 	 * a short time
97118796aa0SAlexey Dobriyan 	 */
97218796aa0SAlexey Dobriyan 	unsigned char fpu_counter;
97318796aa0SAlexey Dobriyan 	s8 oomkilladj; /* OOM kill score adjustment (bit shift). */
9746c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE
9752056a782SJens Axboe 	unsigned int btrace_seq;
9766c5c9341SAlexey Dobriyan #endif
9771da177e4SLinus Torvalds 
97897dc32cdSWilliam Cohen 	unsigned int policy;
9791da177e4SLinus Torvalds 	cpumask_t cpus_allowed;
98073fe6aaeSGregory Haskins 	int nr_cpus_allowed;
9811da177e4SLinus Torvalds 
982e260be67SPaul E. McKenney #ifdef CONFIG_PREEMPT_RCU
983e260be67SPaul E. McKenney 	int rcu_read_lock_nesting;
984e260be67SPaul E. McKenney 	int rcu_flipctr_idx;
985e260be67SPaul E. McKenney #endif /* #ifdef CONFIG_PREEMPT_RCU */
986e260be67SPaul E. McKenney 
98752f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
9881da177e4SLinus Torvalds 	struct sched_info sched_info;
9891da177e4SLinus Torvalds #endif
9901da177e4SLinus Torvalds 
9911da177e4SLinus Torvalds 	struct list_head tasks;
9921da177e4SLinus Torvalds 	/*
9931da177e4SLinus Torvalds 	 * ptrace_list/ptrace_children forms the list of my children
9941da177e4SLinus Torvalds 	 * that were stolen by a ptracer.
9951da177e4SLinus Torvalds 	 */
9961da177e4SLinus Torvalds 	struct list_head ptrace_children;
9971da177e4SLinus Torvalds 	struct list_head ptrace_list;
9981da177e4SLinus Torvalds 
9991da177e4SLinus Torvalds 	struct mm_struct *mm, *active_mm;
10001da177e4SLinus Torvalds 
10011da177e4SLinus Torvalds /* task state */
10021da177e4SLinus Torvalds 	struct linux_binfmt *binfmt;
100397dc32cdSWilliam Cohen 	int exit_state;
10041da177e4SLinus Torvalds 	int exit_code, exit_signal;
10051da177e4SLinus Torvalds 	int pdeath_signal;  /*  The signal sent when the parent dies  */
10061da177e4SLinus Torvalds 	/* ??? */
100797dc32cdSWilliam Cohen 	unsigned int personality;
10081da177e4SLinus Torvalds 	unsigned did_exec:1;
10091da177e4SLinus Torvalds 	pid_t pid;
10101da177e4SLinus Torvalds 	pid_t tgid;
10110a425405SArjan van de Ven 
10120a425405SArjan van de Ven #ifdef CONFIG_CC_STACKPROTECTOR
10130a425405SArjan van de Ven 	/* Canary value for the -fstack-protector gcc feature */
10140a425405SArjan van de Ven 	unsigned long stack_canary;
10150a425405SArjan van de Ven #endif
10161da177e4SLinus Torvalds 	/*
10171da177e4SLinus Torvalds 	 * pointers to (original) parent process, youngest child, younger sibling,
10181da177e4SLinus Torvalds 	 * older sibling, respectively.  (p->father can be replaced with
10191da177e4SLinus Torvalds 	 * p->parent->pid)
10201da177e4SLinus Torvalds 	 */
10211da177e4SLinus Torvalds 	struct task_struct *real_parent; /* real parent process (when being debugged) */
10221da177e4SLinus Torvalds 	struct task_struct *parent;	/* parent process */
10231da177e4SLinus Torvalds 	/*
10241da177e4SLinus Torvalds 	 * children/sibling forms the list of my children plus the
10251da177e4SLinus Torvalds 	 * tasks I'm ptracing.
10261da177e4SLinus Torvalds 	 */
10271da177e4SLinus Torvalds 	struct list_head children;	/* list of my children */
10281da177e4SLinus Torvalds 	struct list_head sibling;	/* linkage in my parent's children list */
10291da177e4SLinus Torvalds 	struct task_struct *group_leader;	/* threadgroup leader */
10301da177e4SLinus Torvalds 
10311da177e4SLinus Torvalds 	/* PID/PID hash table linkage. */
103292476d7fSEric W. Biederman 	struct pid_link pids[PIDTYPE_MAX];
103347e65328SOleg Nesterov 	struct list_head thread_group;
10341da177e4SLinus Torvalds 
10351da177e4SLinus Torvalds 	struct completion *vfork_done;		/* for vfork() */
10361da177e4SLinus Torvalds 	int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
10371da177e4SLinus Torvalds 	int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */
10381da177e4SLinus Torvalds 
103997dc32cdSWilliam Cohen 	unsigned int rt_priority;
1040c66f08beSMichael Neuling 	cputime_t utime, stime, utimescaled, stimescaled;
10419ac52315SLaurent Vivier 	cputime_t gtime;
10429301899bSBalbir Singh 	cputime_t prev_utime, prev_stime;
10431da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw; /* context switch counts */
1044924b42d5STomas Janousek 	struct timespec start_time; 		/* monotonic time */
1045924b42d5STomas Janousek 	struct timespec real_start_time;	/* boot based time */
10461da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
10471da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt;
10481da177e4SLinus Torvalds 
10491da177e4SLinus Torvalds   	cputime_t it_prof_expires, it_virt_expires;
10501da177e4SLinus Torvalds 	unsigned long long it_sched_expires;
10511da177e4SLinus Torvalds 	struct list_head cpu_timers[3];
10521da177e4SLinus Torvalds 
10531da177e4SLinus Torvalds /* process credentials */
10541da177e4SLinus Torvalds 	uid_t uid,euid,suid,fsuid;
10551da177e4SLinus Torvalds 	gid_t gid,egid,sgid,fsgid;
10561da177e4SLinus Torvalds 	struct group_info *group_info;
10571da177e4SLinus Torvalds 	kernel_cap_t   cap_effective, cap_inheritable, cap_permitted;
10581da177e4SLinus Torvalds 	unsigned keep_capabilities:1;
10591da177e4SLinus Torvalds 	struct user_struct *user;
10601da177e4SLinus Torvalds #ifdef CONFIG_KEYS
1061b5f545c8SDavid Howells 	struct key *request_key_auth;	/* assumed request_key authority */
10621da177e4SLinus Torvalds 	struct key *thread_keyring;	/* keyring private to this thread */
10633e30148cSDavid Howells 	unsigned char jit_keyring;	/* default keyring to attach requested keys to */
10641da177e4SLinus Torvalds #endif
106536772092SPaolo 'Blaisorblade' Giarrusso 	char comm[TASK_COMM_LEN]; /* executable name excluding path
106636772092SPaolo 'Blaisorblade' Giarrusso 				     - access with [gs]et_task_comm (which lock
106736772092SPaolo 'Blaisorblade' Giarrusso 				       it with task_lock())
106836772092SPaolo 'Blaisorblade' Giarrusso 				     - initialized normally by flush_old_exec */
10691da177e4SLinus Torvalds /* file system info */
10701da177e4SLinus Torvalds 	int link_count, total_link_count;
10713d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC
10721da177e4SLinus Torvalds /* ipc stuff */
10731da177e4SLinus Torvalds 	struct sysv_sem sysvsem;
10743d5b6fccSAlexey Dobriyan #endif
107582a1fcb9SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP
107682a1fcb9SIngo Molnar /* hung task detection */
107782a1fcb9SIngo Molnar 	unsigned long last_switch_timestamp;
107882a1fcb9SIngo Molnar 	unsigned long last_switch_count;
107982a1fcb9SIngo Molnar #endif
10801da177e4SLinus Torvalds /* CPU-specific state of this task */
10811da177e4SLinus Torvalds 	struct thread_struct thread;
10821da177e4SLinus Torvalds /* filesystem information */
10831da177e4SLinus Torvalds 	struct fs_struct *fs;
10841da177e4SLinus Torvalds /* open file information */
10851da177e4SLinus Torvalds 	struct files_struct *files;
10861651e14eSSerge E. Hallyn /* namespaces */
1087ab516013SSerge E. Hallyn 	struct nsproxy *nsproxy;
10881da177e4SLinus Torvalds /* signal handlers */
10891da177e4SLinus Torvalds 	struct signal_struct *signal;
10901da177e4SLinus Torvalds 	struct sighand_struct *sighand;
10911da177e4SLinus Torvalds 
10921da177e4SLinus Torvalds 	sigset_t blocked, real_blocked;
1093150256d8SDavid Woodhouse 	sigset_t saved_sigmask;		/* To be restored with TIF_RESTORE_SIGMASK */
10941da177e4SLinus Torvalds 	struct sigpending pending;
10951da177e4SLinus Torvalds 
10961da177e4SLinus Torvalds 	unsigned long sas_ss_sp;
10971da177e4SLinus Torvalds 	size_t sas_ss_size;
10981da177e4SLinus Torvalds 	int (*notifier)(void *priv);
10991da177e4SLinus Torvalds 	void *notifier_data;
11001da177e4SLinus Torvalds 	sigset_t *notifier_mask;
110157c521ceSAlexey Dobriyan #ifdef CONFIG_SECURITY
11021da177e4SLinus Torvalds 	void *security;
110357c521ceSAlexey Dobriyan #endif
11041da177e4SLinus Torvalds 	struct audit_context *audit_context;
11051da177e4SLinus Torvalds 	seccomp_t seccomp;
11061da177e4SLinus Torvalds 
11071da177e4SLinus Torvalds /* Thread group tracking */
11081da177e4SLinus Torvalds    	u32 parent_exec_id;
11091da177e4SLinus Torvalds    	u32 self_exec_id;
11101da177e4SLinus Torvalds /* Protection of (de-)allocation: mm, files, fs, tty, keyrings */
11111da177e4SLinus Torvalds 	spinlock_t alloc_lock;
11121da177e4SLinus Torvalds 
1113b29739f9SIngo Molnar 	/* Protection of the PI data structures: */
1114b29739f9SIngo Molnar 	spinlock_t pi_lock;
1115b29739f9SIngo Molnar 
111623f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
111723f78d4aSIngo Molnar 	/* PI waiters blocked on a rt_mutex held by this task */
111823f78d4aSIngo Molnar 	struct plist_head pi_waiters;
111923f78d4aSIngo Molnar 	/* Deadlock detection and priority inheritance handling */
112023f78d4aSIngo Molnar 	struct rt_mutex_waiter *pi_blocked_on;
112123f78d4aSIngo Molnar #endif
112223f78d4aSIngo Molnar 
1123408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES
1124408894eeSIngo Molnar 	/* mutex deadlock detection */
1125408894eeSIngo Molnar 	struct mutex_waiter *blocked_on;
1126408894eeSIngo Molnar #endif
1127de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS
1128de30a2b3SIngo Molnar 	unsigned int irq_events;
1129de30a2b3SIngo Molnar 	int hardirqs_enabled;
1130de30a2b3SIngo Molnar 	unsigned long hardirq_enable_ip;
1131de30a2b3SIngo Molnar 	unsigned int hardirq_enable_event;
1132de30a2b3SIngo Molnar 	unsigned long hardirq_disable_ip;
1133de30a2b3SIngo Molnar 	unsigned int hardirq_disable_event;
1134de30a2b3SIngo Molnar 	int softirqs_enabled;
1135de30a2b3SIngo Molnar 	unsigned long softirq_disable_ip;
1136de30a2b3SIngo Molnar 	unsigned int softirq_disable_event;
1137de30a2b3SIngo Molnar 	unsigned long softirq_enable_ip;
1138de30a2b3SIngo Molnar 	unsigned int softirq_enable_event;
1139de30a2b3SIngo Molnar 	int hardirq_context;
1140de30a2b3SIngo Molnar 	int softirq_context;
1141de30a2b3SIngo Molnar #endif
1142fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP
1143fbb9ce95SIngo Molnar # define MAX_LOCK_DEPTH 30UL
1144fbb9ce95SIngo Molnar 	u64 curr_chain_key;
1145fbb9ce95SIngo Molnar 	int lockdep_depth;
1146fbb9ce95SIngo Molnar 	struct held_lock held_locks[MAX_LOCK_DEPTH];
1147fbb9ce95SIngo Molnar 	unsigned int lockdep_recursion;
1148fbb9ce95SIngo Molnar #endif
1149408894eeSIngo Molnar 
11501da177e4SLinus Torvalds /* journalling filesystem info */
11511da177e4SLinus Torvalds 	void *journal_info;
11521da177e4SLinus Torvalds 
1153d89d8796SNeil Brown /* stacked block device info */
1154d89d8796SNeil Brown 	struct bio *bio_list, **bio_tail;
1155d89d8796SNeil Brown 
11561da177e4SLinus Torvalds /* VM state */
11571da177e4SLinus Torvalds 	struct reclaim_state *reclaim_state;
11581da177e4SLinus Torvalds 
11591da177e4SLinus Torvalds 	struct backing_dev_info *backing_dev_info;
11601da177e4SLinus Torvalds 
11611da177e4SLinus Torvalds 	struct io_context *io_context;
11621da177e4SLinus Torvalds 
11631da177e4SLinus Torvalds 	unsigned long ptrace_message;
11641da177e4SLinus Torvalds 	siginfo_t *last_siginfo; /* For ptrace use.  */
11654b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT
11661da177e4SLinus Torvalds /* i/o counters(bytes read/written, #syscalls */
11671da177e4SLinus Torvalds 	u64 rchar, wchar, syscr, syscw;
11684b98d11bSAlexey Dobriyan #endif
11697c3ab738SAndrew Morton 	struct task_io_accounting ioac;
11708f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT)
11711da177e4SLinus Torvalds 	u64 acct_rss_mem1;	/* accumulated rss usage */
11721da177e4SLinus Torvalds 	u64 acct_vm_mem1;	/* accumulated virtual memory usage */
1173db5fed26SJay Lan 	cputime_t acct_stimexpd;/* stime since last update */
11741da177e4SLinus Torvalds #endif
11751da177e4SLinus Torvalds #ifdef CONFIG_NUMA
11761da177e4SLinus Torvalds   	struct mempolicy *mempolicy;
11771da177e4SLinus Torvalds 	short il_next;
11781da177e4SLinus Torvalds #endif
11791da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS
11801da177e4SLinus Torvalds 	nodemask_t mems_allowed;
11811da177e4SLinus Torvalds 	int cpuset_mems_generation;
1182825a46afSPaul Jackson 	int cpuset_mem_spread_rotor;
11831da177e4SLinus Torvalds #endif
1184ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS
1185817929ecSPaul Menage 	/* Control Group info protected by css_set_lock */
1186817929ecSPaul Menage 	struct css_set *cgroups;
1187817929ecSPaul Menage 	/* cg_list protected by css_set_lock and tsk->alloc_lock */
1188817929ecSPaul Menage 	struct list_head cg_list;
1189ddbcc7e8SPaul Menage #endif
119042b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX
11910771dfefSIngo Molnar 	struct robust_list_head __user *robust_list;
119234f192c6SIngo Molnar #ifdef CONFIG_COMPAT
119334f192c6SIngo Molnar 	struct compat_robust_list_head __user *compat_robust_list;
119434f192c6SIngo Molnar #endif
1195c87e2837SIngo Molnar 	struct list_head pi_state_list;
1196c87e2837SIngo Molnar 	struct futex_pi_state *pi_state_cache;
119742b2dd0aSAlexey Dobriyan #endif
119822e2c507SJens Axboe 	atomic_t fs_excl;	/* holding fs exclusive resources */
1199e56d0903SIngo Molnar 	struct rcu_head rcu;
1200b92ce558SJens Axboe 
1201b92ce558SJens Axboe 	/*
1202b92ce558SJens Axboe 	 * cache last used pipe for splice
1203b92ce558SJens Axboe 	 */
1204b92ce558SJens Axboe 	struct pipe_inode_info *splice_pipe;
1205ca74e92bSShailabh Nagar #ifdef	CONFIG_TASK_DELAY_ACCT
1206ca74e92bSShailabh Nagar 	struct task_delay_info *delays;
1207ca74e92bSShailabh Nagar #endif
1208f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION
1209f4f154fdSAkinobu Mita 	int make_it_fail;
1210f4f154fdSAkinobu Mita #endif
12113e26c149SPeter Zijlstra 	struct prop_local_single dirties;
12121da177e4SLinus Torvalds };
12131da177e4SLinus Torvalds 
1214e05606d3SIngo Molnar /*
1215e05606d3SIngo Molnar  * Priority of a process goes from 0..MAX_PRIO-1, valid RT
1216e05606d3SIngo Molnar  * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
1217e05606d3SIngo Molnar  * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
1218e05606d3SIngo Molnar  * values are inverted: lower p->prio value means higher priority.
1219e05606d3SIngo Molnar  *
1220e05606d3SIngo Molnar  * The MAX_USER_RT_PRIO value allows the actual maximum
1221e05606d3SIngo Molnar  * RT priority to be separate from the value exported to
1222e05606d3SIngo Molnar  * user-space.  This allows kernel threads to set their
1223e05606d3SIngo Molnar  * priority to a value higher than any user task. Note:
1224e05606d3SIngo Molnar  * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
1225e05606d3SIngo Molnar  */
1226e05606d3SIngo Molnar 
1227e05606d3SIngo Molnar #define MAX_USER_RT_PRIO	100
1228e05606d3SIngo Molnar #define MAX_RT_PRIO		MAX_USER_RT_PRIO
1229e05606d3SIngo Molnar 
1230e05606d3SIngo Molnar #define MAX_PRIO		(MAX_RT_PRIO + 40)
1231e05606d3SIngo Molnar #define DEFAULT_PRIO		(MAX_RT_PRIO + 20)
1232e05606d3SIngo Molnar 
1233e05606d3SIngo Molnar static inline int rt_prio(int prio)
1234e05606d3SIngo Molnar {
1235e05606d3SIngo Molnar 	if (unlikely(prio < MAX_RT_PRIO))
1236e05606d3SIngo Molnar 		return 1;
1237e05606d3SIngo Molnar 	return 0;
1238e05606d3SIngo Molnar }
1239e05606d3SIngo Molnar 
1240e868171aSAlexey Dobriyan static inline int rt_task(struct task_struct *p)
1241e05606d3SIngo Molnar {
1242e05606d3SIngo Molnar 	return rt_prio(p->prio);
1243e05606d3SIngo Molnar }
1244e05606d3SIngo Molnar 
1245a47afb0fSPavel Emelianov static inline void set_task_session(struct task_struct *tsk, pid_t session)
1246937949d9SCedric Le Goater {
1247a47afb0fSPavel Emelianov 	tsk->signal->__session = session;
1248937949d9SCedric Le Goater }
1249937949d9SCedric Le Goater 
12509a2e7057SPavel Emelyanov static inline void set_task_pgrp(struct task_struct *tsk, pid_t pgrp)
12519a2e7057SPavel Emelyanov {
12529a2e7057SPavel Emelyanov 	tsk->signal->__pgrp = pgrp;
12539a2e7057SPavel Emelyanov }
12549a2e7057SPavel Emelyanov 
1255e868171aSAlexey Dobriyan static inline struct pid *task_pid(struct task_struct *task)
125622c935f4SEric W. Biederman {
125722c935f4SEric W. Biederman 	return task->pids[PIDTYPE_PID].pid;
125822c935f4SEric W. Biederman }
125922c935f4SEric W. Biederman 
1260e868171aSAlexey Dobriyan static inline struct pid *task_tgid(struct task_struct *task)
126122c935f4SEric W. Biederman {
126222c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PID].pid;
126322c935f4SEric W. Biederman }
126422c935f4SEric W. Biederman 
1265e868171aSAlexey Dobriyan static inline struct pid *task_pgrp(struct task_struct *task)
126622c935f4SEric W. Biederman {
126722c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PGID].pid;
126822c935f4SEric W. Biederman }
126922c935f4SEric W. Biederman 
1270e868171aSAlexey Dobriyan static inline struct pid *task_session(struct task_struct *task)
127122c935f4SEric W. Biederman {
127222c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_SID].pid;
127322c935f4SEric W. Biederman }
127422c935f4SEric W. Biederman 
12757af57294SPavel Emelyanov struct pid_namespace;
12767af57294SPavel Emelyanov 
12777af57294SPavel Emelyanov /*
12787af57294SPavel Emelyanov  * the helpers to get the task's different pids as they are seen
12797af57294SPavel Emelyanov  * from various namespaces
12807af57294SPavel Emelyanov  *
12817af57294SPavel Emelyanov  * task_xid_nr()     : global id, i.e. the id seen from the init namespace;
12827af57294SPavel Emelyanov  * task_xid_vnr()    : virtual id, i.e. the id seen from the namespace the task
12837af57294SPavel Emelyanov  *                     belongs to. this only makes sence when called in the
12847af57294SPavel Emelyanov  *                     context of the task that belongs to the same namespace;
12857af57294SPavel Emelyanov  * task_xid_nr_ns()  : id seen from the ns specified;
12867af57294SPavel Emelyanov  *
12877af57294SPavel Emelyanov  * set_task_vxid()   : assigns a virtual id to a task;
12887af57294SPavel Emelyanov  *
12897af57294SPavel Emelyanov  * see also pid_nr() etc in include/linux/pid.h
12907af57294SPavel Emelyanov  */
12917af57294SPavel Emelyanov 
1292e868171aSAlexey Dobriyan static inline pid_t task_pid_nr(struct task_struct *tsk)
12937af57294SPavel Emelyanov {
12947af57294SPavel Emelyanov 	return tsk->pid;
12957af57294SPavel Emelyanov }
12967af57294SPavel Emelyanov 
12972f2a3a46SPavel Emelyanov pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
12987af57294SPavel Emelyanov 
12997af57294SPavel Emelyanov static inline pid_t task_pid_vnr(struct task_struct *tsk)
13007af57294SPavel Emelyanov {
13017af57294SPavel Emelyanov 	return pid_vnr(task_pid(tsk));
13027af57294SPavel Emelyanov }
13037af57294SPavel Emelyanov 
13047af57294SPavel Emelyanov 
1305e868171aSAlexey Dobriyan static inline pid_t task_tgid_nr(struct task_struct *tsk)
13067af57294SPavel Emelyanov {
13077af57294SPavel Emelyanov 	return tsk->tgid;
13087af57294SPavel Emelyanov }
13097af57294SPavel Emelyanov 
13102f2a3a46SPavel Emelyanov pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
13117af57294SPavel Emelyanov 
13127af57294SPavel Emelyanov static inline pid_t task_tgid_vnr(struct task_struct *tsk)
13137af57294SPavel Emelyanov {
13147af57294SPavel Emelyanov 	return pid_vnr(task_tgid(tsk));
13157af57294SPavel Emelyanov }
13167af57294SPavel Emelyanov 
13177af57294SPavel Emelyanov 
1318e868171aSAlexey Dobriyan static inline pid_t task_pgrp_nr(struct task_struct *tsk)
13197af57294SPavel Emelyanov {
13209a2e7057SPavel Emelyanov 	return tsk->signal->__pgrp;
13217af57294SPavel Emelyanov }
13227af57294SPavel Emelyanov 
13232f2a3a46SPavel Emelyanov pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
13247af57294SPavel Emelyanov 
13257af57294SPavel Emelyanov static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
13267af57294SPavel Emelyanov {
13277af57294SPavel Emelyanov 	return pid_vnr(task_pgrp(tsk));
13287af57294SPavel Emelyanov }
13297af57294SPavel Emelyanov 
13307af57294SPavel Emelyanov 
1331e868171aSAlexey Dobriyan static inline pid_t task_session_nr(struct task_struct *tsk)
13327af57294SPavel Emelyanov {
13337af57294SPavel Emelyanov 	return tsk->signal->__session;
13347af57294SPavel Emelyanov }
13357af57294SPavel Emelyanov 
13362f2a3a46SPavel Emelyanov pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
13377af57294SPavel Emelyanov 
13387af57294SPavel Emelyanov static inline pid_t task_session_vnr(struct task_struct *tsk)
13397af57294SPavel Emelyanov {
13407af57294SPavel Emelyanov 	return pid_vnr(task_session(tsk));
13417af57294SPavel Emelyanov }
13427af57294SPavel Emelyanov 
13437af57294SPavel Emelyanov 
13441da177e4SLinus Torvalds /**
13451da177e4SLinus Torvalds  * pid_alive - check that a task structure is not stale
13461da177e4SLinus Torvalds  * @p: Task structure to be checked.
13471da177e4SLinus Torvalds  *
13481da177e4SLinus Torvalds  * Test if a process is not yet dead (at most zombie state)
13491da177e4SLinus Torvalds  * If pid_alive fails, then pointers within the task structure
13501da177e4SLinus Torvalds  * can be stale and must not be dereferenced.
13511da177e4SLinus Torvalds  */
1352e868171aSAlexey Dobriyan static inline int pid_alive(struct task_struct *p)
13531da177e4SLinus Torvalds {
135492476d7fSEric W. Biederman 	return p->pids[PIDTYPE_PID].pid != NULL;
13551da177e4SLinus Torvalds }
13561da177e4SLinus Torvalds 
1357f400e198SSukadev Bhattiprolu /**
1358b460cbc5SSerge E. Hallyn  * is_global_init - check if a task structure is init
13593260259fSHenne  * @tsk: Task structure to be checked.
13603260259fSHenne  *
13613260259fSHenne  * Check if a task structure is the first user space task the kernel created.
1362f400e198SSukadev Bhattiprolu  */
1363e868171aSAlexey Dobriyan static inline int is_global_init(struct task_struct *tsk)
1364b461cc03SPavel Emelyanov {
1365b461cc03SPavel Emelyanov 	return tsk->pid == 1;
1366b461cc03SPavel Emelyanov }
1367b460cbc5SSerge E. Hallyn 
1368b460cbc5SSerge E. Hallyn /*
1369b460cbc5SSerge E. Hallyn  * is_container_init:
1370b460cbc5SSerge E. Hallyn  * check whether in the task is init in its own pid namespace.
1371b460cbc5SSerge E. Hallyn  */
1372b461cc03SPavel Emelyanov extern int is_container_init(struct task_struct *tsk);
1373f400e198SSukadev Bhattiprolu 
13749ec52099SCedric Le Goater extern struct pid *cad_pid;
13759ec52099SCedric Le Goater 
13761da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk);
13771da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
1378e56d0903SIngo Molnar 
1379158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t);
1380e56d0903SIngo Molnar 
1381e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t)
1382e56d0903SIngo Molnar {
1383e56d0903SIngo Molnar 	if (atomic_dec_and_test(&t->usage))
13848c7904a0SEric W. Biederman 		__put_task_struct(t);
1385e56d0903SIngo Molnar }
13861da177e4SLinus Torvalds 
13871da177e4SLinus Torvalds /*
13881da177e4SLinus Torvalds  * Per process flags
13891da177e4SLinus Torvalds  */
13901da177e4SLinus Torvalds #define PF_ALIGNWARN	0x00000001	/* Print alignment warning msgs */
13911da177e4SLinus Torvalds 					/* Not implemented yet, only for 486*/
13921da177e4SLinus Torvalds #define PF_STARTING	0x00000002	/* being created */
13931da177e4SLinus Torvalds #define PF_EXITING	0x00000004	/* getting shut down */
1394778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
139594886b84SLaurent Vivier #define PF_VCPU		0x00000010	/* I'm a virtual CPU */
13961da177e4SLinus Torvalds #define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
13971da177e4SLinus Torvalds #define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
13981da177e4SLinus Torvalds #define PF_DUMPCORE	0x00000200	/* dumped core */
13991da177e4SLinus Torvalds #define PF_SIGNALED	0x00000400	/* killed by a signal */
14001da177e4SLinus Torvalds #define PF_MEMALLOC	0x00000800	/* Allocating memory */
14011da177e4SLinus Torvalds #define PF_FLUSHER	0x00001000	/* responsible for disk writeback */
14021da177e4SLinus Torvalds #define PF_USED_MATH	0x00002000	/* if unset the fpu must be initialized before use */
14031da177e4SLinus Torvalds #define PF_NOFREEZE	0x00008000	/* this thread should not be frozen */
14041da177e4SLinus Torvalds #define PF_FROZEN	0x00010000	/* frozen for system suspend */
14051da177e4SLinus Torvalds #define PF_FSTRANS	0x00020000	/* inside a filesystem transaction */
14061da177e4SLinus Torvalds #define PF_KSWAPD	0x00040000	/* I am kswapd */
14071da177e4SLinus Torvalds #define PF_SWAPOFF	0x00080000	/* I am in swapoff */
14081da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000	/* Throttle me less: I clean memory */
1409b31dc66aSJens Axboe #define PF_BORROWED_MM	0x00200000	/* I am a kthread doing use_mm */
1410b31dc66aSJens Axboe #define PF_RANDOMIZE	0x00400000	/* randomize virtual address space */
1411b31dc66aSJens Axboe #define PF_SWAPWRITE	0x00800000	/* Allowed to write to swap */
1412b31dc66aSJens Axboe #define PF_SPREAD_PAGE	0x01000000	/* Spread page cache over cpuset */
1413b31dc66aSJens Axboe #define PF_SPREAD_SLAB	0x02000000	/* Spread some slab caches over cpuset */
1414c61afb18SPaul Jackson #define PF_MEMPOLICY	0x10000000	/* Non-default NUMA mempolicy */
141561a87122SThomas Gleixner #define PF_MUTEX_TESTER	0x20000000	/* Thread belongs to the rt mutex tester */
1416ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP	0x40000000	/* Freezer should not count it as freezeable */
14171da177e4SLinus Torvalds 
14181da177e4SLinus Torvalds /*
14191da177e4SLinus Torvalds  * Only the _current_ task can read/write to tsk->flags, but other
14201da177e4SLinus Torvalds  * tasks can access tsk->flags in readonly mode for example
14211da177e4SLinus Torvalds  * with tsk_used_math (like during threaded core dumping).
14221da177e4SLinus Torvalds  * There is however an exception to this rule during ptrace
14231da177e4SLinus Torvalds  * or during fork: the ptracer task is allowed to write to the
14241da177e4SLinus Torvalds  * child->flags of its traced child (same goes for fork, the parent
14251da177e4SLinus Torvalds  * can write to the child->flags), because we're guaranteed the
14261da177e4SLinus Torvalds  * child is not running and in turn not changing child->flags
14271da177e4SLinus Torvalds  * at the same time the parent does it.
14281da177e4SLinus Torvalds  */
14291da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
14301da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
14311da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current)
14321da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current)
14331da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \
14341da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
14351da177e4SLinus Torvalds #define conditional_used_math(condition) \
14361da177e4SLinus Torvalds 	conditional_stopped_child_used_math(condition, current)
14371da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \
14381da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
14391da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
14401da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
14411da177e4SLinus Torvalds #define used_math() tsk_used_math(current)
14421da177e4SLinus Torvalds 
14431da177e4SLinus Torvalds #ifdef CONFIG_SMP
144436c8b586SIngo Molnar extern int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask);
14451da177e4SLinus Torvalds #else
144636c8b586SIngo Molnar static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
14471da177e4SLinus Torvalds {
14484098f991SPaul Jackson 	if (!cpu_isset(0, new_mask))
14491da177e4SLinus Torvalds 		return -EINVAL;
14501da177e4SLinus Torvalds 	return 0;
14511da177e4SLinus Torvalds }
14521da177e4SLinus Torvalds #endif
14531da177e4SLinus Torvalds 
14541da177e4SLinus Torvalds extern unsigned long long sched_clock(void);
1455e436d800SIngo Molnar 
1456e436d800SIngo Molnar /*
1457e436d800SIngo Molnar  * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
1458e436d800SIngo Molnar  * clock constructed from sched_clock():
1459e436d800SIngo Molnar  */
1460e436d800SIngo Molnar extern unsigned long long cpu_clock(int cpu);
1461e436d800SIngo Molnar 
146236c8b586SIngo Molnar extern unsigned long long
146341b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task);
14641da177e4SLinus Torvalds 
14651da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */
14661da177e4SLinus Torvalds #ifdef CONFIG_SMP
14671da177e4SLinus Torvalds extern void sched_exec(void);
14681da177e4SLinus Torvalds #else
14691da177e4SLinus Torvalds #define sched_exec()   {}
14701da177e4SLinus Torvalds #endif
14711da177e4SLinus Torvalds 
14722aa44d05SIngo Molnar extern void sched_clock_idle_sleep_event(void);
14732aa44d05SIngo Molnar extern void sched_clock_idle_wakeup_event(u64 delta_ns);
1474bb29ab26SIngo Molnar 
14751da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU
14761da177e4SLinus Torvalds extern void idle_task_exit(void);
14771da177e4SLinus Torvalds #else
14781da177e4SLinus Torvalds static inline void idle_task_exit(void) {}
14791da177e4SLinus Torvalds #endif
14801da177e4SLinus Torvalds 
14811da177e4SLinus Torvalds extern void sched_idle_next(void);
1482b29739f9SIngo Molnar 
14832bd8e6d4SIngo Molnar #ifdef CONFIG_SCHED_DEBUG
148421805085SPeter Zijlstra extern unsigned int sysctl_sched_latency;
1485b2be5e96SPeter Zijlstra extern unsigned int sysctl_sched_min_granularity;
1486bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity;
1487bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_batch_wakeup_granularity;
1488bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first;
1489bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_features;
1490da84d961SIngo Molnar extern unsigned int sysctl_sched_migration_cost;
1491b82d9fddSPeter Zijlstra extern unsigned int sysctl_sched_nr_migrate;
14926b2d7700SSrivatsa Vaddagiri #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
14936b2d7700SSrivatsa Vaddagiri extern unsigned int sysctl_sched_min_bal_int_shares;
14946b2d7700SSrivatsa Vaddagiri extern unsigned int sysctl_sched_max_bal_int_shares;
14956b2d7700SSrivatsa Vaddagiri #endif
1496b2be5e96SPeter Zijlstra 
1497b2be5e96SPeter Zijlstra int sched_nr_latency_handler(struct ctl_table *table, int write,
1498b2be5e96SPeter Zijlstra 		struct file *file, void __user *buffer, size_t *length,
1499b2be5e96SPeter Zijlstra 		loff_t *ppos);
15002bd8e6d4SIngo Molnar #endif
15012bd8e6d4SIngo Molnar 
15022bd8e6d4SIngo Molnar extern unsigned int sysctl_sched_compat_yield;
1503bf0f6f24SIngo Molnar 
1504b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES
150536c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p);
150636c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio);
150736c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p);
1508b29739f9SIngo Molnar #else
1509e868171aSAlexey Dobriyan static inline int rt_mutex_getprio(struct task_struct *p)
1510b29739f9SIngo Molnar {
1511b29739f9SIngo Molnar 	return p->normal_prio;
1512b29739f9SIngo Molnar }
151395e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p)		do { } while (0)
1514b29739f9SIngo Molnar #endif
1515b29739f9SIngo Molnar 
151636c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice);
151736c8b586SIngo Molnar extern int task_prio(const struct task_struct *p);
151836c8b586SIngo Molnar extern int task_nice(const struct task_struct *p);
151936c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice);
152036c8b586SIngo Molnar extern int task_curr(const struct task_struct *p);
15211da177e4SLinus Torvalds extern int idle_cpu(int cpu);
15221da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
152336c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu);
152436c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu);
152536c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p);
15261da177e4SLinus Torvalds 
15271da177e4SLinus Torvalds void yield(void);
15281da177e4SLinus Torvalds 
15291da177e4SLinus Torvalds /*
15301da177e4SLinus Torvalds  * The default (Linux) execution domain.
15311da177e4SLinus Torvalds  */
15321da177e4SLinus Torvalds extern struct exec_domain	default_exec_domain;
15331da177e4SLinus Torvalds 
15341da177e4SLinus Torvalds union thread_union {
15351da177e4SLinus Torvalds 	struct thread_info thread_info;
15361da177e4SLinus Torvalds 	unsigned long stack[THREAD_SIZE/sizeof(long)];
15371da177e4SLinus Torvalds };
15381da177e4SLinus Torvalds 
15391da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END
15401da177e4SLinus Torvalds static inline int kstack_end(void *addr)
15411da177e4SLinus Torvalds {
15421da177e4SLinus Torvalds 	/* Reliable end of stack detection:
15431da177e4SLinus Torvalds 	 * Some APM bios versions misalign the stack
15441da177e4SLinus Torvalds 	 */
15451da177e4SLinus Torvalds 	return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
15461da177e4SLinus Torvalds }
15471da177e4SLinus Torvalds #endif
15481da177e4SLinus Torvalds 
15491da177e4SLinus Torvalds extern union thread_union init_thread_union;
15501da177e4SLinus Torvalds extern struct task_struct init_task;
15511da177e4SLinus Torvalds 
15521da177e4SLinus Torvalds extern struct   mm_struct init_mm;
15531da177e4SLinus Torvalds 
1554198fe21bSPavel Emelyanov extern struct pid_namespace init_pid_ns;
1555198fe21bSPavel Emelyanov 
1556198fe21bSPavel Emelyanov /*
1557198fe21bSPavel Emelyanov  * find a task by one of its numerical ids
1558198fe21bSPavel Emelyanov  *
1559198fe21bSPavel Emelyanov  * find_task_by_pid_type_ns():
1560198fe21bSPavel Emelyanov  *      it is the most generic call - it finds a task by all id,
1561198fe21bSPavel Emelyanov  *      type and namespace specified
1562198fe21bSPavel Emelyanov  * find_task_by_pid_ns():
1563198fe21bSPavel Emelyanov  *      finds a task by its pid in the specified namespace
1564228ebcbeSPavel Emelyanov  * find_task_by_vpid():
1565228ebcbeSPavel Emelyanov  *      finds a task by its virtual pid
1566198fe21bSPavel Emelyanov  * find_task_by_pid():
1567198fe21bSPavel Emelyanov  *      finds a task by its global pid
1568198fe21bSPavel Emelyanov  *
1569198fe21bSPavel Emelyanov  * see also find_pid() etc in include/linux/pid.h
1570198fe21bSPavel Emelyanov  */
1571198fe21bSPavel Emelyanov 
1572198fe21bSPavel Emelyanov extern struct task_struct *find_task_by_pid_type_ns(int type, int pid,
1573198fe21bSPavel Emelyanov 		struct pid_namespace *ns);
1574198fe21bSPavel Emelyanov 
1575228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid(pid_t nr);
1576228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_vpid(pid_t nr);
1577228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid_ns(pid_t nr,
1578228ebcbeSPavel Emelyanov 		struct pid_namespace *ns);
1579198fe21bSPavel Emelyanov 
15801da177e4SLinus Torvalds extern void __set_special_pids(pid_t session, pid_t pgrp);
15811da177e4SLinus Torvalds 
15821da177e4SLinus Torvalds /* per-UID process charging. */
1583acce292cSCedric Le Goater extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
15841da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u)
15851da177e4SLinus Torvalds {
15861da177e4SLinus Torvalds 	atomic_inc(&u->__count);
15871da177e4SLinus Torvalds 	return u;
15881da177e4SLinus Torvalds }
15891da177e4SLinus Torvalds extern void free_uid(struct user_struct *);
15901da177e4SLinus Torvalds extern void switch_uid(struct user_struct *);
159128f300d2SPavel Emelyanov extern void release_uids(struct user_namespace *ns);
15921da177e4SLinus Torvalds 
15931da177e4SLinus Torvalds #include <asm/current.h>
15941da177e4SLinus Torvalds 
15953171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks);
15961da177e4SLinus Torvalds 
15971da177e4SLinus Torvalds extern int FASTCALL(wake_up_state(struct task_struct * tsk, unsigned int state));
15981da177e4SLinus Torvalds extern int FASTCALL(wake_up_process(struct task_struct * tsk));
15991da177e4SLinus Torvalds extern void FASTCALL(wake_up_new_task(struct task_struct * tsk,
16001da177e4SLinus Torvalds 						unsigned long clone_flags));
16011da177e4SLinus Torvalds #ifdef CONFIG_SMP
16021da177e4SLinus Torvalds  extern void kick_process(struct task_struct *tsk);
16031da177e4SLinus Torvalds #else
16041da177e4SLinus Torvalds  static inline void kick_process(struct task_struct *tsk) { }
16051da177e4SLinus Torvalds #endif
1606ad46c2c4SIngo Molnar extern void sched_fork(struct task_struct *p, int clone_flags);
1607ad46c2c4SIngo Molnar extern void sched_dead(struct task_struct *p);
16081da177e4SLinus Torvalds 
16091da177e4SLinus Torvalds extern int in_group_p(gid_t);
16101da177e4SLinus Torvalds extern int in_egroup_p(gid_t);
16111da177e4SLinus Torvalds 
16121da177e4SLinus Torvalds extern void proc_caches_init(void);
16131da177e4SLinus Torvalds extern void flush_signals(struct task_struct *);
161410ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *);
16151da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default);
16161da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
16171da177e4SLinus Torvalds 
16181da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
16191da177e4SLinus Torvalds {
16201da177e4SLinus Torvalds 	unsigned long flags;
16211da177e4SLinus Torvalds 	int ret;
16221da177e4SLinus Torvalds 
16231da177e4SLinus Torvalds 	spin_lock_irqsave(&tsk->sighand->siglock, flags);
16241da177e4SLinus Torvalds 	ret = dequeue_signal(tsk, mask, info);
16251da177e4SLinus Torvalds 	spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
16261da177e4SLinus Torvalds 
16271da177e4SLinus Torvalds 	return ret;
16281da177e4SLinus Torvalds }
16291da177e4SLinus Torvalds 
16301da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv,
16311da177e4SLinus Torvalds 			      sigset_t *mask);
16321da177e4SLinus Torvalds extern void unblock_all_signals(void);
16331da177e4SLinus Torvalds extern void release_task(struct task_struct * p);
16341da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *);
16351da177e4SLinus Torvalds extern int send_group_sig_info(int, struct siginfo *, struct task_struct *);
16361da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *);
16371da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *);
1638c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
1639c4b92fc1SEric W. Biederman extern int kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
1640c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
16412425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32);
1642c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv);
1643c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv);
1644c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t);
16451da177e4SLinus Torvalds extern void do_notify_parent(struct task_struct *, int);
16461da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *);
16471da177e4SLinus Torvalds extern void force_sig_specific(int, struct task_struct *);
16481da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int);
16491da177e4SLinus Torvalds extern void zap_other_threads(struct task_struct *p);
16501da177e4SLinus Torvalds extern int kill_proc(pid_t, int, int);
16511da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void);
16521da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *);
16531da177e4SLinus Torvalds extern int send_sigqueue(int, struct sigqueue *,  struct task_struct *);
16541da177e4SLinus Torvalds extern int send_group_sigqueue(int, struct sigqueue *,  struct task_struct *);
16559ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
16561da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
16571da177e4SLinus Torvalds 
16589ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv)
16599ec52099SCedric Le Goater {
16609ec52099SCedric Le Goater 	return kill_pid(cad_pid, sig, priv);
16619ec52099SCedric Le Goater }
16629ec52099SCedric Le Goater 
16631da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info.  */
16641da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0)
16651da177e4SLinus Torvalds #define SEND_SIG_PRIV	((struct siginfo *) 1)
16661da177e4SLinus Torvalds #define SEND_SIG_FORCED	((struct siginfo *) 2)
16671da177e4SLinus Torvalds 
1668621d3121SOleg Nesterov static inline int is_si_special(const struct siginfo *info)
1669621d3121SOleg Nesterov {
1670621d3121SOleg Nesterov 	return info <= SEND_SIG_FORCED;
1671621d3121SOleg Nesterov }
1672621d3121SOleg Nesterov 
16731da177e4SLinus Torvalds /* True if we are on the alternate signal stack.  */
16741da177e4SLinus Torvalds 
16751da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp)
16761da177e4SLinus Torvalds {
16771da177e4SLinus Torvalds 	return (sp - current->sas_ss_sp < current->sas_ss_size);
16781da177e4SLinus Torvalds }
16791da177e4SLinus Torvalds 
16801da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp)
16811da177e4SLinus Torvalds {
16821da177e4SLinus Torvalds 	return (current->sas_ss_size == 0 ? SS_DISABLE
16831da177e4SLinus Torvalds 		: on_sig_stack(sp) ? SS_ONSTACK : 0);
16841da177e4SLinus Torvalds }
16851da177e4SLinus Torvalds 
16861da177e4SLinus Torvalds /*
16871da177e4SLinus Torvalds  * Routines for handling mm_structs
16881da177e4SLinus Torvalds  */
16891da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void);
16901da177e4SLinus Torvalds 
16911da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */
16921da177e4SLinus Torvalds extern void FASTCALL(__mmdrop(struct mm_struct *));
16931da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm)
16941da177e4SLinus Torvalds {
16956fb43d7bSIngo Molnar 	if (unlikely(atomic_dec_and_test(&mm->mm_count)))
16961da177e4SLinus Torvalds 		__mmdrop(mm);
16971da177e4SLinus Torvalds }
16981da177e4SLinus Torvalds 
16991da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */
17001da177e4SLinus Torvalds extern void mmput(struct mm_struct *);
17011da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */
17021da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task);
17031da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */
17041da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *);
17051da177e4SLinus Torvalds 
17061da177e4SLinus Torvalds extern int  copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
17071da177e4SLinus Torvalds extern void flush_thread(void);
17081da177e4SLinus Torvalds extern void exit_thread(void);
17091da177e4SLinus Torvalds 
17101da177e4SLinus Torvalds extern void exit_files(struct task_struct *);
17116b3934efSOleg Nesterov extern void __cleanup_signal(struct signal_struct *);
1712a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *);
17131da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *);
17141da177e4SLinus Torvalds 
17151da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int);
17161da177e4SLinus Torvalds 
17171da177e4SLinus Torvalds extern void daemonize(const char *, ...);
17181da177e4SLinus Torvalds extern int allow_signal(int);
17191da177e4SLinus Torvalds extern int disallow_signal(int);
17201da177e4SLinus Torvalds 
17211da177e4SLinus Torvalds extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
17221da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
172336c8b586SIngo Molnar struct task_struct *fork_idle(int);
17241da177e4SLinus Torvalds 
17251da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from);
17261da177e4SLinus Torvalds extern void get_task_comm(char *to, struct task_struct *tsk);
17271da177e4SLinus Torvalds 
17281da177e4SLinus Torvalds #ifdef CONFIG_SMP
172936c8b586SIngo Molnar extern void wait_task_inactive(struct task_struct * p);
17301da177e4SLinus Torvalds #else
17311da177e4SLinus Torvalds #define wait_task_inactive(p)	do { } while (0)
17321da177e4SLinus Torvalds #endif
17331da177e4SLinus Torvalds 
17341da177e4SLinus Torvalds #define remove_parent(p)	list_del_init(&(p)->sibling)
17358fafabd8SOleg Nesterov #define add_parent(p)		list_add_tail(&(p)->sibling,&(p)->parent->children)
17361da177e4SLinus Torvalds 
17375e85d4abSEric W. Biederman #define next_task(p)	list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks)
17381da177e4SLinus Torvalds 
17391da177e4SLinus Torvalds #define for_each_process(p) \
17401da177e4SLinus Torvalds 	for (p = &init_task ; (p = next_task(p)) != &init_task ; )
17411da177e4SLinus Torvalds 
17421da177e4SLinus Torvalds /*
17431da177e4SLinus Torvalds  * Careful: do_each_thread/while_each_thread is a double loop so
17441da177e4SLinus Torvalds  *          'break' will not work as expected - use goto instead.
17451da177e4SLinus Torvalds  */
17461da177e4SLinus Torvalds #define do_each_thread(g, t) \
17471da177e4SLinus Torvalds 	for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
17481da177e4SLinus Torvalds 
17491da177e4SLinus Torvalds #define while_each_thread(g, t) \
17501da177e4SLinus Torvalds 	while ((t = next_thread(t)) != g)
17511da177e4SLinus Torvalds 
1752de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */
1753de12a787SEric W. Biederman #define thread_group_leader(p)	(p == p->group_leader)
17541da177e4SLinus Torvalds 
17550804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process
17560804ef4bSEric W. Biederman  * to have the pid of the thread group leader without actually being
17570804ef4bSEric W. Biederman  * the thread group leader.  For iteration through the pids in proc
17580804ef4bSEric W. Biederman  * all we care about is that we have a task with the appropriate
17590804ef4bSEric W. Biederman  * pid, we don't actually care if we have the right task.
17600804ef4bSEric W. Biederman  */
1761e868171aSAlexey Dobriyan static inline int has_group_leader_pid(struct task_struct *p)
17620804ef4bSEric W. Biederman {
17630804ef4bSEric W. Biederman 	return p->pid == p->tgid;
17640804ef4bSEric W. Biederman }
17650804ef4bSEric W. Biederman 
1766bac0abd6SPavel Emelyanov static inline
1767bac0abd6SPavel Emelyanov int same_thread_group(struct task_struct *p1, struct task_struct *p2)
1768bac0abd6SPavel Emelyanov {
1769bac0abd6SPavel Emelyanov 	return p1->tgid == p2->tgid;
1770bac0abd6SPavel Emelyanov }
1771bac0abd6SPavel Emelyanov 
177236c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p)
177347e65328SOleg Nesterov {
177447e65328SOleg Nesterov 	return list_entry(rcu_dereference(p->thread_group.next),
177536c8b586SIngo Molnar 			  struct task_struct, thread_group);
177647e65328SOleg Nesterov }
177747e65328SOleg Nesterov 
1778e868171aSAlexey Dobriyan static inline int thread_group_empty(struct task_struct *p)
17791da177e4SLinus Torvalds {
178047e65328SOleg Nesterov 	return list_empty(&p->thread_group);
17811da177e4SLinus Torvalds }
17821da177e4SLinus Torvalds 
17831da177e4SLinus Torvalds #define delay_group_leader(p) \
17841da177e4SLinus Torvalds 		(thread_group_leader(p) && !thread_group_empty(p))
17851da177e4SLinus Torvalds 
17861da177e4SLinus Torvalds /*
1787260ea101SEric W. Biederman  * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
178822e2c507SJens Axboe  * subscriptions and synchronises with wait4().  Also used in procfs.  Also
1789ddbcc7e8SPaul Menage  * pins the final release of task.io_context.  Also protects ->cpuset and
1790ddbcc7e8SPaul Menage  * ->cgroup.subsys[].
17911da177e4SLinus Torvalds  *
17921da177e4SLinus Torvalds  * Nests both inside and outside of read_lock(&tasklist_lock).
17931da177e4SLinus Torvalds  * It must not be nested with write_lock_irq(&tasklist_lock),
17941da177e4SLinus Torvalds  * neither inside nor outside.
17951da177e4SLinus Torvalds  */
17961da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p)
17971da177e4SLinus Torvalds {
17981da177e4SLinus Torvalds 	spin_lock(&p->alloc_lock);
17991da177e4SLinus Torvalds }
18001da177e4SLinus Torvalds 
18011da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p)
18021da177e4SLinus Torvalds {
18031da177e4SLinus Torvalds 	spin_unlock(&p->alloc_lock);
18041da177e4SLinus Torvalds }
18051da177e4SLinus Torvalds 
1806f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
1807f63ee72eSOleg Nesterov 							unsigned long *flags);
1808f63ee72eSOleg Nesterov 
1809f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk,
1810f63ee72eSOleg Nesterov 						unsigned long *flags)
1811f63ee72eSOleg Nesterov {
1812f63ee72eSOleg Nesterov 	spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
1813f63ee72eSOleg Nesterov }
1814f63ee72eSOleg Nesterov 
1815f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS
1816f037360fSAl Viro 
1817f7e4217bSRoman Zippel #define task_thread_info(task)	((struct thread_info *)(task)->stack)
1818f7e4217bSRoman Zippel #define task_stack_page(task)	((task)->stack)
1819a1261f54SAl Viro 
182010ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
182110ebffdeSAl Viro {
182210ebffdeSAl Viro 	*task_thread_info(p) = *task_thread_info(org);
182310ebffdeSAl Viro 	task_thread_info(p)->task = p;
182410ebffdeSAl Viro }
182510ebffdeSAl Viro 
182610ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p)
182710ebffdeSAl Viro {
1828f7e4217bSRoman Zippel 	return (unsigned long *)(task_thread_info(p) + 1);
182910ebffdeSAl Viro }
183010ebffdeSAl Viro 
1831f037360fSAl Viro #endif
1832f037360fSAl Viro 
18331da177e4SLinus Torvalds /* set thread flags in other task's structures
18341da177e4SLinus Torvalds  * - see asm/thread_info.h for TIF_xxxx flags available
18351da177e4SLinus Torvalds  */
18361da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
18371da177e4SLinus Torvalds {
1838a1261f54SAl Viro 	set_ti_thread_flag(task_thread_info(tsk), flag);
18391da177e4SLinus Torvalds }
18401da177e4SLinus Torvalds 
18411da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
18421da177e4SLinus Torvalds {
1843a1261f54SAl Viro 	clear_ti_thread_flag(task_thread_info(tsk), flag);
18441da177e4SLinus Torvalds }
18451da177e4SLinus Torvalds 
18461da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
18471da177e4SLinus Torvalds {
1848a1261f54SAl Viro 	return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
18491da177e4SLinus Torvalds }
18501da177e4SLinus Torvalds 
18511da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
18521da177e4SLinus Torvalds {
1853a1261f54SAl Viro 	return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
18541da177e4SLinus Torvalds }
18551da177e4SLinus Torvalds 
18561da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
18571da177e4SLinus Torvalds {
1858a1261f54SAl Viro 	return test_ti_thread_flag(task_thread_info(tsk), flag);
18591da177e4SLinus Torvalds }
18601da177e4SLinus Torvalds 
18611da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk)
18621da177e4SLinus Torvalds {
18631da177e4SLinus Torvalds 	set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
18641da177e4SLinus Torvalds }
18651da177e4SLinus Torvalds 
18661da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk)
18671da177e4SLinus Torvalds {
18681da177e4SLinus Torvalds 	clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
18691da177e4SLinus Torvalds }
18701da177e4SLinus Torvalds 
18711da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p)
18721da177e4SLinus Torvalds {
18731da177e4SLinus Torvalds 	return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
18741da177e4SLinus Torvalds }
18751da177e4SLinus Torvalds 
18761da177e4SLinus Torvalds static inline int need_resched(void)
18771da177e4SLinus Torvalds {
18781da177e4SLinus Torvalds 	return unlikely(test_thread_flag(TIF_NEED_RESCHED));
18791da177e4SLinus Torvalds }
18801da177e4SLinus Torvalds 
18811da177e4SLinus Torvalds /*
18821da177e4SLinus Torvalds  * cond_resched() and cond_resched_lock(): latency reduction via
18831da177e4SLinus Torvalds  * explicit rescheduling in places that are safe. The return
18841da177e4SLinus Torvalds  * value indicates whether a reschedule was done in fact.
18851da177e4SLinus Torvalds  * cond_resched_lock() will drop the spinlock before scheduling,
18861da177e4SLinus Torvalds  * cond_resched_softirq() will enable bhs before scheduling.
18871da177e4SLinus Torvalds  */
18881da177e4SLinus Torvalds extern int cond_resched(void);
18891da177e4SLinus Torvalds extern int cond_resched_lock(spinlock_t * lock);
18901da177e4SLinus Torvalds extern int cond_resched_softirq(void);
18911da177e4SLinus Torvalds 
18921da177e4SLinus Torvalds /*
18931da177e4SLinus Torvalds  * Does a critical section need to be broken due to another
18941da177e4SLinus Torvalds  * task waiting?:
18951da177e4SLinus Torvalds  */
18961da177e4SLinus Torvalds #if defined(CONFIG_PREEMPT) && defined(CONFIG_SMP)
18971da177e4SLinus Torvalds # define need_lockbreak(lock) ((lock)->break_lock)
18981da177e4SLinus Torvalds #else
18991da177e4SLinus Torvalds # define need_lockbreak(lock) 0
19001da177e4SLinus Torvalds #endif
19011da177e4SLinus Torvalds 
19021da177e4SLinus Torvalds /*
19031da177e4SLinus Torvalds  * Does a critical section need to be broken due to another
19041da177e4SLinus Torvalds  * task waiting or preemption being signalled:
19051da177e4SLinus Torvalds  */
19061da177e4SLinus Torvalds static inline int lock_need_resched(spinlock_t *lock)
19071da177e4SLinus Torvalds {
19081da177e4SLinus Torvalds 	if (need_lockbreak(lock) || need_resched())
19091da177e4SLinus Torvalds 		return 1;
19101da177e4SLinus Torvalds 	return 0;
19111da177e4SLinus Torvalds }
19121da177e4SLinus Torvalds 
19137bb44adeSRoland McGrath /*
19147bb44adeSRoland McGrath  * Reevaluate whether the task has signals pending delivery.
19157bb44adeSRoland McGrath  * Wake the task if so.
19167bb44adeSRoland McGrath  * This is required every time the blocked sigset_t changes.
19177bb44adeSRoland McGrath  * callers must hold sighand->siglock.
19187bb44adeSRoland McGrath  */
19197bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t);
19201da177e4SLinus Torvalds extern void recalc_sigpending(void);
19211da177e4SLinus Torvalds 
19221da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped);
19231da177e4SLinus Torvalds 
19241da177e4SLinus Torvalds /*
19251da177e4SLinus Torvalds  * Wrappers for p->thread_info->cpu access. No-op on UP.
19261da177e4SLinus Torvalds  */
19271da177e4SLinus Torvalds #ifdef CONFIG_SMP
19281da177e4SLinus Torvalds 
19291da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
19301da177e4SLinus Torvalds {
1931a1261f54SAl Viro 	return task_thread_info(p)->cpu;
19321da177e4SLinus Torvalds }
19331da177e4SLinus Torvalds 
1934c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
19351da177e4SLinus Torvalds 
19361da177e4SLinus Torvalds #else
19371da177e4SLinus Torvalds 
19381da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
19391da177e4SLinus Torvalds {
19401da177e4SLinus Torvalds 	return 0;
19411da177e4SLinus Torvalds }
19421da177e4SLinus Torvalds 
19431da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
19441da177e4SLinus Torvalds {
19451da177e4SLinus Torvalds }
19461da177e4SLinus Torvalds 
19471da177e4SLinus Torvalds #endif /* CONFIG_SMP */
19481da177e4SLinus Torvalds 
19491da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
19501da177e4SLinus Torvalds extern void arch_pick_mmap_layout(struct mm_struct *mm);
19511da177e4SLinus Torvalds #else
19521da177e4SLinus Torvalds static inline void arch_pick_mmap_layout(struct mm_struct *mm)
19531da177e4SLinus Torvalds {
19541da177e4SLinus Torvalds 	mm->mmap_base = TASK_UNMAPPED_BASE;
19551da177e4SLinus Torvalds 	mm->get_unmapped_area = arch_get_unmapped_area;
19561da177e4SLinus Torvalds 	mm->unmap_area = arch_unmap_area;
19571da177e4SLinus Torvalds }
19581da177e4SLinus Torvalds #endif
19591da177e4SLinus Torvalds 
19601da177e4SLinus Torvalds extern long sched_setaffinity(pid_t pid, cpumask_t new_mask);
19611da177e4SLinus Torvalds extern long sched_getaffinity(pid_t pid, cpumask_t *mask);
19621da177e4SLinus Torvalds 
19635c45bf27SSiddha, Suresh B extern int sched_mc_power_savings, sched_smt_power_savings;
19645c45bf27SSiddha, Suresh B 
19651da177e4SLinus Torvalds extern void normalize_rt_tasks(void);
19661da177e4SLinus Torvalds 
19679b5b7751SSrivatsa Vaddagiri #ifdef CONFIG_FAIR_GROUP_SCHED
19689b5b7751SSrivatsa Vaddagiri 
19694cf86d77SIngo Molnar extern struct task_group init_task_group;
19709b5b7751SSrivatsa Vaddagiri 
19714cf86d77SIngo Molnar extern struct task_group *sched_create_group(void);
19724cf86d77SIngo Molnar extern void sched_destroy_group(struct task_group *tg);
19739b5b7751SSrivatsa Vaddagiri extern void sched_move_task(struct task_struct *tsk);
19744cf86d77SIngo Molnar extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
19755cb350baSDhaval Giani extern unsigned long sched_group_shares(struct task_group *tg);
19769b5b7751SSrivatsa Vaddagiri 
19779b5b7751SSrivatsa Vaddagiri #endif
19789b5b7751SSrivatsa Vaddagiri 
19794b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT
19804b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
19814b98d11bSAlexey Dobriyan {
19824b98d11bSAlexey Dobriyan 	tsk->rchar += amt;
19834b98d11bSAlexey Dobriyan }
19844b98d11bSAlexey Dobriyan 
19854b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
19864b98d11bSAlexey Dobriyan {
19874b98d11bSAlexey Dobriyan 	tsk->wchar += amt;
19884b98d11bSAlexey Dobriyan }
19894b98d11bSAlexey Dobriyan 
19904b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
19914b98d11bSAlexey Dobriyan {
19924b98d11bSAlexey Dobriyan 	tsk->syscr++;
19934b98d11bSAlexey Dobriyan }
19944b98d11bSAlexey Dobriyan 
19954b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
19964b98d11bSAlexey Dobriyan {
19974b98d11bSAlexey Dobriyan 	tsk->syscw++;
19984b98d11bSAlexey Dobriyan }
19994b98d11bSAlexey Dobriyan #else
20004b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
20014b98d11bSAlexey Dobriyan {
20024b98d11bSAlexey Dobriyan }
20034b98d11bSAlexey Dobriyan 
20044b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
20054b98d11bSAlexey Dobriyan {
20064b98d11bSAlexey Dobriyan }
20074b98d11bSAlexey Dobriyan 
20084b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
20094b98d11bSAlexey Dobriyan {
20104b98d11bSAlexey Dobriyan }
20114b98d11bSAlexey Dobriyan 
20124b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
20134b98d11bSAlexey Dobriyan {
20144b98d11bSAlexey Dobriyan }
20154b98d11bSAlexey Dobriyan #endif
20164b98d11bSAlexey Dobriyan 
2017e6fe6649SAdrian Bunk #ifdef CONFIG_SMP
2018e6fe6649SAdrian Bunk void migration_init(void);
2019e6fe6649SAdrian Bunk #else
2020e6fe6649SAdrian Bunk static inline void migration_init(void)
2021e6fe6649SAdrian Bunk {
2022e6fe6649SAdrian Bunk }
2023e6fe6649SAdrian Bunk #endif
2024e6fe6649SAdrian Bunk 
20251da177e4SLinus Torvalds #endif /* __KERNEL__ */
20261da177e4SLinus Torvalds 
20271da177e4SLinus Torvalds #endif
2028