Version:  2.0.40 2.2.26 2.4.37 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10

Linux/include/linux/sched.h

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

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us