11da177e4SLinus Torvalds #ifndef _LINUX_SCHED_H 21da177e4SLinus Torvalds #define _LINUX_SCHED_H 31da177e4SLinus Torvalds 4b7b3c76aSDavid Woodhouse #include <linux/auxvec.h> /* For AT_VECTOR_SIZE */ 5b7b3c76aSDavid Woodhouse 6b7b3c76aSDavid Woodhouse /* 7b7b3c76aSDavid Woodhouse * cloning flags: 8b7b3c76aSDavid Woodhouse */ 9b7b3c76aSDavid Woodhouse #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */ 10b7b3c76aSDavid Woodhouse #define CLONE_VM 0x00000100 /* set if VM shared between processes */ 11b7b3c76aSDavid Woodhouse #define CLONE_FS 0x00000200 /* set if fs info shared between processes */ 12b7b3c76aSDavid Woodhouse #define CLONE_FILES 0x00000400 /* set if open files shared between processes */ 13b7b3c76aSDavid Woodhouse #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */ 14b7b3c76aSDavid Woodhouse #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */ 15b7b3c76aSDavid Woodhouse #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */ 16b7b3c76aSDavid Woodhouse #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */ 17b7b3c76aSDavid Woodhouse #define CLONE_THREAD 0x00010000 /* Same thread group? */ 18b7b3c76aSDavid Woodhouse #define CLONE_NEWNS 0x00020000 /* New namespace group? */ 19b7b3c76aSDavid Woodhouse #define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */ 20b7b3c76aSDavid Woodhouse #define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */ 21b7b3c76aSDavid Woodhouse #define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */ 22b7b3c76aSDavid Woodhouse #define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */ 23b7b3c76aSDavid Woodhouse #define CLONE_DETACHED 0x00400000 /* Unused, ignored */ 24b7b3c76aSDavid Woodhouse #define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */ 25b7b3c76aSDavid Woodhouse #define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */ 26b7b3c76aSDavid Woodhouse #define CLONE_STOPPED 0x02000000 /* Start in stopped state */ 27071df104SSerge E. Hallyn #define CLONE_NEWUTS 0x04000000 /* New utsname group? */ 2825b21cb2SKirill Korotaev #define CLONE_NEWIPC 0x08000000 /* New ipcs */ 29b7b3c76aSDavid Woodhouse 30b7b3c76aSDavid Woodhouse /* 31b7b3c76aSDavid Woodhouse * Scheduling policies 32b7b3c76aSDavid Woodhouse */ 33b7b3c76aSDavid Woodhouse #define SCHED_NORMAL 0 34b7b3c76aSDavid Woodhouse #define SCHED_FIFO 1 35b7b3c76aSDavid Woodhouse #define SCHED_RR 2 36b7b3c76aSDavid Woodhouse #define SCHED_BATCH 3 370e6aca43SIngo Molnar /* SCHED_ISO: reserved but not implemented yet */ 380e6aca43SIngo Molnar #define SCHED_IDLE 5 39b7b3c76aSDavid Woodhouse 40a3b6714eSDavid Woodhouse #ifdef __KERNEL__ 41b7b3c76aSDavid Woodhouse 42b7b3c76aSDavid Woodhouse struct sched_param { 43b7b3c76aSDavid Woodhouse int sched_priority; 44b7b3c76aSDavid Woodhouse }; 45b7b3c76aSDavid Woodhouse 461da177e4SLinus Torvalds #include <asm/param.h> /* for HZ */ 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds #include <linux/capability.h> 491da177e4SLinus Torvalds #include <linux/threads.h> 501da177e4SLinus Torvalds #include <linux/kernel.h> 511da177e4SLinus Torvalds #include <linux/types.h> 521da177e4SLinus Torvalds #include <linux/timex.h> 531da177e4SLinus Torvalds #include <linux/jiffies.h> 541da177e4SLinus Torvalds #include <linux/rbtree.h> 551da177e4SLinus Torvalds #include <linux/thread_info.h> 561da177e4SLinus Torvalds #include <linux/cpumask.h> 571da177e4SLinus Torvalds #include <linux/errno.h> 581da177e4SLinus Torvalds #include <linux/nodemask.h> 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds #include <asm/system.h> 611da177e4SLinus Torvalds #include <asm/semaphore.h> 621da177e4SLinus Torvalds #include <asm/page.h> 631da177e4SLinus Torvalds #include <asm/ptrace.h> 641da177e4SLinus Torvalds #include <asm/mmu.h> 651da177e4SLinus Torvalds #include <asm/cputime.h> 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds #include <linux/smp.h> 681da177e4SLinus Torvalds #include <linux/sem.h> 691da177e4SLinus Torvalds #include <linux/signal.h> 701da177e4SLinus Torvalds #include <linux/securebits.h> 711da177e4SLinus Torvalds #include <linux/fs_struct.h> 721da177e4SLinus Torvalds #include <linux/compiler.h> 731da177e4SLinus Torvalds #include <linux/completion.h> 741da177e4SLinus Torvalds #include <linux/pid.h> 751da177e4SLinus Torvalds #include <linux/percpu.h> 761da177e4SLinus Torvalds #include <linux/topology.h> 771da177e4SLinus Torvalds #include <linux/seccomp.h> 78e56d0903SIngo Molnar #include <linux/rcupdate.h> 790771dfefSIngo Molnar #include <linux/futex.h> 8023f78d4aSIngo Molnar #include <linux/rtmutex.h> 811da177e4SLinus Torvalds 82a3b6714eSDavid Woodhouse #include <linux/time.h> 83a3b6714eSDavid Woodhouse #include <linux/param.h> 84a3b6714eSDavid Woodhouse #include <linux/resource.h> 85a3b6714eSDavid Woodhouse #include <linux/timer.h> 86a3b6714eSDavid Woodhouse #include <linux/hrtimer.h> 877c3ab738SAndrew Morton #include <linux/task_io_accounting.h> 88a3b6714eSDavid Woodhouse 89a3b6714eSDavid Woodhouse #include <asm/processor.h> 9036d57ac4SH. J. Lu 911da177e4SLinus Torvalds struct exec_domain; 92c87e2837SIngo Molnar struct futex_pi_state; 93d89d8796SNeil Brown struct bio; 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds /* 961da177e4SLinus Torvalds * List of flags we want to share for kernel threads, 971da177e4SLinus Torvalds * if only because they are not used by them anyway. 981da177e4SLinus Torvalds */ 991da177e4SLinus Torvalds #define CLONE_KERNEL (CLONE_FS | CLONE_FILES | CLONE_SIGHAND) 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds /* 1021da177e4SLinus Torvalds * These are the constant used to fake the fixed-point load-average 1031da177e4SLinus Torvalds * counting. Some notes: 1041da177e4SLinus Torvalds * - 11 bit fractions expand to 22 bits by the multiplies: this gives 1051da177e4SLinus Torvalds * a load-average precision of 10 bits integer + 11 bits fractional 1061da177e4SLinus Torvalds * - if you want to count load-averages more often, you need more 1071da177e4SLinus Torvalds * precision, or rounding will get you. With 2-second counting freq, 1081da177e4SLinus Torvalds * the EXP_n values would be 1981, 2034 and 2043 if still using only 1091da177e4SLinus Torvalds * 11 bit fractions. 1101da177e4SLinus Torvalds */ 1111da177e4SLinus Torvalds extern unsigned long avenrun[]; /* Load averages */ 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds #define FSHIFT 11 /* nr of bits of precision */ 1141da177e4SLinus Torvalds #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ 1151da177e4SLinus Torvalds #define LOAD_FREQ (5*HZ) /* 5 sec intervals */ 1161da177e4SLinus Torvalds #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ 1171da177e4SLinus Torvalds #define EXP_5 2014 /* 1/exp(5sec/5min) */ 1181da177e4SLinus Torvalds #define EXP_15 2037 /* 1/exp(5sec/15min) */ 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds #define CALC_LOAD(load,exp,n) \ 1211da177e4SLinus Torvalds load *= exp; \ 1221da177e4SLinus Torvalds load += n*(FIXED_1-exp); \ 1231da177e4SLinus Torvalds load >>= FSHIFT; 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds extern unsigned long total_forks; 1261da177e4SLinus Torvalds extern int nr_threads; 1271da177e4SLinus Torvalds DECLARE_PER_CPU(unsigned long, process_counts); 1281da177e4SLinus Torvalds extern int nr_processes(void); 1291da177e4SLinus Torvalds extern unsigned long nr_running(void); 1301da177e4SLinus Torvalds extern unsigned long nr_uninterruptible(void); 131db1b1fefSJack Steiner extern unsigned long nr_active(void); 1321da177e4SLinus Torvalds extern unsigned long nr_iowait(void); 1332dd73a4fSPeter Williams extern unsigned long weighted_cpuload(const int cpu); 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds 1364a8342d2SLinus Torvalds /* 1374a8342d2SLinus Torvalds * Task state bitmask. NOTE! These bits are also 1384a8342d2SLinus Torvalds * encoded in fs/proc/array.c: get_task_state(). 1394a8342d2SLinus Torvalds * 1404a8342d2SLinus Torvalds * We have two separate sets of flags: task->state 1414a8342d2SLinus Torvalds * is about runnability, while task->exit_state are 1424a8342d2SLinus Torvalds * about the task exiting. Confusing, but this way 1434a8342d2SLinus Torvalds * modifying one set can't modify the other one by 1444a8342d2SLinus Torvalds * mistake. 1454a8342d2SLinus Torvalds */ 1461da177e4SLinus Torvalds #define TASK_RUNNING 0 1471da177e4SLinus Torvalds #define TASK_INTERRUPTIBLE 1 1481da177e4SLinus Torvalds #define TASK_UNINTERRUPTIBLE 2 1494a8342d2SLinus Torvalds #define TASK_STOPPED 4 1504a8342d2SLinus Torvalds #define TASK_TRACED 8 1514a8342d2SLinus Torvalds /* in tsk->exit_state */ 1524a8342d2SLinus Torvalds #define EXIT_ZOMBIE 16 1534a8342d2SLinus Torvalds #define EXIT_DEAD 32 1544a8342d2SLinus Torvalds /* in tsk->state again */ 1554a8342d2SLinus Torvalds #define TASK_NONINTERACTIVE 64 156c394cc9fSOleg Nesterov #define TASK_DEAD 128 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds #define __set_task_state(tsk, state_value) \ 1591da177e4SLinus Torvalds do { (tsk)->state = (state_value); } while (0) 1601da177e4SLinus Torvalds #define set_task_state(tsk, state_value) \ 1611da177e4SLinus Torvalds set_mb((tsk)->state, (state_value)) 1621da177e4SLinus Torvalds 163498d0c57SAndrew Morton /* 164498d0c57SAndrew Morton * set_current_state() includes a barrier so that the write of current->state 165498d0c57SAndrew Morton * is correctly serialised wrt the caller's subsequent test of whether to 166498d0c57SAndrew Morton * actually sleep: 167498d0c57SAndrew Morton * 168498d0c57SAndrew Morton * set_current_state(TASK_UNINTERRUPTIBLE); 169498d0c57SAndrew Morton * if (do_i_need_to_sleep()) 170498d0c57SAndrew Morton * schedule(); 171498d0c57SAndrew Morton * 172498d0c57SAndrew Morton * If the caller does not need such serialisation then use __set_current_state() 173498d0c57SAndrew Morton */ 1741da177e4SLinus Torvalds #define __set_current_state(state_value) \ 1751da177e4SLinus Torvalds do { current->state = (state_value); } while (0) 1761da177e4SLinus Torvalds #define set_current_state(state_value) \ 1771da177e4SLinus Torvalds set_mb(current->state, (state_value)) 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds /* Task command name length */ 1801da177e4SLinus Torvalds #define TASK_COMM_LEN 16 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds #include <linux/spinlock.h> 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds /* 1851da177e4SLinus Torvalds * This serializes "schedule()" and also protects 1861da177e4SLinus Torvalds * the run-queue from deletions/modifications (but 1871da177e4SLinus Torvalds * _adding_ to the beginning of the run-queue has 1881da177e4SLinus Torvalds * a separate lock). 1891da177e4SLinus Torvalds */ 1901da177e4SLinus Torvalds extern rwlock_t tasklist_lock; 1911da177e4SLinus Torvalds extern spinlock_t mmlist_lock; 1921da177e4SLinus Torvalds 19336c8b586SIngo Molnar struct task_struct; 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds extern void sched_init(void); 1961da177e4SLinus Torvalds extern void sched_init_smp(void); 19736c8b586SIngo Molnar extern void init_idle(struct task_struct *idle, int cpu); 1981df21055SIngo Molnar extern void init_idle_bootup_task(struct task_struct *idle); 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds extern cpumask_t nohz_cpu_mask; 20146cb4b7cSSiddha, Suresh B #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ) 20246cb4b7cSSiddha, Suresh B extern int select_nohz_load_balancer(int cpu); 20346cb4b7cSSiddha, Suresh B #else 20446cb4b7cSSiddha, Suresh B static inline int select_nohz_load_balancer(int cpu) 20546cb4b7cSSiddha, Suresh B { 20646cb4b7cSSiddha, Suresh B return 0; 20746cb4b7cSSiddha, Suresh B } 20846cb4b7cSSiddha, Suresh B #endif 2091da177e4SLinus Torvalds 210e59e2ae2SIngo Molnar /* 21139bc89fdSIngo Molnar * Only dump TASK_* tasks. (0 for all tasks) 212e59e2ae2SIngo Molnar */ 213e59e2ae2SIngo Molnar extern void show_state_filter(unsigned long state_filter); 214e59e2ae2SIngo Molnar 215e59e2ae2SIngo Molnar static inline void show_state(void) 216e59e2ae2SIngo Molnar { 21739bc89fdSIngo Molnar show_state_filter(0); 218e59e2ae2SIngo Molnar } 219e59e2ae2SIngo Molnar 2201da177e4SLinus Torvalds extern void show_regs(struct pt_regs *); 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds /* 2231da177e4SLinus Torvalds * TASK is a pointer to the task whose backtrace we want to see (or NULL for current 2241da177e4SLinus Torvalds * task), SP is the stack pointer of the first frame that should be shown in the back 2251da177e4SLinus Torvalds * trace (or NULL if the entire call-chain of the task should be shown). 2261da177e4SLinus Torvalds */ 2271da177e4SLinus Torvalds extern void show_stack(struct task_struct *task, unsigned long *sp); 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds void io_schedule(void); 2301da177e4SLinus Torvalds long io_schedule_timeout(long timeout); 2311da177e4SLinus Torvalds 2321da177e4SLinus Torvalds extern void cpu_init (void); 2331da177e4SLinus Torvalds extern void trap_init(void); 2341da177e4SLinus Torvalds extern void update_process_times(int user); 2351da177e4SLinus Torvalds extern void scheduler_tick(void); 2361da177e4SLinus Torvalds 2378446f1d3SIngo Molnar #ifdef CONFIG_DETECT_SOFTLOCKUP 2386687a97dSIngo Molnar extern void softlockup_tick(void); 2398446f1d3SIngo Molnar extern void spawn_softlockup_task(void); 2408446f1d3SIngo Molnar extern void touch_softlockup_watchdog(void); 24104c9167fSJeremy Fitzhardinge extern void touch_all_softlockup_watchdogs(void); 2428446f1d3SIngo Molnar #else 2436687a97dSIngo Molnar static inline void softlockup_tick(void) 2448446f1d3SIngo Molnar { 2458446f1d3SIngo Molnar } 2468446f1d3SIngo Molnar static inline void spawn_softlockup_task(void) 2478446f1d3SIngo Molnar { 2488446f1d3SIngo Molnar } 2498446f1d3SIngo Molnar static inline void touch_softlockup_watchdog(void) 2508446f1d3SIngo Molnar { 2518446f1d3SIngo Molnar } 25204c9167fSJeremy Fitzhardinge static inline void touch_all_softlockup_watchdogs(void) 25304c9167fSJeremy Fitzhardinge { 25404c9167fSJeremy Fitzhardinge } 2558446f1d3SIngo Molnar #endif 2568446f1d3SIngo Molnar 2578446f1d3SIngo Molnar 2581da177e4SLinus Torvalds /* Attach to any functions which should be ignored in wchan output. */ 2591da177e4SLinus Torvalds #define __sched __attribute__((__section__(".sched.text"))) 2601da177e4SLinus Torvalds /* Is this address in the __sched functions? */ 2611da177e4SLinus Torvalds extern int in_sched_functions(unsigned long addr); 2621da177e4SLinus Torvalds 2631da177e4SLinus Torvalds #define MAX_SCHEDULE_TIMEOUT LONG_MAX 2641da177e4SLinus Torvalds extern signed long FASTCALL(schedule_timeout(signed long timeout)); 26564ed93a2SNishanth Aravamudan extern signed long schedule_timeout_interruptible(signed long timeout); 26664ed93a2SNishanth Aravamudan extern signed long schedule_timeout_uninterruptible(signed long timeout); 2671da177e4SLinus Torvalds asmlinkage void schedule(void); 2681da177e4SLinus Torvalds 269ab516013SSerge E. Hallyn struct nsproxy; 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds /* Maximum number of active map areas.. This is a random (large) number */ 2721da177e4SLinus Torvalds #define DEFAULT_MAX_MAP_COUNT 65536 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds extern int sysctl_max_map_count; 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds #include <linux/aio.h> 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds extern unsigned long 2791da177e4SLinus Torvalds arch_get_unmapped_area(struct file *, unsigned long, unsigned long, 2801da177e4SLinus Torvalds unsigned long, unsigned long); 2811da177e4SLinus Torvalds extern unsigned long 2821da177e4SLinus Torvalds arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr, 2831da177e4SLinus Torvalds unsigned long len, unsigned long pgoff, 2841da177e4SLinus Torvalds unsigned long flags); 2851363c3cdSWolfgang Wander extern void arch_unmap_area(struct mm_struct *, unsigned long); 2861363c3cdSWolfgang Wander extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long); 2871da177e4SLinus Torvalds 288f412ac08SHugh Dickins #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS 289f412ac08SHugh Dickins /* 290f412ac08SHugh Dickins * The mm counters are not protected by its page_table_lock, 291f412ac08SHugh Dickins * so must be incremented atomically. 292f412ac08SHugh Dickins */ 293d3cb4871SChristoph Lameter #define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value) 294d3cb4871SChristoph Lameter #define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member)) 295d3cb4871SChristoph Lameter #define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member) 296d3cb4871SChristoph Lameter #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member) 297d3cb4871SChristoph Lameter #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member) 298d3cb4871SChristoph Lameter typedef atomic_long_t mm_counter_t; 299f412ac08SHugh Dickins 300f412ac08SHugh Dickins #else /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */ 301f412ac08SHugh Dickins /* 302f412ac08SHugh Dickins * The mm counters are protected by its page_table_lock, 303f412ac08SHugh Dickins * so can be incremented directly. 304f412ac08SHugh Dickins */ 3051da177e4SLinus Torvalds #define set_mm_counter(mm, member, value) (mm)->_##member = (value) 3061da177e4SLinus Torvalds #define get_mm_counter(mm, member) ((mm)->_##member) 3071da177e4SLinus Torvalds #define add_mm_counter(mm, member, value) (mm)->_##member += (value) 3081da177e4SLinus Torvalds #define inc_mm_counter(mm, member) (mm)->_##member++ 3091da177e4SLinus Torvalds #define dec_mm_counter(mm, member) (mm)->_##member-- 310f412ac08SHugh Dickins typedef unsigned long mm_counter_t; 3114294621fSHugh Dickins 312f412ac08SHugh Dickins #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */ 313f412ac08SHugh Dickins 314f412ac08SHugh Dickins #define get_mm_rss(mm) \ 315f412ac08SHugh Dickins (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss)) 316365e9c87SHugh Dickins #define update_hiwater_rss(mm) do { \ 317365e9c87SHugh Dickins unsigned long _rss = get_mm_rss(mm); \ 318365e9c87SHugh Dickins if ((mm)->hiwater_rss < _rss) \ 319365e9c87SHugh Dickins (mm)->hiwater_rss = _rss; \ 320365e9c87SHugh Dickins } while (0) 321365e9c87SHugh Dickins #define update_hiwater_vm(mm) do { \ 322365e9c87SHugh Dickins if ((mm)->hiwater_vm < (mm)->total_vm) \ 323365e9c87SHugh Dickins (mm)->hiwater_vm = (mm)->total_vm; \ 324365e9c87SHugh Dickins } while (0) 325365e9c87SHugh Dickins 3261da177e4SLinus Torvalds struct mm_struct { 3271da177e4SLinus Torvalds struct vm_area_struct * mmap; /* list of VMAs */ 3281da177e4SLinus Torvalds struct rb_root mm_rb; 3291da177e4SLinus Torvalds struct vm_area_struct * mmap_cache; /* last find_vma result */ 3301da177e4SLinus Torvalds unsigned long (*get_unmapped_area) (struct file *filp, 3311da177e4SLinus Torvalds unsigned long addr, unsigned long len, 3321da177e4SLinus Torvalds unsigned long pgoff, unsigned long flags); 3331363c3cdSWolfgang Wander void (*unmap_area) (struct mm_struct *mm, unsigned long addr); 3341da177e4SLinus Torvalds unsigned long mmap_base; /* base of mmap area */ 3350551fbd2SBenjamin Herrenschmidt unsigned long task_size; /* size of task vm space */ 3361363c3cdSWolfgang Wander unsigned long cached_hole_size; /* if non-zero, the largest hole below free_area_cache */ 3371363c3cdSWolfgang Wander unsigned long free_area_cache; /* first hole of size cached_hole_size or larger */ 3381da177e4SLinus Torvalds pgd_t * pgd; 3391da177e4SLinus Torvalds atomic_t mm_users; /* How many users with user space? */ 3401da177e4SLinus Torvalds atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */ 3411da177e4SLinus Torvalds int map_count; /* number of VMAs */ 3421da177e4SLinus Torvalds struct rw_semaphore mmap_sem; 3431da177e4SLinus Torvalds spinlock_t page_table_lock; /* Protects page tables and some counters */ 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung 3461da177e4SLinus Torvalds * together off init_mm.mmlist, and are protected 3471da177e4SLinus Torvalds * by mmlist_lock 3481da177e4SLinus Torvalds */ 3491da177e4SLinus Torvalds 350f412ac08SHugh Dickins /* Special counters, in some configurations protected by the 351f412ac08SHugh Dickins * page_table_lock, in other configurations by being atomic. 352f412ac08SHugh Dickins */ 3534294621fSHugh Dickins mm_counter_t _file_rss; 3541da177e4SLinus Torvalds mm_counter_t _anon_rss; 3551da177e4SLinus Torvalds 356f449952bSHugh Dickins unsigned long hiwater_rss; /* High-watermark of RSS usage */ 357f449952bSHugh Dickins unsigned long hiwater_vm; /* High-water virtual memory usage */ 358f449952bSHugh Dickins 359f449952bSHugh Dickins unsigned long total_vm, locked_vm, shared_vm, exec_vm; 360f449952bSHugh Dickins unsigned long stack_vm, reserved_vm, def_flags, nr_ptes; 361f449952bSHugh Dickins unsigned long start_code, end_code, start_data, end_data; 362f449952bSHugh Dickins unsigned long start_brk, brk, start_stack; 363f449952bSHugh Dickins unsigned long arg_start, arg_end, env_start, env_end; 364f449952bSHugh Dickins 36536d57ac4SH. J. Lu unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */ 3661da177e4SLinus Torvalds 3671da177e4SLinus Torvalds cpumask_t cpu_vm_mask; 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds /* Architecture-specific MM context */ 3701da177e4SLinus Torvalds mm_context_t context; 3711da177e4SLinus Torvalds 3727602bdf2SAshwin Chaugule /* Swap token stuff */ 3737602bdf2SAshwin Chaugule /* 3747602bdf2SAshwin Chaugule * Last value of global fault stamp as seen by this process. 3757602bdf2SAshwin Chaugule * In other words, this value gives an indication of how long 3767602bdf2SAshwin Chaugule * it has been since this task got the token. 3777602bdf2SAshwin Chaugule * Look at mm/thrash.c 3787602bdf2SAshwin Chaugule */ 3797602bdf2SAshwin Chaugule unsigned int faultstamp; 3807602bdf2SAshwin Chaugule unsigned int token_priority; 3817602bdf2SAshwin Chaugule unsigned int last_interval; 3821da177e4SLinus Torvalds 38336de6437SArnaldo Carvalho de Melo unsigned char dumpable:2; 38436de6437SArnaldo Carvalho de Melo 3851da177e4SLinus Torvalds /* coredumping support */ 3861da177e4SLinus Torvalds int core_waiters; 3871da177e4SLinus Torvalds struct completion *core_startup_done, core_done; 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds /* aio bits */ 3901da177e4SLinus Torvalds rwlock_t ioctx_list_lock; 3911da177e4SLinus Torvalds struct kioctx *ioctx_list; 3921da177e4SLinus Torvalds }; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds struct sighand_struct { 3951da177e4SLinus Torvalds atomic_t count; 3961da177e4SLinus Torvalds struct k_sigaction action[_NSIG]; 3971da177e4SLinus Torvalds spinlock_t siglock; 398fba2afaaSDavide Libenzi struct list_head signalfd_list; 3991da177e4SLinus Torvalds }; 4001da177e4SLinus Torvalds 4010e464814SKaiGai Kohei struct pacct_struct { 402f6ec29a4SKaiGai Kohei int ac_flag; 403f6ec29a4SKaiGai Kohei long ac_exitcode; 4040e464814SKaiGai Kohei unsigned long ac_mem; 40577787bfbSKaiGai Kohei cputime_t ac_utime, ac_stime; 40677787bfbSKaiGai Kohei unsigned long ac_minflt, ac_majflt; 4070e464814SKaiGai Kohei }; 4080e464814SKaiGai Kohei 4091da177e4SLinus Torvalds /* 4101da177e4SLinus Torvalds * NOTE! "signal_struct" does not have it's own 4111da177e4SLinus Torvalds * locking, because a shared signal_struct always 4121da177e4SLinus Torvalds * implies a shared sighand_struct, so locking 4131da177e4SLinus Torvalds * sighand_struct is always a proper superset of 4141da177e4SLinus Torvalds * the locking of signal_struct. 4151da177e4SLinus Torvalds */ 4161da177e4SLinus Torvalds struct signal_struct { 4171da177e4SLinus Torvalds atomic_t count; 4181da177e4SLinus Torvalds atomic_t live; 4191da177e4SLinus Torvalds 4201da177e4SLinus Torvalds wait_queue_head_t wait_chldexit; /* for wait4() */ 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds /* current thread group signal load-balancing target: */ 42336c8b586SIngo Molnar struct task_struct *curr_target; 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds /* shared signal handling: */ 4261da177e4SLinus Torvalds struct sigpending shared_pending; 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds /* thread group exit support */ 4291da177e4SLinus Torvalds int group_exit_code; 4301da177e4SLinus Torvalds /* overloaded: 4311da177e4SLinus Torvalds * - notify group_exit_task when ->count is equal to notify_count 4321da177e4SLinus Torvalds * - everyone except group_exit_task is stopped during signal delivery 4331da177e4SLinus Torvalds * of fatal signals, group_exit_task processes the signal. 4341da177e4SLinus Torvalds */ 4351da177e4SLinus Torvalds struct task_struct *group_exit_task; 4361da177e4SLinus Torvalds int notify_count; 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds /* thread group stop support, overloads group_exit_code too */ 4391da177e4SLinus Torvalds int group_stop_count; 4401da177e4SLinus Torvalds unsigned int flags; /* see SIGNAL_* flags below */ 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds /* POSIX.1b Interval Timers */ 4431da177e4SLinus Torvalds struct list_head posix_timers; 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds /* ITIMER_REAL timer for the process */ 4462ff678b8SThomas Gleixner struct hrtimer real_timer; 44705cfb614SRoman Zippel struct task_struct *tsk; 4482ff678b8SThomas Gleixner ktime_t it_real_incr; 4491da177e4SLinus Torvalds 4501da177e4SLinus Torvalds /* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */ 4511da177e4SLinus Torvalds cputime_t it_prof_expires, it_virt_expires; 4521da177e4SLinus Torvalds cputime_t it_prof_incr, it_virt_incr; 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds /* job control IDs */ 4551da177e4SLinus Torvalds pid_t pgrp; 456ab521dc0SEric W. Biederman struct pid *tty_old_pgrp; 4571ec320afSCedric Le Goater 4581ec320afSCedric Le Goater union { 4591ec320afSCedric Le Goater pid_t session __deprecated; 4601ec320afSCedric Le Goater pid_t __session; 4611ec320afSCedric Le Goater }; 4621ec320afSCedric Le Goater 4631da177e4SLinus Torvalds /* boolean value for session group leader */ 4641da177e4SLinus Torvalds int leader; 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds struct tty_struct *tty; /* NULL if no tty */ 4671da177e4SLinus Torvalds 4681da177e4SLinus Torvalds /* 4691da177e4SLinus Torvalds * Cumulative resource counters for dead threads in the group, 4701da177e4SLinus Torvalds * and for reaped dead child processes forked by this group. 4711da177e4SLinus Torvalds * Live threads maintain their own counters and add to these 4721da177e4SLinus Torvalds * in __exit_signal, except for the group leader. 4731da177e4SLinus Torvalds */ 4741da177e4SLinus Torvalds cputime_t utime, stime, cutime, cstime; 4751da177e4SLinus Torvalds unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; 4761da177e4SLinus Torvalds unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; 4776eaeeabaSEric Dumazet unsigned long inblock, oublock, cinblock, coublock; 4781da177e4SLinus Torvalds 4791da177e4SLinus Torvalds /* 4801da177e4SLinus Torvalds * Cumulative ns of scheduled CPU time for dead threads in the 4811da177e4SLinus Torvalds * group, not including a zombie group leader. (This only differs 4821da177e4SLinus Torvalds * from jiffies_to_ns(utime + stime) if sched_clock uses something 4831da177e4SLinus Torvalds * other than jiffies.) 4841da177e4SLinus Torvalds */ 4851da177e4SLinus Torvalds unsigned long long sched_time; 4861da177e4SLinus Torvalds 4871da177e4SLinus Torvalds /* 4881da177e4SLinus Torvalds * We don't bother to synchronize most readers of this at all, 4891da177e4SLinus Torvalds * because there is no reader checking a limit that actually needs 4901da177e4SLinus Torvalds * to get both rlim_cur and rlim_max atomically, and either one 4911da177e4SLinus Torvalds * alone is a single word that can safely be read normally. 4921da177e4SLinus Torvalds * getrlimit/setrlimit use task_lock(current->group_leader) to 4931da177e4SLinus Torvalds * protect this instead of the siglock, because they really 4941da177e4SLinus Torvalds * have no need to disable irqs. 4951da177e4SLinus Torvalds */ 4961da177e4SLinus Torvalds struct rlimit rlim[RLIM_NLIMITS]; 4971da177e4SLinus Torvalds 4981da177e4SLinus Torvalds struct list_head cpu_timers[3]; 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvalds /* keep the process-shared keyrings here so that they do the right 5011da177e4SLinus Torvalds * thing in threads created with CLONE_THREAD */ 5021da177e4SLinus Torvalds #ifdef CONFIG_KEYS 5031da177e4SLinus Torvalds struct key *session_keyring; /* keyring inherited over fork */ 5041da177e4SLinus Torvalds struct key *process_keyring; /* keyring private to this process */ 5051da177e4SLinus Torvalds #endif 5060e464814SKaiGai Kohei #ifdef CONFIG_BSD_PROCESS_ACCT 5070e464814SKaiGai Kohei struct pacct_struct pacct; /* per-process accounting information */ 5080e464814SKaiGai Kohei #endif 509ad4ecbcbSShailabh Nagar #ifdef CONFIG_TASKSTATS 510ad4ecbcbSShailabh Nagar struct taskstats *stats; 511ad4ecbcbSShailabh Nagar #endif 5121da177e4SLinus Torvalds }; 5131da177e4SLinus Torvalds 5144866cde0SNick Piggin /* Context switch must be unlocked if interrupts are to be enabled */ 5154866cde0SNick Piggin #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW 5164866cde0SNick Piggin # define __ARCH_WANT_UNLOCKED_CTXSW 5174866cde0SNick Piggin #endif 5184866cde0SNick Piggin 5191da177e4SLinus Torvalds /* 5201da177e4SLinus Torvalds * Bits in flags field of signal_struct. 5211da177e4SLinus Torvalds */ 5221da177e4SLinus Torvalds #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */ 5231da177e4SLinus Torvalds #define SIGNAL_STOP_DEQUEUED 0x00000002 /* stop signal dequeued */ 5241da177e4SLinus Torvalds #define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */ 5251da177e4SLinus Torvalds #define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */ 5261da177e4SLinus Torvalds 5271da177e4SLinus Torvalds 5281da177e4SLinus Torvalds /* 5291da177e4SLinus Torvalds * Priority of a process goes from 0..MAX_PRIO-1, valid RT 530b0a9499cSIngo Molnar * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH 531b0a9499cSIngo Molnar * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority 532b0a9499cSIngo Molnar * values are inverted: lower p->prio value means higher priority. 5331da177e4SLinus Torvalds * 5341da177e4SLinus Torvalds * The MAX_USER_RT_PRIO value allows the actual maximum 5351da177e4SLinus Torvalds * RT priority to be separate from the value exported to 5361da177e4SLinus Torvalds * user-space. This allows kernel threads to set their 5371da177e4SLinus Torvalds * priority to a value higher than any user task. Note: 5381da177e4SLinus Torvalds * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO. 5391da177e4SLinus Torvalds */ 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds #define MAX_USER_RT_PRIO 100 5421da177e4SLinus Torvalds #define MAX_RT_PRIO MAX_USER_RT_PRIO 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds #define MAX_PRIO (MAX_RT_PRIO + 40) 5451da177e4SLinus Torvalds 546b29739f9SIngo Molnar #define rt_prio(prio) unlikely((prio) < MAX_RT_PRIO) 547b29739f9SIngo Molnar #define rt_task(p) rt_prio((p)->prio) 548d425b274SCon Kolivas #define batch_task(p) (unlikely((p)->policy == SCHED_BATCH)) 54957a6f51cSOleg Nesterov #define is_rt_policy(p) ((p) != SCHED_NORMAL && (p) != SCHED_BATCH) 55057a6f51cSOleg Nesterov #define has_rt_policy(p) unlikely(is_rt_policy((p)->policy)) 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds /* 5531da177e4SLinus Torvalds * Some day this will be a full-fledged user tracking system.. 5541da177e4SLinus Torvalds */ 5551da177e4SLinus Torvalds struct user_struct { 5561da177e4SLinus Torvalds atomic_t __count; /* reference count */ 5571da177e4SLinus Torvalds atomic_t processes; /* How many processes does this user have? */ 5581da177e4SLinus Torvalds atomic_t files; /* How many open files does this user have? */ 5591da177e4SLinus Torvalds atomic_t sigpending; /* How many pending signals does this user have? */ 5602d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 5610eeca283SRobert Love atomic_t inotify_watches; /* How many inotify watches does this user have? */ 5620eeca283SRobert Love atomic_t inotify_devs; /* How many inotify devs does this user have opened? */ 5630eeca283SRobert Love #endif 5641da177e4SLinus Torvalds /* protected by mq_lock */ 5651da177e4SLinus Torvalds unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */ 5661da177e4SLinus Torvalds unsigned long locked_shm; /* How many pages of mlocked shm ? */ 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds #ifdef CONFIG_KEYS 5691da177e4SLinus Torvalds struct key *uid_keyring; /* UID specific keyring */ 5701da177e4SLinus Torvalds struct key *session_keyring; /* UID's default session keyring */ 5711da177e4SLinus Torvalds #endif 5721da177e4SLinus Torvalds 5731da177e4SLinus Torvalds /* Hash table maintenance information */ 5741da177e4SLinus Torvalds struct list_head uidhash_list; 5751da177e4SLinus Torvalds uid_t uid; 5761da177e4SLinus Torvalds }; 5771da177e4SLinus Torvalds 5781da177e4SLinus Torvalds extern struct user_struct *find_user(uid_t); 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds extern struct user_struct root_user; 5811da177e4SLinus Torvalds #define INIT_USER (&root_user) 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds struct backing_dev_info; 5841da177e4SLinus Torvalds struct reclaim_state; 5851da177e4SLinus Torvalds 58652f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 5871da177e4SLinus Torvalds struct sched_info { 5881da177e4SLinus Torvalds /* cumulative counters */ 5891da177e4SLinus Torvalds unsigned long cpu_time, /* time spent on the cpu */ 5901da177e4SLinus Torvalds run_delay, /* time spent waiting on a runqueue */ 5911da177e4SLinus Torvalds pcnt; /* # of timeslices run on this cpu */ 5921da177e4SLinus Torvalds 5931da177e4SLinus Torvalds /* timestamps */ 5941da177e4SLinus Torvalds unsigned long last_arrival, /* when we last ran on a cpu */ 5951da177e4SLinus Torvalds last_queued; /* when we were last queued to run */ 5961da177e4SLinus Torvalds }; 59752f17b6cSChandra Seetharaman #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */ 5981da177e4SLinus Torvalds 59952f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS 60015ad7cdcSHelge Deller extern const struct file_operations proc_schedstat_operations; 60152f17b6cSChandra Seetharaman #endif /* CONFIG_SCHEDSTATS */ 6021da177e4SLinus Torvalds 603ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 604ca74e92bSShailabh Nagar struct task_delay_info { 605ca74e92bSShailabh Nagar spinlock_t lock; 606ca74e92bSShailabh Nagar unsigned int flags; /* Private per-task flags */ 607ca74e92bSShailabh Nagar 608ca74e92bSShailabh Nagar /* For each stat XXX, add following, aligned appropriately 609ca74e92bSShailabh Nagar * 610ca74e92bSShailabh Nagar * struct timespec XXX_start, XXX_end; 611ca74e92bSShailabh Nagar * u64 XXX_delay; 612ca74e92bSShailabh Nagar * u32 XXX_count; 613ca74e92bSShailabh Nagar * 614ca74e92bSShailabh Nagar * Atomicity of updates to XXX_delay, XXX_count protected by 615ca74e92bSShailabh Nagar * single lock above (split into XXX_lock if contention is an issue). 616ca74e92bSShailabh Nagar */ 6170ff92245SShailabh Nagar 6180ff92245SShailabh Nagar /* 6190ff92245SShailabh Nagar * XXX_count is incremented on every XXX operation, the delay 6200ff92245SShailabh Nagar * associated with the operation is added to XXX_delay. 6210ff92245SShailabh Nagar * XXX_delay contains the accumulated delay time in nanoseconds. 6220ff92245SShailabh Nagar */ 6230ff92245SShailabh Nagar struct timespec blkio_start, blkio_end; /* Shared by blkio, swapin */ 6240ff92245SShailabh Nagar u64 blkio_delay; /* wait for sync block io completion */ 6250ff92245SShailabh Nagar u64 swapin_delay; /* wait for swapin block io completion */ 6260ff92245SShailabh Nagar u32 blkio_count; /* total count of the number of sync block */ 6270ff92245SShailabh Nagar /* io operations performed */ 6280ff92245SShailabh Nagar u32 swapin_count; /* total count of the number of swapin block */ 6290ff92245SShailabh Nagar /* io operations performed */ 630ca74e92bSShailabh Nagar }; 63152f17b6cSChandra Seetharaman #endif /* CONFIG_TASK_DELAY_ACCT */ 63252f17b6cSChandra Seetharaman 63352f17b6cSChandra Seetharaman static inline int sched_info_on(void) 63452f17b6cSChandra Seetharaman { 63552f17b6cSChandra Seetharaman #ifdef CONFIG_SCHEDSTATS 63652f17b6cSChandra Seetharaman return 1; 63752f17b6cSChandra Seetharaman #elif defined(CONFIG_TASK_DELAY_ACCT) 63852f17b6cSChandra Seetharaman extern int delayacct_on; 63952f17b6cSChandra Seetharaman return delayacct_on; 64052f17b6cSChandra Seetharaman #else 64152f17b6cSChandra Seetharaman return 0; 642ca74e92bSShailabh Nagar #endif 64352f17b6cSChandra Seetharaman } 644ca74e92bSShailabh Nagar 645d15bcfdbSIngo Molnar enum cpu_idle_type { 646d15bcfdbSIngo Molnar CPU_IDLE, 647d15bcfdbSIngo Molnar CPU_NOT_IDLE, 648d15bcfdbSIngo Molnar CPU_NEWLY_IDLE, 649d15bcfdbSIngo Molnar CPU_MAX_IDLE_TYPES 6501da177e4SLinus Torvalds }; 6511da177e4SLinus Torvalds 6521da177e4SLinus Torvalds /* 6531da177e4SLinus Torvalds * sched-domains (multiprocessor balancing) declarations: 6541da177e4SLinus Torvalds */ 6559aa7b369SIngo Molnar 6569aa7b369SIngo Molnar /* 6579aa7b369SIngo Molnar * Increase resolution of nice-level calculations: 6589aa7b369SIngo Molnar */ 6599aa7b369SIngo Molnar #define SCHED_LOAD_SHIFT 10 6609aa7b369SIngo Molnar #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT) 6619aa7b369SIngo Molnar 6629aa7b369SIngo Molnar #define SCHED_LOAD_SCALE_FUZZ (SCHED_LOAD_SCALE >> 5) 6631da177e4SLinus Torvalds 6642dd73a4fSPeter Williams #ifdef CONFIG_SMP 6651da177e4SLinus Torvalds #define SD_LOAD_BALANCE 1 /* Do load balancing on this domain. */ 6661da177e4SLinus Torvalds #define SD_BALANCE_NEWIDLE 2 /* Balance when about to become idle */ 6671da177e4SLinus Torvalds #define SD_BALANCE_EXEC 4 /* Balance on exec */ 668147cbb4bSNick Piggin #define SD_BALANCE_FORK 8 /* Balance on fork, clone */ 669147cbb4bSNick Piggin #define SD_WAKE_IDLE 16 /* Wake to idle CPU on task wakeup */ 670147cbb4bSNick Piggin #define SD_WAKE_AFFINE 32 /* Wake task to waking CPU */ 671147cbb4bSNick Piggin #define SD_WAKE_BALANCE 64 /* Perform balancing at task wakeup */ 672147cbb4bSNick Piggin #define SD_SHARE_CPUPOWER 128 /* Domain members share cpu power */ 6735c45bf27SSiddha, Suresh B #define SD_POWERSAVINGS_BALANCE 256 /* Balance for power savings */ 67489c4710eSSiddha, Suresh B #define SD_SHARE_PKG_RESOURCES 512 /* Domain members share cpu pkg resources */ 67508c183f3SChristoph Lameter #define SD_SERIALIZE 1024 /* Only a single load balancing instance */ 6765c45bf27SSiddha, Suresh B 67789c4710eSSiddha, Suresh B #define BALANCE_FOR_MC_POWER \ 67889c4710eSSiddha, Suresh B (sched_smt_power_savings ? SD_POWERSAVINGS_BALANCE : 0) 67989c4710eSSiddha, Suresh B 68089c4710eSSiddha, Suresh B #define BALANCE_FOR_PKG_POWER \ 68189c4710eSSiddha, Suresh B ((sched_mc_power_savings || sched_smt_power_savings) ? \ 68289c4710eSSiddha, Suresh B SD_POWERSAVINGS_BALANCE : 0) 68389c4710eSSiddha, Suresh B 68489c4710eSSiddha, Suresh B #define test_sd_parent(sd, flag) ((sd->parent && \ 68589c4710eSSiddha, Suresh B (sd->parent->flags & flag)) ? 1 : 0) 6865c45bf27SSiddha, Suresh B 6871da177e4SLinus Torvalds 6881da177e4SLinus Torvalds struct sched_group { 6891da177e4SLinus Torvalds struct sched_group *next; /* Must be a circular list */ 6901da177e4SLinus Torvalds cpumask_t cpumask; 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds /* 6931da177e4SLinus Torvalds * CPU power of this group, SCHED_LOAD_SCALE being max power for a 6941da177e4SLinus Torvalds * single CPU. This is read only (except for setup, hotplug CPU). 6955517d86bSEric Dumazet * Note : Never change cpu_power without recompute its reciprocal 6961da177e4SLinus Torvalds */ 6975517d86bSEric Dumazet unsigned int __cpu_power; 6985517d86bSEric Dumazet /* 6995517d86bSEric Dumazet * reciprocal value of cpu_power to avoid expensive divides 7005517d86bSEric Dumazet * (see include/linux/reciprocal_div.h) 7015517d86bSEric Dumazet */ 7025517d86bSEric Dumazet u32 reciprocal_cpu_power; 7031da177e4SLinus Torvalds }; 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds struct sched_domain { 7061da177e4SLinus Torvalds /* These fields must be setup */ 7071da177e4SLinus Torvalds struct sched_domain *parent; /* top domain must be null terminated */ 7081a848870SSiddha, Suresh B struct sched_domain *child; /* bottom domain must be null terminated */ 7091da177e4SLinus Torvalds struct sched_group *groups; /* the balancing groups of the domain */ 7101da177e4SLinus Torvalds cpumask_t span; /* span of all CPUs in this domain */ 7111da177e4SLinus Torvalds unsigned long min_interval; /* Minimum balance interval ms */ 7121da177e4SLinus Torvalds unsigned long max_interval; /* Maximum balance interval ms */ 7131da177e4SLinus Torvalds unsigned int busy_factor; /* less balancing by factor if busy */ 7141da177e4SLinus Torvalds unsigned int imbalance_pct; /* No balance until over watermark */ 7151da177e4SLinus Torvalds unsigned long long cache_hot_time; /* Task considered cache hot (ns) */ 7161da177e4SLinus Torvalds unsigned int cache_nice_tries; /* Leave cache hot tasks for # tries */ 7177897986bSNick Piggin unsigned int busy_idx; 7187897986bSNick Piggin unsigned int idle_idx; 7197897986bSNick Piggin unsigned int newidle_idx; 7207897986bSNick Piggin unsigned int wake_idx; 721147cbb4bSNick Piggin unsigned int forkexec_idx; 7221da177e4SLinus Torvalds int flags; /* See SD_* */ 7231da177e4SLinus Torvalds 7241da177e4SLinus Torvalds /* Runtime fields. */ 7251da177e4SLinus Torvalds unsigned long last_balance; /* init to jiffies. units in jiffies */ 7261da177e4SLinus Torvalds unsigned int balance_interval; /* initialise to 1. units in ms. */ 7271da177e4SLinus Torvalds unsigned int nr_balance_failed; /* initialise to 0 */ 7281da177e4SLinus Torvalds 7291da177e4SLinus Torvalds #ifdef CONFIG_SCHEDSTATS 7301da177e4SLinus Torvalds /* load_balance() stats */ 731d15bcfdbSIngo Molnar unsigned long lb_cnt[CPU_MAX_IDLE_TYPES]; 732d15bcfdbSIngo Molnar unsigned long lb_failed[CPU_MAX_IDLE_TYPES]; 733d15bcfdbSIngo Molnar unsigned long lb_balanced[CPU_MAX_IDLE_TYPES]; 734d15bcfdbSIngo Molnar unsigned long lb_imbalance[CPU_MAX_IDLE_TYPES]; 735d15bcfdbSIngo Molnar unsigned long lb_gained[CPU_MAX_IDLE_TYPES]; 736d15bcfdbSIngo Molnar unsigned long lb_hot_gained[CPU_MAX_IDLE_TYPES]; 737d15bcfdbSIngo Molnar unsigned long lb_nobusyg[CPU_MAX_IDLE_TYPES]; 738d15bcfdbSIngo Molnar unsigned long lb_nobusyq[CPU_MAX_IDLE_TYPES]; 7391da177e4SLinus Torvalds 7401da177e4SLinus Torvalds /* Active load balancing */ 7411da177e4SLinus Torvalds unsigned long alb_cnt; 7421da177e4SLinus Torvalds unsigned long alb_failed; 7431da177e4SLinus Torvalds unsigned long alb_pushed; 7441da177e4SLinus Torvalds 74568767a0aSNick Piggin /* SD_BALANCE_EXEC stats */ 74668767a0aSNick Piggin unsigned long sbe_cnt; 74768767a0aSNick Piggin unsigned long sbe_balanced; 7481da177e4SLinus Torvalds unsigned long sbe_pushed; 7491da177e4SLinus Torvalds 75068767a0aSNick Piggin /* SD_BALANCE_FORK stats */ 75168767a0aSNick Piggin unsigned long sbf_cnt; 75268767a0aSNick Piggin unsigned long sbf_balanced; 75368767a0aSNick Piggin unsigned long sbf_pushed; 75468767a0aSNick Piggin 7551da177e4SLinus Torvalds /* try_to_wake_up() stats */ 7561da177e4SLinus Torvalds unsigned long ttwu_wake_remote; 7571da177e4SLinus Torvalds unsigned long ttwu_move_affine; 7581da177e4SLinus Torvalds unsigned long ttwu_move_balance; 7591da177e4SLinus Torvalds #endif 7601da177e4SLinus Torvalds }; 7611da177e4SLinus Torvalds 76251888ca2SSrivatsa Vaddagiri extern int partition_sched_domains(cpumask_t *partition1, 7631a20ff27SDinakar Guniguntala cpumask_t *partition2); 764198e2f18Sakpm@osdl.org 7651da177e4SLinus Torvalds #endif /* CONFIG_SMP */ 7661da177e4SLinus Torvalds 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds struct io_context; /* See blkdev.h */ 7691da177e4SLinus Torvalds struct cpuset; 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds #define NGROUPS_SMALL 32 7721da177e4SLinus Torvalds #define NGROUPS_PER_BLOCK ((int)(PAGE_SIZE / sizeof(gid_t))) 7731da177e4SLinus Torvalds struct group_info { 7741da177e4SLinus Torvalds int ngroups; 7751da177e4SLinus Torvalds atomic_t usage; 7761da177e4SLinus Torvalds gid_t small_block[NGROUPS_SMALL]; 7771da177e4SLinus Torvalds int nblocks; 7781da177e4SLinus Torvalds gid_t *blocks[0]; 7791da177e4SLinus Torvalds }; 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds /* 7821da177e4SLinus Torvalds * get_group_info() must be called with the owning task locked (via task_lock()) 7831da177e4SLinus Torvalds * when task != current. The reason being that the vast majority of callers are 7841da177e4SLinus Torvalds * looking at current->group_info, which can not be changed except by the 7851da177e4SLinus Torvalds * current task. Changing current->group_info requires the task lock, too. 7861da177e4SLinus Torvalds */ 7871da177e4SLinus Torvalds #define get_group_info(group_info) do { \ 7881da177e4SLinus Torvalds atomic_inc(&(group_info)->usage); \ 7891da177e4SLinus Torvalds } while (0) 7901da177e4SLinus Torvalds 7911da177e4SLinus Torvalds #define put_group_info(group_info) do { \ 7921da177e4SLinus Torvalds if (atomic_dec_and_test(&(group_info)->usage)) \ 7931da177e4SLinus Torvalds groups_free(group_info); \ 7941da177e4SLinus Torvalds } while (0) 7951da177e4SLinus Torvalds 7963e30148cSDavid Howells extern struct group_info *groups_alloc(int gidsetsize); 7973e30148cSDavid Howells extern void groups_free(struct group_info *group_info); 7983e30148cSDavid Howells extern int set_current_groups(struct group_info *group_info); 7993e30148cSDavid Howells extern int groups_search(struct group_info *group_info, gid_t grp); 8001da177e4SLinus Torvalds /* access the groups "array" with this macro */ 8011da177e4SLinus Torvalds #define GROUP_AT(gi, i) \ 8021da177e4SLinus Torvalds ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK]) 8031da177e4SLinus Torvalds 804383f2835SChen, Kenneth W #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK 80536c8b586SIngo Molnar extern void prefetch_stack(struct task_struct *t); 806383f2835SChen, Kenneth W #else 807383f2835SChen, Kenneth W static inline void prefetch_stack(struct task_struct *t) { } 808383f2835SChen, Kenneth W #endif 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds struct audit_context; /* See audit.c */ 8111da177e4SLinus Torvalds struct mempolicy; 812b92ce558SJens Axboe struct pipe_inode_info; 8134865ecf1SSerge E. Hallyn struct uts_namespace; 8141da177e4SLinus Torvalds 8153dee386eSCon Kolivas enum sleep_type { 8163dee386eSCon Kolivas SLEEP_NORMAL, 8173dee386eSCon Kolivas SLEEP_NONINTERACTIVE, 8183dee386eSCon Kolivas SLEEP_INTERACTIVE, 8193dee386eSCon Kolivas SLEEP_INTERRUPTED, 8203dee386eSCon Kolivas }; 8213dee386eSCon Kolivas 82270b97a7fSIngo Molnar struct prio_array; 823*20b8a59fSIngo Molnar struct rq; 824*20b8a59fSIngo Molnar struct sched_domain; 825*20b8a59fSIngo Molnar 826*20b8a59fSIngo Molnar struct sched_class { 827*20b8a59fSIngo Molnar struct sched_class *next; 828*20b8a59fSIngo Molnar 829*20b8a59fSIngo Molnar void (*enqueue_task) (struct rq *rq, struct task_struct *p, 830*20b8a59fSIngo Molnar int wakeup, u64 now); 831*20b8a59fSIngo Molnar void (*dequeue_task) (struct rq *rq, struct task_struct *p, 832*20b8a59fSIngo Molnar int sleep, u64 now); 833*20b8a59fSIngo Molnar void (*yield_task) (struct rq *rq, struct task_struct *p); 834*20b8a59fSIngo Molnar 835*20b8a59fSIngo Molnar void (*check_preempt_curr) (struct rq *rq, struct task_struct *p); 836*20b8a59fSIngo Molnar 837*20b8a59fSIngo Molnar struct task_struct * (*pick_next_task) (struct rq *rq, u64 now); 838*20b8a59fSIngo Molnar void (*put_prev_task) (struct rq *rq, struct task_struct *p, u64 now); 839*20b8a59fSIngo Molnar 840*20b8a59fSIngo Molnar int (*load_balance) (struct rq *this_rq, int this_cpu, 841*20b8a59fSIngo Molnar struct rq *busiest, 842*20b8a59fSIngo Molnar unsigned long max_nr_move, unsigned long max_load_move, 843*20b8a59fSIngo Molnar struct sched_domain *sd, enum cpu_idle_type idle, 844*20b8a59fSIngo Molnar int *all_pinned, unsigned long *total_load_moved); 845*20b8a59fSIngo Molnar 846*20b8a59fSIngo Molnar void (*set_curr_task) (struct rq *rq); 847*20b8a59fSIngo Molnar void (*task_tick) (struct rq *rq, struct task_struct *p); 848*20b8a59fSIngo Molnar void (*task_new) (struct rq *rq, struct task_struct *p); 849*20b8a59fSIngo Molnar }; 850*20b8a59fSIngo Molnar 851*20b8a59fSIngo Molnar struct load_weight { 852*20b8a59fSIngo Molnar unsigned long weight, inv_weight; 853*20b8a59fSIngo Molnar }; 854*20b8a59fSIngo Molnar 855*20b8a59fSIngo Molnar /* 856*20b8a59fSIngo Molnar * CFS stats for a schedulable entity (task, task-group etc) 857*20b8a59fSIngo Molnar * 858*20b8a59fSIngo Molnar * Current field usage histogram: 859*20b8a59fSIngo Molnar * 860*20b8a59fSIngo Molnar * 4 se->block_start 861*20b8a59fSIngo Molnar * 4 se->run_node 862*20b8a59fSIngo Molnar * 4 se->sleep_start 863*20b8a59fSIngo Molnar * 4 se->sleep_start_fair 864*20b8a59fSIngo Molnar * 6 se->load.weight 865*20b8a59fSIngo Molnar * 7 se->delta_fair 866*20b8a59fSIngo Molnar * 15 se->wait_runtime 867*20b8a59fSIngo Molnar */ 868*20b8a59fSIngo Molnar struct sched_entity { 869*20b8a59fSIngo Molnar long wait_runtime; 870*20b8a59fSIngo Molnar unsigned long delta_fair_run; 871*20b8a59fSIngo Molnar unsigned long delta_fair_sleep; 872*20b8a59fSIngo Molnar unsigned long delta_exec; 873*20b8a59fSIngo Molnar s64 fair_key; 874*20b8a59fSIngo Molnar struct load_weight load; /* for load-balancing */ 875*20b8a59fSIngo Molnar struct rb_node run_node; 876*20b8a59fSIngo Molnar unsigned int on_rq; 877*20b8a59fSIngo Molnar 878*20b8a59fSIngo Molnar u64 wait_start_fair; 879*20b8a59fSIngo Molnar u64 wait_start; 880*20b8a59fSIngo Molnar u64 exec_start; 881*20b8a59fSIngo Molnar u64 sleep_start; 882*20b8a59fSIngo Molnar u64 sleep_start_fair; 883*20b8a59fSIngo Molnar u64 block_start; 884*20b8a59fSIngo Molnar u64 sleep_max; 885*20b8a59fSIngo Molnar u64 block_max; 886*20b8a59fSIngo Molnar u64 exec_max; 887*20b8a59fSIngo Molnar u64 wait_max; 888*20b8a59fSIngo Molnar u64 last_ran; 889*20b8a59fSIngo Molnar 890*20b8a59fSIngo Molnar u64 sum_exec_runtime; 891*20b8a59fSIngo Molnar s64 sum_wait_runtime; 892*20b8a59fSIngo Molnar s64 sum_sleep_runtime; 893*20b8a59fSIngo Molnar unsigned long wait_runtime_overruns; 894*20b8a59fSIngo Molnar unsigned long wait_runtime_underruns; 895*20b8a59fSIngo Molnar #ifdef CONFIG_FAIR_GROUP_SCHED 896*20b8a59fSIngo Molnar struct sched_entity *parent; 897*20b8a59fSIngo Molnar /* rq on which this entity is (to be) queued: */ 898*20b8a59fSIngo Molnar struct cfs_rq *cfs_rq; 899*20b8a59fSIngo Molnar /* rq "owned" by this entity/group: */ 900*20b8a59fSIngo Molnar struct cfs_rq *my_q; 901*20b8a59fSIngo Molnar #endif 902*20b8a59fSIngo Molnar }; 90370b97a7fSIngo Molnar 9041da177e4SLinus Torvalds struct task_struct { 9051da177e4SLinus Torvalds volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ 906f7e4217bSRoman Zippel void *stack; 9071da177e4SLinus Torvalds atomic_t usage; 90897dc32cdSWilliam Cohen unsigned int flags; /* per process flags, defined below */ 90997dc32cdSWilliam Cohen unsigned int ptrace; 9101da177e4SLinus Torvalds 91136772092SPaolo 'Blaisorblade' Giarrusso int lock_depth; /* BKL lock depth */ 9121da177e4SLinus Torvalds 9132dd73a4fSPeter Williams #ifdef CONFIG_SMP 9142dd73a4fSPeter Williams #ifdef __ARCH_WANT_UNLOCKED_CTXSW 9154866cde0SNick Piggin int oncpu; 9164866cde0SNick Piggin #endif 9172dd73a4fSPeter Williams #endif 9182dd73a4fSPeter Williams int load_weight; /* for niceness load balancing purposes */ 919b29739f9SIngo Molnar int prio, static_prio, normal_prio; 9201da177e4SLinus Torvalds struct list_head run_list; 92170b97a7fSIngo Molnar struct prio_array *array; 922*20b8a59fSIngo Molnar struct sched_class *sched_class; 923*20b8a59fSIngo Molnar struct sched_entity se; 9241da177e4SLinus Torvalds 92522e2c507SJens Axboe unsigned short ioprio; 9266c5c9341SAlexey Dobriyan #ifdef CONFIG_BLK_DEV_IO_TRACE 9272056a782SJens Axboe unsigned int btrace_seq; 9286c5c9341SAlexey Dobriyan #endif 9291da177e4SLinus Torvalds unsigned long sleep_avg; 9301da177e4SLinus Torvalds unsigned long long timestamp, last_ran; 9311da177e4SLinus Torvalds unsigned long long sched_time; /* sched_clock time spent running */ 9323dee386eSCon Kolivas enum sleep_type sleep_type; 9331da177e4SLinus Torvalds 93497dc32cdSWilliam Cohen unsigned int policy; 9351da177e4SLinus Torvalds cpumask_t cpus_allowed; 9361da177e4SLinus Torvalds unsigned int time_slice, first_time_slice; 9371da177e4SLinus Torvalds 93852f17b6cSChandra Seetharaman #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 9391da177e4SLinus Torvalds struct sched_info sched_info; 9401da177e4SLinus Torvalds #endif 9411da177e4SLinus Torvalds 9421da177e4SLinus Torvalds struct list_head tasks; 9431da177e4SLinus Torvalds /* 9441da177e4SLinus Torvalds * ptrace_list/ptrace_children forms the list of my children 9451da177e4SLinus Torvalds * that were stolen by a ptracer. 9461da177e4SLinus Torvalds */ 9471da177e4SLinus Torvalds struct list_head ptrace_children; 9481da177e4SLinus Torvalds struct list_head ptrace_list; 9491da177e4SLinus Torvalds 9501da177e4SLinus Torvalds struct mm_struct *mm, *active_mm; 9511da177e4SLinus Torvalds 9521da177e4SLinus Torvalds /* task state */ 9531da177e4SLinus Torvalds struct linux_binfmt *binfmt; 95497dc32cdSWilliam Cohen int exit_state; 9551da177e4SLinus Torvalds int exit_code, exit_signal; 9561da177e4SLinus Torvalds int pdeath_signal; /* The signal sent when the parent dies */ 9571da177e4SLinus Torvalds /* ??? */ 95897dc32cdSWilliam Cohen unsigned int personality; 9591da177e4SLinus Torvalds unsigned did_exec:1; 9601da177e4SLinus Torvalds pid_t pid; 9611da177e4SLinus Torvalds pid_t tgid; 9620a425405SArjan van de Ven 9630a425405SArjan van de Ven #ifdef CONFIG_CC_STACKPROTECTOR 9640a425405SArjan van de Ven /* Canary value for the -fstack-protector gcc feature */ 9650a425405SArjan van de Ven unsigned long stack_canary; 9660a425405SArjan van de Ven #endif 9671da177e4SLinus Torvalds /* 9681da177e4SLinus Torvalds * pointers to (original) parent process, youngest child, younger sibling, 9691da177e4SLinus Torvalds * older sibling, respectively. (p->father can be replaced with 9701da177e4SLinus Torvalds * p->parent->pid) 9711da177e4SLinus Torvalds */ 9721da177e4SLinus Torvalds struct task_struct *real_parent; /* real parent process (when being debugged) */ 9731da177e4SLinus Torvalds struct task_struct *parent; /* parent process */ 9741da177e4SLinus Torvalds /* 9751da177e4SLinus Torvalds * children/sibling forms the list of my children plus the 9761da177e4SLinus Torvalds * tasks I'm ptracing. 9771da177e4SLinus Torvalds */ 9781da177e4SLinus Torvalds struct list_head children; /* list of my children */ 9791da177e4SLinus Torvalds struct list_head sibling; /* linkage in my parent's children list */ 9801da177e4SLinus Torvalds struct task_struct *group_leader; /* threadgroup leader */ 9811da177e4SLinus Torvalds 9821da177e4SLinus Torvalds /* PID/PID hash table linkage. */ 98392476d7fSEric W. Biederman struct pid_link pids[PIDTYPE_MAX]; 98447e65328SOleg Nesterov struct list_head thread_group; 9851da177e4SLinus Torvalds 9861da177e4SLinus Torvalds struct completion *vfork_done; /* for vfork() */ 9871da177e4SLinus Torvalds int __user *set_child_tid; /* CLONE_CHILD_SETTID */ 9881da177e4SLinus Torvalds int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */ 9891da177e4SLinus Torvalds 99097dc32cdSWilliam Cohen unsigned int rt_priority; 9911da177e4SLinus Torvalds cputime_t utime, stime; 9921da177e4SLinus Torvalds unsigned long nvcsw, nivcsw; /* context switch counts */ 9931da177e4SLinus Torvalds struct timespec start_time; 9941da177e4SLinus Torvalds /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ 9951da177e4SLinus Torvalds unsigned long min_flt, maj_flt; 9961da177e4SLinus Torvalds 9971da177e4SLinus Torvalds cputime_t it_prof_expires, it_virt_expires; 9981da177e4SLinus Torvalds unsigned long long it_sched_expires; 9991da177e4SLinus Torvalds struct list_head cpu_timers[3]; 10001da177e4SLinus Torvalds 10011da177e4SLinus Torvalds /* process credentials */ 10021da177e4SLinus Torvalds uid_t uid,euid,suid,fsuid; 10031da177e4SLinus Torvalds gid_t gid,egid,sgid,fsgid; 10041da177e4SLinus Torvalds struct group_info *group_info; 10051da177e4SLinus Torvalds kernel_cap_t cap_effective, cap_inheritable, cap_permitted; 10061da177e4SLinus Torvalds unsigned keep_capabilities:1; 10071da177e4SLinus Torvalds struct user_struct *user; 10081da177e4SLinus Torvalds #ifdef CONFIG_KEYS 1009b5f545c8SDavid Howells struct key *request_key_auth; /* assumed request_key authority */ 10101da177e4SLinus Torvalds struct key *thread_keyring; /* keyring private to this thread */ 10113e30148cSDavid Howells unsigned char jit_keyring; /* default keyring to attach requested keys to */ 10121da177e4SLinus Torvalds #endif 1013e07e23e1SArjan van de Ven /* 1014e07e23e1SArjan van de Ven * fpu_counter contains the number of consecutive context switches 1015e07e23e1SArjan van de Ven * that the FPU is used. If this is over a threshold, the lazy fpu 1016e07e23e1SArjan van de Ven * saving becomes unlazy to save the trap. This is an unsigned char 1017e07e23e1SArjan van de Ven * so that after 256 times the counter wraps and the behavior turns 1018e07e23e1SArjan van de Ven * lazy again; this to deal with bursty apps that only use FPU for 1019e07e23e1SArjan van de Ven * a short time 1020e07e23e1SArjan van de Ven */ 1021e07e23e1SArjan van de Ven unsigned char fpu_counter; 10221da177e4SLinus Torvalds int oomkilladj; /* OOM kill score adjustment (bit shift). */ 102336772092SPaolo 'Blaisorblade' Giarrusso char comm[TASK_COMM_LEN]; /* executable name excluding path 102436772092SPaolo 'Blaisorblade' Giarrusso - access with [gs]et_task_comm (which lock 102536772092SPaolo 'Blaisorblade' Giarrusso it with task_lock()) 102636772092SPaolo 'Blaisorblade' Giarrusso - initialized normally by flush_old_exec */ 10271da177e4SLinus Torvalds /* file system info */ 10281da177e4SLinus Torvalds int link_count, total_link_count; 10293d5b6fccSAlexey Dobriyan #ifdef CONFIG_SYSVIPC 10301da177e4SLinus Torvalds /* ipc stuff */ 10311da177e4SLinus Torvalds struct sysv_sem sysvsem; 10323d5b6fccSAlexey Dobriyan #endif 10331da177e4SLinus Torvalds /* CPU-specific state of this task */ 10341da177e4SLinus Torvalds struct thread_struct thread; 10351da177e4SLinus Torvalds /* filesystem information */ 10361da177e4SLinus Torvalds struct fs_struct *fs; 10371da177e4SLinus Torvalds /* open file information */ 10381da177e4SLinus Torvalds struct files_struct *files; 10391651e14eSSerge E. Hallyn /* namespaces */ 1040ab516013SSerge E. Hallyn struct nsproxy *nsproxy; 10411da177e4SLinus Torvalds /* signal handlers */ 10421da177e4SLinus Torvalds struct signal_struct *signal; 10431da177e4SLinus Torvalds struct sighand_struct *sighand; 10441da177e4SLinus Torvalds 10451da177e4SLinus Torvalds sigset_t blocked, real_blocked; 1046150256d8SDavid Woodhouse sigset_t saved_sigmask; /* To be restored with TIF_RESTORE_SIGMASK */ 10471da177e4SLinus Torvalds struct sigpending pending; 10481da177e4SLinus Torvalds 10491da177e4SLinus Torvalds unsigned long sas_ss_sp; 10501da177e4SLinus Torvalds size_t sas_ss_size; 10511da177e4SLinus Torvalds int (*notifier)(void *priv); 10521da177e4SLinus Torvalds void *notifier_data; 10531da177e4SLinus Torvalds sigset_t *notifier_mask; 10541da177e4SLinus Torvalds 10551da177e4SLinus Torvalds void *security; 10561da177e4SLinus Torvalds struct audit_context *audit_context; 10571da177e4SLinus Torvalds seccomp_t seccomp; 10581da177e4SLinus Torvalds 10591da177e4SLinus Torvalds /* Thread group tracking */ 10601da177e4SLinus Torvalds u32 parent_exec_id; 10611da177e4SLinus Torvalds u32 self_exec_id; 10621da177e4SLinus Torvalds /* Protection of (de-)allocation: mm, files, fs, tty, keyrings */ 10631da177e4SLinus Torvalds spinlock_t alloc_lock; 10641da177e4SLinus Torvalds 1065b29739f9SIngo Molnar /* Protection of the PI data structures: */ 1066b29739f9SIngo Molnar spinlock_t pi_lock; 1067b29739f9SIngo Molnar 106823f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 106923f78d4aSIngo Molnar /* PI waiters blocked on a rt_mutex held by this task */ 107023f78d4aSIngo Molnar struct plist_head pi_waiters; 107123f78d4aSIngo Molnar /* Deadlock detection and priority inheritance handling */ 107223f78d4aSIngo Molnar struct rt_mutex_waiter *pi_blocked_on; 107323f78d4aSIngo Molnar #endif 107423f78d4aSIngo Molnar 1075408894eeSIngo Molnar #ifdef CONFIG_DEBUG_MUTEXES 1076408894eeSIngo Molnar /* mutex deadlock detection */ 1077408894eeSIngo Molnar struct mutex_waiter *blocked_on; 1078408894eeSIngo Molnar #endif 1079de30a2b3SIngo Molnar #ifdef CONFIG_TRACE_IRQFLAGS 1080de30a2b3SIngo Molnar unsigned int irq_events; 1081de30a2b3SIngo Molnar int hardirqs_enabled; 1082de30a2b3SIngo Molnar unsigned long hardirq_enable_ip; 1083de30a2b3SIngo Molnar unsigned int hardirq_enable_event; 1084de30a2b3SIngo Molnar unsigned long hardirq_disable_ip; 1085de30a2b3SIngo Molnar unsigned int hardirq_disable_event; 1086de30a2b3SIngo Molnar int softirqs_enabled; 1087de30a2b3SIngo Molnar unsigned long softirq_disable_ip; 1088de30a2b3SIngo Molnar unsigned int softirq_disable_event; 1089de30a2b3SIngo Molnar unsigned long softirq_enable_ip; 1090de30a2b3SIngo Molnar unsigned int softirq_enable_event; 1091de30a2b3SIngo Molnar int hardirq_context; 1092de30a2b3SIngo Molnar int softirq_context; 1093de30a2b3SIngo Molnar #endif 1094fbb9ce95SIngo Molnar #ifdef CONFIG_LOCKDEP 1095fbb9ce95SIngo Molnar # define MAX_LOCK_DEPTH 30UL 1096fbb9ce95SIngo Molnar u64 curr_chain_key; 1097fbb9ce95SIngo Molnar int lockdep_depth; 1098fbb9ce95SIngo Molnar struct held_lock held_locks[MAX_LOCK_DEPTH]; 1099fbb9ce95SIngo Molnar unsigned int lockdep_recursion; 1100fbb9ce95SIngo Molnar #endif 1101408894eeSIngo Molnar 11021da177e4SLinus Torvalds /* journalling filesystem info */ 11031da177e4SLinus Torvalds void *journal_info; 11041da177e4SLinus Torvalds 1105d89d8796SNeil Brown /* stacked block device info */ 1106d89d8796SNeil Brown struct bio *bio_list, **bio_tail; 1107d89d8796SNeil Brown 11081da177e4SLinus Torvalds /* VM state */ 11091da177e4SLinus Torvalds struct reclaim_state *reclaim_state; 11101da177e4SLinus Torvalds 11111da177e4SLinus Torvalds struct backing_dev_info *backing_dev_info; 11121da177e4SLinus Torvalds 11131da177e4SLinus Torvalds struct io_context *io_context; 11141da177e4SLinus Torvalds 11151da177e4SLinus Torvalds unsigned long ptrace_message; 11161da177e4SLinus Torvalds siginfo_t *last_siginfo; /* For ptrace use. */ 11171da177e4SLinus Torvalds /* 11181da177e4SLinus Torvalds * current io wait handle: wait queue entry to use for io waits 11191da177e4SLinus Torvalds * If this thread is processing aio, this points at the waitqueue 11201da177e4SLinus Torvalds * inside the currently handled kiocb. It may be NULL (i.e. default 11211da177e4SLinus Torvalds * to a stack based synchronous wait) if its doing sync IO. 11221da177e4SLinus Torvalds */ 11231da177e4SLinus Torvalds wait_queue_t *io_wait; 11244b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT 11251da177e4SLinus Torvalds /* i/o counters(bytes read/written, #syscalls */ 11261da177e4SLinus Torvalds u64 rchar, wchar, syscr, syscw; 11274b98d11bSAlexey Dobriyan #endif 11287c3ab738SAndrew Morton struct task_io_accounting ioac; 11298f0ab514SJay Lan #if defined(CONFIG_TASK_XACCT) 11301da177e4SLinus Torvalds u64 acct_rss_mem1; /* accumulated rss usage */ 11311da177e4SLinus Torvalds u64 acct_vm_mem1; /* accumulated virtual memory usage */ 1132db5fed26SJay Lan cputime_t acct_stimexpd;/* stime since last update */ 11331da177e4SLinus Torvalds #endif 11341da177e4SLinus Torvalds #ifdef CONFIG_NUMA 11351da177e4SLinus Torvalds struct mempolicy *mempolicy; 11361da177e4SLinus Torvalds short il_next; 11371da177e4SLinus Torvalds #endif 11381da177e4SLinus Torvalds #ifdef CONFIG_CPUSETS 11391da177e4SLinus Torvalds struct cpuset *cpuset; 11401da177e4SLinus Torvalds nodemask_t mems_allowed; 11411da177e4SLinus Torvalds int cpuset_mems_generation; 1142825a46afSPaul Jackson int cpuset_mem_spread_rotor; 11431da177e4SLinus Torvalds #endif 11440771dfefSIngo Molnar struct robust_list_head __user *robust_list; 114534f192c6SIngo Molnar #ifdef CONFIG_COMPAT 114634f192c6SIngo Molnar struct compat_robust_list_head __user *compat_robust_list; 114734f192c6SIngo Molnar #endif 1148c87e2837SIngo Molnar struct list_head pi_state_list; 1149c87e2837SIngo Molnar struct futex_pi_state *pi_state_cache; 11500771dfefSIngo Molnar 115122e2c507SJens Axboe atomic_t fs_excl; /* holding fs exclusive resources */ 1152e56d0903SIngo Molnar struct rcu_head rcu; 1153b92ce558SJens Axboe 1154b92ce558SJens Axboe /* 1155b92ce558SJens Axboe * cache last used pipe for splice 1156b92ce558SJens Axboe */ 1157b92ce558SJens Axboe struct pipe_inode_info *splice_pipe; 1158ca74e92bSShailabh Nagar #ifdef CONFIG_TASK_DELAY_ACCT 1159ca74e92bSShailabh Nagar struct task_delay_info *delays; 1160ca74e92bSShailabh Nagar #endif 1161f4f154fdSAkinobu Mita #ifdef CONFIG_FAULT_INJECTION 1162f4f154fdSAkinobu Mita int make_it_fail; 1163f4f154fdSAkinobu Mita #endif 11641da177e4SLinus Torvalds }; 11651da177e4SLinus Torvalds 11661da177e4SLinus Torvalds static inline pid_t process_group(struct task_struct *tsk) 11671da177e4SLinus Torvalds { 11681da177e4SLinus Torvalds return tsk->signal->pgrp; 11691da177e4SLinus Torvalds } 11701da177e4SLinus Torvalds 11711ec320afSCedric Le Goater static inline pid_t signal_session(struct signal_struct *sig) 11721ec320afSCedric Le Goater { 11731ec320afSCedric Le Goater return sig->__session; 11741ec320afSCedric Le Goater } 11751ec320afSCedric Le Goater 1176937949d9SCedric Le Goater static inline pid_t process_session(struct task_struct *tsk) 1177937949d9SCedric Le Goater { 11781ec320afSCedric Le Goater return signal_session(tsk->signal); 11791ec320afSCedric Le Goater } 11801ec320afSCedric Le Goater 11811ec320afSCedric Le Goater static inline void set_signal_session(struct signal_struct *sig, pid_t session) 11821ec320afSCedric Le Goater { 11831ec320afSCedric Le Goater sig->__session = session; 1184937949d9SCedric Le Goater } 1185937949d9SCedric Le Goater 118622c935f4SEric W. Biederman static inline struct pid *task_pid(struct task_struct *task) 118722c935f4SEric W. Biederman { 118822c935f4SEric W. Biederman return task->pids[PIDTYPE_PID].pid; 118922c935f4SEric W. Biederman } 119022c935f4SEric W. Biederman 119122c935f4SEric W. Biederman static inline struct pid *task_tgid(struct task_struct *task) 119222c935f4SEric W. Biederman { 119322c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PID].pid; 119422c935f4SEric W. Biederman } 119522c935f4SEric W. Biederman 119622c935f4SEric W. Biederman static inline struct pid *task_pgrp(struct task_struct *task) 119722c935f4SEric W. Biederman { 119822c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_PGID].pid; 119922c935f4SEric W. Biederman } 120022c935f4SEric W. Biederman 120122c935f4SEric W. Biederman static inline struct pid *task_session(struct task_struct *task) 120222c935f4SEric W. Biederman { 120322c935f4SEric W. Biederman return task->group_leader->pids[PIDTYPE_SID].pid; 120422c935f4SEric W. Biederman } 120522c935f4SEric W. Biederman 12061da177e4SLinus Torvalds /** 12071da177e4SLinus Torvalds * pid_alive - check that a task structure is not stale 12081da177e4SLinus Torvalds * @p: Task structure to be checked. 12091da177e4SLinus Torvalds * 12101da177e4SLinus Torvalds * Test if a process is not yet dead (at most zombie state) 12111da177e4SLinus Torvalds * If pid_alive fails, then pointers within the task structure 12121da177e4SLinus Torvalds * can be stale and must not be dereferenced. 12131da177e4SLinus Torvalds */ 12141da177e4SLinus Torvalds static inline int pid_alive(struct task_struct *p) 12151da177e4SLinus Torvalds { 121692476d7fSEric W. Biederman return p->pids[PIDTYPE_PID].pid != NULL; 12171da177e4SLinus Torvalds } 12181da177e4SLinus Torvalds 1219f400e198SSukadev Bhattiprolu /** 12203260259fSHenne * is_init - check if a task structure is init 12213260259fSHenne * @tsk: Task structure to be checked. 12223260259fSHenne * 12233260259fSHenne * Check if a task structure is the first user space task the kernel created. 1224f400e198SSukadev Bhattiprolu */ 1225f400e198SSukadev Bhattiprolu static inline int is_init(struct task_struct *tsk) 1226f400e198SSukadev Bhattiprolu { 1227f400e198SSukadev Bhattiprolu return tsk->pid == 1; 1228f400e198SSukadev Bhattiprolu } 1229f400e198SSukadev Bhattiprolu 12309ec52099SCedric Le Goater extern struct pid *cad_pid; 12319ec52099SCedric Le Goater 12321da177e4SLinus Torvalds extern void free_task(struct task_struct *tsk); 12331da177e4SLinus Torvalds #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0) 1234e56d0903SIngo Molnar 1235158d9ebdSAndrew Morton extern void __put_task_struct(struct task_struct *t); 1236e56d0903SIngo Molnar 1237e56d0903SIngo Molnar static inline void put_task_struct(struct task_struct *t) 1238e56d0903SIngo Molnar { 1239e56d0903SIngo Molnar if (atomic_dec_and_test(&t->usage)) 12408c7904a0SEric W. Biederman __put_task_struct(t); 1241e56d0903SIngo Molnar } 12421da177e4SLinus Torvalds 12431da177e4SLinus Torvalds /* 12441da177e4SLinus Torvalds * Per process flags 12451da177e4SLinus Torvalds */ 12461da177e4SLinus Torvalds #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */ 12471da177e4SLinus Torvalds /* Not implemented yet, only for 486*/ 12481da177e4SLinus Torvalds #define PF_STARTING 0x00000002 /* being created */ 12491da177e4SLinus Torvalds #define PF_EXITING 0x00000004 /* getting shut down */ 1250778e9a9cSAlexey Kuznetsov #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ 12511da177e4SLinus Torvalds #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ 12521da177e4SLinus Torvalds #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ 12531da177e4SLinus Torvalds #define PF_DUMPCORE 0x00000200 /* dumped core */ 12541da177e4SLinus Torvalds #define PF_SIGNALED 0x00000400 /* killed by a signal */ 12551da177e4SLinus Torvalds #define PF_MEMALLOC 0x00000800 /* Allocating memory */ 12561da177e4SLinus Torvalds #define PF_FLUSHER 0x00001000 /* responsible for disk writeback */ 12571da177e4SLinus Torvalds #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */ 12581da177e4SLinus Torvalds #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */ 12591da177e4SLinus Torvalds #define PF_FROZEN 0x00010000 /* frozen for system suspend */ 12601da177e4SLinus Torvalds #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ 12611da177e4SLinus Torvalds #define PF_KSWAPD 0x00040000 /* I am kswapd */ 12621da177e4SLinus Torvalds #define PF_SWAPOFF 0x00080000 /* I am in swapoff */ 12631da177e4SLinus Torvalds #define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */ 1264b31dc66aSJens Axboe #define PF_BORROWED_MM 0x00200000 /* I am a kthread doing use_mm */ 1265b31dc66aSJens Axboe #define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */ 1266b31dc66aSJens Axboe #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ 1267b31dc66aSJens Axboe #define PF_SPREAD_PAGE 0x01000000 /* Spread page cache over cpuset */ 1268b31dc66aSJens Axboe #define PF_SPREAD_SLAB 0x02000000 /* Spread some slab caches over cpuset */ 1269c61afb18SPaul Jackson #define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */ 127061a87122SThomas Gleixner #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */ 1271ba96a0c8SRafael J. Wysocki #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezeable */ 12721da177e4SLinus Torvalds 12731da177e4SLinus Torvalds /* 12741da177e4SLinus Torvalds * Only the _current_ task can read/write to tsk->flags, but other 12751da177e4SLinus Torvalds * tasks can access tsk->flags in readonly mode for example 12761da177e4SLinus Torvalds * with tsk_used_math (like during threaded core dumping). 12771da177e4SLinus Torvalds * There is however an exception to this rule during ptrace 12781da177e4SLinus Torvalds * or during fork: the ptracer task is allowed to write to the 12791da177e4SLinus Torvalds * child->flags of its traced child (same goes for fork, the parent 12801da177e4SLinus Torvalds * can write to the child->flags), because we're guaranteed the 12811da177e4SLinus Torvalds * child is not running and in turn not changing child->flags 12821da177e4SLinus Torvalds * at the same time the parent does it. 12831da177e4SLinus Torvalds */ 12841da177e4SLinus Torvalds #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0) 12851da177e4SLinus Torvalds #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0) 12861da177e4SLinus Torvalds #define clear_used_math() clear_stopped_child_used_math(current) 12871da177e4SLinus Torvalds #define set_used_math() set_stopped_child_used_math(current) 12881da177e4SLinus Torvalds #define conditional_stopped_child_used_math(condition, child) \ 12891da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0) 12901da177e4SLinus Torvalds #define conditional_used_math(condition) \ 12911da177e4SLinus Torvalds conditional_stopped_child_used_math(condition, current) 12921da177e4SLinus Torvalds #define copy_to_stopped_child_used_math(child) \ 12931da177e4SLinus Torvalds do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0) 12941da177e4SLinus Torvalds /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */ 12951da177e4SLinus Torvalds #define tsk_used_math(p) ((p)->flags & PF_USED_MATH) 12961da177e4SLinus Torvalds #define used_math() tsk_used_math(current) 12971da177e4SLinus Torvalds 12981da177e4SLinus Torvalds #ifdef CONFIG_SMP 129936c8b586SIngo Molnar extern int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask); 13001da177e4SLinus Torvalds #else 130136c8b586SIngo Molnar static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask) 13021da177e4SLinus Torvalds { 13034098f991SPaul Jackson if (!cpu_isset(0, new_mask)) 13041da177e4SLinus Torvalds return -EINVAL; 13051da177e4SLinus Torvalds return 0; 13061da177e4SLinus Torvalds } 13071da177e4SLinus Torvalds #endif 13081da177e4SLinus Torvalds 13091da177e4SLinus Torvalds extern unsigned long long sched_clock(void); 131036c8b586SIngo Molnar extern unsigned long long 131136c8b586SIngo Molnar current_sched_time(const struct task_struct *current_task); 13121da177e4SLinus Torvalds 13131da177e4SLinus Torvalds /* sched_exec is called by processes performing an exec */ 13141da177e4SLinus Torvalds #ifdef CONFIG_SMP 13151da177e4SLinus Torvalds extern void sched_exec(void); 13161da177e4SLinus Torvalds #else 13171da177e4SLinus Torvalds #define sched_exec() {} 13181da177e4SLinus Torvalds #endif 13191da177e4SLinus Torvalds 13201da177e4SLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU 13211da177e4SLinus Torvalds extern void idle_task_exit(void); 13221da177e4SLinus Torvalds #else 13231da177e4SLinus Torvalds static inline void idle_task_exit(void) {} 13241da177e4SLinus Torvalds #endif 13251da177e4SLinus Torvalds 13261da177e4SLinus Torvalds extern void sched_idle_next(void); 1327b29739f9SIngo Molnar 1328bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_granularity; 1329bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_wakeup_granularity; 1330bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_batch_wakeup_granularity; 1331bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_stat_granularity; 1332bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_runtime_limit; 1333bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_child_runs_first; 1334bf0f6f24SIngo Molnar extern unsigned int sysctl_sched_features; 1335bf0f6f24SIngo Molnar 1336b29739f9SIngo Molnar #ifdef CONFIG_RT_MUTEXES 133736c8b586SIngo Molnar extern int rt_mutex_getprio(struct task_struct *p); 133836c8b586SIngo Molnar extern void rt_mutex_setprio(struct task_struct *p, int prio); 133936c8b586SIngo Molnar extern void rt_mutex_adjust_pi(struct task_struct *p); 1340b29739f9SIngo Molnar #else 134136c8b586SIngo Molnar static inline int rt_mutex_getprio(struct task_struct *p) 1342b29739f9SIngo Molnar { 1343b29739f9SIngo Molnar return p->normal_prio; 1344b29739f9SIngo Molnar } 134595e02ca9SThomas Gleixner # define rt_mutex_adjust_pi(p) do { } while (0) 1346b29739f9SIngo Molnar #endif 1347b29739f9SIngo Molnar 134836c8b586SIngo Molnar extern void set_user_nice(struct task_struct *p, long nice); 134936c8b586SIngo Molnar extern int task_prio(const struct task_struct *p); 135036c8b586SIngo Molnar extern int task_nice(const struct task_struct *p); 135136c8b586SIngo Molnar extern int can_nice(const struct task_struct *p, const int nice); 135236c8b586SIngo Molnar extern int task_curr(const struct task_struct *p); 13531da177e4SLinus Torvalds extern int idle_cpu(int cpu); 13541da177e4SLinus Torvalds extern int sched_setscheduler(struct task_struct *, int, struct sched_param *); 135536c8b586SIngo Molnar extern struct task_struct *idle_task(int cpu); 135636c8b586SIngo Molnar extern struct task_struct *curr_task(int cpu); 135736c8b586SIngo Molnar extern void set_curr_task(int cpu, struct task_struct *p); 13581da177e4SLinus Torvalds 13591da177e4SLinus Torvalds void yield(void); 13601da177e4SLinus Torvalds 13611da177e4SLinus Torvalds /* 13621da177e4SLinus Torvalds * The default (Linux) execution domain. 13631da177e4SLinus Torvalds */ 13641da177e4SLinus Torvalds extern struct exec_domain default_exec_domain; 13651da177e4SLinus Torvalds 13661da177e4SLinus Torvalds union thread_union { 13671da177e4SLinus Torvalds struct thread_info thread_info; 13681da177e4SLinus Torvalds unsigned long stack[THREAD_SIZE/sizeof(long)]; 13691da177e4SLinus Torvalds }; 13701da177e4SLinus Torvalds 13711da177e4SLinus Torvalds #ifndef __HAVE_ARCH_KSTACK_END 13721da177e4SLinus Torvalds static inline int kstack_end(void *addr) 13731da177e4SLinus Torvalds { 13741da177e4SLinus Torvalds /* Reliable end of stack detection: 13751da177e4SLinus Torvalds * Some APM bios versions misalign the stack 13761da177e4SLinus Torvalds */ 13771da177e4SLinus Torvalds return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*))); 13781da177e4SLinus Torvalds } 13791da177e4SLinus Torvalds #endif 13801da177e4SLinus Torvalds 13811da177e4SLinus Torvalds extern union thread_union init_thread_union; 13821da177e4SLinus Torvalds extern struct task_struct init_task; 13831da177e4SLinus Torvalds 13841da177e4SLinus Torvalds extern struct mm_struct init_mm; 13851da177e4SLinus Torvalds 13861da177e4SLinus Torvalds #define find_task_by_pid(nr) find_task_by_pid_type(PIDTYPE_PID, nr) 13871da177e4SLinus Torvalds extern struct task_struct *find_task_by_pid_type(int type, int pid); 13881da177e4SLinus Torvalds extern void __set_special_pids(pid_t session, pid_t pgrp); 13891da177e4SLinus Torvalds 13901da177e4SLinus Torvalds /* per-UID process charging. */ 13911da177e4SLinus Torvalds extern struct user_struct * alloc_uid(uid_t); 13921da177e4SLinus Torvalds static inline struct user_struct *get_uid(struct user_struct *u) 13931da177e4SLinus Torvalds { 13941da177e4SLinus Torvalds atomic_inc(&u->__count); 13951da177e4SLinus Torvalds return u; 13961da177e4SLinus Torvalds } 13971da177e4SLinus Torvalds extern void free_uid(struct user_struct *); 13981da177e4SLinus Torvalds extern void switch_uid(struct user_struct *); 13991da177e4SLinus Torvalds 14001da177e4SLinus Torvalds #include <asm/current.h> 14011da177e4SLinus Torvalds 14023171a030SAtsushi Nemoto extern void do_timer(unsigned long ticks); 14031da177e4SLinus Torvalds 14041da177e4SLinus Torvalds extern int FASTCALL(wake_up_state(struct task_struct * tsk, unsigned int state)); 14051da177e4SLinus Torvalds extern int FASTCALL(wake_up_process(struct task_struct * tsk)); 14061da177e4SLinus Torvalds extern void FASTCALL(wake_up_new_task(struct task_struct * tsk, 14071da177e4SLinus Torvalds unsigned long clone_flags)); 14081da177e4SLinus Torvalds #ifdef CONFIG_SMP 14091da177e4SLinus Torvalds extern void kick_process(struct task_struct *tsk); 14101da177e4SLinus Torvalds #else 14111da177e4SLinus Torvalds static inline void kick_process(struct task_struct *tsk) { } 14121da177e4SLinus Torvalds #endif 141336c8b586SIngo Molnar extern void FASTCALL(sched_fork(struct task_struct * p, int clone_flags)); 141436c8b586SIngo Molnar extern void FASTCALL(sched_exit(struct task_struct * p)); 14151da177e4SLinus Torvalds 14161da177e4SLinus Torvalds extern int in_group_p(gid_t); 14171da177e4SLinus Torvalds extern int in_egroup_p(gid_t); 14181da177e4SLinus Torvalds 14191da177e4SLinus Torvalds extern void proc_caches_init(void); 14201da177e4SLinus Torvalds extern void flush_signals(struct task_struct *); 142110ab825bSOleg Nesterov extern void ignore_signals(struct task_struct *); 14221da177e4SLinus Torvalds extern void flush_signal_handlers(struct task_struct *, int force_default); 14231da177e4SLinus Torvalds extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info); 14241da177e4SLinus Torvalds 14251da177e4SLinus Torvalds static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) 14261da177e4SLinus Torvalds { 14271da177e4SLinus Torvalds unsigned long flags; 14281da177e4SLinus Torvalds int ret; 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds spin_lock_irqsave(&tsk->sighand->siglock, flags); 14311da177e4SLinus Torvalds ret = dequeue_signal(tsk, mask, info); 14321da177e4SLinus Torvalds spin_unlock_irqrestore(&tsk->sighand->siglock, flags); 14331da177e4SLinus Torvalds 14341da177e4SLinus Torvalds return ret; 14351da177e4SLinus Torvalds } 14361da177e4SLinus Torvalds 14371da177e4SLinus Torvalds extern void block_all_signals(int (*notifier)(void *priv), void *priv, 14381da177e4SLinus Torvalds sigset_t *mask); 14391da177e4SLinus Torvalds extern void unblock_all_signals(void); 14401da177e4SLinus Torvalds extern void release_task(struct task_struct * p); 14411da177e4SLinus Torvalds extern int send_sig_info(int, struct siginfo *, struct task_struct *); 14421da177e4SLinus Torvalds extern int send_group_sig_info(int, struct siginfo *, struct task_struct *); 14431da177e4SLinus Torvalds extern int force_sigsegv(int, struct task_struct *); 14441da177e4SLinus Torvalds extern int force_sig_info(int, struct siginfo *, struct task_struct *); 1445c4b92fc1SEric W. Biederman extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp); 1446c4b92fc1SEric W. Biederman extern int kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp); 1447c4b92fc1SEric W. Biederman extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid); 14482425c08bSEric W. Biederman extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32); 1449c4b92fc1SEric W. Biederman extern int kill_pgrp(struct pid *pid, int sig, int priv); 1450c4b92fc1SEric W. Biederman extern int kill_pid(struct pid *pid, int sig, int priv); 1451c3de4b38SMatthew Wilcox extern int kill_proc_info(int, struct siginfo *, pid_t); 14521da177e4SLinus Torvalds extern void do_notify_parent(struct task_struct *, int); 14531da177e4SLinus Torvalds extern void force_sig(int, struct task_struct *); 14541da177e4SLinus Torvalds extern void force_sig_specific(int, struct task_struct *); 14551da177e4SLinus Torvalds extern int send_sig(int, struct task_struct *, int); 14561da177e4SLinus Torvalds extern void zap_other_threads(struct task_struct *p); 14571da177e4SLinus Torvalds extern int kill_proc(pid_t, int, int); 14581da177e4SLinus Torvalds extern struct sigqueue *sigqueue_alloc(void); 14591da177e4SLinus Torvalds extern void sigqueue_free(struct sigqueue *); 14601da177e4SLinus Torvalds extern int send_sigqueue(int, struct sigqueue *, struct task_struct *); 14611da177e4SLinus Torvalds extern int send_group_sigqueue(int, struct sigqueue *, struct task_struct *); 14629ac95f2fSOleg Nesterov extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); 14631da177e4SLinus Torvalds extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long); 14641da177e4SLinus Torvalds 14659ec52099SCedric Le Goater static inline int kill_cad_pid(int sig, int priv) 14669ec52099SCedric Le Goater { 14679ec52099SCedric Le Goater return kill_pid(cad_pid, sig, priv); 14689ec52099SCedric Le Goater } 14699ec52099SCedric Le Goater 14701da177e4SLinus Torvalds /* These can be the second arg to send_sig_info/send_group_sig_info. */ 14711da177e4SLinus Torvalds #define SEND_SIG_NOINFO ((struct siginfo *) 0) 14721da177e4SLinus Torvalds #define SEND_SIG_PRIV ((struct siginfo *) 1) 14731da177e4SLinus Torvalds #define SEND_SIG_FORCED ((struct siginfo *) 2) 14741da177e4SLinus Torvalds 1475621d3121SOleg Nesterov static inline int is_si_special(const struct siginfo *info) 1476621d3121SOleg Nesterov { 1477621d3121SOleg Nesterov return info <= SEND_SIG_FORCED; 1478621d3121SOleg Nesterov } 1479621d3121SOleg Nesterov 14801da177e4SLinus Torvalds /* True if we are on the alternate signal stack. */ 14811da177e4SLinus Torvalds 14821da177e4SLinus Torvalds static inline int on_sig_stack(unsigned long sp) 14831da177e4SLinus Torvalds { 14841da177e4SLinus Torvalds return (sp - current->sas_ss_sp < current->sas_ss_size); 14851da177e4SLinus Torvalds } 14861da177e4SLinus Torvalds 14871da177e4SLinus Torvalds static inline int sas_ss_flags(unsigned long sp) 14881da177e4SLinus Torvalds { 14891da177e4SLinus Torvalds return (current->sas_ss_size == 0 ? SS_DISABLE 14901da177e4SLinus Torvalds : on_sig_stack(sp) ? SS_ONSTACK : 0); 14911da177e4SLinus Torvalds } 14921da177e4SLinus Torvalds 14931da177e4SLinus Torvalds /* 14941da177e4SLinus Torvalds * Routines for handling mm_structs 14951da177e4SLinus Torvalds */ 14961da177e4SLinus Torvalds extern struct mm_struct * mm_alloc(void); 14971da177e4SLinus Torvalds 14981da177e4SLinus Torvalds /* mmdrop drops the mm and the page tables */ 14991da177e4SLinus Torvalds extern void FASTCALL(__mmdrop(struct mm_struct *)); 15001da177e4SLinus Torvalds static inline void mmdrop(struct mm_struct * mm) 15011da177e4SLinus Torvalds { 15021da177e4SLinus Torvalds if (atomic_dec_and_test(&mm->mm_count)) 15031da177e4SLinus Torvalds __mmdrop(mm); 15041da177e4SLinus Torvalds } 15051da177e4SLinus Torvalds 15061da177e4SLinus Torvalds /* mmput gets rid of the mappings and all user-space */ 15071da177e4SLinus Torvalds extern void mmput(struct mm_struct *); 15081da177e4SLinus Torvalds /* Grab a reference to a task's mm, if it is not already going away */ 15091da177e4SLinus Torvalds extern struct mm_struct *get_task_mm(struct task_struct *task); 15101da177e4SLinus Torvalds /* Remove the current tasks stale references to the old mm_struct */ 15111da177e4SLinus Torvalds extern void mm_release(struct task_struct *, struct mm_struct *); 15121da177e4SLinus Torvalds 15131da177e4SLinus Torvalds extern int copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *); 15141da177e4SLinus Torvalds extern void flush_thread(void); 15151da177e4SLinus Torvalds extern void exit_thread(void); 15161da177e4SLinus Torvalds 15171da177e4SLinus Torvalds extern void exit_files(struct task_struct *); 15186b3934efSOleg Nesterov extern void __cleanup_signal(struct signal_struct *); 1519a7e5328aSOleg Nesterov extern void __cleanup_sighand(struct sighand_struct *); 15201da177e4SLinus Torvalds extern void exit_itimers(struct signal_struct *); 15211da177e4SLinus Torvalds 15221da177e4SLinus Torvalds extern NORET_TYPE void do_group_exit(int); 15231da177e4SLinus Torvalds 15241da177e4SLinus Torvalds extern void daemonize(const char *, ...); 15251da177e4SLinus Torvalds extern int allow_signal(int); 15261da177e4SLinus Torvalds extern int disallow_signal(int); 15271da177e4SLinus Torvalds 15281da177e4SLinus Torvalds extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *); 15291da177e4SLinus Torvalds extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *); 153036c8b586SIngo Molnar struct task_struct *fork_idle(int); 15311da177e4SLinus Torvalds 15321da177e4SLinus Torvalds extern void set_task_comm(struct task_struct *tsk, char *from); 15331da177e4SLinus Torvalds extern void get_task_comm(char *to, struct task_struct *tsk); 15341da177e4SLinus Torvalds 15351da177e4SLinus Torvalds #ifdef CONFIG_SMP 153636c8b586SIngo Molnar extern void wait_task_inactive(struct task_struct * p); 15371da177e4SLinus Torvalds #else 15381da177e4SLinus Torvalds #define wait_task_inactive(p) do { } while (0) 15391da177e4SLinus Torvalds #endif 15401da177e4SLinus Torvalds 15411da177e4SLinus Torvalds #define remove_parent(p) list_del_init(&(p)->sibling) 15428fafabd8SOleg Nesterov #define add_parent(p) list_add_tail(&(p)->sibling,&(p)->parent->children) 15431da177e4SLinus Torvalds 15445e85d4abSEric W. Biederman #define next_task(p) list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks) 15451da177e4SLinus Torvalds 15461da177e4SLinus Torvalds #define for_each_process(p) \ 15471da177e4SLinus Torvalds for (p = &init_task ; (p = next_task(p)) != &init_task ; ) 15481da177e4SLinus Torvalds 15491da177e4SLinus Torvalds /* 15501da177e4SLinus Torvalds * Careful: do_each_thread/while_each_thread is a double loop so 15511da177e4SLinus Torvalds * 'break' will not work as expected - use goto instead. 15521da177e4SLinus Torvalds */ 15531da177e4SLinus Torvalds #define do_each_thread(g, t) \ 15541da177e4SLinus Torvalds for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do 15551da177e4SLinus Torvalds 15561da177e4SLinus Torvalds #define while_each_thread(g, t) \ 15571da177e4SLinus Torvalds while ((t = next_thread(t)) != g) 15581da177e4SLinus Torvalds 1559de12a787SEric W. Biederman /* de_thread depends on thread_group_leader not being a pid based check */ 1560de12a787SEric W. Biederman #define thread_group_leader(p) (p == p->group_leader) 15611da177e4SLinus Torvalds 15620804ef4bSEric W. Biederman /* Do to the insanities of de_thread it is possible for a process 15630804ef4bSEric W. Biederman * to have the pid of the thread group leader without actually being 15640804ef4bSEric W. Biederman * the thread group leader. For iteration through the pids in proc 15650804ef4bSEric W. Biederman * all we care about is that we have a task with the appropriate 15660804ef4bSEric W. Biederman * pid, we don't actually care if we have the right task. 15670804ef4bSEric W. Biederman */ 15680804ef4bSEric W. Biederman static inline int has_group_leader_pid(struct task_struct *p) 15690804ef4bSEric W. Biederman { 15700804ef4bSEric W. Biederman return p->pid == p->tgid; 15710804ef4bSEric W. Biederman } 15720804ef4bSEric W. Biederman 157336c8b586SIngo Molnar static inline struct task_struct *next_thread(const struct task_struct *p) 157447e65328SOleg Nesterov { 157547e65328SOleg Nesterov return list_entry(rcu_dereference(p->thread_group.next), 157636c8b586SIngo Molnar struct task_struct, thread_group); 157747e65328SOleg Nesterov } 157847e65328SOleg Nesterov 157936c8b586SIngo Molnar static inline int thread_group_empty(struct task_struct *p) 15801da177e4SLinus Torvalds { 158147e65328SOleg Nesterov return list_empty(&p->thread_group); 15821da177e4SLinus Torvalds } 15831da177e4SLinus Torvalds 15841da177e4SLinus Torvalds #define delay_group_leader(p) \ 15851da177e4SLinus Torvalds (thread_group_leader(p) && !thread_group_empty(p)) 15861da177e4SLinus Torvalds 15871da177e4SLinus Torvalds /* 1588260ea101SEric W. Biederman * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring 158922e2c507SJens Axboe * subscriptions and synchronises with wait4(). Also used in procfs. Also 1590053199edSPaul Jackson * pins the final release of task.io_context. Also protects ->cpuset. 15911da177e4SLinus Torvalds * 15921da177e4SLinus Torvalds * Nests both inside and outside of read_lock(&tasklist_lock). 15931da177e4SLinus Torvalds * It must not be nested with write_lock_irq(&tasklist_lock), 15941da177e4SLinus Torvalds * neither inside nor outside. 15951da177e4SLinus Torvalds */ 15961da177e4SLinus Torvalds static inline void task_lock(struct task_struct *p) 15971da177e4SLinus Torvalds { 15981da177e4SLinus Torvalds spin_lock(&p->alloc_lock); 15991da177e4SLinus Torvalds } 16001da177e4SLinus Torvalds 16011da177e4SLinus Torvalds static inline void task_unlock(struct task_struct *p) 16021da177e4SLinus Torvalds { 16031da177e4SLinus Torvalds spin_unlock(&p->alloc_lock); 16041da177e4SLinus Torvalds } 16051da177e4SLinus Torvalds 1606f63ee72eSOleg Nesterov extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk, 1607f63ee72eSOleg Nesterov unsigned long *flags); 1608f63ee72eSOleg Nesterov 1609f63ee72eSOleg Nesterov static inline void unlock_task_sighand(struct task_struct *tsk, 1610f63ee72eSOleg Nesterov unsigned long *flags) 1611f63ee72eSOleg Nesterov { 1612f63ee72eSOleg Nesterov spin_unlock_irqrestore(&tsk->sighand->siglock, *flags); 1613f63ee72eSOleg Nesterov } 1614f63ee72eSOleg Nesterov 1615f037360fSAl Viro #ifndef __HAVE_THREAD_FUNCTIONS 1616f037360fSAl Viro 1617f7e4217bSRoman Zippel #define task_thread_info(task) ((struct thread_info *)(task)->stack) 1618f7e4217bSRoman Zippel #define task_stack_page(task) ((task)->stack) 1619a1261f54SAl Viro 162010ebffdeSAl Viro static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org) 162110ebffdeSAl Viro { 162210ebffdeSAl Viro *task_thread_info(p) = *task_thread_info(org); 162310ebffdeSAl Viro task_thread_info(p)->task = p; 162410ebffdeSAl Viro } 162510ebffdeSAl Viro 162610ebffdeSAl Viro static inline unsigned long *end_of_stack(struct task_struct *p) 162710ebffdeSAl Viro { 1628f7e4217bSRoman Zippel return (unsigned long *)(task_thread_info(p) + 1); 162910ebffdeSAl Viro } 163010ebffdeSAl Viro 1631f037360fSAl Viro #endif 1632f037360fSAl Viro 16331da177e4SLinus Torvalds /* set thread flags in other task's structures 16341da177e4SLinus Torvalds * - see asm/thread_info.h for TIF_xxxx flags available 16351da177e4SLinus Torvalds */ 16361da177e4SLinus Torvalds static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag) 16371da177e4SLinus Torvalds { 1638a1261f54SAl Viro set_ti_thread_flag(task_thread_info(tsk), flag); 16391da177e4SLinus Torvalds } 16401da177e4SLinus Torvalds 16411da177e4SLinus Torvalds static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag) 16421da177e4SLinus Torvalds { 1643a1261f54SAl Viro clear_ti_thread_flag(task_thread_info(tsk), flag); 16441da177e4SLinus Torvalds } 16451da177e4SLinus Torvalds 16461da177e4SLinus Torvalds static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag) 16471da177e4SLinus Torvalds { 1648a1261f54SAl Viro return test_and_set_ti_thread_flag(task_thread_info(tsk), flag); 16491da177e4SLinus Torvalds } 16501da177e4SLinus Torvalds 16511da177e4SLinus Torvalds static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag) 16521da177e4SLinus Torvalds { 1653a1261f54SAl Viro return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag); 16541da177e4SLinus Torvalds } 16551da177e4SLinus Torvalds 16561da177e4SLinus Torvalds static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag) 16571da177e4SLinus Torvalds { 1658a1261f54SAl Viro return test_ti_thread_flag(task_thread_info(tsk), flag); 16591da177e4SLinus Torvalds } 16601da177e4SLinus Torvalds 16611da177e4SLinus Torvalds static inline void set_tsk_need_resched(struct task_struct *tsk) 16621da177e4SLinus Torvalds { 16631da177e4SLinus Torvalds set_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 16641da177e4SLinus Torvalds } 16651da177e4SLinus Torvalds 16661da177e4SLinus Torvalds static inline void clear_tsk_need_resched(struct task_struct *tsk) 16671da177e4SLinus Torvalds { 16681da177e4SLinus Torvalds clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 16691da177e4SLinus Torvalds } 16701da177e4SLinus Torvalds 16711da177e4SLinus Torvalds static inline int signal_pending(struct task_struct *p) 16721da177e4SLinus Torvalds { 16731da177e4SLinus Torvalds return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING)); 16741da177e4SLinus Torvalds } 16751da177e4SLinus Torvalds 16761da177e4SLinus Torvalds static inline int need_resched(void) 16771da177e4SLinus Torvalds { 16781da177e4SLinus Torvalds return unlikely(test_thread_flag(TIF_NEED_RESCHED)); 16791da177e4SLinus Torvalds } 16801da177e4SLinus Torvalds 16811da177e4SLinus Torvalds /* 16821da177e4SLinus Torvalds * cond_resched() and cond_resched_lock(): latency reduction via 16831da177e4SLinus Torvalds * explicit rescheduling in places that are safe. The return 16841da177e4SLinus Torvalds * value indicates whether a reschedule was done in fact. 16851da177e4SLinus Torvalds * cond_resched_lock() will drop the spinlock before scheduling, 16861da177e4SLinus Torvalds * cond_resched_softirq() will enable bhs before scheduling. 16871da177e4SLinus Torvalds */ 16881da177e4SLinus Torvalds extern int cond_resched(void); 16891da177e4SLinus Torvalds extern int cond_resched_lock(spinlock_t * lock); 16901da177e4SLinus Torvalds extern int cond_resched_softirq(void); 16911da177e4SLinus Torvalds 16921da177e4SLinus Torvalds /* 16931da177e4SLinus Torvalds * Does a critical section need to be broken due to another 16941da177e4SLinus Torvalds * task waiting?: 16951da177e4SLinus Torvalds */ 16961da177e4SLinus Torvalds #if defined(CONFIG_PREEMPT) && defined(CONFIG_SMP) 16971da177e4SLinus Torvalds # define need_lockbreak(lock) ((lock)->break_lock) 16981da177e4SLinus Torvalds #else 16991da177e4SLinus Torvalds # define need_lockbreak(lock) 0 17001da177e4SLinus Torvalds #endif 17011da177e4SLinus Torvalds 17021da177e4SLinus Torvalds /* 17031da177e4SLinus Torvalds * Does a critical section need to be broken due to another 17041da177e4SLinus Torvalds * task waiting or preemption being signalled: 17051da177e4SLinus Torvalds */ 17061da177e4SLinus Torvalds static inline int lock_need_resched(spinlock_t *lock) 17071da177e4SLinus Torvalds { 17081da177e4SLinus Torvalds if (need_lockbreak(lock) || need_resched()) 17091da177e4SLinus Torvalds return 1; 17101da177e4SLinus Torvalds return 0; 17111da177e4SLinus Torvalds } 17121da177e4SLinus Torvalds 17137bb44adeSRoland McGrath /* 17147bb44adeSRoland McGrath * Reevaluate whether the task has signals pending delivery. 17157bb44adeSRoland McGrath * Wake the task if so. 17167bb44adeSRoland McGrath * This is required every time the blocked sigset_t changes. 17177bb44adeSRoland McGrath * callers must hold sighand->siglock. 17187bb44adeSRoland McGrath */ 17197bb44adeSRoland McGrath extern void recalc_sigpending_and_wake(struct task_struct *t); 17201da177e4SLinus Torvalds extern void recalc_sigpending(void); 17211da177e4SLinus Torvalds 17221da177e4SLinus Torvalds extern void signal_wake_up(struct task_struct *t, int resume_stopped); 17231da177e4SLinus Torvalds 17241da177e4SLinus Torvalds /* 17251da177e4SLinus Torvalds * Wrappers for p->thread_info->cpu access. No-op on UP. 17261da177e4SLinus Torvalds */ 17271da177e4SLinus Torvalds #ifdef CONFIG_SMP 17281da177e4SLinus Torvalds 17291da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 17301da177e4SLinus Torvalds { 1731a1261f54SAl Viro return task_thread_info(p)->cpu; 17321da177e4SLinus Torvalds } 17331da177e4SLinus Torvalds 1734c65cc870SIngo Molnar extern void set_task_cpu(struct task_struct *p, unsigned int cpu); 17351da177e4SLinus Torvalds 17361da177e4SLinus Torvalds #else 17371da177e4SLinus Torvalds 17381da177e4SLinus Torvalds static inline unsigned int task_cpu(const struct task_struct *p) 17391da177e4SLinus Torvalds { 17401da177e4SLinus Torvalds return 0; 17411da177e4SLinus Torvalds } 17421da177e4SLinus Torvalds 17431da177e4SLinus Torvalds static inline void set_task_cpu(struct task_struct *p, unsigned int cpu) 17441da177e4SLinus Torvalds { 17451da177e4SLinus Torvalds } 17461da177e4SLinus Torvalds 17471da177e4SLinus Torvalds #endif /* CONFIG_SMP */ 17481da177e4SLinus Torvalds 17491da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 17501da177e4SLinus Torvalds extern void arch_pick_mmap_layout(struct mm_struct *mm); 17511da177e4SLinus Torvalds #else 17521da177e4SLinus Torvalds static inline void arch_pick_mmap_layout(struct mm_struct *mm) 17531da177e4SLinus Torvalds { 17541da177e4SLinus Torvalds mm->mmap_base = TASK_UNMAPPED_BASE; 17551da177e4SLinus Torvalds mm->get_unmapped_area = arch_get_unmapped_area; 17561da177e4SLinus Torvalds mm->unmap_area = arch_unmap_area; 17571da177e4SLinus Torvalds } 17581da177e4SLinus Torvalds #endif 17591da177e4SLinus Torvalds 17601da177e4SLinus Torvalds extern long sched_setaffinity(pid_t pid, cpumask_t new_mask); 17611da177e4SLinus Torvalds extern long sched_getaffinity(pid_t pid, cpumask_t *mask); 17621da177e4SLinus Torvalds 17635c45bf27SSiddha, Suresh B extern int sched_mc_power_savings, sched_smt_power_savings; 17645c45bf27SSiddha, Suresh B 17651da177e4SLinus Torvalds extern void normalize_rt_tasks(void); 17661da177e4SLinus Torvalds 17674b98d11bSAlexey Dobriyan #ifdef CONFIG_TASK_XACCT 17684b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 17694b98d11bSAlexey Dobriyan { 17704b98d11bSAlexey Dobriyan tsk->rchar += amt; 17714b98d11bSAlexey Dobriyan } 17724b98d11bSAlexey Dobriyan 17734b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 17744b98d11bSAlexey Dobriyan { 17754b98d11bSAlexey Dobriyan tsk->wchar += amt; 17764b98d11bSAlexey Dobriyan } 17774b98d11bSAlexey Dobriyan 17784b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 17794b98d11bSAlexey Dobriyan { 17804b98d11bSAlexey Dobriyan tsk->syscr++; 17814b98d11bSAlexey Dobriyan } 17824b98d11bSAlexey Dobriyan 17834b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 17844b98d11bSAlexey Dobriyan { 17854b98d11bSAlexey Dobriyan tsk->syscw++; 17864b98d11bSAlexey Dobriyan } 17874b98d11bSAlexey Dobriyan #else 17884b98d11bSAlexey Dobriyan static inline void add_rchar(struct task_struct *tsk, ssize_t amt) 17894b98d11bSAlexey Dobriyan { 17904b98d11bSAlexey Dobriyan } 17914b98d11bSAlexey Dobriyan 17924b98d11bSAlexey Dobriyan static inline void add_wchar(struct task_struct *tsk, ssize_t amt) 17934b98d11bSAlexey Dobriyan { 17944b98d11bSAlexey Dobriyan } 17954b98d11bSAlexey Dobriyan 17964b98d11bSAlexey Dobriyan static inline void inc_syscr(struct task_struct *tsk) 17974b98d11bSAlexey Dobriyan { 17984b98d11bSAlexey Dobriyan } 17994b98d11bSAlexey Dobriyan 18004b98d11bSAlexey Dobriyan static inline void inc_syscw(struct task_struct *tsk) 18014b98d11bSAlexey Dobriyan { 18024b98d11bSAlexey Dobriyan } 18034b98d11bSAlexey Dobriyan #endif 18044b98d11bSAlexey Dobriyan 18051da177e4SLinus Torvalds #endif /* __KERNEL__ */ 18061da177e4SLinus Torvalds 18071da177e4SLinus Torvalds #endif 1808