Home | History | Annotate | Line # | Download | only in uvm
uvm_stat.c revision 1.27
      1 /*	$NetBSD: uvm_stat.c,v 1.27 2005/05/15 08:01:06 yamt 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.27 2005/05/15 08:01:06 yamt 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 #ifdef UVMHIST
     58 struct uvm_history_head uvm_histories;
     59 #endif
     60 
     61 #ifdef UVMHIST_PRINT
     62 int uvmhist_print_enabled = 1;
     63 #endif
     64 
     65 #ifdef DDB
     66 
     67 /*
     68  * prototypes
     69  */
     70 
     71 #ifdef UVMHIST
     72 void uvmhist_dump(struct uvm_history *);
     73 void uvm_hist(u_int32_t);
     74 static void uvmhist_dump_histories(struct uvm_history *[]);
     75 #endif
     76 void uvmcnt_dump(void);
     77 
     78 
     79 #ifdef UVMHIST
     80 /* call this from ddb */
     81 void
     82 uvmhist_dump(l)
     83 	struct uvm_history *l;
     84 {
     85 	int lcv, s;
     86 
     87 	s = splhigh();
     88 	lcv = l->f;
     89 	do {
     90 		if (l->e[lcv].fmt)
     91 			uvmhist_print(&l->e[lcv]);
     92 		lcv = (lcv + 1) % l->n;
     93 	} while (lcv != l->f);
     94 	splx(s);
     95 }
     96 
     97 /*
     98  * print a merged list of uvm_history structures
     99  */
    100 static void
    101 uvmhist_dump_histories(hists)
    102 	struct uvm_history *hists[];
    103 {
    104 	struct timeval  tv;
    105 	int	cur[MAXHISTS];
    106 	int	s, lcv, hi;
    107 
    108 	/* so we don't get corrupted lists! */
    109 	s = splhigh();
    110 
    111 	/* find the first of each list */
    112 	for (lcv = 0; hists[lcv]; lcv++)
    113 		 cur[lcv] = hists[lcv]->f;
    114 
    115 	/*
    116 	 * here we loop "forever", finding the next earliest
    117 	 * history entry and printing it.  cur[X] is the current
    118 	 * entry to test for the history in hists[X].  if it is
    119 	 * -1, then this history is finished.
    120 	 */
    121 	for (;;) {
    122 		hi = -1;
    123 		tv.tv_sec = tv.tv_usec = 0;
    124 
    125 		/* loop over each history */
    126 		for (lcv = 0; hists[lcv]; lcv++) {
    127 restart:
    128 			if (cur[lcv] == -1)
    129 				continue;
    130 
    131 			/*
    132 			 * if the format is empty, go to the next entry
    133 			 * and retry.
    134 			 */
    135 			if (hists[lcv]->e[cur[lcv]].fmt == NULL) {
    136 				cur[lcv] = (cur[lcv] + 1) % (hists[lcv]->n);
    137 				if (cur[lcv] == hists[lcv]->f)
    138 					cur[lcv] = -1;
    139 				goto restart;
    140 			}
    141 
    142 			/*
    143 			 * if the time hasn't been set yet, or this entry is
    144 			 * earlier than the current tv, set the time and history
    145 			 * index.
    146 			 */
    147 			if (tv.tv_sec == 0 ||
    148 			    timercmp(&hists[lcv]->e[cur[lcv]].tv, &tv, <)) {
    149 				tv = hists[lcv]->e[cur[lcv]].tv;
    150 				hi = lcv;
    151 			}
    152 		}
    153 
    154 		/* if we didn't find any entries, we must be done */
    155 		if (hi == -1)
    156 			break;
    157 
    158 		/* print and move to the next entry */
    159 		uvmhist_print(&hists[hi]->e[cur[hi]]);
    160 		cur[hi] = (cur[hi] + 1) % (hists[hi]->n);
    161 		if (cur[hi] == hists[hi]->f)
    162 			cur[hi] = -1;
    163 	}
    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 	if ((bitmask & UVMHIST_UBCHIST) || bitmask == 0)
    185 		hists[i++] = &ubchist;
    186 
    187 	if ((bitmask & UVMHIST_LOANHIST) || bitmask == 0)
    188 		hists[i++] = &loanhist;
    189 
    190 	hists[i] = NULL;
    191 
    192 	uvmhist_dump_histories(hists);
    193 }
    194 #endif /* UVMHIST */
    195 
    196 /*
    197  * uvmexp_print: ddb hook to print interesting uvm counters
    198  */
    199 void
    200 uvmexp_print(void (*pr)(const char *, ...))
    201 {
    202 
    203 	(*pr)("Current UVM status:\n");
    204 	(*pr)("  pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d\n",
    205 	    uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask,
    206 	    uvmexp.pageshift);
    207 	(*pr)("  %d VM pages: %d active, %d inactive, %d wired, %d free\n",
    208 	    uvmexp.npages, uvmexp.active, uvmexp.inactive, uvmexp.wired,
    209 	    uvmexp.free);
    210 	(*pr)("  min  %d%% (%d) anon, %d%% (%d) file, %d%% (%d) exec\n",
    211 	    uvmexp.anonminpct, uvmexp.anonmin, uvmexp.fileminpct,
    212 	    uvmexp.filemin, uvmexp.execminpct, uvmexp.execmin);
    213 	(*pr)("  max  %d%% (%d) anon, %d%% (%d) file, %d%% (%d) exec\n",
    214 	    uvmexp.anonmaxpct, uvmexp.anonmax, uvmexp.filemaxpct,
    215 	    uvmexp.filemax, uvmexp.execmaxpct, uvmexp.execmax);
    216 	(*pr)("  pages  %d anon, %d file, %d exec\n",
    217 	    uvmexp.anonpages, uvmexp.filepages, uvmexp.execpages);
    218 	(*pr)("  freemin=%d, free-target=%d, inactive-target=%d, "
    219 	    "wired-max=%d\n", uvmexp.freemin, uvmexp.freetarg, uvmexp.inactarg,
    220 	    uvmexp.wiredmax);
    221 	(*pr)("  faults=%d, traps=%d, intrs=%d, ctxswitch=%d\n",
    222 	    uvmexp.faults, uvmexp.traps, uvmexp.intrs, uvmexp.swtch);
    223 	(*pr)("  softint=%d, syscalls=%d, swapins=%d, swapouts=%d\n",
    224 	    uvmexp.softs, uvmexp.syscalls, uvmexp.swapins, uvmexp.swapouts);
    225 
    226 	(*pr)("  fault counts:\n");
    227 	(*pr)("    noram=%d, noanon=%d, pgwait=%d, pgrele=%d\n",
    228 	    uvmexp.fltnoram, uvmexp.fltnoanon, uvmexp.fltpgwait,
    229 	    uvmexp.fltpgrele);
    230 	(*pr)("    ok relocks(total)=%d(%d), anget(retrys)=%d(%d), "
    231 	    "amapcopy=%d\n", uvmexp.fltrelckok, uvmexp.fltrelck,
    232 	    uvmexp.fltanget, uvmexp.fltanretry, uvmexp.fltamcopy);
    233 	(*pr)("    neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n",
    234 	    uvmexp.fltnamap, uvmexp.fltnomap, uvmexp.fltlget, uvmexp.fltget);
    235 	(*pr)("    cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n",
    236 	    uvmexp.flt_anon, uvmexp.flt_acow, uvmexp.flt_obj, uvmexp.flt_prcopy,
    237 	    uvmexp.flt_przero);
    238 
    239 	(*pr)("  daemon and swap counts:\n");
    240 	(*pr)("    woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
    241 	    uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan,
    242 	    uvmexp.pdanscan);
    243 	(*pr)("    busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
    244 	    uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact);
    245 	(*pr)("    pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts,
    246 	    uvmexp.pdpending, uvmexp.nswget);
    247 	(*pr)("    nswapdev=%d, swpgavail=%d\n",
    248 	    uvmexp.nswapdev, uvmexp.swpgavail);
    249 	(*pr)("    swpages=%d, swpginuse=%d, swpgonly=%d, paging=%d\n",
    250 	    uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging);
    251 }
    252 #endif
    253