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

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