xref: /netbsd-src/sys/uvm/uvm_stat.c (revision 27578b9aac214cc7796ead81dcc5427e79d5f2a0)
1 /*	$NetBSD: uvm_stat.c,v 1.20 2001/09/15 20:36:47 chs Exp $	 */
2 
3 /*
4  *
5  * Copyright (c) 1997 Charles D. Cranor and Washington University.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
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.
22  *
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.
33  *
34  * from: Id: uvm_stat.c,v 1.1.2.3 1997/12/19 15:01:00 mrg Exp
35  */
36 
37 #include "opt_uvmhist.h"
38 #include "opt_ddb.h"
39 
40 /*
41  * uvm_stat.c
42  */
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 
47 #include <uvm/uvm.h>
48 #include <uvm/uvm_ddb.h>
49 
50 /*
51  * globals
52  */
53 
54 struct uvm_cnt *uvm_cnt_head = NULL;
55 
56 #ifdef UVMHIST
57 struct uvm_history_head uvm_histories;
58 #endif
59 
60 #ifdef UVMHIST_PRINT
61 int uvmhist_print_enabled = 1;
62 #endif
63 
64 #ifdef DDB
65 
66 /*
67  * prototypes
68  */
69 
70 #ifdef UVMHIST
71 void uvmhist_dump __P((struct uvm_history *));
72 void uvm_hist __P((u_int32_t));
73 static void uvmhist_dump_histories __P((struct uvm_history *[]));
74 #endif
75 void uvmcnt_dump __P((void));
76 
77 
78 #ifdef UVMHIST
79 /* call this from ddb */
80 void
81 uvmhist_dump(l)
82 	struct uvm_history *l;
83 {
84 	int lcv, s;
85 
86 	s = splhigh();
87 	lcv = l->f;
88 	do {
89 		if (l->e[lcv].fmt)
90 			uvmhist_print(&l->e[lcv]);
91 		lcv = (lcv + 1) % l->n;
92 	} while (lcv != l->f);
93 	splx(s);
94 }
95 
96 /*
97  * print a merged list of uvm_history structures
98  */
99 static void
100 uvmhist_dump_histories(hists)
101 	struct uvm_history *hists[];
102 {
103 	struct timeval  tv;
104 	int	cur[MAXHISTS];
105 	int	s, lcv, hi;
106 
107 	/* so we don't get corrupted lists! */
108 	s = splhigh();
109 
110 	/* find the first of each list */
111 	for (lcv = 0; hists[lcv]; lcv++)
112 		 cur[lcv] = hists[lcv]->f;
113 
114 	/*
115 	 * here we loop "forever", finding the next earliest
116 	 * history entry and printing it.  cur[X] is the current
117 	 * entry to test for the history in hists[X].  if it is
118 	 * -1, then this history is finished.
119 	 */
120 	for (;;) {
121 		hi = -1;
122 		tv.tv_sec = tv.tv_usec = 0;
123 
124 		/* loop over each history */
125 		for (lcv = 0; hists[lcv]; lcv++) {
126 restart:
127 			if (cur[lcv] == -1)
128 				continue;
129 
130 			/*
131 			 * if the format is empty, go to the next entry
132 			 * and retry.
133 			 */
134 			if (hists[lcv]->e[cur[lcv]].fmt == NULL) {
135 				cur[lcv] = (cur[lcv] + 1) % (hists[lcv]->n);
136 				if (cur[lcv] == hists[lcv]->f)
137 					cur[lcv] = -1;
138 				goto restart;
139 			}
140 
141 			/*
142 			 * if the time hasn't been set yet, or this entry is
143 			 * earlier than the current tv, set the time and history
144 			 * index.
145 			 */
146 			if (tv.tv_sec == 0 ||
147 			    timercmp(&hists[lcv]->e[cur[lcv]].tv, &tv, <)) {
148 				tv = hists[lcv]->e[cur[lcv]].tv;
149 				hi = lcv;
150 			}
151 		}
152 
153 		/* if we didn't find any entries, we must be done */
154 		if (hi == -1)
155 			break;
156 
157 		/* print and move to the next entry */
158 		uvmhist_print(&hists[hi]->e[cur[hi]]);
159 		cur[hi] = (cur[hi] + 1) % (hists[hi]->n);
160 		if (cur[hi] == hists[hi]->f)
161 			cur[hi] = -1;
162 	}
163 	splx(s);
164 }
165 
166 /*
167  * call this from ddb.  `bitmask' is from <uvm/uvm_stat.h>.  it
168  * merges the named histories.
169  */
170 void
171 uvm_hist(bitmask)
172 	u_int32_t	bitmask;	/* XXX only support 32 hists */
173 {
174 	struct uvm_history *hists[MAXHISTS + 1];
175 	int i = 0;
176 
177 	if ((bitmask & UVMHIST_MAPHIST) || bitmask == 0)
178 		hists[i++] = &maphist;
179 
180 	if ((bitmask & UVMHIST_PDHIST) || bitmask == 0)
181 		hists[i++] = &pdhist;
182 
183 	if ((bitmask & UVMHIST_UBCHIST) || bitmask == 0)
184 		hists[i++] = &ubchist;
185 
186 	hists[i] = NULL;
187 
188 	uvmhist_dump_histories(hists);
189 }
190 #endif /* UVMHIST */
191 
192 void
193 uvmcnt_dump()
194 {
195 	struct uvm_cnt *uvc = uvm_cnt_head;
196 
197 	while (uvc) {
198 		if ((uvc->t & UVMCNT_MASK) != UVMCNT_CNT)
199 			continue;
200 		printf("%s = %d\n", uvc->name, uvc->c);
201 		uvc = uvc->next;
202 	}
203 }
204 
205 /*
206  * uvmexp_print: ddb hook to print interesting uvm counters
207  */
208 void
209 uvmexp_print(void (*pr)(const char *, ...))
210 {
211 
212 	(*pr)("Current UVM status:\n");
213 	(*pr)("  pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d\n",
214 	    uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask,
215 	    uvmexp.pageshift);
216 	(*pr)("  %d VM pages: %d active, %d inactive, %d wired, %d free\n",
217 	    uvmexp.npages, uvmexp.active, uvmexp.inactive, uvmexp.wired,
218 	    uvmexp.free);
219 	(*pr)("  min  %d%% (%d) anon, %d%% (%d) vnode, %d%% (%d) vtext\n",
220 	    uvmexp.anonminpct, uvmexp.anonmin, uvmexp.vnodeminpct,
221 	    uvmexp.vnodemin, uvmexp.vtextminpct, uvmexp.vtextmin);
222 	(*pr)("  pages  %d anon, %d vnode, %d vtext\n",
223 	    uvmexp.anonpages, uvmexp.vnodepages, uvmexp.vtextpages);
224 	(*pr)("  freemin=%d, free-target=%d, inactive-target=%d, "
225 	    "wired-max=%d\n", uvmexp.freemin, uvmexp.freetarg, uvmexp.inactarg,
226 	    uvmexp.wiredmax);
227 	(*pr)("  faults=%d, traps=%d, intrs=%d, ctxswitch=%d\n",
228 	    uvmexp.faults, uvmexp.traps, uvmexp.intrs, uvmexp.swtch);
229 	(*pr)("  softint=%d, syscalls=%d, swapins=%d, swapouts=%d\n",
230 	    uvmexp.softs, uvmexp.syscalls, uvmexp.swapins, uvmexp.swapouts);
231 
232 	(*pr)("  fault counts:\n");
233 	(*pr)("    noram=%d, noanon=%d, pgwait=%d, pgrele=%d\n",
234 	    uvmexp.fltnoram, uvmexp.fltnoanon, uvmexp.fltpgwait,
235 	    uvmexp.fltpgrele);
236 	(*pr)("    ok relocks(total)=%d(%d), anget(retrys)=%d(%d), "
237 	    "amapcopy=%d\n", uvmexp.fltrelckok, uvmexp.fltrelck,
238 	    uvmexp.fltanget, uvmexp.fltanretry, uvmexp.fltamcopy);
239 	(*pr)("    neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n",
240 	    uvmexp.fltnamap, uvmexp.fltnomap, uvmexp.fltlget, uvmexp.fltget);
241 	(*pr)("    cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n",
242 	    uvmexp.flt_anon, uvmexp.flt_acow, uvmexp.flt_obj, uvmexp.flt_prcopy,
243 	    uvmexp.flt_przero);
244 
245 	(*pr)("  daemon and swap counts:\n");
246 	(*pr)("    woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
247 	    uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan,
248 	    uvmexp.pdanscan);
249 	(*pr)("    busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
250 	    uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact);
251 	(*pr)("    pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts,
252 	    uvmexp.pdpending, uvmexp.nswget);
253 	(*pr)("    nswapdev=%d, nanon=%d, nanonneeded=%d nfreeanon=%d\n",
254 	    uvmexp.nswapdev, uvmexp.nanon, uvmexp.nanonneeded,
255 	    uvmexp.nfreeanon);
256 	(*pr)("    swpages=%d, swpginuse=%d, swpgonly=%d paging=%d\n",
257 	    uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging);
258 }
259 #endif
260