root/include/linux/sched.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. add_wait_queue
  2. remove_wait_queue
  3. select_wait
  4. down
  5. up

   1 #ifndef _LINUX_SCHED_H
   2 #define _LINUX_SCHED_H
   3 
   4 #include <linux/config.h>
   5 
   6 /*
   7  * define DEBUG if you want the wait-queues to have some extra
   8  * debugging code. It's not normally used, but might catch some
   9  * wait-queue coding errors.
  10  *
  11  *  #define DEBUG
  12  */
  13 
  14 #include <asm/param.h>  /* for HZ */
  15 
  16 extern unsigned long intr_count;
  17 extern unsigned long event;
  18 
  19 #include <linux/binfmts.h>
  20 #include <linux/personality.h>
  21 #include <linux/tasks.h>
  22 #include <linux/kernel.h>
  23 #include <asm/system.h>
  24 #include <asm/page.h>
  25 
  26 #include <linux/smp.h>
  27 
  28 /*
  29  * cloning flags:
  30  */
  31 #define CSIGNAL         0x000000ff      /* signal mask to be sent at exit */
  32 #define CLONE_VM        0x00000100      /* set if VM shared between processes */
  33 #define CLONE_FS        0x00000200      /* set if fs info shared between processes */
  34 #define CLONE_FILES     0x00000400      /* set if open files shared between processes */
  35 #define CLONE_SIGHAND   0x00000800      /* set if signal handlers shared */
  36 
  37 /*
  38  * These are the constant used to fake the fixed-point load-average
  39  * counting. Some notes:
  40  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
  41  *    a load-average precision of 10 bits integer + 11 bits fractional
  42  *  - if you want to count load-averages more often, you need more
  43  *    precision, or rounding will get you. With 2-second counting freq,
  44  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
  45  *    11 bit fractions.
  46  */
  47 extern unsigned long avenrun[];         /* Load averages */
  48 
  49 #define FSHIFT          11              /* nr of bits of precision */
  50 #define FIXED_1         (1<<FSHIFT)     /* 1.0 as fixed-point */
  51 #define LOAD_FREQ       (5*HZ)          /* 5 sec intervals */
  52 #define EXP_1           1884            /* 1/exp(5sec/1min) as fixed-point */
  53 #define EXP_5           2014            /* 1/exp(5sec/5min) */
  54 #define EXP_15          2037            /* 1/exp(5sec/15min) */
  55 
  56 #define CALC_LOAD(load,exp,n) \
  57         load *= exp; \
  58         load += n*(FIXED_1-exp); \
  59         load >>= FSHIFT;
  60 
  61 #define CT_TO_SECS(x)   ((x) / HZ)
  62 #define CT_TO_USECS(x)  (((x) % HZ) * 1000000/HZ)
  63 
  64 extern int nr_running, nr_tasks;
  65 
  66 #define FIRST_TASK task[0]
  67 #define LAST_TASK task[NR_TASKS-1]
  68 
  69 #include <linux/head.h>
  70 #include <linux/fs.h>
  71 #include <linux/signal.h>
  72 #include <linux/time.h>
  73 #include <linux/param.h>
  74 #include <linux/resource.h>
  75 #include <linux/vm86.h>
  76 #include <linux/math_emu.h>
  77 #include <linux/ptrace.h>
  78 #include <linux/timer.h>
  79 
  80 #include <asm/processor.h>
  81 
  82 #define TASK_RUNNING            0
  83 #define TASK_INTERRUPTIBLE      1
  84 #define TASK_UNINTERRUPTIBLE    2
  85 #define TASK_ZOMBIE             3
  86 #define TASK_STOPPED            4
  87 #define TASK_SWAPPING           5
  88 
  89 #ifndef NULL
  90 #define NULL ((void *) 0)
  91 #endif
  92 
  93 #ifdef __KERNEL__
  94 
  95 #define barrier() __asm__("": : :"memory")
  96 
  97 extern void sched_init(void);
  98 extern void show_state(void);
  99 extern void trap_init(void);
 100 
 101 asmlinkage void schedule(void);
 102 
 103 struct files_struct {
 104         int count;
 105         fd_set close_on_exec;
 106         struct file * fd[NR_OPEN];
 107 };
 108 
 109 #define INIT_FILES { \
 110         1, \
 111         { { 0, } }, \
 112         { NULL, } \
 113 }
 114 
 115 struct fs_struct {
 116         int count;
 117         unsigned short umask;
 118         struct inode * root, * pwd;
 119 };
 120 
 121 #define INIT_FS { \
 122         1, \
 123         0022, \
 124         NULL, NULL \
 125 }
 126 
 127 struct mm_struct {
 128         int count;
 129         pgd_t * pgd;
 130         unsigned long start_code, end_code, start_data, end_data;
 131         unsigned long start_brk, brk, start_stack, start_mmap;
 132         unsigned long arg_start, arg_end, env_start, env_end;
 133         unsigned long rss;
 134         struct vm_area_struct * mmap;
 135         struct vm_area_struct * mmap_avl;
 136 };
 137 
 138 #define INIT_MM { \
 139                 1, \
 140                 swapper_pg_dir, \
 141                 0, 0, 0, 0, \
 142                 0, 0, 0, 0, \
 143                 0, 0, 0, 0, \
 144                 0, \
 145                 &init_mmap, &init_mmap }
 146 
 147 struct signal_struct {
 148         int count;
 149         struct sigaction action[32];
 150 };
 151 
 152 #define INIT_SIGNALS { \
 153                 1, \
 154                 { {0,}, } }
 155 
 156 struct task_struct {
 157 /* these are hardcoded - don't touch */
 158         volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
 159         long counter;
 160         long priority;
 161         unsigned long signal;
 162         unsigned long blocked;  /* bitmap of masked signals */
 163         unsigned long flags;    /* per process flags, defined below */
 164         int errno;
 165         long debugreg[8];  /* Hardware debugging registers */
 166         struct exec_domain *exec_domain;
 167 /* various fields */
 168         struct linux_binfmt *binfmt;
 169         struct task_struct *next_task, *prev_task;
 170         struct task_struct *next_run,  *prev_run;
 171         unsigned long saved_kernel_stack;
 172         unsigned long kernel_stack_page;
 173         int exit_code, exit_signal;
 174         unsigned long personality;
 175         int dumpable:1;
 176         int did_exec:1;
 177         int pid,pgrp,tty_old_pgrp,session,leader;
 178         int     groups[NGROUPS];
 179         /* 
 180          * pointers to (original) parent process, youngest child, younger sibling,
 181          * older sibling, respectively.  (p->father can be replaced with 
 182          * p->p_pptr->pid)
 183          */
 184         struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
 185         struct wait_queue *wait_chldexit;       /* for wait4() */
 186         unsigned short uid,euid,suid,fsuid;
 187         unsigned short gid,egid,sgid,fsgid;
 188         unsigned long timeout;
 189         unsigned long it_real_value, it_prof_value, it_virt_value;
 190         unsigned long it_real_incr, it_prof_incr, it_virt_incr;
 191         struct timer_list real_timer;
 192         long utime, stime, cutime, cstime, start_time;
 193 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
 194         unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
 195         int swappable:1;
 196         unsigned long swap_address;
 197         unsigned long old_maj_flt;      /* old value of maj_flt */
 198         unsigned long dec_flt;          /* page fault count of the last time */
 199         unsigned long swap_cnt;         /* number of pages to swap on next pass */
 200 /* limits */
 201         struct rlimit rlim[RLIM_NLIMITS];
 202         unsigned short used_math;
 203         char comm[16];
 204 /* file system info */
 205         int link_count;
 206         struct tty_struct *tty; /* NULL if no tty */
 207 /* ipc stuff */
 208         struct sem_undo *semundo;
 209         struct sem_queue *semsleeping;
 210 /* ldt for this task - used by Wine.  If NULL, default_ldt is used */
 211         struct desc_struct *ldt;
 212 /* tss for this task */
 213         struct thread_struct tss;
 214 /* filesystem information */
 215         struct fs_struct *fs;
 216 /* open file information */
 217         struct files_struct *files;
 218 /* memory management info */
 219         struct mm_struct *mm;
 220 /* signal handlers */
 221         struct signal_struct *sig;
 222 #ifdef CONFIG_SMP
 223         int processor;
 224         int lock_depth;         /* Lock depth. We can context swithc in and out of holding a syscall kernel lock... */  
 225 #endif  
 226 };
 227 
 228 /*
 229  * Per process flags
 230  */
 231 #define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
 232                                         /* Not implemented yet, only for 486*/
 233 #define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
 234 #define PF_TRACESYS     0x00000020      /* tracing system calls */
 235 
 236 #define PF_STARTING     0x00000100      /* being created */
 237 #define PF_EXITING      0x00000200      /* getting shut down */
 238 
 239 #define PF_USEDFPU      0x00100000      /* Process used the FPU this quantum (SMP only) */
 240 
 241 /*
 242  * Limit the stack by to some sane default: root can always
 243  * increase this limit if needed..  8MB seems reasonable.
 244  */
 245 #define _STK_LIM        (8*1024*1024)
 246 
 247 /*
 248  *  INIT_TASK is used to set up the first task table, touch at
 249  * your own risk!. Base=0, limit=0x1fffff (=2MB)
 250  */
 251 #define INIT_TASK \
 252 /* state etc */ { 0,15*HZ/100,15*HZ/100,0,0,0,0, \
 253 /* debugregs */ { 0, },            \
 254 /* exec domain */&default_exec_domain, \
 255 /* binfmt */    NULL, \
 256 /* schedlink */ &init_task,&init_task, &init_task, &init_task, \
 257 /* stack */     0,(unsigned long) &init_kernel_stack, \
 258 /* ec,brk... */ 0,0,0,0,0, \
 259 /* pid etc.. */ 0,0,0,0,0, \
 260 /* suppl grps*/ {NOGROUP,}, \
 261 /* proc links*/ &init_task,&init_task,NULL,NULL,NULL,NULL, \
 262 /* uid etc */   0,0,0,0,0,0,0,0, \
 263 /* timeout */   0,0,0,0,0,0,0, \
 264 /* timer */     { NULL, NULL, 0, 0, it_real_fn }, \
 265 /* utime */     0,0,0,0,0, \
 266 /* flt */       0,0,0,0, \
 267 /* swp */       0,0,0,0,0, \
 268 /* rlimits */   { {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX},  \
 269                   {LONG_MAX, LONG_MAX}, {_STK_LIM, _STK_LIM},  \
 270                   {       0, LONG_MAX}, {LONG_MAX, LONG_MAX}, \
 271                   {MAX_TASKS_PER_USER, MAX_TASKS_PER_USER}, {NR_OPEN, NR_OPEN}}, \
 272 /* math */      0, \
 273 /* comm */      "swapper", \
 274 /* fs info */   0,NULL, \
 275 /* ipc */       NULL, NULL, \
 276 /* ldt */       NULL, \
 277 /* tss */       INIT_TSS, \
 278 /* fs */        &init_fs, \
 279 /* files */     &init_files, \
 280 /* mm */        &init_mm, \
 281 /* signals */   &init_signals, \
 282 }
 283 
 284 extern struct   mm_struct init_mm;
 285 extern struct task_struct init_task;
 286 extern struct task_struct *task[NR_TASKS];
 287 extern struct task_struct *last_task_used_math;
 288 extern struct task_struct *current_set[NR_CPUS];
 289 /*
 290  *      On a single processor system this comes out as current_set[0] when cpp
 291  *      has finished with it, which gcc will optimise away.
 292  */
 293 #define current (current_set[smp_processor_id()])       /* Current on this processor */
 294 extern unsigned long volatile jiffies;
 295 extern unsigned long itimer_ticks;
 296 extern unsigned long itimer_next;
 297 extern struct timeval xtime;
 298 extern int need_resched;
 299 extern void do_timer(struct pt_regs *);
 300 
 301 extern unsigned long * prof_buffer;
 302 extern unsigned long prof_len;
 303 extern unsigned long prof_shift;
 304 
 305 #define CURRENT_TIME (xtime.tv_sec)
 306 
 307 extern void sleep_on(struct wait_queue ** p);
 308 extern void interruptible_sleep_on(struct wait_queue ** p);
 309 extern void wake_up(struct wait_queue ** p);
 310 extern void wake_up_interruptible(struct wait_queue ** p);
 311 extern void wake_up_process(struct task_struct * tsk);
 312 
 313 extern void notify_parent(struct task_struct * tsk);
 314 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
 315 extern int in_group_p(gid_t grp);
 316 
 317 extern int request_irq(unsigned int irq,void (*handler)(int, struct pt_regs *),
 318         unsigned long flags, const char *device);
 319 extern void free_irq(unsigned int irq);
 320 
 321 extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
 322 extern void flush_thread(void);
 323 extern void exit_thread(void);
 324 
 325 extern void exit_fs(struct task_struct *);
 326 extern void exit_files(struct task_struct *);
 327 extern void exit_sighand(struct task_struct *);
 328 extern void release_thread(struct task_struct *);
 329 
 330 extern int do_execve(char *, char **, char **, struct pt_regs *);
 331 extern int do_fork(unsigned long, unsigned long, struct pt_regs *);
 332 
 333 /*
 334  * The wait-queues are circular lists, and you have to be *very* sure
 335  * to keep them correct. Use only these two functions to add/remove
 336  * entries in the queues.
 337  */
 338 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 339 {
 340         unsigned long flags;
 341 
 342 #ifdef DEBUG
 343         if (wait->next) {
 344                 __label__ here;
 345                 unsigned long pc;
 346                 pc = (unsigned long) &&here;
 347               here:
 348                 printk("add_wait_queue (%08lx): wait->next = %08lx\n",pc,(unsigned long) wait->next);
 349         }
 350 #endif
 351         save_flags(flags);
 352         cli();
 353         if (!*p) {
 354                 wait->next = wait;
 355                 *p = wait;
 356         } else {
 357                 wait->next = (*p)->next;
 358                 (*p)->next = wait;
 359         }
 360         restore_flags(flags);
 361 }
 362 
 363 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 364 {
 365         unsigned long flags;
 366         struct wait_queue * tmp;
 367 #ifdef DEBUG
 368         unsigned long ok = 0;
 369 #endif
 370 
 371         save_flags(flags);
 372         cli();
 373         if ((*p == wait) &&
 374 #ifdef DEBUG
 375             (ok = 1) &&
 376 #endif
 377             ((*p = wait->next) == wait)) {
 378                 *p = NULL;
 379         } else {
 380                 tmp = wait;
 381                 while (tmp->next != wait) {
 382                         tmp = tmp->next;
 383 #ifdef DEBUG
 384                         if (tmp == *p)
 385                                 ok = 1;
 386 #endif
 387                 }
 388                 tmp->next = wait->next;
 389         }
 390         wait->next = NULL;
 391         restore_flags(flags);
 392 #ifdef DEBUG
 393         if (!ok) {
 394                 __label__ here;
 395                 ok = (unsigned long) &&here;
 396                 printk("removed wait_queue not on list.\n");
 397                 printk("list = %08lx, queue = %08lx\n",(unsigned long) p, (unsigned long) wait);
 398               here:
 399                 printk("eip = %08lx\n",ok);
 400         }
 401 #endif
 402 }
 403 
 404 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 405 {
 406         struct select_table_entry * entry;
 407 
 408         if (!p || !wait_address)
 409                 return;
 410         if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
 411                 return;
 412         entry = p->entry + p->nr;
 413         entry->wait_address = wait_address;
 414         entry->wait.task = current;
 415         entry->wait.next = NULL;
 416         add_wait_queue(wait_address,&entry->wait);
 417         p->nr++;
 418 }
 419 
 420 extern void __down(struct semaphore * sem);
 421 
 422 /*
 423  * These are not yet interrupt-safe
 424  */
 425 extern inline void down(struct semaphore * sem)
     /* [previous][next][first][last][top][bottom][index][help] */
 426 {
 427         if (sem->count <= 0)
 428                 __down(sem);
 429         sem->count--;
 430 }
 431 
 432 extern inline void up(struct semaphore * sem)
     /* [previous][next][first][last][top][bottom][index][help] */
 433 {
 434         sem->count++;
 435         wake_up(&sem->wait);
 436 }       
 437 
 438 #define REMOVE_LINKS(p) do { unsigned long flags; \
 439         save_flags(flags) ; cli(); \
 440         (p)->next_task->prev_task = (p)->prev_task; \
 441         (p)->prev_task->next_task = (p)->next_task; \
 442         restore_flags(flags); \
 443         if ((p)->p_osptr) \
 444                 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
 445         if ((p)->p_ysptr) \
 446                 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
 447         else \
 448                 (p)->p_pptr->p_cptr = (p)->p_osptr; \
 449         } while (0)
 450 
 451 #define SET_LINKS(p) do { unsigned long flags; \
 452         save_flags(flags); cli(); \
 453         (p)->next_task = &init_task; \
 454         (p)->prev_task = init_task.prev_task; \
 455         init_task.prev_task->next_task = (p); \
 456         init_task.prev_task = (p); \
 457         restore_flags(flags); \
 458         (p)->p_ysptr = NULL; \
 459         if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
 460                 (p)->p_osptr->p_ysptr = p; \
 461         (p)->p_pptr->p_cptr = p; \
 462         } while (0)
 463 
 464 #define for_each_task(p) \
 465         for (p = &init_task ; (p = p->next_task) != &init_task ; )
 466 
 467 #endif /* __KERNEL__ */
 468 
 469 #endif

/* [previous][next][first][last][top][bottom][index][help] */