Home | History | Annotate | Line # | Download | only in uvm
uvm_stat.h revision 1.18
      1 /*	$NetBSD: uvm_stat.h,v 1.18 2000/04/11 08:12:14 pk 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.h,v 1.1.2.4 1998/02/07 01:16:56 chs Exp
     35  */
     36 
     37 #ifndef _UVM_UVM_STAT_H_
     38 #define _UVM_UVM_STAT_H_
     39 
     40 #if defined(_KERNEL) && !defined(_LKM)
     41 #include "opt_uvmhist.h"
     42 #endif
     43 
     44 #include <sys/queue.h>
     45 
     46 /*
     47  * uvm_stat: monitor what is going on with uvm (or whatever)
     48  */
     49 
     50 /*
     51  * counters  [XXX: maybe replace event counters with this]
     52  */
     53 
     54 #define UVMCNT_MASK	0xf			/* rest are private */
     55 #define UVMCNT_CNT	0			/* normal counter */
     56 #define UVMCNT_DEV	1			/* device event counter */
     57 
     58 struct uvm_cnt {
     59 	int c;					/* the value */
     60 	int t;					/* type */
     61 	struct uvm_cnt *next;			/* global list of cnts */
     62 	char *name;				/* counter name */
     63 	void *p;				/* private data */
     64 };
     65 
     66 #ifdef _KERNEL
     67 
     68 extern struct uvm_cnt *uvm_cnt_head;
     69 
     70 /*
     71  * counter operations.  assume spl is set ok.
     72  */
     73 
     74 #define UVMCNT_INIT(CNT,TYP,VAL,NAM,PRIV) \
     75 do { \
     76 	CNT.c = VAL; \
     77 	CNT.t = TYP; \
     78 	CNT.next = uvm_cnt_head; \
     79 	uvm_cnt_head = &CNT; \
     80 	CNT.name = NAM; \
     81 	CNT.p = PRIV; \
     82 } while (0)
     83 
     84 #define UVMCNT_SET(C,V) \
     85 do { \
     86 	(C).c = (V); \
     87 } while (0)
     88 
     89 #define UVMCNT_ADD(C,V) \
     90 do { \
     91 	(C).c += (V); \
     92 } while (0)
     93 
     94 #define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
     95 #define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
     96 
     97 #endif /* _KERNEL */
     98 
     99 /*
    100  * history/tracing
    101  */
    102 
    103 struct uvm_history_ent {
    104 	struct timeval tv; 		/* time stamp */
    105 	char *fmt; 			/* printf format */
    106 	size_t fmtlen;			/* length of printf format */
    107 	char *fn;			/* function name */
    108 	size_t fnlen;			/* length of function name */
    109 	u_long call;			/* function call number */
    110 	u_long v[4];			/* values */
    111 };
    112 
    113 struct uvm_history {
    114 	const char *name;		/* name of this this history */
    115 	size_t namelen;			/* length of name, not including null */
    116 	LIST_ENTRY(uvm_history) list;	/* link on list of all histories */
    117 	int n;				/* number of entries */
    118 	int f; 				/* next free one */
    119 	simple_lock_data_t l;		/* lock on this history */
    120 	struct uvm_history_ent *e;	/* the malloc'd entries */
    121 };
    122 
    123 LIST_HEAD(uvm_history_head, uvm_history);
    124 
    125 /*
    126  * grovelling lists all at once.  we currently do not allow more than
    127  * 32 histories to exist, as the way to dump a number of them at once
    128  * is by calling uvm_hist() with a bitmask.
    129  */
    130 
    131 /* this is used to set the size of some arrays */
    132 #define	MAXHISTS		32	/* do not change this! */
    133 
    134 /* and these are the bit values of each history */
    135 #define	UVMHIST_MAPHIST		0x00000001	/* maphist */
    136 #define	UVMHIST_PDHIST		0x00000002	/* pdhist */
    137 
    138 #ifdef _KERNEL
    139 
    140 /*
    141  * macros to use the history/tracing code.  note that UVMHIST_LOG
    142  * must take 4 arguments (even if they are ignored by the format).
    143  */
    144 #ifndef UVMHIST
    145 #define UVMHIST_DECL(NAME)
    146 #define UVMHIST_INIT(NAME,N)
    147 #define UVMHIST_INIT_STATIC(NAME,BUF)
    148 #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
    149 #define UVMHIST_CALLED(NAME)
    150 #define UVMHIST_FUNC(FNAME)
    151 #define uvmhist_dump(NAME)
    152 #else
    153 extern	struct uvm_history_head uvm_histories;
    154 
    155 #define UVMHIST_DECL(NAME) struct uvm_history NAME
    156 
    157 #define UVMHIST_INIT(NAME,N) \
    158 do { \
    159 	(NAME).name = __STRING(NAME); \
    160 	(NAME).namelen = strlen((NAME).name); \
    161 	(NAME).n = (N); \
    162 	(NAME).f = 0; \
    163 	simple_lock_init(&(NAME).l); \
    164 	(NAME).e = (struct uvm_history_ent *) \
    165 		malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
    166 		    M_WAITOK); \
    167 	memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \
    168 	LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
    169 } while (0)
    170 
    171 #define UVMHIST_INIT_STATIC(NAME,BUF) \
    172 do { \
    173 	(NAME).name = __STRING(NAME); \
    174 	(NAME).namelen = strlen((NAME).name); \
    175 	(NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
    176 	(NAME).f = 0; \
    177 	simple_lock_init(&(NAME).l); \
    178 	(NAME).e = (struct uvm_history_ent *) (BUF); \
    179 	memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (NAME).n); \
    180 	LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
    181 } while (0)
    182 
    183 extern int cold;
    184 
    185 #if defined(UVMHIST_PRINT)
    186 extern int uvmhist_print_enabled;
    187 #define UVMHIST_PRINTNOW(E) \
    188 do { \
    189 		if (uvmhist_print_enabled) { \
    190 			uvmhist_print(E); \
    191 			DELAY(100000); \
    192 		} \
    193 } while (0)
    194 #else
    195 #define UVMHIST_PRINTNOW(E) /* nothing */
    196 #endif
    197 
    198 #define UVMHIST_LOG(NAME,FMT,A,B,C,D) \
    199 do { \
    200 	int _i_, _s_ = splhigh(); \
    201 	simple_lock(&(NAME).l); \
    202 	_i_ = (NAME).f; \
    203 	(NAME).f = (_i_ + 1) % (NAME).n; \
    204 	simple_unlock(&(NAME).l); \
    205 	splx(_s_); \
    206 	if (!cold) \
    207 		microtime(&(NAME).e[_i_].tv); \
    208 	(NAME).e[_i_].fmt = (FMT); \
    209 	(NAME).e[_i_].fmtlen = strlen((NAME).e[_i_].fmt); \
    210 	(NAME).e[_i_].fn = _uvmhist_name; \
    211 	(NAME).e[_i_].fnlen = strlen((NAME).e[_i_].fn); \
    212 	(NAME).e[_i_].call = _uvmhist_call; \
    213 	(NAME).e[_i_].v[0] = (u_long)(A); \
    214 	(NAME).e[_i_].v[1] = (u_long)(B); \
    215 	(NAME).e[_i_].v[2] = (u_long)(C); \
    216 	(NAME).e[_i_].v[3] = (u_long)(D); \
    217 	UVMHIST_PRINTNOW(&((NAME).e[_i_])); \
    218 } while (0)
    219 
    220 #define UVMHIST_CALLED(NAME) \
    221 do { \
    222 	{ \
    223 		int s = splhigh(); \
    224 		simple_lock(&(NAME).l); \
    225 		_uvmhist_call = _uvmhist_cnt++; \
    226 		simple_unlock(&(NAME).l); \
    227 		splx(s); \
    228 	} \
    229 	UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \
    230 } while (0)
    231 
    232 #define UVMHIST_FUNC(FNAME) \
    233 	static int _uvmhist_cnt = 0; \
    234 	static char *_uvmhist_name = FNAME; \
    235 	int _uvmhist_call;
    236 
    237 static __inline void uvmhist_print __P((struct uvm_history_ent *));
    238 
    239 static __inline void
    240 uvmhist_print(e)
    241 	struct uvm_history_ent *e;
    242 {
    243 	printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
    244 	printf("%s#%ld: ", e->fn, e->call);
    245 	printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
    246 	printf("\n");
    247 }
    248 #endif /* UVMHIST */
    249 
    250 #endif /* _KERNEL */
    251 
    252 #endif /* _UVM_UVM_STAT_H_ */
    253