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

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