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