Home | History | Annotate | Line # | Download | only in uvm
uvm_stat.h revision 1.13
      1  1.13    perry /*	$NetBSD: uvm_stat.h,v 1.13 1998/08/09 22:36:39 perry 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.10  thorpej #define UVMCNT_INIT(CNT,TYP,VAL,NAM,PRIV) \
     77  1.10  thorpej do { \
     78   1.1      mrg 	CNT.c = VAL; \
     79   1.1      mrg 	CNT.t = TYP; \
     80   1.1      mrg 	CNT.next = uvm_cnt_head; \
     81   1.1      mrg 	uvm_cnt_head = &CNT; \
     82   1.1      mrg 	CNT.name = NAM; \
     83   1.1      mrg 	CNT.p = PRIV; \
     84  1.10  thorpej } while (0)
     85   1.1      mrg 
     86  1.10  thorpej #define UVMCNT_SET(C,V) \
     87  1.10  thorpej do { \
     88   1.1      mrg 	(C).c = (V); \
     89  1.10  thorpej } while (0)
     90   1.1      mrg 
     91  1.10  thorpej #define UVMCNT_ADD(C,V) \
     92  1.10  thorpej do { \
     93   1.1      mrg 	(C).c += (V); \
     94  1.10  thorpej } while (0)
     95   1.1      mrg 
     96   1.1      mrg #define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
     97   1.1      mrg #define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
     98   1.1      mrg 
     99   1.1      mrg 
    100   1.1      mrg /*
    101   1.1      mrg  * history/tracing
    102   1.1      mrg  */
    103   1.1      mrg 
    104   1.1      mrg struct uvm_history_ent {
    105  1.10  thorpej 	struct timeval tv; 		/* time stamp */
    106  1.10  thorpej 	char *fmt; 			/* printf format */
    107  1.10  thorpej 	size_t fmtlen;			/* length of printf format */
    108  1.10  thorpej 	char *fn;			/* function name */
    109  1.10  thorpej 	size_t fnlen;			/* length of function name */
    110  1.10  thorpej 	u_long call;			/* function call number */
    111  1.10  thorpej 	u_long v[4];			/* values */
    112   1.1      mrg };
    113   1.1      mrg 
    114   1.1      mrg struct uvm_history {
    115  1.10  thorpej 	const char *name;		/* name of this this history */
    116  1.10  thorpej 	size_t namelen;			/* length of name, not including null */
    117  1.10  thorpej 	LIST_ENTRY(uvm_history) list;	/* link on list of all histories */
    118  1.10  thorpej 	int n;				/* number of entries */
    119  1.10  thorpej 	int f; 				/* next free one */
    120  1.10  thorpej 	simple_lock_data_t l;		/* lock on this history */
    121  1.10  thorpej 	struct uvm_history_ent *e;	/* the malloc'd entries */
    122   1.1      mrg };
    123   1.1      mrg 
    124   1.9  thorpej LIST_HEAD(uvm_history_head, uvm_history);
    125   1.9  thorpej 
    126  1.12      mrg /*
    127  1.12      mrg  * grovelling lists all at once.  we currently do not allow more than
    128  1.12      mrg  * 32 histories to exist, as the way to dump a number of them at once
    129  1.12      mrg  * is by calling uvm_hist() with a bitmask.
    130  1.12      mrg  */
    131  1.12      mrg 
    132  1.12      mrg /* this is used to set the size of some arrays */
    133  1.12      mrg #define	MAXHISTS		32	/* do not change this! */
    134  1.12      mrg 
    135  1.12      mrg /* and these are the bit values of each history */
    136  1.12      mrg #define	UVMHIST_MAPHIST		0x00000001	/* maphist */
    137  1.12      mrg #define	UVMHIST_PDHIST		0x00000002	/* pdhist */
    138  1.12      mrg 
    139  1.12      mrg /*
    140  1.12      mrg  * macros to use the history/tracing code.  note that UVMHIST_LOG
    141  1.12      mrg  * must take 4 arguments (even if they are ignored by the format).
    142  1.12      mrg  */
    143   1.1      mrg #ifndef UVMHIST
    144   1.1      mrg #define UVMHIST_DECL(NAME)
    145   1.1      mrg #define UVMHIST_INIT(NAME,N)
    146   1.1      mrg #define UVMHIST_INIT_STATIC(NAME,BUF)
    147   1.1      mrg #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
    148   1.1      mrg #define UVMHIST_CALLED(NAME)
    149   1.1      mrg #define UVMHIST_FUNC(FNAME)
    150   1.1      mrg #define uvmhist_dump(NAME)
    151   1.1      mrg #else
    152   1.9  thorpej extern	struct uvm_history_head uvm_histories;
    153   1.9  thorpej 
    154   1.1      mrg #define UVMHIST_DECL(NAME) struct uvm_history NAME
    155   1.1      mrg 
    156  1.10  thorpej #define UVMHIST_INIT(NAME,N) \
    157  1.10  thorpej do { \
    158   1.9  thorpej 	(NAME).name = __STRING(NAME); \
    159   1.9  thorpej 	(NAME).namelen = strlen((NAME).name); \
    160   1.1      mrg 	(NAME).n = (N); \
    161   1.1      mrg 	(NAME).f = 0; \
    162   1.1      mrg 	simple_lock_init(&(NAME).l); \
    163   1.1      mrg 	(NAME).e = (struct uvm_history_ent *) \
    164   1.1      mrg 		malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
    165  1.10  thorpej 		    M_WAITOK); \
    166  1.13    perry 	memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \
    167   1.9  thorpej 	LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
    168  1.10  thorpej } while (0)
    169   1.1      mrg 
    170  1.10  thorpej #define UVMHIST_INIT_STATIC(NAME,BUF) \
    171  1.10  thorpej do { \
    172   1.9  thorpej 	(NAME).name = __STRING(NAME); \
    173   1.9  thorpej 	(NAME).namelen = strlen((NAME).name); \
    174   1.1      mrg 	(NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
    175   1.1      mrg 	(NAME).f = 0; \
    176   1.1      mrg 	simple_lock_init(&(NAME).l); \
    177   1.1      mrg 	(NAME).e = (struct uvm_history_ent *) (BUF); \
    178  1.13    perry 	memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (NAME).n); \
    179   1.9  thorpej 	LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
    180  1.10  thorpej } while (0)
    181   1.1      mrg 
    182   1.1      mrg extern int cold;
    183   1.1      mrg 
    184   1.1      mrg #if defined(UVMHIST_PRINT)
    185   1.8  thorpej extern int uvmhist_print_enabled;
    186   1.8  thorpej #define UVMHIST_PRINTNOW(E) \
    187  1.10  thorpej do { \
    188   1.8  thorpej 		if (uvmhist_print_enabled) { \
    189   1.8  thorpej 			uvmhist_print(E); \
    190   1.8  thorpej 			DELAY(100000); \
    191   1.8  thorpej 		} \
    192  1.10  thorpej } while (0)
    193   1.1      mrg #else
    194   1.1      mrg #define UVMHIST_PRINTNOW(E) /* nothing */
    195   1.1      mrg #endif
    196   1.1      mrg 
    197  1.10  thorpej #define UVMHIST_LOG(NAME,FMT,A,B,C,D) \
    198  1.10  thorpej do { \
    199   1.1      mrg 	register int i, s = splhigh(); \
    200   1.1      mrg 	simple_lock(&(NAME).l); \
    201   1.1      mrg 	i = (NAME).f; \
    202   1.1      mrg 	(NAME).f = (i + 1) % (NAME).n; \
    203   1.1      mrg 	simple_unlock(&(NAME).l); \
    204   1.1      mrg 	splx(s); \
    205  1.10  thorpej 	if (!cold) \
    206  1.10  thorpej 		microtime(&(NAME).e[i].tv); \
    207   1.1      mrg 	(NAME).e[i].fmt = (FMT); \
    208   1.9  thorpej 	(NAME).e[i].fmtlen = strlen((NAME).e[i].fmt); \
    209   1.1      mrg 	(NAME).e[i].fn = _uvmhist_name; \
    210   1.9  thorpej 	(NAME).e[i].fnlen = strlen((NAME).e[i].fn); \
    211   1.1      mrg 	(NAME).e[i].call = _uvmhist_call; \
    212   1.1      mrg 	(NAME).e[i].v[0] = (u_long)(A); \
    213   1.1      mrg 	(NAME).e[i].v[1] = (u_long)(B); \
    214   1.1      mrg 	(NAME).e[i].v[2] = (u_long)(C); \
    215   1.1      mrg 	(NAME).e[i].v[3] = (u_long)(D); \
    216  1.11      mrg 	UVMHIST_PRINTNOW(&((NAME).e[i])); \
    217  1.10  thorpej } while (0)
    218   1.1      mrg 
    219   1.1      mrg #define UVMHIST_CALLED(NAME) \
    220  1.10  thorpej do { \
    221  1.10  thorpej 	{ \
    222  1.10  thorpej 		int s = splhigh(); \
    223  1.10  thorpej 		simple_lock(&(NAME).l); \
    224  1.10  thorpej 		_uvmhist_call = _uvmhist_cnt++; \
    225  1.10  thorpej 		simple_unlock(&(NAME).l); \
    226  1.10  thorpej 		splx(s); \
    227  1.10  thorpej 	} \
    228  1.10  thorpej 	UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \
    229  1.10  thorpej } while (0)
    230   1.1      mrg 
    231   1.1      mrg #define UVMHIST_FUNC(FNAME) \
    232   1.1      mrg 	static int _uvmhist_cnt = 0; \
    233   1.1      mrg 	static char *_uvmhist_name = FNAME; \
    234   1.1      mrg 	int _uvmhist_call;
    235   1.1      mrg 
    236   1.1      mrg static __inline void uvmhist_print __P((struct uvm_history_ent *));
    237   1.1      mrg 
    238  1.10  thorpej static __inline void
    239  1.10  thorpej uvmhist_print(e)
    240  1.10  thorpej 	struct uvm_history_ent *e;
    241   1.1      mrg {
    242  1.10  thorpej 	printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
    243  1.10  thorpej 	printf("%s#%ld: ", e->fn, e->call);
    244  1.10  thorpej 	printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
    245  1.10  thorpej 	printf("\n");
    246   1.1      mrg }
    247   1.1      mrg #endif /* UVMHIST */
    248   1.6    perry 
    249   1.6    perry #endif /* _UVM_UVM_STAT_H_ */
    250