xref: /linux/include/linux/sched.h (revision ddbcc7e8e50aefe467c01cac3dec71f118cd8ac2)
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 */
28169e3674SEric W. Biederman #define CLONE_NEWNET		0x40000000	/* New network namespace */
29b7b3c76aSDavid Woodhouse 
30b7b3c76aSDavid Woodhouse /*
31b7b3c76aSDavid Woodhouse  * Scheduling policies
32b7b3c76aSDavid Woodhouse  */
33b7b3c76aSDavid Woodhouse #define SCHED_NORMAL		0
34b7b3c76aSDavid Woodhouse #define SCHED_FIFO		1
35b7b3c76aSDavid Woodhouse #define SCHED_RR		2
36b7b3c76aSDavid Woodhouse #define SCHED_BATCH		3
370e6aca43SIngo Molnar /* SCHED_ISO: reserved but not implemented yet */
380e6aca43SIngo Molnar #define SCHED_IDLE		5
39b7b3c76aSDavid Woodhouse 
40a3b6714eSDavid Woodhouse #ifdef __KERNEL__
41b7b3c76aSDavid Woodhouse 
42b7b3c76aSDavid Woodhouse struct sched_param {
43b7b3c76aSDavid Woodhouse 	int sched_priority;
44b7b3c76aSDavid Woodhouse };
45b7b3c76aSDavid Woodhouse 
461da177e4SLinus Torvalds #include <asm/param.h>	/* for HZ */
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds #include <linux/capability.h>
491da177e4SLinus Torvalds #include <linux/threads.h>
501da177e4SLinus Torvalds #include <linux/kernel.h>
511da177e4SLinus Torvalds #include <linux/types.h>
521da177e4SLinus Torvalds #include <linux/timex.h>
531da177e4SLinus Torvalds #include <linux/jiffies.h>
541da177e4SLinus Torvalds #include <linux/rbtree.h>
551da177e4SLinus Torvalds #include <linux/thread_info.h>
561da177e4SLinus Torvalds #include <linux/cpumask.h>
571da177e4SLinus Torvalds #include <linux/errno.h>
581da177e4SLinus Torvalds #include <linux/nodemask.h>
59c92ff1bdSMartin Schwidefsky #include <linux/mm_types.h>
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds #include <asm/system.h>
621da177e4SLinus Torvalds #include <asm/semaphore.h>
631da177e4SLinus Torvalds #include <asm/page.h>
641da177e4SLinus Torvalds #include <asm/ptrace.h>
651da177e4SLinus Torvalds #include <asm/cputime.h>
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds #include <linux/smp.h>
681da177e4SLinus Torvalds #include <linux/sem.h>
691da177e4SLinus Torvalds #include <linux/signal.h>
701da177e4SLinus Torvalds #include <linux/securebits.h>
711da177e4SLinus Torvalds #include <linux/fs_struct.h>
721da177e4SLinus Torvalds #include <linux/compiler.h>
731da177e4SLinus Torvalds #include <linux/completion.h>
741da177e4SLinus Torvalds #include <linux/pid.h>
751da177e4SLinus Torvalds #include <linux/percpu.h>
761da177e4SLinus Torvalds #include <linux/topology.h>
773e26c149SPeter Zijlstra #include <linux/proportions.h>
781da177e4SLinus Torvalds #include <linux/seccomp.h>
79e56d0903SIngo Molnar #include <linux/rcupdate.h>
800771dfefSIngo Molnar #include <linux/futex.h>
8123f78d4aSIngo Molnar #include <linux/rtmutex.h>
821da177e4SLinus Torvalds 
83a3b6714eSDavid Woodhouse #include <linux/time.h>
84a3b6714eSDavid Woodhouse #include <linux/param.h>
85a3b6714eSDavid Woodhouse #include <linux/resource.h>
86a3b6714eSDavid Woodhouse #include <linux/timer.h>
87a3b6714eSDavid Woodhouse #include <linux/hrtimer.h>
887c3ab738SAndrew Morton #include <linux/task_io_accounting.h>
895cb350baSDhaval Giani #include <linux/kobject.h>
90a3b6714eSDavid Woodhouse 
91a3b6714eSDavid Woodhouse #include <asm/processor.h>
9236d57ac4SH. J. Lu 
931da177e4SLinus Torvalds struct exec_domain;
94c87e2837SIngo Molnar struct futex_pi_state;
95d89d8796SNeil Brown struct bio;
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds /*
981da177e4SLinus Torvalds  * List of flags we want to share for kernel threads,
991da177e4SLinus Torvalds  * if only because they are not used by them anyway.
1001da177e4SLinus Torvalds  */
1011da177e4SLinus Torvalds #define CLONE_KERNEL	(CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds /*
1041da177e4SLinus Torvalds  * These are the constant used to fake the fixed-point load-average
1051da177e4SLinus Torvalds  * counting. Some notes:
1061da177e4SLinus Torvalds  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
1071da177e4SLinus Torvalds  *    a load-average precision of 10 bits integer + 11 bits fractional
1081da177e4SLinus Torvalds  *  - if you want to count load-averages more often, you need more
1091da177e4SLinus Torvalds  *    precision, or rounding will get you. With 2-second counting freq,
1101da177e4SLinus Torvalds  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
1111da177e4SLinus Torvalds  *    11 bit fractions.
1121da177e4SLinus Torvalds  */
1131da177e4SLinus Torvalds extern unsigned long avenrun[];		/* Load averages */
1141da177e4SLinus Torvalds 
1151da177e4SLinus Torvalds #define FSHIFT		11		/* nr of bits of precision */
1161da177e4SLinus Torvalds #define FIXED_1		(1<<FSHIFT)	/* 1.0 as fixed-point */
1170c2043abSLinus Torvalds #define LOAD_FREQ	(5*HZ+1)	/* 5 sec intervals */
1181da177e4SLinus Torvalds #define EXP_1		1884		/* 1/exp(5sec/1min) as fixed-point */
1191da177e4SLinus Torvalds #define EXP_5		2014		/* 1/exp(5sec/5min) */
1201da177e4SLinus Torvalds #define EXP_15		2037		/* 1/exp(5sec/15min) */
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \
1231da177e4SLinus Torvalds 	load *= exp; \
1241da177e4SLinus Torvalds 	load += n*(FIXED_1-exp); \
1251da177e4SLinus Torvalds 	load >>= FSHIFT;
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds extern unsigned long total_forks;
1281da177e4SLinus Torvalds extern int nr_threads;
1291da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts);
1301da177e4SLinus Torvalds extern int nr_processes(void);
1311da177e4SLinus Torvalds extern unsigned long nr_running(void);
1321da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void);
133db1b1fefSJack Steiner extern unsigned long nr_active(void);
1341da177e4SLinus Torvalds extern unsigned long nr_iowait(void);
1352dd73a4fSPeter Williams extern unsigned long weighted_cpuload(const int cpu);
1361da177e4SLinus Torvalds 
13743ae34cbSIngo Molnar struct seq_file;
13843ae34cbSIngo Molnar struct cfs_rq;
1394cf86d77SIngo Molnar struct task_group;
14043ae34cbSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
14143ae34cbSIngo Molnar extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
14243ae34cbSIngo Molnar extern void proc_sched_set_task(struct task_struct *p);
14343ae34cbSIngo Molnar extern void
1445cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
14543ae34cbSIngo Molnar #else
14643ae34cbSIngo Molnar static inline void
14743ae34cbSIngo Molnar proc_sched_show_task(struct task_struct *p, struct seq_file *m)
14843ae34cbSIngo Molnar {
14943ae34cbSIngo Molnar }
15043ae34cbSIngo Molnar static inline void proc_sched_set_task(struct task_struct *p)
15143ae34cbSIngo Molnar {
15243ae34cbSIngo Molnar }
15343ae34cbSIngo Molnar static inline void
1545cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
15543ae34cbSIngo Molnar {
15643ae34cbSIngo Molnar }
15743ae34cbSIngo Molnar #endif
1581da177e4SLinus Torvalds 
1594a8342d2SLinus Torvalds /*
1604a8342d2SLinus Torvalds  * Task state bitmask. NOTE! These bits are also
1614a8342d2SLinus Torvalds  * encoded in fs/proc/array.c: get_task_state().
1624a8342d2SLinus Torvalds  *
1634a8342d2SLinus Torvalds  * We have two separate sets of flags: task->state
1644a8342d2SLinus Torvalds  * is about runnability, while task->exit_state are
1654a8342d2SLinus Torvalds  * about the task exiting. Confusing, but this way
1664a8342d2SLinus Torvalds  * modifying one set can't modify the other one by
1674a8342d2SLinus Torvalds  * mistake.
1684a8342d2SLinus Torvalds  */
1691da177e4SLinus Torvalds #define TASK_RUNNING		0
1701da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE	1
1711da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE	2
1724a8342d2SLinus Torvalds #define TASK_STOPPED		4
1734a8342d2SLinus Torvalds #define TASK_TRACED		8
1744a8342d2SLinus Torvalds /* in tsk->exit_state */
1754a8342d2SLinus Torvalds #define EXIT_ZOMBIE		16
1764a8342d2SLinus Torvalds #define EXIT_DEAD		32
1774a8342d2SLinus Torvalds /* in tsk->state again */
178af927232SMike Galbraith #define TASK_DEAD		64
1791da177e4SLinus Torvalds 
1801da177e4SLinus Torvalds #define __set_task_state(tsk, state_value)		\
1811da177e4SLinus Torvalds 	do { (tsk)->state = (state_value); } while (0)
1821da177e4SLinus Torvalds #define set_task_state(tsk, state_value)		\
1831da177e4SLinus Torvalds 	set_mb((tsk)->state, (state_value))
1841da177e4SLinus Torvalds 
185498d0c57SAndrew Morton /*
186498d0c57SAndrew Morton  * set_current_state() includes a barrier so that the write of current->state
187498d0c57SAndrew Morton  * is correctly serialised wrt the caller's subsequent test of whether to
188498d0c57SAndrew Morton  * actually sleep:
189498d0c57SAndrew Morton  *
190498d0c57SAndrew Morton  *	set_current_state(TASK_UNINTERRUPTIBLE);
191498d0c57SAndrew Morton  *	if (do_i_need_to_sleep())
192498d0c57SAndrew Morton  *		schedule();
193498d0c57SAndrew Morton  *
194498d0c57SAndrew Morton  * If the caller does not need such serialisation then use __set_current_state()
195498d0c57SAndrew Morton  */
1961da177e4SLinus Torvalds #define __set_current_state(state_value)			\
1971da177e4SLinus Torvalds 	do { current->state = (state_value); } while (0)
1981da177e4SLinus Torvalds #define set_current_state(state_value)		\
1991da177e4SLinus Torvalds 	set_mb(current->state, (state_value))
2001da177e4SLinus Torvalds 
2011da177e4SLinus Torvalds /* Task command name length */
2021da177e4SLinus Torvalds #define TASK_COMM_LEN 16
2031da177e4SLinus Torvalds 
2041da177e4SLinus Torvalds #include <linux/spinlock.h>
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds /*
2071da177e4SLinus Torvalds  * This serializes "schedule()" and also protects
2081da177e4SLinus Torvalds  * the run-queue from deletions/modifications (but
2091da177e4SLinus Torvalds  * _adding_ to the beginning of the run-queue has
2101da177e4SLinus Torvalds  * a separate lock).
2111da177e4SLinus Torvalds  */
2121da177e4SLinus Torvalds extern rwlock_t tasklist_lock;
2131da177e4SLinus Torvalds extern spinlock_t mmlist_lock;
2141da177e4SLinus Torvalds 
21536c8b586SIngo Molnar struct task_struct;
2161da177e4SLinus Torvalds 
2171da177e4SLinus Torvalds extern void sched_init(void);
2181da177e4SLinus Torvalds extern void sched_init_smp(void);
21936c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu);
2201df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle);
2211da177e4SLinus Torvalds 
2221da177e4SLinus Torvalds extern cpumask_t nohz_cpu_mask;
22346cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
22446cb4b7cSSiddha, Suresh B extern int select_nohz_load_balancer(int cpu);
22546cb4b7cSSiddha, Suresh B #else
22646cb4b7cSSiddha, Suresh B static inline int select_nohz_load_balancer(int cpu)
22746cb4b7cSSiddha, Suresh B {
22846cb4b7cSSiddha, Suresh B 	return 0;
22946cb4b7cSSiddha, Suresh B }
23046cb4b7cSSiddha, Suresh B #endif
2311da177e4SLinus Torvalds 
232e59e2ae2SIngo Molnar /*
23339bc89fdSIngo Molnar  * Only dump TASK_* tasks. (0 for all tasks)
234e59e2ae2SIngo Molnar  */
235e59e2ae2SIngo Molnar extern void show_state_filter(unsigned long state_filter);
236e59e2ae2SIngo Molnar 
237e59e2ae2SIngo Molnar static inline void show_state(void)
238e59e2ae2SIngo Molnar {
23939bc89fdSIngo Molnar 	show_state_filter(0);
240e59e2ae2SIngo Molnar }
241e59e2ae2SIngo Molnar 
2421da177e4SLinus Torvalds extern void show_regs(struct pt_regs *);
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds /*
2451da177e4SLinus Torvalds  * TASK is a pointer to the task whose backtrace we want to see (or NULL for current
2461da177e4SLinus Torvalds  * task), SP is the stack pointer of the first frame that should be shown in the back
2471da177e4SLinus Torvalds  * trace (or NULL if the entire call-chain of the task should be shown).
2481da177e4SLinus Torvalds  */
2491da177e4SLinus Torvalds extern void show_stack(struct task_struct *task, unsigned long *sp);
2501da177e4SLinus Torvalds 
2511da177e4SLinus Torvalds void io_schedule(void);
2521da177e4SLinus Torvalds long io_schedule_timeout(long timeout);
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds extern void cpu_init (void);
2551da177e4SLinus Torvalds extern void trap_init(void);
2561da177e4SLinus Torvalds extern void update_process_times(int user);
2571da177e4SLinus Torvalds extern void scheduler_tick(void);
2581da177e4SLinus Torvalds 
2598446f1d3SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP
2606687a97dSIngo Molnar extern void softlockup_tick(void);
2618446f1d3SIngo Molnar extern void spawn_softlockup_task(void);
2628446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void);
26304c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void);
264c4f3b63fSRavikiran G Thirumalai extern int softlockup_thresh;
2658446f1d3SIngo Molnar #else
2666687a97dSIngo Molnar static inline void softlockup_tick(void)
2678446f1d3SIngo Molnar {
2688446f1d3SIngo Molnar }
2698446f1d3SIngo Molnar static inline void spawn_softlockup_task(void)
2708446f1d3SIngo Molnar {
2718446f1d3SIngo Molnar }
2728446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void)
2738446f1d3SIngo Molnar {
2748446f1d3SIngo Molnar }
27504c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void)
27604c9167fSJeremy Fitzhardinge {
27704c9167fSJeremy Fitzhardinge }
2788446f1d3SIngo Molnar #endif
2798446f1d3SIngo Molnar 
2808446f1d3SIngo Molnar 
2811da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */
2821da177e4SLinus Torvalds #define __sched		__attribute__((__section__(".sched.text")))
2831da177e4SLinus Torvalds /* Is this address in the __sched functions? */
2841da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr);
2851da177e4SLinus Torvalds 
2861da177e4SLinus Torvalds #define	MAX_SCHEDULE_TIMEOUT	LONG_MAX
2871da177e4SLinus Torvalds extern signed long FASTCALL(schedule_timeout(signed long timeout));
28864ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout);
28964ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout);
2901da177e4SLinus Torvalds asmlinkage void schedule(void);
2911da177e4SLinus Torvalds 
292ab516013SSerge E. Hallyn struct nsproxy;
293acce292cSCedric Le Goater struct user_namespace;
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds /* Maximum number of active map areas.. This is a random (large) number */
2961da177e4SLinus Torvalds #define DEFAULT_MAX_MAP_COUNT	65536
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds extern int sysctl_max_map_count;
2991da177e4SLinus Torvalds 
3001da177e4SLinus Torvalds #include <linux/aio.h>
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds extern unsigned long
3031da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
3041da177e4SLinus Torvalds 		       unsigned long, unsigned long);
3051da177e4SLinus Torvalds extern unsigned long
3061da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
3071da177e4SLinus Torvalds 			  unsigned long len, unsigned long pgoff,
3081da177e4SLinus Torvalds 			  unsigned long flags);
3091363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long);
3101363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
3111da177e4SLinus Torvalds 
312f412ac08SHugh Dickins #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
313f412ac08SHugh Dickins /*
314f412ac08SHugh Dickins  * The mm counters are not protected by its page_table_lock,
315f412ac08SHugh Dickins  * so must be incremented atomically.
316f412ac08SHugh Dickins  */
317d3cb4871SChristoph Lameter #define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
318d3cb4871SChristoph Lameter #define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
319d3cb4871SChristoph Lameter #define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
320d3cb4871SChristoph Lameter #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
321d3cb4871SChristoph Lameter #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
322f412ac08SHugh Dickins 
323f412ac08SHugh Dickins #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
324f412ac08SHugh Dickins /*
325f412ac08SHugh Dickins  * The mm counters are protected by its page_table_lock,
326f412ac08SHugh Dickins  * so can be incremented directly.
327f412ac08SHugh Dickins  */
3281da177e4SLinus Torvalds #define set_mm_counter(mm, member, value) (mm)->_##member = (value)
3291da177e4SLinus Torvalds #define get_mm_counter(mm, member) ((mm)->_##member)
3301da177e4SLinus Torvalds #define add_mm_counter(mm, member, value) (mm)->_##member += (value)
3311da177e4SLinus Torvalds #define inc_mm_counter(mm, member) (mm)->_##member++
3321da177e4SLinus Torvalds #define dec_mm_counter(mm, member) (mm)->_##member--
3334294621fSHugh Dickins 
334f412ac08SHugh Dickins #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
335f412ac08SHugh Dickins 
336f412ac08SHugh Dickins #define get_mm_rss(mm)					\
337f412ac08SHugh Dickins 	(get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
338365e9c87SHugh Dickins #define update_hiwater_rss(mm)	do {			\
339365e9c87SHugh Dickins 	unsigned long _rss = get_mm_rss(mm);		\
340365e9c87SHugh Dickins 	if ((mm)->hiwater_rss < _rss)			\
341365e9c87SHugh Dickins 		(mm)->hiwater_rss = _rss;		\
342365e9c87SHugh Dickins } while (0)
343365e9c87SHugh Dickins #define update_hiwater_vm(mm)	do {			\
344365e9c87SHugh Dickins 	if ((mm)->hiwater_vm < (mm)->total_vm)		\
345365e9c87SHugh Dickins 		(mm)->hiwater_vm = (mm)->total_vm;	\
346365e9c87SHugh Dickins } while (0)
347365e9c87SHugh Dickins 
3486c5d5238SKawai, Hidehiro extern void set_dumpable(struct mm_struct *mm, int value);
3496c5d5238SKawai, Hidehiro extern int get_dumpable(struct mm_struct *mm);
3506c5d5238SKawai, Hidehiro 
3516c5d5238SKawai, Hidehiro /* mm flags */
3523cb4a0bbSKawai, Hidehiro /* dumpable bits */
3536c5d5238SKawai, Hidehiro #define MMF_DUMPABLE      0  /* core dump is permitted */
3546c5d5238SKawai, Hidehiro #define MMF_DUMP_SECURELY 1  /* core file is readable only by root */
3553cb4a0bbSKawai, Hidehiro #define MMF_DUMPABLE_BITS 2
3563cb4a0bbSKawai, Hidehiro 
3573cb4a0bbSKawai, Hidehiro /* coredump filter bits */
3583cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_PRIVATE	2
3593cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_SHARED	3
3603cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_PRIVATE	4
3613cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_SHARED	5
36282df3973SRoland McGrath #define MMF_DUMP_ELF_HEADERS	6
3633cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_SHIFT	MMF_DUMPABLE_BITS
36482df3973SRoland McGrath #define MMF_DUMP_FILTER_BITS	5
3653cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_MASK \
3663cb4a0bbSKawai, Hidehiro 	(((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
3673cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_DEFAULT \
3683cb4a0bbSKawai, Hidehiro 	((1 << MMF_DUMP_ANON_PRIVATE) |	(1 << MMF_DUMP_ANON_SHARED))
3696c5d5238SKawai, Hidehiro 
3701da177e4SLinus Torvalds struct sighand_struct {
3711da177e4SLinus Torvalds 	atomic_t		count;
3721da177e4SLinus Torvalds 	struct k_sigaction	action[_NSIG];
3731da177e4SLinus Torvalds 	spinlock_t		siglock;
374b8fceee1SDavide Libenzi 	wait_queue_head_t	signalfd_wqh;
3751da177e4SLinus Torvalds };
3761da177e4SLinus Torvalds 
3770e464814SKaiGai Kohei struct pacct_struct {
378f6ec29a4SKaiGai Kohei 	int			ac_flag;
379f6ec29a4SKaiGai Kohei 	long			ac_exitcode;
3800e464814SKaiGai Kohei 	unsigned long		ac_mem;
38177787bfbSKaiGai Kohei 	cputime_t		ac_utime, ac_stime;
38277787bfbSKaiGai Kohei 	unsigned long		ac_minflt, ac_majflt;
3830e464814SKaiGai Kohei };
3840e464814SKaiGai Kohei 
3851da177e4SLinus Torvalds /*
3861da177e4SLinus Torvalds  * NOTE! "signal_struct" does not have it's own
3871da177e4SLinus Torvalds  * locking, because a shared signal_struct always
3881da177e4SLinus Torvalds  * implies a shared sighand_struct, so locking
3891da177e4SLinus Torvalds  * sighand_struct is always a proper superset of
3901da177e4SLinus Torvalds  * the locking of signal_struct.
3911da177e4SLinus Torvalds  */
3921da177e4SLinus Torvalds struct signal_struct {
3931da177e4SLinus Torvalds 	atomic_t		count;
3941da177e4SLinus Torvalds 	atomic_t		live;
3951da177e4SLinus Torvalds 
3961da177e4SLinus Torvalds 	wait_queue_head_t	wait_chldexit;	/* for wait4() */
3971da177e4SLinus Torvalds 
3981da177e4SLinus Torvalds 	/* current thread group signal load-balancing target: */
39936c8b586SIngo Molnar 	struct task_struct	*curr_target;
4001da177e4SLinus Torvalds 
4011da177e4SLinus Torvalds 	/* shared signal handling: */
4021da177e4SLinus Torvalds 	struct sigpending	shared_pending;
4031da177e4SLinus Torvalds 
4041da177e4SLinus Torvalds 	/* thread group exit support */
4051da177e4SLinus Torvalds 	int			group_exit_code;
4061da177e4SLinus Torvalds 	/* overloaded:
4071da177e4SLinus Torvalds 	 * - notify group_exit_task when ->count is equal to notify_count
4081da177e4SLinus Torvalds 	 * - everyone except group_exit_task is stopped during signal delivery
4091da177e4SLinus Torvalds 	 *   of fatal signals, group_exit_task processes the signal.
4101da177e4SLinus Torvalds 	 */
4111da177e4SLinus Torvalds 	struct task_struct	*group_exit_task;
4121da177e4SLinus Torvalds 	int			notify_count;
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds 	/* thread group stop support, overloads group_exit_code too */
4151da177e4SLinus Torvalds 	int			group_stop_count;
4161da177e4SLinus Torvalds 	unsigned int		flags; /* see SIGNAL_* flags below */
4171da177e4SLinus Torvalds 
4181da177e4SLinus Torvalds 	/* POSIX.1b Interval Timers */
4191da177e4SLinus Torvalds 	struct list_head posix_timers;
4201da177e4SLinus Torvalds 
4211da177e4SLinus Torvalds 	/* ITIMER_REAL timer for the process */
4222ff678b8SThomas Gleixner 	struct hrtimer real_timer;
42305cfb614SRoman Zippel 	struct task_struct *tsk;
4242ff678b8SThomas Gleixner 	ktime_t it_real_incr;
4251da177e4SLinus Torvalds 
4261da177e4SLinus Torvalds 	/* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
4271da177e4SLinus Torvalds 	cputime_t it_prof_expires, it_virt_expires;
4281da177e4SLinus Torvalds 	cputime_t it_prof_incr, it_virt_incr;
4291da177e4SLinus Torvalds 
4301da177e4SLinus Torvalds 	/* job control IDs */
4311da177e4SLinus Torvalds 	pid_t pgrp;
432ab521dc0SEric W. Biederman 	struct pid *tty_old_pgrp;
4331ec320afSCedric Le Goater 
4341ec320afSCedric Le Goater 	union {
4351ec320afSCedric Le Goater 		pid_t session __deprecated;
4361ec320afSCedric Le Goater 		pid_t __session;
4371ec320afSCedric Le Goater 	};
4381ec320afSCedric Le Goater 
4391da177e4SLinus Torvalds 	/* boolean value for session group leader */
4401da177e4SLinus Torvalds 	int leader;
4411da177e4SLinus Torvalds 
4421da177e4SLinus Torvalds 	struct tty_struct *tty; /* NULL if no tty */
4431da177e4SLinus Torvalds 
4441da177e4SLinus Torvalds 	/*
4451da177e4SLinus Torvalds 	 * Cumulative resource counters for dead threads in the group,
4461da177e4SLinus Torvalds 	 * and for reaped dead child processes forked by this group.
4471da177e4SLinus Torvalds 	 * Live threads maintain their own counters and add to these
4481da177e4SLinus Torvalds 	 * in __exit_signal, except for the group leader.
4491da177e4SLinus Torvalds 	 */
4501da177e4SLinus Torvalds 	cputime_t utime, stime, cutime, cstime;
4519ac52315SLaurent Vivier 	cputime_t gtime;
4529ac52315SLaurent Vivier 	cputime_t cgtime;
4531da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
4541da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
4556eaeeabaSEric Dumazet 	unsigned long inblock, oublock, cinblock, coublock;
4561da177e4SLinus Torvalds 
4571da177e4SLinus Torvalds 	/*
4581da177e4SLinus Torvalds 	 * Cumulative ns of scheduled CPU time for dead threads in the
4591da177e4SLinus Torvalds 	 * group, not including a zombie group leader.  (This only differs
4601da177e4SLinus Torvalds 	 * from jiffies_to_ns(utime + stime) if sched_clock uses something
4611da177e4SLinus Torvalds 	 * other than jiffies.)
4621da177e4SLinus Torvalds 	 */
46341b86e9cSIngo Molnar 	unsigned long long sum_sched_runtime;
4641da177e4SLinus Torvalds 
4651da177e4SLinus Torvalds 	/*
4661da177e4SLinus Torvalds 	 * We don't bother to synchronize most readers of this at all,
4671da177e4SLinus Torvalds 	 * because there is no reader checking a limit that actually needs
4681da177e4SLinus Torvalds 	 * to get both rlim_cur and rlim_max atomically, and either one
4691da177e4SLinus Torvalds 	 * alone is a single word that can safely be read normally.
4701da177e4SLinus Torvalds 	 * getrlimit/setrlimit use task_lock(current->group_leader) to
4711da177e4SLinus Torvalds 	 * protect this instead of the siglock, because they really
4721da177e4SLinus Torvalds 	 * have no need to disable irqs.
4731da177e4SLinus Torvalds 	 */
4741da177e4SLinus Torvalds 	struct rlimit rlim[RLIM_NLIMITS];
4751da177e4SLinus Torvalds 
4761da177e4SLinus Torvalds 	struct list_head cpu_timers[3];
4771da177e4SLinus Torvalds 
4781da177e4SLinus Torvalds 	/* keep the process-shared keyrings here so that they do the right
4791da177e4SLinus Torvalds 	 * thing in threads created with CLONE_THREAD */
4801da177e4SLinus Torvalds #ifdef CONFIG_KEYS
4811da177e4SLinus Torvalds 	struct key *session_keyring;	/* keyring inherited over fork */
4821da177e4SLinus Torvalds 	struct key *process_keyring;	/* keyring private to this process */
4831da177e4SLinus Torvalds #endif
4840e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT
4850e464814SKaiGai Kohei 	struct pacct_struct pacct;	/* per-process accounting information */
4860e464814SKaiGai Kohei #endif
487ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS
488ad4ecbcbSShailabh Nagar 	struct taskstats *stats;
489ad4ecbcbSShailabh Nagar #endif
490522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT
491522ed776SMiloslav Trmac 	unsigned audit_tty;
492522ed776SMiloslav Trmac 	struct tty_audit_buf *tty_audit_buf;
493522ed776SMiloslav Trmac #endif
4941da177e4SLinus Torvalds };
4951da177e4SLinus Torvalds 
4964866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */
4974866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
4984866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW
4994866cde0SNick Piggin #endif
5004866cde0SNick Piggin 
5011da177e4SLinus Torvalds /*
5021da177e4SLinus Torvalds  * Bits in flags field of signal_struct.
5031da177e4SLinus Torvalds  */
5041da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED	0x00000001 /* job control stop in effect */
5051da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED	0x00000002 /* stop signal dequeued */
5061da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED	0x00000004 /* SIGCONT since WCONTINUED reap */
5071da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT	0x00000008 /* group exit in progress */
5081da177e4SLinus Torvalds 
5091da177e4SLinus Torvalds /*
5101da177e4SLinus Torvalds  * Some day this will be a full-fledged user tracking system..
5111da177e4SLinus Torvalds  */
5121da177e4SLinus Torvalds struct user_struct {
5131da177e4SLinus Torvalds 	atomic_t __count;	/* reference count */
5141da177e4SLinus Torvalds 	atomic_t processes;	/* How many processes does this user have? */
5151da177e4SLinus Torvalds 	atomic_t files;		/* How many open files does this user have? */
5161da177e4SLinus Torvalds 	atomic_t sigpending;	/* How many pending signals does this user have? */
5172d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
5180eeca283SRobert Love 	atomic_t inotify_watches; /* How many inotify watches does this user have? */
5190eeca283SRobert Love 	atomic_t inotify_devs;	/* How many inotify devs does this user have opened? */
5200eeca283SRobert Love #endif
521970a8645SAlexey Dobriyan #ifdef CONFIG_POSIX_MQUEUE
5221da177e4SLinus Torvalds 	/* protected by mq_lock	*/
5231da177e4SLinus Torvalds 	unsigned long mq_bytes;	/* How many bytes can be allocated to mqueue? */
524970a8645SAlexey Dobriyan #endif
5251da177e4SLinus Torvalds 	unsigned long locked_shm; /* How many pages of mlocked shm ? */
5261da177e4SLinus Torvalds 
5271da177e4SLinus Torvalds #ifdef CONFIG_KEYS
5281da177e4SLinus Torvalds 	struct key *uid_keyring;	/* UID specific keyring */
5291da177e4SLinus Torvalds 	struct key *session_keyring;	/* UID's default session keyring */
5301da177e4SLinus Torvalds #endif
5311da177e4SLinus Torvalds 
5321da177e4SLinus Torvalds 	/* Hash table maintenance information */
533735de223SPavel Emelyanov 	struct hlist_node uidhash_node;
5341da177e4SLinus Torvalds 	uid_t uid;
53524e377a8SSrivatsa Vaddagiri 
53624e377a8SSrivatsa Vaddagiri #ifdef CONFIG_FAIR_USER_SCHED
5374cf86d77SIngo Molnar 	struct task_group *tg;
538b1a8c172SDhaval Giani #ifdef CONFIG_SYSFS
5395cb350baSDhaval Giani 	struct kset kset;
5405cb350baSDhaval Giani 	struct subsys_attribute user_attr;
5415cb350baSDhaval Giani 	struct work_struct work;
54224e377a8SSrivatsa Vaddagiri #endif
543b1a8c172SDhaval Giani #endif
5441da177e4SLinus Torvalds };
5451da177e4SLinus Torvalds 
5465cb350baSDhaval Giani #ifdef CONFIG_FAIR_USER_SCHED
5475cb350baSDhaval Giani extern int uids_kobject_init(void);
5485cb350baSDhaval Giani #else
5495cb350baSDhaval Giani static inline int uids_kobject_init(void) { return 0; }
5505cb350baSDhaval Giani #endif
5515cb350baSDhaval Giani 
5521da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t);
5531da177e4SLinus Torvalds 
5541da177e4SLinus Torvalds extern struct user_struct root_user;
5551da177e4SLinus Torvalds #define INIT_USER (&root_user)
5561da177e4SLinus Torvalds 
5571da177e4SLinus Torvalds struct backing_dev_info;
5581da177e4SLinus Torvalds struct reclaim_state;
5591da177e4SLinus Torvalds 
56052f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
5611da177e4SLinus Torvalds struct sched_info {
5621da177e4SLinus Torvalds 	/* cumulative counters */
5632d72376bSIngo Molnar 	unsigned long pcount;	      /* # of times run on this cpu */
564172ba844SBalbir Singh 	unsigned long long cpu_time,  /* time spent on the cpu */
565172ba844SBalbir Singh 			   run_delay; /* time spent waiting on a runqueue */
5661da177e4SLinus Torvalds 
5671da177e4SLinus Torvalds 	/* timestamps */
568172ba844SBalbir Singh 	unsigned long long last_arrival,/* when we last ran on a cpu */
5691da177e4SLinus Torvalds 			   last_queued;	/* when we were last queued to run */
570b8efb561SIngo Molnar #ifdef CONFIG_SCHEDSTATS
571b8efb561SIngo Molnar 	/* BKL stats */
572480b9434SKen Chen 	unsigned int bkl_count;
573b8efb561SIngo Molnar #endif
5741da177e4SLinus Torvalds };
57552f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
5761da177e4SLinus Torvalds 
57752f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS
57815ad7cdcSHelge Deller extern const struct file_operations proc_schedstat_operations;
57952f17b6cSChandra Seetharaman #endif /* CONFIG_SCHEDSTATS */
5801da177e4SLinus Torvalds 
581ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT
582ca74e92bSShailabh Nagar struct task_delay_info {
583ca74e92bSShailabh Nagar 	spinlock_t	lock;
584ca74e92bSShailabh Nagar 	unsigned int	flags;	/* Private per-task flags */
585ca74e92bSShailabh Nagar 
586ca74e92bSShailabh Nagar 	/* For each stat XXX, add following, aligned appropriately
587ca74e92bSShailabh Nagar 	 *
588ca74e92bSShailabh Nagar 	 * struct timespec XXX_start, XXX_end;
589ca74e92bSShailabh Nagar 	 * u64 XXX_delay;
590ca74e92bSShailabh Nagar 	 * u32 XXX_count;
591ca74e92bSShailabh Nagar 	 *
592ca74e92bSShailabh Nagar 	 * Atomicity of updates to XXX_delay, XXX_count protected by
593ca74e92bSShailabh Nagar 	 * single lock above (split into XXX_lock if contention is an issue).
594ca74e92bSShailabh Nagar 	 */
5950ff92245SShailabh Nagar 
5960ff92245SShailabh Nagar 	/*
5970ff92245SShailabh Nagar 	 * XXX_count is incremented on every XXX operation, the delay
5980ff92245SShailabh Nagar 	 * associated with the operation is added to XXX_delay.
5990ff92245SShailabh Nagar 	 * XXX_delay contains the accumulated delay time in nanoseconds.
6000ff92245SShailabh Nagar 	 */
6010ff92245SShailabh Nagar 	struct timespec blkio_start, blkio_end;	/* Shared by blkio, swapin */
6020ff92245SShailabh Nagar 	u64 blkio_delay;	/* wait for sync block io completion */
6030ff92245SShailabh Nagar 	u64 swapin_delay;	/* wait for swapin block io completion */
6040ff92245SShailabh Nagar 	u32 blkio_count;	/* total count of the number of sync block */
6050ff92245SShailabh Nagar 				/* io operations performed */
6060ff92245SShailabh Nagar 	u32 swapin_count;	/* total count of the number of swapin block */
6070ff92245SShailabh Nagar 				/* io operations performed */
608ca74e92bSShailabh Nagar };
60952f17b6cSChandra Seetharaman #endif	/* CONFIG_TASK_DELAY_ACCT */
61052f17b6cSChandra Seetharaman 
61152f17b6cSChandra Seetharaman static inline int sched_info_on(void)
61252f17b6cSChandra Seetharaman {
61352f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS
61452f17b6cSChandra Seetharaman 	return 1;
61552f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT)
61652f17b6cSChandra Seetharaman 	extern int delayacct_on;
61752f17b6cSChandra Seetharaman 	return delayacct_on;
61852f17b6cSChandra Seetharaman #else
61952f17b6cSChandra Seetharaman 	return 0;
620ca74e92bSShailabh Nagar #endif
62152f17b6cSChandra Seetharaman }
622ca74e92bSShailabh Nagar 
623d15bcfdbSIngo Molnar enum cpu_idle_type {
624d15bcfdbSIngo Molnar 	CPU_IDLE,
625d15bcfdbSIngo Molnar 	CPU_NOT_IDLE,
626d15bcfdbSIngo Molnar 	CPU_NEWLY_IDLE,
627d15bcfdbSIngo Molnar 	CPU_MAX_IDLE_TYPES
6281da177e4SLinus Torvalds };
6291da177e4SLinus Torvalds 
6301da177e4SLinus Torvalds /*
6311da177e4SLinus Torvalds  * sched-domains (multiprocessor balancing) declarations:
6321da177e4SLinus Torvalds  */
6339aa7b369SIngo Molnar 
6349aa7b369SIngo Molnar /*
6359aa7b369SIngo Molnar  * Increase resolution of nice-level calculations:
6369aa7b369SIngo Molnar  */
6379aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT	10
6389aa7b369SIngo Molnar #define SCHED_LOAD_SCALE	(1L << SCHED_LOAD_SHIFT)
6399aa7b369SIngo Molnar 
640f8700df7SSuresh Siddha #define SCHED_LOAD_SCALE_FUZZ	SCHED_LOAD_SCALE
6411da177e4SLinus Torvalds 
6422dd73a4fSPeter Williams #ifdef CONFIG_SMP
6431da177e4SLinus Torvalds #define SD_LOAD_BALANCE		1	/* Do load balancing on this domain. */
6441da177e4SLinus Torvalds #define SD_BALANCE_NEWIDLE	2	/* Balance when about to become idle */
6451da177e4SLinus Torvalds #define SD_BALANCE_EXEC		4	/* Balance on exec */
646147cbb4bSNick Piggin #define SD_BALANCE_FORK		8	/* Balance on fork, clone */
647147cbb4bSNick Piggin #define SD_WAKE_IDLE		16	/* Wake to idle CPU on task wakeup */
648147cbb4bSNick Piggin #define SD_WAKE_AFFINE		32	/* Wake task to waking CPU */
649147cbb4bSNick Piggin #define SD_WAKE_BALANCE		64	/* Perform balancing at task wakeup */
650147cbb4bSNick Piggin #define SD_SHARE_CPUPOWER	128	/* Domain members share cpu power */
6515c45bf27SSiddha, Suresh B #define SD_POWERSAVINGS_BALANCE	256	/* Balance for power savings */
65289c4710eSSiddha, Suresh B #define SD_SHARE_PKG_RESOURCES	512	/* Domain members share cpu pkg resources */
65308c183f3SChristoph Lameter #define SD_SERIALIZE		1024	/* Only a single load balancing instance */
6545c45bf27SSiddha, Suresh B 
65589c4710eSSiddha, Suresh B #define BALANCE_FOR_MC_POWER	\
65689c4710eSSiddha, Suresh B 	(sched_smt_power_savings ? SD_POWERSAVINGS_BALANCE : 0)
65789c4710eSSiddha, Suresh B 
65889c4710eSSiddha, Suresh B #define BALANCE_FOR_PKG_POWER	\
65989c4710eSSiddha, Suresh B 	((sched_mc_power_savings || sched_smt_power_savings) ?	\
66089c4710eSSiddha, Suresh B 	 SD_POWERSAVINGS_BALANCE : 0)
66189c4710eSSiddha, Suresh B 
66289c4710eSSiddha, Suresh B #define test_sd_parent(sd, flag)	((sd->parent &&		\
66389c4710eSSiddha, Suresh B 					 (sd->parent->flags & flag)) ? 1 : 0)
6645c45bf27SSiddha, Suresh B 
6651da177e4SLinus Torvalds 
6661da177e4SLinus Torvalds struct sched_group {
6671da177e4SLinus Torvalds 	struct sched_group *next;	/* Must be a circular list */
6681da177e4SLinus Torvalds 	cpumask_t cpumask;
6691da177e4SLinus Torvalds 
6701da177e4SLinus Torvalds 	/*
6711da177e4SLinus Torvalds 	 * CPU power of this group, SCHED_LOAD_SCALE being max power for a
6721da177e4SLinus Torvalds 	 * single CPU. This is read only (except for setup, hotplug CPU).
6735517d86bSEric Dumazet 	 * Note : Never change cpu_power without recompute its reciprocal
6741da177e4SLinus Torvalds 	 */
6755517d86bSEric Dumazet 	unsigned int __cpu_power;
6765517d86bSEric Dumazet 	/*
6775517d86bSEric Dumazet 	 * reciprocal value of cpu_power to avoid expensive divides
6785517d86bSEric Dumazet 	 * (see include/linux/reciprocal_div.h)
6795517d86bSEric Dumazet 	 */
6805517d86bSEric Dumazet 	u32 reciprocal_cpu_power;
6811da177e4SLinus Torvalds };
6821da177e4SLinus Torvalds 
6831da177e4SLinus Torvalds struct sched_domain {
6841da177e4SLinus Torvalds 	/* These fields must be setup */
6851da177e4SLinus Torvalds 	struct sched_domain *parent;	/* top domain must be null terminated */
6861a848870SSiddha, Suresh B 	struct sched_domain *child;	/* bottom domain must be null terminated */
6871da177e4SLinus Torvalds 	struct sched_group *groups;	/* the balancing groups of the domain */
6881da177e4SLinus Torvalds 	cpumask_t span;			/* span of all CPUs in this domain */
6891da177e4SLinus Torvalds 	unsigned long min_interval;	/* Minimum balance interval ms */
6901da177e4SLinus Torvalds 	unsigned long max_interval;	/* Maximum balance interval ms */
6911da177e4SLinus Torvalds 	unsigned int busy_factor;	/* less balancing by factor if busy */
6921da177e4SLinus Torvalds 	unsigned int imbalance_pct;	/* No balance until over watermark */
6931da177e4SLinus Torvalds 	unsigned int cache_nice_tries;	/* Leave cache hot tasks for # tries */
6947897986bSNick Piggin 	unsigned int busy_idx;
6957897986bSNick Piggin 	unsigned int idle_idx;
6967897986bSNick Piggin 	unsigned int newidle_idx;
6977897986bSNick Piggin 	unsigned int wake_idx;
698147cbb4bSNick Piggin 	unsigned int forkexec_idx;
6991da177e4SLinus Torvalds 	int flags;			/* See SD_* */
7001da177e4SLinus Torvalds 
7011da177e4SLinus Torvalds 	/* Runtime fields. */
7021da177e4SLinus Torvalds 	unsigned long last_balance;	/* init to jiffies. units in jiffies */
7031da177e4SLinus Torvalds 	unsigned int balance_interval;	/* initialise to 1. units in ms. */
7041da177e4SLinus Torvalds 	unsigned int nr_balance_failed; /* initialise to 0 */
7051da177e4SLinus Torvalds 
7061da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS
7071da177e4SLinus Torvalds 	/* load_balance() stats */
708480b9434SKen Chen 	unsigned int lb_count[CPU_MAX_IDLE_TYPES];
709480b9434SKen Chen 	unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
710480b9434SKen Chen 	unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
711480b9434SKen Chen 	unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
712480b9434SKen Chen 	unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
713480b9434SKen Chen 	unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
714480b9434SKen Chen 	unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
715480b9434SKen Chen 	unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
7161da177e4SLinus Torvalds 
7171da177e4SLinus Torvalds 	/* Active load balancing */
718480b9434SKen Chen 	unsigned int alb_count;
719480b9434SKen Chen 	unsigned int alb_failed;
720480b9434SKen Chen 	unsigned int alb_pushed;
7211da177e4SLinus Torvalds 
72268767a0aSNick Piggin 	/* SD_BALANCE_EXEC stats */
723480b9434SKen Chen 	unsigned int sbe_count;
724480b9434SKen Chen 	unsigned int sbe_balanced;
725480b9434SKen Chen 	unsigned int sbe_pushed;
7261da177e4SLinus Torvalds 
72768767a0aSNick Piggin 	/* SD_BALANCE_FORK stats */
728480b9434SKen Chen 	unsigned int sbf_count;
729480b9434SKen Chen 	unsigned int sbf_balanced;
730480b9434SKen Chen 	unsigned int sbf_pushed;
73168767a0aSNick Piggin 
7321da177e4SLinus Torvalds 	/* try_to_wake_up() stats */
733480b9434SKen Chen 	unsigned int ttwu_wake_remote;
734480b9434SKen Chen 	unsigned int ttwu_move_affine;
735480b9434SKen Chen 	unsigned int ttwu_move_balance;
7361da177e4SLinus Torvalds #endif
7371da177e4SLinus Torvalds };
7381da177e4SLinus Torvalds 
7391da177e4SLinus Torvalds #endif	/* CONFIG_SMP */
7401da177e4SLinus Torvalds 
741d02c7a8cSCon Kolivas /*
742d02c7a8cSCon Kolivas  * A runqueue laden with a single nice 0 task scores a weighted_cpuload of
743d02c7a8cSCon Kolivas  * SCHED_LOAD_SCALE. This function returns 1 if any cpu is laden with a
744d02c7a8cSCon Kolivas  * task of nice 0 or enough lower priority tasks to bring up the
745d02c7a8cSCon Kolivas  * weighted_cpuload
746d02c7a8cSCon Kolivas  */
747d02c7a8cSCon Kolivas static inline int above_background_load(void)
748d02c7a8cSCon Kolivas {
749d02c7a8cSCon Kolivas 	unsigned long cpu;
750d02c7a8cSCon Kolivas 
751d02c7a8cSCon Kolivas 	for_each_online_cpu(cpu) {
752d02c7a8cSCon Kolivas 		if (weighted_cpuload(cpu) >= SCHED_LOAD_SCALE)
753d02c7a8cSCon Kolivas 			return 1;
754d02c7a8cSCon Kolivas 	}
755d02c7a8cSCon Kolivas 	return 0;
756d02c7a8cSCon Kolivas }
7571da177e4SLinus Torvalds 
7581da177e4SLinus Torvalds struct io_context;			/* See blkdev.h */
7591da177e4SLinus Torvalds struct cpuset;
7601da177e4SLinus Torvalds 
7611da177e4SLinus Torvalds #define NGROUPS_SMALL		32
7621da177e4SLinus Torvalds #define NGROUPS_PER_BLOCK	((int)(PAGE_SIZE / sizeof(gid_t)))
7631da177e4SLinus Torvalds struct group_info {
7641da177e4SLinus Torvalds 	int ngroups;
7651da177e4SLinus Torvalds 	atomic_t usage;
7661da177e4SLinus Torvalds 	gid_t small_block[NGROUPS_SMALL];
7671da177e4SLinus Torvalds 	int nblocks;
7681da177e4SLinus Torvalds 	gid_t *blocks[0];
7691da177e4SLinus Torvalds };
7701da177e4SLinus Torvalds 
7711da177e4SLinus Torvalds /*
7721da177e4SLinus Torvalds  * get_group_info() must be called with the owning task locked (via task_lock())
7731da177e4SLinus Torvalds  * when task != current.  The reason being that the vast majority of callers are
7741da177e4SLinus Torvalds  * looking at current->group_info, which can not be changed except by the
7751da177e4SLinus Torvalds  * current task.  Changing current->group_info requires the task lock, too.
7761da177e4SLinus Torvalds  */
7771da177e4SLinus Torvalds #define get_group_info(group_info) do { \
7781da177e4SLinus Torvalds 	atomic_inc(&(group_info)->usage); \
7791da177e4SLinus Torvalds } while (0)
7801da177e4SLinus Torvalds 
7811da177e4SLinus Torvalds #define put_group_info(group_info) do { \
7821da177e4SLinus Torvalds 	if (atomic_dec_and_test(&(group_info)->usage)) \
7831da177e4SLinus Torvalds 		groups_free(group_info); \
7841da177e4SLinus Torvalds } while (0)
7851da177e4SLinus Torvalds 
7863e30148cSDavid Howells extern struct group_info *groups_alloc(int gidsetsize);
7873e30148cSDavid Howells extern void groups_free(struct group_info *group_info);
7883e30148cSDavid Howells extern int set_current_groups(struct group_info *group_info);
7893e30148cSDavid Howells extern int groups_search(struct group_info *group_info, gid_t grp);
7901da177e4SLinus Torvalds /* access the groups "array" with this macro */
7911da177e4SLinus Torvalds #define GROUP_AT(gi, i) \
7921da177e4SLinus Torvalds     ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK])
7931da177e4SLinus Torvalds 
794383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
79536c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t);
796383f2835SChen, Kenneth W #else
797383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { }
798383f2835SChen, Kenneth W #endif
7991da177e4SLinus Torvalds 
8001da177e4SLinus Torvalds struct audit_context;		/* See audit.c */
8011da177e4SLinus Torvalds struct mempolicy;
802b92ce558SJens Axboe struct pipe_inode_info;
8034865ecf1SSerge E. Hallyn struct uts_namespace;
8041da177e4SLinus Torvalds 
80520b8a59fSIngo Molnar struct rq;
80620b8a59fSIngo Molnar struct sched_domain;
80720b8a59fSIngo Molnar 
80820b8a59fSIngo Molnar struct sched_class {
8095522d5d5SIngo Molnar 	const struct sched_class *next;
81020b8a59fSIngo Molnar 
811fd390f6aSIngo Molnar 	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup);
812f02231e5SIngo Molnar 	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep);
8134530d7abSDmitry Adamushko 	void (*yield_task) (struct rq *rq);
81420b8a59fSIngo Molnar 
81520b8a59fSIngo Molnar 	void (*check_preempt_curr) (struct rq *rq, struct task_struct *p);
81620b8a59fSIngo Molnar 
817fb8d4724SIngo Molnar 	struct task_struct * (*pick_next_task) (struct rq *rq);
81831ee529cSIngo Molnar 	void (*put_prev_task) (struct rq *rq, struct task_struct *p);
81920b8a59fSIngo Molnar 
82043010659SPeter Williams 	unsigned long (*load_balance) (struct rq *this_rq, int this_cpu,
82120b8a59fSIngo Molnar 			struct rq *busiest,
82220b8a59fSIngo Molnar 			unsigned long max_nr_move, unsigned long max_load_move,
82320b8a59fSIngo Molnar 			struct sched_domain *sd, enum cpu_idle_type idle,
824a4ac01c3SPeter Williams 			int *all_pinned, int *this_best_prio);
82520b8a59fSIngo Molnar 
82683b699edSSrivatsa Vaddagiri 	void (*set_curr_task) (struct rq *rq);
82720b8a59fSIngo Molnar 	void (*task_tick) (struct rq *rq, struct task_struct *p);
828ee0827d8SIngo Molnar 	void (*task_new) (struct rq *rq, struct task_struct *p);
82920b8a59fSIngo Molnar };
83020b8a59fSIngo Molnar 
83120b8a59fSIngo Molnar struct load_weight {
83220b8a59fSIngo Molnar 	unsigned long weight, inv_weight;
83320b8a59fSIngo Molnar };
83420b8a59fSIngo Molnar 
83520b8a59fSIngo Molnar /*
83620b8a59fSIngo Molnar  * CFS stats for a schedulable entity (task, task-group etc)
83720b8a59fSIngo Molnar  *
83820b8a59fSIngo Molnar  * Current field usage histogram:
83920b8a59fSIngo Molnar  *
84020b8a59fSIngo Molnar  *     4 se->block_start
84120b8a59fSIngo Molnar  *     4 se->run_node
84220b8a59fSIngo Molnar  *     4 se->sleep_start
84320b8a59fSIngo Molnar  *     6 se->load.weight
84420b8a59fSIngo Molnar  */
84520b8a59fSIngo Molnar struct sched_entity {
84620b8a59fSIngo Molnar 	struct load_weight	load;		/* for load-balancing */
84720b8a59fSIngo Molnar 	struct rb_node		run_node;
84820b8a59fSIngo Molnar 	unsigned int		on_rq;
84995938a35SMike Galbraith 	int			peer_preempt;
85020b8a59fSIngo Molnar 
85120b8a59fSIngo Molnar 	u64			exec_start;
85294c18227SIngo Molnar 	u64			sum_exec_runtime;
853e9acbff6SIngo Molnar 	u64			vruntime;
854f6cf891cSIngo Molnar 	u64			prev_sum_exec_runtime;
85594c18227SIngo Molnar 
85694c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS
85794c18227SIngo Molnar 	u64			wait_start;
85894c18227SIngo Molnar 	u64			wait_max;
85994c18227SIngo Molnar 
86094c18227SIngo Molnar 	u64			sleep_start;
86120b8a59fSIngo Molnar 	u64			sleep_max;
86294c18227SIngo Molnar 	s64			sum_sleep_runtime;
86394c18227SIngo Molnar 
86494c18227SIngo Molnar 	u64			block_start;
86520b8a59fSIngo Molnar 	u64			block_max;
86620b8a59fSIngo Molnar 	u64			exec_max;
867eba1ed4bSIngo Molnar 	u64			slice_max;
868cc367732SIngo Molnar 
869cc367732SIngo Molnar 	u64			nr_migrations;
870cc367732SIngo Molnar 	u64			nr_migrations_cold;
871cc367732SIngo Molnar 	u64			nr_failed_migrations_affine;
872cc367732SIngo Molnar 	u64			nr_failed_migrations_running;
873cc367732SIngo Molnar 	u64			nr_failed_migrations_hot;
874cc367732SIngo Molnar 	u64			nr_forced_migrations;
875cc367732SIngo Molnar 	u64			nr_forced2_migrations;
876cc367732SIngo Molnar 
877cc367732SIngo Molnar 	u64			nr_wakeups;
878cc367732SIngo Molnar 	u64			nr_wakeups_sync;
879cc367732SIngo Molnar 	u64			nr_wakeups_migrate;
880cc367732SIngo Molnar 	u64			nr_wakeups_local;
881cc367732SIngo Molnar 	u64			nr_wakeups_remote;
882cc367732SIngo Molnar 	u64			nr_wakeups_affine;
883cc367732SIngo Molnar 	u64			nr_wakeups_affine_attempts;
884cc367732SIngo Molnar 	u64			nr_wakeups_passive;
885cc367732SIngo Molnar 	u64			nr_wakeups_idle;
88694c18227SIngo Molnar #endif
88794c18227SIngo Molnar 
88820b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED
88920b8a59fSIngo Molnar 	struct sched_entity	*parent;
89020b8a59fSIngo Molnar 	/* rq on which this entity is (to be) queued: */
89120b8a59fSIngo Molnar 	struct cfs_rq		*cfs_rq;
89220b8a59fSIngo Molnar 	/* rq "owned" by this entity/group: */
89320b8a59fSIngo Molnar 	struct cfs_rq		*my_q;
89420b8a59fSIngo Molnar #endif
89520b8a59fSIngo Molnar };
89670b97a7fSIngo Molnar 
897*ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS
898*ddbcc7e8SPaul Menage 
899*ddbcc7e8SPaul Menage #define SUBSYS(_x) _x ## _subsys_id,
900*ddbcc7e8SPaul Menage enum cgroup_subsys_id {
901*ddbcc7e8SPaul Menage #include <linux/cgroup_subsys.h>
902*ddbcc7e8SPaul Menage 	CGROUP_SUBSYS_COUNT
903*ddbcc7e8SPaul Menage };
904*ddbcc7e8SPaul Menage #undef SUBSYS
905*ddbcc7e8SPaul Menage 
906*ddbcc7e8SPaul Menage /* A css_set is a structure holding pointers to a set of
907*ddbcc7e8SPaul Menage  * cgroup_subsys_state objects.
908*ddbcc7e8SPaul Menage  */
909*ddbcc7e8SPaul Menage 
910*ddbcc7e8SPaul Menage struct css_set {
911*ddbcc7e8SPaul Menage 
912*ddbcc7e8SPaul Menage 	/* Set of subsystem states, one for each subsystem. NULL for
913*ddbcc7e8SPaul Menage 	 * subsystems that aren't part of this hierarchy. These
914*ddbcc7e8SPaul Menage 	 * pointers reduce the number of dereferences required to get
915*ddbcc7e8SPaul Menage 	 * from a task to its state for a given cgroup, but result
916*ddbcc7e8SPaul Menage 	 * in increased space usage if tasks are in wildly different
917*ddbcc7e8SPaul Menage 	 * groupings across different hierarchies. This array is
918*ddbcc7e8SPaul Menage 	 * immutable after creation */
919*ddbcc7e8SPaul Menage 	struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT];
920*ddbcc7e8SPaul Menage 
921*ddbcc7e8SPaul Menage };
922*ddbcc7e8SPaul Menage 
923*ddbcc7e8SPaul Menage #endif /* CONFIG_CGROUPS */
924*ddbcc7e8SPaul Menage 
9251da177e4SLinus Torvalds struct task_struct {
9261da177e4SLinus Torvalds 	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
927f7e4217bSRoman Zippel 	void *stack;
9281da177e4SLinus Torvalds 	atomic_t usage;
92997dc32cdSWilliam Cohen 	unsigned int flags;	/* per process flags, defined below */
93097dc32cdSWilliam Cohen 	unsigned int ptrace;
9311da177e4SLinus Torvalds 
93236772092SPaolo 'Blaisorblade' Giarrusso 	int lock_depth;		/* BKL lock depth */
9331da177e4SLinus Torvalds 
9342dd73a4fSPeter Williams #ifdef CONFIG_SMP
9352dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW
9364866cde0SNick Piggin 	int oncpu;
9374866cde0SNick Piggin #endif
9382dd73a4fSPeter Williams #endif
93950e645a8SIngo Molnar 
940b29739f9SIngo Molnar 	int prio, static_prio, normal_prio;
9411da177e4SLinus Torvalds 	struct list_head run_list;
9425522d5d5SIngo Molnar 	const struct sched_class *sched_class;
94320b8a59fSIngo Molnar 	struct sched_entity se;
9441da177e4SLinus Torvalds 
945e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS
946e107be36SAvi Kivity 	/* list of struct preempt_notifier: */
947e107be36SAvi Kivity 	struct hlist_head preempt_notifiers;
948e107be36SAvi Kivity #endif
949e107be36SAvi Kivity 
95022e2c507SJens Axboe 	unsigned short ioprio;
95118796aa0SAlexey Dobriyan 	/*
95218796aa0SAlexey Dobriyan 	 * fpu_counter contains the number of consecutive context switches
95318796aa0SAlexey Dobriyan 	 * that the FPU is used. If this is over a threshold, the lazy fpu
95418796aa0SAlexey Dobriyan 	 * saving becomes unlazy to save the trap. This is an unsigned char
95518796aa0SAlexey Dobriyan 	 * so that after 256 times the counter wraps and the behavior turns
95618796aa0SAlexey Dobriyan 	 * lazy again; this to deal with bursty apps that only use FPU for
95718796aa0SAlexey Dobriyan 	 * a short time
95818796aa0SAlexey Dobriyan 	 */
95918796aa0SAlexey Dobriyan 	unsigned char fpu_counter;
96018796aa0SAlexey Dobriyan 	s8 oomkilladj; /* OOM kill score adjustment (bit shift). */
9616c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE
9622056a782SJens Axboe 	unsigned int btrace_seq;
9636c5c9341SAlexey Dobriyan #endif
9641da177e4SLinus Torvalds 
96597dc32cdSWilliam Cohen 	unsigned int policy;
9661da177e4SLinus Torvalds 	cpumask_t cpus_allowed;
96750e645a8SIngo Molnar 	unsigned int time_slice;
9681da177e4SLinus Torvalds 
96952f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
9701da177e4SLinus Torvalds 	struct sched_info sched_info;
9711da177e4SLinus Torvalds #endif
9721da177e4SLinus Torvalds 
9731da177e4SLinus Torvalds 	struct list_head tasks;
9741da177e4SLinus Torvalds 	/*
9751da177e4SLinus Torvalds 	 * ptrace_list/ptrace_children forms the list of my children
9761da177e4SLinus Torvalds 	 * that were stolen by a ptracer.
9771da177e4SLinus Torvalds 	 */
9781da177e4SLinus Torvalds 	struct list_head ptrace_children;
9791da177e4SLinus Torvalds 	struct list_head ptrace_list;
9801da177e4SLinus Torvalds 
9811da177e4SLinus Torvalds 	struct mm_struct *mm, *active_mm;
9821da177e4SLinus Torvalds 
9831da177e4SLinus Torvalds /* task state */
9841da177e4SLinus Torvalds 	struct linux_binfmt *binfmt;
98597dc32cdSWilliam Cohen 	int exit_state;
9861da177e4SLinus Torvalds 	int exit_code, exit_signal;
9871da177e4SLinus Torvalds 	int pdeath_signal;  /*  The signal sent when the parent dies  */
9881da177e4SLinus Torvalds 	/* ??? */
98997dc32cdSWilliam Cohen 	unsigned int personality;
9901da177e4SLinus Torvalds 	unsigned did_exec:1;
9911da177e4SLinus Torvalds 	pid_t pid;
9921da177e4SLinus Torvalds 	pid_t tgid;
9930a425405SArjan van de Ven 
9940a425405SArjan van de Ven #ifdef CONFIG_CC_STACKPROTECTOR
9950a425405SArjan van de Ven 	/* Canary value for the -fstack-protector gcc feature */
9960a425405SArjan van de Ven 	unsigned long stack_canary;
9970a425405SArjan van de Ven #endif
9981da177e4SLinus Torvalds 	/*
9991da177e4SLinus Torvalds 	 * pointers to (original) parent process, youngest child, younger sibling,
10001da177e4SLinus Torvalds 	 * older sibling, respectively.  (p->father can be replaced with
10011da177e4SLinus Torvalds 	 * p->parent->pid)
10021da177e4SLinus Torvalds 	 */
10031da177e4SLinus Torvalds 	struct task_struct *real_parent; /* real parent process (when being debugged) */
10041da177e4SLinus Torvalds 	struct task_struct *parent;	/* parent process */
10051da177e4SLinus Torvalds 	/*
10061da177e4SLinus Torvalds 	 * children/sibling forms the list of my children plus the
10071da177e4SLinus Torvalds 	 * tasks I'm ptracing.
10081da177e4SLinus Torvalds 	 */
10091da177e4SLinus Torvalds 	struct list_head children;	/* list of my children */
10101da177e4SLinus Torvalds 	struct list_head sibling;	/* linkage in my parent's children list */
10111da177e4SLinus Torvalds 	struct task_struct *group_leader;	/* threadgroup leader */
10121da177e4SLinus Torvalds 
10131da177e4SLinus Torvalds 	/* PID/PID hash table linkage. */
101492476d7fSEric W. Biederman 	struct pid_link pids[PIDTYPE_MAX];
101547e65328SOleg Nesterov 	struct list_head thread_group;
10161da177e4SLinus Torvalds 
10171da177e4SLinus Torvalds 	struct completion *vfork_done;		/* for vfork() */
10181da177e4SLinus Torvalds 	int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
10191da177e4SLinus Torvalds 	int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */
10201da177e4SLinus Torvalds 
102197dc32cdSWilliam Cohen 	unsigned int rt_priority;
1022c66f08beSMichael Neuling 	cputime_t utime, stime, utimescaled, stimescaled;
10239ac52315SLaurent Vivier 	cputime_t gtime;
10241da177e4SLinus Torvalds 	unsigned long nvcsw, nivcsw; /* context switch counts */
1025924b42d5STomas Janousek 	struct timespec start_time; 		/* monotonic time */
1026924b42d5STomas Janousek 	struct timespec real_start_time;	/* boot based time */
10271da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
10281da177e4SLinus Torvalds 	unsigned long min_flt, maj_flt;
10291da177e4SLinus Torvalds 
10301da177e4SLinus Torvalds   	cputime_t it_prof_expires, it_virt_expires;
10311da177e4SLinus Torvalds 	unsigned long long it_sched_expires;
10321da177e4SLinus Torvalds 	struct list_head cpu_timers[3];
10331da177e4SLinus Torvalds 
10341da177e4SLinus Torvalds /* process credentials */
10351da177e4SLinus Torvalds 	uid_t uid,euid,suid,fsuid;
10361da177e4SLinus Torvalds 	gid_t gid,egid,sgid,fsgid;
10371da177e4SLinus Torvalds 	struct group_info *group_info;
10381da177e4SLinus Torvalds 	kernel_cap_t   cap_effective, cap_inheritable, cap_permitted;
10391da177e4SLinus Torvalds 	unsigned keep_capabilities:1;
10401da177e4SLinus Torvalds 	struct user_struct *user;
10411da177e4SLinus Torvalds #ifdef CONFIG_KEYS
1042b5f545c8SDavid Howells 	struct key *request_key_auth;	/* assumed request_key authority */
10431da177e4SLinus Torvalds 	struct key *thread_keyring;	/* keyring private to this thread */
10443e30148cSDavid Howells 	unsigned char jit_keyring;	/* default keyring to attach requested keys to */
10451da177e4SLinus Torvalds #endif
104636772092SPaolo 'Blaisorblade' Giarrusso 	char comm[TASK_COMM_LEN]; /* executable name excluding path
104736772092SPaolo 'Blaisorblade' Giarrusso 				     - access with [gs]et_task_comm (which lock
104836772092SPaolo 'Blaisorblade' Giarrusso 				       it with task_lock())
104936772092SPaolo 'Blaisorblade' Giarrusso 				     - initialized normally by flush_old_exec */
10501da177e4SLinus Torvalds /* file system info */
10511da177e4SLinus Torvalds 	int link_count, total_link_count;
10523d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC
10531da177e4SLinus Torvalds /* ipc stuff */
10541da177e4SLinus Torvalds 	struct sysv_sem sysvsem;
10553d5b6fccSAlexey Dobriyan #endif
10561da177e4SLinus Torvalds /* CPU-specific state of this task */
10571da177e4SLinus Torvalds 	struct thread_struct thread;
10581da177e4SLinus Torvalds /* filesystem information */
10591da177e4SLinus Torvalds 	struct fs_struct *fs;
10601da177e4SLinus Torvalds /* open file information */
10611da177e4SLinus Torvalds 	struct files_struct *files;
10621651e14eSSerge E. Hallyn /* namespaces */
1063ab516013SSerge E. Hallyn 	struct nsproxy *nsproxy;
10641da177e4SLinus Torvalds /* signal handlers */
10651da177e4SLinus Torvalds 	struct signal_struct *signal;
10661da177e4SLinus Torvalds 	struct sighand_struct *sighand;
10671da177e4SLinus Torvalds 
10681da177e4SLinus Torvalds 	sigset_t blocked, real_blocked;
1069150256d8SDavid Woodhouse 	sigset_t saved_sigmask;		/* To be restored with TIF_RESTORE_SIGMASK */
10701da177e4SLinus Torvalds 	struct sigpending pending;
10711da177e4SLinus Torvalds 
10721da177e4SLinus Torvalds 	unsigned long sas_ss_sp;
10731da177e4SLinus Torvalds 	size_t sas_ss_size;
10741da177e4SLinus Torvalds 	int (*notifier)(void *priv);
10751da177e4SLinus Torvalds 	void *notifier_data;
10761da177e4SLinus Torvalds 	sigset_t *notifier_mask;
107757c521ceSAlexey Dobriyan #ifdef CONFIG_SECURITY
10781da177e4SLinus Torvalds 	void *security;
107957c521ceSAlexey Dobriyan #endif
10801da177e4SLinus Torvalds 	struct audit_context *audit_context;
10811da177e4SLinus Torvalds 	seccomp_t seccomp;
10821da177e4SLinus Torvalds 
10831da177e4SLinus Torvalds /* Thread group tracking */
10841da177e4SLinus Torvalds    	u32 parent_exec_id;
10851da177e4SLinus Torvalds    	u32 self_exec_id;
10861da177e4SLinus Torvalds /* Protection of (de-)allocation: mm, files, fs, tty, keyrings */
10871da177e4SLinus Torvalds 	spinlock_t alloc_lock;
10881da177e4SLinus Torvalds 
1089b29739f9SIngo Molnar 	/* Protection of the PI data structures: */
1090b29739f9SIngo Molnar 	spinlock_t pi_lock;
1091b29739f9SIngo Molnar 
109223f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
109323f78d4aSIngo Molnar 	/* PI waiters blocked on a rt_mutex held by this task */
109423f78d4aSIngo Molnar 	struct plist_head pi_waiters;
109523f78d4aSIngo Molnar 	/* Deadlock detection and priority inheritance handling */
109623f78d4aSIngo Molnar 	struct rt_mutex_waiter *pi_blocked_on;
109723f78d4aSIngo Molnar #endif
109823f78d4aSIngo Molnar 
1099408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES
1100408894eeSIngo Molnar 	/* mutex deadlock detection */
1101408894eeSIngo Molnar 	struct mutex_waiter *blocked_on;
1102408894eeSIngo Molnar #endif
1103de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS
1104de30a2b3SIngo Molnar 	unsigned int irq_events;
1105de30a2b3SIngo Molnar 	int hardirqs_enabled;
1106de30a2b3SIngo Molnar 	unsigned long hardirq_enable_ip;
1107de30a2b3SIngo Molnar 	unsigned int hardirq_enable_event;
1108de30a2b3SIngo Molnar 	unsigned long hardirq_disable_ip;
1109de30a2b3SIngo Molnar 	unsigned int hardirq_disable_event;
1110de30a2b3SIngo Molnar 	int softirqs_enabled;
1111de30a2b3SIngo Molnar 	unsigned long softirq_disable_ip;
1112de30a2b3SIngo Molnar 	unsigned int softirq_disable_event;
1113de30a2b3SIngo Molnar 	unsigned long softirq_enable_ip;
1114de30a2b3SIngo Molnar 	unsigned int softirq_enable_event;
1115de30a2b3SIngo Molnar 	int hardirq_context;
1116de30a2b3SIngo Molnar 	int softirq_context;
1117de30a2b3SIngo Molnar #endif
1118fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP
1119fbb9ce95SIngo Molnar # define MAX_LOCK_DEPTH 30UL
1120fbb9ce95SIngo Molnar 	u64 curr_chain_key;
1121fbb9ce95SIngo Molnar 	int lockdep_depth;
1122fbb9ce95SIngo Molnar 	struct held_lock held_locks[MAX_LOCK_DEPTH];
1123fbb9ce95SIngo Molnar 	unsigned int lockdep_recursion;
1124fbb9ce95SIngo Molnar #endif
1125408894eeSIngo Molnar 
11261da177e4SLinus Torvalds /* journalling filesystem info */
11271da177e4SLinus Torvalds 	void *journal_info;
11281da177e4SLinus Torvalds 
1129d89d8796SNeil Brown /* stacked block device info */
1130d89d8796SNeil Brown 	struct bio *bio_list, **bio_tail;
1131d89d8796SNeil Brown 
11321da177e4SLinus Torvalds /* VM state */
11331da177e4SLinus Torvalds 	struct reclaim_state *reclaim_state;
11341da177e4SLinus Torvalds 
11351da177e4SLinus Torvalds 	struct backing_dev_info *backing_dev_info;
11361da177e4SLinus Torvalds 
11371da177e4SLinus Torvalds 	struct io_context *io_context;
11381da177e4SLinus Torvalds 
11391da177e4SLinus Torvalds 	unsigned long ptrace_message;
11401da177e4SLinus Torvalds 	siginfo_t *last_siginfo; /* For ptrace use.  */
11414b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT
11421da177e4SLinus Torvalds /* i/o counters(bytes read/written, #syscalls */
11431da177e4SLinus Torvalds 	u64 rchar, wchar, syscr, syscw;
11444b98d11bSAlexey Dobriyan #endif
11457c3ab738SAndrew Morton 	struct task_io_accounting ioac;
11468f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT)
11471da177e4SLinus Torvalds 	u64 acct_rss_mem1;	/* accumulated rss usage */
11481da177e4SLinus Torvalds 	u64 acct_vm_mem1;	/* accumulated virtual memory usage */
1149db5fed26SJay Lan 	cputime_t acct_stimexpd;/* stime since last update */
11501da177e4SLinus Torvalds #endif
11511da177e4SLinus Torvalds #ifdef CONFIG_NUMA
11521da177e4SLinus Torvalds   	struct mempolicy *mempolicy;
11531da177e4SLinus Torvalds 	short il_next;
11541da177e4SLinus Torvalds #endif
11551da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS
11561da177e4SLinus Torvalds 	struct cpuset *cpuset;
11571da177e4SLinus Torvalds 	nodemask_t mems_allowed;
11581da177e4SLinus Torvalds 	int cpuset_mems_generation;
1159825a46afSPaul Jackson 	int cpuset_mem_spread_rotor;
11601da177e4SLinus Torvalds #endif
1161*ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS
1162*ddbcc7e8SPaul Menage 	struct css_set cgroups;
1163*ddbcc7e8SPaul Menage #endif
116442b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX
11650771dfefSIngo Molnar 	struct robust_list_head __user *robust_list;
116634f192c6SIngo Molnar #ifdef CONFIG_COMPAT
116734f192c6SIngo Molnar 	struct compat_robust_list_head __user *compat_robust_list;
116834f192c6SIngo Molnar #endif
1169c87e2837SIngo Molnar 	struct list_head pi_state_list;
1170c87e2837SIngo Molnar 	struct futex_pi_state *pi_state_cache;
117142b2dd0aSAlexey Dobriyan #endif
117222e2c507SJens Axboe 	atomic_t fs_excl;	/* holding fs exclusive resources */
1173e56d0903SIngo Molnar 	struct rcu_head rcu;
1174b92ce558SJens Axboe 
1175b92ce558SJens Axboe 	/*
1176b92ce558SJens Axboe 	 * cache last used pipe for splice
1177b92ce558SJens Axboe 	 */
1178b92ce558SJens Axboe 	struct pipe_inode_info *splice_pipe;
1179ca74e92bSShailabh Nagar #ifdef	CONFIG_TASK_DELAY_ACCT
1180ca74e92bSShailabh Nagar 	struct task_delay_info *delays;
1181ca74e92bSShailabh Nagar #endif
1182f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION
1183f4f154fdSAkinobu Mita 	int make_it_fail;
1184f4f154fdSAkinobu Mita #endif
11853e26c149SPeter Zijlstra 	struct prop_local_single dirties;
11861da177e4SLinus Torvalds };
11871da177e4SLinus Torvalds 
1188e05606d3SIngo Molnar /*
1189e05606d3SIngo Molnar  * Priority of a process goes from 0..MAX_PRIO-1, valid RT
1190e05606d3SIngo Molnar  * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
1191e05606d3SIngo Molnar  * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
1192e05606d3SIngo Molnar  * values are inverted: lower p->prio value means higher priority.
1193e05606d3SIngo Molnar  *
1194e05606d3SIngo Molnar  * The MAX_USER_RT_PRIO value allows the actual maximum
1195e05606d3SIngo Molnar  * RT priority to be separate from the value exported to
1196e05606d3SIngo Molnar  * user-space.  This allows kernel threads to set their
1197e05606d3SIngo Molnar  * priority to a value higher than any user task. Note:
1198e05606d3SIngo Molnar  * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
1199e05606d3SIngo Molnar  */
1200e05606d3SIngo Molnar 
1201e05606d3SIngo Molnar #define MAX_USER_RT_PRIO	100
1202e05606d3SIngo Molnar #define MAX_RT_PRIO		MAX_USER_RT_PRIO
1203e05606d3SIngo Molnar 
1204e05606d3SIngo Molnar #define MAX_PRIO		(MAX_RT_PRIO + 40)
1205e05606d3SIngo Molnar #define DEFAULT_PRIO		(MAX_RT_PRIO + 20)
1206e05606d3SIngo Molnar 
1207e05606d3SIngo Molnar static inline int rt_prio(int prio)
1208e05606d3SIngo Molnar {
1209e05606d3SIngo Molnar 	if (unlikely(prio < MAX_RT_PRIO))
1210e05606d3SIngo Molnar 		return 1;
1211e05606d3SIngo Molnar 	return 0;
1212e05606d3SIngo Molnar }
1213e05606d3SIngo Molnar 
1214e05606d3SIngo Molnar static inline int rt_task(struct task_struct *p)
1215e05606d3SIngo Molnar {
1216e05606d3SIngo Molnar 	return rt_prio(p->prio);
1217e05606d3SIngo Molnar }
1218e05606d3SIngo Molnar 
12191da177e4SLinus Torvalds static inline pid_t process_group(struct task_struct *tsk)
12201da177e4SLinus Torvalds {
12211da177e4SLinus Torvalds 	return tsk->signal->pgrp;
12221da177e4SLinus Torvalds }
12231da177e4SLinus Torvalds 
12241ec320afSCedric Le Goater static inline pid_t signal_session(struct signal_struct *sig)
12251ec320afSCedric Le Goater {
12261ec320afSCedric Le Goater 	return sig->__session;
12271ec320afSCedric Le Goater }
12281ec320afSCedric Le Goater 
1229937949d9SCedric Le Goater static inline pid_t process_session(struct task_struct *tsk)
1230937949d9SCedric Le Goater {
12311ec320afSCedric Le Goater 	return signal_session(tsk->signal);
12321ec320afSCedric Le Goater }
12331ec320afSCedric Le Goater 
12341ec320afSCedric Le Goater static inline void set_signal_session(struct signal_struct *sig, pid_t session)
12351ec320afSCedric Le Goater {
12361ec320afSCedric Le Goater 	sig->__session = session;
1237937949d9SCedric Le Goater }
1238937949d9SCedric Le Goater 
123922c935f4SEric W. Biederman static inline struct pid *task_pid(struct task_struct *task)
124022c935f4SEric W. Biederman {
124122c935f4SEric W. Biederman 	return task->pids[PIDTYPE_PID].pid;
124222c935f4SEric W. Biederman }
124322c935f4SEric W. Biederman 
124422c935f4SEric W. Biederman static inline struct pid *task_tgid(struct task_struct *task)
124522c935f4SEric W. Biederman {
124622c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PID].pid;
124722c935f4SEric W. Biederman }
124822c935f4SEric W. Biederman 
124922c935f4SEric W. Biederman static inline struct pid *task_pgrp(struct task_struct *task)
125022c935f4SEric W. Biederman {
125122c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_PGID].pid;
125222c935f4SEric W. Biederman }
125322c935f4SEric W. Biederman 
125422c935f4SEric W. Biederman static inline struct pid *task_session(struct task_struct *task)
125522c935f4SEric W. Biederman {
125622c935f4SEric W. Biederman 	return task->group_leader->pids[PIDTYPE_SID].pid;
125722c935f4SEric W. Biederman }
125822c935f4SEric W. Biederman 
12591da177e4SLinus Torvalds /**
12601da177e4SLinus Torvalds  * pid_alive - check that a task structure is not stale
12611da177e4SLinus Torvalds  * @p: Task structure to be checked.
12621da177e4SLinus Torvalds  *
12631da177e4SLinus Torvalds  * Test if a process is not yet dead (at most zombie state)
12641da177e4SLinus Torvalds  * If pid_alive fails, then pointers within the task structure
12651da177e4SLinus Torvalds  * can be stale and must not be dereferenced.
12661da177e4SLinus Torvalds  */
12671da177e4SLinus Torvalds static inline int pid_alive(struct task_struct *p)
12681da177e4SLinus Torvalds {
126992476d7fSEric W. Biederman 	return p->pids[PIDTYPE_PID].pid != NULL;
12701da177e4SLinus Torvalds }
12711da177e4SLinus Torvalds 
1272f400e198SSukadev Bhattiprolu /**
12733260259fSHenne  * is_init - check if a task structure is init
12743260259fSHenne  * @tsk: Task structure to be checked.
12753260259fSHenne  *
12763260259fSHenne  * Check if a task structure is the first user space task the kernel created.
1277f400e198SSukadev Bhattiprolu  */
1278f400e198SSukadev Bhattiprolu static inline int is_init(struct task_struct *tsk)
1279f400e198SSukadev Bhattiprolu {
1280f400e198SSukadev Bhattiprolu 	return tsk->pid == 1;
1281f400e198SSukadev Bhattiprolu }
1282f400e198SSukadev Bhattiprolu 
12839ec52099SCedric Le Goater extern struct pid *cad_pid;
12849ec52099SCedric Le Goater 
12851da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk);
12861da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
1287e56d0903SIngo Molnar 
1288158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t);
1289e56d0903SIngo Molnar 
1290e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t)
1291e56d0903SIngo Molnar {
1292e56d0903SIngo Molnar 	if (atomic_dec_and_test(&t->usage))
12938c7904a0SEric W. Biederman 		__put_task_struct(t);
1294e56d0903SIngo Molnar }
12951da177e4SLinus Torvalds 
12961da177e4SLinus Torvalds /*
12971da177e4SLinus Torvalds  * Per process flags
12981da177e4SLinus Torvalds  */
12991da177e4SLinus Torvalds #define PF_ALIGNWARN	0x00000001	/* Print alignment warning msgs */
13001da177e4SLinus Torvalds 					/* Not implemented yet, only for 486*/
13011da177e4SLinus Torvalds #define PF_STARTING	0x00000002	/* being created */
13021da177e4SLinus Torvalds #define PF_EXITING	0x00000004	/* getting shut down */
1303778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
130494886b84SLaurent Vivier #define PF_VCPU		0x00000010	/* I'm a virtual CPU */
13051da177e4SLinus Torvalds #define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
13061da177e4SLinus Torvalds #define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
13071da177e4SLinus Torvalds #define PF_DUMPCORE	0x00000200	/* dumped core */
13081da177e4SLinus Torvalds #define PF_SIGNALED	0x00000400	/* killed by a signal */
13091da177e4SLinus Torvalds #define PF_MEMALLOC	0x00000800	/* Allocating memory */
13101da177e4SLinus Torvalds #define PF_FLUSHER	0x00001000	/* responsible for disk writeback */
13111da177e4SLinus Torvalds #define PF_USED_MATH	0x00002000	/* if unset the fpu must be initialized before use */
13121da177e4SLinus Torvalds #define PF_NOFREEZE	0x00008000	/* this thread should not be frozen */
13131da177e4SLinus Torvalds #define PF_FROZEN	0x00010000	/* frozen for system suspend */
13141da177e4SLinus Torvalds #define PF_FSTRANS	0x00020000	/* inside a filesystem transaction */
13151da177e4SLinus Torvalds #define PF_KSWAPD	0x00040000	/* I am kswapd */
13161da177e4SLinus Torvalds #define PF_SWAPOFF	0x00080000	/* I am in swapoff */
13171da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000	/* Throttle me less: I clean memory */
1318b31dc66aSJens Axboe #define PF_BORROWED_MM	0x00200000	/* I am a kthread doing use_mm */
1319b31dc66aSJens Axboe #define PF_RANDOMIZE	0x00400000	/* randomize virtual address space */
1320b31dc66aSJens Axboe #define PF_SWAPWRITE	0x00800000	/* Allowed to write to swap */
1321b31dc66aSJens Axboe #define PF_SPREAD_PAGE	0x01000000	/* Spread page cache over cpuset */
1322b31dc66aSJens Axboe #define PF_SPREAD_SLAB	0x02000000	/* Spread some slab caches over cpuset */
1323c61afb18SPaul Jackson #define PF_MEMPOLICY	0x10000000	/* Non-default NUMA mempolicy */
132461a87122SThomas Gleixner #define PF_MUTEX_TESTER	0x20000000	/* Thread belongs to the rt mutex tester */
1325ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP	0x40000000	/* Freezer should not count it as freezeable */
13261da177e4SLinus Torvalds 
13271da177e4SLinus Torvalds /*
13281da177e4SLinus Torvalds  * Only the _current_ task can read/write to tsk->flags, but other
13291da177e4SLinus Torvalds  * tasks can access tsk->flags in readonly mode for example
13301da177e4SLinus Torvalds  * with tsk_used_math (like during threaded core dumping).
13311da177e4SLinus Torvalds  * There is however an exception to this rule during ptrace
13321da177e4SLinus Torvalds  * or during fork: the ptracer task is allowed to write to the
13331da177e4SLinus Torvalds  * child->flags of its traced child (same goes for fork, the parent
13341da177e4SLinus Torvalds  * can write to the child->flags), because we're guaranteed the
13351da177e4SLinus Torvalds  * child is not running and in turn not changing child->flags
13361da177e4SLinus Torvalds  * at the same time the parent does it.
13371da177e4SLinus Torvalds  */
13381da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
13391da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
13401da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current)
13411da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current)
13421da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \
13431da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
13441da177e4SLinus Torvalds #define conditional_used_math(condition) \
13451da177e4SLinus Torvalds 	conditional_stopped_child_used_math(condition, current)
13461da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \
13471da177e4SLinus Torvalds 	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
13481da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
13491da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
13501da177e4SLinus Torvalds #define used_math() tsk_used_math(current)
13511da177e4SLinus Torvalds 
13521da177e4SLinus Torvalds #ifdef CONFIG_SMP
135336c8b586SIngo Molnar extern int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask);
13541da177e4SLinus Torvalds #else
135536c8b586SIngo Molnar static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
13561da177e4SLinus Torvalds {
13574098f991SPaul Jackson 	if (!cpu_isset(0, new_mask))
13581da177e4SLinus Torvalds 		return -EINVAL;
13591da177e4SLinus Torvalds 	return 0;
13601da177e4SLinus Torvalds }
13611da177e4SLinus Torvalds #endif
13621da177e4SLinus Torvalds 
13631da177e4SLinus Torvalds extern unsigned long long sched_clock(void);
1364e436d800SIngo Molnar 
1365e436d800SIngo Molnar /*
1366e436d800SIngo Molnar  * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
1367e436d800SIngo Molnar  * clock constructed from sched_clock():
1368e436d800SIngo Molnar  */
1369e436d800SIngo Molnar extern unsigned long long cpu_clock(int cpu);
1370e436d800SIngo Molnar 
137136c8b586SIngo Molnar extern unsigned long long
137241b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task);
13731da177e4SLinus Torvalds 
13741da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */
13751da177e4SLinus Torvalds #ifdef CONFIG_SMP
13761da177e4SLinus Torvalds extern void sched_exec(void);
13771da177e4SLinus Torvalds #else
13781da177e4SLinus Torvalds #define sched_exec()   {}
13791da177e4SLinus Torvalds #endif
13801da177e4SLinus Torvalds 
13812aa44d05SIngo Molnar extern void sched_clock_idle_sleep_event(void);
13822aa44d05SIngo Molnar extern void sched_clock_idle_wakeup_event(u64 delta_ns);
1383bb29ab26SIngo Molnar 
13841da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU
13851da177e4SLinus Torvalds extern void idle_task_exit(void);
13861da177e4SLinus Torvalds #else
13871da177e4SLinus Torvalds static inline void idle_task_exit(void) {}
13881da177e4SLinus Torvalds #endif
13891da177e4SLinus Torvalds 
13901da177e4SLinus Torvalds extern void sched_idle_next(void);
1391b29739f9SIngo Molnar 
13922bd8e6d4SIngo Molnar #ifdef CONFIG_SCHED_DEBUG
139321805085SPeter Zijlstra extern unsigned int sysctl_sched_latency;
13945f6d858eSPeter Zijlstra extern unsigned int sysctl_sched_nr_latency;
1395bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity;
1396bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_batch_wakeup_granularity;
1397bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first;
1398bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_features;
1399da84d961SIngo Molnar extern unsigned int sysctl_sched_migration_cost;
14002bd8e6d4SIngo Molnar #endif
14012bd8e6d4SIngo Molnar 
14022bd8e6d4SIngo Molnar extern unsigned int sysctl_sched_compat_yield;
1403bf0f6f24SIngo Molnar 
1404b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES
140536c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p);
140636c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio);
140736c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p);
1408b29739f9SIngo Molnar #else
140936c8b586SIngo Molnar static inline int rt_mutex_getprio(struct task_struct *p)
1410b29739f9SIngo Molnar {
1411b29739f9SIngo Molnar 	return p->normal_prio;
1412b29739f9SIngo Molnar }
141395e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p)		do { } while (0)
1414b29739f9SIngo Molnar #endif
1415b29739f9SIngo Molnar 
141636c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice);
141736c8b586SIngo Molnar extern int task_prio(const struct task_struct *p);
141836c8b586SIngo Molnar extern int task_nice(const struct task_struct *p);
141936c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice);
142036c8b586SIngo Molnar extern int task_curr(const struct task_struct *p);
14211da177e4SLinus Torvalds extern int idle_cpu(int cpu);
14221da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
142336c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu);
142436c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu);
142536c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p);
14261da177e4SLinus Torvalds 
14271da177e4SLinus Torvalds void yield(void);
14281da177e4SLinus Torvalds 
14291da177e4SLinus Torvalds /*
14301da177e4SLinus Torvalds  * The default (Linux) execution domain.
14311da177e4SLinus Torvalds  */
14321da177e4SLinus Torvalds extern struct exec_domain	default_exec_domain;
14331da177e4SLinus Torvalds 
14341da177e4SLinus Torvalds union thread_union {
14351da177e4SLinus Torvalds 	struct thread_info thread_info;
14361da177e4SLinus Torvalds 	unsigned long stack[THREAD_SIZE/sizeof(long)];
14371da177e4SLinus Torvalds };
14381da177e4SLinus Torvalds 
14391da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END
14401da177e4SLinus Torvalds static inline int kstack_end(void *addr)
14411da177e4SLinus Torvalds {
14421da177e4SLinus Torvalds 	/* Reliable end of stack detection:
14431da177e4SLinus Torvalds 	 * Some APM bios versions misalign the stack
14441da177e4SLinus Torvalds 	 */
14451da177e4SLinus Torvalds 	return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
14461da177e4SLinus Torvalds }
14471da177e4SLinus Torvalds #endif
14481da177e4SLinus Torvalds 
14491da177e4SLinus Torvalds extern union thread_union init_thread_union;
14501da177e4SLinus Torvalds extern struct task_struct init_task;
14511da177e4SLinus Torvalds 
14521da177e4SLinus Torvalds extern struct   mm_struct init_mm;
14531da177e4SLinus Torvalds 
14541da177e4SLinus Torvalds #define find_task_by_pid(nr)	find_task_by_pid_type(PIDTYPE_PID, nr)
14551da177e4SLinus Torvalds extern struct task_struct *find_task_by_pid_type(int type, int pid);
14561da177e4SLinus Torvalds extern void __set_special_pids(pid_t session, pid_t pgrp);
14571da177e4SLinus Torvalds 
14581da177e4SLinus Torvalds /* per-UID process charging. */
1459acce292cSCedric Le Goater extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
14601da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u)
14611da177e4SLinus Torvalds {
14621da177e4SLinus Torvalds 	atomic_inc(&u->__count);
14631da177e4SLinus Torvalds 	return u;
14641da177e4SLinus Torvalds }
14651da177e4SLinus Torvalds extern void free_uid(struct user_struct *);
14661da177e4SLinus Torvalds extern void switch_uid(struct user_struct *);
146728f300d2SPavel Emelyanov extern void release_uids(struct user_namespace *ns);
14681da177e4SLinus Torvalds 
14691da177e4SLinus Torvalds #include <asm/current.h>
14701da177e4SLinus Torvalds 
14713171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks);
14721da177e4SLinus Torvalds 
14731da177e4SLinus Torvalds extern int FASTCALL(wake_up_state(struct task_struct * tsk, unsigned int state));
14741da177e4SLinus Torvalds extern int FASTCALL(wake_up_process(struct task_struct * tsk));
14751da177e4SLinus Torvalds extern void FASTCALL(wake_up_new_task(struct task_struct * tsk,
14761da177e4SLinus Torvalds 						unsigned long clone_flags));
14771da177e4SLinus Torvalds #ifdef CONFIG_SMP
14781da177e4SLinus Torvalds  extern void kick_process(struct task_struct *tsk);
14791da177e4SLinus Torvalds #else
14801da177e4SLinus Torvalds  static inline void kick_process(struct task_struct *tsk) { }
14811da177e4SLinus Torvalds #endif
1482ad46c2c4SIngo Molnar extern void sched_fork(struct task_struct *p, int clone_flags);
1483ad46c2c4SIngo Molnar extern void sched_dead(struct task_struct *p);
14841da177e4SLinus Torvalds 
14851da177e4SLinus Torvalds extern int in_group_p(gid_t);
14861da177e4SLinus Torvalds extern int in_egroup_p(gid_t);
14871da177e4SLinus Torvalds 
14881da177e4SLinus Torvalds extern void proc_caches_init(void);
14891da177e4SLinus Torvalds extern void flush_signals(struct task_struct *);
149010ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *);
14911da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default);
14921da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
14931da177e4SLinus Torvalds 
14941da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
14951da177e4SLinus Torvalds {
14961da177e4SLinus Torvalds 	unsigned long flags;
14971da177e4SLinus Torvalds 	int ret;
14981da177e4SLinus Torvalds 
14991da177e4SLinus Torvalds 	spin_lock_irqsave(&tsk->sighand->siglock, flags);
15001da177e4SLinus Torvalds 	ret = dequeue_signal(tsk, mask, info);
15011da177e4SLinus Torvalds 	spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
15021da177e4SLinus Torvalds 
15031da177e4SLinus Torvalds 	return ret;
15041da177e4SLinus Torvalds }
15051da177e4SLinus Torvalds 
15061da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv,
15071da177e4SLinus Torvalds 			      sigset_t *mask);
15081da177e4SLinus Torvalds extern void unblock_all_signals(void);
15091da177e4SLinus Torvalds extern void release_task(struct task_struct * p);
15101da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *);
15111da177e4SLinus Torvalds extern int send_group_sig_info(int, struct siginfo *, struct task_struct *);
15121da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *);
15131da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *);
1514c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
1515c4b92fc1SEric W. Biederman extern int kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
1516c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
15172425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32);
1518c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv);
1519c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv);
1520c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t);
15211da177e4SLinus Torvalds extern void do_notify_parent(struct task_struct *, int);
15221da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *);
15231da177e4SLinus Torvalds extern void force_sig_specific(int, struct task_struct *);
15241da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int);
15251da177e4SLinus Torvalds extern void zap_other_threads(struct task_struct *p);
15261da177e4SLinus Torvalds extern int kill_proc(pid_t, int, int);
15271da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void);
15281da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *);
15291da177e4SLinus Torvalds extern int send_sigqueue(int, struct sigqueue *,  struct task_struct *);
15301da177e4SLinus Torvalds extern int send_group_sigqueue(int, struct sigqueue *,  struct task_struct *);
15319ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
15321da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
15331da177e4SLinus Torvalds 
15349ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv)
15359ec52099SCedric Le Goater {
15369ec52099SCedric Le Goater 	return kill_pid(cad_pid, sig, priv);
15379ec52099SCedric Le Goater }
15389ec52099SCedric Le Goater 
15391da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info.  */
15401da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0)
15411da177e4SLinus Torvalds #define SEND_SIG_PRIV	((struct siginfo *) 1)
15421da177e4SLinus Torvalds #define SEND_SIG_FORCED	((struct siginfo *) 2)
15431da177e4SLinus Torvalds 
1544621d3121SOleg Nesterov static inline int is_si_special(const struct siginfo *info)
1545621d3121SOleg Nesterov {
1546621d3121SOleg Nesterov 	return info <= SEND_SIG_FORCED;
1547621d3121SOleg Nesterov }
1548621d3121SOleg Nesterov 
15491da177e4SLinus Torvalds /* True if we are on the alternate signal stack.  */
15501da177e4SLinus Torvalds 
15511da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp)
15521da177e4SLinus Torvalds {
15531da177e4SLinus Torvalds 	return (sp - current->sas_ss_sp < current->sas_ss_size);
15541da177e4SLinus Torvalds }
15551da177e4SLinus Torvalds 
15561da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp)
15571da177e4SLinus Torvalds {
15581da177e4SLinus Torvalds 	return (current->sas_ss_size == 0 ? SS_DISABLE
15591da177e4SLinus Torvalds 		: on_sig_stack(sp) ? SS_ONSTACK : 0);
15601da177e4SLinus Torvalds }
15611da177e4SLinus Torvalds 
15621da177e4SLinus Torvalds /*
15631da177e4SLinus Torvalds  * Routines for handling mm_structs
15641da177e4SLinus Torvalds  */
15651da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void);
15661da177e4SLinus Torvalds 
15671da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */
15681da177e4SLinus Torvalds extern void FASTCALL(__mmdrop(struct mm_struct *));
15691da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm)
15701da177e4SLinus Torvalds {
15716fb43d7bSIngo Molnar 	if (unlikely(atomic_dec_and_test(&mm->mm_count)))
15721da177e4SLinus Torvalds 		__mmdrop(mm);
15731da177e4SLinus Torvalds }
15741da177e4SLinus Torvalds 
15751da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */
15761da177e4SLinus Torvalds extern void mmput(struct mm_struct *);
15771da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */
15781da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task);
15791da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */
15801da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *);
15811da177e4SLinus Torvalds 
15821da177e4SLinus Torvalds extern int  copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
15831da177e4SLinus Torvalds extern void flush_thread(void);
15841da177e4SLinus Torvalds extern void exit_thread(void);
15851da177e4SLinus Torvalds 
15861da177e4SLinus Torvalds extern void exit_files(struct task_struct *);
15876b3934efSOleg Nesterov extern void __cleanup_signal(struct signal_struct *);
1588a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *);
15891da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *);
15901da177e4SLinus Torvalds 
15911da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int);
15921da177e4SLinus Torvalds 
15931da177e4SLinus Torvalds extern void daemonize(const char *, ...);
15941da177e4SLinus Torvalds extern int allow_signal(int);
15951da177e4SLinus Torvalds extern int disallow_signal(int);
15961da177e4SLinus Torvalds 
15971da177e4SLinus Torvalds extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
15981da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
159936c8b586SIngo Molnar struct task_struct *fork_idle(int);
16001da177e4SLinus Torvalds 
16011da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from);
16021da177e4SLinus Torvalds extern void get_task_comm(char *to, struct task_struct *tsk);
16031da177e4SLinus Torvalds 
16041da177e4SLinus Torvalds #ifdef CONFIG_SMP
160536c8b586SIngo Molnar extern void wait_task_inactive(struct task_struct * p);
16061da177e4SLinus Torvalds #else
16071da177e4SLinus Torvalds #define wait_task_inactive(p)	do { } while (0)
16081da177e4SLinus Torvalds #endif
16091da177e4SLinus Torvalds 
16101da177e4SLinus Torvalds #define remove_parent(p)	list_del_init(&(p)->sibling)
16118fafabd8SOleg Nesterov #define add_parent(p)		list_add_tail(&(p)->sibling,&(p)->parent->children)
16121da177e4SLinus Torvalds 
16135e85d4abSEric W. Biederman #define next_task(p)	list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks)
16141da177e4SLinus Torvalds 
16151da177e4SLinus Torvalds #define for_each_process(p) \
16161da177e4SLinus Torvalds 	for (p = &init_task ; (p = next_task(p)) != &init_task ; )
16171da177e4SLinus Torvalds 
16181da177e4SLinus Torvalds /*
16191da177e4SLinus Torvalds  * Careful: do_each_thread/while_each_thread is a double loop so
16201da177e4SLinus Torvalds  *          'break' will not work as expected - use goto instead.
16211da177e4SLinus Torvalds  */
16221da177e4SLinus Torvalds #define do_each_thread(g, t) \
16231da177e4SLinus Torvalds 	for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
16241da177e4SLinus Torvalds 
16251da177e4SLinus Torvalds #define while_each_thread(g, t) \
16261da177e4SLinus Torvalds 	while ((t = next_thread(t)) != g)
16271da177e4SLinus Torvalds 
1628de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */
1629de12a787SEric W. Biederman #define thread_group_leader(p)	(p == p->group_leader)
16301da177e4SLinus Torvalds 
16310804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process
16320804ef4bSEric W. Biederman  * to have the pid of the thread group leader without actually being
16330804ef4bSEric W. Biederman  * the thread group leader.  For iteration through the pids in proc
16340804ef4bSEric W. Biederman  * all we care about is that we have a task with the appropriate
16350804ef4bSEric W. Biederman  * pid, we don't actually care if we have the right task.
16360804ef4bSEric W. Biederman  */
16370804ef4bSEric W. Biederman static inline int has_group_leader_pid(struct task_struct *p)
16380804ef4bSEric W. Biederman {
16390804ef4bSEric W. Biederman 	return p->pid == p->tgid;
16400804ef4bSEric W. Biederman }
16410804ef4bSEric W. Biederman 
164236c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p)
164347e65328SOleg Nesterov {
164447e65328SOleg Nesterov 	return list_entry(rcu_dereference(p->thread_group.next),
164536c8b586SIngo Molnar 			  struct task_struct, thread_group);
164647e65328SOleg Nesterov }
164747e65328SOleg Nesterov 
164836c8b586SIngo Molnar static inline int thread_group_empty(struct task_struct *p)
16491da177e4SLinus Torvalds {
165047e65328SOleg Nesterov 	return list_empty(&p->thread_group);
16511da177e4SLinus Torvalds }
16521da177e4SLinus Torvalds 
16531da177e4SLinus Torvalds #define delay_group_leader(p) \
16541da177e4SLinus Torvalds 		(thread_group_leader(p) && !thread_group_empty(p))
16551da177e4SLinus Torvalds 
16561da177e4SLinus Torvalds /*
1657260ea101SEric W. Biederman  * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
165822e2c507SJens Axboe  * subscriptions and synchronises with wait4().  Also used in procfs.  Also
1659*ddbcc7e8SPaul Menage  * pins the final release of task.io_context.  Also protects ->cpuset and
1660*ddbcc7e8SPaul Menage  * ->cgroup.subsys[].
16611da177e4SLinus Torvalds  *
16621da177e4SLinus Torvalds  * Nests both inside and outside of read_lock(&tasklist_lock).
16631da177e4SLinus Torvalds  * It must not be nested with write_lock_irq(&tasklist_lock),
16641da177e4SLinus Torvalds  * neither inside nor outside.
16651da177e4SLinus Torvalds  */
16661da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p)
16671da177e4SLinus Torvalds {
16681da177e4SLinus Torvalds 	spin_lock(&p->alloc_lock);
16691da177e4SLinus Torvalds }
16701da177e4SLinus Torvalds 
16711da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p)
16721da177e4SLinus Torvalds {
16731da177e4SLinus Torvalds 	spin_unlock(&p->alloc_lock);
16741da177e4SLinus Torvalds }
16751da177e4SLinus Torvalds 
1676f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
1677f63ee72eSOleg Nesterov 							unsigned long *flags);
1678f63ee72eSOleg Nesterov 
1679f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk,
1680f63ee72eSOleg Nesterov 						unsigned long *flags)
1681f63ee72eSOleg Nesterov {
1682f63ee72eSOleg Nesterov 	spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
1683f63ee72eSOleg Nesterov }
1684f63ee72eSOleg Nesterov 
1685f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS
1686f037360fSAl Viro 
1687f7e4217bSRoman Zippel #define task_thread_info(task)	((struct thread_info *)(task)->stack)
1688f7e4217bSRoman Zippel #define task_stack_page(task)	((task)->stack)
1689a1261f54SAl Viro 
169010ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
169110ebffdeSAl Viro {
169210ebffdeSAl Viro 	*task_thread_info(p) = *task_thread_info(org);
169310ebffdeSAl Viro 	task_thread_info(p)->task = p;
169410ebffdeSAl Viro }
169510ebffdeSAl Viro 
169610ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p)
169710ebffdeSAl Viro {
1698f7e4217bSRoman Zippel 	return (unsigned long *)(task_thread_info(p) + 1);
169910ebffdeSAl Viro }
170010ebffdeSAl Viro 
1701f037360fSAl Viro #endif
1702f037360fSAl Viro 
17031da177e4SLinus Torvalds /* set thread flags in other task's structures
17041da177e4SLinus Torvalds  * - see asm/thread_info.h for TIF_xxxx flags available
17051da177e4SLinus Torvalds  */
17061da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
17071da177e4SLinus Torvalds {
1708a1261f54SAl Viro 	set_ti_thread_flag(task_thread_info(tsk), flag);
17091da177e4SLinus Torvalds }
17101da177e4SLinus Torvalds 
17111da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
17121da177e4SLinus Torvalds {
1713a1261f54SAl Viro 	clear_ti_thread_flag(task_thread_info(tsk), flag);
17141da177e4SLinus Torvalds }
17151da177e4SLinus Torvalds 
17161da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
17171da177e4SLinus Torvalds {
1718a1261f54SAl Viro 	return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
17191da177e4SLinus Torvalds }
17201da177e4SLinus Torvalds 
17211da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
17221da177e4SLinus Torvalds {
1723a1261f54SAl Viro 	return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
17241da177e4SLinus Torvalds }
17251da177e4SLinus Torvalds 
17261da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
17271da177e4SLinus Torvalds {
1728a1261f54SAl Viro 	return test_ti_thread_flag(task_thread_info(tsk), flag);
17291da177e4SLinus Torvalds }
17301da177e4SLinus Torvalds 
17311da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk)
17321da177e4SLinus Torvalds {
17331da177e4SLinus Torvalds 	set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
17341da177e4SLinus Torvalds }
17351da177e4SLinus Torvalds 
17361da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk)
17371da177e4SLinus Torvalds {
17381da177e4SLinus Torvalds 	clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
17391da177e4SLinus Torvalds }
17401da177e4SLinus Torvalds 
17411da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p)
17421da177e4SLinus Torvalds {
17431da177e4SLinus Torvalds 	return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
17441da177e4SLinus Torvalds }
17451da177e4SLinus Torvalds 
17461da177e4SLinus Torvalds static inline int need_resched(void)
17471da177e4SLinus Torvalds {
17481da177e4SLinus Torvalds 	return unlikely(test_thread_flag(TIF_NEED_RESCHED));
17491da177e4SLinus Torvalds }
17501da177e4SLinus Torvalds 
17511da177e4SLinus Torvalds /*
17521da177e4SLinus Torvalds  * cond_resched() and cond_resched_lock(): latency reduction via
17531da177e4SLinus Torvalds  * explicit rescheduling in places that are safe. The return
17541da177e4SLinus Torvalds  * value indicates whether a reschedule was done in fact.
17551da177e4SLinus Torvalds  * cond_resched_lock() will drop the spinlock before scheduling,
17561da177e4SLinus Torvalds  * cond_resched_softirq() will enable bhs before scheduling.
17571da177e4SLinus Torvalds  */
17581da177e4SLinus Torvalds extern int cond_resched(void);
17591da177e4SLinus Torvalds extern int cond_resched_lock(spinlock_t * lock);
17601da177e4SLinus Torvalds extern int cond_resched_softirq(void);
17611da177e4SLinus Torvalds 
17621da177e4SLinus Torvalds /*
17631da177e4SLinus Torvalds  * Does a critical section need to be broken due to another
17641da177e4SLinus Torvalds  * task waiting?:
17651da177e4SLinus Torvalds  */
17661da177e4SLinus Torvalds #if defined(CONFIG_PREEMPT) && defined(CONFIG_SMP)
17671da177e4SLinus Torvalds # define need_lockbreak(lock) ((lock)->break_lock)
17681da177e4SLinus Torvalds #else
17691da177e4SLinus Torvalds # define need_lockbreak(lock) 0
17701da177e4SLinus Torvalds #endif
17711da177e4SLinus Torvalds 
17721da177e4SLinus Torvalds /*
17731da177e4SLinus Torvalds  * Does a critical section need to be broken due to another
17741da177e4SLinus Torvalds  * task waiting or preemption being signalled:
17751da177e4SLinus Torvalds  */
17761da177e4SLinus Torvalds static inline int lock_need_resched(spinlock_t *lock)
17771da177e4SLinus Torvalds {
17781da177e4SLinus Torvalds 	if (need_lockbreak(lock) || need_resched())
17791da177e4SLinus Torvalds 		return 1;
17801da177e4SLinus Torvalds 	return 0;
17811da177e4SLinus Torvalds }
17821da177e4SLinus Torvalds 
17837bb44adeSRoland McGrath /*
17847bb44adeSRoland McGrath  * Reevaluate whether the task has signals pending delivery.
17857bb44adeSRoland McGrath  * Wake the task if so.
17867bb44adeSRoland McGrath  * This is required every time the blocked sigset_t changes.
17877bb44adeSRoland McGrath  * callers must hold sighand->siglock.
17887bb44adeSRoland McGrath  */
17897bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t);
17901da177e4SLinus Torvalds extern void recalc_sigpending(void);
17911da177e4SLinus Torvalds 
17921da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped);
17931da177e4SLinus Torvalds 
17941da177e4SLinus Torvalds /*
17951da177e4SLinus Torvalds  * Wrappers for p->thread_info->cpu access. No-op on UP.
17961da177e4SLinus Torvalds  */
17971da177e4SLinus Torvalds #ifdef CONFIG_SMP
17981da177e4SLinus Torvalds 
17991da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
18001da177e4SLinus Torvalds {
1801a1261f54SAl Viro 	return task_thread_info(p)->cpu;
18021da177e4SLinus Torvalds }
18031da177e4SLinus Torvalds 
1804c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
18051da177e4SLinus Torvalds 
18061da177e4SLinus Torvalds #else
18071da177e4SLinus Torvalds 
18081da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p)
18091da177e4SLinus Torvalds {
18101da177e4SLinus Torvalds 	return 0;
18111da177e4SLinus Torvalds }
18121da177e4SLinus Torvalds 
18131da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
18141da177e4SLinus Torvalds {
18151da177e4SLinus Torvalds }
18161da177e4SLinus Torvalds 
18171da177e4SLinus Torvalds #endif /* CONFIG_SMP */
18181da177e4SLinus Torvalds 
18191da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
18201da177e4SLinus Torvalds extern void arch_pick_mmap_layout(struct mm_struct *mm);
18211da177e4SLinus Torvalds #else
18221da177e4SLinus Torvalds static inline void arch_pick_mmap_layout(struct mm_struct *mm)
18231da177e4SLinus Torvalds {
18241da177e4SLinus Torvalds 	mm->mmap_base = TASK_UNMAPPED_BASE;
18251da177e4SLinus Torvalds 	mm->get_unmapped_area = arch_get_unmapped_area;
18261da177e4SLinus Torvalds 	mm->unmap_area = arch_unmap_area;
18271da177e4SLinus Torvalds }
18281da177e4SLinus Torvalds #endif
18291da177e4SLinus Torvalds 
18301da177e4SLinus Torvalds extern long sched_setaffinity(pid_t pid, cpumask_t new_mask);
18311da177e4SLinus Torvalds extern long sched_getaffinity(pid_t pid, cpumask_t *mask);
18321da177e4SLinus Torvalds 
18335c45bf27SSiddha, Suresh B extern int sched_mc_power_savings, sched_smt_power_savings;
18345c45bf27SSiddha, Suresh B 
18351da177e4SLinus Torvalds extern void normalize_rt_tasks(void);
18361da177e4SLinus Torvalds 
18379b5b7751SSrivatsa Vaddagiri #ifdef CONFIG_FAIR_GROUP_SCHED
18389b5b7751SSrivatsa Vaddagiri 
18394cf86d77SIngo Molnar extern struct task_group init_task_group;
18409b5b7751SSrivatsa Vaddagiri 
18414cf86d77SIngo Molnar extern struct task_group *sched_create_group(void);
18424cf86d77SIngo Molnar extern void sched_destroy_group(struct task_group *tg);
18439b5b7751SSrivatsa Vaddagiri extern void sched_move_task(struct task_struct *tsk);
18444cf86d77SIngo Molnar extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
18455cb350baSDhaval Giani extern unsigned long sched_group_shares(struct task_group *tg);
18469b5b7751SSrivatsa Vaddagiri 
18479b5b7751SSrivatsa Vaddagiri #endif
18489b5b7751SSrivatsa Vaddagiri 
18494b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT
18504b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
18514b98d11bSAlexey Dobriyan {
18524b98d11bSAlexey Dobriyan 	tsk->rchar += amt;
18534b98d11bSAlexey Dobriyan }
18544b98d11bSAlexey Dobriyan 
18554b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
18564b98d11bSAlexey Dobriyan {
18574b98d11bSAlexey Dobriyan 	tsk->wchar += amt;
18584b98d11bSAlexey Dobriyan }
18594b98d11bSAlexey Dobriyan 
18604b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
18614b98d11bSAlexey Dobriyan {
18624b98d11bSAlexey Dobriyan 	tsk->syscr++;
18634b98d11bSAlexey Dobriyan }
18644b98d11bSAlexey Dobriyan 
18654b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
18664b98d11bSAlexey Dobriyan {
18674b98d11bSAlexey Dobriyan 	tsk->syscw++;
18684b98d11bSAlexey Dobriyan }
18694b98d11bSAlexey Dobriyan #else
18704b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
18714b98d11bSAlexey Dobriyan {
18724b98d11bSAlexey Dobriyan }
18734b98d11bSAlexey Dobriyan 
18744b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
18754b98d11bSAlexey Dobriyan {
18764b98d11bSAlexey Dobriyan }
18774b98d11bSAlexey Dobriyan 
18784b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk)
18794b98d11bSAlexey Dobriyan {
18804b98d11bSAlexey Dobriyan }
18814b98d11bSAlexey Dobriyan 
18824b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk)
18834b98d11bSAlexey Dobriyan {
18844b98d11bSAlexey Dobriyan }
18854b98d11bSAlexey Dobriyan #endif
18864b98d11bSAlexey Dobriyan 
18871da177e4SLinus Torvalds #endif /* __KERNEL__ */
18881da177e4SLinus Torvalds 
18891da177e4SLinus Torvalds #endif
1890