Home | History | Annotate | Line # | Download | only in uvm
uvm_stat.h revision 1.17
      1  1.17       chs /*	$NetBSD: uvm_stat.h,v 1.17 2000/04/11 02:34:19 chs Exp $	*/
      2   1.1       mrg 
      3   1.1       mrg /*
      4   1.1       mrg  *
      5   1.1       mrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      6   1.1       mrg  * All rights reserved.
      7   1.1       mrg  *
      8   1.1       mrg  * Redistribution and use in source and binary forms, with or without
      9   1.1       mrg  * modification, are permitted provided that the following conditions
     10   1.1       mrg  * are met:
     11   1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     12   1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     13   1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     15   1.1       mrg  *    documentation and/or other materials provided with the distribution.
     16   1.1       mrg  * 3. All advertising materials mentioning features or use of this software
     17   1.1       mrg  *    must display the following acknowledgement:
     18   1.1       mrg  *      This product includes software developed by Charles D. Cranor and
     19   1.1       mrg  *      Washington University.
     20   1.1       mrg  * 4. The name of the author may not be used to endorse or promote products
     21   1.1       mrg  *    derived from this software without specific prior written permission.
     22   1.1       mrg  *
     23   1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24   1.1       mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25   1.1       mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26   1.1       mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27   1.1       mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28   1.1       mrg  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29   1.1       mrg  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30   1.1       mrg  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31   1.1       mrg  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32   1.1       mrg  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33   1.4       mrg  *
     34   1.4       mrg  * from: Id: uvm_stat.h,v 1.1.2.4 1998/02/07 01:16:56 chs Exp
     35   1.1       mrg  */
     36   1.6     perry 
     37   1.6     perry #ifndef _UVM_UVM_STAT_H_
     38   1.6     perry #define _UVM_UVM_STAT_H_
     39   1.7       mrg 
     40   1.9   thorpej #if defined(_KERNEL) && !defined(_LKM)
     41   1.7       mrg #include "opt_uvmhist.h"
     42   1.9   thorpej #endif
     43   1.9   thorpej 
     44   1.9   thorpej #include <sys/queue.h>
     45   1.6     perry 
     46   1.1       mrg /*
     47   1.1       mrg  * uvm_stat: monitor what is going on with uvm (or whatever)
     48   1.1       mrg  */
     49   1.1       mrg 
     50   1.1       mrg /*
     51   1.1       mrg  * counters  [XXX: maybe replace event counters with this]
     52   1.1       mrg  */
     53   1.1       mrg 
     54   1.1       mrg #define UVMCNT_MASK	0xf			/* rest are private */
     55   1.1       mrg #define UVMCNT_CNT	0			/* normal counter */
     56   1.1       mrg #define UVMCNT_DEV	1			/* device event counter */
     57   1.1       mrg 
     58   1.1       mrg struct uvm_cnt {
     59   1.1       mrg 	int c;					/* the value */
     60   1.1       mrg 	int t;					/* type */
     61   1.1       mrg 	struct uvm_cnt *next;			/* global list of cnts */
     62   1.1       mrg 	char *name;				/* counter name */
     63   1.1       mrg 	void *p;				/* private data */
     64   1.1       mrg };
     65   1.1       mrg 
     66  1.15   thorpej #ifdef _KERNEL
     67  1.15   thorpej 
     68   1.1       mrg extern struct uvm_cnt *uvm_cnt_head;
     69   1.1       mrg 
     70   1.1       mrg /*
     71   1.3       chs  * counter operations.  assume spl is set ok.
     72   1.1       mrg  */
     73   1.1       mrg 
     74  1.10   thorpej #define UVMCNT_INIT(CNT,TYP,VAL,NAM,PRIV) \
     75  1.10   thorpej do { \
     76   1.1       mrg 	CNT.c = VAL; \
     77   1.1       mrg 	CNT.t = TYP; \
     78   1.1       mrg 	CNT.next = uvm_cnt_head; \
     79   1.1       mrg 	uvm_cnt_head = &CNT; \
     80   1.1       mrg 	CNT.name = NAM; \
     81   1.1       mrg 	CNT.p = PRIV; \
     82  1.10   thorpej } while (0)
     83   1.1       mrg 
     84  1.10   thorpej #define UVMCNT_SET(C,V) \
     85  1.10   thorpej do { \
     86   1.1       mrg 	(C).c = (V); \
     87  1.10   thorpej } while (0)
     88   1.1       mrg 
     89  1.10   thorpej #define UVMCNT_ADD(C,V) \
     90  1.10   thorpej do { \
     91   1.1       mrg 	(C).c += (V); \
     92  1.10   thorpej } while (0)
     93   1.1       mrg 
     94   1.1       mrg #define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
     95   1.1       mrg #define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
     96   1.1       mrg 
     97  1.15   thorpej #endif /* _KERNEL */
     98   1.1       mrg 
     99   1.1       mrg /*
    100   1.1       mrg  * history/tracing
    101   1.1       mrg  */
    102   1.1       mrg 
    103   1.1       mrg struct uvm_history_ent {
    104  1.10   thorpej 	struct timeval tv; 		/* time stamp */
    105  1.10   thorpej 	char *fmt; 			/* printf format */
    106  1.10   thorpej 	size_t fmtlen;			/* length of printf format */
    107  1.10   thorpej 	char *fn;			/* function name */
    108  1.10   thorpej 	size_t fnlen;			/* length of function name */
    109  1.10   thorpej 	u_long call;			/* function call number */
    110  1.10   thorpej 	u_long v[4];			/* values */
    111   1.1       mrg };
    112   1.1       mrg 
    113   1.1       mrg struct uvm_history {
    114  1.10   thorpej 	const char *name;		/* name of this this history */
    115  1.10   thorpej 	size_t namelen;			/* length of name, not including null */
    116  1.10   thorpej 	LIST_ENTRY(uvm_history) list;	/* link on list of all histories */
    117  1.10   thorpej 	int n;				/* number of entries */
    118  1.10   thorpej 	int f; 				/* next free one */
    119  1.10   thorpej 	simple_lock_data_t l;		/* lock on this history */
    120  1.10   thorpej 	struct uvm_history_ent *e;	/* the malloc'd entries */
    121   1.1       mrg };
    122   1.1       mrg 
    123   1.9   thorpej LIST_HEAD(uvm_history_head, uvm_history);
    124   1.9   thorpej 
    125  1.12       mrg /*
    126  1.12       mrg  * grovelling lists all at once.  we currently do not allow more than
    127  1.12       mrg  * 32 histories to exist, as the way to dump a number of them at once
    128  1.12       mrg  * is by calling uvm_hist() with a bitmask.
    129  1.12       mrg  */
    130  1.12       mrg 
    131  1.12       mrg /* this is used to set the size of some arrays */
    132  1.12       mrg #define	MAXHISTS		32	/* do not change this! */
    133  1.12       mrg 
    134  1.12       mrg /* and these are the bit values of each history */
    135  1.12       mrg #define	UVMHIST_MAPHIST		0x00000001	/* maphist */
    136  1.12       mrg #define	UVMHIST_PDHIST		0x00000002	/* pdhist */
    137  1.12       mrg 
    138  1.15   thorpej #ifdef _KERNEL
    139  1.15   thorpej 
    140  1.12       mrg /*
    141  1.12       mrg  * macros to use the history/tracing code.  note that UVMHIST_LOG
    142  1.12       mrg  * must take 4 arguments (even if they are ignored by the format).
    143  1.12       mrg  */
    144   1.1       mrg #ifndef UVMHIST
    145   1.1       mrg #define UVMHIST_DECL(NAME)
    146   1.1       mrg #define UVMHIST_INIT(NAME,N)
    147   1.1       mrg #define UVMHIST_INIT_STATIC(NAME,BUF)
    148   1.1       mrg #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
    149   1.1       mrg #define UVMHIST_CALLED(NAME)
    150   1.1       mrg #define UVMHIST_FUNC(FNAME)
    151   1.1       mrg #define uvmhist_dump(NAME)
    152   1.1       mrg #else
    153   1.9   thorpej extern	struct uvm_history_head uvm_histories;
    154   1.9   thorpej 
    155   1.1       mrg #define UVMHIST_DECL(NAME) struct uvm_history NAME
    156   1.1       mrg 
    157  1.10   thorpej #define UVMHIST_INIT(NAME,N) \
    158  1.10   thorpej do { \
    159   1.9   thorpej 	(NAME).name = __STRING(NAME); \
    160   1.9   thorpej 	(NAME).namelen = strlen((NAME).name); \
    161   1.1       mrg 	(NAME).n = (N); \
    162   1.1       mrg 	(NAME).f = 0; \
    163   1.1       mrg 	simple_lock_init(&(NAME).l); \
    164   1.1       mrg 	(NAME).e = (struct uvm_history_ent *) \
    165   1.1       mrg 		malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
    166  1.10   thorpej 		    M_WAITOK); \
    167  1.13     perry 	memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \
    168   1.9   thorpej 	LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
    169  1.10   thorpej } while (0)
    170   1.1       mrg 
    171  1.10   thorpej #define UVMHIST_INIT_STATIC(NAME,BUF) \
    172  1.10   thorpej do { \
    173   1.9   thorpej 	(NAME).name = __STRING(NAME); \
    174   1.9   thorpej 	(NAME).namelen = strlen((NAME).name); \
    175   1.1       mrg 	(NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
    176   1.1       mrg 	(NAME).f = 0; \
    177   1.1       mrg 	simple_lock_init(&(NAME).l); \
    178   1.1       mrg 	(NAME).e = (struct uvm_history_ent *) (BUF); \
    179  1.13     perry 	memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (NAME).n); \
    180   1.9   thorpej 	LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
    181  1.10   thorpej } while (0)
    182   1.1       mrg 
    183   1.1       mrg extern int cold;
    184   1.1       mrg 
    185   1.1       mrg #if defined(UVMHIST_PRINT)
    186   1.8   thorpej extern int uvmhist_print_enabled;
    187   1.8   thorpej #define UVMHIST_PRINTNOW(E) \
    188  1.10   thorpej do { \
    189   1.8   thorpej 		if (uvmhist_print_enabled) { \
    190   1.8   thorpej 			uvmhist_print(E); \
    191   1.8   thorpej 			DELAY(100000); \
    192   1.8   thorpej 		} \
    193  1.10   thorpej } while (0)
    194   1.1       mrg #else
    195   1.1       mrg #define UVMHIST_PRINTNOW(E) /* nothing */
    196   1.1       mrg #endif
    197   1.1       mrg 
    198  1.10   thorpej #define UVMHIST_LOG(NAME,FMT,A,B,C,D) \
    199  1.10   thorpej do { \
    200  1.16  augustss 	int i, s = splhigh(); \
    201   1.1       mrg 	simple_lock(&(NAME).l); \
    202  1.17       chs 	_i_ = (NAME).f; \
    203  1.17       chs 	(NAME).f = (_i_ + 1) % (NAME).n; \
    204   1.1       mrg 	simple_unlock(&(NAME).l); \
    205  1.17       chs 	splx(_s_); \
    206  1.10   thorpej 	if (!cold) \
    207  1.17       chs 		microtime(&(NAME).e[_i_].tv); \
    208  1.17       chs 	(NAME).e[_i_].fmt = (FMT); \
    209  1.17       chs 	(NAME).e[_i_].fmtlen = strlen((NAME).e[_i_].fmt); \
    210  1.17       chs 	(NAME).e[_i_].fn = _uvmhist_name; \
    211  1.17       chs 	(NAME).e[_i_].fnlen = strlen((NAME).e[_i_].fn); \
    212  1.17       chs 	(NAME).e[_i_].call = _uvmhist_call; \
    213  1.17       chs 	(NAME).e[_i_].v[0] = (u_long)(A); \
    214  1.17       chs 	(NAME).e[_i_].v[1] = (u_long)(B); \
    215  1.17       chs 	(NAME).e[_i_].v[2] = (u_long)(C); \
    216  1.17       chs 	(NAME).e[_i_].v[3] = (u_long)(D); \
    217  1.17       chs 	UVMHIST_PRINTNOW(&((NAME).e[_i_])); \
    218  1.10   thorpej } while (0)
    219   1.1       mrg 
    220   1.1       mrg #define UVMHIST_CALLED(NAME) \
    221  1.10   thorpej do { \
    222  1.10   thorpej 	{ \
    223  1.10   thorpej 		int s = splhigh(); \
    224  1.10   thorpej 		simple_lock(&(NAME).l); \
    225  1.10   thorpej 		_uvmhist_call = _uvmhist_cnt++; \
    226  1.10   thorpej 		simple_unlock(&(NAME).l); \
    227  1.10   thorpej 		splx(s); \
    228  1.10   thorpej 	} \
    229  1.10   thorpej 	UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \
    230  1.10   thorpej } while (0)
    231   1.1       mrg 
    232   1.1       mrg #define UVMHIST_FUNC(FNAME) \
    233   1.1       mrg 	static int _uvmhist_cnt = 0; \
    234   1.1       mrg 	static char *_uvmhist_name = FNAME; \
    235   1.1       mrg 	int _uvmhist_call;
    236   1.1       mrg 
    237   1.1       mrg static __inline void uvmhist_print __P((struct uvm_history_ent *));
    238   1.1       mrg 
    239  1.10   thorpej static __inline void
    240  1.10   thorpej uvmhist_print(e)
    241  1.10   thorpej 	struct uvm_history_ent *e;
    242   1.1       mrg {
    243  1.10   thorpej 	printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
    244  1.10   thorpej 	printf("%s#%ld: ", e->fn, e->call);
    245  1.10   thorpej 	printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
    246  1.10   thorpej 	printf("\n");
    247   1.1       mrg }
    248   1.1       mrg #endif /* UVMHIST */
    249  1.15   thorpej 
    250  1.15   thorpej #endif /* _KERNEL */
    251   1.6     perry 
    252   1.6     perry #endif /* _UVM_UVM_STAT_H_ */
    253