📄 sched.h
字号:
#ifndef _LINUX_SCHED_H#define _LINUX_SCHED_H#include <asm/param.h> /* for HZ */extern unsigned long event;#include <linux/config.h>#include <linux/compiler.h>#include <linux/binfmts.h>#include <linux/threads.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/times.h>#include <linux/timex.h>#include <linux/rbtree.h>#include <linux/condsched.h>#include <asm/system.h>#include <asm/semaphore.h>#include <asm/page.h>#include <asm/ptrace.h>#include <asm/mmu.h>#include <linux/smp.h>//#include <linux/tty.h>#include <linux/sem.h>#include <linux/signal.h>#include <linux/securebits.h>#include <linux/fs_struct.h>struct exec_domain;/* * cloning flags: */#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */#define CLONE_VM 0x00000100 /* set if VM shared between processes */#define CLONE_FS 0x00000200 /* set if fs info shared between processes */#define CLONE_FILES 0x00000400 /* set if open files shared between processes */#define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */#define CLONE_PID 0x00001000 /* set if pid shared */#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */#define CLONE_THREAD 0x00010000 /* Same thread group? */#define CLONE_NEWNS 0x00020000 /* New namespace group? */#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)/* * These are the constant used to fake the fixed-point load-average * counting. Some notes: * - 11 bit fractions expand to 22 bits by the multiplies: this gives * a load-average precision of 10 bits integer + 11 bits fractional * - if you want to count load-averages more often, you need more * precision, or rounding will get you. With 2-second counting freq, * the EXP_n values would be 1981, 2034 and 2043 if still using only * 11 bit fractions. */extern unsigned long avenrun[]; /* Load averages */#define FSHIFT 11 /* nr of bits of precision */#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */#define LOAD_FREQ (5*HZ) /* 5 sec intervals */#define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */#define EXP_5 2014 /* 1/exp(5sec/5min) */#define EXP_15 2037 /* 1/exp(5sec/15min) */#define CALC_LOAD(load,exp,n) \ load *= exp; \ load += n*(FIXED_1-exp); \ load >>= FSHIFT;#define CT_TO_SECS(x) ((x) / HZ)#define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)extern int nr_threads;extern int last_pid;extern unsigned long nr_running(void);//#include <linux/fs.h>#include <linux/time.h>#include <linux/param.h>#include <linux/resource.h>#ifdef __KERNEL__#include <linux/timer.h>#endif#include <asm/processor.h>#define TASK_RUNNING 0#define TASK_INTERRUPTIBLE 1#define TASK_UNINTERRUPTIBLE 2#define TASK_ZOMBIE 4#define TASK_STOPPED 8#define __set_task_state(tsk, state_value) \ do { (tsk)->state = (state_value); } while (0)#ifdef CONFIG_SMP#define set_task_state(tsk, state_value) \ set_mb((tsk)->state, (state_value))#else#define set_task_state(tsk, state_value) \ __set_task_state((tsk), (state_value))#endif#define __set_current_state(state_value) \ do { current->state = (state_value); } while (0)#ifdef CONFIG_SMP#define set_current_state(state_value) \ set_mb(current->state, (state_value))#else#define set_current_state(state_value) \ __set_current_state(state_value)#endif/* * Scheduling policies */#define SCHED_OTHER 0#define SCHED_FIFO 1#define SCHED_RR 2struct sched_param { int sched_priority;};struct completion;#ifdef __KERNEL__#include <linux/spinlock.h>/* * This serializes "schedule()" and also protects * the run-queue from deletions/modifications (but * _adding_ to the beginning of the run-queue has * a separate lock). */extern rwlock_t tasklist_lock;extern spinlock_t mmlist_lock;typedef struct task_struct task_t;extern void sched_init(void);extern void init_idle(task_t *idle, int cpu);extern void show_state(void);extern void cpu_init (void);extern void trap_init(void);extern void update_process_times(int user);extern void update_one_process(task_t *p, unsigned long user, unsigned long system, int cpu);extern void scheduler_tick(int user_tick, int system);extern void migration_init(void);extern unsigned long cache_decay_ticks;#define MAX_SCHEDULE_TIMEOUT LONG_MAXextern signed long FASTCALL(schedule_timeout(signed long timeout));asmlinkage void schedule(void);extern int schedule_task(struct tq_struct *task);extern void flush_scheduled_tasks(void);extern int start_context_thread(void);extern int current_is_keventd(void);extern void force_cpu_reschedule(int cpu);/* * The maximum RT priority is configurable. If the resulting * bitmap is 160-bits , we can use a hand-coded routine which * is optimal. Otherwise, we fall back on a generic routine for * finding the first set bit from an arbitrarily-sized bitmap. */#if MAX_PRIO < 160 && MAX_PRIO > 127#define sched_find_first_bit(map) _sched_find_first_bit(map)#else#define sched_find_first_bit(map) find_first_bit(map, MAX_PRIO)#endif/* * The default fd array needs to be at least BITS_PER_LONG, * as this is the granularity returned by copy_fdset(). */#define NR_OPEN_DEFAULT BITS_PER_LONGstruct namespace;/* * Open file table structure */struct files_struct { atomic_t count; rwlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */ int max_fds; int max_fdset; int next_fd; struct file ** fd; /* current fd array */ fd_set *close_on_exec; fd_set *open_fds; fd_set close_on_exec_init; fd_set open_fds_init; struct file * fd_array[NR_OPEN_DEFAULT];};#define INIT_FILES \{ \ count: ATOMIC_INIT(1), \ file_lock: RW_LOCK_UNLOCKED, \ max_fds: NR_OPEN_DEFAULT, \ max_fdset: __FD_SETSIZE, \ next_fd: 0, \ fd: &init_files.fd_array[0], \ close_on_exec: &init_files.close_on_exec_init, \ open_fds: &init_files.open_fds_init, \ close_on_exec_init: { { 0, } }, \ open_fds_init: { { 0, } }, \ fd_array: { NULL, } \}/* Maximum number of active map areas.. This is a random (large) number */#define DEFAULT_MAX_MAP_COUNT (65536)extern int max_map_count;struct mm_struct { struct vm_area_struct * mmap; /* list of VMAs */ rb_root_t mm_rb; struct vm_area_struct * mmap_cache; /* last find_vma result */ pgd_t * pgd; atomic_t mm_users; /* How many users with user space? */ atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */ int map_count; /* number of VMAs */ struct rw_semaphore mmap_sem; spinlock_t page_table_lock; /* Protects task page tables and mm->rss */ struct list_head mmlist; /* List of all active mm's. These are globally strung * together off init_mm.mmlist, and are protected * by mmlist_lock */ unsigned long start_code, end_code, start_data, end_data; unsigned long start_brk, brk, start_stack; unsigned long arg_start, arg_end, env_start, env_end; unsigned long rss, total_vm, locked_vm; unsigned long def_flags; unsigned long cpu_vm_mask; unsigned long swap_address; unsigned dumpable:1; /* Architecture-specific MM context */ mm_context_t context;};extern int mmlist_nr;#define INIT_MM(name) \{ \ mm_rb: RB_ROOT, \ pgd: swapper_pg_dir, \ mm_users: ATOMIC_INIT(2), \ mm_count: ATOMIC_INIT(1), \ mmap_sem: RWSEM_INITIALIZER(name.mmap_sem), \ page_table_lock: SPIN_LOCK_UNLOCKED, \ mmlist: LIST_HEAD_INIT(name.mmlist), \}struct signal_struct { atomic_t count; struct k_sigaction action[_NSIG]; spinlock_t siglock;};#define INIT_SIGNALS { \ count: ATOMIC_INIT(1), \ action: { {{0,}}, }, \ siglock: SPIN_LOCK_UNLOCKED \}/* * Some day this will be a full-fledged user tracking system.. */struct user_struct { atomic_t __count; /* reference count */ atomic_t processes; /* How many processes does this user have? */ atomic_t files; /* How many open files does this user have? */ /* Hash table maintenance information */ struct user_struct *next, **pprev; uid_t uid;};#define get_current_user() ({ \ struct user_struct *__user = current->user; \ atomic_inc(&__user->__count); \ __user; })extern struct user_struct root_user;#define INIT_USER (&root_user)typedef struct prio_array prio_array_t;struct zone_struct;struct local_pages { struct list_head list; unsigned int order, nr; struct zone_struct * classzone;};struct task_struct { /* * offsets of these are hardcoded elsewhere - touch with care */ volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ unsigned long flags; /* per process flags, defined below */ int sigpending; mm_segment_t addr_limit; /* thread address space: 0-0xBFFFFFFF for user-thead 0-0xFFFFFFFF for kernel-thread */ struct exec_domain *exec_domain; volatile long need_resched; unsigned long ptrace; int lock_depth; /* Lock depth */ /* * offset 32 begins here on 32-bit platforms. */ unsigned int cpu; int prio, static_prio; list_t run_list; prio_array_t *array; unsigned long sleep_avg; unsigned long sleep_timestamp; unsigned long policy; unsigned long cpus_allowed; unsigned int time_slice; int get_child_timeslice; task_t *next_task, *prev_task; struct mm_struct *mm, *active_mm; struct local_pages local_pages;/* task state */ struct linux_binfmt *binfmt; int exit_code, exit_signal; int pdeath_signal; /* The signal sent when the parent dies */ /* ??? */ unsigned long personality; int did_exec:1; pid_t pid; pid_t pgrp; pid_t tty_old_pgrp; pid_t session; pid_t tgid; /* boolean value for session group leader */ int leader; /* * pointers to (original) parent process, youngest child, younger sibling, * older sibling, respectively. (p->father can be replaced with * p->p_pptr->pid) */ task_t *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr; struct list_head thread_group; /* PID hash table linkage. */ task_t *pidhash_next; task_t **pidhash_pprev; wait_queue_head_t wait_chldexit; /* for wait4() */ struct completion *vfork_done; /* for vfork() */ unsigned long rt_priority; unsigned long it_real_value, it_prof_value, it_virt_value; unsigned long it_real_incr, it_prof_incr, it_virt_incr; struct timer_list real_timer; struct tms times; unsigned long start_time; long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS];/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap; int swappable:1;/* process credentials */ uid_t uid,euid,suid,fsuid; gid_t gid,egid,sgid,fsgid; int ngroups; gid_t groups[NGROUPS]; kernel_cap_t cap_effective, cap_inheritable, cap_permitted; int keep_capabilities:1; struct user_struct *user;/* limits */ struct rlimit rlim[RLIM_NLIMITS]; unsigned short used_math; char comm[16];/* file system info */ int link_count, total_link_count; struct tty_struct *tty; /* NULL if no tty */ unsigned int locks; /* How many file locks are being held *//* ipc stuff */ struct sem_undo *semundo; struct sem_queue *semsleeping;/* CPU-specific state of this task */ struct thread_struct thread;/* filesystem information */ struct fs_struct *fs;/* open file information */ struct files_struct *files;/* namespace */ struct namespace *namespace;/* signal handlers */ spinlock_t sigmask_lock; /* Protects signal and blocked */ struct signal_struct *sig; sigset_t blocked; struct sigpending pending; unsigned long sas_ss_sp; size_t sas_ss_size; int (*notifier)(void *priv); void *notifier_data; sigset_t *notifier_mask; /* TUX state */ void *tux_info; void (*tux_exit)(void); /* Thread group tracking */ u32 parent_exec_id; u32 self_exec_id;/* Protection of (de-)allocation: mm, files, fs, tty */ spinlock_t alloc_lock;/* journalling filesystem info */ void *journal_info;};/* * Per process flags */#define PF_EXITING (1UL<<0) /* getting shut down */#define PF_FORKNOEXEC (1UL<<1) /* forked but didn't exec */#define PF_SUPERPRIV (1UL<<2) /* used super-user privileges */#define PF_DUMPCORE (1UL<<3) /* dumped core */#define PF_SIGNALED (1UL<<4) /* killed by a signal */#define PF_MEMALLOC (1UL<<5) /* Allocating memory */#define PF_USEDFPU (1UL<<6) /* task used FPU this quantum (SMP) */#define PF_ATOMICALLOC (1UL<<7) /* do not block during memalloc */#define PF_FREE_PAGES (1UL<<8) /* per process page freeing */#define PF_NOIO (1UL<<9) /* avoid generating further I/O */#define PF_FSTRANS (1UL<<10) /* inside a filesystem transaction *//* * Ptrace flags */#define PT_PTRACED 0x00000001#define PT_TRACESYS 0x00000002#define PT_DTRACE 0x00000004 /* delayed trace (used on m68k, i386) */#define PT_TRACESYSGOOD 0x00000008#define PT_PTRACE_CAP 0x00000010 /* ptracer can follow suid-exec *//* * Limit the stack by to some sane default: root can always * increase this limit if needed.. 8MB seems reasonable. */#define _STK_LIM (8*1024*1024)#if CONFIG_SMPextern void set_cpus_allowed(task_t *p, unsigned long new_mask);#else#define set_cpus_allowed(p, new_mask) do { } while (0)#endifextern void set_user_nice(task_t *p, long nice);extern int task_prio(task_t *p);extern int task_nice(task_t *p);asmlinkage long sys_sched_yield(void);#define yield() sys_sched_yield()/* * The default (Linux) execution domain. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -