1 /* $NetBSD: uvm_stat.c,v 1.14 2000/06/27 17:29:35 mrg 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 <uvm/uvm.h> 47 48 /* 49 * globals 50 */ 51 52 struct uvm_cnt *uvm_cnt_head = NULL; 53 54 #ifdef UVMHIST 55 struct uvm_history_head uvm_histories; 56 #endif 57 58 #ifdef UVMHIST_PRINT 59 int uvmhist_print_enabled = 1; 60 #endif 61 62 /* 63 * prototypes 64 */ 65 66 #ifdef UVMHIST 67 void uvmhist_dump __P((struct uvm_history *)); 68 void uvm_hist __P((u_int32_t)); 69 static void uvmhist_dump_histories __P((struct uvm_history *[])); 70 #endif 71 void uvmcnt_dump __P((void)); 72 void uvm_dump __P((void)); 73 74 75 #ifdef UVMHIST 76 /* call this from ddb */ 77 void 78 uvmhist_dump(l) 79 struct uvm_history *l; 80 { 81 int lcv, s; 82 83 s = splhigh(); 84 lcv = l->f; 85 do { 86 if (l->e[lcv].fmt) 87 uvmhist_print(&l->e[lcv]); 88 lcv = (lcv + 1) % l->n; 89 } while (lcv != l->f); 90 splx(s); 91 } 92 93 /* 94 * print a merged list of uvm_history structures 95 */ 96 static void 97 uvmhist_dump_histories(hists) 98 struct uvm_history *hists[]; 99 { 100 struct timeval tv; 101 int cur[MAXHISTS]; 102 int s, lcv, hi; 103 104 /* so we don't get corrupted lists! */ 105 s = splhigh(); 106 107 /* find the first of each list */ 108 for (lcv = 0; hists[lcv]; lcv++) 109 cur[lcv] = hists[lcv]->f; 110 111 /* 112 * here we loop "forever", finding the next earliest 113 * history entry and printing it. cur[X] is the current 114 * entry to test for the history in hists[X]. if it is 115 * -1, then this history is finished. 116 */ 117 for (;;) { 118 hi = -1; 119 tv.tv_sec = tv.tv_usec = 0; 120 121 /* loop over each history */ 122 for (lcv = 0; hists[lcv]; lcv++) { 123 restart: 124 if (cur[lcv] == -1) 125 continue; 126 127 /* 128 * if the format is empty, go to the next entry 129 * and retry. 130 */ 131 if (hists[lcv]->e[cur[lcv]].fmt == NULL) { 132 cur[lcv] = (cur[lcv] + 1) % (hists[lcv]->n); 133 if (cur[lcv] == hists[lcv]->f) 134 cur[lcv] = -1; 135 goto restart; 136 } 137 138 /* 139 * if the time hasn't been set yet, or this entry is 140 * earlier than the current tv, set the time and history 141 * index. 142 */ 143 if (tv.tv_sec == 0 || 144 timercmp(&hists[lcv]->e[cur[lcv]].tv, &tv, <)) { 145 tv = hists[lcv]->e[cur[lcv]].tv; 146 hi = lcv; 147 } 148 } 149 150 /* if we didn't find any entries, we must be done */ 151 if (hi == -1) 152 break; 153 154 /* print and move to the next entry */ 155 uvmhist_print(&hists[hi]->e[cur[hi]]); 156 cur[hi] = (cur[hi] + 1) % (hists[hi]->n); 157 if (cur[hi] == hists[hi]->f) 158 cur[hi] = -1; 159 } 160 161 /* done! */ 162 splx(s); 163 } 164 165 /* 166 * call this from ddb. `bitmask' is from <uvm/uvm_stat.h>. it 167 * merges the named histories. 168 */ 169 void 170 uvm_hist(bitmask) 171 u_int32_t bitmask; /* XXX only support 32 hists */ 172 { 173 struct uvm_history *hists[MAXHISTS + 1]; 174 int i = 0; 175 176 if ((bitmask & UVMHIST_MAPHIST) || bitmask == 0) 177 hists[i++] = &maphist; 178 179 if ((bitmask & UVMHIST_PDHIST) || bitmask == 0) 180 hists[i++] = &pdhist; 181 182 hists[i] = NULL; 183 184 uvmhist_dump_histories(hists); 185 } 186 #endif /* UVMHIST */ 187 188 void 189 uvmcnt_dump() 190 { 191 struct uvm_cnt *uvc = uvm_cnt_head; 192 193 while (uvc) { 194 if ((uvc->t & UVMCNT_MASK) != UVMCNT_CNT) 195 continue; 196 printf("%s = %d\n", uvc->name, uvc->c); 197 uvc = uvc->next; 198 } 199 } 200 201 /* 202 * uvm_dump: ddb hook to dump interesting uvm counters 203 */ 204 void 205 uvm_dump() 206 { 207 208 printf("Current UVM status:\n"); 209 printf(" pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d\n", 210 uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask, 211 uvmexp.pageshift); 212 printf(" %d VM pages: %d active, %d inactive, %d wired, %d free\n", 213 uvmexp.npages, uvmexp.active, uvmexp.inactive, uvmexp.wired, 214 uvmexp.free); 215 printf(" freemin=%d, free-target=%d, inactive-target=%d, " 216 "wired-max=%d\n", uvmexp.freemin, uvmexp.freetarg, uvmexp.inactarg, 217 uvmexp.wiredmax); 218 printf(" faults=%d, traps=%d, intrs=%d, ctxswitch=%d\n", 219 uvmexp.faults, uvmexp.traps, uvmexp.intrs, uvmexp.swtch); 220 printf(" softint=%d, syscalls=%d, swapins=%d, swapouts=%d\n", 221 uvmexp.softs, uvmexp.syscalls, uvmexp.swapins, uvmexp.swapouts); 222 223 printf(" fault counts:\n"); 224 printf(" noram=%d, noanon=%d, pgwait=%d, pgrele=%d\n", 225 uvmexp.fltnoram, uvmexp.fltnoanon, uvmexp.fltpgwait, 226 uvmexp.fltpgrele); 227 printf(" ok relocks(total)=%d(%d), anget(retrys)=%d(%d), " 228 "amapcopy=%d\n", uvmexp.fltrelckok, uvmexp.fltrelck, 229 uvmexp.fltanget, uvmexp.fltanretry, uvmexp.fltamcopy); 230 printf(" neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n", 231 uvmexp.fltnamap, uvmexp.fltnomap, uvmexp.fltlget, uvmexp.fltget); 232 printf(" cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n", 233 uvmexp.flt_anon, uvmexp.flt_acow, uvmexp.flt_obj, uvmexp.flt_prcopy, 234 uvmexp.flt_przero); 235 236 printf(" daemon and swap counts:\n"); 237 printf(" woke=%d, revs=%d, scans=%d, swout=%d\n", uvmexp.pdwoke, 238 uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdswout); 239 printf(" busy=%d, freed=%d, reactivate=%d, deactivate=%d\n", 240 uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact); 241 printf(" pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts, 242 uvmexp.pdpending, uvmexp.nswget); 243 printf(" nswapdev=%d, nanon=%d, nanonneeded=%d nfreeanon=%d\n", 244 uvmexp.nswapdev, uvmexp.nanon, uvmexp.nanonneeded, 245 uvmexp.nfreeanon); 246 printf(" swpages=%d, swpginuse=%d, swpgonly=%d paging=%d\n", 247 uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging); 248 249 printf(" kernel pointers:\n"); 250 printf(" objs(kern/kmem/mb)=%p/%p/%p\n", uvm.kernel_object, 251 uvmexp.kmem_object, uvmexp.mb_object); 252 } 253