- simplify findhole() for use for 1 page only
[minix.git] / kernel / debug.c
blob7324d4857aaa95438677a7e1b970fb0baaf53ced
1 /* This file implements kernel debugging functionality that is not included
2 * in the standard kernel. Available functionality includes timing of lock
3 * functions and sanity checking of the scheduling queues.
4 */
6 #include "kernel.h"
7 #include "proc.h"
8 #include "debug.h"
10 #include <minix/sysutil.h>
11 #include <limits.h>
12 #include <string.h>
14 #if DEBUG_SCHED_CHECK /* only include code if enabled */
16 #define MAX_LOOP (NR_PROCS + NR_TASKS)
18 PUBLIC void
19 check_runqueues_f(char *file, int line)
21 int q, l = 0;
22 register struct proc *xp;
24 if(!intr_disabled()) {
25 minix_panic("check_runqueues called with interrupts enabled", NO_NUM);
28 FIXME("check_runqueues being done");
30 #define MYPANIC(msg) { \
31 kprintf("check_runqueues:%s:%d: %s\n", file, line, msg); \
32 minix_panic("check_runqueues failed", NO_NUM); \
35 for (xp = BEG_PROC_ADDR; xp < END_PROC_ADDR; ++xp) {
36 xp->p_found = 0;
37 if (l++ > MAX_LOOP) { MYPANIC("check error"); }
40 for (q=l=0; q < NR_SCHED_QUEUES; q++) {
41 if (rdy_head[q] && !rdy_tail[q]) {
42 kprintf("head but no tail in %d\n", q);
43 MYPANIC("scheduling error");
45 if (!rdy_head[q] && rdy_tail[q]) {
46 kprintf("tail but no head in %d\n", q);
47 MYPANIC("scheduling error");
49 if (rdy_tail[q] && rdy_tail[q]->p_nextready != NIL_PROC) {
50 kprintf("tail and tail->next not null in %d\n", q);
51 MYPANIC("scheduling error");
53 for(xp = rdy_head[q]; xp != NIL_PROC; xp = xp->p_nextready) {
54 vir_bytes vxp = (vir_bytes) xp, dxp;
55 if(vxp < (vir_bytes) BEG_PROC_ADDR || vxp >= (vir_bytes) END_PROC_ADDR) {
56 MYPANIC("xp out of range");
58 dxp = vxp - (vir_bytes) BEG_PROC_ADDR;
59 if(dxp % sizeof(struct proc)) {
60 MYPANIC("xp not a real pointer");
62 if(xp->p_magic != PMAGIC) {
63 MYPANIC("magic wrong in xp");
65 if (RTS_ISSET(xp, SLOT_FREE)) {
66 kprintf("scheduling error: dead proc q %d %d\n",
67 q, xp->p_endpoint);
68 MYPANIC("dead proc on run queue");
70 if (!xp->p_ready) {
71 kprintf("scheduling error: unready on runq %d proc %d\n",
72 q, xp->p_nr);
73 MYPANIC("found unready process on run queue");
75 if (xp->p_priority != q) {
76 kprintf("scheduling error: wrong priority q %d proc %d ep %d name %s\n",
77 q, xp->p_nr, xp->p_endpoint, xp->p_name);
78 MYPANIC("wrong priority");
80 if (xp->p_found) {
81 kprintf("scheduling error: double sched q %d proc %d\n",
82 q, xp->p_nr);
83 MYPANIC("proc more than once on scheduling queue");
85 xp->p_found = 1;
86 if (xp->p_nextready == NIL_PROC && rdy_tail[q] != xp) {
87 kprintf("sched err: last element not tail q %d proc %d\n",
88 q, xp->p_nr);
89 MYPANIC("scheduling error");
91 if (l++ > MAX_LOOP) MYPANIC("loop in schedule queue?");
95 l = 0;
96 for (xp = BEG_PROC_ADDR; xp < END_PROC_ADDR; ++xp) {
97 if(xp->p_magic != PMAGIC)
98 MYPANIC("p_magic wrong in proc table");
99 if (isemptyp(xp))
100 continue;
101 if(xp->p_ready && ! xp->p_found) {
102 kprintf("sched error: ready proc %d not on queue\n", xp->p_nr);
103 MYPANIC("ready proc not on scheduling queue");
104 if (l++ > MAX_LOOP) { MYPANIC("loop in debug.c?"); }
109 #endif /* DEBUG_SCHED_CHECK */
111 PUBLIC char *
112 rtsflagstr(int flags)
114 static char str[100];
115 str[0] = '\0';
117 #define FLAG(n) if(flags & n) { strcat(str, #n " "); }
119 FLAG(SLOT_FREE);
120 FLAG(NO_PRIORITY);
121 FLAG(SENDING);
122 FLAG(RECEIVING);
123 FLAG(SIGNALED);
124 FLAG(SIG_PENDING);
125 FLAG(P_STOP);
126 FLAG(NO_PRIV);
127 FLAG(NO_ENDPOINT);
128 FLAG(VMINHIBIT);
129 FLAG(PAGEFAULT);
130 FLAG(VMREQUEST);
131 FLAG(VMREQTARGET);
133 return str;
136 PUBLIC char *
137 miscflagstr(int flags)
139 static char str[100];
140 str[0] = '\0';
142 FLAG(MF_REPLY_PEND);
143 FLAG(MF_ASYNMSG);
144 FLAG(MF_FULLVM);
145 FLAG(MF_DELIVERMSG);
147 return str;