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