1 /* $NetBSD: uvm_stat.c,v 1.10 1998/06/20 13:19:00 mrg Exp $ */ 2 3 /* 4 * XXXCDC: "ROUGH DRAFT" QUALITY UVM PRE-RELEASE FILE! 5 * >>>USE AT YOUR OWN RISK, WORK IS NOT FINISHED<<< 6 */ 7 /* 8 * 9 * Copyright (c) 1997 Charles D. Cranor and Washington University. 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by Charles D. Cranor and 23 * Washington University. 24 * 4. The name of the author may not be used to endorse or promote products 25 * derived from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 29 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 30 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 32 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 36 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 * 38 * from: Id: uvm_stat.c,v 1.1.2.3 1997/12/19 15:01:00 mrg Exp 39 */ 40 41 #include "opt_uvmhist.h" 42 43 /* 44 * uvm_stat.c 45 */ 46 47 #include <sys/param.h> 48 #include <sys/systm.h> 49 50 #include <vm/vm.h> 51 52 #include <uvm/uvm.h> 53 54 /* 55 * globals 56 */ 57 58 struct uvm_cnt *uvm_cnt_head = NULL; 59 60 #ifdef UVMHIST 61 struct uvm_history_head uvm_histories; 62 #endif 63 64 #ifdef UVMHIST_PRINT 65 int uvmhist_print_enabled = 1; 66 #endif 67 68 /* 69 * prototypes 70 */ 71 72 #ifdef UVMHIST 73 void uvmhist_dump __P((struct uvm_history *)); 74 void uvm_hist __P((u_int32_t)); 75 static void uvmhist_dump_histories __P((struct uvm_history *[])); 76 #endif 77 void uvmcnt_dump __P((void)); 78 void uvm_dump __P((void)); 79 80 81 #ifdef UVMHIST 82 /* call this from ddb */ 83 void 84 uvmhist_dump(l) 85 struct uvm_history *l; 86 { 87 int lcv, s; 88 89 s = splhigh(); 90 lcv = l->f; 91 do { 92 if (l->e[lcv].fmt) 93 uvmhist_print(&l->e[lcv]); 94 lcv = (lcv + 1) % l->n; 95 } while (lcv != l->f); 96 splx(s); 97 } 98 99 /* 100 * print a merged list of uvm_history structures 101 */ 102 static void 103 uvmhist_dump_histories(hists) 104 struct uvm_history *hists[]; 105 { 106 struct timeval tv; 107 int cur[MAXHISTS]; 108 int s, lcv, hi; 109 110 /* so we don't get corrupted lists! */ 111 s = splhigh(); 112 113 /* find the first of each list */ 114 for (lcv = 0; hists[lcv]; lcv++) 115 cur[lcv] = hists[lcv]->f; 116 117 /* 118 * here we loop "forever", finding the next earliest 119 * history entry and printing it. cur[X] is the current 120 * entry to test for the history in hists[X]. if it is 121 * -1, then this history is finished. 122 */ 123 for (;;) { 124 hi = -1; 125 tv.tv_sec = tv.tv_usec = 0; 126 127 /* loop over each history */ 128 for (lcv = 0; hists[lcv]; lcv++) { 129 restart: 130 if (cur[lcv] == -1) 131 continue; 132 133 /* 134 * if the format is empty, go to the next entry 135 * and retry. 136 */ 137 if (hists[lcv]->e[cur[lcv]].fmt == NULL) { 138 cur[lcv] = (cur[lcv] + 1) % (hists[lcv]->n); 139 if (cur[lcv] == hists[lcv]->f) 140 cur[lcv] = -1; 141 goto restart; 142 } 143 144 /* 145 * if the time hasn't been set yet, or this entry is 146 * earlier than the current tv, set the time and history 147 * index. 148 */ 149 if (tv.tv_sec == 0 || 150 timercmp(&hists[lcv]->e[cur[lcv]].tv, &tv, <)) { 151 tv = hists[lcv]->e[cur[lcv]].tv; 152 hi = lcv; 153 } 154 } 155 156 /* if we didn't find any entries, we must be done */ 157 if (hi == -1) 158 break; 159 160 /* print and move to the next entry */ 161 uvmhist_print(&hists[hi]->e[cur[hi]]); 162 cur[hi] = (cur[hi] + 1) % (hists[hi]->n); 163 if (cur[hi] == hists[hi]->f) 164 cur[hi] = -1; 165 } 166 167 /* done! */ 168 splx(s); 169 } 170 171 /* 172 * call this from ddb. `bitmask' is from <uvm/uvm_stat.h>. it 173 * merges the named histories. 174 */ 175 void 176 uvm_hist(bitmask) 177 u_int32_t bitmask; /* XXX only support 32 hists */ 178 { 179 struct uvm_history *hists[MAXHISTS + 1]; 180 int i = 0; 181 182 if ((bitmask & UVMHIST_MAPHIST) || bitmask == 0) 183 hists[i++] = &maphist; 184 185 if ((bitmask & UVMHIST_PDHIST) || bitmask == 0) 186 hists[i++] = &pdhist; 187 188 hists[i] = NULL; 189 190 uvmhist_dump_histories(hists); 191 } 192 #endif /* UVMHIST */ 193 194 void 195 uvmcnt_dump() 196 { 197 struct uvm_cnt *uvc = uvm_cnt_head; 198 199 while (uvc) { 200 if ((uvc->t & UVMCNT_MASK) != UVMCNT_CNT) 201 continue; 202 printf("%s = %d\n", uvc->name, uvc->c); 203 uvc = uvc->next; 204 } 205 } 206 207 /* 208 * uvm_dump: ddb hook to dump interesting uvm counters 209 */ 210 void 211 uvm_dump() 212 { 213 214 printf("Current UVM status:\n"); 215 printf(" pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d\n", 216 uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask, 217 uvmexp.pageshift); 218 printf(" %d VM pages: %d active, %d inactive, %d wired, %d free\n", 219 uvmexp.npages, uvmexp.active, uvmexp.inactive, uvmexp.wired, 220 uvmexp.free); 221 printf(" freemin=%d, free-target=%d, inactive-target=%d, " 222 "wired-max=%d\n", uvmexp.freemin, uvmexp.freetarg, uvmexp.inactarg, 223 uvmexp.wiredmax); 224 printf(" faults=%d, traps=%d, intrs=%d, ctxswitch=%d\n", 225 uvmexp.faults, uvmexp.traps, uvmexp.intrs, uvmexp.swtch); 226 printf(" softint=%d, syscalls=%d, swapins=%d, swapouts=%d\n", 227 uvmexp.softs, uvmexp.syscalls, uvmexp.swapins, uvmexp.swapouts); 228 229 printf(" fault counts:\n"); 230 printf(" noram=%d, noanon=%d, pgwait=%d, pgrele=%d\n", 231 uvmexp.fltnoram, uvmexp.fltnoanon, uvmexp.fltpgwait, 232 uvmexp.fltpgrele); 233 printf(" ok relocks(total)=%d(%d), anget(retrys)=%d(%d), " 234 "amapcopy=%d\n", uvmexp.fltrelckok, uvmexp.fltrelck, 235 uvmexp.fltanget, uvmexp.fltanretry, uvmexp.fltamcopy); 236 printf(" neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n", 237 uvmexp.fltnamap, uvmexp.fltnomap, uvmexp.fltlget, uvmexp.fltget); 238 printf(" cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n", 239 uvmexp.flt_anon, uvmexp.flt_acow, uvmexp.flt_obj, uvmexp.flt_prcopy, 240 uvmexp.flt_przero); 241 242 printf(" daemon and swap counts:\n"); 243 printf(" woke=%d, revs=%d, scans=%d, swout=%d\n", uvmexp.pdwoke, 244 uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdswout); 245 printf(" busy=%d, freed=%d, reactivate=%d, deactivate=%d\n", 246 uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact); 247 printf(" pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts, 248 uvmexp.pdpending, uvmexp.nswget); 249 printf(" nswapdev=%d, nanon=%d, nfreeanon=%d\n", uvmexp.nswapdev, 250 uvmexp.nanon, uvmexp.nfreeanon); 251 252 printf(" kernel pointers:\n"); 253 printf(" objs(kern/kmem/mb)=%p/%p/%p\n", uvm.kernel_object, 254 uvmexp.kmem_object, uvmexp.mb_object); 255 } 256