sched/fair: Rename SCHED_LOAD_SHIFT to NICE_0_LOAD_SHIFT and remove SCHED_LOAD_SCALE
[deliverable/linux.git] / include / linux / sched.h
CommitLineData
1da177e4
LT
1#ifndef _LINUX_SCHED_H
2#define _LINUX_SCHED_H
3
607ca46e 4#include <uapi/linux/sched.h>
b7b3c76a 5
5c228079
DY
6#include <linux/sched/prio.h>
7
b7b3c76a
DW
8
9struct sched_param {
10 int sched_priority;
11};
12
1da177e4
LT
13#include <asm/param.h> /* for HZ */
14
1da177e4
LT
15#include <linux/capability.h>
16#include <linux/threads.h>
17#include <linux/kernel.h>
18#include <linux/types.h>
19#include <linux/timex.h>
20#include <linux/jiffies.h>
fb00aca4 21#include <linux/plist.h>
1da177e4
LT
22#include <linux/rbtree.h>
23#include <linux/thread_info.h>
24#include <linux/cpumask.h>
25#include <linux/errno.h>
26#include <linux/nodemask.h>
c92ff1bd 27#include <linux/mm_types.h>
92cf2118 28#include <linux/preempt.h>
1da177e4 29
1da177e4
LT
30#include <asm/page.h>
31#include <asm/ptrace.h>
bfc3f028 32#include <linux/cputime.h>
1da177e4
LT
33
34#include <linux/smp.h>
35#include <linux/sem.h>
ab602f79 36#include <linux/shm.h>
1da177e4 37#include <linux/signal.h>
1da177e4
LT
38#include <linux/compiler.h>
39#include <linux/completion.h>
40#include <linux/pid.h>
41#include <linux/percpu.h>
42#include <linux/topology.h>
3e26c149 43#include <linux/proportions.h>
1da177e4 44#include <linux/seccomp.h>
e56d0903 45#include <linux/rcupdate.h>
05725f7e 46#include <linux/rculist.h>
23f78d4a 47#include <linux/rtmutex.h>
1da177e4 48
a3b6714e
DW
49#include <linux/time.h>
50#include <linux/param.h>
51#include <linux/resource.h>
52#include <linux/timer.h>
53#include <linux/hrtimer.h>
5c9a8750 54#include <linux/kcov.h>
7c3ab738 55#include <linux/task_io_accounting.h>
9745512c 56#include <linux/latencytop.h>
9e2b2dc4 57#include <linux/cred.h>
fa14ff4a 58#include <linux/llist.h>
7b44ab97 59#include <linux/uidgid.h>
21caf2fc 60#include <linux/gfp.h>
d4311ff1 61#include <linux/magic.h>
7d7efec3 62#include <linux/cgroup-defs.h>
a3b6714e
DW
63
64#include <asm/processor.h>
36d57ac4 65
d50dde5a
DF
66#define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */
67
68/*
69 * Extended scheduling parameters data structure.
70 *
71 * This is needed because the original struct sched_param can not be
72 * altered without introducing ABI issues with legacy applications
73 * (e.g., in sched_getparam()).
74 *
75 * However, the possibility of specifying more than just a priority for
76 * the tasks may be useful for a wide variety of application fields, e.g.,
77 * multimedia, streaming, automation and control, and many others.
78 *
79 * This variant (sched_attr) is meant at describing a so-called
80 * sporadic time-constrained task. In such model a task is specified by:
81 * - the activation period or minimum instance inter-arrival time;
82 * - the maximum (or average, depending on the actual scheduling
83 * discipline) computation time of all instances, a.k.a. runtime;
84 * - the deadline (relative to the actual activation time) of each
85 * instance.
86 * Very briefly, a periodic (sporadic) task asks for the execution of
87 * some specific computation --which is typically called an instance--
88 * (at most) every period. Moreover, each instance typically lasts no more
89 * than the runtime and must be completed by time instant t equal to
90 * the instance activation time + the deadline.
91 *
92 * This is reflected by the actual fields of the sched_attr structure:
93 *
94 * @size size of the structure, for fwd/bwd compat.
95 *
96 * @sched_policy task's scheduling policy
97 * @sched_flags for customizing the scheduler behaviour
98 * @sched_nice task's nice value (SCHED_NORMAL/BATCH)
99 * @sched_priority task's static priority (SCHED_FIFO/RR)
100 * @sched_deadline representative of the task's deadline
101 * @sched_runtime representative of the task's runtime
102 * @sched_period representative of the task's period
103 *
104 * Given this task model, there are a multiplicity of scheduling algorithms
105 * and policies, that can be used to ensure all the tasks will make their
106 * timing constraints.
aab03e05
DF
107 *
108 * As of now, the SCHED_DEADLINE policy (sched_dl scheduling class) is the
109 * only user of this new interface. More information about the algorithm
110 * available in the scheduling class file or in Documentation/.
d50dde5a
DF
111 */
112struct sched_attr {
113 u32 size;
114
115 u32 sched_policy;
116 u64 sched_flags;
117
118 /* SCHED_NORMAL, SCHED_BATCH */
119 s32 sched_nice;
120
121 /* SCHED_FIFO, SCHED_RR */
122 u32 sched_priority;
123
124 /* SCHED_DEADLINE */
125 u64 sched_runtime;
126 u64 sched_deadline;
127 u64 sched_period;
128};
129
c87e2837 130struct futex_pi_state;
286100a6 131struct robust_list_head;
bddd87c7 132struct bio_list;
5ad4e53b 133struct fs_struct;
cdd6c482 134struct perf_event_context;
73c10101 135struct blk_plug;
c4ad8f98 136struct filename;
89076bc3 137struct nameidata;
1da177e4 138
615d6e87
DB
139#define VMACACHE_BITS 2
140#define VMACACHE_SIZE (1U << VMACACHE_BITS)
141#define VMACACHE_MASK (VMACACHE_SIZE - 1)
142
1da177e4
LT
143/*
144 * These are the constant used to fake the fixed-point load-average
145 * counting. Some notes:
146 * - 11 bit fractions expand to 22 bits by the multiplies: this gives
147 * a load-average precision of 10 bits integer + 11 bits fractional
148 * - if you want to count load-averages more often, you need more
149 * precision, or rounding will get you. With 2-second counting freq,
150 * the EXP_n values would be 1981, 2034 and 2043 if still using only
151 * 11 bit fractions.
152 */
153extern unsigned long avenrun[]; /* Load averages */
2d02494f 154extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
1da177e4
LT
155
156#define FSHIFT 11 /* nr of bits of precision */
157#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
0c2043ab 158#define LOAD_FREQ (5*HZ+1) /* 5 sec intervals */
1da177e4
LT
159#define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
160#define EXP_5 2014 /* 1/exp(5sec/5min) */
161#define EXP_15 2037 /* 1/exp(5sec/15min) */
162
163#define CALC_LOAD(load,exp,n) \
164 load *= exp; \
165 load += n*(FIXED_1-exp); \
166 load >>= FSHIFT;
167
168extern unsigned long total_forks;
169extern int nr_threads;
1da177e4
LT
170DECLARE_PER_CPU(unsigned long, process_counts);
171extern int nr_processes(void);
172extern unsigned long nr_running(void);
2ee507c4 173extern bool single_task_running(void);
1da177e4 174extern unsigned long nr_iowait(void);
8c215bd3 175extern unsigned long nr_iowait_cpu(int cpu);
372ba8cb 176extern void get_iowait_load(unsigned long *nr_waiters, unsigned long *load);
69d25870 177
0f004f5a 178extern void calc_global_load(unsigned long ticks);
3289bdb4
PZ
179
180#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1f41906a
FW
181extern void cpu_load_update_nohz_start(void);
182extern void cpu_load_update_nohz_stop(void);
3289bdb4 183#else
1f41906a
FW
184static inline void cpu_load_update_nohz_start(void) { }
185static inline void cpu_load_update_nohz_stop(void) { }
3289bdb4 186#endif
1da177e4 187
b637a328
PM
188extern void dump_cpu_task(int cpu);
189
43ae34cb
IM
190struct seq_file;
191struct cfs_rq;
4cf86d77 192struct task_group;
43ae34cb
IM
193#ifdef CONFIG_SCHED_DEBUG
194extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
195extern void proc_sched_set_task(struct task_struct *p);
43ae34cb 196#endif
1da177e4 197
4a8342d2
LT
198/*
199 * Task state bitmask. NOTE! These bits are also
200 * encoded in fs/proc/array.c: get_task_state().
201 *
202 * We have two separate sets of flags: task->state
203 * is about runnability, while task->exit_state are
204 * about the task exiting. Confusing, but this way
205 * modifying one set can't modify the other one by
206 * mistake.
207 */
1da177e4
LT
208#define TASK_RUNNING 0
209#define TASK_INTERRUPTIBLE 1
210#define TASK_UNINTERRUPTIBLE 2
f021a3c2
MW
211#define __TASK_STOPPED 4
212#define __TASK_TRACED 8
4a8342d2 213/* in tsk->exit_state */
ad86622b
ON
214#define EXIT_DEAD 16
215#define EXIT_ZOMBIE 32
abd50b39 216#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD)
4a8342d2 217/* in tsk->state again */
af927232 218#define TASK_DEAD 64
f021a3c2 219#define TASK_WAKEKILL 128
e9c84311 220#define TASK_WAKING 256
f2530dc7 221#define TASK_PARKED 512
80ed87c8
PZ
222#define TASK_NOLOAD 1024
223#define TASK_STATE_MAX 2048
f021a3c2 224
80ed87c8 225#define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWPN"
73342151 226
e1781538
PZ
227extern char ___assert_task_state[1 - 2*!!(
228 sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)];
f021a3c2
MW
229
230/* Convenience macros for the sake of set_task_state */
231#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
232#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
233#define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED)
1da177e4 234
80ed87c8
PZ
235#define TASK_IDLE (TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
236
92a1f4bc
MW
237/* Convenience macros for the sake of wake_up */
238#define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
f021a3c2 239#define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
92a1f4bc
MW
240
241/* get_task_state() */
242#define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \
f021a3c2 243 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
74e37200 244 __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD)
92a1f4bc 245
f021a3c2
MW
246#define task_is_traced(task) ((task->state & __TASK_TRACED) != 0)
247#define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0)
92a1f4bc 248#define task_is_stopped_or_traced(task) \
f021a3c2 249 ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
92a1f4bc 250#define task_contributes_to_load(task) \
e3c8ca83 251 ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
80ed87c8
PZ
252 (task->flags & PF_FROZEN) == 0 && \
253 (task->state & TASK_NOLOAD) == 0)
1da177e4 254
8eb23b9f
PZ
255#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
256
257#define __set_task_state(tsk, state_value) \
258 do { \
259 (tsk)->task_state_change = _THIS_IP_; \
260 (tsk)->state = (state_value); \
261 } while (0)
262#define set_task_state(tsk, state_value) \
263 do { \
264 (tsk)->task_state_change = _THIS_IP_; \
b92b8b35 265 smp_store_mb((tsk)->state, (state_value)); \
8eb23b9f
PZ
266 } while (0)
267
268/*
269 * set_current_state() includes a barrier so that the write of current->state
270 * is correctly serialised wrt the caller's subsequent test of whether to
271 * actually sleep:
272 *
273 * set_current_state(TASK_UNINTERRUPTIBLE);
274 * if (do_i_need_to_sleep())
275 * schedule();
276 *
277 * If the caller does not need such serialisation then use __set_current_state()
278 */
279#define __set_current_state(state_value) \
280 do { \
281 current->task_state_change = _THIS_IP_; \
282 current->state = (state_value); \
283 } while (0)
284#define set_current_state(state_value) \
285 do { \
286 current->task_state_change = _THIS_IP_; \
b92b8b35 287 smp_store_mb(current->state, (state_value)); \
8eb23b9f
PZ
288 } while (0)
289
290#else
291
1da177e4
LT
292#define __set_task_state(tsk, state_value) \
293 do { (tsk)->state = (state_value); } while (0)
294#define set_task_state(tsk, state_value) \
b92b8b35 295 smp_store_mb((tsk)->state, (state_value))
1da177e4 296
498d0c57
AM
297/*
298 * set_current_state() includes a barrier so that the write of current->state
299 * is correctly serialised wrt the caller's subsequent test of whether to
300 * actually sleep:
301 *
302 * set_current_state(TASK_UNINTERRUPTIBLE);
303 * if (do_i_need_to_sleep())
304 * schedule();
305 *
306 * If the caller does not need such serialisation then use __set_current_state()
307 */
8eb23b9f 308#define __set_current_state(state_value) \
1da177e4 309 do { current->state = (state_value); } while (0)
8eb23b9f 310#define set_current_state(state_value) \
b92b8b35 311 smp_store_mb(current->state, (state_value))
1da177e4 312
8eb23b9f
PZ
313#endif
314
1da177e4
LT
315/* Task command name length */
316#define TASK_COMM_LEN 16
317
1da177e4
LT
318#include <linux/spinlock.h>
319
320/*
321 * This serializes "schedule()" and also protects
322 * the run-queue from deletions/modifications (but
323 * _adding_ to the beginning of the run-queue has
324 * a separate lock).
325 */
326extern rwlock_t tasklist_lock;
327extern spinlock_t mmlist_lock;
328
36c8b586 329struct task_struct;
1da177e4 330
db1466b3
PM
331#ifdef CONFIG_PROVE_RCU
332extern int lockdep_tasklist_lock_is_held(void);
333#endif /* #ifdef CONFIG_PROVE_RCU */
334
1da177e4
LT
335extern void sched_init(void);
336extern void sched_init_smp(void);
2d07b255 337extern asmlinkage void schedule_tail(struct task_struct *prev);
36c8b586 338extern void init_idle(struct task_struct *idle, int cpu);
1df21055 339extern void init_idle_bootup_task(struct task_struct *idle);
1da177e4 340
3fa0818b
RR
341extern cpumask_var_t cpu_isolated_map;
342
89f19f04 343extern int runqueue_is_locked(int cpu);
017730c1 344
3451d024 345#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
c1cc017c 346extern void nohz_balance_enter_idle(int cpu);
69e1e811 347extern void set_cpu_sd_state_idle(void);
bc7a34b8 348extern int get_nohz_timer_target(void);
46cb4b7c 349#else
c1cc017c 350static inline void nohz_balance_enter_idle(int cpu) { }
fdaabd80 351static inline void set_cpu_sd_state_idle(void) { }
46cb4b7c 352#endif
1da177e4 353
e59e2ae2 354/*
39bc89fd 355 * Only dump TASK_* tasks. (0 for all tasks)
e59e2ae2
IM
356 */
357extern void show_state_filter(unsigned long state_filter);
358
359static inline void show_state(void)
360{
39bc89fd 361 show_state_filter(0);
e59e2ae2
IM
362}
363
1da177e4
LT
364extern void show_regs(struct pt_regs *);
365
366/*
367 * TASK is a pointer to the task whose backtrace we want to see (or NULL for current
368 * task), SP is the stack pointer of the first frame that should be shown in the back
369 * trace (or NULL if the entire call-chain of the task should be shown).
370 */
371extern void show_stack(struct task_struct *task, unsigned long *sp);
372
1da177e4
LT
373extern void cpu_init (void);
374extern void trap_init(void);
375extern void update_process_times(int user);
376extern void scheduler_tick(void);
377
82a1fcb9
IM
378extern void sched_show_task(struct task_struct *p);
379
19cc36c0 380#ifdef CONFIG_LOCKUP_DETECTOR
03e0d461 381extern void touch_softlockup_watchdog_sched(void);
8446f1d3 382extern void touch_softlockup_watchdog(void);
d6ad3e28 383extern void touch_softlockup_watchdog_sync(void);
04c9167f 384extern void touch_all_softlockup_watchdogs(void);
332fbdbc
DZ
385extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
386 void __user *buffer,
387 size_t *lenp, loff_t *ppos);
9c44bc03 388extern unsigned int softlockup_panic;
ac1f5912 389extern unsigned int hardlockup_panic;
004417a6 390void lockup_detector_init(void);
8446f1d3 391#else
03e0d461
TH
392static inline void touch_softlockup_watchdog_sched(void)
393{
394}
8446f1d3
IM
395static inline void touch_softlockup_watchdog(void)
396{
397}
d6ad3e28
JW
398static inline void touch_softlockup_watchdog_sync(void)
399{
400}
04c9167f
JF
401static inline void touch_all_softlockup_watchdogs(void)
402{
403}
004417a6
PZ
404static inline void lockup_detector_init(void)
405{
406}
8446f1d3
IM
407#endif
408
8b414521
MT
409#ifdef CONFIG_DETECT_HUNG_TASK
410void reset_hung_task_detector(void);
411#else
412static inline void reset_hung_task_detector(void)
413{
414}
415#endif
416
1da177e4
LT
417/* Attach to any functions which should be ignored in wchan output. */
418#define __sched __attribute__((__section__(".sched.text")))
deaf2227
IM
419
420/* Linker adds these: start and end of __sched functions */
421extern char __sched_text_start[], __sched_text_end[];
422
1da177e4
LT
423/* Is this address in the __sched functions? */
424extern int in_sched_functions(unsigned long addr);
425
426#define MAX_SCHEDULE_TIMEOUT LONG_MAX
b3c97528 427extern signed long schedule_timeout(signed long timeout);
64ed93a2 428extern signed long schedule_timeout_interruptible(signed long timeout);
294d5cc2 429extern signed long schedule_timeout_killable(signed long timeout);
64ed93a2 430extern signed long schedule_timeout_uninterruptible(signed long timeout);
69b27baf 431extern signed long schedule_timeout_idle(signed long timeout);
1da177e4 432asmlinkage void schedule(void);
c5491ea7 433extern void schedule_preempt_disabled(void);
1da177e4 434
9cff8ade
N
435extern long io_schedule_timeout(long timeout);
436
437static inline void io_schedule(void)
438{
439 io_schedule_timeout(MAX_SCHEDULE_TIMEOUT);
440}
441
ab516013 442struct nsproxy;
acce292c 443struct user_namespace;
1da177e4 444
efc1a3b1
DH
445#ifdef CONFIG_MMU
446extern void arch_pick_mmap_layout(struct mm_struct *mm);
1da177e4
LT
447extern unsigned long
448arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
449 unsigned long, unsigned long);
450extern unsigned long
451arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
452 unsigned long len, unsigned long pgoff,
453 unsigned long flags);
efc1a3b1
DH
454#else
455static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
456#endif
1da177e4 457
d049f74f
KC
458#define SUID_DUMP_DISABLE 0 /* No setuid dumping */
459#define SUID_DUMP_USER 1 /* Dump as user of process */
460#define SUID_DUMP_ROOT 2 /* Dump as root */
461
6c5d5238 462/* mm flags */
f8af4da3 463
7288e118 464/* for SUID_DUMP_* above */
3cb4a0bb 465#define MMF_DUMPABLE_BITS 2
f8af4da3 466#define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1)
3cb4a0bb 467
942be387
ON
468extern void set_dumpable(struct mm_struct *mm, int value);
469/*
470 * This returns the actual value of the suid_dumpable flag. For things
471 * that are using this for checking for privilege transitions, it must
472 * test against SUID_DUMP_USER rather than treating it as a boolean
473 * value.
474 */
475static inline int __get_dumpable(unsigned long mm_flags)
476{
477 return mm_flags & MMF_DUMPABLE_MASK;
478}
479
480static inline int get_dumpable(struct mm_struct *mm)
481{
482 return __get_dumpable(mm->flags);
483}
484
3cb4a0bb
KH
485/* coredump filter bits */
486#define MMF_DUMP_ANON_PRIVATE 2
487#define MMF_DUMP_ANON_SHARED 3
488#define MMF_DUMP_MAPPED_PRIVATE 4
489#define MMF_DUMP_MAPPED_SHARED 5
82df3973 490#define MMF_DUMP_ELF_HEADERS 6
e575f111
KM
491#define MMF_DUMP_HUGETLB_PRIVATE 7
492#define MMF_DUMP_HUGETLB_SHARED 8
5037835c
RZ
493#define MMF_DUMP_DAX_PRIVATE 9
494#define MMF_DUMP_DAX_SHARED 10
f8af4da3 495
3cb4a0bb 496#define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS
5037835c 497#define MMF_DUMP_FILTER_BITS 9
3cb4a0bb
KH
498#define MMF_DUMP_FILTER_MASK \
499 (((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
500#define MMF_DUMP_FILTER_DEFAULT \
e575f111 501 ((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED) |\
656eb2cd
RM
502 (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
503
504#ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
505# define MMF_DUMP_MASK_DEFAULT_ELF (1 << MMF_DUMP_ELF_HEADERS)
506#else
507# define MMF_DUMP_MASK_DEFAULT_ELF 0
508#endif
f8af4da3
HD
509 /* leave room for more dump flags */
510#define MMF_VM_MERGEABLE 16 /* KSM may merge identical pages */
ba76149f 511#define MMF_VM_HUGEPAGE 17 /* set when VM_HUGEPAGE is set on vma */
bafb282d 512#define MMF_EXE_FILE_CHANGED 18 /* see prctl_set_mm_exe_file() */
f8af4da3 513
9f68f672
ON
514#define MMF_HAS_UPROBES 19 /* has uprobes */
515#define MMF_RECALC_UPROBES 20 /* MMF_HAS_UPROBES can be wrong */
f8ac4ec9 516
f8af4da3 517#define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK)
6c5d5238 518
1da177e4
LT
519struct sighand_struct {
520 atomic_t count;
521 struct k_sigaction action[_NSIG];
522 spinlock_t siglock;
b8fceee1 523 wait_queue_head_t signalfd_wqh;
1da177e4
LT
524};
525
0e464814 526struct pacct_struct {
f6ec29a4
KK
527 int ac_flag;
528 long ac_exitcode;
0e464814 529 unsigned long ac_mem;
77787bfb
KK
530 cputime_t ac_utime, ac_stime;
531 unsigned long ac_minflt, ac_majflt;
0e464814
KK
532};
533
42c4ab41
SG
534struct cpu_itimer {
535 cputime_t expires;
536 cputime_t incr;
8356b5f9
SG
537 u32 error;
538 u32 incr_error;
42c4ab41
SG
539};
540
d37f761d 541/**
9d7fb042 542 * struct prev_cputime - snaphsot of system and user cputime
d37f761d
FW
543 * @utime: time spent in user mode
544 * @stime: time spent in system mode
9d7fb042 545 * @lock: protects the above two fields
d37f761d 546 *
9d7fb042
PZ
547 * Stores previous user/system time values such that we can guarantee
548 * monotonicity.
d37f761d 549 */
9d7fb042
PZ
550struct prev_cputime {
551#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
d37f761d
FW
552 cputime_t utime;
553 cputime_t stime;
9d7fb042
PZ
554 raw_spinlock_t lock;
555#endif
d37f761d
FW
556};
557
9d7fb042
PZ
558static inline void prev_cputime_init(struct prev_cputime *prev)
559{
560#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
561 prev->utime = prev->stime = 0;
562 raw_spin_lock_init(&prev->lock);
563#endif
564}
565
f06febc9
FM
566/**
567 * struct task_cputime - collected CPU time counts
568 * @utime: time spent in user mode, in &cputime_t units
569 * @stime: time spent in kernel mode, in &cputime_t units
570 * @sum_exec_runtime: total time spent on the CPU, in nanoseconds
5ce73a4a 571 *
9d7fb042
PZ
572 * This structure groups together three kinds of CPU time that are tracked for
573 * threads and thread groups. Most things considering CPU time want to group
574 * these counts together and treat all three of them in parallel.
f06febc9
FM
575 */
576struct task_cputime {
577 cputime_t utime;
578 cputime_t stime;
579 unsigned long long sum_exec_runtime;
580};
9d7fb042 581
f06febc9 582/* Alternate field names when used to cache expirations. */
f06febc9 583#define virt_exp utime
9d7fb042 584#define prof_exp stime
f06febc9
FM
585#define sched_exp sum_exec_runtime
586
4cd4c1b4
PZ
587#define INIT_CPUTIME \
588 (struct task_cputime) { \
64861634
MS
589 .utime = 0, \
590 .stime = 0, \
4cd4c1b4
PZ
591 .sum_exec_runtime = 0, \
592 }
593
971e8a98
JL
594/*
595 * This is the atomic variant of task_cputime, which can be used for
596 * storing and updating task_cputime statistics without locking.
597 */
598struct task_cputime_atomic {
599 atomic64_t utime;
600 atomic64_t stime;
601 atomic64_t sum_exec_runtime;
602};
603
604#define INIT_CPUTIME_ATOMIC \
605 (struct task_cputime_atomic) { \
606 .utime = ATOMIC64_INIT(0), \
607 .stime = ATOMIC64_INIT(0), \
608 .sum_exec_runtime = ATOMIC64_INIT(0), \
609 }
610
609ca066 611#define PREEMPT_DISABLED (PREEMPT_DISABLE_OFFSET + PREEMPT_ENABLED)
a233f112 612
c99e6efe 613/*
87dcbc06
PZ
614 * Disable preemption until the scheduler is running -- use an unconditional
615 * value so that it also works on !PREEMPT_COUNT kernels.
d86ee480 616 *
87dcbc06 617 * Reset by start_kernel()->sched_init()->init_idle()->init_idle_preempt_count().
c99e6efe 618 */
87dcbc06 619#define INIT_PREEMPT_COUNT PREEMPT_OFFSET
a233f112 620
c99e6efe 621/*
609ca066
PZ
622 * Initial preempt_count value; reflects the preempt_count schedule invariant
623 * which states that during context switches:
d86ee480 624 *
609ca066
PZ
625 * preempt_count() == 2*PREEMPT_DISABLE_OFFSET
626 *
627 * Note: PREEMPT_DISABLE_OFFSET is 0 for !PREEMPT_COUNT kernels.
628 * Note: See finish_task_switch().
c99e6efe 629 */
609ca066 630#define FORK_PREEMPT_COUNT (2*PREEMPT_DISABLE_OFFSET + PREEMPT_ENABLED)
c99e6efe 631
f06febc9 632/**
4cd4c1b4 633 * struct thread_group_cputimer - thread group interval timer counts
920ce39f 634 * @cputime_atomic: atomic thread group interval timers.
d5c373eb
JL
635 * @running: true when there are timers running and
636 * @cputime_atomic receives updates.
c8d75aa4
JL
637 * @checking_timer: true when a thread in the group is in the
638 * process of checking for thread group timers.
f06febc9
FM
639 *
640 * This structure contains the version of task_cputime, above, that is
4cd4c1b4 641 * used for thread group CPU timer calculations.
f06febc9 642 */
4cd4c1b4 643struct thread_group_cputimer {
71107445 644 struct task_cputime_atomic cputime_atomic;
d5c373eb 645 bool running;
c8d75aa4 646 bool checking_timer;
f06febc9 647};
f06febc9 648
4714d1d3 649#include <linux/rwsem.h>
5091faa4
MG
650struct autogroup;
651
1da177e4 652/*
e815f0a8 653 * NOTE! "signal_struct" does not have its own
1da177e4
LT
654 * locking, because a shared signal_struct always
655 * implies a shared sighand_struct, so locking
656 * sighand_struct is always a proper superset of
657 * the locking of signal_struct.
658 */
659struct signal_struct {
ea6d290c 660 atomic_t sigcnt;
1da177e4 661 atomic_t live;
b3ac022c 662 int nr_threads;
0c740d0a 663 struct list_head thread_head;
1da177e4
LT
664
665 wait_queue_head_t wait_chldexit; /* for wait4() */
666
667 /* current thread group signal load-balancing target: */
36c8b586 668 struct task_struct *curr_target;
1da177e4
LT
669
670 /* shared signal handling: */
671 struct sigpending shared_pending;
672
673 /* thread group exit support */
674 int group_exit_code;
675 /* overloaded:
676 * - notify group_exit_task when ->count is equal to notify_count
677 * - everyone except group_exit_task is stopped during signal delivery
678 * of fatal signals, group_exit_task processes the signal.
679 */
1da177e4 680 int notify_count;
07dd20e0 681 struct task_struct *group_exit_task;
1da177e4
LT
682
683 /* thread group stop support, overloads group_exit_code too */
684 int group_stop_count;
685 unsigned int flags; /* see SIGNAL_* flags below */
686
ebec18a6
LP
687 /*
688 * PR_SET_CHILD_SUBREAPER marks a process, like a service
689 * manager, to re-parent orphan (double-forking) child processes
690 * to this process instead of 'init'. The service manager is
691 * able to receive SIGCHLD signals and is able to investigate
692 * the process until it calls wait(). All children of this
693 * process will inherit a flag if they should look for a
694 * child_subreaper process at exit.
695 */
696 unsigned int is_child_subreaper:1;
697 unsigned int has_child_subreaper:1;
698
1da177e4 699 /* POSIX.1b Interval Timers */
5ed67f05
PE
700 int posix_timer_id;
701 struct list_head posix_timers;
1da177e4
LT
702
703 /* ITIMER_REAL timer for the process */
2ff678b8 704 struct hrtimer real_timer;
fea9d175 705 struct pid *leader_pid;
2ff678b8 706 ktime_t it_real_incr;
1da177e4 707
42c4ab41
SG
708 /*
709 * ITIMER_PROF and ITIMER_VIRTUAL timers for the process, we use
710 * CPUCLOCK_PROF and CPUCLOCK_VIRT for indexing array as these
711 * values are defined to 0 and 1 respectively
712 */
713 struct cpu_itimer it[2];
1da177e4 714
f06febc9 715 /*
4cd4c1b4
PZ
716 * Thread group totals for process CPU timers.
717 * See thread_group_cputimer(), et al, for details.
f06febc9 718 */
4cd4c1b4 719 struct thread_group_cputimer cputimer;
f06febc9
FM
720
721 /* Earliest-expiration cache. */
722 struct task_cputime cputime_expires;
723
d027d45d 724#ifdef CONFIG_NO_HZ_FULL
f009a7a7 725 atomic_t tick_dep_mask;
d027d45d
FW
726#endif
727
f06febc9
FM
728 struct list_head cpu_timers[3];
729
ab521dc0 730 struct pid *tty_old_pgrp;
1ec320af 731
1da177e4
LT
732 /* boolean value for session group leader */
733 int leader;
734
735 struct tty_struct *tty; /* NULL if no tty */
736
5091faa4
MG
737#ifdef CONFIG_SCHED_AUTOGROUP
738 struct autogroup *autogroup;
739#endif
1da177e4
LT
740 /*
741 * Cumulative resource counters for dead threads in the group,
742 * and for reaped dead child processes forked by this group.
743 * Live threads maintain their own counters and add to these
744 * in __exit_signal, except for the group leader.
745 */
e78c3496 746 seqlock_t stats_lock;
32bd671d 747 cputime_t utime, stime, cutime, cstime;
9ac52315
LV
748 cputime_t gtime;
749 cputime_t cgtime;
9d7fb042 750 struct prev_cputime prev_cputime;
1da177e4
LT
751 unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
752 unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
6eaeeaba 753 unsigned long inblock, oublock, cinblock, coublock;
1f10206c 754 unsigned long maxrss, cmaxrss;
940389b8 755 struct task_io_accounting ioac;
1da177e4 756
32bd671d
PZ
757 /*
758 * Cumulative ns of schedule CPU time fo dead threads in the
759 * group, not including a zombie group leader, (This only differs
760 * from jiffies_to_ns(utime + stime) if sched_clock uses something
761 * other than jiffies.)
762 */
763 unsigned long long sum_sched_runtime;
764
1da177e4
LT
765 /*
766 * We don't bother to synchronize most readers of this at all,
767 * because there is no reader checking a limit that actually needs
768 * to get both rlim_cur and rlim_max atomically, and either one
769 * alone is a single word that can safely be read normally.
770 * getrlimit/setrlimit use task_lock(current->group_leader) to
771 * protect this instead of the siglock, because they really
772 * have no need to disable irqs.
773 */
774 struct rlimit rlim[RLIM_NLIMITS];
775
0e464814
KK
776#ifdef CONFIG_BSD_PROCESS_ACCT
777 struct pacct_struct pacct; /* per-process accounting information */
778#endif
ad4ecbcb 779#ifdef CONFIG_TASKSTATS
ad4ecbcb
SN
780 struct taskstats *stats;
781#endif
522ed776
MT
782#ifdef CONFIG_AUDIT
783 unsigned audit_tty;
784 struct tty_audit_buf *tty_audit_buf;
785#endif
28b83c51 786
e1e12d2f 787 oom_flags_t oom_flags;
a9c58b90
DR
788 short oom_score_adj; /* OOM kill score adjustment */
789 short oom_score_adj_min; /* OOM kill score adjustment min value.
790 * Only settable by CAP_SYS_RESOURCE. */
9b1bf12d
KM
791
792 struct mutex cred_guard_mutex; /* guard against foreign influences on
793 * credential calculations
794 * (notably. ptrace) */
1da177e4
LT
795};
796
797/*
798 * Bits in flags field of signal_struct.
799 */
800#define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */
ee77f075
ON
801#define SIGNAL_STOP_CONTINUED 0x00000002 /* SIGCONT since WCONTINUED reap */
802#define SIGNAL_GROUP_EXIT 0x00000004 /* group exit in progress */
403bad72 803#define SIGNAL_GROUP_COREDUMP 0x00000008 /* coredump in progress */
e4420551
ON
804/*
805 * Pending notifications to parent.
806 */
807#define SIGNAL_CLD_STOPPED 0x00000010
808#define SIGNAL_CLD_CONTINUED 0x00000020
809#define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
1da177e4 810
fae5fa44
ON
811#define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */
812
ed5d2cac
ON
813/* If true, all threads except ->group_exit_task have pending SIGKILL */
814static inline int signal_group_exit(const struct signal_struct *sig)
815{
816 return (sig->flags & SIGNAL_GROUP_EXIT) ||
817 (sig->group_exit_task != NULL);
818}
819
1da177e4
LT
820/*
821 * Some day this will be a full-fledged user tracking system..
822 */
823struct user_struct {
824 atomic_t __count; /* reference count */
825 atomic_t processes; /* How many processes does this user have? */
1da177e4 826 atomic_t sigpending; /* How many pending signals does this user have? */
2d9048e2 827#ifdef CONFIG_INOTIFY_USER
0eeca283
RL
828 atomic_t inotify_watches; /* How many inotify watches does this user have? */
829 atomic_t inotify_devs; /* How many inotify devs does this user have opened? */
830#endif
4afeff85
EP
831#ifdef CONFIG_FANOTIFY
832 atomic_t fanotify_listeners;
833#endif
7ef9964e 834#ifdef CONFIG_EPOLL
52bd19f7 835 atomic_long_t epoll_watches; /* The number of file descriptors currently watched */
7ef9964e 836#endif
970a8645 837#ifdef CONFIG_POSIX_MQUEUE
1da177e4
LT
838 /* protected by mq_lock */
839 unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */
970a8645 840#endif
1da177e4 841 unsigned long locked_shm; /* How many pages of mlocked shm ? */
712f4aad 842 unsigned long unix_inflight; /* How many files in flight in unix sockets */
759c0114 843 atomic_long_t pipe_bufs; /* how many pages are allocated in pipe buffers */
1da177e4
LT
844
845#ifdef CONFIG_KEYS
846 struct key *uid_keyring; /* UID specific keyring */
847 struct key *session_keyring; /* UID's default session keyring */
848#endif
849
850 /* Hash table maintenance information */
735de223 851 struct hlist_node uidhash_node;
7b44ab97 852 kuid_t uid;
24e377a8 853
aaac3ba9 854#if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL)
789f90fc
PZ
855 atomic_long_t locked_vm;
856#endif
1da177e4
LT
857};
858
eb41d946 859extern int uids_sysfs_init(void);
5cb350ba 860
7b44ab97 861extern struct user_struct *find_user(kuid_t);
1da177e4
LT
862
863extern struct user_struct root_user;
864#define INIT_USER (&root_user)
865
b6dff3ec 866
1da177e4
LT
867struct backing_dev_info;
868struct reclaim_state;
869
f6db8347 870#ifdef CONFIG_SCHED_INFO
1da177e4
LT
871struct sched_info {
872 /* cumulative counters */
2d72376b 873 unsigned long pcount; /* # of times run on this cpu */
9c2c4802 874 unsigned long long run_delay; /* time spent waiting on a runqueue */
1da177e4
LT
875
876 /* timestamps */
172ba844
BS
877 unsigned long long last_arrival,/* when we last ran on a cpu */
878 last_queued; /* when we were last queued to run */
1da177e4 879};
f6db8347 880#endif /* CONFIG_SCHED_INFO */
1da177e4 881
ca74e92b
SN
882#ifdef CONFIG_TASK_DELAY_ACCT
883struct task_delay_info {
884 spinlock_t lock;
885 unsigned int flags; /* Private per-task flags */
886
887 /* For each stat XXX, add following, aligned appropriately
888 *
889 * struct timespec XXX_start, XXX_end;
890 * u64 XXX_delay;
891 * u32 XXX_count;
892 *
893 * Atomicity of updates to XXX_delay, XXX_count protected by
894 * single lock above (split into XXX_lock if contention is an issue).
895 */
0ff92245
SN
896
897 /*
898 * XXX_count is incremented on every XXX operation, the delay
899 * associated with the operation is added to XXX_delay.
900 * XXX_delay contains the accumulated delay time in nanoseconds.
901 */
9667a23d 902 u64 blkio_start; /* Shared by blkio, swapin */
0ff92245
SN
903 u64 blkio_delay; /* wait for sync block io completion */
904 u64 swapin_delay; /* wait for swapin block io completion */
905 u32 blkio_count; /* total count of the number of sync block */
906 /* io operations performed */
907 u32 swapin_count; /* total count of the number of swapin block */
908 /* io operations performed */
873b4771 909
9667a23d 910 u64 freepages_start;
873b4771
KK
911 u64 freepages_delay; /* wait for memory reclaim */
912 u32 freepages_count; /* total count of memory reclaim */
ca74e92b 913};
52f17b6c
CS
914#endif /* CONFIG_TASK_DELAY_ACCT */
915
916static inline int sched_info_on(void)
917{
918#ifdef CONFIG_SCHEDSTATS
919 return 1;
920#elif defined(CONFIG_TASK_DELAY_ACCT)
921 extern int delayacct_on;
922 return delayacct_on;
923#else
924 return 0;
ca74e92b 925#endif
52f17b6c 926}
ca74e92b 927
cb251765
MG
928#ifdef CONFIG_SCHEDSTATS
929void force_schedstat_enabled(void);
930#endif
931
d15bcfdb
IM
932enum cpu_idle_type {
933 CPU_IDLE,
934 CPU_NOT_IDLE,
935 CPU_NEWLY_IDLE,
936 CPU_MAX_IDLE_TYPES
1da177e4
LT
937};
938
6ecdd749
YD
939/*
940 * Integer metrics need fixed point arithmetic, e.g., sched/fair
941 * has a few: load, load_avg, util_avg, freq, and capacity.
942 *
943 * We define a basic fixed point arithmetic range, and then formalize
944 * all these metrics based on that basic range.
945 */
946# define SCHED_FIXEDPOINT_SHIFT 10
947# define SCHED_FIXEDPOINT_SCALE (1L << SCHED_FIXEDPOINT_SHIFT)
948
1399fa78 949/*
ca8ce3d0 950 * Increase resolution of cpu_capacity calculations
1399fa78 951 */
6ecdd749 952#define SCHED_CAPACITY_SHIFT SCHED_FIXEDPOINT_SHIFT
ca8ce3d0 953#define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT)
1da177e4 954
76751049
PZ
955/*
956 * Wake-queues are lists of tasks with a pending wakeup, whose
957 * callers have already marked the task as woken internally,
958 * and can thus carry on. A common use case is being able to
959 * do the wakeups once the corresponding user lock as been
960 * released.
961 *
962 * We hold reference to each task in the list across the wakeup,
963 * thus guaranteeing that the memory is still valid by the time
964 * the actual wakeups are performed in wake_up_q().
965 *
966 * One per task suffices, because there's never a need for a task to be
967 * in two wake queues simultaneously; it is forbidden to abandon a task
968 * in a wake queue (a call to wake_up_q() _must_ follow), so if a task is
969 * already in a wake queue, the wakeup will happen soon and the second
970 * waker can just skip it.
971 *
972 * The WAKE_Q macro declares and initializes the list head.
973 * wake_up_q() does NOT reinitialize the list; it's expected to be
974 * called near the end of a function, where the fact that the queue is
975 * not used again will be easy to see by inspection.
976 *
977 * Note that this can cause spurious wakeups. schedule() callers
978 * must ensure the call is done inside a loop, confirming that the
979 * wakeup condition has in fact occurred.
980 */
981struct wake_q_node {
982 struct wake_q_node *next;
983};
984
985struct wake_q_head {
986 struct wake_q_node *first;
987 struct wake_q_node **lastp;
988};
989
990#define WAKE_Q_TAIL ((struct wake_q_node *) 0x01)
991
992#define WAKE_Q(name) \
993 struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
994
995extern void wake_q_add(struct wake_q_head *head,
996 struct task_struct *task);
997extern void wake_up_q(struct wake_q_head *head);
998
1399fa78
NR
999/*
1000 * sched-domains (multiprocessor balancing) declarations:
1001 */
2dd73a4f 1002#ifdef CONFIG_SMP
b5d978e0
PZ
1003#define SD_LOAD_BALANCE 0x0001 /* Do load balancing on this domain. */
1004#define SD_BALANCE_NEWIDLE 0x0002 /* Balance when about to become idle */
1005#define SD_BALANCE_EXEC 0x0004 /* Balance on exec */
1006#define SD_BALANCE_FORK 0x0008 /* Balance on fork, clone */
c88d5910 1007#define SD_BALANCE_WAKE 0x0010 /* Balance on wakeup */
b5d978e0 1008#define SD_WAKE_AFFINE 0x0020 /* Wake task to waking CPU */
5d4dfddd 1009#define SD_SHARE_CPUCAPACITY 0x0080 /* Domain members share cpu power */
d77b3ed5 1010#define SD_SHARE_POWERDOMAIN 0x0100 /* Domain members share power domain */
b5d978e0
PZ
1011#define SD_SHARE_PKG_RESOURCES 0x0200 /* Domain members share cpu pkg resources */
1012#define SD_SERIALIZE 0x0400 /* Only a single load balancing instance */
532cb4c4 1013#define SD_ASYM_PACKING 0x0800 /* Place busy groups earlier in the domain */
b5d978e0 1014#define SD_PREFER_SIBLING 0x1000 /* Prefer to place tasks in a sibling domain */
e3589f6c 1015#define SD_OVERLAP 0x2000 /* sched_domains of this level overlap */
3a7053b3 1016#define SD_NUMA 0x4000 /* cross-node balancing */
5c45bf27 1017
143e1e28 1018#ifdef CONFIG_SCHED_SMT
b6220ad6 1019static inline int cpu_smt_flags(void)
143e1e28 1020{
5d4dfddd 1021 return SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
143e1e28
VG
1022}
1023#endif
1024
1025#ifdef CONFIG_SCHED_MC
b6220ad6 1026static inline int cpu_core_flags(void)
143e1e28
VG
1027{
1028 return SD_SHARE_PKG_RESOURCES;
1029}
1030#endif
1031
1032#ifdef CONFIG_NUMA
b6220ad6 1033static inline int cpu_numa_flags(void)
143e1e28
VG
1034{
1035 return SD_NUMA;
1036}
1037#endif
532cb4c4 1038
1d3504fc
HS
1039struct sched_domain_attr {
1040 int relax_domain_level;
1041};
1042
1043#define SD_ATTR_INIT (struct sched_domain_attr) { \
1044 .relax_domain_level = -1, \
1045}
1046
60495e77
PZ
1047extern int sched_domain_level_max;
1048
5e6521ea
LZ
1049struct sched_group;
1050
1da177e4
LT
1051struct sched_domain {
1052 /* These fields must be setup */
1053 struct sched_domain *parent; /* top domain must be null terminated */
1a848870 1054 struct sched_domain *child; /* bottom domain must be null terminated */
1da177e4 1055 struct sched_group *groups; /* the balancing groups of the domain */
1da177e4
LT
1056 unsigned long min_interval; /* Minimum balance interval ms */
1057 unsigned long max_interval; /* Maximum balance interval ms */
1058 unsigned int busy_factor; /* less balancing by factor if busy */
1059 unsigned int imbalance_pct; /* No balance until over watermark */
1da177e4 1060 unsigned int cache_nice_tries; /* Leave cache hot tasks for # tries */
7897986b
NP
1061 unsigned int busy_idx;
1062 unsigned int idle_idx;
1063 unsigned int newidle_idx;
1064 unsigned int wake_idx;
147cbb4b 1065 unsigned int forkexec_idx;
a52bfd73 1066 unsigned int smt_gain;
25f55d9d
VG
1067
1068 int nohz_idle; /* NOHZ IDLE status */
1da177e4 1069 int flags; /* See SD_* */
60495e77 1070 int level;
1da177e4
LT
1071
1072 /* Runtime fields. */
1073 unsigned long last_balance; /* init to jiffies. units in jiffies */
1074 unsigned int balance_interval; /* initialise to 1. units in ms. */
1075 unsigned int nr_balance_failed; /* initialise to 0 */
1076
f48627e6 1077 /* idle_balance() stats */
9bd721c5 1078 u64 max_newidle_lb_cost;
f48627e6 1079 unsigned long next_decay_max_lb_cost;
2398f2c6 1080
1da177e4
LT
1081#ifdef CONFIG_SCHEDSTATS
1082 /* load_balance() stats */
480b9434
KC
1083 unsigned int lb_count[CPU_MAX_IDLE_TYPES];
1084 unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
1085 unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
1086 unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
1087 unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
1088 unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
1089 unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
1090 unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
1da177e4
LT
1091
1092 /* Active load balancing */
480b9434
KC
1093 unsigned int alb_count;
1094 unsigned int alb_failed;
1095 unsigned int alb_pushed;
1da177e4 1096
68767a0a 1097 /* SD_BALANCE_EXEC stats */
480b9434
KC
1098 unsigned int sbe_count;
1099 unsigned int sbe_balanced;
1100 unsigned int sbe_pushed;
1da177e4 1101
68767a0a 1102 /* SD_BALANCE_FORK stats */
480b9434
KC
1103 unsigned int sbf_count;
1104 unsigned int sbf_balanced;
1105 unsigned int sbf_pushed;
68767a0a 1106
1da177e4 1107 /* try_to_wake_up() stats */
480b9434
KC
1108 unsigned int ttwu_wake_remote;
1109 unsigned int ttwu_move_affine;
1110 unsigned int ttwu_move_balance;
1da177e4 1111#endif
a5d8c348
IM
1112#ifdef CONFIG_SCHED_DEBUG
1113 char *name;
1114#endif
dce840a0
PZ
1115 union {
1116 void *private; /* used during construction */
1117 struct rcu_head rcu; /* used during destruction */
1118 };
6c99e9ad 1119
669c55e9 1120 unsigned int span_weight;
4200efd9
IM
1121 /*
1122 * Span of all CPUs in this domain.
1123 *
1124 * NOTE: this field is variable length. (Allocated dynamically
1125 * by attaching extra space to the end of the structure,
1126 * depending on how many CPUs the kernel has booted up with)
4200efd9
IM
1127 */
1128 unsigned long span[0];
1da177e4
LT
1129};
1130
758b2cdc
RR
1131static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
1132{
6c99e9ad 1133 return to_cpumask(sd->span);
758b2cdc
RR
1134}
1135
acc3f5d7 1136extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
1d3504fc 1137 struct sched_domain_attr *dattr_new);
029190c5 1138
acc3f5d7
RR
1139/* Allocate an array of sched domains, for partition_sched_domains(). */
1140cpumask_var_t *alloc_sched_domains(unsigned int ndoms);
1141void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms);
1142
39be3501
PZ
1143bool cpus_share_cache(int this_cpu, int that_cpu);
1144
143e1e28 1145typedef const struct cpumask *(*sched_domain_mask_f)(int cpu);
b6220ad6 1146typedef int (*sched_domain_flags_f)(void);
143e1e28
VG
1147
1148#define SDTL_OVERLAP 0x01
1149
1150struct sd_data {
1151 struct sched_domain **__percpu sd;
1152 struct sched_group **__percpu sg;
63b2ca30 1153 struct sched_group_capacity **__percpu sgc;
143e1e28
VG
1154};
1155
1156struct sched_domain_topology_level {
1157 sched_domain_mask_f mask;
1158 sched_domain_flags_f sd_flags;
1159 int flags;
1160 int numa_level;
1161 struct sd_data data;
1162#ifdef CONFIG_SCHED_DEBUG
1163 char *name;
1164#endif
1165};
1166
143e1e28 1167extern void set_sched_topology(struct sched_domain_topology_level *tl);
f6be8af1 1168extern void wake_up_if_idle(int cpu);
143e1e28
VG
1169
1170#ifdef CONFIG_SCHED_DEBUG
1171# define SD_INIT_NAME(type) .name = #type
1172#else
1173# define SD_INIT_NAME(type)
1174#endif
1175
1b427c15 1176#else /* CONFIG_SMP */
1da177e4 1177
1b427c15 1178struct sched_domain_attr;
d02c7a8c 1179
1b427c15 1180static inline void
acc3f5d7 1181partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
1b427c15
IM
1182 struct sched_domain_attr *dattr_new)
1183{
d02c7a8c 1184}
39be3501
PZ
1185
1186static inline bool cpus_share_cache(int this_cpu, int that_cpu)
1187{
1188 return true;
1189}
1190
1b427c15 1191#endif /* !CONFIG_SMP */
1da177e4 1192
47fe38fc 1193
1da177e4 1194struct io_context; /* See blkdev.h */
1da177e4 1195
1da177e4 1196
383f2835 1197#ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
36c8b586 1198extern void prefetch_stack(struct task_struct *t);
383f2835
CK
1199#else
1200static inline void prefetch_stack(struct task_struct *t) { }
1201#endif
1da177e4
LT
1202
1203struct audit_context; /* See audit.c */
1204struct mempolicy;
b92ce558 1205struct pipe_inode_info;
4865ecf1 1206struct uts_namespace;
1da177e4 1207
20b8a59f 1208struct load_weight {
9dbdb155
PZ
1209 unsigned long weight;
1210 u32 inv_weight;
20b8a59f
IM
1211};
1212
9d89c257
YD
1213/*
1214 * The load_avg/util_avg accumulates an infinite geometric series.
e0f5f3af
DE
1215 * 1) load_avg factors frequency scaling into the amount of time that a
1216 * sched_entity is runnable on a rq into its weight. For cfs_rq, it is the
1217 * aggregated such weights of all runnable and blocked sched_entities.
6ecdd749
YD
1218 * 2) util_avg factors frequency and cpu capacity scaling into the amount of time
1219 * that a sched_entity is running on a CPU, in the range [0..SCHED_CAPACITY_SCALE].
9d89c257
YD
1220 * For cfs_rq, it is the aggregated such times of all runnable and
1221 * blocked sched_entities.
1222 * The 64 bit load_sum can:
1223 * 1) for cfs_rq, afford 4353082796 (=2^64/47742/88761) entities with
1224 * the highest weight (=88761) always runnable, we should not overflow
1225 * 2) for entity, support any load.weight always runnable
1226 */
9d85f21c 1227struct sched_avg {
9d89c257
YD
1228 u64 last_update_time, load_sum;
1229 u32 util_sum, period_contrib;
1230 unsigned long load_avg, util_avg;
9d85f21c
PT
1231};
1232
94c18227 1233#ifdef CONFIG_SCHEDSTATS
41acab88 1234struct sched_statistics {
20b8a59f 1235 u64 wait_start;
94c18227 1236 u64 wait_max;
6d082592
AV
1237 u64 wait_count;
1238 u64 wait_sum;
8f0dfc34
AV
1239 u64 iowait_count;
1240 u64 iowait_sum;
94c18227 1241
20b8a59f 1242 u64 sleep_start;
20b8a59f 1243 u64 sleep_max;
94c18227
IM
1244 s64 sum_sleep_runtime;
1245
1246 u64 block_start;
20b8a59f
IM
1247 u64 block_max;
1248 u64 exec_max;
eba1ed4b 1249 u64 slice_max;
cc367732 1250
cc367732
IM
1251 u64 nr_migrations_cold;
1252 u64 nr_failed_migrations_affine;
1253 u64 nr_failed_migrations_running;
1254 u64 nr_failed_migrations_hot;
1255 u64 nr_forced_migrations;
cc367732
IM
1256
1257 u64 nr_wakeups;
1258 u64 nr_wakeups_sync;
1259 u64 nr_wakeups_migrate;
1260 u64 nr_wakeups_local;
1261 u64 nr_wakeups_remote;
1262 u64 nr_wakeups_affine;
1263 u64 nr_wakeups_affine_attempts;
1264 u64 nr_wakeups_passive;
1265 u64 nr_wakeups_idle;
41acab88
LDM
1266};
1267#endif
1268
1269struct sched_entity {
1270 struct load_weight load; /* for load-balancing */
1271 struct rb_node run_node;
1272 struct list_head group_node;
1273 unsigned int on_rq;
1274
1275 u64 exec_start;
1276 u64 sum_exec_runtime;
1277 u64 vruntime;
1278 u64 prev_sum_exec_runtime;
1279
41acab88
LDM
1280 u64 nr_migrations;
1281
41acab88
LDM
1282#ifdef CONFIG_SCHEDSTATS
1283 struct sched_statistics statistics;
94c18227
IM
1284#endif
1285
20b8a59f 1286#ifdef CONFIG_FAIR_GROUP_SCHED
fed14d45 1287 int depth;
20b8a59f
IM
1288 struct sched_entity *parent;
1289 /* rq on which this entity is (to be) queued: */
1290 struct cfs_rq *cfs_rq;
1291 /* rq "owned" by this entity/group: */
1292 struct cfs_rq *my_q;
1293#endif
8bd75c77 1294
141965c7 1295#ifdef CONFIG_SMP
5a107804
JO
1296 /*
1297 * Per entity load average tracking.
1298 *
1299 * Put into separate cache line so it does not
1300 * collide with read-mostly values above.
1301 */
1302 struct sched_avg avg ____cacheline_aligned_in_smp;
9d85f21c 1303#endif
20b8a59f 1304};
70b97a7f 1305
fa717060
PZ
1306struct sched_rt_entity {
1307 struct list_head run_list;
78f2c7db 1308 unsigned long timeout;
57d2aa00 1309 unsigned long watchdog_stamp;
bee367ed 1310 unsigned int time_slice;
ff77e468
PZ
1311 unsigned short on_rq;
1312 unsigned short on_list;
6f505b16 1313
58d6c2d7 1314 struct sched_rt_entity *back;
052f1dc7 1315#ifdef CONFIG_RT_GROUP_SCHED
6f505b16
PZ
1316 struct sched_rt_entity *parent;
1317 /* rq on which this entity is (to be) queued: */
1318 struct rt_rq *rt_rq;
1319 /* rq "owned" by this entity/group: */
1320 struct rt_rq *my_q;
1321#endif
fa717060
PZ
1322};
1323
aab03e05
DF
1324struct sched_dl_entity {
1325 struct rb_node rb_node;
1326
1327 /*
1328 * Original scheduling parameters. Copied here from sched_attr
4027d080 1329 * during sched_setattr(), they will remain the same until
1330 * the next sched_setattr().
aab03e05
DF
1331 */
1332 u64 dl_runtime; /* maximum runtime for each instance */
1333 u64 dl_deadline; /* relative deadline of each instance */
755378a4 1334 u64 dl_period; /* separation of two instances (period) */
332ac17e 1335 u64 dl_bw; /* dl_runtime / dl_deadline */
aab03e05
DF
1336
1337 /*
1338 * Actual scheduling parameters. Initialized with the values above,
1339 * they are continously updated during task execution. Note that
1340 * the remaining runtime could be < 0 in case we are in overrun.
1341 */
1342 s64 runtime; /* remaining runtime for this instance */
1343 u64 deadline; /* absolute deadline for this instance */
1344 unsigned int flags; /* specifying the scheduler behaviour */
1345
1346 /*
1347 * Some bool flags:
1348 *
1349 * @dl_throttled tells if we exhausted the runtime. If so, the
1350 * task has to wait for a replenishment to be performed at the
1351 * next firing of dl_timer.
1352 *
2d3d891d
DF
1353 * @dl_boosted tells if we are boosted due to DI. If so we are
1354 * outside bandwidth enforcement mechanism (but only until we
5bfd126e
JL
1355 * exit the critical section);
1356 *
1357 * @dl_yielded tells if task gave up the cpu before consuming
1358 * all its available runtime during the last job.
aab03e05 1359 */
72f9f3fd 1360 int dl_throttled, dl_boosted, dl_yielded;
aab03e05
DF
1361
1362 /*
1363 * Bandwidth enforcement timer. Each -deadline task has its
1364 * own bandwidth to be enforced, thus we need one timer per task.
1365 */
1366 struct hrtimer dl_timer;
1367};
8bd75c77 1368
1d082fd0
PM
1369union rcu_special {
1370 struct {
8203d6d0
PM
1371 u8 blocked;
1372 u8 need_qs;
1373 u8 exp_need_qs;
1374 u8 pad; /* Otherwise the compiler can store garbage here. */
1375 } b; /* Bits. */
1376 u32 s; /* Set of bits. */
1d082fd0 1377};
86848966
PM
1378struct rcu_node;
1379
8dc85d54
PZ
1380enum perf_event_task_context {
1381 perf_invalid_context = -1,
1382 perf_hw_context = 0,
89a1e187 1383 perf_sw_context,
8dc85d54
PZ
1384 perf_nr_task_contexts,
1385};
1386
72b252ae
MG
1387/* Track pages that require TLB flushes */
1388struct tlbflush_unmap_batch {
1389 /*
1390 * Each bit set is a CPU that potentially has a TLB entry for one of
1391 * the PFNs being flushed. See set_tlb_ubc_flush_pending().
1392 */
1393 struct cpumask cpumask;
1394
1395 /* True if any bit in cpumask is set */
1396 bool flush_required;
d950c947
MG
1397
1398 /*
1399 * If true then the PTE was dirty when unmapped. The entry must be
1400 * flushed before IO is initiated or a stale TLB entry potentially
1401 * allows an update without redirtying the page.
1402 */
1403 bool writable;
72b252ae
MG
1404};
1405
1da177e4
LT
1406struct task_struct {
1407 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
f7e4217b 1408 void *stack;
1da177e4 1409 atomic_t usage;
97dc32cd
WC
1410 unsigned int flags; /* per process flags, defined below */
1411 unsigned int ptrace;
1da177e4 1412
2dd73a4f 1413#ifdef CONFIG_SMP
fa14ff4a 1414 struct llist_node wake_entry;
3ca7a440 1415 int on_cpu;
63b0e9ed 1416 unsigned int wakee_flips;
62470419 1417 unsigned long wakee_flip_decay_ts;
63b0e9ed 1418 struct task_struct *last_wakee;
ac66f547
PZ
1419
1420 int wake_cpu;
2dd73a4f 1421#endif
fd2f4419 1422 int on_rq;
50e645a8 1423
b29739f9 1424 int prio, static_prio, normal_prio;
c7aceaba 1425 unsigned int rt_priority;
5522d5d5 1426 const struct sched_class *sched_class;
20b8a59f 1427 struct sched_entity se;
fa717060 1428 struct sched_rt_entity rt;
8323f26c
PZ
1429#ifdef CONFIG_CGROUP_SCHED
1430 struct task_group *sched_task_group;
1431#endif
aab03e05 1432 struct sched_dl_entity dl;
1da177e4 1433
e107be36
AK
1434#ifdef CONFIG_PREEMPT_NOTIFIERS
1435 /* list of struct preempt_notifier: */
1436 struct hlist_head preempt_notifiers;
1437#endif
1438
6c5c9341 1439#ifdef CONFIG_BLK_DEV_IO_TRACE
2056a782 1440 unsigned int btrace_seq;
6c5c9341 1441#endif
1da177e4 1442
97dc32cd 1443 unsigned int policy;
29baa747 1444 int nr_cpus_allowed;
1da177e4 1445 cpumask_t cpus_allowed;
1da177e4 1446
a57eb940 1447#ifdef CONFIG_PREEMPT_RCU
e260be67 1448 int rcu_read_lock_nesting;
1d082fd0 1449 union rcu_special rcu_read_unlock_special;
f41d911f 1450 struct list_head rcu_node_entry;
a57eb940 1451 struct rcu_node *rcu_blocked_node;
28f6569a 1452#endif /* #ifdef CONFIG_PREEMPT_RCU */
8315f422
PM
1453#ifdef CONFIG_TASKS_RCU
1454 unsigned long rcu_tasks_nvcsw;
1455 bool rcu_tasks_holdout;
1456 struct list_head rcu_tasks_holdout_list;
176f8f7a 1457 int rcu_tasks_idle_cpu;
8315f422 1458#endif /* #ifdef CONFIG_TASKS_RCU */
e260be67 1459
f6db8347 1460#ifdef CONFIG_SCHED_INFO
1da177e4
LT
1461 struct sched_info sched_info;
1462#endif
1463
1464 struct list_head tasks;
806c09a7 1465#ifdef CONFIG_SMP
917b627d 1466 struct plist_node pushable_tasks;
1baca4ce 1467 struct rb_node pushable_dl_tasks;
806c09a7 1468#endif
1da177e4
LT
1469
1470 struct mm_struct *mm, *active_mm;
615d6e87
DB
1471 /* per-thread vma caching */
1472 u32 vmacache_seqnum;
1473 struct vm_area_struct *vmacache[VMACACHE_SIZE];
34e55232
KH
1474#if defined(SPLIT_RSS_COUNTING)
1475 struct task_rss_stat rss_stat;
1476#endif
1da177e4 1477/* task state */
97dc32cd 1478 int exit_state;
1da177e4
LT
1479 int exit_code, exit_signal;
1480 int pdeath_signal; /* The signal sent when the parent dies */
e7cc4173 1481 unsigned long jobctl; /* JOBCTL_*, siglock protected */
9b89f6ba
AE
1482
1483 /* Used for emulating ABI behavior of previous Linux versions */
97dc32cd 1484 unsigned int personality;
9b89f6ba 1485
be958bdc 1486 /* scheduler bits, serialized by scheduler locks */
ca94c442 1487 unsigned sched_reset_on_fork:1;
a8e4f2ea 1488 unsigned sched_contributes_to_load:1;
ff303e66 1489 unsigned sched_migrated:1;
be958bdc
PZ
1490 unsigned :0; /* force alignment to the next boundary */
1491
1492 /* unserialized, strictly 'current' */
1493 unsigned in_execve:1; /* bit to tell LSMs we're in execve */
1494 unsigned in_iowait:1;
626ebc41
TH
1495#ifdef CONFIG_MEMCG
1496 unsigned memcg_may_oom:1;
127424c8 1497#ifndef CONFIG_SLOB
6f185c29
VD
1498 unsigned memcg_kmem_skip_account:1;
1499#endif
127424c8 1500#endif
ff303e66
PZ
1501#ifdef CONFIG_COMPAT_BRK
1502 unsigned brk_randomized:1;
1503#endif
6f185c29 1504
1d4457f9
KC
1505 unsigned long atomic_flags; /* Flags needing atomic access. */
1506
f56141e3
AL
1507 struct restart_block restart_block;
1508
1da177e4
LT
1509 pid_t pid;
1510 pid_t tgid;
0a425405 1511
1314562a 1512#ifdef CONFIG_CC_STACKPROTECTOR
0a425405
AV
1513 /* Canary value for the -fstack-protector gcc feature */
1514 unsigned long stack_canary;
1314562a 1515#endif
4d1d61a6 1516 /*
1da177e4 1517 * pointers to (original) parent process, youngest child, younger sibling,
4d1d61a6 1518 * older sibling, respectively. (p->father can be replaced with
f470021a 1519 * p->real_parent->pid)
1da177e4 1520 */
abd63bc3
KC
1521 struct task_struct __rcu *real_parent; /* real parent process */
1522 struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
1da177e4 1523 /*
f470021a 1524 * children/sibling forms the list of my natural children
1da177e4
LT
1525 */
1526 struct list_head children; /* list of my children */
1527 struct list_head sibling; /* linkage in my parent's children list */
1528 struct task_struct *group_leader; /* threadgroup leader */
1529
f470021a
RM
1530 /*
1531 * ptraced is the list of tasks this task is using ptrace on.
1532 * This includes both natural children and PTRACE_ATTACH targets.
1533 * p->ptrace_entry is p's link on the p->parent->ptraced list.
1534 */
1535 struct list_head ptraced;
1536 struct list_head ptrace_entry;
1537
1da177e4 1538 /* PID/PID hash table linkage. */
92476d7f 1539 struct pid_link pids[PIDTYPE_MAX];
47e65328 1540 struct list_head thread_group;
0c740d0a 1541 struct list_head thread_node;
1da177e4
LT
1542
1543 struct completion *vfork_done; /* for vfork() */
1544 int __user *set_child_tid; /* CLONE_CHILD_SETTID */
1545 int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
1546
c66f08be 1547 cputime_t utime, stime, utimescaled, stimescaled;
9ac52315 1548 cputime_t gtime;
9d7fb042 1549 struct prev_cputime prev_cputime;
6a61671b 1550#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
b7ce2277 1551 seqcount_t vtime_seqcount;
6a61671b
FW
1552 unsigned long long vtime_snap;
1553 enum {
7098c1ea
FW
1554 /* Task is sleeping or running in a CPU with VTIME inactive */
1555 VTIME_INACTIVE = 0,
1556 /* Task runs in userspace in a CPU with VTIME active */
6a61671b 1557 VTIME_USER,
7098c1ea 1558 /* Task runs in kernelspace in a CPU with VTIME active */
6a61671b
FW
1559 VTIME_SYS,
1560 } vtime_snap_whence;
d99ca3b9 1561#endif
d027d45d
FW
1562
1563#ifdef CONFIG_NO_HZ_FULL
f009a7a7 1564 atomic_t tick_dep_mask;
d027d45d 1565#endif
1da177e4 1566 unsigned long nvcsw, nivcsw; /* context switch counts */
ccbf62d8 1567 u64 start_time; /* monotonic time in nsec */
57e0be04 1568 u64 real_start_time; /* boot based time in nsec */
1da177e4
LT
1569/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
1570 unsigned long min_flt, maj_flt;
1571
f06febc9 1572 struct task_cputime cputime_expires;
1da177e4
LT
1573 struct list_head cpu_timers[3];
1574
1575/* process credentials */
1b0ba1c9 1576 const struct cred __rcu *real_cred; /* objective and real subjective task
3b11a1de 1577 * credentials (COW) */
1b0ba1c9 1578 const struct cred __rcu *cred; /* effective (overridable) subjective task
3b11a1de 1579 * credentials (COW) */
36772092
PBG
1580 char comm[TASK_COMM_LEN]; /* executable name excluding path
1581 - access with [gs]et_task_comm (which lock
1582 it with task_lock())
221af7f8 1583 - initialized normally by setup_new_exec */
1da177e4 1584/* file system info */
756daf26 1585 struct nameidata *nameidata;
3d5b6fcc 1586#ifdef CONFIG_SYSVIPC
1da177e4
LT
1587/* ipc stuff */
1588 struct sysv_sem sysvsem;
ab602f79 1589 struct sysv_shm sysvshm;
3d5b6fcc 1590#endif
e162b39a 1591#ifdef CONFIG_DETECT_HUNG_TASK
82a1fcb9 1592/* hung task detection */
82a1fcb9
IM
1593 unsigned long last_switch_count;
1594#endif
1da177e4
LT
1595/* filesystem information */
1596 struct fs_struct *fs;
1597/* open file information */
1598 struct files_struct *files;
1651e14e 1599/* namespaces */
ab516013 1600 struct nsproxy *nsproxy;
1da177e4
LT
1601/* signal handlers */
1602 struct signal_struct *signal;
1603 struct sighand_struct *sighand;
1604
1605 sigset_t blocked, real_blocked;
f3de272b 1606 sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
1da177e4
LT
1607 struct sigpending pending;
1608
1609 unsigned long sas_ss_sp;
1610 size_t sas_ss_size;
2e01fabe 1611
67d12145 1612 struct callback_head *task_works;
e73f8959 1613
1da177e4 1614 struct audit_context *audit_context;
bfef93a5 1615#ifdef CONFIG_AUDITSYSCALL
e1760bd5 1616 kuid_t loginuid;
4746ec5b 1617 unsigned int sessionid;
bfef93a5 1618#endif
932ecebb 1619 struct seccomp seccomp;
1da177e4
LT
1620
1621/* Thread group tracking */
1622 u32 parent_exec_id;
1623 u32 self_exec_id;
58568d2a
MX
1624/* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
1625 * mempolicy */
1da177e4 1626 spinlock_t alloc_lock;
1da177e4 1627
b29739f9 1628 /* Protection of the PI data structures: */
1d615482 1629 raw_spinlock_t pi_lock;
b29739f9 1630
76751049
PZ
1631 struct wake_q_node wake_q;
1632
23f78d4a
IM
1633#ifdef CONFIG_RT_MUTEXES
1634 /* PI waiters blocked on a rt_mutex held by this task */
fb00aca4
PZ
1635 struct rb_root pi_waiters;
1636 struct rb_node *pi_waiters_leftmost;
23f78d4a
IM
1637 /* Deadlock detection and priority inheritance handling */
1638 struct rt_mutex_waiter *pi_blocked_on;
23f78d4a
IM
1639#endif
1640
408894ee
IM
1641#ifdef CONFIG_DEBUG_MUTEXES
1642 /* mutex deadlock detection */
1643 struct mutex_waiter *blocked_on;
1644#endif
de30a2b3
IM
1645#ifdef CONFIG_TRACE_IRQFLAGS
1646 unsigned int irq_events;
de30a2b3 1647 unsigned long hardirq_enable_ip;
de30a2b3 1648 unsigned long hardirq_disable_ip;
fa1452e8 1649 unsigned int hardirq_enable_event;
de30a2b3 1650 unsigned int hardirq_disable_event;
fa1452e8
HS
1651 int hardirqs_enabled;
1652 int hardirq_context;
de30a2b3 1653 unsigned long softirq_disable_ip;
de30a2b3 1654 unsigned long softirq_enable_ip;
fa1452e8 1655 unsigned int softirq_disable_event;
de30a2b3 1656 unsigned int softirq_enable_event;
fa1452e8 1657 int softirqs_enabled;
de30a2b3
IM
1658 int softirq_context;
1659#endif
fbb9ce95 1660#ifdef CONFIG_LOCKDEP
bdb9441e 1661# define MAX_LOCK_DEPTH 48UL
fbb9ce95
IM
1662 u64 curr_chain_key;
1663 int lockdep_depth;
fbb9ce95 1664 unsigned int lockdep_recursion;
c7aceaba 1665 struct held_lock held_locks[MAX_LOCK_DEPTH];
cf40bd16 1666 gfp_t lockdep_reclaim_gfp;
fbb9ce95 1667#endif
c6d30853
AR
1668#ifdef CONFIG_UBSAN
1669 unsigned int in_ubsan;
1670#endif
408894ee 1671
1da177e4
LT
1672/* journalling filesystem info */
1673 void *journal_info;
1674
d89d8796 1675/* stacked block device info */
bddd87c7 1676 struct bio_list *bio_list;
d89d8796 1677
73c10101
JA
1678#ifdef CONFIG_BLOCK
1679/* stack plugging */
1680 struct blk_plug *plug;
1681#endif
1682
1da177e4
LT
1683/* VM state */
1684 struct reclaim_state *reclaim_state;
1685
1da177e4
LT
1686 struct backing_dev_info *backing_dev_info;
1687
1688 struct io_context *io_context;
1689
1690 unsigned long ptrace_message;
1691 siginfo_t *last_siginfo; /* For ptrace use. */
7c3ab738 1692 struct task_io_accounting ioac;
8f0ab514 1693#if defined(CONFIG_TASK_XACCT)
1da177e4
LT
1694 u64 acct_rss_mem1; /* accumulated rss usage */
1695 u64 acct_vm_mem1; /* accumulated virtual memory usage */
49b5cf34 1696 cputime_t acct_timexpd; /* stime + utime since last update */
1da177e4
LT
1697#endif
1698#ifdef CONFIG_CPUSETS
58568d2a 1699 nodemask_t mems_allowed; /* Protected by alloc_lock */
cc9a6c87 1700 seqcount_t mems_allowed_seq; /* Seqence no to catch updates */
825a46af 1701 int cpuset_mem_spread_rotor;
6adef3eb 1702 int cpuset_slab_spread_rotor;
1da177e4 1703#endif
ddbcc7e8 1704#ifdef CONFIG_CGROUPS
817929ec 1705 /* Control Group info protected by css_set_lock */
2c392b8c 1706 struct css_set __rcu *cgroups;
817929ec
PM
1707 /* cg_list protected by css_set_lock and tsk->alloc_lock */
1708 struct list_head cg_list;
ddbcc7e8 1709#endif
42b2dd0a 1710#ifdef CONFIG_FUTEX
0771dfef 1711 struct robust_list_head __user *robust_list;
34f192c6
IM
1712#ifdef CONFIG_COMPAT
1713 struct compat_robust_list_head __user *compat_robust_list;
1714#endif
c87e2837
IM
1715 struct list_head pi_state_list;
1716 struct futex_pi_state *pi_state_cache;
c7aceaba 1717#endif
cdd6c482 1718#ifdef CONFIG_PERF_EVENTS
8dc85d54 1719 struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
cdd6c482
IM
1720 struct mutex perf_event_mutex;
1721 struct list_head perf_event_list;
a63eaf34 1722#endif
8f47b187
TG
1723#ifdef CONFIG_DEBUG_PREEMPT
1724 unsigned long preempt_disable_ip;
1725#endif
c7aceaba 1726#ifdef CONFIG_NUMA
58568d2a 1727 struct mempolicy *mempolicy; /* Protected by alloc_lock */
c7aceaba 1728 short il_next;
207205a2 1729 short pref_node_fork;
42b2dd0a 1730#endif
cbee9f88
PZ
1731#ifdef CONFIG_NUMA_BALANCING
1732 int numa_scan_seq;
cbee9f88 1733 unsigned int numa_scan_period;
598f0ec0 1734 unsigned int numa_scan_period_max;
de1c9ce6 1735 int numa_preferred_nid;
6b9a7460 1736 unsigned long numa_migrate_retry;
cbee9f88 1737 u64 node_stamp; /* migration stamp */
7e2703e6
RR
1738 u64 last_task_numa_placement;
1739 u64 last_sum_exec_runtime;
cbee9f88 1740 struct callback_head numa_work;
f809ca9a 1741
8c8a743c
PZ
1742 struct list_head numa_entry;
1743 struct numa_group *numa_group;
1744
745d6147 1745 /*
44dba3d5
IM
1746 * numa_faults is an array split into four regions:
1747 * faults_memory, faults_cpu, faults_memory_buffer, faults_cpu_buffer
1748 * in this precise order.
1749 *
1750 * faults_memory: Exponential decaying average of faults on a per-node
1751 * basis. Scheduling placement decisions are made based on these
1752 * counts. The values remain static for the duration of a PTE scan.
1753 * faults_cpu: Track the nodes the process was running on when a NUMA
1754 * hinting fault was incurred.
1755 * faults_memory_buffer and faults_cpu_buffer: Record faults per node
1756 * during the current scan window. When the scan completes, the counts
1757 * in faults_memory and faults_cpu decay and these values are copied.
745d6147 1758 */
44dba3d5 1759 unsigned long *numa_faults;
83e1d2cd 1760 unsigned long total_numa_faults;
745d6147 1761
04bb2f94
RR
1762 /*
1763 * numa_faults_locality tracks if faults recorded during the last
074c2381
MG
1764 * scan window were remote/local or failed to migrate. The task scan
1765 * period is adapted based on the locality of the faults with different
1766 * weights depending on whether they were shared or private faults
04bb2f94 1767 */
074c2381 1768 unsigned long numa_faults_locality[3];
04bb2f94 1769
b32e86b4 1770 unsigned long numa_pages_migrated;
cbee9f88
PZ
1771#endif /* CONFIG_NUMA_BALANCING */
1772
72b252ae
MG
1773#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
1774 struct tlbflush_unmap_batch tlb_ubc;
1775#endif
1776
e56d0903 1777 struct rcu_head rcu;
b92ce558
JA
1778
1779 /*
1780 * cache last used pipe for splice
1781 */
1782 struct pipe_inode_info *splice_pipe;
5640f768
ED
1783
1784 struct page_frag task_frag;
1785
ca74e92b
SN
1786#ifdef CONFIG_TASK_DELAY_ACCT
1787 struct task_delay_info *delays;
f4f154fd
AM
1788#endif
1789#ifdef CONFIG_FAULT_INJECTION
1790 int make_it_fail;
ca74e92b 1791#endif
9d823e8f
WF
1792 /*
1793 * when (nr_dirtied >= nr_dirtied_pause), it's time to call
1794 * balance_dirty_pages() for some dirty throttling pause
1795 */
1796 int nr_dirtied;
1797 int nr_dirtied_pause;
83712358 1798 unsigned long dirty_paused_when; /* start of a write-and-pause period */
9d823e8f 1799
9745512c
AV
1800#ifdef CONFIG_LATENCYTOP
1801 int latency_record_count;
1802 struct latency_record latency_record[LT_SAVECOUNT];
1803#endif
6976675d
AV
1804 /*
1805 * time slack values; these are used to round up poll() and
1806 * select() etc timeout values. These are in nanoseconds.
1807 */
da8b44d5
JS
1808 u64 timer_slack_ns;
1809 u64 default_timer_slack_ns;
f8d570a4 1810
0b24becc
AR
1811#ifdef CONFIG_KASAN
1812 unsigned int kasan_depth;
1813#endif
fb52607a 1814#ifdef CONFIG_FUNCTION_GRAPH_TRACER
3ad2f3fb 1815 /* Index of current stored address in ret_stack */
f201ae23
FW
1816 int curr_ret_stack;
1817 /* Stack of return addresses for return function tracing */
1818 struct ftrace_ret_stack *ret_stack;
8aef2d28
SR
1819 /* time stamp for last schedule */
1820 unsigned long long ftrace_timestamp;
f201ae23
FW
1821 /*
1822 * Number of functions that haven't been traced
1823 * because of depth overrun.
1824 */
1825 atomic_t trace_overrun;
380c4b14
FW
1826 /* Pause for the tracing */
1827 atomic_t tracing_graph_pause;
f201ae23 1828#endif
ea4e2bc4
SR
1829#ifdef CONFIG_TRACING
1830 /* state flags for use by tracers */
1831 unsigned long trace;
b1cff0ad 1832 /* bitmask and counter of trace recursion */
261842b7
SR
1833 unsigned long trace_recursion;
1834#endif /* CONFIG_TRACING */
5c9a8750
DV
1835#ifdef CONFIG_KCOV
1836 /* Coverage collection mode enabled for this task (0 if disabled). */
1837 enum kcov_mode kcov_mode;
1838 /* Size of the kcov_area. */
1839 unsigned kcov_size;
1840 /* Buffer for coverage collection. */
1841 void *kcov_area;
1842 /* kcov desciptor wired with this task or NULL. */
1843 struct kcov *kcov;
1844#endif
6f185c29 1845#ifdef CONFIG_MEMCG
626ebc41
TH
1846 struct mem_cgroup *memcg_in_oom;
1847 gfp_t memcg_oom_gfp_mask;
1848 int memcg_oom_order;
b23afb93
TH
1849
1850 /* number of pages to reclaim on returning to userland */
1851 unsigned int memcg_nr_pages_over_high;
569b846d 1852#endif
0326f5a9
SD
1853#ifdef CONFIG_UPROBES
1854 struct uprobe_task *utask;
0326f5a9 1855#endif
cafe5635
KO
1856#if defined(CONFIG_BCACHE) || defined(CONFIG_BCACHE_MODULE)
1857 unsigned int sequential_io;
1858 unsigned int sequential_io_avg;
1859#endif
8eb23b9f
PZ
1860#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
1861 unsigned long task_state_change;
1862#endif
8bcbde54 1863 int pagefault_disabled;
03049269 1864#ifdef CONFIG_MMU
29c696e1 1865 struct task_struct *oom_reaper_list;
03049269 1866#endif
0c8c0f03
DH
1867/* CPU-specific state of this task */
1868 struct thread_struct thread;
1869/*
1870 * WARNING: on x86, 'thread_struct' contains a variable-sized
1871 * structure. It *MUST* be at the end of 'task_struct'.
1872 *
1873 * Do not put anything below here!
1874 */
1da177e4
LT
1875};
1876
5aaeb5c0
IM
1877#ifdef CONFIG_ARCH_WANTS_DYNAMIC_TASK_STRUCT
1878extern int arch_task_struct_size __read_mostly;
1879#else
1880# define arch_task_struct_size (sizeof(struct task_struct))
1881#endif
0c8c0f03 1882
76e6eee0 1883/* Future-safe accessor for struct task_struct's cpus_allowed. */
a4636818 1884#define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76e6eee0 1885
6688cc05
PZ
1886#define TNF_MIGRATED 0x01
1887#define TNF_NO_GROUP 0x02
dabe1d99 1888#define TNF_SHARED 0x04
04bb2f94 1889#define TNF_FAULT_LOCAL 0x08
074c2381 1890#define TNF_MIGRATE_FAIL 0x10
6688cc05 1891
cbee9f88 1892#ifdef CONFIG_NUMA_BALANCING
6688cc05 1893extern void task_numa_fault(int last_node, int node, int pages, int flags);
e29cf08b 1894extern pid_t task_numa_group_id(struct task_struct *p);
1a687c2e 1895extern void set_numabalancing_state(bool enabled);
82727018 1896extern void task_numa_free(struct task_struct *p);
10f39042
RR
1897extern bool should_numa_migrate_memory(struct task_struct *p, struct page *page,
1898 int src_nid, int dst_cpu);
cbee9f88 1899#else
ac8e895b 1900static inline void task_numa_fault(int last_node, int node, int pages,
6688cc05 1901 int flags)
cbee9f88
PZ
1902{
1903}
e29cf08b
MG
1904static inline pid_t task_numa_group_id(struct task_struct *p)
1905{
1906 return 0;
1907}
1a687c2e
MG
1908static inline void set_numabalancing_state(bool enabled)
1909{
1910}
82727018
RR
1911static inline void task_numa_free(struct task_struct *p)
1912{
1913}
10f39042
RR
1914static inline bool should_numa_migrate_memory(struct task_struct *p,
1915 struct page *page, int src_nid, int dst_cpu)
1916{
1917 return true;
1918}
cbee9f88
PZ
1919#endif
1920
e868171a 1921static inline struct pid *task_pid(struct task_struct *task)
22c935f4
EB
1922{
1923 return task->pids[PIDTYPE_PID].pid;
1924}
1925
e868171a 1926static inline struct pid *task_tgid(struct task_struct *task)
22c935f4
EB
1927{
1928 return task->group_leader->pids[PIDTYPE_PID].pid;
1929}
1930
6dda81f4
ON
1931/*
1932 * Without tasklist or rcu lock it is not safe to dereference
1933 * the result of task_pgrp/task_session even if task == current,
1934 * we can race with another thread doing sys_setsid/sys_setpgid.
1935 */
e868171a 1936static inline struct pid *task_pgrp(struct task_struct *task)
22c935f4
EB
1937{
1938 return task->group_leader->pids[PIDTYPE_PGID].pid;
1939}
1940
e868171a 1941static inline struct pid *task_session(struct task_struct *task)
22c935f4
EB
1942{
1943 return task->group_leader->pids[PIDTYPE_SID].pid;
1944}
1945
7af57294
PE
1946struct pid_namespace;
1947
1948/*
1949 * the helpers to get the task's different pids as they are seen
1950 * from various namespaces
1951 *
1952 * task_xid_nr() : global id, i.e. the id seen from the init namespace;
44c4e1b2
EB
1953 * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of
1954 * current.
7af57294
PE
1955 * task_xid_nr_ns() : id seen from the ns specified;
1956 *
1957 * set_task_vxid() : assigns a virtual id to a task;
1958 *
7af57294
PE
1959 * see also pid_nr() etc in include/linux/pid.h
1960 */
52ee2dfd
ON
1961pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
1962 struct pid_namespace *ns);
7af57294 1963
e868171a 1964static inline pid_t task_pid_nr(struct task_struct *tsk)
7af57294
PE
1965{
1966 return tsk->pid;
1967}
1968
52ee2dfd
ON
1969static inline pid_t task_pid_nr_ns(struct task_struct *tsk,
1970 struct pid_namespace *ns)
1971{
1972 return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
1973}
7af57294
PE
1974
1975static inline pid_t task_pid_vnr(struct task_struct *tsk)
1976{
52ee2dfd 1977 return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7af57294
PE
1978}
1979
1980
e868171a 1981static inline pid_t task_tgid_nr(struct task_struct *tsk)
7af57294
PE
1982{
1983 return tsk->tgid;
1984}
1985
2f2a3a46 1986pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
7af57294
PE
1987
1988static inline pid_t task_tgid_vnr(struct task_struct *tsk)
1989{
1990 return pid_vnr(task_tgid(tsk));
1991}
1992
1993
80e0b6e8 1994static inline int pid_alive(const struct task_struct *p);
ad36d282
RGB
1995static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)
1996{
1997 pid_t pid = 0;
1998
1999 rcu_read_lock();
2000 if (pid_alive(tsk))
2001 pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);
2002 rcu_read_unlock();
2003
2004 return pid;
2005}
2006
2007static inline pid_t task_ppid_nr(const struct task_struct *tsk)
2008{
2009 return task_ppid_nr_ns(tsk, &init_pid_ns);
2010}
2011
52ee2dfd
ON
2012static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk,
2013 struct pid_namespace *ns)
7af57294 2014{
52ee2dfd 2015 return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
7af57294
PE
2016}
2017
7af57294
PE
2018static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
2019{
52ee2dfd 2020 return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
7af57294
PE
2021}
2022
2023
52ee2dfd
ON
2024static inline pid_t task_session_nr_ns(struct task_struct *tsk,
2025 struct pid_namespace *ns)
7af57294 2026{
52ee2dfd 2027 return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
7af57294
PE
2028}
2029
7af57294
PE
2030static inline pid_t task_session_vnr(struct task_struct *tsk)
2031{
52ee2dfd 2032 return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
7af57294
PE
2033}
2034
1b0f7ffd
ON
2035/* obsolete, do not use */
2036static inline pid_t task_pgrp_nr(struct task_struct *tsk)
2037{
2038 return task_pgrp_nr_ns(tsk, &init_pid_ns);
2039}
7af57294 2040
1da177e4
LT
2041/**
2042 * pid_alive - check that a task structure is not stale
2043 * @p: Task structure to be checked.
2044 *
2045 * Test if a process is not yet dead (at most zombie state)
2046 * If pid_alive fails, then pointers within the task structure
2047 * can be stale and must not be dereferenced.
e69f6186
YB
2048 *
2049 * Return: 1 if the process is alive. 0 otherwise.
1da177e4 2050 */
ad36d282 2051static inline int pid_alive(const struct task_struct *p)
1da177e4 2052{
92476d7f 2053 return p->pids[PIDTYPE_PID].pid != NULL;
1da177e4
LT
2054}
2055
f400e198 2056/**
570f5241
SS
2057 * is_global_init - check if a task structure is init. Since init
2058 * is free to have sub-threads we need to check tgid.
3260259f
H
2059 * @tsk: Task structure to be checked.
2060 *
2061 * Check if a task structure is the first user space task the kernel created.
e69f6186
YB
2062 *
2063 * Return: 1 if the task structure is init. 0 otherwise.
b460cbc5 2064 */
e868171a 2065static inline int is_global_init(struct task_struct *tsk)
b461cc03 2066{
570f5241 2067 return task_tgid_nr(tsk) == 1;
b461cc03 2068}
b460cbc5 2069
9ec52099
CLG
2070extern struct pid *cad_pid;
2071
1da177e4 2072extern void free_task(struct task_struct *tsk);
1da177e4 2073#define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
e56d0903 2074
158d9ebd 2075extern void __put_task_struct(struct task_struct *t);
e56d0903
IM
2076
2077static inline void put_task_struct(struct task_struct *t)
2078{
2079 if (atomic_dec_and_test(&t->usage))
8c7904a0 2080 __put_task_struct(t);
e56d0903 2081}
1da177e4 2082
6a61671b
FW
2083#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
2084extern void task_cputime(struct task_struct *t,
2085 cputime_t *utime, cputime_t *stime);
2086extern void task_cputime_scaled(struct task_struct *t,
2087 cputime_t *utimescaled, cputime_t *stimescaled);
2088extern cputime_t task_gtime(struct task_struct *t);
2089#else
6fac4829
FW
2090static inline void task_cputime(struct task_struct *t,
2091 cputime_t *utime, cputime_t *stime)
2092{
2093 if (utime)
2094 *utime = t->utime;
2095 if (stime)
2096 *stime = t->stime;
2097}
2098
2099static inline void task_cputime_scaled(struct task_struct *t,
2100 cputime_t *utimescaled,
2101 cputime_t *stimescaled)
2102{
2103 if (utimescaled)
2104 *utimescaled = t->utimescaled;
2105 if (stimescaled)
2106 *stimescaled = t->stimescaled;
2107}
6a61671b
FW
2108
2109static inline cputime_t task_gtime(struct task_struct *t)
2110{
2111 return t->gtime;
2112}
2113#endif
e80d0a1a
FW
2114extern void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
2115extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
49048622 2116
1da177e4
LT
2117/*
2118 * Per process flags
2119 */
1da177e4 2120#define PF_EXITING 0x00000004 /* getting shut down */
778e9a9c 2121#define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */
94886b84 2122#define PF_VCPU 0x00000010 /* I'm a virtual CPU */
21aa9af0 2123#define PF_WQ_WORKER 0x00000020 /* I'm a workqueue worker */
1da177e4 2124#define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
4db96cf0 2125#define PF_MCE_PROCESS 0x00000080 /* process policy on mce errors */
1da177e4
LT
2126#define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
2127#define PF_DUMPCORE 0x00000200 /* dumped core */
2128#define PF_SIGNALED 0x00000400 /* killed by a signal */
2129#define PF_MEMALLOC 0x00000800 /* Allocating memory */
72fa5997 2130#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
1da177e4 2131#define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
774a1221 2132#define PF_USED_ASYNC 0x00004000 /* used async_schedule*(), used by module init */
1da177e4
LT
2133#define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
2134#define PF_FROZEN 0x00010000 /* frozen for system suspend */
2135#define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */
2136#define PF_KSWAPD 0x00040000 /* I am kswapd */
21caf2fc 2137#define PF_MEMALLOC_NOIO 0x00080000 /* Allocating memory without IO involved */
1da177e4 2138#define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */
246bb0b1 2139#define PF_KTHREAD 0x00200000 /* I am a kernel thread */
b31dc66a
JA
2140#define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */
2141#define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */
14a40ffc 2142#define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_allowed */
4db96cf0 2143#define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */
61a87122 2144#define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */
58a69cb4 2145#define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezable */
2b44c4db 2146#define PF_SUSPEND_TASK 0x80000000 /* this thread called freeze_processes and should not be frozen */
1da177e4
LT
2147
2148/*
2149 * Only the _current_ task can read/write to tsk->flags, but other
2150 * tasks can access tsk->flags in readonly mode for example
2151 * with tsk_used_math (like during threaded core dumping).
2152 * There is however an exception to this rule during ptrace
2153 * or during fork: the ptracer task is allowed to write to the
2154 * child->flags of its traced child (same goes for fork, the parent
2155 * can write to the child->flags), because we're guaranteed the
2156 * child is not running and in turn not changing child->flags
2157 * at the same time the parent does it.
2158 */
2159#define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
2160#define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
2161#define clear_used_math() clear_stopped_child_used_math(current)
2162#define set_used_math() set_stopped_child_used_math(current)
2163#define conditional_stopped_child_used_math(condition, child) \
2164 do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
2165#define conditional_used_math(condition) \
2166 conditional_stopped_child_used_math(condition, current)
2167#define copy_to_stopped_child_used_math(child) \
2168 do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
2169/* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
2170#define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
2171#define used_math() tsk_used_math(current)
2172
934f3072
JB
2173/* __GFP_IO isn't allowed if PF_MEMALLOC_NOIO is set in current->flags
2174 * __GFP_FS is also cleared as it implies __GFP_IO.
2175 */
21caf2fc
ML
2176static inline gfp_t memalloc_noio_flags(gfp_t flags)
2177{
2178 if (unlikely(current->flags & PF_MEMALLOC_NOIO))
934f3072 2179 flags &= ~(__GFP_IO | __GFP_FS);
21caf2fc
ML
2180 return flags;
2181}
2182
2183static inline unsigned int memalloc_noio_save(void)
2184{
2185 unsigned int flags = current->flags & PF_MEMALLOC_NOIO;
2186 current->flags |= PF_MEMALLOC_NOIO;
2187 return flags;
2188}
2189
2190static inline void memalloc_noio_restore(unsigned int flags)
2191{
2192 current->flags = (current->flags & ~PF_MEMALLOC_NOIO) | flags;
2193}
2194
1d4457f9 2195/* Per-process atomic flags. */
a2b86f77 2196#define PFA_NO_NEW_PRIVS 0 /* May not gain new privileges. */
2ad654bc
ZL
2197#define PFA_SPREAD_PAGE 1 /* Spread page cache over cpuset */
2198#define PFA_SPREAD_SLAB 2 /* Spread some slab caches over cpuset */
2199
1d4457f9 2200
e0e5070b
ZL
2201#define TASK_PFA_TEST(name, func) \
2202 static inline bool task_##func(struct task_struct *p) \
2203 { return test_bit(PFA_##name, &p->atomic_flags); }
2204#define TASK_PFA_SET(name, func) \
2205 static inline void task_set_##func(struct task_struct *p) \
2206 { set_bit(PFA_##name, &p->atomic_flags); }
2207#define TASK_PFA_CLEAR(name, func) \
2208 static inline void task_clear_##func(struct task_struct *p) \
2209 { clear_bit(PFA_##name, &p->atomic_flags); }
2210
2211TASK_PFA_TEST(NO_NEW_PRIVS, no_new_privs)
2212TASK_PFA_SET(NO_NEW_PRIVS, no_new_privs)
1d4457f9 2213
2ad654bc
ZL
2214TASK_PFA_TEST(SPREAD_PAGE, spread_page)
2215TASK_PFA_SET(SPREAD_PAGE, spread_page)
2216TASK_PFA_CLEAR(SPREAD_PAGE, spread_page)
2217
2218TASK_PFA_TEST(SPREAD_SLAB, spread_slab)
2219TASK_PFA_SET(SPREAD_SLAB, spread_slab)
2220TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab)
1d4457f9 2221
e5c1902e 2222/*
a8f072c1 2223 * task->jobctl flags
e5c1902e 2224 */
a8f072c1 2225#define JOBCTL_STOP_SIGMASK 0xffff /* signr of the last group stop */
e5c1902e 2226
a8f072c1
TH
2227#define JOBCTL_STOP_DEQUEUED_BIT 16 /* stop signal dequeued */
2228#define JOBCTL_STOP_PENDING_BIT 17 /* task should stop for group stop */
2229#define JOBCTL_STOP_CONSUME_BIT 18 /* consume group stop count */
73ddff2b 2230#define JOBCTL_TRAP_STOP_BIT 19 /* trap for STOP */
fb1d910c 2231#define JOBCTL_TRAP_NOTIFY_BIT 20 /* trap for NOTIFY */
a8f072c1 2232#define JOBCTL_TRAPPING_BIT 21 /* switching to TRACED */
544b2c91 2233#define JOBCTL_LISTENING_BIT 22 /* ptracer is listening for events */
a8f072c1 2234
b76808e6
PD
2235#define JOBCTL_STOP_DEQUEUED (1UL << JOBCTL_STOP_DEQUEUED_BIT)
2236#define JOBCTL_STOP_PENDING (1UL << JOBCTL_STOP_PENDING_BIT)
2237#define JOBCTL_STOP_CONSUME (1UL << JOBCTL_STOP_CONSUME_BIT)
2238#define JOBCTL_TRAP_STOP (1UL << JOBCTL_TRAP_STOP_BIT)
2239#define JOBCTL_TRAP_NOTIFY (1UL << JOBCTL_TRAP_NOTIFY_BIT)
2240#define JOBCTL_TRAPPING (1UL << JOBCTL_TRAPPING_BIT)
2241#define JOBCTL_LISTENING (1UL << JOBCTL_LISTENING_BIT)
a8f072c1 2242
fb1d910c 2243#define JOBCTL_TRAP_MASK (JOBCTL_TRAP_STOP | JOBCTL_TRAP_NOTIFY)
73ddff2b 2244#define JOBCTL_PENDING_MASK (JOBCTL_STOP_PENDING | JOBCTL_TRAP_MASK)
3759a0d9 2245
7dd3db54 2246extern bool task_set_jobctl_pending(struct task_struct *task,
b76808e6 2247 unsigned long mask);
73ddff2b 2248extern void task_clear_jobctl_trapping(struct task_struct *task);
3759a0d9 2249extern void task_clear_jobctl_pending(struct task_struct *task,
b76808e6 2250 unsigned long mask);
39efa3ef 2251
f41d911f
PM
2252static inline void rcu_copy_process(struct task_struct *p)
2253{
8315f422 2254#ifdef CONFIG_PREEMPT_RCU
f41d911f 2255 p->rcu_read_lock_nesting = 0;
1d082fd0 2256 p->rcu_read_unlock_special.s = 0;
dd5d19ba 2257 p->rcu_blocked_node = NULL;
f41d911f 2258 INIT_LIST_HEAD(&p->rcu_node_entry);
8315f422
PM
2259#endif /* #ifdef CONFIG_PREEMPT_RCU */
2260#ifdef CONFIG_TASKS_RCU
2261 p->rcu_tasks_holdout = false;
2262 INIT_LIST_HEAD(&p->rcu_tasks_holdout_list);
176f8f7a 2263 p->rcu_tasks_idle_cpu = -1;
8315f422 2264#endif /* #ifdef CONFIG_TASKS_RCU */
f41d911f
PM
2265}
2266
907aed48
MG
2267static inline void tsk_restore_flags(struct task_struct *task,
2268 unsigned long orig_flags, unsigned long flags)
2269{
2270 task->flags &= ~flags;
2271 task->flags |= orig_flags & flags;
2272}
2273
f82f8042
JL
2274extern int cpuset_cpumask_can_shrink(const struct cpumask *cur,
2275 const struct cpumask *trial);
7f51412a
JL
2276extern int task_can_attach(struct task_struct *p,
2277 const struct cpumask *cs_cpus_allowed);
1da177e4 2278#ifdef CONFIG_SMP
1e1b6c51
KM
2279extern void do_set_cpus_allowed(struct task_struct *p,
2280 const struct cpumask *new_mask);
2281
cd8ba7cd 2282extern int set_cpus_allowed_ptr(struct task_struct *p,
96f874e2 2283 const struct cpumask *new_mask);
1da177e4 2284#else
1e1b6c51
KM
2285static inline void do_set_cpus_allowed(struct task_struct *p,
2286 const struct cpumask *new_mask)
2287{
2288}
cd8ba7cd 2289static inline int set_cpus_allowed_ptr(struct task_struct *p,
96f874e2 2290 const struct cpumask *new_mask)
1da177e4 2291{
96f874e2 2292 if (!cpumask_test_cpu(0, new_mask))
1da177e4
LT
2293 return -EINVAL;
2294 return 0;
2295}
2296#endif
e0ad9556 2297
3451d024 2298#ifdef CONFIG_NO_HZ_COMMON
5167e8d5
PZ
2299void calc_load_enter_idle(void);
2300void calc_load_exit_idle(void);
2301#else
2302static inline void calc_load_enter_idle(void) { }
2303static inline void calc_load_exit_idle(void) { }
3451d024 2304#endif /* CONFIG_NO_HZ_COMMON */
5167e8d5 2305
b342501c 2306/*
c676329a
PZ
2307 * Do not use outside of architecture code which knows its limitations.
2308 *
2309 * sched_clock() has no promise of monotonicity or bounded drift between
2310 * CPUs, use (which you should not) requires disabling IRQs.
2311 *
2312 * Please use one of the three interfaces below.
b342501c 2313 */
1bbfa6f2 2314extern unsigned long long notrace sched_clock(void);
c676329a 2315/*
489a71b0 2316 * See the comment in kernel/sched/clock.c
c676329a 2317 */
545a2bf7 2318extern u64 running_clock(void);
c676329a
PZ
2319extern u64 sched_clock_cpu(int cpu);
2320
e436d800 2321
c1955a3d 2322extern void sched_clock_init(void);
3e51f33f 2323
c1955a3d 2324#ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
3e51f33f
PZ
2325static inline void sched_clock_tick(void)
2326{
2327}
2328
2329static inline void sched_clock_idle_sleep_event(void)
2330{
2331}
2332
2333static inline void sched_clock_idle_wakeup_event(u64 delta_ns)
2334{
2335}
2c923e94
DL
2336
2337static inline u64 cpu_clock(int cpu)
2338{
2339 return sched_clock();
2340}
2341
2342static inline u64 local_clock(void)
2343{
2344 return sched_clock();
2345}
3e51f33f 2346#else
c676329a
PZ
2347/*
2348 * Architectures can set this to 1 if they have specified
2349 * CONFIG_HAVE_UNSTABLE_SCHED_CLOCK in their arch Kconfig,
2350 * but then during bootup it turns out that sched_clock()
2351 * is reliable after all:
2352 */
35af99e6
PZ
2353extern int sched_clock_stable(void);
2354extern void set_sched_clock_stable(void);
2355extern void clear_sched_clock_stable(void);
c676329a 2356
3e51f33f
PZ
2357extern void sched_clock_tick(void);
2358extern void sched_clock_idle_sleep_event(void);
2359extern void sched_clock_idle_wakeup_event(u64 delta_ns);
2c923e94
DL
2360
2361/*
2362 * As outlined in clock.c, provides a fast, high resolution, nanosecond
2363 * time source that is monotonic per cpu argument and has bounded drift
2364 * between cpus.
2365 *
2366 * ######################### BIG FAT WARNING ##########################
2367 * # when comparing cpu_clock(i) to cpu_clock(j) for i != j, time can #
2368 * # go backwards !! #
2369 * ####################################################################
2370 */
2371static inline u64 cpu_clock(int cpu)
2372{
2373 return sched_clock_cpu(cpu);
2374}
2375
2376static inline u64 local_clock(void)
2377{
2378 return sched_clock_cpu(raw_smp_processor_id());
2379}
3e51f33f
PZ
2380#endif
2381
b52bfee4
VP
2382#ifdef CONFIG_IRQ_TIME_ACCOUNTING
2383/*
2384 * An i/f to runtime opt-in for irq time accounting based off of sched_clock.
2385 * The reason for this explicit opt-in is not to have perf penalty with
2386 * slow sched_clocks.
2387 */
2388extern void enable_sched_clock_irqtime(void);
2389extern void disable_sched_clock_irqtime(void);
2390#else
2391static inline void enable_sched_clock_irqtime(void) {}
2392static inline void disable_sched_clock_irqtime(void) {}
2393#endif
2394
36c8b586 2395extern unsigned long long
41b86e9c 2396task_sched_runtime(struct task_struct *task);
1da177e4
LT
2397
2398/* sched_exec is called by processes performing an exec */
2399#ifdef CONFIG_SMP
2400extern void sched_exec(void);
2401#else
2402#define sched_exec() {}
2403#endif
2404
2aa44d05
IM
2405extern void sched_clock_idle_sleep_event(void);
2406extern void sched_clock_idle_wakeup_event(u64 delta_ns);
bb29ab26 2407
1da177e4
LT
2408#ifdef CONFIG_HOTPLUG_CPU
2409extern void idle_task_exit(void);
2410#else
2411static inline void idle_task_exit(void) {}
2412#endif
2413
3451d024 2414#if defined(CONFIG_NO_HZ_COMMON) && defined(CONFIG_SMP)
1c20091e 2415extern void wake_up_nohz_cpu(int cpu);
06d8308c 2416#else
1c20091e 2417static inline void wake_up_nohz_cpu(int cpu) { }
06d8308c
TG
2418#endif
2419
ce831b38 2420#ifdef CONFIG_NO_HZ_FULL
265f22a9 2421extern u64 scheduler_tick_max_deferment(void);
06d8308c
TG
2422#endif
2423
5091faa4 2424#ifdef CONFIG_SCHED_AUTOGROUP
5091faa4
MG
2425extern void sched_autogroup_create_attach(struct task_struct *p);
2426extern void sched_autogroup_detach(struct task_struct *p);
2427extern void sched_autogroup_fork(struct signal_struct *sig);
2428extern void sched_autogroup_exit(struct signal_struct *sig);
2429#ifdef CONFIG_PROC_FS
2430extern void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m);
2e5b5b3a 2431extern int proc_sched_autogroup_set_nice(struct task_struct *p, int nice);
5091faa4
MG
2432#endif
2433#else
2434static inline void sched_autogroup_create_attach(struct task_struct *p) { }
2435static inline void sched_autogroup_detach(struct task_struct *p) { }
2436static inline void sched_autogroup_fork(struct signal_struct *sig) { }
2437static inline void sched_autogroup_exit(struct signal_struct *sig) { }
2438#endif
2439
fa93384f 2440extern int yield_to(struct task_struct *p, bool preempt);
36c8b586
IM
2441extern void set_user_nice(struct task_struct *p, long nice);
2442extern int task_prio(const struct task_struct *p);
d0ea0268
DY
2443/**
2444 * task_nice - return the nice value of a given task.
2445 * @p: the task in question.
2446 *
2447 * Return: The nice value [ -20 ... 0 ... 19 ].
2448 */
2449static inline int task_nice(const struct task_struct *p)
2450{
2451 return PRIO_TO_NICE((p)->static_prio);
2452}
36c8b586
IM
2453extern int can_nice(const struct task_struct *p, const int nice);
2454extern int task_curr(const struct task_struct *p);
1da177e4 2455extern int idle_cpu(int cpu);
fe7de49f
KM
2456extern int sched_setscheduler(struct task_struct *, int,
2457 const struct sched_param *);
961ccddd 2458extern int sched_setscheduler_nocheck(struct task_struct *, int,
fe7de49f 2459 const struct sched_param *);
d50dde5a
DF
2460extern int sched_setattr(struct task_struct *,
2461 const struct sched_attr *);
36c8b586 2462extern struct task_struct *idle_task(int cpu);
c4f30608
PM
2463/**
2464 * is_idle_task - is the specified task an idle task?
fa757281 2465 * @p: the task in question.
e69f6186
YB
2466 *
2467 * Return: 1 if @p is an idle task. 0 otherwise.
c4f30608 2468 */
7061ca3b 2469static inline bool is_idle_task(const struct task_struct *p)
c4f30608
PM
2470{
2471 return p->pid == 0;
2472}
36c8b586
IM
2473extern struct task_struct *curr_task(int cpu);
2474extern void set_curr_task(int cpu, struct task_struct *p);
1da177e4
LT
2475
2476void yield(void);
2477
1da177e4
LT
2478union thread_union {
2479 struct thread_info thread_info;
2480 unsigned long stack[THREAD_SIZE/sizeof(long)];
2481};
2482
2483#ifndef __HAVE_ARCH_KSTACK_END
2484static inline int kstack_end(void *addr)
2485{
2486 /* Reliable end of stack detection:
2487 * Some APM bios versions misalign the stack
2488 */
2489 return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
2490}
2491#endif
2492
2493extern union thread_union init_thread_union;
2494extern struct task_struct init_task;
2495
2496extern struct mm_struct init_mm;
2497
198fe21b
PE
2498extern struct pid_namespace init_pid_ns;
2499
2500/*
2501 * find a task by one of its numerical ids
2502 *
198fe21b
PE
2503 * find_task_by_pid_ns():
2504 * finds a task by its pid in the specified namespace
228ebcbe
PE
2505 * find_task_by_vpid():
2506 * finds a task by its virtual pid
198fe21b 2507 *
e49859e7 2508 * see also find_vpid() etc in include/linux/pid.h
198fe21b
PE
2509 */
2510
228ebcbe
PE
2511extern struct task_struct *find_task_by_vpid(pid_t nr);
2512extern struct task_struct *find_task_by_pid_ns(pid_t nr,
2513 struct pid_namespace *ns);
198fe21b 2514
1da177e4 2515/* per-UID process charging. */
7b44ab97 2516extern struct user_struct * alloc_uid(kuid_t);
1da177e4
LT
2517static inline struct user_struct *get_uid(struct user_struct *u)
2518{
2519 atomic_inc(&u->__count);
2520 return u;
2521}
2522extern void free_uid(struct user_struct *);
1da177e4
LT
2523
2524#include <asm/current.h>
2525
f0af911a 2526extern void xtime_update(unsigned long ticks);
1da177e4 2527
b3c97528
HH
2528extern int wake_up_state(struct task_struct *tsk, unsigned int state);
2529extern int wake_up_process(struct task_struct *tsk);
3e51e3ed 2530extern void wake_up_new_task(struct task_struct *tsk);
1da177e4
LT
2531#ifdef CONFIG_SMP
2532 extern void kick_process(struct task_struct *tsk);
2533#else
2534 static inline void kick_process(struct task_struct *tsk) { }
2535#endif
aab03e05 2536extern int sched_fork(unsigned long clone_flags, struct task_struct *p);
ad46c2c4 2537extern void sched_dead(struct task_struct *p);
1da177e4 2538
1da177e4
LT
2539extern void proc_caches_init(void);
2540extern void flush_signals(struct task_struct *);
10ab825b 2541extern void ignore_signals(struct task_struct *);
1da177e4
LT
2542extern void flush_signal_handlers(struct task_struct *, int force_default);
2543extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
2544
be0e6f29 2545static inline int kernel_dequeue_signal(siginfo_t *info)
1da177e4 2546{
be0e6f29
ON
2547 struct task_struct *tsk = current;
2548 siginfo_t __info;
1da177e4
LT
2549 int ret;
2550
be0e6f29
ON
2551 spin_lock_irq(&tsk->sighand->siglock);
2552 ret = dequeue_signal(tsk, &tsk->blocked, info ?: &__info);
2553 spin_unlock_irq(&tsk->sighand->siglock);
1da177e4
LT
2554
2555 return ret;
53c8f9f1 2556}
1da177e4 2557
9a13049e
ON
2558static inline void kernel_signal_stop(void)
2559{
2560 spin_lock_irq(&current->sighand->siglock);
2561 if (current->jobctl & JOBCTL_STOP_DEQUEUED)
2562 __set_current_state(TASK_STOPPED);
2563 spin_unlock_irq(&current->sighand->siglock);
2564
2565 schedule();
2566}
2567
1da177e4
LT
2568extern void release_task(struct task_struct * p);
2569extern int send_sig_info(int, struct siginfo *, struct task_struct *);
1da177e4
LT
2570extern int force_sigsegv(int, struct task_struct *);
2571extern int force_sig_info(int, struct siginfo *, struct task_struct *);
c4b92fc1 2572extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
c4b92fc1 2573extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
d178bc3a
SH
2574extern int kill_pid_info_as_cred(int, struct siginfo *, struct pid *,
2575 const struct cred *, u32);
c4b92fc1
EB
2576extern int kill_pgrp(struct pid *pid, int sig, int priv);
2577extern int kill_pid(struct pid *pid, int sig, int priv);
c3de4b38 2578extern int kill_proc_info(int, struct siginfo *, pid_t);
86773473 2579extern __must_check bool do_notify_parent(struct task_struct *, int);
a7f0765e 2580extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent);
1da177e4 2581extern void force_sig(int, struct task_struct *);
1da177e4 2582extern int send_sig(int, struct task_struct *, int);
09faef11 2583extern int zap_other_threads(struct task_struct *p);
1da177e4
LT
2584extern struct sigqueue *sigqueue_alloc(void);
2585extern void sigqueue_free(struct sigqueue *);
ac5c2153 2586extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group);
9ac95f2f 2587extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
1da177e4 2588
51a7b448
AV
2589static inline void restore_saved_sigmask(void)
2590{
2591 if (test_and_clear_restore_sigmask())
77097ae5 2592 __set_current_blocked(&current->saved_sigmask);
51a7b448
AV
2593}
2594
b7f9a11a
AV
2595static inline sigset_t *sigmask_to_save(void)
2596{
2597 sigset_t *res = &current->blocked;
2598 if (unlikely(test_restore_sigmask()))
2599 res = &current->saved_sigmask;
2600 return res;
2601}
2602
9ec52099
CLG
2603static inline int kill_cad_pid(int sig, int priv)
2604{
2605 return kill_pid(cad_pid, sig, priv);
2606}
2607
1da177e4
LT
2608/* These can be the second arg to send_sig_info/send_group_sig_info. */
2609#define SEND_SIG_NOINFO ((struct siginfo *) 0)
2610#define SEND_SIG_PRIV ((struct siginfo *) 1)
2611#define SEND_SIG_FORCED ((struct siginfo *) 2)
2612
2a855dd0
SAS
2613/*
2614 * True if we are on the alternate signal stack.
2615 */
1da177e4
LT
2616static inline int on_sig_stack(unsigned long sp)
2617{
2a855dd0
SAS
2618#ifdef CONFIG_STACK_GROWSUP
2619 return sp >= current->sas_ss_sp &&
2620 sp - current->sas_ss_sp < current->sas_ss_size;
2621#else
2622 return sp > current->sas_ss_sp &&
2623 sp - current->sas_ss_sp <= current->sas_ss_size;
2624#endif
1da177e4
LT
2625}
2626
2627static inline int sas_ss_flags(unsigned long sp)
2628{
72f15c03
RW
2629 if (!current->sas_ss_size)
2630 return SS_DISABLE;
2631
2632 return on_sig_stack(sp) ? SS_ONSTACK : 0;
1da177e4
LT
2633}
2634
5a1b98d3
AV
2635static inline unsigned long sigsp(unsigned long sp, struct ksignal *ksig)
2636{
2637 if (unlikely((ksig->ka.sa.sa_flags & SA_ONSTACK)) && ! sas_ss_flags(sp))
2638#ifdef CONFIG_STACK_GROWSUP
2639 return current->sas_ss_sp;
2640#else
2641 return current->sas_ss_sp + current->sas_ss_size;
2642#endif
2643 return sp;
2644}
2645
1da177e4
LT
2646/*
2647 * Routines for handling mm_structs
2648 */
2649extern struct mm_struct * mm_alloc(void);
2650
2651/* mmdrop drops the mm and the page tables */
b3c97528 2652extern void __mmdrop(struct mm_struct *);
1da177e4
LT
2653static inline void mmdrop(struct mm_struct * mm)
2654{
6fb43d7b 2655 if (unlikely(atomic_dec_and_test(&mm->mm_count)))
1da177e4
LT
2656 __mmdrop(mm);
2657}
2658
2659/* mmput gets rid of the mappings and all user-space */
2660extern void mmput(struct mm_struct *);
2661/* Grab a reference to a task's mm, if it is not already going away */
2662extern struct mm_struct *get_task_mm(struct task_struct *task);
8cdb878d
CY
2663/*
2664 * Grab a reference to a task's mm, if it is not already going away
2665 * and ptrace_may_access with the mode parameter passed to it
2666 * succeeds.
2667 */
2668extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode);
1da177e4
LT
2669/* Remove the current tasks stale references to the old mm_struct */
2670extern void mm_release(struct task_struct *, struct mm_struct *);
2671
3033f14a
JT
2672#ifdef CONFIG_HAVE_COPY_THREAD_TLS
2673extern int copy_thread_tls(unsigned long, unsigned long, unsigned long,
2674 struct task_struct *, unsigned long);
2675#else
6f2c55b8 2676extern int copy_thread(unsigned long, unsigned long, unsigned long,
afa86fc4 2677 struct task_struct *);
3033f14a
JT
2678
2679/* Architectures that haven't opted into copy_thread_tls get the tls argument
2680 * via pt_regs, so ignore the tls argument passed via C. */
2681static inline int copy_thread_tls(
2682 unsigned long clone_flags, unsigned long sp, unsigned long arg,
2683 struct task_struct *p, unsigned long tls)
2684{
2685 return copy_thread(clone_flags, sp, arg, p);
2686}
2687#endif
1da177e4
LT
2688extern void flush_thread(void);
2689extern void exit_thread(void);
2690
1da177e4 2691extern void exit_files(struct task_struct *);
a7e5328a 2692extern void __cleanup_sighand(struct sighand_struct *);
cbaffba1 2693
1da177e4 2694extern void exit_itimers(struct signal_struct *);
cbaffba1 2695extern void flush_itimer_signals(void);
1da177e4 2696
9402c95f 2697extern void do_group_exit(int);
1da177e4 2698
c4ad8f98 2699extern int do_execve(struct filename *,
d7627467 2700 const char __user * const __user *,
da3d4c5f 2701 const char __user * const __user *);
51f39a1f
DD
2702extern int do_execveat(int, struct filename *,
2703 const char __user * const __user *,
2704 const char __user * const __user *,
2705 int);
3033f14a 2706extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long);
e80d6661 2707extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *);
36c8b586 2708struct task_struct *fork_idle(int);
2aa3a7f8 2709extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
1da177e4 2710
82b89778
AH
2711extern void __set_task_comm(struct task_struct *tsk, const char *from, bool exec);
2712static inline void set_task_comm(struct task_struct *tsk, const char *from)
2713{
2714 __set_task_comm(tsk, from, false);
2715}
59714d65 2716extern char *get_task_comm(char *to, struct task_struct *tsk);
1da177e4
LT
2717
2718#ifdef CONFIG_SMP
317f3941 2719void scheduler_ipi(void);
85ba2d86 2720extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
1da177e4 2721#else
184748cc 2722static inline void scheduler_ipi(void) { }
85ba2d86
RM
2723static inline unsigned long wait_task_inactive(struct task_struct *p,
2724 long match_state)
2725{
2726 return 1;
2727}
1da177e4
LT
2728#endif
2729
fafe870f
FW
2730#define tasklist_empty() \
2731 list_empty(&init_task.tasks)
2732
05725f7e
JP
2733#define next_task(p) \
2734 list_entry_rcu((p)->tasks.next, struct task_struct, tasks)
1da177e4
LT
2735
2736#define for_each_process(p) \
2737 for (p = &init_task ; (p = next_task(p)) != &init_task ; )
2738
5bb459bb 2739extern bool current_is_single_threaded(void);
d84f4f99 2740
1da177e4
LT
2741/*
2742 * Careful: do_each_thread/while_each_thread is a double loop so
2743 * 'break' will not work as expected - use goto instead.
2744 */
2745#define do_each_thread(g, t) \
2746 for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
2747
2748#define while_each_thread(g, t) \
2749 while ((t = next_thread(t)) != g)
2750
0c740d0a
ON
2751#define __for_each_thread(signal, t) \
2752 list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node)
2753
2754#define for_each_thread(p, t) \
2755 __for_each_thread((p)->signal, t)
2756
2757/* Careful: this is a double loop, 'break' won't work as expected. */
2758#define for_each_process_thread(p, t) \
2759 for_each_process(p) for_each_thread(p, t)
2760
7e49827c
ON
2761static inline int get_nr_threads(struct task_struct *tsk)
2762{
b3ac022c 2763 return tsk->signal->nr_threads;
7e49827c
ON
2764}
2765
087806b1
ON
2766static inline bool thread_group_leader(struct task_struct *p)
2767{
2768 return p->exit_signal >= 0;
2769}
1da177e4 2770
0804ef4b
EB
2771/* Do to the insanities of de_thread it is possible for a process
2772 * to have the pid of the thread group leader without actually being
2773 * the thread group leader. For iteration through the pids in proc
2774 * all we care about is that we have a task with the appropriate
2775 * pid, we don't actually care if we have the right task.
2776 */
e1403b8e 2777static inline bool has_group_leader_pid(struct task_struct *p)
0804ef4b 2778{
e1403b8e 2779 return task_pid(p) == p->signal->leader_pid;
0804ef4b
EB
2780}
2781
bac0abd6 2782static inline
e1403b8e 2783bool same_thread_group(struct task_struct *p1, struct task_struct *p2)
bac0abd6 2784{
e1403b8e 2785 return p1->signal == p2->signal;
bac0abd6
PE
2786}
2787
36c8b586 2788static inline struct task_struct *next_thread(const struct task_struct *p)
47e65328 2789{
05725f7e
JP
2790 return list_entry_rcu(p->thread_group.next,
2791 struct task_struct, thread_group);
47e65328
ON
2792}
2793
e868171a 2794static inline int thread_group_empty(struct task_struct *p)
1da177e4 2795{
47e65328 2796 return list_empty(&p->thread_group);
1da177e4
LT
2797}
2798
2799#define delay_group_leader(p) \
2800 (thread_group_leader(p) && !thread_group_empty(p))
2801
1da177e4 2802/*
260ea101 2803 * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
22e2c507 2804 * subscriptions and synchronises with wait4(). Also used in procfs. Also
ddbcc7e8 2805 * pins the final release of task.io_context. Also protects ->cpuset and
d68b46fe 2806 * ->cgroup.subsys[]. And ->vfork_done.
1da177e4
LT
2807 *
2808 * Nests both inside and outside of read_lock(&tasklist_lock).
2809 * It must not be nested with write_lock_irq(&tasklist_lock),
2810 * neither inside nor outside.
2811 */
2812static inline void task_lock(struct task_struct *p)
2813{
2814 spin_lock(&p->alloc_lock);
2815}
2816
2817static inline void task_unlock(struct task_struct *p)
2818{
2819 spin_unlock(&p->alloc_lock);
2820}
2821
b8ed374e 2822extern struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
f63ee72e
ON
2823 unsigned long *flags);
2824
9388dc30
AV
2825static inline struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
2826 unsigned long *flags)
2827{
2828 struct sighand_struct *ret;
2829
2830 ret = __lock_task_sighand(tsk, flags);
2831 (void)__cond_lock(&tsk->sighand->siglock, ret);
2832 return ret;
2833}
b8ed374e 2834
f63ee72e
ON
2835static inline void unlock_task_sighand(struct task_struct *tsk,
2836 unsigned long *flags)
2837{
2838 spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
2839}
2840
77e4ef99 2841/**
7d7efec3
TH
2842 * threadgroup_change_begin - mark the beginning of changes to a threadgroup
2843 * @tsk: task causing the changes
77e4ef99 2844 *
7d7efec3
TH
2845 * All operations which modify a threadgroup - a new thread joining the
2846 * group, death of a member thread (the assertion of PF_EXITING) and
2847 * exec(2) dethreading the process and replacing the leader - are wrapped
2848 * by threadgroup_change_{begin|end}(). This is to provide a place which
2849 * subsystems needing threadgroup stability can hook into for
2850 * synchronization.
77e4ef99 2851 */
7d7efec3 2852static inline void threadgroup_change_begin(struct task_struct *tsk)
4714d1d3 2853{
7d7efec3
TH
2854 might_sleep();
2855 cgroup_threadgroup_change_begin(tsk);
4714d1d3 2856}
77e4ef99
TH
2857
2858/**
7d7efec3
TH
2859 * threadgroup_change_end - mark the end of changes to a threadgroup
2860 * @tsk: task causing the changes
77e4ef99 2861 *
7d7efec3 2862 * See threadgroup_change_begin().
77e4ef99 2863 */
7d7efec3 2864static inline void threadgroup_change_end(struct task_struct *tsk)
4714d1d3 2865{
7d7efec3 2866 cgroup_threadgroup_change_end(tsk);
4714d1d3 2867}
4714d1d3 2868
f037360f
AV
2869#ifndef __HAVE_THREAD_FUNCTIONS
2870
f7e4217b
RZ
2871#define task_thread_info(task) ((struct thread_info *)(task)->stack)
2872#define task_stack_page(task) ((task)->stack)
a1261f54 2873
10ebffde
AV
2874static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
2875{
2876 *task_thread_info(p) = *task_thread_info(org);
2877 task_thread_info(p)->task = p;
2878}
2879
6a40281a
CE
2880/*
2881 * Return the address of the last usable long on the stack.
2882 *
2883 * When the stack grows down, this is just above the thread
2884 * info struct. Going any lower will corrupt the threadinfo.
2885 *
2886 * When the stack grows up, this is the highest address.
2887 * Beyond that position, we corrupt data on the next page.
2888 */
10ebffde
AV
2889static inline unsigned long *end_of_stack(struct task_struct *p)
2890{
6a40281a
CE
2891#ifdef CONFIG_STACK_GROWSUP
2892 return (unsigned long *)((unsigned long)task_thread_info(p) + THREAD_SIZE) - 1;
2893#else
f7e4217b 2894 return (unsigned long *)(task_thread_info(p) + 1);
6a40281a 2895#endif
10ebffde
AV
2896}
2897
f037360f 2898#endif
a70857e4
AT
2899#define task_stack_end_corrupted(task) \
2900 (*(end_of_stack(task)) != STACK_END_MAGIC)
f037360f 2901
8b05c7e6
FT
2902static inline int object_is_on_stack(void *obj)
2903{
2904 void *stack = task_stack_page(current);
2905
2906 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
2907}
2908
8c9843e5
BH
2909extern void thread_info_cache_init(void);
2910
7c9f8861
ES
2911#ifdef CONFIG_DEBUG_STACK_USAGE
2912static inline unsigned long stack_not_used(struct task_struct *p)
2913{
2914 unsigned long *n = end_of_stack(p);
2915
2916 do { /* Skip over canary */
6c31da34
HD
2917# ifdef CONFIG_STACK_GROWSUP
2918 n--;
2919# else
7c9f8861 2920 n++;
6c31da34 2921# endif
7c9f8861
ES
2922 } while (!*n);
2923
6c31da34
HD
2924# ifdef CONFIG_STACK_GROWSUP
2925 return (unsigned long)end_of_stack(p) - (unsigned long)n;
2926# else
7c9f8861 2927 return (unsigned long)n - (unsigned long)end_of_stack(p);
6c31da34 2928# endif
7c9f8861
ES
2929}
2930#endif
d4311ff1 2931extern void set_task_stack_end_magic(struct task_struct *tsk);
7c9f8861 2932
1da177e4
LT
2933/* set thread flags in other task's structures
2934 * - see asm/thread_info.h for TIF_xxxx flags available
2935 */
2936static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
2937{
a1261f54 2938 set_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4
LT
2939}
2940
2941static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
2942{
a1261f54 2943 clear_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4
LT
2944}
2945
2946static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
2947{
a1261f54 2948 return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4
LT
2949}
2950
2951static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
2952{
a1261f54 2953 return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4
LT
2954}
2955
2956static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
2957{
a1261f54 2958 return test_ti_thread_flag(task_thread_info(tsk), flag);
1da177e4
LT
2959}
2960
2961static inline void set_tsk_need_resched(struct task_struct *tsk)
2962{
2963 set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
2964}
2965
2966static inline void clear_tsk_need_resched(struct task_struct *tsk)
2967{
2968 clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
2969}
2970
8ae121ac
GH
2971static inline int test_tsk_need_resched(struct task_struct *tsk)
2972{
2973 return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
2974}
2975
690cc3ff
EB
2976static inline int restart_syscall(void)
2977{
2978 set_tsk_thread_flag(current, TIF_SIGPENDING);
2979 return -ERESTARTNOINTR;
2980}
2981
1da177e4
LT
2982static inline int signal_pending(struct task_struct *p)
2983{
2984 return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
2985}
f776d12d 2986
d9588725
RM
2987static inline int __fatal_signal_pending(struct task_struct *p)
2988{
2989 return unlikely(sigismember(&p->pending.signal, SIGKILL));
2990}
f776d12d
MW
2991
2992static inline int fatal_signal_pending(struct task_struct *p)
2993{
2994 return signal_pending(p) && __fatal_signal_pending(p);
2995}
2996
16882c1e
ON
2997static inline int signal_pending_state(long state, struct task_struct *p)
2998{
2999 if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
3000 return 0;
3001 if (!signal_pending(p))
3002 return 0;
3003
16882c1e
ON
3004 return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
3005}
3006
1da177e4
LT
3007/*
3008 * cond_resched() and cond_resched_lock(): latency reduction via
3009 * explicit rescheduling in places that are safe. The return
3010 * value indicates whether a reschedule was done in fact.
3011 * cond_resched_lock() will drop the spinlock before scheduling,
3012 * cond_resched_softirq() will enable bhs before scheduling.
3013 */
c3921ab7 3014extern int _cond_resched(void);
6f80bd98 3015
613afbf8 3016#define cond_resched() ({ \
3427445a 3017 ___might_sleep(__FILE__, __LINE__, 0); \
613afbf8
FW
3018 _cond_resched(); \
3019})
6f80bd98 3020
613afbf8
FW
3021extern int __cond_resched_lock(spinlock_t *lock);
3022
3023#define cond_resched_lock(lock) ({ \
3427445a 3024 ___might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);\
613afbf8
FW
3025 __cond_resched_lock(lock); \
3026})
3027
3028extern int __cond_resched_softirq(void);
3029
75e1056f 3030#define cond_resched_softirq() ({ \
3427445a 3031 ___might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET); \
75e1056f 3032 __cond_resched_softirq(); \
613afbf8 3033})
1da177e4 3034
f6f3c437
SH
3035static inline void cond_resched_rcu(void)
3036{
3037#if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
3038 rcu_read_unlock();
3039 cond_resched();
3040 rcu_read_lock();
3041#endif
3042}
3043
1da177e4
LT
3044/*
3045 * Does a critical section need to be broken due to another
95c354fe
NP
3046 * task waiting?: (technically does not depend on CONFIG_PREEMPT,
3047 * but a general need for low latency)
1da177e4 3048 */
95c354fe 3049static inline int spin_needbreak(spinlock_t *lock)
1da177e4 3050{
95c354fe
NP
3051#ifdef CONFIG_PREEMPT
3052 return spin_is_contended(lock);
3053#else
1da177e4 3054 return 0;
95c354fe 3055#endif
1da177e4
LT
3056}
3057
ee761f62
TG
3058/*
3059 * Idle thread specific functions to determine the need_resched
69dd0f84 3060 * polling state.
ee761f62 3061 */
69dd0f84 3062#ifdef TIF_POLLING_NRFLAG
ee761f62
TG
3063static inline int tsk_is_polling(struct task_struct *p)
3064{
3065 return test_tsk_thread_flag(p, TIF_POLLING_NRFLAG);
3066}
ea811747
PZ
3067
3068static inline void __current_set_polling(void)
3a98f871
TG
3069{
3070 set_thread_flag(TIF_POLLING_NRFLAG);
3071}
3072
ea811747
PZ
3073static inline bool __must_check current_set_polling_and_test(void)
3074{
3075 __current_set_polling();
3076
3077 /*
3078 * Polling state must be visible before we test NEED_RESCHED,
8875125e 3079 * paired by resched_curr()
ea811747 3080 */
4e857c58 3081 smp_mb__after_atomic();
ea811747
PZ
3082
3083 return unlikely(tif_need_resched());
3084}
3085
3086static inline void __current_clr_polling(void)
3a98f871
TG
3087{
3088 clear_thread_flag(TIF_POLLING_NRFLAG);
3089}
ea811747
PZ
3090
3091static inline bool __must_check current_clr_polling_and_test(void)
3092{
3093 __current_clr_polling();
3094
3095 /*
3096 * Polling state must be visible before we test NEED_RESCHED,
8875125e 3097 * paired by resched_curr()
ea811747 3098 */
4e857c58 3099 smp_mb__after_atomic();
ea811747
PZ
3100
3101 return unlikely(tif_need_resched());
3102}
3103
ee761f62
TG
3104#else
3105static inline int tsk_is_polling(struct task_struct *p) { return 0; }
ea811747
PZ
3106static inline void __current_set_polling(void) { }
3107static inline void __current_clr_polling(void) { }
3108
3109static inline bool __must_check current_set_polling_and_test(void)
3110{
3111 return unlikely(tif_need_resched());
3112}
3113static inline bool __must_check current_clr_polling_and_test(void)
3114{
3115 return unlikely(tif_need_resched());
3116}
ee761f62
TG
3117#endif
3118
8cb75e0c
PZ
3119static inline void current_clr_polling(void)
3120{
3121 __current_clr_polling();
3122
3123 /*
3124 * Ensure we check TIF_NEED_RESCHED after we clear the polling bit.
3125 * Once the bit is cleared, we'll get IPIs with every new
3126 * TIF_NEED_RESCHED and the IPI handler, scheduler_ipi(), will also
3127 * fold.
3128 */
8875125e 3129 smp_mb(); /* paired with resched_curr() */
8cb75e0c
PZ
3130
3131 preempt_fold_need_resched();
3132}
3133
75f93fed
PZ
3134static __always_inline bool need_resched(void)
3135{
3136 return unlikely(tif_need_resched());
3137}
3138
f06febc9
FM
3139/*
3140 * Thread group CPU time accounting.
3141 */
4cd4c1b4 3142void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
4da94d49 3143void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
f06febc9 3144
7bb44ade
RM
3145/*
3146 * Reevaluate whether the task has signals pending delivery.
3147 * Wake the task if so.
3148 * This is required every time the blocked sigset_t changes.
3149 * callers must hold sighand->siglock.
3150 */
3151extern void recalc_sigpending_and_wake(struct task_struct *t);
1da177e4
LT
3152extern void recalc_sigpending(void);
3153
910ffdb1
ON
3154extern void signal_wake_up_state(struct task_struct *t, unsigned int state);
3155
3156static inline void signal_wake_up(struct task_struct *t, bool resume)
3157{
3158 signal_wake_up_state(t, resume ? TASK_WAKEKILL : 0);
3159}
3160static inline void ptrace_signal_wake_up(struct task_struct *t, bool resume)
3161{
3162 signal_wake_up_state(t, resume ? __TASK_TRACED : 0);
3163}
1da177e4
LT
3164
3165/*
3166 * Wrappers for p->thread_info->cpu access. No-op on UP.
3167 */
3168#ifdef CONFIG_SMP
3169
3170static inline unsigned int task_cpu(const struct task_struct *p)
3171{
a1261f54 3172 return task_thread_info(p)->cpu;
1da177e4
LT
3173}
3174
b32e86b4
IM
3175static inline int task_node(const struct task_struct *p)
3176{
3177 return cpu_to_node(task_cpu(p));
3178}
3179
c65cc870 3180extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
1da177e4
LT
3181
3182#else
3183
3184static inline unsigned int task_cpu(const struct task_struct *p)
3185{
3186 return 0;
3187}
3188
3189static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
3190{
3191}
3192
3193#endif /* CONFIG_SMP */
3194
96f874e2
RR
3195extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
3196extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
5c45bf27 3197
7c941438 3198#ifdef CONFIG_CGROUP_SCHED
07e06b01 3199extern struct task_group root_task_group;
8323f26c 3200#endif /* CONFIG_CGROUP_SCHED */
9b5b7751 3201
54e99124
DG
3202extern int task_can_switch_user(struct user_struct *up,
3203 struct task_struct *tsk);
3204
4b98d11b
AD
3205#ifdef CONFIG_TASK_XACCT
3206static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
3207{
940389b8 3208 tsk->ioac.rchar += amt;
4b98d11b
AD
3209}
3210
3211static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
3212{
940389b8 3213 tsk->ioac.wchar += amt;
4b98d11b
AD
3214}
3215
3216static inline void inc_syscr(struct task_struct *tsk)
3217{
940389b8 3218 tsk->ioac.syscr++;
4b98d11b
AD
3219}
3220
3221static inline void inc_syscw(struct task_struct *tsk)
3222{
940389b8 3223 tsk->ioac.syscw++;
4b98d11b
AD
3224}
3225#else
3226static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
3227{
3228}
3229
3230static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
3231{
3232}
3233
3234static inline void inc_syscr(struct task_struct *tsk)
3235{
3236}
3237
3238static inline void inc_syscw(struct task_struct *tsk)
3239{
3240}
3241#endif
3242
82455257
DH
3243#ifndef TASK_SIZE_OF
3244#define TASK_SIZE_OF(tsk) TASK_SIZE
3245#endif
3246
f98bafa0 3247#ifdef CONFIG_MEMCG
cf475ad2 3248extern void mm_update_next_owner(struct mm_struct *mm);
cf475ad2
BS
3249#else
3250static inline void mm_update_next_owner(struct mm_struct *mm)
3251{
3252}
f98bafa0 3253#endif /* CONFIG_MEMCG */
cf475ad2 3254
3e10e716
JS
3255static inline unsigned long task_rlimit(const struct task_struct *tsk,
3256 unsigned int limit)
3257{
316c1608 3258 return READ_ONCE(tsk->signal->rlim[limit].rlim_cur);
3e10e716
JS
3259}
3260
3261static inline unsigned long task_rlimit_max(const struct task_struct *tsk,
3262 unsigned int limit)
3263{
316c1608 3264 return READ_ONCE(tsk->signal->rlim[limit].rlim_max);
3e10e716
JS
3265}
3266
3267static inline unsigned long rlimit(unsigned int limit)
3268{
3269 return task_rlimit(current, limit);
3270}
3271
3272static inline unsigned long rlimit_max(unsigned int limit)
3273{
3274 return task_rlimit_max(current, limit);
3275}
3276
adaf9fcd
RW
3277#ifdef CONFIG_CPU_FREQ
3278struct update_util_data {
3279 void (*func)(struct update_util_data *data,
3280 u64 time, unsigned long util, unsigned long max);
3281};
3282
3283void cpufreq_set_update_util_data(int cpu, struct update_util_data *data);
3284#endif /* CONFIG_CPU_FREQ */
3285
1da177e4 3286#endif
This page took 2.088057 seconds and 5 git commands to generate.