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

   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 #include <asm/param.h>  /* for HZ */
  13 
  14 extern unsigned long intr_count;
  15 extern unsigned long event;
  16 
  17 #include <linux/binfmts.h>
  18 #include <linux/personality.h>
  19 #include <linux/tasks.h>
  20 #include <linux/kernel.h>
  21 #include <asm/system.h>
  22 
  23 /*
  24  * These are the constant used to fake the fixed-point load-average
  25  * counting. Some notes:
  26  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
  27  *    a load-average precision of 10 bits integer + 11 bits fractional
  28  *  - if you want to count load-averages more often, you need more
  29  *    precision, or rounding will get you. With 2-second counting freq,
  30  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
  31  *    11 bit fractions.
  32  */
  33 extern unsigned long avenrun[];         /* Load averages */
  34 
  35 #define FSHIFT          11              /* nr of bits of precision */
  36 #define FIXED_1         (1<<FSHIFT)     /* 1.0 as fixed-point */
  37 #define LOAD_FREQ       (5*HZ)          /* 5 sec intervals */
  38 #define EXP_1           1884            /* 1/exp(5sec/1min) as fixed-point */
  39 #define EXP_5           2014            /* 1/exp(5sec/5min) */
  40 #define EXP_15          2037            /* 1/exp(5sec/15min) */
  41 
  42 #define CALC_LOAD(load,exp,n) \
  43         load *= exp; \
  44         load += n*(FIXED_1-exp); \
  45         load >>= FSHIFT;
  46 
  47 #define CT_TO_SECS(x)   ((x) / HZ)
  48 #define CT_TO_USECS(x)  (((x) % HZ) * 1000000/HZ)
  49 
  50 #define FIRST_TASK task[0]
  51 #define LAST_TASK task[NR_TASKS-1]
  52 
  53 #include <linux/head.h>
  54 #include <linux/fs.h>
  55 #include <linux/signal.h>
  56 #include <linux/time.h>
  57 #include <linux/param.h>
  58 #include <linux/resource.h>
  59 #include <linux/vm86.h>
  60 #include <linux/math_emu.h>
  61 #include <linux/ptrace.h>
  62 
  63 #include <asm/processor.h>
  64 
  65 #define TASK_RUNNING            0
  66 #define TASK_INTERRUPTIBLE      1
  67 #define TASK_UNINTERRUPTIBLE    2
  68 #define TASK_ZOMBIE             3
  69 #define TASK_STOPPED            4
  70 #define TASK_SWAPPING           5
  71 
  72 #ifndef NULL
  73 #define NULL ((void *) 0)
  74 #endif
  75 
  76 #ifdef __KERNEL__
  77 
  78 extern void sched_init(void);
  79 extern void show_state(void);
  80 extern void trap_init(void);
  81 
  82 asmlinkage void schedule(void);
  83 
  84 #endif /* __KERNEL__ */
  85 
  86 struct files_struct {
  87         int count;
  88         fd_set close_on_exec;
  89         struct file * fd[NR_OPEN];
  90 };
  91 
  92 #define INIT_FILES { \
  93         0, \
  94         { { 0, } }, \
  95         { NULL, } \
  96 }
  97 
  98 struct fs_struct {
  99         int count;
 100         unsigned short umask;
 101         struct inode * root, * pwd;
 102 };
 103 
 104 #define INIT_FS { \
 105         0, \
 106         0022, \
 107         NULL, NULL \
 108 }
 109 
 110 struct mm_struct {
 111         int count;
 112         unsigned long start_code, end_code, end_data;
 113         unsigned long start_brk, brk, start_stack, start_mmap;
 114         unsigned long arg_start, arg_end, env_start, env_end;
 115         unsigned long rss;
 116         unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
 117         int swappable:1;
 118         unsigned long swap_address;
 119         unsigned long old_maj_flt;      /* old value of maj_flt */
 120         unsigned long dec_flt;          /* page fault count of the last time */
 121         unsigned long swap_cnt;         /* number of pages to swap on next pass */
 122         struct vm_area_struct * mmap;
 123         struct vm_area_struct * mmap_avl;
 124 };
 125 
 126 #define INIT_MM { \
 127                 0, \
 128                 0, 0, 0, \
 129                 0, 0, 0, 0, \
 130                 0, 0, 0, 0, \
 131                 0, \
 132 /* ?_flt */     0, 0, 0, 0, \
 133                 0, \
 134 /* swap */      0, 0, 0, 0, \
 135                 &init_mmap, &init_mmap }
 136 
 137 struct task_struct {
 138 /* these are hardcoded - don't touch */
 139         volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
 140         long counter;
 141         long priority;
 142         unsigned long signal;
 143         unsigned long blocked;  /* bitmap of masked signals */
 144         unsigned long flags;    /* per process flags, defined below */
 145         int errno;
 146         int debugreg[8];  /* Hardware debugging registers */
 147         struct exec_domain *exec_domain;
 148 /* various fields */
 149         struct linux_binfmt *binfmt;
 150         struct task_struct *next_task, *prev_task;
 151         struct sigaction sigaction[32];
 152         unsigned long saved_kernel_stack;
 153         unsigned long kernel_stack_page;
 154         int exit_code, exit_signal;
 155         unsigned long personality;
 156         int dumpable:1;
 157         int did_exec:1;
 158         int pid,pgrp,tty_old_pgrp,session,leader;
 159         int     groups[NGROUPS];
 160         /* 
 161          * pointers to (original) parent process, youngest child, younger sibling,
 162          * older sibling, respectively.  (p->father can be replaced with 
 163          * p->p_pptr->pid)
 164          */
 165         struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
 166         struct wait_queue *wait_chldexit;       /* for wait4() */
 167         unsigned short uid,euid,suid,fsuid;
 168         unsigned short gid,egid,sgid,fsgid;
 169         unsigned long timeout;
 170         unsigned long it_real_value, it_prof_value, it_virt_value;
 171         unsigned long it_real_incr, it_prof_incr, it_virt_incr;
 172         long utime, stime, cutime, cstime, start_time;
 173         struct rlimit rlim[RLIM_NLIMITS]; 
 174         unsigned short used_math;
 175         char comm[16];
 176 /* file system info */
 177         int link_count;
 178         struct tty_struct *tty; /* NULL if no tty */
 179 /* ipc stuff */
 180         struct sem_undo *semundo;
 181         struct sem_queue *semsleeping;
 182 /* ldt for this task - used by Wine.  If NULL, default_ldt is used */
 183         struct desc_struct *ldt;
 184 /* tss for this task */
 185         struct thread_struct tss;
 186 /* filesystem information */
 187         struct fs_struct fs[1];
 188 /* open file information */
 189         struct files_struct files[1];
 190 /* memory management info */
 191         struct mm_struct mm[1];
 192 };
 193 
 194 /*
 195  * Per process flags
 196  */
 197 #define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
 198                                         /* Not implemented yet, only for 486*/
 199 #define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
 200 #define PF_TRACESYS     0x00000020      /* tracing system calls */
 201 
 202 #define PF_STARTING     0x00000100      /* being created */
 203 #define PF_EXITING      0x00000200      /* getting shut down */
 204 
 205 /*
 206  * cloning flags:
 207  */
 208 #define CSIGNAL         0x000000ff      /* signal mask to be sent at exit */
 209 #define COPYVM          0x00000100      /* set if VM copy desired (like normal fork()) */
 210 #define COPYFD          0x00000200      /* set if fd's should be copied, not shared (NI) */
 211 
 212 /*
 213  *  INIT_TASK is used to set up the first task table, touch at
 214  * your own risk!. Base=0, limit=0x1fffff (=2MB)
 215  */
 216 #define INIT_TASK \
 217 /* state etc */ { 0,15,15,0,0,0,0, \
 218 /* debugregs */ { 0, },            \
 219 /* exec domain */&default_exec_domain, \
 220 /* binfmt */    NULL, \
 221 /* schedlink */ &init_task,&init_task, \
 222 /* signals */   {{ 0, },}, \
 223 /* stack */     0,(unsigned long) &init_kernel_stack, \
 224 /* ec,brk... */ 0,0,0,0,0, \
 225 /* pid etc.. */ 0,0,0,0,0, \
 226 /* suppl grps*/ {NOGROUP,}, \
 227 /* proc links*/ &init_task,&init_task,NULL,NULL,NULL,NULL, \
 228 /* uid etc */   0,0,0,0,0,0,0,0, \
 229 /* timeout */   0,0,0,0,0,0,0,0,0,0,0,0, \
 230 /* rlimits */   { {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX},  \
 231                   {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX},  \
 232                   {       0, LONG_MAX}, {LONG_MAX, LONG_MAX}, \
 233                   {MAX_TASKS_PER_USER, MAX_TASKS_PER_USER}, {NR_OPEN, NR_OPEN}}, \
 234 /* math */      0, \
 235 /* comm */      "swapper", \
 236 /* fs info */   0,NULL, \
 237 /* ipc */       NULL, NULL, \
 238 /* ldt */       NULL, \
 239 /* tss */       INIT_TSS, \
 240 /* fs */        { INIT_FS }, \
 241 /* files */     { INIT_FILES }, \
 242 /* mm */        { INIT_MM } \
 243 }
 244 
 245 #ifdef __KERNEL__
 246 
 247 extern struct task_struct init_task;
 248 extern struct task_struct *task[NR_TASKS];
 249 extern struct task_struct *last_task_used_math;
 250 extern struct task_struct *current;
 251 extern unsigned long volatile jiffies;
 252 extern unsigned long itimer_ticks;
 253 extern unsigned long itimer_next;
 254 extern struct timeval xtime;
 255 extern int need_resched;
 256 
 257 #define CURRENT_TIME (xtime.tv_sec)
 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_up_interruptible(struct wait_queue ** p);
 263 
 264 extern void notify_parent(struct task_struct * tsk);
 265 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
 266 extern int in_group_p(gid_t grp);
 267 
 268 extern int request_irq(unsigned int irq,void (*handler)(int, struct pt_regs *),
 269         unsigned long flags, const char *device);
 270 extern void free_irq(unsigned int irq);
 271 
 272 extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
 273 extern void flush_thread(void);
 274 extern void exit_thread(void);
 275 
 276 extern int do_execve(char *, char **, char **, struct pt_regs *);
 277 extern int do_fork(unsigned long, unsigned long, struct pt_regs *);
 278 asmlinkage int do_signal(unsigned long, struct pt_regs *);
 279 
 280 /*
 281  * The wait-queues are circular lists, and you have to be *very* sure
 282  * to keep them correct. Use only these two functions to add/remove
 283  * entries in the queues.
 284  */
 285 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 286 {
 287         unsigned long flags;
 288 
 289 #ifdef DEBUG
 290         if (wait->next) {
 291                 unsigned long pc;
 292                 __asm__ __volatile__("call 1f\n"
 293                         "1:\tpopl %0":"=r" (pc));
 294                 printk("add_wait_queue (%08x): wait->next = %08x\n",pc,(unsigned long) wait->next);
 295         }
 296 #endif
 297         save_flags(flags);
 298         cli();
 299         if (!*p) {
 300                 wait->next = wait;
 301                 *p = wait;
 302         } else {
 303                 wait->next = (*p)->next;
 304                 (*p)->next = wait;
 305         }
 306         restore_flags(flags);
 307 }
 308 
 309 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 310 {
 311         unsigned long flags;
 312         struct wait_queue * tmp;
 313 #ifdef DEBUG
 314         unsigned long ok = 0;
 315 #endif
 316 
 317         save_flags(flags);
 318         cli();
 319         if ((*p == wait) &&
 320 #ifdef DEBUG
 321             (ok = 1) &&
 322 #endif
 323             ((*p = wait->next) == wait)) {
 324                 *p = NULL;
 325         } else {
 326                 tmp = wait;
 327                 while (tmp->next != wait) {
 328                         tmp = tmp->next;
 329 #ifdef DEBUG
 330                         if (tmp == *p)
 331                                 ok = 1;
 332 #endif
 333                 }
 334                 tmp->next = wait->next;
 335         }
 336         wait->next = NULL;
 337         restore_flags(flags);
 338 #ifdef DEBUG
 339         if (!ok) {
 340                 printk("removed wait_queue not on list.\n");
 341                 printk("list = %08x, queue = %08x\n",(unsigned long) p, (unsigned long) wait);
 342                 __asm__("call 1f\n1:\tpopl %0":"=r" (ok));
 343                 printk("eip = %08x\n",ok);
 344         }
 345 #endif
 346 }
 347 
 348 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 349 {
 350         struct select_table_entry * entry;
 351 
 352         if (!p || !wait_address)
 353                 return;
 354         if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
 355                 return;
 356         entry = p->entry + p->nr;
 357         entry->wait_address = wait_address;
 358         entry->wait.task = current;
 359         entry->wait.next = NULL;
 360         add_wait_queue(wait_address,&entry->wait);
 361         p->nr++;
 362 }
 363 
 364 extern void __down(struct semaphore * sem);
 365 
 366 /*
 367  * These are not yet interrupt-safe
 368  */
 369 extern inline void down(struct semaphore * sem)
     /* [previous][next][first][last][top][bottom][index][help] */
 370 {
 371         if (sem->count <= 0)
 372                 __down(sem);
 373         sem->count--;
 374 }
 375 
 376 extern inline void up(struct semaphore * sem)
     /* [previous][next][first][last][top][bottom][index][help] */
 377 {
 378         sem->count++;
 379         wake_up(&sem->wait);
 380 }       
 381 
 382 #define REMOVE_LINKS(p) do { unsigned long flags; \
 383         save_flags(flags) ; cli(); \
 384         (p)->next_task->prev_task = (p)->prev_task; \
 385         (p)->prev_task->next_task = (p)->next_task; \
 386         restore_flags(flags); \
 387         if ((p)->p_osptr) \
 388                 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
 389         if ((p)->p_ysptr) \
 390                 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
 391         else \
 392                 (p)->p_pptr->p_cptr = (p)->p_osptr; \
 393         } while (0)
 394 
 395 #define SET_LINKS(p) do { unsigned long flags; \
 396         save_flags(flags); cli(); \
 397         (p)->next_task = &init_task; \
 398         (p)->prev_task = init_task.prev_task; \
 399         init_task.prev_task->next_task = (p); \
 400         init_task.prev_task = (p); \
 401         restore_flags(flags); \
 402         (p)->p_ysptr = NULL; \
 403         if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
 404                 (p)->p_osptr->p_ysptr = p; \
 405         (p)->p_pptr->p_cptr = p; \
 406         } while (0)
 407 
 408 #define for_each_task(p) \
 409         for (p = &init_task ; (p = p->next_task) != &init_task ; )
 410 
 411 #endif /* __KERNEL__ */
 412 
 413 #endif

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