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

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