source: branches/minix3-book/kernel/proc.h@ 25

Last change on this file since 25 was 4, checked in by Mattia Monga, 14 years ago

Importazione sorgenti libro

File size: 4.4 KB
Line 
1#ifndef PROC_H
2#define PROC_H
3
4/* Here is the declaration of the process table. It contains all process
5 * data, including registers, flags, scheduling priority, memory map,
6 * accounting, message passing (IPC) information, and so on.
7 *
8 * Many assembly code routines reference fields in it. The offsets to these
9 * fields are defined in the assembler include file sconst.h. When changing
10 * struct proc, be sure to change sconst.h to match.
11 */
12#include <minix/com.h>
13#include "protect.h"
14#include "const.h"
15#include "priv.h"
16
17struct proc {
18 struct stackframe_s p_reg; /* process' registers saved in stack frame */
19 reg_t p_ldt_sel; /* selector in gdt with ldt base and limit */
20 struct segdesc_s p_ldt[2+NR_REMOTE_SEGS]; /* CS, DS and remote segments */
21
22 proc_nr_t p_nr; /* number of this process (for fast access) */
23 struct priv *p_priv; /* system privileges structure */
24 char p_rts_flags; /* SENDING, RECEIVING, etc. */
25
26 char p_priority; /* current scheduling priority */
27 char p_max_priority; /* maximum scheduling priority */
28 char p_ticks_left; /* number of scheduling ticks left */
29 char p_quantum_size; /* quantum size in ticks */
30
31 struct mem_map p_memmap[NR_LOCAL_SEGS]; /* memory map (T, D, S) */
32
33 clock_t p_user_time; /* user time in ticks */
34 clock_t p_sys_time; /* sys time in ticks */
35
36 struct proc *p_nextready; /* pointer to next ready process */
37 struct proc *p_caller_q; /* head of list of procs wishing to send */
38 struct proc *p_q_link; /* link to next proc wishing to send */
39 message *p_messbuf; /* pointer to passed message buffer */
40 proc_nr_t p_getfrom; /* from whom does process want to receive? */
41 proc_nr_t p_sendto; /* to whom does process want to send? */
42
43 sigset_t p_pending; /* bit map for pending kernel signals */
44
45 char p_name[P_NAME_LEN]; /* name of the process, including \0 */
46};
47
48/* Bits for the runtime flags. A process is runnable iff p_rts_flags == 0. */
49#define SLOT_FREE 0x01 /* process slot is free */
50#define NO_MAP 0x02 /* keeps unmapped forked child from running */
51#define SENDING 0x04 /* process blocked trying to SEND */
52#define RECEIVING 0x08 /* process blocked trying to RECEIVE */
53#define SIGNALED 0x10 /* set when new kernel signal arrives */
54#define SIG_PENDING 0x20 /* unready while signal being processed */
55#define P_STOP 0x40 /* set when process is being traced */
56#define NO_PRIV 0x80 /* keep forked system process from running */
57
58/* Scheduling priorities for p_priority. Values must start at zero (highest
59 * priority) and increment. Priorities of the processes in the boot image
60 * can be set in table.c. IDLE must have a queue for itself, to prevent low
61 * priority user processes to run round-robin with IDLE.
62 */
63#define NR_SCHED_QUEUES 16 /* MUST equal minimum priority + 1 */
64#define TASK_Q 0 /* highest, used for kernel tasks */
65#define MAX_USER_Q 0 /* highest priority for user processes */
66#define USER_Q 7 /* default (should correspond to nice 0) */
67#define MIN_USER_Q 14 /* minimum priority for user processes */
68#define IDLE_Q 15 /* lowest, only IDLE process goes here */
69
70/* Magic process table addresses. */
71#define BEG_PROC_ADDR (&proc[0])
72#define BEG_USER_ADDR (&proc[NR_TASKS])
73#define END_PROC_ADDR (&proc[NR_TASKS + NR_PROCS])
74
75#define NIL_PROC ((struct proc *) 0)
76#define NIL_SYS_PROC ((struct proc *) 1)
77#define cproc_addr(n) (&(proc + NR_TASKS)[(n)])
78#define proc_addr(n) (pproc_addr + NR_TASKS)[(n)]
79#define proc_nr(p) ((p)->p_nr)
80
81#define isokprocn(n) ((unsigned) ((n) + NR_TASKS) < NR_PROCS + NR_TASKS)
82#define isemptyn(n) isemptyp(proc_addr(n))
83#define isemptyp(p) ((p)->p_rts_flags == SLOT_FREE)
84#define iskernelp(p) iskerneln((p)->p_nr)
85#define iskerneln(n) ((n) < 0)
86#define isuserp(p) isusern((p)->p_nr)
87#define isusern(n) ((n) >= 0)
88
89/* The process table and pointers to process table slots. The pointers allow
90 * faster access because now a process entry can be found by indexing the
91 * pproc_addr array, while accessing an element i requires a multiplication
92 * with sizeof(struct proc) to determine the address.
93 */
94EXTERN struct proc proc[NR_TASKS + NR_PROCS]; /* process table */
95EXTERN struct proc *pproc_addr[NR_TASKS + NR_PROCS];
96EXTERN struct proc *rdy_head[NR_SCHED_QUEUES]; /* ptrs to ready list headers */
97EXTERN struct proc *rdy_tail[NR_SCHED_QUEUES]; /* ptrs to ready list tails */
98
99#endif /* PROC_H */
Note: See TracBrowser for help on using the repository browser.