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