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
  6. _get_base
  7. get_limit

   1 #ifndef _LINUX_SCHED_H
   2 #define _LINUX_SCHED_H
   3 
   4 #define NEW_SWAP
   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 #define HZ 100
  15 
  16 /*
  17  * System setup flags..
  18  */
  19 extern int hard_math;
  20 extern int x86;
  21 extern int ignore_irq13;
  22 extern int wp_works_ok;
  23 
  24 /*
  25  * Bus types (default is ISA, but people can check others with these..)
  26  * MCA_bus hardcoded to 0 for now.
  27  */
  28 extern int EISA_bus;
  29 #define MCA_bus 0
  30 
  31 #include <linux/tasks.h>
  32 #include <asm/system.h>
  33 
  34 /*
  35  * User space process size: 3GB. This is hardcoded into a few places,
  36  * so don't change it unless you know what you are doing.
  37  */
  38 #define TASK_SIZE       0xc0000000
  39 
  40 /*
  41  * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
  42  */
  43 #define IO_BITMAP_SIZE  32
  44 
  45 /*
  46  * These are the constant used to fake the fixed-point load-average
  47  * counting. Some notes:
  48  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
  49  *    a load-average precision of 10 bits integer + 11 bits fractional
  50  *  - if you want to count load-averages more often, you need more
  51  *    precision, or rounding will get you. With 2-second counting freq,
  52  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
  53  *    11 bit fractions.
  54  */
  55 extern unsigned long avenrun[];         /* Load averages */
  56 
  57 #define FSHIFT          11              /* nr of bits of precision */
  58 #define FIXED_1         (1<<FSHIFT)     /* 1.0 as fixed-point */
  59 #define LOAD_FREQ       (5*HZ)          /* 5 sec intervals */
  60 #define EXP_1           1884            /* 1/exp(5sec/1min) as fixed-point */
  61 #define EXP_5           2014            /* 1/exp(5sec/5min) */
  62 #define EXP_15          2037            /* 1/exp(5sec/15min) */
  63 
  64 #define CALC_LOAD(load,exp,n) \
  65         load *= exp; \
  66         load += n*(FIXED_1-exp); \
  67         load >>= FSHIFT;
  68 
  69 #define CT_TO_SECS(x)   ((x) / HZ)
  70 #define CT_TO_USECS(x)  (((x) % HZ) * 1000000/HZ)
  71 
  72 #define FIRST_TASK task[0]
  73 #define LAST_TASK task[NR_TASKS-1]
  74 
  75 #include <linux/head.h>
  76 #include <linux/fs.h>
  77 #include <linux/mm.h>
  78 #include <linux/signal.h>
  79 #include <linux/time.h>
  80 #include <linux/param.h>
  81 #include <linux/resource.h>
  82 #include <linux/vm86.h>
  83 #include <linux/math_emu.h>
  84 
  85 #define TASK_RUNNING            0
  86 #define TASK_INTERRUPTIBLE      1
  87 #define TASK_UNINTERRUPTIBLE    2
  88 #define TASK_ZOMBIE             3
  89 #define TASK_STOPPED            4
  90 #define TASK_SWAPPING           5
  91 
  92 #ifndef NULL
  93 #define NULL ((void *) 0)
  94 #endif
  95 
  96 #ifdef __KERNEL__
  97 
  98 extern void sched_init(void);
  99 extern void show_state(void);
 100 extern void trap_init(void);
 101 
 102 asmlinkage void schedule(void);
 103 
 104 #endif /* __KERNEL__ */
 105 
 106 struct i387_hard_struct {
 107         long    cwd;
 108         long    swd;
 109         long    twd;
 110         long    fip;
 111         long    fcs;
 112         long    foo;
 113         long    fos;
 114         long    st_space[20];   /* 8*10 bytes for each FP-reg = 80 bytes */
 115 };
 116 
 117 struct i387_soft_struct {
 118         long    cwd;
 119         long    swd;
 120         long    twd;
 121         long    fip;
 122         long    fcs;
 123         long    foo;
 124         long    fos;
 125         long    top;
 126         struct fpu_reg  regs[8];        /* 8*16 bytes for each FP-reg = 128 bytes */
 127         unsigned char   lookahead;
 128         struct info     *info;
 129         unsigned long   entry_eip;
 130 };
 131 
 132 union i387_union {
 133         struct i387_hard_struct hard;
 134         struct i387_soft_struct soft;
 135 };
 136 
 137 struct tss_struct {
 138         unsigned short  back_link,__blh;
 139         unsigned long   esp0;
 140         unsigned short  ss0,__ss0h;
 141         unsigned long   esp1;
 142         unsigned short  ss1,__ss1h;
 143         unsigned long   esp2;
 144         unsigned short  ss2,__ss2h;
 145         unsigned long   cr3;
 146         unsigned long   eip;
 147         unsigned long   eflags;
 148         unsigned long   eax,ecx,edx,ebx;
 149         unsigned long   esp;
 150         unsigned long   ebp;
 151         unsigned long   esi;
 152         unsigned long   edi;
 153         unsigned short  es, __esh;
 154         unsigned short  cs, __csh;
 155         unsigned short  ss, __ssh;
 156         unsigned short  ds, __dsh;
 157         unsigned short  fs, __fsh;
 158         unsigned short  gs, __gsh;
 159         unsigned short  ldt, __ldth;
 160         unsigned short  trace, bitmap;
 161         unsigned long   io_bitmap[IO_BITMAP_SIZE+1];
 162         unsigned long   tr;
 163         unsigned long   cr2, trap_no, error_code;
 164         union i387_union i387;
 165 };
 166 
 167 struct task_struct {
 168 /* these are hardcoded - don't touch */
 169         volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
 170         long counter;
 171         long priority;
 172         unsigned long signal;
 173         unsigned long blocked;  /* bitmap of masked signals */
 174         unsigned long flags;    /* per process flags, defined below */
 175         int errno;
 176         int debugreg[8];  /* Hardware debugging registers */
 177 /* various fields */
 178         struct task_struct *next_task, *prev_task;
 179         struct sigaction sigaction[32];
 180         unsigned long saved_kernel_stack;
 181         unsigned long kernel_stack_page;
 182         int exit_code, exit_signal;
 183         int elf_executable:1;
 184         int dumpable:1;
 185         int swappable:1;
 186         int did_exec:1;
 187         unsigned long start_code,end_code,end_data,start_brk,brk,start_stack,start_mmap;
 188         unsigned long arg_start, arg_end, env_start, env_end;
 189         int pid,pgrp,session,leader;
 190         int     groups[NGROUPS];
 191         /* 
 192          * pointers to (original) parent process, youngest child, younger sibling,
 193          * older sibling, respectively.  (p->father can be replaced with 
 194          * p->p_pptr->pid)
 195          */
 196         struct task_struct *p_opptr,*p_pptr, *p_cptr, *p_ysptr, *p_osptr;
 197         struct wait_queue *wait_chldexit;       /* for wait4() */
 198         /*
 199          * For ease of programming... Normal sleeps don't need to
 200          * keep track of a wait-queue: every task has an entry of its own
 201          */
 202         unsigned short uid,euid,suid;
 203         unsigned short gid,egid,sgid;
 204         unsigned long timeout;
 205         unsigned long it_real_value, it_prof_value, it_virt_value;
 206         unsigned long it_real_incr, it_prof_incr, it_virt_incr;
 207         long utime,stime,cutime,cstime,start_time;
 208         unsigned long min_flt, maj_flt;
 209         unsigned long cmin_flt, cmaj_flt;
 210         struct rlimit rlim[RLIM_NLIMITS]; 
 211         unsigned short used_math;
 212         unsigned short rss;     /* number of resident pages */
 213         char comm[16];
 214         struct vm86_struct * vm86_info;
 215         unsigned long screen_bitmap;
 216 /* file system info */
 217         int link_count;
 218         int tty;                /* -1 if no tty, so it must be signed */
 219         unsigned short umask;
 220         struct inode * pwd;
 221         struct inode * root;
 222         struct inode * executable;
 223         struct vm_area_struct * mmap;
 224         struct shm_desc *shm;
 225         struct sem_undo *semun;
 226         struct file * filp[NR_OPEN];
 227         fd_set close_on_exec;
 228 /* ldt for this task - used by Wine.  If NULL, default_ldt is used */
 229         struct desc_struct *ldt;
 230 /* tss for this task */
 231         struct tss_struct tss;
 232 #ifdef NEW_SWAP
 233         unsigned long old_maj_flt;      /* old value of maj_flt */
 234         unsigned long dec_flt;          /* page fault count of the last time */
 235         unsigned long swap_cnt;         /* number of pages to swap on next pass */
 236         short swap_table;               /* current page table */
 237         short swap_page;                /* current page */
 238 #endif NEW_SWAP
 239         struct vm_area_struct *stk_vma;
 240 };
 241 
 242 /*
 243  * Per process flags
 244  */
 245 #define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
 246                                         /* Not implemented yet, only for 486*/
 247 #define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
 248 #define PF_TRACESYS     0x00000020      /* tracing system calls */
 249 
 250 /*
 251  * cloning flags:
 252  */
 253 #define CSIGNAL         0x000000ff      /* signal mask to be sent at exit */
 254 #define COPYVM          0x00000100      /* set if VM copy desired (like normal fork()) */
 255 #define COPYFD          0x00000200      /* set if fd's should be copied, not shared (NI) */
 256 
 257 /*
 258  *  INIT_TASK is used to set up the first task table, touch at
 259  * your own risk!. Base=0, limit=0x1fffff (=2MB)
 260  */
 261 #define INIT_TASK \
 262 /* state etc */ { 0,15,15,0,0,0,0, \
 263 /* debugregs */ { 0, },            \
 264 /* schedlink */ &init_task,&init_task, \
 265 /* signals */   {{ 0, },}, \
 266 /* stack */     0,(unsigned long) &init_kernel_stack, \
 267 /* ec,brk... */ 0,0,0,0,0,0,0,0,0,0,0,0,0, \
 268 /* argv.. */    0,0,0,0, \
 269 /* pid etc.. */ 0,0,0,0, \
 270 /* suppl grps*/ {NOGROUP,}, \
 271 /* proc links*/ &init_task,&init_task,NULL,NULL,NULL,NULL, \
 272 /* uid etc */   0,0,0,0,0,0, \
 273 /* timeout */   0,0,0,0,0,0,0,0,0,0,0,0, \
 274 /* min_flt */   0,0,0,0, \
 275 /* rlimits */   { {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX},  \
 276                   {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX},  \
 277                   {       0, LONG_MAX}, {LONG_MAX, LONG_MAX}}, \
 278 /* math */      0, \
 279 /* rss */       2, \
 280 /* comm */      "swapper", \
 281 /* vm86_info */ NULL, 0, \
 282 /* fs info */   0,-1,0022,NULL,NULL,NULL,NULL, \
 283 /* ipc */       NULL, NULL, \
 284 /* filp */      {NULL,}, \
 285 /* cloe */      {{ 0, }}, \
 286 /* ldt */       NULL, \
 287 /*tss*/ {0,0, \
 288          sizeof(init_kernel_stack) + (long) &init_kernel_stack, KERNEL_DS, 0, \
 289          0,0,0,0,0,0, \
 290          (long) &swapper_pg_dir, \
 291          0,0,0,0,0,0,0,0,0,0, \
 292          USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0, \
 293          _LDT(0),0, \
 294          0, 0x8000, \
 295 /* ioperm */    {~0, }, \
 296          _TSS(0), 0, 0,0, \
 297 /* 387 state */ { { 0, }, } \
 298         } \
 299 }
 300 
 301 extern struct task_struct init_task;
 302 extern struct task_struct *task[NR_TASKS];
 303 extern struct task_struct *last_task_used_math;
 304 extern struct task_struct *current;
 305 extern unsigned long volatile jiffies;
 306 extern unsigned long itimer_ticks;
 307 extern unsigned long itimer_next;
 308 extern struct timeval xtime;
 309 extern int need_resched;
 310 
 311 #define CURRENT_TIME (xtime.tv_sec)
 312 
 313 extern void sleep_on(struct wait_queue ** p);
 314 extern void interruptible_sleep_on(struct wait_queue ** p);
 315 extern void wake_up(struct wait_queue ** p);
 316 extern void wake_up_interruptible(struct wait_queue ** p);
 317 
 318 extern void notify_parent(struct task_struct * tsk);
 319 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
 320 extern int in_group_p(gid_t grp);
 321 
 322 extern int request_irq(unsigned int irq,void (*handler)(int));
 323 extern void free_irq(unsigned int irq);
 324 extern int irqaction(unsigned int irq,struct sigaction * sa);
 325 
 326 /*
 327  * Entry into gdt where to find first TSS. GDT layout:
 328  *   0 - nul
 329  *   1 - kernel code segment
 330  *   2 - kernel data segment
 331  *   3 - user code segment
 332  *   4 - user data segment
 333  * ...
 334  *   8 - TSS #0
 335  *   9 - LDT #0
 336  *  10 - TSS #1
 337  *  11 - LDT #1
 338  */
 339 #define FIRST_TSS_ENTRY 8
 340 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
 341 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
 342 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
 343 #define load_TR(n) __asm__("ltr %%ax": /* no output */ :"a" (_TSS(n)))
 344 #define load_ldt(n) __asm__("lldt %%ax": /* no output */ :"a" (_LDT(n)))
 345 #define store_TR(n) \
 346 __asm__("str %%ax\n\t" \
 347         "subl %2,%%eax\n\t" \
 348         "shrl $4,%%eax" \
 349         :"=a" (n) \
 350         :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
 351 /*
 352  *      switch_to(n) should switch tasks to task nr n, first
 353  * checking that n isn't the current task, in which case it does nothing.
 354  * This also clears the TS-flag if the task we switched to has used
 355  * tha math co-processor latest.
 356  */
 357 #define switch_to(tsk) \
 358 __asm__("cmpl %%ecx,_current\n\t" \
 359         "je 1f\n\t" \
 360         "cli\n\t" \
 361         "xchgl %%ecx,_current\n\t" \
 362         "ljmp %0\n\t" \
 363         "sti\n\t" \
 364         "cmpl %%ecx,_last_task_used_math\n\t" \
 365         "jne 1f\n\t" \
 366         "clts\n" \
 367         "1:" \
 368         : /* no output */ \
 369         :"m" (*(((char *)&tsk->tss.tr)-4)), \
 370          "c" (tsk) \
 371         :"cx")
 372 
 373 #define _set_base(addr,base) \
 374 __asm__("movw %%dx,%0\n\t" \
 375         "rorl $16,%%edx\n\t" \
 376         "movb %%dl,%1\n\t" \
 377         "movb %%dh,%2" \
 378         : /* no output */ \
 379         :"m" (*((addr)+2)), \
 380          "m" (*((addr)+4)), \
 381          "m" (*((addr)+7)), \
 382          "d" (base) \
 383         :"dx")
 384 
 385 #define _set_limit(addr,limit) \
 386 __asm__("movw %%dx,%0\n\t" \
 387         "rorl $16,%%edx\n\t" \
 388         "movb %1,%%dh\n\t" \
 389         "andb $0xf0,%%dh\n\t" \
 390         "orb %%dh,%%dl\n\t" \
 391         "movb %%dl,%1" \
 392         : /* no output */ \
 393         :"m" (*(addr)), \
 394          "m" (*((addr)+6)), \
 395          "d" (limit) \
 396         :"dx")
 397 
 398 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
 399 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
 400 
 401 /*
 402  * The wait-queues are circular lists, and you have to be *very* sure
 403  * to keep them correct. Use only these two functions to add/remove
 404  * entries in the queues.
 405  */
 406 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 407 {
 408         unsigned long flags;
 409 
 410 #ifdef DEBUG
 411         if (wait->next) {
 412                 unsigned long pc;
 413                 __asm__ __volatile__("call 1f\n"
 414                         "1:\tpopl %0":"=r" (pc));
 415                 printk("add_wait_queue (%08x): wait->next = %08x\n",pc,(unsigned long) wait->next);
 416         }
 417 #endif
 418         save_flags(flags);
 419         cli();
 420         if (!*p) {
 421                 wait->next = wait;
 422                 *p = wait;
 423         } else {
 424                 wait->next = (*p)->next;
 425                 (*p)->next = wait;
 426         }
 427         restore_flags(flags);
 428 }
 429 
 430 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 431 {
 432         unsigned long flags;
 433         struct wait_queue * tmp;
 434 #ifdef DEBUG
 435         unsigned long ok = 0;
 436 #endif
 437 
 438         save_flags(flags);
 439         cli();
 440         if ((*p == wait) &&
 441 #ifdef DEBUG
 442             (ok = 1) &&
 443 #endif
 444             ((*p = wait->next) == wait)) {
 445                 *p = NULL;
 446         } else {
 447                 tmp = wait;
 448                 while (tmp->next != wait) {
 449                         tmp = tmp->next;
 450 #ifdef DEBUG
 451                         if (tmp == *p)
 452                                 ok = 1;
 453 #endif
 454                 }
 455                 tmp->next = wait->next;
 456         }
 457         wait->next = NULL;
 458         restore_flags(flags);
 459 #ifdef DEBUG
 460         if (!ok) {
 461                 printk("removed wait_queue not on list.\n");
 462                 printk("list = %08x, queue = %08x\n",(unsigned long) p, (unsigned long) wait);
 463                 __asm__("call 1f\n1:\tpopl %0":"=r" (ok));
 464                 printk("eip = %08x\n",ok);
 465         }
 466 #endif
 467 }
 468 
 469 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 470 {
 471         struct select_table_entry * entry;
 472 
 473         if (!p || !wait_address)
 474                 return;
 475         if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
 476                 return;
 477         entry = p->entry + p->nr;
 478         entry->wait_address = wait_address;
 479         entry->wait.task = current;
 480         entry->wait.next = NULL;
 481         add_wait_queue(wait_address,&entry->wait);
 482         p->nr++;
 483 }
 484 
 485 extern void __down(struct semaphore * sem);
 486 
 487 extern inline void down(struct semaphore * sem)
     /* [previous][next][first][last][top][bottom][index][help] */
 488 {
 489         if (sem->count <= 0)
 490                 __down(sem);
 491         sem->count--;
 492 }
 493 
 494 extern inline void up(struct semaphore * sem)
     /* [previous][next][first][last][top][bottom][index][help] */
 495 {
 496         sem->count++;
 497         wake_up(&sem->wait);
 498 }       
 499 
 500 static inline unsigned long _get_base(char * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 501 {
 502         unsigned long __base;
 503         __asm__("movb %3,%%dh\n\t"
 504                 "movb %2,%%dl\n\t"
 505                 "shll $16,%%edx\n\t"
 506                 "movw %1,%%dx"
 507                 :"=&d" (__base)
 508                 :"m" (*((addr)+2)),
 509                  "m" (*((addr)+4)),
 510                  "m" (*((addr)+7)));
 511         return __base;
 512 }
 513 
 514 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
 515 
 516 static inline unsigned long get_limit(unsigned long segment)
     /* [previous][next][first][last][top][bottom][index][help] */
 517 {
 518         unsigned long __limit;
 519         __asm__("lsll %1,%0"
 520                 :"=r" (__limit):"r" (segment));
 521         return __limit+1;
 522 }
 523 
 524 #define REMOVE_LINKS(p) do { unsigned long flags; \
 525         save_flags(flags) ; cli(); \
 526         (p)->next_task->prev_task = (p)->prev_task; \
 527         (p)->prev_task->next_task = (p)->next_task; \
 528         restore_flags(flags); \
 529         if ((p)->p_osptr) \
 530                 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
 531         if ((p)->p_ysptr) \
 532                 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
 533         else \
 534                 (p)->p_pptr->p_cptr = (p)->p_osptr; \
 535         } while (0)
 536 
 537 #define SET_LINKS(p) do { unsigned long flags; \
 538         save_flags(flags); cli(); \
 539         (p)->next_task = &init_task; \
 540         (p)->prev_task = init_task.prev_task; \
 541         init_task.prev_task->next_task = (p); \
 542         init_task.prev_task = (p); \
 543         restore_flags(flags); \
 544         (p)->p_ysptr = NULL; \
 545         if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
 546                 (p)->p_osptr->p_ysptr = p; \
 547         (p)->p_pptr->p_cptr = p; \
 548         } while (0)
 549 
 550 #define for_each_task(p) \
 551         for (p = &init_task ; (p = p->next_task) != &init_task ; )
 552 
 553 /*
 554  * This is the ldt that every process will get unless we need
 555  * something other than this.
 556  */
 557 extern struct desc_struct default_ldt;
 558 
 559 /* This special macro can be used to load a debugging register */
 560 
 561 #define loaddebug(register) \
 562                 __asm__("movl %0,%%edx\n\t" \
 563                         "movl %%edx,%%db" #register "\n\t" \
 564                         : /* no output */ \
 565                         :"m" (current->debugreg[register]) \
 566                         :"dx");
 567 
 568 #endif

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