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

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