uvm_stat.h revision 1.9 1 /* $NetBSD: uvm_stat.h,v 1.9 1998/02/13 04:55:14 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 CNT.c = VAL; \
78 CNT.t = TYP; \
79 CNT.next = uvm_cnt_head; \
80 uvm_cnt_head = &CNT; \
81 CNT.name = NAM; \
82 CNT.p = PRIV; \
83 }
84
85 #define UVMCNT_SET(C,V) { \
86 (C).c = (V); \
87 }
88
89 #define UVMCNT_ADD(C,V) { \
90 (C).c += (V); \
91 }
92
93 #define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
94 #define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
95
96
97 /*
98 * history/tracing
99 */
100
101 struct uvm_history_ent {
102 struct timeval tv; /* time stamp */
103 char *fmt; /* printf format */
104 size_t fmtlen; /* length of printf format */
105 char *fn; /* function name */
106 size_t fnlen; /* length of function name */
107 u_long call; /* function call number */
108 u_long v[4]; /* values */
109 };
110
111 struct uvm_history {
112 const char *name; /* name of this this history */
113 size_t namelen; /* length of name, not including null */
114 LIST_ENTRY(uvm_history) list; /* link on list of all histories */
115 int n; /* number of entries */
116 int f; /* next free one */
117 simple_lock_data_t l; /* lock on this history */
118 struct uvm_history_ent *e; /* the malloc'd entries */
119 };
120
121 LIST_HEAD(uvm_history_head, uvm_history);
122
123 #ifndef UVMHIST
124 #define UVMHIST_DECL(NAME)
125 #define UVMHIST_INIT(NAME,N)
126 #define UVMHIST_INIT_STATIC(NAME,BUF)
127 #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
128 #define UVMHIST_CALLED(NAME)
129 #define UVMHIST_FUNC(FNAME)
130 #define uvmhist_dump(NAME)
131 #else
132 extern struct uvm_history_head uvm_histories;
133
134 #define UVMHIST_DECL(NAME) struct uvm_history NAME
135
136 #define UVMHIST_INIT(NAME,N) { \
137 (NAME).name = __STRING(NAME); \
138 (NAME).namelen = strlen((NAME).name); \
139 (NAME).n = (N); \
140 (NAME).f = 0; \
141 simple_lock_init(&(NAME).l); \
142 (NAME).e = (struct uvm_history_ent *) \
143 malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
144 M_WAITOK); \
145 bzero((NAME).e, sizeof(struct uvm_history_ent) * (N)); \
146 LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
147 }
148
149 #define UVMHIST_INIT_STATIC(NAME,BUF) { \
150 (NAME).name = __STRING(NAME); \
151 (NAME).namelen = strlen((NAME).name); \
152 (NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
153 (NAME).f = 0; \
154 simple_lock_init(&(NAME).l); \
155 (NAME).e = (struct uvm_history_ent *) (BUF); \
156 bzero((NAME).e, sizeof(struct uvm_history_ent) * (NAME).n); \
157 LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
158 }
159
160 extern int cold;
161
162 #if defined(UVMHIST_PRINT)
163 extern int uvmhist_print_enabled;
164 #define UVMHIST_PRINTNOW(E) \
165 do { \
166 if (uvmhist_print_enabled) { \
167 uvmhist_print(E); \
168 DELAY(100000); \
169 } \
170 } while (0)
171 #else
172 #define UVMHIST_PRINTNOW(E) /* nothing */
173 #endif
174
175 #define UVMHIST_LOG(NAME,FMT,A,B,C,D) { \
176 register int i, s = splhigh(); \
177 simple_lock(&(NAME).l); \
178 i = (NAME).f; \
179 (NAME).f = (i + 1) % (NAME).n; \
180 simple_unlock(&(NAME).l); \
181 splx(s); \
182 if (!cold) microtime(&(NAME).e[i].tv); \
183 (NAME).e[i].fmt = (FMT); \
184 (NAME).e[i].fmtlen = strlen((NAME).e[i].fmt); \
185 (NAME).e[i].fn = _uvmhist_name; \
186 (NAME).e[i].fnlen = strlen((NAME).e[i].fn); \
187 (NAME).e[i].call = _uvmhist_call; \
188 (NAME).e[i].v[0] = (u_long)(A); \
189 (NAME).e[i].v[1] = (u_long)(B); \
190 (NAME).e[i].v[2] = (u_long)(C); \
191 (NAME).e[i].v[3] = (u_long)(D); \
192 UVMHIST_PRINTNOW(&((NAME).e[i])); \
193 }
194
195 #define UVMHIST_CALLED(NAME) \
196 { int s = splhigh(); simple_lock(&(NAME).l); \
197 _uvmhist_call = _uvmhist_cnt++; \
198 simple_unlock(&(NAME).l); splx(s); } \
199 UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0);
200
201 #define UVMHIST_FUNC(FNAME) \
202 static int _uvmhist_cnt = 0; \
203 static char *_uvmhist_name = FNAME; \
204 int _uvmhist_call;
205
206 static __inline void uvmhist_print __P((struct uvm_history_ent *));
207 /* shut up GCC */
208
209 static __inline void uvmhist_print(e)
210
211 struct uvm_history_ent *e;
212 {
213 printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
214 printf("%s#%ld: ", e->fn, e->call);
215 printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
216 printf("\n");
217 }
218
219 #endif /* UVMHIST */
220
221 #endif /* _UVM_UVM_STAT_H_ */
222