1 /* $NetBSD: uvm_stat.h,v 1.44 2008/08/08 17:09:28 skrll Exp $ */
5 * Copyright (c) 1997 Charles D. Cranor and Washington University.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Charles D. Cranor and
19 * Washington University.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * from: Id: uvm_stat.h,v 1.1.2.4 1998/02/07 01:16:56 chs Exp
37 #ifndef _UVM_UVM_STAT_H_
38 #define _UVM_UVM_STAT_H_
40 #if defined(_KERNEL_OPT)
41 #include "opt_uvmhist.h"
44 #include <sys/queue.h>
47 #include <sys/malloc.h>
51 * uvm_stat: monitor what is going on with uvm (or whatever)
58 struct uvm_history_ent
{
59 struct timeval tv
; /* time stamp */
61 const char *fmt
; /* printf format */
62 size_t fmtlen
; /* length of printf format */
63 const char *fn
; /* function name */
64 size_t fnlen
; /* length of function name */
65 u_long call
; /* function call number */
66 u_long v
[4]; /* values */
70 const char *name
; /* name of this history */
71 size_t namelen
; /* length of name, not including null */
72 LIST_ENTRY(uvm_history
) list
; /* link on list of all histories */
73 int n
; /* number of entries */
74 int f
; /* next free one */
75 int unused
; /* old location of lock */
76 struct uvm_history_ent
*e
; /* the malloc'd entries */
77 kmutex_t l
; /* lock on this history */
80 LIST_HEAD(uvm_history_head
, uvm_history
);
83 * grovelling lists all at once. we currently do not allow more than
84 * 32 histories to exist, as the way to dump a number of them at once
85 * is by calling uvm_hist() with a bitmask.
88 /* this is used to set the size of some arrays */
89 #define MAXHISTS 32 /* do not change this! */
91 /* and these are the bit values of each history */
92 #define UVMHIST_MAPHIST 0x00000001 /* maphist */
93 #define UVMHIST_PDHIST 0x00000002 /* pdhist */
94 #define UVMHIST_UBCHIST 0x00000004 /* ubchist */
95 #define UVMHIST_LOANHIST 0x00000008 /* loanhist */
100 * macros to use the history/tracing code. note that UVMHIST_LOG
101 * must take 4 arguments (even if they are ignored by the format).
104 #define UVMHIST_DECL(NAME)
105 #define UVMHIST_INIT(NAME,N)
106 #define UVMHIST_INIT_STATIC(NAME,BUF)
107 #define UVMHIST_LOG(NAME,FMT,A,B,C,D)
108 #define UVMHIST_CALLED(NAME)
109 #define UVMHIST_FUNC(FNAME)
110 #define uvmhist_dump(NAME)
112 #include <sys/kernel.h> /* for "cold" variable */
114 extern struct uvm_history_head uvm_histories
;
116 #define UVMHIST_DECL(NAME) struct uvm_history NAME
118 #define UVMHIST_INIT(NAME,N) \
120 (NAME).name = __STRING(NAME); \
121 (NAME).namelen = strlen(__STRING(NAME)); \
124 mutex_init(&(NAME).l, MUTEX_SPIN, IPL_HIGH); \
125 (NAME).e = (struct uvm_history_ent *) \
126 malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
128 memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \
129 LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
130 } while (/*CONSTCOND*/ 0)
132 #define UVMHIST_INIT_STATIC(NAME,BUF) \
134 (NAME).name = __STRING(NAME); \
135 (NAME).namelen = strlen(__STRING(NAME)); \
136 (NAME).n = sizeof(BUF) / sizeof(struct uvm_history_ent); \
138 mutex_init(&(NAME).l, MUTEX_SPIN, IPL_HIGH); \
139 (NAME).e = (struct uvm_history_ent *) (BUF); \
140 memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (NAME).n); \
141 LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
142 } while (/*CONSTCOND*/ 0)
144 #if defined(UVMHIST_PRINT)
145 extern int uvmhist_print_enabled
;
146 #define UVMHIST_PRINTNOW(E) \
148 if (uvmhist_print_enabled) { \
149 uvmhist_entry_print(E); \
152 } while (/*CONSTCOND*/ 0)
154 #define UVMHIST_PRINTNOW(E) /* nothing */
157 #define UVMHIST_LOG(NAME,FMT,A,B,C,D) \
160 mutex_enter(&(NAME).l); \
162 (NAME).f = (_i_ + 1 < (NAME).n) ? _i_ + 1 : 0; \
163 mutex_exit(&(NAME).l); \
165 microtime(&(NAME).e[_i_].tv); \
166 (NAME).e[_i_].cpunum = cpu_number(); \
167 (NAME).e[_i_].fmt = (FMT); \
168 (NAME).e[_i_].fmtlen = strlen(FMT); \
169 (NAME).e[_i_].fn = _uvmhist_name; \
170 (NAME).e[_i_].fnlen = strlen(_uvmhist_name); \
171 (NAME).e[_i_].call = _uvmhist_call; \
172 (NAME).e[_i_].v[0] = (u_long)(A); \
173 (NAME).e[_i_].v[1] = (u_long)(B); \
174 (NAME).e[_i_].v[2] = (u_long)(C); \
175 (NAME).e[_i_].v[3] = (u_long)(D); \
176 UVMHIST_PRINTNOW(&((NAME).e[_i_])); \
177 } while (/*CONSTCOND*/ 0)
179 #define UVMHIST_CALLED(NAME) \
182 mutex_enter(&(NAME).l); \
183 _uvmhist_call = _uvmhist_cnt++; \
184 mutex_exit(&(NAME).l); \
186 UVMHIST_LOG(NAME,"called!", 0, 0, 0, 0); \
187 } while (/*CONSTCOND*/ 0)
189 #define UVMHIST_FUNC(FNAME) \
190 static int _uvmhist_cnt = 0; \
191 static const char *const _uvmhist_name = FNAME; \
194 static __inline
void uvmhist_entry_print(struct uvm_history_ent
*);
197 uvmhist_entry_print(e
)
198 struct uvm_history_ent
*e
;
200 printf("%06" PRIu64
".%06d ", e
->tv
.tv_sec
, e
->tv
.tv_usec
);
201 printf("%s#%ld@%d: ", e
->fn
, e
->call
, e
->cpunum
);
202 printf(e
->fmt
, e
->v
[0], e
->v
[1], e
->v
[2], e
->v
[3]);
209 #endif /* _UVM_UVM_STAT_H_ */