This source file includes following definitions.
- add_wait_queue
- remove_wait_queue
- select_wait
- _get_base
- get_limit
1 #ifndef _LINUX_SCHED_H
2 #define _LINUX_SCHED_H
3
4 #define NEW_SWAP
5
6
7
8
9
10
11
12
13
14 #define HZ 100
15
16 #include <linux/tasks.h>
17 #include <asm/system.h>
18
19
20
21
22
23 #define TASK_SIZE 0xc0000000
24
25
26
27
28 #define IO_BITMAP_SIZE 32
29
30
31
32
33
34
35
36
37
38
39
40 extern unsigned long avenrun[];
41
42 #define FSHIFT 11
43 #define FIXED_1 (1<<FSHIFT)
44 #define LOAD_FREQ (5*HZ)
45 #define EXP_1 1884
46 #define EXP_5 2014
47 #define EXP_15 2037
48
49 #define CALC_LOAD(load,exp,n) \
50 load *= exp; \
51 load += n*(FIXED_1-exp); \
52 load >>= FSHIFT;
53
54 #define CT_TO_SECS(x) ((x) / HZ)
55 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
56
57 #define FIRST_TASK task[0]
58 #define LAST_TASK task[NR_TASKS-1]
59
60 #include <linux/head.h>
61 #include <linux/fs.h>
62 #include <linux/mm.h>
63 #include <linux/signal.h>
64 #include <linux/time.h>
65 #include <linux/param.h>
66 #include <linux/resource.h>
67 #include <linux/vm86.h>
68 #include <linux/math_emu.h>
69
70 #define TASK_RUNNING 0
71 #define TASK_INTERRUPTIBLE 1
72 #define TASK_UNINTERRUPTIBLE 2
73 #define TASK_ZOMBIE 3
74 #define TASK_STOPPED 4
75 #define TASK_SWAPPING 5
76
77 #ifndef NULL
78 #define NULL ((void *) 0)
79 #endif
80
81 #ifdef __KERNEL__
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 i387_hard_struct {
92 long cwd;
93 long swd;
94 long twd;
95 long fip;
96 long fcs;
97 long foo;
98 long fos;
99 long st_space[20];
100 };
101
102 struct i387_soft_struct {
103 long cwd;
104 long swd;
105 long twd;
106 long fip;
107 long fcs;
108 long foo;
109 long fos;
110 long top;
111 struct fpu_reg regs[8];
112 unsigned char lookahead;
113 struct info *info;
114 unsigned long entry_eip;
115 };
116
117 union i387_union {
118 struct i387_hard_struct hard;
119 struct i387_soft_struct soft;
120 };
121
122 struct tss_struct {
123 unsigned short back_link,__blh;
124 unsigned long esp0;
125 unsigned short ss0,__ss0h;
126 unsigned long esp1;
127 unsigned short ss1,__ss1h;
128 unsigned long esp2;
129 unsigned short ss2,__ss2h;
130 unsigned long cr3;
131 unsigned long eip;
132 unsigned long eflags;
133 unsigned long eax,ecx,edx,ebx;
134 unsigned long esp;
135 unsigned long ebp;
136 unsigned long esi;
137 unsigned long edi;
138 unsigned short es, __esh;
139 unsigned short cs, __csh;
140 unsigned short ss, __ssh;
141 unsigned short ds, __dsh;
142 unsigned short fs, __fsh;
143 unsigned short gs, __gsh;
144 unsigned short ldt, __ldth;
145 unsigned short trace, bitmap;
146 unsigned long io_bitmap[IO_BITMAP_SIZE+1];
147 unsigned long tr;
148 unsigned long cr2;
149 union i387_union i387;
150 };
151
152 struct task_struct {
153
154 long state;
155 long counter;
156 long priority;
157 unsigned long signal;
158 unsigned long blocked;
159 unsigned long flags;
160 int errno;
161 int debugreg[8];
162
163 struct task_struct *next_task, *prev_task;
164 struct sigaction sigaction[32];
165 unsigned long saved_kernel_stack;
166 unsigned long kernel_stack_page;
167 int exit_code, exit_signal;
168 int elf_executable:1;
169 int dumpable:1;
170 int swappable:1;
171 unsigned long start_code,end_code,end_data,start_brk,brk,start_stack,start_mmap;
172 unsigned long arg_start, arg_end, env_start, env_end;
173 int pid,pgrp,session,leader;
174 int groups[NGROUPS];
175
176
177
178
179
180 struct task_struct *p_opptr,*p_pptr, *p_cptr, *p_ysptr, *p_osptr;
181 struct wait_queue *wait_chldexit;
182
183
184
185
186 unsigned short uid,euid,suid;
187 unsigned short gid,egid,sgid;
188 unsigned long timeout;
189 unsigned long it_real_value, it_prof_value, it_virt_value;
190 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
191 long utime,stime,cutime,cstime,start_time;
192 unsigned long min_flt, maj_flt;
193 unsigned long cmin_flt, cmaj_flt;
194 struct rlimit rlim[RLIM_NLIMITS];
195 unsigned short used_math;
196 unsigned short rss;
197 char comm[16];
198 struct vm86_struct * vm86_info;
199 unsigned long screen_bitmap;
200
201 int link_count;
202 int tty;
203 unsigned short umask;
204 struct inode * pwd;
205 struct inode * root;
206 struct inode * executable;
207 struct vm_area_struct * mmap;
208 struct shm_desc *shm;
209 struct sem_undo *semun;
210 struct file * filp[NR_OPEN];
211 fd_set close_on_exec;
212
213 struct desc_struct *ldt;
214
215 struct tss_struct tss;
216 #ifdef NEW_SWAP
217 unsigned long old_maj_flt;
218 unsigned long dec_flt;
219 unsigned long swap_cnt;
220 short swap_table;
221 short swap_page;
222 #endif NEW_SWAP
223 struct vm_area_struct *stk_vma;
224 };
225
226
227
228
229 #define PF_ALIGNWARN 0x00000001
230
231 #define PF_PTRACED 0x00000010
232 #define PF_TRACESYS 0x00000020
233
234
235
236
237 #define CSIGNAL 0x000000ff
238 #define COPYVM 0x00000100
239 #define COPYFD 0x00000200
240
241
242
243
244
245 #define INIT_TASK \
246 { 0,15,15,0,0,0,0, \
247 { 0, }, \
248 &init_task,&init_task, \
249 {{ 0, },}, \
250 0,(unsigned long) &init_kernel_stack, \
251 0,0,0,0,0,0,0,0,0,0,0,0, \
252 0,0,0,0, \
253 0,0,0,0, \
254 {NOGROUP,}, \
255 &init_task,&init_task,NULL,NULL,NULL,NULL, \
256 0,0,0,0,0,0, \
257 0,0,0,0,0,0,0,0,0,0,0,0, \
258 0,0,0,0, \
259 { {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX}, \
260 {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX}, \
261 { 0, LONG_MAX}, {LONG_MAX, LONG_MAX}}, \
262 0, \
263 2, \
264 "swapper", \
265 NULL, 0, \
266 0,-1,0022,NULL,NULL,NULL,NULL, \
267 NULL, NULL, \
268 {NULL,}, \
269 {{ 0, }}, \
270 NULL, \
271 {0,0, \
272 sizeof(init_kernel_stack) + (long) &init_kernel_stack, KERNEL_DS, 0, \
273 0,0,0,0,0,0, \
274 (long) &swapper_pg_dir, \
275 0,0,0,0,0,0,0,0,0,0, \
276 USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0, \
277 _LDT(0),0, \
278 0, 0x8000, \
279 {~0, }, \
280 _TSS(0), 0, \
281 { { 0, }, } \
282 } \
283 }
284
285 extern struct task_struct init_task;
286 extern struct task_struct *task[NR_TASKS];
287 extern struct task_struct *last_task_used_math;
288 extern struct task_struct *current;
289 extern unsigned long volatile jiffies;
290 extern struct timeval xtime;
291 extern int need_resched;
292
293 extern int hard_math;
294 extern int x86;
295 extern int ignore_irq13;
296 extern int wp_works_ok;
297
298 #define CURRENT_TIME (xtime.tv_sec)
299
300 extern void sleep_on(struct wait_queue ** p);
301 extern void interruptible_sleep_on(struct wait_queue ** p);
302 extern void wake_up(struct wait_queue ** p);
303 extern void wake_up_interruptible(struct wait_queue ** p);
304
305 extern void notify_parent(struct task_struct * tsk);
306 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
307 extern int in_group_p(gid_t grp);
308
309 extern int request_irq(unsigned int irq,void (*handler)(int));
310 extern void free_irq(unsigned int irq);
311 extern int irqaction(unsigned int irq,struct sigaction * sa);
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326 #define FIRST_TSS_ENTRY 8
327 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
328 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
329 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
330 #define load_TR(n) __asm__("ltr %%ax": :"a" (_TSS(n)))
331 #define load_ldt(n) __asm__("lldt %%ax": :"a" (_LDT(n)))
332 #define store_TR(n) \
333 __asm__("str %%ax\n\t" \
334 "subl %2,%%eax\n\t" \
335 "shrl $4,%%eax" \
336 :"=a" (n) \
337 :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
338
339
340
341
342
343
344 #define switch_to(tsk) \
345 __asm__("cmpl %%ecx,_current\n\t" \
346 "je 1f\n\t" \
347 "cli\n\t" \
348 "xchgl %%ecx,_current\n\t" \
349 "ljmp %0\n\t" \
350 "sti\n\t" \
351 "cmpl %%ecx,_last_task_used_math\n\t" \
352 "jne 1f\n\t" \
353 "clts\n" \
354 "1:" \
355 : \
356 :"m" (*(((char *)&tsk->tss.tr)-4)), \
357 "c" (tsk) \
358 :"cx")
359
360 #define _set_base(addr,base) \
361 __asm__("movw %%dx,%0\n\t" \
362 "rorl $16,%%edx\n\t" \
363 "movb %%dl,%1\n\t" \
364 "movb %%dh,%2" \
365 : \
366 :"m" (*((addr)+2)), \
367 "m" (*((addr)+4)), \
368 "m" (*((addr)+7)), \
369 "d" (base) \
370 :"dx")
371
372 #define _set_limit(addr,limit) \
373 __asm__("movw %%dx,%0\n\t" \
374 "rorl $16,%%edx\n\t" \
375 "movb %1,%%dh\n\t" \
376 "andb $0xf0,%%dh\n\t" \
377 "orb %%dh,%%dl\n\t" \
378 "movb %%dl,%1" \
379 : \
380 :"m" (*(addr)), \
381 "m" (*((addr)+6)), \
382 "d" (limit) \
383 :"dx")
384
385 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
386 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
387
388
389
390
391
392
393 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
394 {
395 unsigned long flags;
396
397 #ifdef DEBUG
398 if (wait->next) {
399 unsigned long pc;
400 __asm__ __volatile__("call 1f\n"
401 "1:\tpopl %0":"=r" (pc));
402 printk("add_wait_queue (%08x): wait->next = %08x\n",pc,(unsigned long) wait->next);
403 }
404 #endif
405 save_flags(flags);
406 cli();
407 if (!*p) {
408 wait->next = wait;
409 *p = wait;
410 } else {
411 wait->next = (*p)->next;
412 (*p)->next = wait;
413 }
414 restore_flags(flags);
415 }
416
417 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
418 {
419 unsigned long flags;
420 struct wait_queue * tmp;
421 #ifdef DEBUG
422 unsigned long ok = 0;
423 #endif
424
425 save_flags(flags);
426 cli();
427 if ((*p == wait) &&
428 #ifdef DEBUG
429 (ok = 1) &&
430 #endif
431 ((*p = wait->next) == wait)) {
432 *p = NULL;
433 } else {
434 tmp = wait;
435 while (tmp->next != wait) {
436 tmp = tmp->next;
437 #ifdef DEBUG
438 if (tmp == *p)
439 ok = 1;
440 #endif
441 }
442 tmp->next = wait->next;
443 }
444 wait->next = NULL;
445 restore_flags(flags);
446 #ifdef DEBUG
447 if (!ok) {
448 printk("removed wait_queue not on list.\n");
449 printk("list = %08x, queue = %08x\n",(unsigned long) p, (unsigned long) wait);
450 __asm__("call 1f\n1:\tpopl %0":"=r" (ok));
451 printk("eip = %08x\n",ok);
452 }
453 #endif
454 }
455
456 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
457 {
458 struct select_table_entry * entry;
459
460 if (!p || !wait_address)
461 return;
462 if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
463 return;
464 entry = p->entry + p->nr;
465 entry->wait_address = wait_address;
466 entry->wait.task = current;
467 entry->wait.next = NULL;
468 add_wait_queue(wait_address,&entry->wait);
469 p->nr++;
470 }
471
472 static inline unsigned long _get_base(char * addr)
473 {
474 unsigned long __base;
475 __asm__("movb %3,%%dh\n\t"
476 "movb %2,%%dl\n\t"
477 "shll $16,%%edx\n\t"
478 "movw %1,%%dx"
479 :"=&d" (__base)
480 :"m" (*((addr)+2)),
481 "m" (*((addr)+4)),
482 "m" (*((addr)+7)));
483 return __base;
484 }
485
486 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
487
488 static inline unsigned long get_limit(unsigned long segment)
489 {
490 unsigned long __limit;
491 __asm__("lsll %1,%0"
492 :"=r" (__limit):"r" (segment));
493 return __limit+1;
494 }
495
496 #define REMOVE_LINKS(p) do { unsigned long flags; \
497 save_flags(flags) ; cli(); \
498 (p)->next_task->prev_task = (p)->prev_task; \
499 (p)->prev_task->next_task = (p)->next_task; \
500 restore_flags(flags); \
501 if ((p)->p_osptr) \
502 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
503 if ((p)->p_ysptr) \
504 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
505 else \
506 (p)->p_pptr->p_cptr = (p)->p_osptr; \
507 } while (0)
508
509 #define SET_LINKS(p) do { unsigned long flags; \
510 save_flags(flags); cli(); \
511 (p)->next_task = &init_task; \
512 (p)->prev_task = init_task.prev_task; \
513 init_task.prev_task->next_task = (p); \
514 init_task.prev_task = (p); \
515 restore_flags(flags); \
516 (p)->p_ysptr = NULL; \
517 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
518 (p)->p_osptr->p_ysptr = p; \
519 (p)->p_pptr->p_cptr = p; \
520 } while (0)
521
522 #define for_each_task(p) \
523 for (p = &init_task ; (p = p->next_task) != &init_task ; )
524
525
526
527
528
529 extern struct desc_struct default_ldt;
530
531
532
533 #define loaddebug(register) \
534 __asm__("movl %0,%%edx\n\t" \
535 "movl %%edx,%%db" #register "\n\t" \
536 : \
537 :"m" (current->debugreg[register]) \
538 :"dx");
539
540 #endif