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