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

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