uvm_stat.h revision 1.43 1 1.43 chs /* $NetBSD: uvm_stat.h,v 1.43 2008/05/25 16:02:08 chs 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.43 chs #ifdef UVMHIST
46 1.43 chs #include <sys/cpu.h>
47 1.43 chs #include <sys/malloc.h>
48 1.43 chs #endif
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 * history/tracing
56 1.1 mrg */
57 1.1 mrg
58 1.1 mrg struct uvm_history_ent {
59 1.10 thorpej struct timeval tv; /* time stamp */
60 1.26 pk int cpunum;
61 1.34 yamt const char *fmt; /* printf format */
62 1.10 thorpej size_t fmtlen; /* length of printf format */
63 1.34 yamt const char *fn; /* function name */
64 1.10 thorpej size_t fnlen; /* length of function name */
65 1.10 thorpej u_long call; /* function call number */
66 1.10 thorpej u_long v[4]; /* values */
67 1.1 mrg };
68 1.1 mrg
69 1.1 mrg struct uvm_history {
70 1.30 simonb const char *name; /* name of this history */
71 1.10 thorpej size_t namelen; /* length of name, not including null */
72 1.10 thorpej LIST_ENTRY(uvm_history) list; /* link on list of all histories */
73 1.10 thorpej int n; /* number of entries */
74 1.10 thorpej int f; /* next free one */
75 1.42 ad int unused; /* old location of lock */
76 1.28 dbj struct uvm_history_ent *e; /* the malloc'd entries */
77 1.40 ad kmutex_t l; /* lock on this history */
78 1.1 mrg };
79 1.1 mrg
80 1.9 thorpej LIST_HEAD(uvm_history_head, uvm_history);
81 1.9 thorpej
82 1.12 mrg /*
83 1.12 mrg * grovelling lists all at once. we currently do not allow more than
84 1.12 mrg * 32 histories to exist, as the way to dump a number of them at once
85 1.12 mrg * is by calling uvm_hist() with a bitmask.
86 1.12 mrg */
87 1.12 mrg
88 1.12 mrg /* this is used to set the size of some arrays */
89 1.12 mrg #define MAXHISTS 32 /* do not change this! */
90 1.12 mrg
91 1.12 mrg /* and these are the bit values of each history */
92 1.12 mrg #define UVMHIST_MAPHIST 0x00000001 /* maphist */
93 1.12 mrg #define UVMHIST_PDHIST 0x00000002 /* pdhist */
94 1.19 mrg #define UVMHIST_UBCHIST 0x00000004 /* ubchist */
95 1.33 yamt #define UVMHIST_LOANHIST 0x00000008 /* loanhist */
96 1.12 mrg
97 1.15 thorpej #ifdef _KERNEL
98 1.15 thorpej
99 1.12 mrg /*
100 1.12 mrg * macros to use the history/tracing code. note that UVMHIST_LOG
101 1.12 mrg * must take 4 arguments (even if they are ignored by the format).
102 1.12 mrg */
103 1.1 mrg #ifndef UVMHIST
104 1.1 mrg #define UVMHIST_DECL(NAME)
105 1.1 mrg #define UVMHIST_INIT(NAME,N)
106 1.1 mrg #define UVMHIST_INIT_STATIC(NAME,BUF)
107 1.1 mrg #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
108 1.1 mrg #define UVMHIST_CALLED(NAME)
109 1.1 mrg #define UVMHIST_FUNC(FNAME)
110 1.1 mrg #define uvmhist_dump(NAME)
111 1.1 mrg #else
112 1.24 simonb #include <sys/kernel.h> /* for "cold" variable */
113 1.24 simonb
114 1.9 thorpej extern struct uvm_history_head uvm_histories;
115 1.9 thorpej
116 1.1 mrg #define UVMHIST_DECL(NAME) struct uvm_history NAME
117 1.1 mrg
118 1.10 thorpej #define UVMHIST_INIT(NAME,N) \
119 1.10 thorpej do { \
120 1.9 thorpej (NAME).name = __STRING(NAME); \
121 1.31 enami (NAME).namelen = strlen(__STRING(NAME)); \
122 1.1 mrg (NAME).n = (N); \
123 1.1 mrg (NAME).f = 0; \
124 1.40 ad mutex_init(&(NAME).l, MUTEX_SPIN, IPL_HIGH); \
125 1.1 mrg (NAME).e = (struct uvm_history_ent *) \
126 1.1 mrg malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
127 1.10 thorpej M_WAITOK); \
128 1.13 perry memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \
129 1.9 thorpej LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
130 1.25 perry } while (/*CONSTCOND*/ 0)
131 1.1 mrg
132 1.10 thorpej #define UVMHIST_INIT_STATIC(NAME,BUF) \
133 1.10 thorpej do { \
134 1.9 thorpej (NAME).name = __STRING(NAME); \
135 1.31 enami (NAME).namelen = strlen(__STRING(NAME)); \
136 1.1 mrg (NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
137 1.1 mrg (NAME).f = 0; \
138 1.41 reinoud mutex_init(&(NAME).l, MUTEX_SPIN, IPL_HIGH); \
139 1.1 mrg (NAME).e = (struct uvm_history_ent *) (BUF); \
140 1.13 perry memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (NAME).n); \
141 1.9 thorpej LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
142 1.25 perry } while (/*CONSTCOND*/ 0)
143 1.1 mrg
144 1.1 mrg #if defined(UVMHIST_PRINT)
145 1.8 thorpej extern int uvmhist_print_enabled;
146 1.8 thorpej #define UVMHIST_PRINTNOW(E) \
147 1.10 thorpej do { \
148 1.8 thorpej if (uvmhist_print_enabled) { \
149 1.8 thorpej uvmhist_print(E); \
150 1.8 thorpej DELAY(100000); \
151 1.8 thorpej } \
152 1.25 perry } while (/*CONSTCOND*/ 0)
153 1.1 mrg #else
154 1.1 mrg #define UVMHIST_PRINTNOW(E) /* nothing */
155 1.1 mrg #endif
156 1.1 mrg
157 1.10 thorpej #define UVMHIST_LOG(NAME,FMT,A,B,C,D) \
158 1.10 thorpej do { \
159 1.40 ad int _i_; \
160 1.40 ad mutex_enter(&(NAME).l); \
161 1.17 chs _i_ = (NAME).f; \
162 1.35 yamt (NAME).f = (_i_ + 1 < (NAME).n) ? _i_ + 1 : 0; \
163 1.40 ad mutex_exit(&(NAME).l); \
164 1.10 thorpej if (!cold) \
165 1.17 chs microtime(&(NAME).e[_i_].tv); \
166 1.27 tsutsui (NAME).e[_i_].cpunum = cpu_number(); \
167 1.17 chs (NAME).e[_i_].fmt = (FMT); \
168 1.31 enami (NAME).e[_i_].fmtlen = strlen(FMT); \
169 1.17 chs (NAME).e[_i_].fn = _uvmhist_name; \
170 1.31 enami (NAME).e[_i_].fnlen = strlen(_uvmhist_name); \
171 1.17 chs (NAME).e[_i_].call = _uvmhist_call; \
172 1.17 chs (NAME).e[_i_].v[0] = (u_long)(A); \
173 1.17 chs (NAME).e[_i_].v[1] = (u_long)(B); \
174 1.17 chs (NAME).e[_i_].v[2] = (u_long)(C); \
175 1.17 chs (NAME).e[_i_].v[3] = (u_long)(D); \
176 1.17 chs UVMHIST_PRINTNOW(&((NAME).e[_i_])); \
177 1.25 perry } while (/*CONSTCOND*/ 0)
178 1.1 mrg
179 1.1 mrg #define UVMHIST_CALLED(NAME) \
180 1.10 thorpej do { \
181 1.10 thorpej { \
182 1.40 ad mutex_enter(&(NAME).l); \
183 1.10 thorpej _uvmhist_call = _uvmhist_cnt++; \
184 1.40 ad mutex_exit(&(NAME).l); \
185 1.10 thorpej } \
186 1.10 thorpej UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \
187 1.25 perry } while (/*CONSTCOND*/ 0)
188 1.1 mrg
189 1.1 mrg #define UVMHIST_FUNC(FNAME) \
190 1.1 mrg static int _uvmhist_cnt = 0; \
191 1.34 yamt static const char *const _uvmhist_name = FNAME; \
192 1.20 chs int _uvmhist_call;
193 1.1 mrg
194 1.39 perry static __inline void uvmhist_print(struct uvm_history_ent *);
195 1.1 mrg
196 1.39 perry static __inline void
197 1.10 thorpej uvmhist_print(e)
198 1.10 thorpej struct uvm_history_ent *e;
199 1.1 mrg {
200 1.10 thorpej printf("%06ld.%06ld ", e->tv.tv_sec, e->tv.tv_usec);
201 1.26 pk printf("%s#%ld@%d: ", e->fn, e->call, e->cpunum);
202 1.10 thorpej printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
203 1.10 thorpej printf("\n");
204 1.1 mrg }
205 1.1 mrg #endif /* UVMHIST */
206 1.15 thorpej
207 1.15 thorpej #endif /* _KERNEL */
208 1.6 perry
209 1.6 perry #endif /* _UVM_UVM_STAT_H_ */
210