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

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