uvm_stat.h revision 1.10 1 /* $NetBSD: uvm_stat.h,v 1.10 1998/02/13 05:33:56 thorpej 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 #ifndef UVMHIST
127 #define UVMHIST_DECL(NAME)
128 #define UVMHIST_INIT(NAME,N)
129 #define UVMHIST_INIT_STATIC(NAME,BUF)
130 #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
131 #define UVMHIST_CALLED(NAME)
132 #define UVMHIST_FUNC(FNAME)
133 #define uvmhist_dump(NAME)
134 #else
135 extern struct uvm_history_head uvm_histories;
136
137 #define UVMHIST_DECL(NAME) struct uvm_history NAME
138
139 #define UVMHIST_INIT(NAME,N) \
140 do { \
141 (NAME).name = __STRING(NAME); \
142 (NAME).namelen = strlen((NAME).name); \
143 (NAME).n = (N); \
144 (NAME).f = 0; \
145 simple_lock_init(&(NAME).l); \
146 (NAME).e = (struct uvm_history_ent *) \
147 malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
148 M_WAITOK); \
149 bzero((NAME).e, sizeof(struct uvm_history_ent) * (N)); \
150 LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
151 } while (0)
152
153 #define UVMHIST_INIT_STATIC(NAME,BUF) \
154 do { \
155 (NAME).name = __STRING(NAME); \
156 (NAME).namelen = strlen((NAME).name); \
157 (NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
158 (NAME).f = 0; \
159 simple_lock_init(&(NAME).l); \
160 (NAME).e = (struct uvm_history_ent *) (BUF); \
161 bzero((NAME).e, sizeof(struct uvm_history_ent) * (NAME).n); \
162 LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
163 } while (0)
164
165 extern int cold;
166
167 #if defined(UVMHIST_PRINT)
168 extern int uvmhist_print_enabled;
169 #define UVMHIST_PRINTNOW(E) \
170 do { \
171 if (uvmhist_print_enabled) { \
172 uvmhist_print(E); \
173 DELAY(100000); \
174 } \
175 } while (0)
176 #else
177 #define UVMHIST_PRINTNOW(E) /* nothing */
178 #endif
179
180 #define UVMHIST_LOG(NAME,FMT,A,B,C,D) \
181 do { \
182 register int i, s = splhigh(); \
183 simple_lock(&(NAME).l); \
184 i = (NAME).f; \
185 (NAME).f = (i + 1) % (NAME).n; \
186 simple_unlock(&(NAME).l); \
187 splx(s); \
188 if (!cold) \
189 microtime(&(NAME).e[i].tv); \
190 (NAME).e[i].fmt = (FMT); \
191 (NAME).e[i].fmtlen = strlen((NAME).e[i].fmt); \
192 (NAME).e[i].fn = _uvmhist_name; \
193 (NAME).e[i].fnlen = strlen((NAME).e[i].fn); \
194 (NAME).e[i].call = _uvmhist_call; \
195 (NAME).e[i].v[0] = (u_long)(A); \
196 (NAME).e[i].v[1] = (u_long)(B); \
197 (NAME).e[i].v[2] = (u_long)(C); \
198 (NAME).e[i].v[3] = (u_long)(D); \
199 UVMHIST_PRINTNOW(&((NAME).e[i])); \
200 } while (0)
201
202 #define UVMHIST_CALLED(NAME) \
203 do { \
204 { \
205 int s = splhigh(); \
206 simple_lock(&(NAME).l); \
207 _uvmhist_call = _uvmhist_cnt++; \
208 simple_unlock(&(NAME).l); \
209 splx(s); \
210 } \
211 UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \
212 } while (0)
213
214 #define UVMHIST_FUNC(FNAME) \
215 static int _uvmhist_cnt = 0; \
216 static char *_uvmhist_name = FNAME; \
217 int _uvmhist_call;
218
219 static __inline void uvmhist_print __P((struct uvm_history_ent *));
220
221 static __inline void
222 uvmhist_print(e)
223 struct uvm_history_ent *e;
224 {
225 printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
226 printf("%s#%ld: ", e->fn, e->call);
227 printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
228 printf("\n");
229 }
230 #endif /* UVMHIST */
231
232 #endif /* _UVM_UVM_STAT_H_ */
233