OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [linux/] [sched.h] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1633 jcastillo
#ifndef _LINUX_SCHED_H
2
#define _LINUX_SCHED_H
3
 
4
/*
5
 * define DEBUG if you want the wait-queues to have some extra
6
 * debugging code. It's not normally used, but might catch some
7
 * wait-queue coding errors.
8
 *
9
 *  #define DEBUG
10
 */
11
 
12
/*
13
 * uClinux revisions for NO_MM
14
 * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
15
 *                     The Silver Hammer Group, Ltd.
16
 */
17
 
18
#include <asm/param.h>  /* for HZ */
19
 
20
extern unsigned long event;
21
 
22
#include <linux/binfmts.h>
23
#include <linux/personality.h>
24
#include <linux/tasks.h>
25
#include <linux/kernel.h>
26
 
27
#include <asm/system.h>
28
#include <asm/semaphore.h>
29
#include <asm/page.h>
30
#include <asm/signal.h>
31
 
32
#include <linux/smp.h>
33
#include <linux/tty.h>
34
#include <linux/sem.h>
35
 
36
/*
37
 * cloning flags:
38
 */
39
#define CSIGNAL         0x000000ff      /* signal mask to be sent at exit */
40
#define CLONE_VM        0x00000100      /* set if VM shared between processes */
41
#define CLONE_FS        0x00000200      /* set if fs info shared between processes */
42
#define CLONE_FILES     0x00000400      /* set if open files shared between processes */
43
#define CLONE_SIGHAND   0x00000800      /* set if signal handlers shared */
44
#define CLONE_PID       0x00001000      /* set if pid shared */
45
 
46
#define CLONE_WAIT      0x00002000      /* set if parent should wait for child to exec or exit */
47
 
48
/*
49
 * These are the constant used to fake the fixed-point load-average
50
 * counting. Some notes:
51
 *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
52
 *    a load-average precision of 10 bits integer + 11 bits fractional
53
 *  - if you want to count load-averages more often, you need more
54
 *    precision, or rounding will get you. With 2-second counting freq,
55
 *    the EXP_n values would be 1981, 2034 and 2043 if still using only
56
 *    11 bit fractions.
57
 */
58
extern unsigned long avenrun[];         /* Load averages */
59
 
60
#define FSHIFT          11              /* nr of bits of precision */
61
#define FIXED_1         (1<<FSHIFT)     /* 1.0 as fixed-point */
62
#define LOAD_FREQ       (5*HZ)          /* 5 sec intervals */
63
#define EXP_1           1884            /* 1/exp(5sec/1min) as fixed-point */
64
#define EXP_5           2014            /* 1/exp(5sec/5min) */
65
#define EXP_15          2037            /* 1/exp(5sec/15min) */
66
 
67
#define CALC_LOAD(load,exp,n) \
68
        load *= exp; \
69
        load += n*(FIXED_1-exp); \
70
        load >>= FSHIFT;
71
 
72
#define CT_TO_SECS(x)   ((x) / HZ)
73
#define CT_TO_USECS(x)  (((x) % HZ) * 1000000/HZ)
74
 
75
extern int nr_running, nr_tasks;
76
extern int last_pid;
77
 
78
#define FIRST_TASK task[0]
79
#define LAST_TASK task[NR_TASKS-1]
80
 
81
#include <linux/head.h>
82
#include <linux/fs.h>
83
#include <linux/signal.h>
84
#include <linux/time.h>
85
#include <linux/param.h>
86
#include <linux/resource.h>
87
#include <linux/ptrace.h>
88
#include <linux/timer.h>
89
 
90
#include <asm/processor.h>
91
 
92
#define TASK_RUNNING            0
93
#define TASK_INTERRUPTIBLE      1
94
#define TASK_UNINTERRUPTIBLE    2
95
#define TASK_ZOMBIE             3
96
#define TASK_STOPPED            4
97
#define TASK_SWAPPING           5
98
 
99
/*
100
 * Scheduling policies
101
 */
