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 #include <linux/smp.h>
  25 #include <linux/tty.h>
  26 #include <linux/sem.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 /*
  91  * Scheduling policies
  92  */
  93 #define SCHED_OTHER             0
  94 #define SCHED_FIFO              1
  95 #define SCHED_RR                2
  96 
  97 struct sched_param {
  98         int sched_priority;
  99 };
 100 
 101 #ifndef NULL
 102 #define NULL ((void *) 0)
 103 #endif
 104 
 105 #ifdef __KERNEL__
 106 
 107 #define barrier() __asm__("": : :"memory")
 108 
 109 extern void sched_init(void);
 110 extern void show_state(void);
 111 extern void trap_init(void);
 112 
 113 asmlinkage void schedule(void);
 114 
 115 struct files_struct {
 116         int count;
 117         fd_set close_on_exec;
 118         struct file * fd[NR_OPEN];
 119 };
 120 
 121 #define INIT_FILES { \
 122         1, \
 123         { { 0, } }, \
 124         { NULL, } \
 125 }
 126 
 127 struct fs_struct {
 128         int count;
 129         unsigned short umask;
 130         struct inode * root, * pwd;
 131 };
 132 
 133 #define INIT_FS { \
 134         1, \
 135         0022, \
 136         NULL, NULL \
 137 }
 138 
 139 struct mm_struct {
 140         int count;
 141         pgd_t * pgd;
 142         unsigned long context;
 143         unsigned long start_code, end_code, start_data, end_data;
 144         unsigned long start_brk, brk, start_stack, start_mmap;
 145         unsigned long arg_start, arg_end, env_start, env_end;
 146         unsigned long rss, total_vm, locked_vm;
 147         unsigned long def_flags;
 148         struct vm_area_struct * mmap;
 149         struct vm_area_struct * mmap_avl;
 150 };
 151 
 152 #define INIT_MM { \
 153                 1, \
 154                 swapper_pg_dir, \
 155                 0, \
 156                 0, 0, 0, 0, \
 157                 0, 0, 0, 0, \
 158                 0, 0, 0, 0, \
 159                 0, 0, 0, \
 160                 0, \
 161                 &init_mmap, &init_mmap }
 162 
 163 struct signal_struct {
 164         int count;
 165         struct sigaction action[32];
 166 };
 167 
 168 #define INIT_SIGNALS { \
 169                 1, \
 170                 { {0,}, } }
 171 
 172 struct task_struct {
 173 /* these are hardcoded - don't touch */
 174         volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
 175         long counter;
 176         long priority;
 177         unsigned long signal;
 178         unsigned long blocked;  /* bitmap of masked signals */
 179         unsigned long flags;    /* per process flags, defined below */
 180         int errno;
 181         long debugreg[8];  /* Hardware debugging registers */
 182         struct exec_domain *exec_domain;
 183 /* various fields */
 184         struct linux_binfmt *binfmt;
 185         struct task_struct *next_task, *prev_task;
 186         struct task_struct *next_run,  *prev_run;
 187         unsigned long saved_kernel_stack;
 188         unsigned long kernel_stack_page;
 189         int exit_code, exit_signal;
 190         unsigned long personality;
 191         int dumpable:1;
 192         int did_exec:1;
 193         int pid,pgrp,tty_old_pgrp,session,leader;
 194         int     groups[NGROUPS];
 195         /* 
 196          * pointers to (original) parent process, youngest child, younger sibling,
 197          * older sibling, respectively.  (p->father can be replaced with 
 198          * p->p_pptr->pid)
 199          */
 200         struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
 201         struct wait_queue *wait_chldexit;       /* for wait4() */
 202         unsigned short uid,euid,suid,fsuid;
 203         unsigned short gid,egid,sgid,fsgid;
 204         unsigned long timeout, policy, rt_priority;
 205         unsigned long it_real_value, it_prof_value, it_virt_value;
 206         unsigned long it_real_incr, it_prof_incr, it_virt_incr;
 207         struct timer_list real_timer;
 208         long utime, stime, cutime, cstime, start_time;
 209 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
 210         unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
 211         int swappable:1;
 212         unsigned long swap_address;
 213         unsigned long old_maj_flt;      /* old value of maj_flt */
 214         unsigned long dec_flt;          /* page fault count of the last time */
 215         unsigned long swap_cnt;         /* number of pages to swap on next pass */
 216 /* limits */
 217         struct rlimit rlim[RLIM_NLIMITS];
 218         unsigned short used_math;
 219         char comm[16];
 220 /* file system info */
 221         int link_count;
 222         struct tty_struct *tty; /* NULL if no tty */
 223 /* ipc stuff */
 224         struct sem_undo *semundo;
 225         struct sem_queue *semsleeping;
 226 /* ldt for this task - used by Wine.  If NULL, default_ldt is used */
 227         struct desc_struct *ldt;
 228 /* tss for this task */
 229         struct thread_struct tss;
 230 /* filesystem information */
 231         struct fs_struct *fs;
 232 /* open file information */
 233         struct files_struct *files;
 234 /* memory management info */
 235         struct mm_struct *mm;
 236 /* signal handlers */
 237         struct signal_struct *sig;
 238 #ifdef __SMP__
 239         int processor;
 240         int last_processor;
 241         int lock_depth;         /* Lock depth. We can context switch in and out of holding a syscall kernel lock... */  
 242 #endif  
 243 };
 244 
 245 /*
 246  * Per process flags
 247  */
 248 #define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
 249                                         /* Not implemented yet, only for 486*/
 250 #define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
 251 #define PF_TRACESYS     0x00000020      /* tracing system calls */
 252 
 253 #define PF_STARTING     0x00000100      /* being created */
 254 #define PF_EXITING      0x00000200      /* getting shut down */
 255 
 256 #define PF_USEDFPU      0x00100000      /* Process used the FPU this quantum (SMP only) */
 257 
 258 /*
 259  * Limit the stack by to some sane default: root can always
 260  * increase this limit if needed..  8MB seems reasonable.
 261  */
 262 #define _STK_LIM        (8*1024*1024)
 263 
 264 #define DEF_PRIORITY    (20*HZ/100)     /* 200 ms time slices */
 265 
 266 /*
 267  *  INIT_TASK is used to set up the first task table, touch at
 268  * your own risk!. Base=0, limit=0x1fffff (=2MB)
 269  */
 270 #define INIT_TASK \
 271 /* state etc */ { 0,DEF_PRIORITY,DEF_PRIORITY,0,0,0,0, \
 272 /* debugregs */ { 0, },            \
 273 /* exec domain */&default_exec_domain, \
 274 /* binfmt */    NULL, \
 275 /* schedlink */ &init_task,&init_task, &init_task, &init_task, \
 276 /* stack */     0,(unsigned long) &init_kernel_stack, \
 277 /* ec,brk... */ 0,0,0,0,0, \
 278 /* pid etc.. */ 0,0,0,0,0, \
 279 /* suppl grps*/ {NOGROUP,}, \
 280 /* proc links*/ &init_task,&init_task,NULL,NULL,NULL,NULL, \
 281 /* uid etc */   0,0,0,0,0,0,0,0, \
 282 /* timeout */   0,SCHED_OTHER,0,0,0,0,0,0,0, \
 283 /* timer */     { NULL, NULL, 0, 0, it_real_fn }, \
 284 /* utime */     0,0,0,0,0, \
 285 /* flt */       0,0,0,0,0,0, \
 286 /* swp */       0,0,0,0,0, \
 287 /* rlimits */   INIT_RLIMITS, \
 288 /* math */      0, \
 289 /* comm */      "swapper", \
 290 /* fs info */   0,NULL, \
 291 /* ipc */       NULL, NULL, \
 292 /* ldt */       NULL, \
 293 /* tss */       INIT_TSS, \
 294 /* fs */        &init_fs, \
 295 /* files */     &init_files, \
 296 /* mm */        &init_mm, \
 297 /* signals */   &init_signals, \
 298 }
 299 
 300 extern struct   mm_struct init_mm;
 301 extern struct task_struct init_task;
 302 extern struct task_struct *task[NR_TASKS];
 303 extern struct task_struct *last_task_used_math;
 304 extern struct task_struct *current_set[NR_CPUS];
 305 /*
 306  *      On a single processor system this comes out as current_set[0] when cpp
 307  *      has finished with it, which gcc will optimise away.
 308  */
 309 #define current (0+current_set[smp_processor_id()])     /* Current on this processor */
 310 extern unsigned long volatile jiffies;
 311 extern unsigned long itimer_ticks;
 312 extern unsigned long itimer_next;
 313 extern struct timeval xtime;
 314 extern int need_resched;
 315 extern void do_timer(struct pt_regs *);
 316 
 317 extern unsigned long * prof_buffer;
 318 extern unsigned long prof_len;
 319 extern unsigned long prof_shift;
 320 
 321 extern int securelevel; /* system security level */
 322 
 323 #define CURRENT_TIME (xtime.tv_sec)
 324 
 325 extern void sleep_on(struct wait_queue ** p);
 326 extern void interruptible_sleep_on(struct wait_queue ** p);
 327 extern void wake_up(struct wait_queue ** p);
 328 extern void wake_up_interruptible(struct wait_queue ** p);
 329 extern void wake_up_process(struct task_struct * tsk);
 330 
 331 extern void notify_parent(struct task_struct * tsk);
 332 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
 333 extern int in_group_p(gid_t grp);
 334 
 335 extern int request_irq(unsigned int irq,void (*handler)(int, struct pt_regs *),
 336         unsigned long flags, const char *device);
 337 extern void free_irq(unsigned int irq);
 338 
 339 extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
 340 extern void flush_thread(void);
 341 extern void exit_thread(void);
 342 
 343 extern void exit_fs(struct task_struct *);
 344 extern void exit_files(struct task_struct *);
 345 extern void exit_sighand(struct task_struct *);
 346 extern void release_thread(struct task_struct *);
 347 
 348 extern int do_execve(char *, char **, char **, struct pt_regs *);
 349 extern int do_fork(unsigned long, unsigned long, struct pt_regs *);
 350 
 351 /*
 352  * The wait-queues are circular lists, and you have to be *very* sure
 353  * to keep them correct. Use only these two functions to add/remove
 354  * entries in the queues.
 355  */
 356 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 357 {
 358         unsigned long flags;
 359 
 360 #ifdef DEBUG
 361         if (wait->next) {
 362                 __label__ here;
 363                 unsigned long pc;
 364                 pc = (unsigned long) &&here;
 365               here:
 366                 printk("add_wait_queue (%08lx): wait->next = %08lx\n",pc,(unsigned long) wait->next);
 367         }
 368 #endif
 369         save_flags(flags);
 370         cli();
 371         if (!*p) {
 372                 wait->next = wait;
 373                 *p = wait;
 374         } else {
 375                 wait->next = (*p)->next;
 376                 (*p)->next = wait;
 377         }
 378         restore_flags(flags);
 379 }
 380 
 381 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 382 {
 383         unsigned long flags;
 384         struct wait_queue * tmp;
 385 #ifdef DEBUG
 386         unsigned long ok = 0;
 387 #endif
 388 
 389         save_flags(flags);
 390         cli();
 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         restore_flags(flags);
 410 #ifdef DEBUG
 411         if (!ok) {
 412                 __label__ here;
 413                 ok = (unsigned long) &&here;
 414                 printk("removed wait_queue not on list.\n");
 415                 printk("list = %08lx, queue = %08lx\n",(unsigned long) p, (unsigned long) wait);
 416               here:
 417                 printk("eip = %08lx\n",ok);
 418         }
 419 #endif
 420 }
 421 
 422 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
     /* [previous][next][first][last][top][bottom][index][help] */
 423 {
 424         struct select_table_entry * entry;
 425 
 426         if (!p || !wait_address)
 427                 return;
 428         if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
 429                 return;
 430         entry = p->entry + p->nr;
 431         entry->wait_address = wait_address;
 432         entry->wait.task = current;
 433         entry->wait.next = NULL;
 434         add_wait_queue(wait_address,&entry->wait);
 435         p->nr++;
 436 }
 437 
 438 extern void __down(struct semaphore * sem);
 439 
 440 /*
 441  * These are not yet interrupt-safe
 442  */
 443 extern inline void down(struct semaphore * sem)
     /* [previous][next][first][last][top][bottom][index][help] */
 444 {
 445         if (sem->count <= 0)
 446                 __down(sem);
 447         sem->count--;
 448 }
 449 
 450 extern inline void up(struct semaphore * sem)
     /* [previous][next][first][last][top][bottom][index][help] */
 451 {
 452         sem->count++;
 453         wake_up(&sem->wait);
 454 }       
 455 
 456 #define REMOVE_LINKS(p) do { unsigned long flags; \
 457         save_flags(flags) ; cli(); \
 458         (p)->next_task->prev_task = (p)->prev_task; \
 459         (p)->prev_task->next_task = (p)->next_task; \
 460         restore_flags(flags); \
 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         } while (0)
 468 
 469 #define SET_LINKS(p) do { unsigned long flags; \
 470         save_flags(flags); cli(); \
 471         (p)->next_task = &init_task; \
 472         (p)->prev_task = init_task.prev_task; \
 473         init_task.prev_task->next_task = (p); \
 474         init_task.prev_task = (p); \
 475         restore_flags(flags); \
 476         (p)->p_ysptr = NULL; \
 477         if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
 478                 (p)->p_osptr->p_ysptr = p; \
 479         (p)->p_pptr->p_cptr = p; \
 480         } while (0)
 481 
 482 #define for_each_task(p) \
 483         for (p = &init_task ; (p = p->next_task) != &init_task ; )
 484 
 485 #endif /* __KERNEL__ */
 486 
 487 #endif

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