Blame view

include/linux/sched.h 81.5 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  #ifndef _LINUX_SCHED_H
  #define _LINUX_SCHED_H
b7b3c76a0   David Woodhouse   Sanitise linux/sc...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  /*
   * cloning flags:
   */
  #define CSIGNAL		0x000000ff	/* signal mask to be sent at exit */
  #define CLONE_VM	0x00000100	/* set if VM shared between processes */
  #define CLONE_FS	0x00000200	/* set if fs info shared between processes */
  #define CLONE_FILES	0x00000400	/* set if open files shared between processes */
  #define CLONE_SIGHAND	0x00000800	/* set if signal handlers and blocked signals shared */
  #define CLONE_PTRACE	0x00002000	/* set if we want to let tracing continue on the child too */
  #define CLONE_VFORK	0x00004000	/* set if the parent wants the child to wake it up on mm_release */
  #define CLONE_PARENT	0x00008000	/* set if we want to have the same parent as the cloner */
  #define CLONE_THREAD	0x00010000	/* Same thread group? */
  #define CLONE_NEWNS	0x00020000	/* New namespace group? */
  #define CLONE_SYSVSEM	0x00040000	/* share system V SEM_UNDO semantics */
  #define CLONE_SETTLS	0x00080000	/* create a new TLS for the child */
  #define CLONE_PARENT_SETTID	0x00100000	/* set the TID in the parent */
  #define CLONE_CHILD_CLEARTID	0x00200000	/* clear the TID in the child */
  #define CLONE_DETACHED		0x00400000	/* Unused, ignored */
  #define CLONE_UNTRACED		0x00800000	/* set if the tracing process can't force CLONE_PTRACE on this clone */
  #define CLONE_CHILD_SETTID	0x01000000	/* set the TID in the child */
43bb40c9e   Dave Jones   sched: remove lon...
23
24
  /* 0x02000000 was previously the unused CLONE_STOPPED (Start in stopped state)
     and is now available for re-use. */
071df104f   Serge E. Hallyn   [PATCH] namespace...
25
  #define CLONE_NEWUTS		0x04000000	/* New utsname group? */
25b21cb2f   Kirill Korotaev   [PATCH] IPC names...
26
  #define CLONE_NEWIPC		0x08000000	/* New ipcs */
77ec739d8   Serge E. Hallyn   user namespace: a...
27
  #define CLONE_NEWUSER		0x10000000	/* New user namespace */
30e49c263   Pavel Emelyanov   pid namespaces: a...
28
  #define CLONE_NEWPID		0x20000000	/* New pid namespace */
169e36742   Eric W. Biederman   [NETNS]: CLONE_NE...
29
  #define CLONE_NEWNET		0x40000000	/* New network namespace */
fadad878c   Jens Axboe   kernel: add CLONE...
30
  #define CLONE_IO		0x80000000	/* Clone io context */
b7b3c76a0   David Woodhouse   Sanitise linux/sc...
31
32
33
34
35
36
37
38
  
  /*
   * Scheduling policies
   */
  #define SCHED_NORMAL		0
  #define SCHED_FIFO		1
  #define SCHED_RR		2
  #define SCHED_BATCH		3
0e6aca43e   Ingo Molnar   sched: add SCHED_...
39
40
  /* SCHED_ISO: reserved but not implemented yet */
  #define SCHED_IDLE		5
ca94c4425   Lennart Poettering   sched: Introduce ...
41
42
  /* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
  #define SCHED_RESET_ON_FORK     0x40000000
b7b3c76a0   David Woodhouse   Sanitise linux/sc...
43

a3b6714e1   David Woodhouse   Partially sanitis...
44
  #ifdef __KERNEL__
b7b3c76a0   David Woodhouse   Sanitise linux/sc...
45
46
47
48
  
  struct sched_param {
  	int sched_priority;
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
  #include <asm/param.h>	/* for HZ */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
52
53
54
55
56
57
58
59
60
  #include <linux/capability.h>
  #include <linux/threads.h>
  #include <linux/kernel.h>
  #include <linux/types.h>
  #include <linux/timex.h>
  #include <linux/jiffies.h>
  #include <linux/rbtree.h>
  #include <linux/thread_info.h>
  #include <linux/cpumask.h>
  #include <linux/errno.h>
  #include <linux/nodemask.h>
c92ff1bde   Martin Schwidefsky   move mm_struct an...
61
  #include <linux/mm_types.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
  
  #include <asm/system.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
65
  #include <asm/page.h>
  #include <asm/ptrace.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
  #include <asm/cputime.h>
  
  #include <linux/smp.h>
  #include <linux/sem.h>
  #include <linux/signal.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
73
74
75
  #include <linux/compiler.h>
  #include <linux/completion.h>
  #include <linux/pid.h>
  #include <linux/percpu.h>
  #include <linux/topology.h>
3e26c149c   Peter Zijlstra   mm: dirty balanci...
76
  #include <linux/proportions.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
  #include <linux/seccomp.h>
e56d09031   Ingo Molnar   [PATCH] RCU signa...
78
  #include <linux/rcupdate.h>
05725f7eb   Jiri Pirko   rculist: use list...
79
  #include <linux/rculist.h>
23f78d4a0   Ingo Molnar   [PATCH] pi-futex:...
80
  #include <linux/rtmutex.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81

a3b6714e1   David Woodhouse   Partially sanitis...
82
83
84
85
86
  #include <linux/time.h>
  #include <linux/param.h>
  #include <linux/resource.h>
  #include <linux/timer.h>
  #include <linux/hrtimer.h>
7c3ab7381   Andrew Morton   [PATCH] io-accoun...
87
  #include <linux/task_io_accounting.h>
9745512ce   Arjan van de Ven   sched: latencytop...
88
  #include <linux/latencytop.h>
9e2b2dc41   David Howells   CRED: Introduce c...
89
  #include <linux/cred.h>
fa14ff4ac   Peter Zijlstra   sched: Convert to...
90
  #include <linux/llist.h>
a3b6714e1   David Woodhouse   Partially sanitis...
91
92
  
  #include <asm/processor.h>
36d57ac4a   H. J. Lu   [PATCH] auxiliary...
93

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
  struct exec_domain;
c87e2837b   Ingo Molnar   [PATCH] pi-futex:...
95
  struct futex_pi_state;
286100a6c   Alexey Dobriyan   sched, futex: det...
96
  struct robust_list_head;
bddd87c7e   Akinobu Mita   blk-core: use BIO...
97
  struct bio_list;
5ad4e53bd   Al Viro   Get rid of indire...
98
  struct fs_struct;
cdd6c482c   Ingo Molnar   perf: Do the big ...
99
  struct perf_event_context;
73c101011   Jens Axboe   block: initial pa...
100
  struct blk_plug;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
101
102
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
   * List of flags we want to share for kernel threads,
   * if only because they are not used by them anyway.
   */
  #define CLONE_KERNEL	(CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
  
  /*
   * These are the constant used to fake the fixed-point load-average
   * counting. Some notes:
   *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
   *    a load-average precision of 10 bits integer + 11 bits fractional
   *  - if you want to count load-averages more often, you need more
   *    precision, or rounding will get you. With 2-second counting freq,
   *    the EXP_n values would be 1981, 2034 and 2043 if still using only
   *    11 bit fractions.
   */
  extern unsigned long avenrun[];		/* Load averages */
2d02494f5   Thomas Gleixner   sched, timers: cl...
119
  extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120
121
122
  
  #define FSHIFT		11		/* nr of bits of precision */
  #define FIXED_1		(1<<FSHIFT)	/* 1.0 as fixed-point */
0c2043abe   Linus Torvalds   Don't do load-ave...
123
  #define LOAD_FREQ	(5*HZ+1)	/* 5 sec intervals */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
125
126
127
128
129
130
131
132
133
134
  #define EXP_1		1884		/* 1/exp(5sec/1min) as fixed-point */
  #define EXP_5		2014		/* 1/exp(5sec/5min) */
  #define EXP_15		2037		/* 1/exp(5sec/15min) */
  
  #define CALC_LOAD(load,exp,n) \
  	load *= exp; \
  	load += n*(FIXED_1-exp); \
  	load >>= FSHIFT;
  
  extern unsigned long total_forks;
  extern int nr_threads;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
136
137
138
139
  DECLARE_PER_CPU(unsigned long, process_counts);
  extern int nr_processes(void);
  extern unsigned long nr_running(void);
  extern unsigned long nr_uninterruptible(void);
  extern unsigned long nr_iowait(void);
8c215bd38   Peter Zijlstra   sched: Cure nr_io...
140
  extern unsigned long nr_iowait_cpu(int cpu);
69d25870f   Arjan van de Ven   cpuidle: fix the ...
141
  extern unsigned long this_cpu_load(void);
0f004f5a6   Peter Zijlstra   sched: Cure more ...
142
  extern void calc_global_load(unsigned long ticks);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
143

7e49fcce1   Steven Rostedt   trace, lockdep: m...
144
  extern unsigned long get_parent_ip(unsigned long addr);
43ae34cb4   Ingo Molnar   sched: scheduler ...
145
146
  struct seq_file;
  struct cfs_rq;
4cf86d77f   Ingo Molnar   sched: cleanup: r...
147
  struct task_group;
43ae34cb4   Ingo Molnar   sched: scheduler ...
148
149
150
151
  #ifdef CONFIG_SCHED_DEBUG
  extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
  extern void proc_sched_set_task(struct task_struct *p);
  extern void
5cef9eca3   Ingo Molnar   sched: remove the...
152
  print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
43ae34cb4   Ingo Molnar   sched: scheduler ...
153
154
155
156
157
158
159
160
161
  #else
  static inline void
  proc_sched_show_task(struct task_struct *p, struct seq_file *m)
  {
  }
  static inline void proc_sched_set_task(struct task_struct *p)
  {
  }
  static inline void
5cef9eca3   Ingo Molnar   sched: remove the...
162
  print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
43ae34cb4   Ingo Molnar   sched: scheduler ...
163
164
165
  {
  }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
166

4a8342d23   Linus Torvalds   Revert task flag ...
167
168
169
170
171
172
173
174
175
176
  /*
   * Task state bitmask. NOTE! These bits are also
   * encoded in fs/proc/array.c: get_task_state().
   *
   * We have two separate sets of flags: task->state
   * is about runnability, while task->exit_state are
   * about the task exiting. Confusing, but this way
   * modifying one set can't modify the other one by
   * mistake.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
178
179
  #define TASK_RUNNING		0
  #define TASK_INTERRUPTIBLE	1
  #define TASK_UNINTERRUPTIBLE	2
f021a3c2b   Matthew Wilcox   Add TASK_WAKEKILL
180
181
  #define __TASK_STOPPED		4
  #define __TASK_TRACED		8
4a8342d23   Linus Torvalds   Revert task flag ...
182
183
184
185
  /* in tsk->exit_state */
  #define EXIT_ZOMBIE		16
  #define EXIT_DEAD		32
  /* in tsk->state again */
af9272326   Mike Galbraith   sched: cleanup, r...
186
  #define TASK_DEAD		64
f021a3c2b   Matthew Wilcox   Add TASK_WAKEKILL
187
  #define TASK_WAKEKILL		128
e9c843118   Peter Zijlstra   sched: Add TASK_W...
188
  #define TASK_WAKING		256
e1781538c   Peter Zijlstra   sched: Assert tas...
189
  #define TASK_STATE_MAX		512
f021a3c2b   Matthew Wilcox   Add TASK_WAKEKILL
190

44d90df6b   Peter Zijlstra   sched: Add missin...
191
  #define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW"
733421516   Peter Zijlstra   sched: Move TASK_...
192

e1781538c   Peter Zijlstra   sched: Assert tas...
193
194
  extern char ___assert_task_state[1 - 2*!!(
  		sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)];
f021a3c2b   Matthew Wilcox   Add TASK_WAKEKILL
195
196
197
198
199
  
  /* Convenience macros for the sake of set_task_state */
  #define TASK_KILLABLE		(TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
  #define TASK_STOPPED		(TASK_WAKEKILL | __TASK_STOPPED)
  #define TASK_TRACED		(TASK_WAKEKILL | __TASK_TRACED)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
200

92a1f4bc7   Matthew Wilcox   Add macros to rep...
201
202
  /* Convenience macros for the sake of wake_up */
  #define TASK_NORMAL		(TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
f021a3c2b   Matthew Wilcox   Add TASK_WAKEKILL
203
  #define TASK_ALL		(TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
92a1f4bc7   Matthew Wilcox   Add macros to rep...
204
205
206
  
  /* get_task_state() */
  #define TASK_REPORT		(TASK_RUNNING | TASK_INTERRUPTIBLE | \
f021a3c2b   Matthew Wilcox   Add TASK_WAKEKILL
207
208
  				 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
  				 __TASK_TRACED)
92a1f4bc7   Matthew Wilcox   Add macros to rep...
209

f021a3c2b   Matthew Wilcox   Add TASK_WAKEKILL
210
211
  #define task_is_traced(task)	((task->state & __TASK_TRACED) != 0)
  #define task_is_stopped(task)	((task->state & __TASK_STOPPED) != 0)
8f92054e7   David Howells   CRED: Fix __task_...
212
  #define task_is_dead(task)	((task)->exit_state != 0)
92a1f4bc7   Matthew Wilcox   Add macros to rep...
213
  #define task_is_stopped_or_traced(task)	\
