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

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