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

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