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

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