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