f021a3c2b   Matthew Wilcox   Add TASK_WAKEKILL
214
  			((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
92a1f4bc7   Matthew Wilcox   Add macros to rep...
215
  #define task_contributes_to_load(task)	\
e3c8ca833   Nathan Lynch   sched: do not cou...
216
  				((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
376fede80   Tejun Heo   freezer: kill PF_...
217
  				 (task->flags & PF_FROZEN) == 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
218
219
220
221
222
  
  #define __set_task_state(tsk, state_value)		\
  	do { (tsk)->state = (state_value); } while (0)
  #define set_task_state(tsk, state_value)		\
  	set_mb((tsk)->state, (state_value))
498d0c571   Andrew Morton   [PATCH] set_curre...
223
224
225
226
227
228
229
230
231
232
233
  /*
   * set_current_state() includes a barrier so that the write of current->state
   * is correctly serialised wrt the caller's subsequent test of whether to
   * actually sleep:
   *
   *	set_current_state(TASK_UNINTERRUPTIBLE);
   *	if (do_i_need_to_sleep())
   *		schedule();
   *
   * If the caller does not need such serialisation then use __set_current_state()
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
235
236
237
238
239
240
  #define __set_current_state(state_value)			\
  	do { current->state = (state_value); } while (0)
  #define set_current_state(state_value)		\
  	set_mb(current->state, (state_value))
  
  /* Task command name length */
  #define TASK_COMM_LEN 16
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
241
242
243
244
245
246
247
248
249
250
  #include <linux/spinlock.h>
  
  /*
   * This serializes "schedule()" and also protects
   * the run-queue from deletions/modifications (but
   * _adding_ to the beginning of the run-queue has
   * a separate lock).
   */
  extern rwlock_t tasklist_lock;
  extern spinlock_t mmlist_lock;
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
251
  struct task_struct;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
252

db1466b3e   Paul E. McKenney   rcu: Use wrapper ...
253
254
255
  #ifdef CONFIG_PROVE_RCU
  extern int lockdep_tasklist_lock_is_held(void);
  #endif /* #ifdef CONFIG_PROVE_RCU */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
256
257
  extern void sched_init(void);
  extern void sched_init_smp(void);
2d07b255c   Harvey Harrison   sched: add declar...
258
  extern asmlinkage void schedule_tail(struct task_struct *prev);
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
259
  extern void init_idle(struct task_struct *idle, int cpu);
1df21055e   Ingo Molnar   sched: add init_i...
260
  extern void init_idle_bootup_task(struct task_struct *idle);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261

89f19f04d   Andrew Morton   sched: Fix racine...
262
  extern int runqueue_is_locked(int cpu);
017730c11   Ingo Molnar   ftrace: fix wakeups
263

46cb4b7c8   Siddha, Suresh B   sched: dynticks i...
264
  #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
83cd4fe27   Venkatesh Pallipadi   sched: Change noh...
265
  extern void select_nohz_load_balancer(int stop_tick);
69e1e811d   Suresh Siddha   sched, nohz: Trac...
266
  extern void set_cpu_sd_state_idle(void);
83cd4fe27   Venkatesh Pallipadi   sched: Change noh...
267
  extern int get_nohz_timer_target(void);
46cb4b7c8   Siddha, Suresh B   sched: dynticks i...
268
  #else
83cd4fe27   Venkatesh Pallipadi   sched: Change noh...
269
  static inline void select_nohz_load_balancer(int stop_tick) { }
fdaabd800   Peter Zijlstra   sched: Fix compil...
270
  static inline void set_cpu_sd_state_idle(void) { }
46cb4b7c8   Siddha, Suresh B   sched: dynticks i...
271
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
272

e59e2ae2c   Ingo Molnar   [PATCH] SysRq-X: ...
273
  /*
39bc89fd4   Ingo Molnar   make SysRq-T show...
274
   * Only dump TASK_* tasks. (0 for all tasks)
e59e2ae2c   Ingo Molnar   [PATCH] SysRq-X: ...
275
276
277
278
279
   */
  extern void show_state_filter(unsigned long state_filter);
  
  static inline void show_state(void)
  {
39bc89fd4   Ingo Molnar   make SysRq-T show...
280
  	show_state_filter(0);
e59e2ae2c   Ingo Molnar   [PATCH] SysRq-X: ...
281
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
  extern void show_regs(struct pt_regs *);
  
  /*
   * TASK is a pointer to the task whose backtrace we want to see (or NULL for current
   * task), SP is the stack pointer of the first frame that should be shown in the back
   * trace (or NULL if the entire call-chain of the task should be shown).
   */
  extern void show_stack(struct task_struct *task, unsigned long *sp);
  
  void io_schedule(void);
  long io_schedule_timeout(long timeout);
  
  extern void cpu_init (void);
  extern void trap_init(void);
  extern void update_process_times(int user);
  extern void scheduler_tick(void);
82a1fcb90   Ingo Molnar   softlockup: autom...
298
  extern void sched_show_task(struct task_struct *p);
19cc36c0f   Frederic Weisbecker   lockup_detector: ...
299
  #ifdef CONFIG_LOCKUP_DETECTOR
8446f1d39   Ingo Molnar   [PATCH] detect so...
300
  extern void touch_softlockup_watchdog(void);
d6ad3e286   Jason Wessel   softlockup: Add s...
301
  extern void touch_softlockup_watchdog_sync(void);
04c9167f9   Jeremy Fitzhardinge   add touch_all_sof...
302
  extern void touch_all_softlockup_watchdogs(void);
332fbdbca   Don Zickus   lockup_detector: ...
303
304
305
  extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
  				  void __user *buffer,
  				  size_t *lenp, loff_t *ppos);
9c44bc03f   Ingo Molnar   softlockup: allow...
306
  extern unsigned int  softlockup_panic;
004417a6d   Peter Zijlstra   perf, arch: Clean...
307
  void lockup_detector_init(void);
8446f1d39   Ingo Molnar   [PATCH] detect so...
308
  #else
8446f1d39   Ingo Molnar   [PATCH] detect so...
309
310
311
  static inline void touch_softlockup_watchdog(void)
  {
  }
d6ad3e286   Jason Wessel   softlockup: Add s...
312
313
314
  static inline void touch_softlockup_watchdog_sync(void)
  {
  }
04c9167f9   Jeremy Fitzhardinge   add touch_all_sof...
315
316
317
  static inline void touch_all_softlockup_watchdogs(void)
  {
  }
004417a6d   Peter Zijlstra   perf, arch: Clean...
318
319
320
  static inline void lockup_detector_init(void)
  {
  }
8446f1d39   Ingo Molnar   [PATCH] detect so...
321
  #endif
e162b39a3   Mandeep Singh Baines   softlockup: decou...
322
323
324
325
326
327
  #ifdef CONFIG_DETECT_HUNG_TASK
  extern unsigned int  sysctl_hung_task_panic;
  extern unsigned long sysctl_hung_task_check_count;
  extern unsigned long sysctl_hung_task_timeout_secs;
  extern unsigned long sysctl_hung_task_warnings;
  extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
8d65af789   Alexey Dobriyan   sysctl: remove "s...
328
  					 void __user *buffer,
e162b39a3   Mandeep Singh Baines   softlockup: decou...
329
  					 size_t *lenp, loff_t *ppos);
e4ecda1b6   Mark Lord   Fix compile error...
330
331
332
  #else
  /* Avoid need for ifdefs elsewhere in the code */
  enum { sysctl_hung_task_timeout_secs = 0 };
e162b39a3   Mandeep Singh Baines   softlockup: decou...
333
  #endif
8446f1d39   Ingo Molnar   [PATCH] detect so...
334

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
336
  /* Attach to any functions which should be ignored in wchan output. */
  #define __sched		__attribute__((__section__(".sched.text")))
deaf2227d   Ingo Molnar   sched: clean up, ...
337
338
339
  
  /* Linker adds these: start and end of __sched functions */
  extern char __sched_text_start[], __sched_text_end[];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340
341
342
343
  /* Is this address in the __sched functions? */
  extern int in_sched_functions(unsigned long addr);
  
  #define	MAX_SCHEDULE_TIMEOUT	LONG_MAX
b3c975286   Harvey Harrison   include/linux: Re...
344
  extern signed long schedule_timeout(signed long timeout);
64ed93a26   Nishanth Aravamudan   [PATCH] add sched...
345
  extern signed long schedule_timeout_interruptible(signed long timeout);
294d5cc23   Matthew Wilcox   Add schedule_time...
346
  extern signed long schedule_timeout_killable(signed long timeout);
64ed93a26   Nishanth Aravamudan   [PATCH] add sched...
347
  extern signed long schedule_timeout_uninterruptible(signed long timeout);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
  asmlinkage void schedule(void);
c6eb3dda2   Peter Zijlstra   mutex: Use p->on_...
349
  extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350

ab516013a   Serge E. Hallyn   [PATCH] namespace...
351
  struct nsproxy;
acce292c8   Cedric Le Goater   user namespace: a...
352
  struct user_namespace;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
353

341c87bf3   KAMEZAWA Hiroyuki   elf: limit max ma...
354
355
356
357
358
359
360
361
362
363
364
365
366
  /*
   * Default maximum number of active map areas, this limits the number of vmas
   * per mm struct. Users can overwrite this number by sysctl but there is a
   * problem.
   *
   * When a program's coredump is generated as ELF format, a section is created
   * per a vma. In ELF, the number of sections is represented in unsigned short.
   * This means the number of sections should be smaller than 65535 at coredump.
   * Because the kernel adds some informative sections to a image of program at
   * generating coredump, we need some margin. The number of extra sections is
   * 1-3 now and depends on arch. We use "5" as safe margin, here.
   */
  #define MAPCOUNT_ELF_CORE_MARGIN	(5)
4be929be3   Alexey Dobriyan   kernel-wide: repl...
367
  #define DEFAULT_MAX_MAP_COUNT	(USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
369
370
371
  
  extern int sysctl_max_map_count;
  
  #include <linux/aio.h>
efc1a3b16   David Howells   nommu: don't need...
372
373
  #ifdef CONFIG_MMU
  extern void arch_pick_mmap_layout(struct mm_struct *mm);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
374
375
376
377
378
379
380
  extern unsigned long
  arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
  		       unsigned long, unsigned long);
  extern unsigned long
  arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
  			  unsigned long len, unsigned long pgoff,
  			  unsigned long flags);
1363c3cd8   Wolfgang Wander   [PATCH] Avoiding ...
381
382
  extern void arch_unmap_area(struct mm_struct *, unsigned long);
  extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
efc1a3b16   David Howells   nommu: don't need...
383
384
385
  #else
  static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386

901608d90   Oleg Nesterov   mm: introduce get...
387

6c5d52382   Kawai, Hidehiro   coredump masking:...
388
389
390
391
  extern void set_dumpable(struct mm_struct *mm, int value);
  extern int get_dumpable(struct mm_struct *mm);
  
  /* mm flags */
3cb4a0bb1   Kawai, Hidehiro   coredump masking:...
392
  /* dumpable bits */
6c5d52382   Kawai, Hidehiro   coredump masking:...
393
394
  #define MMF_DUMPABLE      0  /* core dump is permitted */
  #define MMF_DUMP_SECURELY 1  /* core file is readable only by root */
f8af4da3b   Hugh Dickins   ksm: the mm inter...
395

3cb4a0bb1   Kawai, Hidehiro   coredump masking:...
396
  #define MMF_DUMPABLE_BITS 2
f8af4da3b   Hugh Dickins   ksm: the mm inter...
397
  #define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1)
3cb4a0bb1   Kawai, Hidehiro   coredump masking:...
398
399
400
401
402
403
  
  /* coredump filter bits */
  #define MMF_DUMP_ANON_PRIVATE	2
  #define MMF_DUMP_ANON_SHARED	3
  #define MMF_DUMP_MAPPED_PRIVATE	4
  #define MMF_DUMP_MAPPED_SHARED	5
82df39738   Roland McGrath   Add MMF_DUMP_ELF_...
404
  #define MMF_DUMP_ELF_HEADERS	6
e575f111d   KOSAKI Motohiro   coredump_filter: ...
405
406
  #define MMF_DUMP_HUGETLB_PRIVATE 7
  #define MMF_DUMP_HUGETLB_SHARED  8
f8af4da3b   Hugh Dickins   ksm: the mm inter...
407

3cb4a0bb1   Kawai, Hidehiro   coredump masking:...
408
  #define MMF_DUMP_FILTER_SHIFT	MMF_DUMPABLE_BITS
e575f111d   KOSAKI Motohiro   coredump_filter: ...
409
  #define MMF_DUMP_FILTER_BITS	7
3cb4a0bb1   Kawai, Hidehiro   coredump masking:...
410
411
412
  #define MMF_DUMP_FILTER_MASK \
  	(((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
  #define MMF_DUMP_FILTER_DEFAULT \
e575f111d   KOSAKI Motohiro   coredump_filter: ...
413
  	((1 << MMF_DUMP_ANON_PRIVATE) |	(1 << MMF_DUMP_ANON_SHARED) |\
656eb2cd5   Roland McGrath   add CONFIG_CORE_D...
414
415
416
417
418
419
420
  	 (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
  
  #ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
  # define MMF_DUMP_MASK_DEFAULT_ELF	(1 << MMF_DUMP_ELF_HEADERS)
  #else
  # define MMF_DUMP_MASK_DEFAULT_ELF	0
  #endif
f8af4da3b   Hugh Dickins   ksm: the mm inter...
421
422
  					/* leave room for more dump flags */
  #define MMF_VM_MERGEABLE	16	/* KSM may merge identical pages */
ba76149f4   Andrea Arcangeli   thp: khugepaged
423
  #define MMF_VM_HUGEPAGE		17	/* set when VM_HUGEPAGE is set on vma */
f8af4da3b   Hugh Dickins   ksm: the mm inter...
424
425
  
  #define MMF_INIT_MASK		(MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK)
6c5d52382   Kawai, Hidehiro   coredump masking:...
426

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
427
428
429
430
  struct sighand_struct {
  	atomic_t		count;
  	struct k_sigaction	action[_NSIG];
  	spinlock_t		siglock;
b8fceee17   Davide Libenzi   signalfd simplifi...
431
  	wait_queue_head_t	signalfd_wqh;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
432
  };
0e4648141   KaiGai Kohei   [PATCH] pacct: ad...
433
  struct pacct_struct {
f6ec29a42   KaiGai Kohei   [PATCH] pacct: av...
434
435
  	int			ac_flag;
  	long			ac_exitcode;
0e4648141   KaiGai Kohei   [PATCH] pacct: ad...
436
  	unsigned long		ac_mem;
77787bfb4   KaiGai Kohei   [PATCH] pacct: no...
437
438
  	cputime_t		ac_utime, ac_stime;
  	unsigned long		ac_minflt, ac_majflt;
0e4648141   KaiGai Kohei   [PATCH] pacct: ad...
439
  };
42c4ab41a   Stanislaw Gruszka   itimers: Merge IT...
440
441
442
  struct cpu_itimer {
  	cputime_t expires;
  	cputime_t incr;
8356b5f9c   Stanislaw Gruszka   itimers: Fix peri...
443
444
  	u32 error;
  	u32 incr_error;
42c4ab41a   Stanislaw Gruszka   itimers: Merge IT...
445
  };
f06febc96   Frank Mayhar   timers: fix itime...
446
447
448
449
450
  /**
   * struct task_cputime - collected CPU time counts
   * @utime:		time spent in user mode, in &cputime_t units
   * @stime:		time spent in kernel mode, in &cputime_t units
   * @sum_exec_runtime:	total time spent on the CPU, in nanoseconds
5ce73a4a5   Ingo Molnar   timers: fix itime...
451
   *
f06febc96   Frank Mayhar   timers: fix itime...
452
453
454
455
456
457
458
459
460
461
462
463
464
465
   * This structure groups together three kinds of CPU time that are
   * tracked for threads and thread groups.  Most things considering
   * CPU time want to group these counts together and treat all three
   * of them in parallel.
   */
  struct task_cputime {
  	cputime_t utime;
  	cputime_t stime;
  	unsigned long long sum_exec_runtime;
  };
  /* Alternate field names when used to cache expirations. */
  #define prof_exp	stime
  #define virt_exp	utime
  #define sched_exp	sum_exec_runtime
4cd4c1b40   Peter Zijlstra   timers: split pro...
466
467
  #define INIT_CPUTIME	\
  	(struct task_cputime) {					\
648616343   Martin Schwidefsky   [S390] cputime: a...
468
469
  		.utime = 0,					\
  		.stime = 0,					\
4cd4c1b40   Peter Zijlstra   timers: split pro...
470
471
  		.sum_exec_runtime = 0,				\
  	}
c99e6efe1   Peter Zijlstra   sched: INIT_PREEM...
472
473
474
  /*
   * Disable preemption until the scheduler is running.
   * Reset by start_kernel()->sched_init()->init_idle().
d86ee4809   Peter Zijlstra   sched: optimize c...
475
476
477
   *
   * We include PREEMPT_ACTIVE to avoid cond_resched() from working
   * before the scheduler is active -- see should_resched().
c99e6efe1   Peter Zijlstra   sched: INIT_PREEM...
478
   */
d86ee4809   Peter Zijlstra   sched: optimize c...
479
  #define INIT_PREEMPT_COUNT	(1 + PREEMPT_ACTIVE)
c99e6efe1   Peter Zijlstra   sched: INIT_PREEM...
480

f06febc96   Frank Mayhar   timers: fix itime...
481
  /**
4cd4c1b40   Peter Zijlstra   timers: split pro...
482
483
484
485
486
   * struct thread_group_cputimer - thread group interval timer counts
   * @cputime:		thread group interval timers.
   * @running:		non-zero when there are timers running and
   * 			@cputime receives updates.
   * @lock:		lock for fields in this struct.
f06febc96   Frank Mayhar   timers: fix itime...
487
488
   *
   * This structure contains the version of task_cputime, above, that is
4cd4c1b40   Peter Zijlstra   timers: split pro...
489
   * used for thread group CPU timer calculations.
f06febc96   Frank Mayhar   timers: fix itime...
490
   */
4cd4c1b40   Peter Zijlstra   timers: split pro...
491
492
493
  struct thread_group_cputimer {
  	struct task_cputime cputime;
  	int running;
ee30a7b2f   Thomas Gleixner   locking, sched: A...
494
  	raw_spinlock_t lock;
f06febc96   Frank Mayhar   timers: fix itime...
495
  };
f06febc96   Frank Mayhar   timers: fix itime...
496

4714d1d32   Ben Blum   cgroups: read-wri...
497
  #include <linux/rwsem.h>
5091faa44   Mike Galbraith   sched: Add 'autog...
498
  struct autogroup;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
499
  /*
e815f0a84   Jonathan Neuschäfer   sched.h: Fix a ty...
500
   * NOTE! "signal_struct" does not have its own
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
501
502
503
504
505
506
   * locking, because a shared signal_struct always
   * implies a shared sighand_struct, so locking
   * sighand_struct is always a proper superset of
   * the locking of signal_struct.
   */
  struct signal_struct {
ea6d290ca   Oleg Nesterov   signals: make tas...
507
  	atomic_t		sigcnt;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
  	atomic_t		live;
b3ac022cb   Oleg Nesterov   proc: turn signal...
509
  	int			nr_threads;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
510
511
512
513
  
  	wait_queue_head_t	wait_chldexit;	/* for wait4() */
  
  	/* current thread group signal load-balancing target: */
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
514
  	struct task_struct	*curr_target;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
516
517
518
519
520
521
522
523
524
525
  
  	/* shared signal handling: */
  	struct sigpending	shared_pending;
  
  	/* thread group exit support */
  	int			group_exit_code;
  	/* overloaded:
  	 * - notify group_exit_task when ->count is equal to notify_count
  	 * - everyone except group_exit_task is stopped during signal delivery
  	 *   of fatal signals, group_exit_task processes the signal.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
526
  	int			notify_count;
07dd20e03   Richard Kennedy   sched: reorder si...
527
  	struct task_struct	*group_exit_task;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
528
529
530
531
532
533
534
535
536
  
  	/* thread group stop support, overloads group_exit_code too */
  	int			group_stop_count;
  	unsigned int		flags; /* see SIGNAL_* flags below */
  
  	/* POSIX.1b Interval Timers */
  	struct list_head posix_timers;
  
  	/* ITIMER_REAL timer for the process */
2ff678b8d   Thomas Gleixner   [PATCH] hrtimer: ...
537
  	struct hrtimer real_timer;
fea9d1755   Oleg Nesterov   ITIMER_REAL: conv...
538
  	struct pid *leader_pid;
2ff678b8d   Thomas Gleixner   [PATCH] hrtimer: ...
539
  	ktime_t it_real_incr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
540

42c4ab41a   Stanislaw Gruszka   itimers: Merge IT...
541
542
543
544
545
546
  	/*
  	 * ITIMER_PROF and ITIMER_VIRTUAL timers for the process, we use
  	 * CPUCLOCK_PROF and CPUCLOCK_VIRT for indexing array as these
  	 * values are defined to 0 and 1 respectively
  	 */
  	struct cpu_itimer it[2];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
547

f06febc96   Frank Mayhar   timers: fix itime...
548
  	/*
4cd4c1b40   Peter Zijlstra   timers: split pro...
549
550
  	 * Thread group totals for process CPU timers.
  	 * See thread_group_cputimer(), et al, for details.
f06febc96   Frank Mayhar   timers: fix itime...
551
  	 */
4cd4c1b40   Peter Zijlstra   timers: split pro...
552
  	struct thread_group_cputimer cputimer;
f06febc96   Frank Mayhar   timers: fix itime...
553
554
555
556
557
  
  	/* Earliest-expiration cache. */
  	struct task_cputime cputime_expires;
  
  	struct list_head cpu_timers[3];
ab521dc0f   Eric W. Biederman   [PATCH] tty: upda...
558
  	struct pid *tty_old_pgrp;
1ec320afd   Cedric Le Goater   [PATCH] add proce...
559

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
560
561
562
563
  	/* boolean value for session group leader */
  	int leader;
  
  	struct tty_struct *tty; /* NULL if no tty */
5091faa44   Mike Galbraith   sched: Add 'autog...
564
565
566
  #ifdef CONFIG_SCHED_AUTOGROUP
  	struct autogroup *autogroup;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
567
568
569
570
571
572
  	/*
  	 * Cumulative resource counters for dead threads in the group,
  	 * and for reaped dead child processes forked by this group.
  	 * Live threads maintain their own counters and add to these
  	 * in __exit_signal, except for the group leader.
  	 */
32bd671d6   Peter Zijlstra   signal: re-add de...
573
  	cputime_t utime, stime, cutime, cstime;
9ac52315d   Laurent Vivier   sched: guest CPU ...
574
575
  	cputime_t gtime;
  	cputime_t cgtime;
0cf55e1ec   Hidetoshi Seto   sched, cputime: I...
576
577
578
  #ifndef CONFIG_VIRT_CPU_ACCOUNTING
  	cputime_t prev_utime, prev_stime;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
579
580
  	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
  	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
6eaeeaba3   Eric Dumazet   getrusage(): fill...
581
  	unsigned long inblock, oublock, cinblock, coublock;
1f10206cf   Jiri Pirko   getrusage: fill r...
582
  	unsigned long maxrss, cmaxrss;
940389b8a   Andrea Righi   task IO accountin...
583
  	struct task_io_accounting ioac;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
584
585
  
  	/*
32bd671d6   Peter Zijlstra   signal: re-add de...
586
587
588
589
590
591
592
593
  	 * Cumulative ns of schedule CPU time fo dead threads in the
  	 * group, not including a zombie group leader, (This only differs
  	 * from jiffies_to_ns(utime + stime) if sched_clock uses something
  	 * other than jiffies.)
  	 */
  	unsigned long long sum_sched_runtime;
  
  	/*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
594
595
596
597
598
599
600
601
602
  	 * We don't bother to synchronize most readers of this at all,
  	 * because there is no reader checking a limit that actually needs
  	 * to get both rlim_cur and rlim_max atomically, and either one
  	 * alone is a single word that can safely be read normally.
  	 * getrlimit/setrlimit use task_lock(current->group_leader) to
  	 * protect this instead of the siglock, because they really
  	 * have no need to disable irqs.
  	 */
  	struct rlimit rlim[RLIM_NLIMITS];
0e4648141   KaiGai Kohei   [PATCH] pacct: ad...
603
604
605
  #ifdef CONFIG_BSD_PROCESS_ACCT
  	struct pacct_struct pacct;	/* per-process accounting information */
  #endif
ad4ecbcba   Shailabh Nagar   [PATCH] delay acc...
606
  #ifdef CONFIG_TASKSTATS
ad4ecbcba   Shailabh Nagar   [PATCH] delay acc...
607
608
  	struct taskstats *stats;
  #endif
522ed7767   Miloslav Trmac   Audit: add TTY in...
609
610
611
612
  #ifdef CONFIG_AUDIT
  	unsigned audit_tty;
  	struct tty_audit_buf *tty_audit_buf;
  #endif
4714d1d32   Ben Blum   cgroups: read-wri...
613
614
  #ifdef CONFIG_CGROUPS
  	/*
77e4ef99d   Tejun Heo   threadgroup: exte...
615
616
617
618
619
620
621
  	 * group_rwsem prevents new tasks from entering the threadgroup and
  	 * member tasks from exiting,a more specifically, setting of
  	 * PF_EXITING.  fork and exit paths are protected with this rwsem
  	 * using threadgroup_change_begin/end().  Users which require
  	 * threadgroup to remain stable should use threadgroup_[un]lock()
  	 * which also takes care of exec path.  Currently, cgroup is the
  	 * only user.
4714d1d32   Ben Blum   cgroups: read-wri...
622
  	 */
257058ae2   Tejun Heo   threadgroup: rena...
623
  	struct rw_semaphore group_rwsem;
4714d1d32   Ben Blum   cgroups: read-wri...
624
  #endif
28b83c519   KOSAKI Motohiro   oom: move oom_adj...
625

a63d83f42   David Rientjes   oom: badness heur...
626
627
  	int oom_adj;		/* OOM kill score adjustment (bit shift) */
  	int oom_score_adj;	/* OOM kill score adjustment */
dabb16f63   Mandeep Singh Baines   oom: allow a non-...
628
629
  	int oom_score_adj_min;	/* OOM kill score adjustment minimum value.
  				 * Only settable by CAP_SYS_RESOURCE. */
9b1bf12d5   KOSAKI Motohiro   signals: move cre...
630
631
632
633
  
  	struct mutex cred_guard_mutex;	/* guard against foreign influences on
  					 * credential calculations
  					 * (notably. ptrace) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
634
  };
4866cde06   Nick Piggin   [PATCH] sched: cl...
635
636
637
638
  /* Context switch must be unlocked if interrupts are to be enabled */
  #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
  # define __ARCH_WANT_UNLOCKED_CTXSW
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
639
640
641
642
  /*
   * Bits in flags field of signal_struct.
   */
  #define SIGNAL_STOP_STOPPED	0x00000001 /* job control stop in effect */
ee77f0759   Oleg Nesterov   signal: Turn SIGN...
643
644
  #define SIGNAL_STOP_CONTINUED	0x00000002 /* SIGCONT since WCONTINUED reap */
  #define SIGNAL_GROUP_EXIT	0x00000004 /* group exit in progress */
e44205519   Oleg Nesterov   signals: re-assig...
645
646
647
648
649
650
  /*
   * Pending notifications to parent.
   */
  #define SIGNAL_CLD_STOPPED	0x00000010
  #define SIGNAL_CLD_CONTINUED	0x00000020
  #define SIGNAL_CLD_MASK		(SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
651

fae5fa44f   Oleg Nesterov   signals: fix /sbi...
652
  #define SIGNAL_UNKILLABLE	0x00000040 /* for init: ignore fatal signals */
ed5d2cac1   Oleg Nesterov   exec: rework the ...
653
654
655
656
657
658
  /* If true, all threads except ->group_exit_task have pending SIGKILL */
  static inline int signal_group_exit(const struct signal_struct *sig)
  {
  	return	(sig->flags & SIGNAL_GROUP_EXIT) ||
  		(sig->group_exit_task != NULL);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
659
660
661
662
663
664
665
666
  /*
   * Some day this will be a full-fledged user tracking system..
   */
  struct user_struct {
  	atomic_t __count;	/* reference count */
  	atomic_t processes;	/* How many processes does this user have? */
  	atomic_t files;		/* How many open files does this user have? */
  	atomic_t sigpending;	/* How many pending signals does this user have? */
2d9048e20   Amy Griffis   [PATCH] inotify (...
667
  #ifdef CONFIG_INOTIFY_USER
0eeca2830   Robert Love   [PATCH] inotify
668
669
670
  	atomic_t inotify_watches; /* How many inotify watches does this user have? */
  	atomic_t inotify_devs;	/* How many inotify devs does this user have opened? */
  #endif
4afeff850   Eric Paris   fanotify: limit n...
671
672
673
  #ifdef CONFIG_FANOTIFY
  	atomic_t fanotify_listeners;
  #endif
7ef9964e6   Davide Libenzi   epoll: introduce ...
674
  #ifdef CONFIG_EPOLL
52bd19f76   Robin Holt   epoll: convert ma...
675
  	atomic_long_t epoll_watches; /* The number of file descriptors currently watched */
7ef9964e6   Davide Libenzi   epoll: introduce ...
676
  #endif
970a8645c   Alexey Dobriyan   user.c: #ifdef ->...
677
  #ifdef CONFIG_POSIX_MQUEUE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
678
679
  	/* protected by mq_lock	*/
  	unsigned long mq_bytes;	/* How many bytes can be allocated to mqueue? */
970a8645c   Alexey Dobriyan   user.c: #ifdef ->...
680
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
681
682
683
684
685
686
687
688
  	unsigned long locked_shm; /* How many pages of mlocked shm ? */
  
  #ifdef CONFIG_KEYS
  	struct key *uid_keyring;	/* UID specific keyring */
  	struct key *session_keyring;	/* UID's default session keyring */
  #endif
  
  	/* Hash table maintenance information */
735de2230   Pavel Emelyanov   Convert uid hash ...
689
  	struct hlist_node uidhash_node;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
690
  	uid_t uid;
18b6e0414   Serge Hallyn   User namespaces: ...
691
  	struct user_namespace *user_ns;
24e377a83   Srivatsa Vaddagiri   sched: add fair-u...
692

cdd6c482c   Ingo Molnar   perf: Do the big ...
693
  #ifdef CONFIG_PERF_EVENTS
789f90fcf   Peter Zijlstra   perf_counter: per...
694
695
  	atomic_long_t locked_vm;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
696
  };
eb41d9465   Kay Sievers   fix struct user_i...
697
  extern int uids_sysfs_init(void);
5cb350baf   Dhaval Giani   sched: group sche...
698

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
699
700
701
702
  extern struct user_struct *find_user(uid_t);
  
  extern struct user_struct root_user;
  #define INIT_USER (&root_user)
b6dff3ec5   David Howells   CRED: Separate ta...
703

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
704
705
  struct backing_dev_info;
  struct reclaim_state;
52f17b6c2   Chandra Seetharaman   [PATCH] per-task-...
706
  #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
707
708
  struct sched_info {
  	/* cumulative counters */
2d72376b3   Ingo Molnar   sched: clean up s...
709
  	unsigned long pcount;	      /* # of times run on this cpu */
9c2c48020   Ken Chen   schedstat: consol...
710
  	unsigned long long run_delay; /* time spent waiting on a runqueue */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
711
712
  
  	/* timestamps */
172ba844a   Balbir Singh   sched: update del...
713
714
  	unsigned long long last_arrival,/* when we last ran on a cpu */
  			   last_queued;	/* when we were last queued to run */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
715
  };
52f17b6c2   Chandra Seetharaman   [PATCH] per-task-...
716
  #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
717

ca74e92b4   Shailabh Nagar   [PATCH] per-task-...
718
719
720
721
722
723
724
725
726
727
728
729
730
731
  #ifdef CONFIG_TASK_DELAY_ACCT
  struct task_delay_info {
  	spinlock_t	lock;
  	unsigned int	flags;	/* Private per-task flags */
  
  	/* For each stat XXX, add following, aligned appropriately
  	 *
  	 * struct timespec XXX_start, XXX_end;
  	 * u64 XXX_delay;
  	 * u32 XXX_count;
  	 *
  	 * Atomicity of updates to XXX_delay, XXX_count protected by
  	 * single lock above (split into XXX_lock if contention is an issue).
  	 */
0ff922452   Shailabh Nagar   [PATCH] per-task-...
732
733
734
735
736
737
738
739
740
741
742
743
744
  
  	/*
  	 * XXX_count is incremented on every XXX operation, the delay
  	 * associated with the operation is added to XXX_delay.
  	 * XXX_delay contains the accumulated delay time in nanoseconds.
  	 */
  	struct timespec blkio_start, blkio_end;	/* Shared by blkio, swapin */
  	u64 blkio_delay;	/* wait for sync block io completion */
  	u64 swapin_delay;	/* wait for swapin block io completion */
  	u32 blkio_count;	/* total count of the number of sync block */
  				/* io operations performed */
  	u32 swapin_count;	/* total count of the number of swapin block */
  				/* io operations performed */
873b47717   Keika Kobayashi   per-task-delay-ac...
745
746
747
748
  
  	struct timespec freepages_start, freepages_end;
  	u64 freepages_delay;	/* wait for memory reclaim */
  	u32 freepages_count;	/* total count of memory reclaim */
ca74e92b4   Shailabh Nagar   [PATCH] per-task-...
749
  };
52f17b6c2   Chandra Seetharaman   [PATCH] per-task-...
750
751
752
753
754
755
756
757
758
759
760
  #endif	/* CONFIG_TASK_DELAY_ACCT */
  
  static inline int sched_info_on(void)
  {
  #ifdef CONFIG_SCHEDSTATS
  	return 1;
  #elif defined(CONFIG_TASK_DELAY_ACCT)
  	extern int delayacct_on;
  	return delayacct_on;
  #else
  	return 0;
ca74e92b4   Shailabh Nagar   [PATCH] per-task-...
761
  #endif
52f17b6c2   Chandra Seetharaman   [PATCH] per-task-...
762
  }
ca74e92b4   Shailabh Nagar   [PATCH] per-task-...
763

d15bcfdbe   Ingo Molnar   sched: rename idl...
764
765
766
767
768
  enum cpu_idle_type {
  	CPU_IDLE,
  	CPU_NOT_IDLE,
  	CPU_NEWLY_IDLE,
  	CPU_MAX_IDLE_TYPES
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
769
770
771
  };
  
  /*
c8b281161   Nikhil Rao   sched: Increase S...
772
773
774
775
776
777
778
779
780
781
   * Increase resolution of nice-level calculations for 64-bit architectures.
   * The extra resolution improves shares distribution and load balancing of
   * low-weight task groups (eg. nice +19 on an autogroup), deeper taskgroup
   * hierarchies, especially on larger systems. This is not a user-visible change
   * and does not change the user-interface for setting shares/weights.
   *
   * We increase resolution only if we have enough bits to allow this increased
   * resolution (i.e. BITS_PER_LONG > 32). The costs for increasing resolution
   * when BITS_PER_LONG <= 32 are pretty high and the returns do not justify the
   * increased costs.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
782
   */
e4c2fb0d5   Peter Zijlstra   sched: Disable (r...
783
  #if 0 /* BITS_PER_LONG > 32 -- currently broken: it increases power usage under light load  */
c8b281161   Nikhil Rao   sched: Increase S...
784
785
786
787
788
789
790
791
  # define SCHED_LOAD_RESOLUTION	10
  # define scale_load(w)		((w) << SCHED_LOAD_RESOLUTION)
  # define scale_load_down(w)	((w) >> SCHED_LOAD_RESOLUTION)
  #else
  # define SCHED_LOAD_RESOLUTION	0
  # define scale_load(w)		(w)
  # define scale_load_down(w)	(w)
  #endif
9aa7b3698   Ingo Molnar   sched: increase t...
792

c8b281161   Nikhil Rao   sched: Increase S...
793
  #define SCHED_LOAD_SHIFT	(10 + SCHED_LOAD_RESOLUTION)
9aa7b3698   Ingo Molnar   sched: increase t...
794
  #define SCHED_LOAD_SCALE	(1L << SCHED_LOAD_SHIFT)
1399fa780   Nikhil Rao   sched: Introduce ...
795
796
797
798
799
  /*
   * Increase resolution of cpu_power calculations
   */
  #define SCHED_POWER_SHIFT	10
  #define SCHED_POWER_SCALE	(1L << SCHED_POWER_SHIFT)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
800

1399fa780   Nikhil Rao   sched: Introduce ...
801
802
803
  /*
   * sched-domains (multiprocessor balancing) declarations:
   */
2dd73a4f0   Peter Williams   [PATCH] sched: im...
804
  #ifdef CONFIG_SMP
b5d978e0c   Peter Zijlstra   sched: Add SD_PRE...
805
806
807
808
  #define SD_LOAD_BALANCE		0x0001	/* Do load balancing on this domain. */
  #define SD_BALANCE_NEWIDLE	0x0002	/* Balance when about to become idle */
  #define SD_BALANCE_EXEC		0x0004	/* Balance on exec */
  #define SD_BALANCE_FORK		0x0008	/* Balance on fork, clone */
c88d59108   Peter Zijlstra   sched: Merge sele...
809
  #define SD_BALANCE_WAKE		0x0010  /* Balance on wakeup */
b5d978e0c   Peter Zijlstra   sched: Add SD_PRE...
810
  #define SD_WAKE_AFFINE		0x0020	/* Wake task to waking CPU */
59abf0264   Peter Zijlstra   sched: Add SD_PRE...
811
  #define SD_PREFER_LOCAL		0x0040  /* Prefer to keep tasks local to this domain */
b5d978e0c   Peter Zijlstra   sched: Add SD_PRE...
812
813
814
815
  #define SD_SHARE_CPUPOWER	0x0080	/* Domain members share cpu power */
  #define SD_POWERSAVINGS_BALANCE	0x0100	/* Balance for power savings */
  #define SD_SHARE_PKG_RESOURCES	0x0200	/* Domain members share cpu pkg resources */
  #define SD_SERIALIZE		0x0400	/* Only a single load balancing instance */
532cb4c40   Michael Neuling   sched: Add asymme...
816
  #define SD_ASYM_PACKING		0x0800  /* Place busy groups earlier in the domain */
b5d978e0c   Peter Zijlstra   sched: Add SD_PRE...
817
  #define SD_PREFER_SIBLING	0x1000	/* Prefer to place tasks in a sibling domain */
e3589f6c8   Peter Zijlstra   sched: Allow for ...
818
  #define SD_OVERLAP		0x2000	/* sched_domains of this level overlap */
5c45bf279   Siddha, Suresh B   [PATCH] sched: mc...
819

afb8a9b70   Gautham R Shenoy   sched: framework ...
820
821
822
823
824
825
826
827
828
829
  enum powersavings_balance_level {
  	POWERSAVINGS_BALANCE_NONE = 0,  /* No power saving load balance */
  	POWERSAVINGS_BALANCE_BASIC,	/* Fill one thread/core/package
  					 * first for long running threads
  					 */
  	POWERSAVINGS_BALANCE_WAKEUP,	/* Also bias task wakeups to semi-idle
  					 * cpu package for power savings
  					 */
  	MAX_POWERSAVINGS_BALANCE_LEVELS
  };
89c4710ee   Siddha, Suresh B   [PATCH] sched: cl...
830

716707b29   Vaidyanathan Srinivasan   sched: convert BA...
831
  extern int sched_mc_power_savings, sched_smt_power_savings;
89c4710ee   Siddha, Suresh B   [PATCH] sched: cl...
832

716707b29   Vaidyanathan Srinivasan   sched: convert BA...
833
834
835
836
  static inline int sd_balance_for_mc_power(void)
  {
  	if (sched_smt_power_savings)
  		return SD_POWERSAVINGS_BALANCE;
5c45bf279   Siddha, Suresh B   [PATCH] sched: mc...
837

28f531816   Vaidyanathan Srinivasan   sched: Fix sched_...
838
839
840
841
  	if (!sched_mc_power_savings)
  		return SD_PREFER_SIBLING;
  
  	return 0;
716707b29   Vaidyanathan Srinivasan   sched: convert BA...
842
  }
89c4710ee   Siddha, Suresh B   [PATCH] sched: cl...
843

716707b29   Vaidyanathan Srinivasan   sched: convert BA...
844
845
846
847
  static inline int sd_balance_for_package_power(void)
  {
  	if (sched_mc_power_savings | sched_smt_power_savings)
  		return SD_POWERSAVINGS_BALANCE;
b5d978e0c   Peter Zijlstra   sched: Add SD_PRE...
848
  	return SD_PREFER_SIBLING;
716707b29   Vaidyanathan Srinivasan   sched: convert BA...
849
  }
5c45bf279   Siddha, Suresh B   [PATCH] sched: mc...
850

532cb4c40   Michael Neuling   sched: Add asymme...
851
  extern int __weak arch_sd_sibiling_asym_packing(void);
100fdaee7   Vaidyanathan Srinivasan   sched: add SD_BAL...
852
853
  /*
   * Optimise SD flags for power savings:
25985edce   Lucas De Marchi   Fix common misspe...
854
   * SD_BALANCE_NEWIDLE helps aggressive task consolidation and power savings.
100fdaee7   Vaidyanathan Srinivasan   sched: add SD_BAL...
855
856
857
858
859
860
861
862
863
864
   * Keep default SD flags if sched_{smt,mc}_power_saving=0
   */
  
  static inline int sd_power_saving_flags(void)
  {
  	if (sched_mc_power_savings | sched_smt_power_savings)
  		return SD_BALANCE_NEWIDLE;
  
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
865

9c3f75cbd   Peter Zijlstra   sched: Break out ...
866
  struct sched_group_power {
e3589f6c8   Peter Zijlstra   sched: Allow for ...
867
  	atomic_t ref;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
868
869
  	/*
  	 * CPU power of this group, SCHED_LOAD_SCALE being max power for a
18a3885fc   Peter Zijlstra   sched: Remove rec...
870
  	 * single CPU.
5517d86be   Eric Dumazet   Speed up divides ...
871
  	 */
9c3f75cbd   Peter Zijlstra   sched: Break out ...
872
  	unsigned int power, power_orig;
69e1e811d   Suresh Siddha   sched, nohz: Trac...
873
874
875
876
  	/*
  	 * Number of busy cpus in this group.
  	 */
  	atomic_t nr_busy_cpus;
9c3f75cbd   Peter Zijlstra   sched: Break out ...
877
878
879
880
881
  };
  
  struct sched_group {
  	struct sched_group *next;	/* Must be a circular list */
  	atomic_t ref;
aae6d3ddd   Suresh Siddha   sched: Use group ...
882
  	unsigned int group_weight;
9c3f75cbd   Peter Zijlstra   sched: Break out ...
883
  	struct sched_group_power *sgp;
6c99e9ad4   Rusty Russell   sched: convert st...
884

4200efd9a   Ingo Molnar   sched: properly d...
885
886
887
888
889
890
  	/*
  	 * The CPUs this group covers.
  	 *
  	 * NOTE: this field is variable length. (Allocated dynamically
  	 * by attaching extra space to the end of the structure,
  	 * depending on how many CPUs the kernel has booted up with)
4200efd9a   Ingo Molnar   sched: properly d...
891
892
  	 */
  	unsigned long cpumask[0];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
893
  };
758b2cdc6   Rusty Russell   sched: wrap sched...
894
895
  static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
  {
6c99e9ad4   Rusty Russell   sched: convert st...
896
  	return to_cpumask(sg->cpumask);
758b2cdc6   Rusty Russell   sched: wrap sched...
897
  }
029632fbb   Peter Zijlstra   sched: Make separ...
898
899
900
901
902
903
904
905
  /**
   * group_first_cpu - Returns the first cpu in the cpumask of a sched_group.
   * @group: The group whose first cpu is to be returned.
   */
  static inline unsigned int group_first_cpu(struct sched_group *group)
  {
  	return cpumask_first(sched_group_cpus(group));
  }
1d3504fcf   Hidetoshi Seto   sched, cpuset: cu...
906
907
908
909
910
911
912
  struct sched_domain_attr {
  	int relax_domain_level;
  };
  
  #define SD_ATTR_INIT	(struct sched_domain_attr) {	\
  	.relax_domain_level = -1,			\
  }
60495e776   Peter Zijlstra   sched: Dynamic sc...
913
  extern int sched_domain_level_max;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
914
915
916
  struct sched_domain {
  	/* These fields must be setup */
  	struct sched_domain *parent;	/* top domain must be null terminated */
1a8488708   Siddha, Suresh B   [PATCH] sched: in...
917
  	struct sched_domain *child;	/* bottom domain must be null terminated */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
918
  	struct sched_group *groups;	/* the balancing groups of the domain */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
919
920
921
922
  	unsigned long min_interval;	/* Minimum balance interval ms */
  	unsigned long max_interval;	/* Maximum balance interval ms */
  	unsigned int busy_factor;	/* less balancing by factor if busy */
  	unsigned int imbalance_pct;	/* No balance until over watermark */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
923
  	unsigned int cache_nice_tries;	/* Leave cache hot tasks for # tries */
7897986ba   Nick Piggin   [PATCH] sched: ba...
924
925
926
927
  	unsigned int busy_idx;
  	unsigned int idle_idx;
  	unsigned int newidle_idx;
  	unsigned int wake_idx;
147cbb4bb   Nick Piggin   [PATCH] sched: ba...
928
  	unsigned int forkexec_idx;
a52bfd735   Peter Zijlstra   sched: Add smt_gain
929
  	unsigned int smt_gain;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
930
  	int flags;			/* See SD_* */
60495e776   Peter Zijlstra   sched: Dynamic sc...
931
  	int level;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
932
933
934
935
936
  
  	/* Runtime fields. */
  	unsigned long last_balance;	/* init to jiffies. units in jiffies */
  	unsigned int balance_interval;	/* initialise to 1. units in ms. */
  	unsigned int nr_balance_failed; /* initialise to 0 */
2398f2c6d   Peter Zijlstra   sched: update sha...
937
  	u64 last_update;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
938
939
  #ifdef CONFIG_SCHEDSTATS
  	/* load_balance() stats */
480b9434c   Ken Chen   sched: reduce sch...
940
941
942
943
944
945
946
947
  	unsigned int lb_count[CPU_MAX_IDLE_TYPES];
  	unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
  	unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
  	unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
  	unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
  	unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
  	unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
  	unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
948
949
  
  	/* Active load balancing */
480b9434c   Ken Chen   sched: reduce sch...
950
951
952
  	unsigned int alb_count;
  	unsigned int alb_failed;
  	unsigned int alb_pushed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
953

68767a0ae   Nick Piggin   [PATCH] sched: sc...
954
  	/* SD_BALANCE_EXEC stats */
480b9434c   Ken Chen   sched: reduce sch...
955
956
957
  	unsigned int sbe_count;
  	unsigned int sbe_balanced;
  	unsigned int sbe_pushed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
958

68767a0ae   Nick Piggin   [PATCH] sched: sc...
959
  	/* SD_BALANCE_FORK stats */
480b9434c   Ken Chen   sched: reduce sch...
960
961
962
  	unsigned int sbf_count;
  	unsigned int sbf_balanced;
  	unsigned int sbf_pushed;
68767a0ae   Nick Piggin   [PATCH] sched: sc...
963

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
964
  	/* try_to_wake_up() stats */
480b9434c   Ken Chen   sched: reduce sch...
965
966
967
  	unsigned int ttwu_wake_remote;
  	unsigned int ttwu_move_affine;
  	unsigned int ttwu_move_balance;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
968
  #endif
a5d8c3483   Ingo Molnar   sched debug: add ...
969
970
971
  #ifdef CONFIG_SCHED_DEBUG
  	char *name;
  #endif
dce840a08   Peter Zijlstra   sched: Dynamicall...
972
973
974
975
  	union {
  		void *private;		/* used during construction */
  		struct rcu_head rcu;	/* used during destruction */
  	};
6c99e9ad4   Rusty Russell   sched: convert st...
976

669c55e9f   Peter Zijlstra   sched: Pre-comput...
977
  	unsigned int span_weight;
4200efd9a   Ingo Molnar   sched: properly d...
978
979
980
981
982
983
  	/*
  	 * Span of all CPUs in this domain.
  	 *
  	 * NOTE: this field is variable length. (Allocated dynamically
  	 * by attaching extra space to the end of the structure,
  	 * depending on how many CPUs the kernel has booted up with)
4200efd9a   Ingo Molnar   sched: properly d...
984
985
  	 */
  	unsigned long span[0];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
986
  };
758b2cdc6   Rusty Russell   sched: wrap sched...
987
988
  static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
  {
6c99e9ad4   Rusty Russell   sched: convert st...
989
  	return to_cpumask(sd->span);
758b2cdc6   Rusty Russell   sched: wrap sched...
990
  }
acc3f5d7c   Rusty Russell   cpumask: Partitio...
991
  extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
1d3504fcf   Hidetoshi Seto   sched, cpuset: cu...
992
  				    struct sched_domain_attr *dattr_new);
029190c51   Paul Jackson   cpuset sched_load...
993

acc3f5d7c   Rusty Russell   cpumask: Partitio...
994
995
996
  /* Allocate an array of sched domains, for partition_sched_domains(). */
  cpumask_var_t *alloc_sched_domains(unsigned int ndoms);
  void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms);
06aaf76a7   Ingo Molnar   sched: move test_...
997
998
999
1000
1001
1002
1003
1004
  /* Test a flag in parent sched domain */
  static inline int test_sd_parent(struct sched_domain *sd, int flag)
  {
  	if (sd->parent && (sd->parent->flags & flag))
  		return 1;
  
  	return 0;
  }
029190c51   Paul Jackson   cpuset sched_load...
1005

47fe38fcf   Peter Zijlstra   x86: sched: Provi...
1006
1007
  unsigned long default_scale_freq_power(struct sched_domain *sd, int cpu);
  unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu);
1b427c153   Ingo Molnar   sched: fix build ...
1008
  #else /* CONFIG_SMP */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1009

1b427c153   Ingo Molnar   sched: fix build ...
1010
  struct sched_domain_attr;
d02c7a8cf   Con Kolivas   [PATCH] sched: ad...
1011

1b427c153   Ingo Molnar   sched: fix build ...
1012
  static inline void
acc3f5d7c   Rusty Russell   cpumask: Partitio...
1013
  partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
1b427c153   Ingo Molnar   sched: fix build ...
1014
1015
  			struct sched_domain_attr *dattr_new)
  {
d02c7a8cf   Con Kolivas   [PATCH] sched: ad...
1016
  }
1b427c153   Ingo Molnar   sched: fix build ...
1017
  #endif	/* !CONFIG_SMP */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1018

47fe38fcf   Peter Zijlstra   x86: sched: Provi...
1019

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1020
  struct io_context;			/* See blkdev.h */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1021

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1022

383f2835e   Kenneth W Chen   [PATCH] Prefetch ...
1023
  #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
1024
  extern void prefetch_stack(struct task_struct *t);
383f2835e   Kenneth W Chen   [PATCH] Prefetch ...
1025
1026
1027
  #else
  static inline void prefetch_stack(struct task_struct *t) { }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1028
1029
1030
  
  struct audit_context;		/* See audit.c */
  struct mempolicy;
b92ce5589   Jens Axboe   [PATCH] splice: a...
1031
  struct pipe_inode_info;
4865ecf13   Serge E. Hallyn   [PATCH] namespace...
1032
  struct uts_namespace;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1033

20b8a59f2   Ingo Molnar   sched: cfs, core ...
1034
1035
  struct rq;
  struct sched_domain;
7d4787214   Peter Zijlstra   sched: Rename syn...
1036
1037
1038
1039
  /*
   * wake flags
   */
  #define WF_SYNC		0x01		/* waker goes to sleep after wakup */
a7558e010   Peter Zijlstra   sched: Add WF_FORK
1040
  #define WF_FORK		0x02		/* child wakeup after fork */
f339b9dc1   Peter Zijlstra   sched: Fix scheds...
1041
  #define WF_MIGRATED	0x04		/* internal use, task got migrated */
7d4787214   Peter Zijlstra   sched: Rename syn...
1042

371fd7e7a   Peter Zijlstra   sched: Add enqueu...
1043
  #define ENQUEUE_WAKEUP		1
74f8e4b23   Peter Zijlstra   sched: Remove rq ...
1044
1045
1046
1047
1048
1049
  #define ENQUEUE_HEAD		2
  #ifdef CONFIG_SMP
  #define ENQUEUE_WAKING		4	/* sched_class::task_waking was called */
  #else
  #define ENQUEUE_WAKING		0
  #endif
371fd7e7a   Peter Zijlstra   sched: Add enqueu...
1050
1051
  
  #define DEQUEUE_SLEEP		1
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1052
  struct sched_class {
5522d5d5f   Ingo Molnar   sched: mark sched...
1053
  	const struct sched_class *next;
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1054

371fd7e7a   Peter Zijlstra   sched: Add enqueu...
1055
1056
  	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
  	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
4530d7ab0   Dmitry Adamushko   sched: simplify s...
1057
  	void (*yield_task) (struct rq *rq);
d95f41220   Mike Galbraith   sched: Add yield_...
1058
  	bool (*yield_to_task) (struct rq *rq, struct task_struct *p, bool preempt);
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1059

7d4787214   Peter Zijlstra   sched: Rename syn...
1060
  	void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1061

fb8d47240   Ingo Molnar   sched: remove the...
1062
  	struct task_struct * (*pick_next_task) (struct rq *rq);
31ee529cc   Ingo Molnar   sched: remove the...
1063
  	void (*put_prev_task) (struct rq *rq, struct task_struct *p);
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1064

681f3e685   Peter Williams   sched: isolate SM...
1065
  #ifdef CONFIG_SMP
7608dec2c   Peter Zijlstra   sched: Drop the r...
1066
  	int  (*select_task_rq)(struct task_struct *p, int sd_flag, int flags);
4ce72a2c0   Li Zefan   sched: add CONFIG...
1067

9a897c5a6   Steven Rostedt   sched: RT-balance...
1068
1069
  	void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
  	void (*post_schedule) (struct rq *this_rq);
74f8e4b23   Peter Zijlstra   sched: Remove rq ...
1070
  	void (*task_waking) (struct task_struct *task);
efbbd05a5   Peter Zijlstra   sched: Add pre an...
1071
  	void (*task_woken) (struct rq *this_rq, struct task_struct *task);
e1d1484f7   Peter Williams   sched: reduce bal...
1072

cd8ba7cd9   Mike Travis   sched: add new se...
1073
  	void (*set_cpus_allowed)(struct task_struct *p,
96f874e26   Rusty Russell   sched: convert re...
1074
  				 const struct cpumask *newmask);
57d885fea   Gregory Haskins   sched: add sched-...
1075

1f11eb6a8   Gregory Haskins   sched: fix cpupri...
1076
1077
  	void (*rq_online)(struct rq *rq);
  	void (*rq_offline)(struct rq *rq);
4ce72a2c0   Li Zefan   sched: add CONFIG...
1078
1079
1080
1081
  #endif
  
  	void (*set_curr_task) (struct rq *rq);
  	void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
cd29fe6f2   Peter Zijlstra   sched: Sanitize f...
1082
  	void (*task_fork) (struct task_struct *p);
cb4698450   Steven Rostedt   sched: RT-balance...
1083

da7a735e5   Peter Zijlstra   sched: Fix switch...
1084
1085
  	void (*switched_from) (struct rq *this_rq, struct task_struct *task);
  	void (*switched_to) (struct rq *this_rq, struct task_struct *task);
cb4698450   Steven Rostedt   sched: RT-balance...
1086
  	void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
da7a735e5   Peter Zijlstra   sched: Fix switch...
1087
  			     int oldprio);
810b38179   Peter Zijlstra   sched: retain vru...
1088

dba091b9e   Thomas Gleixner   sched: Protect sc...
1089
1090
  	unsigned int (*get_rr_interval) (struct rq *rq,
  					 struct task_struct *task);
0d721cead   Peter Williams   sched: Simplify s...
1091

810b38179   Peter Zijlstra   sched: retain vru...
1092
  #ifdef CONFIG_FAIR_GROUP_SCHED
b2b5ce022   Peter Zijlstra   sched, cgroup: Fi...
1093
  	void (*task_move_group) (struct task_struct *p, int on_rq);
810b38179   Peter Zijlstra   sched: retain vru...
1094
  #endif
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1095
1096
1097
1098
1099
  };
  
  struct load_weight {
  	unsigned long weight, inv_weight;
  };
94c18227d   Ingo Molnar   [PATCH] sched: re...
1100
  #ifdef CONFIG_SCHEDSTATS
41acab885   Lucas De Marchi   sched: Implement ...
1101
  struct sched_statistics {
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1102
  	u64			wait_start;
94c18227d   Ingo Molnar   [PATCH] sched: re...
1103
  	u64			wait_max;
6d082592b   Arjan van de Ven   sched: keep total...
1104
1105
  	u64			wait_count;
  	u64			wait_sum;
8f0dfc34e   Arjan van de Ven   sched: Provide io...
1106
1107
  	u64			iowait_count;
  	u64			iowait_sum;
94c18227d   Ingo Molnar   [PATCH] sched: re...
1108

20b8a59f2   Ingo Molnar   sched: cfs, core ...
1109
  	u64			sleep_start;
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1110
  	u64			sleep_max;
94c18227d   Ingo Molnar   [PATCH] sched: re...
1111
1112
1113
  	s64			sum_sleep_runtime;
  
  	u64			block_start;
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1114
1115
  	u64			block_max;
  	u64			exec_max;
eba1ed4b7   Ingo Molnar   sched: debug: tra...
1116
  	u64			slice_max;
cc367732f   Ingo Molnar   sched: debug, imp...
1117

cc367732f   Ingo Molnar   sched: debug, imp...
1118
1119
1120
1121
1122
  	u64			nr_migrations_cold;
  	u64			nr_failed_migrations_affine;
  	u64			nr_failed_migrations_running;
  	u64			nr_failed_migrations_hot;
  	u64			nr_forced_migrations;
cc367732f   Ingo Molnar   sched: debug, imp...
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
  
  	u64			nr_wakeups;
  	u64			nr_wakeups_sync;
  	u64			nr_wakeups_migrate;
  	u64			nr_wakeups_local;
  	u64			nr_wakeups_remote;
  	u64			nr_wakeups_affine;
  	u64			nr_wakeups_affine_attempts;
  	u64			nr_wakeups_passive;
  	u64			nr_wakeups_idle;
41acab885   Lucas De Marchi   sched: Implement ...
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
  };
  #endif
  
  struct sched_entity {
  	struct load_weight	load;		/* for load-balancing */
  	struct rb_node		run_node;
  	struct list_head	group_node;
  	unsigned int		on_rq;
  
  	u64			exec_start;
  	u64			sum_exec_runtime;
  	u64			vruntime;
  	u64			prev_sum_exec_runtime;
41acab885   Lucas De Marchi   sched: Implement ...
1146
  	u64			nr_migrations;
41acab885   Lucas De Marchi   sched: Implement ...
1147
1148
  #ifdef CONFIG_SCHEDSTATS
  	struct sched_statistics statistics;
94c18227d   Ingo Molnar   [PATCH] sched: re...
1149
  #endif
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1150
1151
1152
1153
1154
1155
1156
1157
  #ifdef CONFIG_FAIR_GROUP_SCHED
  	struct sched_entity	*parent;
  	/* rq on which this entity is (to be) queued: */
  	struct cfs_rq		*cfs_rq;
  	/* rq "owned" by this entity/group: */
  	struct cfs_rq		*my_q;
  #endif
  };
70b97a7f0   Ingo Molnar   [PATCH] sched: cl...
1158

fa717060f   Peter Zijlstra   sched: sched_rt_e...
1159
1160
  struct sched_rt_entity {
  	struct list_head run_list;
78f2c7db6   Peter Zijlstra   sched: SCHED_FIFO...
1161
  	unsigned long timeout;
bee367ed0   Richard Kennedy   sched: reorder st...
1162
  	unsigned int time_slice;
6f505b164   Peter Zijlstra   sched: rt group s...
1163
  	int nr_cpus_allowed;
58d6c2d72   Peter Zijlstra   sched: rt-group: ...
1164
  	struct sched_rt_entity *back;
052f1dc7e   Peter Zijlstra   sched: rt-group: ...
1165
  #ifdef CONFIG_RT_GROUP_SCHED
6f505b164   Peter Zijlstra   sched: rt group s...
1166
1167
1168
1169
1170
1171
  	struct sched_rt_entity	*parent;
  	/* rq on which this entity is (to be) queued: */
  	struct rt_rq		*rt_rq;
  	/* rq "owned" by this entity/group: */
  	struct rt_rq		*my_q;
  #endif
fa717060f   Peter Zijlstra   sched: sched_rt_e...
1172
  };
868489660   Paul E. McKenney   rcu: Changes from...
1173
  struct rcu_node;
8dc85d547   Peter Zijlstra   perf: Multiple ta...
1174
1175
1176
  enum perf_event_task_context {
  	perf_invalid_context = -1,
  	perf_hw_context = 0,
89a1e1873   Peter Zijlstra   perf: Provide a s...
1177
  	perf_sw_context,
8dc85d547   Peter Zijlstra   perf: Multiple ta...
1178
1179
  	perf_nr_task_contexts,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1180
1181
  struct task_struct {
  	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
f7e4217b0   Roman Zippel   rename thread_inf...
1182
  	void *stack;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1183
  	atomic_t usage;
97dc32cdb   William Cohen   reduce size of ta...
1184
1185
  	unsigned int flags;	/* per process flags, defined below */
  	unsigned int ptrace;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1186

2dd73a4f0   Peter Williams   [PATCH] sched: im...
1187
  #ifdef CONFIG_SMP
fa14ff4ac   Peter Zijlstra   sched: Convert to...
1188
  	struct llist_node wake_entry;
3ca7a440d   Peter Zijlstra   sched: Always pro...
1189
  	int on_cpu;
2dd73a4f0   Peter Williams   [PATCH] sched: im...
1190
  #endif
fd2f4419b   Peter Zijlstra   sched: Provide p-...
1191
  	int on_rq;
50e645a8a   Ingo Molnar   sched: remove int...
1192

b29739f90   Ingo Molnar   [PATCH] pi-futex:...
1193
  	int prio, static_prio, normal_prio;
c7aceaba0   Richard Kennedy   sched: reorder ta...
1194
  	unsigned int rt_priority;
5522d5d5f   Ingo Molnar   sched: mark sched...
1195
  	const struct sched_class *sched_class;
20b8a59f2   Ingo Molnar   sched: cfs, core ...
1196
  	struct sched_entity se;
fa717060f   Peter Zijlstra   sched: sched_rt_e...
1197
  	struct sched_rt_entity rt;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1198

e107be36e   Avi Kivity   [PATCH] sched: ar...
1199
1200
1201
1202
  #ifdef CONFIG_PREEMPT_NOTIFIERS
  	/* list of struct preempt_notifier: */
  	struct hlist_head preempt_notifiers;
  #endif
18796aa00   Alexey Dobriyan   task_struct: move...
1203
1204
1205
1206
1207
1208
1209
1210
1211
  	/*
  	 * fpu_counter contains the number of consecutive context switches
  	 * that the FPU is used. If this is over a threshold, the lazy fpu
  	 * saving becomes unlazy to save the trap. This is an unsigned char
  	 * so that after 256 times the counter wraps and the behavior turns
  	 * lazy again; this to deal with bursty apps that only use FPU for
  	 * a short time
  	 */
  	unsigned char fpu_counter;
6c5c93415   Alexey Dobriyan   [PATCH] ifdef blk...
1212
  #ifdef CONFIG_BLK_DEV_IO_TRACE
2056a782f   Jens Axboe   [PATCH] Block que...
1213
  	unsigned int btrace_seq;
6c5c93415   Alexey Dobriyan   [PATCH] ifdef blk...
1214
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1215

97dc32cdb   William Cohen   reduce size of ta...
1216
  	unsigned int policy;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1217
  	cpumask_t cpus_allowed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1218

a57eb940d   Paul E. McKenney   rcu: Add a TINY_P...
1219
  #ifdef CONFIG_PREEMPT_RCU
e260be673   Paul E. McKenney   Preempt-RCU: impl...
1220
  	int rcu_read_lock_nesting;
f41d911f8   Paul E. McKenney   rcu: Merge preemp...
1221
  	char rcu_read_unlock_special;
f41d911f8   Paul E. McKenney   rcu: Merge preemp...
1222
  	struct list_head rcu_node_entry;
a57eb940d   Paul E. McKenney   rcu: Add a TINY_P...
1223
1224
1225
  #endif /* #ifdef CONFIG_PREEMPT_RCU */
  #ifdef CONFIG_TREE_PREEMPT_RCU
  	struct rcu_node *rcu_blocked_node;
f41d911f8   Paul E. McKenney   rcu: Merge preemp...
1226
  #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
24278d148   Paul E. McKenney   rcu: priority boo...
1227
1228
1229
  #ifdef CONFIG_RCU_BOOST
  	struct rt_mutex *rcu_boost_mutex;
  #endif /* #ifdef CONFIG_RCU_BOOST */
e260be673   Paul E. McKenney   Preempt-RCU: impl...
1230

52f17b6c2   Chandra Seetharaman   [PATCH] per-task-...
1231
  #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1232
1233
1234
1235
  	struct sched_info sched_info;
  #endif
  
  	struct list_head tasks;
806c09a7d   Dario Faggioli   sched: Make pusha...
1236
  #ifdef CONFIG_SMP
917b627d4   Gregory Haskins   sched: create "pu...
1237
  	struct plist_node pushable_tasks;
806c09a7d   Dario Faggioli   sched: Make pusha...
1238
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1239
1240
  
  	struct mm_struct *mm, *active_mm;
4471a675d   Jiri Kosina   brk: COMPAT_BRK: ...
1241
1242
1243
  #ifdef CONFIG_COMPAT_BRK
  	unsigned brk_randomized:1;
  #endif
34e55232e   KAMEZAWA Hiroyuki   mm: avoid false s...
1244
1245
1246
  #if defined(SPLIT_RSS_COUNTING)
  	struct task_rss_stat	rss_stat;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1247
  /* task state */
97dc32cdb   William Cohen   reduce size of ta...
1248
  	int exit_state;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1249
1250
  	int exit_code, exit_signal;
  	int pdeath_signal;  /*  The signal sent when the parent dies  */
a8f072c1d   Tejun Heo   job control: rena...
1251
  	unsigned int jobctl;	/* JOBCTL_*, siglock protected */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1252
  	/* ??? */
97dc32cdb   William Cohen   reduce size of ta...
1253
  	unsigned int personality;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1254
  	unsigned did_exec:1;
f9ce1f1cd   Kentaro Takeda   Add in_execve fla...
1255
1256
  	unsigned in_execve:1;	/* Tell the LSMs that the process is doing an
  				 * execve */
8f0dfc34e   Arjan van de Ven   sched: Provide io...
1257
  	unsigned in_iowait:1;
ca94c4425   Lennart Poettering   sched: Introduce ...
1258
1259
1260
  
  	/* Revert to default priority/policy when forking */
  	unsigned sched_reset_on_fork:1;
a8e4f2eae   Peter Zijlstra   sched: Delay task...
1261
  	unsigned sched_contributes_to_load:1;
ca94c4425   Lennart Poettering   sched: Introduce ...
1262

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1263
1264
  	pid_t pid;
  	pid_t tgid;
0a4254058   Arjan van de Ven   [PATCH] Add the c...
1265

1314562a9   Hiroshi Shimamoto   sched, task_struc...
1266
  #ifdef CONFIG_CC_STACKPROTECTOR
0a4254058   Arjan van de Ven   [PATCH] Add the c...
1267
1268
  	/* Canary value for the -fstack-protector gcc feature */
  	unsigned long stack_canary;
1314562a9   Hiroshi Shimamoto   sched, task_struc...
1269
  #endif
e00320875   Ingo Molnar   x86: fix stackpro...
1270

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1271
1272
1273
  	/* 
  	 * pointers to (original) parent process, youngest child, younger sibling,
  	 * older sibling, respectively.  (p->father can be replaced with 
f470021ad   Roland McGrath   ptrace children r...
1274
  	 * p->real_parent->pid)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1275
  	 */
abd63bc3a   Kees Cook   sched: Mark paren...
1276
1277
  	struct task_struct __rcu *real_parent; /* real parent process */
  	struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1278
  	/*
f470021ad   Roland McGrath   ptrace children r...
1279
  	 * children/sibling forms the list of my natural children
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1280
1281
1282
1283
  	 */
  	struct list_head children;	/* list of my children */
  	struct list_head sibling;	/* linkage in my parent's children list */
  	struct task_struct *group_leader;	/* threadgroup leader */
f470021ad   Roland McGrath   ptrace children r...
1284
1285
1286
1287
1288
1289
1290
  	/*
  	 * ptraced is the list of tasks this task is using ptrace on.
  	 * This includes both natural children and PTRACE_ATTACH targets.
  	 * p->ptrace_entry is p's link on the p->parent->ptraced list.
  	 */
  	struct list_head ptraced;
  	struct list_head ptrace_entry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1291
  	/* PID/PID hash table linkage. */
92476d7fc   Eric W. Biederman   [PATCH] pidhash: ...
1292
  	struct pid_link pids[PIDTYPE_MAX];
47e65328a   Oleg Nesterov   [PATCH] pids: kil...
1293
  	struct list_head thread_group;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1294
1295
1296
1297
  
  	struct completion *vfork_done;		/* for vfork() */
  	int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
  	int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */
c66f08be7   Michael Neuling   Add scaled time t...
1298
  	cputime_t utime, stime, utimescaled, stimescaled;
9ac52315d   Laurent Vivier   sched: guest CPU ...
1299
  	cputime_t gtime;
d99ca3b97   Hidetoshi Seto   sched, cputime: C...
1300
  #ifndef CONFIG_VIRT_CPU_ACCOUNTING
9301899be   Balbir Singh   sched: fix /proc/...
1301
  	cputime_t prev_utime, prev_stime;
d99ca3b97   Hidetoshi Seto   sched, cputime: C...
1302
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1303
  	unsigned long nvcsw, nivcsw; /* context switch counts */
924b42d5a   Tomas Janousek   Use boot based ti...
1304
1305
  	struct timespec start_time; 		/* monotonic time */
  	struct timespec real_start_time;	/* boot based time */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1306
1307
  /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
  	unsigned long min_flt, maj_flt;
f06febc96   Frank Mayhar   timers: fix itime...
1308
  	struct task_cputime cputime_expires;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1309
1310
1311
  	struct list_head cpu_timers[3];
  
  /* process credentials */
1b0ba1c90   Arnd Bergmann   credentials: rcu ...
1312
  	const struct cred __rcu *real_cred; /* objective and real subjective task
3b11a1dec   David Howells   CRED: Differentia...
1313
  					 * credentials (COW) */
1b0ba1c90   Arnd Bergmann   credentials: rcu ...
1314
  	const struct cred __rcu *cred;	/* effective (overridable) subjective task
3b11a1dec   David Howells   CRED: Differentia...
1315
  					 * credentials (COW) */
ee18d64c1   David Howells   KEYS: Add a keyct...
1316
  	struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
b6dff3ec5   David Howells   CRED: Separate ta...
1317

367720923   Paolo 'Blaisorblade' Giarrusso   [PATCH] comments ...
1318
1319
1320
  	char comm[TASK_COMM_LEN]; /* executable name excluding path
  				     - access with [gs]et_task_comm (which lock
  				       it with task_lock())
221af7f87   Linus Torvalds   Split 'flush_old_...
1321
  				     - initialized normally by setup_new_exec */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1322
1323
  /* file system info */
  	int link_count, total_link_count;
3d5b6fccc   Alexey Dobriyan   [PATCH] task_stru...
1324
  #ifdef CONFIG_SYSVIPC
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1325
1326
  /* ipc stuff */
  	struct sysv_sem sysvsem;
3d5b6fccc   Alexey Dobriyan   [PATCH] task_stru...
1327
  #endif
e162b39a3   Mandeep Singh Baines   softlockup: decou...
1328
  #ifdef CONFIG_DETECT_HUNG_TASK
82a1fcb90   Ingo Molnar   softlockup: autom...
1329
  /* hung task detection */
82a1fcb90   Ingo Molnar   softlockup: autom...
1330
1331
  	unsigned long last_switch_count;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1332
1333
1334
1335
1336
1337
  /* CPU-specific state of this task */
  	struct thread_struct thread;
  /* filesystem information */
  	struct fs_struct *fs;
  /* open file information */
  	struct files_struct *files;
1651e14e2   Serge E. Hallyn   [PATCH] namespace...
1338
  /* namespaces */
ab516013a   Serge E. Hallyn   [PATCH] namespace...
1339
  	struct nsproxy *nsproxy;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1340
1341
1342
1343
1344
  /* signal handlers */
  	struct signal_struct *signal;
  	struct sighand_struct *sighand;
  
  	sigset_t blocked, real_blocked;
f3de272b8   Roland McGrath   signals: use HAVE...
1345
  	sigset_t saved_sigmask;	/* restored if set_restore_sigmask() was used */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1346
1347
1348
1349
1350
1351
1352
  	struct sigpending pending;
  
  	unsigned long sas_ss_sp;
  	size_t sas_ss_size;
  	int (*notifier)(void *priv);
  	void *notifier_data;
  	sigset_t *notifier_mask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1353
  	struct audit_context *audit_context;
bfef93a5d   Al Viro   [PATCH] get rid o...
1354
1355
  #ifdef CONFIG_AUDITSYSCALL
  	uid_t loginuid;
4746ec5b0   Eric Paris   [AUDIT] add sessi...
1356
  	unsigned int sessionid;
bfef93a5d   Al Viro   [PATCH] get rid o...
1357
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1358
1359
1360
1361
1362
  	seccomp_t seccomp;
  
  /* Thread group tracking */
     	u32 parent_exec_id;
     	u32 self_exec_id;
58568d2a8   Miao Xie   cpuset,mm: update...
1363
1364
  /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
   * mempolicy */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1365
  	spinlock_t alloc_lock;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1366

3aa551c9b   Thomas Gleixner   genirq: add threa...
1367
1368
1369
1370
  #ifdef CONFIG_GENERIC_HARDIRQS
  	/* IRQ handler threads */
  	struct irqaction *irqaction;
  #endif
b29739f90   Ingo Molnar   [PATCH] pi-futex:...
1371
  	/* Protection of the PI data structures: */
1d6154825   Thomas Gleixner   sched: Convert pi...
1372
  	raw_spinlock_t pi_lock;
b29739f90   Ingo Molnar   [PATCH] pi-futex:...
1373

23f78d4a0   Ingo Molnar   [PATCH] pi-futex:...
1374
1375
1376
1377
1378
  #ifdef CONFIG_RT_MUTEXES
  	/* PI waiters blocked on a rt_mutex held by this task */
  	struct plist_head pi_waiters;
  	/* Deadlock detection and priority inheritance handling */
  	struct rt_mutex_waiter *pi_blocked_on;
23f78d4a0   Ingo Molnar   [PATCH] pi-futex:...
1379
  #endif
408894ee4   Ingo Molnar   [PATCH] mutex sub...
1380
1381
1382
1383
  #ifdef CONFIG_DEBUG_MUTEXES
  	/* mutex deadlock detection */
  	struct mutex_waiter *blocked_on;
  #endif
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
1384
1385
  #ifdef CONFIG_TRACE_IRQFLAGS
  	unsigned int irq_events;
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
1386
  	unsigned long hardirq_enable_ip;
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
1387
  	unsigned long hardirq_disable_ip;
fa1452e80   Hiroshi Shimamoto   locking, task_str...
1388
  	unsigned int hardirq_enable_event;
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
1389
  	unsigned int hardirq_disable_event;
fa1452e80   Hiroshi Shimamoto   locking, task_str...
1390
1391
  	int hardirqs_enabled;
  	int hardirq_context;
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
1392
  	unsigned long softirq_disable_ip;
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
1393
  	unsigned long softirq_enable_ip;
fa1452e80   Hiroshi Shimamoto   locking, task_str...
1394
  	unsigned int softirq_disable_event;
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
1395
  	unsigned int softirq_enable_event;
fa1452e80   Hiroshi Shimamoto   locking, task_str...
1396
  	int softirqs_enabled;
de30a2b35   Ingo Molnar   [PATCH] lockdep: ...
1397
1398
  	int softirq_context;
  #endif
fbb9ce953   Ingo Molnar   [PATCH] lockdep: ...
1399
  #ifdef CONFIG_LOCKDEP
bdb9441e9   Peter Zijlstra   lockdep: increase...
1400
  # define MAX_LOCK_DEPTH 48UL
fbb9ce953   Ingo Molnar   [PATCH] lockdep: ...
1401
1402
  	u64 curr_chain_key;
  	int lockdep_depth;
fbb9ce953   Ingo Molnar   [PATCH] lockdep: ...
1403
  	unsigned int lockdep_recursion;
c7aceaba0   Richard Kennedy   sched: reorder ta...
1404
  	struct held_lock held_locks[MAX_LOCK_DEPTH];
cf40bd16f   Nick Piggin   lockdep: annotate...
1405
  	gfp_t lockdep_reclaim_gfp;
fbb9ce953   Ingo Molnar   [PATCH] lockdep: ...
1406
  #endif
408894ee4   Ingo Molnar   [PATCH] mutex sub...
1407

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1408
1409
  /* journalling filesystem info */
  	void *journal_info;
d89d87965   Neil Brown   When stacked bloc...
1410
  /* stacked block device info */
bddd87c7e   Akinobu Mita   blk-core: use BIO...
1411
  	struct bio_list *bio_list;
d89d87965   Neil Brown   When stacked bloc...
1412

73c101011   Jens Axboe   block: initial pa...
1413
1414
1415
1416
  #ifdef CONFIG_BLOCK
  /* stack plugging */
  	struct blk_plug *plug;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1417
1418
  /* VM state */
  	struct reclaim_state *reclaim_state;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1419
1420
1421
1422
1423
1424
  	struct backing_dev_info *backing_dev_info;
  
  	struct io_context *io_context;
  
  	unsigned long ptrace_message;
  	siginfo_t *last_siginfo; /* For ptrace use.  */
7c3ab7381   Andrew Morton   [PATCH] io-accoun...
1425
  	struct task_io_accounting ioac;
8f0ab5147   Jay Lan   [PATCH] csa: conv...
1426
  #if defined(CONFIG_TASK_XACCT)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1427
1428
  	u64 acct_rss_mem1;	/* accumulated rss usage */
  	u64 acct_vm_mem1;	/* accumulated virtual memory usage */
49b5cf347   Jonathan Lim   accounting: accou...
1429
  	cputime_t acct_timexpd;	/* stime + utime since last update */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1430
1431
  #endif
  #ifdef CONFIG_CPUSETS
58568d2a8   Miao Xie   cpuset,mm: update...
1432
  	nodemask_t mems_allowed;	/* Protected by alloc_lock */
c0ff7453b   Miao Xie   cpuset,mm: fix no...
1433
  	int mems_allowed_change_disable;
825a46af5   Paul Jackson   [PATCH] cpuset me...
1434
  	int cpuset_mem_spread_rotor;
6adef3ebe   Jack Steiner   cpusets: new roun...
1435
  	int cpuset_slab_spread_rotor;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1436
  #endif
ddbcc7e8e   Paul Menage   Task Control Grou...
1437
  #ifdef CONFIG_CGROUPS
817929ec2   Paul Menage   Task Control Grou...
1438
  	/* Control Group info protected by css_set_lock */
2c392b8c3   Arnd Bergmann   cgroups: __rcu an...
1439
  	struct css_set __rcu *cgroups;
817929ec2   Paul Menage   Task Control Grou...
1440
1441
  	/* cg_list protected by css_set_lock and tsk->alloc_lock */
  	struct list_head cg_list;
ddbcc7e8e   Paul Menage   Task Control Grou...
1442
  #endif
42b2dd0a0   Alexey Dobriyan   Shrink task_struc...
1443
  #ifdef CONFIG_FUTEX
0771dfefc   Ingo Molnar   [PATCH] lightweig...
1444
  	struct robust_list_head __user *robust_list;
34f192c65   Ingo Molnar   [PATCH] lightweig...
1445
1446
1447
  #ifdef CONFIG_COMPAT
  	struct compat_robust_list_head __user *compat_robust_list;
  #endif
c87e2837b   Ingo Molnar   [PATCH] pi-futex:...
1448
1449
  	struct list_head pi_state_list;
  	struct futex_pi_state *pi_state_cache;
42b2dd0a0   Alexey Dobriyan   Shrink task_struc...
1450
  #endif
cdd6c482c   Ingo Molnar   perf: Do the big ...
1451
  #ifdef CONFIG_PERF_EVENTS
8dc85d547   Peter Zijlstra   perf: Multiple ta...
1452
  	struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
cdd6c482c   Ingo Molnar   perf: Do the big ...
1453
1454
  	struct mutex perf_event_mutex;
  	struct list_head perf_event_list;
a63eaf34a   Paul Mackerras   perf_counter: Dyn...
1455
  #endif
c7aceaba0   Richard Kennedy   sched: reorder ta...
1456
  #ifdef CONFIG_NUMA
58568d2a8   Miao Xie   cpuset,mm: update...
1457
  	struct mempolicy *mempolicy;	/* Protected by alloc_lock */
c7aceaba0   Richard Kennedy   sched: reorder ta...
1458
  	short il_next;
207205a2b   Eric Dumazet   kthread: NUMA awa...
1459
  	short pref_node_fork;
c7aceaba0   Richard Kennedy   sched: reorder ta...
1460
  #endif
e56d09031   Ingo Molnar   [PATCH] RCU signa...
1461
  	struct rcu_head rcu;
b92ce5589   Jens Axboe   [PATCH] splice: a...
1462
1463
1464
1465
1466
  
  	/*
  	 * cache last used pipe for splice
  	 */
  	struct pipe_inode_info *splice_pipe;
ca74e92b4   Shailabh Nagar   [PATCH] per-task-...
1467
1468
  #ifdef	CONFIG_TASK_DELAY_ACCT
  	struct task_delay_info *delays;
f4f154fd9   Akinobu Mita   [PATCH] fault inj...
1469
1470
1471
  #endif
  #ifdef CONFIG_FAULT_INJECTION
  	int make_it_fail;
ca74e92b4   Shailabh Nagar   [PATCH] per-task-...
1472
  #endif
9d823e8f6   Wu Fengguang   writeback: per ta...
1473
1474
1475
1476
1477
1478
  	/*
  	 * when (nr_dirtied >= nr_dirtied_pause), it's time to call
  	 * balance_dirty_pages() for some dirty throttling pause
  	 */
  	int nr_dirtied;
  	int nr_dirtied_pause;
83712358b   Wu Fengguang   writeback: dirty ...
1479
  	unsigned long dirty_paused_when; /* start of a write-and-pause period */
9d823e8f6   Wu Fengguang   writeback: per ta...
1480

9745512ce   Arjan van de Ven   sched: latencytop...
1481
1482
1483
1484
  #ifdef CONFIG_LATENCYTOP
  	int latency_record_count;
  	struct latency_record latency_record[LT_SAVECOUNT];
  #endif
6976675d9   Arjan van de Ven   hrtimer: create a...
1485
1486
1487
1488
1489
1490
  	/*
  	 * time slack values; these are used to round up poll() and
  	 * select() etc timeout values. These are in nanoseconds.
  	 */
  	unsigned long timer_slack_ns;
  	unsigned long default_timer_slack_ns;
f8d570a47   David Miller   net: Fix recursiv...
1491
1492
  
  	struct list_head	*scm_work_list;
fb52607af   Frederic Weisbecker   tracing/function-...
1493
  #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3ad2f3fbb   Daniel Mack   tree-wide: Assort...
1494
  	/* Index of current stored address in ret_stack */
f201ae235   Frederic Weisbecker   tracing/function-...
1495
1496
1497
  	int curr_ret_stack;
  	/* Stack of return addresses for return function tracing */
  	struct ftrace_ret_stack	*ret_stack;
8aef2d285   Steven Rostedt   function-graph: i...
1498
1499
  	/* time stamp for last schedule */
  	unsigned long long ftrace_timestamp;
f201ae235   Frederic Weisbecker   tracing/function-...
1500
1501
1502
1503
1504
  	/*
  	 * Number of functions that haven't been traced
  	 * because of depth overrun.
  	 */
  	atomic_t trace_overrun;
380c4b141   Frederic Weisbecker   tracing/function-...
1505
1506
  	/* Pause for the tracing */
  	atomic_t tracing_graph_pause;
f201ae235   Frederic Weisbecker   tracing/function-...
1507
  #endif
ea4e2bc4d   Steven Rostedt   ftrace: graph of ...
1508
1509
1510
  #ifdef CONFIG_TRACING
  	/* state flags for use by tracers */
  	unsigned long trace;
b1cff0ad1   Steven Rostedt   ftrace: Add inter...
1511
  	/* bitmask and counter of trace recursion */
261842b7c   Steven Rostedt   tracing: add same...
1512
1513
  	unsigned long trace_recursion;
  #endif /* CONFIG_TRACING */
569b846df   KAMEZAWA Hiroyuki   memcg: coalesce u...
1514
1515
1516
1517
  #ifdef CONFIG_CGROUP_MEM_RES_CTLR /* memcg uses this to do batch job */
  	struct memcg_batch_info {
  		int do_batch;	/* incremented when batch uncharge started */
  		struct mem_cgroup *memcg; /* target memcg of uncharge */
7ffd4ca7a   Johannes Weiner   memcg: convert un...
1518
1519
  		unsigned long nr_pages;	/* uncharged usage */
  		unsigned long memsw_nr_pages; /* uncharged mem+swap usage */
569b846df   KAMEZAWA Hiroyuki   memcg: coalesce u...
1520
1521
  	} memcg_batch;
  #endif
bf26c0184   Frederic Weisbecker   ptrace: Prepare t...
1522
1523
1524
  #ifdef CONFIG_HAVE_HW_BREAKPOINT
  	atomic_t ptrace_bp_refcnt;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1525
  };
76e6eee03   Rusty Russell   cpumask: tsk_cpum...
1526
  /* Future-safe accessor for struct task_struct's cpus_allowed. */
a4636818f   Rusty Russell   cpumask: rename t...
1527
  #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76e6eee03   Rusty Russell   cpumask: tsk_cpum...
1528

e05606d33   Ingo Molnar   sched: clean up t...
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
  /*
   * Priority of a process goes from 0..MAX_PRIO-1, valid RT
   * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
   * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
   * values are inverted: lower p->prio value means higher priority.
   *
   * The MAX_USER_RT_PRIO value allows the actual maximum
   * RT priority to be separate from the value exported to
   * user-space.  This allows kernel threads to set their
   * priority to a value higher than any user task. Note:
   * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
   */
  
  #define MAX_USER_RT_PRIO	100
  #define MAX_RT_PRIO		MAX_USER_RT_PRIO
  
  #define MAX_PRIO		(MAX_RT_PRIO + 40)
  #define DEFAULT_PRIO		(MAX_RT_PRIO + 20)
  
  static inline int rt_prio(int prio)
  {
  	if (unlikely(prio < MAX_RT_PRIO))
  		return 1;
  	return 0;
  }
e868171a9   Alexey Dobriyan   De-constify sched.h
1554
  static inline int rt_task(struct task_struct *p)
e05606d33   Ingo Molnar   sched: clean up t...
1555
1556
1557
  {
  	return rt_prio(p->prio);
  }
e868171a9   Alexey Dobriyan   De-constify sched.h
1558
  static inline struct pid *task_pid(struct task_struct *task)
22c935f47   Eric W. Biederman   [PATCH] pid: impl...
1559
1560
1561
  {
  	return task->pids[PIDTYPE_PID].pid;
  }
e868171a9   Alexey Dobriyan   De-constify sched.h
1562
  static inline struct pid *task_tgid(struct task_struct *task)
22c935f47   Eric W. Biederman   [PATCH] pid: impl...
1563
1564
1565
  {
  	return task->group_leader->pids[PIDTYPE_PID].pid;
  }
6dda81f43   Oleg Nesterov   pids: document ta...
1566
1567
1568
1569
1570
  /*
   * Without tasklist or rcu lock it is not safe to dereference
   * the result of task_pgrp/task_session even if task == current,
   * we can race with another thread doing sys_setsid/sys_setpgid.
   */
e868171a9   Alexey Dobriyan   De-constify sched.h
1571
  static inline struct pid *task_pgrp(struct task_struct *task)
22c935f47   Eric W. Biederman   [PATCH] pid: impl...
1572
1573
1574
  {
  	return task->group_leader->pids[PIDTYPE_PGID].pid;
  }
e868171a9   Alexey Dobriyan   De-constify sched.h
1575
  static inline struct pid *task_session(struct task_struct *task)
22c935f47   Eric W. Biederman   [PATCH] pid: impl...
1576
1577
1578
  {
  	return task->group_leader->pids[PIDTYPE_SID].pid;
  }
7af572947   Pavel Emelyanov   pid namespaces: h...
1579
1580
1581
1582
1583
1584
1585
  struct pid_namespace;
  
  /*
   * the helpers to get the task's different pids as they are seen
   * from various namespaces
   *
   * task_xid_nr()     : global id, i.e. the id seen from the init namespace;
44c4e1b25   Eric W. Biederman   pid: Extend/Fix p...
1586
1587
   * task_xid_vnr()    : virtual id, i.e. the id seen from the pid namespace of
   *                     current.
7af572947   Pavel Emelyanov   pid namespaces: h...
1588
1589
1590
1591
   * task_xid_nr_ns()  : id seen from the ns specified;
   *
   * set_task_vxid()   : assigns a virtual id to a task;
   *
7af572947   Pavel Emelyanov   pid namespaces: h...
1592
1593
   * see also pid_nr() etc in include/linux/pid.h
   */
52ee2dfdd   Oleg Nesterov   pids: refactor vn...
1594
1595
  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
  			struct pid_namespace *ns);
7af572947   Pavel Emelyanov   pid namespaces: h...
1596

e868171a9   Alexey Dobriyan   De-constify sched.h
1597
  static inline pid_t task_pid_nr(struct task_struct *tsk)
7af572947   Pavel Emelyanov   pid namespaces: h...
1598
1599
1600
  {
  	return tsk->pid;
  }
52ee2dfdd   Oleg Nesterov   pids: refactor vn...
1601
1602
1603
1604
1605
  static inline pid_t task_pid_nr_ns(struct task_struct *tsk,
  					struct pid_namespace *ns)
  {
  	return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
  }
7af572947   Pavel Emelyanov   pid namespaces: h...
1606
1607
1608
  
  static inline pid_t task_pid_vnr(struct task_struct *tsk)
  {
52ee2dfdd   Oleg Nesterov   pids: refactor vn...
1609
  	return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7af572947   Pavel Emelyanov   pid namespaces: h...
1610
  }
e868171a9   Alexey Dobriyan   De-constify sched.h
1611
  static inline pid_t task_tgid_nr(struct task_struct *tsk)
7af572947   Pavel Emelyanov   pid namespaces: h...
1612
1613
1614
  {
  	return tsk->tgid;
  }
2f2a3a46f   Pavel Emelyanov   Uninline the task...
1615
  pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
7af572947   Pavel Emelyanov   pid namespaces: h...
1616
1617
1618
1619
1620
  
  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
  {
  	return pid_vnr(task_tgid(tsk));
  }
52ee2dfdd   Oleg Nesterov   pids: refactor vn...
1621
1622
  static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk,
  					struct pid_namespace *ns)
7af572947   Pavel Emelyanov   pid namespaces: h...
1623
  {
52ee2dfdd   Oleg Nesterov   pids: refactor vn...
1624
  	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
7af572947   Pavel Emelyanov   pid namespaces: h...
1625
  }
7af572947   Pavel Emelyanov   pid namespaces: h...
1626
1627
  static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
  {
52ee2dfdd   Oleg Nesterov   pids: refactor vn...
1628
  	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
7af572947   Pavel Emelyanov   pid namespaces: h...
1629
  }
52ee2dfdd   Oleg Nesterov   pids: refactor vn...
1630
1631
  static inline pid_t task_session_nr_ns(struct task_struct *tsk,
  					struct pid_namespace *ns)
7af572947   Pavel Emelyanov   pid namespaces: h...
1632
  {
52ee2dfdd   Oleg Nesterov   pids: refactor vn...
1633
  	return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
7af572947   Pavel Emelyanov   pid namespaces: h...
1634
  }
7af572947   Pavel Emelyanov   pid namespaces: h...
1635
1636
  static inline pid_t task_session_vnr(struct task_struct *tsk)
  {
52ee2dfdd   Oleg Nesterov   pids: refactor vn...
1637
  	return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
7af572947   Pavel Emelyanov   pid namespaces: h...
1638
  }
1b0f7ffd0   Oleg Nesterov   pids: kill signal...
1639
1640
1641
1642
1643
  /* obsolete, do not use */
  static inline pid_t task_pgrp_nr(struct task_struct *tsk)
  {
  	return task_pgrp_nr_ns(tsk, &init_pid_ns);
  }
7af572947   Pavel Emelyanov   pid namespaces: h...
1644

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1645
1646
1647
1648
1649
1650
1651
1652
  /**
   * pid_alive - check that a task structure is not stale
   * @p: Task structure to be checked.
   *
   * Test if a process is not yet dead (at most zombie state)
   * If pid_alive fails, then pointers within the task structure
   * can be stale and must not be dereferenced.
   */
e868171a9   Alexey Dobriyan   De-constify sched.h
1653
  static inline int pid_alive(struct task_struct *p)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1654
  {
92476d7fc   Eric W. Biederman   [PATCH] pidhash: ...
1655
  	return p->pids[PIDTYPE_PID].pid != NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1656
  }
f400e198b   Sukadev Bhattiprolu   [PATCH] pidspace:...
1657
  /**
b460cbc58   Serge E. Hallyn   pid namespaces: d...
1658
   * is_global_init - check if a task structure is init
3260259f0   Henrik Kretzschmar   [PATCH] sched: fi...
1659
1660
1661
   * @tsk: Task structure to be checked.
   *
   * Check if a task structure is the first user space task the kernel created.
b460cbc58   Serge E. Hallyn   pid namespaces: d...
1662
   */
e868171a9   Alexey Dobriyan   De-constify sched.h
1663
  static inline int is_global_init(struct task_struct *tsk)
b461cc038   Pavel Emelyanov   pid namespaces: m...
1664
1665
1666
  {
  	return tsk->pid == 1;
  }
b460cbc58   Serge E. Hallyn   pid namespaces: d...
1667
1668
1669
1670
  
  /*
   * is_container_init:
   * check whether in the task is init in its own pid namespace.
f400e198b   Sukadev Bhattiprolu   [PATCH] pidspace:...
1671
   */
b461cc038   Pavel Emelyanov   pid namespaces: m...
1672
  extern int is_container_init(struct task_struct *tsk);
f400e198b   Sukadev Bhattiprolu   [PATCH] pidspace:...
1673

9ec52099e   Cedric Le Goater   [PATCH] replace c...
1674
  extern struct pid *cad_pid;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1675
  extern void free_task(struct task_struct *tsk);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1676
  #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
e56d09031   Ingo Molnar   [PATCH] RCU signa...
1677

158d9ebd1   Andrew Morton   [PATCH] resurrect...
1678
  extern void __put_task_struct(struct task_struct *t);
e56d09031   Ingo Molnar   [PATCH] RCU signa...
1679
1680
1681
1682
  
  static inline void put_task_struct(struct task_struct *t)
  {
  	if (atomic_dec_and_test(&t->usage))
8c7904a00   Eric W. Biederman   [PATCH] task: RCU...
1683
  		__put_task_struct(t);
e56d09031   Ingo Molnar   [PATCH] RCU signa...
1684
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1685

d180c5bcc   Hidetoshi Seto   sched: Introduce ...
1686
  extern void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st);
0cf55e1ec   Hidetoshi Seto   sched, cputime: I...
1687
  extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st);
49048622e   Balbir Singh   sched: fix proces...
1688

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1689
1690
1691
  /*
   * Per process flags
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1692
1693
  #define PF_STARTING	0x00000002	/* being created */
  #define PF_EXITING	0x00000004	/* getting shut down */
778e9a9c3   Alexey Kuznetsov   pi-futex: fix exi...
1694
  #define PF_EXITPIDONE	0x00000008	/* pi exit done on shut down */
94886b84b   Laurent Vivier   sched: guest CPU ...
1695
  #define PF_VCPU		0x00000010	/* I'm a virtual CPU */
21aa9af03   Tejun Heo   sched: add hooks ...
1696
  #define PF_WQ_WORKER	0x00000020	/* I'm a workqueue worker */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1697
  #define PF_FORKNOEXEC	0x00000040	/* forked but didn't exec */
4db96cf07   Andi Kleen   HWPOISON: Add PR_...
1698
  #define PF_MCE_PROCESS  0x00000080      /* process policy on mce errors */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1699
1700
1701
1702
  #define PF_SUPERPRIV	0x00000100	/* used super-user privileges */
  #define PF_DUMPCORE	0x00000200	/* dumped core */
  #define PF_SIGNALED	0x00000400	/* killed by a signal */
  #define PF_MEMALLOC	0x00000800	/* Allocating memory */
72fa59970   Vasiliy Kulikov   move RLIMIT_NPROC...
1703
  #define PF_NPROC_EXCEEDED 0x00001000	/* set_user noticed that RLIMIT_NPROC was exceeded */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1704
  #define PF_USED_MATH	0x00002000	/* if unset the fpu must be initialized before use */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1705
1706
1707
1708
  #define PF_NOFREEZE	0x00008000	/* this thread should not be frozen */
  #define PF_FROZEN	0x00010000	/* frozen for system suspend */
  #define PF_FSTRANS	0x00020000	/* inside a filesystem transaction */
  #define PF_KSWAPD	0x00040000	/* I am kswapd */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1709
  #define PF_LESS_THROTTLE 0x00100000	/* Throttle me less: I clean memory */
246bb0b1d   Oleg Nesterov   kill PF_BORROWED_...
1710
  #define PF_KTHREAD	0x00200000	/* I am a kernel thread */
b31dc66a5   Jens Axboe   [PATCH] Kill PF_S...
1711
1712
1713
1714
  #define PF_RANDOMIZE	0x00400000	/* randomize virtual address space */
  #define PF_SWAPWRITE	0x00800000	/* Allowed to write to swap */
  #define PF_SPREAD_PAGE	0x01000000	/* Spread page cache over cpuset */
  #define PF_SPREAD_SLAB	0x02000000	/* Spread some slab caches over cpuset */
9985b0bab   David Rientjes   sched: prevent bo...
1715
  #define PF_THREAD_BOUND	0x04000000	/* Thread bound to specific cpu */
4db96cf07   Andi Kleen   HWPOISON: Add PR_...
1716
  #define PF_MCE_EARLY    0x08000000      /* Early kill for mce process policy */
c61afb181   Paul Jackson   [PATCH] cpuset me...
1717
  #define PF_MEMPOLICY	0x10000000	/* Non-default NUMA mempolicy */
61a871228   Thomas Gleixner   [PATCH] pi-futex:...
1718
  #define PF_MUTEX_TESTER	0x20000000	/* Thread belongs to the rt mutex tester */
58a69cb47   Tejun Heo   workqueue, freeze...
1719
  #define PF_FREEZER_SKIP	0x40000000	/* Freezer should not count it as freezable */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
  
  /*
   * Only the _current_ task can read/write to tsk->flags, but other
   * tasks can access tsk->flags in readonly mode for example
   * with tsk_used_math (like during threaded core dumping).
   * There is however an exception to this rule during ptrace
   * or during fork: the ptracer task is allowed to write to the
   * child->flags of its traced child (same goes for fork, the parent
   * can write to the child->flags), because we're guaranteed the
   * child is not running and in turn not changing child->flags
   * at the same time the parent does it.
   */
  #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
  #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
  #define clear_used_math() clear_stopped_child_used_math(current)
  #define set_used_math() set_stopped_child_used_math(current)
  #define conditional_stopped_child_used_math(condition, child) \
  	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
  #define conditional_used_math(condition) \
  	conditional_stopped_child_used_math(condition, current)
  #define copy_to_stopped_child_used_math(child) \
  	do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
  /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
  #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
  #define used_math() tsk_used_math(current)
e5c1902e9   Tejun Heo   signal: Fix prema...
1745
  /*
a8f072c1d   Tejun Heo   job control: rena...
1746
   * task->jobctl flags
e5c1902e9   Tejun Heo   signal: Fix prema...
1747
   */
a8f072c1d   Tejun Heo   job control: rena...
1748
  #define JOBCTL_STOP_SIGMASK	0xffff	/* signr of the last group stop */
e5c1902e9   Tejun Heo   signal: Fix prema...
1749

a8f072c1d   Tejun Heo   job control: rena...
1750
1751
1752
  #define JOBCTL_STOP_DEQUEUED_BIT 16	/* stop signal dequeued */
  #define JOBCTL_STOP_PENDING_BIT	17	/* task should stop for group stop */
  #define JOBCTL_STOP_CONSUME_BIT	18	/* consume group stop count */
73ddff2be   Tejun Heo   job control: intr...
1753
  #define JOBCTL_TRAP_STOP_BIT	19	/* trap for STOP */
fb1d910c1   Tejun Heo   ptrace: implement...
1754
  #define JOBCTL_TRAP_NOTIFY_BIT	20	/* trap for NOTIFY */
a8f072c1d   Tejun Heo   job control: rena...
1755
  #define JOBCTL_TRAPPING_BIT	21	/* switching to TRACED */
544b2c91a   Tejun Heo   ptrace: implement...
1756
  #define JOBCTL_LISTENING_BIT	22	/* ptracer is listening for events */
a8f072c1d   Tejun Heo   job control: rena...
1757
1758
1759
1760
  
  #define JOBCTL_STOP_DEQUEUED	(1 << JOBCTL_STOP_DEQUEUED_BIT)
  #define JOBCTL_STOP_PENDING	(1 << JOBCTL_STOP_PENDING_BIT)
  #define JOBCTL_STOP_CONSUME	(1 << JOBCTL_STOP_CONSUME_BIT)
73ddff2be   Tejun Heo   job control: intr...
1761
  #define JOBCTL_TRAP_STOP	(1 << JOBCTL_TRAP_STOP_BIT)
fb1d910c1   Tejun Heo   ptrace: implement...
1762
  #define JOBCTL_TRAP_NOTIFY	(1 << JOBCTL_TRAP_NOTIFY_BIT)
a8f072c1d   Tejun Heo   job control: rena...
1763
  #define JOBCTL_TRAPPING		(1 << JOBCTL_TRAPPING_BIT)
544b2c91a   Tejun Heo   ptrace: implement...
1764
  #define JOBCTL_LISTENING	(1 << JOBCTL_LISTENING_BIT)
a8f072c1d   Tejun Heo   job control: rena...
1765

fb1d910c1   Tejun Heo   ptrace: implement...
1766
  #define JOBCTL_TRAP_MASK	(JOBCTL_TRAP_STOP | JOBCTL_TRAP_NOTIFY)
73ddff2be   Tejun Heo   job control: intr...
1767
  #define JOBCTL_PENDING_MASK	(JOBCTL_STOP_PENDING | JOBCTL_TRAP_MASK)
3759a0d94   Tejun Heo   job control: intr...
1768

7dd3db54e   Tejun Heo   job control: intr...
1769
1770
  extern bool task_set_jobctl_pending(struct task_struct *task,
  				    unsigned int mask);
73ddff2be   Tejun Heo   job control: intr...
1771
  extern void task_clear_jobctl_trapping(struct task_struct *task);
3759a0d94   Tejun Heo   job control: intr...
1772
1773
  extern void task_clear_jobctl_pending(struct task_struct *task,
  				      unsigned int mask);
39efa3ef3   Tejun Heo   signal: Use GROUP...
1774

a57eb940d   Paul E. McKenney   rcu: Add a TINY_P...
1775
  #ifdef CONFIG_PREEMPT_RCU
f41d911f8   Paul E. McKenney   rcu: Merge preemp...
1776
1777
  
  #define RCU_READ_UNLOCK_BLOCKED (1 << 0) /* blocked while in RCU read-side. */
24278d148   Paul E. McKenney   rcu: priority boo...
1778
1779
  #define RCU_READ_UNLOCK_BOOSTED (1 << 1) /* boosted while in RCU read-side. */
  #define RCU_READ_UNLOCK_NEED_QS (1 << 2) /* RCU core needs CPU response. */
f41d911f8   Paul E. McKenney   rcu: Merge preemp...
1780
1781
1782
1783
1784
  
  static inline void rcu_copy_process(struct task_struct *p)
  {
  	p->rcu_read_lock_nesting = 0;
  	p->rcu_read_unlock_special = 0;
a57eb940d   Paul E. McKenney   rcu: Add a TINY_P...
1785
  #ifdef CONFIG_TREE_PREEMPT_RCU
dd5d19baf   Paul E. McKenney   rcu: Create rcutr...
1786
  	p->rcu_blocked_node = NULL;
24278d148   Paul E. McKenney   rcu: priority boo...
1787
1788
1789
1790
  #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
  #ifdef CONFIG_RCU_BOOST
  	p->rcu_boost_mutex = NULL;
  #endif /* #ifdef CONFIG_RCU_BOOST */
f41d911f8   Paul E. McKenney   rcu: Merge preemp...
1791
1792
  	INIT_LIST_HEAD(&p->rcu_node_entry);
  }
f41d911f8   Paul E. McKenney   rcu: Merge preemp...
1793
1794
1795
1796
1797
1798
1799
  #else
  
  static inline void rcu_copy_process(struct task_struct *p)
  {
  }
  
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1800
  #ifdef CONFIG_SMP
1e1b6c511   KOSAKI Motohiro   cpuset: Fix cpuse...
1801
1802
  extern void do_set_cpus_allowed(struct task_struct *p,
  			       const struct cpumask *new_mask);
cd8ba7cd9   Mike Travis   sched: add new se...
1803
  extern int set_cpus_allowed_ptr(struct task_struct *p,
96f874e26   Rusty Russell   sched: convert re...
1804
  				const struct cpumask *new_mask);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1805
  #else
1e1b6c511   KOSAKI Motohiro   cpuset: Fix cpuse...
1806
1807
1808
1809
  static inline void do_set_cpus_allowed(struct task_struct *p,
  				      const struct cpumask *new_mask)
  {
  }
cd8ba7cd9   Mike Travis   sched: add new se...
1810
  static inline int set_cpus_allowed_ptr(struct task_struct *p,
96f874e26   Rusty Russell   sched: convert re...
1811
  				       const struct cpumask *new_mask)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1812
  {
96f874e26   Rusty Russell   sched: convert re...
1813
  	if (!cpumask_test_cpu(0, new_mask))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1814
1815
1816
1817
  		return -EINVAL;
  	return 0;
  }
  #endif
e0ad95568   Rusty Russell   cpumask: don't de...
1818
1819
  
  #ifndef CONFIG_CPUMASK_OFFSTACK
cd8ba7cd9   Mike Travis   sched: add new se...
1820
1821
1822
1823
  static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
  {
  	return set_cpus_allowed_ptr(p, &new_mask);
  }
e0ad95568   Rusty Russell   cpumask: don't de...
1824
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1825

b342501cd   Ingo Molnar   sched: allow arch...
1826
  /*
c676329ab   Peter Zijlstra   sched_clock: Add ...
1827
1828
1829
1830
1831
1832
   * Do not use outside of architecture code which knows its limitations.
   *
   * sched_clock() has no promise of monotonicity or bounded drift between
   * CPUs, use (which you should not) requires disabling IRQs.
   *
   * Please use one of the three interfaces below.
b342501cd   Ingo Molnar   sched: allow arch...
1833
   */
1bbfa6f25   Mike Frysinger   sched: Mark sched...
1834
  extern unsigned long long notrace sched_clock(void);
c676329ab   Peter Zijlstra   sched_clock: Add ...
1835
1836
1837
1838
1839
1840
  /*
   * See the comment in kernel/sched_clock.c
   */
  extern u64 cpu_clock(int cpu);
  extern u64 local_clock(void);
  extern u64 sched_clock_cpu(int cpu);
e436d8008   Ingo Molnar   [PATCH] sched: im...
1841

c1955a3d4   Peter Zijlstra   sched_clock: dela...
1842
  extern void sched_clock_init(void);
3e51f33fc   Peter Zijlstra   sched: add option...
1843

c1955a3d4   Peter Zijlstra   sched_clock: dela...
1844
  #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
3e51f33fc   Peter Zijlstra   sched: add option...
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
  static inline void sched_clock_tick(void)
  {
  }
  
  static inline void sched_clock_idle_sleep_event(void)
  {
  }
  
  static inline void sched_clock_idle_wakeup_event(u64 delta_ns)
  {
  }
  #else
c676329ab   Peter Zijlstra   sched_clock: Add ...
1857
1858
1859
1860
1861
1862
1863
  /*
   * Architectures can set this to 1 if they have specified
   * CONFIG_HAVE_UNSTABLE_SCHED_CLOCK in their arch Kconfig,
   * but then during bootup it turns out that sched_clock()
   * is reliable after all:
   */
  extern int sched_clock_stable;
3e51f33fc   Peter Zijlstra   sched: add option...
1864
1865
1866
1867
  extern void sched_clock_tick(void);
  extern void sched_clock_idle_sleep_event(void);
  extern void sched_clock_idle_wakeup_event(u64 delta_ns);
  #endif
b52bfee44   Venkatesh Pallipadi   sched: Add IRQ_TI...
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
  #ifdef CONFIG_IRQ_TIME_ACCOUNTING
  /*
   * An i/f to runtime opt-in for irq time accounting based off of sched_clock.
   * The reason for this explicit opt-in is not to have perf penalty with
   * slow sched_clocks.
   */
  extern void enable_sched_clock_irqtime(void);
  extern void disable_sched_clock_irqtime(void);
  #else
  static inline void enable_sched_clock_irqtime(void) {}
  static inline void disable_sched_clock_irqtime(void) {}
  #endif
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
1880
  extern unsigned long long
41b86e9c5   Ingo Molnar   sched: make posix...
1881
  task_sched_runtime(struct task_struct *task);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1882
1883
1884
1885
1886
1887
1888
  
  /* sched_exec is called by processes performing an exec */
  #ifdef CONFIG_SMP
  extern void sched_exec(void);
  #else
  #define sched_exec()   {}
  #endif
2aa44d056   Ingo Molnar   sched: sched_cloc...
1889
1890
  extern void sched_clock_idle_sleep_event(void);
  extern void sched_clock_idle_wakeup_event(u64 delta_ns);
bb29ab268   Ingo Molnar   sched: x86, track...
1891

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1892
1893
1894
1895
1896
  #ifdef CONFIG_HOTPLUG_CPU
  extern void idle_task_exit(void);
  #else
  static inline void idle_task_exit(void) {}
  #endif
06d8308c6   Thomas Gleixner   NOHZ: reevaluate ...
1897
1898
1899
1900
1901
  #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
  extern void wake_up_idle_cpu(int cpu);
  #else
  static inline void wake_up_idle_cpu(int cpu) { }
  #endif
218050855   Peter Zijlstra   sched: adaptive s...
1902
  extern unsigned int sysctl_sched_latency;
b2be5e96d   Peter Zijlstra   sched: reintroduc...
1903
  extern unsigned int sysctl_sched_min_granularity;
bf0f6f24a   Ingo Molnar   sched: cfs core, ...
1904
  extern unsigned int sysctl_sched_wakeup_granularity;
bf0f6f24a   Ingo Molnar   sched: cfs core, ...
1905
  extern unsigned int sysctl_sched_child_runs_first;
1983a922a   Christian Ehrhardt   sched: Make tunab...
1906
1907
1908
1909
1910
1911
1912
1913
  
  enum sched_tunable_scaling {
  	SCHED_TUNABLESCALING_NONE,
  	SCHED_TUNABLESCALING_LOG,
  	SCHED_TUNABLESCALING_LINEAR,
  	SCHED_TUNABLESCALING_END,
  };
  extern enum sched_tunable_scaling sysctl_sched_tunable_scaling;
2bba22c50   Mike Galbraith   sched: Turn off c...
1914
  #ifdef CONFIG_SCHED_DEBUG
da84d9617   Ingo Molnar   sched: reintroduc...
1915
  extern unsigned int sysctl_sched_migration_cost;
b82d9fdd8   Peter Zijlstra   sched: avoid larg...
1916
  extern unsigned int sysctl_sched_nr_migrate;
e9e9250bc   Peter Zijlstra   sched: Scale down...
1917
  extern unsigned int sysctl_sched_time_avg;
cd1bb94b4   Arun R Bharadwaj   timers: /proc/sys...
1918
  extern unsigned int sysctl_timer_migration;
a7a4f8a75   Paul Turner   sched: Add sysctl...
1919
  extern unsigned int sysctl_sched_shares_window;
b2be5e96d   Peter Zijlstra   sched: reintroduc...
1920

1983a922a   Christian Ehrhardt   sched: Make tunab...
1921
  int sched_proc_update_handler(struct ctl_table *table, int write,
8d65af789   Alexey Dobriyan   sysctl: remove "s...
1922
  		void __user *buffer, size_t *length,
b2be5e96d   Peter Zijlstra   sched: reintroduc...
1923
  		loff_t *ppos);
2bd8e6d42   Ingo Molnar   sched: use consta...
1924
  #endif
eea08f32a   Arun R Bharadwaj   timers: Logic to ...
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
  #ifdef CONFIG_SCHED_DEBUG
  static inline unsigned int get_sysctl_timer_migration(void)
  {
  	return sysctl_timer_migration;
  }
  #else
  static inline unsigned int get_sysctl_timer_migration(void)
  {
  	return 1;
  }
  #endif
9f0c1e560   Peter Zijlstra   sched: rt-group: ...
1936
1937
  extern unsigned int sysctl_sched_rt_period;
  extern int sysctl_sched_rt_runtime;
2bd8e6d42   Ingo Molnar   sched: use consta...
1938

d0b27fa77   Peter Zijlstra   sched: rt-group: ...
1939
  int sched_rt_handler(struct ctl_table *table, int write,
8d65af789   Alexey Dobriyan   sysctl: remove "s...
1940
  		void __user *buffer, size_t *lenp,
d0b27fa77   Peter Zijlstra   sched: rt-group: ...
1941
  		loff_t *ppos);
5091faa44   Mike Galbraith   sched: Add 'autog...
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
  #ifdef CONFIG_SCHED_AUTOGROUP
  extern unsigned int sysctl_sched_autogroup_enabled;
  
  extern void sched_autogroup_create_attach(struct task_struct *p);
  extern void sched_autogroup_detach(struct task_struct *p);
  extern void sched_autogroup_fork(struct signal_struct *sig);
  extern void sched_autogroup_exit(struct signal_struct *sig);
  #ifdef CONFIG_PROC_FS
  extern void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m);
  extern int proc_sched_autogroup_set_nice(struct task_struct *p, int *nice);
  #endif
  #else
  static inline void sched_autogroup_create_attach(struct task_struct *p) { }
  static inline void sched_autogroup_detach(struct task_struct *p) { }
  static inline void sched_autogroup_fork(struct signal_struct *sig) { }
  static inline void sched_autogroup_exit(struct signal_struct *sig) { }
  #endif
ec12cb7f3   Paul Turner   sched: Accumulate...
1959
1960
1961
  #ifdef CONFIG_CFS_BANDWIDTH
  extern unsigned int sysctl_sched_cfs_bandwidth_slice;
  #endif
b29739f90   Ingo Molnar   [PATCH] pi-futex:...
1962
  #ifdef CONFIG_RT_MUTEXES
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
1963
1964
1965
  extern int rt_mutex_getprio(struct task_struct *p);
  extern void rt_mutex_setprio(struct task_struct *p, int prio);
  extern void rt_mutex_adjust_pi(struct task_struct *p);
b29739f90   Ingo Molnar   [PATCH] pi-futex:...
1966
  #else
e868171a9   Alexey Dobriyan   De-constify sched.h
1967
  static inline int rt_mutex_getprio(struct task_struct *p)
b29739f90   Ingo Molnar   [PATCH] pi-futex:...
1968
1969
1970
  {
  	return p->normal_prio;
  }
95e02ca9b   Thomas Gleixner   [PATCH] rtmutex: ...
1971
  # define rt_mutex_adjust_pi(p)		do { } while (0)
b29739f90   Ingo Molnar   [PATCH] pi-futex:...
1972
  #endif
d95f41220   Mike Galbraith   sched: Add yield_...
1973
  extern bool yield_to(struct task_struct *p, bool preempt);
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
1974
1975
1976
1977
1978
  extern void set_user_nice(struct task_struct *p, long nice);
  extern int task_prio(const struct task_struct *p);
  extern int task_nice(const struct task_struct *p);
  extern int can_nice(const struct task_struct *p, const int nice);
  extern int task_curr(const struct task_struct *p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1979
  extern int idle_cpu(int cpu);
fe7de49f9   KOSAKI Motohiro   sched: Make sched...
1980
1981
  extern int sched_setscheduler(struct task_struct *, int,
  			      const struct sched_param *);
961ccddd5   Rusty Russell   sched: add new AP...
1982
  extern int sched_setscheduler_nocheck(struct task_struct *, int,
fe7de49f9   KOSAKI Motohiro   sched: Make sched...
1983
  				      const struct sched_param *);
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
1984
  extern struct task_struct *idle_task(int cpu);
c4f306084   Paul E. McKenney   sched: Add is_idl...
1985
1986
1987
1988
1989
1990
1991
1992
  /**
   * is_idle_task - is the specified task an idle task?
   * @tsk: the task in question.
   */
  static inline bool is_idle_task(struct task_struct *p)
  {
  	return p->pid == 0;
  }
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
1993
1994
  extern struct task_struct *curr_task(int cpu);
  extern void set_curr_task(int cpu, struct task_struct *p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
  
  void yield(void);
  
  /*
   * The default (Linux) execution domain.
   */
  extern struct exec_domain	default_exec_domain;
  
  union thread_union {
  	struct thread_info thread_info;
  	unsigned long stack[THREAD_SIZE/sizeof(long)];
  };
  
  #ifndef __HAVE_ARCH_KSTACK_END
  static inline int kstack_end(void *addr)
  {
  	/* Reliable end of stack detection:
  	 * Some APM bios versions misalign the stack
  	 */
  	return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
  }
  #endif
  
  extern union thread_union init_thread_union;
  extern struct task_struct init_task;
  
  extern struct   mm_struct init_mm;
198fe21b0   Pavel Emelyanov   pid namespaces: h...
2022
2023
2024
2025
2026
  extern struct pid_namespace init_pid_ns;
  
  /*
   * find a task by one of its numerical ids
   *
198fe21b0   Pavel Emelyanov   pid namespaces: h...
2027
2028
   * find_task_by_pid_ns():
   *      finds a task by its pid in the specified namespace
228ebcbe6   Pavel Emelyanov   Uninline find_tas...
2029
2030
   * find_task_by_vpid():
   *      finds a task by its virtual pid
198fe21b0   Pavel Emelyanov   pid namespaces: h...
2031
   *
e49859e71   Pavel Emelyanov   pidns: remove now...
2032
   * see also find_vpid() etc in include/linux/pid.h
198fe21b0   Pavel Emelyanov   pid namespaces: h...
2033
   */
228ebcbe6   Pavel Emelyanov   Uninline find_tas...
2034
2035
2036
  extern struct task_struct *find_task_by_vpid(pid_t nr);
  extern struct task_struct *find_task_by_pid_ns(pid_t nr,
  		struct pid_namespace *ns);
198fe21b0   Pavel Emelyanov   pid namespaces: h...
2037

8520d7c7f   Oleg Nesterov   teach set_special...
2038
  extern void __set_special_pids(struct pid *pid);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2039
2040
  
  /* per-UID process charging. */
acce292c8   Cedric Le Goater   user namespace: a...
2041
  extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2042
2043
2044
2045
2046
2047
  static inline struct user_struct *get_uid(struct user_struct *u)
  {
  	atomic_inc(&u->__count);
  	return u;
  }
  extern void free_uid(struct user_struct *);
28f300d23   Pavel Emelyanov   Fix user namespac...
2048
  extern void release_uids(struct user_namespace *ns);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2049
2050
  
  #include <asm/current.h>
f0af911a9   Torben Hohn   time: Provide xti...
2051
  extern void xtime_update(unsigned long ticks);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2052

b3c975286   Harvey Harrison   include/linux: Re...
2053
2054
  extern int wake_up_state(struct task_struct *tsk, unsigned int state);
  extern int wake_up_process(struct task_struct *tsk);
3e51e3edf   Samir Bellabes   sched: Remove unu...
2055
  extern void wake_up_new_task(struct task_struct *tsk);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2056
2057
2058
2059
2060
  #ifdef CONFIG_SMP
   extern void kick_process(struct task_struct *tsk);
  #else
   static inline void kick_process(struct task_struct *tsk) { }
  #endif
3e51e3edf   Samir Bellabes   sched: Remove unu...
2061
  extern void sched_fork(struct task_struct *p);
ad46c2c4e   Ingo Molnar   sched: clean up f...
2062
  extern void sched_dead(struct task_struct *p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2063

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2064
2065
  extern void proc_caches_init(void);
  extern void flush_signals(struct task_struct *);
3bcac0263   David Howells   SELinux: Don't fl...
2066
  extern void __flush_signals(struct task_struct *);
10ab825bd   Oleg Nesterov   change kernel thr...
2067
  extern void ignore_signals(struct task_struct *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
  extern void flush_signal_handlers(struct task_struct *, int force_default);
  extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
  
  static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
  {
  	unsigned long flags;
  	int ret;
  
  	spin_lock_irqsave(&tsk->sighand->siglock, flags);
  	ret = dequeue_signal(tsk, mask, info);
  	spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
  
  	return ret;
53c8f9f19   Oleg Nesterov   make do_notify_pa...
2081
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2082
2083
2084
2085
2086
2087
  
  extern void block_all_signals(int (*notifier)(void *priv), void *priv,
  			      sigset_t *mask);
  extern void unblock_all_signals(void);
  extern void release_task(struct task_struct * p);
  extern int send_sig_info(int, struct siginfo *, struct task_struct *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2088
2089
  extern int force_sigsegv(int, struct task_struct *);
  extern int force_sig_info(int, struct siginfo *, struct task_struct *);
c4b92fc11   Eric W. Biederman   [PATCH] pid: impl...
2090
  extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
c4b92fc11   Eric W. Biederman   [PATCH] pid: impl...
2091
  extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
d178bc3a7   Serge Hallyn   user namespace: u...
2092
2093
  extern int kill_pid_info_as_cred(int, struct siginfo *, struct pid *,
  				const struct cred *, u32);
c4b92fc11   Eric W. Biederman   [PATCH] pid: impl...
2094
2095
  extern int kill_pgrp(struct pid *pid, int sig, int priv);
  extern int kill_pid(struct pid *pid, int sig, int priv);
c3de4b381   Matthew Wilcox   Revert "[PATCH] m...
2096
  extern int kill_proc_info(int, struct siginfo *, pid_t);
867734737   Oleg Nesterov   make do_notify_pa...
2097
  extern __must_check bool do_notify_parent(struct task_struct *, int);
a7f0765ed   Oleg Nesterov   ptrace: __ptrace_...
2098
  extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2099
  extern void force_sig(int, struct task_struct *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2100
  extern int send_sig(int, struct task_struct *, int);
09faef11d   Oleg Nesterov   exit: change zap_...
2101
  extern int zap_other_threads(struct task_struct *p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2102
2103
  extern struct sigqueue *sigqueue_alloc(void);
  extern void sigqueue_free(struct sigqueue *);
ac5c21538   Oleg Nesterov   signals: join sen...
2104
  extern int send_sigqueue(struct sigqueue *,  struct task_struct *, int group);
9ac95f2f9   Oleg Nesterov   [PATCH] do_sigact...
2105
  extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2106
  extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
9ec52099e   Cedric Le Goater   [PATCH] replace c...
2107
2108
2109
2110
  static inline int kill_cad_pid(int sig, int priv)
  {
  	return kill_pid(cad_pid, sig, priv);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2111
2112
2113
2114
  /* These can be the second arg to send_sig_info/send_group_sig_info.  */
  #define SEND_SIG_NOINFO ((struct siginfo *) 0)
  #define SEND_SIG_PRIV	((struct siginfo *) 1)
  #define SEND_SIG_FORCED	((struct siginfo *) 2)
2a855dd01   Sebastian Andrzej Siewior   signal: Fix alter...
2115
2116
2117
  /*
   * True if we are on the alternate signal stack.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2118
2119
  static inline int on_sig_stack(unsigned long sp)
  {
2a855dd01   Sebastian Andrzej Siewior   signal: Fix alter...
2120
2121
2122
2123
2124
2125
2126
  #ifdef CONFIG_STACK_GROWSUP
  	return sp >= current->sas_ss_sp &&
  		sp - current->sas_ss_sp < current->sas_ss_size;
  #else
  	return sp > current->sas_ss_sp &&
  		sp - current->sas_ss_sp <= current->sas_ss_size;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2127
2128
2129
2130
2131
2132
2133
  }
  
  static inline int sas_ss_flags(unsigned long sp)
  {
  	return (current->sas_ss_size == 0 ? SS_DISABLE
  		: on_sig_stack(sp) ? SS_ONSTACK : 0);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2134
2135
2136
2137
2138
2139
  /*
   * Routines for handling mm_structs
   */
  extern struct mm_struct * mm_alloc(void);
  
  /* mmdrop drops the mm and the page tables */
b3c975286   Harvey Harrison   include/linux: Re...
2140
  extern void __mmdrop(struct mm_struct *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2141
2142
  static inline void mmdrop(struct mm_struct * mm)
  {
6fb43d7b5   Ingo Molnar   sched: micro-opti...
2143
  	if (unlikely(atomic_dec_and_test(&mm->mm_count)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2144
2145
2146
2147
2148
2149
2150
2151
2152
  		__mmdrop(mm);
  }
  
  /* mmput gets rid of the mappings and all user-space */
  extern void mmput(struct mm_struct *);
  /* Grab a reference to a task's mm, if it is not already going away */
  extern struct mm_struct *get_task_mm(struct task_struct *task);
  /* Remove the current tasks stale references to the old mm_struct */
  extern void mm_release(struct task_struct *, struct mm_struct *);
402b08622   Carsten Otte   s390: KVM prepara...
2153
2154
  /* Allocate a new mm structure and copy contents from tsk->mm */
  extern struct mm_struct *dup_mm(struct task_struct *tsk);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2155

6f2c55b84   Alexey Dobriyan   Simplify copy_thr...
2156
2157
  extern int copy_thread(unsigned long, unsigned long, unsigned long,
  			struct task_struct *, struct pt_regs *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2158
2159
  extern void flush_thread(void);
  extern void exit_thread(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2160
  extern void exit_files(struct task_struct *);
a7e5328a0   Oleg Nesterov   [PATCH] cleanup _...
2161
  extern void __cleanup_sighand(struct sighand_struct *);
cbaffba12   Oleg Nesterov   posix timers: dis...
2162

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2163
  extern void exit_itimers(struct signal_struct *);
cbaffba12   Oleg Nesterov   posix timers: dis...
2164
  extern void flush_itimer_signals(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2165

9402c95f3   Joe Perches   treewide: remove ...
2166
  extern void do_group_exit(int);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2167

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2168
2169
2170
  extern void daemonize(const char *, ...);
  extern int allow_signal(int);
  extern int disallow_signal(int);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2171

d7627467b   David Howells   Make do_execve() ...
2172
2173
2174
  extern int do_execve(const char *,
  		     const char __user * const __user *,
  		     const char __user * const __user *, struct pt_regs *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2175
  extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
2176
  struct task_struct *fork_idle(int);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2177
2178
  
  extern void set_task_comm(struct task_struct *tsk, char *from);
59714d65d   Andrew Morton   get_task_comm(): ...
2179
  extern char *get_task_comm(char *to, struct task_struct *tsk);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2180
2181
  
  #ifdef CONFIG_SMP
317f39416   Peter Zijlstra   sched: Move the s...
2182
  void scheduler_ipi(void);
85ba2d862   Roland McGrath   tracehook: wait_t...
2183
  extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2184
  #else
184748cc5   Peter Zijlstra   sched: Provide sc...
2185
  static inline void scheduler_ipi(void) { }
85ba2d862   Roland McGrath   tracehook: wait_t...
2186
2187
2188
2189
2190
  static inline unsigned long wait_task_inactive(struct task_struct *p,
  					       long match_state)
  {
  	return 1;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2191
  #endif
05725f7eb   Jiri Pirko   rculist: use list...
2192
2193
  #define next_task(p) \
  	list_entry_rcu((p)->tasks.next, struct task_struct, tasks)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2194
2195
2196
  
  #define for_each_process(p) \
  	for (p = &init_task ; (p = next_task(p)) != &init_task ; )
5bb459bb4   Oleg Nesterov   kernel: rename is...
2197
  extern bool current_is_single_threaded(void);
d84f4f992   David Howells   CRED: Inaugurate ...
2198

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2199
2200
2201
2202
2203
2204
2205
2206
2207
  /*
   * Careful: do_each_thread/while_each_thread is a double loop so
   *          'break' will not work as expected - use goto instead.
   */
  #define do_each_thread(g, t) \
  	for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
  
  #define while_each_thread(g, t) \
  	while ((t = next_thread(t)) != g)
7e49827cc   Oleg Nesterov   proc: get_nr_thre...
2208
2209
  static inline int get_nr_threads(struct task_struct *tsk)
  {
b3ac022cb   Oleg Nesterov   proc: turn signal...
2210
  	return tsk->signal->nr_threads;
7e49827cc   Oleg Nesterov   proc: get_nr_thre...
2211
  }
087806b12   Oleg Nesterov   redefine thread_g...
2212
2213
2214
2215
  static inline bool thread_group_leader(struct task_struct *p)
  {
  	return p->exit_signal >= 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2216

0804ef4b0   Eric W. Biederman   [PATCH] proc: rea...
2217
2218
2219
2220
2221
2222
  /* Do to the insanities of de_thread it is possible for a process
   * to have the pid of the thread group leader without actually being
   * the thread group leader.  For iteration through the pids in proc
   * all we care about is that we have a task with the appropriate
   * pid, we don't actually care if we have the right task.
   */
e868171a9   Alexey Dobriyan   De-constify sched.h
2223
  static inline int has_group_leader_pid(struct task_struct *p)
0804ef4b0   Eric W. Biederman   [PATCH] proc: rea...
2224
2225
2226
  {
  	return p->pid == p->tgid;
  }
bac0abd61   Pavel Emelyanov   Isolate some expl...
2227
2228
2229
2230
2231
  static inline
  int same_thread_group(struct task_struct *p1, struct task_struct *p2)
  {
  	return p1->tgid == p2->tgid;
  }
36c8b5868   Ingo Molnar   [PATCH] sched: cl...
2232
  static inline struct task_struct *next_thread(const struct task_struct *p)
47e65328a   Oleg Nesterov   [PATCH] pids: kil...
2233
  {
05725f7eb   Jiri Pirko   rculist: use list...
2234
2235
  	return list_entry_rcu(p->thread_group.next,
  			      struct task_struct, thread_group);
47e65328a   Oleg Nesterov   [PATCH] pids: kil...
2236
  }
e868171a9   Alexey Dobriyan   De-constify sched.h
2237
  static inline int thread_group_empty(struct task_struct *p)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2238
  {
47e65328a   Oleg Nesterov   [PATCH] pids: kil...
2239
  	return list_empty(&p->thread_group);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2240
2241
2242
2243
  }
  
  #define delay_group_leader(p) \
  		(thread_group_leader(p) && !thread_group_empty(p))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2244
  /*
260ea1013   Eric W. Biederman   [PATCH] ptrace: d...
2245
   * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
22e2c507c   Jens Axboe   [PATCH] Update cf...
2246
   * subscriptions and synchronises with wait4().  Also used in procfs.  Also
ddbcc7e8e   Paul Menage   Task Control Grou...
2247
2248
   * pins the final release of task.io_context.  Also protects ->cpuset and
   * ->cgroup.subsys[].
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
   *
   * Nests both inside and outside of read_lock(&tasklist_lock).
   * It must not be nested with write_lock_irq(&tasklist_lock),
   * neither inside nor outside.
   */
  static inline void task_lock(struct task_struct *p)
  {
  	spin_lock(&p->alloc_lock);
  }
  
  static inline void task_unlock(struct task_struct *p)
  {
  	spin_unlock(&p->alloc_lock);
  }
b8ed374e2   Namhyung Kim   signals: annotate...
2263
  extern struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
f63ee72e0   Oleg Nesterov   [PATCH] introduce...
2264
  							unsigned long *flags);
b8ed374e2   Namhyung Kim   signals: annotate...
2265
2266
2267
2268
2269
2270
  #define lock_task_sighand(tsk, flags)					\
  ({	struct sighand_struct *__ss;					\
  	__cond_lock(&(tsk)->sighand->siglock,				\
  		    (__ss = __lock_task_sighand(tsk, flags)));		\
  	__ss;								\
  })									\
f63ee72e0   Oleg Nesterov   [PATCH] introduce...
2271
2272
2273
2274
2275
  static inline void unlock_task_sighand(struct task_struct *tsk,
  						unsigned long *flags)
  {
  	spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
  }
4714d1d32   Ben Blum   cgroups: read-wri...
2276
  #ifdef CONFIG_CGROUPS
257058ae2   Tejun Heo   threadgroup: rena...
2277
  static inline void threadgroup_change_begin(struct task_struct *tsk)
4714d1d32   Ben Blum   cgroups: read-wri...
2278
  {
257058ae2   Tejun Heo   threadgroup: rena...
2279
  	down_read(&tsk->signal->group_rwsem);
4714d1d32   Ben Blum   cgroups: read-wri...
2280
  }
257058ae2   Tejun Heo   threadgroup: rena...
2281
  static inline void threadgroup_change_end(struct task_struct *tsk)
4714d1d32   Ben Blum   cgroups: read-wri...
2282
  {
257058ae2   Tejun Heo   threadgroup: rena...
2283
  	up_read(&tsk->signal->group_rwsem);
4714d1d32   Ben Blum   cgroups: read-wri...
2284
  }
77e4ef99d   Tejun Heo   threadgroup: exte...
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
  
  /**
   * threadgroup_lock - lock threadgroup
   * @tsk: member task of the threadgroup to lock
   *
   * Lock the threadgroup @tsk belongs to.  No new task is allowed to enter
   * and member tasks aren't allowed to exit (as indicated by PF_EXITING) or
   * perform exec.  This is useful for cases where the threadgroup needs to
   * stay stable across blockable operations.
   *
   * fork and exit paths explicitly call threadgroup_change_{begin|end}() for
   * synchronization.  While held, no new task will be added to threadgroup
   * and no existing live task will have its PF_EXITING set.
   *
   * During exec, a task goes and puts its thread group through unusual
   * changes.  After de-threading, exclusive access is assumed to resources
   * which are usually shared by tasks in the same group - e.g. sighand may
   * be replaced with a new one.  Also, the exec'ing task takes over group
   * leader role including its pid.  Exclude these changes while locked by
   * grabbing cred_guard_mutex which is used to synchronize exec path.
   */
257058ae2   Tejun Heo   threadgroup: rena...
2306
  static inline void threadgroup_lock(struct task_struct *tsk)
4714d1d32   Ben Blum   cgroups: read-wri...
2307
  {
77e4ef99d   Tejun Heo   threadgroup: exte...
2308
2309
2310
2311
2312
  	/*
  	 * exec uses exit for de-threading nesting group_rwsem inside
  	 * cred_guard_mutex. Grab cred_guard_mutex first.
  	 */
  	mutex_lock(&tsk->signal->cred_guard_mutex);
257058ae2   Tejun Heo   threadgroup: rena...
2313
  	down_write(&tsk->signal->group_rwsem);
4714d1d32   Ben Blum   cgroups: read-wri...
2314
  }
77e4ef99d   Tejun Heo   threadgroup: exte...
2315
2316
2317
2318
2319
2320
2321
  
  /**
   * threadgroup_unlock - unlock threadgroup
   * @tsk: member task of the threadgroup to unlock
   *
   * Reverse threadgroup_lock().
   */
257058ae2   Tejun Heo   threadgroup: rena...
2322
  static inline void threadgroup_unlock(struct task_struct *tsk)
4714d1d32   Ben Blum   cgroups: read-wri...
2323
  {
257058ae2   Tejun Heo   threadgroup: rena...
2324
  	up_write(&tsk->signal->group_rwsem);
77e4ef99d   Tejun Heo   threadgroup: exte...
2325
  	mutex_unlock(&tsk->signal->cred_guard_mutex);
4714d1d32   Ben Blum   cgroups: read-wri...
2326
2327
  }
  #else
257058ae2   Tejun Heo   threadgroup: rena...
2328
2329
2330
2331
  static inline void threadgroup_change_begin(struct task_struct *tsk) {}
  static inline void threadgroup_change_end(struct task_struct *tsk) {}
  static inline void threadgroup_lock(struct task_struct *tsk) {}
  static inline void threadgroup_unlock(struct task_struct *tsk) {}
4714d1d32   Ben Blum   cgroups: read-wri...
2332
  #endif
f037360f2   Al Viro   [PATCH] m68k: thr...
2333
  #ifndef __HAVE_THREAD_FUNCTIONS
f7e4217b0   Roman Zippel   rename thread_inf...
2334
2335
  #define task_thread_info(task)	((struct thread_info *)(task)->stack)
  #define task_stack_page(task)	((task)->stack)
a1261f546   Al Viro   [PATCH] m68k: int...
2336

10ebffde3   Al Viro   [PATCH] m68k: int...
2337
2338
2339
2340
2341
2342
2343
2344
  static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
  {
  	*task_thread_info(p) = *task_thread_info(org);
  	task_thread_info(p)->task = p;
  }
  
  static inline unsigned long *end_of_stack(struct task_struct *p)
  {
f7e4217b0   Roman Zippel   rename thread_inf...
2345
  	return (unsigned long *)(task_thread_info(p) + 1);
10ebffde3   Al Viro   [PATCH] m68k: int...
2346
  }
f037360f2   Al Viro   [PATCH] m68k: thr...
2347
  #endif
8b05c7e6e   FUJITA Tomonori   add a helper func...
2348
2349
2350
2351
2352
2353
  static inline int object_is_on_stack(void *obj)
  {
  	void *stack = task_stack_page(current);
  
  	return (obj >= stack) && (obj < (stack + THREAD_SIZE));
  }
8c9843e57   Benjamin Herrenschmidt   [POWERPC] Add thr...
2354
  extern void thread_info_cache_init(void);
7c9f8861e   Eric Sandeen   stackprotector: u...
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
  #ifdef CONFIG_DEBUG_STACK_USAGE
  static inline unsigned long stack_not_used(struct task_struct *p)
  {
  	unsigned long *n = end_of_stack(p);
  
  	do { 	/* Skip over canary */
  		n++;
  	} while (!*n);
  
  	return (unsigned long)n - (unsigned long)end_of_stack(p);
  }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2367
2368
2369
2370
2371
  /* set thread flags in other task's structures
   * - see asm/thread_info.h for TIF_xxxx flags available
   */
  static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
  {
a1261f546   Al Viro   [PATCH] m68k: int...
2372
  	set_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2373
2374
2375
2376
  }
  
  static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
  {
a1261f546   Al Viro   [PATCH] m68k: int...
2377
  	clear_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2378
2379
2380
2381
  }
  
  static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
  {
a1261f546   Al Viro   [PATCH] m68k: int...
2382
  	return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2383
2384
2385
2386
  }
  
  static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
  {
a1261f546   Al Viro   [PATCH] m68k: int...
2387
  	return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2388
2389
2390
2391
  }
  
  static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
  {
a1261f546   Al Viro   [PATCH] m68k: int...
2392
  	return test_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
  }
  
  static inline void set_tsk_need_resched(struct task_struct *tsk)
  {
  	set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
  }
  
  static inline void clear_tsk_need_resched(struct task_struct *tsk)
  {
  	clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
  }
8ae121ac8   Gregory Haskins   sched: fix RT tas...
2404
2405
2406
2407
  static inline int test_tsk_need_resched(struct task_struct *tsk)
  {
  	return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
  }
690cc3ffe   Eric W. Biederman   syscall: Implemen...
2408
2409
2410
2411
2412
  static inline int restart_syscall(void)
  {
  	set_tsk_thread_flag(current, TIF_SIGPENDING);
  	return -ERESTARTNOINTR;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2413
2414
2415
2416
  static inline int signal_pending(struct task_struct *p)
  {
  	return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
  }
f776d12dd   Matthew Wilcox   Add fatal_signal_...
2417

d9588725e   Roland McGrath   signals: inline _...
2418
2419
2420
2421
  static inline int __fatal_signal_pending(struct task_struct *p)
  {
  	return unlikely(sigismember(&p->pending.signal, SIGKILL));
  }
f776d12dd   Matthew Wilcox   Add fatal_signal_...
2422
2423
2424
2425
2426
  
  static inline int fatal_signal_pending(struct task_struct *p)
  {
  	return signal_pending(p) && __fatal_signal_pending(p);
  }
16882c1e9   Oleg Nesterov   sched: fix TASK_W...
2427
2428
2429
2430
2431
2432
  static inline int signal_pending_state(long state, struct task_struct *p)
  {
  	if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
  		return 0;
  	if (!signal_pending(p))
  		return 0;
16882c1e9   Oleg Nesterov   sched: fix TASK_W...
2433
2434
  	return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2435
2436
  static inline int need_resched(void)
  {
9404ef029   Linus Torvalds   Fix up 'need_resc...
2437
  	return unlikely(test_thread_flag(TIF_NEED_RESCHED));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2438
2439
2440
2441
2442
2443
2444
2445
2446
  }
  
  /*
   * cond_resched() and cond_resched_lock(): latency reduction via
   * explicit rescheduling in places that are safe. The return
   * value indicates whether a reschedule was done in fact.
   * cond_resched_lock() will drop the spinlock before scheduling,
   * cond_resched_softirq() will enable bhs before scheduling.
   */
c3921ab71   Linus Torvalds   Add new 'cond_res...
2447
  extern int _cond_resched(void);
6f80bd985   Frederic Weisbecker   sched: Remove the...
2448

613afbf83   Frederic Weisbecker   sched: Pull up th...
2449
2450
2451
2452
  #define cond_resched() ({			\
  	__might_sleep(__FILE__, __LINE__, 0);	\
  	_cond_resched();			\
  })
6f80bd985   Frederic Weisbecker   sched: Remove the...
2453

613afbf83   Frederic Weisbecker   sched: Pull up th...
2454
  extern int __cond_resched_lock(spinlock_t *lock);
bdd4e85dc   Frederic Weisbecker   sched: Isolate pr...
2455
  #ifdef CONFIG_PREEMPT_COUNT
716a42348   Frederic Weisbecker   sched: Fix cond_r...
2456
  #define PREEMPT_LOCK_OFFSET	PREEMPT_OFFSET
02b67cc3b   Herbert Xu   sched: do not do ...
2457
  #else
716a42348   Frederic Weisbecker   sched: Fix cond_r...
2458
  #define PREEMPT_LOCK_OFFSET	0
02b67cc3b   Herbert Xu   sched: do not do ...
2459
  #endif
716a42348   Frederic Weisbecker   sched: Fix cond_r...
2460

613afbf83   Frederic Weisbecker   sched: Pull up th...
2461
  #define cond_resched_lock(lock) ({				\
716a42348   Frederic Weisbecker   sched: Fix cond_r...
2462
  	__might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);	\
613afbf83   Frederic Weisbecker   sched: Pull up th...
2463
2464
2465
2466
  	__cond_resched_lock(lock);				\
  })
  
  extern int __cond_resched_softirq(void);
75e1056f5   Venkatesh Pallipadi   sched: Fix softir...
2467
2468
2469
  #define cond_resched_softirq() ({					\
  	__might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET);	\
  	__cond_resched_softirq();					\
613afbf83   Frederic Weisbecker   sched: Pull up th...
2470
  })
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2471
2472
2473
  
  /*
   * Does a critical section need to be broken due to another
95c354fe9   Nick Piggin   spinlock: lockbre...
2474
2475
   * task waiting?: (technically does not depend on CONFIG_PREEMPT,
   * but a general need for low latency)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2476
   */
95c354fe9   Nick Piggin   spinlock: lockbre...
2477
  static inline int spin_needbreak(spinlock_t *lock)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2478
  {
95c354fe9   Nick Piggin   spinlock: lockbre...
2479
2480
2481
  #ifdef CONFIG_PREEMPT
  	return spin_is_contended(lock);
  #else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2482
  	return 0;
95c354fe9   Nick Piggin   spinlock: lockbre...
2483
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2484
  }
7bb44adef   Roland McGrath   recalc_sigpending...
2485
  /*
f06febc96   Frank Mayhar   timers: fix itime...
2486
2487
   * Thread group CPU time accounting.
   */
4cd4c1b40   Peter Zijlstra   timers: split pro...
2488
  void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
4da94d49b   Peter Zijlstra   timers: fix TIMER...
2489
  void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
f06febc96   Frank Mayhar   timers: fix itime...
2490

490dea45d   Peter Zijlstra   itimers: remove t...
2491
  static inline void thread_group_cputime_init(struct signal_struct *sig)
f06febc96   Frank Mayhar   timers: fix itime...
2492
  {
ee30a7b2f   Thomas Gleixner   locking, sched: A...
2493
  	raw_spin_lock_init(&sig->cputimer.lock);
f06febc96   Frank Mayhar   timers: fix itime...
2494
  }
f06febc96   Frank Mayhar   timers: fix itime...
2495
  /*
7bb44adef   Roland McGrath   recalc_sigpending...
2496
2497
2498
2499
2500
2501
   * Reevaluate whether the task has signals pending delivery.
   * Wake the task if so.
   * This is required every time the blocked sigset_t changes.
   * callers must hold sighand->siglock.
   */
  extern void recalc_sigpending_and_wake(struct task_struct *t);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
  extern void recalc_sigpending(void);
  
  extern void signal_wake_up(struct task_struct *t, int resume_stopped);
  
  /*
   * Wrappers for p->thread_info->cpu access. No-op on UP.
   */
  #ifdef CONFIG_SMP
  
  static inline unsigned int task_cpu(const struct task_struct *p)
  {
a1261f546   Al Viro   [PATCH] m68k: int...
2513
  	return task_thread_info(p)->cpu;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2514
  }
c65cc8705   Ingo Molnar   sched: uninline s...
2515
  extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
  
  #else
  
  static inline unsigned int task_cpu(const struct task_struct *p)
  {
  	return 0;
  }
  
  static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
  {
  }
  
  #endif /* CONFIG_SMP */
96f874e26   Rusty Russell   sched: convert re...
2529
2530
  extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
  extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
5c45bf279   Siddha, Suresh B   [PATCH] sched: mc...
2531

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2532
  extern void normalize_rt_tasks(void);
7c9414385   Dhaval Giani   sched: Remove USE...
2533
  #ifdef CONFIG_CGROUP_SCHED
9b5b77512   Srivatsa Vaddagiri   sched: clean up c...
2534

07e06b011   Yong Zhang   sched: Consolidat...
2535
  extern struct task_group root_task_group;
9b5b77512   Srivatsa Vaddagiri   sched: clean up c...
2536

ec7dc8ac7   Dhaval Giani   sched: allow the ...
2537
  extern struct task_group *sched_create_group(struct task_group *parent);
4cf86d77f   Ingo Molnar   sched: cleanup: r...
2538
  extern void sched_destroy_group(struct task_group *tg);
9b5b77512   Srivatsa Vaddagiri   sched: clean up c...
2539
  extern void sched_move_task(struct task_struct *tsk);
052f1dc7e   Peter Zijlstra   sched: rt-group: ...
2540
  #ifdef CONFIG_FAIR_GROUP_SCHED
4cf86d77f   Ingo Molnar   sched: cleanup: r...
2541
  extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
5cb350baf   Dhaval Giani   sched: group sche...
2542
  extern unsigned long sched_group_shares(struct task_group *tg);
052f1dc7e   Peter Zijlstra   sched: rt-group: ...
2543
2544
  #endif
  #ifdef CONFIG_RT_GROUP_SCHED
9f0c1e560   Peter Zijlstra   sched: rt-group: ...
2545
2546
2547
  extern int sched_group_set_rt_runtime(struct task_group *tg,
  				      long rt_runtime_us);
  extern long sched_group_rt_runtime(struct task_group *tg);
d0b27fa77   Peter Zijlstra   sched: rt-group: ...
2548
2549
2550
  extern int sched_group_set_rt_period(struct task_group *tg,
  				      long rt_period_us);
  extern long sched_group_rt_period(struct task_group *tg);
54e991242   Dhaval Giani   sched: don't allo...
2551
  extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk);
052f1dc7e   Peter Zijlstra   sched: rt-group: ...
2552
  #endif
9b5b77512   Srivatsa Vaddagiri   sched: clean up c...
2553
  #endif
54e991242   Dhaval Giani   sched: don't allo...
2554
2555
  extern int task_can_switch_user(struct user_struct *up,
  					struct task_struct *tsk);
4b98d11b4   Alexey Dobriyan   [PATCH] ifdef ->r...
2556
2557
2558
  #ifdef CONFIG_TASK_XACCT
  static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
  {
940389b8a   Andrea Righi   task IO accountin...
2559
  	tsk->ioac.rchar += amt;
4b98d11b4   Alexey Dobriyan   [PATCH] ifdef ->r...
2560
2561
2562
2563
  }
  
  static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
  {
940389b8a   Andrea Righi   task IO accountin...
2564
  	tsk->ioac.wchar += amt;
4b98d11b4   Alexey Dobriyan   [PATCH] ifdef ->r...
2565
2566
2567
2568
  }
  
  static inline void inc_syscr(struct task_struct *tsk)
  {
940389b8a   Andrea Righi   task IO accountin...
2569
  	tsk->ioac.syscr++;
4b98d11b4   Alexey Dobriyan   [PATCH] ifdef ->r...
2570
2571
2572
2573
  }
  
  static inline void inc_syscw(struct task_struct *tsk)
  {
940389b8a   Andrea Righi   task IO accountin...
2574
  	tsk->ioac.syscw++;
4b98d11b4   Alexey Dobriyan   [PATCH] ifdef ->r...
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
  }
  #else
  static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
  {
  }
  
  static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
  {
  }
  
  static inline void inc_syscr(struct task_struct *tsk)
  {
  }
  
  static inline void inc_syscw(struct task_struct *tsk)
  {
  }
  #endif
824552574   Dave Hansen   maps4: rework TAS...
2593
2594
2595
  #ifndef TASK_SIZE_OF
  #define TASK_SIZE_OF(tsk)	TASK_SIZE
  #endif
cf475ad28   Balbir Singh   cgroups: add an o...
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
  #ifdef CONFIG_MM_OWNER
  extern void mm_update_next_owner(struct mm_struct *mm);
  extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p);
  #else
  static inline void mm_update_next_owner(struct mm_struct *mm)
  {
  }
  
  static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p)
  {
  }
  #endif /* CONFIG_MM_OWNER */
3e10e716a   Jiri Slaby   resource: add hel...
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
  static inline unsigned long task_rlimit(const struct task_struct *tsk,
  		unsigned int limit)
  {
  	return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_cur);
  }
  
  static inline unsigned long task_rlimit_max(const struct task_struct *tsk,
  		unsigned int limit)
  {
  	return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_max);
  }
  
  static inline unsigned long rlimit(unsigned int limit)
  {
  	return task_rlimit(current, limit);
  }
  
  static inline unsigned long rlimit_max(unsigned int limit)
  {
  	return task_rlimit_max(current, limit);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2629
2630
2631
  #endif /* __KERNEL__ */
  
  #endif