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

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