102
#define SCHED_OTHER             0
103
#define SCHED_FIFO              1
104
#define SCHED_RR                2
105
 
106
struct sched_param {
107
        int sched_priority;
108
};
109
 
110
#ifndef NULL
111
#define NULL ((void *) 0)
112
#endif
113
 
114
#ifdef __KERNEL__
115
 
116
extern void sched_init(void);
117
extern void show_state(void);
118
extern void trap_init(void);
119
 
120
asmlinkage void schedule(void);
121
 
122
/* Open file table structure */
123
struct files_struct {
124
        int count;
125
        fd_set close_on_exec;
126
        fd_set open_fds;
127
        struct file * fd[NR_OPEN];
128
};
129
 
130
#define INIT_FILES { \
131
        1, \
132
        { { 0, } }, \
133
        { { 0, } }, \
134
        { NULL, } \
135
}
136
 
137
struct fs_struct {
138
        int count;
139
        unsigned short umask;
140
        struct inode * root, * pwd;
141
};
142
 
143
#define INIT_FS { \
144
        1, \
145
        0022, \
146
        NULL, NULL \
147
}
148
 
149
#ifndef NO_MM
150
struct mm_struct {
151
        int count;
152
        pgd_t * pgd;
153
        unsigned long context;
154
        unsigned long start_code, end_code, start_data, end_data;
155
        unsigned long start_brk, brk, start_stack, start_mmap;
156
        unsigned long arg_start, arg_end, env_start, env_end;
157
        unsigned long rss, total_vm, locked_vm;
158
        unsigned long def_flags;
159
        struct vm_area_struct * mmap;
160
        struct vm_area_struct * mmap_avl;
161
        struct semaphore mmap_sem;
162
};
163
 
164
#define INIT_MM { \
165
                1, \
166
                swapper_pg_dir, \
167
                0, \
168
                0, 0, 0, 0, \
169
                0, 0, 0, 0, \
170
                0, 0, 0, 0, \
171
                0, 0, 0, \
172
                0, \
173
                &init_mmap, &init_mmap, MUTEX }
174
#else /* NO_MM */
175
struct mm_rblock_struct {
176
        int size;
177
        int refcount;
178
        void * kblock;
179
};
180
struct mm_tblock_struct {
181
        struct mm_rblock_struct * rblock;
182
        struct mm_tblock_struct * next;
183
};
184
struct mm_struct {
185
        int count;
186
        unsigned long context;
187
        unsigned long start_code, end_code, start_data, end_data;
188
        unsigned long start_brk, brk, start_stack, start_mmap;
189
        unsigned long arg_start, arg_end, env_start, env_end;
190
        unsigned long rss, total_vm, locked_vm;
191
        unsigned long def_flags;
192
        struct wait_queue * vforkwait;
193
        struct inode * executable;
194
        struct mm_tblock_struct tblock;
195
};
196
 
197
#define INIT_MM { \
198
                1, \
199
                0, \
200
                0, 0, 0, 0, \
201
                0, 0, 0, 0, \
202
                0, 0, 0, 0, \
203
                0, 0, 0, \
204
                0, \
205
                0, \
206
                0, \
207
                { 0, 0} }
208
#endif /* NO_MM */
209
 
210
 
211
struct signal_struct {
212
        int count;
213
        struct sigaction action[NSIG];
214
};
215
 
216
#define INIT_SIGNALS { \
217
                1, \
218
                { {0,}, } }
219
 
