This source file includes following definitions.
- add_wait_queue
- remove_wait_queue
- select_wait
- down
- up
1 #ifndef _LINUX_SCHED_H
2 #define _LINUX_SCHED_H
3
4
5
6
7
8
9
10
11
12 #include <asm/param.h>
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
28
29 #define CSIGNAL 0x000000ff
30 #define CLONE_VM 0x00000100
31 #define CLONE_FS 0x00000200
32 #define CLONE_FILES 0x00000400
33 #define CLONE_SIGHAND 0x00000800
34 #define CLONE_PID 0x00001000
35
36
37
38
39
40
41
42
43
44
45
46 extern unsigned long avenrun[];
47
48 #define FSHIFT 11
49 #define FIXED_1 (1<<FSHIFT)
50 #define LOAD_FREQ (5*HZ)
51 #define EXP_1 1884
52 #define EXP_5 2014
53 #define EXP_15 2037
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
90
91 #define SCHED_OTHER 0
92 #define SCHED_FIFO 1
93 #define SCHED_RR 2
94
95 struct sched_param {
96 int sched_priority;
97 };
98
99 #ifndef NULL
100 #define NULL ((void *) 0)
101 #endif
102
103 #ifdef __KERNEL__
104
105 #define barrier() __asm__("": : :"memory")
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 struct files_struct {
114 int count;
115 fd_set close_on_exec;
116 struct file * fd[NR_OPEN];
117 };
118
119 #define INIT_FILES { \
120 1, \
121 { { 0, } }, \
122 { NULL, } \
123 }
124
125 struct fs_struct {
126 int count;
127 unsigned short umask;
128 struct inode * root, * pwd;
129 };
130
131 #define INIT_FS { \
132 1, \
133 0022, \
134 NULL, NULL \
135 }
136
137 struct mm_struct {
138 int count;
139 pgd_t * pgd;
140 unsigned long context;
141 unsigned long start_code, end_code, start_data, end_data;
142 unsigned long start_brk, brk, start_stack, start_mmap;
143 unsigned long arg_start, arg_end, env_start, env_end;
144 unsigned long rss, total_vm, locked_vm;
145 unsigned long def_flags;
146 struct vm_area_struct * mmap;
147 struct vm_area_struct * mmap_avl;
148 };
149
150 #define INIT_MM { \
151 1, \
152 swapper_pg_dir, \
153 0, \
154 0, 0, 0, 0, \
155 0, 0, 0, 0, \
156 0, 0, 0, 0, \
157 0, 0, 0, \
158 0, \
159 &init_mmap, &init_mmap }
160
161 struct signal_struct {
162 int count;
163 struct sigaction action[32];
164 };
165
166 #define INIT_SIGNALS { \
167 1, \
168 { {0,}, } }
169
170 struct task_struct {
171
172 volatile long state;
173 long counter;
174 long priority;
175 unsigned long signal;
176 unsigned long blocked;
177 unsigned long flags;
178 int errno;
179 long debugreg[8];
180 struct exec_domain *exec_domain;
181
182 struct linux_binfmt *binfmt;
183 struct task_struct *next_task, *prev_task;
184 struct task_struct *next_run, *prev_run;
185 unsigned long saved_kernel_stack;
186 unsigned long kernel_stack_page;
187 int exit_code, exit_signal;
188 unsigned long personality;
189 int dumpable:1;
190 int did_exec:1;
191 int pid,pgrp,tty_old_pgrp,session,leader;
192 int groups[NGROUPS];
193
194
195
196
197
198 struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
199 struct wait_queue *wait_chldexit;
200 unsigned short uid,euid,suid,fsuid;
201 unsigned short gid,egid,sgid,fsgid;
202 unsigned long timeout, policy, rt_priority;
203 unsigned long it_real_value, it_prof_value, it_virt_value;
204 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
205 struct timer_list real_timer;
206 long utime, stime, cutime, cstime, start_time;
207
208 unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
209 int swappable:1;
210 unsigned long swap_address;
211 unsigned long old_maj_flt;
212 unsigned long dec_flt;
213 unsigned long swap_cnt;
214
215 struct rlimit rlim[RLIM_NLIMITS];
216 unsigned short used_math;
217 char comm[16];
218
219 int link_count;
220 struct tty_struct *tty;
221
222 struct sem_undo *semundo;
223 struct sem_queue *semsleeping;
224
225 struct desc_struct *ldt;
226
227 struct thread_struct tss;
228
229 struct fs_struct *fs;
230
231 struct files_struct *files;
232
233 struct mm_struct *mm;
234
235 struct signal_struct *sig;
236 #ifdef __SMP__
237 int processor;
238 int last_processor;
239 int lock_depth;
240 #endif
241 };
242
243
244
245
246 #define PF_ALIGNWARN 0x00000001
247
248 #define PF_PTRACED 0x00000010
249 #define PF_TRACESYS 0x00000020
250
251 #define PF_STARTING 0x00000100
252 #define PF_EXITING 0x00000200
253
254 #define PF_USEDFPU 0x00100000
255
256
257
258
259
260 #define _STK_LIM (8*1024*1024)
261
262 #define DEF_PRIORITY (20*HZ/100)
263
264
265
266
267
268 #define INIT_TASK \
269 { 0,DEF_PRIORITY,DEF_PRIORITY,0,0,0,0, \
270 { 0, }, \
271 &default_exec_domain, \
272 NULL, \
273 &init_task,&init_task, &init_task, &init_task, \
274 0,(unsigned long) &init_kernel_stack, \
275 0,0,0,0,0, \
276 0,0,0,0,0, \
277 {NOGROUP,}, \
278 &init_task,&init_task,NULL,NULL,NULL,NULL, \
279 0,0,0,0,0,0,0,0, \
280 0,SCHED_OTHER,0,0,0,0,0,0,0, \
281 { NULL, NULL, 0, 0, it_real_fn }, \
282 0,0,0,0,0, \
283 0,0,0,0,0,0, \
284 0,0,0,0,0, \
285 INIT_RLIMITS, \
286 0, \
287 "swapper", \
288 0,NULL, \
289 NULL, NULL, \
290 NULL, \
291 INIT_TSS, \
292 &init_fs, \
293 &init_files, \
294 &init_mm, \
295 &init_signals, \
296 }
297
298 extern struct mm_struct init_mm;
299 extern struct task_struct init_task;
300 extern struct task_struct *task[NR_TASKS];
301 extern struct task_struct *last_task_used_math;
302 extern struct task_struct *current_set[NR_CPUS];
303
304
305
306
307 #define current (0+current_set[smp_processor_id()])
308 extern unsigned long volatile jiffies;
309 extern unsigned long itimer_ticks;
310 extern unsigned long itimer_next;
311 extern struct timeval xtime;
312 extern int need_resched;
313 extern void do_timer(struct pt_regs *);
314
315 extern unsigned long * prof_buffer;
316 extern unsigned long prof_len;
317 extern unsigned long prof_shift;
318
319 extern int securelevel;
320
321 #define CURRENT_TIME (xtime.tv_sec)
322
323 extern void sleep_on(struct wait_queue ** p);
324 extern void interruptible_sleep_on(struct wait_queue ** p);
325 extern void wake_up(struct wait_queue ** p);
326 extern void wake_up_interruptible(struct wait_queue ** p);
327 extern void wake_up_process(struct task_struct * tsk);
328
329 extern void notify_parent(struct task_struct * tsk);
330 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
331 extern int in_group_p(gid_t grp);
332
333 extern int request_irq(unsigned int irq,void (*handler)(int, struct pt_regs *),
334 unsigned long flags, const char *device);
335 extern void free_irq(unsigned int irq);
336
337 extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
338 extern void flush_thread(void);
339 extern void exit_thread(void);
340
341 extern void exit_fs(struct task_struct *);
342 extern void exit_files(struct task_struct *);
343 extern void exit_sighand(struct task_struct *);
344 extern void release_thread(struct task_struct *);
345
346 extern int do_execve(char *, char **, char **, struct pt_regs *);
347 extern int do_fork(unsigned long, unsigned long, struct pt_regs *);
348
349
350
351
352
353
354 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
355 {
356 unsigned long flags;
357
358 #ifdef DEBUG
359 if (wait->next) {
360 __label__ here;
361 unsigned long pc;
362 pc = (unsigned long) &&here;
363 here:
364 printk("add_wait_queue (%08lx): wait->next = %08lx\n",pc,(unsigned long) wait->next);
365 }
366 #endif
367 save_flags(flags);
368 cli();
369 if (!*p) {
370 wait->next = wait;
371 *p = wait;
372 } else {
373 wait->next = (*p)->next;
374 (*p)->next = wait;
375 }
376 restore_flags(flags);
377 }
378
379 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
380 {
381 unsigned long flags;
382 struct wait_queue * tmp;
383 #ifdef DEBUG
384 unsigned long ok = 0;
385 #endif
386
387 save_flags(flags);
388 cli();
389 if ((*p == wait) &&
390 #ifdef DEBUG
391 (ok = 1) &&
392 #endif
393 ((*p = wait->next) == wait)) {
394 *p = NULL;
395 } else {
396 tmp = wait;
397 while (tmp->next != wait) {
398 tmp = tmp->next;
399 #ifdef DEBUG
400 if (tmp == *p)
401 ok = 1;
402 #endif
403 }
404 tmp->next = wait->next;
405 }
406 wait->next = NULL;
407 restore_flags(flags);
408 #ifdef DEBUG
409 if (!ok) {
410 __label__ here;
411 ok = (unsigned long) &&here;
412 printk("removed wait_queue not on list.\n");
413 printk("list = %08lx, queue = %08lx\n",(unsigned long) p, (unsigned long) wait);
414 here:
415 printk("eip = %08lx\n",ok);
416 }
417 #endif
418 }
419
420 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
421 {
422 struct select_table_entry * entry;
423
424 if (!p || !wait_address)
425 return;
426 if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
427 return;
428 entry = p->entry + p->nr;
429 entry->wait_address = wait_address;
430 entry->wait.task = current;
431 entry->wait.next = NULL;
432 add_wait_queue(wait_address,&entry->wait);
433 p->nr++;
434 }
435
436 extern void __down(struct semaphore * sem);
437
438
439
440
441 extern inline void down(struct semaphore * sem)
442 {
443 if (sem->count <= 0)
444 __down(sem);
445 sem->count--;
446 }
447
448 extern inline void up(struct semaphore * sem)
449 {
450 sem->count++;
451 wake_up(&sem->wait);
452 }
453
454 #define REMOVE_LINKS(p) do { unsigned long flags; \
455 save_flags(flags) ; cli(); \
456 (p)->next_task->prev_task = (p)->prev_task; \
457 (p)->prev_task->next_task = (p)->next_task; \
458 restore_flags(flags); \
459 if ((p)->p_osptr) \
460 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
461 if ((p)->p_ysptr) \
462 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
463 else \
464 (p)->p_pptr->p_cptr = (p)->p_osptr; \
465 } while (0)
466
467 #define SET_LINKS(p) do { unsigned long flags; \
468 save_flags(flags); cli(); \
469 (p)->next_task = &init_task; \
470 (p)->prev_task = init_task.prev_task; \
471 init_task.prev_task->next_task = (p); \
472 init_task.prev_task = (p); \
473 restore_flags(flags); \
474 (p)->p_ysptr = NULL; \
475 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
476 (p)->p_osptr->p_ysptr = p; \
477 (p)->p_pptr->p_cptr = p; \
478 } while (0)
479
480 #define for_each_task(p) \
481 for (p = &init_task ; (p = p->next_task) != &init_task ; )
482
483 #endif
484
485 #endif