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 HZ 100
   5 
   6 /*
   7  * This is the maximum nr of tasks - change it if you need to
   8  */
   9 #define NR_TASKS        64
  10 
  11 /*
  12  * User space process size: 3GB. This is hardcoded into a few places,
  13  * so don't change it unless you know what you are doing.
  14  */
  15 #define TASK_SIZE       0xc0000000
  16 
  17 /*
  18  * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
  19  */
  20 #define IO_BITMAP_SIZE  32
  21 
  22 /*
  23  * These are the constant used to fake the fixed-point load-average
  24  * counting. Some notes:
  25  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
  26  *    a load-average precision of 10 bits integer + 11 bits fractional
  27  *  - if you want to count load-averages more often, you need more
  28  *    precision, or rounding will get you. With 2-second counting freq,
  29  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
  30  *    11 bit fractions.
  31  */
  32 #define FSHIFT          11              /* nr of bits of precision */
  33 #define FIXED_1         (1<<FSHIFT)     /* 1.0 as fixed-point */
  34 #define LOAD_FREQ       (5*HZ)          /* 5 sec intervals */
  35 #define EXP_1           1884            /* 1/exp(5sec/1min) as fixed-point */
  36 #define EXP_5           2014            /* 1/exp(5sec/5min) */
  37 #define EXP_15          2037            /* 1/exp(5sec/15min) */
  38 
  39 #define CALC_LOAD(load,exp,n) \
  40         load *= exp; \
  41         load += n*(FIXED_1-exp); \
  42         load >>= FSHIFT;
  43 
  44 #define CT_TO_SECS(x)   ((x) / HZ)
  45 #define CT_TO_USECS(x)  (((x) % HZ) * 1000000/HZ)
  46 
  47 #define FIRST_TASK task[0]
  48 #define LAST_TASK task[NR_TASKS-1]
  49 
  50 #include <linux/head.h>
  51 #include <linux/fs.h>
  52 #include <linux/mm.h>
  53 #include <linux/signal.h>
  54 #include <linux/time.h>
  55 #include <linux/param.h>
  56 #include <linux/resource.h>
  57 #include <linux/vm86.h>
  58 
  59 #if (NR_OPEN > 32)
  60 #error "Currently the close-on-exec-flags and select masks are in one long, max 32 files/proc"
  61 #endif
  62 
  63 #define TASK_RUNNING            0
  64 #define TASK_INTERRUPTIBLE      1
  65 #define TASK_UNINTERRUPTIBLE    2
  66 #define TASK_ZOMBIE             3
  67 #define TASK_STOPPED            4
  68 
  69 #ifndef NULL
  70 #define NULL ((void *) 0)
  71 #endif
  72 
  73 #define MAX_SHARED_LIBS 6
  74 
  75 extern void sched_init(void);
  76 extern void show_state(void);
  77 extern void schedule(void);
  78 extern void trap_init(void);
  79 extern void panic(const char * str);
  80 
  81 typedef int (*fn_ptr)();
  82 
  83 union i387_union {
  84         struct i387_hard_struct {
  85                 long    cwd;
  86                 long    swd;
  87                 long    twd;
  88                 long    fip;
  89                 long    fcs;
  90                 long    foo;
  91                 long    fos;
  92                 long    st_space[20];   /* 8*10 bytes for each FP-reg = 80 bytes */
  93         } hard;
  94         struct i387_soft_struct {
  95                 long    cwd;
  96                 long    swd;
  97                 long    twd;
  98                 long    fip;
  99                 long    fcs;
 100                 long    foo;
 101                 long    fos;
 102                 long    top;
 103                 long    regs_space[32]; /* 8*16 bytes for each FP-reg = 112 bytes */
 104         } soft;
 105 };
 106 
 107 struct tss_struct {
 108         unsigned long   back_link;      /* 16 high bits zero */
 109         unsigned long   esp0;
 110         unsigned long   ss0;            /* 16 high bits zero */
 111         unsigned long   esp1;
 112         unsigned long   ss1;            /* 16 high bits zero */
 113         unsigned long   esp2;
 114         unsigned long   ss2;            /* 16 high bits zero */
 115         unsigned long   cr3;
 116         unsigned long   eip;
 117         unsigned long   eflags;
 118         unsigned long   eax,ecx,edx,ebx;
 119         unsigned long   esp;
 120         unsigned long   ebp;
 121         unsigned long   esi;
 122         unsigned long   edi;
 123         unsigned long   es;             /* 16 high bits zero */
 124         unsigned long   cs;             /* 16 high bits zero */
 125         unsigned long   ss;             /* 16 high bits zero */
 126         unsigned long   ds;             /* 16 high bits zero */
 127         unsigned long   fs;             /* 16 high bits zero */
 128         unsigned long   gs;             /* 16 high bits zero */
 129         unsigned long   ldt;            /* 16 high bits zero */
 130         unsigned long   trace_bitmap;   /* bits: trace 0, bitmap 16-31 */
 131         unsigned long   io_bitmap[IO_BITMAP_SIZE];
 132         union i387_union i387;
 133 };
 134 
 135 struct task_struct {
 136 /* these are hardcoded - don't touch */
 137         long state;     /* -1 unrunnable, 0 runnable, >0 stopped */
 138         long counter;
 139         long priority;
 140         long signal;
 141         struct sigaction sigaction[32];
 142         long blocked;   /* bitmap of masked signals */
 143         unsigned long saved_kernel_stack;
 144 /* various fields */
 145         int exit_code;
 146         int dumpable:1;
 147         int swappable:1;
 148         unsigned long start_code,end_code,end_data,brk,start_stack;
 149         long pid,pgrp,session,leader;
 150         int     groups[NGROUPS];
 151         /* 
 152          * pointers to (original) parent process, youngest child, younger sibling,
 153          * older sibling, respectively.  (p->father can be replaced with 
 154          * p->p_pptr->pid)
 155          */
 156         struct task_struct *p_opptr,*p_pptr, *p_cptr, *p_ysptr, *p_osptr;
 157         /*
 158          * For ease of programming... Normal sleeps don't need to
 159          * keep track of a wait-queue: every task has an entry of it's own
 160          */
 161         struct wait_queue wait;
 162         unsigned short uid,euid,suid;
 163         unsigned short gid,egid,sgid;
 164         unsigned long timeout;
 165         unsigned long it_real_value, it_prof_value, it_virt_value;
 166         unsigned long it_real_incr, it_prof_incr, it_virt_incr;
 167         long utime,stime,cutime,cstime,start_time;
 168         unsigned long min_flt, maj_flt;
 169         unsigned long cmin_flt, cmaj_flt;
 170         struct rlimit rlim[RLIM_NLIMITS]; 
 171         unsigned int flags;     /* per process flags, defined below */
 172         unsigned short used_math;
 173         unsigned short rss;     /* number of resident pages */
 174         char comm[8];
 175         struct vm86_struct * vm86_info;
 176         unsigned long screen_bitmap;
 177 /* file system info */
 178         int link_count;
 179         int tty;                /* -1 if no tty, so it must be signed */
 180         unsigned short umask;
 181         struct inode * pwd;
 182         struct inode * root;
 183         struct inode * executable;
 184         struct vm_area_struct * mmap;
 185         struct {
 186                 struct inode * library;
 187                 unsigned long start;
 188                 unsigned long length;
 189                 unsigned long bss;
 190         } libraries[MAX_SHARED_LIBS];
 191         int numlibraries;
 192         struct file * filp[NR_OPEN];
 193         unsigned long close_on_exec;
 194 /* ldt for this task 0 - zero 1 - cs 2 - ds&ss */
 195         struct desc_struct ldt[3];
 196 /* tss for this task */
 197         struct tss_struct tss;
 198 };
 199 
 200 /*
 201  * Per process flags
 202  */
 203 #define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
 204                                         /* Not implemented yet, only for 486*/
 205 #define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
 206 
 207 /*
 208  *  INIT_TASK is used to set up the first task table, touch at
 209  * your own risk!. Base=0, limit=0x9ffff (=640kB)
 210  */
 211 #define INIT_TASK \
 212 /* state etc */ { 0,15,15, \
 213 /* signals */   0,{{},},0,0, \
 214 /* ec,brk... */ 0,0,0,0,0,0,0,0, \
 215 /* pid etc.. */ 0,0,0,0, \
 216 /* suppl grps*/ {NOGROUP,}, \
 217 /* proc links*/ &init_task.task,&init_task.task,NULL,NULL,NULL, \
 218 /* wait queue*/ {&init_task.task,NULL}, \
 219 /* uid etc */   0,0,0,0,0,0, \
 220 /* timeout */   0,0,0,0,0,0,0,0,0,0,0,0, \
 221 /* min_flt */   0,0,0,0, \
 222 /* rlimits */   { {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff},  \
 223                   {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
 224                   {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}}, \
 225 /* flags */     0, \
 226 /* math */      0, \
 227 /* rss */       2, \
 228 /* comm */      "swapper", \
 229 /* vm86_info */ NULL, 0, \
 230 /* fs info */   0,-1,0022,NULL,NULL,NULL,NULL, \
 231 /* libraries */ { { NULL, 0, 0}, }, 0, \
 232 /* filp */      {NULL,}, 0, \
 233                 { \
 234                         {0,0}, \
 235 /* ldt */               {0x9f,0xc0c0fa00}, \
 236                         {0x9f,0xc0c0f200} \
 237                 }, \
 238 /*tss*/ {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&swapper_pg_dir,\
 239          0,0,0,0,0,0,0,0, \
 240          0,0,0x17,0x17,0x17,0x17,0x17,0x17, \
 241          _LDT(0),0x80000000,{0xffffffff}, \
 242                 { { 0, } } \
 243         }, \
 244 }
 245 
 246 extern struct task_struct *task[NR_TASKS];
 247 extern struct task_struct *last_task_used_math;
 248 extern struct task_struct *current;
 249 extern unsigned long volatile jiffies;
 250 extern unsigned long startup_time;
 251 extern int jiffies_offset;
 252 extern int need_resched;
 253 extern int hard_math;
 254 
 255 #define CURRENT_TIME (startup_time+(jiffies+jiffies_offset)/HZ)
 256 
 257 extern void add_timer(long jiffies, void (*fn)(void));
 258 
 259 extern void sleep_on(struct wait_queue ** p);
 260 extern void interruptible_sleep_on(struct wait_queue ** p);
 261 extern void wake_up(struct wait_queue ** p);
 262 extern void wake_one_task(struct task_struct * p);
 263 
 264 extern int send_sig(long sig,struct task_struct * p,int priv);
 265 extern int in_group_p(gid_t grp);
 266 
 267 extern int request_irq(unsigned int irq,void (*handler)(int));
 268 extern void free_irq(unsigned int irq);
 269 extern int irqaction(unsigned int irq,struct sigaction * new);
 270 
 271 /*
 272  * Entry into gdt where to find first TSS. 0-nul, 1-cs, 2-ds, 3-syscall
 273  * 4-TSS0, 5-LDT0, 6-TSS1 etc ...
 274  */
 275 #define FIRST_TSS_ENTRY 4
 276 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
 277 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
 278 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
 279 #define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
 280 #define lldt(n) __asm__("lldt %%ax"::"a" (_LDT(n)))
 281 #define str(n) \
 282 __asm__("str %%ax\n\t" \
 283         "subl %2,%%eax\n\t" \
 284         "shrl $4,%%eax" \
 285         :"=a" (n) \
 286         :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
 287 /*
 288  *      switch_to(n) should switch tasks to task nr n, first
 289  * checking that n isn't the current task, in which case it does nothing.
 290  * This also clears the TS-flag if the task we switched to has used
 291  * tha math co-processor latest.
 292  */
 293 #define switch_to(n) {\
 294 struct {long a,b;} __tmp; \
 295 __asm__("cmpl %%ecx,_current\n\t" \
 296         "je 1f\n\t" \
 297         "movw %%dx,%1\n\t" \
 298         "cli\n\t" \
 299         "xchgl %%ecx,_current\n\t" \
 300         "ljmp %0\n\t" \
 301         "sti\n\t" \
 302         "cmpl %%ecx,_last_task_used_math\n\t" \
 303         "jne 1f\n\t" \
 304         "clts\n" \
 305         "1:" \
 306         ::"m" (*&__tmp.a),"m" (*&__tmp.b), \
 307         "d" (_TSS(n)),"c" ((long) task[n]) \
 308         :"cx"); \
 309 }
 310 
 311 #define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000)
 312 
 313 #define _set_base(addr,base) \
 314 __asm__("movw %%dx,%0\n\t" \
 315         "rorl $16,%%edx\n\t" \
 316         "movb %%dl,%1\n\t" \
 317         "movb %%dh,%2" \
 318         ::"m" (*((addr)+2)), \
 319           "m" (*((addr)+4)), \
 320           "m" (*((addr)+7)), \
 321           "d" (base) \
 322         :"dx")
 323 
 324 #define _set_limit(addr,limit) \
 325 __asm__("movw %%dx,%0\n\t" \
 326         "rorl $16,%%edx\n\t" \
 327         "movb %1,%%dh\n\t" \
 328         "andb $0xf0,%%dh\n\t" \
 329         "orb %%dh,%%dl\n\t" \
 330         "movb %%dl,%1" \
 331         ::"m" (*(addr)), \
 332           "m" (*((addr)+6)), \
 333           "d" (limit) \
 334         :"dx")
 335 
 336 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
 337 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
 338 
 339 /*
 340  * The wait-queues are circular lists, and you have to be *very* sure
 341  * to keep them correct. Use only these two functions to add/remove
 342  * entries in the queues.
 343  */
 344 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 345 {
 346         unsigned long flags;
 347 
 348 #ifdef DEBUG
 349         if (wait->next) {
 350                 unsigned long pc;
 351                 __asm__ __volatile__("call 1f\n"
 352                         "1:\tpopl %0":"=r" (pc));
 353                 printk("add_wait_queue (%08x): wait->next = %08x\n",pc,wait->next);
 354         }
 355 #endif
 356         __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
 357         if (!*p) {
 358                 wait->next = wait;
 359                 *p = wait;
 360         } else {
 361                 wait->next = (*p)->next;
 362                 (*p)->next = wait;
 363         }
 364         __asm__ __volatile__("pushl %0 ; popfl"::"r" (flags));
 365 }
 366 
 367 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 368 {
 369         unsigned long flags;
 370         struct wait_queue * tmp;
 371 
 372         __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
 373         if ((*p == wait) && ((*p = wait->next) == wait)) {
 374                 *p = NULL;
 375         } else {
 376                 tmp = wait;
 377                 while (tmp->next != wait)
 378                         tmp = tmp->next;
 379                 tmp->next = wait->next;
 380         }
 381         wait->next = NULL;
 382         __asm__ __volatile__("pushl %0 ; popfl"::"r" (flags));
 383 }
 384 
 385 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 386 {
 387         struct select_table_entry * entry = p->entry + p->nr;
 388 
 389         if (!wait_address)
 390                 return;
 391         entry->wait_address = wait_address;
 392         entry->wait.task = current;
 393         entry->wait.next = NULL;
 394         add_wait_queue(wait_address,&entry->wait);
 395         p->nr++;
 396 }
 397 
 398 static unsigned long inline _get_base(char * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 399 {
 400         unsigned long __base;
 401         __asm__("movb %3,%%dh\n\t"
 402                 "movb %2,%%dl\n\t"
 403                 "shll $16,%%edx\n\t"
 404                 "movw %1,%%dx"
 405                 :"=&d" (__base)
 406                 :"m" (*((addr)+2)),
 407                  "m" (*((addr)+4)),
 408                  "m" (*((addr)+7)));
 409         return __base;
 410 }
 411 
 412 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
 413 
 414 static unsigned long inline get_limit(unsigned long segment)
     /* [previous][next][first][last][top][bottom][index][help] */
 415 {
 416         unsigned long __limit;
 417         __asm__("lsll %1,%0"
 418                 :"=r" (__limit):"r" (segment));
 419         return __limit+1;
 420 }
 421 
 422 #define REMOVE_LINKS(p) \
 423         if ((p)->p_osptr) \
 424                 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
 425         if ((p)->p_ysptr) \
 426                 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
 427         else \
 428                 (p)->p_pptr->p_cptr = (p)->p_osptr
 429 
 430 #define SET_LINKS(p) \
 431         (p)->p_ysptr = NULL; \
 432         if ((p)->p_osptr = (p)->p_pptr->p_cptr) \
 433                 (p)->p_osptr->p_ysptr = p; \
 434         (p)->p_pptr->p_cptr = p
 435 
 436 #endif

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