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