Home | History | Annotate | Line # | Download | only in uvm
uvm_stat.h revision 1.1
      1 /*	$Id: uvm_stat.h,v 1.1 1998/02/05 06:25:08 mrg 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 #if NCPU > 1
     54 	simple_lock_data_t l;			/* lock on this counter */
     55 #endif /* NCPU */
     56 	struct uvm_cnt *next;			/* global list of cnts */
     57 	char *name;				/* counter name */
     58 	void *p;				/* private data */
     59 };
     60 
     61 extern struct uvm_cnt *uvm_cnt_head;
     62 
     63 /*
     64  * counter operations.   note simple_locks compiles out if NCPU == 1.
     65  * assume spl is set ok.
     66  */
     67 
     68 #define UVMCNT_INIT(CNT,TYP,VAL,NAM,PRIV) { \
     69 	CNT.c = VAL; \
     70 	CNT.t = TYP; \
     71 	simple_lock_init(&CNT.l); \
     72 	CNT.next = uvm_cnt_head; \
     73 	uvm_cnt_head = &CNT; \
     74 	CNT.name = NAM; \
     75 	CNT.p = PRIV; \
     76 	}
     77 
     78 #define UVMCNT_SET(C,V) { \
     79 	simple_lock(&(C).l); \
     80 	(C).c = (V); \
     81 	simple_unlock(&(C).l); \
     82 	}
     83 
     84 #define UVMCNT_ADD(C,V) { \
     85 	simple_lock(&(C).l); \
     86 	(C).c += (V); \
     87 	simple_unlock(&(C).l); \
     88 	}
     89 
     90 #define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
     91 #define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
     92 
     93 
     94 /*
     95  * history/tracing
     96  */
     97 
     98 #if !defined(UVM_NOHIST)
     99 #define UVMHIST
    100 #endif
    101 
    102 struct uvm_history_ent {
    103   struct timeval tv; 		/* time stamp */
    104   char *fmt; 			/* printf format */
    105   char *fn;			/* function name */
    106   u_long call;			/* function call number */
    107   u_long v[4];			/* values */
    108 };
    109 
    110 struct uvm_history {
    111   int n;			/* number of entries */
    112   int f; 			/* next free one */
    113 #if NCPU > 1
    114   simple_lock_data_t l;		/* lock on this history */
    115 #endif /* NCPU */
    116   struct uvm_history_ent *e;	/* the malloc'd entries */
    117 };
    118 
    119 #ifndef UVMHIST
    120 #define UVMHIST_DECL(NAME)
    121 #define UVMHIST_INIT(NAME,N)
    122 #define UVMHIST_INIT_STATIC(NAME,BUF)
    123 #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
    124 #define UVMHIST_CALLED(NAME)
    125 #define UVMHIST_FUNC(FNAME)
    126 #define uvmhist_dump(NAME)
    127 #else
    128 #define UVMHIST_DECL(NAME) struct uvm_history NAME
    129 
    130 #define UVMHIST_INIT(NAME,N) { \
    131 	(NAME).n = (N); \
    132 	(NAME).f = 0; \
    133 	simple_lock_init(&(NAME).l); \
    134 	(NAME).e = (struct uvm_history_ent *) \
    135 		malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
    136 				M_WAITOK); \
    137 	bzero((NAME).e, sizeof(struct uvm_history_ent) * (N)); \
    138 	}
    139 
    140 #define UVMHIST_INIT_STATIC(NAME,BUF) { \
    141 	(NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
    142 	(NAME).f = 0; \
    143 	simple_lock_init(&(NAME).l); \
    144 	(NAME).e = (struct uvm_history_ent *) (BUF); \
    145 	bzero((NAME).e, sizeof(struct uvm_history_ent) * (NAME).n); \
    146 	}
    147 
    148 extern int cold;
    149 
    150 #if defined(UVMHIST_PRINT)
    151 #define UVMHIST_PRINTNOW(E) uvmhist_print(E); DELAY(100000);
    152 #else
    153 #define UVMHIST_PRINTNOW(E) /* nothing */
    154 #endif
    155 
    156 #define UVMHIST_LOG(NAME,FMT,A,B,C,D) { \
    157 	register int i, s = splhigh(); \
    158 	simple_lock(&(NAME).l); \
    159 	i = (NAME).f; \
    160 	(NAME).f = (i + 1) % (NAME).n; \
    161 	simple_unlock(&(NAME).l); \
    162 	splx(s); \
    163 	if (!cold) microtime(&(NAME).e[i].tv); \
    164 	(NAME).e[i].fmt = (FMT); \
    165 	(NAME).e[i].fn = _uvmhist_name; \
    166 	(NAME).e[i].call = _uvmhist_call; \
    167 	(NAME).e[i].v[0] = (u_long)(A); \
    168 	(NAME).e[i].v[1] = (u_long)(B); \
    169 	(NAME).e[i].v[2] = (u_long)(C); \
    170 	(NAME).e[i].v[3] = (u_long)(D); \
    171         UVMHIST_PRINTNOW(&((NAME).e[i])); \
    172 	}
    173 
    174 #define UVMHIST_CALLED(NAME) \
    175 	{ int s = splhigh(); simple_lock(&(NAME).l); \
    176 	 	_uvmhist_call = _uvmhist_cnt++; \
    177 	  simple_unlock(&(NAME).l); splx(s); } \
    178 	UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0);
    179 
    180 #define UVMHIST_FUNC(FNAME) \
    181 	static int _uvmhist_cnt = 0; \
    182 	static char *_uvmhist_name = FNAME; \
    183 	int _uvmhist_call;
    184 
    185 static __inline void uvmhist_print __P((struct uvm_history_ent *));
    186 	/* shut up GCC */
    187 
    188 static __inline void uvmhist_print(e)
    189 
    190 struct uvm_history_ent *e;
    191 {
    192   printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
    193   printf("%s#%ld: ", e->fn, e->call);
    194   printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
    195   printf("\n");
    196 }
    197 
    198 #endif /* UVMHIST */
    199