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