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
5
6
7
8
9
10
11
12
13 #define HZ 100
14
15 #include <linux/tasks.h>
16
17
18
19
20
21 #define TASK_SIZE 0xc0000000
22
23
24
25
26 #define IO_BITMAP_SIZE 32
27
28
29
30
31
32
33
34
35
36
37
38 extern unsigned long avenrun[];
39
40 #define FSHIFT 11
41 #define FIXED_1 (1<<FSHIFT)
42 #define LOAD_FREQ (5*HZ)
43 #define EXP_1 1884
44 #define EXP_5 2014
45 #define EXP_15 2037
46
47 #define CALC_LOAD(load,exp,n) \
48 load *= exp; \
49 load += n*(FIXED_1-exp); \
50 load >>= FSHIFT;
51
52 #define CT_TO_SECS(x) ((x) / HZ)
53 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
54
55 #define FIRST_TASK task[0]
56 #define LAST_TASK task[NR_TASKS-1]
57
58 #include <linux/head.h>
59 #include <linux/fs.h>
60 #include <linux/mm.h>
61 #include <linux/signal.h>
62 #include <linux/time.h>
63 #include <linux/param.h>
64 #include <linux/resource.h>
65 #include <linux/vm86.h>
66 #include <linux/math_emu.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 #define MAX_SHARED_LIBS 16
80
81 extern void sched_init(void);
82 extern void show_state(void);
83 extern void schedule(void);
84 extern void trap_init(void);
85 extern void panic(const char * str);
86
87 typedef int (*fn_ptr)();
88
89 union i387_union {
90 struct i387_hard_struct {
91 long cwd;
92 long swd;
93 long twd;
94 long fip;
95 long fcs;
96 long foo;
97 long fos;
98 long st_space[20];
99 } hard;
100 struct i387_soft_struct {
101 long cwd;
102 long swd;
103 long twd;
104 long fip;
105 long fcs;
106 long foo;
107 long fos;
108 long top;
109 struct fpu_reg regs[8];
110 unsigned char lookahead;
111 struct info *info;
112 unsigned long entry_eip;
113 } soft;
114 };
115
116 struct tss_struct {
117 unsigned long back_link;
118 unsigned long esp0;
119 unsigned long ss0;
120 unsigned long esp1;
121 unsigned long ss1;
122 unsigned long esp2;
123 unsigned long ss2;
124 unsigned long cr3;
125 unsigned long eip;
126 unsigned long eflags;
127 unsigned long eax,ecx,edx,ebx;
128 unsigned long esp;
129 unsigned long ebp;
130 unsigned long esi;
131 unsigned long edi;
132 unsigned long es;
133 unsigned long cs;
134 unsigned long ss;
135 unsigned long ds;
136 unsigned long fs;
137 unsigned long gs;
138 unsigned long ldt;
139 unsigned long trace_bitmap;
140 unsigned long io_bitmap[IO_BITMAP_SIZE];
141 union i387_union i387;
142 };
143
144 struct task_struct {
145
146 long state;
147 long counter;
148 long priority;
149 unsigned long signal;
150 unsigned long blocked;
151 unsigned long flags;
152 int errno;
153
154 struct sigaction sigaction[32];
155 unsigned long saved_kernel_stack;
156 unsigned long kernel_stack_page;
157 int exit_code;
158 int dumpable:1;
159 int swappable:1;
160 unsigned long start_code,end_code,end_data,brk,start_stack;
161 unsigned long arg_start, arg_end, env_start, env_end;
162 long pid,pgrp,session,leader;
163 int groups[NGROUPS];
164
165
166
167
168
169 struct task_struct *p_opptr,*p_pptr, *p_cptr, *p_ysptr, *p_osptr;
170
171
172
173
174 unsigned short uid,euid,suid;
175 unsigned short gid,egid,sgid;
176 unsigned long timeout;
177 unsigned long it_real_value, it_prof_value, it_virt_value;
178 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
179 long utime,stime,cutime,cstime,start_time;
180 unsigned long min_flt, maj_flt;
181 unsigned long cmin_flt, cmaj_flt;
182 struct rlimit rlim[RLIM_NLIMITS];
183 unsigned short used_math;
184 unsigned short rss;
185 char comm[16];
186 struct vm86_struct * vm86_info;
187 unsigned long screen_bitmap;
188
189 int link_count;
190 int tty;
191 unsigned short umask;
192 struct inode * pwd;
193 struct inode * root;
194 struct inode * executable;
195 struct vm_area_struct * mmap;
196 struct {
197 struct inode * library;
198 unsigned long start;
199 unsigned long length;
200 unsigned long bss;
201 } libraries[MAX_SHARED_LIBS];
202 int numlibraries;
203 struct file * filp[NR_OPEN];
204 fd_set close_on_exec;
205
206 struct desc_struct ldt[32];
207
208 struct tss_struct tss;
209 };
210
211
212
213
214 #define PF_ALIGNWARN 0x00000001
215
216 #define PF_PTRACED 0x00000010
217 #define PF_TRACESYS 0x00000020
218
219
220
221
222
223 #define INIT_TASK \
224 { 0,15,15,0,0,0,0, \
225 {{ 0, },}, \
226 0,0, \
227 0,0,0,0,0,0,0,0, \
228 0,0,0,0, \
229 0,0,0,0, \
230 {NOGROUP,}, \
231 &init_task,&init_task,NULL,NULL,NULL, \
232 0,0,0,0,0,0, \
233 0,0,0,0,0,0,0,0,0,0,0,0, \
234 0,0,0,0, \
235 { {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
236 {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
237 {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}}, \
238 0, \
239 2, \
240 "swapper", \
241 NULL, 0, \
242 0,-1,0022,NULL,NULL,NULL,NULL, \
243 { { NULL, 0, 0, 0}, }, 0, \
244 {NULL,}, \
245 {{ 0, }}, \
246 { \
247 {0,0}, \
248 {0x1ff,0xc0c0fa00}, \
249 {0x1ff,0xc0c0f200}, \
250 }, \
251 {0,sizeof(init_kernel_stack) + (long) &init_kernel_stack, \
252 0x10,0,0,0,0,(long) &swapper_pg_dir,\
253 0,0,0,0,0,0,0,0, \
254 0,0,0x17,0x17,0x17,0x17,0x17,0x17, \
255 _LDT(0),0x80000000,{0xffffffff}, \
256 { { 0, }, } \
257 } \
258 }
259
260 extern struct task_struct *task[NR_TASKS];
261 extern struct task_struct *last_task_used_math;
262 extern struct task_struct *current;
263 extern unsigned long volatile jiffies;
264 extern unsigned long startup_time;
265 extern int jiffies_offset;
266 extern int need_resched;
267 extern int hard_math;
268 extern int ignore_irq13;
269
270 #define CURRENT_TIME (startup_time+(jiffies+jiffies_offset)/HZ)
271
272 extern void add_timer(long jiffies, void (*fn)(void));
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
279 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
280 extern int in_group_p(gid_t grp);
281
282 extern int request_irq(unsigned int irq,void (*handler)(int));
283 extern void free_irq(unsigned int irq);
284 extern int irqaction(unsigned int irq,struct sigaction * new);
285
286
287
288
289
290 #define FIRST_TSS_ENTRY 4
291 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
292 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
293 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
294 #define load_TR(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
295 #define load_ldt(n) __asm__("lldt %%ax"::"a" (_LDT(n)))
296 #define store_TR(n) \
297 __asm__("str %%ax\n\t" \
298 "subl %2,%%eax\n\t" \
299 "shrl $4,%%eax" \
300 :"=a" (n) \
301 :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
302
303
304
305
306
307
308 #define switch_to(n) {\
309 struct {long a,b;} __tmp; \
310 __asm__("cmpl %%ecx,_current\n\t" \
311 "je 1f\n\t" \
312 "movw %%dx,%1\n\t" \
313 "cli\n\t" \
314 "xchgl %%ecx,_current\n\t" \
315 "ljmp %0\n\t" \
316 "sti\n\t" \
317 "cmpl %%ecx,_last_task_used_math\n\t" \
318 "jne 1f\n\t" \
319 "clts\n" \
320 "1:" \
321 ::"m" (*&__tmp.a),"m" (*&__tmp.b), \
322 "d" (_TSS(n)),"c" ((long) task[n]) \
323 :"cx"); \
324 }
325
326 #define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000)
327
328 #define _set_base(addr,base) \
329 __asm__("movw %%dx,%0\n\t" \
330 "rorl $16,%%edx\n\t" \
331 "movb %%dl,%1\n\t" \
332 "movb %%dh,%2" \
333 ::"m" (*((addr)+2)), \
334 "m" (*((addr)+4)), \
335 "m" (*((addr)+7)), \
336 "d" (base) \
337 :"dx")
338
339 #define _set_limit(addr,limit) \
340 __asm__("movw %%dx,%0\n\t" \
341 "rorl $16,%%edx\n\t" \
342 "movb %1,%%dh\n\t" \
343 "andb $0xf0,%%dh\n\t" \
344 "orb %%dh,%%dl\n\t" \
345 "movb %%dl,%1" \
346 ::"m" (*(addr)), \
347 "m" (*((addr)+6)), \
348 "d" (limit) \
349 :"dx")
350
351 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
352 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
353
354
355
356
357
358
359 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
360 {
361 unsigned long flags;
362
363 #ifdef DEBUG
364 if (wait->next) {
365 unsigned long pc;
366 __asm__ __volatile__("call 1f\n"
367 "1:\tpopl %0":"=r" (pc));
368 printk("add_wait_queue (%08x): wait->next = %08x\n",pc,wait->next);
369 }
370 #endif
371 __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
372 if (!*p) {
373 wait->next = wait;
374 *p = wait;
375 } else {
376 wait->next = (*p)->next;
377 (*p)->next = wait;
378 }
379 __asm__ __volatile__("pushl %0 ; popfl"::"r" (flags));
380 }
381
382 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
383 {
384 unsigned long flags;
385 struct wait_queue * tmp;
386 #ifdef DEBUG
387 unsigned long ok = 0;
388 #endif
389
390 __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
391 if ((*p == wait) &&
392 #ifdef DEBUG
393 (ok = 1) &&
394 #endif
395 ((*p = wait->next) == wait)) {
396 *p = NULL;
397 } else {
398 tmp = wait;
399 while (tmp->next != wait) {
400 tmp = tmp->next;
401 #ifdef DEBUG
402 if (tmp == *p)
403 ok = 1;
404 #endif
405 }
406 tmp->next = wait->next;
407 }
408 wait->next = NULL;
409 __asm__ __volatile__("pushl %0 ; popfl"::"r" (flags));
410 #ifdef DEBUG
411 if (!ok) {
412 printk("removed wait_queue not on list.\n");
413 printk("list = %08x, queue = %08x\n",p,wait);
414 __asm__("call 1f\n1:\tpopl %0":"=r" (ok));
415 printk("eip = %08x\n",ok);
416 }
417 #endif
418 }
419
420 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
421 {
422 struct select_table_entry * entry;
423
424 if (!p || !wait_address)
425 return;
426 if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
427 return;
428 entry = p->entry + p->nr;
429 entry->wait_address = wait_address;
430 entry->wait.task = current;
431 entry->wait.next = NULL;
432 add_wait_queue(wait_address,&entry->wait);
433 p->nr++;
434 }
435
436 static inline unsigned long _get_base(char * addr)
437 {
438 unsigned long __base;
439 __asm__("movb %3,%%dh\n\t"
440 "movb %2,%%dl\n\t"
441 "shll $16,%%edx\n\t"
442 "movw %1,%%dx"
443 :"=&d" (__base)
444 :"m" (*((addr)+2)),
445 "m" (*((addr)+4)),
446 "m" (*((addr)+7)));
447 return __base;
448 }
449
450 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
451
452 static inline unsigned long get_limit(unsigned long segment)
453 {
454 unsigned long __limit;
455 __asm__("lsll %1,%0"
456 :"=r" (__limit):"r" (segment));
457 return __limit+1;
458 }
459
460 #define REMOVE_LINKS(p) \
461 if ((p)->p_osptr) \
462 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
463 if ((p)->p_ysptr) \
464 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
465 else \
466 (p)->p_pptr->p_cptr = (p)->p_osptr
467
468 #define SET_LINKS(p) \
469 (p)->p_ysptr = NULL; \
470 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
471 (p)->p_osptr->p_ysptr = p; \
472 (p)->p_pptr->p_cptr = p
473
474 #endif