220
struct task_struct {
221
/* these are hardcoded - don't touch */
222
        volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
223
        long counter;
224
        long priority;
225
        unsigned long signal;
226
        unsigned long blocked;  /* bitmap of masked signals */
227
        unsigned long flags;    /* per process flags, defined below */
228
        int errno;
229
        long debugreg[8];  /* Hardware debugging registers */
230
        struct exec_domain *exec_domain;
231
/* various fields */
232
        struct linux_binfmt *binfmt;
233
        struct task_struct *next_task, *prev_task;
234
        struct task_struct *next_run,  *prev_run;
235
        unsigned long saved_kernel_stack;
236
        unsigned long kernel_stack_page;
237
        int exit_code, exit_signal;
238
        /* ??? */
239
        unsigned long personality;
240
        int dumpable:1;
241
        int did_exec:1;
242
        /* shouldn't this be pid_t? */
243
        int pid;
244
        int pgrp;
245
        int tty_old_pgrp;
246
        int session;
247
        /* boolean value for session group leader */
248
        int leader;
249
        int     groups[NGROUPS];
250
        /*
251
         * pointers to (original) parent process, youngest child, younger sibling,
252
         * older sibling, respectively.  (p->father can be replaced with
253
         * p->p_pptr->pid)
254
         */
255
        struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
256
        struct wait_queue *wait_chldexit;       /* for wait4() */
257
        unsigned short uid,euid,suid,fsuid;
258
        unsigned short gid,egid,sgid,fsgid;
259
        unsigned long timeout, policy, rt_priority;
260
        unsigned long it_real_value, it_prof_value, it_virt_value;
261
        unsigned long it_real_incr, it_prof_incr, it_virt_incr;
262
        struct timer_list real_timer;
263
        long utime, stime, cutime, cstime, start_time;
264
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
265
        unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
266
        int swappable:1;
267
        unsigned long swap_address;
268
        unsigned long old_maj_flt;      /* old value of maj_flt */
269
        unsigned long dec_flt;          /* page fault count of the last time */
270
        unsigned long swap_cnt;         /* number of pages to swap on next pass */
271
/* limits */
272
        struct rlimit rlim[RLIM_NLIMITS];
273
        unsigned short used_math;
274
        char comm[16];
275
/* file system info */
276
        int link_count;
277
        struct tty_struct *tty; /* NULL if no tty */
278
/* ipc stuff */
279
        struct sem_undo *semundo;
280
        struct sem_queue *semsleeping;
281
/* ldt for this task - used by Wine.  If NULL, default_ldt is used */
282
        struct desc_struct *ldt;
283
/* tss for this task */
284
        struct thread_struct tss;
285
/* filesystem information */
286
        struct fs_struct *fs;
287
/* open file information */
288
        struct files_struct *files;
289
/* memory management info */
290
        struct mm_struct *mm;
291
/* signal handlers */
292
        struct signal_struct *sig;
293
#ifdef __SMP__
294
        int processor;
295
        int last_processor;
296
        int lock_depth;         /* Lock depth. We can context switch in and out of holding a syscall kernel lock... */
297
#endif  
298
};
299
 
300
/*
301
 * Per process flags
302
 */
303
#define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
304
                                        /* Not implemented yet, only for 486*/
305
#define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
306
#define PF_TRACESYS     0x00000020      /* tracing system calls */
307
#define PF_FORKNOEXEC   0x00000040      /* forked but didn't exec */
308
#define PF_SUPERPRIV    0x00000100      /* used super-user privileges */
309
#define PF_DUMPCORE     0x00000200      /* dumped core */
310
#define PF_SIGNALED     0x00000400      /* killed by a signal */
311
 
312
#define PF_STARTING     0x00000002      /* being created */
313
#define PF_EXITING      0x00000004      /* getting shut down */
314
 
315
#define PF_USEDFPU      0x00100000      /* Process used the FPU this quantum (SMP only) */
316
#define PF_DTRACE       0x00200000      /* delayed trace (used on m68k) */
317
#define PF_ONSIGSTK     0x00400000      /* works on signal stack (m68k only) */
318
 
319
/*
320
 * Limit the stack by to some sane default: root can always
321
 * increase this limit if needed..  8MB seems reasonable.
322
 */
323
#define _STK_LIM        (8*1024*1024)
324
 
325
#define DEF_PRIORITY    (20*HZ/100)     /* 200 ms time slices */
326
 
327
/*
328
 *  INIT_TASK is used to set up the first task table, touch at
329
 * your own risk!. Base=0, limit=0x1fffff (=2MB)
330
 */
