1 /* $NetBSD: uvm_stat.h,v 1.27 2003/03/08 15:17:23 tsutsui 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_OPT) 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 (/*CONSTCOND*/ 0) 83 84 #define UVMCNT_SET(C,V) \ 85 do { \ 86 (C).c = (V); \ 87 } while (/*CONSTCOND*/ 0) 88 89 #define UVMCNT_ADD(C,V) \ 90 do { \ 91 (C).c += (V); \ 92 } while (/*CONSTCOND*/ 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 int cpunum; 106 char *fmt; /* printf format */ 107 size_t fmtlen; /* length of printf format */ 108 char *fn; /* function name */ 109 size_t fnlen; /* length of function name */ 110 u_long call; /* function call number */ 111 u_long v[4]; /* values */ 112 }; 113 114 struct uvm_history { 115 const char *name; /* name of this this history */ 116 size_t namelen; /* length of name, not including null */ 117 LIST_ENTRY(uvm_history) list; /* link on list of all histories */ 118 int n; /* number of entries */ 119 int f; /* next free one */ 120 struct simplelock l; /* lock on this history */ 121 struct uvm_history_ent *e; /* the malloc'd entries */ 122 }; 123 124 LIST_HEAD(uvm_history_head, uvm_history); 125 126 /* 127 * grovelling lists all at once. we currently do not allow more than 128 * 32 histories to exist, as the way to dump a number of them at once 129 * is by calling uvm_hist() with a bitmask. 130 */ 131 132 /* this is used to set the size of some arrays */ 133 #define MAXHISTS 32 /* do not change this! */ 134 135 /* and these are the bit values of each history */ 136 #define UVMHIST_MAPHIST 0x00000001 /* maphist */ 137 #define UVMHIST_PDHIST 0x00000002 /* pdhist */ 138 #define UVMHIST_UBCHIST 0x00000004 /* ubchist */ 139 140 #ifdef _KERNEL 141 142 /* 143 * macros to use the history/tracing code. note that UVMHIST_LOG 144 * must take 4 arguments (even if they are ignored by the format). 145 */ 146 #ifndef UVMHIST 147 #define UVMHIST_DECL(NAME) 148 #define UVMHIST_INIT(NAME,N) 149 #define UVMHIST_INIT_STATIC(NAME,BUF) 150 #define UVMHIST_LOG(NAME,FMT,A,B,C,D) 151 #define UVMHIST_CALLED(NAME) 152 #define UVMHIST_FUNC(FNAME) 153 #define uvmhist_dump(NAME) 154 #else 155 #include <sys/kernel.h> /* for "cold" variable */ 156 157 extern struct uvm_history_head uvm_histories; 158 159 #define UVMHIST_DECL(NAME) struct uvm_history NAME 160 161 #define UVMHIST_INIT(NAME,N) \ 162 do { \ 163 (NAME).name = __STRING(NAME); \ 164 (NAME).namelen = strlen((NAME).name); \ 165 (NAME).n = (N); \ 166 (NAME).f = 0; \ 167 simple_lock_init(&(NAME).l); \ 168 (NAME).e = (struct uvm_history_ent *) \ 169 malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \ 170 M_WAITOK); \ 171 memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \ 172 LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \ 173 } while (/*CONSTCOND*/ 0) 174 175 #define UVMHIST_INIT_STATIC(NAME,BUF) \ 176 do { \ 177 (NAME).name = __STRING(NAME); \ 178 (NAME).namelen = strlen((NAME).name); \ 179 (NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \ 180 (NAME).f = 0; \ 181 simple_lock_init(&(NAME).l); \ 182 (NAME).e = (struct uvm_history_ent *) (BUF); \ 183 memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (NAME).n); \ 184 LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \ 185 } while (/*CONSTCOND*/ 0) 186 187 #if defined(UVMHIST_PRINT) 188 extern int uvmhist_print_enabled; 189 #define UVMHIST_PRINTNOW(E) \ 190 do { \ 191 if (uvmhist_print_enabled) { \ 192 uvmhist_print(E); \ 193 DELAY(100000); \ 194 } \ 195 } while (/*CONSTCOND*/ 0) 196 #else 197 #define UVMHIST_PRINTNOW(E) /* nothing */ 198 #endif 199 200 #define UVMHIST_LOG(NAME,FMT,A,B,C,D) \ 201 do { \ 202 int _i_, _s_ = splhigh(); \ 203 simple_lock(&(NAME).l); \ 204 _i_ = (NAME).f; \ 205 (NAME).f = (_i_ + 1) % (NAME).n; \ 206 simple_unlock(&(NAME).l); \ 207 splx(_s_); \ 208 if (!cold) \ 209 microtime(&(NAME).e[_i_].tv); \ 210 (NAME).e[_i_].cpunum = cpu_number(); \ 211 (NAME).e[_i_].fmt = (FMT); \ 212 (NAME).e[_i_].fmtlen = strlen((NAME).e[_i_].fmt); \ 213 (NAME).e[_i_].fn = _uvmhist_name; \ 214 (NAME).e[_i_].fnlen = strlen((NAME).e[_i_].fn); \ 215 (NAME).e[_i_].call = _uvmhist_call; \ 216 (NAME).e[_i_].v[0] = (u_long)(A); \ 217 (NAME).e[_i_].v[1] = (u_long)(B); \ 218 (NAME).e[_i_].v[2] = (u_long)(C); \ 219 (NAME).e[_i_].v[3] = (u_long)(D); \ 220 UVMHIST_PRINTNOW(&((NAME).e[_i_])); \ 221 } while (/*CONSTCOND*/ 0) 222 223 #define UVMHIST_CALLED(NAME) \ 224 do { \ 225 { \ 226 int s = splhigh(); \ 227 simple_lock(&(NAME).l); \ 228 _uvmhist_call = _uvmhist_cnt++; \ 229 simple_unlock(&(NAME).l); \ 230 splx(s); \ 231 } \ 232 UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \ 233 } while (/*CONSTCOND*/ 0) 234 235 #define UVMHIST_FUNC(FNAME) \ 236 static int _uvmhist_cnt = 0; \ 237 static char *_uvmhist_name = FNAME; \ 238 int _uvmhist_call; 239 240 static __inline void uvmhist_print __P((struct uvm_history_ent *)); 241 242 static __inline void 243 uvmhist_print(e) 244 struct uvm_history_ent *e; 245 { 246 printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec); 247 printf("%s#%ld@%d: ", e->fn, e->call, e->cpunum); 248 printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]); 249 printf("\n"); 250 } 251 #endif /* UVMHIST */ 252 253 #endif /* _KERNEL */ 254 255 #endif /* _UVM_UVM_STAT_H_ */ 256