root/include/linux/sched.h

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

INCLUDED FROM


DEFINITIONS

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

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