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