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