331
#define INIT_TASK \
332
/* state etc */ { 0,DEF_PRIORITY,DEF_PRIORITY,0,0,0,0, \
333
/* debugregs */ { 0, },            \
334
/* exec domain */&default_exec_domain, \
335
/* binfmt */    NULL, \
336
/* schedlink */ &init_task,&init_task, &init_task, &init_task, \
337
/* stack */     0,(unsigned long) &init_kernel_stack, \
338
/* ec,brk... */ 0,0,0,0,0, \
339
/* pid etc.. */ 0,0,0,0,0, \
340
/* suppl grps*/ {NOGROUP,}, \
341
/* proc links*/ &init_task,&init_task,NULL,NULL,NULL,NULL, \
342
/* uid etc */   0,0,0,0,0,0,0,0, \
343
/* timeout */   0,SCHED_OTHER,0,0,0,0,0,0,0, \
344
/* timer */     { NULL, NULL, 0, 0, it_real_fn }, \
345
/* utime */     0,0,0,0,0, \
346
/* flt */       0,0,0,0,0,0, \
347
/* swp */       0,0,0,0,0, \
348
/* rlimits */   INIT_RLIMITS, \
349
/* math */      0, \
350
/* comm */      "swapper", \
351
/* fs info */   0,NULL, \
352
/* ipc */       NULL, NULL, \
353
/* ldt */       NULL, \
354
/* tss */       INIT_TSS, \
355
/* fs */        &init_fs, \
356
/* files */     &init_files, \
357
/* mm */        &init_mm, \
358
/* signals */   &init_signals, \
359
}
360
 
361
extern struct   mm_struct init_mm;
362
extern struct task_struct init_task;
363
extern struct task_struct *task[NR_TASKS];
364
extern struct task_struct *last_task_used_math;
365
extern struct task_struct *current_set[NR_CPUS];
366
/*
367
 *      On a single processor system this comes out as current_set[0] when cpp
368
 *      has finished with it, which gcc will optimise away.
369
 */
370
#define current (0+current_set[smp_processor_id()])     /* Current on this processor */
371
extern unsigned long volatile jiffies;
372
extern unsigned long itimer_ticks;
373
extern unsigned long itimer_next;
374
/* SIMON: firbidden change of source file - won't compile with gcc 3.1 */
375
extern volatile struct timeval xtime;
376
extern int need_resched;
377
extern void do_timer(struct pt_regs *);
378
 
379
extern unsigned int * prof_buffer;
380
extern unsigned long prof_len;
381
extern unsigned long prof_shift;
382
 
383
extern int securelevel; /* system security level */
384
 
385
#define CURRENT_TIME (xtime.tv_sec)
386
 
387
extern void sleep_on(struct wait_queue ** p);
388
extern void interruptible_sleep_on(struct wait_queue ** p);
389
extern void wake_up(struct wait_queue ** p);
390
extern void wake_up_interruptible(struct wait_queue ** p);
391
extern void wake_up_process(struct task_struct * tsk);
392
 
393
extern void notify_parent(struct task_struct * tsk, int signal);
394
extern void force_sig(unsigned long sig,struct task_struct * p);
395
extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
396
extern int in_group_p(gid_t grp);
397
 
398
extern int request_irq(unsigned int irq,
399
                       void (*handler)(int, void *, struct pt_regs *),
400
                       unsigned long flags,
401
                       const char *device,
402
                       void *dev_id);
403
extern void free_irq(unsigned int irq, void *dev_id);
404
 
405
/*
406
 * This has now become a routine instead of a macro, it sets a flag if
407
 * it returns true (to do BSD-style accounting where the process is flagged
408
 * if it uses root privs). The implication of this is that you should do
409
 * normal permissions checks first, and check suser() last.
410
 */
411
extern inline int suser(void)
412
{
413
        if (current->euid == 0) {
414
                current->flags |= PF_SUPERPRIV;
415
                return 1;
416
        }
417
        return 0;
418
}
419
 
