uvm_stat.h revision 1.8 1 /* $NetBSD: uvm_stat.h,v 1.8 1998/02/12 20:10:18 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 #include "opt_uvmhist.h"
45
46 /*
47 * uvm_stat: monitor what is going on with uvm (or whatever)
48 */
49
50 /*
51 * counters [XXX: maybe replace event counters with this]
52 */
53
54 #define UVMCNT_MASK 0xf /* rest are private */
55 #define UVMCNT_CNT 0 /* normal counter */
56 #define UVMCNT_DEV 1 /* device event counter */
57
58 struct uvm_cnt {
59 int c; /* the value */
60 int t; /* type */
61 struct uvm_cnt *next; /* global list of cnts */
62 char *name; /* counter name */
63 void *p; /* private data */
64 };
65
66 extern struct uvm_cnt *uvm_cnt_head;
67
68 /*
69 * counter operations. assume spl is set ok.
70 */
71
72 #define UVMCNT_INIT(CNT,TYP,VAL,NAM,PRIV) { \
73 CNT.c = VAL; \
74 CNT.t = TYP; \
75 CNT.next = uvm_cnt_head; \
76 uvm_cnt_head = &CNT; \
77 CNT.name = NAM; \
78 CNT.p = PRIV; \
79 }
80
81 #define UVMCNT_SET(C,V) { \
82 (C).c = (V); \
83 }
84
85 #define UVMCNT_ADD(C,V) { \
86 (C).c += (V); \
87 }
88
89 #define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
90 #define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
91
92
93 /*
94 * history/tracing
95 */
96
97 struct uvm_history_ent {
98 struct timeval tv; /* time stamp */
99 char *fmt; /* printf format */
100 char *fn; /* function name */
101 u_long call; /* function call number */
102 u_long v[4]; /* values */
103 };
104
105 struct uvm_history {
106 int n; /* number of entries */
107 int f; /* next free one */
108 #if NCPU > 1
109 simple_lock_data_t l; /* lock on this history */
110 #endif /* NCPU */
111 struct uvm_history_ent *e; /* the malloc'd entries */
112 };
113
114 #ifndef UVMHIST
115 #define UVMHIST_DECL(NAME)
116 #define UVMHIST_INIT(NAME,N)
117 #define UVMHIST_INIT_STATIC(NAME,BUF)
118 #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
119 #define UVMHIST_CALLED(NAME)
120 #define UVMHIST_FUNC(FNAME)
121 #define uvmhist_dump(NAME)
122 #else
123 #define UVMHIST_DECL(NAME) struct uvm_history NAME
124
125 #define UVMHIST_INIT(NAME,N) { \
126 (NAME).n = (N); \
127 (NAME).f = 0; \
128 simple_lock_init(&(NAME).l); \
129 (NAME).e = (struct uvm_history_ent *) \
130 malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
131 M_WAITOK); \
132 bzero((NAME).e, sizeof(struct uvm_history_ent) * (N)); \
133 }
134
135 #define UVMHIST_INIT_STATIC(NAME,BUF) { \
136 (NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
137 (NAME).f = 0; \
138 simple_lock_init(&(NAME).l); \
139 (NAME).e = (struct uvm_history_ent *) (BUF); \
140 bzero((NAME).e, sizeof(struct uvm_history_ent) * (NAME).n); \
141 }
142
143 extern int cold;
144
145 #if defined(UVMHIST_PRINT)
146 extern int uvmhist_print_enabled;
147 #define UVMHIST_PRINTNOW(E) \
148 do { \
149 if (uvmhist_print_enabled) { \
150 uvmhist_print(E); \
151 DELAY(100000); \
152 } \
153 } while (0)
154 #else
155 #define UVMHIST_PRINTNOW(E) /* nothing */
156 #endif
157
158 #define UVMHIST_LOG(NAME,FMT,A,B,C,D) { \
159 register int i, s = splhigh(); \
160 simple_lock(&(NAME).l); \
161 i = (NAME).f; \
162 (NAME).f = (i + 1) % (NAME).n; \
163 simple_unlock(&(NAME).l); \
164 splx(s); \
165 if (!cold) microtime(&(NAME).e[i].tv); \
166 (NAME).e[i].fmt = (FMT); \
167 (NAME).e[i].fn = _uvmhist_name; \
168 (NAME).e[i].call = _uvmhist_call; \
169 (NAME).e[i].v[0] = (u_long)(A); \
170 (NAME).e[i].v[1] = (u_long)(B); \
171 (NAME).e[i].v[2] = (u_long)(C); \
172 (NAME).e[i].v[3] = (u_long)(D); \
173 UVMHIST_PRINTNOW(&((NAME).e[i])); \
174 }
175
176 #define UVMHIST_CALLED(NAME) \
177 { int s = splhigh(); simple_lock(&(NAME).l); \
178 _uvmhist_call = _uvmhist_cnt++; \
179 simple_unlock(&(NAME).l); splx(s); } \
180 UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0);
181
182 #define UVMHIST_FUNC(FNAME) \
183 static int _uvmhist_cnt = 0; \
184 static char *_uvmhist_name = FNAME; \
185 int _uvmhist_call;
186
187 static __inline void uvmhist_print __P((struct uvm_history_ent *));
188 /* shut up GCC */
189
190 static __inline void uvmhist_print(e)
191
192 struct uvm_history_ent *e;
193 {
194 printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
195 printf("%s#%ld: ", e->fn, e->call);
196 printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
197 printf("\n");
198 }
199
200 #endif /* UVMHIST */
201
202 #endif /* _UVM_UVM_STAT_H_ */
203