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

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