11da177e4SLinus Torvalds #ifndef _LINUX_SCHED_H 21da177e4SLinus Torvalds #define _LINUX_SCHED_H 31da177e4SLinus Torvalds 4b7b3c76aSDavid Woodhouse /* 5b7b3c76aSDavid Woodhouse * cloning flags: 6b7b3c76aSDavid Woodhouse */ 7b7b3c76aSDavid Woodhouse #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */ 8b7b3c76aSDavid Woodhouse #define CLONE_VM 0x00000100 /* set if VM shared between processes */ 9b7b3c76aSDavid Woodhouse #define CLONE_FS 0x00000200 /* set if fs info shared between processes */ 10b7b3c76aSDavid Woodhouse #define CLONE_FILES 0x00000400 /* set if open files shared between processes */ 11b7b3c76aSDavid Woodhouse #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */ 12b7b3c76aSDavid Woodhouse #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */ 13b7b3c76aSDavid Woodhouse #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */ 14b7b3c76aSDavid Woodhouse #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */ 15b7b3c76aSDavid Woodhouse #define CLONE_THREAD 0x00010000 /* Same thread group? */ 16b7b3c76aSDavid Woodhouse #define CLONE_NEWNS 0x00020000 /* New namespace group? */ 17b7b3c76aSDavid Woodhouse #define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */ 18b7b3c76aSDavid Woodhouse #define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */ 19b7b3c76aSDavid Woodhouse #define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */ 20b7b3c76aSDavid Woodhouse #define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */ 21b7b3c76aSDavid Woodhouse #define CLONE_DETACHED 0x00400000 /* Unused, ignored */ 22b7b3c76aSDavid Woodhouse #define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */ 23b7b3c76aSDavid Woodhouse #define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */ 24b7b3c76aSDavid Woodhouse #define CLONE_STOPPED 0x02000000 /* Start in stopped state */ 25071df104SSerge E. Hallyn #define CLONE_NEWUTS 0x04000000 /* New utsname group? */ 2625b21cb2SKirill Korotaev #define CLONE_NEWIPC 0x08000000 /* New ipcs */ 2777ec739dSSerge E. Hallyn #define CLONE_NEWUSER 0x10000000 /* New user namespace */ 2830e49c26SPavel Emelyanov #define CLONE_NEWPID 0x20000000 /* New pid namespace */ 29169e3674SEric W. Biederman #define CLONE_NEWNET 0x40000000 /* New network namespace */ 30fadad878SJens Axboe #define CLONE_IO 0x80000000 /* Clone io context */ 31b7b3c76aSDavid Woodhouse 32b7b3c76aSDavid Woodhouse /* 33b7b3c76aSDavid Woodhouse * Scheduling policies 34b7b3c76aSDavid Woodhouse */ 35b7b3c76aSDavid Woodhouse #define SCHED_NORMAL 0 36b7b3c76aSDavid Woodhouse #define SCHED_FIFO 1 37b7b3c76aSDavid Woodhouse #define SCHED_RR 2 38b7b3c76aSDavid Woodhouse #define SCHED_BATCH 3 390e6aca43SIngo Molnar /* SCHED_ISO: reserved but not implemented yet */ 400e6aca43SIngo Molnar #define SCHED_IDLE 5 41ca94c442SLennart Poettering /* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */ 42ca94c442SLennart Poettering #define SCHED_RESET_ON_FORK 0x40000000 43b7b3c76aSDavid Woodhouse 44a3b6714eSDavid Woodhouse #ifdef __KERNEL__ 45b7b3c76aSDavid Woodhouse 46b7b3c76aSDavid Woodhouse struct sched_param { 47b7b3c76aSDavid Woodhouse int sched_priority; 48b7b3c76aSDavid Woodhouse }; 49b7b3c76aSDavid Woodhouse 501da177e4SLinus Torvalds #include <asm/param.h> /* for HZ */ 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds #include <linux/capability.h> 531da177e4SLinus Torvalds #include <linux/threads.h> 541da177e4SLinus Torvalds #include <linux/kernel.h> 551da177e4SLinus Torvalds #include <linux/types.h> 561da177e4SLinus Torvalds #include <linux/timex.h> 571da177e4SLinus Torvalds #include <linux/jiffies.h> 581da177e4SLinus Torvalds #include <linux/rbtree.h> 591da177e4SLinus Torvalds #include <linux/thread_info.h> 601da177e4SLinus Torvalds #include <linux/cpumask.h> 611da177e4SLinus Torvalds #include <linux/errno.h> 621da177e4SLinus Torvalds #include <linux/nodemask.h> 63c92ff1bdSMartin Schwidefsky #include <linux/mm_types.h> 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds #include <asm/system.h> 661da177e4SLinus Torvalds #include <asm/page.h> 671da177e4SLinus Torvalds #include <asm/ptrace.h> 681da177e4SLinus Torvalds #include <asm/cputime.h> 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds #include <linux/smp.h> 711da177e4SLinus Torvalds #include <linux/sem.h> 721da177e4SLinus Torvalds #include <linux/signal.h> 735ad4e53bSAl Viro #include <linux/path.h> 741da177e4SLinus Torvalds #include <linux/compiler.h> 751da177e4SLinus Torvalds #include <linux/completion.h> 761da177e4SLinus Torvalds #include <linux/pid.h> 771da177e4SLinus Torvalds #include <linux/percpu.h> 781da177e4SLinus Torvalds #include <linux/topology.h> 793e26c149SPeter Zijlstra #include <linux/proportions.h> 801da177e4SLinus Torvalds #include <linux/seccomp.h> 81e56d0903SIngo Molnar #include <linux/rcupdate.h> 8205725f7eSJiri Pirko #include <linux/rculist.h> 8323f78d4aSIngo Molnar #include <linux/rtmutex.h> 841da177e4SLinus Torvalds 85a3b6714eSDavid Woodhouse #include <linux/time.h> 86a3b6714eSDavid Woodhouse #include <linux/param.h> 87a3b6714eSDavid Woodhouse #include <linux/resource.h> 88a3b6714eSDavid Woodhouse #include <linux/timer.h> 89a3b6714eSDavid Woodhouse #include <linux/hrtimer.h> 907c3ab738SAndrew Morton #include <linux/task_io_accounting.h> 915cb350baSDhaval Giani #include <linux/kobject.h> 929745512cSArjan van de Ven #include <linux/latencytop.h> 939e2b2dc4SDavid Howells #include <linux/cred.h> 94a3b6714eSDavid Woodhouse 95a3b6714eSDavid Woodhouse #include <asm/processor.h> 9636d57ac4SH. J. Lu 971da177e4SLinus Torvalds struct exec_domain; 98c87e2837SIngo Molnar struct futex_pi_state; 99286100a6SAlexey Dobriyan struct robust_list_head; 100d89d8796SNeil Brown struct bio; 1015ad4e53bSAl Viro struct fs_struct; 102e2b371f0SMarkus Metzger struct bts_context; 103a63eaf34SPaul Mackerras struct perf_counter_context; 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds /* 1061da177e4SLinus Torvalds * List of flags we want to share for kernel threads, 1071da177e4SLinus Torvalds * if only because they are not used by them anyway. 1081da177e4SLinus Torvalds */ 1091da177e4SLinus Torvalds #define CLONE_KERNEL (CLONE_FS | CLONE_FILES | CLONE_SIGHAND) 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /* 1121da177e4SLinus Torvalds * These are the constant used to fake the fixed-point load-average 1131da177e4SLinus Torvalds * counting. Some notes: 1141da177e4SLinus Torvalds * - 11 bit fractions expand to 22 bits by the multiplies: this gives 1151da177e4SLinus Torvalds * a load-average precision of 10 bits integer + 11 bits fractional 1161da177e4SLinus Torvalds * - if you want to count load-averages more often, you need more 1171da177e4SLinus Torvalds * precision, or rounding will get you. With 2-second counting freq, 1181da177e4SLinus Torvalds * the EXP_n values would be 1981, 2034 and 2043 if still using only 1191da177e4SLinus Torvalds * 11 bit fractions. 1201da177e4SLinus Torvalds */ 1211da177e4SLinus Torvalds extern unsigned long avenrun[]; /* Load averages */ 1222d02494fSThomas Gleixner extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift); 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds #define FSHIFT 11 /* nr of bits of precision */ 1251da177e4SLinus Torvalds #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ 1260c2043abSLinus Torvalds #define LOAD_FREQ (5*HZ+1) /* 5 sec intervals */ 1271da177e4SLinus Torvalds #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ 1281da177e4SLinus Torvalds #define EXP_5 2014 /* 1/exp(5sec/5min) */ 1291da177e4SLinus Torvalds #define EXP_15 2037 /* 1/exp(5sec/15min) */ 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \ 1321da177e4SLinus Torvalds load *= exp; \ 1331da177e4SLinus Torvalds load += n*(FIXED_1-exp); \ 1341da177e4SLinus Torvalds load >>= FSHIFT; 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds extern unsigned long total_forks; 1371da177e4SLinus Torvalds extern int nr_threads; 1381da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts); 1391da177e4SLinus Torvalds extern int nr_processes(void); 1401da177e4SLinus Torvalds extern unsigned long nr_running(void); 1411da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void); 1421da177e4SLinus Torvalds extern unsigned long nr_iowait(void); 143dce48a84SThomas Gleixner extern void calc_global_load(void); 14423a185caSPaul Mackerras extern u64 cpu_nr_migrations(int cpu); 1451da177e4SLinus Torvalds 1467e49fcceSSteven Rostedt extern unsigned long get_parent_ip(unsigned long addr); 1477e49fcceSSteven Rostedt 14843ae34cbSIngo Molnar struct seq_file; 14943ae34cbSIngo Molnar struct cfs_rq; 1504cf86d77SIngo Molnar struct task_group; 15143ae34cbSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 15243ae34cbSIngo Molnar extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m); 15343ae34cbSIngo Molnar extern void proc_sched_set_task(struct task_struct *p); 15443ae34cbSIngo Molnar extern void 1555cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq); 15643ae34cbSIngo Molnar #else 15743ae34cbSIngo Molnar static inline void 15843ae34cbSIngo Molnar proc_sched_show_task(struct task_struct *p, struct seq_file *m) 15943ae34cbSIngo Molnar { 16043ae34cbSIngo Molnar } 16143ae34cbSIngo Molnar static inline void proc_sched_set_task(struct task_struct *p) 16243ae34cbSIngo Molnar { 16343ae34cbSIngo Molnar } 16443ae34cbSIngo Molnar static inline void 1655cef9ecaSIngo Molnar print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) 16643ae34cbSIngo Molnar { 16743ae34cbSIngo Molnar } 16843ae34cbSIngo Molnar #endif 1691da177e4SLinus Torvalds 170690229a0SIngo Molnar extern unsigned long long time_sync_thresh; 171690229a0SIngo Molnar 1724a8342d2SLinus Torvalds /* 1734a8342d2SLinus Torvalds * Task state bitmask. NOTE! These bits are also 1744a8342d2SLinus Torvalds * encoded in fs/proc/array.c: get_task_state(). 1754a8342d2SLinus Torvalds * 1764a8342d2SLinus Torvalds * We have two separate sets of flags: task->state 1774a8342d2SLinus Torvalds * is about runnability, while task->exit_state are 1784a8342d2SLinus Torvalds * about the task exiting. Confusing, but this way 1794a8342d2SLinus Torvalds * modifying one set can't modify the other one by 1804a8342d2SLinus Torvalds * mistake. 1814a8342d2SLinus Torvalds */ 1821da177e4SLinus Torvalds #define TASK_RUNNING 0 1831da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE 1 1841da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE 2 185f021a3c2SMatthew Wilcox #define __TASK_STOPPED 4 186f021a3c2SMatthew Wilcox #define __TASK_TRACED 8 1874a8342d2SLinus Torvalds /* in tsk->exit_state */ 1884a8342d2SLinus Torvalds #define EXIT_ZOMBIE 16 1894a8342d2SLinus Torvalds #define EXIT_DEAD 32 1904a8342d2SLinus Torvalds /* in tsk->state again */ 191af927232SMike Galbraith #define TASK_DEAD 64 192f021a3c2SMatthew Wilcox #define TASK_WAKEKILL 128 193f021a3c2SMatthew Wilcox 194f021a3c2SMatthew Wilcox /* Convenience macros for the sake of set_task_state */ 195f021a3c2SMatthew Wilcox #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) 196f021a3c2SMatthew Wilcox #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) 197f021a3c2SMatthew Wilcox #define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED) 1981da177e4SLinus Torvalds 19992a1f4bcSMatthew Wilcox /* Convenience macros for the sake of wake_up */ 20092a1f4bcSMatthew Wilcox #define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE) 201f021a3c2SMatthew Wilcox #define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED) 20292a1f4bcSMatthew Wilcox 20392a1f4bcSMatthew Wilcox /* get_task_state() */ 20492a1f4bcSMatthew Wilcox #define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \ 205f021a3c2SMatthew Wilcox TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \ 206f021a3c2SMatthew Wilcox __TASK_TRACED) 20792a1f4bcSMatthew Wilcox 208f021a3c2SMatthew Wilcox #define task_is_traced(task) ((task->state & __TASK_TRACED) != 0) 209f021a3c2SMatthew Wilcox #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0) 21092a1f4bcSMatthew Wilcox #define task_is_stopped_or_traced(task) \ 211f021a3c2SMatthew Wilcox ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0) 21292a1f4bcSMatthew Wilcox #define task_contributes_to_load(task) \ 213e3c8ca83SNathan Lynch ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \ 214e3c8ca83SNathan Lynch (task->flags & PF_FROZEN) == 0) 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds #define __set_task_state(tsk, state_value) \ 2171da177e4SLinus Torvalds do { (tsk)->state = (state_value); } while (0) 2181da177e4SLinus Torvalds #define set_task_state(tsk, state_value) \ 2191da177e4SLinus Torvalds set_mb((tsk)->state, (state_value)) 2201da177e4SLinus Torvalds 221498d0c57SAndrew Morton /* 222498d0c57SAndrew Morton * set_current_state() includes a barrier so that the write of current->state 223498d0c57SAndrew Morton * is correctly serialised wrt the caller's subsequent test of whether to 224498d0c57SAndrew Morton * actually sleep: 225498d0c57SAndrew Morton * 226498d0c57SAndrew Morton * set_current_state(TASK_UNINTERRUPTIBLE); 227498d0c57SAndrew Morton * if (do_i_need_to_sleep()) 228498d0c57SAndrew Morton * schedule(); 229498d0c57SAndrew Morton * 230498d0c57SAndrew Morton * If the caller does not need such serialisation then use __set_current_state() 231498d0c57SAndrew Morton */ 2321da177e4SLinus Torvalds #define __set_current_state(state_value) \ 2331da177e4SLinus Torvalds do { current->state = (state_value); } while (0) 2341da177e4SLinus Torvalds #define set_current_state(state_value) \ 2351da177e4SLinus Torvalds set_mb(current->state, (state_value)) 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds /* Task command name length */ 2381da177e4SLinus Torvalds #define TASK_COMM_LEN 16 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds #include <linux/spinlock.h> 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds /* 2431da177e4SLinus Torvalds * This serializes "schedule()" and also protects 2441da177e4SLinus Torvalds * the run-queue from deletions/modifications (but 2451da177e4SLinus Torvalds * _adding_ to the beginning of the run-queue has 2461da177e4SLinus Torvalds * a separate lock). 2471da177e4SLinus Torvalds */ 2481da177e4SLinus Torvalds extern rwlock_t tasklist_lock; 2491da177e4SLinus Torvalds extern spinlock_t mmlist_lock; 2501da177e4SLinus Torvalds 25136c8b586SIngo Molnar struct task_struct; 2521da177e4SLinus Torvalds 2531da177e4SLinus Torvalds extern void sched_init(void); 2541da177e4SLinus Torvalds extern void sched_init_smp(void); 2552d07b255SHarvey Harrison extern asmlinkage void schedule_tail(struct task_struct *prev); 25636c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu); 2571df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle); 2581da177e4SLinus Torvalds 259017730c1SIngo Molnar extern int runqueue_is_locked(void); 260ad474cacSOleg Nesterov extern void task_rq_unlock_wait(struct task_struct *p); 261017730c1SIngo Molnar 2626a7b3dc3SRusty Russell extern cpumask_var_t nohz_cpu_mask; 26346cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ) 26446cb4b7cSSiddha, Suresh B extern int select_nohz_load_balancer(int cpu); 265eea08f32SArun R Bharadwaj extern int get_nohz_load_balancer(void); 26646cb4b7cSSiddha, Suresh B #else 26746cb4b7cSSiddha, Suresh B static inline int select_nohz_load_balancer(int cpu) 26846cb4b7cSSiddha, Suresh B { 26946cb4b7cSSiddha, Suresh B return 0; 27046cb4b7cSSiddha, Suresh B } 27146cb4b7cSSiddha, Suresh B #endif 2721da177e4SLinus Torvalds 273e59e2ae2SIngo Molnar /* 27439bc89fdSIngo Molnar * Only dump TASK_* tasks. (0 for all tasks) 275e59e2ae2SIngo Molnar */ 276e59e2ae2SIngo Molnar extern void show_state_filter(unsigned long state_filter); 277e59e2ae2SIngo Molnar 278e59e2ae2SIngo Molnar static inline void show_state(void) 279e59e2ae2SIngo Molnar { 28039bc89fdSIngo Molnar show_state_filter(0); 281e59e2ae2SIngo Molnar } 282e59e2ae2SIngo Molnar 2831da177e4SLinus Torvalds extern void show_regs(struct pt_regs *); 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds /* 2861da177e4SLinus Torvalds * TASK is a pointer to the task whose backtrace we want to see (or NULL for current 2871da177e4SLinus Torvalds * task), SP is the stack pointer of the first frame that should be shown in the back 2881da177e4SLinus Torvalds * trace (or NULL if the entire call-chain of the task should be shown). 2891da177e4SLinus Torvalds */ 2901da177e4SLinus Torvalds extern void show_stack(struct task_struct *task, unsigned long *sp); 2911da177e4SLinus Torvalds 2921da177e4SLinus Torvalds void io_schedule(void); 2931da177e4SLinus Torvalds long io_schedule_timeout(long timeout); 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds extern void cpu_init (void); 2961da177e4SLinus Torvalds extern void trap_init(void); 2971da177e4SLinus Torvalds extern void update_process_times(int user); 2981da177e4SLinus Torvalds extern void scheduler_tick(void); 2991da177e4SLinus Torvalds 30082a1fcb9SIngo Molnar extern void sched_show_task(struct task_struct *p); 30182a1fcb9SIngo Molnar 3028446f1d3SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP 3036687a97dSIngo Molnar extern void softlockup_tick(void); 3048446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void); 30504c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void); 306baf48f65SMandeep Singh Baines extern int proc_dosoftlockup_thresh(struct ctl_table *table, int write, 307baf48f65SMandeep Singh Baines struct file *filp, void __user *buffer, 308baf48f65SMandeep Singh Baines size_t *lenp, loff_t *ppos); 3099c44bc03SIngo Molnar extern unsigned int softlockup_panic; 3109383d967SDimitri Sivanich extern int softlockup_thresh; 3118446f1d3SIngo Molnar #else 3126687a97dSIngo Molnar static inline void softlockup_tick(void) 3138446f1d3SIngo Molnar { 3148446f1d3SIngo Molnar } 3158446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void) 3168446f1d3SIngo Molnar { 3178446f1d3SIngo Molnar } 31804c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void) 31904c9167fSJeremy Fitzhardinge { 32004c9167fSJeremy Fitzhardinge } 3218446f1d3SIngo Molnar #endif 3228446f1d3SIngo Molnar 323e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK 324e162b39aSMandeep Singh Baines extern unsigned int sysctl_hung_task_panic; 325e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_check_count; 326e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_timeout_secs; 327e162b39aSMandeep Singh Baines extern unsigned long sysctl_hung_task_warnings; 328e162b39aSMandeep Singh Baines extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write, 329e162b39aSMandeep Singh Baines struct file *filp, void __user *buffer, 330e162b39aSMandeep Singh Baines size_t *lenp, loff_t *ppos); 331e162b39aSMandeep Singh Baines #endif 3328446f1d3SIngo Molnar 3331da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */ 3341da177e4SLinus Torvalds #define __sched __attribute__((__section__(".sched.text"))) 335deaf2227SIngo Molnar 336deaf2227SIngo Molnar /* Linker adds these: start and end of __sched functions */ 337deaf2227SIngo Molnar extern char __sched_text_start[], __sched_text_end[]; 338deaf2227SIngo Molnar 3391da177e4SLinus Torvalds /* Is this address in the __sched functions? */ 3401da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr); 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds #define MAX_SCHEDULE_TIMEOUT LONG_MAX 343b3c97528SHarvey Harrison extern signed long schedule_timeout(signed long timeout); 34464ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout); 345294d5cc2SMatthew Wilcox extern signed long schedule_timeout_killable(signed long timeout); 34664ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout); 34741719b03SPeter Zijlstra asmlinkage void __schedule(void); 3481da177e4SLinus Torvalds asmlinkage void schedule(void); 3490d66bf6dSPeter Zijlstra extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner); 3501da177e4SLinus Torvalds 351ab516013SSerge E. Hallyn struct nsproxy; 352acce292cSCedric Le Goater struct user_namespace; 3531da177e4SLinus Torvalds 354341c87bfSKAMEZAWA Hiroyuki /* 355341c87bfSKAMEZAWA Hiroyuki * Default maximum number of active map areas, this limits the number of vmas 356341c87bfSKAMEZAWA Hiroyuki * per mm struct. Users can overwrite this number by sysctl but there is a 357341c87bfSKAMEZAWA Hiroyuki * problem. 358341c87bfSKAMEZAWA Hiroyuki * 359341c87bfSKAMEZAWA Hiroyuki * When a program's coredump is generated as ELF format, a section is created 360341c87bfSKAMEZAWA Hiroyuki * per a vma. In ELF, the number of sections is represented in unsigned short. 361341c87bfSKAMEZAWA Hiroyuki * This means the number of sections should be smaller than 65535 at coredump. 362341c87bfSKAMEZAWA Hiroyuki * Because the kernel adds some informative sections to a image of program at 363341c87bfSKAMEZAWA Hiroyuki * generating coredump, we need some margin. The number of extra sections is 364341c87bfSKAMEZAWA Hiroyuki * 1-3 now and depends on arch. We use "5" as safe margin, here. 365341c87bfSKAMEZAWA Hiroyuki */ 366341c87bfSKAMEZAWA Hiroyuki #define MAPCOUNT_ELF_CORE_MARGIN (5) 367341c87bfSKAMEZAWA Hiroyuki #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN) 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds extern int sysctl_max_map_count; 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds #include <linux/aio.h> 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds extern unsigned long 3741da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long, 3751da177e4SLinus Torvalds unsigned long, unsigned long); 3761da177e4SLinus Torvalds extern unsigned long 3771da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr, 3781da177e4SLinus Torvalds unsigned long len, unsigned long pgoff, 3791da177e4SLinus Torvalds unsigned long flags); 3801363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long); 3811363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long); 3821da177e4SLinus Torvalds 383f7d0b926SJeremy Fitzhardinge #if USE_SPLIT_PTLOCKS 384f412ac08SHugh Dickins /* 385f412ac08SHugh Dickins * The mm counters are not protected by its page_table_lock, 386f412ac08SHugh Dickins * so must be incremented atomically. 387f412ac08SHugh Dickins */ 388d3cb4871SChristoph Lameter #define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value) 389d3cb4871SChristoph Lameter #define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member)) 390d3cb4871SChristoph Lameter #define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member) 391d3cb4871SChristoph Lameter #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member) 392d3cb4871SChristoph Lameter #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member) 393f412ac08SHugh Dickins 394f7d0b926SJeremy Fitzhardinge #else /* !USE_SPLIT_PTLOCKS */ 395f412ac08SHugh Dickins /* 396f412ac08SHugh Dickins * The mm counters are protected by its page_table_lock, 397f412ac08SHugh Dickins * so can be incremented directly. 398f412ac08SHugh Dickins */ 3991da177e4SLinus Torvalds #define set_mm_counter(mm, member, value) (mm)->_##member = (value) 4001da177e4SLinus Torvalds #define get_mm_counter(mm, member) ((mm)->_##member) 4011da177e4SLinus Torvalds #define add_mm_counter(mm, member, value) (mm)->_##member += (value) 4021da177e4SLinus Torvalds #define inc_mm_counter(mm, member) (mm)->_##member++ 4031da177e4SLinus Torvalds #define dec_mm_counter(mm, member) (mm)->_##member-- 4044294621fSHugh Dickins 405f7d0b926SJeremy Fitzhardinge #endif /* !USE_SPLIT_PTLOCKS */ 406f412ac08SHugh Dickins 407f412ac08SHugh Dickins #define get_mm_rss(mm) \ 408f412ac08SHugh Dickins (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss)) 409365e9c87SHugh Dickins #define update_hiwater_rss(mm) do { \ 410365e9c87SHugh Dickins unsigned long _rss = get_mm_rss(mm); \ 411365e9c87SHugh Dickins if ((mm)->hiwater_rss < _rss) \ 412365e9c87SHugh Dickins (mm)->hiwater_rss = _rss; \ 413365e9c87SHugh Dickins } while (0) 414365e9c87SHugh Dickins #define update_hiwater_vm(mm) do { \ 415365e9c87SHugh Dickins if ((mm)->hiwater_vm < (mm)->total_vm) \ 416365e9c87SHugh Dickins (mm)->hiwater_vm = (mm)->total_vm; \ 417365e9c87SHugh Dickins } while (0) 418365e9c87SHugh Dickins 4199de1581eSOleg Nesterov static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm) 4209de1581eSOleg Nesterov { 4219de1581eSOleg Nesterov return max(mm->hiwater_rss, get_mm_rss(mm)); 4229de1581eSOleg Nesterov } 4239de1581eSOleg Nesterov 4249de1581eSOleg Nesterov static inline unsigned long get_mm_hiwater_vm(struct mm_struct *mm) 4259de1581eSOleg Nesterov { 4269de1581eSOleg Nesterov return max(mm->hiwater_vm, mm->total_vm); 4279de1581eSOleg Nesterov } 428901608d9SOleg Nesterov 4296c5d5238SKawai, Hidehiro extern void set_dumpable(struct mm_struct *mm, int value); 4306c5d5238SKawai, Hidehiro extern int get_dumpable(struct mm_struct *mm); 4316c5d5238SKawai, Hidehiro 4326c5d5238SKawai, Hidehiro /* mm flags */ 4333cb4a0bbSKawai, Hidehiro /* dumpable bits */ 4346c5d5238SKawai, Hidehiro #define MMF_DUMPABLE 0 /* core dump is permitted */ 4356c5d5238SKawai, Hidehiro #define MMF_DUMP_SECURELY 1 /* core file is readable only by root */ 4363cb4a0bbSKawai, Hidehiro #define MMF_DUMPABLE_BITS 2 4373cb4a0bbSKawai, Hidehiro 4383cb4a0bbSKawai, Hidehiro /* coredump filter bits */ 4393cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_PRIVATE 2 4403cb4a0bbSKawai, Hidehiro #define MMF_DUMP_ANON_SHARED 3 4413cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_PRIVATE 4 4423cb4a0bbSKawai, Hidehiro #define MMF_DUMP_MAPPED_SHARED 5 44382df3973SRoland McGrath #define MMF_DUMP_ELF_HEADERS 6 444e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_PRIVATE 7 445e575f111SKOSAKI Motohiro #define MMF_DUMP_HUGETLB_SHARED 8 4463cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS 447e575f111SKOSAKI Motohiro #define MMF_DUMP_FILTER_BITS 7 4483cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_MASK \ 4493cb4a0bbSKawai, Hidehiro (((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT) 4503cb4a0bbSKawai, Hidehiro #define MMF_DUMP_FILTER_DEFAULT \ 451e575f111SKOSAKI Motohiro ((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED) |\ 452656eb2cdSRoland McGrath (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF) 453656eb2cdSRoland McGrath 454656eb2cdSRoland McGrath #ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS 455656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF (1 << MMF_DUMP_ELF_HEADERS) 456656eb2cdSRoland McGrath #else 457656eb2cdSRoland McGrath # define MMF_DUMP_MASK_DEFAULT_ELF 0 458656eb2cdSRoland McGrath #endif 4596c5d5238SKawai, Hidehiro 4601da177e4SLinus Torvalds struct sighand_struct { 4611da177e4SLinus Torvalds atomic_t count; 4621da177e4SLinus Torvalds struct k_sigaction action[_NSIG]; 4631da177e4SLinus Torvalds spinlock_t siglock; 464b8fceee1SDavide Libenzi wait_queue_head_t signalfd_wqh; 4651da177e4SLinus Torvalds }; 4661da177e4SLinus Torvalds 4670e464814SKaiGai Kohei struct pacct_struct { 468f6ec29a4SKaiGai Kohei int ac_flag; 469f6ec29a4SKaiGai Kohei long ac_exitcode; 4700e464814SKaiGai Kohei unsigned long ac_mem; 47177787bfbSKaiGai Kohei cputime_t ac_utime, ac_stime; 47277787bfbSKaiGai Kohei unsigned long ac_minflt, ac_majflt; 4730e464814SKaiGai Kohei }; 4740e464814SKaiGai Kohei 475f06febc9SFrank Mayhar /** 476f06febc9SFrank Mayhar * struct task_cputime - collected CPU time counts 477f06febc9SFrank Mayhar * @utime: time spent in user mode, in &cputime_t units 478f06febc9SFrank Mayhar * @stime: time spent in kernel mode, in &cputime_t units 479f06febc9SFrank Mayhar * @sum_exec_runtime: total time spent on the CPU, in nanoseconds 480f06febc9SFrank Mayhar * 481f06febc9SFrank Mayhar * This structure groups together three kinds of CPU time that are 482f06febc9SFrank Mayhar * tracked for threads and thread groups. Most things considering 483f06febc9SFrank Mayhar * CPU time want to group these counts together and treat all three 484f06febc9SFrank Mayhar * of them in parallel. 485f06febc9SFrank Mayhar */ 486f06febc9SFrank Mayhar struct task_cputime { 487f06febc9SFrank Mayhar cputime_t utime; 488f06febc9SFrank Mayhar cputime_t stime; 489f06febc9SFrank Mayhar unsigned long long sum_exec_runtime; 490f06febc9SFrank Mayhar }; 491f06febc9SFrank Mayhar /* Alternate field names when used to cache expirations. */ 492f06febc9SFrank Mayhar #define prof_exp stime 493f06febc9SFrank Mayhar #define virt_exp utime 494f06febc9SFrank Mayhar #define sched_exp sum_exec_runtime 495f06febc9SFrank Mayhar 4964cd4c1b4SPeter Zijlstra #define INIT_CPUTIME \ 4974cd4c1b4SPeter Zijlstra (struct task_cputime) { \ 4984cd4c1b4SPeter Zijlstra .utime = cputime_zero, \ 4994cd4c1b4SPeter Zijlstra .stime = cputime_zero, \ 5004cd4c1b4SPeter Zijlstra .sum_exec_runtime = 0, \ 5014cd4c1b4SPeter Zijlstra } 5024cd4c1b4SPeter Zijlstra 503c99e6efeSPeter Zijlstra /* 504c99e6efeSPeter Zijlstra * Disable preemption until the scheduler is running. 505c99e6efeSPeter Zijlstra * Reset by start_kernel()->sched_init()->init_idle(). 506d86ee480SPeter Zijlstra * 507d86ee480SPeter Zijlstra * We include PREEMPT_ACTIVE to avoid cond_resched() from working 508d86ee480SPeter Zijlstra * before the scheduler is active -- see should_resched(). 509c99e6efeSPeter Zijlstra */ 510d86ee480SPeter Zijlstra #define INIT_PREEMPT_COUNT (1 + PREEMPT_ACTIVE) 511c99e6efeSPeter Zijlstra 512f06febc9SFrank Mayhar /** 5134cd4c1b4SPeter Zijlstra * struct thread_group_cputimer - thread group interval timer counts 5144cd4c1b4SPeter Zijlstra * @cputime: thread group interval timers. 5154cd4c1b4SPeter Zijlstra * @running: non-zero when there are timers running and 5164cd4c1b4SPeter Zijlstra * @cputime receives updates. 5174cd4c1b4SPeter Zijlstra * @lock: lock for fields in this struct. 518f06febc9SFrank Mayhar * 519f06febc9SFrank Mayhar * This structure contains the version of task_cputime, above, that is 5204cd4c1b4SPeter Zijlstra * used for thread group CPU timer calculations. 521f06febc9SFrank Mayhar */ 5224cd4c1b4SPeter Zijlstra struct thread_group_cputimer { 5234cd4c1b4SPeter Zijlstra struct task_cputime cputime; 5244cd4c1b4SPeter Zijlstra int running; 5254cd4c1b4SPeter Zijlstra spinlock_t lock; 526f06febc9SFrank Mayhar }; 527f06febc9SFrank Mayhar 5281da177e4SLinus Torvalds /* 5291da177e4SLinus Torvalds * NOTE! "signal_struct" does not have it's own 5301da177e4SLinus Torvalds * locking, because a shared signal_struct always 5311da177e4SLinus Torvalds * implies a shared sighand_struct, so locking 5321da177e4SLinus Torvalds * sighand_struct is always a proper superset of 5331da177e4SLinus Torvalds * the locking of signal_struct. 5341da177e4SLinus Torvalds */ 5351da177e4SLinus Torvalds struct signal_struct { 5361da177e4SLinus Torvalds atomic_t count; 5371da177e4SLinus Torvalds atomic_t live; 5381da177e4SLinus Torvalds 5391da177e4SLinus Torvalds wait_queue_head_t wait_chldexit; /* for wait4() */ 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds /* current thread group signal load-balancing target: */ 54236c8b586SIngo Molnar struct task_struct *curr_target; 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds /* shared signal handling: */ 5451da177e4SLinus Torvalds struct sigpending shared_pending; 5461da177e4SLinus Torvalds 5471da177e4SLinus Torvalds /* thread group exit support */ 5481da177e4SLinus Torvalds int group_exit_code; 5491da177e4SLinus Torvalds /* overloaded: 5501da177e4SLinus Torvalds * - notify group_exit_task when ->count is equal to notify_count 5511da177e4SLinus Torvalds * - everyone except group_exit_task is stopped during signal delivery 5521da177e4SLinus Torvalds * of fatal signals, group_exit_task processes the signal. 5531da177e4SLinus Torvalds */ 5541da177e4SLinus Torvalds int notify_count; 55507dd20e0SRichard Kennedy struct task_struct *group_exit_task; 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds /* thread group stop support, overloads group_exit_code too */ 5581da177e4SLinus Torvalds int group_stop_count; 5591da177e4SLinus Torvalds unsigned int flags; /* see SIGNAL_* flags below */ 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds /* POSIX.1b Interval Timers */ 5621da177e4SLinus Torvalds struct list_head posix_timers; 5631da177e4SLinus Torvalds 5641da177e4SLinus Torvalds /* ITIMER_REAL timer for the process */ 5652ff678b8SThomas Gleixner struct hrtimer real_timer; 566fea9d175SOleg Nesterov struct pid *leader_pid; 5672ff678b8SThomas Gleixner ktime_t it_real_incr; 5681da177e4SLinus Torvalds 5691da177e4SLinus Torvalds /* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */ 5701da177e4SLinus Torvalds cputime_t it_prof_expires, it_virt_expires; 5711da177e4SLinus Torvalds cputime_t it_prof_incr, it_virt_incr; 5721da177e4SLinus Torvalds 573f06febc9SFrank Mayhar /* 5744cd4c1b4SPeter Zijlstra * Thread group totals for process CPU timers. 5754cd4c1b4SPeter Zijlstra * See thread_group_cputimer(), et al, for details. 576f06febc9SFrank Mayhar */ 5774cd4c1b4SPeter Zijlstra struct thread_group_cputimer cputimer; 578f06febc9SFrank Mayhar 579f06febc9SFrank Mayhar /* Earliest-expiration cache. */ 580f06febc9SFrank Mayhar struct task_cputime cputime_expires; 581f06febc9SFrank Mayhar 582f06febc9SFrank Mayhar struct list_head cpu_timers[3]; 583f06febc9SFrank Mayhar 584ab521dc0SEric W. Biederman struct pid *tty_old_pgrp; 5851ec320afSCedric Le Goater 5861da177e4SLinus Torvalds /* boolean value for session group leader */ 5871da177e4SLinus Torvalds int leader; 5881da177e4SLinus Torvalds 5891da177e4SLinus Torvalds struct tty_struct *tty; /* NULL if no tty */ 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds /* 5921da177e4SLinus Torvalds * Cumulative resource counters for dead threads in the group, 5931da177e4SLinus Torvalds * and for reaped dead child processes forked by this group. 5941da177e4SLinus Torvalds * Live threads maintain their own counters and add to these 5951da177e4SLinus Torvalds * in __exit_signal, except for the group leader. 5961da177e4SLinus Torvalds */ 59732bd671dSPeter Zijlstra cputime_t utime, stime, cutime, cstime; 5989ac52315SLaurent Vivier cputime_t gtime; 5999ac52315SLaurent Vivier cputime_t cgtime; 6001da177e4SLinus Torvalds unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; 6011da177e4SLinus Torvalds unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; 6026eaeeabaSEric Dumazet unsigned long inblock, oublock, cinblock, coublock; 603940389b8SAndrea Righi struct task_io_accounting ioac; 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds /* 60632bd671dSPeter Zijlstra * Cumulative ns of schedule CPU time fo dead threads in the 60732bd671dSPeter Zijlstra * group, not including a zombie group leader, (This only differs 60832bd671dSPeter Zijlstra * from jiffies_to_ns(utime + stime) if sched_clock uses something 60932bd671dSPeter Zijlstra * other than jiffies.) 61032bd671dSPeter Zijlstra */ 61132bd671dSPeter Zijlstra unsigned long long sum_sched_runtime; 61232bd671dSPeter Zijlstra 61332bd671dSPeter Zijlstra /* 6141da177e4SLinus Torvalds * We don't bother to synchronize most readers of this at all, 6151da177e4SLinus Torvalds * because there is no reader checking a limit that actually needs 6161da177e4SLinus Torvalds * to get both rlim_cur and rlim_max atomically, and either one 6171da177e4SLinus Torvalds * alone is a single word that can safely be read normally. 6181da177e4SLinus Torvalds * getrlimit/setrlimit use task_lock(current->group_leader) to 6191da177e4SLinus Torvalds * protect this instead of the siglock, because they really 6201da177e4SLinus Torvalds * have no need to disable irqs. 6211da177e4SLinus Torvalds */ 6221da177e4SLinus Torvalds struct rlimit rlim[RLIM_NLIMITS]; 6231da177e4SLinus Torvalds 6240e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT 6250e464814SKaiGai Kohei struct pacct_struct pacct; /* per-process accounting information */ 6260e464814SKaiGai Kohei #endif 627ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS 628ad4ecbcbSShailabh Nagar struct taskstats *stats; 629ad4ecbcbSShailabh Nagar #endif 630522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT 631522ed776SMiloslav Trmac unsigned audit_tty; 632522ed776SMiloslav Trmac struct tty_audit_buf *tty_audit_buf; 633522ed776SMiloslav Trmac #endif 6341da177e4SLinus Torvalds }; 6351da177e4SLinus Torvalds 6364866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */ 6374866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW 6384866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW 6394866cde0SNick Piggin #endif 6404866cde0SNick Piggin 6411da177e4SLinus Torvalds /* 6421da177e4SLinus Torvalds * Bits in flags field of signal_struct. 6431da177e4SLinus Torvalds */ 6441da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */ 6451da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED 0x00000002 /* stop signal dequeued */ 6461da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */ 6471da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */ 648e4420551SOleg Nesterov /* 649e4420551SOleg Nesterov * Pending notifications to parent. 650e4420551SOleg Nesterov */ 651e4420551SOleg Nesterov #define SIGNAL_CLD_STOPPED 0x00000010 652e4420551SOleg Nesterov #define SIGNAL_CLD_CONTINUED 0x00000020 653e4420551SOleg Nesterov #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED) 6541da177e4SLinus Torvalds 655fae5fa44SOleg Nesterov #define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */ 656fae5fa44SOleg Nesterov 657ed5d2cacSOleg Nesterov /* If true, all threads except ->group_exit_task have pending SIGKILL */ 658ed5d2cacSOleg Nesterov static inline int signal_group_exit(const struct signal_struct *sig) 659ed5d2cacSOleg Nesterov { 660ed5d2cacSOleg Nesterov return (sig->flags & SIGNAL_GROUP_EXIT) || 661ed5d2cacSOleg Nesterov (sig->group_exit_task != NULL); 662ed5d2cacSOleg Nesterov } 663ed5d2cacSOleg Nesterov 6641da177e4SLinus Torvalds /* 6651da177e4SLinus Torvalds * Some day this will be a full-fledged user tracking system.. 6661da177e4SLinus Torvalds */ 6671da177e4SLinus Torvalds struct user_struct { 6681da177e4SLinus Torvalds atomic_t __count; /* reference count */ 6691da177e4SLinus Torvalds atomic_t processes; /* How many processes does this user have? */ 6701da177e4SLinus Torvalds atomic_t files; /* How many open files does this user have? */ 6711da177e4SLinus Torvalds atomic_t sigpending; /* How many pending signals does this user have? */ 6722d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 6730eeca283SRobert Love atomic_t inotify_watches; /* How many inotify watches does this user have? */ 6740eeca283SRobert Love atomic_t inotify_devs; /* How many inotify devs does this user have opened? */ 6750eeca283SRobert Love #endif 6767ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL 6777ef9964eSDavide Libenzi atomic_t epoll_watches; /* The number of file descriptors currently watched */ 6787ef9964eSDavide Libenzi #endif 679970a8645SAlexey Dobriyan #ifdef CONFIG_POSIX_MQUEUE 6801da177e4SLinus Torvalds /* protected by mq_lock */ 6811da177e4SLinus Torvalds unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */ 682970a8645SAlexey Dobriyan #endif 6831da177e4SLinus Torvalds unsigned long locked_shm; /* How many pages of mlocked shm ? */ 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds #ifdef CONFIG_KEYS 6861da177e4SLinus Torvalds struct key *uid_keyring; /* UID specific keyring */ 6871da177e4SLinus Torvalds struct key *session_keyring; /* UID's default session keyring */ 6881da177e4SLinus Torvalds #endif 6891da177e4SLinus Torvalds 6901da177e4SLinus Torvalds /* Hash table maintenance information */ 691735de223SPavel Emelyanov struct hlist_node uidhash_node; 6921da177e4SLinus Torvalds uid_t uid; 69318b6e041SSerge Hallyn struct user_namespace *user_ns; 69424e377a8SSrivatsa Vaddagiri 695052f1dc7SPeter Zijlstra #ifdef CONFIG_USER_SCHED 6964cf86d77SIngo Molnar struct task_group *tg; 697b1a8c172SDhaval Giani #ifdef CONFIG_SYSFS 698eb41d946SKay Sievers struct kobject kobj; 6993959214fSKay Sievers struct delayed_work work; 70024e377a8SSrivatsa Vaddagiri #endif 701b1a8c172SDhaval Giani #endif 702789f90fcSPeter Zijlstra 703789f90fcSPeter Zijlstra #ifdef CONFIG_PERF_COUNTERS 704789f90fcSPeter Zijlstra atomic_long_t locked_vm; 705789f90fcSPeter Zijlstra #endif 7061da177e4SLinus Torvalds }; 7071da177e4SLinus Torvalds 708eb41d946SKay Sievers extern int uids_sysfs_init(void); 7095cb350baSDhaval Giani 7101da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t); 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds extern struct user_struct root_user; 7131da177e4SLinus Torvalds #define INIT_USER (&root_user) 7141da177e4SLinus Torvalds 715b6dff3ecSDavid Howells 7161da177e4SLinus Torvalds struct backing_dev_info; 7171da177e4SLinus Torvalds struct reclaim_state; 7181da177e4SLinus Torvalds 71952f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 7201da177e4SLinus Torvalds struct sched_info { 7211da177e4SLinus Torvalds /* cumulative counters */ 7222d72376bSIngo Molnar unsigned long pcount; /* # of times run on this cpu */ 7239c2c4802SKen Chen unsigned long long run_delay; /* time spent waiting on a runqueue */ 7241da177e4SLinus Torvalds 7251da177e4SLinus Torvalds /* timestamps */ 726172ba844SBalbir Singh unsigned long long last_arrival,/* when we last ran on a cpu */ 7271da177e4SLinus Torvalds last_queued; /* when we were last queued to run */ 728b8efb561SIngo Molnar #ifdef CONFIG_SCHEDSTATS 729b8efb561SIngo Molnar /* BKL stats */ 730480b9434SKen Chen unsigned int bkl_count; 731b8efb561SIngo Molnar #endif 7321da177e4SLinus Torvalds }; 73352f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */ 7341da177e4SLinus Torvalds 735ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 736ca74e92bSShailabh Nagar struct task_delay_info { 737ca74e92bSShailabh Nagar spinlock_t lock; 738ca74e92bSShailabh Nagar unsigned int flags; /* Private per-task flags */ 739ca74e92bSShailabh Nagar 740ca74e92bSShailabh Nagar /* For each stat XXX, add following, aligned appropriately 741ca74e92bSShailabh Nagar * 742ca74e92bSShailabh Nagar * struct timespec XXX_start, XXX_end; 743ca74e92bSShailabh Nagar * u64 XXX_delay; 744ca74e92bSShailabh Nagar * u32 XXX_count; 745ca74e92bSShailabh Nagar * 746ca74e92bSShailabh Nagar * Atomicity of updates to XXX_delay, XXX_count protected by 747ca74e92bSShailabh Nagar * single lock above (split into XXX_lock if contention is an issue). 748ca74e92bSShailabh Nagar */ 7490ff92245SShailabh Nagar 7500ff92245SShailabh Nagar /* 7510ff92245SShailabh Nagar * XXX_count is incremented on every XXX operation, the delay 7520ff92245SShailabh Nagar * associated with the operation is added to XXX_delay. 7530ff92245SShailabh Nagar * XXX_delay contains the accumulated delay time in nanoseconds. 7540ff92245SShailabh Nagar */ 7550ff92245SShailabh Nagar struct timespec blkio_start, blkio_end; /* Shared by blkio, swapin */ 7560ff92245SShailabh Nagar u64 blkio_delay; /* wait for sync block io completion */ 7570ff92245SShailabh Nagar u64 swapin_delay; /* wait for swapin block io completion */ 7580ff92245SShailabh Nagar u32 blkio_count; /* total count of the number of sync block */ 7590ff92245SShailabh Nagar /* io operations performed */ 7600ff92245SShailabh Nagar u32 swapin_count; /* total count of the number of swapin block */ 7610ff92245SShailabh Nagar /* io operations performed */ 762873b4771SKeika Kobayashi 763873b4771SKeika Kobayashi struct timespec freepages_start, freepages_end; 764873b4771SKeika Kobayashi u64 freepages_delay; /* wait for memory reclaim */ 765873b4771SKeika Kobayashi u32 freepages_count; /* total count of memory reclaim */ 766ca74e92bSShailabh Nagar }; 76752f17b6cSChandra Seetharaman #endif /* CONFIG_TASK_DELAY_ACCT */ 76852f17b6cSChandra Seetharaman 76952f17b6cSChandra Seetharaman static inline int sched_info_on(void) 77052f17b6cSChandra Seetharaman { 77152f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS 77252f17b6cSChandra Seetharaman return 1; 77352f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT) 77452f17b6cSChandra Seetharaman extern int delayacct_on; 77552f17b6cSChandra Seetharaman return delayacct_on; 77652f17b6cSChandra Seetharaman #else 77752f17b6cSChandra Seetharaman return 0; 778ca74e92bSShailabh Nagar #endif 77952f17b6cSChandra Seetharaman } 780ca74e92bSShailabh Nagar 781d15bcfdbSIngo Molnar enum cpu_idle_type { 782d15bcfdbSIngo Molnar CPU_IDLE, 783d15bcfdbSIngo Molnar CPU_NOT_IDLE, 784d15bcfdbSIngo Molnar CPU_NEWLY_IDLE, 785d15bcfdbSIngo Molnar CPU_MAX_IDLE_TYPES 7861da177e4SLinus Torvalds }; 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds /* 7891da177e4SLinus Torvalds * sched-domains (multiprocessor balancing) declarations: 7901da177e4SLinus Torvalds */ 7919aa7b369SIngo Molnar 7929aa7b369SIngo Molnar /* 7939aa7b369SIngo Molnar * Increase resolution of nice-level calculations: 7949aa7b369SIngo Molnar */ 7959aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT 10 7969aa7b369SIngo Molnar #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT) 7979aa7b369SIngo Molnar 798f8700df7SSuresh Siddha #define SCHED_LOAD_SCALE_FUZZ SCHED_LOAD_SCALE 7991da177e4SLinus Torvalds 8002dd73a4fSPeter Williams #ifdef CONFIG_SMP 8011da177e4SLinus Torvalds #define SD_LOAD_BALANCE 1 /* Do load balancing on this domain. */ 8021da177e4SLinus Torvalds #define SD_BALANCE_NEWIDLE 2 /* Balance when about to become idle */ 8031da177e4SLinus Torvalds #define SD_BALANCE_EXEC 4 /* Balance on exec */ 804147cbb4bSNick Piggin #define SD_BALANCE_FORK 8 /* Balance on fork, clone */ 805147cbb4bSNick Piggin #define SD_WAKE_IDLE 16 /* Wake to idle CPU on task wakeup */ 806147cbb4bSNick Piggin #define SD_WAKE_AFFINE 32 /* Wake task to waking CPU */ 807147cbb4bSNick Piggin #define SD_WAKE_BALANCE 64 /* Perform balancing at task wakeup */ 808147cbb4bSNick Piggin #define SD_SHARE_CPUPOWER 128 /* Domain members share cpu power */ 8095c45bf27SSiddha, Suresh B #define SD_POWERSAVINGS_BALANCE 256 /* Balance for power savings */ 81089c4710eSSiddha, Suresh B #define SD_SHARE_PKG_RESOURCES 512 /* Domain members share cpu pkg resources */ 81108c183f3SChristoph Lameter #define SD_SERIALIZE 1024 /* Only a single load balancing instance */ 8121d3504fcSHidetoshi Seto #define SD_WAKE_IDLE_FAR 2048 /* Gain latency sacrificing cache hit */ 8135c45bf27SSiddha, Suresh B 814afb8a9b7SGautham R Shenoy enum powersavings_balance_level { 815afb8a9b7SGautham R Shenoy POWERSAVINGS_BALANCE_NONE = 0, /* No power saving load balance */ 816afb8a9b7SGautham R Shenoy POWERSAVINGS_BALANCE_BASIC, /* Fill one thread/core/package 817afb8a9b7SGautham R Shenoy * first for long running threads 818afb8a9b7SGautham R Shenoy */ 819afb8a9b7SGautham R Shenoy POWERSAVINGS_BALANCE_WAKEUP, /* Also bias task wakeups to semi-idle 820afb8a9b7SGautham R Shenoy * cpu package for power savings 821afb8a9b7SGautham R Shenoy */ 822afb8a9b7SGautham R Shenoy MAX_POWERSAVINGS_BALANCE_LEVELS 823afb8a9b7SGautham R Shenoy }; 82489c4710eSSiddha, Suresh B 825716707b2SVaidyanathan Srinivasan extern int sched_mc_power_savings, sched_smt_power_savings; 82689c4710eSSiddha, Suresh B 827716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_mc_power(void) 828716707b2SVaidyanathan Srinivasan { 829716707b2SVaidyanathan Srinivasan if (sched_smt_power_savings) 830716707b2SVaidyanathan Srinivasan return SD_POWERSAVINGS_BALANCE; 8315c45bf27SSiddha, Suresh B 832716707b2SVaidyanathan Srinivasan return 0; 833716707b2SVaidyanathan Srinivasan } 834716707b2SVaidyanathan Srinivasan 835716707b2SVaidyanathan Srinivasan static inline int sd_balance_for_package_power(void) 836716707b2SVaidyanathan Srinivasan { 837716707b2SVaidyanathan Srinivasan if (sched_mc_power_savings | sched_smt_power_savings) 838716707b2SVaidyanathan Srinivasan return SD_POWERSAVINGS_BALANCE; 839716707b2SVaidyanathan Srinivasan 840716707b2SVaidyanathan Srinivasan return 0; 841716707b2SVaidyanathan Srinivasan } 8421da177e4SLinus Torvalds 843100fdaeeSVaidyanathan Srinivasan /* 844100fdaeeSVaidyanathan Srinivasan * Optimise SD flags for power savings: 845100fdaeeSVaidyanathan Srinivasan * SD_BALANCE_NEWIDLE helps agressive task consolidation and power savings. 846100fdaeeSVaidyanathan Srinivasan * Keep default SD flags if sched_{smt,mc}_power_saving=0 847100fdaeeSVaidyanathan Srinivasan */ 848100fdaeeSVaidyanathan Srinivasan 849100fdaeeSVaidyanathan Srinivasan static inline int sd_power_saving_flags(void) 850100fdaeeSVaidyanathan Srinivasan { 851100fdaeeSVaidyanathan Srinivasan if (sched_mc_power_savings | sched_smt_power_savings) 852100fdaeeSVaidyanathan Srinivasan return SD_BALANCE_NEWIDLE; 853100fdaeeSVaidyanathan Srinivasan 854100fdaeeSVaidyanathan Srinivasan return 0; 855100fdaeeSVaidyanathan Srinivasan } 8561da177e4SLinus Torvalds 8571da177e4SLinus Torvalds struct sched_group { 8581da177e4SLinus Torvalds struct sched_group *next; /* Must be a circular list */ 8591da177e4SLinus Torvalds 8601da177e4SLinus Torvalds /* 8611da177e4SLinus Torvalds * CPU power of this group, SCHED_LOAD_SCALE being max power for a 8621da177e4SLinus Torvalds * single CPU. This is read only (except for setup, hotplug CPU). 8635517d86bSEric Dumazet * Note : Never change cpu_power without recompute its reciprocal 8641da177e4SLinus Torvalds */ 8655517d86bSEric Dumazet unsigned int __cpu_power; 8665517d86bSEric Dumazet /* 8675517d86bSEric Dumazet * reciprocal value of cpu_power to avoid expensive divides 8685517d86bSEric Dumazet * (see include/linux/reciprocal_div.h) 8695517d86bSEric Dumazet */ 8705517d86bSEric Dumazet u32 reciprocal_cpu_power; 8716c99e9adSRusty Russell 8724200efd9SIngo Molnar /* 8734200efd9SIngo Molnar * The CPUs this group covers. 8744200efd9SIngo Molnar * 8754200efd9SIngo Molnar * NOTE: this field is variable length. (Allocated dynamically 8764200efd9SIngo Molnar * by attaching extra space to the end of the structure, 8774200efd9SIngo Molnar * depending on how many CPUs the kernel has booted up with) 8784200efd9SIngo Molnar * 8794200efd9SIngo Molnar * It is also be embedded into static data structures at build 8804200efd9SIngo Molnar * time. (See 'struct static_sched_group' in kernel/sched.c) 8814200efd9SIngo Molnar */ 8824200efd9SIngo Molnar unsigned long cpumask[0]; 8831da177e4SLinus Torvalds }; 8841da177e4SLinus Torvalds 885758b2cdcSRusty Russell static inline struct cpumask *sched_group_cpus(struct sched_group *sg) 886758b2cdcSRusty Russell { 8876c99e9adSRusty Russell return to_cpumask(sg->cpumask); 888758b2cdcSRusty Russell } 889758b2cdcSRusty Russell 8901d3504fcSHidetoshi Seto enum sched_domain_level { 8911d3504fcSHidetoshi Seto SD_LV_NONE = 0, 8921d3504fcSHidetoshi Seto SD_LV_SIBLING, 8931d3504fcSHidetoshi Seto SD_LV_MC, 8941d3504fcSHidetoshi Seto SD_LV_CPU, 8951d3504fcSHidetoshi Seto SD_LV_NODE, 8961d3504fcSHidetoshi Seto SD_LV_ALLNODES, 8971d3504fcSHidetoshi Seto SD_LV_MAX 8981d3504fcSHidetoshi Seto }; 8991d3504fcSHidetoshi Seto 9001d3504fcSHidetoshi Seto struct sched_domain_attr { 9011d3504fcSHidetoshi Seto int relax_domain_level; 9021d3504fcSHidetoshi Seto }; 9031d3504fcSHidetoshi Seto 9041d3504fcSHidetoshi Seto #define SD_ATTR_INIT (struct sched_domain_attr) { \ 9051d3504fcSHidetoshi Seto .relax_domain_level = -1, \ 9061d3504fcSHidetoshi Seto } 9071d3504fcSHidetoshi Seto 9081da177e4SLinus Torvalds struct sched_domain { 9091da177e4SLinus Torvalds /* These fields must be setup */ 9101da177e4SLinus Torvalds struct sched_domain *parent; /* top domain must be null terminated */ 9111a848870SSiddha, Suresh B struct sched_domain *child; /* bottom domain must be null terminated */ 9121da177e4SLinus Torvalds struct sched_group *groups; /* the balancing groups of the domain */ 9131da177e4SLinus Torvalds unsigned long min_interval; /* Minimum balance interval ms */ 9141da177e4SLinus Torvalds unsigned long max_interval; /* Maximum balance interval ms */ 9151da177e4SLinus Torvalds unsigned int busy_factor; /* less balancing by factor if busy */ 9161da177e4SLinus Torvalds unsigned int imbalance_pct; /* No balance until over watermark */ 9171da177e4SLinus Torvalds unsigned int cache_nice_tries; /* Leave cache hot tasks for # tries */ 9187897986bSNick Piggin unsigned int busy_idx; 9197897986bSNick Piggin unsigned int idle_idx; 9207897986bSNick Piggin unsigned int newidle_idx; 9217897986bSNick Piggin unsigned int wake_idx; 922147cbb4bSNick Piggin unsigned int forkexec_idx; 9231da177e4SLinus Torvalds int flags; /* See SD_* */ 9241d3504fcSHidetoshi Seto enum sched_domain_level level; 9251da177e4SLinus Torvalds 9261da177e4SLinus Torvalds /* Runtime fields. */ 9271da177e4SLinus Torvalds unsigned long last_balance; /* init to jiffies. units in jiffies */ 9281da177e4SLinus Torvalds unsigned int balance_interval; /* initialise to 1. units in ms. */ 9291da177e4SLinus Torvalds unsigned int nr_balance_failed; /* initialise to 0 */ 9301da177e4SLinus Torvalds 9312398f2c6SPeter Zijlstra u64 last_update; 9322398f2c6SPeter Zijlstra 9331da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS 9341da177e4SLinus Torvalds /* load_balance() stats */ 935480b9434SKen Chen unsigned int lb_count[CPU_MAX_IDLE_TYPES]; 936480b9434SKen Chen unsigned int lb_failed[CPU_MAX_IDLE_TYPES]; 937480b9434SKen Chen unsigned int lb_balanced[CPU_MAX_IDLE_TYPES]; 938480b9434SKen Chen unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES]; 939480b9434SKen Chen unsigned int lb_gained[CPU_MAX_IDLE_TYPES]; 940480b9434SKen Chen unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES]; 941480b9434SKen Chen unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES]; 942480b9434SKen Chen unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES]; 9431da177e4SLinus Torvalds 9441da177e4SLinus Torvalds /* Active load balancing */ 945480b9434SKen Chen unsigned int alb_count; 946480b9434SKen Chen unsigned int alb_failed; 947480b9434SKen Chen unsigned int alb_pushed; 9481da177e4SLinus Torvalds 94968767a0aSNick Piggin /* SD_BALANCE_EXEC stats */ 950480b9434SKen Chen unsigned int sbe_count; 951480b9434SKen Chen unsigned int sbe_balanced; 952480b9434SKen Chen unsigned int sbe_pushed; 9531da177e4SLinus Torvalds 95468767a0aSNick Piggin /* SD_BALANCE_FORK stats */ 955480b9434SKen Chen unsigned int sbf_count; 956480b9434SKen Chen unsigned int sbf_balanced; 957480b9434SKen Chen unsigned int sbf_pushed; 95868767a0aSNick Piggin 9591da177e4SLinus Torvalds /* try_to_wake_up() stats */ 960480b9434SKen Chen unsigned int ttwu_wake_remote; 961480b9434SKen Chen unsigned int ttwu_move_affine; 962480b9434SKen Chen unsigned int ttwu_move_balance; 9631da177e4SLinus Torvalds #endif 964a5d8c348SIngo Molnar #ifdef CONFIG_SCHED_DEBUG 965a5d8c348SIngo Molnar char *name; 966a5d8c348SIngo Molnar #endif 9676c99e9adSRusty Russell 9684200efd9SIngo Molnar /* 9694200efd9SIngo Molnar * Span of all CPUs in this domain. 9704200efd9SIngo Molnar * 9714200efd9SIngo Molnar * NOTE: this field is variable length. (Allocated dynamically 9724200efd9SIngo Molnar * by attaching extra space to the end of the structure, 9734200efd9SIngo Molnar * depending on how many CPUs the kernel has booted up with) 9744200efd9SIngo Molnar * 9754200efd9SIngo Molnar * It is also be embedded into static data structures at build 9764200efd9SIngo Molnar * time. (See 'struct static_sched_domain' in kernel/sched.c) 9774200efd9SIngo Molnar */ 9784200efd9SIngo Molnar unsigned long span[0]; 9791da177e4SLinus Torvalds }; 9801da177e4SLinus Torvalds 981758b2cdcSRusty Russell static inline struct cpumask *sched_domain_span(struct sched_domain *sd) 982758b2cdcSRusty Russell { 9836c99e9adSRusty Russell return to_cpumask(sd->span); 984758b2cdcSRusty Russell } 985758b2cdcSRusty Russell 98696f874e2SRusty Russell extern void partition_sched_domains(int ndoms_new, struct cpumask *doms_new, 9871d3504fcSHidetoshi Seto struct sched_domain_attr *dattr_new); 988029190c5SPaul Jackson 98906aaf76aSIngo Molnar /* Test a flag in parent sched domain */ 99006aaf76aSIngo Molnar static inline int test_sd_parent(struct sched_domain *sd, int flag) 99106aaf76aSIngo Molnar { 99206aaf76aSIngo Molnar if (sd->parent && (sd->parent->flags & flag)) 99306aaf76aSIngo Molnar return 1; 99406aaf76aSIngo Molnar 99506aaf76aSIngo Molnar return 0; 99606aaf76aSIngo Molnar } 9971da177e4SLinus Torvalds 9981b427c15SIngo Molnar #else /* CONFIG_SMP */ 9991da177e4SLinus Torvalds 10001b427c15SIngo Molnar struct sched_domain_attr; 10011b427c15SIngo Molnar 10021b427c15SIngo Molnar static inline void 100396f874e2SRusty Russell partition_sched_domains(int ndoms_new, struct cpumask *doms_new, 10041b427c15SIngo Molnar struct sched_domain_attr *dattr_new) 1005d02c7a8cSCon Kolivas { 1006d02c7a8cSCon Kolivas } 10071b427c15SIngo Molnar #endif /* !CONFIG_SMP */ 10081da177e4SLinus Torvalds 10091da177e4SLinus Torvalds struct io_context; /* See blkdev.h */ 10101da177e4SLinus Torvalds 10111da177e4SLinus Torvalds 1012383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK 101336c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t); 1014383f2835SChen, Kenneth W #else 1015383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { } 1016383f2835SChen, Kenneth W #endif 10171da177e4SLinus Torvalds 10181da177e4SLinus Torvalds struct audit_context; /* See audit.c */ 10191da177e4SLinus Torvalds struct mempolicy; 1020b92ce558SJens Axboe struct pipe_inode_info; 10214865ecf1SSerge E. Hallyn struct uts_namespace; 10221da177e4SLinus Torvalds 102320b8a59fSIngo Molnar struct rq; 102420b8a59fSIngo Molnar struct sched_domain; 102520b8a59fSIngo Molnar 102620b8a59fSIngo Molnar struct sched_class { 10275522d5d5SIngo Molnar const struct sched_class *next; 102820b8a59fSIngo Molnar 1029fd390f6aSIngo Molnar void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup); 1030f02231e5SIngo Molnar void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep); 10314530d7abSDmitry Adamushko void (*yield_task) (struct rq *rq); 103220b8a59fSIngo Molnar 103315afe09bSPeter Zijlstra void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int sync); 103420b8a59fSIngo Molnar 1035fb8d4724SIngo Molnar struct task_struct * (*pick_next_task) (struct rq *rq); 103631ee529cSIngo Molnar void (*put_prev_task) (struct rq *rq, struct task_struct *p); 103720b8a59fSIngo Molnar 1038681f3e68SPeter Williams #ifdef CONFIG_SMP 10394ce72a2cSLi Zefan int (*select_task_rq)(struct task_struct *p, int sync); 10404ce72a2cSLi Zefan 104143010659SPeter Williams unsigned long (*load_balance) (struct rq *this_rq, int this_cpu, 1042e1d1484fSPeter Williams struct rq *busiest, unsigned long max_load_move, 104320b8a59fSIngo Molnar struct sched_domain *sd, enum cpu_idle_type idle, 1044a4ac01c3SPeter Williams int *all_pinned, int *this_best_prio); 104520b8a59fSIngo Molnar 1046e1d1484fSPeter Williams int (*move_one_task) (struct rq *this_rq, int this_cpu, 1047e1d1484fSPeter Williams struct rq *busiest, struct sched_domain *sd, 1048e1d1484fSPeter Williams enum cpu_idle_type idle); 10499a897c5aSSteven Rostedt void (*pre_schedule) (struct rq *this_rq, struct task_struct *task); 1050967fc046SGregory Haskins int (*needs_post_schedule) (struct rq *this_rq); 10519a897c5aSSteven Rostedt void (*post_schedule) (struct rq *this_rq); 10529a897c5aSSteven Rostedt void (*task_wake_up) (struct rq *this_rq, struct task_struct *task); 1053e1d1484fSPeter Williams 1054cd8ba7cdSMike Travis void (*set_cpus_allowed)(struct task_struct *p, 105596f874e2SRusty Russell const struct cpumask *newmask); 105657d885feSGregory Haskins 10571f11eb6aSGregory Haskins void (*rq_online)(struct rq *rq); 10581f11eb6aSGregory Haskins void (*rq_offline)(struct rq *rq); 10594ce72a2cSLi Zefan #endif 10604ce72a2cSLi Zefan 10614ce72a2cSLi Zefan void (*set_curr_task) (struct rq *rq); 10624ce72a2cSLi Zefan void (*task_tick) (struct rq *rq, struct task_struct *p, int queued); 10634ce72a2cSLi Zefan void (*task_new) (struct rq *rq, struct task_struct *p); 1064cb469845SSteven Rostedt 1065cb469845SSteven Rostedt void (*switched_from) (struct rq *this_rq, struct task_struct *task, 1066cb469845SSteven Rostedt int running); 1067cb469845SSteven Rostedt void (*switched_to) (struct rq *this_rq, struct task_struct *task, 1068cb469845SSteven Rostedt int running); 1069cb469845SSteven Rostedt void (*prio_changed) (struct rq *this_rq, struct task_struct *task, 1070cb469845SSteven Rostedt int oldprio, int running); 1071810b3817SPeter Zijlstra 1072810b3817SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED 1073810b3817SPeter Zijlstra void (*moved_group) (struct task_struct *p); 1074810b3817SPeter Zijlstra #endif 107520b8a59fSIngo Molnar }; 107620b8a59fSIngo Molnar 107720b8a59fSIngo Molnar struct load_weight { 107820b8a59fSIngo Molnar unsigned long weight, inv_weight; 107920b8a59fSIngo Molnar }; 108020b8a59fSIngo Molnar 108120b8a59fSIngo Molnar /* 108220b8a59fSIngo Molnar * CFS stats for a schedulable entity (task, task-group etc) 108320b8a59fSIngo Molnar * 108420b8a59fSIngo Molnar * Current field usage histogram: 108520b8a59fSIngo Molnar * 108620b8a59fSIngo Molnar * 4 se->block_start 108720b8a59fSIngo Molnar * 4 se->run_node 108820b8a59fSIngo Molnar * 4 se->sleep_start 108920b8a59fSIngo Molnar * 6 se->load.weight 109020b8a59fSIngo Molnar */ 109120b8a59fSIngo Molnar struct sched_entity { 109220b8a59fSIngo Molnar struct load_weight load; /* for load-balancing */ 109320b8a59fSIngo Molnar struct rb_node run_node; 10944a55bd5eSPeter Zijlstra struct list_head group_node; 109520b8a59fSIngo Molnar unsigned int on_rq; 109620b8a59fSIngo Molnar 109720b8a59fSIngo Molnar u64 exec_start; 109894c18227SIngo Molnar u64 sum_exec_runtime; 1099e9acbff6SIngo Molnar u64 vruntime; 1100f6cf891cSIngo Molnar u64 prev_sum_exec_runtime; 110194c18227SIngo Molnar 11024ae7d5ceSIngo Molnar u64 last_wakeup; 11034ae7d5ceSIngo Molnar u64 avg_overlap; 11044ae7d5ceSIngo Molnar 11056c594c21SIngo Molnar u64 nr_migrations; 11066c594c21SIngo Molnar 110734cb6135SIngo Molnar u64 start_runtime; 110834cb6135SIngo Molnar u64 avg_wakeup; 110934cb6135SIngo Molnar 111094c18227SIngo Molnar #ifdef CONFIG_SCHEDSTATS 111194c18227SIngo Molnar u64 wait_start; 111294c18227SIngo Molnar u64 wait_max; 11136d082592SArjan van de Ven u64 wait_count; 11146d082592SArjan van de Ven u64 wait_sum; 111594c18227SIngo Molnar 111694c18227SIngo Molnar u64 sleep_start; 111720b8a59fSIngo Molnar u64 sleep_max; 111894c18227SIngo Molnar s64 sum_sleep_runtime; 111994c18227SIngo Molnar 112094c18227SIngo Molnar u64 block_start; 112120b8a59fSIngo Molnar u64 block_max; 112220b8a59fSIngo Molnar u64 exec_max; 1123eba1ed4bSIngo Molnar u64 slice_max; 1124cc367732SIngo Molnar 1125cc367732SIngo Molnar u64 nr_migrations_cold; 1126cc367732SIngo Molnar u64 nr_failed_migrations_affine; 1127cc367732SIngo Molnar u64 nr_failed_migrations_running; 1128cc367732SIngo Molnar u64 nr_failed_migrations_hot; 1129cc367732SIngo Molnar u64 nr_forced_migrations; 1130cc367732SIngo Molnar u64 nr_forced2_migrations; 1131cc367732SIngo Molnar 1132cc367732SIngo Molnar u64 nr_wakeups; 1133cc367732SIngo Molnar u64 nr_wakeups_sync; 1134cc367732SIngo Molnar u64 nr_wakeups_migrate; 1135cc367732SIngo Molnar u64 nr_wakeups_local; 1136cc367732SIngo Molnar u64 nr_wakeups_remote; 1137cc367732SIngo Molnar u64 nr_wakeups_affine; 1138cc367732SIngo Molnar u64 nr_wakeups_affine_attempts; 1139cc367732SIngo Molnar u64 nr_wakeups_passive; 1140cc367732SIngo Molnar u64 nr_wakeups_idle; 114194c18227SIngo Molnar #endif 114294c18227SIngo Molnar 114320b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED 114420b8a59fSIngo Molnar struct sched_entity *parent; 114520b8a59fSIngo Molnar /* rq on which this entity is (to be) queued: */ 114620b8a59fSIngo Molnar struct cfs_rq *cfs_rq; 114720b8a59fSIngo Molnar /* rq "owned" by this entity/group: */ 114820b8a59fSIngo Molnar struct cfs_rq *my_q; 114920b8a59fSIngo Molnar #endif 115020b8a59fSIngo Molnar }; 115170b97a7fSIngo Molnar 1152fa717060SPeter Zijlstra struct sched_rt_entity { 1153fa717060SPeter Zijlstra struct list_head run_list; 115478f2c7dbSPeter Zijlstra unsigned long timeout; 1155bee367edSRichard Kennedy unsigned int time_slice; 11566f505b16SPeter Zijlstra int nr_cpus_allowed; 11576f505b16SPeter Zijlstra 115858d6c2d7SPeter Zijlstra struct sched_rt_entity *back; 1159052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED 11606f505b16SPeter Zijlstra struct sched_rt_entity *parent; 11616f505b16SPeter Zijlstra /* rq on which this entity is (to be) queued: */ 11626f505b16SPeter Zijlstra struct rt_rq *rt_rq; 11636f505b16SPeter Zijlstra /* rq "owned" by this entity/group: */ 11646f505b16SPeter Zijlstra struct rt_rq *my_q; 11656f505b16SPeter Zijlstra #endif 1166fa717060SPeter Zijlstra }; 1167fa717060SPeter Zijlstra 11681da177e4SLinus Torvalds struct task_struct { 11691da177e4SLinus Torvalds volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ 1170f7e4217bSRoman Zippel void *stack; 11711da177e4SLinus Torvalds atomic_t usage; 117297dc32cdSWilliam Cohen unsigned int flags; /* per process flags, defined below */ 117397dc32cdSWilliam Cohen unsigned int ptrace; 11741da177e4SLinus Torvalds 117536772092SPaolo 'Blaisorblade' Giarrusso int lock_depth; /* BKL lock depth */ 11761da177e4SLinus Torvalds 11772dd73a4fSPeter Williams #ifdef CONFIG_SMP 11782dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW 11794866cde0SNick Piggin int oncpu; 11804866cde0SNick Piggin #endif 11812dd73a4fSPeter Williams #endif 118250e645a8SIngo Molnar 1183b29739f9SIngo Molnar int prio, static_prio, normal_prio; 1184c7aceabaSRichard Kennedy unsigned int rt_priority; 11855522d5d5SIngo Molnar const struct sched_class *sched_class; 118620b8a59fSIngo Molnar struct sched_entity se; 1187fa717060SPeter Zijlstra struct sched_rt_entity rt; 11881da177e4SLinus Torvalds 1189e107be36SAvi Kivity #ifdef CONFIG_PREEMPT_NOTIFIERS 1190e107be36SAvi Kivity /* list of struct preempt_notifier: */ 1191e107be36SAvi Kivity struct hlist_head preempt_notifiers; 1192e107be36SAvi Kivity #endif 1193e107be36SAvi Kivity 119418796aa0SAlexey Dobriyan /* 119518796aa0SAlexey Dobriyan * fpu_counter contains the number of consecutive context switches 119618796aa0SAlexey Dobriyan * that the FPU is used. If this is over a threshold, the lazy fpu 119718796aa0SAlexey Dobriyan * saving becomes unlazy to save the trap. This is an unsigned char 119818796aa0SAlexey Dobriyan * so that after 256 times the counter wraps and the behavior turns 119918796aa0SAlexey Dobriyan * lazy again; this to deal with bursty apps that only use FPU for 120018796aa0SAlexey Dobriyan * a short time 120118796aa0SAlexey Dobriyan */ 120218796aa0SAlexey Dobriyan unsigned char fpu_counter; 12036c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE 12042056a782SJens Axboe unsigned int btrace_seq; 12056c5c9341SAlexey Dobriyan #endif 12061da177e4SLinus Torvalds 120797dc32cdSWilliam Cohen unsigned int policy; 12081da177e4SLinus Torvalds cpumask_t cpus_allowed; 12091da177e4SLinus Torvalds 1210e260be67SPaul E. McKenney #ifdef CONFIG_PREEMPT_RCU 1211e260be67SPaul E. McKenney int rcu_read_lock_nesting; 1212e260be67SPaul E. McKenney int rcu_flipctr_idx; 1213e260be67SPaul E. McKenney #endif /* #ifdef CONFIG_PREEMPT_RCU */ 1214e260be67SPaul E. McKenney 121552f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 12161da177e4SLinus Torvalds struct sched_info sched_info; 12171da177e4SLinus Torvalds #endif 12181da177e4SLinus Torvalds 12191da177e4SLinus Torvalds struct list_head tasks; 1220917b627dSGregory Haskins struct plist_node pushable_tasks; 12211da177e4SLinus Torvalds 12221da177e4SLinus Torvalds struct mm_struct *mm, *active_mm; 12231da177e4SLinus Torvalds 12241da177e4SLinus Torvalds /* task state */ 12251da177e4SLinus Torvalds struct linux_binfmt *binfmt; 122697dc32cdSWilliam Cohen int exit_state; 12271da177e4SLinus Torvalds int exit_code, exit_signal; 12281da177e4SLinus Torvalds int pdeath_signal; /* The signal sent when the parent dies */ 12291da177e4SLinus Torvalds /* ??? */ 123097dc32cdSWilliam Cohen unsigned int personality; 12311da177e4SLinus Torvalds unsigned did_exec:1; 1232f9ce1f1cSKentaro Takeda unsigned in_execve:1; /* Tell the LSMs that the process is doing an 1233f9ce1f1cSKentaro Takeda * execve */ 1234ca94c442SLennart Poettering 1235ca94c442SLennart Poettering /* Revert to default priority/policy when forking */ 1236ca94c442SLennart Poettering unsigned sched_reset_on_fork:1; 1237ca94c442SLennart Poettering 12381da177e4SLinus Torvalds pid_t pid; 12391da177e4SLinus Torvalds pid_t tgid; 12400a425405SArjan van de Ven 12410a425405SArjan van de Ven /* Canary value for the -fstack-protector gcc feature */ 12420a425405SArjan van de Ven unsigned long stack_canary; 1243e0032087SIngo Molnar 12441da177e4SLinus Torvalds /* 12451da177e4SLinus Torvalds * pointers to (original) parent process, youngest child, younger sibling, 12461da177e4SLinus Torvalds * older sibling, respectively. (p->father can be replaced with 1247f470021aSRoland McGrath * p->real_parent->pid) 12481da177e4SLinus Torvalds */ 1249f470021aSRoland McGrath struct task_struct *real_parent; /* real parent process */ 1250f470021aSRoland McGrath struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports */ 12511da177e4SLinus Torvalds /* 1252f470021aSRoland McGrath * children/sibling forms the list of my natural children 12531da177e4SLinus Torvalds */ 12541da177e4SLinus Torvalds struct list_head children; /* list of my children */ 12551da177e4SLinus Torvalds struct list_head sibling; /* linkage in my parent's children list */ 12561da177e4SLinus Torvalds struct task_struct *group_leader; /* threadgroup leader */ 12571da177e4SLinus Torvalds 1258f470021aSRoland McGrath /* 1259f470021aSRoland McGrath * ptraced is the list of tasks this task is using ptrace on. 1260f470021aSRoland McGrath * This includes both natural children and PTRACE_ATTACH targets. 1261f470021aSRoland McGrath * p->ptrace_entry is p's link on the p->parent->ptraced list. 1262f470021aSRoland McGrath */ 1263f470021aSRoland McGrath struct list_head ptraced; 1264f470021aSRoland McGrath struct list_head ptrace_entry; 1265f470021aSRoland McGrath 1266ca0002a1SMarkus Metzger /* 1267ca0002a1SMarkus Metzger * This is the tracer handle for the ptrace BTS extension. 1268ca0002a1SMarkus Metzger * This field actually belongs to the ptracer task. 1269ca0002a1SMarkus Metzger */ 1270e2b371f0SMarkus Metzger struct bts_context *bts; 1271ca0002a1SMarkus Metzger 12721da177e4SLinus Torvalds /* PID/PID hash table linkage. */ 127392476d7fSEric W. Biederman struct pid_link pids[PIDTYPE_MAX]; 127447e65328SOleg Nesterov struct list_head thread_group; 12751da177e4SLinus Torvalds 12761da177e4SLinus Torvalds struct completion *vfork_done; /* for vfork() */ 12771da177e4SLinus Torvalds int __user *set_child_tid; /* CLONE_CHILD_SETTID */ 12781da177e4SLinus Torvalds int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */ 12791da177e4SLinus Torvalds 1280c66f08beSMichael Neuling cputime_t utime, stime, utimescaled, stimescaled; 12819ac52315SLaurent Vivier cputime_t gtime; 12829301899bSBalbir Singh cputime_t prev_utime, prev_stime; 12831da177e4SLinus Torvalds unsigned long nvcsw, nivcsw; /* context switch counts */ 1284924b42d5STomas Janousek struct timespec start_time; /* monotonic time */ 1285924b42d5STomas Janousek struct timespec real_start_time; /* boot based time */ 12861da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ 12871da177e4SLinus Torvalds unsigned long min_flt, maj_flt; 12881da177e4SLinus Torvalds 1289f06febc9SFrank Mayhar struct task_cputime cputime_expires; 12901da177e4SLinus Torvalds struct list_head cpu_timers[3]; 12911da177e4SLinus Torvalds 12921da177e4SLinus Torvalds /* process credentials */ 12933b11a1deSDavid Howells const struct cred *real_cred; /* objective and real subjective task 12943b11a1deSDavid Howells * credentials (COW) */ 12953b11a1deSDavid Howells const struct cred *cred; /* effective (overridable) subjective task 12963b11a1deSDavid Howells * credentials (COW) */ 12975e751e99SDavid Howells struct mutex cred_guard_mutex; /* guard against foreign influences on 12985e751e99SDavid Howells * credential calculations 12995e751e99SDavid Howells * (notably. ptrace) */ 1300b6dff3ecSDavid Howells 130136772092SPaolo 'Blaisorblade' Giarrusso char comm[TASK_COMM_LEN]; /* executable name excluding path 130236772092SPaolo 'Blaisorblade' Giarrusso - access with [gs]et_task_comm (which lock 130336772092SPaolo 'Blaisorblade' Giarrusso it with task_lock()) 130436772092SPaolo 'Blaisorblade' Giarrusso - initialized normally by flush_old_exec */ 13051da177e4SLinus Torvalds /* file system info */ 13061da177e4SLinus Torvalds int link_count, total_link_count; 13073d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC 13081da177e4SLinus Torvalds /* ipc stuff */ 13091da177e4SLinus Torvalds struct sysv_sem sysvsem; 13103d5b6fccSAlexey Dobriyan #endif 1311e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK 131282a1fcb9SIngo Molnar /* hung task detection */ 131382a1fcb9SIngo Molnar unsigned long last_switch_count; 131482a1fcb9SIngo Molnar #endif 13151da177e4SLinus Torvalds /* CPU-specific state of this task */ 13161da177e4SLinus Torvalds struct thread_struct thread; 13171da177e4SLinus Torvalds /* filesystem information */ 13181da177e4SLinus Torvalds struct fs_struct *fs; 13191da177e4SLinus Torvalds /* open file information */ 13201da177e4SLinus Torvalds struct files_struct *files; 13211651e14eSSerge E. Hallyn /* namespaces */ 1322ab516013SSerge E. Hallyn struct nsproxy *nsproxy; 13231da177e4SLinus Torvalds /* signal handlers */ 13241da177e4SLinus Torvalds struct signal_struct *signal; 13251da177e4SLinus Torvalds struct sighand_struct *sighand; 13261da177e4SLinus Torvalds 13271da177e4SLinus Torvalds sigset_t blocked, real_blocked; 1328f3de272bSRoland McGrath sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */ 13291da177e4SLinus Torvalds struct sigpending pending; 13301da177e4SLinus Torvalds 13311da177e4SLinus Torvalds unsigned long sas_ss_sp; 13321da177e4SLinus Torvalds size_t sas_ss_size; 13331da177e4SLinus Torvalds int (*notifier)(void *priv); 13341da177e4SLinus Torvalds void *notifier_data; 13351da177e4SLinus Torvalds sigset_t *notifier_mask; 13361da177e4SLinus Torvalds struct audit_context *audit_context; 1337bfef93a5SAl Viro #ifdef CONFIG_AUDITSYSCALL 1338bfef93a5SAl Viro uid_t loginuid; 13394746ec5bSEric Paris unsigned int sessionid; 1340bfef93a5SAl Viro #endif 13411da177e4SLinus Torvalds seccomp_t seccomp; 13421da177e4SLinus Torvalds 13431da177e4SLinus Torvalds /* Thread group tracking */ 13441da177e4SLinus Torvalds u32 parent_exec_id; 13451da177e4SLinus Torvalds u32 self_exec_id; 134658568d2aSMiao Xie /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed, 134758568d2aSMiao Xie * mempolicy */ 13481da177e4SLinus Torvalds spinlock_t alloc_lock; 13491da177e4SLinus Torvalds 13503aa551c9SThomas Gleixner #ifdef CONFIG_GENERIC_HARDIRQS 13513aa551c9SThomas Gleixner /* IRQ handler threads */ 13523aa551c9SThomas Gleixner struct irqaction *irqaction; 13533aa551c9SThomas Gleixner #endif 13543aa551c9SThomas Gleixner 1355b29739f9SIngo Molnar /* Protection of the PI data structures: */ 1356b29739f9SIngo Molnar spinlock_t pi_lock; 1357b29739f9SIngo Molnar 135823f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 135923f78d4aSIngo Molnar /* PI waiters blocked on a rt_mutex held by this task */ 136023f78d4aSIngo Molnar struct plist_head pi_waiters; 136123f78d4aSIngo Molnar /* Deadlock detection and priority inheritance handling */ 136223f78d4aSIngo Molnar struct rt_mutex_waiter *pi_blocked_on; 136323f78d4aSIngo Molnar #endif 136423f78d4aSIngo Molnar 1365408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES 1366408894eeSIngo Molnar /* mutex deadlock detection */ 1367408894eeSIngo Molnar struct mutex_waiter *blocked_on; 1368408894eeSIngo Molnar #endif 1369de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS 1370de30a2b3SIngo Molnar unsigned int irq_events; 1371de30a2b3SIngo Molnar int hardirqs_enabled; 1372de30a2b3SIngo Molnar unsigned long hardirq_enable_ip; 1373de30a2b3SIngo Molnar unsigned int hardirq_enable_event; 1374de30a2b3SIngo Molnar unsigned long hardirq_disable_ip; 1375de30a2b3SIngo Molnar unsigned int hardirq_disable_event; 1376de30a2b3SIngo Molnar int softirqs_enabled; 1377de30a2b3SIngo Molnar unsigned long softirq_disable_ip; 1378de30a2b3SIngo Molnar unsigned int softirq_disable_event; 1379de30a2b3SIngo Molnar unsigned long softirq_enable_ip; 1380de30a2b3SIngo Molnar unsigned int softirq_enable_event; 1381de30a2b3SIngo Molnar int hardirq_context; 1382de30a2b3SIngo Molnar int softirq_context; 1383de30a2b3SIngo Molnar #endif 1384fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP 1385bdb9441eSPeter Zijlstra # define MAX_LOCK_DEPTH 48UL 1386fbb9ce95SIngo Molnar u64 curr_chain_key; 1387fbb9ce95SIngo Molnar int lockdep_depth; 1388fbb9ce95SIngo Molnar unsigned int lockdep_recursion; 1389c7aceabaSRichard Kennedy struct held_lock held_locks[MAX_LOCK_DEPTH]; 1390cf40bd16SNick Piggin gfp_t lockdep_reclaim_gfp; 1391fbb9ce95SIngo Molnar #endif 1392408894eeSIngo Molnar 13931da177e4SLinus Torvalds /* journalling filesystem info */ 13941da177e4SLinus Torvalds void *journal_info; 13951da177e4SLinus Torvalds 1396d89d8796SNeil Brown /* stacked block device info */ 1397d89d8796SNeil Brown struct bio *bio_list, **bio_tail; 1398d89d8796SNeil Brown 13991da177e4SLinus Torvalds /* VM state */ 14001da177e4SLinus Torvalds struct reclaim_state *reclaim_state; 14011da177e4SLinus Torvalds 14021da177e4SLinus Torvalds struct backing_dev_info *backing_dev_info; 14031da177e4SLinus Torvalds 14041da177e4SLinus Torvalds struct io_context *io_context; 14051da177e4SLinus Torvalds 14061da177e4SLinus Torvalds unsigned long ptrace_message; 14071da177e4SLinus Torvalds siginfo_t *last_siginfo; /* For ptrace use. */ 14087c3ab738SAndrew Morton struct task_io_accounting ioac; 14098f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT) 14101da177e4SLinus Torvalds u64 acct_rss_mem1; /* accumulated rss usage */ 14111da177e4SLinus Torvalds u64 acct_vm_mem1; /* accumulated virtual memory usage */ 141249b5cf34SJonathan Lim cputime_t acct_timexpd; /* stime + utime since last update */ 14131da177e4SLinus Torvalds #endif 14141da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS 141558568d2aSMiao Xie nodemask_t mems_allowed; /* Protected by alloc_lock */ 1416825a46afSPaul Jackson int cpuset_mem_spread_rotor; 14171da177e4SLinus Torvalds #endif 1418ddbcc7e8SPaul Menage #ifdef CONFIG_CGROUPS 1419817929ecSPaul Menage /* Control Group info protected by css_set_lock */ 1420817929ecSPaul Menage struct css_set *cgroups; 1421817929ecSPaul Menage /* cg_list protected by css_set_lock and tsk->alloc_lock */ 1422817929ecSPaul Menage struct list_head cg_list; 1423ddbcc7e8SPaul Menage #endif 142442b2dd0aSAlexey Dobriyan #ifdef CONFIG_FUTEX 14250771dfefSIngo Molnar struct robust_list_head __user *robust_list; 142634f192c6SIngo Molnar #ifdef CONFIG_COMPAT 142734f192c6SIngo Molnar struct compat_robust_list_head __user *compat_robust_list; 142834f192c6SIngo Molnar #endif 1429c87e2837SIngo Molnar struct list_head pi_state_list; 1430c87e2837SIngo Molnar struct futex_pi_state *pi_state_cache; 143142b2dd0aSAlexey Dobriyan #endif 1432a63eaf34SPaul Mackerras #ifdef CONFIG_PERF_COUNTERS 1433a63eaf34SPaul Mackerras struct perf_counter_context *perf_counter_ctxp; 1434082ff5a2SPeter Zijlstra struct mutex perf_counter_mutex; 1435082ff5a2SPeter Zijlstra struct list_head perf_counter_list; 1436a63eaf34SPaul Mackerras #endif 1437c7aceabaSRichard Kennedy #ifdef CONFIG_NUMA 143858568d2aSMiao Xie struct mempolicy *mempolicy; /* Protected by alloc_lock */ 1439c7aceabaSRichard Kennedy short il_next; 1440c7aceabaSRichard Kennedy #endif 144122e2c507SJens Axboe atomic_t fs_excl; /* holding fs exclusive resources */ 1442e56d0903SIngo Molnar struct rcu_head rcu; 1443b92ce558SJens Axboe 1444b92ce558SJens Axboe /* 1445b92ce558SJens Axboe * cache last used pipe for splice 1446b92ce558SJens Axboe */ 1447b92ce558SJens Axboe struct pipe_inode_info *splice_pipe; 1448ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 1449ca74e92bSShailabh Nagar struct task_delay_info *delays; 1450ca74e92bSShailabh Nagar #endif 1451f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION 1452f4f154fdSAkinobu Mita int make_it_fail; 1453f4f154fdSAkinobu Mita #endif 14543e26c149SPeter Zijlstra struct prop_local_single dirties; 14559745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP 14569745512cSArjan van de Ven int latency_record_count; 14579745512cSArjan van de Ven struct latency_record latency_record[LT_SAVECOUNT]; 14589745512cSArjan van de Ven #endif 14596976675dSArjan van de Ven /* 14606976675dSArjan van de Ven * time slack values; these are used to round up poll() and 14616976675dSArjan van de Ven * select() etc timeout values. These are in nanoseconds. 14626976675dSArjan van de Ven */ 14636976675dSArjan van de Ven unsigned long timer_slack_ns; 14646976675dSArjan van de Ven unsigned long default_timer_slack_ns; 1465f8d570a4SDavid Miller 1466f8d570a4SDavid Miller struct list_head *scm_work_list; 1467fb52607aSFrederic Weisbecker #ifdef CONFIG_FUNCTION_GRAPH_TRACER 1468f201ae23SFrederic Weisbecker /* Index of current stored adress in ret_stack */ 1469f201ae23SFrederic Weisbecker int curr_ret_stack; 1470f201ae23SFrederic Weisbecker /* Stack of return addresses for return function tracing */ 1471f201ae23SFrederic Weisbecker struct ftrace_ret_stack *ret_stack; 14728aef2d28SSteven Rostedt /* time stamp for last schedule */ 14738aef2d28SSteven Rostedt unsigned long long ftrace_timestamp; 1474f201ae23SFrederic Weisbecker /* 1475f201ae23SFrederic Weisbecker * Number of functions that haven't been traced 1476f201ae23SFrederic Weisbecker * because of depth overrun. 1477f201ae23SFrederic Weisbecker */ 1478f201ae23SFrederic Weisbecker atomic_t trace_overrun; 1479380c4b14SFrederic Weisbecker /* Pause for the tracing */ 1480380c4b14SFrederic Weisbecker atomic_t tracing_graph_pause; 1481f201ae23SFrederic Weisbecker #endif 1482ea4e2bc4SSteven Rostedt #ifdef CONFIG_TRACING 1483ea4e2bc4SSteven Rostedt /* state flags for use by tracers */ 1484ea4e2bc4SSteven Rostedt unsigned long trace; 1485261842b7SSteven Rostedt /* bitmask of trace recursion */ 1486261842b7SSteven Rostedt unsigned long trace_recursion; 1487261842b7SSteven Rostedt #endif /* CONFIG_TRACING */ 14881da177e4SLinus Torvalds }; 14891da177e4SLinus Torvalds 149076e6eee0SRusty Russell /* Future-safe accessor for struct task_struct's cpus_allowed. */ 149176e6eee0SRusty Russell #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed) 149276e6eee0SRusty Russell 1493e05606d3SIngo Molnar /* 1494e05606d3SIngo Molnar * Priority of a process goes from 0..MAX_PRIO-1, valid RT 1495e05606d3SIngo Molnar * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH 1496e05606d3SIngo Molnar * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority 1497e05606d3SIngo Molnar * values are inverted: lower p->prio value means higher priority. 1498e05606d3SIngo Molnar * 1499e05606d3SIngo Molnar * The MAX_USER_RT_PRIO value allows the actual maximum 1500e05606d3SIngo Molnar * RT priority to be separate from the value exported to 1501e05606d3SIngo Molnar * user-space. This allows kernel threads to set their 1502e05606d3SIngo Molnar * priority to a value higher than any user task. Note: 1503e05606d3SIngo Molnar * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO. 1504e05606d3SIngo Molnar */ 1505e05606d3SIngo Molnar 1506e05606d3SIngo Molnar #define MAX_USER_RT_PRIO 100 1507e05606d3SIngo Molnar #define MAX_RT_PRIO MAX_USER_RT_PRIO 1508e05606d3SIngo Molnar 1509e05606d3SIngo Molnar #define MAX_PRIO (MAX_RT_PRIO + 40) 1510e05606d3SIngo Molnar #define DEFAULT_PRIO (MAX_RT_PRIO + 20) 1511e05606d3SIngo Molnar 1512e05606d3SIngo Molnar static inline int rt_prio(int prio) 1513e05606d3SIngo Molnar { 1514e05606d3SIngo Molnar if (unlikely(prio < MAX_RT_PRIO)) 1515e05606d3SIngo Molnar return 1; 1516e05606d3SIngo Molnar return 0; 1517e05606d3SIngo Molnar } 1518e05606d3SIngo Molnar 1519e868171aSAlexey Dobriyan static inline int rt_task(struct task_struct *p) 1520e05606d3SIngo Molnar { 1521e05606d3SIngo Molnar return rt_prio(p->prio); 1522e05606d3SIngo Molnar } 1523e05606d3SIngo Molnar 1524e868171aSAlexey Dobriyan static inline struct pid *task_pid(struct task_struct *task) 152522c935f4SEric W. Biederman { 152622c935f4SEric W. Biederman return task->pids[PIDTYPE_PID].pid; 152722c935f4SEric W. Biederman } 152822c935f4SEric W. Biederman 1529e868171aSAlexey Dobriyan static inline struct pid *task_tgid(struct task_struct *task) 153022c935f4SEric W. Biederman { 153122c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PID].pid; 153222c935f4SEric W. Biederman } 153322c935f4SEric W. Biederman 15346dda81f4SOleg Nesterov /* 15356dda81f4SOleg Nesterov * Without tasklist or rcu lock it is not safe to dereference 15366dda81f4SOleg Nesterov * the result of task_pgrp/task_session even if task == current, 15376dda81f4SOleg Nesterov * we can race with another thread doing sys_setsid/sys_setpgid. 15386dda81f4SOleg Nesterov */ 1539e868171aSAlexey Dobriyan static inline struct pid *task_pgrp(struct task_struct *task) 154022c935f4SEric W. Biederman { 154122c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PGID].pid; 154222c935f4SEric W. Biederman } 154322c935f4SEric W. Biederman 1544e868171aSAlexey Dobriyan static inline struct pid *task_session(struct task_struct *task) 154522c935f4SEric W. Biederman { 154622c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_SID].pid; 154722c935f4SEric W. Biederman } 154822c935f4SEric W. Biederman 15497af57294SPavel Emelyanov struct pid_namespace; 15507af57294SPavel Emelyanov 15517af57294SPavel Emelyanov /* 15527af57294SPavel Emelyanov * the helpers to get the task's different pids as they are seen 15537af57294SPavel Emelyanov * from various namespaces 15547af57294SPavel Emelyanov * 15557af57294SPavel Emelyanov * task_xid_nr() : global id, i.e. the id seen from the init namespace; 155644c4e1b2SEric W. Biederman * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of 155744c4e1b2SEric W. Biederman * current. 15587af57294SPavel Emelyanov * task_xid_nr_ns() : id seen from the ns specified; 15597af57294SPavel Emelyanov * 15607af57294SPavel Emelyanov * set_task_vxid() : assigns a virtual id to a task; 15617af57294SPavel Emelyanov * 15627af57294SPavel Emelyanov * see also pid_nr() etc in include/linux/pid.h 15637af57294SPavel Emelyanov */ 156452ee2dfdSOleg Nesterov pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, 156552ee2dfdSOleg Nesterov struct pid_namespace *ns); 15667af57294SPavel Emelyanov 1567e868171aSAlexey Dobriyan static inline pid_t task_pid_nr(struct task_struct *tsk) 15687af57294SPavel Emelyanov { 15697af57294SPavel Emelyanov return tsk->pid; 15707af57294SPavel Emelyanov } 15717af57294SPavel Emelyanov 157252ee2dfdSOleg Nesterov static inline pid_t task_pid_nr_ns(struct task_struct *tsk, 157352ee2dfdSOleg Nesterov struct pid_namespace *ns) 157452ee2dfdSOleg Nesterov { 157552ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns); 157652ee2dfdSOleg Nesterov } 15777af57294SPavel Emelyanov 15787af57294SPavel Emelyanov static inline pid_t task_pid_vnr(struct task_struct *tsk) 15797af57294SPavel Emelyanov { 158052ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL); 15817af57294SPavel Emelyanov } 15827af57294SPavel Emelyanov 15837af57294SPavel Emelyanov 1584e868171aSAlexey Dobriyan static inline pid_t task_tgid_nr(struct task_struct *tsk) 15857af57294SPavel Emelyanov { 15867af57294SPavel Emelyanov return tsk->tgid; 15877af57294SPavel Emelyanov } 15887af57294SPavel Emelyanov 15892f2a3a46SPavel Emelyanov pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns); 15907af57294SPavel Emelyanov 15917af57294SPavel Emelyanov static inline pid_t task_tgid_vnr(struct task_struct *tsk) 15927af57294SPavel Emelyanov { 15937af57294SPavel Emelyanov return pid_vnr(task_tgid(tsk)); 15947af57294SPavel Emelyanov } 15957af57294SPavel Emelyanov 15967af57294SPavel Emelyanov 159752ee2dfdSOleg Nesterov static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, 159852ee2dfdSOleg Nesterov struct pid_namespace *ns) 15997af57294SPavel Emelyanov { 160052ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns); 16017af57294SPavel Emelyanov } 16027af57294SPavel Emelyanov 16037af57294SPavel Emelyanov static inline pid_t task_pgrp_vnr(struct task_struct *tsk) 16047af57294SPavel Emelyanov { 160552ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL); 16067af57294SPavel Emelyanov } 16077af57294SPavel Emelyanov 16087af57294SPavel Emelyanov 160952ee2dfdSOleg Nesterov static inline pid_t task_session_nr_ns(struct task_struct *tsk, 161052ee2dfdSOleg Nesterov struct pid_namespace *ns) 16117af57294SPavel Emelyanov { 161252ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns); 16137af57294SPavel Emelyanov } 16147af57294SPavel Emelyanov 16157af57294SPavel Emelyanov static inline pid_t task_session_vnr(struct task_struct *tsk) 16167af57294SPavel Emelyanov { 161752ee2dfdSOleg Nesterov return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL); 16187af57294SPavel Emelyanov } 16197af57294SPavel Emelyanov 16201b0f7ffdSOleg Nesterov /* obsolete, do not use */ 16211b0f7ffdSOleg Nesterov static inline pid_t task_pgrp_nr(struct task_struct *tsk) 16221b0f7ffdSOleg Nesterov { 16231b0f7ffdSOleg Nesterov return task_pgrp_nr_ns(tsk, &init_pid_ns); 16241b0f7ffdSOleg Nesterov } 16257af57294SPavel Emelyanov 16261da177e4SLinus Torvalds /** 16271da177e4SLinus Torvalds * pid_alive - check that a task structure is not stale 16281da177e4SLinus Torvalds * @p: Task structure to be checked. 16291da177e4SLinus Torvalds * 16301da177e4SLinus Torvalds * Test if a process is not yet dead (at most zombie state) 16311da177e4SLinus Torvalds * If pid_alive fails, then pointers within the task structure 16321da177e4SLinus Torvalds * can be stale and must not be dereferenced. 16331da177e4SLinus Torvalds */ 1634e868171aSAlexey Dobriyan static inline int pid_alive(struct task_struct *p) 16351da177e4SLinus Torvalds { 163692476d7fSEric W. Biederman return p->pids[PIDTYPE_PID].pid != NULL; 16371da177e4SLinus Torvalds } 16381da177e4SLinus Torvalds 1639f400e198SSukadev Bhattiprolu /** 1640b460cbc5SSerge E. Hallyn * is_global_init - check if a task structure is init 16413260259fSHenne * @tsk: Task structure to be checked. 16423260259fSHenne * 16433260259fSHenne * Check if a task structure is the first user space task the kernel created. 1644f400e198SSukadev Bhattiprolu */ 1645e868171aSAlexey Dobriyan static inline int is_global_init(struct task_struct *tsk) 1646b461cc03SPavel Emelyanov { 1647b461cc03SPavel Emelyanov return tsk->pid == 1; 1648b461cc03SPavel Emelyanov } 1649b460cbc5SSerge E. Hallyn 1650b460cbc5SSerge E. Hallyn /* 1651b460cbc5SSerge E. Hallyn * is_container_init: 1652b460cbc5SSerge E. Hallyn * check whether in the task is init in its own pid namespace. 1653b460cbc5SSerge E. Hallyn */ 1654b461cc03SPavel Emelyanov extern int is_container_init(struct task_struct *tsk); 1655f400e198SSukadev Bhattiprolu 16569ec52099SCedric Le Goater extern struct pid *cad_pid; 16579ec52099SCedric Le Goater 16581da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk); 16591da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0) 1660e56d0903SIngo Molnar 1661158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t); 1662e56d0903SIngo Molnar 1663e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t) 1664e56d0903SIngo Molnar { 1665e56d0903SIngo Molnar if (atomic_dec_and_test(&t->usage)) 16668c7904a0SEric W. Biederman __put_task_struct(t); 1667e56d0903SIngo Molnar } 16681da177e4SLinus Torvalds 166949048622SBalbir Singh extern cputime_t task_utime(struct task_struct *p); 167049048622SBalbir Singh extern cputime_t task_stime(struct task_struct *p); 167149048622SBalbir Singh extern cputime_t task_gtime(struct task_struct *p); 167249048622SBalbir Singh 16731da177e4SLinus Torvalds /* 16741da177e4SLinus Torvalds * Per process flags 16751da177e4SLinus Torvalds */ 16761da177e4SLinus Torvalds #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */ 16771da177e4SLinus Torvalds /* Not implemented yet, only for 486*/ 16781da177e4SLinus Torvalds #define PF_STARTING 0x00000002 /* being created */ 16791da177e4SLinus Torvalds #define PF_EXITING 0x00000004 /* getting shut down */ 1680778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ 168194886b84SLaurent Vivier #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ 16821da177e4SLinus Torvalds #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ 16831da177e4SLinus Torvalds #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ 16841da177e4SLinus Torvalds #define PF_DUMPCORE 0x00000200 /* dumped core */ 16851da177e4SLinus Torvalds #define PF_SIGNALED 0x00000400 /* killed by a signal */ 16861da177e4SLinus Torvalds #define PF_MEMALLOC 0x00000800 /* Allocating memory */ 16871da177e4SLinus Torvalds #define PF_FLUSHER 0x00001000 /* responsible for disk writeback */ 16881da177e4SLinus Torvalds #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */ 16891da177e4SLinus Torvalds #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */ 16901da177e4SLinus Torvalds #define PF_FROZEN 0x00010000 /* frozen for system suspend */ 16911da177e4SLinus Torvalds #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ 16921da177e4SLinus Torvalds #define PF_KSWAPD 0x00040000 /* I am kswapd */ 16931da177e4SLinus Torvalds #define PF_SWAPOFF 0x00080000 /* I am in swapoff */ 16941da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */ 1695246bb0b1SOleg Nesterov #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ 1696b31dc66aSJens Axboe #define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */ 1697b31dc66aSJens Axboe #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ 1698b31dc66aSJens Axboe #define PF_SPREAD_PAGE 0x01000000 /* Spread page cache over cpuset */ 1699b31dc66aSJens Axboe #define PF_SPREAD_SLAB 0x02000000 /* Spread some slab caches over cpuset */ 17009985b0baSDavid Rientjes #define PF_THREAD_BOUND 0x04000000 /* Thread bound to specific cpu */ 1701c61afb18SPaul Jackson #define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */ 170261a87122SThomas Gleixner #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */ 1703ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezeable */ 1704ebb12db5SRafael J. Wysocki #define PF_FREEZER_NOSIG 0x80000000 /* Freezer won't send signals to it */ 17051da177e4SLinus Torvalds 17061da177e4SLinus Torvalds /* 17071da177e4SLinus Torvalds * Only the _current_ task can read/write to tsk->flags, but other 17081da177e4SLinus Torvalds * tasks can access tsk->flags in readonly mode for example 17091da177e4SLinus Torvalds * with tsk_used_math (like during threaded core dumping). 17101da177e4SLinus Torvalds * There is however an exception to this rule during ptrace 17111da177e4SLinus Torvalds * or during fork: the ptracer task is allowed to write to the 17121da177e4SLinus Torvalds * child->flags of its traced child (same goes for fork, the parent 17131da177e4SLinus Torvalds * can write to the child->flags), because we're guaranteed the 17141da177e4SLinus Torvalds * child is not running and in turn not changing child->flags 17151da177e4SLinus Torvalds * at the same time the parent does it. 17161da177e4SLinus Torvalds */ 17171da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0) 17181da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0) 17191da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current) 17201da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current) 17211da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \ 17221da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0) 17231da177e4SLinus Torvalds #define conditional_used_math(condition) \ 17241da177e4SLinus Torvalds conditional_stopped_child_used_math(condition, current) 17251da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \ 17261da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0) 17271da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */ 17281da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH) 17291da177e4SLinus Torvalds #define used_math() tsk_used_math(current) 17301da177e4SLinus Torvalds 17311da177e4SLinus Torvalds #ifdef CONFIG_SMP 1732cd8ba7cdSMike Travis extern int set_cpus_allowed_ptr(struct task_struct *p, 173396f874e2SRusty Russell const struct cpumask *new_mask); 17341da177e4SLinus Torvalds #else 1735cd8ba7cdSMike Travis static inline int set_cpus_allowed_ptr(struct task_struct *p, 173696f874e2SRusty Russell const struct cpumask *new_mask) 17371da177e4SLinus Torvalds { 173896f874e2SRusty Russell if (!cpumask_test_cpu(0, new_mask)) 17391da177e4SLinus Torvalds return -EINVAL; 17401da177e4SLinus Torvalds return 0; 17411da177e4SLinus Torvalds } 17421da177e4SLinus Torvalds #endif 1743cd8ba7cdSMike Travis static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask) 1744cd8ba7cdSMike Travis { 1745cd8ba7cdSMike Travis return set_cpus_allowed_ptr(p, &new_mask); 1746cd8ba7cdSMike Travis } 17471da177e4SLinus Torvalds 1748b342501cSIngo Molnar /* 1749b342501cSIngo Molnar * Architectures can set this to 1 if they have specified 1750b342501cSIngo Molnar * CONFIG_HAVE_UNSTABLE_SCHED_CLOCK in their arch Kconfig, 1751b342501cSIngo Molnar * but then during bootup it turns out that sched_clock() 1752b342501cSIngo Molnar * is reliable after all: 1753b342501cSIngo Molnar */ 1754b342501cSIngo Molnar #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK 1755b342501cSIngo Molnar extern int sched_clock_stable; 1756b342501cSIngo Molnar #endif 1757b342501cSIngo Molnar 17581da177e4SLinus Torvalds extern unsigned long long sched_clock(void); 1759e436d800SIngo Molnar 1760c1955a3dSPeter Zijlstra extern void sched_clock_init(void); 1761c1955a3dSPeter Zijlstra extern u64 sched_clock_cpu(int cpu); 1762c1955a3dSPeter Zijlstra 17633e51f33fSPeter Zijlstra #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK 17643e51f33fSPeter Zijlstra static inline void sched_clock_tick(void) 17653e51f33fSPeter Zijlstra { 17663e51f33fSPeter Zijlstra } 17673e51f33fSPeter Zijlstra 17683e51f33fSPeter Zijlstra static inline void sched_clock_idle_sleep_event(void) 17693e51f33fSPeter Zijlstra { 17703e51f33fSPeter Zijlstra } 17713e51f33fSPeter Zijlstra 17723e51f33fSPeter Zijlstra static inline void sched_clock_idle_wakeup_event(u64 delta_ns) 17733e51f33fSPeter Zijlstra { 17743e51f33fSPeter Zijlstra } 17753e51f33fSPeter Zijlstra #else 17763e51f33fSPeter Zijlstra extern void sched_clock_tick(void); 17773e51f33fSPeter Zijlstra extern void sched_clock_idle_sleep_event(void); 17783e51f33fSPeter Zijlstra extern void sched_clock_idle_wakeup_event(u64 delta_ns); 17793e51f33fSPeter Zijlstra #endif 17803e51f33fSPeter Zijlstra 1781e436d800SIngo Molnar /* 1782e436d800SIngo Molnar * For kernel-internal use: high-speed (but slightly incorrect) per-cpu 1783e436d800SIngo Molnar * clock constructed from sched_clock(): 1784e436d800SIngo Molnar */ 1785e436d800SIngo Molnar extern unsigned long long cpu_clock(int cpu); 1786e436d800SIngo Molnar 178736c8b586SIngo Molnar extern unsigned long long 178841b86e9cSIngo Molnar task_sched_runtime(struct task_struct *task); 1789f06febc9SFrank Mayhar extern unsigned long long thread_group_sched_runtime(struct task_struct *task); 17901da177e4SLinus Torvalds 17911da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */ 17921da177e4SLinus Torvalds #ifdef CONFIG_SMP 17931da177e4SLinus Torvalds extern void sched_exec(void); 17941da177e4SLinus Torvalds #else 17951da177e4SLinus Torvalds #define sched_exec() {} 17961da177e4SLinus Torvalds #endif 17971da177e4SLinus Torvalds 17982aa44d05SIngo Molnar extern void sched_clock_idle_sleep_event(void); 17992aa44d05SIngo Molnar extern void sched_clock_idle_wakeup_event(u64 delta_ns); 1800bb29ab26SIngo Molnar 18011da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU 18021da177e4SLinus Torvalds extern void idle_task_exit(void); 18031da177e4SLinus Torvalds #else 18041da177e4SLinus Torvalds static inline void idle_task_exit(void) {} 18051da177e4SLinus Torvalds #endif 18061da177e4SLinus Torvalds 18071da177e4SLinus Torvalds extern void sched_idle_next(void); 1808b29739f9SIngo Molnar 180906d8308cSThomas Gleixner #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP) 181006d8308cSThomas Gleixner extern void wake_up_idle_cpu(int cpu); 181106d8308cSThomas Gleixner #else 181206d8308cSThomas Gleixner static inline void wake_up_idle_cpu(int cpu) { } 181306d8308cSThomas Gleixner #endif 181406d8308cSThomas Gleixner 181521805085SPeter Zijlstra extern unsigned int sysctl_sched_latency; 1816b2be5e96SPeter Zijlstra extern unsigned int sysctl_sched_min_granularity; 1817bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity; 181847fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_ratelimit; 181947fea2adSJaswinder Singh Rajput extern unsigned int sysctl_sched_shares_thresh; 182047fea2adSJaswinder Singh Rajput #ifdef CONFIG_SCHED_DEBUG 1821bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first; 1822bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_features; 1823da84d961SIngo Molnar extern unsigned int sysctl_sched_migration_cost; 1824b82d9fddSPeter Zijlstra extern unsigned int sysctl_sched_nr_migrate; 1825cd1bb94bSArun R Bharadwaj extern unsigned int sysctl_timer_migration; 1826b2be5e96SPeter Zijlstra 1827b2be5e96SPeter Zijlstra int sched_nr_latency_handler(struct ctl_table *table, int write, 1828b2be5e96SPeter Zijlstra struct file *file, void __user *buffer, size_t *length, 1829b2be5e96SPeter Zijlstra loff_t *ppos); 18302bd8e6d4SIngo Molnar #endif 1831eea08f32SArun R Bharadwaj #ifdef CONFIG_SCHED_DEBUG 1832eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void) 1833eea08f32SArun R Bharadwaj { 1834eea08f32SArun R Bharadwaj return sysctl_timer_migration; 1835eea08f32SArun R Bharadwaj } 1836eea08f32SArun R Bharadwaj #else 1837eea08f32SArun R Bharadwaj static inline unsigned int get_sysctl_timer_migration(void) 1838eea08f32SArun R Bharadwaj { 1839eea08f32SArun R Bharadwaj return 1; 1840eea08f32SArun R Bharadwaj } 1841eea08f32SArun R Bharadwaj #endif 18429f0c1e56SPeter Zijlstra extern unsigned int sysctl_sched_rt_period; 18439f0c1e56SPeter Zijlstra extern int sysctl_sched_rt_runtime; 18442bd8e6d4SIngo Molnar 1845d0b27fa7SPeter Zijlstra int sched_rt_handler(struct ctl_table *table, int write, 1846d0b27fa7SPeter Zijlstra struct file *filp, void __user *buffer, size_t *lenp, 1847d0b27fa7SPeter Zijlstra loff_t *ppos); 1848d0b27fa7SPeter Zijlstra 18492bd8e6d4SIngo Molnar extern unsigned int sysctl_sched_compat_yield; 1850bf0f6f24SIngo Molnar 1851b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES 185236c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p); 185336c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio); 185436c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p); 1855b29739f9SIngo Molnar #else 1856e868171aSAlexey Dobriyan static inline int rt_mutex_getprio(struct task_struct *p) 1857b29739f9SIngo Molnar { 1858b29739f9SIngo Molnar return p->normal_prio; 1859b29739f9SIngo Molnar } 186095e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p) do { } while (0) 1861b29739f9SIngo Molnar #endif 1862b29739f9SIngo Molnar 186336c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice); 186436c8b586SIngo Molnar extern int task_prio(const struct task_struct *p); 186536c8b586SIngo Molnar extern int task_nice(const struct task_struct *p); 186636c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice); 186736c8b586SIngo Molnar extern int task_curr(const struct task_struct *p); 18681da177e4SLinus Torvalds extern int idle_cpu(int cpu); 18691da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *); 1870961ccdddSRusty Russell extern int sched_setscheduler_nocheck(struct task_struct *, int, 1871961ccdddSRusty Russell struct sched_param *); 187236c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu); 187336c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu); 187436c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p); 18751da177e4SLinus Torvalds 18761da177e4SLinus Torvalds void yield(void); 18771da177e4SLinus Torvalds 18781da177e4SLinus Torvalds /* 18791da177e4SLinus Torvalds * The default (Linux) execution domain. 18801da177e4SLinus Torvalds */ 18811da177e4SLinus Torvalds extern struct exec_domain default_exec_domain; 18821da177e4SLinus Torvalds 18831da177e4SLinus Torvalds union thread_union { 18841da177e4SLinus Torvalds struct thread_info thread_info; 18851da177e4SLinus Torvalds unsigned long stack[THREAD_SIZE/sizeof(long)]; 18861da177e4SLinus Torvalds }; 18871da177e4SLinus Torvalds 18881da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END 18891da177e4SLinus Torvalds static inline int kstack_end(void *addr) 18901da177e4SLinus Torvalds { 18911da177e4SLinus Torvalds /* Reliable end of stack detection: 18921da177e4SLinus Torvalds * Some APM bios versions misalign the stack 18931da177e4SLinus Torvalds */ 18941da177e4SLinus Torvalds return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*))); 18951da177e4SLinus Torvalds } 18961da177e4SLinus Torvalds #endif 18971da177e4SLinus Torvalds 18981da177e4SLinus Torvalds extern union thread_union init_thread_union; 18991da177e4SLinus Torvalds extern struct task_struct init_task; 19001da177e4SLinus Torvalds 19011da177e4SLinus Torvalds extern struct mm_struct init_mm; 19021da177e4SLinus Torvalds 1903198fe21bSPavel Emelyanov extern struct pid_namespace init_pid_ns; 1904198fe21bSPavel Emelyanov 1905198fe21bSPavel Emelyanov /* 1906198fe21bSPavel Emelyanov * find a task by one of its numerical ids 1907198fe21bSPavel Emelyanov * 1908198fe21bSPavel Emelyanov * find_task_by_pid_ns(): 1909198fe21bSPavel Emelyanov * finds a task by its pid in the specified namespace 1910228ebcbeSPavel Emelyanov * find_task_by_vpid(): 1911228ebcbeSPavel Emelyanov * finds a task by its virtual pid 1912198fe21bSPavel Emelyanov * 1913e49859e7SPavel Emelyanov * see also find_vpid() etc in include/linux/pid.h 1914198fe21bSPavel Emelyanov */ 1915198fe21bSPavel Emelyanov 1916228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_vpid(pid_t nr); 1917228ebcbeSPavel Emelyanov extern struct task_struct *find_task_by_pid_ns(pid_t nr, 1918228ebcbeSPavel Emelyanov struct pid_namespace *ns); 1919198fe21bSPavel Emelyanov 19208520d7c7SOleg Nesterov extern void __set_special_pids(struct pid *pid); 19211da177e4SLinus Torvalds 19221da177e4SLinus Torvalds /* per-UID process charging. */ 1923acce292cSCedric Le Goater extern struct user_struct * alloc_uid(struct user_namespace *, uid_t); 19241da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u) 19251da177e4SLinus Torvalds { 19261da177e4SLinus Torvalds atomic_inc(&u->__count); 19271da177e4SLinus Torvalds return u; 19281da177e4SLinus Torvalds } 19291da177e4SLinus Torvalds extern void free_uid(struct user_struct *); 193028f300d2SPavel Emelyanov extern void release_uids(struct user_namespace *ns); 19311da177e4SLinus Torvalds 19321da177e4SLinus Torvalds #include <asm/current.h> 19331da177e4SLinus Torvalds 19343171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks); 19351da177e4SLinus Torvalds 1936b3c97528SHarvey Harrison extern int wake_up_state(struct task_struct *tsk, unsigned int state); 1937b3c97528SHarvey Harrison extern int wake_up_process(struct task_struct *tsk); 1938b3c97528SHarvey Harrison extern void wake_up_new_task(struct task_struct *tsk, 1939b3c97528SHarvey Harrison unsigned long clone_flags); 19401da177e4SLinus Torvalds #ifdef CONFIG_SMP 19411da177e4SLinus Torvalds extern void kick_process(struct task_struct *tsk); 19421da177e4SLinus Torvalds #else 19431da177e4SLinus Torvalds static inline void kick_process(struct task_struct *tsk) { } 19441da177e4SLinus Torvalds #endif 1945ad46c2c4SIngo Molnar extern void sched_fork(struct task_struct *p, int clone_flags); 1946ad46c2c4SIngo Molnar extern void sched_dead(struct task_struct *p); 19471da177e4SLinus Torvalds 19481da177e4SLinus Torvalds extern void proc_caches_init(void); 19491da177e4SLinus Torvalds extern void flush_signals(struct task_struct *); 19503bcac026SDavid Howells extern void __flush_signals(struct task_struct *); 195110ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *); 19521da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default); 19531da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info); 19541da177e4SLinus Torvalds 19551da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) 19561da177e4SLinus Torvalds { 19571da177e4SLinus Torvalds unsigned long flags; 19581da177e4SLinus Torvalds int ret; 19591da177e4SLinus Torvalds 19601da177e4SLinus Torvalds spin_lock_irqsave(&tsk->sighand->siglock, flags); 19611da177e4SLinus Torvalds ret = dequeue_signal(tsk, mask, info); 19621da177e4SLinus Torvalds spin_unlock_irqrestore(&tsk->sighand->siglock, flags); 19631da177e4SLinus Torvalds 19641da177e4SLinus Torvalds return ret; 19651da177e4SLinus Torvalds } 19661da177e4SLinus Torvalds 19671da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv, 19681da177e4SLinus Torvalds sigset_t *mask); 19691da177e4SLinus Torvalds extern void unblock_all_signals(void); 19701da177e4SLinus Torvalds extern void release_task(struct task_struct * p); 19711da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *); 19721da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *); 19731da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *); 1974c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp); 1975c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid); 19762425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32); 1977c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv); 1978c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv); 1979c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t); 19802b2a1ff6SRoland McGrath extern int do_notify_parent(struct task_struct *, int); 19811da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *); 19821da177e4SLinus Torvalds extern void force_sig_specific(int, struct task_struct *); 19831da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int); 19841da177e4SLinus Torvalds extern void zap_other_threads(struct task_struct *p); 19851da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void); 19861da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *); 1987ac5c2153SOleg Nesterov extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group); 19889ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); 19891da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long); 19901da177e4SLinus Torvalds 19919ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv) 19929ec52099SCedric Le Goater { 19939ec52099SCedric Le Goater return kill_pid(cad_pid, sig, priv); 19949ec52099SCedric Le Goater } 19959ec52099SCedric Le Goater 19961da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info. */ 19971da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0) 19981da177e4SLinus Torvalds #define SEND_SIG_PRIV ((struct siginfo *) 1) 19991da177e4SLinus Torvalds #define SEND_SIG_FORCED ((struct siginfo *) 2) 20001da177e4SLinus Torvalds 2001621d3121SOleg Nesterov static inline int is_si_special(const struct siginfo *info) 2002621d3121SOleg Nesterov { 2003621d3121SOleg Nesterov return info <= SEND_SIG_FORCED; 2004621d3121SOleg Nesterov } 2005621d3121SOleg Nesterov 20061da177e4SLinus Torvalds /* True if we are on the alternate signal stack. */ 20071da177e4SLinus Torvalds 20081da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp) 20091da177e4SLinus Torvalds { 20101da177e4SLinus Torvalds return (sp - current->sas_ss_sp < current->sas_ss_size); 20111da177e4SLinus Torvalds } 20121da177e4SLinus Torvalds 20131da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp) 20141da177e4SLinus Torvalds { 20151da177e4SLinus Torvalds return (current->sas_ss_size == 0 ? SS_DISABLE 20161da177e4SLinus Torvalds : on_sig_stack(sp) ? SS_ONSTACK : 0); 20171da177e4SLinus Torvalds } 20181da177e4SLinus Torvalds 20191da177e4SLinus Torvalds /* 20201da177e4SLinus Torvalds * Routines for handling mm_structs 20211da177e4SLinus Torvalds */ 20221da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void); 20231da177e4SLinus Torvalds 20241da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */ 2025b3c97528SHarvey Harrison extern void __mmdrop(struct mm_struct *); 20261da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm) 20271da177e4SLinus Torvalds { 20286fb43d7bSIngo Molnar if (unlikely(atomic_dec_and_test(&mm->mm_count))) 20291da177e4SLinus Torvalds __mmdrop(mm); 20301da177e4SLinus Torvalds } 20311da177e4SLinus Torvalds 20321da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */ 20331da177e4SLinus Torvalds extern void mmput(struct mm_struct *); 20341da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */ 20351da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task); 20361da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */ 20371da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *); 2038402b0862SCarsten Otte /* Allocate a new mm structure and copy contents from tsk->mm */ 2039402b0862SCarsten Otte extern struct mm_struct *dup_mm(struct task_struct *tsk); 20401da177e4SLinus Torvalds 20416f2c55b8SAlexey Dobriyan extern int copy_thread(unsigned long, unsigned long, unsigned long, 20426f2c55b8SAlexey Dobriyan struct task_struct *, struct pt_regs *); 20431da177e4SLinus Torvalds extern void flush_thread(void); 20441da177e4SLinus Torvalds extern void exit_thread(void); 20451da177e4SLinus Torvalds 20461da177e4SLinus Torvalds extern void exit_files(struct task_struct *); 20476b3934efSOleg Nesterov extern void __cleanup_signal(struct signal_struct *); 2048a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *); 2049cbaffba1SOleg Nesterov 20501da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *); 2051cbaffba1SOleg Nesterov extern void flush_itimer_signals(void); 20521da177e4SLinus Torvalds 20531da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int); 20541da177e4SLinus Torvalds 20551da177e4SLinus Torvalds extern void daemonize(const char *, ...); 20561da177e4SLinus Torvalds extern int allow_signal(int); 20571da177e4SLinus Torvalds extern int disallow_signal(int); 20581da177e4SLinus Torvalds 20591da177e4SLinus Torvalds extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *); 20601da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *); 206136c8b586SIngo Molnar struct task_struct *fork_idle(int); 20621da177e4SLinus Torvalds 20631da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from); 206459714d65SAndrew Morton extern char *get_task_comm(char *to, struct task_struct *tsk); 20651da177e4SLinus Torvalds 20661da177e4SLinus Torvalds #ifdef CONFIG_SMP 2067a26b89f0SMarkus Metzger extern void wait_task_context_switch(struct task_struct *p); 206885ba2d86SRoland McGrath extern unsigned long wait_task_inactive(struct task_struct *, long match_state); 20691da177e4SLinus Torvalds #else 2070a26b89f0SMarkus Metzger static inline void wait_task_context_switch(struct task_struct *p) {} 207185ba2d86SRoland McGrath static inline unsigned long wait_task_inactive(struct task_struct *p, 207285ba2d86SRoland McGrath long match_state) 207385ba2d86SRoland McGrath { 207485ba2d86SRoland McGrath return 1; 207585ba2d86SRoland McGrath } 20761da177e4SLinus Torvalds #endif 20771da177e4SLinus Torvalds 207805725f7eSJiri Pirko #define next_task(p) \ 207905725f7eSJiri Pirko list_entry_rcu((p)->tasks.next, struct task_struct, tasks) 20801da177e4SLinus Torvalds 20811da177e4SLinus Torvalds #define for_each_process(p) \ 20821da177e4SLinus Torvalds for (p = &init_task ; (p = next_task(p)) != &init_task ; ) 20831da177e4SLinus Torvalds 2084d84f4f99SDavid Howells extern bool is_single_threaded(struct task_struct *); 2085d84f4f99SDavid Howells 20861da177e4SLinus Torvalds /* 20871da177e4SLinus Torvalds * Careful: do_each_thread/while_each_thread is a double loop so 20881da177e4SLinus Torvalds * 'break' will not work as expected - use goto instead. 20891da177e4SLinus Torvalds */ 20901da177e4SLinus Torvalds #define do_each_thread(g, t) \ 20911da177e4SLinus Torvalds for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do 20921da177e4SLinus Torvalds 20931da177e4SLinus Torvalds #define while_each_thread(g, t) \ 20941da177e4SLinus Torvalds while ((t = next_thread(t)) != g) 20951da177e4SLinus Torvalds 2096de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */ 2097de12a787SEric W. Biederman #define thread_group_leader(p) (p == p->group_leader) 20981da177e4SLinus Torvalds 20990804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process 21000804ef4bSEric W. Biederman * to have the pid of the thread group leader without actually being 21010804ef4bSEric W. Biederman * the thread group leader. For iteration through the pids in proc 21020804ef4bSEric W. Biederman * all we care about is that we have a task with the appropriate 21030804ef4bSEric W. Biederman * pid, we don't actually care if we have the right task. 21040804ef4bSEric W. Biederman */ 2105e868171aSAlexey Dobriyan static inline int has_group_leader_pid(struct task_struct *p) 21060804ef4bSEric W. Biederman { 21070804ef4bSEric W. Biederman return p->pid == p->tgid; 21080804ef4bSEric W. Biederman } 21090804ef4bSEric W. Biederman 2110bac0abd6SPavel Emelyanov static inline 2111bac0abd6SPavel Emelyanov int same_thread_group(struct task_struct *p1, struct task_struct *p2) 2112bac0abd6SPavel Emelyanov { 2113bac0abd6SPavel Emelyanov return p1->tgid == p2->tgid; 2114bac0abd6SPavel Emelyanov } 2115bac0abd6SPavel Emelyanov 211636c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p) 211747e65328SOleg Nesterov { 211805725f7eSJiri Pirko return list_entry_rcu(p->thread_group.next, 211936c8b586SIngo Molnar struct task_struct, thread_group); 212047e65328SOleg Nesterov } 212147e65328SOleg Nesterov 2122e868171aSAlexey Dobriyan static inline int thread_group_empty(struct task_struct *p) 21231da177e4SLinus Torvalds { 212447e65328SOleg Nesterov return list_empty(&p->thread_group); 21251da177e4SLinus Torvalds } 21261da177e4SLinus Torvalds 21271da177e4SLinus Torvalds #define delay_group_leader(p) \ 21281da177e4SLinus Torvalds (thread_group_leader(p) && !thread_group_empty(p)) 21291da177e4SLinus Torvalds 213039c626aeSOleg Nesterov static inline int task_detached(struct task_struct *p) 213139c626aeSOleg Nesterov { 213239c626aeSOleg Nesterov return p->exit_signal == -1; 213339c626aeSOleg Nesterov } 213439c626aeSOleg Nesterov 21351da177e4SLinus Torvalds /* 2136260ea101SEric W. Biederman * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring 213722e2c507SJens Axboe * subscriptions and synchronises with wait4(). Also used in procfs. Also 2138ddbcc7e8SPaul Menage * pins the final release of task.io_context. Also protects ->cpuset and 2139ddbcc7e8SPaul Menage * ->cgroup.subsys[]. 21401da177e4SLinus Torvalds * 21411da177e4SLinus Torvalds * Nests both inside and outside of read_lock(&tasklist_lock). 21421da177e4SLinus Torvalds * It must not be nested with write_lock_irq(&tasklist_lock), 21431da177e4SLinus Torvalds * neither inside nor outside. 21441da177e4SLinus Torvalds */ 21451da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p) 21461da177e4SLinus Torvalds { 21471da177e4SLinus Torvalds spin_lock(&p->alloc_lock); 21481da177e4SLinus Torvalds } 21491da177e4SLinus Torvalds 21501da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p) 21511da177e4SLinus Torvalds { 21521da177e4SLinus Torvalds spin_unlock(&p->alloc_lock); 21531da177e4SLinus Torvalds } 21541da177e4SLinus Torvalds 2155f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk, 2156f63ee72eSOleg Nesterov unsigned long *flags); 2157f63ee72eSOleg Nesterov 2158f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk, 2159f63ee72eSOleg Nesterov unsigned long *flags) 2160f63ee72eSOleg Nesterov { 2161f63ee72eSOleg Nesterov spin_unlock_irqrestore(&tsk->sighand->siglock, *flags); 2162f63ee72eSOleg Nesterov } 2163f63ee72eSOleg Nesterov 2164f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS 2165f037360fSAl Viro 2166f7e4217bSRoman Zippel #define task_thread_info(task) ((struct thread_info *)(task)->stack) 2167f7e4217bSRoman Zippel #define task_stack_page(task) ((task)->stack) 2168a1261f54SAl Viro 216910ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org) 217010ebffdeSAl Viro { 217110ebffdeSAl Viro *task_thread_info(p) = *task_thread_info(org); 217210ebffdeSAl Viro task_thread_info(p)->task = p; 217310ebffdeSAl Viro } 217410ebffdeSAl Viro 217510ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p) 217610ebffdeSAl Viro { 2177f7e4217bSRoman Zippel return (unsigned long *)(task_thread_info(p) + 1); 217810ebffdeSAl Viro } 217910ebffdeSAl Viro 2180f037360fSAl Viro #endif 2181f037360fSAl Viro 21828b05c7e6SFUJITA Tomonori static inline int object_is_on_stack(void *obj) 21838b05c7e6SFUJITA Tomonori { 21848b05c7e6SFUJITA Tomonori void *stack = task_stack_page(current); 21858b05c7e6SFUJITA Tomonori 21868b05c7e6SFUJITA Tomonori return (obj >= stack) && (obj < (stack + THREAD_SIZE)); 21878b05c7e6SFUJITA Tomonori } 21888b05c7e6SFUJITA Tomonori 21898c9843e5SBenjamin Herrenschmidt extern void thread_info_cache_init(void); 21908c9843e5SBenjamin Herrenschmidt 21917c9f8861SEric Sandeen #ifdef CONFIG_DEBUG_STACK_USAGE 21927c9f8861SEric Sandeen static inline unsigned long stack_not_used(struct task_struct *p) 21937c9f8861SEric Sandeen { 21947c9f8861SEric Sandeen unsigned long *n = end_of_stack(p); 21957c9f8861SEric Sandeen 21967c9f8861SEric Sandeen do { /* Skip over canary */ 21977c9f8861SEric Sandeen n++; 21987c9f8861SEric Sandeen } while (!*n); 21997c9f8861SEric Sandeen 22007c9f8861SEric Sandeen return (unsigned long)n - (unsigned long)end_of_stack(p); 22017c9f8861SEric Sandeen } 22027c9f8861SEric Sandeen #endif 22037c9f8861SEric Sandeen 22041da177e4SLinus Torvalds /* set thread flags in other task's structures 22051da177e4SLinus Torvalds * - see asm/thread_info.h for TIF_xxxx flags available 22061da177e4SLinus Torvalds */ 22071da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag) 22081da177e4SLinus Torvalds { 2209a1261f54SAl Viro set_ti_thread_flag(task_thread_info(tsk), flag); 22101da177e4SLinus Torvalds } 22111da177e4SLinus Torvalds 22121da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag) 22131da177e4SLinus Torvalds { 2214a1261f54SAl Viro clear_ti_thread_flag(task_thread_info(tsk), flag); 22151da177e4SLinus Torvalds } 22161da177e4SLinus Torvalds 22171da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag) 22181da177e4SLinus Torvalds { 2219a1261f54SAl Viro return test_and_set_ti_thread_flag(task_thread_info(tsk), flag); 22201da177e4SLinus Torvalds } 22211da177e4SLinus Torvalds 22221da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag) 22231da177e4SLinus Torvalds { 2224a1261f54SAl Viro return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag); 22251da177e4SLinus Torvalds } 22261da177e4SLinus Torvalds 22271da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag) 22281da177e4SLinus Torvalds { 2229a1261f54SAl Viro return test_ti_thread_flag(task_thread_info(tsk), flag); 22301da177e4SLinus Torvalds } 22311da177e4SLinus Torvalds 22321da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk) 22331da177e4SLinus Torvalds { 22341da177e4SLinus Torvalds set_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 22351da177e4SLinus Torvalds } 22361da177e4SLinus Torvalds 22371da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk) 22381da177e4SLinus Torvalds { 22391da177e4SLinus Torvalds clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 22401da177e4SLinus Torvalds } 22411da177e4SLinus Torvalds 22428ae121acSGregory Haskins static inline int test_tsk_need_resched(struct task_struct *tsk) 22438ae121acSGregory Haskins { 22448ae121acSGregory Haskins return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED)); 22458ae121acSGregory Haskins } 22468ae121acSGregory Haskins 2247690cc3ffSEric W. Biederman static inline int restart_syscall(void) 2248690cc3ffSEric W. Biederman { 2249690cc3ffSEric W. Biederman set_tsk_thread_flag(current, TIF_SIGPENDING); 2250690cc3ffSEric W. Biederman return -ERESTARTNOINTR; 2251690cc3ffSEric W. Biederman } 2252690cc3ffSEric W. Biederman 22531da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p) 22541da177e4SLinus Torvalds { 22551da177e4SLinus Torvalds return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING)); 22561da177e4SLinus Torvalds } 22571da177e4SLinus Torvalds 2258b3c97528SHarvey Harrison extern int __fatal_signal_pending(struct task_struct *p); 2259f776d12dSMatthew Wilcox 2260f776d12dSMatthew Wilcox static inline int fatal_signal_pending(struct task_struct *p) 2261f776d12dSMatthew Wilcox { 2262f776d12dSMatthew Wilcox return signal_pending(p) && __fatal_signal_pending(p); 2263f776d12dSMatthew Wilcox } 2264f776d12dSMatthew Wilcox 226516882c1eSOleg Nesterov static inline int signal_pending_state(long state, struct task_struct *p) 226616882c1eSOleg Nesterov { 226716882c1eSOleg Nesterov if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL))) 226816882c1eSOleg Nesterov return 0; 226916882c1eSOleg Nesterov if (!signal_pending(p)) 227016882c1eSOleg Nesterov return 0; 227116882c1eSOleg Nesterov 227216882c1eSOleg Nesterov return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p); 227316882c1eSOleg Nesterov } 227416882c1eSOleg Nesterov 22751da177e4SLinus Torvalds static inline int need_resched(void) 22761da177e4SLinus Torvalds { 22779404ef02SLinus Torvalds return unlikely(test_thread_flag(TIF_NEED_RESCHED)); 22781da177e4SLinus Torvalds } 22791da177e4SLinus Torvalds 22801da177e4SLinus Torvalds /* 22811da177e4SLinus Torvalds * cond_resched() and cond_resched_lock(): latency reduction via 22821da177e4SLinus Torvalds * explicit rescheduling in places that are safe. The return 22831da177e4SLinus Torvalds * value indicates whether a reschedule was done in fact. 22841da177e4SLinus Torvalds * cond_resched_lock() will drop the spinlock before scheduling, 22851da177e4SLinus Torvalds * cond_resched_softirq() will enable bhs before scheduling. 22861da177e4SLinus Torvalds */ 2287c3921ab7SLinus Torvalds extern int _cond_resched(void); 2288*6f80bd98SFrederic Weisbecker 228902b67cc3SHerbert Xu static inline int cond_resched(void) 229002b67cc3SHerbert Xu { 229102b67cc3SHerbert Xu return _cond_resched(); 229202b67cc3SHerbert Xu } 2293*6f80bd98SFrederic Weisbecker 22941da177e4SLinus Torvalds extern int cond_resched_lock(spinlock_t * lock); 22951da177e4SLinus Torvalds extern int cond_resched_softirq(void); 2296c3921ab7SLinus Torvalds static inline int cond_resched_bkl(void) 2297c3921ab7SLinus Torvalds { 2298c3921ab7SLinus Torvalds return _cond_resched(); 2299c3921ab7SLinus Torvalds } 23001da177e4SLinus Torvalds 23011da177e4SLinus Torvalds /* 23021da177e4SLinus Torvalds * Does a critical section need to be broken due to another 230395c354feSNick Piggin * task waiting?: (technically does not depend on CONFIG_PREEMPT, 230495c354feSNick Piggin * but a general need for low latency) 23051da177e4SLinus Torvalds */ 230695c354feSNick Piggin static inline int spin_needbreak(spinlock_t *lock) 23071da177e4SLinus Torvalds { 230895c354feSNick Piggin #ifdef CONFIG_PREEMPT 230995c354feSNick Piggin return spin_is_contended(lock); 231095c354feSNick Piggin #else 23111da177e4SLinus Torvalds return 0; 231295c354feSNick Piggin #endif 23131da177e4SLinus Torvalds } 23141da177e4SLinus Torvalds 23157bb44adeSRoland McGrath /* 2316f06febc9SFrank Mayhar * Thread group CPU time accounting. 2317f06febc9SFrank Mayhar */ 23184cd4c1b4SPeter Zijlstra void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times); 23194da94d49SPeter Zijlstra void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times); 2320f06febc9SFrank Mayhar 2321f06febc9SFrank Mayhar static inline void thread_group_cputime_init(struct signal_struct *sig) 2322f06febc9SFrank Mayhar { 23234cd4c1b4SPeter Zijlstra sig->cputimer.cputime = INIT_CPUTIME; 23244cd4c1b4SPeter Zijlstra spin_lock_init(&sig->cputimer.lock); 23254cd4c1b4SPeter Zijlstra sig->cputimer.running = 0; 2326f06febc9SFrank Mayhar } 2327f06febc9SFrank Mayhar 2328f06febc9SFrank Mayhar static inline void thread_group_cputime_free(struct signal_struct *sig) 2329f06febc9SFrank Mayhar { 2330f06febc9SFrank Mayhar } 2331f06febc9SFrank Mayhar 2332f06febc9SFrank Mayhar /* 23337bb44adeSRoland McGrath * Reevaluate whether the task has signals pending delivery. 23347bb44adeSRoland McGrath * Wake the task if so. 23357bb44adeSRoland McGrath * This is required every time the blocked sigset_t changes. 23367bb44adeSRoland McGrath * callers must hold sighand->siglock. 23377bb44adeSRoland McGrath */ 23387bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t); 23391da177e4SLinus Torvalds extern void recalc_sigpending(void); 23401da177e4SLinus Torvalds 23411da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped); 23421da177e4SLinus Torvalds 23431da177e4SLinus Torvalds /* 23441da177e4SLinus Torvalds * Wrappers for p->thread_info->cpu access. No-op on UP. 23451da177e4SLinus Torvalds */ 23461da177e4SLinus Torvalds #ifdef CONFIG_SMP 23471da177e4SLinus Torvalds 23481da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 23491da177e4SLinus Torvalds { 2350a1261f54SAl Viro return task_thread_info(p)->cpu; 23511da177e4SLinus Torvalds } 23521da177e4SLinus Torvalds 2353c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu); 23541da177e4SLinus Torvalds 23551da177e4SLinus Torvalds #else 23561da177e4SLinus Torvalds 23571da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 23581da177e4SLinus Torvalds { 23591da177e4SLinus Torvalds return 0; 23601da177e4SLinus Torvalds } 23611da177e4SLinus Torvalds 23621da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu) 23631da177e4SLinus Torvalds { 23641da177e4SLinus Torvalds } 23651da177e4SLinus Torvalds 23661da177e4SLinus Torvalds #endif /* CONFIG_SMP */ 23671da177e4SLinus Torvalds 23681da177e4SLinus Torvalds extern void arch_pick_mmap_layout(struct mm_struct *mm); 23691da177e4SLinus Torvalds 23701a3c3034SIngo Molnar #ifdef CONFIG_TRACING 23711a3c3034SIngo Molnar extern void 23721a3c3034SIngo Molnar __trace_special(void *__tr, void *__data, 23731a3c3034SIngo Molnar unsigned long arg1, unsigned long arg2, unsigned long arg3); 23741da177e4SLinus Torvalds #else 23751a3c3034SIngo Molnar static inline void 23761a3c3034SIngo Molnar __trace_special(void *__tr, void *__data, 23771a3c3034SIngo Molnar unsigned long arg1, unsigned long arg2, unsigned long arg3) 23781da177e4SLinus Torvalds { 23791da177e4SLinus Torvalds } 23801da177e4SLinus Torvalds #endif 23811da177e4SLinus Torvalds 238296f874e2SRusty Russell extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask); 238396f874e2SRusty Russell extern long sched_getaffinity(pid_t pid, struct cpumask *mask); 23845c45bf27SSiddha, Suresh B 23851da177e4SLinus Torvalds extern void normalize_rt_tasks(void); 23861da177e4SLinus Torvalds 2387052f1dc7SPeter Zijlstra #ifdef CONFIG_GROUP_SCHED 23889b5b7751SSrivatsa Vaddagiri 23894cf86d77SIngo Molnar extern struct task_group init_task_group; 2390eff766a6SPeter Zijlstra #ifdef CONFIG_USER_SCHED 2391eff766a6SPeter Zijlstra extern struct task_group root_task_group; 23926c415b92SArun R Bharadwaj extern void set_tg_uid(struct user_struct *user); 2393eff766a6SPeter Zijlstra #endif 23949b5b7751SSrivatsa Vaddagiri 2395ec7dc8acSDhaval Giani extern struct task_group *sched_create_group(struct task_group *parent); 23964cf86d77SIngo Molnar extern void sched_destroy_group(struct task_group *tg); 23979b5b7751SSrivatsa Vaddagiri extern void sched_move_task(struct task_struct *tsk); 2398052f1dc7SPeter Zijlstra #ifdef CONFIG_FAIR_GROUP_SCHED 23994cf86d77SIngo Molnar extern int sched_group_set_shares(struct task_group *tg, unsigned long shares); 24005cb350baSDhaval Giani extern unsigned long sched_group_shares(struct task_group *tg); 2401052f1dc7SPeter Zijlstra #endif 2402052f1dc7SPeter Zijlstra #ifdef CONFIG_RT_GROUP_SCHED 24039f0c1e56SPeter Zijlstra extern int sched_group_set_rt_runtime(struct task_group *tg, 24049f0c1e56SPeter Zijlstra long rt_runtime_us); 24059f0c1e56SPeter Zijlstra extern long sched_group_rt_runtime(struct task_group *tg); 2406d0b27fa7SPeter Zijlstra extern int sched_group_set_rt_period(struct task_group *tg, 2407d0b27fa7SPeter Zijlstra long rt_period_us); 2408d0b27fa7SPeter Zijlstra extern long sched_group_rt_period(struct task_group *tg); 240954e99124SDhaval Giani extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk); 2410052f1dc7SPeter Zijlstra #endif 24119b5b7751SSrivatsa Vaddagiri #endif 24129b5b7751SSrivatsa Vaddagiri 241354e99124SDhaval Giani extern int task_can_switch_user(struct user_struct *up, 241454e99124SDhaval Giani struct task_struct *tsk); 241554e99124SDhaval Giani 24164b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT 24174b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 24184b98d11bSAlexey Dobriyan { 2419940389b8SAndrea Righi tsk->ioac.rchar += amt; 24204b98d11bSAlexey Dobriyan } 24214b98d11bSAlexey Dobriyan 24224b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 24234b98d11bSAlexey Dobriyan { 2424940389b8SAndrea Righi tsk->ioac.wchar += amt; 24254b98d11bSAlexey Dobriyan } 24264b98d11bSAlexey Dobriyan 24274b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 24284b98d11bSAlexey Dobriyan { 2429940389b8SAndrea Righi tsk->ioac.syscr++; 24304b98d11bSAlexey Dobriyan } 24314b98d11bSAlexey Dobriyan 24324b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 24334b98d11bSAlexey Dobriyan { 2434940389b8SAndrea Righi tsk->ioac.syscw++; 24354b98d11bSAlexey Dobriyan } 24364b98d11bSAlexey Dobriyan #else 24374b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 24384b98d11bSAlexey Dobriyan { 24394b98d11bSAlexey Dobriyan } 24404b98d11bSAlexey Dobriyan 24414b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 24424b98d11bSAlexey Dobriyan { 24434b98d11bSAlexey Dobriyan } 24444b98d11bSAlexey Dobriyan 24454b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 24464b98d11bSAlexey Dobriyan { 24474b98d11bSAlexey Dobriyan } 24484b98d11bSAlexey Dobriyan 24494b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 24504b98d11bSAlexey Dobriyan { 24514b98d11bSAlexey Dobriyan } 24524b98d11bSAlexey Dobriyan #endif 24534b98d11bSAlexey Dobriyan 245482455257SDave Hansen #ifndef TASK_SIZE_OF 245582455257SDave Hansen #define TASK_SIZE_OF(tsk) TASK_SIZE 245682455257SDave Hansen #endif 245782455257SDave Hansen 24580793a61dSThomas Gleixner /* 24590793a61dSThomas Gleixner * Call the function if the target task is executing on a CPU right now: 24600793a61dSThomas Gleixner */ 24610793a61dSThomas Gleixner extern void task_oncpu_function_call(struct task_struct *p, 24620793a61dSThomas Gleixner void (*func) (void *info), void *info); 24630793a61dSThomas Gleixner 24640793a61dSThomas Gleixner 2465cf475ad2SBalbir Singh #ifdef CONFIG_MM_OWNER 2466cf475ad2SBalbir Singh extern void mm_update_next_owner(struct mm_struct *mm); 2467cf475ad2SBalbir Singh extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p); 2468cf475ad2SBalbir Singh #else 2469cf475ad2SBalbir Singh static inline void mm_update_next_owner(struct mm_struct *mm) 2470cf475ad2SBalbir Singh { 2471cf475ad2SBalbir Singh } 2472cf475ad2SBalbir Singh 2473cf475ad2SBalbir Singh static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p) 2474cf475ad2SBalbir Singh { 2475cf475ad2SBalbir Singh } 2476cf475ad2SBalbir Singh #endif /* CONFIG_MM_OWNER */ 2477cf475ad2SBalbir Singh 24787c731e0aSSteven Rostedt #define TASK_STATE_TO_CHAR_STR "RSDTtZX" 24797c731e0aSSteven Rostedt 24801da177e4SLinus Torvalds #endif /* __KERNEL__ */ 24811da177e4SLinus Torvalds 24821da177e4SLinus Torvalds #endif 2483