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