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 extern void panic(const char * fmt, ...)
  87         __attribute__ ((format (printf, 1, 2)));
  88 
  89 asmlinkage void schedule(void);
  90 
  91 #endif /* __KERNEL__ */
  92 
  93 struct i387_hard_struct {
  94         long    cwd;
  95         long    swd;
  96         long    twd;
  97         long    fip;
  98         long    fcs;
  99         long    foo;
 100         long    fos;
 101         long    st_space[20];   /* 8*10 bytes for each FP-reg = 80 bytes */
 102 };
 103 
 104 struct i387_soft_struct {
 105         long    cwd;
 106         long    swd;
 107         long    twd;
 108         long    fip;
 109         long    fcs;
 110         long    foo;
 111         long    fos;
 112         long    top;
 113         struct fpu_reg  regs[8];        /* 8*16 bytes for each FP-reg = 128 bytes */
 114         unsigned char   lookahead;
 115         struct info     *info;
 116         unsigned long   entry_eip;
 117 };
 118 
 119 union i387_union {
 120         struct i387_hard_struct hard;
 121         struct i387_soft_struct soft;
 122 };
 123 
 124 struct tss_struct {
 125         unsigned short  back_link,__blh;
 126         unsigned long   esp0;
 127         unsigned short  ss0,__ss0h;
 128         unsigned long   esp1;
 129         unsigned short  ss1,__ss1h;
 130         unsigned long   esp2;
 131         unsigned short  ss2,__ss2h;
 132         unsigned long   cr3;
 133         unsigned long   eip;
 134         unsigned long   eflags;
 135         unsigned long   eax,ecx,edx,ebx;
 136         unsigned long   esp;
 137         unsigned long   ebp;
 138         unsigned long   esi;
 139         unsigned long   edi;
 140         unsigned short  es, __esh;
 141         unsigned short  cs, __csh;
 142         unsigned short  ss, __ssh;
 143         unsigned short  ds, __dsh;
 144         unsigned short  fs, __fsh;
 145         unsigned short  gs, __gsh;
 146         unsigned short  ldt, __ldth;
 147         unsigned short  trace, bitmap;
 148         unsigned long   io_bitmap[IO_BITMAP_SIZE+1];
 149         unsigned long   tr;
 150         union i387_union i387;
 151 };
 152 
 153 struct task_struct {
 154 /* these are hardcoded - don't touch */
 155         long state;             /* -1 unrunnable, 0 runnable, >0 stopped */
 156         long counter;
 157         long priority;
 158         unsigned long signal;
 159         unsigned long blocked;  /* bitmap of masked signals */
 160         unsigned long flags;    /* per process flags, defined below */
 161         int errno;
 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         long 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 it's 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 };
 224 
 225 /*
 226  * Per process flags
 227  */
 228 #define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
 229                                         /* Not implemented yet, only for 486*/
 230 #define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
 231 #define PF_TRACESYS     0x00000020      /* tracing system calls */
 232 
 233 /*
 234  * cloning flags:
 235  */
 236 #define CSIGNAL         0x000000ff      /* signal mask to be sent at exit */
 237 #define COPYVM          0x00000100      /* set if VM copy desired (like normal fork()) */
 238 #define COPYFD          0x00000200      /* set if fd's should be copied, not shared (NI) */
 239 
 240 /*
 241  *  INIT_TASK is used to set up the first task table, touch at
 242  * your own risk!. Base=0, limit=0x1fffff (=2MB)
 243  */
 244 #define INIT_TASK \
 245 /* state etc */ { 0,15,15,0,0,0,0, \
 246 /* schedlink */ &init_task,&init_task, \
 247 /* signals */   {{ 0, },}, \
 248 /* stack */     0,0, \
 249 /* ec,brk... */ 0,0,0,0,0,0,0,0,0,0,0,0, \
 250 /* argv.. */    0,0,0,0, \
 251 /* pid etc.. */ 0,0,0,0, \
 252 /* suppl grps*/ {NOGROUP,}, \
 253 /* proc links*/ &init_task,&init_task,NULL,NULL,NULL,NULL, \
 254 /* uid etc */   0,0,0,0,0,0, \
 255 /* timeout */   0,0,0,0,0,0,0,0,0,0,0,0, \
 256 /* min_flt */   0,0,0,0, \
 257 /* rlimits */   { {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX},  \
 258                   {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX},  \
 259                   {       0, LONG_MAX}, {LONG_MAX, LONG_MAX}}, \
 260 /* math */      0, \
 261 /* rss */       2, \
 262 /* comm */      "swapper", \
 263 /* vm86_info */ NULL, 0, \
 264 /* fs info */   0,-1,0022,NULL,NULL,NULL,NULL, \
 265 /* ipc */       NULL, NULL, \
 266 /* filp */      {NULL,}, \
 267 /* cloe */      {{ 0, }}, \
 268 /* ldt */       NULL, \
 269 /*tss*/ {0,0, \
 270          sizeof(init_kernel_stack) + (long) &init_kernel_stack, KERNEL_DS, 0, \
 271          0,0,0,0,0,0, \
 272          (long) &swapper_pg_dir, \
 273          0,0,0,0,0,0,0,0,0,0, \
 274          USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0, \
 275          _LDT(0),0, \
 276          0, 0x8000, \
 277 /* ioperm */    {~0, }, \
 278          _TSS(0), \
 279 /* 387 state */ { { 0, }, } \
 280         } \
 281 }
 282 
 283 extern struct task_struct init_task;
 284 extern struct task_struct *task[NR_TASKS];
 285 extern struct task_struct *last_task_used_math;
 286 extern struct task_struct *current;
 287 extern unsigned long volatile jiffies;
 288 extern unsigned long startup_time;
 289 extern int jiffies_offset;
 290 extern int need_resched;
 291 
 292 extern int hard_math;
 293 extern int x86;
 294 extern int ignore_irq13;
 295 extern int wp_works_ok;
 296 
 297 #define CURRENT_TIME (startup_time+(jiffies+jiffies_offset)/HZ)
 298 
 299 extern void sleep_on(struct wait_queue ** p);
 300 extern void interruptible_sleep_on(struct wait_queue ** p);
 301 extern void wake_up(struct wait_queue ** p);
 302 extern void wake_up_interruptible(struct wait_queue ** p);
 303 
 304 extern void notify_parent(struct task_struct * tsk);
 305 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
 306 extern int in_group_p(gid_t grp);
 307 
 308 extern int request_irq(unsigned int irq,void (*handler)(int));
 309 extern void free_irq(unsigned int irq);
 310 extern int irqaction(unsigned int irq,struct sigaction * sa);
 311 
 312 /*
 313  * Entry into gdt where to find first TSS. GDT layout:
 314  *   0 - nul
 315  *   1 - kernel code segment
 316  *   2 - kernel data segment
 317  *   3 - user code segment
 318  *   4 - user data segment
 319  * ...
 320  *   8 - TSS #0
 321  *   9 - LDT #0
 322  *  10 - TSS #1
 323  *  11 - LDT #1
 324  */
 325 #define FIRST_TSS_ENTRY 8
 326 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
 327 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
 328 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
 329 #define load_TR(n) __asm__("ltr %%ax": /* no output */ :"a" (_TSS(n)))
 330 #define load_ldt(n) __asm__("lldt %%ax": /* no output */ :"a" (_LDT(n)))
 331 #define store_TR(n) \
 332 __asm__("str %%ax\n\t" \
 333         "subl %2,%%eax\n\t" \
 334         "shrl $4,%%eax" \
 335         :"=a" (n) \
 336         :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
 337 /*
 338  *      switch_to(n) should switch tasks to task nr n, first
 339  * checking that n isn't the current task, in which case it does nothing.
 340  * This also clears the TS-flag if the task we switched to has used
 341  * tha math co-processor latest.
 342  */
 343 #define switch_to(tsk) \
 344 __asm__("cmpl %%ecx,_current\n\t" \
 345         "je 1f\n\t" \
 346         "cli\n\t" \
 347         "xchgl %%ecx,_current\n\t" \
 348         "ljmp %0\n\t" \
 349         "sti\n\t" \
 350         "cmpl %%ecx,_last_task_used_math\n\t" \
 351         "jne 1f\n\t" \
 352         "clts\n" \
 353         "1:" \
 354         : /* no output */ \
 355         :"m" (*(((char *)&tsk->tss.tr)-4)), \
 356          "c" (tsk) \
 357         :"cx")
 358 
 359 #define _set_base(addr,base) \
 360 __asm__("movw %%dx,%0\n\t" \
 361         "rorl $16,%%edx\n\t" \
 362         "movb %%dl,%1\n\t" \
 363         "movb %%dh,%2" \
 364         : /* no output */ \
 365         :"m" (*((addr)+2)), \
 366          "m" (*((addr)+4)), \
 367          "m" (*((addr)+7)), \
 368          "d" (base) \
 369         :"dx")
 370 
 371 #define _set_limit(addr,limit) \
 372 __asm__("movw %%dx,%0\n\t" \
 373         "rorl $16,%%edx\n\t" \
 374         "movb %1,%%dh\n\t" \
 375         "andb $0xf0,%%dh\n\t" \
 376         "orb %%dh,%%dl\n\t" \
 377         "movb %%dl,%1" \
 378         : /* no output */ \
 379         :"m" (*(addr)), \
 380          "m" (*((addr)+6)), \
 381          "d" (limit) \
 382         :"dx")
 383 
 384 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
 385 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
 386 
 387 /*
 388  * The wait-queues are circular lists, and you have to be *very* sure
 389  * to keep them correct. Use only these two functions to add/remove
 390  * entries in the queues.
 391  */
 392 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 393 {
 394         unsigned long flags;
 395 
 396 #ifdef DEBUG
 397         if (wait->next) {
 398                 unsigned long pc;
 399                 __asm__ __volatile__("call 1f\n"
 400                         "1:\tpopl %0":"=r" (pc));
 401                 printk("add_wait_queue (%08x): wait->next = %08x\n",pc,wait->next);
 402         }
 403 #endif
 404         save_flags(flags);
 405         cli();
 406         if (!*p) {
 407                 wait->next = wait;
 408                 *p = wait;
 409         } else {
 410                 wait->next = (*p)->next;
 411                 (*p)->next = wait;
 412         }
 413         restore_flags(flags);
 414 }
 415 
 416 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 417 {
 418         unsigned long flags;
 419         struct wait_queue * tmp;
 420 #ifdef DEBUG
 421         unsigned long ok = 0;
 422 #endif
 423 
 424         save_flags(flags);
 425         cli();
 426         if ((*p == wait) &&
 427 #ifdef DEBUG
 428             (ok = 1) &&
 429 #endif
 430             ((*p = wait->next) == wait)) {
 431                 *p = NULL;
 432         } else {
 433                 tmp = wait;
 434                 while (tmp->next != wait) {
 435                         tmp = tmp->next;
 436 #ifdef DEBUG
 437                         if (tmp == *p)
 438                                 ok = 1;
 439 #endif
 440                 }
 441                 tmp->next = wait->next;
 442         }
 443         wait->next = NULL;
 444         restore_flags(flags);
 445 #ifdef DEBUG
 446         if (!ok) {
 447                 printk("removed wait_queue not on list.\n");
 448                 printk("list = %08x, queue = %08x\n",p,wait);
 449                 __asm__("call 1f\n1:\tpopl %0":"=r" (ok));
 450                 printk("eip = %08x\n",ok);
 451         }
 452 #endif
 453 }
 454 
 455 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 456 {
 457         struct select_table_entry * entry;
 458 
 459         if (!p || !wait_address)
 460                 return;
 461         if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
 462                 return;
 463         entry = p->entry + p->nr;
 464         entry->wait_address = wait_address;
 465         entry->wait.task = current;
 466         entry->wait.next = NULL;
 467         add_wait_queue(wait_address,&entry->wait);
 468         p->nr++;
 469 }
 470 
 471 static inline unsigned long _get_base(char * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 472 {
 473         unsigned long __base;
 474         __asm__("movb %3,%%dh\n\t"
 475                 "movb %2,%%dl\n\t"
 476                 "shll $16,%%edx\n\t"
 477                 "movw %1,%%dx"
 478                 :"=&d" (__base)
 479                 :"m" (*((addr)+2)),
 480                  "m" (*((addr)+4)),
 481                  "m" (*((addr)+7)));
 482         return __base;
 483 }
 484 
 485 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
 486 
 487 static inline unsigned long get_limit(unsigned long segment)
     /* [previous][next][first][last][top][bottom][index][help] */
 488 {
 489         unsigned long __limit;
 490         __asm__("lsll %1,%0"
 491                 :"=r" (__limit):"r" (segment));
 492         return __limit+1;
 493 }
 494 
 495 #define REMOVE_LINKS(p) do { unsigned long flags; \
 496         save_flags(flags) ; cli(); \
 497         (p)->next_task->prev_task = (p)->prev_task; \
 498         (p)->prev_task->next_task = (p)->next_task; \
 499         restore_flags(flags); \
 500         if ((p)->p_osptr) \
 501                 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
 502         if ((p)->p_ysptr) \
 503                 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
 504         else \
 505                 (p)->p_pptr->p_cptr = (p)->p_osptr; \
 506         } while (0)
 507 
 508 #define SET_LINKS(p) do { unsigned long flags; \
 509         save_flags(flags); cli(); \
 510         (p)->next_task = &init_task; \
 511         (p)->prev_task = init_task.prev_task; \
 512         init_task.prev_task->next_task = (p); \
 513         init_task.prev_task = (p); \
 514         restore_flags(flags); \
 515         (p)->p_ysptr = NULL; \
 516         if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
 517                 (p)->p_osptr->p_ysptr = p; \
 518         (p)->p_pptr->p_cptr = p; \
 519         } while (0)
 520 
 521 #define for_each_task(p) \
 522         for (p = &init_task ; (p = p->next_task) != &init_task ; )
 523 
 524 /*
 525  * This is the ldt that every process will get unless we need
 526  * something other than this.
 527  */
 528 extern struct desc_struct default_ldt;
 529 
 530 #endif

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