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