1 #ifndef PROC_H 2 #define PROC_H 3 4 #include <minix/const.h> 5 #include <sys/cdefs.h> 6 7 #ifndef __ASSEMBLY__ 8 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. 12 * 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. 16 */ 17 #include <minix/com.h> 18 #include <minix/portio.h> 19 #include "const.h" 20 #include "priv.h" 21 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 */ 29 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 the 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 44 */ 45 #endif 46 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; 56 57 clock_t p_dequeued; /* uptime at which process was last dequeued */ 58 59 clock_t p_user_time; /* user time in ticks */ 60 clock_t p_sys_time; /* sys time in ticks */ 61 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 */ 64 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) */ 68 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) */ 71 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? */ 77 78 sigset_t p_pending; /* bit map for pending kernel signals */ 79 80 char p_name[PROC_NAME_LEN]; /* name of the process, including \0 */ 81 82 endpoint_t p_endpoint; /* endpoint number, generation-aware */ 83 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 */ 87 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. 91 * 92 * The requester gets a copy of its request message in reqmsg and gets 93 * VMREQUEST set. 94 */ 95 struct { 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 102 103 int type; /* suspended operation */ 104 union ixfer_saved{ 105 /* VMSTYPE_SYS_MESSAGE */ 106 message reqmsg; /* suspended request message */ 107 } saved; 108 109 /* Parameters of request to VM */ 110 int req_type; 111 endpoint_t target; 112 union ixfer_params{ 113 struct { 114 vir_bytes start, length; /* memory range */ 115 u8_t writeflag; /* nonzero for write access */ 116 } check; 117 } params; 118 /* VM result when available */ 119 int vmresult; 120 121 /* If the suspended operation is a sys_call, its details are 122 * stored here. 123 */ 124 } p_vmrequest; 125 126 int p_found; /* consistency checking variables */ 127 int p_magic; /* check validity of proc pointers */ 128 129 /* if MF_SC_DEFER is set, this struct is valid and contains the 130 * do_ipc() arguments that are still to be executed 131 */ 132 struct { reg_t r1, r2, r3; } p_defer; 133 134 #if DEBUG_TRACE 135 int p_schedules; 136 #endif 137 }; 138 139 #endif /* __ASSEMBLY__ */ 140 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 161 */ 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 165 queue again */ 166 #define RTS_BOOTINHIBIT 0x10000 /* not ready until VM has made it */ 167 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)) 171 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)) 176 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)) 180 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. 186 */ 187 #define P_BLOCKEDON(p) \ 188 ( \ 189 ((p)->p_rts_flags & RTS_SENDING) ? \ 190 (p)->p_sendto_e : \ 191 ( \ 192 ( \ 193 ((p)->p_rts_flags & RTS_RECEIVING) ? \ 194 (p)->p_getfrom_e : \ 195 NONE \ 196 ) \ 197 ) \ 198 ) 199 200 /* These runtime flags can be tested and manipulated by these macros. */ 201 202 #define RTS_ISSET(rp, f) (((rp)->p_rts_flags & (f)) == (f)) 203 204 205 /* Set flag and dequeue if the process was runnable. */ 206 #define RTS_SET(rp, f) \ 207 do { \ 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)) { \ 211 dequeue(rp); \ 212 } \ 213 } while(0) 214 215 /* Clear flag and enqueue if the process was not runnable but is now. */ 216 #define RTS_UNSET(rp, f) \ 217 do { \ 218 int rts; \ 219 rts = (rp)->p_rts_flags; \ 220 (rp)->p_rts_flags &= ~(f); \ 221 if(!rts_f_is_runnable(rts) && proc_is_runnable(rp)) { \ 222 enqueue(rp); \ 223 } \ 224 } while(0) 225 226 /* Set flags to this value. */ 227 #define RTS_SETFLAGS(rp, f) \ 228 do { \ 229 if(proc_is_runnable(rp) && (f)) { dequeue(rp); } \ 230 (rp)->p_rts_flags = (f); \ 231 } while(0) 232 233 /* Misc flags */ 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 241 now 242 */ 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 255 applies to SMP */ 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 259 space*/ 260 #define MF_STEP 0x40000 /* Single-step process */ 261 #define MF_MSGFAILED 0x80000 262 #define MF_NICED 0x100000 /* user has lowered max process priority */ 263 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]) 268 269 #define proc_addr(n) (&(proc[NR_TASKS + (n)])) 270 #define proc_nr(p) ((p)->p_nr) 271 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) 280 281 #ifndef __ASSEMBLY__ 282 283 EXTERN struct proc proc[NR_TASKS + NR_PROCS]; /* process table */ 284 285 int mini_send(struct proc *caller_ptr, endpoint_t dst_e, message *m_ptr, 286 int flags); 287 288 #endif /* __ASSEMBLY__ */ 289 290 #endif /* PROC_H */ 291