Home | History | Annotate | Line # | Download | only in uvm
uvm_stat.h revision 1.9
      1  1.9  thorpej /*	$NetBSD: uvm_stat.h,v 1.9 1998/02/13 04:55:14 thorpej Exp $	*/
      2  1.1      mrg 
      3  1.1      mrg /*
      4  1.1      mrg  * 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.4      mrg  *
     38  1.4      mrg  * from: Id: uvm_stat.h,v 1.1.2.4 1998/02/07 01:16:56 chs Exp
     39  1.1      mrg  */
     40  1.6    perry 
     41  1.6    perry #ifndef _UVM_UVM_STAT_H_
     42  1.6    perry #define _UVM_UVM_STAT_H_
     43  1.7      mrg 
     44  1.9  thorpej #if defined(_KERNEL) && !defined(_LKM)
     45  1.7      mrg #include "opt_uvmhist.h"
     46  1.9  thorpej #endif
     47  1.9  thorpej 
     48  1.9  thorpej #include <sys/queue.h>
     49  1.6    perry 
     50  1.1      mrg /*
     51  1.1      mrg  * uvm_stat: monitor what is going on with uvm (or whatever)
     52  1.1      mrg  */
     53  1.1      mrg 
     54  1.1      mrg /*
     55  1.1      mrg  * counters  [XXX: maybe replace event counters with this]
     56  1.1      mrg  */
     57  1.1      mrg 
     58  1.1      mrg #define UVMCNT_MASK	0xf			/* rest are private */
     59  1.1      mrg #define UVMCNT_CNT	0			/* normal counter */
     60  1.1      mrg #define UVMCNT_DEV	1			/* device event counter */
     61  1.1      mrg 
     62  1.1      mrg struct uvm_cnt {
     63  1.1      mrg 	int c;					/* the value */
     64  1.1      mrg 	int t;					/* type */
     65  1.1      mrg 	struct uvm_cnt *next;			/* global list of cnts */
     66  1.1      mrg 	char *name;				/* counter name */
     67  1.1      mrg 	void *p;				/* private data */
     68  1.1      mrg };
     69  1.1      mrg 
     70  1.1      mrg extern struct uvm_cnt *uvm_cnt_head;
     71  1.1      mrg 
     72  1.1      mrg /*
     73  1.3      chs  * counter operations.  assume spl is set ok.
     74  1.1      mrg  */
     75  1.1      mrg 
     76  1.1      mrg #define UVMCNT_INIT(CNT,TYP,VAL,NAM,PRIV) { \
     77  1.1      mrg 	CNT.c = VAL; \
     78  1.1      mrg 	CNT.t = TYP; \
     79  1.1      mrg 	CNT.next = uvm_cnt_head; \
     80  1.1      mrg 	uvm_cnt_head = &CNT; \
     81  1.1      mrg 	CNT.name = NAM; \
     82  1.1      mrg 	CNT.p = PRIV; \
     83  1.1      mrg 	}
     84  1.1      mrg 
     85  1.1      mrg #define UVMCNT_SET(C,V) { \
     86  1.1      mrg 	(C).c = (V); \
     87  1.1      mrg 	}
     88  1.1      mrg 
     89  1.1      mrg #define UVMCNT_ADD(C,V) { \
     90  1.1      mrg 	(C).c += (V); \
     91  1.1      mrg 	}
     92  1.1      mrg 
     93  1.1      mrg #define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
     94  1.1      mrg #define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
     95  1.1      mrg 
     96  1.1      mrg 
     97  1.1      mrg /*
     98  1.1      mrg  * history/tracing
     99  1.1      mrg  */
    100  1.1      mrg 
    101  1.1      mrg struct uvm_history_ent {
    102  1.1      mrg   struct timeval tv; 		/* time stamp */
    103  1.1      mrg   char *fmt; 			/* printf format */
    104  1.9  thorpej   size_t fmtlen;		/* length of printf format */
    105  1.1      mrg   char *fn;			/* function name */
    106  1.9  thorpej   size_t fnlen;			/* length of function name */
    107  1.1      mrg   u_long call;			/* function call number */
    108  1.1      mrg   u_long v[4];			/* values */
    109  1.1      mrg };
    110  1.1      mrg 
    111  1.1      mrg struct uvm_history {
    112  1.9  thorpej   const char *name;		/* name of this this history */
    113  1.9  thorpej   size_t namelen;		/* length of name, not including null */
    114  1.9  thorpej   LIST_ENTRY(uvm_history) list;	/* link on list of all histories */
    115  1.1      mrg   int n;			/* number of entries */
    116  1.1      mrg   int f; 			/* next free one */
    117  1.1      mrg   simple_lock_data_t l;		/* lock on this history */
    118  1.1      mrg   struct uvm_history_ent *e;	/* the malloc'd entries */
    119  1.1      mrg };
    120  1.1      mrg 
    121  1.9  thorpej LIST_HEAD(uvm_history_head, uvm_history);
    122  1.9  thorpej 
    123  1.1      mrg #ifndef UVMHIST
    124  1.1      mrg #define UVMHIST_DECL(NAME)
    125  1.1      mrg #define UVMHIST_INIT(NAME,N)
    126  1.1      mrg #define UVMHIST_INIT_STATIC(NAME,BUF)
    127  1.1      mrg #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
    128  1.1      mrg #define UVMHIST_CALLED(NAME)
    129  1.1      mrg #define UVMHIST_FUNC(FNAME)
    130  1.1      mrg #define uvmhist_dump(NAME)
    131  1.1      mrg #else
    132  1.9  thorpej extern	struct uvm_history_head uvm_histories;
    133  1.9  thorpej 
    134  1.1      mrg #define UVMHIST_DECL(NAME) struct uvm_history NAME
    135  1.1      mrg 
    136  1.1      mrg #define UVMHIST_INIT(NAME,N) { \
    137  1.9  thorpej 	(NAME).name = __STRING(NAME); \
    138  1.9  thorpej 	(NAME).namelen = strlen((NAME).name); \
    139  1.1      mrg 	(NAME).n = (N); \
    140  1.1      mrg 	(NAME).f = 0; \
    141  1.1      mrg 	simple_lock_init(&(NAME).l); \
    142  1.1      mrg 	(NAME).e = (struct uvm_history_ent *) \
    143  1.1      mrg 		malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
    144  1.1      mrg 				M_WAITOK); \
    145  1.1      mrg 	bzero((NAME).e, sizeof(struct uvm_history_ent) * (N)); \
    146  1.9  thorpej 	LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
    147  1.1      mrg 	}
    148  1.1      mrg 
    149  1.1      mrg #define UVMHIST_INIT_STATIC(NAME,BUF) { \
    150  1.9  thorpej 	(NAME).name = __STRING(NAME); \
    151  1.9  thorpej 	(NAME).namelen = strlen((NAME).name); \
    152  1.1      mrg 	(NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
    153  1.1      mrg 	(NAME).f = 0; \
    154  1.1      mrg 	simple_lock_init(&(NAME).l); \
    155  1.1      mrg 	(NAME).e = (struct uvm_history_ent *) (BUF); \
    156  1.1      mrg 	bzero((NAME).e, sizeof(struct uvm_history_ent) * (NAME).n); \
    157  1.9  thorpej 	LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
    158  1.1      mrg 	}
    159  1.1      mrg 
    160  1.1      mrg extern int cold;
    161  1.1      mrg 
    162  1.1      mrg #if defined(UVMHIST_PRINT)
    163  1.8  thorpej extern int uvmhist_print_enabled;
    164  1.8  thorpej #define UVMHIST_PRINTNOW(E) \
    165  1.8  thorpej 	do { \
    166  1.8  thorpej 		if (uvmhist_print_enabled) { \
    167  1.8  thorpej 			uvmhist_print(E); \
    168  1.8  thorpej 			DELAY(100000); \
    169  1.8  thorpej 		} \
    170  1.8  thorpej 	} while (0)
    171  1.1      mrg #else
    172  1.1      mrg #define UVMHIST_PRINTNOW(E) /* nothing */
    173  1.1      mrg #endif
    174  1.1      mrg 
    175  1.1      mrg #define UVMHIST_LOG(NAME,FMT,A,B,C,D) { \
    176  1.1      mrg 	register int i, s = splhigh(); \
    177  1.1      mrg 	simple_lock(&(NAME).l); \
    178  1.1      mrg 	i = (NAME).f; \
    179  1.1      mrg 	(NAME).f = (i + 1) % (NAME).n; \
    180  1.1      mrg 	simple_unlock(&(NAME).l); \
    181  1.1      mrg 	splx(s); \
    182  1.1      mrg 	if (!cold) microtime(&(NAME).e[i].tv); \
    183  1.1      mrg 	(NAME).e[i].fmt = (FMT); \
    184  1.9  thorpej 	(NAME).e[i].fmtlen = strlen((NAME).e[i].fmt); \
    185  1.1      mrg 	(NAME).e[i].fn = _uvmhist_name; \
    186  1.9  thorpej 	(NAME).e[i].fnlen = strlen((NAME).e[i].fn); \
    187  1.1      mrg 	(NAME).e[i].call = _uvmhist_call; \
    188  1.1      mrg 	(NAME).e[i].v[0] = (u_long)(A); \
    189  1.1      mrg 	(NAME).e[i].v[1] = (u_long)(B); \
    190  1.1      mrg 	(NAME).e[i].v[2] = (u_long)(C); \
    191  1.1      mrg 	(NAME).e[i].v[3] = (u_long)(D); \
    192  1.1      mrg         UVMHIST_PRINTNOW(&((NAME).e[i])); \
    193  1.1      mrg 	}
    194  1.1      mrg 
    195  1.1      mrg #define UVMHIST_CALLED(NAME) \
    196  1.1      mrg 	{ int s = splhigh(); simple_lock(&(NAME).l); \
    197  1.1      mrg 	 	_uvmhist_call = _uvmhist_cnt++; \
    198  1.1      mrg 	  simple_unlock(&(NAME).l); splx(s); } \
    199  1.1      mrg 	UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0);
    200  1.1      mrg 
    201  1.1      mrg #define UVMHIST_FUNC(FNAME) \
    202  1.1      mrg 	static int _uvmhist_cnt = 0; \
    203  1.1      mrg 	static char *_uvmhist_name = FNAME; \
    204  1.1      mrg 	int _uvmhist_call;
    205  1.1      mrg 
    206  1.1      mrg static __inline void uvmhist_print __P((struct uvm_history_ent *));
    207  1.1      mrg 	/* shut up GCC */
    208  1.1      mrg 
    209  1.1      mrg static __inline void uvmhist_print(e)
    210  1.1      mrg 
    211  1.1      mrg struct uvm_history_ent *e;
    212  1.1      mrg {
    213  1.1      mrg   printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
    214  1.1      mrg   printf("%s#%ld: ", e->fn, e->call);
    215  1.1      mrg   printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
    216  1.1      mrg   printf("\n");
    217  1.1      mrg }
    218  1.1      mrg 
    219  1.1      mrg #endif /* UVMHIST */
    220  1.6    perry 
    221  1.6    perry #endif /* _UVM_UVM_STAT_H_ */
    222