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