1 /* $NetBSD: uvm_stat.c,v 1.22 2001/12/09 03:07:20 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 /* 38 * uvm_stat.c 39 */ 40 41 #include <sys/cdefs.h> 42 __KERNEL_RCSID(0, "$NetBSD: uvm_stat.c,v 1.22 2001/12/09 03:07:20 chs Exp $"); 43 44 #include "opt_uvmhist.h" 45 #include "opt_ddb.h" 46 47 #include <sys/param.h> 48 #include <sys/systm.h> 49 50 #include <uvm/uvm.h> 51 #include <uvm/uvm_ddb.h> 52 53 /* 54 * globals 55 */ 56 57 struct uvm_cnt *uvm_cnt_head = NULL; 58 59 #ifdef UVMHIST 60 struct uvm_history_head uvm_histories; 61 #endif 62 63 #ifdef UVMHIST_PRINT 64 int uvmhist_print_enabled = 1; 65 #endif 66 67 #ifdef DDB 68 69 /* 70 * prototypes 71 */ 72 73 #ifdef UVMHIST 74 void uvmhist_dump __P((struct uvm_history *)); 75 void uvm_hist __P((u_int32_t)); 76 static void uvmhist_dump_histories __P((struct uvm_history *[])); 77 #endif 78 void uvmcnt_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 splx(s); 167 } 168 169 /* 170 * call this from ddb. `bitmask' is from <uvm/uvm_stat.h>. it 171 * merges the named histories. 172 */ 173 void 174 uvm_hist(bitmask) 175 u_int32_t bitmask; /* XXX only support 32 hists */ 176 { 177 struct uvm_history *hists[MAXHISTS + 1]; 178 int i = 0; 179 180 if ((bitmask & UVMHIST_MAPHIST) || bitmask == 0) 181 hists[i++] = &maphist; 182 183 if ((bitmask & UVMHIST_PDHIST) || bitmask == 0) 184 hists[i++] = &pdhist; 185 186 if ((bitmask & UVMHIST_UBCHIST) || bitmask == 0) 187 hists[i++] = &ubchist; 188 189 hists[i] = NULL; 190 191 uvmhist_dump_histories(hists); 192 } 193 #endif /* UVMHIST */ 194 195 void 196 uvmcnt_dump() 197 { 198 struct uvm_cnt *uvc = uvm_cnt_head; 199 200 while (uvc) { 201 if ((uvc->t & UVMCNT_MASK) != UVMCNT_CNT) 202 continue; 203 printf("%s = %d\n", uvc->name, uvc->c); 204 uvc = uvc->next; 205 } 206 } 207 208 /* 209 * uvmexp_print: ddb hook to print interesting uvm counters 210 */ 211 void 212 uvmexp_print(void (*pr)(const char *, ...)) 213 { 214 215 (*pr)("Current UVM status:\n"); 216 (*pr)(" pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d\n", 217 uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask, 218 uvmexp.pageshift); 219 (*pr)(" %d VM pages: %d active, %d inactive, %d wired, %d free\n", 220 uvmexp.npages, uvmexp.active, uvmexp.inactive, uvmexp.wired, 221 uvmexp.free); 222 (*pr)(" min %d%% (%d) anon, %d%% (%d) file, %d%% (%d) exec\n", 223 uvmexp.anonminpct, uvmexp.anonmin, uvmexp.fileminpct, 224 uvmexp.filemin, uvmexp.execminpct, uvmexp.execmin); 225 (*pr)(" max %d%% (%d) anon, %d%% (%d) file, %d%% (%d) exec\n", 226 uvmexp.anonmaxpct, uvmexp.anonmax, uvmexp.filemaxpct, 227 uvmexp.filemax, uvmexp.execmaxpct, uvmexp.execmax); 228 (*pr)(" pages %d anon, %d file, %d exec\n", 229 uvmexp.anonpages, uvmexp.filepages, uvmexp.execpages); 230 (*pr)(" freemin=%d, free-target=%d, inactive-target=%d, " 231 "wired-max=%d\n", uvmexp.freemin, uvmexp.freetarg, uvmexp.inactarg, 232 uvmexp.wiredmax); 233 (*pr)(" faults=%d, traps=%d, intrs=%d, ctxswitch=%d\n", 234 uvmexp.faults, uvmexp.traps, uvmexp.intrs, uvmexp.swtch); 235 (*pr)(" softint=%d, syscalls=%d, swapins=%d, swapouts=%d\n", 236 uvmexp.softs, uvmexp.syscalls, uvmexp.swapins, uvmexp.swapouts); 237 238 (*pr)(" fault counts:\n"); 239 (*pr)(" noram=%d, noanon=%d, pgwait=%d, pgrele=%d\n", 240 uvmexp.fltnoram, uvmexp.fltnoanon, uvmexp.fltpgwait, 241 uvmexp.fltpgrele); 242 (*pr)(" ok relocks(total)=%d(%d), anget(retrys)=%d(%d), " 243 "amapcopy=%d\n", uvmexp.fltrelckok, uvmexp.fltrelck, 244 uvmexp.fltanget, uvmexp.fltanretry, uvmexp.fltamcopy); 245 (*pr)(" neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n", 246 uvmexp.fltnamap, uvmexp.fltnomap, uvmexp.fltlget, uvmexp.fltget); 247 (*pr)(" cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n", 248 uvmexp.flt_anon, uvmexp.flt_acow, uvmexp.flt_obj, uvmexp.flt_prcopy, 249 uvmexp.flt_przero); 250 251 (*pr)(" daemon and swap counts:\n"); 252 (*pr)(" woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n", 253 uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan, 254 uvmexp.pdanscan); 255 (*pr)(" busy=%d, freed=%d, reactivate=%d, deactivate=%d\n", 256 uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact); 257 (*pr)(" pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts, 258 uvmexp.pdpending, uvmexp.nswget); 259 (*pr)(" nswapdev=%d, nanon=%d, nanonneeded=%d nfreeanon=%d\n", 260 uvmexp.nswapdev, uvmexp.nanon, uvmexp.nanonneeded, 261 uvmexp.nfreeanon); 262 (*pr)(" swpages=%d, swpginuse=%d, swpgonly=%d paging=%d\n", 263 uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging); 264 } 265 #endif 266