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

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