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