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