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; 102cdd6c482SIngo Molnar struct perf_event_context; 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds /* 1051da177e4SLinus Torvalds * List of flags we want to share for kernel threads, 1061da177e4SLinus Torvalds * if only because they are not used by them anyway. 1071da177e4SLinus Torvalds */ 1081da177e4SLinus Torvalds #define CLONE_KERNEL (CLONE_FS | CLONE_FILES | CLONE_SIGHAND) 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds /* 1111da177e4SLinus Torvalds * These are the constant used to fake the fixed-point load-average 1121da177e4SLinus Torvalds * counting. Some notes: 1131da177e4SLinus Torvalds * - 11 bit fractions expand to 22 bits by the multiplies: this gives 1141da177e4SLinus Torvalds * a load-average precision of 10 bits integer + 11 bits fractional 1151da177e4SLinus Torvalds * - if you want to count load-averages more often, you need more 1161da177e4SLinus Torvalds * precision, or rounding will get you. With 2-second counting freq, 1171da177e4SLinus Torvalds * the EXP_n values would be 1981, 2034 and 2043 if still using only 1181da177e4SLinus Torvalds * 11 bit fractions. 1191da177e4SLinus Torvalds */ 1201da177e4SLinus Torvalds extern unsigned long avenrun[]; /* Load averages */ 1212d02494fSThomas Gleixner extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift); 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds #define FSHIFT 11 /* nr of bits of precision */ 1241da177e4SLinus Torvalds #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ 1250c2043abSLinus Torvalds #define LOAD_FREQ (5*HZ+1) /* 5 sec intervals */ 1261da177e4SLinus Torvalds #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ 1271da177e4SLinus Torvalds #define EXP_5 2014 /* 1/exp(5sec/5min) */ 1281da177e4SLinus Torvalds #define EXP_15 2037 /* 1/exp(5sec/15min) */ 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \ 1311da177e4SLinus Torvalds load *= exp; \ 1321da177e4SLinus Torvalds load += n*(FIXED_1-exp); \ 1331da177e4SLinus Torvalds load >>= FSHIFT; 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds extern unsigned long total_forks; 1361da177e4SLinus Torvalds extern int nr_threads; 1371da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts); 1381da177e4SLinus Torvalds extern int nr_processes(void); 1391da177e4SLinus Torvalds extern unsigned long nr_running(void); 1401da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void); 1411da177e4SLinus Torvalds extern unsigned long nr_iowait(void); 1428c215bd3SPeter Zijlstra extern unsigned long nr_iowait_cpu(int cpu); 14369d25870SArjan van de Ven extern unsigned long this_cpu_load(void); 14469d25870SArjan van de Ven 14569d25870SArjan van de Ven 146dce48a84SThomas Gleixner extern void calc_global_load(void); 1471da177e4SLinus Torvalds 1487e49fcceSSteven Rostedt extern unsigned long get_parent_ip(unsigned long addr); 1497e49fcceSSteven Rostedt 15043ae34cbSIngo Molnar struct seq_file; 15143ae34cbSIngo Molnar struct cfs_rq; 1524cf86d77SIngo Molnar struct task_group; 15343ae34cbSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 15443ae34cbSIngo Molnar extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m); 15543ae34cbSIngo Molnar extern void proc_sched_set_task(struct task_struct *p); 15643ae34cbSIngo Molnar extern void 1575cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq); 15843ae34cbSIngo Molnar #else 15943ae34cbSIngo Molnar static inline void 16043ae34cbSIngo Molnar proc_sched_show_task(struct task_struct *p, struct seq_file *m) 16143ae34cbSIngo Molnar { 16243ae34cbSIngo Molnar } 16343ae34cbSIngo Molnar static inline void proc_sched_set_task(struct task_struct *p) 16443ae34cbSIngo Molnar { 16543ae34cbSIngo Molnar } 16643ae34cbSIngo Molnar static inline void 1675cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) 16843ae34cbSIngo Molnar { 16943ae34cbSIngo Molnar } 17043ae34cbSIngo Molnar #endif 1711da177e4SLinus Torvalds 1724a8342d2SLinus Torvalds /* 1734a8342d2SLinus Torvalds * Task state bitmask. NOTE! These bits are also 1744a8342d2SLinus Torvalds * encoded in fs/proc/array.c: get_task_state(). 1754a8342d2SLinus Torvalds * 1764a8342d2SLinus Torvalds * We have two separate sets of flags: task->state 1774a8342d2SLinus Torvalds * is about runnability, while task->exit_state are 1784a8342d2SLinus Torvalds * about the task exiting. Confusing, but this way 1794a8342d2SLinus Torvalds * modifying one set can't modify the other one by 1804a8342d2SLinus Torvalds * mistake. 1814a8342d2SLinus Torvalds */ 1821da177e4SLinus Torvalds #define TASK_RUNNING 0 1831da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE 1 1841da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE 2 185f021a3c2SMatthew Wilcox #define __TASK_STOPPED 4 186f021a3c2SMatthew Wilcox #define __TASK_TRACED 8 1874a8342d2SLinus Torvalds /* in tsk->exit_state */ 1884a8342d2SLinus Torvalds #define EXIT_ZOMBIE 16 1894a8342d2SLinus Torvalds #define EXIT_DEAD 32 1904a8342d2SLinus Torvalds /* in tsk->state again */ 191af927232SMike Galbraith #define TASK_DEAD 64 192f021a3c2SMatthew Wilcox #define TASK_WAKEKILL 128 193e9c84311SPeter Zijlstra #define TASK_WAKING 256 194e1781538SPeter Zijlstra #define TASK_STATE_MAX 512 195f021a3c2SMatthew Wilcox 19644d90df6SPeter Zijlstra #define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW" 19773342151SPeter Zijlstra 198e1781538SPeter Zijlstra extern char ___assert_task_state[1 - 2*!!( 199e1781538SPeter Zijlstra sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)]; 200f021a3c2SMatthew Wilcox 201f021a3c2SMatthew Wilcox /* Convenience macros for the sake of set_task_state */ 202f021a3c2SMatthew Wilcox #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) 203f021a3c2SMatthew Wilcox #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) 204f021a3c2SMatthew Wilcox #define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED) 2051da177e4SLinus Torvalds 20692a1f4bcSMatthew Wilcox /* Convenience macros for the sake of wake_up */ 20792a1f4bcSMatthew Wilcox #define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE) 208f021a3c2SMatthew Wilcox #define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED) 20992a1f4bcSMatthew Wilcox 21092a1f4bcSMatthew Wilcox /* get_task_state() */ 21192a1f4bcSMatthew Wilcox #define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \ 212f021a3c2SMatthew Wilcox TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \ 213f021a3c2SMatthew Wilcox __TASK_TRACED) 21492a1f4bcSMatthew Wilcox 215f021a3c2SMatthew Wilcox #define task_is_traced(task) ((task->state & __TASK_TRACED) != 0) 216f021a3c2SMatthew Wilcox #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0) 2178f92054eSDavid Howells #define task_is_dead(task) ((task)->exit_state != 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 261db1466b3SPaul E. McKenney #ifdef CONFIG_PROVE_RCU 262db1466b3SPaul E. McKenney extern int lockdep_tasklist_lock_is_held(void); 263db1466b3SPaul E. McKenney #endif /* #ifdef CONFIG_PROVE_RCU */ 264db1466b3SPaul E. McKenney 2651da177e4SLinus Torvalds extern void sched_init(void); 2661da177e4SLinus Torvalds extern void sched_init_smp(void); 2672d07b255SHarvey Harrison extern asmlinkage void schedule_tail(struct task_struct *prev); 26836c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu); 2691df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle); 2701da177e4SLinus Torvalds 27189f19f04SAndrew Morton extern int runqueue_is_locked(int cpu); 272017730c1SIngo Molnar 2736a7b3dc3SRusty Russell extern cpumask_var_t nohz_cpu_mask; 27446cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ) 27583cd4fe2SVenkatesh Pallipadi extern void select_nohz_load_balancer(int stop_tick); 27683cd4fe2SVenkatesh Pallipadi extern int get_nohz_timer_target(void); 27746cb4b7cSSiddha, Suresh B #else 27883cd4fe2SVenkatesh Pallipadi static inline void select_nohz_load_balancer(int stop_tick) { } 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 31019cc36c0SFrederic Weisbecker #ifdef CONFIG_LOCKUP_DETECTOR 3118446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void); 312d6ad3e28SJason Wessel extern void touch_softlockup_watchdog_sync(void); 31304c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void); 314332fbdbcSDon Zickus extern int proc_dowatchdog_thresh(struct ctl_table *table, int write, 3158d65af78SAlexey Dobriyan void __user *buffer, 316baf48f65SMandeep Singh Baines size_t *lenp, loff_t *ppos); 3179c44bc03SIngo Molnar extern unsigned int softlockup_panic; 3189383d967SDimitri Sivanich extern int softlockup_thresh; 3198446f1d3SIngo Molnar #else 3208446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void) 3218446f1d3SIngo Molnar { 3228446f1d3SIngo Molnar } 323d6ad3e28SJason Wessel static inline void touch_softlockup_watchdog_sync(void) 324d6ad3e28SJason Wessel { 325d6ad3e28SJason Wessel } 32604c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void) 32704c9167fSJeremy Fitzhardinge { 32804c9167fSJeremy Fitzhardinge } 3298446f1d3SIngo Molnar #endif 3308446f1d3SIngo Molnar 331e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK 332e162b39aSMandeep Singh Baines extern unsigned int sysctl_hung_task_panic; 333e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_check_count; 334e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_timeout_secs; 335e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_warnings; 336e162b39aSMandeep Singh Baines extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, 3378d65af78SAlexey Dobriyan void __user *buffer, 338e162b39aSMandeep Singh Baines size_t *lenp, loff_t *ppos); 339e162b39aSMandeep Singh Baines #endif 3408446f1d3SIngo Molnar 3411da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */ 3421da177e4SLinus Torvalds #define __sched __attribute__((__section__(".sched.text"))) 343deaf2227SIngo Molnar 344deaf2227SIngo Molnar /* Linker adds these: start and end of __sched functions */ 345deaf2227SIngo Molnar extern char __sched_text_start[], __sched_text_end[]; 346deaf2227SIngo Molnar 3471da177e4SLinus Torvalds /* Is this address in the __sched functions? */ 3481da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr); 3491da177e4SLinus Torvalds 3501da177e4SLinus Torvalds #define MAX_SCHEDULE_TIMEOUT LONG_MAX 351b3c97528SHarvey Harrison extern signed long schedule_timeout(signed long timeout); 35264ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout); 353294d5cc2SMatthew Wilcox extern signed long schedule_timeout_killable(signed long timeout); 35464ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout); 3551da177e4SLinus Torvalds asmlinkage void schedule(void); 3560d66bf6dSPeter Zijlstra extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner); 3571da177e4SLinus Torvalds 358ab516013SSerge E. Hallyn struct nsproxy; 359acce292cSCedric Le Goater struct user_namespace; 3601da177e4SLinus Torvalds 361341c87bfSKAMEZAWA Hiroyuki /* 362341c87bfSKAMEZAWA Hiroyuki * Default maximum number of active map areas, this limits the number of vmas 363341c87bfSKAMEZAWA Hiroyuki * per mm struct. Users can overwrite this number by sysctl but there is a 364341c87bfSKAMEZAWA Hiroyuki * problem. 365341c87bfSKAMEZAWA Hiroyuki * 366341c87bfSKAMEZAWA Hiroyuki * When a program's coredump is generated as ELF format, a section is created 367341c87bfSKAMEZAWA Hiroyuki * per a vma. In ELF, the number of sections is represented in unsigned short. 368341c87bfSKAMEZAWA Hiroyuki * This means the number of sections should be smaller than 65535 at coredump. 369341c87bfSKAMEZAWA Hiroyuki * Because the kernel adds some informative sections to a image of program at 370341c87bfSKAMEZAWA Hiroyuki * generating coredump, we need some margin. The number of extra sections is 371341c87bfSKAMEZAWA Hiroyuki * 1-3 now and depends on arch. We use "5" as safe margin, here. 372341c87bfSKAMEZAWA Hiroyuki */ 373341c87bfSKAMEZAWA Hiroyuki #define MAPCOUNT_ELF_CORE_MARGIN (5) 3744be929beSAlexey Dobriyan #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN) 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds extern int sysctl_max_map_count; 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds #include <linux/aio.h> 3791da177e4SLinus Torvalds 380efc1a3b1SDavid Howells #ifdef CONFIG_MMU 381efc1a3b1SDavid Howells extern void arch_pick_mmap_layout(struct mm_struct *mm); 3821da177e4SLinus Torvalds extern unsigned long 3831da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long, 3841da177e4SLinus Torvalds unsigned long, unsigned long); 3851da177e4SLinus Torvalds extern unsigned long 3861da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr, 3871da177e4SLinus Torvalds unsigned long len, unsigned long pgoff, 3881da177e4SLinus Torvalds unsigned long flags); 3891363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long); 3901363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long); 391efc1a3b1SDavid Howells #else 392efc1a3b1SDavid Howells static inline void arch_pick_mmap_layout(struct mm_struct *mm) {} 393efc1a3b1SDavid Howells #endif 3941da177e4SLinus Torvalds 395901608d9SOleg Nesterov 3966c5d5238SKawai, Hidehiro extern void set_dumpable(struct mm_struct *mm, int value); 3976c5d5238SKawai, Hidehiro extern int get_dumpable(struct mm_struct *mm); 3986c5d5238SKawai, Hidehiro 3996c5d5238SKawai, Hidehiro /* mm flags */ 4003cb4a0bbSKawai, Hidehiro /* dumpable bits */ 4016c5d5238SKawai, Hidehiro #define MMF_DUMPABLE 0 /* core dump is permitted */ 4026c5d5238SKawai, Hidehiro #define MMF_DUMP_SECURELY 1 /* core file is readable only by root */ 403f8af4da3SHugh Dickins 4043cb4a0bbSKawai, Hidehiro #define MMF_DUMPABLE_BITS 2 405f8af4da3SHugh Dickins #define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1) 4063cb4a0bbSKawai, Hidehiro 4073cb4a0bbSKawai, Hidehiro /* coredump filter bits */ 4083cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_PRIVATE 2 4093cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_SHARED 3 4103cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_PRIVATE 4 4113cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_SHARED 5 41282df3973SRoland McGrath #define MMF_DUMP_ELF_HEADERS 6 413e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_PRIVATE 7 414e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_SHARED 8 415f8af4da3SHugh Dickins 4163cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS 417e575f111SKOSAKI Motohiro #define MMF_DUMP_FILTER_BITS 7 4183cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_MASK \ 4193cb4a0bbSKawai, Hidehiro (((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT) 4203cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_DEFAULT \ 421e575f111SKOSAKI Motohiro ((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED) |\ 422656eb2cdSRoland McGrath (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF) 423656eb2cdSRoland McGrath 424656eb2cdSRoland McGrath #ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS 425656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF (1 << MMF_DUMP_ELF_HEADERS) 426656eb2cdSRoland McGrath #else 427656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF 0 428656eb2cdSRoland McGrath #endif 429f8af4da3SHugh Dickins /* leave room for more dump flags */ 430f8af4da3SHugh Dickins #define MMF_VM_MERGEABLE 16 /* KSM may merge identical pages */ 431f8af4da3SHugh Dickins 432f8af4da3SHugh Dickins #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK) 4336c5d5238SKawai, Hidehiro 4341da177e4SLinus Torvalds struct sighand_struct { 4351da177e4SLinus Torvalds atomic_t count; 4361da177e4SLinus Torvalds struct k_sigaction action[_NSIG]; 4371da177e4SLinus Torvalds spinlock_t siglock; 438b8fceee1SDavide Libenzi wait_queue_head_t signalfd_wqh; 4391da177e4SLinus Torvalds }; 4401da177e4SLinus Torvalds 4410e464814SKaiGai Kohei struct pacct_struct { 442f6ec29a4SKaiGai Kohei int ac_flag; 443f6ec29a4SKaiGai Kohei long ac_exitcode; 4440e464814SKaiGai Kohei unsigned long ac_mem; 44577787bfbSKaiGai Kohei cputime_t ac_utime, ac_stime; 44677787bfbSKaiGai Kohei unsigned long ac_minflt, ac_majflt; 4470e464814SKaiGai Kohei }; 4480e464814SKaiGai Kohei 44942c4ab41SStanislaw Gruszka struct cpu_itimer { 45042c4ab41SStanislaw Gruszka cputime_t expires; 45142c4ab41SStanislaw Gruszka cputime_t incr; 4528356b5f9SStanislaw Gruszka u32 error; 4538356b5f9SStanislaw Gruszka u32 incr_error; 45442c4ab41SStanislaw Gruszka }; 45542c4ab41SStanislaw Gruszka 456f06febc9SFrank Mayhar /** 457f06febc9SFrank Mayhar * struct task_cputime - collected CPU time counts 458f06febc9SFrank Mayhar * @utime: time spent in user mode, in &cputime_t units 459f06febc9SFrank Mayhar * @stime: time spent in kernel mode, in &cputime_t units 460f06febc9SFrank Mayhar * @sum_exec_runtime: total time spent on the CPU, in nanoseconds 461f06febc9SFrank Mayhar * 462f06febc9SFrank Mayhar * This structure groups together three kinds of CPU time that are 463f06febc9SFrank Mayhar * tracked for threads and thread groups. Most things considering 464f06febc9SFrank Mayhar * CPU time want to group these counts together and treat all three 465f06febc9SFrank Mayhar * of them in parallel. 466f06febc9SFrank Mayhar */ 467f06febc9SFrank Mayhar struct task_cputime { 468f06febc9SFrank Mayhar cputime_t utime; 469f06febc9SFrank Mayhar cputime_t stime; 470f06febc9SFrank Mayhar unsigned long long sum_exec_runtime; 471f06febc9SFrank Mayhar }; 472f06febc9SFrank Mayhar /* Alternate field names when used to cache expirations. */ 473f06febc9SFrank Mayhar #define prof_exp stime 474f06febc9SFrank Mayhar #define virt_exp utime 475f06febc9SFrank Mayhar #define sched_exp sum_exec_runtime 476f06febc9SFrank Mayhar 4774cd4c1b4SPeter Zijlstra #define INIT_CPUTIME \ 4784cd4c1b4SPeter Zijlstra (struct task_cputime) { \ 4794cd4c1b4SPeter Zijlstra .utime = cputime_zero, \ 4804cd4c1b4SPeter Zijlstra .stime = cputime_zero, \ 4814cd4c1b4SPeter Zijlstra .sum_exec_runtime = 0, \ 4824cd4c1b4SPeter Zijlstra } 4834cd4c1b4SPeter Zijlstra 484c99e6efeSPeter Zijlstra /* 485c99e6efeSPeter Zijlstra * Disable preemption until the scheduler is running. 486c99e6efeSPeter Zijlstra * Reset by start_kernel()->sched_init()->init_idle(). 487d86ee480SPeter Zijlstra * 488d86ee480SPeter Zijlstra * We include PREEMPT_ACTIVE to avoid cond_resched() from working 489d86ee480SPeter Zijlstra * before the scheduler is active -- see should_resched(). 490c99e6efeSPeter Zijlstra */ 491d86ee480SPeter Zijlstra #define INIT_PREEMPT_COUNT (1 + PREEMPT_ACTIVE) 492c99e6efeSPeter Zijlstra 493f06febc9SFrank Mayhar /** 4944cd4c1b4SPeter Zijlstra * struct thread_group_cputimer - thread group interval timer counts 4954cd4c1b4SPeter Zijlstra * @cputime: thread group interval timers. 4964cd4c1b4SPeter Zijlstra * @running: non-zero when there are timers running and 4974cd4c1b4SPeter Zijlstra * @cputime receives updates. 4984cd4c1b4SPeter Zijlstra * @lock: lock for fields in this struct. 499f06febc9SFrank Mayhar * 500f06febc9SFrank Mayhar * This structure contains the version of task_cputime, above, that is 5014cd4c1b4SPeter Zijlstra * used for thread group CPU timer calculations. 502f06febc9SFrank Mayhar */ 5034cd4c1b4SPeter Zijlstra struct thread_group_cputimer { 5044cd4c1b4SPeter Zijlstra struct task_cputime cputime; 5054cd4c1b4SPeter Zijlstra int running; 5064cd4c1b4SPeter Zijlstra spinlock_t lock; 507f06febc9SFrank Mayhar }; 508f06febc9SFrank Mayhar 5091da177e4SLinus Torvalds /* 5101da177e4SLinus Torvalds * NOTE! "signal_struct" does not have it's own 5111da177e4SLinus Torvalds * locking, because a shared signal_struct always 5121da177e4SLinus Torvalds * implies a shared sighand_struct, so locking 5131da177e4SLinus Torvalds * sighand_struct is always a proper superset of 5141da177e4SLinus Torvalds * the locking of signal_struct. 5151da177e4SLinus Torvalds */ 5161da177e4SLinus Torvalds struct signal_struct { 517ea6d290cSOleg Nesterov atomic_t sigcnt; 5181da177e4SLinus Torvalds atomic_t live; 519b3ac022cSOleg Nesterov int nr_threads; 5201da177e4SLinus Torvalds 5211da177e4SLinus Torvalds wait_queue_head_t wait_chldexit; /* for wait4() */ 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds /* current thread group signal load-balancing target: */ 52436c8b586SIngo Molnar struct task_struct *curr_target; 5251da177e4SLinus Torvalds 5261da177e4SLinus Torvalds /* shared signal handling: */ 5271da177e4SLinus Torvalds struct sigpending shared_pending; 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds /* thread group exit support */ 5301da177e4SLinus Torvalds int group_exit_code; 5311da177e4SLinus Torvalds /* overloaded: 5321da177e4SLinus Torvalds * - notify group_exit_task when ->count is equal to notify_count 5331da177e4SLinus Torvalds * - everyone except group_exit_task is stopped during signal delivery 5341da177e4SLinus Torvalds * of fatal signals, group_exit_task processes the signal. 5351da177e4SLinus Torvalds */ 5361da177e4SLinus Torvalds int notify_count; 53707dd20e0SRichard Kennedy struct task_struct *group_exit_task; 5381da177e4SLinus Torvalds 5391da177e4SLinus Torvalds /* thread group stop support, overloads group_exit_code too */ 5401da177e4SLinus Torvalds int group_stop_count; 5411da177e4SLinus Torvalds unsigned int flags; /* see SIGNAL_* flags below */ 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds /* POSIX.1b Interval Timers */ 5441da177e4SLinus Torvalds struct list_head posix_timers; 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds /* ITIMER_REAL timer for the process */ 5472ff678b8SThomas Gleixner struct hrtimer real_timer; 548fea9d175SOleg Nesterov struct pid *leader_pid; 5492ff678b8SThomas Gleixner ktime_t it_real_incr; 5501da177e4SLinus Torvalds 55142c4ab41SStanislaw Gruszka /* 55242c4ab41SStanislaw Gruszka * ITIMER_PROF and ITIMER_VIRTUAL timers for the process, we use 55342c4ab41SStanislaw Gruszka * CPUCLOCK_PROF and CPUCLOCK_VIRT for indexing array as these 55442c4ab41SStanislaw Gruszka * values are defined to 0 and 1 respectively 55542c4ab41SStanislaw Gruszka */ 55642c4ab41SStanislaw Gruszka struct cpu_itimer it[2]; 5571da177e4SLinus Torvalds 558f06febc9SFrank Mayhar /* 5594cd4c1b4SPeter Zijlstra * Thread group totals for process CPU timers. 5604cd4c1b4SPeter Zijlstra * See thread_group_cputimer(), et al, for details. 561f06febc9SFrank Mayhar */ 5624cd4c1b4SPeter Zijlstra struct thread_group_cputimer cputimer; 563f06febc9SFrank Mayhar 564f06febc9SFrank Mayhar /* Earliest-expiration cache. */ 565f06febc9SFrank Mayhar struct task_cputime cputime_expires; 566f06febc9SFrank Mayhar 567f06febc9SFrank Mayhar struct list_head cpu_timers[3]; 568f06febc9SFrank Mayhar 569ab521dc0SEric W. Biederman struct pid *tty_old_pgrp; 5701ec320afSCedric Le Goater 5711da177e4SLinus Torvalds /* boolean value for session group leader */ 5721da177e4SLinus Torvalds int leader; 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds struct tty_struct *tty; /* NULL if no tty */ 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvalds /* 5771da177e4SLinus Torvalds * Cumulative resource counters for dead threads in the group, 5781da177e4SLinus Torvalds * and for reaped dead child processes forked by this group. 5791da177e4SLinus Torvalds * Live threads maintain their own counters and add to these 5801da177e4SLinus Torvalds * in __exit_signal, except for the group leader. 5811da177e4SLinus Torvalds */ 58232bd671dSPeter Zijlstra cputime_t utime, stime, cutime, cstime; 5839ac52315SLaurent Vivier cputime_t gtime; 5849ac52315SLaurent Vivier cputime_t cgtime; 5850cf55e1eSHidetoshi Seto #ifndef CONFIG_VIRT_CPU_ACCOUNTING 5860cf55e1eSHidetoshi Seto cputime_t prev_utime, prev_stime; 5870cf55e1eSHidetoshi Seto #endif 5881da177e4SLinus Torvalds unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; 5891da177e4SLinus Torvalds unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; 5906eaeeabaSEric Dumazet unsigned long inblock, oublock, cinblock, coublock; 5911f10206cSJiri Pirko unsigned long maxrss, cmaxrss; 592940389b8SAndrea Righi struct task_io_accounting ioac; 5931da177e4SLinus Torvalds 5941da177e4SLinus Torvalds /* 59532bd671dSPeter Zijlstra * Cumulative ns of schedule CPU time fo dead threads in the 59632bd671dSPeter Zijlstra * group, not including a zombie group leader, (This only differs 59732bd671dSPeter Zijlstra * from jiffies_to_ns(utime + stime) if sched_clock uses something 59832bd671dSPeter Zijlstra * other than jiffies.) 59932bd671dSPeter Zijlstra */ 60032bd671dSPeter Zijlstra unsigned long long sum_sched_runtime; 60132bd671dSPeter Zijlstra 60232bd671dSPeter Zijlstra /* 6031da177e4SLinus Torvalds * We don't bother to synchronize most readers of this at all, 6041da177e4SLinus Torvalds * because there is no reader checking a limit that actually needs 6051da177e4SLinus Torvalds * to get both rlim_cur and rlim_max atomically, and either one 6061da177e4SLinus Torvalds * alone is a single word that can safely be read normally. 6071da177e4SLinus Torvalds * getrlimit/setrlimit use task_lock(current->group_leader) to 6081da177e4SLinus Torvalds * protect this instead of the siglock, because they really 6091da177e4SLinus Torvalds * have no need to disable irqs. 6101da177e4SLinus Torvalds */ 6111da177e4SLinus Torvalds struct rlimit rlim[RLIM_NLIMITS]; 6121da177e4SLinus Torvalds 6130e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT 6140e464814SKaiGai Kohei struct pacct_struct pacct; /* per-process accounting information */ 6150e464814SKaiGai Kohei #endif 616ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS 617ad4ecbcbSShailabh Nagar struct taskstats *stats; 618ad4ecbcbSShailabh Nagar #endif 619522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT 620522ed776SMiloslav Trmac unsigned audit_tty; 621522ed776SMiloslav Trmac struct tty_audit_buf *tty_audit_buf; 622522ed776SMiloslav Trmac #endif 62328b83c51SKOSAKI Motohiro 62428b83c51SKOSAKI Motohiro int oom_adj; /* OOM kill score adjustment (bit shift) */ 625a63d83f4SDavid Rientjes int oom_score_adj; /* OOM kill score adjustment */ 6261da177e4SLinus Torvalds }; 6271da177e4SLinus Torvalds 6284866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */ 6294866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW 6304866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW 6314866cde0SNick Piggin #endif 6324866cde0SNick Piggin 6331da177e4SLinus Torvalds /* 6341da177e4SLinus Torvalds * Bits in flags field of signal_struct. 6351da177e4SLinus Torvalds */ 6361da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */ 6371da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED 0x00000002 /* stop signal dequeued */ 6381da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */ 6391da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */ 640e4420551SOleg Nesterov /* 641e4420551SOleg Nesterov * Pending notifications to parent. 642e4420551SOleg Nesterov */ 643e4420551SOleg Nesterov #define SIGNAL_CLD_STOPPED 0x00000010 644e4420551SOleg Nesterov #define SIGNAL_CLD_CONTINUED 0x00000020 645e4420551SOleg Nesterov #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED) 6461da177e4SLinus Torvalds 647fae5fa44SOleg Nesterov #define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */ 648fae5fa44SOleg Nesterov 649ed5d2cacSOleg Nesterov /* If true, all threads except ->group_exit_task have pending SIGKILL */ 650ed5d2cacSOleg Nesterov static inline int signal_group_exit(const struct signal_struct *sig) 651ed5d2cacSOleg Nesterov { 652ed5d2cacSOleg Nesterov return (sig->flags & SIGNAL_GROUP_EXIT) || 653ed5d2cacSOleg Nesterov (sig->group_exit_task != NULL); 654ed5d2cacSOleg Nesterov } 655ed5d2cacSOleg Nesterov 6561da177e4SLinus Torvalds /* 6571da177e4SLinus Torvalds * Some day this will be a full-fledged user tracking system.. 6581da177e4SLinus Torvalds */ 6591da177e4SLinus Torvalds struct user_struct { 6601da177e4SLinus Torvalds atomic_t __count; /* reference count */ 6611da177e4SLinus Torvalds atomic_t processes; /* How many processes does this user have? */ 6621da177e4SLinus Torvalds atomic_t files; /* How many open files does this user have? */ 6631da177e4SLinus Torvalds atomic_t sigpending; /* How many pending signals does this user have? */ 6642d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 6650eeca283SRobert Love atomic_t inotify_watches; /* How many inotify watches does this user have? */ 6660eeca283SRobert Love atomic_t inotify_devs; /* How many inotify devs does this user have opened? */ 6670eeca283SRobert Love #endif 6687ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL 6697ef9964eSDavide Libenzi atomic_t epoll_watches; /* The number of file descriptors currently watched */ 6707ef9964eSDavide Libenzi #endif 671970a8645SAlexey Dobriyan #ifdef CONFIG_POSIX_MQUEUE 6721da177e4SLinus Torvalds /* protected by mq_lock */ 6731da177e4SLinus Torvalds unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */ 674970a8645SAlexey Dobriyan #endif 6751da177e4SLinus Torvalds unsigned long locked_shm; /* How many pages of mlocked shm ? */ 6761da177e4SLinus Torvalds 6771da177e4SLinus Torvalds #ifdef CONFIG_KEYS 6781da177e4SLinus Torvalds struct key *uid_keyring; /* UID specific keyring */ 6791da177e4SLinus Torvalds struct key *session_keyring; /* UID's default session keyring */ 6801da177e4SLinus Torvalds #endif 6811da177e4SLinus Torvalds 6821da177e4SLinus Torvalds /* Hash table maintenance information */ 683735de223SPavel Emelyanov struct hlist_node uidhash_node; 6841da177e4SLinus Torvalds uid_t uid; 68518b6e041SSerge Hallyn struct user_namespace *user_ns; 68624e377a8SSrivatsa Vaddagiri 687cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS 688789f90fcSPeter Zijlstra atomic_long_t locked_vm; 689789f90fcSPeter Zijlstra #endif 6901da177e4SLinus Torvalds }; 6911da177e4SLinus Torvalds 692eb41d946SKay Sievers extern int uids_sysfs_init(void); 6935cb350baSDhaval Giani 6941da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t); 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds extern struct user_struct root_user; 6971da177e4SLinus Torvalds #define INIT_USER (&root_user) 6981da177e4SLinus Torvalds 699b6dff3ecSDavid Howells 7001da177e4SLinus Torvalds struct backing_dev_info; 7011da177e4SLinus Torvalds struct reclaim_state; 7021da177e4SLinus Torvalds 70352f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 7041da177e4SLinus Torvalds struct sched_info { 7051da177e4SLinus Torvalds /* cumulative counters */ 7062d72376bSIngo Molnar unsigned long pcount; /* # of times run on this cpu */ 7079c2c4802SKen Chen unsigned long long run_delay; /* time spent waiting on a runqueue */ 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds /* timestamps */ 710172ba844SBalbir Singh unsigned long long last_arrival,/* when we last ran on a cpu */ 7111da177e4SLinus Torvalds last_queued; /* when we were last queued to run */ 712b8efb561SIngo Molnar #ifdef CONFIG_SCHEDSTATS 713b8efb561SIngo Molnar /* BKL stats */ 714480b9434SKen Chen unsigned int bkl_count; 715b8efb561SIngo Molnar #endif 7161da177e4SLinus Torvalds }; 71752f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */ 7181da177e4SLinus Torvalds 719ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 720ca74e92bSShailabh Nagar struct task_delay_info { 721ca74e92bSShailabh Nagar spinlock_t lock; 722ca74e92bSShailabh Nagar unsigned int flags; /* Private per-task flags */ 723ca74e92bSShailabh Nagar 724ca74e92bSShailabh Nagar /* For each stat XXX, add following, aligned appropriately 725ca74e92bSShailabh Nagar * 726ca74e92bSShailabh Nagar * struct timespec XXX_start, XXX_end; 727ca74e92bSShailabh Nagar * u64 XXX_delay; 728ca74e92bSShailabh Nagar * u32 XXX_count; 729ca74e92bSShailabh Nagar * 730ca74e92bSShailabh Nagar * Atomicity of updates to XXX_delay, XXX_count protected by 731ca74e92bSShailabh Nagar * single lock above (split into XXX_lock if contention is an issue). 732ca74e92bSShailabh Nagar */ 7330ff92245SShailabh Nagar 7340ff92245SShailabh Nagar /* 7350ff92245SShailabh Nagar * XXX_count is incremented on every XXX operation, the delay 7360ff92245SShailabh Nagar * associated with the operation is added to XXX_delay. 7370ff92245SShailabh Nagar * XXX_delay contains the accumulated delay time in nanoseconds. 7380ff92245SShailabh Nagar */ 7390ff92245SShailabh Nagar struct timespec blkio_start, blkio_end; /* Shared by blkio, swapin */ 7400ff92245SShailabh Nagar u64 blkio_delay; /* wait for sync block io completion */ 7410ff92245SShailabh Nagar u64 swapin_delay; /* wait for swapin block io completion */ 7420ff92245SShailabh Nagar u32 blkio_count; /* total count of the number of sync block */ 7430ff92245SShailabh Nagar /* io operations performed */ 7440ff92245SShailabh Nagar u32 swapin_count; /* total count of the number of swapin block */ 7450ff92245SShailabh Nagar /* io operations performed */ 746873b4771SKeika Kobayashi 747873b4771SKeika Kobayashi struct timespec freepages_start, freepages_end; 748873b4771SKeika Kobayashi u64 freepages_delay; /* wait for memory reclaim */ 749873b4771SKeika Kobayashi u32 freepages_count; /* total count of memory reclaim */ 750ca74e92bSShailabh Nagar }; 75152f17b6cSChandra Seetharaman #endif /* CONFIG_TASK_DELAY_ACCT */ 75252f17b6cSChandra Seetharaman 75352f17b6cSChandra Seetharaman static inline int sched_info_on(void) 75452f17b6cSChandra Seetharaman { 75552f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS 75652f17b6cSChandra Seetharaman return 1; 75752f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT) 75852f17b6cSChandra Seetharaman extern int delayacct_on; 75952f17b6cSChandra Seetharaman return delayacct_on; 76052f17b6cSChandra Seetharaman #else 76152f17b6cSChandra Seetharaman return 0; 762ca74e92bSShailabh Nagar #endif 76352f17b6cSChandra Seetharaman } 764ca74e92bSShailabh Nagar 765d15bcfdbSIngo Molnar enum cpu_idle_type { 766d15bcfdbSIngo Molnar CPU_IDLE, 767d15bcfdbSIngo Molnar CPU_NOT_IDLE, 768d15bcfdbSIngo Molnar CPU_NEWLY_IDLE, 769d15bcfdbSIngo Molnar CPU_MAX_IDLE_TYPES 7701da177e4SLinus Torvalds }; 7711da177e4SLinus Torvalds 7721da177e4SLinus Torvalds /* 7731da177e4SLinus Torvalds * sched-domains (multiprocessor balancing) declarations: 7741da177e4SLinus Torvalds */ 7759aa7b369SIngo Molnar 7769aa7b369SIngo Molnar /* 7779aa7b369SIngo Molnar * Increase resolution of nice-level calculations: 7789aa7b369SIngo Molnar */ 7799aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT 10 7809aa7b369SIngo Molnar #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT) 7819aa7b369SIngo Molnar 782f8700df7SSuresh Siddha #define SCHED_LOAD_SCALE_FUZZ SCHED_LOAD_SCALE 7831da177e4SLinus Torvalds 7842dd73a4fSPeter Williams #ifdef CONFIG_SMP 785b5d978e0SPeter Zijlstra #define SD_LOAD_BALANCE 0x0001 /* Do load balancing on this domain. */ 786b5d978e0SPeter Zijlstra #define SD_BALANCE_NEWIDLE 0x0002 /* Balance when about to become idle */ 787b5d978e0SPeter Zijlstra #define SD_BALANCE_EXEC 0x0004 /* Balance on exec */ 788b5d978e0SPeter Zijlstra #define SD_BALANCE_FORK 0x0008 /* Balance on fork, clone */ 789c88d5910SPeter Zijlstra #define SD_BALANCE_WAKE 0x0010 /* Balance on wakeup */ 790b5d978e0SPeter Zijlstra #define SD_WAKE_AFFINE 0x0020 /* Wake task to waking CPU */ 79159abf026SPeter Zijlstra #define SD_PREFER_LOCAL 0x0040 /* Prefer to keep tasks local to this domain */ 792b5d978e0SPeter Zijlstra #define SD_SHARE_CPUPOWER 0x0080 /* Domain members share cpu power */ 793b5d978e0SPeter Zijlstra #define SD_POWERSAVINGS_BALANCE 0x0100 /* Balance for power savings */ 794b5d978e0SPeter Zijlstra #define SD_SHARE_PKG_RESOURCES 0x0200 /* Domain members share cpu pkg resources */ 795b5d978e0SPeter Zijlstra #define SD_SERIALIZE 0x0400 /* Only a single load balancing instance */ 796532cb4c4SMichael Neuling #define SD_ASYM_PACKING 0x0800 /* Place busy groups earlier in the domain */ 797b5d978e0SPeter Zijlstra #define SD_PREFER_SIBLING 0x1000 /* Prefer to place tasks in a sibling domain */ 7985c45bf27SSiddha, Suresh B 799afb8a9b7SGautham R Shenoy enum powersavings_balance_level { 800afb8a9b7SGautham R Shenoy POWERSAVINGS_BALANCE_NONE = 0, /* No power saving load balance */ 801afb8a9b7SGautham R Shenoy POWERSAVINGS_BALANCE_BASIC, /* Fill one thread/core/package 802afb8a9b7SGautham R Shenoy * first for long running threads 803afb8a9b7SGautham R Shenoy */ 804afb8a9b7SGautham R Shenoy POWERSAVINGS_BALANCE_WAKEUP, /* Also bias task wakeups to semi-idle 805afb8a9b7SGautham R Shenoy * cpu package for power savings 806afb8a9b7SGautham R Shenoy */ 807afb8a9b7SGautham R Shenoy MAX_POWERSAVINGS_BALANCE_LEVELS 808afb8a9b7SGautham R Shenoy }; 80989c4710eSSiddha, Suresh B 810716707b2SVaidyanathan Srinivasan extern int sched_mc_power_savings, sched_smt_power_savings; 81189c4710eSSiddha, Suresh B 812716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_mc_power(void) 813716707b2SVaidyanathan Srinivasan { 814716707b2SVaidyanathan Srinivasan if (sched_smt_power_savings) 815716707b2SVaidyanathan Srinivasan return SD_POWERSAVINGS_BALANCE; 8165c45bf27SSiddha, Suresh B 81728f53181SVaidyanathan Srinivasan if (!sched_mc_power_savings) 818b5d978e0SPeter Zijlstra return SD_PREFER_SIBLING; 81928f53181SVaidyanathan Srinivasan 82028f53181SVaidyanathan Srinivasan return 0; 821716707b2SVaidyanathan Srinivasan } 822716707b2SVaidyanathan Srinivasan 823716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_package_power(void) 824716707b2SVaidyanathan Srinivasan { 825716707b2SVaidyanathan Srinivasan if (sched_mc_power_savings | sched_smt_power_savings) 826716707b2SVaidyanathan Srinivasan return SD_POWERSAVINGS_BALANCE; 827716707b2SVaidyanathan Srinivasan 828b5d978e0SPeter Zijlstra return SD_PREFER_SIBLING; 829716707b2SVaidyanathan Srinivasan } 830147cbb4bSNick Piggin 831532cb4c4SMichael Neuling extern int __weak arch_sd_sibiling_asym_packing(void); 832532cb4c4SMichael Neuling 833100fdaeeSVaidyanathan Srinivasan /* 834100fdaeeSVaidyanathan Srinivasan * Optimise SD flags for power savings: 835100fdaeeSVaidyanathan Srinivasan * SD_BALANCE_NEWIDLE helps agressive task consolidation and power savings. 836100fdaeeSVaidyanathan Srinivasan * Keep default SD flags if sched_{smt,mc}_power_saving=0 837100fdaeeSVaidyanathan Srinivasan */ 838100fdaeeSVaidyanathan Srinivasan 839100fdaeeSVaidyanathan Srinivasan static inline int sd_power_saving_flags(void) 840100fdaeeSVaidyanathan Srinivasan { 841100fdaeeSVaidyanathan Srinivasan if (sched_mc_power_savings | sched_smt_power_savings) 842100fdaeeSVaidyanathan Srinivasan return SD_BALANCE_NEWIDLE; 843100fdaeeSVaidyanathan Srinivasan 844100fdaeeSVaidyanathan Srinivasan return 0; 845100fdaeeSVaidyanathan Srinivasan } 8461da177e4SLinus Torvalds 8471da177e4SLinus Torvalds struct sched_group { 8481da177e4SLinus Torvalds struct sched_group *next; /* Must be a circular list */ 8491da177e4SLinus Torvalds 8501da177e4SLinus Torvalds /* 8511da177e4SLinus Torvalds * CPU power of this group, SCHED_LOAD_SCALE being max power for a 85218a3885fSPeter Zijlstra * single CPU. 8531da177e4SLinus Torvalds */ 8549d5efe05SSrivatsa Vaddagiri unsigned int cpu_power, cpu_power_orig; 8556c99e9adSRusty Russell 8564200efd9SIngo Molnar /* 8574200efd9SIngo Molnar * The CPUs this group covers. 8584200efd9SIngo Molnar * 8594200efd9SIngo Molnar * NOTE: this field is variable length. (Allocated dynamically 8604200efd9SIngo Molnar * by attaching extra space to the end of the structure, 8614200efd9SIngo Molnar * depending on how many CPUs the kernel has booted up with) 8624200efd9SIngo Molnar * 8634200efd9SIngo Molnar * It is also be embedded into static data structures at build 8644200efd9SIngo Molnar * time. (See 'struct static_sched_group' in kernel/sched.c) 8654200efd9SIngo Molnar */ 8664200efd9SIngo Molnar unsigned long cpumask[0]; 8671da177e4SLinus Torvalds }; 8681da177e4SLinus Torvalds 869758b2cdcSRusty Russell static inline struct cpumask *sched_group_cpus(struct sched_group *sg) 870758b2cdcSRusty Russell { 8716c99e9adSRusty Russell return to_cpumask(sg->cpumask); 872758b2cdcSRusty Russell } 873758b2cdcSRusty Russell 8741d3504fcSHidetoshi Seto enum sched_domain_level { 8751d3504fcSHidetoshi Seto SD_LV_NONE = 0, 8761d3504fcSHidetoshi Seto SD_LV_SIBLING, 8771d3504fcSHidetoshi Seto SD_LV_MC, 8781d3504fcSHidetoshi Seto SD_LV_CPU, 8791d3504fcSHidetoshi Seto SD_LV_NODE, 8801d3504fcSHidetoshi Seto SD_LV_ALLNODES, 8811d3504fcSHidetoshi Seto SD_LV_MAX 8821d3504fcSHidetoshi Seto }; 8831d3504fcSHidetoshi Seto 8841d3504fcSHidetoshi Seto struct sched_domain_attr { 8851d3504fcSHidetoshi Seto int relax_domain_level; 8861d3504fcSHidetoshi Seto }; 8871d3504fcSHidetoshi Seto 8881d3504fcSHidetoshi Seto #define SD_ATTR_INIT (struct sched_domain_attr) { \ 8891d3504fcSHidetoshi Seto .relax_domain_level = -1, \ 8901d3504fcSHidetoshi Seto } 8911d3504fcSHidetoshi Seto 8921da177e4SLinus Torvalds struct sched_domain { 8931da177e4SLinus Torvalds /* These fields must be setup */ 8941da177e4SLinus Torvalds struct sched_domain *parent; /* top domain must be null terminated */ 8951a848870SSiddha, Suresh B struct sched_domain *child; /* bottom domain must be null terminated */ 8961da177e4SLinus Torvalds struct sched_group *groups; /* the balancing groups of the domain */ 8971da177e4SLinus Torvalds unsigned long min_interval; /* Minimum balance interval ms */ 8981da177e4SLinus Torvalds unsigned long max_interval; /* Maximum balance interval ms */ 8991da177e4SLinus Torvalds unsigned int busy_factor; /* less balancing by factor if busy */ 9001da177e4SLinus Torvalds unsigned int imbalance_pct; /* No balance until over watermark */ 9011da177e4SLinus Torvalds unsigned int cache_nice_tries; /* Leave cache hot tasks for # tries */ 9027897986bSNick Piggin unsigned int busy_idx; 9037897986bSNick Piggin unsigned int idle_idx; 9047897986bSNick Piggin unsigned int newidle_idx; 9057897986bSNick Piggin unsigned int wake_idx; 906147cbb4bSNick Piggin unsigned int forkexec_idx; 907a52bfd73SPeter Zijlstra unsigned int smt_gain; 9081da177e4SLinus Torvalds int flags; /* See SD_* */ 9091d3504fcSHidetoshi Seto enum sched_domain_level level; 9101da177e4SLinus Torvalds 9111da177e4SLinus Torvalds /* Runtime fields. */ 9121da177e4SLinus Torvalds unsigned long last_balance; /* init to jiffies. units in jiffies */ 9131da177e4SLinus Torvalds unsigned int balance_interval; /* initialise to 1. units in ms. */ 9141da177e4SLinus Torvalds unsigned int nr_balance_failed; /* initialise to 0 */ 9151da177e4SLinus Torvalds 9162398f2c6SPeter Zijlstra u64 last_update; 9172398f2c6SPeter Zijlstra 9181da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS 9191da177e4SLinus Torvalds /* load_balance() stats */ 920480b9434SKen Chen unsigned int lb_count[CPU_MAX_IDLE_TYPES]; 921480b9434SKen Chen unsigned int lb_failed[CPU_MAX_IDLE_TYPES]; 922480b9434SKen Chen unsigned int lb_balanced[CPU_MAX_IDLE_TYPES]; 923480b9434SKen Chen unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES]; 924480b9434SKen Chen unsigned int lb_gained[CPU_MAX_IDLE_TYPES]; 925480b9434SKen Chen unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES]; 926480b9434SKen Chen unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES]; 927480b9434SKen Chen unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES]; 9281da177e4SLinus Torvalds 9291da177e4SLinus Torvalds /* Active load balancing */ 930480b9434SKen Chen unsigned int alb_count; 931480b9434SKen Chen unsigned int alb_failed; 932480b9434SKen Chen unsigned int alb_pushed; 9331da177e4SLinus Torvalds 93468767a0aSNick Piggin /* SD_BALANCE_EXEC stats */ 935480b9434SKen Chen unsigned int sbe_count; 936480b9434SKen Chen unsigned int sbe_balanced; 937480b9434SKen Chen unsigned int sbe_pushed; 9381da177e4SLinus Torvalds 93968767a0aSNick Piggin /* SD_BALANCE_FORK stats */ 940480b9434SKen Chen unsigned int sbf_count; 941480b9434SKen Chen unsigned int sbf_balanced; 942480b9434SKen Chen unsigned int sbf_pushed; 94368767a0aSNick Piggin 9441da177e4SLinus Torvalds /* try_to_wake_up() stats */ 945480b9434SKen Chen unsigned int ttwu_wake_remote; 946480b9434SKen Chen unsigned int ttwu_move_affine; 947480b9434SKen Chen unsigned int ttwu_move_balance; 9481da177e4SLinus Torvalds #endif 949a5d8c348SIngo Molnar #ifdef CONFIG_SCHED_DEBUG 950a5d8c348SIngo Molnar char *name; 951a5d8c348SIngo Molnar #endif 9526c99e9adSRusty Russell 953669c55e9SPeter Zijlstra unsigned int span_weight; 9544200efd9SIngo Molnar /* 9554200efd9SIngo Molnar * Span of all CPUs in this domain. 9564200efd9SIngo Molnar * 9574200efd9SIngo Molnar * NOTE: this field is variable length. (Allocated dynamically 9584200efd9SIngo Molnar * by attaching extra space to the end of the structure, 9594200efd9SIngo Molnar * depending on how many CPUs the kernel has booted up with) 9604200efd9SIngo Molnar * 9614200efd9SIngo Molnar * It is also be embedded into static data structures at build 9624200efd9SIngo Molnar * time. (See 'struct static_sched_domain' in kernel/sched.c) 9634200efd9SIngo Molnar */ 9644200efd9SIngo Molnar unsigned long span[0]; 9651da177e4SLinus Torvalds }; 9661da177e4SLinus Torvalds 967758b2cdcSRusty Russell static inline struct cpumask *sched_domain_span(struct sched_domain *sd) 968758b2cdcSRusty Russell { 9696c99e9adSRusty Russell return to_cpumask(sd->span); 970758b2cdcSRusty Russell } 971758b2cdcSRusty Russell 972acc3f5d7SRusty Russell extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], 9731d3504fcSHidetoshi Seto struct sched_domain_attr *dattr_new); 974029190c5SPaul Jackson 975acc3f5d7SRusty Russell /* Allocate an array of sched domains, for partition_sched_domains(). */ 976acc3f5d7SRusty Russell cpumask_var_t *alloc_sched_domains(unsigned int ndoms); 977acc3f5d7SRusty Russell void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms); 978acc3f5d7SRusty Russell 97906aaf76aSIngo Molnar /* Test a flag in parent sched domain */ 98006aaf76aSIngo Molnar static inline int test_sd_parent(struct sched_domain *sd, int flag) 98106aaf76aSIngo Molnar { 98206aaf76aSIngo Molnar if (sd->parent && (sd->parent->flags & flag)) 98306aaf76aSIngo Molnar return 1; 98406aaf76aSIngo Molnar 98506aaf76aSIngo Molnar return 0; 98606aaf76aSIngo Molnar } 9871da177e4SLinus Torvalds 98847fe38fcSPeter Zijlstra unsigned long default_scale_freq_power(struct sched_domain *sd, int cpu); 98947fe38fcSPeter Zijlstra unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu); 99047fe38fcSPeter Zijlstra 9911b427c15SIngo Molnar #else /* CONFIG_SMP */ 9921da177e4SLinus Torvalds 9931b427c15SIngo Molnar struct sched_domain_attr; 9941b427c15SIngo Molnar 9951b427c15SIngo Molnar static inline void 996acc3f5d7SRusty Russell partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], 9971b427c15SIngo Molnar struct sched_domain_attr *dattr_new) 998d02c7a8cSCon Kolivas { 999d02c7a8cSCon Kolivas } 10001b427c15SIngo Molnar #endif /* !CONFIG_SMP */ 10011da177e4SLinus Torvalds 100247fe38fcSPeter Zijlstra 10031da177e4SLinus Torvalds struct io_context; /* See blkdev.h */ 10041da177e4SLinus Torvalds 10051da177e4SLinus Torvalds 1006383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK 100736c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t); 1008383f2835SChen, Kenneth W #else 1009383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { } 1010383f2835SChen, Kenneth W #endif 10111da177e4SLinus Torvalds 10121da177e4SLinus Torvalds struct audit_context; /* See audit.c */ 10131da177e4SLinus Torvalds struct mempolicy; 1014b92ce558SJens Axboe struct pipe_inode_info; 10154865ecf1SSerge E. Hallyn struct uts_namespace; 10161da177e4SLinus Torvalds 101720b8a59fSIngo Molnar struct rq; 101820b8a59fSIngo Molnar struct sched_domain; 101920b8a59fSIngo Molnar 10207d478721SPeter Zijlstra /* 10217d478721SPeter Zijlstra * wake flags 10227d478721SPeter Zijlstra */ 10237d478721SPeter Zijlstra #define WF_SYNC 0x01 /* waker goes to sleep after wakup */ 1024a7558e01SPeter Zijlstra #define WF_FORK 0x02 /* child wakeup after fork */ 10257d478721SPeter Zijlstra 1026371fd7e7SPeter Zijlstra #define ENQUEUE_WAKEUP 1 1027371fd7e7SPeter Zijlstra #define ENQUEUE_WAKING 2 1028371fd7e7SPeter Zijlstra #define ENQUEUE_HEAD 4 1029371fd7e7SPeter Zijlstra 1030371fd7e7SPeter Zijlstra #define DEQUEUE_SLEEP 1 1031371fd7e7SPeter Zijlstra 103220b8a59fSIngo Molnar struct sched_class { 10335522d5d5SIngo Molnar const struct sched_class *next; 103420b8a59fSIngo Molnar 1035371fd7e7SPeter Zijlstra void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags); 1036371fd7e7SPeter Zijlstra void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags); 10374530d7abSDmitry Adamushko void (*yield_task) (struct rq *rq); 103820b8a59fSIngo Molnar 10397d478721SPeter Zijlstra void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags); 104020b8a59fSIngo Molnar 1041fb8d4724SIngo Molnar struct task_struct * (*pick_next_task) (struct rq *rq); 104231ee529cSIngo Molnar void (*put_prev_task) (struct rq *rq, struct task_struct *p); 104320b8a59fSIngo Molnar 1044681f3e68SPeter Williams #ifdef CONFIG_SMP 10450017d735SPeter Zijlstra int (*select_task_rq)(struct rq *rq, struct task_struct *p, 10460017d735SPeter Zijlstra int sd_flag, int flags); 10474ce72a2cSLi Zefan 10489a897c5aSSteven Rostedt void (*pre_schedule) (struct rq *this_rq, struct task_struct *task); 10499a897c5aSSteven Rostedt void (*post_schedule) (struct rq *this_rq); 1050efbbd05aSPeter Zijlstra void (*task_waking) (struct rq *this_rq, struct task_struct *task); 1051efbbd05aSPeter Zijlstra void (*task_woken) (struct rq *this_rq, struct task_struct *task); 1052e1d1484fSPeter Williams 1053cd8ba7cdSMike Travis void (*set_cpus_allowed)(struct task_struct *p, 105496f874e2SRusty Russell const struct cpumask *newmask); 105557d885feSGregory Haskins 10561f11eb6aSGregory Haskins void (*rq_online)(struct rq *rq); 10571f11eb6aSGregory Haskins void (*rq_offline)(struct rq *rq); 10584ce72a2cSLi Zefan #endif 10594ce72a2cSLi Zefan 10604ce72a2cSLi Zefan void (*set_curr_task) (struct rq *rq); 10614ce72a2cSLi Zefan void (*task_tick) (struct rq *rq, struct task_struct *p, int queued); 1062cd29fe6fSPeter Zijlstra void (*task_fork) (struct task_struct *p); 1063cb469845SSteven Rostedt 1064cb469845SSteven Rostedt void (*switched_from) (struct rq *this_rq, struct task_struct *task, 1065cb469845SSteven Rostedt int running); 1066cb469845SSteven Rostedt void (*switched_to) (struct rq *this_rq, struct task_struct *task, 1067cb469845SSteven Rostedt int running); 1068cb469845SSteven Rostedt void (*prio_changed) (struct rq *this_rq, struct task_struct *task, 1069cb469845SSteven Rostedt int oldprio, int running); 1070810b3817SPeter Zijlstra 1071dba091b9SThomas Gleixner unsigned int (*get_rr_interval) (struct rq *rq, 1072dba091b9SThomas Gleixner struct task_struct *task); 10730d721ceaSPeter Williams 1074810b3817SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED 107588ec22d3SPeter Zijlstra void (*moved_group) (struct task_struct *p, int on_rq); 1076810b3817SPeter Zijlstra #endif 107720b8a59fSIngo Molnar }; 107820b8a59fSIngo Molnar 107920b8a59fSIngo Molnar struct load_weight { 108020b8a59fSIngo Molnar unsigned long weight, inv_weight; 108120b8a59fSIngo Molnar }; 108220b8a59fSIngo Molnar 108394c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS 108441acab88SLucas De Marchi struct sched_statistics { 108594c18227SIngo Molnar u64 wait_start; 108694c18227SIngo Molnar u64 wait_max; 10876d082592SArjan van de Ven u64 wait_count; 10886d082592SArjan van de Ven u64 wait_sum; 10898f0dfc34SArjan van de Ven u64 iowait_count; 10908f0dfc34SArjan van de Ven u64 iowait_sum; 109194c18227SIngo Molnar 109294c18227SIngo Molnar u64 sleep_start; 109320b8a59fSIngo Molnar u64 sleep_max; 109494c18227SIngo Molnar s64 sum_sleep_runtime; 109594c18227SIngo Molnar 109694c18227SIngo Molnar u64 block_start; 109720b8a59fSIngo Molnar u64 block_max; 109820b8a59fSIngo Molnar u64 exec_max; 1099eba1ed4bSIngo Molnar u64 slice_max; 1100cc367732SIngo Molnar 1101cc367732SIngo Molnar u64 nr_migrations_cold; 1102cc367732SIngo Molnar u64 nr_failed_migrations_affine; 1103cc367732SIngo Molnar u64 nr_failed_migrations_running; 1104cc367732SIngo Molnar u64 nr_failed_migrations_hot; 1105cc367732SIngo Molnar u64 nr_forced_migrations; 1106cc367732SIngo Molnar 1107cc367732SIngo Molnar u64 nr_wakeups; 1108cc367732SIngo Molnar u64 nr_wakeups_sync; 1109cc367732SIngo Molnar u64 nr_wakeups_migrate; 1110cc367732SIngo Molnar u64 nr_wakeups_local; 1111cc367732SIngo Molnar u64 nr_wakeups_remote; 1112cc367732SIngo Molnar u64 nr_wakeups_affine; 1113cc367732SIngo Molnar u64 nr_wakeups_affine_attempts; 1114cc367732SIngo Molnar u64 nr_wakeups_passive; 1115cc367732SIngo Molnar u64 nr_wakeups_idle; 111641acab88SLucas De Marchi }; 111741acab88SLucas De Marchi #endif 111841acab88SLucas De Marchi 111941acab88SLucas De Marchi struct sched_entity { 112041acab88SLucas De Marchi struct load_weight load; /* for load-balancing */ 112141acab88SLucas De Marchi struct rb_node run_node; 112241acab88SLucas De Marchi struct list_head group_node; 112341acab88SLucas De Marchi unsigned int on_rq; 112441acab88SLucas De Marchi 112541acab88SLucas De Marchi u64 exec_start; 112641acab88SLucas De Marchi u64 sum_exec_runtime; 112741acab88SLucas De Marchi u64 vruntime; 112841acab88SLucas De Marchi u64 prev_sum_exec_runtime; 112941acab88SLucas De Marchi 113041acab88SLucas De Marchi u64 nr_migrations; 113141acab88SLucas De Marchi 113241acab88SLucas De Marchi #ifdef CONFIG_SCHEDSTATS 113341acab88SLucas De Marchi struct sched_statistics statistics; 113494c18227SIngo Molnar #endif 113594c18227SIngo Molnar 113620b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED 113720b8a59fSIngo Molnar struct sched_entity *parent; 113820b8a59fSIngo Molnar /* rq on which this entity is (to be) queued: */ 113920b8a59fSIngo Molnar struct cfs_rq *cfs_rq; 114020b8a59fSIngo Molnar /* rq "owned" by this entity/group: */ 114120b8a59fSIngo Molnar struct cfs_rq *my_q; 114220b8a59fSIngo Molnar #endif 114320b8a59fSIngo Molnar }; 114470b97a7fSIngo Molnar 1145fa717060SPeter Zijlstra struct sched_rt_entity { 1146fa717060SPeter Zijlstra struct list_head run_list; 114778f2c7dbSPeter Zijlstra unsigned long timeout; 1148bee367edSRichard Kennedy unsigned int time_slice; 11496f505b16SPeter Zijlstra int nr_cpus_allowed; 11506f505b16SPeter Zijlstra 115158d6c2d7SPeter Zijlstra struct sched_rt_entity *back; 1152052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED 11536f505b16SPeter Zijlstra struct sched_rt_entity *parent; 11546f505b16SPeter Zijlstra /* rq on which this entity is (to be) queued: */ 11556f505b16SPeter Zijlstra struct rt_rq *rt_rq; 11566f505b16SPeter Zijlstra /* rq "owned" by this entity/group: */ 11576f505b16SPeter Zijlstra struct rt_rq *my_q; 11586f505b16SPeter Zijlstra #endif 1159fa717060SPeter Zijlstra }; 1160fa717060SPeter Zijlstra 116186848966SPaul E. McKenney struct rcu_node; 116286848966SPaul E. McKenney 11631da177e4SLinus Torvalds struct task_struct { 11641da177e4SLinus Torvalds volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ 1165f7e4217bSRoman Zippel void *stack; 11661da177e4SLinus Torvalds atomic_t usage; 116797dc32cdSWilliam Cohen unsigned int flags; /* per process flags, defined below */ 116897dc32cdSWilliam Cohen unsigned int ptrace; 11691da177e4SLinus Torvalds 117036772092SPaolo 'Blaisorblade' Giarrusso int lock_depth; /* BKL lock depth */ 11711da177e4SLinus Torvalds 11722dd73a4fSPeter Williams #ifdef CONFIG_SMP 11732dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW 11744866cde0SNick Piggin int oncpu; 11754866cde0SNick Piggin #endif 11762dd73a4fSPeter Williams #endif 117750e645a8SIngo Molnar 1178b29739f9SIngo Molnar int prio, static_prio, normal_prio; 1179c7aceabaSRichard Kennedy unsigned int rt_priority; 11805522d5d5SIngo Molnar const struct sched_class *sched_class; 118120b8a59fSIngo Molnar struct sched_entity se; 1182fa717060SPeter Zijlstra struct sched_rt_entity rt; 11831da177e4SLinus Torvalds 1184e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS 1185e107be36SAvi Kivity /* list of struct preempt_notifier: */ 1186e107be36SAvi Kivity struct hlist_head preempt_notifiers; 1187e107be36SAvi Kivity #endif 1188e107be36SAvi Kivity 118918796aa0SAlexey Dobriyan /* 119018796aa0SAlexey Dobriyan * fpu_counter contains the number of consecutive context switches 119118796aa0SAlexey Dobriyan * that the FPU is used. If this is over a threshold, the lazy fpu 119218796aa0SAlexey Dobriyan * saving becomes unlazy to save the trap. This is an unsigned char 119318796aa0SAlexey Dobriyan * so that after 256 times the counter wraps and the behavior turns 119418796aa0SAlexey Dobriyan * lazy again; this to deal with bursty apps that only use FPU for 119518796aa0SAlexey Dobriyan * a short time 119618796aa0SAlexey Dobriyan */ 119718796aa0SAlexey Dobriyan unsigned char fpu_counter; 11986c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE 11992056a782SJens Axboe unsigned int btrace_seq; 12006c5c9341SAlexey Dobriyan #endif 12011da177e4SLinus Torvalds 120297dc32cdSWilliam Cohen unsigned int policy; 12031da177e4SLinus Torvalds cpumask_t cpus_allowed; 12041da177e4SLinus Torvalds 1205f41d911fSPaul E. McKenney #ifdef CONFIG_TREE_PREEMPT_RCU 1206e260be67SPaul E. McKenney int rcu_read_lock_nesting; 1207f41d911fSPaul E. McKenney char rcu_read_unlock_special; 120886848966SPaul E. McKenney struct rcu_node *rcu_blocked_node; 1209f41d911fSPaul E. McKenney struct list_head rcu_node_entry; 1210f41d911fSPaul E. McKenney #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */ 1211e260be67SPaul E. McKenney 121252f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 12131da177e4SLinus Torvalds struct sched_info sched_info; 12141da177e4SLinus Torvalds #endif 12151da177e4SLinus Torvalds 12161da177e4SLinus Torvalds struct list_head tasks; 1217917b627dSGregory Haskins struct plist_node pushable_tasks; 12181da177e4SLinus Torvalds 12191da177e4SLinus Torvalds struct mm_struct *mm, *active_mm; 122034e55232SKAMEZAWA Hiroyuki #if defined(SPLIT_RSS_COUNTING) 122134e55232SKAMEZAWA Hiroyuki struct task_rss_stat rss_stat; 122234e55232SKAMEZAWA Hiroyuki #endif 12231da177e4SLinus Torvalds /* task state */ 122497dc32cdSWilliam Cohen int exit_state; 12251da177e4SLinus Torvalds int exit_code, exit_signal; 12261da177e4SLinus Torvalds int pdeath_signal; /* The signal sent when the parent dies */ 12271da177e4SLinus Torvalds /* ??? */ 122897dc32cdSWilliam Cohen unsigned int personality; 12291da177e4SLinus Torvalds unsigned did_exec:1; 1230f9ce1f1cSKentaro Takeda unsigned in_execve:1; /* Tell the LSMs that the process is doing an 1231f9ce1f1cSKentaro Takeda * execve */ 12328f0dfc34SArjan van de Ven unsigned in_iowait:1; 12338f0dfc34SArjan van de Ven 1234ca94c442SLennart Poettering 1235ca94c442SLennart Poettering /* Revert to default priority/policy when forking */ 1236ca94c442SLennart Poettering unsigned sched_reset_on_fork:1; 1237ca94c442SLennart Poettering 12381da177e4SLinus Torvalds pid_t pid; 12391da177e4SLinus Torvalds pid_t tgid; 12400a425405SArjan van de Ven 12411314562aSHiroshi Shimamoto #ifdef CONFIG_CC_STACKPROTECTOR 12420a425405SArjan van de Ven /* Canary value for the -fstack-protector gcc feature */ 12430a425405SArjan van de Ven unsigned long stack_canary; 12441314562aSHiroshi Shimamoto #endif 1245e0032087SIngo Molnar 12461da177e4SLinus Torvalds /* 12471da177e4SLinus Torvalds * pointers to (original) parent process, youngest child, younger sibling, 12481da177e4SLinus Torvalds * older sibling, respectively. (p->father can be replaced with 1249f470021aSRoland McGrath * p->real_parent->pid) 12501da177e4SLinus Torvalds */ 1251f470021aSRoland McGrath struct task_struct *real_parent; /* real parent process */ 1252f470021aSRoland McGrath struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports */ 12531da177e4SLinus Torvalds /* 1254f470021aSRoland McGrath * children/sibling forms the list of my natural children 12551da177e4SLinus Torvalds */ 12561da177e4SLinus Torvalds struct list_head children; /* list of my children */ 12571da177e4SLinus Torvalds struct list_head sibling; /* linkage in my parent's children list */ 12581da177e4SLinus Torvalds struct task_struct *group_leader; /* threadgroup leader */ 12591da177e4SLinus Torvalds 1260f470021aSRoland McGrath /* 1261f470021aSRoland McGrath * ptraced is the list of tasks this task is using ptrace on. 1262f470021aSRoland McGrath * This includes both natural children and PTRACE_ATTACH targets. 1263f470021aSRoland McGrath * p->ptrace_entry is p's link on the p->parent->ptraced list. 1264f470021aSRoland McGrath */ 1265f470021aSRoland McGrath struct list_head ptraced; 1266f470021aSRoland McGrath struct list_head ptrace_entry; 1267f470021aSRoland McGrath 12681da177e4SLinus Torvalds /* PID/PID hash table linkage. */ 126992476d7fSEric W. Biederman struct pid_link pids[PIDTYPE_MAX]; 127047e65328SOleg Nesterov struct list_head thread_group; 12711da177e4SLinus Torvalds 12721da177e4SLinus Torvalds struct completion *vfork_done; /* for vfork() */ 12731da177e4SLinus Torvalds int __user *set_child_tid; /* CLONE_CHILD_SETTID */ 12741da177e4SLinus Torvalds int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */ 12751da177e4SLinus Torvalds 1276c66f08beSMichael Neuling cputime_t utime, stime, utimescaled, stimescaled; 12779ac52315SLaurent Vivier cputime_t gtime; 1278d99ca3b9SHidetoshi Seto #ifndef CONFIG_VIRT_CPU_ACCOUNTING 12799301899bSBalbir Singh cputime_t prev_utime, prev_stime; 1280d99ca3b9SHidetoshi Seto #endif 12811da177e4SLinus Torvalds unsigned long nvcsw, nivcsw; /* context switch counts */ 1282924b42d5STomas Janousek struct timespec start_time; /* monotonic time */ 1283924b42d5STomas Janousek struct timespec real_start_time; /* boot based time */ 12841da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ 12851da177e4SLinus Torvalds unsigned long min_flt, maj_flt; 12861da177e4SLinus Torvalds 1287f06febc9SFrank Mayhar struct task_cputime cputime_expires; 12881da177e4SLinus Torvalds struct list_head cpu_timers[3]; 12891da177e4SLinus Torvalds 12901da177e4SLinus Torvalds /* process credentials */ 12913b11a1deSDavid Howells const struct cred *real_cred; /* objective and real subjective task 12923b11a1deSDavid Howells * credentials (COW) */ 12933b11a1deSDavid Howells const struct cred *cred; /* effective (overridable) subjective task 12943b11a1deSDavid Howells * credentials (COW) */ 12955e751e99SDavid Howells struct mutex cred_guard_mutex; /* guard against foreign influences on 12965e751e99SDavid Howells * credential calculations 12975e751e99SDavid Howells * (notably. ptrace) */ 1298ee18d64cSDavid Howells struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */ 1299b6dff3ecSDavid Howells 130036772092SPaolo 'Blaisorblade' Giarrusso char comm[TASK_COMM_LEN]; /* executable name excluding path 130136772092SPaolo 'Blaisorblade' Giarrusso - access with [gs]et_task_comm (which lock 130236772092SPaolo 'Blaisorblade' Giarrusso it with task_lock()) 1303221af7f8SLinus Torvalds - initialized normally by setup_new_exec */ 13041da177e4SLinus Torvalds /* file system info */ 13051da177e4SLinus Torvalds int link_count, total_link_count; 13063d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC 13071da177e4SLinus Torvalds /* ipc stuff */ 13081da177e4SLinus Torvalds struct sysv_sem sysvsem; 13093d5b6fccSAlexey Dobriyan #endif 1310e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK 131182a1fcb9SIngo Molnar /* hung task detection */ 131282a1fcb9SIngo Molnar unsigned long last_switch_count; 131382a1fcb9SIngo Molnar #endif 13141da177e4SLinus Torvalds /* CPU-specific state of this task */ 13151da177e4SLinus Torvalds struct thread_struct thread; 13161da177e4SLinus Torvalds /* filesystem information */ 13171da177e4SLinus Torvalds struct fs_struct *fs; 13181da177e4SLinus Torvalds /* open file information */ 13191da177e4SLinus Torvalds struct files_struct *files; 13201651e14eSSerge E. Hallyn /* namespaces */ 1321ab516013SSerge E. Hallyn struct nsproxy *nsproxy; 13221da177e4SLinus Torvalds /* signal handlers */ 13231da177e4SLinus Torvalds struct signal_struct *signal; 13241da177e4SLinus Torvalds struct sighand_struct *sighand; 13251da177e4SLinus Torvalds 13261da177e4SLinus Torvalds sigset_t blocked, real_blocked; 1327f3de272bSRoland McGrath sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */ 13281da177e4SLinus Torvalds struct sigpending pending; 13291da177e4SLinus Torvalds 13301da177e4SLinus Torvalds unsigned long sas_ss_sp; 13311da177e4SLinus Torvalds size_t sas_ss_size; 13321da177e4SLinus Torvalds int (*notifier)(void *priv); 13331da177e4SLinus Torvalds void *notifier_data; 13341da177e4SLinus Torvalds sigset_t *notifier_mask; 13351da177e4SLinus Torvalds struct audit_context *audit_context; 1336bfef93a5SAl Viro #ifdef CONFIG_AUDITSYSCALL 1337bfef93a5SAl Viro uid_t loginuid; 13384746ec5bSEric Paris unsigned int sessionid; 1339bfef93a5SAl Viro #endif 13401da177e4SLinus Torvalds seccomp_t seccomp; 13411da177e4SLinus Torvalds 13421da177e4SLinus Torvalds /* Thread group tracking */ 13431da177e4SLinus Torvalds u32 parent_exec_id; 13441da177e4SLinus Torvalds u32 self_exec_id; 134558568d2aSMiao Xie /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed, 134658568d2aSMiao Xie * mempolicy */ 13471da177e4SLinus Torvalds spinlock_t alloc_lock; 13481da177e4SLinus Torvalds 13493aa551c9SThomas Gleixner #ifdef CONFIG_GENERIC_HARDIRQS 13503aa551c9SThomas Gleixner /* IRQ handler threads */ 13513aa551c9SThomas Gleixner struct irqaction *irqaction; 13523aa551c9SThomas Gleixner #endif 13533aa551c9SThomas Gleixner 1354b29739f9SIngo Molnar /* Protection of the PI data structures: */ 13551d615482SThomas Gleixner raw_spinlock_t pi_lock; 1356b29739f9SIngo Molnar 135723f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 135823f78d4aSIngo Molnar /* PI waiters blocked on a rt_mutex held by this task */ 135923f78d4aSIngo Molnar struct plist_head pi_waiters; 136023f78d4aSIngo Molnar /* Deadlock detection and priority inheritance handling */ 136123f78d4aSIngo Molnar struct rt_mutex_waiter *pi_blocked_on; 136223f78d4aSIngo Molnar #endif 136323f78d4aSIngo Molnar 1364408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES 1365408894eeSIngo Molnar /* mutex deadlock detection */ 1366408894eeSIngo Molnar struct mutex_waiter *blocked_on; 1367408894eeSIngo Molnar #endif 1368de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS 1369de30a2b3SIngo Molnar unsigned int irq_events; 1370de30a2b3SIngo Molnar unsigned long hardirq_enable_ip; 1371de30a2b3SIngo Molnar unsigned long hardirq_disable_ip; 1372fa1452e8SHiroshi Shimamoto unsigned int hardirq_enable_event; 1373de30a2b3SIngo Molnar unsigned int hardirq_disable_event; 1374fa1452e8SHiroshi Shimamoto int hardirqs_enabled; 1375de30a2b3SIngo Molnar int hardirq_context; 1376fa1452e8SHiroshi Shimamoto unsigned long softirq_disable_ip; 1377fa1452e8SHiroshi Shimamoto unsigned long softirq_enable_ip; 1378fa1452e8SHiroshi Shimamoto unsigned int softirq_disable_event; 1379fa1452e8SHiroshi Shimamoto unsigned int softirq_enable_event; 1380fa1452e8SHiroshi Shimamoto int softirqs_enabled; 1381de30a2b3SIngo Molnar int softirq_context; 1382de30a2b3SIngo Molnar #endif 1383fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP 1384bdb9441eSPeter Zijlstra # define MAX_LOCK_DEPTH 48UL 1385fbb9ce95SIngo Molnar u64 curr_chain_key; 1386fbb9ce95SIngo Molnar int lockdep_depth; 1387fbb9ce95SIngo Molnar unsigned int lockdep_recursion; 1388c7aceabaSRichard Kennedy struct held_lock held_locks[MAX_LOCK_DEPTH]; 1389cf40bd16SNick Piggin gfp_t lockdep_reclaim_gfp; 1390fbb9ce95SIngo Molnar #endif 1391408894eeSIngo Molnar 13921da177e4SLinus Torvalds /* journalling filesystem info */ 13931da177e4SLinus Torvalds void *journal_info; 13941da177e4SLinus Torvalds 1395d89d8796SNeil Brown /* stacked block device info */ 1396bddd87c7SAkinobu Mita struct bio_list *bio_list; 1397d89d8796SNeil Brown 13981da177e4SLinus Torvalds /* VM state */ 13991da177e4SLinus Torvalds struct reclaim_state *reclaim_state; 14001da177e4SLinus Torvalds 14011da177e4SLinus Torvalds struct backing_dev_info *backing_dev_info; 14021da177e4SLinus Torvalds 14031da177e4SLinus Torvalds struct io_context *io_context; 14041da177e4SLinus Torvalds 14051da177e4SLinus Torvalds unsigned long ptrace_message; 14061da177e4SLinus Torvalds siginfo_t *last_siginfo; /* For ptrace use. */ 14077c3ab738SAndrew Morton struct task_io_accounting ioac; 14088f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT) 14091da177e4SLinus Torvalds u64 acct_rss_mem1; /* accumulated rss usage */ 14101da177e4SLinus Torvalds u64 acct_vm_mem1; /* accumulated virtual memory usage */ 141149b5cf34SJonathan Lim cputime_t acct_timexpd; /* stime + utime since last update */ 14121da177e4SLinus Torvalds #endif 14131da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS 141458568d2aSMiao Xie nodemask_t mems_allowed; /* Protected by alloc_lock */ 1415c0ff7453SMiao Xie int mems_allowed_change_disable; 1416825a46afSPaul Jackson int cpuset_mem_spread_rotor; 14176adef3ebSJack Steiner int cpuset_slab_spread_rotor; 14181da177e4SLinus Torvalds #endif 1419ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS 1420817929ecSPaul Menage /* Control Group info protected by css_set_lock */ 1421*2c392b8cSArnd Bergmann struct css_set __rcu *cgroups; 1422817929ecSPaul Menage /* cg_list protected by css_set_lock and tsk->alloc_lock */ 1423817929ecSPaul Menage struct list_head cg_list; 1424ddbcc7e8SPaul Menage #endif 142542b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX 14260771dfefSIngo Molnar struct robust_list_head __user *robust_list; 142734f192c6SIngo Molnar #ifdef CONFIG_COMPAT 142834f192c6SIngo Molnar struct compat_robust_list_head __user *compat_robust_list; 142934f192c6SIngo Molnar #endif 1430c87e2837SIngo Molnar struct list_head pi_state_list; 1431c87e2837SIngo Molnar struct futex_pi_state *pi_state_cache; 143242b2dd0aSAlexey Dobriyan #endif 1433cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS 1434cdd6c482SIngo Molnar struct perf_event_context *perf_event_ctxp; 1435cdd6c482SIngo Molnar struct mutex perf_event_mutex; 1436cdd6c482SIngo Molnar struct list_head perf_event_list; 1437a63eaf34SPaul Mackerras #endif 1438c7aceabaSRichard Kennedy #ifdef CONFIG_NUMA 143958568d2aSMiao Xie struct mempolicy *mempolicy; /* Protected by alloc_lock */ 1440c7aceabaSRichard Kennedy short il_next; 1441c7aceabaSRichard Kennedy #endif 144222e2c507SJens Axboe atomic_t fs_excl; /* holding fs exclusive resources */ 1443e56d0903SIngo Molnar struct rcu_head rcu; 1444b92ce558SJens Axboe 1445b92ce558SJens Axboe /* 1446b92ce558SJens Axboe * cache last used pipe for splice 1447b92ce558SJens Axboe */ 1448b92ce558SJens Axboe struct pipe_inode_info *splice_pipe; 1449ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 1450ca74e92bSShailabh Nagar struct task_delay_info *delays; 1451ca74e92bSShailabh Nagar #endif 1452f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION 1453f4f154fdSAkinobu Mita int make_it_fail; 1454f4f154fdSAkinobu Mita #endif 14553e26c149SPeter Zijlstra struct prop_local_single dirties; 14569745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP 14579745512cSArjan van de Ven int latency_record_count; 14589745512cSArjan van de Ven struct latency_record latency_record[LT_SAVECOUNT]; 14599745512cSArjan van de Ven #endif 14606976675dSArjan van de Ven /* 14616976675dSArjan van de Ven * time slack values; these are used to round up poll() and 14626976675dSArjan van de Ven * select() etc timeout values. These are in nanoseconds. 14636976675dSArjan van de Ven */ 14646976675dSArjan van de Ven unsigned long timer_slack_ns; 14656976675dSArjan van de Ven unsigned long default_timer_slack_ns; 1466f8d570a4SDavid Miller 1467f8d570a4SDavid Miller struct list_head *scm_work_list; 1468fb52607aSFrederic Weisbecker #ifdef CONFIG_FUNCTION_GRAPH_TRACER 14693ad2f3fbSDaniel Mack /* Index of current stored address in ret_stack */ 1470f201ae23SFrederic Weisbecker int curr_ret_stack; 1471f201ae23SFrederic Weisbecker /* Stack of return addresses for return function tracing */ 1472f201ae23SFrederic Weisbecker struct ftrace_ret_stack *ret_stack; 14738aef2d28SSteven Rostedt /* time stamp for last schedule */ 14748aef2d28SSteven Rostedt unsigned long long ftrace_timestamp; 1475f201ae23SFrederic Weisbecker /* 1476f201ae23SFrederic Weisbecker * Number of functions that haven't been traced 1477f201ae23SFrederic Weisbecker * because of depth overrun. 1478f201ae23SFrederic Weisbecker */ 1479f201ae23SFrederic Weisbecker atomic_t trace_overrun; 1480380c4b14SFrederic Weisbecker /* Pause for the tracing */ 1481380c4b14SFrederic Weisbecker atomic_t tracing_graph_pause; 1482f201ae23SFrederic Weisbecker #endif 1483ea4e2bc4SSteven Rostedt #ifdef CONFIG_TRACING 1484ea4e2bc4SSteven Rostedt /* state flags for use by tracers */ 1485ea4e2bc4SSteven Rostedt unsigned long trace; 1486261842b7SSteven Rostedt /* bitmask of trace recursion */ 1487261842b7SSteven Rostedt unsigned long trace_recursion; 1488261842b7SSteven Rostedt #endif /* CONFIG_TRACING */ 1489569b846dSKAMEZAWA Hiroyuki #ifdef CONFIG_CGROUP_MEM_RES_CTLR /* memcg uses this to do batch job */ 1490569b846dSKAMEZAWA Hiroyuki struct memcg_batch_info { 1491569b846dSKAMEZAWA Hiroyuki int do_batch; /* incremented when batch uncharge started */ 1492569b846dSKAMEZAWA Hiroyuki struct mem_cgroup *memcg; /* target memcg of uncharge */ 1493569b846dSKAMEZAWA Hiroyuki unsigned long bytes; /* uncharged usage */ 1494569b846dSKAMEZAWA Hiroyuki unsigned long memsw_bytes; /* uncharged mem+swap usage */ 1495569b846dSKAMEZAWA Hiroyuki } memcg_batch; 1496569b846dSKAMEZAWA Hiroyuki #endif 14971da177e4SLinus Torvalds }; 14981da177e4SLinus Torvalds 149976e6eee0SRusty Russell /* Future-safe accessor for struct task_struct's cpus_allowed. */ 1500a4636818SRusty Russell #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed) 150176e6eee0SRusty Russell 1502e05606d3SIngo Molnar /* 1503e05606d3SIngo Molnar * Priority of a process goes from 0..MAX_PRIO-1, valid RT 1504e05606d3SIngo Molnar * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH 1505e05606d3SIngo Molnar * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority 1506e05606d3SIngo Molnar * values are inverted: lower p->prio value means higher priority. 1507e05606d3SIngo Molnar * 1508e05606d3SIngo Molnar * The MAX_USER_RT_PRIO value allows the actual maximum 1509e05606d3SIngo Molnar * RT priority to be separate from the value exported to 1510e05606d3SIngo Molnar * user-space. This allows kernel threads to set their 1511e05606d3SIngo Molnar * priority to a value higher than any user task. Note: 1512e05606d3SIngo Molnar * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO. 1513e05606d3SIngo Molnar */ 1514e05606d3SIngo Molnar 1515e05606d3SIngo Molnar #define MAX_USER_RT_PRIO 100 1516e05606d3SIngo Molnar #define MAX_RT_PRIO MAX_USER_RT_PRIO 1517e05606d3SIngo Molnar 1518e05606d3SIngo Molnar #define MAX_PRIO (MAX_RT_PRIO + 40) 1519e05606d3SIngo Molnar #define DEFAULT_PRIO (MAX_RT_PRIO + 20) 1520e05606d3SIngo Molnar 1521e05606d3SIngo Molnar static inline int rt_prio(int prio) 1522e05606d3SIngo Molnar { 1523e05606d3SIngo Molnar if (unlikely(prio < MAX_RT_PRIO)) 1524e05606d3SIngo Molnar return 1; 1525e05606d3SIngo Molnar return 0; 1526e05606d3SIngo Molnar } 1527e05606d3SIngo Molnar 1528e868171aSAlexey Dobriyan static inline int rt_task(struct task_struct *p) 1529e05606d3SIngo Molnar { 1530e05606d3SIngo Molnar return rt_prio(p->prio); 1531e05606d3SIngo Molnar } 1532e05606d3SIngo Molnar 1533e868171aSAlexey Dobriyan static inline struct pid *task_pid(struct task_struct *task) 153422c935f4SEric W. Biederman { 153522c935f4SEric W. Biederman return task->pids[PIDTYPE_PID].pid; 153622c935f4SEric W. Biederman } 153722c935f4SEric W. Biederman 1538e868171aSAlexey Dobriyan static inline struct pid *task_tgid(struct task_struct *task) 153922c935f4SEric W. Biederman { 154022c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PID].pid; 154122c935f4SEric W. Biederman } 154222c935f4SEric W. Biederman 15436dda81f4SOleg Nesterov /* 15446dda81f4SOleg Nesterov * Without tasklist or rcu lock it is not safe to dereference 15456dda81f4SOleg Nesterov * the result of task_pgrp/task_session even if task == current, 15466dda81f4SOleg Nesterov * we can race with another thread doing sys_setsid/sys_setpgid. 15476dda81f4SOleg Nesterov */ 1548e868171aSAlexey Dobriyan static inline struct pid *task_pgrp(struct task_struct *task) 154922c935f4SEric W. Biederman { 155022c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PGID].pid; 155122c935f4SEric W. Biederman } 155222c935f4SEric W. Biederman 1553e868171aSAlexey Dobriyan static inline struct pid *task_session(struct task_struct *task) 155422c935f4SEric W. Biederman { 155522c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_SID].pid; 155622c935f4SEric W. Biederman } 155722c935f4SEric W. Biederman 15587af57294SPavel Emelyanov struct pid_namespace; 15597af57294SPavel Emelyanov 15607af57294SPavel Emelyanov /* 15617af57294SPavel Emelyanov * the helpers to get the task's different pids as they are seen 15627af57294SPavel Emelyanov * from various namespaces 15637af57294SPavel Emelyanov * 15647af57294SPavel Emelyanov * task_xid_nr() : global id, i.e. the id seen from the init namespace; 156544c4e1b2SEric W. Biederman * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of 156644c4e1b2SEric W. Biederman * current. 15677af57294SPavel Emelyanov * task_xid_nr_ns() : id seen from the ns specified; 15687af57294SPavel Emelyanov * 15697af57294SPavel Emelyanov * set_task_vxid() : assigns a virtual id to a task; 15707af57294SPavel Emelyanov * 15717af57294SPavel Emelyanov * see also pid_nr() etc in include/linux/pid.h 15727af57294SPavel Emelyanov */ 157352ee2dfdSOleg Nesterov pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, 157452ee2dfdSOleg Nesterov struct pid_namespace *ns); 15757af57294SPavel Emelyanov 1576e868171aSAlexey Dobriyan static inline pid_t task_pid_nr(struct task_struct *tsk) 15777af57294SPavel Emelyanov { 15787af57294SPavel Emelyanov return tsk->pid; 15797af57294SPavel Emelyanov } 15807af57294SPavel Emelyanov 158152ee2dfdSOleg Nesterov static inline pid_t task_pid_nr_ns(struct task_struct *tsk, 158252ee2dfdSOleg Nesterov struct pid_namespace *ns) 158352ee2dfdSOleg Nesterov { 158452ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns); 158552ee2dfdSOleg Nesterov } 15867af57294SPavel Emelyanov 15877af57294SPavel Emelyanov static inline pid_t task_pid_vnr(struct task_struct *tsk) 15887af57294SPavel Emelyanov { 158952ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL); 15907af57294SPavel Emelyanov } 15917af57294SPavel Emelyanov 15927af57294SPavel Emelyanov 1593e868171aSAlexey Dobriyan static inline pid_t task_tgid_nr(struct task_struct *tsk) 15947af57294SPavel Emelyanov { 15957af57294SPavel Emelyanov return tsk->tgid; 15967af57294SPavel Emelyanov } 15977af57294SPavel Emelyanov 15982f2a3a46SPavel Emelyanov pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); 15997af57294SPavel Emelyanov 16007af57294SPavel Emelyanov static inline pid_t task_tgid_vnr(struct task_struct *tsk) 16017af57294SPavel Emelyanov { 16027af57294SPavel Emelyanov return pid_vnr(task_tgid(tsk)); 16037af57294SPavel Emelyanov } 16047af57294SPavel Emelyanov 16057af57294SPavel Emelyanov 160652ee2dfdSOleg Nesterov static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, 160752ee2dfdSOleg Nesterov struct pid_namespace *ns) 16087af57294SPavel Emelyanov { 160952ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns); 16107af57294SPavel Emelyanov } 16117af57294SPavel Emelyanov 16127af57294SPavel Emelyanov static inline pid_t task_pgrp_vnr(struct task_struct *tsk) 16137af57294SPavel Emelyanov { 161452ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL); 16157af57294SPavel Emelyanov } 16167af57294SPavel Emelyanov 16177af57294SPavel Emelyanov 161852ee2dfdSOleg Nesterov static inline pid_t task_session_nr_ns(struct task_struct *tsk, 161952ee2dfdSOleg Nesterov struct pid_namespace *ns) 16207af57294SPavel Emelyanov { 162152ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns); 16227af57294SPavel Emelyanov } 16237af57294SPavel Emelyanov 16247af57294SPavel Emelyanov static inline pid_t task_session_vnr(struct task_struct *tsk) 16257af57294SPavel Emelyanov { 162652ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL); 16277af57294SPavel Emelyanov } 16287af57294SPavel Emelyanov 16291b0f7ffdSOleg Nesterov /* obsolete, do not use */ 16301b0f7ffdSOleg Nesterov static inline pid_t task_pgrp_nr(struct task_struct *tsk) 16311b0f7ffdSOleg Nesterov { 16321b0f7ffdSOleg Nesterov return task_pgrp_nr_ns(tsk, &init_pid_ns); 16331b0f7ffdSOleg Nesterov } 16347af57294SPavel Emelyanov 16351da177e4SLinus Torvalds /** 16361da177e4SLinus Torvalds * pid_alive - check that a task structure is not stale 16371da177e4SLinus Torvalds * @p: Task structure to be checked. 16381da177e4SLinus Torvalds * 16391da177e4SLinus Torvalds * Test if a process is not yet dead (at most zombie state) 16401da177e4SLinus Torvalds * If pid_alive fails, then pointers within the task structure 16411da177e4SLinus Torvalds * can be stale and must not be dereferenced. 16421da177e4SLinus Torvalds */ 1643e868171aSAlexey Dobriyan static inline int pid_alive(struct task_struct *p) 16441da177e4SLinus Torvalds { 164592476d7fSEric W. Biederman return p->pids[PIDTYPE_PID].pid != NULL; 16461da177e4SLinus Torvalds } 16471da177e4SLinus Torvalds 1648f400e198SSukadev Bhattiprolu /** 1649b460cbc5SSerge E. Hallyn * is_global_init - check if a task structure is init 16503260259fSHenne * @tsk: Task structure to be checked. 16513260259fSHenne * 16523260259fSHenne * Check if a task structure is the first user space task the kernel created. 1653f400e198SSukadev Bhattiprolu */ 1654e868171aSAlexey Dobriyan static inline int is_global_init(struct task_struct *tsk) 1655b461cc03SPavel Emelyanov { 1656b461cc03SPavel Emelyanov return tsk->pid == 1; 1657b461cc03SPavel Emelyanov } 1658b460cbc5SSerge E. Hallyn 1659b460cbc5SSerge E. Hallyn /* 1660b460cbc5SSerge E. Hallyn * is_container_init: 1661b460cbc5SSerge E. Hallyn * check whether in the task is init in its own pid namespace. 1662b460cbc5SSerge E. Hallyn */ 1663b461cc03SPavel Emelyanov extern int is_container_init(struct task_struct *tsk); 1664f400e198SSukadev Bhattiprolu 16659ec52099SCedric Le Goater extern struct pid *cad_pid; 16669ec52099SCedric Le Goater 16671da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk); 16681da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0) 1669e56d0903SIngo Molnar 1670158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t); 1671e56d0903SIngo Molnar 1672e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t) 1673e56d0903SIngo Molnar { 1674e56d0903SIngo Molnar if (atomic_dec_and_test(&t->usage)) 16758c7904a0SEric W. Biederman __put_task_struct(t); 1676e56d0903SIngo Molnar } 16771da177e4SLinus Torvalds 1678d180c5bcSHidetoshi Seto extern void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st); 16790cf55e1eSHidetoshi Seto extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st); 168049048622SBalbir Singh 16811da177e4SLinus Torvalds /* 16821da177e4SLinus Torvalds * Per process flags 16831da177e4SLinus Torvalds */ 16841da177e4SLinus Torvalds #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */ 16851da177e4SLinus Torvalds /* Not implemented yet, only for 486*/ 16861da177e4SLinus Torvalds #define PF_STARTING 0x00000002 /* being created */ 16871da177e4SLinus Torvalds #define PF_EXITING 0x00000004 /* getting shut down */ 1688778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ 168994886b84SLaurent Vivier #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ 169021aa9af0STejun Heo #define PF_WQ_WORKER 0x00000020 /* I'm a workqueue worker */ 16911da177e4SLinus Torvalds #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ 16924db96cf0SAndi Kleen #define PF_MCE_PROCESS 0x00000080 /* process policy on mce errors */ 16931da177e4SLinus Torvalds #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ 16941da177e4SLinus Torvalds #define PF_DUMPCORE 0x00000200 /* dumped core */ 16951da177e4SLinus Torvalds #define PF_SIGNALED 0x00000400 /* killed by a signal */ 16961da177e4SLinus Torvalds #define PF_MEMALLOC 0x00000800 /* Allocating memory */ 16971da177e4SLinus Torvalds #define PF_FLUSHER 0x00001000 /* responsible for disk writeback */ 16981da177e4SLinus Torvalds #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */ 16996301cb95SThomas Gleixner #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */ 17001da177e4SLinus Torvalds #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */ 17011da177e4SLinus Torvalds #define PF_FROZEN 0x00010000 /* frozen for system suspend */ 17021da177e4SLinus Torvalds #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ 17031da177e4SLinus Torvalds #define PF_KSWAPD 0x00040000 /* I am kswapd */ 170435451beeSHugh Dickins #define PF_OOM_ORIGIN 0x00080000 /* Allocating much memory to others */ 17051da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */ 1706246bb0b1SOleg Nesterov #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ 1707b31dc66aSJens Axboe #define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */ 1708b31dc66aSJens Axboe #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ 1709b31dc66aSJens Axboe #define PF_SPREAD_PAGE 0x01000000 /* Spread page cache over cpuset */ 1710b31dc66aSJens Axboe #define PF_SPREAD_SLAB 0x02000000 /* Spread some slab caches over cpuset */ 17119985b0baSDavid Rientjes #define PF_THREAD_BOUND 0x04000000 /* Thread bound to specific cpu */ 17124db96cf0SAndi Kleen #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */ 1713c61afb18SPaul Jackson #define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */ 171461a87122SThomas Gleixner #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */ 1715ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezeable */ 1716ebb12db5SRafael J. Wysocki #define PF_FREEZER_NOSIG 0x80000000 /* Freezer won't send signals to it */ 17171da177e4SLinus Torvalds 17181da177e4SLinus Torvalds /* 17191da177e4SLinus Torvalds * Only the _current_ task can read/write to tsk->flags, but other 17201da177e4SLinus Torvalds * tasks can access tsk->flags in readonly mode for example 17211da177e4SLinus Torvalds * with tsk_used_math (like during threaded core dumping). 17221da177e4SLinus Torvalds * There is however an exception to this rule during ptrace 17231da177e4SLinus Torvalds * or during fork: the ptracer task is allowed to write to the 17241da177e4SLinus Torvalds * child->flags of its traced child (same goes for fork, the parent 17251da177e4SLinus Torvalds * can write to the child->flags), because we're guaranteed the 17261da177e4SLinus Torvalds * child is not running and in turn not changing child->flags 17271da177e4SLinus Torvalds * at the same time the parent does it. 17281da177e4SLinus Torvalds */ 17291da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0) 17301da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0) 17311da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current) 17321da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current) 17331da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \ 17341da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0) 17351da177e4SLinus Torvalds #define conditional_used_math(condition) \ 17361da177e4SLinus Torvalds conditional_stopped_child_used_math(condition, current) 17371da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \ 17381da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0) 17391da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */ 17401da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH) 17411da177e4SLinus Torvalds #define used_math() tsk_used_math(current) 17421da177e4SLinus Torvalds 1743f41d911fSPaul E. McKenney #ifdef CONFIG_TREE_PREEMPT_RCU 1744f41d911fSPaul E. McKenney 1745f41d911fSPaul E. McKenney #define RCU_READ_UNLOCK_BLOCKED (1 << 0) /* blocked while in RCU read-side. */ 1746f41d911fSPaul E. McKenney #define RCU_READ_UNLOCK_NEED_QS (1 << 1) /* RCU core needs CPU response. */ 1747f41d911fSPaul E. McKenney 1748f41d911fSPaul E. McKenney static inline void rcu_copy_process(struct task_struct *p) 1749f41d911fSPaul E. McKenney { 1750f41d911fSPaul E. McKenney p->rcu_read_lock_nesting = 0; 1751f41d911fSPaul E. McKenney p->rcu_read_unlock_special = 0; 1752dd5d19baSPaul E. McKenney p->rcu_blocked_node = NULL; 1753f41d911fSPaul E. McKenney INIT_LIST_HEAD(&p->rcu_node_entry); 1754f41d911fSPaul E. McKenney } 1755f41d911fSPaul E. McKenney 1756f41d911fSPaul E. McKenney #else 1757f41d911fSPaul E. McKenney 1758f41d911fSPaul E. McKenney static inline void rcu_copy_process(struct task_struct *p) 1759f41d911fSPaul E. McKenney { 1760f41d911fSPaul E. McKenney } 1761f41d911fSPaul E. McKenney 1762f41d911fSPaul E. McKenney #endif 1763f41d911fSPaul E. McKenney 17641da177e4SLinus Torvalds #ifdef CONFIG_SMP 1765cd8ba7cdSMike Travis extern int set_cpus_allowed_ptr(struct task_struct *p, 176696f874e2SRusty Russell const struct cpumask *new_mask); 17671da177e4SLinus Torvalds #else 1768cd8ba7cdSMike Travis static inline int set_cpus_allowed_ptr(struct task_struct *p, 176996f874e2SRusty Russell const struct cpumask *new_mask) 17701da177e4SLinus Torvalds { 177196f874e2SRusty Russell if (!cpumask_test_cpu(0, new_mask)) 17721da177e4SLinus Torvalds return -EINVAL; 17731da177e4SLinus Torvalds return 0; 17741da177e4SLinus Torvalds } 17751da177e4SLinus Torvalds #endif 1776e0ad9556SRusty Russell 1777e0ad9556SRusty Russell #ifndef CONFIG_CPUMASK_OFFSTACK 1778cd8ba7cdSMike Travis static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask) 1779cd8ba7cdSMike Travis { 1780cd8ba7cdSMike Travis return set_cpus_allowed_ptr(p, &new_mask); 1781cd8ba7cdSMike Travis } 1782e0ad9556SRusty Russell #endif 17831da177e4SLinus Torvalds 1784b342501cSIngo Molnar /* 1785c676329aSPeter Zijlstra * Do not use outside of architecture code which knows its limitations. 1786c676329aSPeter Zijlstra * 1787c676329aSPeter Zijlstra * sched_clock() has no promise of monotonicity or bounded drift between 1788c676329aSPeter Zijlstra * CPUs, use (which you should not) requires disabling IRQs. 1789c676329aSPeter Zijlstra * 1790c676329aSPeter Zijlstra * Please use one of the three interfaces below. 1791b342501cSIngo Molnar */ 17921bbfa6f2SMike Frysinger extern unsigned long long notrace sched_clock(void); 1793c676329aSPeter Zijlstra /* 1794c676329aSPeter Zijlstra * See the comment in kernel/sched_clock.c 1795c676329aSPeter Zijlstra */ 1796c676329aSPeter Zijlstra extern u64 cpu_clock(int cpu); 1797c676329aSPeter Zijlstra extern u64 local_clock(void); 1798c676329aSPeter Zijlstra extern u64 sched_clock_cpu(int cpu); 1799c676329aSPeter Zijlstra 1800e436d800SIngo Molnar 1801c1955a3dSPeter Zijlstra extern void sched_clock_init(void); 1802c1955a3dSPeter Zijlstra 18033e51f33fSPeter Zijlstra #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK 18043e51f33fSPeter Zijlstra static inline void sched_clock_tick(void) 18053e51f33fSPeter Zijlstra { 18063e51f33fSPeter Zijlstra } 18073e51f33fSPeter Zijlstra 18083e51f33fSPeter Zijlstra static inline void sched_clock_idle_sleep_event(void) 18093e51f33fSPeter Zijlstra { 18103e51f33fSPeter Zijlstra } 18113e51f33fSPeter Zijlstra 18123e51f33fSPeter Zijlstra static inline void sched_clock_idle_wakeup_event(u64 delta_ns) 18133e51f33fSPeter Zijlstra { 18143e51f33fSPeter Zijlstra } 18153e51f33fSPeter Zijlstra #else 1816c676329aSPeter Zijlstra /* 1817c676329aSPeter Zijlstra * Architectures can set this to 1 if they have specified 1818c676329aSPeter Zijlstra * CONFIG_HAVE_UNSTABLE_SCHED_CLOCK in their arch Kconfig, 1819c676329aSPeter Zijlstra * but then during bootup it turns out that sched_clock() 1820c676329aSPeter Zijlstra * is reliable after all: 1821c676329aSPeter Zijlstra */ 1822c676329aSPeter Zijlstra extern int sched_clock_stable; 1823c676329aSPeter Zijlstra 18243e51f33fSPeter Zijlstra extern void sched_clock_tick(void); 18253e51f33fSPeter Zijlstra extern void sched_clock_idle_sleep_event(void); 18263e51f33fSPeter Zijlstra extern void sched_clock_idle_wakeup_event(u64 delta_ns); 18273e51f33fSPeter Zijlstra #endif 18283e51f33fSPeter Zijlstra 182936c8b586SIngo Molnar extern unsigned long long 183041b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task); 1831f06febc9SFrank Mayhar extern unsigned long long thread_group_sched_runtime(struct task_struct *task); 18321da177e4SLinus Torvalds 18331da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */ 18341da177e4SLinus Torvalds #ifdef CONFIG_SMP 18351da177e4SLinus Torvalds extern void sched_exec(void); 18361da177e4SLinus Torvalds #else 18371da177e4SLinus Torvalds #define sched_exec() {} 18381da177e4SLinus Torvalds #endif 18391da177e4SLinus Torvalds 18402aa44d05SIngo Molnar extern void sched_clock_idle_sleep_event(void); 18412aa44d05SIngo Molnar extern void sched_clock_idle_wakeup_event(u64 delta_ns); 1842bb29ab26SIngo Molnar 18431da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU 18446a1bdc1bSOleg Nesterov extern void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p); 18451da177e4SLinus Torvalds extern void idle_task_exit(void); 18461da177e4SLinus Torvalds #else 18471da177e4SLinus Torvalds static inline void idle_task_exit(void) {} 18481da177e4SLinus Torvalds #endif 18491da177e4SLinus Torvalds 18501da177e4SLinus Torvalds extern void sched_idle_next(void); 1851b29739f9SIngo Molnar 185206d8308cSThomas Gleixner #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP) 185306d8308cSThomas Gleixner extern void wake_up_idle_cpu(int cpu); 185406d8308cSThomas Gleixner #else 185506d8308cSThomas Gleixner static inline void wake_up_idle_cpu(int cpu) { } 185606d8308cSThomas Gleixner #endif 185706d8308cSThomas Gleixner 185821805085SPeter Zijlstra extern unsigned int sysctl_sched_latency; 1859b2be5e96SPeter Zijlstra extern unsigned int sysctl_sched_min_granularity; 1860bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity; 186147fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_ratelimit; 186247fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_thresh; 1863bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first; 18641983a922SChristian Ehrhardt 18651983a922SChristian Ehrhardt enum sched_tunable_scaling { 18661983a922SChristian Ehrhardt SCHED_TUNABLESCALING_NONE, 18671983a922SChristian Ehrhardt SCHED_TUNABLESCALING_LOG, 18681983a922SChristian Ehrhardt SCHED_TUNABLESCALING_LINEAR, 18691983a922SChristian Ehrhardt SCHED_TUNABLESCALING_END, 18701983a922SChristian Ehrhardt }; 18711983a922SChristian Ehrhardt extern enum sched_tunable_scaling sysctl_sched_tunable_scaling; 18721983a922SChristian Ehrhardt 18732bba22c5SMike Galbraith #ifdef CONFIG_SCHED_DEBUG 1874da84d961SIngo Molnar extern unsigned int sysctl_sched_migration_cost; 1875b82d9fddSPeter Zijlstra extern unsigned int sysctl_sched_nr_migrate; 1876e9e9250bSPeter Zijlstra extern unsigned int sysctl_sched_time_avg; 1877cd1bb94bSArun R Bharadwaj extern unsigned int sysctl_timer_migration; 1878b2be5e96SPeter Zijlstra 18791983a922SChristian Ehrhardt int sched_proc_update_handler(struct ctl_table *table, int write, 18808d65af78SAlexey Dobriyan void __user *buffer, size_t *length, 1881b2be5e96SPeter Zijlstra loff_t *ppos); 18822bd8e6d4SIngo Molnar #endif 1883eea08f32SArun R Bharadwaj #ifdef CONFIG_SCHED_DEBUG 1884eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void) 1885eea08f32SArun R Bharadwaj { 1886eea08f32SArun R Bharadwaj return sysctl_timer_migration; 1887eea08f32SArun R Bharadwaj } 1888eea08f32SArun R Bharadwaj #else 1889eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void) 1890eea08f32SArun R Bharadwaj { 1891eea08f32SArun R Bharadwaj return 1; 1892eea08f32SArun R Bharadwaj } 1893eea08f32SArun R Bharadwaj #endif 18949f0c1e56SPeter Zijlstra extern unsigned int sysctl_sched_rt_period; 18959f0c1e56SPeter Zijlstra extern int sysctl_sched_rt_runtime; 18962bd8e6d4SIngo Molnar 1897d0b27fa7SPeter Zijlstra int sched_rt_handler(struct ctl_table *table, int write, 18988d65af78SAlexey Dobriyan void __user *buffer, size_t *lenp, 1899d0b27fa7SPeter Zijlstra loff_t *ppos); 1900d0b27fa7SPeter Zijlstra 19012bd8e6d4SIngo Molnar extern unsigned int sysctl_sched_compat_yield; 1902bf0f6f24SIngo Molnar 1903b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES 190436c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p); 190536c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio); 190636c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p); 1907b29739f9SIngo Molnar #else 1908e868171aSAlexey Dobriyan static inline int rt_mutex_getprio(struct task_struct *p) 1909b29739f9SIngo Molnar { 1910b29739f9SIngo Molnar return p->normal_prio; 1911b29739f9SIngo Molnar } 191295e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p) do { } while (0) 1913b29739f9SIngo Molnar #endif 1914b29739f9SIngo Molnar 191536c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice); 191636c8b586SIngo Molnar extern int task_prio(const struct task_struct *p); 191736c8b586SIngo Molnar extern int task_nice(const struct task_struct *p); 191836c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice); 191936c8b586SIngo Molnar extern int task_curr(const struct task_struct *p); 19201da177e4SLinus Torvalds extern int idle_cpu(int cpu); 19211da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *); 1922961ccdddSRusty Russell extern int sched_setscheduler_nocheck(struct task_struct *, int, 1923961ccdddSRusty Russell struct sched_param *); 192436c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu); 192536c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu); 192636c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p); 19271da177e4SLinus Torvalds 19281da177e4SLinus Torvalds void yield(void); 19291da177e4SLinus Torvalds 19301da177e4SLinus Torvalds /* 19311da177e4SLinus Torvalds * The default (Linux) execution domain. 19321da177e4SLinus Torvalds */ 19331da177e4SLinus Torvalds extern struct exec_domain default_exec_domain; 19341da177e4SLinus Torvalds 19351da177e4SLinus Torvalds union thread_union { 19361da177e4SLinus Torvalds struct thread_info thread_info; 19371da177e4SLinus Torvalds unsigned long stack[THREAD_SIZE/sizeof(long)]; 19381da177e4SLinus Torvalds }; 19391da177e4SLinus Torvalds 19401da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END 19411da177e4SLinus Torvalds static inline int kstack_end(void *addr) 19421da177e4SLinus Torvalds { 19431da177e4SLinus Torvalds /* Reliable end of stack detection: 19441da177e4SLinus Torvalds * Some APM bios versions misalign the stack 19451da177e4SLinus Torvalds */ 19461da177e4SLinus Torvalds return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*))); 19471da177e4SLinus Torvalds } 19481da177e4SLinus Torvalds #endif 19491da177e4SLinus Torvalds 19501da177e4SLinus Torvalds extern union thread_union init_thread_union; 19511da177e4SLinus Torvalds extern struct task_struct init_task; 19521da177e4SLinus Torvalds 19531da177e4SLinus Torvalds extern struct mm_struct init_mm; 19541da177e4SLinus Torvalds 1955198fe21bSPavel Emelyanov extern struct pid_namespace init_pid_ns; 1956198fe21bSPavel Emelyanov 1957198fe21bSPavel Emelyanov /* 1958198fe21bSPavel Emelyanov * find a task by one of its numerical ids 1959198fe21bSPavel Emelyanov * 1960198fe21bSPavel Emelyanov * find_task_by_pid_ns(): 1961198fe21bSPavel Emelyanov * finds a task by its pid in the specified namespace 1962228ebcbeSPavel Emelyanov * find_task_by_vpid(): 1963228ebcbeSPavel Emelyanov * finds a task by its virtual pid 1964198fe21bSPavel Emelyanov * 1965e49859e7SPavel Emelyanov * see also find_vpid() etc in include/linux/pid.h 1966198fe21bSPavel Emelyanov */ 1967198fe21bSPavel Emelyanov 1968228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_vpid(pid_t nr); 1969228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid_ns(pid_t nr, 1970228ebcbeSPavel Emelyanov struct pid_namespace *ns); 1971198fe21bSPavel Emelyanov 19728520d7c7SOleg Nesterov extern void __set_special_pids(struct pid *pid); 19731da177e4SLinus Torvalds 19741da177e4SLinus Torvalds /* per-UID process charging. */ 1975acce292cSCedric Le Goater extern struct user_struct * alloc_uid(struct user_namespace *, uid_t); 19761da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u) 19771da177e4SLinus Torvalds { 19781da177e4SLinus Torvalds atomic_inc(&u->__count); 19791da177e4SLinus Torvalds return u; 19801da177e4SLinus Torvalds } 19811da177e4SLinus Torvalds extern void free_uid(struct user_struct *); 198228f300d2SPavel Emelyanov extern void release_uids(struct user_namespace *ns); 19831da177e4SLinus Torvalds 19841da177e4SLinus Torvalds #include <asm/current.h> 19851da177e4SLinus Torvalds 19863171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks); 19871da177e4SLinus Torvalds 1988b3c97528SHarvey Harrison extern int wake_up_state(struct task_struct *tsk, unsigned int state); 1989b3c97528SHarvey Harrison extern int wake_up_process(struct task_struct *tsk); 1990b3c97528SHarvey Harrison extern void wake_up_new_task(struct task_struct *tsk, 1991b3c97528SHarvey Harrison unsigned long clone_flags); 19921da177e4SLinus Torvalds #ifdef CONFIG_SMP 19931da177e4SLinus Torvalds extern void kick_process(struct task_struct *tsk); 19941da177e4SLinus Torvalds #else 19951da177e4SLinus Torvalds static inline void kick_process(struct task_struct *tsk) { } 19961da177e4SLinus Torvalds #endif 1997ad46c2c4SIngo Molnar extern void sched_fork(struct task_struct *p, int clone_flags); 1998ad46c2c4SIngo Molnar extern void sched_dead(struct task_struct *p); 19991da177e4SLinus Torvalds 20001da177e4SLinus Torvalds extern void proc_caches_init(void); 20011da177e4SLinus Torvalds extern void flush_signals(struct task_struct *); 20023bcac026SDavid Howells extern void __flush_signals(struct task_struct *); 200310ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *); 20041da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default); 20051da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info); 20061da177e4SLinus Torvalds 20071da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) 20081da177e4SLinus Torvalds { 20091da177e4SLinus Torvalds unsigned long flags; 20101da177e4SLinus Torvalds int ret; 20111da177e4SLinus Torvalds 20121da177e4SLinus Torvalds spin_lock_irqsave(&tsk->sighand->siglock, flags); 20131da177e4SLinus Torvalds ret = dequeue_signal(tsk, mask, info); 20141da177e4SLinus Torvalds spin_unlock_irqrestore(&tsk->sighand->siglock, flags); 20151da177e4SLinus Torvalds 20161da177e4SLinus Torvalds return ret; 20171da177e4SLinus Torvalds } 20181da177e4SLinus Torvalds 20191da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv, 20201da177e4SLinus Torvalds sigset_t *mask); 20211da177e4SLinus Torvalds extern void unblock_all_signals(void); 20221da177e4SLinus Torvalds extern void release_task(struct task_struct * p); 20231da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *); 20241da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *); 20251da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *); 2026c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp); 2027c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid); 20282425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32); 2029c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv); 2030c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv); 2031c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t); 20322b2a1ff6SRoland McGrath extern int do_notify_parent(struct task_struct *, int); 2033a7f0765eSOleg Nesterov extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent); 20341da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *); 20351da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int); 203609faef11SOleg Nesterov extern int zap_other_threads(struct task_struct *p); 20371da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void); 20381da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *); 2039ac5c2153SOleg Nesterov extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group); 20409ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); 20411da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long); 20421da177e4SLinus Torvalds 20439ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv) 20449ec52099SCedric Le Goater { 20459ec52099SCedric Le Goater return kill_pid(cad_pid, sig, priv); 20469ec52099SCedric Le Goater } 20479ec52099SCedric Le Goater 20481da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info. */ 20491da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0) 20501da177e4SLinus Torvalds #define SEND_SIG_PRIV ((struct siginfo *) 1) 20511da177e4SLinus Torvalds #define SEND_SIG_FORCED ((struct siginfo *) 2) 20521da177e4SLinus Torvalds 20532a855dd0SSebastian Andrzej Siewior /* 20542a855dd0SSebastian Andrzej Siewior * True if we are on the alternate signal stack. 20552a855dd0SSebastian Andrzej Siewior */ 20561da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp) 20571da177e4SLinus Torvalds { 20582a855dd0SSebastian Andrzej Siewior #ifdef CONFIG_STACK_GROWSUP 20592a855dd0SSebastian Andrzej Siewior return sp >= current->sas_ss_sp && 20602a855dd0SSebastian Andrzej Siewior sp - current->sas_ss_sp < current->sas_ss_size; 20612a855dd0SSebastian Andrzej Siewior #else 20622a855dd0SSebastian Andrzej Siewior return sp > current->sas_ss_sp && 20632a855dd0SSebastian Andrzej Siewior sp - current->sas_ss_sp <= current->sas_ss_size; 20642a855dd0SSebastian Andrzej Siewior #endif 20651da177e4SLinus Torvalds } 20661da177e4SLinus Torvalds 20671da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp) 20681da177e4SLinus Torvalds { 20691da177e4SLinus Torvalds return (current->sas_ss_size == 0 ? SS_DISABLE 20701da177e4SLinus Torvalds : on_sig_stack(sp) ? SS_ONSTACK : 0); 20711da177e4SLinus Torvalds } 20721da177e4SLinus Torvalds 20731da177e4SLinus Torvalds /* 20741da177e4SLinus Torvalds * Routines for handling mm_structs 20751da177e4SLinus Torvalds */ 20761da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void); 20771da177e4SLinus Torvalds 20781da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */ 2079b3c97528SHarvey Harrison extern void __mmdrop(struct mm_struct *); 20801da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm) 20811da177e4SLinus Torvalds { 20826fb43d7bSIngo Molnar if (unlikely(atomic_dec_and_test(&mm->mm_count))) 20831da177e4SLinus Torvalds __mmdrop(mm); 20841da177e4SLinus Torvalds } 20851da177e4SLinus Torvalds 20861da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */ 20871da177e4SLinus Torvalds extern void mmput(struct mm_struct *); 20881da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */ 20891da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task); 20901da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */ 20911da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *); 2092402b0862SCarsten Otte /* Allocate a new mm structure and copy contents from tsk->mm */ 2093402b0862SCarsten Otte extern struct mm_struct *dup_mm(struct task_struct *tsk); 20941da177e4SLinus Torvalds 20956f2c55b8SAlexey Dobriyan extern int copy_thread(unsigned long, unsigned long, unsigned long, 20966f2c55b8SAlexey Dobriyan struct task_struct *, struct pt_regs *); 20971da177e4SLinus Torvalds extern void flush_thread(void); 20981da177e4SLinus Torvalds extern void exit_thread(void); 20991da177e4SLinus Torvalds 21001da177e4SLinus Torvalds extern void exit_files(struct task_struct *); 2101a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *); 2102cbaffba1SOleg Nesterov 21031da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *); 2104cbaffba1SOleg Nesterov extern void flush_itimer_signals(void); 21051da177e4SLinus Torvalds 21061da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int); 21071da177e4SLinus Torvalds 21081da177e4SLinus Torvalds extern void daemonize(const char *, ...); 21091da177e4SLinus Torvalds extern int allow_signal(int); 21101da177e4SLinus Torvalds extern int disallow_signal(int); 21111da177e4SLinus Torvalds 2112d7627467SDavid Howells extern int do_execve(const char *, 2113d7627467SDavid Howells const char __user * const __user *, 2114d7627467SDavid Howells const char __user * const __user *, struct pt_regs *); 21151da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *); 211636c8b586SIngo Molnar struct task_struct *fork_idle(int); 21171da177e4SLinus Torvalds 21181da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from); 211959714d65SAndrew Morton extern char *get_task_comm(char *to, struct task_struct *tsk); 21201da177e4SLinus Torvalds 21211da177e4SLinus Torvalds #ifdef CONFIG_SMP 212285ba2d86SRoland McGrath extern unsigned long wait_task_inactive(struct task_struct *, long match_state); 21231da177e4SLinus Torvalds #else 212485ba2d86SRoland McGrath static inline unsigned long wait_task_inactive(struct task_struct *p, 212585ba2d86SRoland McGrath long match_state) 212685ba2d86SRoland McGrath { 212785ba2d86SRoland McGrath return 1; 212885ba2d86SRoland McGrath } 21291da177e4SLinus Torvalds #endif 21301da177e4SLinus Torvalds 213105725f7eSJiri Pirko #define next_task(p) \ 213205725f7eSJiri Pirko list_entry_rcu((p)->tasks.next, struct task_struct, tasks) 21331da177e4SLinus Torvalds 21341da177e4SLinus Torvalds #define for_each_process(p) \ 21351da177e4SLinus Torvalds for (p = &init_task ; (p = next_task(p)) != &init_task ; ) 21361da177e4SLinus Torvalds 21375bb459bbSOleg Nesterov extern bool current_is_single_threaded(void); 2138d84f4f99SDavid Howells 21391da177e4SLinus Torvalds /* 21401da177e4SLinus Torvalds * Careful: do_each_thread/while_each_thread is a double loop so 21411da177e4SLinus Torvalds * 'break' will not work as expected - use goto instead. 21421da177e4SLinus Torvalds */ 21431da177e4SLinus Torvalds #define do_each_thread(g, t) \ 21441da177e4SLinus Torvalds for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do 21451da177e4SLinus Torvalds 21461da177e4SLinus Torvalds #define while_each_thread(g, t) \ 21471da177e4SLinus Torvalds while ((t = next_thread(t)) != g) 21481da177e4SLinus Torvalds 21497e49827cSOleg Nesterov static inline int get_nr_threads(struct task_struct *tsk) 21507e49827cSOleg Nesterov { 2151b3ac022cSOleg Nesterov return tsk->signal->nr_threads; 21527e49827cSOleg Nesterov } 21537e49827cSOleg Nesterov 2154de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */ 2155de12a787SEric W. Biederman #define thread_group_leader(p) (p == p->group_leader) 21561da177e4SLinus Torvalds 21570804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process 21580804ef4bSEric W. Biederman * to have the pid of the thread group leader without actually being 21590804ef4bSEric W. Biederman * the thread group leader. For iteration through the pids in proc 21600804ef4bSEric W. Biederman * all we care about is that we have a task with the appropriate 21610804ef4bSEric W. Biederman * pid, we don't actually care if we have the right task. 21620804ef4bSEric W. Biederman */ 2163e868171aSAlexey Dobriyan static inline int has_group_leader_pid(struct task_struct *p) 21640804ef4bSEric W. Biederman { 21650804ef4bSEric W. Biederman return p->pid == p->tgid; 21660804ef4bSEric W. Biederman } 21670804ef4bSEric W. Biederman 2168bac0abd6SPavel Emelyanov static inline 2169bac0abd6SPavel Emelyanov int same_thread_group(struct task_struct *p1, struct task_struct *p2) 2170bac0abd6SPavel Emelyanov { 2171bac0abd6SPavel Emelyanov return p1->tgid == p2->tgid; 2172bac0abd6SPavel Emelyanov } 2173bac0abd6SPavel Emelyanov 217436c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p) 217547e65328SOleg Nesterov { 217605725f7eSJiri Pirko return list_entry_rcu(p->thread_group.next, 217736c8b586SIngo Molnar struct task_struct, thread_group); 217847e65328SOleg Nesterov } 217947e65328SOleg Nesterov 2180e868171aSAlexey Dobriyan static inline int thread_group_empty(struct task_struct *p) 21811da177e4SLinus Torvalds { 218247e65328SOleg Nesterov return list_empty(&p->thread_group); 21831da177e4SLinus Torvalds } 21841da177e4SLinus Torvalds 21851da177e4SLinus Torvalds #define delay_group_leader(p) \ 21861da177e4SLinus Torvalds (thread_group_leader(p) && !thread_group_empty(p)) 21871da177e4SLinus Torvalds 218839c626aeSOleg Nesterov static inline int task_detached(struct task_struct *p) 218939c626aeSOleg Nesterov { 219039c626aeSOleg Nesterov return p->exit_signal == -1; 219139c626aeSOleg Nesterov } 219239c626aeSOleg Nesterov 21931da177e4SLinus Torvalds /* 2194260ea101SEric W. Biederman * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring 219522e2c507SJens Axboe * subscriptions and synchronises with wait4(). Also used in procfs. Also 2196ddbcc7e8SPaul Menage * pins the final release of task.io_context. Also protects ->cpuset and 2197ddbcc7e8SPaul Menage * ->cgroup.subsys[]. 21981da177e4SLinus Torvalds * 21991da177e4SLinus Torvalds * Nests both inside and outside of read_lock(&tasklist_lock). 22001da177e4SLinus Torvalds * It must not be nested with write_lock_irq(&tasklist_lock), 22011da177e4SLinus Torvalds * neither inside nor outside. 22021da177e4SLinus Torvalds */ 22031da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p) 22041da177e4SLinus Torvalds { 22051da177e4SLinus Torvalds spin_lock(&p->alloc_lock); 22061da177e4SLinus Torvalds } 22071da177e4SLinus Torvalds 22081da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p) 22091da177e4SLinus Torvalds { 22101da177e4SLinus Torvalds spin_unlock(&p->alloc_lock); 22111da177e4SLinus Torvalds } 22121da177e4SLinus Torvalds 2213f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk, 2214f63ee72eSOleg Nesterov unsigned long *flags); 2215f63ee72eSOleg Nesterov 2216f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk, 2217f63ee72eSOleg Nesterov unsigned long *flags) 2218f63ee72eSOleg Nesterov { 2219f63ee72eSOleg Nesterov spin_unlock_irqrestore(&tsk->sighand->siglock, *flags); 2220f63ee72eSOleg Nesterov } 2221f63ee72eSOleg Nesterov 2222f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS 2223f037360fSAl Viro 2224f7e4217bSRoman Zippel #define task_thread_info(task) ((struct thread_info *)(task)->stack) 2225f7e4217bSRoman Zippel #define task_stack_page(task) ((task)->stack) 2226a1261f54SAl Viro 222710ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org) 222810ebffdeSAl Viro { 222910ebffdeSAl Viro *task_thread_info(p) = *task_thread_info(org); 223010ebffdeSAl Viro task_thread_info(p)->task = p; 223110ebffdeSAl Viro } 223210ebffdeSAl Viro 223310ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p) 223410ebffdeSAl Viro { 2235f7e4217bSRoman Zippel return (unsigned long *)(task_thread_info(p) + 1); 223610ebffdeSAl Viro } 223710ebffdeSAl Viro 2238f037360fSAl Viro #endif 2239f037360fSAl Viro 22408b05c7e6SFUJITA Tomonori static inline int object_is_on_stack(void *obj) 22418b05c7e6SFUJITA Tomonori { 22428b05c7e6SFUJITA Tomonori void *stack = task_stack_page(current); 22438b05c7e6SFUJITA Tomonori 22448b05c7e6SFUJITA Tomonori return (obj >= stack) && (obj < (stack + THREAD_SIZE)); 22458b05c7e6SFUJITA Tomonori } 22468b05c7e6SFUJITA Tomonori 22478c9843e5SBenjamin Herrenschmidt extern void thread_info_cache_init(void); 22488c9843e5SBenjamin Herrenschmidt 22497c9f8861SEric Sandeen #ifdef CONFIG_DEBUG_STACK_USAGE 22507c9f8861SEric Sandeen static inline unsigned long stack_not_used(struct task_struct *p) 22517c9f8861SEric Sandeen { 22527c9f8861SEric Sandeen unsigned long *n = end_of_stack(p); 22537c9f8861SEric Sandeen 22547c9f8861SEric Sandeen do { /* Skip over canary */ 22557c9f8861SEric Sandeen n++; 22567c9f8861SEric Sandeen } while (!*n); 22577c9f8861SEric Sandeen 22587c9f8861SEric Sandeen return (unsigned long)n - (unsigned long)end_of_stack(p); 22597c9f8861SEric Sandeen } 22607c9f8861SEric Sandeen #endif 22617c9f8861SEric Sandeen 22621da177e4SLinus Torvalds /* set thread flags in other task's structures 22631da177e4SLinus Torvalds * - see asm/thread_info.h for TIF_xxxx flags available 22641da177e4SLinus Torvalds */ 22651da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag) 22661da177e4SLinus Torvalds { 2267a1261f54SAl Viro set_ti_thread_flag(task_thread_info(tsk), flag); 22681da177e4SLinus Torvalds } 22691da177e4SLinus Torvalds 22701da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag) 22711da177e4SLinus Torvalds { 2272a1261f54SAl Viro clear_ti_thread_flag(task_thread_info(tsk), flag); 22731da177e4SLinus Torvalds } 22741da177e4SLinus Torvalds 22751da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag) 22761da177e4SLinus Torvalds { 2277a1261f54SAl Viro return test_and_set_ti_thread_flag(task_thread_info(tsk), flag); 22781da177e4SLinus Torvalds } 22791da177e4SLinus Torvalds 22801da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag) 22811da177e4SLinus Torvalds { 2282a1261f54SAl Viro return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag); 22831da177e4SLinus Torvalds } 22841da177e4SLinus Torvalds 22851da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag) 22861da177e4SLinus Torvalds { 2287a1261f54SAl Viro return test_ti_thread_flag(task_thread_info(tsk), flag); 22881da177e4SLinus Torvalds } 22891da177e4SLinus Torvalds 22901da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk) 22911da177e4SLinus Torvalds { 22921da177e4SLinus Torvalds set_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 22931da177e4SLinus Torvalds } 22941da177e4SLinus Torvalds 22951da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk) 22961da177e4SLinus Torvalds { 22971da177e4SLinus Torvalds clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 22981da177e4SLinus Torvalds } 22991da177e4SLinus Torvalds 23008ae121acSGregory Haskins static inline int test_tsk_need_resched(struct task_struct *tsk) 23018ae121acSGregory Haskins { 23028ae121acSGregory Haskins return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED)); 23038ae121acSGregory Haskins } 23048ae121acSGregory Haskins 2305690cc3ffSEric W. Biederman static inline int restart_syscall(void) 2306690cc3ffSEric W. Biederman { 2307690cc3ffSEric W. Biederman set_tsk_thread_flag(current, TIF_SIGPENDING); 2308690cc3ffSEric W. Biederman return -ERESTARTNOINTR; 2309690cc3ffSEric W. Biederman } 2310690cc3ffSEric W. Biederman 23111da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p) 23121da177e4SLinus Torvalds { 23131da177e4SLinus Torvalds return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING)); 23141da177e4SLinus Torvalds } 23151da177e4SLinus Torvalds 2316d9588725SRoland McGrath static inline int __fatal_signal_pending(struct task_struct *p) 2317d9588725SRoland McGrath { 2318d9588725SRoland McGrath return unlikely(sigismember(&p->pending.signal, SIGKILL)); 2319d9588725SRoland McGrath } 2320f776d12dSMatthew Wilcox 2321f776d12dSMatthew Wilcox static inline int fatal_signal_pending(struct task_struct *p) 2322f776d12dSMatthew Wilcox { 2323f776d12dSMatthew Wilcox return signal_pending(p) && __fatal_signal_pending(p); 2324f776d12dSMatthew Wilcox } 2325f776d12dSMatthew Wilcox 232616882c1eSOleg Nesterov static inline int signal_pending_state(long state, struct task_struct *p) 232716882c1eSOleg Nesterov { 232816882c1eSOleg Nesterov if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL))) 232916882c1eSOleg Nesterov return 0; 233016882c1eSOleg Nesterov if (!signal_pending(p)) 233116882c1eSOleg Nesterov return 0; 233216882c1eSOleg Nesterov 233316882c1eSOleg Nesterov return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p); 233416882c1eSOleg Nesterov } 233516882c1eSOleg Nesterov 23361da177e4SLinus Torvalds static inline int need_resched(void) 23371da177e4SLinus Torvalds { 23389404ef02SLinus Torvalds return unlikely(test_thread_flag(TIF_NEED_RESCHED)); 23391da177e4SLinus Torvalds } 23401da177e4SLinus Torvalds 23411da177e4SLinus Torvalds /* 23421da177e4SLinus Torvalds * cond_resched() and cond_resched_lock(): latency reduction via 23431da177e4SLinus Torvalds * explicit rescheduling in places that are safe. The return 23441da177e4SLinus Torvalds * value indicates whether a reschedule was done in fact. 23451da177e4SLinus Torvalds * cond_resched_lock() will drop the spinlock before scheduling, 23461da177e4SLinus Torvalds * cond_resched_softirq() will enable bhs before scheduling. 23471da177e4SLinus Torvalds */ 2348c3921ab7SLinus Torvalds extern int _cond_resched(void); 23496f80bd98SFrederic Weisbecker 2350613afbf8SFrederic Weisbecker #define cond_resched() ({ \ 2351613afbf8SFrederic Weisbecker __might_sleep(__FILE__, __LINE__, 0); \ 2352613afbf8SFrederic Weisbecker _cond_resched(); \ 2353613afbf8SFrederic Weisbecker }) 23546f80bd98SFrederic Weisbecker 2355613afbf8SFrederic Weisbecker extern int __cond_resched_lock(spinlock_t *lock); 2356613afbf8SFrederic Weisbecker 2357716a4234SFrederic Weisbecker #ifdef CONFIG_PREEMPT 2358716a4234SFrederic Weisbecker #define PREEMPT_LOCK_OFFSET PREEMPT_OFFSET 235902b67cc3SHerbert Xu #else 2360716a4234SFrederic Weisbecker #define PREEMPT_LOCK_OFFSET 0 236102b67cc3SHerbert Xu #endif 2362716a4234SFrederic Weisbecker 2363613afbf8SFrederic Weisbecker #define cond_resched_lock(lock) ({ \ 2364716a4234SFrederic Weisbecker __might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET); \ 2365613afbf8SFrederic Weisbecker __cond_resched_lock(lock); \ 2366613afbf8SFrederic Weisbecker }) 2367613afbf8SFrederic Weisbecker 2368613afbf8SFrederic Weisbecker extern int __cond_resched_softirq(void); 2369613afbf8SFrederic Weisbecker 2370613afbf8SFrederic Weisbecker #define cond_resched_softirq() ({ \ 2371613afbf8SFrederic Weisbecker __might_sleep(__FILE__, __LINE__, SOFTIRQ_OFFSET); \ 2372613afbf8SFrederic Weisbecker __cond_resched_softirq(); \ 2373613afbf8SFrederic Weisbecker }) 23741da177e4SLinus Torvalds 23751da177e4SLinus Torvalds /* 23761da177e4SLinus Torvalds * Does a critical section need to be broken due to another 237795c354feSNick Piggin * task waiting?: (technically does not depend on CONFIG_PREEMPT, 237895c354feSNick Piggin * but a general need for low latency) 23791da177e4SLinus Torvalds */ 238095c354feSNick Piggin static inline int spin_needbreak(spinlock_t *lock) 23811da177e4SLinus Torvalds { 238295c354feSNick Piggin #ifdef CONFIG_PREEMPT 238395c354feSNick Piggin return spin_is_contended(lock); 238495c354feSNick Piggin #else 23851da177e4SLinus Torvalds return 0; 238695c354feSNick Piggin #endif 23871da177e4SLinus Torvalds } 23881da177e4SLinus Torvalds 23897bb44adeSRoland McGrath /* 2390f06febc9SFrank Mayhar * Thread group CPU time accounting. 2391f06febc9SFrank Mayhar */ 23924cd4c1b4SPeter Zijlstra void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times); 23934da94d49SPeter Zijlstra void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times); 2394f06febc9SFrank Mayhar 2395f06febc9SFrank Mayhar static inline void thread_group_cputime_init(struct signal_struct *sig) 2396f06febc9SFrank Mayhar { 23974cd4c1b4SPeter Zijlstra spin_lock_init(&sig->cputimer.lock); 2398f06febc9SFrank Mayhar } 2399f06febc9SFrank Mayhar 2400f06febc9SFrank Mayhar /* 24017bb44adeSRoland McGrath * Reevaluate whether the task has signals pending delivery. 24027bb44adeSRoland McGrath * Wake the task if so. 24037bb44adeSRoland McGrath * This is required every time the blocked sigset_t changes. 24047bb44adeSRoland McGrath * callers must hold sighand->siglock. 24057bb44adeSRoland McGrath */ 24067bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t); 24071da177e4SLinus Torvalds extern void recalc_sigpending(void); 24081da177e4SLinus Torvalds 24091da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped); 24101da177e4SLinus Torvalds 24111da177e4SLinus Torvalds /* 24121da177e4SLinus Torvalds * Wrappers for p->thread_info->cpu access. No-op on UP. 24131da177e4SLinus Torvalds */ 24141da177e4SLinus Torvalds #ifdef CONFIG_SMP 24151da177e4SLinus Torvalds 24161da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 24171da177e4SLinus Torvalds { 2418a1261f54SAl Viro return task_thread_info(p)->cpu; 24191da177e4SLinus Torvalds } 24201da177e4SLinus Torvalds 2421c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu); 24221da177e4SLinus Torvalds 24231da177e4SLinus Torvalds #else 24241da177e4SLinus Torvalds 24251da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 24261da177e4SLinus Torvalds { 24271da177e4SLinus Torvalds return 0; 24281da177e4SLinus Torvalds } 24291da177e4SLinus Torvalds 24301da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu) 24311da177e4SLinus Torvalds { 24321da177e4SLinus Torvalds } 24331da177e4SLinus Torvalds 24341da177e4SLinus Torvalds #endif /* CONFIG_SMP */ 24351da177e4SLinus Torvalds 243696f874e2SRusty Russell extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask); 243796f874e2SRusty Russell extern long sched_getaffinity(pid_t pid, struct cpumask *mask); 24385c45bf27SSiddha, Suresh B 24391da177e4SLinus Torvalds extern void normalize_rt_tasks(void); 24401da177e4SLinus Torvalds 24417c941438SDhaval Giani #ifdef CONFIG_CGROUP_SCHED 24429b5b7751SSrivatsa Vaddagiri 24434cf86d77SIngo Molnar extern struct task_group init_task_group; 24449b5b7751SSrivatsa Vaddagiri 2445ec7dc8acSDhaval Giani extern struct task_group *sched_create_group(struct task_group *parent); 24464cf86d77SIngo Molnar extern void sched_destroy_group(struct task_group *tg); 24479b5b7751SSrivatsa Vaddagiri extern void sched_move_task(struct task_struct *tsk); 2448052f1dc7SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED 24494cf86d77SIngo Molnar extern int sched_group_set_shares(struct task_group *tg, unsigned long shares); 24505cb350baSDhaval Giani extern unsigned long sched_group_shares(struct task_group *tg); 2451052f1dc7SPeter Zijlstra #endif 2452052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED 24539f0c1e56SPeter Zijlstra extern int sched_group_set_rt_runtime(struct task_group *tg, 24549f0c1e56SPeter Zijlstra long rt_runtime_us); 24559f0c1e56SPeter Zijlstra extern long sched_group_rt_runtime(struct task_group *tg); 2456d0b27fa7SPeter Zijlstra extern int sched_group_set_rt_period(struct task_group *tg, 2457d0b27fa7SPeter Zijlstra long rt_period_us); 2458d0b27fa7SPeter Zijlstra extern long sched_group_rt_period(struct task_group *tg); 245954e99124SDhaval Giani extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk); 2460052f1dc7SPeter Zijlstra #endif 24619b5b7751SSrivatsa Vaddagiri #endif 24629b5b7751SSrivatsa Vaddagiri 246354e99124SDhaval Giani extern int task_can_switch_user(struct user_struct *up, 246454e99124SDhaval Giani struct task_struct *tsk); 246554e99124SDhaval Giani 24664b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT 24674b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 24684b98d11bSAlexey Dobriyan { 2469940389b8SAndrea Righi tsk->ioac.rchar += amt; 24704b98d11bSAlexey Dobriyan } 24714b98d11bSAlexey Dobriyan 24724b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 24734b98d11bSAlexey Dobriyan { 2474940389b8SAndrea Righi tsk->ioac.wchar += amt; 24754b98d11bSAlexey Dobriyan } 24764b98d11bSAlexey Dobriyan 24774b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 24784b98d11bSAlexey Dobriyan { 2479940389b8SAndrea Righi tsk->ioac.syscr++; 24804b98d11bSAlexey Dobriyan } 24814b98d11bSAlexey Dobriyan 24824b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 24834b98d11bSAlexey Dobriyan { 2484940389b8SAndrea Righi tsk->ioac.syscw++; 24854b98d11bSAlexey Dobriyan } 24864b98d11bSAlexey Dobriyan #else 24874b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 24884b98d11bSAlexey Dobriyan { 24894b98d11bSAlexey Dobriyan } 24904b98d11bSAlexey Dobriyan 24914b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 24924b98d11bSAlexey Dobriyan { 24934b98d11bSAlexey Dobriyan } 24944b98d11bSAlexey Dobriyan 24954b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 24964b98d11bSAlexey Dobriyan { 24974b98d11bSAlexey Dobriyan } 24984b98d11bSAlexey Dobriyan 24994b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 25004b98d11bSAlexey Dobriyan { 25014b98d11bSAlexey Dobriyan } 25024b98d11bSAlexey Dobriyan #endif 25034b98d11bSAlexey Dobriyan 250482455257SDave Hansen #ifndef TASK_SIZE_OF 250582455257SDave Hansen #define TASK_SIZE_OF(tsk) TASK_SIZE 250682455257SDave Hansen #endif 250782455257SDave Hansen 25080793a61dSThomas Gleixner /* 25090793a61dSThomas Gleixner * Call the function if the target task is executing on a CPU right now: 25100793a61dSThomas Gleixner */ 25110793a61dSThomas Gleixner extern void task_oncpu_function_call(struct task_struct *p, 25120793a61dSThomas Gleixner void (*func) (void *info), void *info); 25130793a61dSThomas Gleixner 25140793a61dSThomas Gleixner 2515cf475ad2SBalbir Singh #ifdef CONFIG_MM_OWNER 2516cf475ad2SBalbir Singh extern void mm_update_next_owner(struct mm_struct *mm); 2517cf475ad2SBalbir Singh extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p); 2518cf475ad2SBalbir Singh #else 2519cf475ad2SBalbir Singh static inline void mm_update_next_owner(struct mm_struct *mm) 2520cf475ad2SBalbir Singh { 2521cf475ad2SBalbir Singh } 2522cf475ad2SBalbir Singh 2523cf475ad2SBalbir Singh static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p) 2524cf475ad2SBalbir Singh { 2525cf475ad2SBalbir Singh } 2526cf475ad2SBalbir Singh #endif /* CONFIG_MM_OWNER */ 2527cf475ad2SBalbir Singh 25283e10e716SJiri Slaby static inline unsigned long task_rlimit(const struct task_struct *tsk, 25293e10e716SJiri Slaby unsigned int limit) 25303e10e716SJiri Slaby { 25313e10e716SJiri Slaby return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_cur); 25323e10e716SJiri Slaby } 25333e10e716SJiri Slaby 25343e10e716SJiri Slaby static inline unsigned long task_rlimit_max(const struct task_struct *tsk, 25353e10e716SJiri Slaby unsigned int limit) 25363e10e716SJiri Slaby { 25373e10e716SJiri Slaby return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_max); 25383e10e716SJiri Slaby } 25393e10e716SJiri Slaby 25403e10e716SJiri Slaby static inline unsigned long rlimit(unsigned int limit) 25413e10e716SJiri Slaby { 25423e10e716SJiri Slaby return task_rlimit(current, limit); 25433e10e716SJiri Slaby } 25443e10e716SJiri Slaby 25453e10e716SJiri Slaby static inline unsigned long rlimit_max(unsigned int limit) 25463e10e716SJiri Slaby { 25473e10e716SJiri Slaby return task_rlimit_max(current, limit); 25483e10e716SJiri Slaby } 25493e10e716SJiri Slaby 25501da177e4SLinus Torvalds #endif /* __KERNEL__ */ 25511da177e4SLinus Torvalds 25521da177e4SLinus Torvalds #endif 2553