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

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