4 #include <minix/const.h>
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>
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
34 struct proc
*p_scheduler
; /* who should get out of quantum msg */
35 unsigned p_cpu
; /* what CPU is the process running on */
37 bitchunk_t p_cpu_mask
[BITMAP_CHUNKS(CONFIG_MAX_CPUS
)]; /* what CPUs is the
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
47 /* Accounting statistics that get passed to the process' scheduler */
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
;
57 clock_t p_dequeued
; /* uptime at which process was last dequeued */
59 clock_t p_user_time
; /* user time in ticks */
60 clock_t p_sys_time
; /* sys time in ticks */
62 clock_t p_virt_left
; /* number of ticks left on virtual timer */
63 clock_t p_prof_left
; /* number of ticks left on profile timer */
65 u64_t p_cycles
; /* how many cycles did the process use */
66 u64_t p_kcall_cycles
; /* kernel cycles caused by this proc (kcall) */
67 u64_t p_kipc_cycles
; /* cycles caused by this proc (ipc) */
69 u64_t p_tick_cycles
; /* cycles accumulated for up to a clock tick */
70 struct cpuavg p_cpuavg
; /* running CPU average, for ps(1) */
72 struct proc
*p_nextready
; /* pointer to next ready process */
73 struct proc
*p_caller_q
; /* head of list of procs wishing to send */
74 struct proc
*p_q_link
; /* link to next proc wishing to send */
75 endpoint_t p_getfrom_e
; /* from whom does process want to receive? */
76 endpoint_t p_sendto_e
; /* to whom does process want to send? */
78 sigset_t p_pending
; /* bit map for pending kernel signals */
80 char p_name
[PROC_NAME_LEN
]; /* name of the process, including \0 */
82 endpoint_t p_endpoint
; /* endpoint number, generation-aware */
84 message p_sendmsg
; /* Message from this process if SENDING */
85 message p_delivermsg
; /* Message for this process if MF_DELIVERMSG */
86 vir_bytes p_delivermsg_vir
; /* Virtual addr this proc wants message at */
88 /* If handler functions detect a process wants to do something with
89 * memory that isn't present, VM has to fix it. Until it has asked
90 * what needs to be done and fixed it, save necessary state here.
92 * The requester gets a copy of its request message in reqmsg and gets
96 struct proc
*nextrestart
; /* next in vmrestart chain */
97 struct proc
*nextrequestor
; /* next in vmrequest chain */
98 #define VMSTYPE_SYS_NONE 0
99 #define VMSTYPE_KERNELCALL 1
100 #define VMSTYPE_DELIVERMSG 2
101 #define VMSTYPE_MAP 3
103 int type
; /* suspended operation */
105 /* VMSTYPE_SYS_MESSAGE */
106 message reqmsg
; /* suspended request message */
109 /* Parameters of request to VM */
114 vir_bytes start
, length
; /* memory range */
115 u8_t writeflag
; /* nonzero for write access */
118 /* VM result when available */
121 /* If the suspended operation is a sys_call, its details are
126 int p_found
; /* consistency checking variables */
127 int p_magic
; /* check validity of proc pointers */
129 /* if MF_SC_DEFER is set, this struct is valid and contains the
130 * do_ipc() arguments that are still to be executed
132 struct { reg_t r1
, r2
, r3
; } p_defer
;
139 #endif /* __ASSEMBLY__ */
141 /* Bits for the runtime flags. A process is runnable iff p_rts_flags == 0. */
142 #define RTS_SLOT_FREE 0x01 /* process slot is free */
143 #define RTS_PROC_STOP 0x02 /* process has been stopped */
144 #define RTS_SENDING 0x04 /* process blocked trying to send */
145 #define RTS_RECEIVING 0x08 /* process blocked trying to receive */
146 #define RTS_SIGNALED 0x10 /* set when new kernel signal arrives */
147 #define RTS_SIG_PENDING 0x20 /* unready while signal being processed */
148 #define RTS_P_STOP 0x40 /* set when process is being traced */
149 #define RTS_NO_PRIV 0x80 /* keep forked system process from running */
150 #define RTS_NO_ENDPOINT 0x100 /* process cannot send or receive messages */
151 #define RTS_VMINHIBIT 0x200 /* not scheduled until pagetable set by VM */
152 #define RTS_PAGEFAULT 0x400 /* process has unhandled pagefault */
153 #define RTS_VMREQUEST 0x800 /* originator of vm memory request */
154 #define RTS_VMREQTARGET 0x1000 /* target of vm memory request */
155 #define RTS_PREEMPTED 0x4000 /* this process was preempted by a higher
156 priority process and we should pick a new one
157 to run. Processes with this flag should be
158 returned to the front of their current
159 priority queue if they are still runnable
160 before we pick a new one
162 #define RTS_NO_QUANTUM 0x8000 /* process ran out of its quantum and we should
163 pick a new one. Process was dequeued and
164 should be enqueued at the end of some run
166 #define RTS_BOOTINHIBIT 0x10000 /* not ready until VM has made it */
168 /* A process is runnable iff p_rts_flags == 0. */
169 #define rts_f_is_runnable(flg) ((flg) == 0)
170 #define proc_is_runnable(p) (rts_f_is_runnable((p)->p_rts_flags))
172 #define proc_is_preempted(p) ((p)->p_rts_flags & RTS_PREEMPTED)
173 #define proc_no_quantum(p) ((p)->p_rts_flags & RTS_NO_QUANTUM)
174 #define proc_ptr_ok(p) ((p)->p_magic == PMAGIC)
175 #define proc_used_fpu(p) ((p)->p_misc_flags & (MF_FPU_INITIALIZED))
177 /* test whether the process is scheduled by the kernel's default policy */
178 #define proc_kernel_scheduler(p) ((p)->p_scheduler == NULL || \
179 (p)->p_scheduler == (p))
181 /* Macro to return: on which process is a certain process blocked?
182 * return endpoint number (can be ANY) or NONE. It's important to
183 * check RTS_SENDING first, and then RTS_RECEIVING, as they could
184 * both be on (if a ipc_sendrec() blocks on sending), and p_getfrom_e
185 * could be nonsense even though RTS_RECEIVING is on.
187 #define P_BLOCKEDON(p) \
189 ((p)->p_rts_flags & RTS_SENDING) ? \
193 ((p)->p_rts_flags & RTS_RECEIVING) ? \
200 /* These runtime flags can be tested and manipulated by these macros. */
202 #define RTS_ISSET(rp, f) (((rp)->p_rts_flags & (f)) == (f))
205 /* Set flag and dequeue if the process was runnable. */
206 #define RTS_SET(rp, f) \
208 const int rts = (rp)->p_rts_flags; \
209 (rp)->p_rts_flags |= (f); \
210 if(rts_f_is_runnable(rts) && !proc_is_runnable(rp)) { \
215 /* Clear flag and enqueue if the process was not runnable but is now. */
216 #define RTS_UNSET(rp, f) \
219 rts = (rp)->p_rts_flags; \
220 (rp)->p_rts_flags &= ~(f); \
221 if(!rts_f_is_runnable(rts) && proc_is_runnable(rp)) { \
226 /* Set flags to this value. */
227 #define RTS_SETFLAGS(rp, f) \
229 if(proc_is_runnable(rp) && (f)) { dequeue(rp); } \
230 (rp)->p_rts_flags = (f); \
234 #define MF_REPLY_PEND 0x001 /* reply to IPC_REQUEST is pending */
235 #define MF_VIRT_TIMER 0x002 /* process-virtual timer is running */
236 #define MF_PROF_TIMER 0x004 /* process-virtual profile timer is running */
237 #define MF_KCALL_RESUME 0x008 /* processing a kernel call was interrupted,
238 most likely because we need VM to resolve a
239 problem or a long running copy was preempted.
240 We need to resume the kernel call execution
243 #define MF_DELIVERMSG 0x040 /* Copy message for him before running */
244 #define MF_SIG_DELAY 0x080 /* Send signal when no longer sending */
245 #define MF_SC_ACTIVE 0x100 /* Syscall tracing: in a system call now */
246 #define MF_SC_DEFER 0x200 /* Syscall tracing: deferred system call */
247 #define MF_SC_TRACE 0x400 /* Syscall tracing: trigger syscall events */
248 #define MF_FPU_INITIALIZED 0x1000 /* process already used math, so fpu
249 * regs are significant (initialized)*/
250 #define MF_SENDING_FROM_KERNEL 0x2000 /* message of this process is from kernel */
251 #define MF_CONTEXT_SET 0x4000 /* don't touch context */
252 #define MF_SPROF_SEEN 0x8000 /* profiling has seen this process */
253 #define MF_FLUSH_TLB 0x10000 /* if set, TLB must be flushed before letting
254 this process run again. Currently it only
256 #define MF_SENDA_VM_MISS 0x20000 /* set if a processes wanted to receive an asyn
257 message from this sender but could not
258 because of VM modifying the sender's address
260 #define MF_STEP 0x40000 /* Single-step process */
261 #define MF_MSGFAILED 0x80000
262 #define MF_NICED 0x100000 /* user has lowered max process priority */
264 /* Magic process table addresses. */
265 #define BEG_PROC_ADDR (&proc[0])
266 #define BEG_USER_ADDR (&proc[NR_TASKS])
267 #define END_PROC_ADDR (&proc[NR_TASKS + NR_PROCS])
269 #define proc_addr(n) (&(proc[NR_TASKS + (n)]))
270 #define proc_nr(p) ((p)->p_nr)
272 #define isokprocn(n) ((unsigned) ((n) + NR_TASKS) < NR_PROCS + NR_TASKS)
273 #define isemptyn(n) isemptyp(proc_addr(n))
274 #define isemptyp(p) ((p)->p_rts_flags == RTS_SLOT_FREE)
275 #define iskernelp(p) ((p) < BEG_USER_ADDR)
276 #define iskerneln(n) ((n) < 0)
277 #define isuserp(p) isusern((p) >= BEG_USER_ADDR)
278 #define isusern(n) ((n) >= 0)
279 #define isrootsysn(n) ((n) == ROOT_SYS_PROC_NR)
283 EXTERN
struct proc proc
[NR_TASKS
+ NR_PROCS
]; /* process table */
285 int mini_send(struct proc
*caller_ptr
, endpoint_t dst_e
, message
*m_ptr
,
288 #endif /* __ASSEMBLY__ */