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 struct i387_struct {
  84         long    cwd;
  85         long    swd;
  86         long    twd;
  87         long    fip;
  88         long    fcs;
  89         long    foo;
  90         long    fos;
  91         long    st_space[20];   /* 8*10 bytes for each FP-reg = 80 bytes */
  92 };
  93 
  94 struct tss_struct {
  95         unsigned long   back_link;      /* 16 high bits zero */
  96         unsigned long   esp0;
  97         unsigned long   ss0;            /* 16 high bits zero */
  98         unsigned long   esp1;
  99         unsigned long   ss1;            /* 16 high bits zero */
 100         unsigned long   esp2;
 101         unsigned long   ss2;            /* 16 high bits zero */
 102         unsigned long   cr3;
 103         unsigned long   eip;
 104         unsigned long   eflags;
 105         unsigned long   eax,ecx,edx,ebx;
 106         unsigned long   esp;
 107         unsigned long   ebp;
 108         unsigned long   esi;
 109         unsigned long   edi;
 110         unsigned long   es;             /* 16 high bits zero */
 111         unsigned long   cs;             /* 16 high bits zero */
 112         unsigned long   ss;             /* 16 high bits zero */
 113         unsigned long   ds;             /* 16 high bits zero */
 114         unsigned long   fs;             /* 16 high bits zero */
 115         unsigned long   gs;             /* 16 high bits zero */
 116         unsigned long   ldt;            /* 16 high bits zero */
 117         unsigned long   trace_bitmap;   /* bits: trace 0, bitmap 16-31 */
 118         unsigned long   io_bitmap[IO_BITMAP_SIZE];
 119         struct i387_struct i387;
 120 };
 121 
 122 struct task_struct {
 123 /* these are hardcoded - don't touch */
 124         long state;     /* -1 unrunnable, 0 runnable, >0 stopped */
 125         long counter;
 126         long priority;
 127         long signal;
 128         struct sigaction sigaction[32];
 129         long blocked;   /* bitmap of masked signals */
 130         unsigned long saved_kernel_stack;
 131 /* various fields */
 132         int exit_code;
 133         int dumpable:1;
 134         int swappable:1;
 135         unsigned long start_code,end_code,end_data,brk,start_stack;
 136         long pid,pgrp,session,leader;
 137         int     groups[NGROUPS];
 138         /* 
 139          * pointers to (original) parent process, youngest child, younger sibling,
 140          * older sibling, respectively.  (p->father can be replaced with 
 141          * p->p_pptr->pid)
 142          */
 143         struct task_struct *p_opptr,*p_pptr, *p_cptr, *p_ysptr, *p_osptr;
 144         /*
 145          * For ease of programming... Normal sleeps don't need to
 146          * keep track of a wait-queue: every task has an entry of it's own
 147          */
 148         struct wait_queue wait;
 149         unsigned short uid,euid,suid;
 150         unsigned short gid,egid,sgid;
 151         unsigned long timeout;
 152         unsigned long it_real_value, it_prof_value, it_virt_value;
 153         unsigned long it_real_incr, it_prof_incr, it_virt_incr;
 154         long utime,stime,cutime,cstime,start_time;
 155         unsigned long min_flt, maj_flt;
 156         unsigned long cmin_flt, cmaj_flt;
 157         struct rlimit rlim[RLIM_NLIMITS]; 
 158         unsigned int flags;     /* per process flags, defined below */
 159         unsigned short used_math;
 160         unsigned short rss;     /* number of resident pages */
 161         char comm[8];
 162         struct vm86_struct * vm86_info;
 163         unsigned long screen_bitmap;
 164 /* file system info */
 165         int link_count;
 166         int tty;                /* -1 if no tty, so it must be signed */
 167         unsigned short umask;
 168         struct inode * pwd;
 169         struct inode * root;
 170         struct inode * executable;
 171         struct {
 172                 struct inode * library;
 173                 unsigned long start;
 174                 unsigned long length;
 175                 unsigned long bss;
 176         } libraries[MAX_SHARED_LIBS];
 177         int numlibraries;
 178         struct file * filp[NR_OPEN];
 179         unsigned long close_on_exec;
 180 /* ldt for this task 0 - zero 1 - cs 2 - ds&ss */
 181         struct desc_struct ldt[3];
 182 /* tss for this task */
 183         struct tss_struct tss;
 184 };
 185 
 186 /*
 187  * Per process flags
 188  */
 189 #define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
 190                                         /* Not implemented yet, only for 486*/
 191 #define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
 192 
 193 /*
 194  *  INIT_TASK is used to set up the first task table, touch at
 195  * your own risk!. Base=0, limit=0x9ffff (=640kB)
 196  */
 197 #define INIT_TASK \
 198 /* state etc */ { 0,15,15, \
 199 /* signals */   0,{{},},0,0, \
 200 /* ec,brk... */ 0,0,0,0,0,0,0,0, \
 201 /* pid etc.. */ 0,0,0,0, \
 202 /* suppl grps*/ {NOGROUP,}, \
 203 /* proc links*/ &init_task.task,&init_task.task,NULL,NULL,NULL, \
 204 /* wait queue*/ {&init_task.task,NULL}, \
 205 /* uid etc */   0,0,0,0,0,0, \
 206 /* timeout */   0,0,0,0,0,0,0,0,0,0,0,0, \
 207 /* min_flt */   0,0,0,0, \
 208 /* rlimits */   { {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff},  \
 209                   {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
 210                   {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}}, \
 211 /* flags */     0, \
 212 /* math */      0, \
 213 /* rss */       2, \
 214 /* comm */      "swapper", \
 215 /* vm86_info */ NULL, 0, \
 216 /* fs info */   0,-1,0022,NULL,NULL,NULL, \
 217 /* libraries */ { { NULL, 0, 0}, }, 0, \
 218 /* filp */      {NULL,}, 0, \
 219                 { \
 220                         {0,0}, \
 221 /* ldt */               {0x9f,0xc0c0fa00}, \
 222                         {0x9f,0xc0c0f200} \
 223                 }, \
 224 /*tss*/ {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&swapper_pg_dir,\
 225          0,0,0,0,0,0,0,0, \
 226          0,0,0x17,0x17,0x17,0x17,0x17,0x17, \
 227          _LDT(0),0x80000000,{0xffffffff}, \
 228                 {} \
 229         }, \
 230 }
 231 
 232 extern struct task_struct *task[NR_TASKS];
 233 extern struct task_struct *last_task_used_math;
 234 extern struct task_struct *current;
 235 extern unsigned long volatile jiffies;
 236 extern unsigned long startup_time;
 237 extern int jiffies_offset;
 238 extern int need_resched;
 239 
 240 #define CURRENT_TIME (startup_time+(jiffies+jiffies_offset)/HZ)
 241 
 242 extern void add_timer(long jiffies, void (*fn)(void));
 243 
 244 extern void sleep_on(struct wait_queue ** p);
 245 extern void interruptible_sleep_on(struct wait_queue ** p);
 246 extern void wake_up(struct wait_queue ** p);
 247 extern void wake_one_task(struct task_struct * p);
 248 
 249 extern int send_sig(long sig,struct task_struct * p,int priv);
 250 extern int in_group_p(gid_t grp);
 251 
 252 extern int request_irq(unsigned int irq,void (*handler)(int));
 253 extern void free_irq(unsigned int irq);
 254 extern int irqaction(unsigned int irq,struct sigaction * new);
 255 
 256 /*
 257  * Entry into gdt where to find first TSS. 0-nul, 1-cs, 2-ds, 3-syscall
 258  * 4-TSS0, 5-LDT0, 6-TSS1 etc ...
 259  */
 260 #define FIRST_TSS_ENTRY 4
 261 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
 262 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
 263 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
 264 #define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
 265 #define lldt(n) __asm__("lldt %%ax"::"a" (_LDT(n)))
 266 #define str(n) \
 267 __asm__("str %%ax\n\t" \
 268         "subl %2,%%eax\n\t" \
 269         "shrl $4,%%eax" \
 270         :"=a" (n) \
 271         :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
 272 /*
 273  *      switch_to(n) should switch tasks to task nr n, first
 274  * checking that n isn't the current task, in which case it does nothing.
 275  * This also clears the TS-flag if the task we switched to has used
 276  * tha math co-processor latest.
 277  */
 278 #define switch_to(n) {\
 279 struct {long a,b;} __tmp; \
 280 __asm__("cmpl %%ecx,_current\n\t" \
 281         "je 1f\n\t" \
 282         "movw %%dx,%1\n\t" \
 283         "cli\n\t" \
 284         "xchgl %%ecx,_current\n\t" \
 285         "ljmp %0\n\t" \
 286         "sti\n\t" \
 287         "cmpl %%ecx,_last_task_used_math\n\t" \
 288         "jne 1f\n\t" \
 289         "clts\n" \
 290         "1:" \
 291         ::"m" (*&__tmp.a),"m" (*&__tmp.b), \
 292         "d" (_TSS(n)),"c" ((long) task[n]) \
 293         :"cx"); \
 294 }
 295 
 296 #define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000)
 297 
 298 #define _set_base(addr,base) \
 299 __asm__("movw %%dx,%0\n\t" \
 300         "rorl $16,%%edx\n\t" \
 301         "movb %%dl,%1\n\t" \
 302         "movb %%dh,%2" \
 303         ::"m" (*((addr)+2)), \
 304           "m" (*((addr)+4)), \
 305           "m" (*((addr)+7)), \
 306           "d" (base) \
 307         :"dx")
 308 
 309 #define _set_limit(addr,limit) \
 310 __asm__("movw %%dx,%0\n\t" \
 311         "rorl $16,%%edx\n\t" \
 312         "movb %1,%%dh\n\t" \
 313         "andb $0xf0,%%dh\n\t" \
 314         "orb %%dh,%%dl\n\t" \
 315         "movb %%dl,%1" \
 316         ::"m" (*(addr)), \
 317           "m" (*((addr)+6)), \
 318           "d" (limit) \
 319         :"dx")
 320 
 321 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
 322 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
 323 
 324 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 325 {
 326         unsigned long flags;
 327         struct wait_queue * tmp;
 328 
 329         __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
 330         wait->next = *p;
 331         tmp = wait;
 332         while (tmp->next)
 333                 if ((tmp = tmp->next)->next == *p)
 334                         break;
 335         *p = tmp->next = wait;
 336         __asm__ __volatile__("pushl %0 ; popfl"::"r" (flags));
 337 }
 338 
 339 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 340 {
 341         unsigned long flags;
 342         struct wait_queue * tmp;
 343 
 344         __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
 345         if (*p == wait)
 346                 if ((*p = wait->next) == wait)
 347                         *p = NULL;
 348         tmp = wait;
 349         while (tmp && tmp->next != wait)
 350                 tmp = tmp->next;
 351         if (tmp)
 352                 tmp->next = wait->next;
 353         wait->next = NULL;
 354         __asm__ __volatile__("pushl %0 ; popfl"::"r" (flags));
 355 }
 356 
 357 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 358 {
 359         struct select_table_entry * entry = p->entry + p->nr;
 360 
 361         if (!wait_address)
 362                 return;
 363         entry->wait_address = wait_address;
 364         entry->wait.task = current;
 365         add_wait_queue(wait_address,&entry->wait);
 366         p->nr++;
 367 }
 368 
 369 static unsigned long inline _get_base(char * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 370 {
 371         unsigned long __base;
 372         __asm__("movb %3,%%dh\n\t"
 373                 "movb %2,%%dl\n\t"
 374                 "shll $16,%%edx\n\t"
 375                 "movw %1,%%dx"
 376                 :"=&d" (__base)
 377                 :"m" (*((addr)+2)),
 378                  "m" (*((addr)+4)),
 379                  "m" (*((addr)+7)));
 380         return __base;
 381 }
 382 
 383 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
 384 
 385 static unsigned long inline get_limit(unsigned long segment)
     /* [previous][next][first][last][top][bottom][index][help] */
 386 {
 387         unsigned long __limit;
 388         __asm__("lsll %1,%0"
 389                 :"=r" (__limit):"r" (segment));
 390         return __limit+1;
 391 }
 392 
 393 #define REMOVE_LINKS(p) \
 394         if ((p)->p_osptr) \
 395                 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
 396         if ((p)->p_ysptr) \
 397                 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
 398         else \
 399                 (p)->p_pptr->p_cptr = (p)->p_osptr
 400 
 401 #define SET_LINKS(p) \
 402         (p)->p_ysptr = NULL; \
 403         if ((p)->p_osptr = (p)->p_pptr->p_cptr) \
 404                 (p)->p_osptr->p_ysptr = p; \
 405         (p)->p_pptr->p_cptr = p
 406 
 407 #endif

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