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

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