Add unzip.
[netbsd-mini2440.git] / sys / uvm / uvm_stat.c
blobcc685fceb5a94de86a75d904a4e903046906c682
1 /* $NetBSD: uvm_stat.c,v 1.30 2006/09/15 15:51:13 yamt Exp $ */
3 /*
5 * Copyright (c) 1997 Charles D. Cranor and Washington University.
6 * All rights reserved.
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.
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.c,v 1.1.2.3 1997/12/19 15:01:00 mrg Exp
38 * uvm_stat.c
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: uvm_stat.c,v 1.30 2006/09/15 15:51:13 yamt Exp $");
44 #include "opt_uvmhist.h"
45 #include "opt_readahead.h"
46 #include "opt_ddb.h"
48 #include <sys/param.h>
49 #include <sys/systm.h>
51 #include <uvm/uvm.h>
52 #include <uvm/uvm_ddb.h>
55 * globals
58 #ifdef UVMHIST
59 struct uvm_history_head uvm_histories;
60 #endif
62 #ifdef UVMHIST_PRINT
63 int uvmhist_print_enabled = 1;
64 #endif
66 #ifdef DDB
69 * prototypes
72 #ifdef UVMHIST
73 void uvmhist_dump(struct uvm_history *);
74 void uvm_hist(u_int32_t);
75 static void uvmhist_dump_histories(struct uvm_history *[]);
76 #endif
77 void uvmcnt_dump(void);
80 #ifdef UVMHIST
81 /* call this from ddb */
82 void
83 uvmhist_dump(struct uvm_history *l)
85 int lcv, s;
87 s = splhigh();
88 lcv = l->f;
89 do {
90 if (l->e[lcv].fmt)
91 uvmhist_entry_print(&l->e[lcv]);
92 lcv = (lcv + 1) % l->n;
93 } while (lcv != l->f);
94 splx(s);
98 * print a merged list of uvm_history structures
100 static void
101 uvmhist_dump_histories(struct uvm_history *hists[])
103 struct timeval tv;
104 int cur[MAXHISTS];
105 int s, lcv, hi;
107 /* so we don't get corrupted lists! */
108 s = splhigh();
110 /* find the first of each list */
111 for (lcv = 0; hists[lcv]; lcv++)
112 cur[lcv] = hists[lcv]->f;
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.
120 for (;;) {
121 hi = -1;
122 tv.tv_sec = tv.tv_usec = 0;
124 /* loop over each history */
125 for (lcv = 0; hists[lcv]; lcv++) {
126 restart:
127 if (cur[lcv] == -1)
128 continue;
131 * if the format is empty, go to the next entry
132 * and retry.
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;
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.
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;
153 /* if we didn't find any entries, we must be done */
154 if (hi == -1)
155 break;
157 /* print and move to the next entry */
158 uvmhist_entry_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;
163 splx(s);
167 * call this from ddb. `bitmask' is from <uvm/uvm_stat.h>. it
168 * merges the named histories.
170 void
171 uvm_hist(u_int32_t bitmask) /* XXX only support 32 hists */
173 struct uvm_history *hists[MAXHISTS + 1];
174 int i = 0;
176 if ((bitmask & UVMHIST_MAPHIST) || bitmask == 0)
177 hists[i++] = &maphist;
179 if ((bitmask & UVMHIST_PDHIST) || bitmask == 0)
180 hists[i++] = &pdhist;
182 if ((bitmask & UVMHIST_UBCHIST) || bitmask == 0)
183 hists[i++] = &ubchist;
185 if ((bitmask & UVMHIST_LOANHIST) || bitmask == 0)
186 hists[i++] = &loanhist;
188 hists[i] = NULL;
190 uvmhist_dump_histories(hists);
194 * uvmhist_print: ddb hook to print uvm history
196 void
197 uvmhist_print(void (*pr)(const char *, ...))
199 uvmhist_dump(LIST_FIRST(&uvm_histories));
202 #endif /* UVMHIST */
205 * uvmexp_print: ddb hook to print interesting uvm counters
207 void
208 uvmexp_print(void (*pr)(const char *, ...))
210 int active, inactive;
212 uvm_estimatepageable(&active, &inactive);
214 (*pr)("Current UVM status:\n");
215 (*pr)(" pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d\n",
216 uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask,
217 uvmexp.pageshift);
218 (*pr)(" %d VM pages: %d active, %d inactive, %d wired, %d free\n",
219 uvmexp.npages, active, inactive, uvmexp.wired,
220 uvmexp.free);
221 (*pr)(" pages %d anon, %d file, %d exec\n",
222 uvmexp.anonpages, uvmexp.filepages, uvmexp.execpages);
223 (*pr)(" freemin=%d, free-target=%d, wired-max=%d\n",
224 uvmexp.freemin, uvmexp.freetarg, uvmexp.wiredmax);
225 (*pr)(" faults=%d, traps=%d, intrs=%d, ctxswitch=%d\n",
226 uvmexp.faults, uvmexp.traps, uvmexp.intrs, uvmexp.swtch);
227 (*pr)(" softint=%d, syscalls=%d, swapins=%d, swapouts=%d\n",
228 uvmexp.softs, uvmexp.syscalls, uvmexp.swapins, uvmexp.swapouts);
230 (*pr)(" fault counts:\n");
231 (*pr)(" noram=%d, noanon=%d, pgwait=%d, pgrele=%d\n",
232 uvmexp.fltnoram, uvmexp.fltnoanon, uvmexp.fltpgwait,
233 uvmexp.fltpgrele);
234 (*pr)(" ok relocks(total)=%d(%d), anget(retrys)=%d(%d), "
235 "amapcopy=%d\n", uvmexp.fltrelckok, uvmexp.fltrelck,
236 uvmexp.fltanget, uvmexp.fltanretry, uvmexp.fltamcopy);
237 (*pr)(" neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n",
238 uvmexp.fltnamap, uvmexp.fltnomap, uvmexp.fltlget, uvmexp.fltget);
239 (*pr)(" cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n",
240 uvmexp.flt_anon, uvmexp.flt_acow, uvmexp.flt_obj, uvmexp.flt_prcopy,
241 uvmexp.flt_przero);
243 (*pr)(" daemon and swap counts:\n");
244 (*pr)(" woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
245 uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan,
246 uvmexp.pdanscan);
247 (*pr)(" busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
248 uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact);
249 (*pr)(" pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts,
250 uvmexp.pdpending, uvmexp.nswget);
251 (*pr)(" nswapdev=%d, swpgavail=%d\n",
252 uvmexp.nswapdev, uvmexp.swpgavail);
253 (*pr)(" swpages=%d, swpginuse=%d, swpgonly=%d, paging=%d\n",
254 uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging);
256 #endif
258 #if defined(READAHEAD_STATS)
260 #define UVM_RA_EVCNT_DEFINE(name) \
261 struct evcnt uvm_ra_##name = \
262 EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "readahead", #name); \
263 EVCNT_ATTACH_STATIC(uvm_ra_##name);
265 UVM_RA_EVCNT_DEFINE(total);
266 UVM_RA_EVCNT_DEFINE(hit);
267 UVM_RA_EVCNT_DEFINE(miss);
269 #endif /* defined(READAHEAD_STATS) */