vm: merge i386 and arm pagetable code
[minix.git] / kernel / proc.h
blob0d2d9148e26acd316635fe9fd1725b84b898d1b7
1 #ifndef PROC_H
2 #define PROC_H
4 #include <minix/const.h>
5 #include <sys/cdefs.h>
7 #ifndef __ASSEMBLY__
9 /* Here is the declaration of the process table. It contains all process
10 * data, including registers, flags, scheduling priority, memory map,
11 * accounting, message passing (IPC) information, and so on.
13 * Many assembly code routines reference fields in it. The offsets to these
14 * fields are defined in the assembler include file sconst.h. When changing
15 * struct proc, be sure to change sconst.h to match.
17 #include <minix/com.h>
18 #include <minix/portio.h>
19 #include "const.h"
20 #include "priv.h"
22 struct proc {
23 struct stackframe_s p_reg; /* process' registers saved in stack frame */
24 struct segframe p_seg; /* segment descriptors */
25 proc_nr_t p_nr; /* number of this process (for fast access) */
26 struct priv *p_priv; /* system privileges structure */
27 volatile u32_t p_rts_flags; /* process is runnable only if zero */
28 volatile u32_t p_misc_flags; /* flags that do not suspend the process */
30 char p_priority; /* current process priority */
31 u64_t p_cpu_time_left; /* time left to use the cpu */
32 unsigned p_quantum_size_ms; /* assigned time quantum in ms
33 FIXME remove this */
34 struct proc *p_scheduler; /* who should get out of quantum msg */
35 unsigned p_cpu; /* what CPU is the process running on */
36 #ifdef CONFIG_SMP
37 bitchunk_t p_cpu_mask[BITMAP_CHUNKS(CONFIG_MAX_CPUS)]; /* what CPUs is hte
38 process allowed to
39 run on */
40 bitchunk_t p_stale_tlb[BITMAP_CHUNKS(CONFIG_MAX_CPUS)]; /* On which cpu are
41 possibly stale entries from this process and has
42 to be fresed the next kernel touches this
43 processes memory
45 #endif
47 /* Accounting statistics that get passed to the process' scheduler */
48 struct {
49 u64_t enter_queue; /* time when enqueued (cycles) */
50 u64_t time_in_queue; /* time spent in queue */
51 unsigned long dequeues;
52 unsigned long ipc_sync;
53 unsigned long ipc_async;
54 unsigned long preempted;
55 } p_accounting;
57 clock_t p_user_time; /* user time in ticks */
58 clock_t p_sys_time; /* sys time in ticks */
60 clock_t p_virt_left; /* number of ticks left on virtual timer */
61 clock_t p_prof_left; /* number of ticks left on profile timer */
63 u64_t p_cycles; /* how many cycles did the process use */
64 u64_t p_kcall_cycles; /* kernel cycles caused by this proc (kcall) */
65 u64_t p_kipc_cycles; /* cycles caused by this proc (ipc) */
67 struct proc *p_nextready; /* pointer to next ready process */
68 struct proc *p_caller_q; /* head of list of procs wishing to send */
69 struct proc *p_q_link; /* link to next proc wishing to send */
70 endpoint_t p_getfrom_e; /* from whom does process want to receive? */
71 endpoint_t p_sendto_e; /* to whom does process want to send? */
73 sigset_t p_pending; /* bit map for pending kernel signals */
75 char p_name[PROC_NAME_LEN]; /* name of the process, including \0 */
77 endpoint_t p_endpoint; /* endpoint number, generation-aware */
79 message p_sendmsg; /* Message from this process if SENDING */
80 message p_delivermsg; /* Message for this process if MF_DELIVERMSG */
81 vir_bytes p_delivermsg_vir; /* Virtual addr this proc wants message at */
83 /* If handler functions detect a process wants to do something with
84 * memory that isn't present, VM has to fix it. Until it has asked
85 * what needs to be done and fixed it, save necessary state here.
87 * The requestor gets a copy of its request message in reqmsg and gets
88 * VMREQUEST set.
90 struct {
91 struct proc *nextrestart; /* next in vmrestart chain */
92 struct proc *nextrequestor; /* next in vmrequest chain */
93 #define VMSTYPE_SYS_NONE 0
94 #define VMSTYPE_KERNELCALL 1
95 #define VMSTYPE_DELIVERMSG 2
96 #define VMSTYPE_MAP 3
98 int type; /* suspended operation */
99 union {
100 /* VMSTYPE_SYS_MESSAGE */
101 message reqmsg; /* suspended request message */
102 } saved;
104 /* Parameters of request to VM */
105 int req_type;
106 endpoint_t target;
107 union {
108 struct {
109 vir_bytes start, length; /* memory range */
110 u8_t writeflag; /* nonzero for write access */
111 } check;
112 } params;
113 /* VM result when available */
114 int vmresult;
116 /* If the suspended operation is a sys_call, its details are
117 * stored here.
119 } p_vmrequest;
121 int p_found; /* consistency checking variables */
122 int p_magic; /* check validity of proc pointers */
124 #if DEBUG_TRACE
125 int p_schedules;
126 #endif
129 #endif /* __ASSEMBLY__ */
131 /* Bits for the runtime flags. A process is runnable iff p_rts_flags == 0. */
132 #define RTS_SLOT_FREE 0x01 /* process slot is free */
133 #define RTS_PROC_STOP 0x02 /* process has been stopped */
134 #define RTS_SENDING 0x04 /* process blocked trying to send */
135 #define RTS_RECEIVING 0x08 /* process blocked trying to receive */
136 #define RTS_SIGNALED 0x10 /* set when new kernel signal arrives */
137 #define RTS_SIG_PENDING 0x20 /* unready while signal being processed */
138 #define RTS_P_STOP 0x40 /* set when process is being traced */
139 #define RTS_NO_PRIV 0x80 /* keep forked system process from running */
140 #define RTS_NO_ENDPOINT 0x100 /* process cannot send or receive messages */
141 #define RTS_VMINHIBIT 0x200 /* not scheduled until pagetable set by VM */
142 #define RTS_PAGEFAULT 0x400 /* process has unhandled pagefault */
143 #define RTS_VMREQUEST 0x800 /* originator of vm memory request */
144 #define RTS_VMREQTARGET 0x1000 /* target of vm memory request */
145 #define RTS_PREEMPTED 0x4000 /* this process was preempted by a higher
146 priority process and we should pick a new one
147 to run. Processes with this flag should be
148 returned to the front of their current
149 priority queue if they are still runnable
150 before we pick a new one
152 #define RTS_NO_QUANTUM 0x8000 /* process ran out of its quantum and we should
153 pick a new one. Process was dequeued and
154 should be enqueued at the end of some run
155 queue again */
156 #define RTS_BOOTINHIBIT 0x10000 /* not ready until VM has made it */
158 /* A process is runnable iff p_rts_flags == 0. */
159 #define rts_f_is_runnable(flg) ((flg) == 0)
160 #define proc_is_runnable(p) (rts_f_is_runnable((p)->p_rts_flags))
162 #define proc_is_preempted(p) ((p)->p_rts_flags & RTS_PREEMPTED)
163 #define proc_no_quantum(p) ((p)->p_rts_flags & RTS_NO_QUANTUM)
164 #define proc_ptr_ok(p) ((p)->p_magic == PMAGIC)
165 #define proc_used_fpu(p) ((p)->p_misc_flags & (MF_FPU_INITIALIZED))
167 /* test whether the process is scheduled by the kernel's default policy */
168 #define proc_kernel_scheduler(p) ((p)->p_scheduler == NULL || \
169 (p)->p_scheduler == (p))
171 /* Macro to return: on which process is a certain process blocked?
172 * return endpoint number (can be ANY) or NONE. It's important to
173 * check RTS_SENDING first, and then RTS_RECEIVING, as they could
174 * both be on (if a sendrec() blocks on sending), and p_getfrom_e
175 * could be nonsense even though RTS_RECEIVING is on.
177 #define P_BLOCKEDON(p) \
179 ((p)->p_rts_flags & RTS_SENDING) ? \
180 (p)->p_sendto_e : \
183 ((p)->p_rts_flags & RTS_RECEIVING) ? \
184 (p)->p_getfrom_e : \
185 NONE \
190 /* These runtime flags can be tested and manipulated by these macros. */
192 #define RTS_ISSET(rp, f) (((rp)->p_rts_flags & (f)) == (f))
195 /* Set flag and dequeue if the process was runnable. */
196 #define RTS_SET(rp, f) \
197 do { \
198 const int rts = (rp)->p_rts_flags; \
199 (rp)->p_rts_flags |= (f); \
200 if(rts_f_is_runnable(rts) && !proc_is_runnable(rp)) { \
201 dequeue(rp); \
203 } while(0)
205 /* Clear flag and enqueue if the process was not runnable but is now. */
206 #define RTS_UNSET(rp, f) \
207 do { \
208 int rts; \
209 rts = (rp)->p_rts_flags; \
210 (rp)->p_rts_flags &= ~(f); \
211 if(!rts_f_is_runnable(rts) && proc_is_runnable(rp)) { \
212 enqueue(rp); \
214 } while(0)
216 /* Set flags to this value. */
217 #define RTS_SETFLAGS(rp, f) \
218 do { \
219 if(proc_is_runnable(rp) && (f)) { dequeue(rp); } \
220 (rp)->p_rts_flags = (f); \
221 } while(0)
223 /* Misc flags */
224 #define MF_REPLY_PEND 0x001 /* reply to IPC_REQUEST is pending */
225 #define MF_VIRT_TIMER 0x002 /* process-virtual timer is running */
226 #define MF_PROF_TIMER 0x004 /* process-virtual profile timer is running */
227 #define MF_KCALL_RESUME 0x008 /* processing a kernel call was interrupted,
228 most likely because we need VM to resolve a
229 problem or a long running copy was preempted.
230 We need to resume the kernel call execution
233 #define MF_DELIVERMSG 0x040 /* Copy message for him before running */
234 #define MF_SIG_DELAY 0x080 /* Send signal when no longer sending */
235 #define MF_SC_ACTIVE 0x100 /* Syscall tracing: in a system call now */
236 #define MF_SC_DEFER 0x200 /* Syscall tracing: deferred system call */
237 #define MF_SC_TRACE 0x400 /* Syscall tracing: trigger syscall events */
238 #define MF_FPU_INITIALIZED 0x1000 /* process already used math, so fpu
239 * regs are significant (initialized)*/
240 #define MF_SENDING_FROM_KERNEL 0x2000 /* message of this process is from kernel */
241 #define MF_CONTEXT_SET 0x4000 /* don't touch context */
242 #define MF_SPROF_SEEN 0x8000 /* profiling has seen this process */
243 #define MF_FLUSH_TLB 0x10000 /* if set, TLB must be flushed before letting
244 this process run again. Currently it only
245 applies to SMP */
246 #define MF_SENDA_VM_MISS 0x20000 /* set if a processes wanted to receive an asyn
247 message from this sender but could not
248 because of VM modifying the sender's address
249 space*/
251 /* Magic process table addresses. */
252 #define BEG_PROC_ADDR (&proc[0])
253 #define BEG_USER_ADDR (&proc[NR_TASKS])
254 #define END_PROC_ADDR (&proc[NR_TASKS + NR_PROCS])
256 #define proc_addr(n) (&(proc[NR_TASKS + (n)]))
257 #define proc_nr(p) ((p)->p_nr)
259 #define isokprocn(n) ((unsigned) ((n) + NR_TASKS) < NR_PROCS + NR_TASKS)
260 #define isemptyn(n) isemptyp(proc_addr(n))
261 #define isemptyp(p) ((p)->p_rts_flags == RTS_SLOT_FREE)
262 #define iskernelp(p) ((p) < BEG_USER_ADDR)
263 #define iskerneln(n) ((n) < 0)
264 #define isuserp(p) isusern((p) >= BEG_USER_ADDR)
265 #define isusern(n) ((n) >= 0)
266 #define isrootsysn(n) ((n) == ROOT_SYS_PROC_NR)
268 #ifndef __ASSEMBLY__
270 EXTERN struct proc proc[NR_TASKS + NR_PROCS]; /* process table */
272 int mini_send(struct proc *caller_ptr, endpoint_t dst_e, message *m_ptr,
273 int flags);
275 #endif /* __ASSEMBLY__ */
277 #endif /* PROC_H */