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

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