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 41b7b3c76aSDavid Woodhouse 42a3b6714eSDavid Woodhouse #ifdef __KERNEL__ 43b7b3c76aSDavid Woodhouse 44b7b3c76aSDavid Woodhouse struct sched_param { 45b7b3c76aSDavid Woodhouse int sched_priority; 46b7b3c76aSDavid Woodhouse }; 47b7b3c76aSDavid Woodhouse 481da177e4SLinus Torvalds #include <asm/param.h> /* for HZ */ 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds #include <linux/capability.h> 511da177e4SLinus Torvalds #include <linux/threads.h> 521da177e4SLinus Torvalds #include <linux/kernel.h> 531da177e4SLinus Torvalds #include <linux/types.h> 541da177e4SLinus Torvalds #include <linux/timex.h> 551da177e4SLinus Torvalds #include <linux/jiffies.h> 561da177e4SLinus Torvalds #include <linux/rbtree.h> 571da177e4SLinus Torvalds #include <linux/thread_info.h> 581da177e4SLinus Torvalds #include <linux/cpumask.h> 591da177e4SLinus Torvalds #include <linux/errno.h> 601da177e4SLinus Torvalds #include <linux/nodemask.h> 61c92ff1bdSMartin Schwidefsky #include <linux/mm_types.h> 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds #include <asm/system.h> 641da177e4SLinus Torvalds #include <asm/page.h> 651da177e4SLinus Torvalds #include <asm/ptrace.h> 661da177e4SLinus Torvalds #include <asm/cputime.h> 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds #include <linux/smp.h> 691da177e4SLinus Torvalds #include <linux/sem.h> 701da177e4SLinus Torvalds #include <linux/signal.h> 711da177e4SLinus Torvalds #include <linux/fs_struct.h> 721da177e4SLinus Torvalds #include <linux/compiler.h> 731da177e4SLinus Torvalds #include <linux/completion.h> 741da177e4SLinus Torvalds #include <linux/pid.h> 751da177e4SLinus Torvalds #include <linux/percpu.h> 761da177e4SLinus Torvalds #include <linux/topology.h> 773e26c149SPeter Zijlstra #include <linux/proportions.h> 781da177e4SLinus Torvalds #include <linux/seccomp.h> 79e56d0903SIngo Molnar #include <linux/rcupdate.h> 8023f78d4aSIngo Molnar #include <linux/rtmutex.h> 811da177e4SLinus Torvalds 82a3b6714eSDavid Woodhouse #include <linux/time.h> 83a3b6714eSDavid Woodhouse #include <linux/param.h> 84a3b6714eSDavid Woodhouse #include <linux/resource.h> 85a3b6714eSDavid Woodhouse #include <linux/timer.h> 86a3b6714eSDavid Woodhouse #include <linux/hrtimer.h> 877c3ab738SAndrew Morton #include <linux/task_io_accounting.h> 885cb350baSDhaval Giani #include <linux/kobject.h> 899745512cSArjan van de Ven #include <linux/latencytop.h> 90a3b6714eSDavid Woodhouse 91a3b6714eSDavid Woodhouse #include <asm/processor.h> 9236d57ac4SH. J. Lu 9378fb7466SPavel Emelianov struct mem_cgroup; 941da177e4SLinus Torvalds struct exec_domain; 95c87e2837SIngo Molnar struct futex_pi_state; 96286100a6SAlexey Dobriyan struct robust_list_head; 97d89d8796SNeil Brown struct bio; 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds /* 1001da177e4SLinus Torvalds * List of flags we want to share for kernel threads, 1011da177e4SLinus Torvalds * if only because they are not used by them anyway. 1021da177e4SLinus Torvalds */ 1031da177e4SLinus Torvalds #define CLONE_KERNEL (CLONE_FS | CLONE_FILES | CLONE_SIGHAND) 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds /* 1061da177e4SLinus Torvalds * These are the constant used to fake the fixed-point load-average 1071da177e4SLinus Torvalds * counting. Some notes: 1081da177e4SLinus Torvalds * - 11 bit fractions expand to 22 bits by the multiplies: this gives 1091da177e4SLinus Torvalds * a load-average precision of 10 bits integer + 11 bits fractional 1101da177e4SLinus Torvalds * - if you want to count load-averages more often, you need more 1111da177e4SLinus Torvalds * precision, or rounding will get you. With 2-second counting freq, 1121da177e4SLinus Torvalds * the EXP_n values would be 1981, 2034 and 2043 if still using only 1131da177e4SLinus Torvalds * 11 bit fractions. 1141da177e4SLinus Torvalds */ 1151da177e4SLinus Torvalds extern unsigned long avenrun[]; /* Load averages */ 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds #define FSHIFT 11 /* nr of bits of precision */ 1181da177e4SLinus Torvalds #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ 1190c2043abSLinus Torvalds #define LOAD_FREQ (5*HZ+1) /* 5 sec intervals */ 1201da177e4SLinus Torvalds #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ 1211da177e4SLinus Torvalds #define EXP_5 2014 /* 1/exp(5sec/5min) */ 1221da177e4SLinus Torvalds #define EXP_15 2037 /* 1/exp(5sec/15min) */ 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \ 1251da177e4SLinus Torvalds load *= exp; \ 1261da177e4SLinus Torvalds load += n*(FIXED_1-exp); \ 1271da177e4SLinus Torvalds load >>= FSHIFT; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds extern unsigned long total_forks; 1301da177e4SLinus Torvalds extern int nr_threads; 1311da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts); 1321da177e4SLinus Torvalds extern int nr_processes(void); 1331da177e4SLinus Torvalds extern unsigned long nr_running(void); 1341da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void); 135db1b1fefSJack Steiner extern unsigned long nr_active(void); 1361da177e4SLinus Torvalds extern unsigned long nr_iowait(void); 1371da177e4SLinus Torvalds 13843ae34cbSIngo Molnar struct seq_file; 13943ae34cbSIngo Molnar struct cfs_rq; 1404cf86d77SIngo Molnar struct task_group; 14143ae34cbSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 14243ae34cbSIngo Molnar extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m); 14343ae34cbSIngo Molnar extern void proc_sched_set_task(struct task_struct *p); 14443ae34cbSIngo Molnar extern void 1455cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq); 14643ae34cbSIngo Molnar #else 14743ae34cbSIngo Molnar static inline void 14843ae34cbSIngo Molnar proc_sched_show_task(struct task_struct *p, struct seq_file *m) 14943ae34cbSIngo Molnar { 15043ae34cbSIngo Molnar } 15143ae34cbSIngo Molnar static inline void proc_sched_set_task(struct task_struct *p) 15243ae34cbSIngo Molnar { 15343ae34cbSIngo Molnar } 15443ae34cbSIngo Molnar static inline void 1555cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) 15643ae34cbSIngo Molnar { 15743ae34cbSIngo Molnar } 15843ae34cbSIngo Molnar #endif 1591da177e4SLinus Torvalds 160690229a0SIngo Molnar extern unsigned long long time_sync_thresh; 161690229a0SIngo Molnar 1624a8342d2SLinus Torvalds /* 1634a8342d2SLinus Torvalds * Task state bitmask. NOTE! These bits are also 1644a8342d2SLinus Torvalds * encoded in fs/proc/array.c: get_task_state(). 1654a8342d2SLinus Torvalds * 1664a8342d2SLinus Torvalds * We have two separate sets of flags: task->state 1674a8342d2SLinus Torvalds * is about runnability, while task->exit_state are 1684a8342d2SLinus Torvalds * about the task exiting. Confusing, but this way 1694a8342d2SLinus Torvalds * modifying one set can't modify the other one by 1704a8342d2SLinus Torvalds * mistake. 1714a8342d2SLinus Torvalds */ 1721da177e4SLinus Torvalds #define TASK_RUNNING 0 1731da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE 1 1741da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE 2 175f021a3c2SMatthew Wilcox #define __TASK_STOPPED 4 176f021a3c2SMatthew Wilcox #define __TASK_TRACED 8 1774a8342d2SLinus Torvalds /* in tsk->exit_state */ 1784a8342d2SLinus Torvalds #define EXIT_ZOMBIE 16 1794a8342d2SLinus Torvalds #define EXIT_DEAD 32 1804a8342d2SLinus Torvalds /* in tsk->state again */ 181af927232SMike Galbraith #define TASK_DEAD 64 182f021a3c2SMatthew Wilcox #define TASK_WAKEKILL 128 183f021a3c2SMatthew Wilcox 184f021a3c2SMatthew Wilcox /* Convenience macros for the sake of set_task_state */ 185f021a3c2SMatthew Wilcox #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) 186f021a3c2SMatthew Wilcox #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) 187f021a3c2SMatthew Wilcox #define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED) 1881da177e4SLinus Torvalds 18992a1f4bcSMatthew Wilcox /* Convenience macros for the sake of wake_up */ 19092a1f4bcSMatthew Wilcox #define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE) 191f021a3c2SMatthew Wilcox #define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED) 19292a1f4bcSMatthew Wilcox 19392a1f4bcSMatthew Wilcox /* get_task_state() */ 19492a1f4bcSMatthew Wilcox #define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \ 195f021a3c2SMatthew Wilcox TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \ 196f021a3c2SMatthew Wilcox __TASK_TRACED) 19792a1f4bcSMatthew Wilcox 198f021a3c2SMatthew Wilcox #define task_is_traced(task) ((task->state & __TASK_TRACED) != 0) 199f021a3c2SMatthew Wilcox #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0) 20092a1f4bcSMatthew Wilcox #define task_is_stopped_or_traced(task) \ 201f021a3c2SMatthew Wilcox ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0) 20292a1f4bcSMatthew Wilcox #define task_contributes_to_load(task) \ 20392a1f4bcSMatthew Wilcox ((task->state & TASK_UNINTERRUPTIBLE) != 0) 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds #define __set_task_state(tsk, state_value) \ 2061da177e4SLinus Torvalds do { (tsk)->state = (state_value); } while (0) 2071da177e4SLinus Torvalds #define set_task_state(tsk, state_value) \ 2081da177e4SLinus Torvalds set_mb((tsk)->state, (state_value)) 2091da177e4SLinus Torvalds 210498d0c57SAndrew Morton /* 211498d0c57SAndrew Morton * set_current_state() includes a barrier so that the write of current->state 212498d0c57SAndrew Morton * is correctly serialised wrt the caller's subsequent test of whether to 213498d0c57SAndrew Morton * actually sleep: 214498d0c57SAndrew Morton * 215498d0c57SAndrew Morton * set_current_state(TASK_UNINTERRUPTIBLE); 216498d0c57SAndrew Morton * if (do_i_need_to_sleep()) 217498d0c57SAndrew Morton * schedule(); 218498d0c57SAndrew Morton * 219498d0c57SAndrew Morton * If the caller does not need such serialisation then use __set_current_state() 220498d0c57SAndrew Morton */ 2211da177e4SLinus Torvalds #define __set_current_state(state_value) \ 2221da177e4SLinus Torvalds do { current->state = (state_value); } while (0) 2231da177e4SLinus Torvalds #define set_current_state(state_value) \ 2241da177e4SLinus Torvalds set_mb(current->state, (state_value)) 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds /* Task command name length */ 2271da177e4SLinus Torvalds #define TASK_COMM_LEN 16 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds #include <linux/spinlock.h> 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds /* 2321da177e4SLinus Torvalds * This serializes "schedule()" and also protects 2331da177e4SLinus Torvalds * the run-queue from deletions/modifications (but 2341da177e4SLinus Torvalds * _adding_ to the beginning of the run-queue has 2351da177e4SLinus Torvalds * a separate lock). 2361da177e4SLinus Torvalds */ 2371da177e4SLinus Torvalds extern rwlock_t tasklist_lock; 2381da177e4SLinus Torvalds extern spinlock_t mmlist_lock; 2391da177e4SLinus Torvalds 24036c8b586SIngo Molnar struct task_struct; 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds extern void sched_init(void); 2431da177e4SLinus Torvalds extern void sched_init_smp(void); 2442d07b255SHarvey Harrison extern asmlinkage void schedule_tail(struct task_struct *prev); 24536c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu); 2461df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle); 2471da177e4SLinus Torvalds 248017730c1SIngo Molnar extern int runqueue_is_locked(void); 249017730c1SIngo Molnar 2501da177e4SLinus Torvalds extern cpumask_t nohz_cpu_mask; 25146cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ) 25246cb4b7cSSiddha, Suresh B extern int select_nohz_load_balancer(int cpu); 25346cb4b7cSSiddha, Suresh B #else 25446cb4b7cSSiddha, Suresh B static inline int select_nohz_load_balancer(int cpu) 25546cb4b7cSSiddha, Suresh B { 25646cb4b7cSSiddha, Suresh B return 0; 25746cb4b7cSSiddha, Suresh B } 25846cb4b7cSSiddha, Suresh B #endif 2591da177e4SLinus Torvalds 26048d5e258SPeter Zijlstra extern unsigned long rt_needs_cpu(int cpu); 26148d5e258SPeter Zijlstra 262e59e2ae2SIngo Molnar /* 26339bc89fdSIngo Molnar * Only dump TASK_* tasks. (0 for all tasks) 264e59e2ae2SIngo Molnar */ 265e59e2ae2SIngo Molnar extern void show_state_filter(unsigned long state_filter); 266e59e2ae2SIngo Molnar 267e59e2ae2SIngo Molnar static inline void show_state(void) 268e59e2ae2SIngo Molnar { 26939bc89fdSIngo Molnar show_state_filter(0); 270e59e2ae2SIngo Molnar } 271e59e2ae2SIngo Molnar 2721da177e4SLinus Torvalds extern void show_regs(struct pt_regs *); 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds /* 2751da177e4SLinus Torvalds * TASK is a pointer to the task whose backtrace we want to see (or NULL for current 2761da177e4SLinus Torvalds * task), SP is the stack pointer of the first frame that should be shown in the back 2771da177e4SLinus Torvalds * trace (or NULL if the entire call-chain of the task should be shown). 2781da177e4SLinus Torvalds */ 2791da177e4SLinus Torvalds extern void show_stack(struct task_struct *task, unsigned long *sp); 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvalds void io_schedule(void); 2821da177e4SLinus Torvalds long io_schedule_timeout(long timeout); 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds extern void cpu_init (void); 2851da177e4SLinus Torvalds extern void trap_init(void); 286fa13a5a1SPaul Mackerras extern void account_process_tick(struct task_struct *task, int user); 2871da177e4SLinus Torvalds extern void update_process_times(int user); 2881da177e4SLinus Torvalds extern void scheduler_tick(void); 2898f4d37ecSPeter Zijlstra extern void hrtick_resched(void); 2901da177e4SLinus Torvalds 29182a1fcb9SIngo Molnar extern void sched_show_task(struct task_struct *p); 29282a1fcb9SIngo Molnar 2938446f1d3SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP 2946687a97dSIngo Molnar extern void softlockup_tick(void); 2958446f1d3SIngo Molnar extern void spawn_softlockup_task(void); 2968446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void); 29704c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void); 2989c44bc03SIngo Molnar extern unsigned int softlockup_panic; 29982a1fcb9SIngo Molnar extern unsigned long sysctl_hung_task_check_count; 30082a1fcb9SIngo Molnar extern unsigned long sysctl_hung_task_timeout_secs; 30190739081SIngo Molnar extern unsigned long sysctl_hung_task_warnings; 3029383d967SDimitri Sivanich extern int softlockup_thresh; 3038446f1d3SIngo Molnar #else 3046687a97dSIngo Molnar static inline void softlockup_tick(void) 3058446f1d3SIngo Molnar { 3068446f1d3SIngo Molnar } 3078446f1d3SIngo Molnar static inline void spawn_softlockup_task(void) 3088446f1d3SIngo Molnar { 3098446f1d3SIngo Molnar } 3108446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void) 3118446f1d3SIngo Molnar { 3128446f1d3SIngo Molnar } 31304c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void) 31404c9167fSJeremy Fitzhardinge { 31504c9167fSJeremy Fitzhardinge } 3168446f1d3SIngo Molnar #endif 3178446f1d3SIngo Molnar 3188446f1d3SIngo Molnar 3191da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */ 3201da177e4SLinus Torvalds #define __sched __attribute__((__section__(".sched.text"))) 321deaf2227SIngo Molnar 322deaf2227SIngo Molnar /* Linker adds these: start and end of __sched functions */ 323deaf2227SIngo Molnar extern char __sched_text_start[], __sched_text_end[]; 324deaf2227SIngo Molnar 3251da177e4SLinus Torvalds /* Is this address in the __sched functions? */ 3261da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr); 3271da177e4SLinus Torvalds 3281da177e4SLinus Torvalds #define MAX_SCHEDULE_TIMEOUT LONG_MAX 329b3c97528SHarvey Harrison extern signed long schedule_timeout(signed long timeout); 33064ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout); 331294d5cc2SMatthew Wilcox extern signed long schedule_timeout_killable(signed long timeout); 33264ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout); 3331da177e4SLinus Torvalds asmlinkage void schedule(void); 3341da177e4SLinus Torvalds 335ab516013SSerge E. Hallyn struct nsproxy; 336acce292cSCedric Le Goater struct user_namespace; 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds /* Maximum number of active map areas.. This is a random (large) number */ 3391da177e4SLinus Torvalds #define DEFAULT_MAX_MAP_COUNT 65536 3401da177e4SLinus Torvalds 3411da177e4SLinus Torvalds extern int sysctl_max_map_count; 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvalds #include <linux/aio.h> 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds extern unsigned long 3461da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long, 3471da177e4SLinus Torvalds unsigned long, unsigned long); 3481da177e4SLinus Torvalds extern unsigned long 3491da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr, 3501da177e4SLinus Torvalds unsigned long len, unsigned long pgoff, 3511da177e4SLinus Torvalds unsigned long flags); 3521363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long); 3531363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long); 3541da177e4SLinus Torvalds 355f412ac08SHugh Dickins #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS 356f412ac08SHugh Dickins /* 357f412ac08SHugh Dickins * The mm counters are not protected by its page_table_lock, 358f412ac08SHugh Dickins * so must be incremented atomically. 359f412ac08SHugh Dickins */ 360d3cb4871SChristoph Lameter #define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value) 361d3cb4871SChristoph Lameter #define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member)) 362d3cb4871SChristoph Lameter #define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member) 363d3cb4871SChristoph Lameter #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member) 364d3cb4871SChristoph Lameter #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member) 365f412ac08SHugh Dickins 366f412ac08SHugh Dickins #else /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */ 367f412ac08SHugh Dickins /* 368f412ac08SHugh Dickins * The mm counters are protected by its page_table_lock, 369f412ac08SHugh Dickins * so can be incremented directly. 370f412ac08SHugh Dickins */ 3711da177e4SLinus Torvalds #define set_mm_counter(mm, member, value) (mm)->_##member = (value) 3721da177e4SLinus Torvalds #define get_mm_counter(mm, member) ((mm)->_##member) 3731da177e4SLinus Torvalds #define add_mm_counter(mm, member, value) (mm)->_##member += (value) 3741da177e4SLinus Torvalds #define inc_mm_counter(mm, member) (mm)->_##member++ 3751da177e4SLinus Torvalds #define dec_mm_counter(mm, member) (mm)->_##member-- 3764294621fSHugh Dickins 377f412ac08SHugh Dickins #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */ 378f412ac08SHugh Dickins 379f412ac08SHugh Dickins #define get_mm_rss(mm) \ 380f412ac08SHugh Dickins (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss)) 381365e9c87SHugh Dickins #define update_hiwater_rss(mm) do { \ 382365e9c87SHugh Dickins unsigned long _rss = get_mm_rss(mm); \ 383365e9c87SHugh Dickins if ((mm)->hiwater_rss < _rss) \ 384365e9c87SHugh Dickins (mm)->hiwater_rss = _rss; \ 385365e9c87SHugh Dickins } while (0) 386365e9c87SHugh Dickins #define update_hiwater_vm(mm) do { \ 387365e9c87SHugh Dickins if ((mm)->hiwater_vm < (mm)->total_vm) \ 388365e9c87SHugh Dickins (mm)->hiwater_vm = (mm)->total_vm; \ 389365e9c87SHugh Dickins } while (0) 390365e9c87SHugh Dickins 3916c5d5238SKawai, Hidehiro extern void set_dumpable(struct mm_struct *mm, int value); 3926c5d5238SKawai, Hidehiro extern int get_dumpable(struct mm_struct *mm); 3936c5d5238SKawai, Hidehiro 3946c5d5238SKawai, Hidehiro /* mm flags */ 3953cb4a0bbSKawai, Hidehiro /* dumpable bits */ 3966c5d5238SKawai, Hidehiro #define MMF_DUMPABLE 0 /* core dump is permitted */ 3976c5d5238SKawai, Hidehiro #define MMF_DUMP_SECURELY 1 /* core file is readable only by root */ 3983cb4a0bbSKawai, Hidehiro #define MMF_DUMPABLE_BITS 2 3993cb4a0bbSKawai, Hidehiro 4003cb4a0bbSKawai, Hidehiro /* coredump filter bits */ 4013cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_PRIVATE 2 4023cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_SHARED 3 4033cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_PRIVATE 4 4043cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_SHARED 5 40582df3973SRoland McGrath #define MMF_DUMP_ELF_HEADERS 6 4063cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS 40782df3973SRoland McGrath #define MMF_DUMP_FILTER_BITS 5 4083cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_MASK \ 4093cb4a0bbSKawai, Hidehiro (((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT) 4103cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_DEFAULT \ 4113cb4a0bbSKawai, Hidehiro ((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED)) 4126c5d5238SKawai, Hidehiro 4131da177e4SLinus Torvalds struct sighand_struct { 4141da177e4SLinus Torvalds atomic_t count; 4151da177e4SLinus Torvalds struct k_sigaction action[_NSIG]; 4161da177e4SLinus Torvalds spinlock_t siglock; 417b8fceee1SDavide Libenzi wait_queue_head_t signalfd_wqh; 4181da177e4SLinus Torvalds }; 4191da177e4SLinus Torvalds 4200e464814SKaiGai Kohei struct pacct_struct { 421f6ec29a4SKaiGai Kohei int ac_flag; 422f6ec29a4SKaiGai Kohei long ac_exitcode; 4230e464814SKaiGai Kohei unsigned long ac_mem; 42477787bfbSKaiGai Kohei cputime_t ac_utime, ac_stime; 42577787bfbSKaiGai Kohei unsigned long ac_minflt, ac_majflt; 4260e464814SKaiGai Kohei }; 4270e464814SKaiGai Kohei 4281da177e4SLinus Torvalds /* 4291da177e4SLinus Torvalds * NOTE! "signal_struct" does not have it's own 4301da177e4SLinus Torvalds * locking, because a shared signal_struct always 4311da177e4SLinus Torvalds * implies a shared sighand_struct, so locking 4321da177e4SLinus Torvalds * sighand_struct is always a proper superset of 4331da177e4SLinus Torvalds * the locking of signal_struct. 4341da177e4SLinus Torvalds */ 4351da177e4SLinus Torvalds struct signal_struct { 4361da177e4SLinus Torvalds atomic_t count; 4371da177e4SLinus Torvalds atomic_t live; 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds wait_queue_head_t wait_chldexit; /* for wait4() */ 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds /* current thread group signal load-balancing target: */ 44236c8b586SIngo Molnar struct task_struct *curr_target; 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvalds /* shared signal handling: */ 4451da177e4SLinus Torvalds struct sigpending shared_pending; 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds /* thread group exit support */ 4481da177e4SLinus Torvalds int group_exit_code; 4491da177e4SLinus Torvalds /* overloaded: 4501da177e4SLinus Torvalds * - notify group_exit_task when ->count is equal to notify_count 4511da177e4SLinus Torvalds * - everyone except group_exit_task is stopped during signal delivery 4521da177e4SLinus Torvalds * of fatal signals, group_exit_task processes the signal. 4531da177e4SLinus Torvalds */ 4541da177e4SLinus Torvalds struct task_struct *group_exit_task; 4551da177e4SLinus Torvalds int notify_count; 4561da177e4SLinus Torvalds 4571da177e4SLinus Torvalds /* thread group stop support, overloads group_exit_code too */ 4581da177e4SLinus Torvalds int group_stop_count; 4591da177e4SLinus Torvalds unsigned int flags; /* see SIGNAL_* flags below */ 4601da177e4SLinus Torvalds 4611da177e4SLinus Torvalds /* POSIX.1b Interval Timers */ 4621da177e4SLinus Torvalds struct list_head posix_timers; 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds /* ITIMER_REAL timer for the process */ 4652ff678b8SThomas Gleixner struct hrtimer real_timer; 466fea9d175SOleg Nesterov struct pid *leader_pid; 4672ff678b8SThomas Gleixner ktime_t it_real_incr; 4681da177e4SLinus Torvalds 4691da177e4SLinus Torvalds /* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */ 4701da177e4SLinus Torvalds cputime_t it_prof_expires, it_virt_expires; 4711da177e4SLinus Torvalds cputime_t it_prof_incr, it_virt_incr; 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds /* job control IDs */ 4749a2e7057SPavel Emelyanov 4759a2e7057SPavel Emelyanov /* 4769a2e7057SPavel Emelyanov * pgrp and session fields are deprecated. 4779a2e7057SPavel Emelyanov * use the task_session_Xnr and task_pgrp_Xnr routines below 4789a2e7057SPavel Emelyanov */ 4799a2e7057SPavel Emelyanov 4809a2e7057SPavel Emelyanov union { 4819a2e7057SPavel Emelyanov pid_t pgrp __deprecated; 4829a2e7057SPavel Emelyanov pid_t __pgrp; 4839a2e7057SPavel Emelyanov }; 4849a2e7057SPavel Emelyanov 485ab521dc0SEric W. Biederman struct pid *tty_old_pgrp; 4861ec320afSCedric Le Goater 4871ec320afSCedric Le Goater union { 4881ec320afSCedric Le Goater pid_t session __deprecated; 4891ec320afSCedric Le Goater pid_t __session; 4901ec320afSCedric Le Goater }; 4911ec320afSCedric Le Goater 4921da177e4SLinus Torvalds /* boolean value for session group leader */ 4931da177e4SLinus Torvalds int leader; 4941da177e4SLinus Torvalds 4951da177e4SLinus Torvalds struct tty_struct *tty; /* NULL if no tty */ 4961da177e4SLinus Torvalds 4971da177e4SLinus Torvalds /* 4981da177e4SLinus Torvalds * Cumulative resource counters for dead threads in the group, 4991da177e4SLinus Torvalds * and for reaped dead child processes forked by this group. 5001da177e4SLinus Torvalds * Live threads maintain their own counters and add to these 5011da177e4SLinus Torvalds * in __exit_signal, except for the group leader. 5021da177e4SLinus Torvalds */ 5031da177e4SLinus Torvalds cputime_t utime, stime, cutime, cstime; 5049ac52315SLaurent Vivier cputime_t gtime; 5059ac52315SLaurent Vivier cputime_t cgtime; 5061da177e4SLinus Torvalds unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; 5071da177e4SLinus Torvalds unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; 5086eaeeabaSEric Dumazet unsigned long inblock, oublock, cinblock, coublock; 5091da177e4SLinus Torvalds 5101da177e4SLinus Torvalds /* 5111da177e4SLinus Torvalds * Cumulative ns of scheduled CPU time for dead threads in the 5121da177e4SLinus Torvalds * group, not including a zombie group leader. (This only differs 5131da177e4SLinus Torvalds * from jiffies_to_ns(utime + stime) if sched_clock uses something 5141da177e4SLinus Torvalds * other than jiffies.) 5151da177e4SLinus Torvalds */ 51641b86e9cSIngo Molnar unsigned long long sum_sched_runtime; 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds /* 5191da177e4SLinus Torvalds * We don't bother to synchronize most readers of this at all, 5201da177e4SLinus Torvalds * because there is no reader checking a limit that actually needs 5211da177e4SLinus Torvalds * to get both rlim_cur and rlim_max atomically, and either one 5221da177e4SLinus Torvalds * alone is a single word that can safely be read normally. 5231da177e4SLinus Torvalds * getrlimit/setrlimit use task_lock(current->group_leader) to 5241da177e4SLinus Torvalds * protect this instead of the siglock, because they really 5251da177e4SLinus Torvalds * have no need to disable irqs. 5261da177e4SLinus Torvalds */ 5271da177e4SLinus Torvalds struct rlimit rlim[RLIM_NLIMITS]; 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds struct list_head cpu_timers[3]; 5301da177e4SLinus Torvalds 5311da177e4SLinus Torvalds /* keep the process-shared keyrings here so that they do the right 5321da177e4SLinus Torvalds * thing in threads created with CLONE_THREAD */ 5331da177e4SLinus Torvalds #ifdef CONFIG_KEYS 5341da177e4SLinus Torvalds struct key *session_keyring; /* keyring inherited over fork */ 5351da177e4SLinus Torvalds struct key *process_keyring; /* keyring private to this process */ 5361da177e4SLinus Torvalds #endif 5370e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT 5380e464814SKaiGai Kohei struct pacct_struct pacct; /* per-process accounting information */ 5390e464814SKaiGai Kohei #endif 540ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS 541ad4ecbcbSShailabh Nagar struct taskstats *stats; 542ad4ecbcbSShailabh Nagar #endif 543522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT 544522ed776SMiloslav Trmac unsigned audit_tty; 545522ed776SMiloslav Trmac struct tty_audit_buf *tty_audit_buf; 546522ed776SMiloslav Trmac #endif 5471da177e4SLinus Torvalds }; 5481da177e4SLinus Torvalds 5494866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */ 5504866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW 5514866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW 5524866cde0SNick Piggin #endif 5534866cde0SNick Piggin 5541da177e4SLinus Torvalds /* 5551da177e4SLinus Torvalds * Bits in flags field of signal_struct. 5561da177e4SLinus Torvalds */ 5571da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */ 5581da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED 0x00000002 /* stop signal dequeued */ 5591da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */ 5601da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */ 561e4420551SOleg Nesterov /* 562e4420551SOleg Nesterov * Pending notifications to parent. 563e4420551SOleg Nesterov */ 564e4420551SOleg Nesterov #define SIGNAL_CLD_STOPPED 0x00000010 565e4420551SOleg Nesterov #define SIGNAL_CLD_CONTINUED 0x00000020 566e4420551SOleg Nesterov #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED) 5671da177e4SLinus Torvalds 568fae5fa44SOleg Nesterov #define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */ 569fae5fa44SOleg Nesterov 570ed5d2cacSOleg Nesterov /* If true, all threads except ->group_exit_task have pending SIGKILL */ 571ed5d2cacSOleg Nesterov static inline int signal_group_exit(const struct signal_struct *sig) 572ed5d2cacSOleg Nesterov { 573ed5d2cacSOleg Nesterov return (sig->flags & SIGNAL_GROUP_EXIT) || 574ed5d2cacSOleg Nesterov (sig->group_exit_task != NULL); 575ed5d2cacSOleg Nesterov } 576ed5d2cacSOleg Nesterov 5771da177e4SLinus Torvalds /* 5781da177e4SLinus Torvalds * Some day this will be a full-fledged user tracking system.. 5791da177e4SLinus Torvalds */ 5801da177e4SLinus Torvalds struct user_struct { 5811da177e4SLinus Torvalds atomic_t __count; /* reference count */ 5821da177e4SLinus Torvalds atomic_t processes; /* How many processes does this user have? */ 5831da177e4SLinus Torvalds atomic_t files; /* How many open files does this user have? */ 5841da177e4SLinus Torvalds atomic_t sigpending; /* How many pending signals does this user have? */ 5852d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 5860eeca283SRobert Love atomic_t inotify_watches; /* How many inotify watches does this user have? */ 5870eeca283SRobert Love atomic_t inotify_devs; /* How many inotify devs does this user have opened? */ 5880eeca283SRobert Love #endif 589970a8645SAlexey Dobriyan #ifdef CONFIG_POSIX_MQUEUE 5901da177e4SLinus Torvalds /* protected by mq_lock */ 5911da177e4SLinus Torvalds unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */ 592970a8645SAlexey Dobriyan #endif 5931da177e4SLinus Torvalds unsigned long locked_shm; /* How many pages of mlocked shm ? */ 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds #ifdef CONFIG_KEYS 5961da177e4SLinus Torvalds struct key *uid_keyring; /* UID specific keyring */ 5971da177e4SLinus Torvalds struct key *session_keyring; /* UID's default session keyring */ 5981da177e4SLinus Torvalds #endif 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds /* Hash table maintenance information */ 601735de223SPavel Emelyanov struct hlist_node uidhash_node; 6021da177e4SLinus Torvalds uid_t uid; 60324e377a8SSrivatsa Vaddagiri 604052f1dc7SPeter Zijlstra #ifdef CONFIG_USER_SCHED 6054cf86d77SIngo Molnar struct task_group *tg; 606b1a8c172SDhaval Giani #ifdef CONFIG_SYSFS 607eb41d946SKay Sievers struct kobject kobj; 6085cb350baSDhaval Giani struct work_struct work; 60924e377a8SSrivatsa Vaddagiri #endif 610b1a8c172SDhaval Giani #endif 6111da177e4SLinus Torvalds }; 6121da177e4SLinus Torvalds 613eb41d946SKay Sievers extern int uids_sysfs_init(void); 6145cb350baSDhaval Giani 6151da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t); 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds extern struct user_struct root_user; 6181da177e4SLinus Torvalds #define INIT_USER (&root_user) 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds struct backing_dev_info; 6211da177e4SLinus Torvalds struct reclaim_state; 6221da177e4SLinus Torvalds 62352f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 6241da177e4SLinus Torvalds struct sched_info { 6251da177e4SLinus Torvalds /* cumulative counters */ 6262d72376bSIngo Molnar unsigned long pcount; /* # of times run on this cpu */ 627172ba844SBalbir Singh unsigned long long cpu_time, /* time spent on the cpu */ 628172ba844SBalbir Singh run_delay; /* time spent waiting on a runqueue */ 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds /* timestamps */ 631172ba844SBalbir Singh unsigned long long last_arrival,/* when we last ran on a cpu */ 6321da177e4SLinus Torvalds last_queued; /* when we were last queued to run */ 633b8efb561SIngo Molnar #ifdef CONFIG_SCHEDSTATS 634b8efb561SIngo Molnar /* BKL stats */ 635480b9434SKen Chen unsigned int bkl_count; 636b8efb561SIngo Molnar #endif 6371da177e4SLinus Torvalds }; 63852f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */ 6391da177e4SLinus Torvalds 64052f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS 64115ad7cdcSHelge Deller extern const struct file_operations proc_schedstat_operations; 64252f17b6cSChandra Seetharaman #endif /* CONFIG_SCHEDSTATS */ 6431da177e4SLinus Torvalds 644ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 645ca74e92bSShailabh Nagar struct task_delay_info { 646ca74e92bSShailabh Nagar spinlock_t lock; 647ca74e92bSShailabh Nagar unsigned int flags; /* Private per-task flags */ 648ca74e92bSShailabh Nagar 649ca74e92bSShailabh Nagar /* For each stat XXX, add following, aligned appropriately 650ca74e92bSShailabh Nagar * 651ca74e92bSShailabh Nagar * struct timespec XXX_start, XXX_end; 652ca74e92bSShailabh Nagar * u64 XXX_delay; 653ca74e92bSShailabh Nagar * u32 XXX_count; 654ca74e92bSShailabh Nagar * 655ca74e92bSShailabh Nagar * Atomicity of updates to XXX_delay, XXX_count protected by 656ca74e92bSShailabh Nagar * single lock above (split into XXX_lock if contention is an issue). 657ca74e92bSShailabh Nagar */ 6580ff92245SShailabh Nagar 6590ff92245SShailabh Nagar /* 6600ff92245SShailabh Nagar * XXX_count is incremented on every XXX operation, the delay 6610ff92245SShailabh Nagar * associated with the operation is added to XXX_delay. 6620ff92245SShailabh Nagar * XXX_delay contains the accumulated delay time in nanoseconds. 6630ff92245SShailabh Nagar */ 6640ff92245SShailabh Nagar struct timespec blkio_start, blkio_end; /* Shared by blkio, swapin */ 6650ff92245SShailabh Nagar u64 blkio_delay; /* wait for sync block io completion */ 6660ff92245SShailabh Nagar u64 swapin_delay; /* wait for swapin block io completion */ 6670ff92245SShailabh Nagar u32 blkio_count; /* total count of the number of sync block */ 6680ff92245SShailabh Nagar /* io operations performed */ 6690ff92245SShailabh Nagar u32 swapin_count; /* total count of the number of swapin block */ 6700ff92245SShailabh Nagar /* io operations performed */ 671ca74e92bSShailabh Nagar }; 67252f17b6cSChandra Seetharaman #endif /* CONFIG_TASK_DELAY_ACCT */ 67352f17b6cSChandra Seetharaman 67452f17b6cSChandra Seetharaman static inline int sched_info_on(void) 67552f17b6cSChandra Seetharaman { 67652f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS 67752f17b6cSChandra Seetharaman return 1; 67852f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT) 67952f17b6cSChandra Seetharaman extern int delayacct_on; 68052f17b6cSChandra Seetharaman return delayacct_on; 68152f17b6cSChandra Seetharaman #else 68252f17b6cSChandra Seetharaman return 0; 683ca74e92bSShailabh Nagar #endif 68452f17b6cSChandra Seetharaman } 685ca74e92bSShailabh Nagar 686d15bcfdbSIngo Molnar enum cpu_idle_type { 687d15bcfdbSIngo Molnar CPU_IDLE, 688d15bcfdbSIngo Molnar CPU_NOT_IDLE, 689d15bcfdbSIngo Molnar CPU_NEWLY_IDLE, 690d15bcfdbSIngo Molnar CPU_MAX_IDLE_TYPES 6911da177e4SLinus Torvalds }; 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds /* 6941da177e4SLinus Torvalds * sched-domains (multiprocessor balancing) declarations: 6951da177e4SLinus Torvalds */ 6969aa7b369SIngo Molnar 6979aa7b369SIngo Molnar /* 6989aa7b369SIngo Molnar * Increase resolution of nice-level calculations: 6999aa7b369SIngo Molnar */ 7009aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT 10 7019aa7b369SIngo Molnar #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT) 7029aa7b369SIngo Molnar 703f8700df7SSuresh Siddha #define SCHED_LOAD_SCALE_FUZZ SCHED_LOAD_SCALE 7041da177e4SLinus Torvalds 7052dd73a4fSPeter Williams #ifdef CONFIG_SMP 7061da177e4SLinus Torvalds #define SD_LOAD_BALANCE 1 /* Do load balancing on this domain. */ 7071da177e4SLinus Torvalds #define SD_BALANCE_NEWIDLE 2 /* Balance when about to become idle */ 7081da177e4SLinus Torvalds #define SD_BALANCE_EXEC 4 /* Balance on exec */ 709147cbb4bSNick Piggin #define SD_BALANCE_FORK 8 /* Balance on fork, clone */ 710147cbb4bSNick Piggin #define SD_WAKE_IDLE 16 /* Wake to idle CPU on task wakeup */ 711147cbb4bSNick Piggin #define SD_WAKE_AFFINE 32 /* Wake task to waking CPU */ 712147cbb4bSNick Piggin #define SD_WAKE_BALANCE 64 /* Perform balancing at task wakeup */ 713147cbb4bSNick Piggin #define SD_SHARE_CPUPOWER 128 /* Domain members share cpu power */ 7145c45bf27SSiddha, Suresh B #define SD_POWERSAVINGS_BALANCE 256 /* Balance for power savings */ 71589c4710eSSiddha, Suresh B #define SD_SHARE_PKG_RESOURCES 512 /* Domain members share cpu pkg resources */ 71608c183f3SChristoph Lameter #define SD_SERIALIZE 1024 /* Only a single load balancing instance */ 7171d3504fcSHidetoshi Seto #define SD_WAKE_IDLE_FAR 2048 /* Gain latency sacrificing cache hit */ 7185c45bf27SSiddha, Suresh B 71989c4710eSSiddha, Suresh B #define BALANCE_FOR_MC_POWER \ 72089c4710eSSiddha, Suresh B (sched_smt_power_savings ? SD_POWERSAVINGS_BALANCE : 0) 72189c4710eSSiddha, Suresh B 72289c4710eSSiddha, Suresh B #define BALANCE_FOR_PKG_POWER \ 72389c4710eSSiddha, Suresh B ((sched_mc_power_savings || sched_smt_power_savings) ? \ 72489c4710eSSiddha, Suresh B SD_POWERSAVINGS_BALANCE : 0) 72589c4710eSSiddha, Suresh B 72689c4710eSSiddha, Suresh B #define test_sd_parent(sd, flag) ((sd->parent && \ 72789c4710eSSiddha, Suresh B (sd->parent->flags & flag)) ? 1 : 0) 7285c45bf27SSiddha, Suresh B 7291da177e4SLinus Torvalds 7301da177e4SLinus Torvalds struct sched_group { 7311da177e4SLinus Torvalds struct sched_group *next; /* Must be a circular list */ 7321da177e4SLinus Torvalds cpumask_t cpumask; 7331da177e4SLinus Torvalds 7341da177e4SLinus Torvalds /* 7351da177e4SLinus Torvalds * CPU power of this group, SCHED_LOAD_SCALE being max power for a 7361da177e4SLinus Torvalds * single CPU. This is read only (except for setup, hotplug CPU). 7375517d86bSEric Dumazet * Note : Never change cpu_power without recompute its reciprocal 7381da177e4SLinus Torvalds */ 7395517d86bSEric Dumazet unsigned int __cpu_power; 7405517d86bSEric Dumazet /* 7415517d86bSEric Dumazet * reciprocal value of cpu_power to avoid expensive divides 7425517d86bSEric Dumazet * (see include/linux/reciprocal_div.h) 7435517d86bSEric Dumazet */ 7445517d86bSEric Dumazet u32 reciprocal_cpu_power; 7451da177e4SLinus Torvalds }; 7461da177e4SLinus Torvalds 7471d3504fcSHidetoshi Seto enum sched_domain_level { 7481d3504fcSHidetoshi Seto SD_LV_NONE = 0, 7491d3504fcSHidetoshi Seto SD_LV_SIBLING, 7501d3504fcSHidetoshi Seto SD_LV_MC, 7511d3504fcSHidetoshi Seto SD_LV_CPU, 7521d3504fcSHidetoshi Seto SD_LV_NODE, 7531d3504fcSHidetoshi Seto SD_LV_ALLNODES, 7541d3504fcSHidetoshi Seto SD_LV_MAX 7551d3504fcSHidetoshi Seto }; 7561d3504fcSHidetoshi Seto 7571d3504fcSHidetoshi Seto struct sched_domain_attr { 7581d3504fcSHidetoshi Seto int relax_domain_level; 7591d3504fcSHidetoshi Seto }; 7601d3504fcSHidetoshi Seto 7611d3504fcSHidetoshi Seto #define SD_ATTR_INIT (struct sched_domain_attr) { \ 7621d3504fcSHidetoshi Seto .relax_domain_level = -1, \ 7631d3504fcSHidetoshi Seto } 7641d3504fcSHidetoshi Seto 7651da177e4SLinus Torvalds struct sched_domain { 7661da177e4SLinus Torvalds /* These fields must be setup */ 7671da177e4SLinus Torvalds struct sched_domain *parent; /* top domain must be null terminated */ 7681a848870SSiddha, Suresh B struct sched_domain *child; /* bottom domain must be null terminated */ 7691da177e4SLinus Torvalds struct sched_group *groups; /* the balancing groups of the domain */ 7701da177e4SLinus Torvalds cpumask_t span; /* span of all CPUs in this domain */ 7711da177e4SLinus Torvalds unsigned long min_interval; /* Minimum balance interval ms */ 7721da177e4SLinus Torvalds unsigned long max_interval; /* Maximum balance interval ms */ 7731da177e4SLinus Torvalds unsigned int busy_factor; /* less balancing by factor if busy */ 7741da177e4SLinus Torvalds unsigned int imbalance_pct; /* No balance until over watermark */ 7751da177e4SLinus Torvalds unsigned int cache_nice_tries; /* Leave cache hot tasks for # tries */ 7767897986bSNick Piggin unsigned int busy_idx; 7777897986bSNick Piggin unsigned int idle_idx; 7787897986bSNick Piggin unsigned int newidle_idx; 7797897986bSNick Piggin unsigned int wake_idx; 780147cbb4bSNick Piggin unsigned int forkexec_idx; 7811da177e4SLinus Torvalds int flags; /* See SD_* */ 7821d3504fcSHidetoshi Seto enum sched_domain_level level; 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds /* Runtime fields. */ 7851da177e4SLinus Torvalds unsigned long last_balance; /* init to jiffies. units in jiffies */ 7861da177e4SLinus Torvalds unsigned int balance_interval; /* initialise to 1. units in ms. */ 7871da177e4SLinus Torvalds unsigned int nr_balance_failed; /* initialise to 0 */ 7881da177e4SLinus Torvalds 7892398f2c6SPeter Zijlstra u64 last_update; 7902398f2c6SPeter Zijlstra 7911da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS 7921da177e4SLinus Torvalds /* load_balance() stats */ 793480b9434SKen Chen unsigned int lb_count[CPU_MAX_IDLE_TYPES]; 794480b9434SKen Chen unsigned int lb_failed[CPU_MAX_IDLE_TYPES]; 795480b9434SKen Chen unsigned int lb_balanced[CPU_MAX_IDLE_TYPES]; 796480b9434SKen Chen unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES]; 797480b9434SKen Chen unsigned int lb_gained[CPU_MAX_IDLE_TYPES]; 798480b9434SKen Chen unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES]; 799480b9434SKen Chen unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES]; 800480b9434SKen Chen unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES]; 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds /* Active load balancing */ 803480b9434SKen Chen unsigned int alb_count; 804480b9434SKen Chen unsigned int alb_failed; 805480b9434SKen Chen unsigned int alb_pushed; 8061da177e4SLinus Torvalds 80768767a0aSNick Piggin /* SD_BALANCE_EXEC stats */ 808480b9434SKen Chen unsigned int sbe_count; 809480b9434SKen Chen unsigned int sbe_balanced; 810480b9434SKen Chen unsigned int sbe_pushed; 8111da177e4SLinus Torvalds 81268767a0aSNick Piggin /* SD_BALANCE_FORK stats */ 813480b9434SKen Chen unsigned int sbf_count; 814480b9434SKen Chen unsigned int sbf_balanced; 815480b9434SKen Chen unsigned int sbf_pushed; 81668767a0aSNick Piggin 8171da177e4SLinus Torvalds /* try_to_wake_up() stats */ 818480b9434SKen Chen unsigned int ttwu_wake_remote; 819480b9434SKen Chen unsigned int ttwu_move_affine; 820480b9434SKen Chen unsigned int ttwu_move_balance; 8211da177e4SLinus Torvalds #endif 8221da177e4SLinus Torvalds }; 8231da177e4SLinus Torvalds 8241d3504fcSHidetoshi Seto extern void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, 8251d3504fcSHidetoshi Seto struct sched_domain_attr *dattr_new); 8269aefd0abSHeiko Carstens extern int arch_reinit_sched_domains(void); 827029190c5SPaul Jackson 8281b427c15SIngo Molnar #else /* CONFIG_SMP */ 8291b427c15SIngo Molnar 8301b427c15SIngo Molnar struct sched_domain_attr; 8311b427c15SIngo Molnar 8321b427c15SIngo Molnar static inline void 8331b427c15SIngo Molnar partition_sched_domains(int ndoms_new, cpumask_t *doms_new, 8341b427c15SIngo Molnar struct sched_domain_attr *dattr_new) 8351b427c15SIngo Molnar { 8361b427c15SIngo Molnar } 8371b427c15SIngo Molnar #endif /* !CONFIG_SMP */ 8381da177e4SLinus Torvalds 8391da177e4SLinus Torvalds struct io_context; /* See blkdev.h */ 8401da177e4SLinus Torvalds #define NGROUPS_SMALL 32 8411bf47346SEric Dumazet #define NGROUPS_PER_BLOCK ((unsigned int)(PAGE_SIZE / sizeof(gid_t))) 8421da177e4SLinus Torvalds struct group_info { 8431da177e4SLinus Torvalds int ngroups; 8441da177e4SLinus Torvalds atomic_t usage; 8451da177e4SLinus Torvalds gid_t small_block[NGROUPS_SMALL]; 8461da177e4SLinus Torvalds int nblocks; 8471da177e4SLinus Torvalds gid_t *blocks[0]; 8481da177e4SLinus Torvalds }; 8491da177e4SLinus Torvalds 8501da177e4SLinus Torvalds /* 8511da177e4SLinus Torvalds * get_group_info() must be called with the owning task locked (via task_lock()) 8521da177e4SLinus Torvalds * when task != current. The reason being that the vast majority of callers are 8531da177e4SLinus Torvalds * looking at current->group_info, which can not be changed except by the 8541da177e4SLinus Torvalds * current task. Changing current->group_info requires the task lock, too. 8551da177e4SLinus Torvalds */ 8561da177e4SLinus Torvalds #define get_group_info(group_info) do { \ 8571da177e4SLinus Torvalds atomic_inc(&(group_info)->usage); \ 8581da177e4SLinus Torvalds } while (0) 8591da177e4SLinus Torvalds 8601da177e4SLinus Torvalds #define put_group_info(group_info) do { \ 8611da177e4SLinus Torvalds if (atomic_dec_and_test(&(group_info)->usage)) \ 8621da177e4SLinus Torvalds groups_free(group_info); \ 8631da177e4SLinus Torvalds } while (0) 8641da177e4SLinus Torvalds 8653e30148cSDavid Howells extern struct group_info *groups_alloc(int gidsetsize); 8663e30148cSDavid Howells extern void groups_free(struct group_info *group_info); 8673e30148cSDavid Howells extern int set_current_groups(struct group_info *group_info); 8683e30148cSDavid Howells extern int groups_search(struct group_info *group_info, gid_t grp); 8691da177e4SLinus Torvalds /* access the groups "array" with this macro */ 8701da177e4SLinus Torvalds #define GROUP_AT(gi, i) \ 8711da177e4SLinus Torvalds ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK]) 8721da177e4SLinus Torvalds 873383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK 87436c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t); 875383f2835SChen, Kenneth W #else 876383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { } 877383f2835SChen, Kenneth W #endif 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds struct audit_context; /* See audit.c */ 8801da177e4SLinus Torvalds struct mempolicy; 881b92ce558SJens Axboe struct pipe_inode_info; 8824865ecf1SSerge E. Hallyn struct uts_namespace; 8831da177e4SLinus Torvalds 88420b8a59fSIngo Molnar struct rq; 88520b8a59fSIngo Molnar struct sched_domain; 88620b8a59fSIngo Molnar 88720b8a59fSIngo Molnar struct sched_class { 8885522d5d5SIngo Molnar const struct sched_class *next; 88920b8a59fSIngo Molnar 890fd390f6aSIngo Molnar void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup); 891f02231e5SIngo Molnar void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep); 8924530d7abSDmitry Adamushko void (*yield_task) (struct rq *rq); 893e7693a36SGregory Haskins int (*select_task_rq)(struct task_struct *p, int sync); 89420b8a59fSIngo Molnar 89520b8a59fSIngo Molnar void (*check_preempt_curr) (struct rq *rq, struct task_struct *p); 89620b8a59fSIngo Molnar 897fb8d4724SIngo Molnar struct task_struct * (*pick_next_task) (struct rq *rq); 89831ee529cSIngo Molnar void (*put_prev_task) (struct rq *rq, struct task_struct *p); 89920b8a59fSIngo Molnar 900681f3e68SPeter Williams #ifdef CONFIG_SMP 90143010659SPeter Williams unsigned long (*load_balance) (struct rq *this_rq, int this_cpu, 902e1d1484fSPeter Williams struct rq *busiest, unsigned long max_load_move, 90320b8a59fSIngo Molnar struct sched_domain *sd, enum cpu_idle_type idle, 904a4ac01c3SPeter Williams int *all_pinned, int *this_best_prio); 90520b8a59fSIngo Molnar 906e1d1484fSPeter Williams int (*move_one_task) (struct rq *this_rq, int this_cpu, 907e1d1484fSPeter Williams struct rq *busiest, struct sched_domain *sd, 908e1d1484fSPeter Williams enum cpu_idle_type idle); 9099a897c5aSSteven Rostedt void (*pre_schedule) (struct rq *this_rq, struct task_struct *task); 9109a897c5aSSteven Rostedt void (*post_schedule) (struct rq *this_rq); 9119a897c5aSSteven Rostedt void (*task_wake_up) (struct rq *this_rq, struct task_struct *task); 912681f3e68SPeter Williams #endif 913e1d1484fSPeter Williams 91483b699edSSrivatsa Vaddagiri void (*set_curr_task) (struct rq *rq); 9158f4d37ecSPeter Zijlstra void (*task_tick) (struct rq *rq, struct task_struct *p, int queued); 916ee0827d8SIngo Molnar void (*task_new) (struct rq *rq, struct task_struct *p); 917cd8ba7cdSMike Travis void (*set_cpus_allowed)(struct task_struct *p, 918cd8ba7cdSMike Travis const cpumask_t *newmask); 91957d885feSGregory Haskins 9201f11eb6aSGregory Haskins void (*rq_online)(struct rq *rq); 9211f11eb6aSGregory Haskins void (*rq_offline)(struct rq *rq); 922cb469845SSteven Rostedt 923cb469845SSteven Rostedt void (*switched_from) (struct rq *this_rq, struct task_struct *task, 924cb469845SSteven Rostedt int running); 925cb469845SSteven Rostedt void (*switched_to) (struct rq *this_rq, struct task_struct *task, 926cb469845SSteven Rostedt int running); 927cb469845SSteven Rostedt void (*prio_changed) (struct rq *this_rq, struct task_struct *task, 928cb469845SSteven Rostedt int oldprio, int running); 929810b3817SPeter Zijlstra 930810b3817SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED 931810b3817SPeter Zijlstra void (*moved_group) (struct task_struct *p); 932810b3817SPeter Zijlstra #endif 93320b8a59fSIngo Molnar }; 93420b8a59fSIngo Molnar 93520b8a59fSIngo Molnar struct load_weight { 93620b8a59fSIngo Molnar unsigned long weight, inv_weight; 93720b8a59fSIngo Molnar }; 93820b8a59fSIngo Molnar 93920b8a59fSIngo Molnar /* 94020b8a59fSIngo Molnar * CFS stats for a schedulable entity (task, task-group etc) 94120b8a59fSIngo Molnar * 94220b8a59fSIngo Molnar * Current field usage histogram: 94320b8a59fSIngo Molnar * 94420b8a59fSIngo Molnar * 4 se->block_start 94520b8a59fSIngo Molnar * 4 se->run_node 94620b8a59fSIngo Molnar * 4 se->sleep_start 94720b8a59fSIngo Molnar * 6 se->load.weight 94820b8a59fSIngo Molnar */ 94920b8a59fSIngo Molnar struct sched_entity { 95020b8a59fSIngo Molnar struct load_weight load; /* for load-balancing */ 95120b8a59fSIngo Molnar struct rb_node run_node; 9524a55bd5eSPeter Zijlstra struct list_head group_node; 95320b8a59fSIngo Molnar unsigned int on_rq; 95420b8a59fSIngo Molnar 95520b8a59fSIngo Molnar u64 exec_start; 95694c18227SIngo Molnar u64 sum_exec_runtime; 957e9acbff6SIngo Molnar u64 vruntime; 958f6cf891cSIngo Molnar u64 prev_sum_exec_runtime; 95994c18227SIngo Molnar 9604ae7d5ceSIngo Molnar u64 last_wakeup; 9614ae7d5ceSIngo Molnar u64 avg_overlap; 9624ae7d5ceSIngo Molnar 96394c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS 96494c18227SIngo Molnar u64 wait_start; 96594c18227SIngo Molnar u64 wait_max; 9666d082592SArjan van de Ven u64 wait_count; 9676d082592SArjan van de Ven u64 wait_sum; 96894c18227SIngo Molnar 96994c18227SIngo Molnar u64 sleep_start; 97020b8a59fSIngo Molnar u64 sleep_max; 97194c18227SIngo Molnar s64 sum_sleep_runtime; 97294c18227SIngo Molnar 97394c18227SIngo Molnar u64 block_start; 97420b8a59fSIngo Molnar u64 block_max; 97520b8a59fSIngo Molnar u64 exec_max; 976eba1ed4bSIngo Molnar u64 slice_max; 977cc367732SIngo Molnar 978cc367732SIngo Molnar u64 nr_migrations; 979cc367732SIngo Molnar u64 nr_migrations_cold; 980cc367732SIngo Molnar u64 nr_failed_migrations_affine; 981cc367732SIngo Molnar u64 nr_failed_migrations_running; 982cc367732SIngo Molnar u64 nr_failed_migrations_hot; 983cc367732SIngo Molnar u64 nr_forced_migrations; 984cc367732SIngo Molnar u64 nr_forced2_migrations; 985cc367732SIngo Molnar 986cc367732SIngo Molnar u64 nr_wakeups; 987cc367732SIngo Molnar u64 nr_wakeups_sync; 988cc367732SIngo Molnar u64 nr_wakeups_migrate; 989cc367732SIngo Molnar u64 nr_wakeups_local; 990cc367732SIngo Molnar u64 nr_wakeups_remote; 991cc367732SIngo Molnar u64 nr_wakeups_affine; 992cc367732SIngo Molnar u64 nr_wakeups_affine_attempts; 993cc367732SIngo Molnar u64 nr_wakeups_passive; 994cc367732SIngo Molnar u64 nr_wakeups_idle; 99594c18227SIngo Molnar #endif 99694c18227SIngo Molnar 99720b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED 99820b8a59fSIngo Molnar struct sched_entity *parent; 99920b8a59fSIngo Molnar /* rq on which this entity is (to be) queued: */ 100020b8a59fSIngo Molnar struct cfs_rq *cfs_rq; 100120b8a59fSIngo Molnar /* rq "owned" by this entity/group: */ 100220b8a59fSIngo Molnar struct cfs_rq *my_q; 100320b8a59fSIngo Molnar #endif 100420b8a59fSIngo Molnar }; 100570b97a7fSIngo Molnar 1006fa717060SPeter Zijlstra struct sched_rt_entity { 1007fa717060SPeter Zijlstra struct list_head run_list; 1008fa717060SPeter Zijlstra unsigned int time_slice; 100978f2c7dbSPeter Zijlstra unsigned long timeout; 10106f505b16SPeter Zijlstra int nr_cpus_allowed; 10116f505b16SPeter Zijlstra 101258d6c2d7SPeter Zijlstra struct sched_rt_entity *back; 1013052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED 10146f505b16SPeter Zijlstra struct sched_rt_entity *parent; 10156f505b16SPeter Zijlstra /* rq on which this entity is (to be) queued: */ 10166f505b16SPeter Zijlstra struct rt_rq *rt_rq; 10176f505b16SPeter Zijlstra /* rq "owned" by this entity/group: */ 10186f505b16SPeter Zijlstra struct rt_rq *my_q; 10196f505b16SPeter Zijlstra #endif 1020fa717060SPeter Zijlstra }; 1021fa717060SPeter Zijlstra 10221da177e4SLinus Torvalds struct task_struct { 10231da177e4SLinus Torvalds volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ 1024f7e4217bSRoman Zippel void *stack; 10251da177e4SLinus Torvalds atomic_t usage; 102697dc32cdSWilliam Cohen unsigned int flags; /* per process flags, defined below */ 102797dc32cdSWilliam Cohen unsigned int ptrace; 10281da177e4SLinus Torvalds 102936772092SPaolo 'Blaisorblade' Giarrusso int lock_depth; /* BKL lock depth */ 10301da177e4SLinus Torvalds 10312dd73a4fSPeter Williams #ifdef CONFIG_SMP 10322dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW 10334866cde0SNick Piggin int oncpu; 10344866cde0SNick Piggin #endif 10352dd73a4fSPeter Williams #endif 103650e645a8SIngo Molnar 1037b29739f9SIngo Molnar int prio, static_prio, normal_prio; 1038c7aceabaSRichard Kennedy unsigned int rt_priority; 10395522d5d5SIngo Molnar const struct sched_class *sched_class; 104020b8a59fSIngo Molnar struct sched_entity se; 1041fa717060SPeter Zijlstra struct sched_rt_entity rt; 10421da177e4SLinus Torvalds 1043e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS 1044e107be36SAvi Kivity /* list of struct preempt_notifier: */ 1045e107be36SAvi Kivity struct hlist_head preempt_notifiers; 1046e107be36SAvi Kivity #endif 1047e107be36SAvi Kivity 104818796aa0SAlexey Dobriyan /* 104918796aa0SAlexey Dobriyan * fpu_counter contains the number of consecutive context switches 105018796aa0SAlexey Dobriyan * that the FPU is used. If this is over a threshold, the lazy fpu 105118796aa0SAlexey Dobriyan * saving becomes unlazy to save the trap. This is an unsigned char 105218796aa0SAlexey Dobriyan * so that after 256 times the counter wraps and the behavior turns 105318796aa0SAlexey Dobriyan * lazy again; this to deal with bursty apps that only use FPU for 105418796aa0SAlexey Dobriyan * a short time 105518796aa0SAlexey Dobriyan */ 105618796aa0SAlexey Dobriyan unsigned char fpu_counter; 105718796aa0SAlexey Dobriyan s8 oomkilladj; /* OOM kill score adjustment (bit shift). */ 10586c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE 10592056a782SJens Axboe unsigned int btrace_seq; 10606c5c9341SAlexey Dobriyan #endif 10611da177e4SLinus Torvalds 106297dc32cdSWilliam Cohen unsigned int policy; 10631da177e4SLinus Torvalds cpumask_t cpus_allowed; 10641da177e4SLinus Torvalds 1065e260be67SPaul E. McKenney #ifdef CONFIG_PREEMPT_RCU 1066e260be67SPaul E. McKenney int rcu_read_lock_nesting; 1067e260be67SPaul E. McKenney int rcu_flipctr_idx; 1068e260be67SPaul E. McKenney #endif /* #ifdef CONFIG_PREEMPT_RCU */ 1069e260be67SPaul E. McKenney 107052f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 10711da177e4SLinus Torvalds struct sched_info sched_info; 10721da177e4SLinus Torvalds #endif 10731da177e4SLinus Torvalds 10741da177e4SLinus Torvalds struct list_head tasks; 10751da177e4SLinus Torvalds 10761da177e4SLinus Torvalds struct mm_struct *mm, *active_mm; 10771da177e4SLinus Torvalds 10781da177e4SLinus Torvalds /* task state */ 10791da177e4SLinus Torvalds struct linux_binfmt *binfmt; 108097dc32cdSWilliam Cohen int exit_state; 10811da177e4SLinus Torvalds int exit_code, exit_signal; 10821da177e4SLinus Torvalds int pdeath_signal; /* The signal sent when the parent dies */ 10831da177e4SLinus Torvalds /* ??? */ 108497dc32cdSWilliam Cohen unsigned int personality; 10851da177e4SLinus Torvalds unsigned did_exec:1; 10861da177e4SLinus Torvalds pid_t pid; 10871da177e4SLinus Torvalds pid_t tgid; 10880a425405SArjan van de Ven 10890a425405SArjan van de Ven #ifdef CONFIG_CC_STACKPROTECTOR 10900a425405SArjan van de Ven /* Canary value for the -fstack-protector gcc feature */ 10910a425405SArjan van de Ven unsigned long stack_canary; 10920a425405SArjan van de Ven #endif 10931da177e4SLinus Torvalds /* 10941da177e4SLinus Torvalds * pointers to (original) parent process, youngest child, younger sibling, 10951da177e4SLinus Torvalds * older sibling, respectively. (p->father can be replaced with 1096f470021aSRoland McGrath * p->real_parent->pid) 10971da177e4SLinus Torvalds */ 1098f470021aSRoland McGrath struct task_struct *real_parent; /* real parent process */ 1099f470021aSRoland McGrath struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports */ 11001da177e4SLinus Torvalds /* 1101f470021aSRoland McGrath * children/sibling forms the list of my natural children 11021da177e4SLinus Torvalds */ 11031da177e4SLinus Torvalds struct list_head children; /* list of my children */ 11041da177e4SLinus Torvalds struct list_head sibling; /* linkage in my parent's children list */ 11051da177e4SLinus Torvalds struct task_struct *group_leader; /* threadgroup leader */ 11061da177e4SLinus Torvalds 1107f470021aSRoland McGrath /* 1108f470021aSRoland McGrath * ptraced is the list of tasks this task is using ptrace on. 1109f470021aSRoland McGrath * This includes both natural children and PTRACE_ATTACH targets. 1110f470021aSRoland McGrath * p->ptrace_entry is p's link on the p->parent->ptraced list. 1111f470021aSRoland McGrath */ 1112f470021aSRoland McGrath struct list_head ptraced; 1113f470021aSRoland McGrath struct list_head ptrace_entry; 1114f470021aSRoland McGrath 11151da177e4SLinus Torvalds /* PID/PID hash table linkage. */ 111692476d7fSEric W. Biederman struct pid_link pids[PIDTYPE_MAX]; 111747e65328SOleg Nesterov struct list_head thread_group; 11181da177e4SLinus Torvalds 11191da177e4SLinus Torvalds struct completion *vfork_done; /* for vfork() */ 11201da177e4SLinus Torvalds int __user *set_child_tid; /* CLONE_CHILD_SETTID */ 11211da177e4SLinus Torvalds int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */ 11221da177e4SLinus Torvalds 1123c66f08beSMichael Neuling cputime_t utime, stime, utimescaled, stimescaled; 11249ac52315SLaurent Vivier cputime_t gtime; 11259301899bSBalbir Singh cputime_t prev_utime, prev_stime; 11261da177e4SLinus Torvalds unsigned long nvcsw, nivcsw; /* context switch counts */ 1127924b42d5STomas Janousek struct timespec start_time; /* monotonic time */ 1128924b42d5STomas Janousek struct timespec real_start_time; /* boot based time */ 11291da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ 11301da177e4SLinus Torvalds unsigned long min_flt, maj_flt; 11311da177e4SLinus Torvalds 11321da177e4SLinus Torvalds cputime_t it_prof_expires, it_virt_expires; 11331da177e4SLinus Torvalds unsigned long long it_sched_expires; 11341da177e4SLinus Torvalds struct list_head cpu_timers[3]; 11351da177e4SLinus Torvalds 11361da177e4SLinus Torvalds /* process credentials */ 11371da177e4SLinus Torvalds uid_t uid,euid,suid,fsuid; 11381da177e4SLinus Torvalds gid_t gid,egid,sgid,fsgid; 11391da177e4SLinus Torvalds struct group_info *group_info; 11403b7391deSSerge E. Hallyn kernel_cap_t cap_effective, cap_inheritable, cap_permitted, cap_bset; 11411da177e4SLinus Torvalds struct user_struct *user; 1142c7aceabaSRichard Kennedy unsigned securebits; 11431da177e4SLinus Torvalds #ifdef CONFIG_KEYS 1144c7aceabaSRichard Kennedy unsigned char jit_keyring; /* default keyring to attach requested keys to */ 1145b5f545c8SDavid Howells struct key *request_key_auth; /* assumed request_key authority */ 11461da177e4SLinus Torvalds struct key *thread_keyring; /* keyring private to this thread */ 11471da177e4SLinus Torvalds #endif 114836772092SPaolo 'Blaisorblade' Giarrusso char comm[TASK_COMM_LEN]; /* executable name excluding path 114936772092SPaolo 'Blaisorblade' Giarrusso - access with [gs]et_task_comm (which lock 115036772092SPaolo 'Blaisorblade' Giarrusso it with task_lock()) 115136772092SPaolo 'Blaisorblade' Giarrusso - initialized normally by flush_old_exec */ 11521da177e4SLinus Torvalds /* file system info */ 11531da177e4SLinus Torvalds int link_count, total_link_count; 11543d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC 11551da177e4SLinus Torvalds /* ipc stuff */ 11561da177e4SLinus Torvalds struct sysv_sem sysvsem; 11573d5b6fccSAlexey Dobriyan #endif 115882a1fcb9SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP 115982a1fcb9SIngo Molnar /* hung task detection */ 116082a1fcb9SIngo Molnar unsigned long last_switch_timestamp; 116182a1fcb9SIngo Molnar unsigned long last_switch_count; 116282a1fcb9SIngo Molnar #endif 11631da177e4SLinus Torvalds /* CPU-specific state of this task */ 11641da177e4SLinus Torvalds struct thread_struct thread; 11651da177e4SLinus Torvalds /* filesystem information */ 11661da177e4SLinus Torvalds struct fs_struct *fs; 11671da177e4SLinus Torvalds /* open file information */ 11681da177e4SLinus Torvalds struct files_struct *files; 11691651e14eSSerge E. Hallyn /* namespaces */ 1170ab516013SSerge E. Hallyn struct nsproxy *nsproxy; 11711da177e4SLinus Torvalds /* signal handlers */ 11721da177e4SLinus Torvalds struct signal_struct *signal; 11731da177e4SLinus Torvalds struct sighand_struct *sighand; 11741da177e4SLinus Torvalds 11751da177e4SLinus Torvalds sigset_t blocked, real_blocked; 1176f3de272bSRoland McGrath sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */ 11771da177e4SLinus Torvalds struct sigpending pending; 11781da177e4SLinus Torvalds 11791da177e4SLinus Torvalds unsigned long sas_ss_sp; 11801da177e4SLinus Torvalds size_t sas_ss_size; 11811da177e4SLinus Torvalds int (*notifier)(void *priv); 11821da177e4SLinus Torvalds void *notifier_data; 11831da177e4SLinus Torvalds sigset_t *notifier_mask; 118457c521ceSAlexey Dobriyan #ifdef CONFIG_SECURITY 11851da177e4SLinus Torvalds void *security; 118657c521ceSAlexey Dobriyan #endif 11871da177e4SLinus Torvalds struct audit_context *audit_context; 1188bfef93a5SAl Viro #ifdef CONFIG_AUDITSYSCALL 1189bfef93a5SAl Viro uid_t loginuid; 11904746ec5bSEric Paris unsigned int sessionid; 1191bfef93a5SAl Viro #endif 11921da177e4SLinus Torvalds seccomp_t seccomp; 11931da177e4SLinus Torvalds 11941da177e4SLinus Torvalds /* Thread group tracking */ 11951da177e4SLinus Torvalds u32 parent_exec_id; 11961da177e4SLinus Torvalds u32 self_exec_id; 11971da177e4SLinus Torvalds /* Protection of (de-)allocation: mm, files, fs, tty, keyrings */ 11981da177e4SLinus Torvalds spinlock_t alloc_lock; 11991da177e4SLinus Torvalds 1200b29739f9SIngo Molnar /* Protection of the PI data structures: */ 1201b29739f9SIngo Molnar spinlock_t pi_lock; 1202b29739f9SIngo Molnar 120323f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 120423f78d4aSIngo Molnar /* PI waiters blocked on a rt_mutex held by this task */ 120523f78d4aSIngo Molnar struct plist_head pi_waiters; 120623f78d4aSIngo Molnar /* Deadlock detection and priority inheritance handling */ 120723f78d4aSIngo Molnar struct rt_mutex_waiter *pi_blocked_on; 120823f78d4aSIngo Molnar #endif 120923f78d4aSIngo Molnar 1210408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES 1211408894eeSIngo Molnar /* mutex deadlock detection */ 1212408894eeSIngo Molnar struct mutex_waiter *blocked_on; 1213408894eeSIngo Molnar #endif 1214de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS 1215de30a2b3SIngo Molnar unsigned int irq_events; 1216de30a2b3SIngo Molnar int hardirqs_enabled; 1217de30a2b3SIngo Molnar unsigned long hardirq_enable_ip; 1218de30a2b3SIngo Molnar unsigned int hardirq_enable_event; 1219de30a2b3SIngo Molnar unsigned long hardirq_disable_ip; 1220de30a2b3SIngo Molnar unsigned int hardirq_disable_event; 1221de30a2b3SIngo Molnar int softirqs_enabled; 1222de30a2b3SIngo Molnar unsigned long softirq_disable_ip; 1223de30a2b3SIngo Molnar unsigned int softirq_disable_event; 1224de30a2b3SIngo Molnar unsigned long softirq_enable_ip; 1225de30a2b3SIngo Molnar unsigned int softirq_enable_event; 1226de30a2b3SIngo Molnar int hardirq_context; 1227de30a2b3SIngo Molnar int softirq_context; 1228de30a2b3SIngo Molnar #endif 1229fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP 1230bdb9441eSPeter Zijlstra # define MAX_LOCK_DEPTH 48UL 1231fbb9ce95SIngo Molnar u64 curr_chain_key; 1232fbb9ce95SIngo Molnar int lockdep_depth; 1233fbb9ce95SIngo Molnar unsigned int lockdep_recursion; 1234c7aceabaSRichard Kennedy struct held_lock held_locks[MAX_LOCK_DEPTH]; 1235fbb9ce95SIngo Molnar #endif 1236408894eeSIngo Molnar 12371da177e4SLinus Torvalds /* journalling filesystem info */ 12381da177e4SLinus Torvalds void *journal_info; 12391da177e4SLinus Torvalds 1240d89d8796SNeil Brown /* stacked block device info */ 1241d89d8796SNeil Brown struct bio *bio_list, **bio_tail; 1242d89d8796SNeil Brown 12431da177e4SLinus Torvalds /* VM state */ 12441da177e4SLinus Torvalds struct reclaim_state *reclaim_state; 12451da177e4SLinus Torvalds 12461da177e4SLinus Torvalds struct backing_dev_info *backing_dev_info; 12471da177e4SLinus Torvalds 12481da177e4SLinus Torvalds struct io_context *io_context; 12491da177e4SLinus Torvalds 12501da177e4SLinus Torvalds unsigned long ptrace_message; 12511da177e4SLinus Torvalds siginfo_t *last_siginfo; /* For ptrace use. */ 12524b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT 12531da177e4SLinus Torvalds /* i/o counters(bytes read/written, #syscalls */ 12541da177e4SLinus Torvalds u64 rchar, wchar, syscr, syscw; 12554b98d11bSAlexey Dobriyan #endif 12567c3ab738SAndrew Morton struct task_io_accounting ioac; 12578f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT) 12581da177e4SLinus Torvalds u64 acct_rss_mem1; /* accumulated rss usage */ 12591da177e4SLinus Torvalds u64 acct_vm_mem1; /* accumulated virtual memory usage */ 1260db5fed26SJay Lan cputime_t acct_stimexpd;/* stime since last update */ 12611da177e4SLinus Torvalds #endif 12621da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS 12631da177e4SLinus Torvalds nodemask_t mems_allowed; 12641da177e4SLinus Torvalds int cpuset_mems_generation; 1265825a46afSPaul Jackson int cpuset_mem_spread_rotor; 12661da177e4SLinus Torvalds #endif 1267ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS 1268817929ecSPaul Menage /* Control Group info protected by css_set_lock */ 1269817929ecSPaul Menage struct css_set *cgroups; 1270817929ecSPaul Menage /* cg_list protected by css_set_lock and tsk->alloc_lock */ 1271817929ecSPaul Menage struct list_head cg_list; 1272ddbcc7e8SPaul Menage #endif 127342b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX 12740771dfefSIngo Molnar struct robust_list_head __user *robust_list; 127534f192c6SIngo Molnar #ifdef CONFIG_COMPAT 127634f192c6SIngo Molnar struct compat_robust_list_head __user *compat_robust_list; 127734f192c6SIngo Molnar #endif 1278c87e2837SIngo Molnar struct list_head pi_state_list; 1279c87e2837SIngo Molnar struct futex_pi_state *pi_state_cache; 128042b2dd0aSAlexey Dobriyan #endif 1281c7aceabaSRichard Kennedy #ifdef CONFIG_NUMA 1282c7aceabaSRichard Kennedy struct mempolicy *mempolicy; 1283c7aceabaSRichard Kennedy short il_next; 1284c7aceabaSRichard Kennedy #endif 128522e2c507SJens Axboe atomic_t fs_excl; /* holding fs exclusive resources */ 1286e56d0903SIngo Molnar struct rcu_head rcu; 1287b92ce558SJens Axboe 1288b92ce558SJens Axboe /* 1289b92ce558SJens Axboe * cache last used pipe for splice 1290b92ce558SJens Axboe */ 1291b92ce558SJens Axboe struct pipe_inode_info *splice_pipe; 1292ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 1293ca74e92bSShailabh Nagar struct task_delay_info *delays; 1294ca74e92bSShailabh Nagar #endif 1295f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION 1296f4f154fdSAkinobu Mita int make_it_fail; 1297f4f154fdSAkinobu Mita #endif 12983e26c149SPeter Zijlstra struct prop_local_single dirties; 12999745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP 13009745512cSArjan van de Ven int latency_record_count; 13019745512cSArjan van de Ven struct latency_record latency_record[LT_SAVECOUNT]; 13029745512cSArjan van de Ven #endif 13031da177e4SLinus Torvalds }; 13041da177e4SLinus Torvalds 1305e05606d3SIngo Molnar /* 1306e05606d3SIngo Molnar * Priority of a process goes from 0..MAX_PRIO-1, valid RT 1307e05606d3SIngo Molnar * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH 1308e05606d3SIngo Molnar * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority 1309e05606d3SIngo Molnar * values are inverted: lower p->prio value means higher priority. 1310e05606d3SIngo Molnar * 1311e05606d3SIngo Molnar * The MAX_USER_RT_PRIO value allows the actual maximum 1312e05606d3SIngo Molnar * RT priority to be separate from the value exported to 1313e05606d3SIngo Molnar * user-space. This allows kernel threads to set their 1314e05606d3SIngo Molnar * priority to a value higher than any user task. Note: 1315e05606d3SIngo Molnar * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO. 1316e05606d3SIngo Molnar */ 1317e05606d3SIngo Molnar 1318e05606d3SIngo Molnar #define MAX_USER_RT_PRIO 100 1319e05606d3SIngo Molnar #define MAX_RT_PRIO MAX_USER_RT_PRIO 1320e05606d3SIngo Molnar 1321e05606d3SIngo Molnar #define MAX_PRIO (MAX_RT_PRIO + 40) 1322e05606d3SIngo Molnar #define DEFAULT_PRIO (MAX_RT_PRIO + 20) 1323e05606d3SIngo Molnar 1324e05606d3SIngo Molnar static inline int rt_prio(int prio) 1325e05606d3SIngo Molnar { 1326e05606d3SIngo Molnar if (unlikely(prio < MAX_RT_PRIO)) 1327e05606d3SIngo Molnar return 1; 1328e05606d3SIngo Molnar return 0; 1329e05606d3SIngo Molnar } 1330e05606d3SIngo Molnar 1331e868171aSAlexey Dobriyan static inline int rt_task(struct task_struct *p) 1332e05606d3SIngo Molnar { 1333e05606d3SIngo Molnar return rt_prio(p->prio); 1334e05606d3SIngo Molnar } 1335e05606d3SIngo Molnar 1336a47afb0fSPavel Emelianov static inline void set_task_session(struct task_struct *tsk, pid_t session) 1337937949d9SCedric Le Goater { 1338a47afb0fSPavel Emelianov tsk->signal->__session = session; 1339937949d9SCedric Le Goater } 1340937949d9SCedric Le Goater 13419a2e7057SPavel Emelyanov static inline void set_task_pgrp(struct task_struct *tsk, pid_t pgrp) 13429a2e7057SPavel Emelyanov { 13439a2e7057SPavel Emelyanov tsk->signal->__pgrp = pgrp; 13449a2e7057SPavel Emelyanov } 13459a2e7057SPavel Emelyanov 1346e868171aSAlexey Dobriyan static inline struct pid *task_pid(struct task_struct *task) 134722c935f4SEric W. Biederman { 134822c935f4SEric W. Biederman return task->pids[PIDTYPE_PID].pid; 134922c935f4SEric W. Biederman } 135022c935f4SEric W. Biederman 1351e868171aSAlexey Dobriyan static inline struct pid *task_tgid(struct task_struct *task) 135222c935f4SEric W. Biederman { 135322c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PID].pid; 135422c935f4SEric W. Biederman } 135522c935f4SEric W. Biederman 1356e868171aSAlexey Dobriyan static inline struct pid *task_pgrp(struct task_struct *task) 135722c935f4SEric W. Biederman { 135822c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PGID].pid; 135922c935f4SEric W. Biederman } 136022c935f4SEric W. Biederman 1361e868171aSAlexey Dobriyan static inline struct pid *task_session(struct task_struct *task) 136222c935f4SEric W. Biederman { 136322c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_SID].pid; 136422c935f4SEric W. Biederman } 136522c935f4SEric W. Biederman 13667af57294SPavel Emelyanov struct pid_namespace; 13677af57294SPavel Emelyanov 13687af57294SPavel Emelyanov /* 13697af57294SPavel Emelyanov * the helpers to get the task's different pids as they are seen 13707af57294SPavel Emelyanov * from various namespaces 13717af57294SPavel Emelyanov * 13727af57294SPavel Emelyanov * task_xid_nr() : global id, i.e. the id seen from the init namespace; 137344c4e1b2SEric W. Biederman * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of 137444c4e1b2SEric W. Biederman * current. 13757af57294SPavel Emelyanov * task_xid_nr_ns() : id seen from the ns specified; 13767af57294SPavel Emelyanov * 13777af57294SPavel Emelyanov * set_task_vxid() : assigns a virtual id to a task; 13787af57294SPavel Emelyanov * 13797af57294SPavel Emelyanov * see also pid_nr() etc in include/linux/pid.h 13807af57294SPavel Emelyanov */ 13817af57294SPavel Emelyanov 1382e868171aSAlexey Dobriyan static inline pid_t task_pid_nr(struct task_struct *tsk) 13837af57294SPavel Emelyanov { 13847af57294SPavel Emelyanov return tsk->pid; 13857af57294SPavel Emelyanov } 13867af57294SPavel Emelyanov 13872f2a3a46SPavel Emelyanov pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); 13887af57294SPavel Emelyanov 13897af57294SPavel Emelyanov static inline pid_t task_pid_vnr(struct task_struct *tsk) 13907af57294SPavel Emelyanov { 13917af57294SPavel Emelyanov return pid_vnr(task_pid(tsk)); 13927af57294SPavel Emelyanov } 13937af57294SPavel Emelyanov 13947af57294SPavel Emelyanov 1395e868171aSAlexey Dobriyan static inline pid_t task_tgid_nr(struct task_struct *tsk) 13967af57294SPavel Emelyanov { 13977af57294SPavel Emelyanov return tsk->tgid; 13987af57294SPavel Emelyanov } 13997af57294SPavel Emelyanov 14002f2a3a46SPavel Emelyanov pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); 14017af57294SPavel Emelyanov 14027af57294SPavel Emelyanov static inline pid_t task_tgid_vnr(struct task_struct *tsk) 14037af57294SPavel Emelyanov { 14047af57294SPavel Emelyanov return pid_vnr(task_tgid(tsk)); 14057af57294SPavel Emelyanov } 14067af57294SPavel Emelyanov 14077af57294SPavel Emelyanov 1408e868171aSAlexey Dobriyan static inline pid_t task_pgrp_nr(struct task_struct *tsk) 14097af57294SPavel Emelyanov { 14109a2e7057SPavel Emelyanov return tsk->signal->__pgrp; 14117af57294SPavel Emelyanov } 14127af57294SPavel Emelyanov 14132f2a3a46SPavel Emelyanov pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); 14147af57294SPavel Emelyanov 14157af57294SPavel Emelyanov static inline pid_t task_pgrp_vnr(struct task_struct *tsk) 14167af57294SPavel Emelyanov { 14177af57294SPavel Emelyanov return pid_vnr(task_pgrp(tsk)); 14187af57294SPavel Emelyanov } 14197af57294SPavel Emelyanov 14207af57294SPavel Emelyanov 1421e868171aSAlexey Dobriyan static inline pid_t task_session_nr(struct task_struct *tsk) 14227af57294SPavel Emelyanov { 14237af57294SPavel Emelyanov return tsk->signal->__session; 14247af57294SPavel Emelyanov } 14257af57294SPavel Emelyanov 14262f2a3a46SPavel Emelyanov pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); 14277af57294SPavel Emelyanov 14287af57294SPavel Emelyanov static inline pid_t task_session_vnr(struct task_struct *tsk) 14297af57294SPavel Emelyanov { 14307af57294SPavel Emelyanov return pid_vnr(task_session(tsk)); 14317af57294SPavel Emelyanov } 14327af57294SPavel Emelyanov 14337af57294SPavel Emelyanov 14341da177e4SLinus Torvalds /** 14351da177e4SLinus Torvalds * pid_alive - check that a task structure is not stale 14361da177e4SLinus Torvalds * @p: Task structure to be checked. 14371da177e4SLinus Torvalds * 14381da177e4SLinus Torvalds * Test if a process is not yet dead (at most zombie state) 14391da177e4SLinus Torvalds * If pid_alive fails, then pointers within the task structure 14401da177e4SLinus Torvalds * can be stale and must not be dereferenced. 14411da177e4SLinus Torvalds */ 1442e868171aSAlexey Dobriyan static inline int pid_alive(struct task_struct *p) 14431da177e4SLinus Torvalds { 144492476d7fSEric W. Biederman return p->pids[PIDTYPE_PID].pid != NULL; 14451da177e4SLinus Torvalds } 14461da177e4SLinus Torvalds 1447f400e198SSukadev Bhattiprolu /** 1448b460cbc5SSerge E. Hallyn * is_global_init - check if a task structure is init 14493260259fSHenne * @tsk: Task structure to be checked. 14503260259fSHenne * 14513260259fSHenne * Check if a task structure is the first user space task the kernel created. 1452f400e198SSukadev Bhattiprolu */ 1453e868171aSAlexey Dobriyan static inline int is_global_init(struct task_struct *tsk) 1454b461cc03SPavel Emelyanov { 1455b461cc03SPavel Emelyanov return tsk->pid == 1; 1456b461cc03SPavel Emelyanov } 1457b460cbc5SSerge E. Hallyn 1458b460cbc5SSerge E. Hallyn /* 1459b460cbc5SSerge E. Hallyn * is_container_init: 1460b460cbc5SSerge E. Hallyn * check whether in the task is init in its own pid namespace. 1461b460cbc5SSerge E. Hallyn */ 1462b461cc03SPavel Emelyanov extern int is_container_init(struct task_struct *tsk); 1463f400e198SSukadev Bhattiprolu 14649ec52099SCedric Le Goater extern struct pid *cad_pid; 14659ec52099SCedric Le Goater 14661da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk); 14671da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0) 1468e56d0903SIngo Molnar 1469158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t); 1470e56d0903SIngo Molnar 1471e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t) 1472e56d0903SIngo Molnar { 1473e56d0903SIngo Molnar if (atomic_dec_and_test(&t->usage)) 14748c7904a0SEric W. Biederman __put_task_struct(t); 1475e56d0903SIngo Molnar } 14761da177e4SLinus Torvalds 14771da177e4SLinus Torvalds /* 14781da177e4SLinus Torvalds * Per process flags 14791da177e4SLinus Torvalds */ 14801da177e4SLinus Torvalds #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */ 14811da177e4SLinus Torvalds /* Not implemented yet, only for 486*/ 14821da177e4SLinus Torvalds #define PF_STARTING 0x00000002 /* being created */ 14831da177e4SLinus Torvalds #define PF_EXITING 0x00000004 /* getting shut down */ 1484778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ 148594886b84SLaurent Vivier #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ 14861da177e4SLinus Torvalds #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ 14871da177e4SLinus Torvalds #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ 14881da177e4SLinus Torvalds #define PF_DUMPCORE 0x00000200 /* dumped core */ 14891da177e4SLinus Torvalds #define PF_SIGNALED 0x00000400 /* killed by a signal */ 14901da177e4SLinus Torvalds #define PF_MEMALLOC 0x00000800 /* Allocating memory */ 14911da177e4SLinus Torvalds #define PF_FLUSHER 0x00001000 /* responsible for disk writeback */ 14921da177e4SLinus Torvalds #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */ 14931da177e4SLinus Torvalds #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */ 14941da177e4SLinus Torvalds #define PF_FROZEN 0x00010000 /* frozen for system suspend */ 14951da177e4SLinus Torvalds #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ 14961da177e4SLinus Torvalds #define PF_KSWAPD 0x00040000 /* I am kswapd */ 14971da177e4SLinus Torvalds #define PF_SWAPOFF 0x00080000 /* I am in swapoff */ 14981da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */ 1499246bb0b1SOleg Nesterov #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ 1500b31dc66aSJens Axboe #define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */ 1501b31dc66aSJens Axboe #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ 1502b31dc66aSJens Axboe #define PF_SPREAD_PAGE 0x01000000 /* Spread page cache over cpuset */ 1503b31dc66aSJens Axboe #define PF_SPREAD_SLAB 0x02000000 /* Spread some slab caches over cpuset */ 15049985b0baSDavid Rientjes #define PF_THREAD_BOUND 0x04000000 /* Thread bound to specific cpu */ 1505c61afb18SPaul Jackson #define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */ 150661a87122SThomas Gleixner #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */ 1507ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezeable */ 1508ebb12db5SRafael J. Wysocki #define PF_FREEZER_NOSIG 0x80000000 /* Freezer won't send signals to it */ 15091da177e4SLinus Torvalds 15101da177e4SLinus Torvalds /* 15111da177e4SLinus Torvalds * Only the _current_ task can read/write to tsk->flags, but other 15121da177e4SLinus Torvalds * tasks can access tsk->flags in readonly mode for example 15131da177e4SLinus Torvalds * with tsk_used_math (like during threaded core dumping). 15141da177e4SLinus Torvalds * There is however an exception to this rule during ptrace 15151da177e4SLinus Torvalds * or during fork: the ptracer task is allowed to write to the 15161da177e4SLinus Torvalds * child->flags of its traced child (same goes for fork, the parent 15171da177e4SLinus Torvalds * can write to the child->flags), because we're guaranteed the 15181da177e4SLinus Torvalds * child is not running and in turn not changing child->flags 15191da177e4SLinus Torvalds * at the same time the parent does it. 15201da177e4SLinus Torvalds */ 15211da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0) 15221da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0) 15231da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current) 15241da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current) 15251da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \ 15261da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0) 15271da177e4SLinus Torvalds #define conditional_used_math(condition) \ 15281da177e4SLinus Torvalds conditional_stopped_child_used_math(condition, current) 15291da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \ 15301da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0) 15311da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */ 15321da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH) 15331da177e4SLinus Torvalds #define used_math() tsk_used_math(current) 15341da177e4SLinus Torvalds 15351da177e4SLinus Torvalds #ifdef CONFIG_SMP 1536cd8ba7cdSMike Travis extern int set_cpus_allowed_ptr(struct task_struct *p, 1537cd8ba7cdSMike Travis const cpumask_t *new_mask); 15381da177e4SLinus Torvalds #else 1539cd8ba7cdSMike Travis static inline int set_cpus_allowed_ptr(struct task_struct *p, 1540cd8ba7cdSMike Travis const cpumask_t *new_mask) 15411da177e4SLinus Torvalds { 1542cd8ba7cdSMike Travis if (!cpu_isset(0, *new_mask)) 15431da177e4SLinus Torvalds return -EINVAL; 15441da177e4SLinus Torvalds return 0; 15451da177e4SLinus Torvalds } 15461da177e4SLinus Torvalds #endif 1547cd8ba7cdSMike Travis static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask) 1548cd8ba7cdSMike Travis { 1549cd8ba7cdSMike Travis return set_cpus_allowed_ptr(p, &new_mask); 1550cd8ba7cdSMike Travis } 15511da177e4SLinus Torvalds 15521da177e4SLinus Torvalds extern unsigned long long sched_clock(void); 1553e436d800SIngo Molnar 15543e51f33fSPeter Zijlstra #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK 15553e51f33fSPeter Zijlstra static inline void sched_clock_init(void) 15563e51f33fSPeter Zijlstra { 15573e51f33fSPeter Zijlstra } 15583e51f33fSPeter Zijlstra 15593e51f33fSPeter Zijlstra static inline u64 sched_clock_cpu(int cpu) 15603e51f33fSPeter Zijlstra { 15613e51f33fSPeter Zijlstra return sched_clock(); 15623e51f33fSPeter Zijlstra } 15633e51f33fSPeter Zijlstra 15643e51f33fSPeter Zijlstra static inline void sched_clock_tick(void) 15653e51f33fSPeter Zijlstra { 15663e51f33fSPeter Zijlstra } 15673e51f33fSPeter Zijlstra 15683e51f33fSPeter Zijlstra static inline void sched_clock_idle_sleep_event(void) 15693e51f33fSPeter Zijlstra { 15703e51f33fSPeter Zijlstra } 15713e51f33fSPeter Zijlstra 15723e51f33fSPeter Zijlstra static inline void sched_clock_idle_wakeup_event(u64 delta_ns) 15733e51f33fSPeter Zijlstra { 15743e51f33fSPeter Zijlstra } 1575af52a90aSSteven Rostedt 1576af52a90aSSteven Rostedt #ifdef CONFIG_NO_HZ 1577af52a90aSSteven Rostedt static inline void sched_clock_tick_stop(int cpu) 1578af52a90aSSteven Rostedt { 1579af52a90aSSteven Rostedt } 1580af52a90aSSteven Rostedt 1581af52a90aSSteven Rostedt static inline void sched_clock_tick_start(int cpu) 1582af52a90aSSteven Rostedt { 1583af52a90aSSteven Rostedt } 1584af52a90aSSteven Rostedt #endif 1585af52a90aSSteven Rostedt 1586af52a90aSSteven Rostedt #else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */ 15873e51f33fSPeter Zijlstra extern void sched_clock_init(void); 15883e51f33fSPeter Zijlstra extern u64 sched_clock_cpu(int cpu); 15893e51f33fSPeter Zijlstra extern void sched_clock_tick(void); 15903e51f33fSPeter Zijlstra extern void sched_clock_idle_sleep_event(void); 15913e51f33fSPeter Zijlstra extern void sched_clock_idle_wakeup_event(u64 delta_ns); 1592af52a90aSSteven Rostedt #ifdef CONFIG_NO_HZ 1593af52a90aSSteven Rostedt extern void sched_clock_tick_stop(int cpu); 1594af52a90aSSteven Rostedt extern void sched_clock_tick_start(int cpu); 15953e51f33fSPeter Zijlstra #endif 1596af52a90aSSteven Rostedt #endif /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */ 15973e51f33fSPeter Zijlstra 1598e436d800SIngo Molnar /* 1599e436d800SIngo Molnar * For kernel-internal use: high-speed (but slightly incorrect) per-cpu 1600e436d800SIngo Molnar * clock constructed from sched_clock(): 1601e436d800SIngo Molnar */ 1602e436d800SIngo Molnar extern unsigned long long cpu_clock(int cpu); 1603e436d800SIngo Molnar 160436c8b586SIngo Molnar extern unsigned long long 160541b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task); 16061da177e4SLinus Torvalds 16071da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */ 16081da177e4SLinus Torvalds #ifdef CONFIG_SMP 16091da177e4SLinus Torvalds extern void sched_exec(void); 16101da177e4SLinus Torvalds #else 16111da177e4SLinus Torvalds #define sched_exec() {} 16121da177e4SLinus Torvalds #endif 16131da177e4SLinus Torvalds 16142aa44d05SIngo Molnar extern void sched_clock_idle_sleep_event(void); 16152aa44d05SIngo Molnar extern void sched_clock_idle_wakeup_event(u64 delta_ns); 1616bb29ab26SIngo Molnar 16171da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU 16181da177e4SLinus Torvalds extern void idle_task_exit(void); 16191da177e4SLinus Torvalds #else 16201da177e4SLinus Torvalds static inline void idle_task_exit(void) {} 16211da177e4SLinus Torvalds #endif 16221da177e4SLinus Torvalds 16231da177e4SLinus Torvalds extern void sched_idle_next(void); 1624b29739f9SIngo Molnar 162506d8308cSThomas Gleixner #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP) 162606d8308cSThomas Gleixner extern void wake_up_idle_cpu(int cpu); 162706d8308cSThomas Gleixner #else 162806d8308cSThomas Gleixner static inline void wake_up_idle_cpu(int cpu) { } 162906d8308cSThomas Gleixner #endif 163006d8308cSThomas Gleixner 16312bd8e6d4SIngo Molnar #ifdef CONFIG_SCHED_DEBUG 163221805085SPeter Zijlstra extern unsigned int sysctl_sched_latency; 1633b2be5e96SPeter Zijlstra extern unsigned int sysctl_sched_min_granularity; 1634bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity; 1635bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first; 1636bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_features; 1637da84d961SIngo Molnar extern unsigned int sysctl_sched_migration_cost; 1638b82d9fddSPeter Zijlstra extern unsigned int sysctl_sched_nr_migrate; 16392398f2c6SPeter Zijlstra extern unsigned int sysctl_sched_shares_ratelimit; 1640b2be5e96SPeter Zijlstra 1641b2be5e96SPeter Zijlstra int sched_nr_latency_handler(struct ctl_table *table, int write, 1642b2be5e96SPeter Zijlstra struct file *file, void __user *buffer, size_t *length, 1643b2be5e96SPeter Zijlstra loff_t *ppos); 16442bd8e6d4SIngo Molnar #endif 16459f0c1e56SPeter Zijlstra extern unsigned int sysctl_sched_rt_period; 16469f0c1e56SPeter Zijlstra extern int sysctl_sched_rt_runtime; 16472bd8e6d4SIngo Molnar 1648d0b27fa7SPeter Zijlstra int sched_rt_handler(struct ctl_table *table, int write, 1649d0b27fa7SPeter Zijlstra struct file *filp, void __user *buffer, size_t *lenp, 1650d0b27fa7SPeter Zijlstra loff_t *ppos); 1651d0b27fa7SPeter Zijlstra 16522bd8e6d4SIngo Molnar extern unsigned int sysctl_sched_compat_yield; 1653bf0f6f24SIngo Molnar 1654b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES 165536c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p); 165636c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio); 165736c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p); 1658b29739f9SIngo Molnar #else 1659e868171aSAlexey Dobriyan static inline int rt_mutex_getprio(struct task_struct *p) 1660b29739f9SIngo Molnar { 1661b29739f9SIngo Molnar return p->normal_prio; 1662b29739f9SIngo Molnar } 166395e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p) do { } while (0) 1664b29739f9SIngo Molnar #endif 1665b29739f9SIngo Molnar 166636c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice); 166736c8b586SIngo Molnar extern int task_prio(const struct task_struct *p); 166836c8b586SIngo Molnar extern int task_nice(const struct task_struct *p); 166936c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice); 167036c8b586SIngo Molnar extern int task_curr(const struct task_struct *p); 16711da177e4SLinus Torvalds extern int idle_cpu(int cpu); 16721da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *); 1673961ccdddSRusty Russell extern int sched_setscheduler_nocheck(struct task_struct *, int, 1674961ccdddSRusty Russell struct sched_param *); 167536c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu); 167636c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu); 167736c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p); 16781da177e4SLinus Torvalds 16791da177e4SLinus Torvalds void yield(void); 16801da177e4SLinus Torvalds 16811da177e4SLinus Torvalds /* 16821da177e4SLinus Torvalds * The default (Linux) execution domain. 16831da177e4SLinus Torvalds */ 16841da177e4SLinus Torvalds extern struct exec_domain default_exec_domain; 16851da177e4SLinus Torvalds 16861da177e4SLinus Torvalds union thread_union { 16871da177e4SLinus Torvalds struct thread_info thread_info; 16881da177e4SLinus Torvalds unsigned long stack[THREAD_SIZE/sizeof(long)]; 16891da177e4SLinus Torvalds }; 16901da177e4SLinus Torvalds 16911da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END 16921da177e4SLinus Torvalds static inline int kstack_end(void *addr) 16931da177e4SLinus Torvalds { 16941da177e4SLinus Torvalds /* Reliable end of stack detection: 16951da177e4SLinus Torvalds * Some APM bios versions misalign the stack 16961da177e4SLinus Torvalds */ 16971da177e4SLinus Torvalds return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*))); 16981da177e4SLinus Torvalds } 16991da177e4SLinus Torvalds #endif 17001da177e4SLinus Torvalds 17011da177e4SLinus Torvalds extern union thread_union init_thread_union; 17021da177e4SLinus Torvalds extern struct task_struct init_task; 17031da177e4SLinus Torvalds 17041da177e4SLinus Torvalds extern struct mm_struct init_mm; 17051da177e4SLinus Torvalds 1706198fe21bSPavel Emelyanov extern struct pid_namespace init_pid_ns; 1707198fe21bSPavel Emelyanov 1708198fe21bSPavel Emelyanov /* 1709198fe21bSPavel Emelyanov * find a task by one of its numerical ids 1710198fe21bSPavel Emelyanov * 1711198fe21bSPavel Emelyanov * find_task_by_pid_type_ns(): 1712198fe21bSPavel Emelyanov * it is the most generic call - it finds a task by all id, 1713198fe21bSPavel Emelyanov * type and namespace specified 1714198fe21bSPavel Emelyanov * find_task_by_pid_ns(): 1715198fe21bSPavel Emelyanov * finds a task by its pid in the specified namespace 1716228ebcbeSPavel Emelyanov * find_task_by_vpid(): 1717228ebcbeSPavel Emelyanov * finds a task by its virtual pid 1718198fe21bSPavel Emelyanov * find_task_by_pid(): 1719198fe21bSPavel Emelyanov * finds a task by its global pid 1720198fe21bSPavel Emelyanov * 1721*e49859e7SPavel Emelyanov * see also find_vpid() etc in include/linux/pid.h 1722198fe21bSPavel Emelyanov */ 1723198fe21bSPavel Emelyanov 1724198fe21bSPavel Emelyanov extern struct task_struct *find_task_by_pid_type_ns(int type, int pid, 1725198fe21bSPavel Emelyanov struct pid_namespace *ns); 1726198fe21bSPavel Emelyanov 17275cd20455SPavel Emelyanov static inline struct task_struct *__deprecated find_task_by_pid(pid_t nr) 17285cd20455SPavel Emelyanov { 17295cd20455SPavel Emelyanov return find_task_by_pid_type_ns(PIDTYPE_PID, nr, &init_pid_ns); 17305cd20455SPavel Emelyanov } 1731228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_vpid(pid_t nr); 1732228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid_ns(pid_t nr, 1733228ebcbeSPavel Emelyanov struct pid_namespace *ns); 1734198fe21bSPavel Emelyanov 17358520d7c7SOleg Nesterov extern void __set_special_pids(struct pid *pid); 17361da177e4SLinus Torvalds 17371da177e4SLinus Torvalds /* per-UID process charging. */ 1738acce292cSCedric Le Goater extern struct user_struct * alloc_uid(struct user_namespace *, uid_t); 17391da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u) 17401da177e4SLinus Torvalds { 17411da177e4SLinus Torvalds atomic_inc(&u->__count); 17421da177e4SLinus Torvalds return u; 17431da177e4SLinus Torvalds } 17441da177e4SLinus Torvalds extern void free_uid(struct user_struct *); 17451da177e4SLinus Torvalds extern void switch_uid(struct user_struct *); 174628f300d2SPavel Emelyanov extern void release_uids(struct user_namespace *ns); 17471da177e4SLinus Torvalds 17481da177e4SLinus Torvalds #include <asm/current.h> 17491da177e4SLinus Torvalds 17503171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks); 17511da177e4SLinus Torvalds 1752b3c97528SHarvey Harrison extern int wake_up_state(struct task_struct *tsk, unsigned int state); 1753b3c97528SHarvey Harrison extern int wake_up_process(struct task_struct *tsk); 1754b3c97528SHarvey Harrison extern void wake_up_new_task(struct task_struct *tsk, 1755b3c97528SHarvey Harrison unsigned long clone_flags); 17561da177e4SLinus Torvalds #ifdef CONFIG_SMP 17571da177e4SLinus Torvalds extern void kick_process(struct task_struct *tsk); 17581da177e4SLinus Torvalds #else 17591da177e4SLinus Torvalds static inline void kick_process(struct task_struct *tsk) { } 17601da177e4SLinus Torvalds #endif 1761ad46c2c4SIngo Molnar extern void sched_fork(struct task_struct *p, int clone_flags); 1762ad46c2c4SIngo Molnar extern void sched_dead(struct task_struct *p); 17631da177e4SLinus Torvalds 17641da177e4SLinus Torvalds extern int in_group_p(gid_t); 17651da177e4SLinus Torvalds extern int in_egroup_p(gid_t); 17661da177e4SLinus Torvalds 17671da177e4SLinus Torvalds extern void proc_caches_init(void); 17681da177e4SLinus Torvalds extern void flush_signals(struct task_struct *); 176910ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *); 17701da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default); 17711da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info); 17721da177e4SLinus Torvalds 17731da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) 17741da177e4SLinus Torvalds { 17751da177e4SLinus Torvalds unsigned long flags; 17761da177e4SLinus Torvalds int ret; 17771da177e4SLinus Torvalds 17781da177e4SLinus Torvalds spin_lock_irqsave(&tsk->sighand->siglock, flags); 17791da177e4SLinus Torvalds ret = dequeue_signal(tsk, mask, info); 17801da177e4SLinus Torvalds spin_unlock_irqrestore(&tsk->sighand->siglock, flags); 17811da177e4SLinus Torvalds 17821da177e4SLinus Torvalds return ret; 17831da177e4SLinus Torvalds } 17841da177e4SLinus Torvalds 17851da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv, 17861da177e4SLinus Torvalds sigset_t *mask); 17871da177e4SLinus Torvalds extern void unblock_all_signals(void); 17881da177e4SLinus Torvalds extern void release_task(struct task_struct * p); 17891da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *); 17901da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *); 17911da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *); 1792c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp); 1793c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid); 17942425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32); 1795c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv); 1796c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv); 1797c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t); 17981da177e4SLinus Torvalds extern void do_notify_parent(struct task_struct *, int); 17991da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *); 18001da177e4SLinus Torvalds extern void force_sig_specific(int, struct task_struct *); 18011da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int); 18021da177e4SLinus Torvalds extern void zap_other_threads(struct task_struct *p); 18031da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void); 18041da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *); 1805ac5c2153SOleg Nesterov extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group); 18069ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); 18071da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long); 18081da177e4SLinus Torvalds 18099ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv) 18109ec52099SCedric Le Goater { 18119ec52099SCedric Le Goater return kill_pid(cad_pid, sig, priv); 18129ec52099SCedric Le Goater } 18139ec52099SCedric Le Goater 18141da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info. */ 18151da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0) 18161da177e4SLinus Torvalds #define SEND_SIG_PRIV ((struct siginfo *) 1) 18171da177e4SLinus Torvalds #define SEND_SIG_FORCED ((struct siginfo *) 2) 18181da177e4SLinus Torvalds 1819621d3121SOleg Nesterov static inline int is_si_special(const struct siginfo *info) 1820621d3121SOleg Nesterov { 1821621d3121SOleg Nesterov return info <= SEND_SIG_FORCED; 1822621d3121SOleg Nesterov } 1823621d3121SOleg Nesterov 18241da177e4SLinus Torvalds /* True if we are on the alternate signal stack. */ 18251da177e4SLinus Torvalds 18261da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp) 18271da177e4SLinus Torvalds { 18281da177e4SLinus Torvalds return (sp - current->sas_ss_sp < current->sas_ss_size); 18291da177e4SLinus Torvalds } 18301da177e4SLinus Torvalds 18311da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp) 18321da177e4SLinus Torvalds { 18331da177e4SLinus Torvalds return (current->sas_ss_size == 0 ? SS_DISABLE 18341da177e4SLinus Torvalds : on_sig_stack(sp) ? SS_ONSTACK : 0); 18351da177e4SLinus Torvalds } 18361da177e4SLinus Torvalds 18371da177e4SLinus Torvalds /* 18381da177e4SLinus Torvalds * Routines for handling mm_structs 18391da177e4SLinus Torvalds */ 18401da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void); 18411da177e4SLinus Torvalds 18421da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */ 1843b3c97528SHarvey Harrison extern void __mmdrop(struct mm_struct *); 18441da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm) 18451da177e4SLinus Torvalds { 18466fb43d7bSIngo Molnar if (unlikely(atomic_dec_and_test(&mm->mm_count))) 18471da177e4SLinus Torvalds __mmdrop(mm); 18481da177e4SLinus Torvalds } 18491da177e4SLinus Torvalds 18501da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */ 18511da177e4SLinus Torvalds extern void mmput(struct mm_struct *); 18521da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */ 18531da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task); 18541da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */ 18551da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *); 1856402b0862SCarsten Otte /* Allocate a new mm structure and copy contents from tsk->mm */ 1857402b0862SCarsten Otte extern struct mm_struct *dup_mm(struct task_struct *tsk); 18581da177e4SLinus Torvalds 18591da177e4SLinus Torvalds extern int copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *); 18601da177e4SLinus Torvalds extern void flush_thread(void); 18611da177e4SLinus Torvalds extern void exit_thread(void); 18621da177e4SLinus Torvalds 18631da177e4SLinus Torvalds extern void exit_files(struct task_struct *); 18646b3934efSOleg Nesterov extern void __cleanup_signal(struct signal_struct *); 1865a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *); 1866cbaffba1SOleg Nesterov 18671da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *); 1868cbaffba1SOleg Nesterov extern void flush_itimer_signals(void); 18691da177e4SLinus Torvalds 18701da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int); 18711da177e4SLinus Torvalds 18721da177e4SLinus Torvalds extern void daemonize(const char *, ...); 18731da177e4SLinus Torvalds extern int allow_signal(int); 18741da177e4SLinus Torvalds extern int disallow_signal(int); 18751da177e4SLinus Torvalds 18761da177e4SLinus Torvalds extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *); 18771da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *); 187836c8b586SIngo Molnar struct task_struct *fork_idle(int); 18791da177e4SLinus Torvalds 18801da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from); 188159714d65SAndrew Morton extern char *get_task_comm(char *to, struct task_struct *tsk); 18821da177e4SLinus Torvalds 18831da177e4SLinus Torvalds #ifdef CONFIG_SMP 188436c8b586SIngo Molnar extern void wait_task_inactive(struct task_struct * p); 18851da177e4SLinus Torvalds #else 18861da177e4SLinus Torvalds #define wait_task_inactive(p) do { } while (0) 18871da177e4SLinus Torvalds #endif 18881da177e4SLinus Torvalds 18895e85d4abSEric W. Biederman #define next_task(p) list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks) 18901da177e4SLinus Torvalds 18911da177e4SLinus Torvalds #define for_each_process(p) \ 18921da177e4SLinus Torvalds for (p = &init_task ; (p = next_task(p)) != &init_task ; ) 18931da177e4SLinus Torvalds 18941da177e4SLinus Torvalds /* 18951da177e4SLinus Torvalds * Careful: do_each_thread/while_each_thread is a double loop so 18961da177e4SLinus Torvalds * 'break' will not work as expected - use goto instead. 18971da177e4SLinus Torvalds */ 18981da177e4SLinus Torvalds #define do_each_thread(g, t) \ 18991da177e4SLinus Torvalds for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do 19001da177e4SLinus Torvalds 19011da177e4SLinus Torvalds #define while_each_thread(g, t) \ 19021da177e4SLinus Torvalds while ((t = next_thread(t)) != g) 19031da177e4SLinus Torvalds 1904de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */ 1905de12a787SEric W. Biederman #define thread_group_leader(p) (p == p->group_leader) 19061da177e4SLinus Torvalds 19070804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process 19080804ef4bSEric W. Biederman * to have the pid of the thread group leader without actually being 19090804ef4bSEric W. Biederman * the thread group leader. For iteration through the pids in proc 19100804ef4bSEric W. Biederman * all we care about is that we have a task with the appropriate 19110804ef4bSEric W. Biederman * pid, we don't actually care if we have the right task. 19120804ef4bSEric W. Biederman */ 1913e868171aSAlexey Dobriyan static inline int has_group_leader_pid(struct task_struct *p) 19140804ef4bSEric W. Biederman { 19150804ef4bSEric W. Biederman return p->pid == p->tgid; 19160804ef4bSEric W. Biederman } 19170804ef4bSEric W. Biederman 1918bac0abd6SPavel Emelyanov static inline 1919bac0abd6SPavel Emelyanov int same_thread_group(struct task_struct *p1, struct task_struct *p2) 1920bac0abd6SPavel Emelyanov { 1921bac0abd6SPavel Emelyanov return p1->tgid == p2->tgid; 1922bac0abd6SPavel Emelyanov } 1923bac0abd6SPavel Emelyanov 192436c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p) 192547e65328SOleg Nesterov { 192647e65328SOleg Nesterov return list_entry(rcu_dereference(p->thread_group.next), 192736c8b586SIngo Molnar struct task_struct, thread_group); 192847e65328SOleg Nesterov } 192947e65328SOleg Nesterov 1930e868171aSAlexey Dobriyan static inline int thread_group_empty(struct task_struct *p) 19311da177e4SLinus Torvalds { 193247e65328SOleg Nesterov return list_empty(&p->thread_group); 19331da177e4SLinus Torvalds } 19341da177e4SLinus Torvalds 19351da177e4SLinus Torvalds #define delay_group_leader(p) \ 19361da177e4SLinus Torvalds (thread_group_leader(p) && !thread_group_empty(p)) 19371da177e4SLinus Torvalds 19381da177e4SLinus Torvalds /* 1939260ea101SEric W. Biederman * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring 194022e2c507SJens Axboe * subscriptions and synchronises with wait4(). Also used in procfs. Also 1941ddbcc7e8SPaul Menage * pins the final release of task.io_context. Also protects ->cpuset and 1942ddbcc7e8SPaul Menage * ->cgroup.subsys[]. 19431da177e4SLinus Torvalds * 19441da177e4SLinus Torvalds * Nests both inside and outside of read_lock(&tasklist_lock). 19451da177e4SLinus Torvalds * It must not be nested with write_lock_irq(&tasklist_lock), 19461da177e4SLinus Torvalds * neither inside nor outside. 19471da177e4SLinus Torvalds */ 19481da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p) 19491da177e4SLinus Torvalds { 19501da177e4SLinus Torvalds spin_lock(&p->alloc_lock); 19511da177e4SLinus Torvalds } 19521da177e4SLinus Torvalds 19531da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p) 19541da177e4SLinus Torvalds { 19551da177e4SLinus Torvalds spin_unlock(&p->alloc_lock); 19561da177e4SLinus Torvalds } 19571da177e4SLinus Torvalds 1958f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk, 1959f63ee72eSOleg Nesterov unsigned long *flags); 1960f63ee72eSOleg Nesterov 1961f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk, 1962f63ee72eSOleg Nesterov unsigned long *flags) 1963f63ee72eSOleg Nesterov { 1964f63ee72eSOleg Nesterov spin_unlock_irqrestore(&tsk->sighand->siglock, *flags); 1965f63ee72eSOleg Nesterov } 1966f63ee72eSOleg Nesterov 1967f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS 1968f037360fSAl Viro 1969f7e4217bSRoman Zippel #define task_thread_info(task) ((struct thread_info *)(task)->stack) 1970f7e4217bSRoman Zippel #define task_stack_page(task) ((task)->stack) 1971a1261f54SAl Viro 197210ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org) 197310ebffdeSAl Viro { 197410ebffdeSAl Viro *task_thread_info(p) = *task_thread_info(org); 197510ebffdeSAl Viro task_thread_info(p)->task = p; 197610ebffdeSAl Viro } 197710ebffdeSAl Viro 197810ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p) 197910ebffdeSAl Viro { 1980f7e4217bSRoman Zippel return (unsigned long *)(task_thread_info(p) + 1); 198110ebffdeSAl Viro } 198210ebffdeSAl Viro 1983f037360fSAl Viro #endif 1984f037360fSAl Viro 19858b05c7e6SFUJITA Tomonori static inline int object_is_on_stack(void *obj) 19868b05c7e6SFUJITA Tomonori { 19878b05c7e6SFUJITA Tomonori void *stack = task_stack_page(current); 19888b05c7e6SFUJITA Tomonori 19898b05c7e6SFUJITA Tomonori return (obj >= stack) && (obj < (stack + THREAD_SIZE)); 19908b05c7e6SFUJITA Tomonori } 19918b05c7e6SFUJITA Tomonori 19928c9843e5SBenjamin Herrenschmidt extern void thread_info_cache_init(void); 19938c9843e5SBenjamin Herrenschmidt 19941da177e4SLinus Torvalds /* set thread flags in other task's structures 19951da177e4SLinus Torvalds * - see asm/thread_info.h for TIF_xxxx flags available 19961da177e4SLinus Torvalds */ 19971da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag) 19981da177e4SLinus Torvalds { 1999a1261f54SAl Viro set_ti_thread_flag(task_thread_info(tsk), flag); 20001da177e4SLinus Torvalds } 20011da177e4SLinus Torvalds 20021da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag) 20031da177e4SLinus Torvalds { 2004a1261f54SAl Viro clear_ti_thread_flag(task_thread_info(tsk), flag); 20051da177e4SLinus Torvalds } 20061da177e4SLinus Torvalds 20071da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag) 20081da177e4SLinus Torvalds { 2009a1261f54SAl Viro return test_and_set_ti_thread_flag(task_thread_info(tsk), flag); 20101da177e4SLinus Torvalds } 20111da177e4SLinus Torvalds 20121da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag) 20131da177e4SLinus Torvalds { 2014a1261f54SAl Viro return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag); 20151da177e4SLinus Torvalds } 20161da177e4SLinus Torvalds 20171da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag) 20181da177e4SLinus Torvalds { 2019a1261f54SAl Viro return test_ti_thread_flag(task_thread_info(tsk), flag); 20201da177e4SLinus Torvalds } 20211da177e4SLinus Torvalds 20221da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk) 20231da177e4SLinus Torvalds { 20241da177e4SLinus Torvalds set_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 20251da177e4SLinus Torvalds } 20261da177e4SLinus Torvalds 20271da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk) 20281da177e4SLinus Torvalds { 20291da177e4SLinus Torvalds clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 20301da177e4SLinus Torvalds } 20311da177e4SLinus Torvalds 20328ae121acSGregory Haskins static inline int test_tsk_need_resched(struct task_struct *tsk) 20338ae121acSGregory Haskins { 20348ae121acSGregory Haskins return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED)); 20358ae121acSGregory Haskins } 20368ae121acSGregory Haskins 20371da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p) 20381da177e4SLinus Torvalds { 20391da177e4SLinus Torvalds return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING)); 20401da177e4SLinus Torvalds } 20411da177e4SLinus Torvalds 2042b3c97528SHarvey Harrison extern int __fatal_signal_pending(struct task_struct *p); 2043f776d12dSMatthew Wilcox 2044f776d12dSMatthew Wilcox static inline int fatal_signal_pending(struct task_struct *p) 2045f776d12dSMatthew Wilcox { 2046f776d12dSMatthew Wilcox return signal_pending(p) && __fatal_signal_pending(p); 2047f776d12dSMatthew Wilcox } 2048f776d12dSMatthew Wilcox 204916882c1eSOleg Nesterov static inline int signal_pending_state(long state, struct task_struct *p) 205016882c1eSOleg Nesterov { 205116882c1eSOleg Nesterov if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL))) 205216882c1eSOleg Nesterov return 0; 205316882c1eSOleg Nesterov if (!signal_pending(p)) 205416882c1eSOleg Nesterov return 0; 205516882c1eSOleg Nesterov 205616882c1eSOleg Nesterov return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p); 205716882c1eSOleg Nesterov } 205816882c1eSOleg Nesterov 20591da177e4SLinus Torvalds static inline int need_resched(void) 20601da177e4SLinus Torvalds { 20619404ef02SLinus Torvalds return unlikely(test_thread_flag(TIF_NEED_RESCHED)); 20621da177e4SLinus Torvalds } 20631da177e4SLinus Torvalds 20641da177e4SLinus Torvalds /* 20651da177e4SLinus Torvalds * cond_resched() and cond_resched_lock(): latency reduction via 20661da177e4SLinus Torvalds * explicit rescheduling in places that are safe. The return 20671da177e4SLinus Torvalds * value indicates whether a reschedule was done in fact. 20681da177e4SLinus Torvalds * cond_resched_lock() will drop the spinlock before scheduling, 20691da177e4SLinus Torvalds * cond_resched_softirq() will enable bhs before scheduling. 20701da177e4SLinus Torvalds */ 2071c3921ab7SLinus Torvalds extern int _cond_resched(void); 2072c714a534SLinus Torvalds #ifdef CONFIG_PREEMPT_BKL 207302b67cc3SHerbert Xu static inline int cond_resched(void) 207402b67cc3SHerbert Xu { 207502b67cc3SHerbert Xu return 0; 207602b67cc3SHerbert Xu } 207702b67cc3SHerbert Xu #else 207802b67cc3SHerbert Xu static inline int cond_resched(void) 207902b67cc3SHerbert Xu { 208002b67cc3SHerbert Xu return _cond_resched(); 208102b67cc3SHerbert Xu } 208202b67cc3SHerbert Xu #endif 20831da177e4SLinus Torvalds extern int cond_resched_lock(spinlock_t * lock); 20841da177e4SLinus Torvalds extern int cond_resched_softirq(void); 2085c3921ab7SLinus Torvalds static inline int cond_resched_bkl(void) 2086c3921ab7SLinus Torvalds { 2087c3921ab7SLinus Torvalds return _cond_resched(); 2088c3921ab7SLinus Torvalds } 20891da177e4SLinus Torvalds 20901da177e4SLinus Torvalds /* 20911da177e4SLinus Torvalds * Does a critical section need to be broken due to another 209295c354feSNick Piggin * task waiting?: (technically does not depend on CONFIG_PREEMPT, 209395c354feSNick Piggin * but a general need for low latency) 20941da177e4SLinus Torvalds */ 209595c354feSNick Piggin static inline int spin_needbreak(spinlock_t *lock) 20961da177e4SLinus Torvalds { 209795c354feSNick Piggin #ifdef CONFIG_PREEMPT 209895c354feSNick Piggin return spin_is_contended(lock); 209995c354feSNick Piggin #else 21001da177e4SLinus Torvalds return 0; 210195c354feSNick Piggin #endif 21021da177e4SLinus Torvalds } 21031da177e4SLinus Torvalds 21047bb44adeSRoland McGrath /* 21057bb44adeSRoland McGrath * Reevaluate whether the task has signals pending delivery. 21067bb44adeSRoland McGrath * Wake the task if so. 21077bb44adeSRoland McGrath * This is required every time the blocked sigset_t changes. 21087bb44adeSRoland McGrath * callers must hold sighand->siglock. 21097bb44adeSRoland McGrath */ 21107bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t); 21111da177e4SLinus Torvalds extern void recalc_sigpending(void); 21121da177e4SLinus Torvalds 21131da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped); 21141da177e4SLinus Torvalds 21151da177e4SLinus Torvalds /* 21161da177e4SLinus Torvalds * Wrappers for p->thread_info->cpu access. No-op on UP. 21171da177e4SLinus Torvalds */ 21181da177e4SLinus Torvalds #ifdef CONFIG_SMP 21191da177e4SLinus Torvalds 21201da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 21211da177e4SLinus Torvalds { 2122a1261f54SAl Viro return task_thread_info(p)->cpu; 21231da177e4SLinus Torvalds } 21241da177e4SLinus Torvalds 2125c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu); 21261da177e4SLinus Torvalds 21271da177e4SLinus Torvalds #else 21281da177e4SLinus Torvalds 21291da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 21301da177e4SLinus Torvalds { 21311da177e4SLinus Torvalds return 0; 21321da177e4SLinus Torvalds } 21331da177e4SLinus Torvalds 21341da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu) 21351da177e4SLinus Torvalds { 21361da177e4SLinus Torvalds } 21371da177e4SLinus Torvalds 21381da177e4SLinus Torvalds #endif /* CONFIG_SMP */ 21391da177e4SLinus Torvalds 21401da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 21411da177e4SLinus Torvalds extern void arch_pick_mmap_layout(struct mm_struct *mm); 21421da177e4SLinus Torvalds #else 21431da177e4SLinus Torvalds static inline void arch_pick_mmap_layout(struct mm_struct *mm) 21441da177e4SLinus Torvalds { 21451da177e4SLinus Torvalds mm->mmap_base = TASK_UNMAPPED_BASE; 21461da177e4SLinus Torvalds mm->get_unmapped_area = arch_get_unmapped_area; 21471da177e4SLinus Torvalds mm->unmap_area = arch_unmap_area; 21481da177e4SLinus Torvalds } 21491da177e4SLinus Torvalds #endif 21501da177e4SLinus Torvalds 21511a3c3034SIngo Molnar #ifdef CONFIG_TRACING 21521a3c3034SIngo Molnar extern void 21531a3c3034SIngo Molnar __trace_special(void *__tr, void *__data, 21541a3c3034SIngo Molnar unsigned long arg1, unsigned long arg2, unsigned long arg3); 21551a3c3034SIngo Molnar #else 21561a3c3034SIngo Molnar static inline void 21571a3c3034SIngo Molnar __trace_special(void *__tr, void *__data, 21581a3c3034SIngo Molnar unsigned long arg1, unsigned long arg2, unsigned long arg3) 21591a3c3034SIngo Molnar { 21601a3c3034SIngo Molnar } 21611a3c3034SIngo Molnar #endif 21621a3c3034SIngo Molnar 2163b53e921bSMike Travis extern long sched_setaffinity(pid_t pid, const cpumask_t *new_mask); 21641da177e4SLinus Torvalds extern long sched_getaffinity(pid_t pid, cpumask_t *mask); 21651da177e4SLinus Torvalds 21665c45bf27SSiddha, Suresh B extern int sched_mc_power_savings, sched_smt_power_savings; 21675c45bf27SSiddha, Suresh B 21681da177e4SLinus Torvalds extern void normalize_rt_tasks(void); 21691da177e4SLinus Torvalds 2170052f1dc7SPeter Zijlstra #ifdef CONFIG_GROUP_SCHED 21719b5b7751SSrivatsa Vaddagiri 21724cf86d77SIngo Molnar extern struct task_group init_task_group; 2173eff766a6SPeter Zijlstra #ifdef CONFIG_USER_SCHED 2174eff766a6SPeter Zijlstra extern struct task_group root_task_group; 2175eff766a6SPeter Zijlstra #endif 21769b5b7751SSrivatsa Vaddagiri 2177ec7dc8acSDhaval Giani extern struct task_group *sched_create_group(struct task_group *parent); 21784cf86d77SIngo Molnar extern void sched_destroy_group(struct task_group *tg); 21799b5b7751SSrivatsa Vaddagiri extern void sched_move_task(struct task_struct *tsk); 2180052f1dc7SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED 21814cf86d77SIngo Molnar extern int sched_group_set_shares(struct task_group *tg, unsigned long shares); 21825cb350baSDhaval Giani extern unsigned long sched_group_shares(struct task_group *tg); 2183052f1dc7SPeter Zijlstra #endif 2184052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED 21859f0c1e56SPeter Zijlstra extern int sched_group_set_rt_runtime(struct task_group *tg, 21869f0c1e56SPeter Zijlstra long rt_runtime_us); 21879f0c1e56SPeter Zijlstra extern long sched_group_rt_runtime(struct task_group *tg); 2188d0b27fa7SPeter Zijlstra extern int sched_group_set_rt_period(struct task_group *tg, 2189d0b27fa7SPeter Zijlstra long rt_period_us); 2190d0b27fa7SPeter Zijlstra extern long sched_group_rt_period(struct task_group *tg); 2191052f1dc7SPeter Zijlstra #endif 21929b5b7751SSrivatsa Vaddagiri #endif 21939b5b7751SSrivatsa Vaddagiri 21944b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT 21954b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 21964b98d11bSAlexey Dobriyan { 21974b98d11bSAlexey Dobriyan tsk->rchar += amt; 21984b98d11bSAlexey Dobriyan } 21994b98d11bSAlexey Dobriyan 22004b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 22014b98d11bSAlexey Dobriyan { 22024b98d11bSAlexey Dobriyan tsk->wchar += amt; 22034b98d11bSAlexey Dobriyan } 22044b98d11bSAlexey Dobriyan 22054b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 22064b98d11bSAlexey Dobriyan { 22074b98d11bSAlexey Dobriyan tsk->syscr++; 22084b98d11bSAlexey Dobriyan } 22094b98d11bSAlexey Dobriyan 22104b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 22114b98d11bSAlexey Dobriyan { 22124b98d11bSAlexey Dobriyan tsk->syscw++; 22134b98d11bSAlexey Dobriyan } 22144b98d11bSAlexey Dobriyan #else 22154b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 22164b98d11bSAlexey Dobriyan { 22174b98d11bSAlexey Dobriyan } 22184b98d11bSAlexey Dobriyan 22194b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 22204b98d11bSAlexey Dobriyan { 22214b98d11bSAlexey Dobriyan } 22224b98d11bSAlexey Dobriyan 22234b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 22244b98d11bSAlexey Dobriyan { 22254b98d11bSAlexey Dobriyan } 22264b98d11bSAlexey Dobriyan 22274b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 22284b98d11bSAlexey Dobriyan { 22294b98d11bSAlexey Dobriyan } 22304b98d11bSAlexey Dobriyan #endif 22314b98d11bSAlexey Dobriyan 2232e6fe6649SAdrian Bunk #ifdef CONFIG_SMP 2233e6fe6649SAdrian Bunk void migration_init(void); 2234e6fe6649SAdrian Bunk #else 2235e6fe6649SAdrian Bunk static inline void migration_init(void) 2236e6fe6649SAdrian Bunk { 2237e6fe6649SAdrian Bunk } 2238e6fe6649SAdrian Bunk #endif 2239e6fe6649SAdrian Bunk 224082455257SDave Hansen #ifndef TASK_SIZE_OF 224182455257SDave Hansen #define TASK_SIZE_OF(tsk) TASK_SIZE 224282455257SDave Hansen #endif 224382455257SDave Hansen 2244cf475ad2SBalbir Singh #ifdef CONFIG_MM_OWNER 2245cf475ad2SBalbir Singh extern void mm_update_next_owner(struct mm_struct *mm); 2246cf475ad2SBalbir Singh extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p); 2247cf475ad2SBalbir Singh #else 2248cf475ad2SBalbir Singh static inline void mm_update_next_owner(struct mm_struct *mm) 2249cf475ad2SBalbir Singh { 2250cf475ad2SBalbir Singh } 2251cf475ad2SBalbir Singh 2252cf475ad2SBalbir Singh static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p) 2253cf475ad2SBalbir Singh { 2254cf475ad2SBalbir Singh } 2255cf475ad2SBalbir Singh #endif /* CONFIG_MM_OWNER */ 2256cf475ad2SBalbir Singh 22577c731e0aSSteven Rostedt #define TASK_STATE_TO_CHAR_STR "RSDTtZX" 22587c731e0aSSteven Rostedt 22591da177e4SLinus Torvalds #endif /* __KERNEL__ */ 22601da177e4SLinus Torvalds 22611da177e4SLinus Torvalds #endif 2262