Home | History | Annotate | Line # | Download | only in uvm
uvm_stat.h revision 1.3
      1 /*	$NetBSD: uvm_stat.h,v 1.3 1998/02/07 02:16:52 chs Exp $	*/
      2 
      3 /*
      4  * XXXCDC: "ROUGH DRAFT" QUALITY UVM PRE-RELEASE FILE!
      5  *	   >>>USE AT YOUR OWN RISK, WORK IS NOT FINISHED<<<
      6  */
      7 /*
      8  *
      9  * Copyright (c) 1997 Charles D. Cranor and Washington University.
     10  * All rights reserved.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *      This product includes software developed by Charles D. Cranor and
     23  *      Washington University.
     24  * 4. The name of the author may not be used to endorse or promote products
     25  *    derived from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     28  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     29  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     30  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     31  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     32  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     36  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 /*
     39  * uvm_stat: monitor what is going on with uvm (or whatever)
     40  */
     41 
     42 /*
     43  * counters  [XXX: maybe replace event counters with this]
     44  */
     45 
     46 #define UVMCNT_MASK	0xf			/* rest are private */
     47 #define UVMCNT_CNT	0			/* normal counter */
     48 #define UVMCNT_DEV	1			/* device event counter */
     49 
     50 struct uvm_cnt {
     51 	int c;					/* the value */
     52 	int t;					/* type */
     53 	struct uvm_cnt *next;			/* global list of cnts */
     54 	char *name;				/* counter name */
     55 	void *p;				/* private data */
     56 };
     57 
     58 extern struct uvm_cnt *uvm_cnt_head;
     59 
     60 /*
     61  * counter operations.  assume spl is set ok.
     62  */
     63 
     64 #define UVMCNT_INIT(CNT,TYP,VAL,NAM,PRIV) { \
     65 	CNT.c = VAL; \
     66 	CNT.t = TYP; \
     67 	CNT.next = uvm_cnt_head; \
     68 	uvm_cnt_head = &CNT; \
     69 	CNT.name = NAM; \
     70 	CNT.p = PRIV; \
     71 	}
     72 
     73 #define UVMCNT_SET(C,V) { \
     74 	(C).c = (V); \
     75 	}
     76 
     77 #define UVMCNT_ADD(C,V) { \
     78 	(C).c += (V); \
     79 	}
     80 
     81 #define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
     82 #define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
     83 
     84 
     85 /*
     86  * history/tracing
     87  */
     88 
     89 #if !defined(UVM_NOHIST)
     90 #define UVMHIST
     91 #endif
     92 
     93 struct uvm_history_ent {
     94   struct timeval tv; 		/* time stamp */
     95   char *fmt; 			/* printf format */
     96   char *fn;			/* function name */
     97   u_long call;			/* function call number */
     98   u_long v[4];			/* values */
     99 };
    100 
    101 struct uvm_history {
    102   int n;			/* number of entries */
    103   int f; 			/* next free one */
    104 #if NCPU > 1
    105   simple_lock_data_t l;		/* lock on this history */
    106 #endif /* NCPU */
    107   struct uvm_history_ent *e;	/* the malloc'd entries */
    108 };
    109 
    110 #ifndef UVMHIST
    111 #define UVMHIST_DECL(NAME)
    112 #define UVMHIST_INIT(NAME,N)
    113 #define UVMHIST_INIT_STATIC(NAME,BUF)
    114 #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
    115 #define UVMHIST_CALLED(NAME)
    116 #define UVMHIST_FUNC(FNAME)
    117 #define uvmhist_dump(NAME)
    118 #else
    119 #define UVMHIST_DECL(NAME) struct uvm_history NAME
    120 
    121 #define UVMHIST_INIT(NAME,N) { \
    122 	(NAME).n = (N); \
    123 	(NAME).f = 0; \
    124 	simple_lock_init(&(NAME).l); \
    125 	(NAME).e = (struct uvm_history_ent *) \
    126 		malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
    127 				M_WAITOK); \
    128 	bzero((NAME).e, sizeof(struct uvm_history_ent) * (N)); \
    129 	}
    130 
    131 #define UVMHIST_INIT_STATIC(NAME,BUF) { \
    132 	(NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
    133 	(NAME).f = 0; \
    134 	simple_lock_init(&(NAME).l); \
    135 	(NAME).e = (struct uvm_history_ent *) (BUF); \
    136 	bzero((NAME).e, sizeof(struct uvm_history_ent) * (NAME).n); \
    137 	}
    138 
    139 extern int cold;
    140 
    141 #if defined(UVMHIST_PRINT)
    142 #define UVMHIST_PRINTNOW(E) uvmhist_print(E); DELAY(100000);
    143 #else
    144 #define UVMHIST_PRINTNOW(E) /* nothing */
    145 #endif
    146 
    147 #define UVMHIST_LOG(NAME,FMT,A,B,C,D) { \
    148 	register int i, s = splhigh(); \
    149 	simple_lock(&(NAME).l); \
    150 	i = (NAME).f; \
    151 	(NAME).f = (i + 1) % (NAME).n; \
    152 	simple_unlock(&(NAME).l); \
    153 	splx(s); \
    154 	if (!cold) microtime(&(NAME).e[i].tv); \
    155 	(NAME).e[i].fmt = (FMT); \
    156 	(NAME).e[i].fn = _uvmhist_name; \
    157 	(NAME).e[i].call = _uvmhist_call; \
    158 	(NAME).e[i].v[0] = (u_long)(A); \
    159 	(NAME).e[i].v[1] = (u_long)(B); \
    160 	(NAME).e[i].v[2] = (u_long)(C); \
    161 	(NAME).e[i].v[3] = (u_long)(D); \
    162         UVMHIST_PRINTNOW(&((NAME).e[i])); \
    163 	}
    164 
    165 #define UVMHIST_CALLED(NAME) \
    166 	{ int s = splhigh(); simple_lock(&(NAME).l); \
    167 	 	_uvmhist_call = _uvmhist_cnt++; \
    168 	  simple_unlock(&(NAME).l); splx(s); } \
    169 	UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0);
    170 
    171 #define UVMHIST_FUNC(FNAME) \
    172 	static int _uvmhist_cnt = 0; \
    173 	static char *_uvmhist_name = FNAME; \
    174 	int _uvmhist_call;
    175 
    176 static __inline void uvmhist_print __P((struct uvm_history_ent *));
    177 	/* shut up GCC */
    178 
    179 static __inline void uvmhist_print(e)
    180 
    181 struct uvm_history_ent *e;
    182 {
    183   printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
    184   printf("%s#%ld: ", e->fn, e->call);
    185   printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
    186   printf("\n");
    187 }
    188 
    189 #endif /* UVMHIST */
    190