420
extern void copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
421
extern void flush_thread(void);
422
extern void exit_thread(void);
423
 
424
extern void exit_mm(struct task_struct *);
425
extern void exit_fs(struct task_struct *);
426
extern void exit_files(struct task_struct *);
427
extern void exit_sighand(struct task_struct *);
428
extern void release_thread(struct task_struct *);
429
 
430
extern int do_execve(char *, char **, char **, struct pt_regs *);
431
extern int do_fork(unsigned long, unsigned long, struct pt_regs *);
432
 
433
 
434
/* See if we have a valid user level fd.
435
 * If it makes sense, return the file structure it references.
436
 * Otherwise return NULL.
437
 */
438
extern inline struct file *file_from_fd(const unsigned int fd)
439
{
440
 
441
        if (fd >= NR_OPEN)
442
                return NULL;
443
        /* either valid or null */
444
        return current->files->fd[fd];
445
}
446
 
447
/*
448
 * The wait-queues are circular lists, and you have to be *very* sure
449
 * to keep them correct. Use only these two functions to add/remove
450
 * entries in the queues.
451
 */
452
extern inline void __add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
453
{
454
        struct wait_queue *head = *p;
455
        struct wait_queue *next = WAIT_QUEUE_HEAD(p);
456
 
457
        if (head)
458
                next = head;
459
        *p = wait;
460
        wait->next = next;
461
}
462
 
463
extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
464
{
465
        unsigned long flags;
466
 
467
        save_flags(flags);
468
        cli();
469
        __add_wait_queue(p, wait);
470
        restore_flags(flags);
471
}
472
 
473
extern inline void __remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
474
{
475
        struct wait_queue * next = wait->next;
476
        struct wait_queue * head = next;
477
 
478
        for (;;) {
479
                struct wait_queue * nextlist = head->next;
480
                if (nextlist == wait)
481
                        break;
482
                head = nextlist;
483
        }
484
        head->next = next;
485
}
486
 
487
extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
488
{
489
        unsigned long flags;
490
 
491
        save_flags(flags);
492
        cli();
493
        __remove_wait_queue(p, wait);
494
        restore_flags(flags);
495
}
496
 
497
extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
498
{
499
        struct select_table_entry * entry;
500
 
501
        if (!p || !wait_address)
502
                return;
503
        if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
504
                return;
505
        entry = p->entry + p->nr;
506
        entry->wait_address = wait_address;
507
        entry->wait.task = current;
508
        entry->wait.next = NULL;
509
        add_wait_queue(wait_address,&entry->wait);
510
        p->nr++;
511
}
512
 
513
#define REMOVE_LINKS(p) do { unsigned long flags; \
514
        save_flags(flags) ; cli(); \
515
        (p)->next_task->prev_task = (p)->prev_task; \
516
        (p)->prev_task->next_task = (p)->next_task; \
517
        restore_flags(flags); \
518
        if ((p)->p_osptr) \
519
                (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
520
        if ((p)->p_ysptr) \
521
                (p)->p_ysptr->p_osptr = (p)->p_osptr; \
522
        else \
523
                (p)->p_pptr->p_cptr = (p)->p_osptr; \
524
        } while (0)
525
 
526
#define SET_LINKS(p) do { unsigned long flags; \
527
        save_flags(flags); cli(); \
528
        (p)->next_task = &init_task; \
529
        (p)->prev_task = init_task.prev_task; \
530
        init_task.prev_task->next_task = (p); \
531
        init_task.prev_task = (p); \
532
        restore_flags(flags); \
533
        (p)->p_ysptr = NULL; \
534
        if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
535
                (p)->p_osptr->p_ysptr = p; \
536
        (p)->p_pptr->p_cptr = p; \
537
        } while (0)
538
 
539
#define for_each_task(p) \
540
        for (p = &init_task ; (p = p->next_task) != &init_task ; )
541
 
542
#endif /* __KERNEL__ */
543
 
544
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.