11da177e4SLinus Torvalds #ifndef _LINUX_SCHED_H 21da177e4SLinus Torvalds #define _LINUX_SCHED_H 31da177e4SLinus Torvalds 4b7b3c76aSDavid Woodhouse /* 5b7b3c76aSDavid Woodhouse * cloning flags: 6b7b3c76aSDavid Woodhouse */ 7b7b3c76aSDavid Woodhouse #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */ 8b7b3c76aSDavid Woodhouse #define CLONE_VM 0x00000100 /* set if VM shared between processes */ 9b7b3c76aSDavid Woodhouse #define CLONE_FS 0x00000200 /* set if fs info shared between processes */ 10b7b3c76aSDavid Woodhouse #define CLONE_FILES 0x00000400 /* set if open files shared between processes */ 11b7b3c76aSDavid Woodhouse #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */ 12b7b3c76aSDavid Woodhouse #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */ 13b7b3c76aSDavid Woodhouse #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */ 14b7b3c76aSDavid Woodhouse #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */ 15b7b3c76aSDavid Woodhouse #define CLONE_THREAD 0x00010000 /* Same thread group? */ 16b7b3c76aSDavid Woodhouse #define CLONE_NEWNS 0x00020000 /* New namespace group? */ 17b7b3c76aSDavid Woodhouse #define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */ 18b7b3c76aSDavid Woodhouse #define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */ 19b7b3c76aSDavid Woodhouse #define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */ 20b7b3c76aSDavid Woodhouse #define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */ 21b7b3c76aSDavid Woodhouse #define CLONE_DETACHED 0x00400000 /* Unused, ignored */ 22b7b3c76aSDavid Woodhouse #define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */ 23b7b3c76aSDavid Woodhouse #define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */ 24b7b3c76aSDavid Woodhouse #define CLONE_STOPPED 0x02000000 /* Start in stopped state */ 25071df104SSerge E. Hallyn #define CLONE_NEWUTS 0x04000000 /* New utsname group? */ 2625b21cb2SKirill Korotaev #define CLONE_NEWIPC 0x08000000 /* New ipcs */ 2777ec739dSSerge E. Hallyn #define CLONE_NEWUSER 0x10000000 /* New user namespace */ 2830e49c26SPavel Emelyanov #define CLONE_NEWPID 0x20000000 /* New pid namespace */ 29169e3674SEric W. Biederman #define CLONE_NEWNET 0x40000000 /* New network namespace */ 30fadad878SJens Axboe #define CLONE_IO 0x80000000 /* Clone io context */ 31b7b3c76aSDavid Woodhouse 32b7b3c76aSDavid Woodhouse /* 33b7b3c76aSDavid Woodhouse * Scheduling policies 34b7b3c76aSDavid Woodhouse */ 35b7b3c76aSDavid Woodhouse #define SCHED_NORMAL 0 36b7b3c76aSDavid Woodhouse #define SCHED_FIFO 1 37b7b3c76aSDavid Woodhouse #define SCHED_RR 2 38b7b3c76aSDavid Woodhouse #define SCHED_BATCH 3 390e6aca43SIngo Molnar /* SCHED_ISO: reserved but not implemented yet */ 400e6aca43SIngo Molnar #define SCHED_IDLE 5 41ca94c442SLennart Poettering /* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */ 42ca94c442SLennart Poettering #define SCHED_RESET_ON_FORK 0x40000000 43b7b3c76aSDavid Woodhouse 44a3b6714eSDavid Woodhouse #ifdef __KERNEL__ 45b7b3c76aSDavid Woodhouse 46b7b3c76aSDavid Woodhouse struct sched_param { 47b7b3c76aSDavid Woodhouse int sched_priority; 48b7b3c76aSDavid Woodhouse }; 49b7b3c76aSDavid Woodhouse 501da177e4SLinus Torvalds #include <asm/param.h> /* for HZ */ 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds #include <linux/capability.h> 531da177e4SLinus Torvalds #include <linux/threads.h> 541da177e4SLinus Torvalds #include <linux/kernel.h> 551da177e4SLinus Torvalds #include <linux/types.h> 561da177e4SLinus Torvalds #include <linux/timex.h> 571da177e4SLinus Torvalds #include <linux/jiffies.h> 581da177e4SLinus Torvalds #include <linux/rbtree.h> 591da177e4SLinus Torvalds #include <linux/thread_info.h> 601da177e4SLinus Torvalds #include <linux/cpumask.h> 611da177e4SLinus Torvalds #include <linux/errno.h> 621da177e4SLinus Torvalds #include <linux/nodemask.h> 63c92ff1bdSMartin Schwidefsky #include <linux/mm_types.h> 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds #include <asm/system.h> 661da177e4SLinus Torvalds #include <asm/page.h> 671da177e4SLinus Torvalds #include <asm/ptrace.h> 681da177e4SLinus Torvalds #include <asm/cputime.h> 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds #include <linux/smp.h> 711da177e4SLinus Torvalds #include <linux/sem.h> 721da177e4SLinus Torvalds #include <linux/signal.h> 735ad4e53bSAl Viro #include <linux/path.h> 741da177e4SLinus Torvalds #include <linux/compiler.h> 751da177e4SLinus Torvalds #include <linux/completion.h> 761da177e4SLinus Torvalds #include <linux/pid.h> 771da177e4SLinus Torvalds #include <linux/percpu.h> 781da177e4SLinus Torvalds #include <linux/topology.h> 793e26c149SPeter Zijlstra #include <linux/proportions.h> 801da177e4SLinus Torvalds #include <linux/seccomp.h> 81e56d0903SIngo Molnar #include <linux/rcupdate.h> 8205725f7eSJiri Pirko #include <linux/rculist.h> 8323f78d4aSIngo Molnar #include <linux/rtmutex.h> 841da177e4SLinus Torvalds 85a3b6714eSDavid Woodhouse #include <linux/time.h> 86a3b6714eSDavid Woodhouse #include <linux/param.h> 87a3b6714eSDavid Woodhouse #include <linux/resource.h> 88a3b6714eSDavid Woodhouse #include <linux/timer.h> 89a3b6714eSDavid Woodhouse #include <linux/hrtimer.h> 907c3ab738SAndrew Morton #include <linux/task_io_accounting.h> 915cb350baSDhaval Giani #include <linux/kobject.h> 929745512cSArjan van de Ven #include <linux/latencytop.h> 939e2b2dc4SDavid Howells #include <linux/cred.h> 94a3b6714eSDavid Woodhouse 95a3b6714eSDavid Woodhouse #include <asm/processor.h> 9636d57ac4SH. J. Lu 971da177e4SLinus Torvalds struct exec_domain; 98c87e2837SIngo Molnar struct futex_pi_state; 99286100a6SAlexey Dobriyan struct robust_list_head; 100bddd87c7SAkinobu Mita struct bio_list; 1015ad4e53bSAl Viro struct fs_struct; 102e2b371f0SMarkus Metzger struct bts_context; 103cdd6c482SIngo Molnar struct perf_event_context; 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds /* 1061da177e4SLinus Torvalds * List of flags we want to share for kernel threads, 1071da177e4SLinus Torvalds * if only because they are not used by them anyway. 1081da177e4SLinus Torvalds */ 1091da177e4SLinus Torvalds #define CLONE_KERNEL (CLONE_FS | CLONE_FILES | CLONE_SIGHAND) 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /* 1121da177e4SLinus Torvalds * These are the constant used to fake the fixed-point load-average 1131da177e4SLinus Torvalds * counting. Some notes: 1141da177e4SLinus Torvalds * - 11 bit fractions expand to 22 bits by the multiplies: this gives 1151da177e4SLinus Torvalds * a load-average precision of 10 bits integer + 11 bits fractional 1161da177e4SLinus Torvalds * - if you want to count load-averages more often, you need more 1171da177e4SLinus Torvalds * precision, or rounding will get you. With 2-second counting freq, 1181da177e4SLinus Torvalds * the EXP_n values would be 1981, 2034 and 2043 if still using only 1191da177e4SLinus Torvalds * 11 bit fractions. 1201da177e4SLinus Torvalds */ 1211da177e4SLinus Torvalds extern unsigned long avenrun[]; /* Load averages */ 1222d02494fSThomas Gleixner extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift); 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds #define FSHIFT 11 /* nr of bits of precision */ 1251da177e4SLinus Torvalds #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ 1260c2043abSLinus Torvalds #define LOAD_FREQ (5*HZ+1) /* 5 sec intervals */ 1271da177e4SLinus Torvalds #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ 1281da177e4SLinus Torvalds #define EXP_5 2014 /* 1/exp(5sec/5min) */ 1291da177e4SLinus Torvalds #define EXP_15 2037 /* 1/exp(5sec/15min) */ 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \ 1321da177e4SLinus Torvalds load *= exp; \ 1331da177e4SLinus Torvalds load += n*(FIXED_1-exp); \ 1341da177e4SLinus Torvalds load >>= FSHIFT; 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds extern unsigned long total_forks; 1371da177e4SLinus Torvalds extern int nr_threads; 1381da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts); 1391da177e4SLinus Torvalds extern int nr_processes(void); 1401da177e4SLinus Torvalds extern unsigned long nr_running(void); 1411da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void); 1421da177e4SLinus Torvalds extern unsigned long nr_iowait(void); 14369d25870SArjan van de Ven extern unsigned long nr_iowait_cpu(void); 14469d25870SArjan van de Ven extern unsigned long this_cpu_load(void); 14569d25870SArjan van de Ven 14669d25870SArjan van de Ven 147dce48a84SThomas Gleixner extern void calc_global_load(void); 1481da177e4SLinus Torvalds 1497e49fcceSSteven Rostedt extern unsigned long get_parent_ip(unsigned long addr); 1507e49fcceSSteven Rostedt 15143ae34cbSIngo Molnar struct seq_file; 15243ae34cbSIngo Molnar struct cfs_rq; 1534cf86d77SIngo Molnar struct task_group; 15443ae34cbSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 15543ae34cbSIngo Molnar extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m); 15643ae34cbSIngo Molnar extern void proc_sched_set_task(struct task_struct *p); 15743ae34cbSIngo Molnar extern void 1585cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq); 15943ae34cbSIngo Molnar #else 16043ae34cbSIngo Molnar static inline void 16143ae34cbSIngo Molnar proc_sched_show_task(struct task_struct *p, struct seq_file *m) 16243ae34cbSIngo Molnar { 16343ae34cbSIngo Molnar } 16443ae34cbSIngo Molnar static inline void proc_sched_set_task(struct task_struct *p) 16543ae34cbSIngo Molnar { 16643ae34cbSIngo Molnar } 16743ae34cbSIngo Molnar static inline void 1685cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) 16943ae34cbSIngo Molnar { 17043ae34cbSIngo Molnar } 17143ae34cbSIngo Molnar #endif 1721da177e4SLinus Torvalds 1734a8342d2SLinus Torvalds /* 1744a8342d2SLinus Torvalds * Task state bitmask. NOTE! These bits are also 1754a8342d2SLinus Torvalds * encoded in fs/proc/array.c: get_task_state(). 1764a8342d2SLinus Torvalds * 1774a8342d2SLinus Torvalds * We have two separate sets of flags: task->state 1784a8342d2SLinus Torvalds * is about runnability, while task->exit_state are 1794a8342d2SLinus Torvalds * about the task exiting. Confusing, but this way 1804a8342d2SLinus Torvalds * modifying one set can't modify the other one by 1814a8342d2SLinus Torvalds * mistake. 1824a8342d2SLinus Torvalds */ 1831da177e4SLinus Torvalds #define TASK_RUNNING 0 1841da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE 1 1851da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE 2 186f021a3c2SMatthew Wilcox #define __TASK_STOPPED 4 187f021a3c2SMatthew Wilcox #define __TASK_TRACED 8 1884a8342d2SLinus Torvalds /* in tsk->exit_state */ 1894a8342d2SLinus Torvalds #define EXIT_ZOMBIE 16 1904a8342d2SLinus Torvalds #define EXIT_DEAD 32 1914a8342d2SLinus Torvalds /* in tsk->state again */ 192af927232SMike Galbraith #define TASK_DEAD 64 193f021a3c2SMatthew Wilcox #define TASK_WAKEKILL 128 194e9c84311SPeter Zijlstra #define TASK_WAKING 256 195e1781538SPeter Zijlstra #define TASK_STATE_MAX 512 196f021a3c2SMatthew Wilcox 19744d90df6SPeter Zijlstra #define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW" 19873342151SPeter Zijlstra 199e1781538SPeter Zijlstra extern char ___assert_task_state[1 - 2*!!( 200e1781538SPeter Zijlstra sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)]; 201f021a3c2SMatthew Wilcox 202f021a3c2SMatthew Wilcox /* Convenience macros for the sake of set_task_state */ 203f021a3c2SMatthew Wilcox #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) 204f021a3c2SMatthew Wilcox #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) 205f021a3c2SMatthew Wilcox #define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED) 2061da177e4SLinus Torvalds 20792a1f4bcSMatthew Wilcox /* Convenience macros for the sake of wake_up */ 20892a1f4bcSMatthew Wilcox #define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE) 209f021a3c2SMatthew Wilcox #define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED) 21092a1f4bcSMatthew Wilcox 21192a1f4bcSMatthew Wilcox /* get_task_state() */ 21292a1f4bcSMatthew Wilcox #define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \ 213f021a3c2SMatthew Wilcox TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \ 214f021a3c2SMatthew Wilcox __TASK_TRACED) 21592a1f4bcSMatthew Wilcox 216f021a3c2SMatthew Wilcox #define task_is_traced(task) ((task->state & __TASK_TRACED) != 0) 217f021a3c2SMatthew Wilcox #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0) 21892a1f4bcSMatthew Wilcox #define task_is_stopped_or_traced(task) \ 219f021a3c2SMatthew Wilcox ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0) 22092a1f4bcSMatthew Wilcox #define task_contributes_to_load(task) \ 221e3c8ca83SNathan Lynch ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \ 2226301cb95SThomas Gleixner (task->flags & PF_FREEZING) == 0) 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds #define __set_task_state(tsk, state_value) \ 2251da177e4SLinus Torvalds do { (tsk)->state = (state_value); } while (0) 2261da177e4SLinus Torvalds #define set_task_state(tsk, state_value) \ 2271da177e4SLinus Torvalds set_mb((tsk)->state, (state_value)) 2281da177e4SLinus Torvalds 229498d0c57SAndrew Morton /* 230498d0c57SAndrew Morton * set_current_state() includes a barrier so that the write of current->state 231498d0c57SAndrew Morton * is correctly serialised wrt the caller's subsequent test of whether to 232498d0c57SAndrew Morton * actually sleep: 233498d0c57SAndrew Morton * 234498d0c57SAndrew Morton * set_current_state(TASK_UNINTERRUPTIBLE); 235498d0c57SAndrew Morton * if (do_i_need_to_sleep()) 236498d0c57SAndrew Morton * schedule(); 237498d0c57SAndrew Morton * 238498d0c57SAndrew Morton * If the caller does not need such serialisation then use __set_current_state() 239498d0c57SAndrew Morton */ 2401da177e4SLinus Torvalds #define __set_current_state(state_value) \ 2411da177e4SLinus Torvalds do { current->state = (state_value); } while (0) 2421da177e4SLinus Torvalds #define set_current_state(state_value) \ 2431da177e4SLinus Torvalds set_mb(current->state, (state_value)) 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds /* Task command name length */ 2461da177e4SLinus Torvalds #define TASK_COMM_LEN 16 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds #include <linux/spinlock.h> 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds /* 2511da177e4SLinus Torvalds * This serializes "schedule()" and also protects 2521da177e4SLinus Torvalds * the run-queue from deletions/modifications (but 2531da177e4SLinus Torvalds * _adding_ to the beginning of the run-queue has 2541da177e4SLinus Torvalds * a separate lock). 2551da177e4SLinus Torvalds */ 2561da177e4SLinus Torvalds extern rwlock_t tasklist_lock; 2571da177e4SLinus Torvalds extern spinlock_t mmlist_lock; 2581da177e4SLinus Torvalds 25936c8b586SIngo Molnar struct task_struct; 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds extern void sched_init(void); 2621da177e4SLinus Torvalds extern void sched_init_smp(void); 2632d07b255SHarvey Harrison extern asmlinkage void schedule_tail(struct task_struct *prev); 26436c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu); 2651df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle); 2661da177e4SLinus Torvalds 26789f19f04SAndrew Morton extern int runqueue_is_locked(int cpu); 268ad474cacSOleg Nesterov extern void task_rq_unlock_wait(struct task_struct *p); 269017730c1SIngo Molnar 2706a7b3dc3SRusty Russell extern cpumask_var_t nohz_cpu_mask; 27146cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ) 27246cb4b7cSSiddha, Suresh B extern int select_nohz_load_balancer(int cpu); 273eea08f32SArun R Bharadwaj extern int get_nohz_load_balancer(void); 27446cb4b7cSSiddha, Suresh B #else 27546cb4b7cSSiddha, Suresh B static inline int select_nohz_load_balancer(int cpu) 27646cb4b7cSSiddha, Suresh B { 27746cb4b7cSSiddha, Suresh B return 0; 27846cb4b7cSSiddha, Suresh B } 27946cb4b7cSSiddha, Suresh B #endif 2801da177e4SLinus Torvalds 281e59e2ae2SIngo Molnar /* 28239bc89fdSIngo Molnar * Only dump TASK_* tasks. (0 for all tasks) 283e59e2ae2SIngo Molnar */ 284e59e2ae2SIngo Molnar extern void show_state_filter(unsigned long state_filter); 285e59e2ae2SIngo Molnar 286e59e2ae2SIngo Molnar static inline void show_state(void) 287e59e2ae2SIngo Molnar { 28839bc89fdSIngo Molnar show_state_filter(0); 289e59e2ae2SIngo Molnar } 290e59e2ae2SIngo Molnar 2911da177e4SLinus Torvalds extern void show_regs(struct pt_regs *); 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds /* 2941da177e4SLinus Torvalds * TASK is a pointer to the task whose backtrace we want to see (or NULL for current 2951da177e4SLinus Torvalds * task), SP is the stack pointer of the first frame that should be shown in the back 2961da177e4SLinus Torvalds * trace (or NULL if the entire call-chain of the task should be shown). 2971da177e4SLinus Torvalds */ 2981da177e4SLinus Torvalds extern void show_stack(struct task_struct *task, unsigned long *sp); 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds void io_schedule(void); 3011da177e4SLinus Torvalds long io_schedule_timeout(long timeout); 3021da177e4SLinus Torvalds 3031da177e4SLinus Torvalds extern void cpu_init (void); 3041da177e4SLinus Torvalds extern void trap_init(void); 3051da177e4SLinus Torvalds extern void update_process_times(int user); 3061da177e4SLinus Torvalds extern void scheduler_tick(void); 3071da177e4SLinus Torvalds 30882a1fcb9SIngo Molnar extern void sched_show_task(struct task_struct *p); 30982a1fcb9SIngo Molnar 3108446f1d3SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP 3116687a97dSIngo Molnar extern void softlockup_tick(void); 3128446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void); 313d6ad3e28SJason Wessel extern void touch_softlockup_watchdog_sync(void); 31404c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void); 315baf48f65SMandeep Singh Baines extern int proc_dosoftlockup_thresh(struct ctl_table *table, int write, 3168d65af78SAlexey Dobriyan void __user *buffer, 317baf48f65SMandeep Singh Baines size_t *lenp, loff_t *ppos); 3189c44bc03SIngo Molnar extern unsigned int softlockup_panic; 3199383d967SDimitri Sivanich extern int softlockup_thresh; 3208446f1d3SIngo Molnar #else 3216687a97dSIngo Molnar static inline void softlockup_tick(void) 3228446f1d3SIngo Molnar { 3238446f1d3SIngo Molnar } 3248446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void) 3258446f1d3SIngo Molnar { 3268446f1d3SIngo Molnar } 327d6ad3e28SJason Wessel static inline void touch_softlockup_watchdog_sync(void) 328d6ad3e28SJason Wessel { 329d6ad3e28SJason Wessel } 33004c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void) 33104c9167fSJeremy Fitzhardinge { 33204c9167fSJeremy Fitzhardinge } 3338446f1d3SIngo Molnar #endif 3348446f1d3SIngo Molnar 335e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK 336e162b39aSMandeep Singh Baines extern unsigned int sysctl_hung_task_panic; 337e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_check_count; 338e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_timeout_secs; 339e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_warnings; 340e162b39aSMandeep Singh Baines extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, 3418d65af78SAlexey Dobriyan void __user *buffer, 342e162b39aSMandeep Singh Baines size_t *lenp, loff_t *ppos); 343e162b39aSMandeep Singh Baines #endif 3448446f1d3SIngo Molnar 3451da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */ 3461da177e4SLinus Torvalds #define __sched __attribute__((__section__(".sched.text"))) 347deaf2227SIngo Molnar 348deaf2227SIngo Molnar /* Linker adds these: start and end of __sched functions */ 349deaf2227SIngo Molnar extern char __sched_text_start[], __sched_text_end[]; 350deaf2227SIngo Molnar 3511da177e4SLinus Torvalds /* Is this address in the __sched functions? */ 3521da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr); 3531da177e4SLinus Torvalds 3541da177e4SLinus Torvalds #define MAX_SCHEDULE_TIMEOUT LONG_MAX 355b3c97528SHarvey Harrison extern signed long schedule_timeout(signed long timeout); 35664ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout); 357294d5cc2SMatthew Wilcox extern signed long schedule_timeout_killable(signed long timeout); 35864ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout); 3591da177e4SLinus Torvalds asmlinkage void schedule(void); 3600d66bf6dSPeter Zijlstra extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner); 3611da177e4SLinus Torvalds 362ab516013SSerge E. Hallyn struct nsproxy; 363acce292cSCedric Le Goater struct user_namespace; 3641da177e4SLinus Torvalds 365341c87bfSKAMEZAWA Hiroyuki /* 366341c87bfSKAMEZAWA Hiroyuki * Default maximum number of active map areas, this limits the number of vmas 367341c87bfSKAMEZAWA Hiroyuki * per mm struct. Users can overwrite this number by sysctl but there is a 368341c87bfSKAMEZAWA Hiroyuki * problem. 369341c87bfSKAMEZAWA Hiroyuki * 370341c87bfSKAMEZAWA Hiroyuki * When a program's coredump is generated as ELF format, a section is created 371341c87bfSKAMEZAWA Hiroyuki * per a vma. In ELF, the number of sections is represented in unsigned short. 372341c87bfSKAMEZAWA Hiroyuki * This means the number of sections should be smaller than 65535 at coredump. 373341c87bfSKAMEZAWA Hiroyuki * Because the kernel adds some informative sections to a image of program at 374341c87bfSKAMEZAWA Hiroyuki * generating coredump, we need some margin. The number of extra sections is 375341c87bfSKAMEZAWA Hiroyuki * 1-3 now and depends on arch. We use "5" as safe margin, here. 376341c87bfSKAMEZAWA Hiroyuki */ 377341c87bfSKAMEZAWA Hiroyuki #define MAPCOUNT_ELF_CORE_MARGIN (5) 378341c87bfSKAMEZAWA Hiroyuki #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN) 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds extern int sysctl_max_map_count; 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds #include <linux/aio.h> 3831da177e4SLinus Torvalds 384efc1a3b1SDavid Howells #ifdef CONFIG_MMU 385efc1a3b1SDavid Howells extern void arch_pick_mmap_layout(struct mm_struct *mm); 3861da177e4SLinus Torvalds extern unsigned long 3871da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long, 3881da177e4SLinus Torvalds unsigned long, unsigned long); 3891da177e4SLinus Torvalds extern unsigned long 3901da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr, 3911da177e4SLinus Torvalds unsigned long len, unsigned long pgoff, 3921da177e4SLinus Torvalds unsigned long flags); 3931363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long); 3941363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long); 395efc1a3b1SDavid Howells #else 396efc1a3b1SDavid Howells static inline void arch_pick_mmap_layout(struct mm_struct *mm) {} 397efc1a3b1SDavid Howells #endif 3981da177e4SLinus Torvalds 399f7d0b926SJeremy Fitzhardinge #if USE_SPLIT_PTLOCKS 400f412ac08SHugh Dickins /* 401f412ac08SHugh Dickins * The mm counters are not protected by its page_table_lock, 402f412ac08SHugh Dickins * so must be incremented atomically. 403f412ac08SHugh Dickins */ 404d3cb4871SChristoph Lameter #define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value) 405d3cb4871SChristoph Lameter #define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member)) 406d3cb4871SChristoph Lameter #define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member) 407d3cb4871SChristoph Lameter #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member) 408d3cb4871SChristoph Lameter #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member) 409f412ac08SHugh Dickins 410f7d0b926SJeremy Fitzhardinge #else /* !USE_SPLIT_PTLOCKS */ 411f412ac08SHugh Dickins /* 412f412ac08SHugh Dickins * The mm counters are protected by its page_table_lock, 413f412ac08SHugh Dickins * so can be incremented directly. 414f412ac08SHugh Dickins */ 4151da177e4SLinus Torvalds #define set_mm_counter(mm, member, value) (mm)->_##member = (value) 4161da177e4SLinus Torvalds #define get_mm_counter(mm, member) ((mm)->_##member) 4171da177e4SLinus Torvalds #define add_mm_counter(mm, member, value) (mm)->_##member += (value) 4181da177e4SLinus Torvalds #define inc_mm_counter(mm, member) (mm)->_##member++ 4191da177e4SLinus Torvalds #define dec_mm_counter(mm, member) (mm)->_##member-- 4204294621fSHugh Dickins 421f7d0b926SJeremy Fitzhardinge #endif /* !USE_SPLIT_PTLOCKS */ 422f412ac08SHugh Dickins 423f412ac08SHugh Dickins #define get_mm_rss(mm) \ 424f412ac08SHugh Dickins (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss)) 425365e9c87SHugh Dickins #define update_hiwater_rss(mm) do { \ 426365e9c87SHugh Dickins unsigned long _rss = get_mm_rss(mm); \ 427365e9c87SHugh Dickins if ((mm)->hiwater_rss < _rss) \ 428365e9c87SHugh Dickins (mm)->hiwater_rss = _rss; \ 429365e9c87SHugh Dickins } while (0) 430365e9c87SHugh Dickins #define update_hiwater_vm(mm) do { \ 431365e9c87SHugh Dickins if ((mm)->hiwater_vm < (mm)->total_vm) \ 432365e9c87SHugh Dickins (mm)->hiwater_vm = (mm)->total_vm; \ 433365e9c87SHugh Dickins } while (0) 434365e9c87SHugh Dickins 4359de1581eSOleg Nesterov static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm) 4369de1581eSOleg Nesterov { 4379de1581eSOleg Nesterov return max(mm->hiwater_rss, get_mm_rss(mm)); 4389de1581eSOleg Nesterov } 4399de1581eSOleg Nesterov 4401f10206cSJiri Pirko static inline void setmax_mm_hiwater_rss(unsigned long *maxrss, 4411f10206cSJiri Pirko struct mm_struct *mm) 4421f10206cSJiri Pirko { 4431f10206cSJiri Pirko unsigned long hiwater_rss = get_mm_hiwater_rss(mm); 4441f10206cSJiri Pirko 4451f10206cSJiri Pirko if (*maxrss < hiwater_rss) 4461f10206cSJiri Pirko *maxrss = hiwater_rss; 4471f10206cSJiri Pirko } 4481f10206cSJiri Pirko 4499de1581eSOleg Nesterov static inline unsigned long get_mm_hiwater_vm(struct mm_struct *mm) 4509de1581eSOleg Nesterov { 4519de1581eSOleg Nesterov return max(mm->hiwater_vm, mm->total_vm); 4529de1581eSOleg Nesterov } 453901608d9SOleg Nesterov 4546c5d5238SKawai, Hidehiro extern void set_dumpable(struct mm_struct *mm, int value); 4556c5d5238SKawai, Hidehiro extern int get_dumpable(struct mm_struct *mm); 4566c5d5238SKawai, Hidehiro 4576c5d5238SKawai, Hidehiro /* mm flags */ 4583cb4a0bbSKawai, Hidehiro /* dumpable bits */ 4596c5d5238SKawai, Hidehiro #define MMF_DUMPABLE 0 /* core dump is permitted */ 4606c5d5238SKawai, Hidehiro #define MMF_DUMP_SECURELY 1 /* core file is readable only by root */ 461f8af4da3SHugh Dickins 4623cb4a0bbSKawai, Hidehiro #define MMF_DUMPABLE_BITS 2 463f8af4da3SHugh Dickins #define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1) 4643cb4a0bbSKawai, Hidehiro 4653cb4a0bbSKawai, Hidehiro /* coredump filter bits */ 4663cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_PRIVATE 2 4673cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_SHARED 3 4683cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_PRIVATE 4 4693cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_SHARED 5 47082df3973SRoland McGrath #define MMF_DUMP_ELF_HEADERS 6 471e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_PRIVATE 7 472e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_SHARED 8 473f8af4da3SHugh Dickins 4743cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS 475e575f111SKOSAKI Motohiro #define MMF_DUMP_FILTER_BITS 7 4763cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_MASK \ 4773cb4a0bbSKawai, Hidehiro (((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT) 4783cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_DEFAULT \ 479e575f111SKOSAKI Motohiro ((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED) |\ 480656eb2cdSRoland McGrath (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF) 481656eb2cdSRoland McGrath 482656eb2cdSRoland McGrath #ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS 483656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF (1 << MMF_DUMP_ELF_HEADERS) 484656eb2cdSRoland McGrath #else 485656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF 0 486656eb2cdSRoland McGrath #endif 487f8af4da3SHugh Dickins /* leave room for more dump flags */ 488f8af4da3SHugh Dickins #define MMF_VM_MERGEABLE 16 /* KSM may merge identical pages */ 489f8af4da3SHugh Dickins 490f8af4da3SHugh Dickins #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK) 4916c5d5238SKawai, Hidehiro 4921da177e4SLinus Torvalds struct sighand_struct { 4931da177e4SLinus Torvalds atomic_t count; 4941da177e4SLinus Torvalds struct k_sigaction action[_NSIG]; 4951da177e4SLinus Torvalds spinlock_t siglock; 496b8fceee1SDavide Libenzi wait_queue_head_t signalfd_wqh; 4971da177e4SLinus Torvalds }; 4981da177e4SLinus Torvalds 4990e464814SKaiGai Kohei struct pacct_struct { 500f6ec29a4SKaiGai Kohei int ac_flag; 501f6ec29a4SKaiGai Kohei long ac_exitcode; 5020e464814SKaiGai Kohei unsigned long ac_mem; 50377787bfbSKaiGai Kohei cputime_t ac_utime, ac_stime; 50477787bfbSKaiGai Kohei unsigned long ac_minflt, ac_majflt; 5050e464814SKaiGai Kohei }; 5060e464814SKaiGai Kohei 50742c4ab41SStanislaw Gruszka struct cpu_itimer { 50842c4ab41SStanislaw Gruszka cputime_t expires; 50942c4ab41SStanislaw Gruszka cputime_t incr; 5108356b5f9SStanislaw Gruszka u32 error; 5118356b5f9SStanislaw Gruszka u32 incr_error; 51242c4ab41SStanislaw Gruszka }; 51342c4ab41SStanislaw Gruszka 514f06febc9SFrank Mayhar /** 515f06febc9SFrank Mayhar * struct task_cputime - collected CPU time counts 516f06febc9SFrank Mayhar * @utime: time spent in user mode, in &cputime_t units 517f06febc9SFrank Mayhar * @stime: time spent in kernel mode, in &cputime_t units 518f06febc9SFrank Mayhar * @sum_exec_runtime: total time spent on the CPU, in nanoseconds 519f06febc9SFrank Mayhar * 520f06febc9SFrank Mayhar * This structure groups together three kinds of CPU time that are 521f06febc9SFrank Mayhar * tracked for threads and thread groups. Most things considering 522f06febc9SFrank Mayhar * CPU time want to group these counts together and treat all three 523f06febc9SFrank Mayhar * of them in parallel. 524f06febc9SFrank Mayhar */ 525f06febc9SFrank Mayhar struct task_cputime { 526f06febc9SFrank Mayhar cputime_t utime; 527f06febc9SFrank Mayhar cputime_t stime; 528f06febc9SFrank Mayhar unsigned long long sum_exec_runtime; 529f06febc9SFrank Mayhar }; 530f06febc9SFrank Mayhar /* Alternate field names when used to cache expirations. */ 531f06febc9SFrank Mayhar #define prof_exp stime 532f06febc9SFrank Mayhar #define virt_exp utime 533f06febc9SFrank Mayhar #define sched_exp sum_exec_runtime 534f06febc9SFrank Mayhar 5354cd4c1b4SPeter Zijlstra #define INIT_CPUTIME \ 5364cd4c1b4SPeter Zijlstra (struct task_cputime) { \ 5374cd4c1b4SPeter Zijlstra .utime = cputime_zero, \ 5384cd4c1b4SPeter Zijlstra .stime = cputime_zero, \ 5394cd4c1b4SPeter Zijlstra .sum_exec_runtime = 0, \ 5404cd4c1b4SPeter Zijlstra } 5414cd4c1b4SPeter Zijlstra 542c99e6efeSPeter Zijlstra /* 543c99e6efeSPeter Zijlstra * Disable preemption until the scheduler is running. 544c99e6efeSPeter Zijlstra * Reset by start_kernel()->sched_init()->init_idle(). 545d86ee480SPeter Zijlstra * 546d86ee480SPeter Zijlstra * We include PREEMPT_ACTIVE to avoid cond_resched() from working 547d86ee480SPeter Zijlstra * before the scheduler is active -- see should_resched(). 548c99e6efeSPeter Zijlstra */ 549d86ee480SPeter Zijlstra #define INIT_PREEMPT_COUNT (1 + PREEMPT_ACTIVE) 550c99e6efeSPeter Zijlstra 551f06febc9SFrank Mayhar /** 5524cd4c1b4SPeter Zijlstra * struct thread_group_cputimer - thread group interval timer counts 5534cd4c1b4SPeter Zijlstra * @cputime: thread group interval timers. 5544cd4c1b4SPeter Zijlstra * @running: non-zero when there are timers running and 5554cd4c1b4SPeter Zijlstra * @cputime receives updates. 5564cd4c1b4SPeter Zijlstra * @lock: lock for fields in this struct. 557f06febc9SFrank Mayhar * 558f06febc9SFrank Mayhar * This structure contains the version of task_cputime, above, that is 5594cd4c1b4SPeter Zijlstra * used for thread group CPU timer calculations. 560f06febc9SFrank Mayhar */ 5614cd4c1b4SPeter Zijlstra struct thread_group_cputimer { 5624cd4c1b4SPeter Zijlstra struct task_cputime cputime; 5634cd4c1b4SPeter Zijlstra int running; 5644cd4c1b4SPeter Zijlstra spinlock_t lock; 565f06febc9SFrank Mayhar }; 566f06febc9SFrank Mayhar 5671da177e4SLinus Torvalds /* 5681da177e4SLinus Torvalds * NOTE! "signal_struct" does not have it's own 5691da177e4SLinus Torvalds * locking, because a shared signal_struct always 5701da177e4SLinus Torvalds * implies a shared sighand_struct, so locking 5711da177e4SLinus Torvalds * sighand_struct is always a proper superset of 5721da177e4SLinus Torvalds * the locking of signal_struct. 5731da177e4SLinus Torvalds */ 5741da177e4SLinus Torvalds struct signal_struct { 5751da177e4SLinus Torvalds atomic_t count; 5761da177e4SLinus Torvalds atomic_t live; 5771da177e4SLinus Torvalds 5781da177e4SLinus Torvalds wait_queue_head_t wait_chldexit; /* for wait4() */ 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds /* current thread group signal load-balancing target: */ 58136c8b586SIngo Molnar struct task_struct *curr_target; 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds /* shared signal handling: */ 5841da177e4SLinus Torvalds struct sigpending shared_pending; 5851da177e4SLinus Torvalds 5861da177e4SLinus Torvalds /* thread group exit support */ 5871da177e4SLinus Torvalds int group_exit_code; 5881da177e4SLinus Torvalds /* overloaded: 5891da177e4SLinus Torvalds * - notify group_exit_task when ->count is equal to notify_count 5901da177e4SLinus Torvalds * - everyone except group_exit_task is stopped during signal delivery 5911da177e4SLinus Torvalds * of fatal signals, group_exit_task processes the signal. 5921da177e4SLinus Torvalds */ 5931da177e4SLinus Torvalds int notify_count; 59407dd20e0SRichard Kennedy struct task_struct *group_exit_task; 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds /* thread group stop support, overloads group_exit_code too */ 5971da177e4SLinus Torvalds int group_stop_count; 5981da177e4SLinus Torvalds unsigned int flags; /* see SIGNAL_* flags below */ 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds /* POSIX.1b Interval Timers */ 6011da177e4SLinus Torvalds struct list_head posix_timers; 6021da177e4SLinus Torvalds 6031da177e4SLinus Torvalds /* ITIMER_REAL timer for the process */ 6042ff678b8SThomas Gleixner struct hrtimer real_timer; 605fea9d175SOleg Nesterov struct pid *leader_pid; 6062ff678b8SThomas Gleixner ktime_t it_real_incr; 6071da177e4SLinus Torvalds 60842c4ab41SStanislaw Gruszka /* 60942c4ab41SStanislaw Gruszka * ITIMER_PROF and ITIMER_VIRTUAL timers for the process, we use 61042c4ab41SStanislaw Gruszka * CPUCLOCK_PROF and CPUCLOCK_VIRT for indexing array as these 61142c4ab41SStanislaw Gruszka * values are defined to 0 and 1 respectively 61242c4ab41SStanislaw Gruszka */ 61342c4ab41SStanislaw Gruszka struct cpu_itimer it[2]; 6141da177e4SLinus Torvalds 615f06febc9SFrank Mayhar /* 6164cd4c1b4SPeter Zijlstra * Thread group totals for process CPU timers. 6174cd4c1b4SPeter Zijlstra * See thread_group_cputimer(), et al, for details. 618f06febc9SFrank Mayhar */ 6194cd4c1b4SPeter Zijlstra struct thread_group_cputimer cputimer; 620f06febc9SFrank Mayhar 621f06febc9SFrank Mayhar /* Earliest-expiration cache. */ 622f06febc9SFrank Mayhar struct task_cputime cputime_expires; 623f06febc9SFrank Mayhar 624f06febc9SFrank Mayhar struct list_head cpu_timers[3]; 625f06febc9SFrank Mayhar 626ab521dc0SEric W. Biederman struct pid *tty_old_pgrp; 6271ec320afSCedric Le Goater 6281da177e4SLinus Torvalds /* boolean value for session group leader */ 6291da177e4SLinus Torvalds int leader; 6301da177e4SLinus Torvalds 6311da177e4SLinus Torvalds struct tty_struct *tty; /* NULL if no tty */ 6321da177e4SLinus Torvalds 6331da177e4SLinus Torvalds /* 6341da177e4SLinus Torvalds * Cumulative resource counters for dead threads in the group, 6351da177e4SLinus Torvalds * and for reaped dead child processes forked by this group. 6361da177e4SLinus Torvalds * Live threads maintain their own counters and add to these 6371da177e4SLinus Torvalds * in __exit_signal, except for the group leader. 6381da177e4SLinus Torvalds */ 63932bd671dSPeter Zijlstra cputime_t utime, stime, cutime, cstime; 6409ac52315SLaurent Vivier cputime_t gtime; 6419ac52315SLaurent Vivier cputime_t cgtime; 6420cf55e1eSHidetoshi Seto #ifndef CONFIG_VIRT_CPU_ACCOUNTING 6430cf55e1eSHidetoshi Seto cputime_t prev_utime, prev_stime; 6440cf55e1eSHidetoshi Seto #endif 6451da177e4SLinus Torvalds unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; 6461da177e4SLinus Torvalds unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; 6476eaeeabaSEric Dumazet unsigned long inblock, oublock, cinblock, coublock; 6481f10206cSJiri Pirko unsigned long maxrss, cmaxrss; 649940389b8SAndrea Righi struct task_io_accounting ioac; 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds /* 65232bd671dSPeter Zijlstra * Cumulative ns of schedule CPU time fo dead threads in the 65332bd671dSPeter Zijlstra * group, not including a zombie group leader, (This only differs 65432bd671dSPeter Zijlstra * from jiffies_to_ns(utime + stime) if sched_clock uses something 65532bd671dSPeter Zijlstra * other than jiffies.) 65632bd671dSPeter Zijlstra */ 65732bd671dSPeter Zijlstra unsigned long long sum_sched_runtime; 65832bd671dSPeter Zijlstra 65932bd671dSPeter Zijlstra /* 6601da177e4SLinus Torvalds * We don't bother to synchronize most readers of this at all, 6611da177e4SLinus Torvalds * because there is no reader checking a limit that actually needs 6621da177e4SLinus Torvalds * to get both rlim_cur and rlim_max atomically, and either one 6631da177e4SLinus Torvalds * alone is a single word that can safely be read normally. 6641da177e4SLinus Torvalds * getrlimit/setrlimit use task_lock(current->group_leader) to 6651da177e4SLinus Torvalds * protect this instead of the siglock, because they really 6661da177e4SLinus Torvalds * have no need to disable irqs. 6671da177e4SLinus Torvalds */ 6681da177e4SLinus Torvalds struct rlimit rlim[RLIM_NLIMITS]; 6691da177e4SLinus Torvalds 6700e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT 6710e464814SKaiGai Kohei struct pacct_struct pacct; /* per-process accounting information */ 6720e464814SKaiGai Kohei #endif 673ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS 674ad4ecbcbSShailabh Nagar struct taskstats *stats; 675ad4ecbcbSShailabh Nagar #endif 676522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT 677522ed776SMiloslav Trmac unsigned audit_tty; 678522ed776SMiloslav Trmac struct tty_audit_buf *tty_audit_buf; 679522ed776SMiloslav Trmac #endif 68028b83c51SKOSAKI Motohiro 68128b83c51SKOSAKI Motohiro int oom_adj; /* OOM kill score adjustment (bit shift) */ 6821da177e4SLinus Torvalds }; 6831da177e4SLinus Torvalds 6844866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */ 6854866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW 6864866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW 6874866cde0SNick Piggin #endif 6884866cde0SNick Piggin 6891da177e4SLinus Torvalds /* 6901da177e4SLinus Torvalds * Bits in flags field of signal_struct. 6911da177e4SLinus Torvalds */ 6921da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */ 6931da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED 0x00000002 /* stop signal dequeued */ 6941da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */ 6951da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */ 696e4420551SOleg Nesterov /* 697e4420551SOleg Nesterov * Pending notifications to parent. 698e4420551SOleg Nesterov */ 699e4420551SOleg Nesterov #define SIGNAL_CLD_STOPPED 0x00000010 700e4420551SOleg Nesterov #define SIGNAL_CLD_CONTINUED 0x00000020 701e4420551SOleg Nesterov #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED) 7021da177e4SLinus Torvalds 703fae5fa44SOleg Nesterov #define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */ 704fae5fa44SOleg Nesterov 705ed5d2cacSOleg Nesterov /* If true, all threads except ->group_exit_task have pending SIGKILL */ 706ed5d2cacSOleg Nesterov static inline int signal_group_exit(const struct signal_struct *sig) 707ed5d2cacSOleg Nesterov { 708ed5d2cacSOleg Nesterov return (sig->flags & SIGNAL_GROUP_EXIT) || 709ed5d2cacSOleg Nesterov (sig->group_exit_task != NULL); 710ed5d2cacSOleg Nesterov } 711ed5d2cacSOleg Nesterov 7121da177e4SLinus Torvalds /* 7131da177e4SLinus Torvalds * Some day this will be a full-fledged user tracking system.. 7141da177e4SLinus Torvalds */ 7151da177e4SLinus Torvalds struct user_struct { 7161da177e4SLinus Torvalds atomic_t __count; /* reference count */ 7171da177e4SLinus Torvalds atomic_t processes; /* How many processes does this user have? */ 7181da177e4SLinus Torvalds atomic_t files; /* How many open files does this user have? */ 7191da177e4SLinus Torvalds atomic_t sigpending; /* How many pending signals does this user have? */ 7202d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 7210eeca283SRobert Love atomic_t inotify_watches; /* How many inotify watches does this user have? */ 7220eeca283SRobert Love atomic_t inotify_devs; /* How many inotify devs does this user have opened? */ 7230eeca283SRobert Love #endif 7247ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL 7257ef9964eSDavide Libenzi atomic_t epoll_watches; /* The number of file descriptors currently watched */ 7267ef9964eSDavide Libenzi #endif 727970a8645SAlexey Dobriyan #ifdef CONFIG_POSIX_MQUEUE 7281da177e4SLinus Torvalds /* protected by mq_lock */ 7291da177e4SLinus Torvalds unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */ 730970a8645SAlexey Dobriyan #endif 7311da177e4SLinus Torvalds unsigned long locked_shm; /* How many pages of mlocked shm ? */ 7321da177e4SLinus Torvalds 7331da177e4SLinus Torvalds #ifdef CONFIG_KEYS 7341da177e4SLinus Torvalds struct key *uid_keyring; /* UID specific keyring */ 7351da177e4SLinus Torvalds struct key *session_keyring; /* UID's default session keyring */ 7361da177e4SLinus Torvalds #endif 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds /* Hash table maintenance information */ 739735de223SPavel Emelyanov struct hlist_node uidhash_node; 7401da177e4SLinus Torvalds uid_t uid; 74118b6e041SSerge Hallyn struct user_namespace *user_ns; 74224e377a8SSrivatsa Vaddagiri 743cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS 744789f90fcSPeter Zijlstra atomic_long_t locked_vm; 745789f90fcSPeter Zijlstra #endif 7461da177e4SLinus Torvalds }; 7471da177e4SLinus Torvalds 748eb41d946SKay Sievers extern int uids_sysfs_init(void); 7495cb350baSDhaval Giani 7501da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t); 7511da177e4SLinus Torvalds 7521da177e4SLinus Torvalds extern struct user_struct root_user; 7531da177e4SLinus Torvalds #define INIT_USER (&root_user) 7541da177e4SLinus Torvalds 755b6dff3ecSDavid Howells 7561da177e4SLinus Torvalds struct backing_dev_info; 7571da177e4SLinus Torvalds struct reclaim_state; 7581da177e4SLinus Torvalds 75952f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 7601da177e4SLinus Torvalds struct sched_info { 7611da177e4SLinus Torvalds /* cumulative counters */ 7622d72376bSIngo Molnar unsigned long pcount; /* # of times run on this cpu */ 7639c2c4802SKen Chen unsigned long long run_delay; /* time spent waiting on a runqueue */ 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds /* timestamps */ 766172ba844SBalbir Singh unsigned long long last_arrival,/* when we last ran on a cpu */ 7671da177e4SLinus Torvalds last_queued; /* when we were last queued to run */ 768b8efb561SIngo Molnar #ifdef CONFIG_SCHEDSTATS 769b8efb561SIngo Molnar /* BKL stats */ 770480b9434SKen Chen unsigned int bkl_count; 771b8efb561SIngo Molnar #endif 7721da177e4SLinus Torvalds }; 77352f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */ 7741da177e4SLinus Torvalds 775ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 776ca74e92bSShailabh Nagar struct task_delay_info { 777ca74e92bSShailabh Nagar spinlock_t lock; 778ca74e92bSShailabh Nagar unsigned int flags; /* Private per-task flags */ 779ca74e92bSShailabh Nagar 780ca74e92bSShailabh Nagar /* For each stat XXX, add following, aligned appropriately 781ca74e92bSShailabh Nagar * 782ca74e92bSShailabh Nagar * struct timespec XXX_start, XXX_end; 783ca74e92bSShailabh Nagar * u64 XXX_delay; 784ca74e92bSShailabh Nagar * u32 XXX_count; 785ca74e92bSShailabh Nagar * 786ca74e92bSShailabh Nagar * Atomicity of updates to XXX_delay, XXX_count protected by 787ca74e92bSShailabh Nagar * single lock above (split into XXX_lock if contention is an issue). 788ca74e92bSShailabh Nagar */ 7890ff92245SShailabh Nagar 7900ff92245SShailabh Nagar /* 7910ff92245SShailabh Nagar * XXX_count is incremented on every XXX operation, the delay 7920ff92245SShailabh Nagar * associated with the operation is added to XXX_delay. 7930ff92245SShailabh Nagar * XXX_delay contains the accumulated delay time in nanoseconds. 7940ff92245SShailabh Nagar */ 7950ff92245SShailabh Nagar struct timespec blkio_start, blkio_end; /* Shared by blkio, swapin */ 7960ff92245SShailabh Nagar u64 blkio_delay; /* wait for sync block io completion */ 7970ff92245SShailabh Nagar u64 swapin_delay; /* wait for swapin block io completion */ 7980ff92245SShailabh Nagar u32 blkio_count; /* total count of the number of sync block */ 7990ff92245SShailabh Nagar /* io operations performed */ 8000ff92245SShailabh Nagar u32 swapin_count; /* total count of the number of swapin block */ 8010ff92245SShailabh Nagar /* io operations performed */ 802873b4771SKeika Kobayashi 803873b4771SKeika Kobayashi struct timespec freepages_start, freepages_end; 804873b4771SKeika Kobayashi u64 freepages_delay; /* wait for memory reclaim */ 805873b4771SKeika Kobayashi u32 freepages_count; /* total count of memory reclaim */ 806ca74e92bSShailabh Nagar }; 80752f17b6cSChandra Seetharaman #endif /* CONFIG_TASK_DELAY_ACCT */ 80852f17b6cSChandra Seetharaman 80952f17b6cSChandra Seetharaman static inline int sched_info_on(void) 81052f17b6cSChandra Seetharaman { 81152f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS 81252f17b6cSChandra Seetharaman return 1; 81352f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT) 81452f17b6cSChandra Seetharaman extern int delayacct_on; 81552f17b6cSChandra Seetharaman return delayacct_on; 81652f17b6cSChandra Seetharaman #else 81752f17b6cSChandra Seetharaman return 0; 818ca74e92bSShailabh Nagar #endif 81952f17b6cSChandra Seetharaman } 820ca74e92bSShailabh Nagar 821d15bcfdbSIngo Molnar enum cpu_idle_type { 822d15bcfdbSIngo Molnar CPU_IDLE, 823d15bcfdbSIngo Molnar CPU_NOT_IDLE, 824d15bcfdbSIngo Molnar CPU_NEWLY_IDLE, 825d15bcfdbSIngo Molnar CPU_MAX_IDLE_TYPES 8261da177e4SLinus Torvalds }; 8271da177e4SLinus Torvalds 8281da177e4SLinus Torvalds /* 8291da177e4SLinus Torvalds * sched-domains (multiprocessor balancing) declarations: 8301da177e4SLinus Torvalds */ 8319aa7b369SIngo Molnar 8329aa7b369SIngo Molnar /* 8339aa7b369SIngo Molnar * Increase resolution of nice-level calculations: 8349aa7b369SIngo Molnar */ 8359aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT 10 8369aa7b369SIngo Molnar #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT) 8379aa7b369SIngo Molnar 838f8700df7SSuresh Siddha #define SCHED_LOAD_SCALE_FUZZ SCHED_LOAD_SCALE 8391da177e4SLinus Torvalds 8402dd73a4fSPeter Williams #ifdef CONFIG_SMP 841b5d978e0SPeter Zijlstra #define SD_LOAD_BALANCE 0x0001 /* Do load balancing on this domain. */ 842b5d978e0SPeter Zijlstra #define SD_BALANCE_NEWIDLE 0x0002 /* Balance when about to become idle */ 843b5d978e0SPeter Zijlstra #define SD_BALANCE_EXEC 0x0004 /* Balance on exec */ 844b5d978e0SPeter Zijlstra #define SD_BALANCE_FORK 0x0008 /* Balance on fork, clone */ 845c88d5910SPeter Zijlstra #define SD_BALANCE_WAKE 0x0010 /* Balance on wakeup */ 846b5d978e0SPeter Zijlstra #define SD_WAKE_AFFINE 0x0020 /* Wake task to waking CPU */ 84759abf026SPeter Zijlstra #define SD_PREFER_LOCAL 0x0040 /* Prefer to keep tasks local to this domain */ 848b5d978e0SPeter Zijlstra #define SD_SHARE_CPUPOWER 0x0080 /* Domain members share cpu power */ 849b5d978e0SPeter Zijlstra #define SD_POWERSAVINGS_BALANCE 0x0100 /* Balance for power savings */ 850b5d978e0SPeter Zijlstra #define SD_SHARE_PKG_RESOURCES 0x0200 /* Domain members share cpu pkg resources */ 851b5d978e0SPeter Zijlstra #define SD_SERIALIZE 0x0400 /* Only a single load balancing instance */ 852c88d5910SPeter Zijlstra 853b5d978e0SPeter Zijlstra #define SD_PREFER_SIBLING 0x1000 /* Prefer to place tasks in a sibling domain */ 8545c45bf27SSiddha, Suresh B 855afb8a9b7SGautham R Shenoy enum powersavings_balance_level { 856afb8a9b7SGautham R Shenoy POWERSAVINGS_BALANCE_NONE = 0, /* No power saving load balance */ 857afb8a9b7SGautham R Shenoy POWERSAVINGS_BALANCE_BASIC, /* Fill one thread/core/package 858afb8a9b7SGautham R Shenoy * first for long running threads 859afb8a9b7SGautham R Shenoy */ 860afb8a9b7SGautham R Shenoy POWERSAVINGS_BALANCE_WAKEUP, /* Also bias task wakeups to semi-idle 861afb8a9b7SGautham R Shenoy * cpu package for power savings 862afb8a9b7SGautham R Shenoy */ 863afb8a9b7SGautham R Shenoy MAX_POWERSAVINGS_BALANCE_LEVELS 864afb8a9b7SGautham R Shenoy }; 86589c4710eSSiddha, Suresh B 866716707b2SVaidyanathan Srinivasan extern int sched_mc_power_savings, sched_smt_power_savings; 86789c4710eSSiddha, Suresh B 868716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_mc_power(void) 869716707b2SVaidyanathan Srinivasan { 870716707b2SVaidyanathan Srinivasan if (sched_smt_power_savings) 871716707b2SVaidyanathan Srinivasan return SD_POWERSAVINGS_BALANCE; 8725c45bf27SSiddha, Suresh B 87328f53181SVaidyanathan Srinivasan if (!sched_mc_power_savings) 874b5d978e0SPeter Zijlstra return SD_PREFER_SIBLING; 87528f53181SVaidyanathan Srinivasan 87628f53181SVaidyanathan Srinivasan return 0; 877716707b2SVaidyanathan Srinivasan } 878716707b2SVaidyanathan Srinivasan 879716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_package_power(void) 880716707b2SVaidyanathan Srinivasan { 881716707b2SVaidyanathan Srinivasan if (sched_mc_power_savings | sched_smt_power_savings) 882716707b2SVaidyanathan Srinivasan return SD_POWERSAVINGS_BALANCE; 883716707b2SVaidyanathan Srinivasan 884b5d978e0SPeter Zijlstra return SD_PREFER_SIBLING; 885716707b2SVaidyanathan Srinivasan } 886147cbb4bSNick Piggin 887100fdaeeSVaidyanathan Srinivasan /* 888100fdaeeSVaidyanathan Srinivasan * Optimise SD flags for power savings: 889100fdaeeSVaidyanathan Srinivasan * SD_BALANCE_NEWIDLE helps agressive task consolidation and power savings. 890100fdaeeSVaidyanathan Srinivasan * Keep default SD flags if sched_{smt,mc}_power_saving=0 891100fdaeeSVaidyanathan Srinivasan */ 892100fdaeeSVaidyanathan Srinivasan 893100fdaeeSVaidyanathan Srinivasan static inline int sd_power_saving_flags(void) 894100fdaeeSVaidyanathan Srinivasan { 895100fdaeeSVaidyanathan Srinivasan if (sched_mc_power_savings | sched_smt_power_savings) 896100fdaeeSVaidyanathan Srinivasan return SD_BALANCE_NEWIDLE; 897100fdaeeSVaidyanathan Srinivasan 898100fdaeeSVaidyanathan Srinivasan return 0; 899100fdaeeSVaidyanathan Srinivasan } 9001da177e4SLinus Torvalds 9011da177e4SLinus Torvalds struct sched_group { 9021da177e4SLinus Torvalds struct sched_group *next; /* Must be a circular list */ 9031da177e4SLinus Torvalds 9041da177e4SLinus Torvalds /* 9051da177e4SLinus Torvalds * CPU power of this group, SCHED_LOAD_SCALE being max power for a 90618a3885fSPeter Zijlstra * single CPU. 9071da177e4SLinus Torvalds */ 90818a3885fSPeter Zijlstra unsigned int cpu_power; 9096c99e9adSRusty Russell 9104200efd9SIngo Molnar /* 9114200efd9SIngo Molnar * The CPUs this group covers. 9124200efd9SIngo Molnar * 9134200efd9SIngo Molnar * NOTE: this field is variable length. (Allocated dynamically 9144200efd9SIngo Molnar * by attaching extra space to the end of the structure, 9154200efd9SIngo Molnar * depending on how many CPUs the kernel has booted up with) 9164200efd9SIngo Molnar * 9174200efd9SIngo Molnar * It is also be embedded into static data structures at build 9184200efd9SIngo Molnar * time. (See 'struct static_sched_group' in kernel/sched.c) 9194200efd9SIngo Molnar */ 9204200efd9SIngo Molnar unsigned long cpumask[0]; 9211da177e4SLinus Torvalds }; 9221da177e4SLinus Torvalds 923758b2cdcSRusty Russell static inline struct cpumask *sched_group_cpus(struct sched_group *sg) 924758b2cdcSRusty Russell { 9256c99e9adSRusty Russell return to_cpumask(sg->cpumask); 926758b2cdcSRusty Russell } 927758b2cdcSRusty Russell 9281d3504fcSHidetoshi Seto enum sched_domain_level { 9291d3504fcSHidetoshi Seto SD_LV_NONE = 0, 9301d3504fcSHidetoshi Seto SD_LV_SIBLING, 9311d3504fcSHidetoshi Seto SD_LV_MC, 9321d3504fcSHidetoshi Seto SD_LV_CPU, 9331d3504fcSHidetoshi Seto SD_LV_NODE, 9341d3504fcSHidetoshi Seto SD_LV_ALLNODES, 9351d3504fcSHidetoshi Seto SD_LV_MAX 9361d3504fcSHidetoshi Seto }; 9371d3504fcSHidetoshi Seto 9381d3504fcSHidetoshi Seto struct sched_domain_attr { 9391d3504fcSHidetoshi Seto int relax_domain_level; 9401d3504fcSHidetoshi Seto }; 9411d3504fcSHidetoshi Seto 9421d3504fcSHidetoshi Seto #define SD_ATTR_INIT (struct sched_domain_attr) { \ 9431d3504fcSHidetoshi Seto .relax_domain_level = -1, \ 9441d3504fcSHidetoshi Seto } 9451d3504fcSHidetoshi Seto 9461da177e4SLinus Torvalds struct sched_domain { 9471da177e4SLinus Torvalds /* These fields must be setup */ 9481da177e4SLinus Torvalds struct sched_domain *parent; /* top domain must be null terminated */ 9491a848870SSiddha, Suresh B struct sched_domain *child; /* bottom domain must be null terminated */ 9501da177e4SLinus Torvalds struct sched_group *groups; /* the balancing groups of the domain */ 9511da177e4SLinus Torvalds unsigned long min_interval; /* Minimum balance interval ms */ 9521da177e4SLinus Torvalds unsigned long max_interval; /* Maximum balance interval ms */ 9531da177e4SLinus Torvalds unsigned int busy_factor; /* less balancing by factor if busy */ 9541da177e4SLinus Torvalds unsigned int imbalance_pct; /* No balance until over watermark */ 9551da177e4SLinus Torvalds unsigned int cache_nice_tries; /* Leave cache hot tasks for # tries */ 9567897986bSNick Piggin unsigned int busy_idx; 9577897986bSNick Piggin unsigned int idle_idx; 9587897986bSNick Piggin unsigned int newidle_idx; 9597897986bSNick Piggin unsigned int wake_idx; 960147cbb4bSNick Piggin unsigned int forkexec_idx; 961a52bfd73SPeter Zijlstra unsigned int smt_gain; 9621da177e4SLinus Torvalds int flags; /* See SD_* */ 9631d3504fcSHidetoshi Seto enum sched_domain_level level; 9641da177e4SLinus Torvalds 9651da177e4SLinus Torvalds /* Runtime fields. */ 9661da177e4SLinus Torvalds unsigned long last_balance; /* init to jiffies. units in jiffies */ 9671da177e4SLinus Torvalds unsigned int balance_interval; /* initialise to 1. units in ms. */ 9681da177e4SLinus Torvalds unsigned int nr_balance_failed; /* initialise to 0 */ 9691da177e4SLinus Torvalds 9702398f2c6SPeter Zijlstra u64 last_update; 9712398f2c6SPeter Zijlstra 9721da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS 9731da177e4SLinus Torvalds /* load_balance() stats */ 974480b9434SKen Chen unsigned int lb_count[CPU_MAX_IDLE_TYPES]; 975480b9434SKen Chen unsigned int lb_failed[CPU_MAX_IDLE_TYPES]; 976480b9434SKen Chen unsigned int lb_balanced[CPU_MAX_IDLE_TYPES]; 977480b9434SKen Chen unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES]; 978480b9434SKen Chen unsigned int lb_gained[CPU_MAX_IDLE_TYPES]; 979480b9434SKen Chen unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES]; 980480b9434SKen Chen unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES]; 981480b9434SKen Chen unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES]; 9821da177e4SLinus Torvalds 9831da177e4SLinus Torvalds /* Active load balancing */ 984480b9434SKen Chen unsigned int alb_count; 985480b9434SKen Chen unsigned int alb_failed; 986480b9434SKen Chen unsigned int alb_pushed; 9871da177e4SLinus Torvalds 98868767a0aSNick Piggin /* SD_BALANCE_EXEC stats */ 989480b9434SKen Chen unsigned int sbe_count; 990480b9434SKen Chen unsigned int sbe_balanced; 991480b9434SKen Chen unsigned int sbe_pushed; 9921da177e4SLinus Torvalds 99368767a0aSNick Piggin /* SD_BALANCE_FORK stats */ 994480b9434SKen Chen unsigned int sbf_count; 995480b9434SKen Chen unsigned int sbf_balanced; 996480b9434SKen Chen unsigned int sbf_pushed; 99768767a0aSNick Piggin 9981da177e4SLinus Torvalds /* try_to_wake_up() stats */ 999480b9434SKen Chen unsigned int ttwu_wake_remote; 1000480b9434SKen Chen unsigned int ttwu_move_affine; 1001480b9434SKen Chen unsigned int ttwu_move_balance; 10021da177e4SLinus Torvalds #endif 1003a5d8c348SIngo Molnar #ifdef CONFIG_SCHED_DEBUG 1004a5d8c348SIngo Molnar char *name; 1005a5d8c348SIngo Molnar #endif 10066c99e9adSRusty Russell 10074200efd9SIngo Molnar /* 10084200efd9SIngo Molnar * Span of all CPUs in this domain. 10094200efd9SIngo Molnar * 10104200efd9SIngo Molnar * NOTE: this field is variable length. (Allocated dynamically 10114200efd9SIngo Molnar * by attaching extra space to the end of the structure, 10124200efd9SIngo Molnar * depending on how many CPUs the kernel has booted up with) 10134200efd9SIngo Molnar * 10144200efd9SIngo Molnar * It is also be embedded into static data structures at build 10154200efd9SIngo Molnar * time. (See 'struct static_sched_domain' in kernel/sched.c) 10164200efd9SIngo Molnar */ 10174200efd9SIngo Molnar unsigned long span[0]; 10181da177e4SLinus Torvalds }; 10191da177e4SLinus Torvalds 1020758b2cdcSRusty Russell static inline struct cpumask *sched_domain_span(struct sched_domain *sd) 1021758b2cdcSRusty Russell { 10226c99e9adSRusty Russell return to_cpumask(sd->span); 1023758b2cdcSRusty Russell } 1024758b2cdcSRusty Russell 1025acc3f5d7SRusty Russell extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], 10261d3504fcSHidetoshi Seto struct sched_domain_attr *dattr_new); 1027029190c5SPaul Jackson 1028acc3f5d7SRusty Russell /* Allocate an array of sched domains, for partition_sched_domains(). */ 1029acc3f5d7SRusty Russell cpumask_var_t *alloc_sched_domains(unsigned int ndoms); 1030acc3f5d7SRusty Russell void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms); 1031acc3f5d7SRusty Russell 103206aaf76aSIngo Molnar /* Test a flag in parent sched domain */ 103306aaf76aSIngo Molnar static inline int test_sd_parent(struct sched_domain *sd, int flag) 103406aaf76aSIngo Molnar { 103506aaf76aSIngo Molnar if (sd->parent && (sd->parent->flags & flag)) 103606aaf76aSIngo Molnar return 1; 103706aaf76aSIngo Molnar 103806aaf76aSIngo Molnar return 0; 103906aaf76aSIngo Molnar } 10401da177e4SLinus Torvalds 104147fe38fcSPeter Zijlstra unsigned long default_scale_freq_power(struct sched_domain *sd, int cpu); 104247fe38fcSPeter Zijlstra unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu); 104347fe38fcSPeter Zijlstra 10441b427c15SIngo Molnar #else /* CONFIG_SMP */ 10451da177e4SLinus Torvalds 10461b427c15SIngo Molnar struct sched_domain_attr; 10471b427c15SIngo Molnar 10481b427c15SIngo Molnar static inline void 1049acc3f5d7SRusty Russell partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], 10501b427c15SIngo Molnar struct sched_domain_attr *dattr_new) 1051d02c7a8cSCon Kolivas { 1052d02c7a8cSCon Kolivas } 10531b427c15SIngo Molnar #endif /* !CONFIG_SMP */ 10541da177e4SLinus Torvalds 105547fe38fcSPeter Zijlstra 10561da177e4SLinus Torvalds struct io_context; /* See blkdev.h */ 10571da177e4SLinus Torvalds 10581da177e4SLinus Torvalds 1059383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK 106036c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t); 1061383f2835SChen, Kenneth W #else 1062383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { } 1063383f2835SChen, Kenneth W #endif 10641da177e4SLinus Torvalds 10651da177e4SLinus Torvalds struct audit_context; /* See audit.c */ 10661da177e4SLinus Torvalds struct mempolicy; 1067b92ce558SJens Axboe struct pipe_inode_info; 10684865ecf1SSerge E. Hallyn struct uts_namespace; 10691da177e4SLinus Torvalds 107020b8a59fSIngo Molnar struct rq; 107120b8a59fSIngo Molnar struct sched_domain; 107220b8a59fSIngo Molnar 10737d478721SPeter Zijlstra /* 10747d478721SPeter Zijlstra * wake flags 10757d478721SPeter Zijlstra */ 10767d478721SPeter Zijlstra #define WF_SYNC 0x01 /* waker goes to sleep after wakup */ 1077a7558e01SPeter Zijlstra #define WF_FORK 0x02 /* child wakeup after fork */ 10787d478721SPeter Zijlstra 107920b8a59fSIngo Molnar struct sched_class { 10805522d5d5SIngo Molnar const struct sched_class *next; 108120b8a59fSIngo Molnar 1082ea87bb78SThomas Gleixner void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup, 1083ea87bb78SThomas Gleixner bool head); 1084f02231e5SIngo Molnar void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep); 10854530d7abSDmitry Adamushko void (*yield_task) (struct rq *rq); 108620b8a59fSIngo Molnar 10877d478721SPeter Zijlstra void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags); 108820b8a59fSIngo Molnar 1089fb8d4724SIngo Molnar struct task_struct * (*pick_next_task) (struct rq *rq); 109031ee529cSIngo Molnar void (*put_prev_task) (struct rq *rq, struct task_struct *p); 109120b8a59fSIngo Molnar 1092681f3e68SPeter Williams #ifdef CONFIG_SMP 10937d478721SPeter Zijlstra int (*select_task_rq)(struct task_struct *p, int sd_flag, int flags); 10944ce72a2cSLi Zefan 10959a897c5aSSteven Rostedt void (*pre_schedule) (struct rq *this_rq, struct task_struct *task); 10969a897c5aSSteven Rostedt void (*post_schedule) (struct rq *this_rq); 1097efbbd05aSPeter Zijlstra void (*task_waking) (struct rq *this_rq, struct task_struct *task); 1098efbbd05aSPeter Zijlstra void (*task_woken) (struct rq *this_rq, struct task_struct *task); 1099e1d1484fSPeter Williams 1100cd8ba7cdSMike Travis void (*set_cpus_allowed)(struct task_struct *p, 110196f874e2SRusty Russell const struct cpumask *newmask); 110257d885feSGregory Haskins 11031f11eb6aSGregory Haskins void (*rq_online)(struct rq *rq); 11041f11eb6aSGregory Haskins void (*rq_offline)(struct rq *rq); 11054ce72a2cSLi Zefan #endif 11064ce72a2cSLi Zefan 11074ce72a2cSLi Zefan void (*set_curr_task) (struct rq *rq); 11084ce72a2cSLi Zefan void (*task_tick) (struct rq *rq, struct task_struct *p, int queued); 1109cd29fe6fSPeter Zijlstra void (*task_fork) (struct task_struct *p); 1110cb469845SSteven Rostedt 1111cb469845SSteven Rostedt void (*switched_from) (struct rq *this_rq, struct task_struct *task, 1112cb469845SSteven Rostedt int running); 1113cb469845SSteven Rostedt void (*switched_to) (struct rq *this_rq, struct task_struct *task, 1114cb469845SSteven Rostedt int running); 1115cb469845SSteven Rostedt void (*prio_changed) (struct rq *this_rq, struct task_struct *task, 1116cb469845SSteven Rostedt int oldprio, int running); 1117810b3817SPeter Zijlstra 1118dba091b9SThomas Gleixner unsigned int (*get_rr_interval) (struct rq *rq, 1119dba091b9SThomas Gleixner struct task_struct *task); 11200d721ceaSPeter Williams 1121810b3817SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED 112288ec22d3SPeter Zijlstra void (*moved_group) (struct task_struct *p, int on_rq); 1123810b3817SPeter Zijlstra #endif 112420b8a59fSIngo Molnar }; 112520b8a59fSIngo Molnar 112620b8a59fSIngo Molnar struct load_weight { 112720b8a59fSIngo Molnar unsigned long weight, inv_weight; 112820b8a59fSIngo Molnar }; 112920b8a59fSIngo Molnar 113094c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS 1131*41acab88SLucas De Marchi struct sched_statistics { 113294c18227SIngo Molnar u64 wait_start; 113394c18227SIngo Molnar u64 wait_max; 11346d082592SArjan van de Ven u64 wait_count; 11356d082592SArjan van de Ven u64 wait_sum; 11368f0dfc34SArjan van de Ven u64 iowait_count; 11378f0dfc34SArjan van de Ven u64 iowait_sum; 113894c18227SIngo Molnar 113994c18227SIngo Molnar u64 sleep_start; 114020b8a59fSIngo Molnar u64 sleep_max; 114194c18227SIngo Molnar s64 sum_sleep_runtime; 114294c18227SIngo Molnar 114394c18227SIngo Molnar u64 block_start; 114420b8a59fSIngo Molnar u64 block_max; 114520b8a59fSIngo Molnar u64 exec_max; 1146eba1ed4bSIngo Molnar u64 slice_max; 1147cc367732SIngo Molnar 1148cc367732SIngo Molnar u64 nr_migrations_cold; 1149cc367732SIngo Molnar u64 nr_failed_migrations_affine; 1150cc367732SIngo Molnar u64 nr_failed_migrations_running; 1151cc367732SIngo Molnar u64 nr_failed_migrations_hot; 1152cc367732SIngo Molnar u64 nr_forced_migrations; 1153cc367732SIngo Molnar 1154cc367732SIngo Molnar u64 nr_wakeups; 1155cc367732SIngo Molnar u64 nr_wakeups_sync; 1156cc367732SIngo Molnar u64 nr_wakeups_migrate; 1157cc367732SIngo Molnar u64 nr_wakeups_local; 1158cc367732SIngo Molnar u64 nr_wakeups_remote; 1159cc367732SIngo Molnar u64 nr_wakeups_affine; 1160cc367732SIngo Molnar u64 nr_wakeups_affine_attempts; 1161cc367732SIngo Molnar u64 nr_wakeups_passive; 1162cc367732SIngo Molnar u64 nr_wakeups_idle; 1163*41acab88SLucas De Marchi }; 1164*41acab88SLucas De Marchi #endif 1165*41acab88SLucas De Marchi 1166*41acab88SLucas De Marchi struct sched_entity { 1167*41acab88SLucas De Marchi struct load_weight load; /* for load-balancing */ 1168*41acab88SLucas De Marchi struct rb_node run_node; 1169*41acab88SLucas De Marchi struct list_head group_node; 1170*41acab88SLucas De Marchi unsigned int on_rq; 1171*41acab88SLucas De Marchi 1172*41acab88SLucas De Marchi u64 exec_start; 1173*41acab88SLucas De Marchi u64 sum_exec_runtime; 1174*41acab88SLucas De Marchi u64 vruntime; 1175*41acab88SLucas De Marchi u64 prev_sum_exec_runtime; 1176*41acab88SLucas De Marchi 1177*41acab88SLucas De Marchi u64 last_wakeup; 1178*41acab88SLucas De Marchi u64 avg_overlap; 1179*41acab88SLucas De Marchi 1180*41acab88SLucas De Marchi u64 nr_migrations; 1181*41acab88SLucas De Marchi 1182*41acab88SLucas De Marchi u64 start_runtime; 1183*41acab88SLucas De Marchi u64 avg_wakeup; 1184*41acab88SLucas De Marchi 1185*41acab88SLucas De Marchi #ifdef CONFIG_SCHEDSTATS 1186*41acab88SLucas De Marchi struct sched_statistics statistics; 118794c18227SIngo Molnar #endif 118894c18227SIngo Molnar 118920b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED 119020b8a59fSIngo Molnar struct sched_entity *parent; 119120b8a59fSIngo Molnar /* rq on which this entity is (to be) queued: */ 119220b8a59fSIngo Molnar struct cfs_rq *cfs_rq; 119320b8a59fSIngo Molnar /* rq "owned" by this entity/group: */ 119420b8a59fSIngo Molnar struct cfs_rq *my_q; 119520b8a59fSIngo Molnar #endif 119620b8a59fSIngo Molnar }; 119770b97a7fSIngo Molnar 1198fa717060SPeter Zijlstra struct sched_rt_entity { 1199fa717060SPeter Zijlstra struct list_head run_list; 120078f2c7dbSPeter Zijlstra unsigned long timeout; 1201bee367edSRichard Kennedy unsigned int time_slice; 12026f505b16SPeter Zijlstra int nr_cpus_allowed; 12036f505b16SPeter Zijlstra 120458d6c2d7SPeter Zijlstra struct sched_rt_entity *back; 1205052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED 12066f505b16SPeter Zijlstra struct sched_rt_entity *parent; 12076f505b16SPeter Zijlstra /* rq on which this entity is (to be) queued: */ 12086f505b16SPeter Zijlstra struct rt_rq *rt_rq; 12096f505b16SPeter Zijlstra /* rq "owned" by this entity/group: */ 12106f505b16SPeter Zijlstra struct rt_rq *my_q; 12116f505b16SPeter Zijlstra #endif 1212fa717060SPeter Zijlstra }; 1213fa717060SPeter Zijlstra 121486848966SPaul E. McKenney struct rcu_node; 121586848966SPaul E. McKenney 12161da177e4SLinus Torvalds struct task_struct { 12171da177e4SLinus Torvalds volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ 1218f7e4217bSRoman Zippel void *stack; 12191da177e4SLinus Torvalds atomic_t usage; 122097dc32cdSWilliam Cohen unsigned int flags; /* per process flags, defined below */ 122197dc32cdSWilliam Cohen unsigned int ptrace; 12221da177e4SLinus Torvalds 122336772092SPaolo 'Blaisorblade' Giarrusso int lock_depth; /* BKL lock depth */ 12241da177e4SLinus Torvalds 12252dd73a4fSPeter Williams #ifdef CONFIG_SMP 12262dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW 12274866cde0SNick Piggin int oncpu; 12284866cde0SNick Piggin #endif 12292dd73a4fSPeter Williams #endif 123050e645a8SIngo Molnar 1231b29739f9SIngo Molnar int prio, static_prio, normal_prio; 1232c7aceabaSRichard Kennedy unsigned int rt_priority; 12335522d5d5SIngo Molnar const struct sched_class *sched_class; 123420b8a59fSIngo Molnar struct sched_entity se; 1235fa717060SPeter Zijlstra struct sched_rt_entity rt; 12361da177e4SLinus Torvalds 1237e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS 1238e107be36SAvi Kivity /* list of struct preempt_notifier: */ 1239e107be36SAvi Kivity struct hlist_head preempt_notifiers; 1240e107be36SAvi Kivity #endif 1241e107be36SAvi Kivity 124218796aa0SAlexey Dobriyan /* 124318796aa0SAlexey Dobriyan * fpu_counter contains the number of consecutive context switches 124418796aa0SAlexey Dobriyan * that the FPU is used. If this is over a threshold, the lazy fpu 124518796aa0SAlexey Dobriyan * saving becomes unlazy to save the trap. This is an unsigned char 124618796aa0SAlexey Dobriyan * so that after 256 times the counter wraps and the behavior turns 124718796aa0SAlexey Dobriyan * lazy again; this to deal with bursty apps that only use FPU for 124818796aa0SAlexey Dobriyan * a short time 124918796aa0SAlexey Dobriyan */ 125018796aa0SAlexey Dobriyan unsigned char fpu_counter; 12516c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE 12522056a782SJens Axboe unsigned int btrace_seq; 12536c5c9341SAlexey Dobriyan #endif 12541da177e4SLinus Torvalds 125597dc32cdSWilliam Cohen unsigned int policy; 12561da177e4SLinus Torvalds cpumask_t cpus_allowed; 12571da177e4SLinus Torvalds 1258f41d911fSPaul E. McKenney #ifdef CONFIG_TREE_PREEMPT_RCU 1259e260be67SPaul E. McKenney int rcu_read_lock_nesting; 1260f41d911fSPaul E. McKenney char rcu_read_unlock_special; 126186848966SPaul E. McKenney struct rcu_node *rcu_blocked_node; 1262f41d911fSPaul E. McKenney struct list_head rcu_node_entry; 1263f41d911fSPaul E. McKenney #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ 1264e260be67SPaul E. McKenney 126552f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 12661da177e4SLinus Torvalds struct sched_info sched_info; 12671da177e4SLinus Torvalds #endif 12681da177e4SLinus Torvalds 12691da177e4SLinus Torvalds struct list_head tasks; 1270917b627dSGregory Haskins struct plist_node pushable_tasks; 12711da177e4SLinus Torvalds 12721da177e4SLinus Torvalds struct mm_struct *mm, *active_mm; 12731da177e4SLinus Torvalds 12741da177e4SLinus Torvalds /* task state */ 127597dc32cdSWilliam Cohen int exit_state; 12761da177e4SLinus Torvalds int exit_code, exit_signal; 12771da177e4SLinus Torvalds int pdeath_signal; /* The signal sent when the parent dies */ 12781da177e4SLinus Torvalds /* ??? */ 127997dc32cdSWilliam Cohen unsigned int personality; 12801da177e4SLinus Torvalds unsigned did_exec:1; 1281f9ce1f1cSKentaro Takeda unsigned in_execve:1; /* Tell the LSMs that the process is doing an 1282f9ce1f1cSKentaro Takeda * execve */ 12838f0dfc34SArjan van de Ven unsigned in_iowait:1; 12848f0dfc34SArjan van de Ven 1285ca94c442SLennart Poettering 1286ca94c442SLennart Poettering /* Revert to default priority/policy when forking */ 1287ca94c442SLennart Poettering unsigned sched_reset_on_fork:1; 1288ca94c442SLennart Poettering 12891da177e4SLinus Torvalds pid_t pid; 12901da177e4SLinus Torvalds pid_t tgid; 12910a425405SArjan van de Ven 12921314562aSHiroshi Shimamoto #ifdef CONFIG_CC_STACKPROTECTOR 12930a425405SArjan van de Ven /* Canary value for the -fstack-protector gcc feature */ 12940a425405SArjan van de Ven unsigned long stack_canary; 12951314562aSHiroshi Shimamoto #endif 1296e0032087SIngo Molnar 12971da177e4SLinus Torvalds /* 12981da177e4SLinus Torvalds * pointers to (original) parent process, youngest child, younger sibling, 12991da177e4SLinus Torvalds * older sibling, respectively. (p->father can be replaced with 1300f470021aSRoland McGrath * p->real_parent->pid) 13011da177e4SLinus Torvalds */ 1302f470021aSRoland McGrath struct task_struct *real_parent; /* real parent process */ 1303f470021aSRoland McGrath struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports */ 13041da177e4SLinus Torvalds /* 1305f470021aSRoland McGrath * children/sibling forms the list of my natural children 13061da177e4SLinus Torvalds */ 13071da177e4SLinus Torvalds struct list_head children; /* list of my children */ 13081da177e4SLinus Torvalds struct list_head sibling; /* linkage in my parent's children list */ 13091da177e4SLinus Torvalds struct task_struct *group_leader; /* threadgroup leader */ 13101da177e4SLinus Torvalds 1311f470021aSRoland McGrath /* 1312f470021aSRoland McGrath * ptraced is the list of tasks this task is using ptrace on. 1313f470021aSRoland McGrath * This includes both natural children and PTRACE_ATTACH targets. 1314f470021aSRoland McGrath * p->ptrace_entry is p's link on the p->parent->ptraced list. 1315f470021aSRoland McGrath */ 1316f470021aSRoland McGrath struct list_head ptraced; 1317f470021aSRoland McGrath struct list_head ptrace_entry; 1318f470021aSRoland McGrath 1319ca0002a1SMarkus Metzger /* 1320ca0002a1SMarkus Metzger * This is the tracer handle for the ptrace BTS extension. 1321ca0002a1SMarkus Metzger * This field actually belongs to the ptracer task. 1322ca0002a1SMarkus Metzger */ 1323e2b371f0SMarkus Metzger struct bts_context *bts; 1324ca0002a1SMarkus Metzger 13251da177e4SLinus Torvalds /* PID/PID hash table linkage. */ 132692476d7fSEric W. Biederman struct pid_link pids[PIDTYPE_MAX]; 132747e65328SOleg Nesterov struct list_head thread_group; 13281da177e4SLinus Torvalds 13291da177e4SLinus Torvalds struct completion *vfork_done; /* for vfork() */ 13301da177e4SLinus Torvalds int __user *set_child_tid; /* CLONE_CHILD_SETTID */ 13311da177e4SLinus Torvalds int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */ 13321da177e4SLinus Torvalds 1333c66f08beSMichael Neuling cputime_t utime, stime, utimescaled, stimescaled; 13349ac52315SLaurent Vivier cputime_t gtime; 1335d99ca3b9SHidetoshi Seto #ifndef CONFIG_VIRT_CPU_ACCOUNTING 13369301899bSBalbir Singh cputime_t prev_utime, prev_stime; 1337d99ca3b9SHidetoshi Seto #endif 13381da177e4SLinus Torvalds unsigned long nvcsw, nivcsw; /* context switch counts */ 1339924b42d5STomas Janousek struct timespec start_time; /* monotonic time */ 1340924b42d5STomas Janousek struct timespec real_start_time; /* boot based time */ 13411da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ 13421da177e4SLinus Torvalds unsigned long min_flt, maj_flt; 13431da177e4SLinus Torvalds 1344f06febc9SFrank Mayhar struct task_cputime cputime_expires; 13451da177e4SLinus Torvalds struct list_head cpu_timers[3]; 13461da177e4SLinus Torvalds 13471da177e4SLinus Torvalds /* process credentials */ 13483b11a1deSDavid Howells const struct cred *real_cred; /* objective and real subjective task 13493b11a1deSDavid Howells * credentials (COW) */ 13503b11a1deSDavid Howells const struct cred *cred; /* effective (overridable) subjective task 13513b11a1deSDavid Howells * credentials (COW) */ 13525e751e99SDavid Howells struct mutex cred_guard_mutex; /* guard against foreign influences on 13535e751e99SDavid Howells * credential calculations 13545e751e99SDavid Howells * (notably. ptrace) */ 1355ee18d64cSDavid Howells struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */ 1356b6dff3ecSDavid Howells 135736772092SPaolo 'Blaisorblade' Giarrusso char comm[TASK_COMM_LEN]; /* executable name excluding path 135836772092SPaolo 'Blaisorblade' Giarrusso - access with [gs]et_task_comm (which lock 135936772092SPaolo 'Blaisorblade' Giarrusso it with task_lock()) 1360221af7f8SLinus Torvalds - initialized normally by setup_new_exec */ 13611da177e4SLinus Torvalds /* file system info */ 13621da177e4SLinus Torvalds int link_count, total_link_count; 13633d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC 13641da177e4SLinus Torvalds /* ipc stuff */ 13651da177e4SLinus Torvalds struct sysv_sem sysvsem; 13663d5b6fccSAlexey Dobriyan #endif 1367e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK 136882a1fcb9SIngo Molnar /* hung task detection */ 136982a1fcb9SIngo Molnar unsigned long last_switch_count; 137082a1fcb9SIngo Molnar #endif 13711da177e4SLinus Torvalds /* CPU-specific state of this task */ 13721da177e4SLinus Torvalds struct thread_struct thread; 13731da177e4SLinus Torvalds /* filesystem information */ 13741da177e4SLinus Torvalds struct fs_struct *fs; 13751da177e4SLinus Torvalds /* open file information */ 13761da177e4SLinus Torvalds struct files_struct *files; 13771651e14eSSerge E. Hallyn /* namespaces */ 1378ab516013SSerge E. Hallyn struct nsproxy *nsproxy; 13791da177e4SLinus Torvalds /* signal handlers */ 13801da177e4SLinus Torvalds struct signal_struct *signal; 13811da177e4SLinus Torvalds struct sighand_struct *sighand; 13821da177e4SLinus Torvalds 13831da177e4SLinus Torvalds sigset_t blocked, real_blocked; 1384f3de272bSRoland McGrath sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */ 13851da177e4SLinus Torvalds struct sigpending pending; 13861da177e4SLinus Torvalds 13871da177e4SLinus Torvalds unsigned long sas_ss_sp; 13881da177e4SLinus Torvalds size_t sas_ss_size; 13891da177e4SLinus Torvalds int (*notifier)(void *priv); 13901da177e4SLinus Torvalds void *notifier_data; 13911da177e4SLinus Torvalds sigset_t *notifier_mask; 13921da177e4SLinus Torvalds struct audit_context *audit_context; 1393bfef93a5SAl Viro #ifdef CONFIG_AUDITSYSCALL 1394bfef93a5SAl Viro uid_t loginuid; 13954746ec5bSEric Paris unsigned int sessionid; 1396bfef93a5SAl Viro #endif 13971da177e4SLinus Torvalds seccomp_t seccomp; 13981da177e4SLinus Torvalds 13991da177e4SLinus Torvalds /* Thread group tracking */ 14001da177e4SLinus Torvalds u32 parent_exec_id; 14011da177e4SLinus Torvalds u32 self_exec_id; 140258568d2aSMiao Xie /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed, 140358568d2aSMiao Xie * mempolicy */ 14041da177e4SLinus Torvalds spinlock_t alloc_lock; 14051da177e4SLinus Torvalds 14063aa551c9SThomas Gleixner #ifdef CONFIG_GENERIC_HARDIRQS 14073aa551c9SThomas Gleixner /* IRQ handler threads */ 14083aa551c9SThomas Gleixner struct irqaction *irqaction; 14093aa551c9SThomas Gleixner #endif 14103aa551c9SThomas Gleixner 1411b29739f9SIngo Molnar /* Protection of the PI data structures: */ 14121d615482SThomas Gleixner raw_spinlock_t pi_lock; 1413b29739f9SIngo Molnar 141423f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 141523f78d4aSIngo Molnar /* PI waiters blocked on a rt_mutex held by this task */ 141623f78d4aSIngo Molnar struct plist_head pi_waiters; 141723f78d4aSIngo Molnar /* Deadlock detection and priority inheritance handling */ 141823f78d4aSIngo Molnar struct rt_mutex_waiter *pi_blocked_on; 141923f78d4aSIngo Molnar #endif 142023f78d4aSIngo Molnar 1421408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES 1422408894eeSIngo Molnar /* mutex deadlock detection */ 1423408894eeSIngo Molnar struct mutex_waiter *blocked_on; 1424408894eeSIngo Molnar #endif 1425de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS 1426de30a2b3SIngo Molnar unsigned int irq_events; 1427de30a2b3SIngo Molnar unsigned long hardirq_enable_ip; 1428de30a2b3SIngo Molnar unsigned long hardirq_disable_ip; 1429fa1452e8SHiroshi Shimamoto unsigned int hardirq_enable_event; 1430de30a2b3SIngo Molnar unsigned int hardirq_disable_event; 1431fa1452e8SHiroshi Shimamoto int hardirqs_enabled; 1432de30a2b3SIngo Molnar int hardirq_context; 1433fa1452e8SHiroshi Shimamoto unsigned long softirq_disable_ip; 1434fa1452e8SHiroshi Shimamoto unsigned long softirq_enable_ip; 1435fa1452e8SHiroshi Shimamoto unsigned int softirq_disable_event; 1436fa1452e8SHiroshi Shimamoto unsigned int softirq_enable_event; 1437fa1452e8SHiroshi Shimamoto int softirqs_enabled; 1438de30a2b3SIngo Molnar int softirq_context; 1439de30a2b3SIngo Molnar #endif 1440fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP 1441bdb9441eSPeter Zijlstra # define MAX_LOCK_DEPTH 48UL 1442fbb9ce95SIngo Molnar u64 curr_chain_key; 1443fbb9ce95SIngo Molnar int lockdep_depth; 1444fbb9ce95SIngo Molnar unsigned int lockdep_recursion; 1445c7aceabaSRichard Kennedy struct held_lock held_locks[MAX_LOCK_DEPTH]; 1446cf40bd16SNick Piggin gfp_t lockdep_reclaim_gfp; 1447fbb9ce95SIngo Molnar #endif 1448408894eeSIngo Molnar 14491da177e4SLinus Torvalds /* journalling filesystem info */ 14501da177e4SLinus Torvalds void *journal_info; 14511da177e4SLinus Torvalds 1452d89d8796SNeil Brown /* stacked block device info */ 1453bddd87c7SAkinobu Mita struct bio_list *bio_list; 1454d89d8796SNeil Brown 14551da177e4SLinus Torvalds /* VM state */ 14561da177e4SLinus Torvalds struct reclaim_state *reclaim_state; 14571da177e4SLinus Torvalds 14581da177e4SLinus Torvalds struct backing_dev_info *backing_dev_info; 14591da177e4SLinus Torvalds 14601da177e4SLinus Torvalds struct io_context *io_context; 14611da177e4SLinus Torvalds 14621da177e4SLinus Torvalds unsigned long ptrace_message; 14631da177e4SLinus Torvalds siginfo_t *last_siginfo; /* For ptrace use. */ 14647c3ab738SAndrew Morton struct task_io_accounting ioac; 14658f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT) 14661da177e4SLinus Torvalds u64 acct_rss_mem1; /* accumulated rss usage */ 14671da177e4SLinus Torvalds u64 acct_vm_mem1; /* accumulated virtual memory usage */ 146849b5cf34SJonathan Lim cputime_t acct_timexpd; /* stime + utime since last update */ 14691da177e4SLinus Torvalds #endif 14701da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS 147158568d2aSMiao Xie nodemask_t mems_allowed; /* Protected by alloc_lock */ 1472825a46afSPaul Jackson int cpuset_mem_spread_rotor; 14731da177e4SLinus Torvalds #endif 1474ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS 1475817929ecSPaul Menage /* Control Group info protected by css_set_lock */ 1476817929ecSPaul Menage struct css_set *cgroups; 1477817929ecSPaul Menage /* cg_list protected by css_set_lock and tsk->alloc_lock */ 1478817929ecSPaul Menage struct list_head cg_list; 1479ddbcc7e8SPaul Menage #endif 148042b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX 14810771dfefSIngo Molnar struct robust_list_head __user *robust_list; 148234f192c6SIngo Molnar #ifdef CONFIG_COMPAT 148334f192c6SIngo Molnar struct compat_robust_list_head __user *compat_robust_list; 148434f192c6SIngo Molnar #endif 1485c87e2837SIngo Molnar struct list_head pi_state_list; 1486c87e2837SIngo Molnar struct futex_pi_state *pi_state_cache; 148742b2dd0aSAlexey Dobriyan #endif 1488cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS 1489cdd6c482SIngo Molnar struct perf_event_context *perf_event_ctxp; 1490cdd6c482SIngo Molnar struct mutex perf_event_mutex; 1491cdd6c482SIngo Molnar struct list_head perf_event_list; 1492a63eaf34SPaul Mackerras #endif 1493c7aceabaSRichard Kennedy #ifdef CONFIG_NUMA 149458568d2aSMiao Xie struct mempolicy *mempolicy; /* Protected by alloc_lock */ 1495c7aceabaSRichard Kennedy short il_next; 1496c7aceabaSRichard Kennedy #endif 149722e2c507SJens Axboe atomic_t fs_excl; /* holding fs exclusive resources */ 1498e56d0903SIngo Molnar struct rcu_head rcu; 1499b92ce558SJens Axboe 1500b92ce558SJens Axboe /* 1501b92ce558SJens Axboe * cache last used pipe for splice 1502b92ce558SJens Axboe */ 1503b92ce558SJens Axboe struct pipe_inode_info *splice_pipe; 1504ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 1505ca74e92bSShailabh Nagar struct task_delay_info *delays; 1506ca74e92bSShailabh Nagar #endif 1507f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION 1508f4f154fdSAkinobu Mita int make_it_fail; 1509f4f154fdSAkinobu Mita #endif 15103e26c149SPeter Zijlstra struct prop_local_single dirties; 15119745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP 15129745512cSArjan van de Ven int latency_record_count; 15139745512cSArjan van de Ven struct latency_record latency_record[LT_SAVECOUNT]; 15149745512cSArjan van de Ven #endif 15156976675dSArjan van de Ven /* 15166976675dSArjan van de Ven * time slack values; these are used to round up poll() and 15176976675dSArjan van de Ven * select() etc timeout values. These are in nanoseconds. 15186976675dSArjan van de Ven */ 15196976675dSArjan van de Ven unsigned long timer_slack_ns; 15206976675dSArjan van de Ven unsigned long default_timer_slack_ns; 1521f8d570a4SDavid Miller 1522f8d570a4SDavid Miller struct list_head *scm_work_list; 1523fb52607aSFrederic Weisbecker #ifdef CONFIG_FUNCTION_GRAPH_TRACER 1524f201ae23SFrederic Weisbecker /* Index of current stored adress in ret_stack */ 1525f201ae23SFrederic Weisbecker int curr_ret_stack; 1526f201ae23SFrederic Weisbecker /* Stack of return addresses for return function tracing */ 1527f201ae23SFrederic Weisbecker struct ftrace_ret_stack *ret_stack; 15288aef2d28SSteven Rostedt /* time stamp for last schedule */ 15298aef2d28SSteven Rostedt unsigned long long ftrace_timestamp; 1530f201ae23SFrederic Weisbecker /* 1531f201ae23SFrederic Weisbecker * Number of functions that haven't been traced 1532f201ae23SFrederic Weisbecker * because of depth overrun. 1533f201ae23SFrederic Weisbecker */ 1534f201ae23SFrederic Weisbecker atomic_t trace_overrun; 1535380c4b14SFrederic Weisbecker /* Pause for the tracing */ 1536380c4b14SFrederic Weisbecker atomic_t tracing_graph_pause; 1537f201ae23SFrederic Weisbecker #endif 1538ea4e2bc4SSteven Rostedt #ifdef CONFIG_TRACING 1539ea4e2bc4SSteven Rostedt /* state flags for use by tracers */ 1540ea4e2bc4SSteven Rostedt unsigned long trace; 1541261842b7SSteven Rostedt /* bitmask of trace recursion */ 1542261842b7SSteven Rostedt unsigned long trace_recursion; 1543261842b7SSteven Rostedt #endif /* CONFIG_TRACING */ 1544d899bf7bSStefani Seibold unsigned long stack_start; 1545569b846dSKAMEZAWA Hiroyuki #ifdef CONFIG_CGROUP_MEM_RES_CTLR /* memcg uses this to do batch job */ 1546569b846dSKAMEZAWA Hiroyuki struct memcg_batch_info { 1547569b846dSKAMEZAWA Hiroyuki int do_batch; /* incremented when batch uncharge started */ 1548569b846dSKAMEZAWA Hiroyuki struct mem_cgroup *memcg; /* target memcg of uncharge */ 1549569b846dSKAMEZAWA Hiroyuki unsigned long bytes; /* uncharged usage */ 1550569b846dSKAMEZAWA Hiroyuki unsigned long memsw_bytes; /* uncharged mem+swap usage */ 1551569b846dSKAMEZAWA Hiroyuki } memcg_batch; 1552569b846dSKAMEZAWA Hiroyuki #endif 15531da177e4SLinus Torvalds }; 15541da177e4SLinus Torvalds 155576e6eee0SRusty Russell /* Future-safe accessor for struct task_struct's cpus_allowed. */ 1556a4636818SRusty Russell #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed) 155776e6eee0SRusty Russell 1558e05606d3SIngo Molnar /* 1559e05606d3SIngo Molnar * Priority of a process goes from 0..MAX_PRIO-1, valid RT 1560e05606d3SIngo Molnar * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH 1561e05606d3SIngo Molnar * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority 1562e05606d3SIngo Molnar * values are inverted: lower p->prio value means higher priority. 1563e05606d3SIngo Molnar * 1564e05606d3SIngo Molnar * The MAX_USER_RT_PRIO value allows the actual maximum 1565e05606d3SIngo Molnar * RT priority to be separate from the value exported to 1566e05606d3SIngo Molnar * user-space. This allows kernel threads to set their 1567e05606d3SIngo Molnar * priority to a value higher than any user task. Note: 1568e05606d3SIngo Molnar * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO. 1569e05606d3SIngo Molnar */ 1570e05606d3SIngo Molnar 1571e05606d3SIngo Molnar #define MAX_USER_RT_PRIO 100 1572e05606d3SIngo Molnar #define MAX_RT_PRIO MAX_USER_RT_PRIO 1573e05606d3SIngo Molnar 1574e05606d3SIngo Molnar #define MAX_PRIO (MAX_RT_PRIO + 40) 1575e05606d3SIngo Molnar #define DEFAULT_PRIO (MAX_RT_PRIO + 20) 1576e05606d3SIngo Molnar 1577e05606d3SIngo Molnar static inline int rt_prio(int prio) 1578e05606d3SIngo Molnar { 1579e05606d3SIngo Molnar if (unlikely(prio < MAX_RT_PRIO)) 1580e05606d3SIngo Molnar return 1; 1581e05606d3SIngo Molnar return 0; 1582e05606d3SIngo Molnar } 1583e05606d3SIngo Molnar 1584e868171aSAlexey Dobriyan static inline int rt_task(struct task_struct *p) 1585e05606d3SIngo Molnar { 1586e05606d3SIngo Molnar return rt_prio(p->prio); 1587e05606d3SIngo Molnar } 1588e05606d3SIngo Molnar 1589e868171aSAlexey Dobriyan static inline struct pid *task_pid(struct task_struct *task) 159022c935f4SEric W. Biederman { 159122c935f4SEric W. Biederman return task->pids[PIDTYPE_PID].pid; 159222c935f4SEric W. Biederman } 159322c935f4SEric W. Biederman 1594e868171aSAlexey Dobriyan static inline struct pid *task_tgid(struct task_struct *task) 159522c935f4SEric W. Biederman { 159622c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PID].pid; 159722c935f4SEric W. Biederman } 159822c935f4SEric W. Biederman 15996dda81f4SOleg Nesterov /* 16006dda81f4SOleg Nesterov * Without tasklist or rcu lock it is not safe to dereference 16016dda81f4SOleg Nesterov * the result of task_pgrp/task_session even if task == current, 16026dda81f4SOleg Nesterov * we can race with another thread doing sys_setsid/sys_setpgid. 16036dda81f4SOleg Nesterov */ 1604e868171aSAlexey Dobriyan static inline struct pid *task_pgrp(struct task_struct *task) 160522c935f4SEric W. Biederman { 160622c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PGID].pid; 160722c935f4SEric W. Biederman } 160822c935f4SEric W. Biederman 1609e868171aSAlexey Dobriyan static inline struct pid *task_session(struct task_struct *task) 161022c935f4SEric W. Biederman { 161122c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_SID].pid; 161222c935f4SEric W. Biederman } 161322c935f4SEric W. Biederman 16147af57294SPavel Emelyanov struct pid_namespace; 16157af57294SPavel Emelyanov 16167af57294SPavel Emelyanov /* 16177af57294SPavel Emelyanov * the helpers to get the task's different pids as they are seen 16187af57294SPavel Emelyanov * from various namespaces 16197af57294SPavel Emelyanov * 16207af57294SPavel Emelyanov * task_xid_nr() : global id, i.e. the id seen from the init namespace; 162144c4e1b2SEric W. Biederman * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of 162244c4e1b2SEric W. Biederman * current. 16237af57294SPavel Emelyanov * task_xid_nr_ns() : id seen from the ns specified; 16247af57294SPavel Emelyanov * 16257af57294SPavel Emelyanov * set_task_vxid() : assigns a virtual id to a task; 16267af57294SPavel Emelyanov * 16277af57294SPavel Emelyanov * see also pid_nr() etc in include/linux/pid.h 16287af57294SPavel Emelyanov */ 162952ee2dfdSOleg Nesterov pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, 163052ee2dfdSOleg Nesterov struct pid_namespace *ns); 16317af57294SPavel Emelyanov 1632e868171aSAlexey Dobriyan static inline pid_t task_pid_nr(struct task_struct *tsk) 16337af57294SPavel Emelyanov { 16347af57294SPavel Emelyanov return tsk->pid; 16357af57294SPavel Emelyanov } 16367af57294SPavel Emelyanov 163752ee2dfdSOleg Nesterov static inline pid_t task_pid_nr_ns(struct task_struct *tsk, 163852ee2dfdSOleg Nesterov struct pid_namespace *ns) 163952ee2dfdSOleg Nesterov { 164052ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns); 164152ee2dfdSOleg Nesterov } 16427af57294SPavel Emelyanov 16437af57294SPavel Emelyanov static inline pid_t task_pid_vnr(struct task_struct *tsk) 16447af57294SPavel Emelyanov { 164552ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL); 16467af57294SPavel Emelyanov } 16477af57294SPavel Emelyanov 16487af57294SPavel Emelyanov 1649e868171aSAlexey Dobriyan static inline pid_t task_tgid_nr(struct task_struct *tsk) 16507af57294SPavel Emelyanov { 16517af57294SPavel Emelyanov return tsk->tgid; 16527af57294SPavel Emelyanov } 16537af57294SPavel Emelyanov 16542f2a3a46SPavel Emelyanov pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); 16557af57294SPavel Emelyanov 16567af57294SPavel Emelyanov static inline pid_t task_tgid_vnr(struct task_struct *tsk) 16577af57294SPavel Emelyanov { 16587af57294SPavel Emelyanov return pid_vnr(task_tgid(tsk)); 16597af57294SPavel Emelyanov } 16607af57294SPavel Emelyanov 16617af57294SPavel Emelyanov 166252ee2dfdSOleg Nesterov static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, 166352ee2dfdSOleg Nesterov struct pid_namespace *ns) 16647af57294SPavel Emelyanov { 166552ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns); 16667af57294SPavel Emelyanov } 16677af57294SPavel Emelyanov 16687af57294SPavel Emelyanov static inline pid_t task_pgrp_vnr(struct task_struct *tsk) 16697af57294SPavel Emelyanov { 167052ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL); 16717af57294SPavel Emelyanov } 16727af57294SPavel Emelyanov 16737af57294SPavel Emelyanov 167452ee2dfdSOleg Nesterov static inline pid_t task_session_nr_ns(struct task_struct *tsk, 167552ee2dfdSOleg Nesterov struct pid_namespace *ns) 16767af57294SPavel Emelyanov { 167752ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns); 16787af57294SPavel Emelyanov } 16797af57294SPavel Emelyanov 16807af57294SPavel Emelyanov static inline pid_t task_session_vnr(struct task_struct *tsk) 16817af57294SPavel Emelyanov { 168252ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL); 16837af57294SPavel Emelyanov } 16847af57294SPavel Emelyanov 16851b0f7ffdSOleg Nesterov /* obsolete, do not use */ 16861b0f7ffdSOleg Nesterov static inline pid_t task_pgrp_nr(struct task_struct *tsk) 16871b0f7ffdSOleg Nesterov { 16881b0f7ffdSOleg Nesterov return task_pgrp_nr_ns(tsk, &init_pid_ns); 16891b0f7ffdSOleg Nesterov } 16907af57294SPavel Emelyanov 16911da177e4SLinus Torvalds /** 16921da177e4SLinus Torvalds * pid_alive - check that a task structure is not stale 16931da177e4SLinus Torvalds * @p: Task structure to be checked. 16941da177e4SLinus Torvalds * 16951da177e4SLinus Torvalds * Test if a process is not yet dead (at most zombie state) 16961da177e4SLinus Torvalds * If pid_alive fails, then pointers within the task structure 16971da177e4SLinus Torvalds * can be stale and must not be dereferenced. 16981da177e4SLinus Torvalds */ 1699e868171aSAlexey Dobriyan static inline int pid_alive(struct task_struct *p) 17001da177e4SLinus Torvalds { 170192476d7fSEric W. Biederman return p->pids[PIDTYPE_PID].pid != NULL; 17021da177e4SLinus Torvalds } 17031da177e4SLinus Torvalds 1704f400e198SSukadev Bhattiprolu /** 1705b460cbc5SSerge E. Hallyn * is_global_init - check if a task structure is init 17063260259fSHenne * @tsk: Task structure to be checked. 17073260259fSHenne * 17083260259fSHenne * Check if a task structure is the first user space task the kernel created. 1709f400e198SSukadev Bhattiprolu */ 1710e868171aSAlexey Dobriyan static inline int is_global_init(struct task_struct *tsk) 1711b461cc03SPavel Emelyanov { 1712b461cc03SPavel Emelyanov return tsk->pid == 1; 1713b461cc03SPavel Emelyanov } 1714b460cbc5SSerge E. Hallyn 1715b460cbc5SSerge E. Hallyn /* 1716b460cbc5SSerge E. Hallyn * is_container_init: 1717b460cbc5SSerge E. Hallyn * check whether in the task is init in its own pid namespace. 1718b460cbc5SSerge E. Hallyn */ 1719b461cc03SPavel Emelyanov extern int is_container_init(struct task_struct *tsk); 1720f400e198SSukadev Bhattiprolu 17219ec52099SCedric Le Goater extern struct pid *cad_pid; 17229ec52099SCedric Le Goater 17231da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk); 17241da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0) 1725e56d0903SIngo Molnar 1726158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t); 1727e56d0903SIngo Molnar 1728e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t) 1729e56d0903SIngo Molnar { 1730e56d0903SIngo Molnar if (atomic_dec_and_test(&t->usage)) 17318c7904a0SEric W. Biederman __put_task_struct(t); 1732e56d0903SIngo Molnar } 17331da177e4SLinus Torvalds 1734d180c5bcSHidetoshi Seto extern void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st); 17350cf55e1eSHidetoshi Seto extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st); 173649048622SBalbir Singh 17371da177e4SLinus Torvalds /* 17381da177e4SLinus Torvalds * Per process flags 17391da177e4SLinus Torvalds */ 17401da177e4SLinus Torvalds #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */ 17411da177e4SLinus Torvalds /* Not implemented yet, only for 486*/ 17421da177e4SLinus Torvalds #define PF_STARTING 0x00000002 /* being created */ 17431da177e4SLinus Torvalds #define PF_EXITING 0x00000004 /* getting shut down */ 1744778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ 174594886b84SLaurent Vivier #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ 17461da177e4SLinus Torvalds #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ 17474db96cf0SAndi Kleen #define PF_MCE_PROCESS 0x00000080 /* process policy on mce errors */ 17481da177e4SLinus Torvalds #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ 17491da177e4SLinus Torvalds #define PF_DUMPCORE 0x00000200 /* dumped core */ 17501da177e4SLinus Torvalds #define PF_SIGNALED 0x00000400 /* killed by a signal */ 17511da177e4SLinus Torvalds #define PF_MEMALLOC 0x00000800 /* Allocating memory */ 17521da177e4SLinus Torvalds #define PF_FLUSHER 0x00001000 /* responsible for disk writeback */ 17531da177e4SLinus Torvalds #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */ 17546301cb95SThomas Gleixner #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */ 17551da177e4SLinus Torvalds #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */ 17561da177e4SLinus Torvalds #define PF_FROZEN 0x00010000 /* frozen for system suspend */ 17571da177e4SLinus Torvalds #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ 17581da177e4SLinus Torvalds #define PF_KSWAPD 0x00040000 /* I am kswapd */ 175935451beeSHugh Dickins #define PF_OOM_ORIGIN 0x00080000 /* Allocating much memory to others */ 17601da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */ 1761246bb0b1SOleg Nesterov #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ 1762b31dc66aSJens Axboe #define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */ 1763b31dc66aSJens Axboe #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ 1764b31dc66aSJens Axboe #define PF_SPREAD_PAGE 0x01000000 /* Spread page cache over cpuset */ 1765b31dc66aSJens Axboe #define PF_SPREAD_SLAB 0x02000000 /* Spread some slab caches over cpuset */ 17669985b0baSDavid Rientjes #define PF_THREAD_BOUND 0x04000000 /* Thread bound to specific cpu */ 17674db96cf0SAndi Kleen #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */ 1768c61afb18SPaul Jackson #define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */ 176961a87122SThomas Gleixner #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */ 1770ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezeable */ 1771ebb12db5SRafael J. Wysocki #define PF_FREEZER_NOSIG 0x80000000 /* Freezer won't send signals to it */ 17721da177e4SLinus Torvalds 17731da177e4SLinus Torvalds /* 17741da177e4SLinus Torvalds * Only the _current_ task can read/write to tsk->flags, but other 17751da177e4SLinus Torvalds * tasks can access tsk->flags in readonly mode for example 17761da177e4SLinus Torvalds * with tsk_used_math (like during threaded core dumping). 17771da177e4SLinus Torvalds * There is however an exception to this rule during ptrace 17781da177e4SLinus Torvalds * or during fork: the ptracer task is allowed to write to the 17791da177e4SLinus Torvalds * child->flags of its traced child (same goes for fork, the parent 17801da177e4SLinus Torvalds * can write to the child->flags), because we're guaranteed the 17811da177e4SLinus Torvalds * child is not running and in turn not changing child->flags 17821da177e4SLinus Torvalds * at the same time the parent does it. 17831da177e4SLinus Torvalds */ 17841da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0) 17851da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0) 17861da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current) 17871da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current) 17881da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \ 17891da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0) 17901da177e4SLinus Torvalds #define conditional_used_math(condition) \ 17911da177e4SLinus Torvalds conditional_stopped_child_used_math(condition, current) 17921da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \ 17931da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0) 17941da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */ 17951da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH) 17961da177e4SLinus Torvalds #define used_math() tsk_used_math(current) 17971da177e4SLinus Torvalds 1798f41d911fSPaul E. McKenney #ifdef CONFIG_TREE_PREEMPT_RCU 1799f41d911fSPaul E. McKenney 1800f41d911fSPaul E. McKenney #define RCU_READ_UNLOCK_BLOCKED (1 << 0) /* blocked while in RCU read-side. */ 1801f41d911fSPaul E. McKenney #define RCU_READ_UNLOCK_NEED_QS (1 << 1) /* RCU core needs CPU response. */ 1802f41d911fSPaul E. McKenney 1803f41d911fSPaul E. McKenney static inline void rcu_copy_process(struct task_struct *p) 1804f41d911fSPaul E. McKenney { 1805f41d911fSPaul E. McKenney p->rcu_read_lock_nesting = 0; 1806f41d911fSPaul E. McKenney p->rcu_read_unlock_special = 0; 1807dd5d19baSPaul E. McKenney p->rcu_blocked_node = NULL; 1808f41d911fSPaul E. McKenney INIT_LIST_HEAD(&p->rcu_node_entry); 1809f41d911fSPaul E. McKenney } 1810f41d911fSPaul E. McKenney 1811f41d911fSPaul E. McKenney #else 1812f41d911fSPaul E. McKenney 1813f41d911fSPaul E. McKenney static inline void rcu_copy_process(struct task_struct *p) 1814f41d911fSPaul E. McKenney { 1815f41d911fSPaul E. McKenney } 1816f41d911fSPaul E. McKenney 1817f41d911fSPaul E. McKenney #endif 1818f41d911fSPaul E. McKenney 18191da177e4SLinus Torvalds #ifdef CONFIG_SMP 1820cd8ba7cdSMike Travis extern int set_cpus_allowed_ptr(struct task_struct *p, 182196f874e2SRusty Russell const struct cpumask *new_mask); 18221da177e4SLinus Torvalds #else 1823cd8ba7cdSMike Travis static inline int set_cpus_allowed_ptr(struct task_struct *p, 182496f874e2SRusty Russell const struct cpumask *new_mask) 18251da177e4SLinus Torvalds { 182696f874e2SRusty Russell if (!cpumask_test_cpu(0, new_mask)) 18271da177e4SLinus Torvalds return -EINVAL; 18281da177e4SLinus Torvalds return 0; 18291da177e4SLinus Torvalds } 18301da177e4SLinus Torvalds #endif 1831e0ad9556SRusty Russell 1832e0ad9556SRusty Russell #ifndef CONFIG_CPUMASK_OFFSTACK 1833cd8ba7cdSMike Travis static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask) 1834cd8ba7cdSMike Travis { 1835cd8ba7cdSMike Travis return set_cpus_allowed_ptr(p, &new_mask); 1836cd8ba7cdSMike Travis } 1837e0ad9556SRusty Russell #endif 18381da177e4SLinus Torvalds 1839b342501cSIngo Molnar /* 1840b342501cSIngo Molnar * Architectures can set this to 1 if they have specified 1841b342501cSIngo Molnar * CONFIG_HAVE_UNSTABLE_SCHED_CLOCK in their arch Kconfig, 1842b342501cSIngo Molnar * but then during bootup it turns out that sched_clock() 1843b342501cSIngo Molnar * is reliable after all: 1844b342501cSIngo Molnar */ 1845b342501cSIngo Molnar #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK 1846b342501cSIngo Molnar extern int sched_clock_stable; 1847b342501cSIngo Molnar #endif 1848b342501cSIngo Molnar 18491bbfa6f2SMike Frysinger /* ftrace calls sched_clock() directly */ 18501bbfa6f2SMike Frysinger extern unsigned long long notrace sched_clock(void); 1851e436d800SIngo Molnar 1852c1955a3dSPeter Zijlstra extern void sched_clock_init(void); 1853c1955a3dSPeter Zijlstra extern u64 sched_clock_cpu(int cpu); 1854c1955a3dSPeter Zijlstra 18553e51f33fSPeter Zijlstra #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK 18563e51f33fSPeter Zijlstra static inline void sched_clock_tick(void) 18573e51f33fSPeter Zijlstra { 18583e51f33fSPeter Zijlstra } 18593e51f33fSPeter Zijlstra 18603e51f33fSPeter Zijlstra static inline void sched_clock_idle_sleep_event(void) 18613e51f33fSPeter Zijlstra { 18623e51f33fSPeter Zijlstra } 18633e51f33fSPeter Zijlstra 18643e51f33fSPeter Zijlstra static inline void sched_clock_idle_wakeup_event(u64 delta_ns) 18653e51f33fSPeter Zijlstra { 18663e51f33fSPeter Zijlstra } 18673e51f33fSPeter Zijlstra #else 18683e51f33fSPeter Zijlstra extern void sched_clock_tick(void); 18693e51f33fSPeter Zijlstra extern void sched_clock_idle_sleep_event(void); 18703e51f33fSPeter Zijlstra extern void sched_clock_idle_wakeup_event(u64 delta_ns); 18713e51f33fSPeter Zijlstra #endif 18723e51f33fSPeter Zijlstra 1873e436d800SIngo Molnar /* 1874e436d800SIngo Molnar * For kernel-internal use: high-speed (but slightly incorrect) per-cpu 1875e436d800SIngo Molnar * clock constructed from sched_clock(): 1876e436d800SIngo Molnar */ 1877e436d800SIngo Molnar extern unsigned long long cpu_clock(int cpu); 1878e436d800SIngo Molnar 187936c8b586SIngo Molnar extern unsigned long long 188041b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task); 1881f06febc9SFrank Mayhar extern unsigned long long thread_group_sched_runtime(struct task_struct *task); 18821da177e4SLinus Torvalds 18831da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */ 18841da177e4SLinus Torvalds #ifdef CONFIG_SMP 18851da177e4SLinus Torvalds extern void sched_exec(void); 18861da177e4SLinus Torvalds #else 18871da177e4SLinus Torvalds #define sched_exec() {} 18881da177e4SLinus Torvalds #endif 18891da177e4SLinus Torvalds 18902aa44d05SIngo Molnar extern void sched_clock_idle_sleep_event(void); 18912aa44d05SIngo Molnar extern void sched_clock_idle_wakeup_event(u64 delta_ns); 1892bb29ab26SIngo Molnar 18931da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU 18941da177e4SLinus Torvalds extern void idle_task_exit(void); 18951da177e4SLinus Torvalds #else 18961da177e4SLinus Torvalds static inline void idle_task_exit(void) {} 18971da177e4SLinus Torvalds #endif 18981da177e4SLinus Torvalds 18991da177e4SLinus Torvalds extern void sched_idle_next(void); 1900b29739f9SIngo Molnar 190106d8308cSThomas Gleixner #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP) 190206d8308cSThomas Gleixner extern void wake_up_idle_cpu(int cpu); 190306d8308cSThomas Gleixner #else 190406d8308cSThomas Gleixner static inline void wake_up_idle_cpu(int cpu) { } 190506d8308cSThomas Gleixner #endif 190606d8308cSThomas Gleixner 190721805085SPeter Zijlstra extern unsigned int sysctl_sched_latency; 1908b2be5e96SPeter Zijlstra extern unsigned int sysctl_sched_min_granularity; 1909bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity; 191047fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_ratelimit; 191147fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_thresh; 1912bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first; 19131983a922SChristian Ehrhardt 19141983a922SChristian Ehrhardt enum sched_tunable_scaling { 19151983a922SChristian Ehrhardt SCHED_TUNABLESCALING_NONE, 19161983a922SChristian Ehrhardt SCHED_TUNABLESCALING_LOG, 19171983a922SChristian Ehrhardt SCHED_TUNABLESCALING_LINEAR, 19181983a922SChristian Ehrhardt SCHED_TUNABLESCALING_END, 19191983a922SChristian Ehrhardt }; 19201983a922SChristian Ehrhardt extern enum sched_tunable_scaling sysctl_sched_tunable_scaling; 19211983a922SChristian Ehrhardt 19222bba22c5SMike Galbraith #ifdef CONFIG_SCHED_DEBUG 1923da84d961SIngo Molnar extern unsigned int sysctl_sched_migration_cost; 1924b82d9fddSPeter Zijlstra extern unsigned int sysctl_sched_nr_migrate; 1925e9e9250bSPeter Zijlstra extern unsigned int sysctl_sched_time_avg; 1926cd1bb94bSArun R Bharadwaj extern unsigned int sysctl_timer_migration; 1927b2be5e96SPeter Zijlstra 19281983a922SChristian Ehrhardt int sched_proc_update_handler(struct ctl_table *table, int write, 19298d65af78SAlexey Dobriyan void __user *buffer, size_t *length, 1930b2be5e96SPeter Zijlstra loff_t *ppos); 19312bd8e6d4SIngo Molnar #endif 1932eea08f32SArun R Bharadwaj #ifdef CONFIG_SCHED_DEBUG 1933eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void) 1934eea08f32SArun R Bharadwaj { 1935eea08f32SArun R Bharadwaj return sysctl_timer_migration; 1936eea08f32SArun R Bharadwaj } 1937eea08f32SArun R Bharadwaj #else 1938eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void) 1939eea08f32SArun R Bharadwaj { 1940eea08f32SArun R Bharadwaj return 1; 1941eea08f32SArun R Bharadwaj } 1942eea08f32SArun R Bharadwaj #endif 19439f0c1e56SPeter Zijlstra extern unsigned int sysctl_sched_rt_period; 19449f0c1e56SPeter Zijlstra extern int sysctl_sched_rt_runtime; 19452bd8e6d4SIngo Molnar 1946d0b27fa7SPeter Zijlstra int sched_rt_handler(struct ctl_table *table, int write, 19478d65af78SAlexey Dobriyan void __user *buffer, size_t *lenp, 1948d0b27fa7SPeter Zijlstra loff_t *ppos); 1949d0b27fa7SPeter Zijlstra 19502bd8e6d4SIngo Molnar extern unsigned int sysctl_sched_compat_yield; 1951bf0f6f24SIngo Molnar 1952b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES 195336c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p); 195436c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio); 195536c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p); 1956b29739f9SIngo Molnar #else 1957e868171aSAlexey Dobriyan static inline int rt_mutex_getprio(struct task_struct *p) 1958b29739f9SIngo Molnar { 1959b29739f9SIngo Molnar return p->normal_prio; 1960b29739f9SIngo Molnar } 196195e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p) do { } while (0) 1962b29739f9SIngo Molnar #endif 1963b29739f9SIngo Molnar 196436c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice); 196536c8b586SIngo Molnar extern int task_prio(const struct task_struct *p); 196636c8b586SIngo Molnar extern int task_nice(const struct task_struct *p); 196736c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice); 196836c8b586SIngo Molnar extern int task_curr(const struct task_struct *p); 19691da177e4SLinus Torvalds extern int idle_cpu(int cpu); 19701da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *); 1971961ccdddSRusty Russell extern int sched_setscheduler_nocheck(struct task_struct *, int, 1972961ccdddSRusty Russell struct sched_param *); 197336c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu); 197436c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu); 197536c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p); 19761da177e4SLinus Torvalds 19771da177e4SLinus Torvalds void yield(void); 19781da177e4SLinus Torvalds 19791da177e4SLinus Torvalds /* 19801da177e4SLinus Torvalds * The default (Linux) execution domain. 19811da177e4SLinus Torvalds */ 19821da177e4SLinus Torvalds extern struct exec_domain default_exec_domain; 19831da177e4SLinus Torvalds 19841da177e4SLinus Torvalds union thread_union { 19851da177e4SLinus Torvalds struct thread_info thread_info; 19861da177e4SLinus Torvalds unsigned long stack[THREAD_SIZE/sizeof(long)]; 19871da177e4SLinus Torvalds }; 19881da177e4SLinus Torvalds 19891da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END 19901da177e4SLinus Torvalds static inline int kstack_end(void *addr) 19911da177e4SLinus Torvalds { 19921da177e4SLinus Torvalds /* Reliable end of stack detection: 19931da177e4SLinus Torvalds * Some APM bios versions misalign the stack 19941da177e4SLinus Torvalds */ 19951da177e4SLinus Torvalds return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*))); 19961da177e4SLinus Torvalds } 19971da177e4SLinus Torvalds #endif 19981da177e4SLinus Torvalds 19991da177e4SLinus Torvalds extern union thread_union init_thread_union; 20001da177e4SLinus Torvalds extern struct task_struct init_task; 20011da177e4SLinus Torvalds 20021da177e4SLinus Torvalds extern struct mm_struct init_mm; 20031da177e4SLinus Torvalds 2004198fe21bSPavel Emelyanov extern struct pid_namespace init_pid_ns; 2005198fe21bSPavel Emelyanov 2006198fe21bSPavel Emelyanov /* 2007198fe21bSPavel Emelyanov * find a task by one of its numerical ids 2008198fe21bSPavel Emelyanov * 2009198fe21bSPavel Emelyanov * find_task_by_pid_ns(): 2010198fe21bSPavel Emelyanov * finds a task by its pid in the specified namespace 2011228ebcbeSPavel Emelyanov * find_task_by_vpid(): 2012228ebcbeSPavel Emelyanov * finds a task by its virtual pid 2013198fe21bSPavel Emelyanov * 2014e49859e7SPavel Emelyanov * see also find_vpid() etc in include/linux/pid.h 2015198fe21bSPavel Emelyanov */ 2016198fe21bSPavel Emelyanov 2017228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_vpid(pid_t nr); 2018228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid_ns(pid_t nr, 2019228ebcbeSPavel Emelyanov struct pid_namespace *ns); 2020198fe21bSPavel Emelyanov 20218520d7c7SOleg Nesterov extern void __set_special_pids(struct pid *pid); 20221da177e4SLinus Torvalds 20231da177e4SLinus Torvalds /* per-UID process charging. */ 2024acce292cSCedric Le Goater extern struct user_struct * alloc_uid(struct user_namespace *, uid_t); 20251da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u) 20261da177e4SLinus Torvalds { 20271da177e4SLinus Torvalds atomic_inc(&u->__count); 20281da177e4SLinus Torvalds return u; 20291da177e4SLinus Torvalds } 20301da177e4SLinus Torvalds extern void free_uid(struct user_struct *); 203128f300d2SPavel Emelyanov extern void release_uids(struct user_namespace *ns); 20321da177e4SLinus Torvalds 20331da177e4SLinus Torvalds #include <asm/current.h> 20341da177e4SLinus Torvalds 20353171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks); 20361da177e4SLinus Torvalds 2037b3c97528SHarvey Harrison extern int wake_up_state(struct task_struct *tsk, unsigned int state); 2038b3c97528SHarvey Harrison extern int wake_up_process(struct task_struct *tsk); 2039b3c97528SHarvey Harrison extern void wake_up_new_task(struct task_struct *tsk, 2040b3c97528SHarvey Harrison unsigned long clone_flags); 20411da177e4SLinus Torvalds #ifdef CONFIG_SMP 20421da177e4SLinus Torvalds extern void kick_process(struct task_struct *tsk); 20431da177e4SLinus Torvalds #else 20441da177e4SLinus Torvalds static inline void kick_process(struct task_struct *tsk) { } 20451da177e4SLinus Torvalds #endif 2046ad46c2c4SIngo Molnar extern void sched_fork(struct task_struct *p, int clone_flags); 2047ad46c2c4SIngo Molnar extern void sched_dead(struct task_struct *p); 20481da177e4SLinus Torvalds 20491da177e4SLinus Torvalds extern void proc_caches_init(void); 20501da177e4SLinus Torvalds extern void flush_signals(struct task_struct *); 20513bcac026SDavid Howells extern void __flush_signals(struct task_struct *); 205210ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *); 20531da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default); 20541da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info); 20551da177e4SLinus Torvalds 20561da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) 20571da177e4SLinus Torvalds { 20581da177e4SLinus Torvalds unsigned long flags; 20591da177e4SLinus Torvalds int ret; 20601da177e4SLinus Torvalds 20611da177e4SLinus Torvalds spin_lock_irqsave(&tsk->sighand->siglock, flags); 20621da177e4SLinus Torvalds ret = dequeue_signal(tsk, mask, info); 20631da177e4SLinus Torvalds spin_unlock_irqrestore(&tsk->sighand->siglock, flags); 20641da177e4SLinus Torvalds 20651da177e4SLinus Torvalds return ret; 20661da177e4SLinus Torvalds } 20671da177e4SLinus Torvalds 20681da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv, 20691da177e4SLinus Torvalds sigset_t *mask); 20701da177e4SLinus Torvalds extern void unblock_all_signals(void); 20711da177e4SLinus Torvalds extern void release_task(struct task_struct * p); 20721da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *); 20731da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *); 20741da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *); 2075c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp); 2076c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid); 20772425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32); 2078c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv); 2079c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv); 2080c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t); 20812b2a1ff6SRoland McGrath extern int do_notify_parent(struct task_struct *, int); 2082a7f0765eSOleg Nesterov extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent); 20831da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *); 20841da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int); 20851da177e4SLinus Torvalds extern void zap_other_threads(struct task_struct *p); 20861da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void); 20871da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *); 2088ac5c2153SOleg Nesterov extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group); 20899ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); 20901da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long); 20911da177e4SLinus Torvalds 20929ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv) 20939ec52099SCedric Le Goater { 20949ec52099SCedric Le Goater return kill_pid(cad_pid, sig, priv); 20959ec52099SCedric Le Goater } 20969ec52099SCedric Le Goater 20971da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info. */ 20981da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0) 20991da177e4SLinus Torvalds #define SEND_SIG_PRIV ((struct siginfo *) 1) 21001da177e4SLinus Torvalds #define SEND_SIG_FORCED ((struct siginfo *) 2) 21011da177e4SLinus Torvalds 21022a855dd0SSebastian Andrzej Siewior /* 21032a855dd0SSebastian Andrzej Siewior * True if we are on the alternate signal stack. 21042a855dd0SSebastian Andrzej Siewior */ 21051da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp) 21061da177e4SLinus Torvalds { 21072a855dd0SSebastian Andrzej Siewior #ifdef CONFIG_STACK_GROWSUP 21082a855dd0SSebastian Andrzej Siewior return sp >= current->sas_ss_sp && 21092a855dd0SSebastian Andrzej Siewior sp - current->sas_ss_sp < current->sas_ss_size; 21102a855dd0SSebastian Andrzej Siewior #else 21112a855dd0SSebastian Andrzej Siewior return sp > current->sas_ss_sp && 21122a855dd0SSebastian Andrzej Siewior sp - current->sas_ss_sp <= current->sas_ss_size; 21132a855dd0SSebastian Andrzej Siewior #endif 21141da177e4SLinus Torvalds } 21151da177e4SLinus Torvalds 21161da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp) 21171da177e4SLinus Torvalds { 21181da177e4SLinus Torvalds return (current->sas_ss_size == 0 ? SS_DISABLE 21191da177e4SLinus Torvalds : on_sig_stack(sp) ? SS_ONSTACK : 0); 21201da177e4SLinus Torvalds } 21211da177e4SLinus Torvalds 21221da177e4SLinus Torvalds /* 21231da177e4SLinus Torvalds * Routines for handling mm_structs 21241da177e4SLinus Torvalds */ 21251da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void); 21261da177e4SLinus Torvalds 21271da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */ 2128b3c97528SHarvey Harrison extern void __mmdrop(struct mm_struct *); 21291da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm) 21301da177e4SLinus Torvalds { 21316fb43d7bSIngo Molnar if (unlikely(atomic_dec_and_test(&mm->mm_count))) 21321da177e4SLinus Torvalds __mmdrop(mm); 21331da177e4SLinus Torvalds } 21341da177e4SLinus Torvalds 21351da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */ 21361da177e4SLinus Torvalds extern void mmput(struct mm_struct *); 21371da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */ 21381da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task); 21391da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */ 21401da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *); 2141402b0862SCarsten Otte /* Allocate a new mm structure and copy contents from tsk->mm */ 2142402b0862SCarsten Otte extern struct mm_struct *dup_mm(struct task_struct *tsk); 21431da177e4SLinus Torvalds 21446f2c55b8SAlexey Dobriyan extern int copy_thread(unsigned long, unsigned long, unsigned long, 21456f2c55b8SAlexey Dobriyan struct task_struct *, struct pt_regs *); 21461da177e4SLinus Torvalds extern void flush_thread(void); 21471da177e4SLinus Torvalds extern void exit_thread(void); 21481da177e4SLinus Torvalds 21491da177e4SLinus Torvalds extern void exit_files(struct task_struct *); 21506b3934efSOleg Nesterov extern void __cleanup_signal(struct signal_struct *); 2151a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *); 2152cbaffba1SOleg Nesterov 21531da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *); 2154cbaffba1SOleg Nesterov extern void flush_itimer_signals(void); 21551da177e4SLinus Torvalds 21561da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int); 21571da177e4SLinus Torvalds 21581da177e4SLinus Torvalds extern void daemonize(const char *, ...); 21591da177e4SLinus Torvalds extern int allow_signal(int); 21601da177e4SLinus Torvalds extern int disallow_signal(int); 21611da177e4SLinus Torvalds 21621da177e4SLinus Torvalds extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *); 21631da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *); 216436c8b586SIngo Molnar struct task_struct *fork_idle(int); 21651da177e4SLinus Torvalds 21661da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from); 216759714d65SAndrew Morton extern char *get_task_comm(char *to, struct task_struct *tsk); 21681da177e4SLinus Torvalds 21691da177e4SLinus Torvalds #ifdef CONFIG_SMP 2170a26b89f0SMarkus Metzger extern void wait_task_context_switch(struct task_struct *p); 217185ba2d86SRoland McGrath extern unsigned long wait_task_inactive(struct task_struct *, long match_state); 21721da177e4SLinus Torvalds #else 2173a26b89f0SMarkus Metzger static inline void wait_task_context_switch(struct task_struct *p) {} 217485ba2d86SRoland McGrath static inline unsigned long wait_task_inactive(struct task_struct *p, 217585ba2d86SRoland McGrath long match_state) 217685ba2d86SRoland McGrath { 217785ba2d86SRoland McGrath return 1; 217885ba2d86SRoland McGrath } 21791da177e4SLinus Torvalds #endif 21801da177e4SLinus Torvalds 218105725f7eSJiri Pirko #define next_task(p) \ 218205725f7eSJiri Pirko list_entry_rcu((p)->tasks.next, struct task_struct, tasks) 21831da177e4SLinus Torvalds 21841da177e4SLinus Torvalds #define for_each_process(p) \ 21851da177e4SLinus Torvalds for (p = &init_task ; (p = next_task(p)) != &init_task ; ) 21861da177e4SLinus Torvalds 21875bb459bbSOleg Nesterov extern bool current_is_single_threaded(void); 2188d84f4f99SDavid Howells 21891da177e4SLinus Torvalds /* 21901da177e4SLinus Torvalds * Careful: do_each_thread/while_each_thread is a double loop so 21911da177e4SLinus Torvalds * 'break' will not work as expected - use goto instead. 21921da177e4SLinus Torvalds */ 21931da177e4SLinus Torvalds #define do_each_thread(g, t) \ 21941da177e4SLinus Torvalds for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do 21951da177e4SLinus Torvalds 21961da177e4SLinus Torvalds #define while_each_thread(g, t) \ 21971da177e4SLinus Torvalds while ((t = next_thread(t)) != g) 21981da177e4SLinus Torvalds 2199de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */ 2200de12a787SEric W. Biederman #define thread_group_leader(p) (p == p->group_leader) 22011da177e4SLinus Torvalds 22020804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process 22030804ef4bSEric W. Biederman * to have the pid of the thread group leader without actually being 22040804ef4bSEric W. Biederman * the thread group leader. For iteration through the pids in proc 22050804ef4bSEric W. Biederman * all we care about is that we have a task with the appropriate 22060804ef4bSEric W. Biederman * pid, we don't actually care if we have the right task. 22070804ef4bSEric W. Biederman */ 2208e868171aSAlexey Dobriyan static inline int has_group_leader_pid(struct task_struct *p) 22090804ef4bSEric W. Biederman { 22100804ef4bSEric W. Biederman return p->pid == p->tgid; 22110804ef4bSEric W. Biederman } 22120804ef4bSEric W. Biederman 2213bac0abd6SPavel Emelyanov static inline 2214bac0abd6SPavel Emelyanov int same_thread_group(struct task_struct *p1, struct task_struct *p2) 2215bac0abd6SPavel Emelyanov { 2216bac0abd6SPavel Emelyanov return p1->tgid == p2->tgid; 2217bac0abd6SPavel Emelyanov } 2218bac0abd6SPavel Emelyanov 221936c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p) 222047e65328SOleg Nesterov { 222105725f7eSJiri Pirko return list_entry_rcu(p->thread_group.next, 222236c8b586SIngo Molnar struct task_struct, thread_group); 222347e65328SOleg Nesterov } 222447e65328SOleg Nesterov 2225e868171aSAlexey Dobriyan static inline int thread_group_empty(struct task_struct *p) 22261da177e4SLinus Torvalds { 222747e65328SOleg Nesterov return list_empty(&p->thread_group); 22281da177e4SLinus Torvalds } 22291da177e4SLinus Torvalds 22301da177e4SLinus Torvalds #define delay_group_leader(p) \ 22311da177e4SLinus Torvalds (thread_group_leader(p) && !thread_group_empty(p)) 22321da177e4SLinus Torvalds 223339c626aeSOleg Nesterov static inline int task_detached(struct task_struct *p) 223439c626aeSOleg Nesterov { 223539c626aeSOleg Nesterov return p->exit_signal == -1; 223639c626aeSOleg Nesterov } 223739c626aeSOleg Nesterov 22381da177e4SLinus Torvalds /* 2239260ea101SEric W. Biederman * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring 224022e2c507SJens Axboe * subscriptions and synchronises with wait4(). Also used in procfs. Also 2241ddbcc7e8SPaul Menage * pins the final release of task.io_context. Also protects ->cpuset and 2242ddbcc7e8SPaul Menage * ->cgroup.subsys[]. 22431da177e4SLinus Torvalds * 22441da177e4SLinus Torvalds * Nests both inside and outside of read_lock(&tasklist_lock). 22451da177e4SLinus Torvalds * It must not be nested with write_lock_irq(&tasklist_lock), 22461da177e4SLinus Torvalds * neither inside nor outside. 22471da177e4SLinus Torvalds */ 22481da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p) 22491da177e4SLinus Torvalds { 22501da177e4SLinus Torvalds spin_lock(&p->alloc_lock); 22511da177e4SLinus Torvalds } 22521da177e4SLinus Torvalds 22531da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p) 22541da177e4SLinus Torvalds { 22551da177e4SLinus Torvalds spin_unlock(&p->alloc_lock); 22561da177e4SLinus Torvalds } 22571da177e4SLinus Torvalds 2258f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk, 2259f63ee72eSOleg Nesterov unsigned long *flags); 2260f63ee72eSOleg Nesterov 2261f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk, 2262f63ee72eSOleg Nesterov unsigned long *flags) 2263f63ee72eSOleg Nesterov { 2264f63ee72eSOleg Nesterov spin_unlock_irqrestore(&tsk->sighand->siglock, *flags); 2265f63ee72eSOleg Nesterov } 2266f63ee72eSOleg Nesterov 2267f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS 2268f037360fSAl Viro 2269f7e4217bSRoman Zippel #define task_thread_info(task) ((struct thread_info *)(task)->stack) 2270f7e4217bSRoman Zippel #define task_stack_page(task) ((task)->stack) 2271a1261f54SAl Viro 227210ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org) 227310ebffdeSAl Viro { 227410ebffdeSAl Viro *task_thread_info(p) = *task_thread_info(org); 227510ebffdeSAl Viro task_thread_info(p)->task = p; 227610ebffdeSAl Viro } 227710ebffdeSAl Viro 227810ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p) 227910ebffdeSAl Viro { 2280f7e4217bSRoman Zippel return (unsigned long *)(task_thread_info(p) + 1); 228110ebffdeSAl Viro } 228210ebffdeSAl Viro 2283f037360fSAl Viro #endif 2284f037360fSAl Viro 22858b05c7e6SFUJITA Tomonori static inline int object_is_on_stack(void *obj) 22868b05c7e6SFUJITA Tomonori { 22878b05c7e6SFUJITA Tomonori void *stack = task_stack_page(current); 22888b05c7e6SFUJITA Tomonori 22898b05c7e6SFUJITA Tomonori return (obj >= stack) && (obj < (stack + THREAD_SIZE)); 22908b05c7e6SFUJITA Tomonori } 22918b05c7e6SFUJITA Tomonori 22928c9843e5SBenjamin Herrenschmidt extern void thread_info_cache_init(void); 22938c9843e5SBenjamin Herrenschmidt 22947c9f8861SEric Sandeen #ifdef CONFIG_DEBUG_STACK_USAGE 22957c9f8861SEric Sandeen static inline unsigned long stack_not_used(struct task_struct *p) 22967c9f8861SEric Sandeen { 22977c9f8861SEric Sandeen unsigned long *n = end_of_stack(p); 22987c9f8861SEric Sandeen 22997c9f8861SEric Sandeen do { /* Skip over canary */ 23007c9f8861SEric Sandeen n++; 23017c9f8861SEric Sandeen } while (!*n); 23027c9f8861SEric Sandeen 23037c9f8861SEric Sandeen return (unsigned long)n - (unsigned long)end_of_stack(p); 23047c9f8861SEric Sandeen } 23057c9f8861SEric Sandeen #endif 23067c9f8861SEric Sandeen 23071da177e4SLinus Torvalds /* set thread flags in other task's structures 23081da177e4SLinus Torvalds * - see asm/thread_info.h for TIF_xxxx flags available 23091da177e4SLinus Torvalds */ 23101da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag) 23111da177e4SLinus Torvalds { 2312a1261f54SAl Viro set_ti_thread_flag(task_thread_info(tsk), flag); 23131da177e4SLinus Torvalds } 23141da177e4SLinus Torvalds 23151da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag) 23161da177e4SLinus Torvalds { 2317a1261f54SAl Viro clear_ti_thread_flag(task_thread_info(tsk), flag); 23181da177e4SLinus Torvalds } 23191da177e4SLinus Torvalds 23201da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag) 23211da177e4SLinus Torvalds { 2322a1261f54SAl Viro return test_and_set_ti_thread_flag(task_thread_info(tsk), flag); 23231da177e4SLinus Torvalds } 23241da177e4SLinus Torvalds 23251da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag) 23261da177e4SLinus Torvalds { 2327a1261f54SAl Viro return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag); 23281da177e4SLinus Torvalds } 23291da177e4SLinus Torvalds 23301da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag) 23311da177e4SLinus Torvalds { 2332a1261f54SAl Viro return test_ti_thread_flag(task_thread_info(tsk), flag); 23331da177e4SLinus Torvalds } 23341da177e4SLinus Torvalds 23351da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk) 23361da177e4SLinus Torvalds { 23371da177e4SLinus Torvalds set_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 23381da177e4SLinus Torvalds } 23391da177e4SLinus Torvalds 23401da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk) 23411da177e4SLinus Torvalds { 23421da177e4SLinus Torvalds clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 23431da177e4SLinus Torvalds } 23441da177e4SLinus Torvalds 23458ae121acSGregory Haskins static inline int test_tsk_need_resched(struct task_struct *tsk) 23468ae121acSGregory Haskins { 23478ae121acSGregory Haskins return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED)); 23488ae121acSGregory Haskins } 23498ae121acSGregory Haskins 2350690cc3ffSEric W. Biederman static inline int restart_syscall(void) 2351690cc3ffSEric W. Biederman { 2352690cc3ffSEric W. Biederman set_tsk_thread_flag(current, TIF_SIGPENDING); 2353690cc3ffSEric W. Biederman return -ERESTARTNOINTR; 2354690cc3ffSEric W. Biederman } 2355690cc3ffSEric W. Biederman 23561da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p) 23571da177e4SLinus Torvalds { 23581da177e4SLinus Torvalds return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING)); 23591da177e4SLinus Torvalds } 23601da177e4SLinus Torvalds 2361d9588725SRoland McGrath static inline int __fatal_signal_pending(struct task_struct *p) 2362d9588725SRoland McGrath { 2363d9588725SRoland McGrath return unlikely(sigismember(&p->pending.signal, SIGKILL)); 2364d9588725SRoland McGrath } 2365f776d12dSMatthew Wilcox 2366f776d12dSMatthew Wilcox static inline int fatal_signal_pending(struct task_struct *p) 2367f776d12dSMatthew Wilcox { 2368f776d12dSMatthew Wilcox return signal_pending(p) && __fatal_signal_pending(p); 2369f776d12dSMatthew Wilcox } 2370f776d12dSMatthew Wilcox 237116882c1eSOleg Nesterov static inline int signal_pending_state(long state, struct task_struct *p) 237216882c1eSOleg Nesterov { 237316882c1eSOleg Nesterov if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL))) 237416882c1eSOleg Nesterov return 0; 237516882c1eSOleg Nesterov if (!signal_pending(p)) 237616882c1eSOleg Nesterov return 0; 237716882c1eSOleg Nesterov 237816882c1eSOleg Nesterov return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p); 237916882c1eSOleg Nesterov } 238016882c1eSOleg Nesterov 23811da177e4SLinus Torvalds static inline int need_resched(void) 23821da177e4SLinus Torvalds { 23839404ef02SLinus Torvalds return unlikely(test_thread_flag(TIF_NEED_RESCHED)); 23841da177e4SLinus Torvalds } 23851da177e4SLinus Torvalds 23861da177e4SLinus Torvalds /* 23871da177e4SLinus Torvalds * cond_resched() and cond_resched_lock(): latency reduction via 23881da177e4SLinus Torvalds * explicit rescheduling in places that are safe. The return 23891da177e4SLinus Torvalds * value indicates whether a reschedule was done in fact. 23901da177e4SLinus Torvalds * cond_resched_lock() will drop the spinlock before scheduling, 23911da177e4SLinus Torvalds * cond_resched_softirq() will enable bhs before scheduling. 23921da177e4SLinus Torvalds */ 2393c3921ab7SLinus Torvalds extern int _cond_resched(void); 23946f80bd98SFrederic Weisbecker 2395613afbf8SFrederic Weisbecker #define cond_resched() ({ \ 2396613afbf8SFrederic Weisbecker __might_sleep(__FILE__, __LINE__, 0); \ 2397613afbf8SFrederic Weisbecker _cond_resched(); \ 2398613afbf8SFrederic Weisbecker }) 23996f80bd98SFrederic Weisbecker 2400613afbf8SFrederic Weisbecker extern int __cond_resched_lock(spinlock_t *lock); 2401613afbf8SFrederic Weisbecker 2402716a4234SFrederic Weisbecker #ifdef CONFIG_PREEMPT 2403716a4234SFrederic Weisbecker #define PREEMPT_LOCK_OFFSET PREEMPT_OFFSET 240402b67cc3SHerbert Xu #else 2405716a4234SFrederic Weisbecker #define PREEMPT_LOCK_OFFSET 0 240602b67cc3SHerbert Xu #endif 2407716a4234SFrederic Weisbecker 2408613afbf8SFrederic Weisbecker #define cond_resched_lock(lock) ({ \ 2409716a4234SFrederic Weisbecker __might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET); \ 2410613afbf8SFrederic Weisbecker __cond_resched_lock(lock); \ 2411613afbf8SFrederic Weisbecker }) 2412613afbf8SFrederic Weisbecker 2413613afbf8SFrederic Weisbecker extern int __cond_resched_softirq(void); 2414613afbf8SFrederic Weisbecker 2415613afbf8SFrederic Weisbecker #define cond_resched_softirq() ({ \ 2416613afbf8SFrederic Weisbecker __might_sleep(__FILE__, __LINE__, SOFTIRQ_OFFSET); \ 2417613afbf8SFrederic Weisbecker __cond_resched_softirq(); \ 2418613afbf8SFrederic Weisbecker }) 24191da177e4SLinus Torvalds 24201da177e4SLinus Torvalds /* 24211da177e4SLinus Torvalds * Does a critical section need to be broken due to another 242295c354feSNick Piggin * task waiting?: (technically does not depend on CONFIG_PREEMPT, 242395c354feSNick Piggin * but a general need for low latency) 24241da177e4SLinus Torvalds */ 242595c354feSNick Piggin static inline int spin_needbreak(spinlock_t *lock) 24261da177e4SLinus Torvalds { 242795c354feSNick Piggin #ifdef CONFIG_PREEMPT 242895c354feSNick Piggin return spin_is_contended(lock); 242995c354feSNick Piggin #else 24301da177e4SLinus Torvalds return 0; 243195c354feSNick Piggin #endif 24321da177e4SLinus Torvalds } 24331da177e4SLinus Torvalds 24347bb44adeSRoland McGrath /* 2435f06febc9SFrank Mayhar * Thread group CPU time accounting. 2436f06febc9SFrank Mayhar */ 24374cd4c1b4SPeter Zijlstra void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times); 24384da94d49SPeter Zijlstra void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times); 2439f06febc9SFrank Mayhar 2440f06febc9SFrank Mayhar static inline void thread_group_cputime_init(struct signal_struct *sig) 2441f06febc9SFrank Mayhar { 24424cd4c1b4SPeter Zijlstra sig->cputimer.cputime = INIT_CPUTIME; 24434cd4c1b4SPeter Zijlstra spin_lock_init(&sig->cputimer.lock); 24444cd4c1b4SPeter Zijlstra sig->cputimer.running = 0; 2445f06febc9SFrank Mayhar } 2446f06febc9SFrank Mayhar 2447f06febc9SFrank Mayhar static inline void thread_group_cputime_free(struct signal_struct *sig) 2448f06febc9SFrank Mayhar { 2449f06febc9SFrank Mayhar } 2450f06febc9SFrank Mayhar 2451f06febc9SFrank Mayhar /* 24527bb44adeSRoland McGrath * Reevaluate whether the task has signals pending delivery. 24537bb44adeSRoland McGrath * Wake the task if so. 24547bb44adeSRoland McGrath * This is required every time the blocked sigset_t changes. 24557bb44adeSRoland McGrath * callers must hold sighand->siglock. 24567bb44adeSRoland McGrath */ 24577bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t); 24581da177e4SLinus Torvalds extern void recalc_sigpending(void); 24591da177e4SLinus Torvalds 24601da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped); 24611da177e4SLinus Torvalds 24621da177e4SLinus Torvalds /* 24631da177e4SLinus Torvalds * Wrappers for p->thread_info->cpu access. No-op on UP. 24641da177e4SLinus Torvalds */ 24651da177e4SLinus Torvalds #ifdef CONFIG_SMP 24661da177e4SLinus Torvalds 24671da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 24681da177e4SLinus Torvalds { 2469a1261f54SAl Viro return task_thread_info(p)->cpu; 24701da177e4SLinus Torvalds } 24711da177e4SLinus Torvalds 2472c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu); 24731da177e4SLinus Torvalds 24741da177e4SLinus Torvalds #else 24751da177e4SLinus Torvalds 24761da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 24771da177e4SLinus Torvalds { 24781da177e4SLinus Torvalds return 0; 24791da177e4SLinus Torvalds } 24801da177e4SLinus Torvalds 24811da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu) 24821da177e4SLinus Torvalds { 24831da177e4SLinus Torvalds } 24841da177e4SLinus Torvalds 24851da177e4SLinus Torvalds #endif /* CONFIG_SMP */ 24861da177e4SLinus Torvalds 24871a3c3034SIngo Molnar #ifdef CONFIG_TRACING 24881a3c3034SIngo Molnar extern void 24891a3c3034SIngo Molnar __trace_special(void *__tr, void *__data, 24901a3c3034SIngo Molnar unsigned long arg1, unsigned long arg2, unsigned long arg3); 24911da177e4SLinus Torvalds #else 24921a3c3034SIngo Molnar static inline void 24931a3c3034SIngo Molnar __trace_special(void *__tr, void *__data, 24941a3c3034SIngo Molnar unsigned long arg1, unsigned long arg2, unsigned long arg3) 24951da177e4SLinus Torvalds { 24961da177e4SLinus Torvalds } 24971da177e4SLinus Torvalds #endif 24981da177e4SLinus Torvalds 249996f874e2SRusty Russell extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask); 250096f874e2SRusty Russell extern long sched_getaffinity(pid_t pid, struct cpumask *mask); 25015c45bf27SSiddha, Suresh B 25021da177e4SLinus Torvalds extern void normalize_rt_tasks(void); 25031da177e4SLinus Torvalds 25047c941438SDhaval Giani #ifdef CONFIG_CGROUP_SCHED 25059b5b7751SSrivatsa Vaddagiri 25064cf86d77SIngo Molnar extern struct task_group init_task_group; 25079b5b7751SSrivatsa Vaddagiri 2508ec7dc8acSDhaval Giani extern struct task_group *sched_create_group(struct task_group *parent); 25094cf86d77SIngo Molnar extern void sched_destroy_group(struct task_group *tg); 25109b5b7751SSrivatsa Vaddagiri extern void sched_move_task(struct task_struct *tsk); 2511052f1dc7SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED 25124cf86d77SIngo Molnar extern int sched_group_set_shares(struct task_group *tg, unsigned long shares); 25135cb350baSDhaval Giani extern unsigned long sched_group_shares(struct task_group *tg); 2514052f1dc7SPeter Zijlstra #endif 2515052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED 25169f0c1e56SPeter Zijlstra extern int sched_group_set_rt_runtime(struct task_group *tg, 25179f0c1e56SPeter Zijlstra long rt_runtime_us); 25189f0c1e56SPeter Zijlstra extern long sched_group_rt_runtime(struct task_group *tg); 2519d0b27fa7SPeter Zijlstra extern int sched_group_set_rt_period(struct task_group *tg, 2520d0b27fa7SPeter Zijlstra long rt_period_us); 2521d0b27fa7SPeter Zijlstra extern long sched_group_rt_period(struct task_group *tg); 252254e99124SDhaval Giani extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk); 2523052f1dc7SPeter Zijlstra #endif 25249b5b7751SSrivatsa Vaddagiri #endif 25259b5b7751SSrivatsa Vaddagiri 252654e99124SDhaval Giani extern int task_can_switch_user(struct user_struct *up, 252754e99124SDhaval Giani struct task_struct *tsk); 252854e99124SDhaval Giani 25294b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT 25304b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 25314b98d11bSAlexey Dobriyan { 2532940389b8SAndrea Righi tsk->ioac.rchar += amt; 25334b98d11bSAlexey Dobriyan } 25344b98d11bSAlexey Dobriyan 25354b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 25364b98d11bSAlexey Dobriyan { 2537940389b8SAndrea Righi tsk->ioac.wchar += amt; 25384b98d11bSAlexey Dobriyan } 25394b98d11bSAlexey Dobriyan 25404b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 25414b98d11bSAlexey Dobriyan { 2542940389b8SAndrea Righi tsk->ioac.syscr++; 25434b98d11bSAlexey Dobriyan } 25444b98d11bSAlexey Dobriyan 25454b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 25464b98d11bSAlexey Dobriyan { 2547940389b8SAndrea Righi tsk->ioac.syscw++; 25484b98d11bSAlexey Dobriyan } 25494b98d11bSAlexey Dobriyan #else 25504b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 25514b98d11bSAlexey Dobriyan { 25524b98d11bSAlexey Dobriyan } 25534b98d11bSAlexey Dobriyan 25544b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 25554b98d11bSAlexey Dobriyan { 25564b98d11bSAlexey Dobriyan } 25574b98d11bSAlexey Dobriyan 25584b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 25594b98d11bSAlexey Dobriyan { 25604b98d11bSAlexey Dobriyan } 25614b98d11bSAlexey Dobriyan 25624b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 25634b98d11bSAlexey Dobriyan { 25644b98d11bSAlexey Dobriyan } 25654b98d11bSAlexey Dobriyan #endif 25664b98d11bSAlexey Dobriyan 256782455257SDave Hansen #ifndef TASK_SIZE_OF 256882455257SDave Hansen #define TASK_SIZE_OF(tsk) TASK_SIZE 256982455257SDave Hansen #endif 257082455257SDave Hansen 25710793a61dSThomas Gleixner /* 25720793a61dSThomas Gleixner * Call the function if the target task is executing on a CPU right now: 25730793a61dSThomas Gleixner */ 25740793a61dSThomas Gleixner extern void task_oncpu_function_call(struct task_struct *p, 25750793a61dSThomas Gleixner void (*func) (void *info), void *info); 25760793a61dSThomas Gleixner 25770793a61dSThomas Gleixner 2578cf475ad2SBalbir Singh #ifdef CONFIG_MM_OWNER 2579cf475ad2SBalbir Singh extern void mm_update_next_owner(struct mm_struct *mm); 2580cf475ad2SBalbir Singh extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p); 2581cf475ad2SBalbir Singh #else 2582cf475ad2SBalbir Singh static inline void mm_update_next_owner(struct mm_struct *mm) 2583cf475ad2SBalbir Singh { 2584cf475ad2SBalbir Singh } 2585cf475ad2SBalbir Singh 2586cf475ad2SBalbir Singh static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p) 2587cf475ad2SBalbir Singh { 2588cf475ad2SBalbir Singh } 2589cf475ad2SBalbir Singh #endif /* CONFIG_MM_OWNER */ 2590cf475ad2SBalbir Singh 25913e10e716SJiri Slaby static inline unsigned long task_rlimit(const struct task_struct *tsk, 25923e10e716SJiri Slaby unsigned int limit) 25933e10e716SJiri Slaby { 25943e10e716SJiri Slaby return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_cur); 25953e10e716SJiri Slaby } 25963e10e716SJiri Slaby 25973e10e716SJiri Slaby static inline unsigned long task_rlimit_max(const struct task_struct *tsk, 25983e10e716SJiri Slaby unsigned int limit) 25993e10e716SJiri Slaby { 26003e10e716SJiri Slaby return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_max); 26013e10e716SJiri Slaby } 26023e10e716SJiri Slaby 26033e10e716SJiri Slaby static inline unsigned long rlimit(unsigned int limit) 26043e10e716SJiri Slaby { 26053e10e716SJiri Slaby return task_rlimit(current, limit); 26063e10e716SJiri Slaby } 26073e10e716SJiri Slaby 26083e10e716SJiri Slaby static inline unsigned long rlimit_max(unsigned int limit) 26093e10e716SJiri Slaby { 26103e10e716SJiri Slaby return task_rlimit_max(current, limit); 26113e10e716SJiri Slaby } 26123e10e716SJiri Slaby 26131da177e4SLinus Torvalds #endif /* __KERNEL__ */ 26141da177e4SLinus Torvalds 26151da177e4SLinus Torvalds #endif 2616