]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_SCHED_H |
2 | #define _LINUX_SCHED_H | |
3 | ||
607ca46e | 4 | #include <uapi/linux/sched.h> |
b7b3c76a | 5 | |
5c228079 | 6 | #include <linux/sched/prio.h> |
ee6a3d19 | 7 | #include <linux/nodemask.h> |
5c228079 | 8 | |
b69339ba | 9 | #include <linux/mutex.h> |
fb00aca4 | 10 | #include <linux/plist.h> |
77ba809e | 11 | #include <linux/mm_types_task.h> |
1da177e4 | 12 | |
1da177e4 | 13 | #include <linux/sem.h> |
ab602f79 | 14 | #include <linux/shm.h> |
f361bf4a | 15 | #include <linux/signal_types.h> |
1da177e4 | 16 | #include <linux/pid.h> |
1da177e4 | 17 | #include <linux/seccomp.h> |
b68070e1 | 18 | #include <linux/rcupdate.h> |
1da177e4 | 19 | |
a3b6714e | 20 | #include <linux/resource.h> |
a3b6714e | 21 | #include <linux/hrtimer.h> |
5c9a8750 | 22 | #include <linux/kcov.h> |
7c3ab738 | 23 | #include <linux/task_io_accounting.h> |
9745512c | 24 | #include <linux/latencytop.h> |
a3b6714e | 25 | |
70b8157e IM |
26 | #include <asm/current.h> |
27 | ||
c7af7877 IM |
28 | /* task_struct member predeclarations: */ |
29 | struct audit_context; | |
30 | struct autogroup; | |
31 | struct backing_dev_info; | |
bddd87c7 | 32 | struct bio_list; |
73c10101 | 33 | struct blk_plug; |
c7af7877 | 34 | struct cfs_rq; |
c4ad8f98 | 35 | struct filename; |
c7af7877 IM |
36 | struct fs_struct; |
37 | struct futex_pi_state; | |
38 | struct io_context; | |
39 | struct mempolicy; | |
89076bc3 | 40 | struct nameidata; |
c7af7877 IM |
41 | struct nsproxy; |
42 | struct perf_event_context; | |
43 | struct pid_namespace; | |
44 | struct pipe_inode_info; | |
45 | struct rcu_node; | |
46 | struct reclaim_state; | |
47 | struct robust_list_head; | |
48 | struct sched_attr; | |
49 | struct sched_param; | |
43ae34cb | 50 | struct seq_file; |
c7af7877 IM |
51 | struct sighand_struct; |
52 | struct signal_struct; | |
53 | struct task_delay_info; | |
4cf86d77 | 54 | struct task_group; |
c7af7877 IM |
55 | struct task_struct; |
56 | struct uts_namespace; | |
1da177e4 | 57 | |
4a8342d2 LT |
58 | /* |
59 | * Task state bitmask. NOTE! These bits are also | |
60 | * encoded in fs/proc/array.c: get_task_state(). | |
61 | * | |
62 | * We have two separate sets of flags: task->state | |
63 | * is about runnability, while task->exit_state are | |
64 | * about the task exiting. Confusing, but this way | |
65 | * modifying one set can't modify the other one by | |
66 | * mistake. | |
67 | */ | |
1da177e4 LT |
68 | #define TASK_RUNNING 0 |
69 | #define TASK_INTERRUPTIBLE 1 | |
70 | #define TASK_UNINTERRUPTIBLE 2 | |
f021a3c2 MW |
71 | #define __TASK_STOPPED 4 |
72 | #define __TASK_TRACED 8 | |
4a8342d2 | 73 | /* in tsk->exit_state */ |
ad86622b ON |
74 | #define EXIT_DEAD 16 |
75 | #define EXIT_ZOMBIE 32 | |
abd50b39 | 76 | #define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD) |
4a8342d2 | 77 | /* in tsk->state again */ |
af927232 | 78 | #define TASK_DEAD 64 |
f021a3c2 | 79 | #define TASK_WAKEKILL 128 |
e9c84311 | 80 | #define TASK_WAKING 256 |
f2530dc7 | 81 | #define TASK_PARKED 512 |
80ed87c8 | 82 | #define TASK_NOLOAD 1024 |
7dc603c9 PZ |
83 | #define TASK_NEW 2048 |
84 | #define TASK_STATE_MAX 4096 | |
f021a3c2 | 85 | |
7dc603c9 | 86 | #define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWPNn" |
73342151 | 87 | |
642fa448 | 88 | /* Convenience macros for the sake of set_current_state */ |
f021a3c2 MW |
89 | #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) |
90 | #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) | |
91 | #define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED) | |
1da177e4 | 92 | |
80ed87c8 PZ |
93 | #define TASK_IDLE (TASK_UNINTERRUPTIBLE | TASK_NOLOAD) |
94 | ||
92a1f4bc MW |
95 | /* Convenience macros for the sake of wake_up */ |
96 | #define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE) | |
f021a3c2 | 97 | #define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED) |
92a1f4bc MW |
98 | |
99 | /* get_task_state() */ | |
100 | #define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \ | |
f021a3c2 | 101 | TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \ |
74e37200 | 102 | __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD) |
92a1f4bc | 103 | |
f021a3c2 MW |
104 | #define task_is_traced(task) ((task->state & __TASK_TRACED) != 0) |
105 | #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0) | |
92a1f4bc | 106 | #define task_is_stopped_or_traced(task) \ |
f021a3c2 | 107 | ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0) |
92a1f4bc | 108 | #define task_contributes_to_load(task) \ |
e3c8ca83 | 109 | ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \ |
80ed87c8 PZ |
110 | (task->flags & PF_FROZEN) == 0 && \ |
111 | (task->state & TASK_NOLOAD) == 0) | |
1da177e4 | 112 | |
8eb23b9f PZ |
113 | #ifdef CONFIG_DEBUG_ATOMIC_SLEEP |
114 | ||
8eb23b9f PZ |
115 | #define __set_current_state(state_value) \ |
116 | do { \ | |
117 | current->task_state_change = _THIS_IP_; \ | |
118 | current->state = (state_value); \ | |
119 | } while (0) | |
120 | #define set_current_state(state_value) \ | |
121 | do { \ | |
122 | current->task_state_change = _THIS_IP_; \ | |
a2250238 | 123 | smp_store_mb(current->state, (state_value)); \ |
8eb23b9f PZ |
124 | } while (0) |
125 | ||
126 | #else | |
498d0c57 AM |
127 | /* |
128 | * set_current_state() includes a barrier so that the write of current->state | |
129 | * is correctly serialised wrt the caller's subsequent test of whether to | |
130 | * actually sleep: | |
131 | * | |
a2250238 | 132 | * for (;;) { |
498d0c57 | 133 | * set_current_state(TASK_UNINTERRUPTIBLE); |
a2250238 PZ |
134 | * if (!need_sleep) |
135 | * break; | |
136 | * | |
137 | * schedule(); | |
138 | * } | |
139 | * __set_current_state(TASK_RUNNING); | |
140 | * | |
141 | * If the caller does not need such serialisation (because, for instance, the | |
142 | * condition test and condition change and wakeup are under the same lock) then | |
143 | * use __set_current_state(). | |
144 | * | |
145 | * The above is typically ordered against the wakeup, which does: | |
146 | * | |
147 | * need_sleep = false; | |
148 | * wake_up_state(p, TASK_UNINTERRUPTIBLE); | |
149 | * | |
150 | * Where wake_up_state() (and all other wakeup primitives) imply enough | |
151 | * barriers to order the store of the variable against wakeup. | |
152 | * | |
153 | * Wakeup will do: if (@state & p->state) p->state = TASK_RUNNING, that is, | |
154 | * once it observes the TASK_UNINTERRUPTIBLE store the waking CPU can issue a | |
155 | * TASK_RUNNING store which can collide with __set_current_state(TASK_RUNNING). | |
498d0c57 | 156 | * |
a2250238 | 157 | * This is obviously fine, since they both store the exact same value. |
498d0c57 | 158 | * |
a2250238 | 159 | * Also see the comments of try_to_wake_up(). |
498d0c57 | 160 | */ |
8eb23b9f | 161 | #define __set_current_state(state_value) \ |
1da177e4 | 162 | do { current->state = (state_value); } while (0) |
8eb23b9f | 163 | #define set_current_state(state_value) \ |
b92b8b35 | 164 | smp_store_mb(current->state, (state_value)) |
1da177e4 | 165 | |
8eb23b9f PZ |
166 | #endif |
167 | ||
1da177e4 LT |
168 | /* Task command name length */ |
169 | #define TASK_COMM_LEN 16 | |
170 | ||
3fa0818b RR |
171 | extern cpumask_var_t cpu_isolated_map; |
172 | ||
1da177e4 LT |
173 | extern void scheduler_tick(void); |
174 | ||
1da177e4 | 175 | #define MAX_SCHEDULE_TIMEOUT LONG_MAX |
b3c97528 | 176 | extern signed long schedule_timeout(signed long timeout); |
64ed93a2 | 177 | extern signed long schedule_timeout_interruptible(signed long timeout); |
294d5cc2 | 178 | extern signed long schedule_timeout_killable(signed long timeout); |
64ed93a2 | 179 | extern signed long schedule_timeout_uninterruptible(signed long timeout); |
69b27baf | 180 | extern signed long schedule_timeout_idle(signed long timeout); |
1da177e4 | 181 | asmlinkage void schedule(void); |
c5491ea7 | 182 | extern void schedule_preempt_disabled(void); |
1da177e4 | 183 | |
10ab5643 TH |
184 | extern int __must_check io_schedule_prepare(void); |
185 | extern void io_schedule_finish(int token); | |
9cff8ade | 186 | extern long io_schedule_timeout(long timeout); |
10ab5643 | 187 | extern void io_schedule(void); |
9cff8ade | 188 | |
d37f761d | 189 | /** |
9d7fb042 | 190 | * struct prev_cputime - snaphsot of system and user cputime |
d37f761d FW |
191 | * @utime: time spent in user mode |
192 | * @stime: time spent in system mode | |
9d7fb042 | 193 | * @lock: protects the above two fields |
d37f761d | 194 | * |
9d7fb042 PZ |
195 | * Stores previous user/system time values such that we can guarantee |
196 | * monotonicity. | |
d37f761d | 197 | */ |
9d7fb042 PZ |
198 | struct prev_cputime { |
199 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE | |
5613fda9 FW |
200 | u64 utime; |
201 | u64 stime; | |
9d7fb042 PZ |
202 | raw_spinlock_t lock; |
203 | #endif | |
d37f761d FW |
204 | }; |
205 | ||
f06febc9 FM |
206 | /** |
207 | * struct task_cputime - collected CPU time counts | |
5613fda9 FW |
208 | * @utime: time spent in user mode, in nanoseconds |
209 | * @stime: time spent in kernel mode, in nanoseconds | |
f06febc9 | 210 | * @sum_exec_runtime: total time spent on the CPU, in nanoseconds |
5ce73a4a | 211 | * |
9d7fb042 PZ |
212 | * This structure groups together three kinds of CPU time that are tracked for |
213 | * threads and thread groups. Most things considering CPU time want to group | |
214 | * these counts together and treat all three of them in parallel. | |
f06febc9 FM |
215 | */ |
216 | struct task_cputime { | |
5613fda9 FW |
217 | u64 utime; |
218 | u64 stime; | |
f06febc9 FM |
219 | unsigned long long sum_exec_runtime; |
220 | }; | |
9d7fb042 | 221 | |
f06febc9 | 222 | /* Alternate field names when used to cache expirations. */ |
f06febc9 | 223 | #define virt_exp utime |
9d7fb042 | 224 | #define prof_exp stime |
f06febc9 FM |
225 | #define sched_exp sum_exec_runtime |
226 | ||
f6db8347 | 227 | #ifdef CONFIG_SCHED_INFO |
1da177e4 LT |
228 | struct sched_info { |
229 | /* cumulative counters */ | |
2d72376b | 230 | unsigned long pcount; /* # of times run on this cpu */ |
9c2c4802 | 231 | unsigned long long run_delay; /* time spent waiting on a runqueue */ |
1da177e4 LT |
232 | |
233 | /* timestamps */ | |
172ba844 BS |
234 | unsigned long long last_arrival,/* when we last ran on a cpu */ |
235 | last_queued; /* when we were last queued to run */ | |
1da177e4 | 236 | }; |
f6db8347 | 237 | #endif /* CONFIG_SCHED_INFO */ |
1da177e4 | 238 | |
6ecdd749 YD |
239 | /* |
240 | * Integer metrics need fixed point arithmetic, e.g., sched/fair | |
241 | * has a few: load, load_avg, util_avg, freq, and capacity. | |
242 | * | |
243 | * We define a basic fixed point arithmetic range, and then formalize | |
244 | * all these metrics based on that basic range. | |
245 | */ | |
246 | # define SCHED_FIXEDPOINT_SHIFT 10 | |
247 | # define SCHED_FIXEDPOINT_SCALE (1L << SCHED_FIXEDPOINT_SHIFT) | |
248 | ||
20b8a59f | 249 | struct load_weight { |
9dbdb155 PZ |
250 | unsigned long weight; |
251 | u32 inv_weight; | |
20b8a59f IM |
252 | }; |
253 | ||
9d89c257 | 254 | /* |
7b595334 YD |
255 | * The load_avg/util_avg accumulates an infinite geometric series |
256 | * (see __update_load_avg() in kernel/sched/fair.c). | |
257 | * | |
258 | * [load_avg definition] | |
259 | * | |
260 | * load_avg = runnable% * scale_load_down(load) | |
261 | * | |
262 | * where runnable% is the time ratio that a sched_entity is runnable. | |
263 | * For cfs_rq, it is the aggregated load_avg of all runnable and | |
9d89c257 | 264 | * blocked sched_entities. |
7b595334 YD |
265 | * |
266 | * load_avg may also take frequency scaling into account: | |
267 | * | |
268 | * load_avg = runnable% * scale_load_down(load) * freq% | |
269 | * | |
270 | * where freq% is the CPU frequency normalized to the highest frequency. | |
271 | * | |
272 | * [util_avg definition] | |
273 | * | |
274 | * util_avg = running% * SCHED_CAPACITY_SCALE | |
275 | * | |
276 | * where running% is the time ratio that a sched_entity is running on | |
277 | * a CPU. For cfs_rq, it is the aggregated util_avg of all runnable | |
278 | * and blocked sched_entities. | |
279 | * | |
280 | * util_avg may also factor frequency scaling and CPU capacity scaling: | |
281 | * | |
282 | * util_avg = running% * SCHED_CAPACITY_SCALE * freq% * capacity% | |
283 | * | |
284 | * where freq% is the same as above, and capacity% is the CPU capacity | |
285 | * normalized to the greatest capacity (due to uarch differences, etc). | |
286 | * | |
287 | * N.B., the above ratios (runnable%, running%, freq%, and capacity%) | |
288 | * themselves are in the range of [0, 1]. To do fixed point arithmetics, | |
289 | * we therefore scale them to as large a range as necessary. This is for | |
290 | * example reflected by util_avg's SCHED_CAPACITY_SCALE. | |
291 | * | |
292 | * [Overflow issue] | |
293 | * | |
294 | * The 64-bit load_sum can have 4353082796 (=2^64/47742/88761) entities | |
295 | * with the highest load (=88761), always runnable on a single cfs_rq, | |
296 | * and should not overflow as the number already hits PID_MAX_LIMIT. | |
297 | * | |
298 | * For all other cases (including 32-bit kernels), struct load_weight's | |
299 | * weight will overflow first before we do, because: | |
300 | * | |
301 | * Max(load_avg) <= Max(load.weight) | |
302 | * | |
303 | * Then it is the load_weight's responsibility to consider overflow | |
304 | * issues. | |
9d89c257 | 305 | */ |
9d85f21c | 306 | struct sched_avg { |
9d89c257 YD |
307 | u64 last_update_time, load_sum; |
308 | u32 util_sum, period_contrib; | |
309 | unsigned long load_avg, util_avg; | |
9d85f21c PT |
310 | }; |
311 | ||
94c18227 | 312 | #ifdef CONFIG_SCHEDSTATS |
41acab88 | 313 | struct sched_statistics { |
20b8a59f | 314 | u64 wait_start; |
94c18227 | 315 | u64 wait_max; |
6d082592 AV |
316 | u64 wait_count; |
317 | u64 wait_sum; | |
8f0dfc34 AV |
318 | u64 iowait_count; |
319 | u64 iowait_sum; | |
94c18227 | 320 | |
20b8a59f | 321 | u64 sleep_start; |
20b8a59f | 322 | u64 sleep_max; |
94c18227 IM |
323 | s64 sum_sleep_runtime; |
324 | ||
325 | u64 block_start; | |
20b8a59f IM |
326 | u64 block_max; |
327 | u64 exec_max; | |
eba1ed4b | 328 | u64 slice_max; |
cc367732 | 329 | |
cc367732 IM |
330 | u64 nr_migrations_cold; |
331 | u64 nr_failed_migrations_affine; | |
332 | u64 nr_failed_migrations_running; | |
333 | u64 nr_failed_migrations_hot; | |
334 | u64 nr_forced_migrations; | |
cc367732 IM |
335 | |
336 | u64 nr_wakeups; | |
337 | u64 nr_wakeups_sync; | |
338 | u64 nr_wakeups_migrate; | |
339 | u64 nr_wakeups_local; | |
340 | u64 nr_wakeups_remote; | |
341 | u64 nr_wakeups_affine; | |
342 | u64 nr_wakeups_affine_attempts; | |
343 | u64 nr_wakeups_passive; | |
344 | u64 nr_wakeups_idle; | |
41acab88 LDM |
345 | }; |
346 | #endif | |
347 | ||
348 | struct sched_entity { | |
349 | struct load_weight load; /* for load-balancing */ | |
350 | struct rb_node run_node; | |
351 | struct list_head group_node; | |
352 | unsigned int on_rq; | |
353 | ||
354 | u64 exec_start; | |
355 | u64 sum_exec_runtime; | |
356 | u64 vruntime; | |
357 | u64 prev_sum_exec_runtime; | |
358 | ||
41acab88 LDM |
359 | u64 nr_migrations; |
360 | ||
41acab88 LDM |
361 | #ifdef CONFIG_SCHEDSTATS |
362 | struct sched_statistics statistics; | |
94c18227 IM |
363 | #endif |
364 | ||
20b8a59f | 365 | #ifdef CONFIG_FAIR_GROUP_SCHED |
fed14d45 | 366 | int depth; |
20b8a59f IM |
367 | struct sched_entity *parent; |
368 | /* rq on which this entity is (to be) queued: */ | |
369 | struct cfs_rq *cfs_rq; | |
370 | /* rq "owned" by this entity/group: */ | |
371 | struct cfs_rq *my_q; | |
372 | #endif | |
8bd75c77 | 373 | |
141965c7 | 374 | #ifdef CONFIG_SMP |
5a107804 JO |
375 | /* |
376 | * Per entity load average tracking. | |
377 | * | |
378 | * Put into separate cache line so it does not | |
379 | * collide with read-mostly values above. | |
380 | */ | |
381 | struct sched_avg avg ____cacheline_aligned_in_smp; | |
9d85f21c | 382 | #endif |
20b8a59f | 383 | }; |
70b97a7f | 384 | |
fa717060 PZ |
385 | struct sched_rt_entity { |
386 | struct list_head run_list; | |
78f2c7db | 387 | unsigned long timeout; |
57d2aa00 | 388 | unsigned long watchdog_stamp; |
bee367ed | 389 | unsigned int time_slice; |
ff77e468 PZ |
390 | unsigned short on_rq; |
391 | unsigned short on_list; | |
6f505b16 | 392 | |
58d6c2d7 | 393 | struct sched_rt_entity *back; |
052f1dc7 | 394 | #ifdef CONFIG_RT_GROUP_SCHED |
6f505b16 PZ |
395 | struct sched_rt_entity *parent; |
396 | /* rq on which this entity is (to be) queued: */ | |
397 | struct rt_rq *rt_rq; | |
398 | /* rq "owned" by this entity/group: */ | |
399 | struct rt_rq *my_q; | |
400 | #endif | |
fa717060 PZ |
401 | }; |
402 | ||
aab03e05 DF |
403 | struct sched_dl_entity { |
404 | struct rb_node rb_node; | |
405 | ||
406 | /* | |
407 | * Original scheduling parameters. Copied here from sched_attr | |
4027d080 | 408 | * during sched_setattr(), they will remain the same until |
409 | * the next sched_setattr(). | |
aab03e05 DF |
410 | */ |
411 | u64 dl_runtime; /* maximum runtime for each instance */ | |
412 | u64 dl_deadline; /* relative deadline of each instance */ | |
755378a4 | 413 | u64 dl_period; /* separation of two instances (period) */ |
332ac17e | 414 | u64 dl_bw; /* dl_runtime / dl_deadline */ |
aab03e05 DF |
415 | |
416 | /* | |
417 | * Actual scheduling parameters. Initialized with the values above, | |
418 | * they are continously updated during task execution. Note that | |
419 | * the remaining runtime could be < 0 in case we are in overrun. | |
420 | */ | |
421 | s64 runtime; /* remaining runtime for this instance */ | |
422 | u64 deadline; /* absolute deadline for this instance */ | |
423 | unsigned int flags; /* specifying the scheduler behaviour */ | |
424 | ||
425 | /* | |
426 | * Some bool flags: | |
427 | * | |
428 | * @dl_throttled tells if we exhausted the runtime. If so, the | |
429 | * task has to wait for a replenishment to be performed at the | |
430 | * next firing of dl_timer. | |
431 | * | |
2d3d891d DF |
432 | * @dl_boosted tells if we are boosted due to DI. If so we are |
433 | * outside bandwidth enforcement mechanism (but only until we | |
5bfd126e JL |
434 | * exit the critical section); |
435 | * | |
436 | * @dl_yielded tells if task gave up the cpu before consuming | |
437 | * all its available runtime during the last job. | |
aab03e05 | 438 | */ |
72f9f3fd | 439 | int dl_throttled, dl_boosted, dl_yielded; |
aab03e05 DF |
440 | |
441 | /* | |
442 | * Bandwidth enforcement timer. Each -deadline task has its | |
443 | * own bandwidth to be enforced, thus we need one timer per task. | |
444 | */ | |
445 | struct hrtimer dl_timer; | |
446 | }; | |
8bd75c77 | 447 | |
1d082fd0 PM |
448 | union rcu_special { |
449 | struct { | |
8203d6d0 PM |
450 | u8 blocked; |
451 | u8 need_qs; | |
452 | u8 exp_need_qs; | |
453 | u8 pad; /* Otherwise the compiler can store garbage here. */ | |
454 | } b; /* Bits. */ | |
455 | u32 s; /* Set of bits. */ | |
1d082fd0 | 456 | }; |
86848966 | 457 | |
8dc85d54 PZ |
458 | enum perf_event_task_context { |
459 | perf_invalid_context = -1, | |
460 | perf_hw_context = 0, | |
89a1e187 | 461 | perf_sw_context, |
8dc85d54 PZ |
462 | perf_nr_task_contexts, |
463 | }; | |
464 | ||
eb61baf6 IM |
465 | struct wake_q_node { |
466 | struct wake_q_node *next; | |
467 | }; | |
468 | ||
1da177e4 | 469 | struct task_struct { |
c65eacbe AL |
470 | #ifdef CONFIG_THREAD_INFO_IN_TASK |
471 | /* | |
472 | * For reasons of header soup (see current_thread_info()), this | |
473 | * must be the first element of task_struct. | |
474 | */ | |
475 | struct thread_info thread_info; | |
476 | #endif | |
1da177e4 | 477 | volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ |
f7e4217b | 478 | void *stack; |
1da177e4 | 479 | atomic_t usage; |
97dc32cd WC |
480 | unsigned int flags; /* per process flags, defined below */ |
481 | unsigned int ptrace; | |
1da177e4 | 482 | |
2dd73a4f | 483 | #ifdef CONFIG_SMP |
fa14ff4a | 484 | struct llist_node wake_entry; |
3ca7a440 | 485 | int on_cpu; |
c65eacbe AL |
486 | #ifdef CONFIG_THREAD_INFO_IN_TASK |
487 | unsigned int cpu; /* current CPU */ | |
488 | #endif | |
63b0e9ed | 489 | unsigned int wakee_flips; |
62470419 | 490 | unsigned long wakee_flip_decay_ts; |
63b0e9ed | 491 | struct task_struct *last_wakee; |
ac66f547 PZ |
492 | |
493 | int wake_cpu; | |
2dd73a4f | 494 | #endif |
fd2f4419 | 495 | int on_rq; |
50e645a8 | 496 | |
b29739f9 | 497 | int prio, static_prio, normal_prio; |
c7aceaba | 498 | unsigned int rt_priority; |
5522d5d5 | 499 | const struct sched_class *sched_class; |
20b8a59f | 500 | struct sched_entity se; |
fa717060 | 501 | struct sched_rt_entity rt; |
8323f26c PZ |
502 | #ifdef CONFIG_CGROUP_SCHED |
503 | struct task_group *sched_task_group; | |
504 | #endif | |
aab03e05 | 505 | struct sched_dl_entity dl; |
1da177e4 | 506 | |
e107be36 AK |
507 | #ifdef CONFIG_PREEMPT_NOTIFIERS |
508 | /* list of struct preempt_notifier: */ | |
509 | struct hlist_head preempt_notifiers; | |
510 | #endif | |
511 | ||
6c5c9341 | 512 | #ifdef CONFIG_BLK_DEV_IO_TRACE |
2056a782 | 513 | unsigned int btrace_seq; |
6c5c9341 | 514 | #endif |
1da177e4 | 515 | |
97dc32cd | 516 | unsigned int policy; |
29baa747 | 517 | int nr_cpus_allowed; |
1da177e4 | 518 | cpumask_t cpus_allowed; |
1da177e4 | 519 | |
a57eb940 | 520 | #ifdef CONFIG_PREEMPT_RCU |
e260be67 | 521 | int rcu_read_lock_nesting; |
1d082fd0 | 522 | union rcu_special rcu_read_unlock_special; |
f41d911f | 523 | struct list_head rcu_node_entry; |
a57eb940 | 524 | struct rcu_node *rcu_blocked_node; |
28f6569a | 525 | #endif /* #ifdef CONFIG_PREEMPT_RCU */ |
8315f422 PM |
526 | #ifdef CONFIG_TASKS_RCU |
527 | unsigned long rcu_tasks_nvcsw; | |
528 | bool rcu_tasks_holdout; | |
529 | struct list_head rcu_tasks_holdout_list; | |
176f8f7a | 530 | int rcu_tasks_idle_cpu; |
8315f422 | 531 | #endif /* #ifdef CONFIG_TASKS_RCU */ |
e260be67 | 532 | |
f6db8347 | 533 | #ifdef CONFIG_SCHED_INFO |
1da177e4 LT |
534 | struct sched_info sched_info; |
535 | #endif | |
536 | ||
537 | struct list_head tasks; | |
806c09a7 | 538 | #ifdef CONFIG_SMP |
917b627d | 539 | struct plist_node pushable_tasks; |
1baca4ce | 540 | struct rb_node pushable_dl_tasks; |
806c09a7 | 541 | #endif |
1da177e4 LT |
542 | |
543 | struct mm_struct *mm, *active_mm; | |
314ff785 IM |
544 | |
545 | /* Per-thread vma caching: */ | |
546 | struct vmacache vmacache; | |
547 | ||
34e55232 KH |
548 | #if defined(SPLIT_RSS_COUNTING) |
549 | struct task_rss_stat rss_stat; | |
550 | #endif | |
1da177e4 | 551 | /* task state */ |
97dc32cd | 552 | int exit_state; |
1da177e4 LT |
553 | int exit_code, exit_signal; |
554 | int pdeath_signal; /* The signal sent when the parent dies */ | |
e7cc4173 | 555 | unsigned long jobctl; /* JOBCTL_*, siglock protected */ |
9b89f6ba AE |
556 | |
557 | /* Used for emulating ABI behavior of previous Linux versions */ | |
97dc32cd | 558 | unsigned int personality; |
9b89f6ba | 559 | |
be958bdc | 560 | /* scheduler bits, serialized by scheduler locks */ |
ca94c442 | 561 | unsigned sched_reset_on_fork:1; |
a8e4f2ea | 562 | unsigned sched_contributes_to_load:1; |
ff303e66 | 563 | unsigned sched_migrated:1; |
b7e7ade3 | 564 | unsigned sched_remote_wakeup:1; |
be958bdc PZ |
565 | unsigned :0; /* force alignment to the next boundary */ |
566 | ||
567 | /* unserialized, strictly 'current' */ | |
568 | unsigned in_execve:1; /* bit to tell LSMs we're in execve */ | |
569 | unsigned in_iowait:1; | |
7e781418 AL |
570 | #if !defined(TIF_RESTORE_SIGMASK) |
571 | unsigned restore_sigmask:1; | |
572 | #endif | |
626ebc41 TH |
573 | #ifdef CONFIG_MEMCG |
574 | unsigned memcg_may_oom:1; | |
127424c8 | 575 | #ifndef CONFIG_SLOB |
6f185c29 VD |
576 | unsigned memcg_kmem_skip_account:1; |
577 | #endif | |
127424c8 | 578 | #endif |
ff303e66 PZ |
579 | #ifdef CONFIG_COMPAT_BRK |
580 | unsigned brk_randomized:1; | |
581 | #endif | |
6f185c29 | 582 | |
1d4457f9 KC |
583 | unsigned long atomic_flags; /* Flags needing atomic access. */ |
584 | ||
f56141e3 AL |
585 | struct restart_block restart_block; |
586 | ||
1da177e4 LT |
587 | pid_t pid; |
588 | pid_t tgid; | |
0a425405 | 589 | |
1314562a | 590 | #ifdef CONFIG_CC_STACKPROTECTOR |
0a425405 AV |
591 | /* Canary value for the -fstack-protector gcc feature */ |
592 | unsigned long stack_canary; | |
1314562a | 593 | #endif |
4d1d61a6 | 594 | /* |
1da177e4 | 595 | * pointers to (original) parent process, youngest child, younger sibling, |
4d1d61a6 | 596 | * older sibling, respectively. (p->father can be replaced with |
f470021a | 597 | * p->real_parent->pid) |
1da177e4 | 598 | */ |
abd63bc3 KC |
599 | struct task_struct __rcu *real_parent; /* real parent process */ |
600 | struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */ | |
1da177e4 | 601 | /* |
f470021a | 602 | * children/sibling forms the list of my natural children |
1da177e4 LT |
603 | */ |
604 | struct list_head children; /* list of my children */ | |
605 | struct list_head sibling; /* linkage in my parent's children list */ | |
606 | struct task_struct *group_leader; /* threadgroup leader */ | |
607 | ||
f470021a RM |
608 | /* |
609 | * ptraced is the list of tasks this task is using ptrace on. | |
610 | * This includes both natural children and PTRACE_ATTACH targets. | |
611 | * p->ptrace_entry is p's link on the p->parent->ptraced list. | |
612 | */ | |
613 | struct list_head ptraced; | |
614 | struct list_head ptrace_entry; | |
615 | ||
1da177e4 | 616 | /* PID/PID hash table linkage. */ |
92476d7f | 617 | struct pid_link pids[PIDTYPE_MAX]; |
47e65328 | 618 | struct list_head thread_group; |
0c740d0a | 619 | struct list_head thread_node; |
1da177e4 LT |
620 | |
621 | struct completion *vfork_done; /* for vfork() */ | |
622 | int __user *set_child_tid; /* CLONE_CHILD_SETTID */ | |
623 | int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */ | |
624 | ||
5613fda9 | 625 | u64 utime, stime; |
40565b5a | 626 | #ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME |
5613fda9 | 627 | u64 utimescaled, stimescaled; |
40565b5a | 628 | #endif |
16a6d9be | 629 | u64 gtime; |
9d7fb042 | 630 | struct prev_cputime prev_cputime; |
6a61671b | 631 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN |
b7ce2277 | 632 | seqcount_t vtime_seqcount; |
6a61671b FW |
633 | unsigned long long vtime_snap; |
634 | enum { | |
7098c1ea FW |
635 | /* Task is sleeping or running in a CPU with VTIME inactive */ |
636 | VTIME_INACTIVE = 0, | |
637 | /* Task runs in userspace in a CPU with VTIME active */ | |
6a61671b | 638 | VTIME_USER, |
7098c1ea | 639 | /* Task runs in kernelspace in a CPU with VTIME active */ |
6a61671b FW |
640 | VTIME_SYS, |
641 | } vtime_snap_whence; | |
d99ca3b9 | 642 | #endif |
d027d45d FW |
643 | |
644 | #ifdef CONFIG_NO_HZ_FULL | |
f009a7a7 | 645 | atomic_t tick_dep_mask; |
d027d45d | 646 | #endif |
1da177e4 | 647 | unsigned long nvcsw, nivcsw; /* context switch counts */ |
ccbf62d8 | 648 | u64 start_time; /* monotonic time in nsec */ |
57e0be04 | 649 | u64 real_start_time; /* boot based time in nsec */ |
1da177e4 LT |
650 | /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ |
651 | unsigned long min_flt, maj_flt; | |
652 | ||
b18b6a9c | 653 | #ifdef CONFIG_POSIX_TIMERS |
f06febc9 | 654 | struct task_cputime cputime_expires; |
1da177e4 | 655 | struct list_head cpu_timers[3]; |
b18b6a9c | 656 | #endif |
1da177e4 LT |
657 | |
658 | /* process credentials */ | |
64b875f7 | 659 | const struct cred __rcu *ptracer_cred; /* Tracer's credentials at attach */ |
1b0ba1c9 | 660 | const struct cred __rcu *real_cred; /* objective and real subjective task |
3b11a1de | 661 | * credentials (COW) */ |
1b0ba1c9 | 662 | const struct cred __rcu *cred; /* effective (overridable) subjective task |
3b11a1de | 663 | * credentials (COW) */ |
36772092 PBG |
664 | char comm[TASK_COMM_LEN]; /* executable name excluding path |
665 | - access with [gs]et_task_comm (which lock | |
666 | it with task_lock()) | |
221af7f8 | 667 | - initialized normally by setup_new_exec */ |
1da177e4 | 668 | /* file system info */ |
756daf26 | 669 | struct nameidata *nameidata; |
3d5b6fcc | 670 | #ifdef CONFIG_SYSVIPC |
1da177e4 LT |
671 | /* ipc stuff */ |
672 | struct sysv_sem sysvsem; | |
ab602f79 | 673 | struct sysv_shm sysvshm; |
3d5b6fcc | 674 | #endif |
e162b39a | 675 | #ifdef CONFIG_DETECT_HUNG_TASK |
82a1fcb9 | 676 | /* hung task detection */ |
82a1fcb9 IM |
677 | unsigned long last_switch_count; |
678 | #endif | |
1da177e4 LT |
679 | /* filesystem information */ |
680 | struct fs_struct *fs; | |
681 | /* open file information */ | |
682 | struct files_struct *files; | |
1651e14e | 683 | /* namespaces */ |
ab516013 | 684 | struct nsproxy *nsproxy; |
1da177e4 LT |
685 | /* signal handlers */ |
686 | struct signal_struct *signal; | |
687 | struct sighand_struct *sighand; | |
688 | ||
689 | sigset_t blocked, real_blocked; | |
f3de272b | 690 | sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */ |
1da177e4 LT |
691 | struct sigpending pending; |
692 | ||
693 | unsigned long sas_ss_sp; | |
694 | size_t sas_ss_size; | |
2a742138 | 695 | unsigned sas_ss_flags; |
2e01fabe | 696 | |
67d12145 | 697 | struct callback_head *task_works; |
e73f8959 | 698 | |
1da177e4 | 699 | struct audit_context *audit_context; |
bfef93a5 | 700 | #ifdef CONFIG_AUDITSYSCALL |
e1760bd5 | 701 | kuid_t loginuid; |
4746ec5b | 702 | unsigned int sessionid; |
bfef93a5 | 703 | #endif |
932ecebb | 704 | struct seccomp seccomp; |
1da177e4 LT |
705 | |
706 | /* Thread group tracking */ | |
707 | u32 parent_exec_id; | |
708 | u32 self_exec_id; | |
58568d2a MX |
709 | /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed, |
710 | * mempolicy */ | |
1da177e4 | 711 | spinlock_t alloc_lock; |
1da177e4 | 712 | |
b29739f9 | 713 | /* Protection of the PI data structures: */ |
1d615482 | 714 | raw_spinlock_t pi_lock; |
b29739f9 | 715 | |
76751049 PZ |
716 | struct wake_q_node wake_q; |
717 | ||
23f78d4a IM |
718 | #ifdef CONFIG_RT_MUTEXES |
719 | /* PI waiters blocked on a rt_mutex held by this task */ | |
fb00aca4 PZ |
720 | struct rb_root pi_waiters; |
721 | struct rb_node *pi_waiters_leftmost; | |
23f78d4a IM |
722 | /* Deadlock detection and priority inheritance handling */ |
723 | struct rt_mutex_waiter *pi_blocked_on; | |
23f78d4a IM |
724 | #endif |
725 | ||
408894ee IM |
726 | #ifdef CONFIG_DEBUG_MUTEXES |
727 | /* mutex deadlock detection */ | |
728 | struct mutex_waiter *blocked_on; | |
729 | #endif | |
de30a2b3 IM |
730 | #ifdef CONFIG_TRACE_IRQFLAGS |
731 | unsigned int irq_events; | |
de30a2b3 | 732 | unsigned long hardirq_enable_ip; |
de30a2b3 | 733 | unsigned long hardirq_disable_ip; |
fa1452e8 | 734 | unsigned int hardirq_enable_event; |
de30a2b3 | 735 | unsigned int hardirq_disable_event; |
fa1452e8 HS |
736 | int hardirqs_enabled; |
737 | int hardirq_context; | |
de30a2b3 | 738 | unsigned long softirq_disable_ip; |
de30a2b3 | 739 | unsigned long softirq_enable_ip; |
fa1452e8 | 740 | unsigned int softirq_disable_event; |
de30a2b3 | 741 | unsigned int softirq_enable_event; |
fa1452e8 | 742 | int softirqs_enabled; |
de30a2b3 IM |
743 | int softirq_context; |
744 | #endif | |
fbb9ce95 | 745 | #ifdef CONFIG_LOCKDEP |
bdb9441e | 746 | # define MAX_LOCK_DEPTH 48UL |
fbb9ce95 IM |
747 | u64 curr_chain_key; |
748 | int lockdep_depth; | |
fbb9ce95 | 749 | unsigned int lockdep_recursion; |
c7aceaba | 750 | struct held_lock held_locks[MAX_LOCK_DEPTH]; |
cf40bd16 | 751 | gfp_t lockdep_reclaim_gfp; |
fbb9ce95 | 752 | #endif |
c6d30853 AR |
753 | #ifdef CONFIG_UBSAN |
754 | unsigned int in_ubsan; | |
755 | #endif | |
408894ee | 756 | |
1da177e4 LT |
757 | /* journalling filesystem info */ |
758 | void *journal_info; | |
759 | ||
d89d8796 | 760 | /* stacked block device info */ |
bddd87c7 | 761 | struct bio_list *bio_list; |
d89d8796 | 762 | |
73c10101 JA |
763 | #ifdef CONFIG_BLOCK |
764 | /* stack plugging */ | |
765 | struct blk_plug *plug; | |
766 | #endif | |
767 | ||
1da177e4 LT |
768 | /* VM state */ |
769 | struct reclaim_state *reclaim_state; | |
770 | ||
1da177e4 LT |
771 | struct backing_dev_info *backing_dev_info; |
772 | ||
773 | struct io_context *io_context; | |
774 | ||
775 | unsigned long ptrace_message; | |
776 | siginfo_t *last_siginfo; /* For ptrace use. */ | |
7c3ab738 | 777 | struct task_io_accounting ioac; |
8f0ab514 | 778 | #if defined(CONFIG_TASK_XACCT) |
1da177e4 LT |
779 | u64 acct_rss_mem1; /* accumulated rss usage */ |
780 | u64 acct_vm_mem1; /* accumulated virtual memory usage */ | |
605dc2b3 | 781 | u64 acct_timexpd; /* stime + utime since last update */ |
1da177e4 LT |
782 | #endif |
783 | #ifdef CONFIG_CPUSETS | |
58568d2a | 784 | nodemask_t mems_allowed; /* Protected by alloc_lock */ |
cc9a6c87 | 785 | seqcount_t mems_allowed_seq; /* Seqence no to catch updates */ |
825a46af | 786 | int cpuset_mem_spread_rotor; |
6adef3eb | 787 | int cpuset_slab_spread_rotor; |
1da177e4 | 788 | #endif |
ddbcc7e8 | 789 | #ifdef CONFIG_CGROUPS |
817929ec | 790 | /* Control Group info protected by css_set_lock */ |
2c392b8c | 791 | struct css_set __rcu *cgroups; |
817929ec PM |
792 | /* cg_list protected by css_set_lock and tsk->alloc_lock */ |
793 | struct list_head cg_list; | |
ddbcc7e8 | 794 | #endif |
e02737d5 FY |
795 | #ifdef CONFIG_INTEL_RDT_A |
796 | int closid; | |
797 | #endif | |
42b2dd0a | 798 | #ifdef CONFIG_FUTEX |
0771dfef | 799 | struct robust_list_head __user *robust_list; |
34f192c6 IM |
800 | #ifdef CONFIG_COMPAT |
801 | struct compat_robust_list_head __user *compat_robust_list; | |
802 | #endif | |
c87e2837 IM |
803 | struct list_head pi_state_list; |
804 | struct futex_pi_state *pi_state_cache; | |
c7aceaba | 805 | #endif |
cdd6c482 | 806 | #ifdef CONFIG_PERF_EVENTS |
8dc85d54 | 807 | struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts]; |
cdd6c482 IM |
808 | struct mutex perf_event_mutex; |
809 | struct list_head perf_event_list; | |
a63eaf34 | 810 | #endif |
8f47b187 TG |
811 | #ifdef CONFIG_DEBUG_PREEMPT |
812 | unsigned long preempt_disable_ip; | |
813 | #endif | |
c7aceaba | 814 | #ifdef CONFIG_NUMA |
58568d2a | 815 | struct mempolicy *mempolicy; /* Protected by alloc_lock */ |
c7aceaba | 816 | short il_next; |
207205a2 | 817 | short pref_node_fork; |
42b2dd0a | 818 | #endif |
cbee9f88 PZ |
819 | #ifdef CONFIG_NUMA_BALANCING |
820 | int numa_scan_seq; | |
cbee9f88 | 821 | unsigned int numa_scan_period; |
598f0ec0 | 822 | unsigned int numa_scan_period_max; |
de1c9ce6 | 823 | int numa_preferred_nid; |
6b9a7460 | 824 | unsigned long numa_migrate_retry; |
cbee9f88 | 825 | u64 node_stamp; /* migration stamp */ |
7e2703e6 RR |
826 | u64 last_task_numa_placement; |
827 | u64 last_sum_exec_runtime; | |
cbee9f88 | 828 | struct callback_head numa_work; |
f809ca9a | 829 | |
8c8a743c PZ |
830 | struct list_head numa_entry; |
831 | struct numa_group *numa_group; | |
832 | ||
745d6147 | 833 | /* |
44dba3d5 IM |
834 | * numa_faults is an array split into four regions: |
835 | * faults_memory, faults_cpu, faults_memory_buffer, faults_cpu_buffer | |
836 | * in this precise order. | |
837 | * | |
838 | * faults_memory: Exponential decaying average of faults on a per-node | |
839 | * basis. Scheduling placement decisions are made based on these | |
840 | * counts. The values remain static for the duration of a PTE scan. | |
841 | * faults_cpu: Track the nodes the process was running on when a NUMA | |
842 | * hinting fault was incurred. | |
843 | * faults_memory_buffer and faults_cpu_buffer: Record faults per node | |
844 | * during the current scan window. When the scan completes, the counts | |
845 | * in faults_memory and faults_cpu decay and these values are copied. | |
745d6147 | 846 | */ |
44dba3d5 | 847 | unsigned long *numa_faults; |
83e1d2cd | 848 | unsigned long total_numa_faults; |
745d6147 | 849 | |
04bb2f94 RR |
850 | /* |
851 | * numa_faults_locality tracks if faults recorded during the last | |
074c2381 MG |
852 | * scan window were remote/local or failed to migrate. The task scan |
853 | * period is adapted based on the locality of the faults with different | |
854 | * weights depending on whether they were shared or private faults | |
04bb2f94 | 855 | */ |
074c2381 | 856 | unsigned long numa_faults_locality[3]; |
04bb2f94 | 857 | |
b32e86b4 | 858 | unsigned long numa_pages_migrated; |
cbee9f88 PZ |
859 | #endif /* CONFIG_NUMA_BALANCING */ |
860 | ||
72b252ae | 861 | struct tlbflush_unmap_batch tlb_ubc; |
72b252ae | 862 | |
e56d0903 | 863 | struct rcu_head rcu; |
b92ce558 JA |
864 | |
865 | /* | |
866 | * cache last used pipe for splice | |
867 | */ | |
868 | struct pipe_inode_info *splice_pipe; | |
5640f768 ED |
869 | |
870 | struct page_frag task_frag; | |
871 | ||
47913d4e IM |
872 | #ifdef CONFIG_TASK_DELAY_ACCT |
873 | struct task_delay_info *delays; | |
f4f154fd | 874 | #endif |
47913d4e | 875 | |
f4f154fd AM |
876 | #ifdef CONFIG_FAULT_INJECTION |
877 | int make_it_fail; | |
ca74e92b | 878 | #endif |
9d823e8f WF |
879 | /* |
880 | * when (nr_dirtied >= nr_dirtied_pause), it's time to call | |
881 | * balance_dirty_pages() for some dirty throttling pause | |
882 | */ | |
883 | int nr_dirtied; | |
884 | int nr_dirtied_pause; | |
83712358 | 885 | unsigned long dirty_paused_when; /* start of a write-and-pause period */ |
9d823e8f | 886 | |
9745512c AV |
887 | #ifdef CONFIG_LATENCYTOP |
888 | int latency_record_count; | |
889 | struct latency_record latency_record[LT_SAVECOUNT]; | |
890 | #endif | |
6976675d AV |
891 | /* |
892 | * time slack values; these are used to round up poll() and | |
893 | * select() etc timeout values. These are in nanoseconds. | |
894 | */ | |
da8b44d5 JS |
895 | u64 timer_slack_ns; |
896 | u64 default_timer_slack_ns; | |
f8d570a4 | 897 | |
0b24becc AR |
898 | #ifdef CONFIG_KASAN |
899 | unsigned int kasan_depth; | |
900 | #endif | |
fb52607a | 901 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
3ad2f3fb | 902 | /* Index of current stored address in ret_stack */ |
f201ae23 FW |
903 | int curr_ret_stack; |
904 | /* Stack of return addresses for return function tracing */ | |
905 | struct ftrace_ret_stack *ret_stack; | |
8aef2d28 SR |
906 | /* time stamp for last schedule */ |
907 | unsigned long long ftrace_timestamp; | |
f201ae23 FW |
908 | /* |
909 | * Number of functions that haven't been traced | |
910 | * because of depth overrun. | |
911 | */ | |
912 | atomic_t trace_overrun; | |
380c4b14 FW |
913 | /* Pause for the tracing */ |
914 | atomic_t tracing_graph_pause; | |
f201ae23 | 915 | #endif |
ea4e2bc4 SR |
916 | #ifdef CONFIG_TRACING |
917 | /* state flags for use by tracers */ | |
918 | unsigned long trace; | |
b1cff0ad | 919 | /* bitmask and counter of trace recursion */ |
261842b7 SR |
920 | unsigned long trace_recursion; |
921 | #endif /* CONFIG_TRACING */ | |
5c9a8750 DV |
922 | #ifdef CONFIG_KCOV |
923 | /* Coverage collection mode enabled for this task (0 if disabled). */ | |
924 | enum kcov_mode kcov_mode; | |
925 | /* Size of the kcov_area. */ | |
926 | unsigned kcov_size; | |
927 | /* Buffer for coverage collection. */ | |
928 | void *kcov_area; | |
929 | /* kcov desciptor wired with this task or NULL. */ | |
930 | struct kcov *kcov; | |
931 | #endif | |
6f185c29 | 932 | #ifdef CONFIG_MEMCG |
626ebc41 TH |
933 | struct mem_cgroup *memcg_in_oom; |
934 | gfp_t memcg_oom_gfp_mask; | |
935 | int memcg_oom_order; | |
b23afb93 TH |
936 | |
937 | /* number of pages to reclaim on returning to userland */ | |
938 | unsigned int memcg_nr_pages_over_high; | |
569b846d | 939 | #endif |
0326f5a9 SD |
940 | #ifdef CONFIG_UPROBES |
941 | struct uprobe_task *utask; | |
0326f5a9 | 942 | #endif |
cafe5635 KO |
943 | #if defined(CONFIG_BCACHE) || defined(CONFIG_BCACHE_MODULE) |
944 | unsigned int sequential_io; | |
945 | unsigned int sequential_io_avg; | |
946 | #endif | |
8eb23b9f PZ |
947 | #ifdef CONFIG_DEBUG_ATOMIC_SLEEP |
948 | unsigned long task_state_change; | |
949 | #endif | |
8bcbde54 | 950 | int pagefault_disabled; |
03049269 | 951 | #ifdef CONFIG_MMU |
29c696e1 | 952 | struct task_struct *oom_reaper_list; |
03049269 | 953 | #endif |
ba14a194 AL |
954 | #ifdef CONFIG_VMAP_STACK |
955 | struct vm_struct *stack_vm_area; | |
956 | #endif | |
68f24b08 AL |
957 | #ifdef CONFIG_THREAD_INFO_IN_TASK |
958 | /* A live task holds one reference. */ | |
959 | atomic_t stack_refcount; | |
960 | #endif | |
0c8c0f03 DH |
961 | /* CPU-specific state of this task */ |
962 | struct thread_struct thread; | |
963 | /* | |
964 | * WARNING: on x86, 'thread_struct' contains a variable-sized | |
965 | * structure. It *MUST* be at the end of 'task_struct'. | |
966 | * | |
967 | * Do not put anything below here! | |
968 | */ | |
1da177e4 LT |
969 | }; |
970 | ||
e868171a | 971 | static inline struct pid *task_pid(struct task_struct *task) |
22c935f4 EB |
972 | { |
973 | return task->pids[PIDTYPE_PID].pid; | |
974 | } | |
975 | ||
e868171a | 976 | static inline struct pid *task_tgid(struct task_struct *task) |
22c935f4 EB |
977 | { |
978 | return task->group_leader->pids[PIDTYPE_PID].pid; | |
979 | } | |
980 | ||
6dda81f4 ON |
981 | /* |
982 | * Without tasklist or rcu lock it is not safe to dereference | |
983 | * the result of task_pgrp/task_session even if task == current, | |
984 | * we can race with another thread doing sys_setsid/sys_setpgid. | |
985 | */ | |
e868171a | 986 | static inline struct pid *task_pgrp(struct task_struct *task) |
22c935f4 EB |
987 | { |
988 | return task->group_leader->pids[PIDTYPE_PGID].pid; | |
989 | } | |
990 | ||
e868171a | 991 | static inline struct pid *task_session(struct task_struct *task) |
22c935f4 EB |
992 | { |
993 | return task->group_leader->pids[PIDTYPE_SID].pid; | |
994 | } | |
995 | ||
7af57294 PE |
996 | /* |
997 | * the helpers to get the task's different pids as they are seen | |
998 | * from various namespaces | |
999 | * | |
1000 | * task_xid_nr() : global id, i.e. the id seen from the init namespace; | |
44c4e1b2 EB |
1001 | * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of |
1002 | * current. | |
7af57294 PE |
1003 | * task_xid_nr_ns() : id seen from the ns specified; |
1004 | * | |
1005 | * set_task_vxid() : assigns a virtual id to a task; | |
1006 | * | |
7af57294 PE |
1007 | * see also pid_nr() etc in include/linux/pid.h |
1008 | */ | |
52ee2dfd ON |
1009 | pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, |
1010 | struct pid_namespace *ns); | |
7af57294 | 1011 | |
e868171a | 1012 | static inline pid_t task_pid_nr(struct task_struct *tsk) |
7af57294 PE |
1013 | { |
1014 | return tsk->pid; | |
1015 | } | |
1016 | ||
52ee2dfd ON |
1017 | static inline pid_t task_pid_nr_ns(struct task_struct *tsk, |
1018 | struct pid_namespace *ns) | |
1019 | { | |
1020 | return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns); | |
1021 | } | |
7af57294 PE |
1022 | |
1023 | static inline pid_t task_pid_vnr(struct task_struct *tsk) | |
1024 | { | |
52ee2dfd | 1025 | return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL); |
7af57294 PE |
1026 | } |
1027 | ||
1028 | ||
e868171a | 1029 | static inline pid_t task_tgid_nr(struct task_struct *tsk) |
7af57294 PE |
1030 | { |
1031 | return tsk->tgid; | |
1032 | } | |
1033 | ||
2f2a3a46 | 1034 | pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); |
7af57294 PE |
1035 | |
1036 | static inline pid_t task_tgid_vnr(struct task_struct *tsk) | |
1037 | { | |
1038 | return pid_vnr(task_tgid(tsk)); | |
1039 | } | |
1040 | ||
1041 | ||
80e0b6e8 | 1042 | static inline int pid_alive(const struct task_struct *p); |
ad36d282 RGB |
1043 | static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns) |
1044 | { | |
1045 | pid_t pid = 0; | |
1046 | ||
1047 | rcu_read_lock(); | |
1048 | if (pid_alive(tsk)) | |
1049 | pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns); | |
1050 | rcu_read_unlock(); | |
1051 | ||
1052 | return pid; | |
1053 | } | |
1054 | ||
1055 | static inline pid_t task_ppid_nr(const struct task_struct *tsk) | |
1056 | { | |
1057 | return task_ppid_nr_ns(tsk, &init_pid_ns); | |
1058 | } | |
1059 | ||
52ee2dfd ON |
1060 | static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, |
1061 | struct pid_namespace *ns) | |
7af57294 | 1062 | { |
52ee2dfd | 1063 | return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns); |
7af57294 PE |
1064 | } |
1065 | ||
7af57294 PE |
1066 | static inline pid_t task_pgrp_vnr(struct task_struct *tsk) |
1067 | { | |
52ee2dfd | 1068 | return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL); |
7af57294 PE |
1069 | } |
1070 | ||
1071 | ||
52ee2dfd ON |
1072 | static inline pid_t task_session_nr_ns(struct task_struct *tsk, |
1073 | struct pid_namespace *ns) | |
7af57294 | 1074 | { |
52ee2dfd | 1075 | return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns); |
7af57294 PE |
1076 | } |
1077 | ||
7af57294 PE |
1078 | static inline pid_t task_session_vnr(struct task_struct *tsk) |
1079 | { | |
52ee2dfd | 1080 | return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL); |
7af57294 PE |
1081 | } |
1082 | ||
1b0f7ffd ON |
1083 | /* obsolete, do not use */ |
1084 | static inline pid_t task_pgrp_nr(struct task_struct *tsk) | |
1085 | { | |
1086 | return task_pgrp_nr_ns(tsk, &init_pid_ns); | |
1087 | } | |
7af57294 | 1088 | |
1da177e4 LT |
1089 | /** |
1090 | * pid_alive - check that a task structure is not stale | |
1091 | * @p: Task structure to be checked. | |
1092 | * | |
1093 | * Test if a process is not yet dead (at most zombie state) | |
1094 | * If pid_alive fails, then pointers within the task structure | |
1095 | * can be stale and must not be dereferenced. | |
e69f6186 YB |
1096 | * |
1097 | * Return: 1 if the process is alive. 0 otherwise. | |
1da177e4 | 1098 | */ |
ad36d282 | 1099 | static inline int pid_alive(const struct task_struct *p) |
1da177e4 | 1100 | { |
92476d7f | 1101 | return p->pids[PIDTYPE_PID].pid != NULL; |
1da177e4 LT |
1102 | } |
1103 | ||
f400e198 | 1104 | /** |
570f5241 SS |
1105 | * is_global_init - check if a task structure is init. Since init |
1106 | * is free to have sub-threads we need to check tgid. | |
3260259f HK |
1107 | * @tsk: Task structure to be checked. |
1108 | * | |
1109 | * Check if a task structure is the first user space task the kernel created. | |
e69f6186 YB |
1110 | * |
1111 | * Return: 1 if the task structure is init. 0 otherwise. | |
b460cbc5 | 1112 | */ |
e868171a | 1113 | static inline int is_global_init(struct task_struct *tsk) |
b461cc03 | 1114 | { |
570f5241 | 1115 | return task_tgid_nr(tsk) == 1; |
b461cc03 | 1116 | } |
b460cbc5 | 1117 | |
9ec52099 CLG |
1118 | extern struct pid *cad_pid; |
1119 | ||
1da177e4 LT |
1120 | /* |
1121 | * Per process flags | |
1122 | */ | |
c1de45ca | 1123 | #define PF_IDLE 0x00000002 /* I am an IDLE thread */ |
1da177e4 | 1124 | #define PF_EXITING 0x00000004 /* getting shut down */ |
778e9a9c | 1125 | #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ |
94886b84 | 1126 | #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ |
21aa9af0 | 1127 | #define PF_WQ_WORKER 0x00000020 /* I'm a workqueue worker */ |
1da177e4 | 1128 | #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ |
4db96cf0 | 1129 | #define PF_MCE_PROCESS 0x00000080 /* process policy on mce errors */ |
1da177e4 LT |
1130 | #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ |
1131 | #define PF_DUMPCORE 0x00000200 /* dumped core */ | |
1132 | #define PF_SIGNALED 0x00000400 /* killed by a signal */ | |
1133 | #define PF_MEMALLOC 0x00000800 /* Allocating memory */ | |
72fa5997 | 1134 | #define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */ |
1da177e4 | 1135 | #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */ |
774a1221 | 1136 | #define PF_USED_ASYNC 0x00004000 /* used async_schedule*(), used by module init */ |
1da177e4 LT |
1137 | #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */ |
1138 | #define PF_FROZEN 0x00010000 /* frozen for system suspend */ | |
1139 | #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ | |
1140 | #define PF_KSWAPD 0x00040000 /* I am kswapd */ | |
21caf2fc | 1141 | #define PF_MEMALLOC_NOIO 0x00080000 /* Allocating memory without IO involved */ |
1da177e4 | 1142 | #define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */ |
246bb0b1 | 1143 | #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ |
b31dc66a JA |
1144 | #define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */ |
1145 | #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ | |
14a40ffc | 1146 | #define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_allowed */ |
4db96cf0 | 1147 | #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */ |
61a87122 | 1148 | #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */ |
58a69cb4 | 1149 | #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezable */ |
2b44c4db | 1150 | #define PF_SUSPEND_TASK 0x80000000 /* this thread called freeze_processes and should not be frozen */ |
1da177e4 LT |
1151 | |
1152 | /* | |
1153 | * Only the _current_ task can read/write to tsk->flags, but other | |
1154 | * tasks can access tsk->flags in readonly mode for example | |
1155 | * with tsk_used_math (like during threaded core dumping). | |
1156 | * There is however an exception to this rule during ptrace | |
1157 | * or during fork: the ptracer task is allowed to write to the | |
1158 | * child->flags of its traced child (same goes for fork, the parent | |
1159 | * can write to the child->flags), because we're guaranteed the | |
1160 | * child is not running and in turn not changing child->flags | |
1161 | * at the same time the parent does it. | |
1162 | */ | |
1163 | #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0) | |
1164 | #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0) | |
1165 | #define clear_used_math() clear_stopped_child_used_math(current) | |
1166 | #define set_used_math() set_stopped_child_used_math(current) | |
1167 | #define conditional_stopped_child_used_math(condition, child) \ | |
1168 | do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0) | |
1169 | #define conditional_used_math(condition) \ | |
1170 | conditional_stopped_child_used_math(condition, current) | |
1171 | #define copy_to_stopped_child_used_math(child) \ | |
1172 | do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0) | |
1173 | /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */ | |
1174 | #define tsk_used_math(p) ((p)->flags & PF_USED_MATH) | |
1175 | #define used_math() tsk_used_math(current) | |
1176 | ||
1d4457f9 | 1177 | /* Per-process atomic flags. */ |
a2b86f77 | 1178 | #define PFA_NO_NEW_PRIVS 0 /* May not gain new privileges. */ |
2ad654bc ZL |
1179 | #define PFA_SPREAD_PAGE 1 /* Spread page cache over cpuset */ |
1180 | #define PFA_SPREAD_SLAB 2 /* Spread some slab caches over cpuset */ | |
77ed2c57 | 1181 | #define PFA_LMK_WAITING 3 /* Lowmemorykiller is waiting */ |
2ad654bc | 1182 | |
1d4457f9 | 1183 | |
e0e5070b ZL |
1184 | #define TASK_PFA_TEST(name, func) \ |
1185 | static inline bool task_##func(struct task_struct *p) \ | |
1186 | { return test_bit(PFA_##name, &p->atomic_flags); } | |
1187 | #define TASK_PFA_SET(name, func) \ | |
1188 | static inline void task_set_##func(struct task_struct *p) \ | |
1189 | { set_bit(PFA_##name, &p->atomic_flags); } | |
1190 | #define TASK_PFA_CLEAR(name, func) \ | |
1191 | static inline void task_clear_##func(struct task_struct *p) \ | |
1192 | { clear_bit(PFA_##name, &p->atomic_flags); } | |
1193 | ||
1194 | TASK_PFA_TEST(NO_NEW_PRIVS, no_new_privs) | |
1195 | TASK_PFA_SET(NO_NEW_PRIVS, no_new_privs) | |
1d4457f9 | 1196 | |
2ad654bc ZL |
1197 | TASK_PFA_TEST(SPREAD_PAGE, spread_page) |
1198 | TASK_PFA_SET(SPREAD_PAGE, spread_page) | |
1199 | TASK_PFA_CLEAR(SPREAD_PAGE, spread_page) | |
1200 | ||
1201 | TASK_PFA_TEST(SPREAD_SLAB, spread_slab) | |
1202 | TASK_PFA_SET(SPREAD_SLAB, spread_slab) | |
1203 | TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab) | |
1d4457f9 | 1204 | |
77ed2c57 TH |
1205 | TASK_PFA_TEST(LMK_WAITING, lmk_waiting) |
1206 | TASK_PFA_SET(LMK_WAITING, lmk_waiting) | |
1207 | ||
907aed48 MG |
1208 | static inline void tsk_restore_flags(struct task_struct *task, |
1209 | unsigned long orig_flags, unsigned long flags) | |
1210 | { | |
1211 | task->flags &= ~flags; | |
1212 | task->flags |= orig_flags & flags; | |
1213 | } | |
1214 | ||
f82f8042 JL |
1215 | extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, |
1216 | const struct cpumask *trial); | |
7f51412a JL |
1217 | extern int task_can_attach(struct task_struct *p, |
1218 | const struct cpumask *cs_cpus_allowed); | |
1da177e4 | 1219 | #ifdef CONFIG_SMP |
1e1b6c51 KM |
1220 | extern void do_set_cpus_allowed(struct task_struct *p, |
1221 | const struct cpumask *new_mask); | |
1222 | ||
cd8ba7cd | 1223 | extern int set_cpus_allowed_ptr(struct task_struct *p, |
96f874e2 | 1224 | const struct cpumask *new_mask); |
1da177e4 | 1225 | #else |
1e1b6c51 KM |
1226 | static inline void do_set_cpus_allowed(struct task_struct *p, |
1227 | const struct cpumask *new_mask) | |
1228 | { | |
1229 | } | |
cd8ba7cd | 1230 | static inline int set_cpus_allowed_ptr(struct task_struct *p, |
96f874e2 | 1231 | const struct cpumask *new_mask) |
1da177e4 | 1232 | { |
96f874e2 | 1233 | if (!cpumask_test_cpu(0, new_mask)) |
1da177e4 LT |
1234 | return -EINVAL; |
1235 | return 0; | |
1236 | } | |
1237 | #endif | |
e0ad9556 | 1238 | |
6d0d2878 CB |
1239 | #ifndef cpu_relax_yield |
1240 | #define cpu_relax_yield() cpu_relax() | |
1241 | #endif | |
1242 | ||
fa93384f | 1243 | extern int yield_to(struct task_struct *p, bool preempt); |
36c8b586 IM |
1244 | extern void set_user_nice(struct task_struct *p, long nice); |
1245 | extern int task_prio(const struct task_struct *p); | |
d0ea0268 DY |
1246 | /** |
1247 | * task_nice - return the nice value of a given task. | |
1248 | * @p: the task in question. | |
1249 | * | |
1250 | * Return: The nice value [ -20 ... 0 ... 19 ]. | |
1251 | */ | |
1252 | static inline int task_nice(const struct task_struct *p) | |
1253 | { | |
1254 | return PRIO_TO_NICE((p)->static_prio); | |
1255 | } | |
36c8b586 IM |
1256 | extern int can_nice(const struct task_struct *p, const int nice); |
1257 | extern int task_curr(const struct task_struct *p); | |
1da177e4 | 1258 | extern int idle_cpu(int cpu); |
fe7de49f KM |
1259 | extern int sched_setscheduler(struct task_struct *, int, |
1260 | const struct sched_param *); | |
961ccddd | 1261 | extern int sched_setscheduler_nocheck(struct task_struct *, int, |
fe7de49f | 1262 | const struct sched_param *); |
d50dde5a DF |
1263 | extern int sched_setattr(struct task_struct *, |
1264 | const struct sched_attr *); | |
36c8b586 | 1265 | extern struct task_struct *idle_task(int cpu); |
c4f30608 PM |
1266 | /** |
1267 | * is_idle_task - is the specified task an idle task? | |
fa757281 | 1268 | * @p: the task in question. |
e69f6186 YB |
1269 | * |
1270 | * Return: 1 if @p is an idle task. 0 otherwise. | |
c4f30608 | 1271 | */ |
7061ca3b | 1272 | static inline bool is_idle_task(const struct task_struct *p) |
c4f30608 | 1273 | { |
c1de45ca | 1274 | return !!(p->flags & PF_IDLE); |
c4f30608 | 1275 | } |
36c8b586 | 1276 | extern struct task_struct *curr_task(int cpu); |
a458ae2e | 1277 | extern void ia64_set_curr_task(int cpu, struct task_struct *p); |
1da177e4 LT |
1278 | |
1279 | void yield(void); | |
1280 | ||
1da177e4 | 1281 | union thread_union { |
c65eacbe | 1282 | #ifndef CONFIG_THREAD_INFO_IN_TASK |
1da177e4 | 1283 | struct thread_info thread_info; |
c65eacbe | 1284 | #endif |
1da177e4 LT |
1285 | unsigned long stack[THREAD_SIZE/sizeof(long)]; |
1286 | }; | |
1287 | ||
f3ac6067 IM |
1288 | #ifdef CONFIG_THREAD_INFO_IN_TASK |
1289 | static inline struct thread_info *task_thread_info(struct task_struct *task) | |
1290 | { | |
1291 | return &task->thread_info; | |
1292 | } | |
1293 | #elif !defined(__HAVE_THREAD_FUNCTIONS) | |
1294 | # define task_thread_info(task) ((struct thread_info *)(task)->stack) | |
1295 | #endif | |
1296 | ||
198fe21b PE |
1297 | /* |
1298 | * find a task by one of its numerical ids | |
1299 | * | |
198fe21b PE |
1300 | * find_task_by_pid_ns(): |
1301 | * finds a task by its pid in the specified namespace | |
228ebcbe PE |
1302 | * find_task_by_vpid(): |
1303 | * finds a task by its virtual pid | |
198fe21b | 1304 | * |
e49859e7 | 1305 | * see also find_vpid() etc in include/linux/pid.h |
198fe21b PE |
1306 | */ |
1307 | ||
228ebcbe PE |
1308 | extern struct task_struct *find_task_by_vpid(pid_t nr); |
1309 | extern struct task_struct *find_task_by_pid_ns(pid_t nr, | |
1310 | struct pid_namespace *ns); | |
198fe21b | 1311 | |
b3c97528 HH |
1312 | extern int wake_up_state(struct task_struct *tsk, unsigned int state); |
1313 | extern int wake_up_process(struct task_struct *tsk); | |
3e51e3ed | 1314 | extern void wake_up_new_task(struct task_struct *tsk); |
1da177e4 LT |
1315 | #ifdef CONFIG_SMP |
1316 | extern void kick_process(struct task_struct *tsk); | |
1317 | #else | |
1318 | static inline void kick_process(struct task_struct *tsk) { } | |
1319 | #endif | |
1da177e4 | 1320 | |
82b89778 AH |
1321 | extern void __set_task_comm(struct task_struct *tsk, const char *from, bool exec); |
1322 | static inline void set_task_comm(struct task_struct *tsk, const char *from) | |
1323 | { | |
1324 | __set_task_comm(tsk, from, false); | |
1325 | } | |
59714d65 | 1326 | extern char *get_task_comm(char *to, struct task_struct *tsk); |
1da177e4 LT |
1327 | |
1328 | #ifdef CONFIG_SMP | |
317f3941 | 1329 | void scheduler_ipi(void); |
85ba2d86 | 1330 | extern unsigned long wait_task_inactive(struct task_struct *, long match_state); |
1da177e4 | 1331 | #else |
184748cc | 1332 | static inline void scheduler_ipi(void) { } |
85ba2d86 RM |
1333 | static inline unsigned long wait_task_inactive(struct task_struct *p, |
1334 | long match_state) | |
1335 | { | |
1336 | return 1; | |
1337 | } | |
1da177e4 LT |
1338 | #endif |
1339 | ||
1da177e4 LT |
1340 | /* set thread flags in other task's structures |
1341 | * - see asm/thread_info.h for TIF_xxxx flags available | |
1342 | */ | |
1343 | static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag) | |
1344 | { | |
a1261f54 | 1345 | set_ti_thread_flag(task_thread_info(tsk), flag); |
1da177e4 LT |
1346 | } |
1347 | ||
1348 | static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag) | |
1349 | { | |
a1261f54 | 1350 | clear_ti_thread_flag(task_thread_info(tsk), flag); |
1da177e4 LT |
1351 | } |
1352 | ||
1353 | static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag) | |
1354 | { | |
a1261f54 | 1355 | return test_and_set_ti_thread_flag(task_thread_info(tsk), flag); |
1da177e4 LT |
1356 | } |
1357 | ||
1358 | static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag) | |
1359 | { | |
a1261f54 | 1360 | return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag); |
1da177e4 LT |
1361 | } |
1362 | ||
1363 | static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag) | |
1364 | { | |
a1261f54 | 1365 | return test_ti_thread_flag(task_thread_info(tsk), flag); |
1da177e4 LT |
1366 | } |
1367 | ||
1368 | static inline void set_tsk_need_resched(struct task_struct *tsk) | |
1369 | { | |
1370 | set_tsk_thread_flag(tsk,TIF_NEED_RESCHED); | |
1371 | } | |
1372 | ||
1373 | static inline void clear_tsk_need_resched(struct task_struct *tsk) | |
1374 | { | |
1375 | clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED); | |
1376 | } | |
1377 | ||
8ae121ac GH |
1378 | static inline int test_tsk_need_resched(struct task_struct *tsk) |
1379 | { | |
1380 | return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED)); | |
1381 | } | |
1382 | ||
1da177e4 LT |
1383 | /* |
1384 | * cond_resched() and cond_resched_lock(): latency reduction via | |
1385 | * explicit rescheduling in places that are safe. The return | |
1386 | * value indicates whether a reschedule was done in fact. | |
1387 | * cond_resched_lock() will drop the spinlock before scheduling, | |
1388 | * cond_resched_softirq() will enable bhs before scheduling. | |
1389 | */ | |
35a773a0 | 1390 | #ifndef CONFIG_PREEMPT |
c3921ab7 | 1391 | extern int _cond_resched(void); |
35a773a0 PZ |
1392 | #else |
1393 | static inline int _cond_resched(void) { return 0; } | |
1394 | #endif | |
6f80bd98 | 1395 | |
613afbf8 | 1396 | #define cond_resched() ({ \ |
3427445a | 1397 | ___might_sleep(__FILE__, __LINE__, 0); \ |
613afbf8 FW |
1398 | _cond_resched(); \ |
1399 | }) | |
6f80bd98 | 1400 | |
613afbf8 FW |
1401 | extern int __cond_resched_lock(spinlock_t *lock); |
1402 | ||
1403 | #define cond_resched_lock(lock) ({ \ | |
3427445a | 1404 | ___might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);\ |
613afbf8 FW |
1405 | __cond_resched_lock(lock); \ |
1406 | }) | |
1407 | ||
1408 | extern int __cond_resched_softirq(void); | |
1409 | ||
75e1056f | 1410 | #define cond_resched_softirq() ({ \ |
3427445a | 1411 | ___might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET); \ |
75e1056f | 1412 | __cond_resched_softirq(); \ |
613afbf8 | 1413 | }) |
1da177e4 | 1414 | |
f6f3c437 SH |
1415 | static inline void cond_resched_rcu(void) |
1416 | { | |
1417 | #if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU) | |
1418 | rcu_read_unlock(); | |
1419 | cond_resched(); | |
1420 | rcu_read_lock(); | |
1421 | #endif | |
1422 | } | |
1423 | ||
1da177e4 LT |
1424 | /* |
1425 | * Does a critical section need to be broken due to another | |
95c354fe NP |
1426 | * task waiting?: (technically does not depend on CONFIG_PREEMPT, |
1427 | * but a general need for low latency) | |
1da177e4 | 1428 | */ |
95c354fe | 1429 | static inline int spin_needbreak(spinlock_t *lock) |
1da177e4 | 1430 | { |
95c354fe NP |
1431 | #ifdef CONFIG_PREEMPT |
1432 | return spin_is_contended(lock); | |
1433 | #else | |
1da177e4 | 1434 | return 0; |
95c354fe | 1435 | #endif |
1da177e4 LT |
1436 | } |
1437 | ||
75f93fed PZ |
1438 | static __always_inline bool need_resched(void) |
1439 | { | |
1440 | return unlikely(tif_need_resched()); | |
1441 | } | |
1442 | ||
1da177e4 LT |
1443 | /* |
1444 | * Wrappers for p->thread_info->cpu access. No-op on UP. | |
1445 | */ | |
1446 | #ifdef CONFIG_SMP | |
1447 | ||
1448 | static inline unsigned int task_cpu(const struct task_struct *p) | |
1449 | { | |
c65eacbe AL |
1450 | #ifdef CONFIG_THREAD_INFO_IN_TASK |
1451 | return p->cpu; | |
1452 | #else | |
a1261f54 | 1453 | return task_thread_info(p)->cpu; |
c65eacbe | 1454 | #endif |
1da177e4 LT |
1455 | } |
1456 | ||
c65cc870 | 1457 | extern void set_task_cpu(struct task_struct *p, unsigned int cpu); |
1da177e4 LT |
1458 | |
1459 | #else | |
1460 | ||
1461 | static inline unsigned int task_cpu(const struct task_struct *p) | |
1462 | { | |
1463 | return 0; | |
1464 | } | |
1465 | ||
1466 | static inline void set_task_cpu(struct task_struct *p, unsigned int cpu) | |
1467 | { | |
1468 | } | |
1469 | ||
1470 | #endif /* CONFIG_SMP */ | |
1471 | ||
d9345c65 PX |
1472 | /* |
1473 | * In order to reduce various lock holder preemption latencies provide an | |
1474 | * interface to see if a vCPU is currently running or not. | |
1475 | * | |
1476 | * This allows us to terminate optimistic spin loops and block, analogous to | |
1477 | * the native optimistic spin heuristic of testing if the lock owner task is | |
1478 | * running or not. | |
1479 | */ | |
1480 | #ifndef vcpu_is_preempted | |
1481 | # define vcpu_is_preempted(cpu) false | |
1482 | #endif | |
1483 | ||
96f874e2 RR |
1484 | extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask); |
1485 | extern long sched_getaffinity(pid_t pid, struct cpumask *mask); | |
5c45bf27 | 1486 | |
82455257 DH |
1487 | #ifndef TASK_SIZE_OF |
1488 | #define TASK_SIZE_OF(tsk) TASK_SIZE | |
1489 | #endif | |
1490 | ||
1da177e4 | 1491 | #endif |