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
23
24
25
26
27
28
29
30
31
32
33 extern unsigned long avenrun[];
34
35 #define FSHIFT 11
36 #define FIXED_1 (1<<FSHIFT)
37 #define LOAD_FREQ (5*HZ)
38 #define EXP_1 1884
39 #define EXP_5 2014
40 #define EXP_15 2037
41
42 #define CALC_LOAD(load,exp,n) \
43 load *= exp; \
44 load += n*(FIXED_1-exp); \
45 load >>= FSHIFT;
46
47 #define CT_TO_SECS(x) ((x) / HZ)
48 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
49
50 extern int nr_running, nr_tasks;
51
52 #define FIRST_TASK task[0]
53 #define LAST_TASK task[NR_TASKS-1]
54
55 #include <linux/head.h>
56 #include <linux/fs.h>
57 #include <linux/signal.h>
58 #include <linux/time.h>
59 #include <linux/param.h>
60 #include <linux/resource.h>
61 #include <linux/vm86.h>
62 #include <linux/math_emu.h>
63 #include <linux/ptrace.h>
64
65 #include <asm/processor.h>
66
67 #define TASK_RUNNING 0
68 #define TASK_INTERRUPTIBLE 1
69 #define TASK_UNINTERRUPTIBLE 2
70 #define TASK_ZOMBIE 3
71 #define TASK_STOPPED 4
72 #define TASK_SWAPPING 5
73
74 #ifndef NULL
75 #define NULL ((void *) 0)
76 #endif
77
78 #ifdef __KERNEL__
79
80 extern void sched_init(void);
81 extern void show_state(void);
82 extern void trap_init(void);
83
84 asmlinkage void schedule(void);
85
86 #endif
87
88 struct files_struct {
89 int count;
90 fd_set close_on_exec;
91 struct file * fd[NR_OPEN];
92 };
93
94 #define INIT_FILES { \
95 0, \
96 { { 0, } }, \
97 { NULL, } \
98 }
99
100 struct fs_struct {
101 int count;
102 unsigned short umask;
103 struct inode * root, * pwd;
104 };
105
106 #define INIT_FS { \
107 0, \
108 0022, \
109 NULL, NULL \
110 }
111
112 struct mm_struct {
113 int count;
114 unsigned long start_code, end_code, end_data;
115 unsigned long start_brk, brk, start_stack, start_mmap;
116 unsigned long arg_start, arg_end, env_start, env_end;
117 unsigned long rss;
118 unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
119 int swappable:1;
120 unsigned long swap_address;
121 unsigned long old_maj_flt;
122 unsigned long dec_flt;
123 unsigned long swap_cnt;
124 struct vm_area_struct * mmap;
125 struct vm_area_struct * mmap_avl;
126 };
127
128 #define INIT_MM { \
129 0, \
130 0, 0, 0, \
131 0, 0, 0, 0, \
132 0, 0, 0, 0, \
133 0, \
134 0, 0, 0, 0, \
135 0, \
136 0, 0, 0, 0, \
137 &init_mmap, &init_mmap }
138
139 struct task_struct {
140
141 volatile long state;
142 long counter;
143 long priority;
144 unsigned long signal;
145 unsigned long blocked;
146 unsigned long flags;
147 int errno;
148 int debugreg[8];
149 struct exec_domain *exec_domain;
150
151 struct linux_binfmt *binfmt;
152 struct task_struct *next_task, *prev_task;
153 struct sigaction sigaction[32];
154 unsigned long saved_kernel_stack;
155 unsigned long kernel_stack_page;
156 int exit_code, exit_signal;
157 unsigned long personality;
158 int dumpable:1;
159 int did_exec:1;
160 int pid,pgrp,tty_old_pgrp,session,leader;
161 int groups[NGROUPS];
162
163
164
165
166
167 struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
168 struct wait_queue *wait_chldexit;
169 unsigned short uid,euid,suid,fsuid;
170 unsigned short gid,egid,sgid,fsgid;
171 unsigned long timeout;
172 unsigned long it_real_value, it_prof_value, it_virt_value;
173 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
174 long utime, stime, cutime, cstime, start_time;
175 struct rlimit rlim[RLIM_NLIMITS];
176 unsigned short used_math;
177 char comm[16];
178
179 int link_count;
180 struct tty_struct *tty;
181
182 struct sem_undo *semundo;
183 struct sem_queue *semsleeping;
184
185 struct desc_struct *ldt;
186
187 struct thread_struct tss;
188
189 struct fs_struct fs[1];
190
191 struct files_struct files[1];
192
193 struct mm_struct mm[1];
194 };
195
196
197
198
199 #define PF_ALIGNWARN 0x00000001
200
201 #define PF_PTRACED 0x00000010
202 #define PF_TRACESYS 0x00000020
203
204 #define PF_STARTING 0x00000100
205 #define PF_EXITING 0x00000200
206
207
208
209
210 #define CSIGNAL 0x000000ff
211 #define COPYVM 0x00000100
212 #define COPYFD 0x00000200
213
214
215
216
217
218 #define INIT_TASK \
219 { 0,15,15,0,0,0,0, \
220 { 0, }, \
221 &default_exec_domain, \
222 NULL, \
223 &init_task,&init_task, \
224 {{ 0, },}, \
225 0,(unsigned long) &init_kernel_stack, \
226 0,0,0,0,0, \
227 0,0,0,0,0, \
228 {NOGROUP,}, \
229 &init_task,&init_task,NULL,NULL,NULL,NULL, \
230 0,0,0,0,0,0,0,0, \
231 0,0,0,0,0,0,0,0,0,0,0,0, \
232 { {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX}, \
233 {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX}, \
234 { 0, LONG_MAX}, {LONG_MAX, LONG_MAX}, \
235 {MAX_TASKS_PER_USER, MAX_TASKS_PER_USER}, {NR_OPEN, NR_OPEN}}, \
236 0, \
237 "swapper", \
238 0,NULL, \
239 NULL, NULL, \
240 NULL, \
241 INIT_TSS, \
242 { INIT_FS }, \
243 { INIT_FILES }, \
244 { INIT_MM } \
245 }
246
247 #ifdef __KERNEL__
248
249 extern struct task_struct init_task;
250 extern struct task_struct *task[NR_TASKS];
251 extern struct task_struct *last_task_used_math;
252 extern struct task_struct *current;
253 extern unsigned long volatile jiffies;
254 extern unsigned long itimer_ticks;
255 extern unsigned long itimer_next;
256 extern struct timeval xtime;
257 extern int need_resched;
258
259 #define CURRENT_TIME (xtime.tv_sec)
260
261 extern void sleep_on(struct wait_queue ** p);
262 extern void interruptible_sleep_on(struct wait_queue ** p);
263 extern void wake_up(struct wait_queue ** p);
264 extern void wake_up_interruptible(struct wait_queue ** p);
265
266 extern void notify_parent(struct task_struct * tsk);
267 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
268 extern int in_group_p(gid_t grp);
269
270 extern int request_irq(unsigned int irq,void (*handler)(int, struct pt_regs *),
271 unsigned long flags, const char *device);
272 extern void free_irq(unsigned int irq);
273
274 extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
275 extern void flush_thread(void);
276 extern void exit_thread(void);
277
278 extern int do_execve(char *, char **, char **, struct pt_regs *);
279 extern int do_fork(unsigned long, unsigned long, struct pt_regs *);
280 asmlinkage int do_signal(unsigned long, struct pt_regs *);
281
282
283
284
285
286
287 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
288 {
289 unsigned long flags;
290
291 #ifdef DEBUG
292 if (wait->next) {
293 unsigned long pc;
294 __asm__ __volatile__("call 1f\n"
295 "1:\tpopl %0":"=r" (pc));
296 printk("add_wait_queue (%08x): wait->next = %08x\n",pc,(unsigned long) wait->next);
297 }
298 #endif
299 save_flags(flags);
300 cli();
301 if (!*p) {
302 wait->next = wait;
303 *p = wait;
304 } else {
305 wait->next = (*p)->next;
306 (*p)->next = wait;
307 }
308 restore_flags(flags);
309 }
310
311 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
312 {
313 unsigned long flags;
314 struct wait_queue * tmp;
315 #ifdef DEBUG
316 unsigned long ok = 0;
317 #endif
318
319 save_flags(flags);
320 cli();
321 if ((*p == wait) &&
322 #ifdef DEBUG
323 (ok = 1) &&
324 #endif
325 ((*p = wait->next) == wait)) {
326 *p = NULL;
327 } else {
328 tmp = wait;
329 while (tmp->next != wait) {
330 tmp = tmp->next;
331 #ifdef DEBUG
332 if (tmp == *p)
333 ok = 1;
334 #endif
335 }
336 tmp->next = wait->next;
337 }
338 wait->next = NULL;
339 restore_flags(flags);
340 #ifdef DEBUG
341 if (!ok) {
342 printk("removed wait_queue not on list.\n");
343 printk("list = %08x, queue = %08x\n",(unsigned long) p, (unsigned long) wait);
344 __asm__("call 1f\n1:\tpopl %0":"=r" (ok));
345 printk("eip = %08x\n",ok);
346 }
347 #endif
348 }
349
350 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
351 {
352 struct select_table_entry * entry;
353
354 if (!p || !wait_address)
355 return;
356 if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
357 return;
358 entry = p->entry + p->nr;
359 entry->wait_address = wait_address;
360 entry->wait.task = current;
361 entry->wait.next = NULL;
362 add_wait_queue(wait_address,&entry->wait);
363 p->nr++;
364 }
365
366 extern void __down(struct semaphore * sem);
367
368
369
370
371 extern inline void down(struct semaphore * sem)
372 {
373 if (sem->count <= 0)
374 __down(sem);
375 sem->count--;
376 }
377
378 extern inline void up(struct semaphore * sem)
379 {
380 sem->count++;
381 wake_up(&sem->wait);
382 }
383
384 #define REMOVE_LINKS(p) do { unsigned long flags; \
385 save_flags(flags) ; cli(); \
386 (p)->next_task->prev_task = (p)->prev_task; \
387 (p)->prev_task->next_task = (p)->next_task; \
388 restore_flags(flags); \
389 if ((p)->p_osptr) \
390 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
391 if ((p)->p_ysptr) \
392 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
393 else \
394 (p)->p_pptr->p_cptr = (p)->p_osptr; \
395 } while (0)
396
397 #define SET_LINKS(p) do { unsigned long flags; \
398 save_flags(flags); cli(); \
399 (p)->next_task = &init_task; \
400 (p)->prev_task = init_task.prev_task; \
401 init_task.prev_task->next_task = (p); \
402 init_task.prev_task = (p); \
403 restore_flags(flags); \
404 (p)->p_ysptr = NULL; \
405 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
406 (p)->p_osptr->p_ysptr = p; \
407 (p)->p_pptr->p_cptr = p; \
408 } while (0)
409
410 #define for_each_task(p) \
411 for (p = &init_task ; (p = p->next_task) != &init_task ; )
412
413 #endif
414
415 #endif