uvm_stat.h revision 1.22 1 1.22 mrg /* $NetBSD: uvm_stat.h,v 1.22 2001/05/30 11:57:17 mrg 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.22 mrg #if defined(_KERNEL_OPT)
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.21 chs struct simplelock 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.19 mrg #define UVMHIST_UBCHIST 0x00000004 /* ubchist */
138 1.12 mrg
139 1.15 thorpej #ifdef _KERNEL
140 1.15 thorpej
141 1.12 mrg /*
142 1.12 mrg * macros to use the history/tracing code. note that UVMHIST_LOG
143 1.12 mrg * must take 4 arguments (even if they are ignored by the format).
144 1.12 mrg */
145 1.1 mrg #ifndef UVMHIST
146 1.1 mrg #define UVMHIST_DECL(NAME)
147 1.1 mrg #define UVMHIST_INIT(NAME,N)
148 1.1 mrg #define UVMHIST_INIT_STATIC(NAME,BUF)
149 1.1 mrg #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
150 1.1 mrg #define UVMHIST_CALLED(NAME)
151 1.1 mrg #define UVMHIST_FUNC(FNAME)
152 1.1 mrg #define uvmhist_dump(NAME)
153 1.1 mrg #else
154 1.9 thorpej extern struct uvm_history_head uvm_histories;
155 1.9 thorpej
156 1.1 mrg #define UVMHIST_DECL(NAME) struct uvm_history NAME
157 1.1 mrg
158 1.10 thorpej #define UVMHIST_INIT(NAME,N) \
159 1.10 thorpej do { \
160 1.9 thorpej (NAME).name = __STRING(NAME); \
161 1.9 thorpej (NAME).namelen = strlen((NAME).name); \
162 1.1 mrg (NAME).n = (N); \
163 1.1 mrg (NAME).f = 0; \
164 1.1 mrg simple_lock_init(&(NAME).l); \
165 1.1 mrg (NAME).e = (struct uvm_history_ent *) \
166 1.1 mrg malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
167 1.10 thorpej M_WAITOK); \
168 1.13 perry memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \
169 1.9 thorpej LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
170 1.10 thorpej } while (0)
171 1.1 mrg
172 1.10 thorpej #define UVMHIST_INIT_STATIC(NAME,BUF) \
173 1.10 thorpej do { \
174 1.9 thorpej (NAME).name = __STRING(NAME); \
175 1.9 thorpej (NAME).namelen = strlen((NAME).name); \
176 1.1 mrg (NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
177 1.1 mrg (NAME).f = 0; \
178 1.1 mrg simple_lock_init(&(NAME).l); \
179 1.1 mrg (NAME).e = (struct uvm_history_ent *) (BUF); \
180 1.13 perry memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (NAME).n); \
181 1.9 thorpej LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
182 1.10 thorpej } while (0)
183 1.1 mrg
184 1.1 mrg extern int cold;
185 1.1 mrg
186 1.1 mrg #if defined(UVMHIST_PRINT)
187 1.8 thorpej extern int uvmhist_print_enabled;
188 1.8 thorpej #define UVMHIST_PRINTNOW(E) \
189 1.10 thorpej do { \
190 1.8 thorpej if (uvmhist_print_enabled) { \
191 1.8 thorpej uvmhist_print(E); \
192 1.8 thorpej DELAY(100000); \
193 1.8 thorpej } \
194 1.10 thorpej } while (0)
195 1.1 mrg #else
196 1.1 mrg #define UVMHIST_PRINTNOW(E) /* nothing */
197 1.1 mrg #endif
198 1.1 mrg
199 1.10 thorpej #define UVMHIST_LOG(NAME,FMT,A,B,C,D) \
200 1.10 thorpej do { \
201 1.18 pk int _i_, _s_ = splhigh(); \
202 1.1 mrg simple_lock(&(NAME).l); \
203 1.17 chs _i_ = (NAME).f; \
204 1.17 chs (NAME).f = (_i_ + 1) % (NAME).n; \
205 1.1 mrg simple_unlock(&(NAME).l); \
206 1.17 chs splx(_s_); \
207 1.10 thorpej if (!cold) \
208 1.17 chs microtime(&(NAME).e[_i_].tv); \
209 1.17 chs (NAME).e[_i_].fmt = (FMT); \
210 1.17 chs (NAME).e[_i_].fmtlen = strlen((NAME).e[_i_].fmt); \
211 1.17 chs (NAME).e[_i_].fn = _uvmhist_name; \
212 1.17 chs (NAME).e[_i_].fnlen = strlen((NAME).e[_i_].fn); \
213 1.17 chs (NAME).e[_i_].call = _uvmhist_call; \
214 1.17 chs (NAME).e[_i_].v[0] = (u_long)(A); \
215 1.17 chs (NAME).e[_i_].v[1] = (u_long)(B); \
216 1.17 chs (NAME).e[_i_].v[2] = (u_long)(C); \
217 1.17 chs (NAME).e[_i_].v[3] = (u_long)(D); \
218 1.17 chs UVMHIST_PRINTNOW(&((NAME).e[_i_])); \
219 1.10 thorpej } while (0)
220 1.1 mrg
221 1.1 mrg #define UVMHIST_CALLED(NAME) \
222 1.10 thorpej do { \
223 1.10 thorpej { \
224 1.10 thorpej int s = splhigh(); \
225 1.10 thorpej simple_lock(&(NAME).l); \
226 1.10 thorpej _uvmhist_call = _uvmhist_cnt++; \
227 1.10 thorpej simple_unlock(&(NAME).l); \
228 1.10 thorpej splx(s); \
229 1.10 thorpej } \
230 1.10 thorpej UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \
231 1.10 thorpej } while (0)
232 1.1 mrg
233 1.1 mrg #define UVMHIST_FUNC(FNAME) \
234 1.1 mrg static int _uvmhist_cnt = 0; \
235 1.1 mrg static char *_uvmhist_name = FNAME; \
236 1.20 chs int _uvmhist_call;
237 1.1 mrg
238 1.1 mrg static __inline void uvmhist_print __P((struct uvm_history_ent *));
239 1.1 mrg
240 1.10 thorpej static __inline void
241 1.10 thorpej uvmhist_print(e)
242 1.10 thorpej struct uvm_history_ent *e;
243 1.1 mrg {
244 1.10 thorpej printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
245 1.10 thorpej printf("%s#%ld: ", e->fn, e->call);
246 1.10 thorpej printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
247 1.10 thorpej printf("\n");
248 1.1 mrg }
249 1.1 mrg #endif /* UVMHIST */
250 1.15 thorpej
251 1.15 thorpej #endif /* _KERNEL */
252 1.6 perry
253 1.6 perry #endif /* _UVM_UVM_STAT_H_ */
254