2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)vm_meter.c 8.4 (Berkeley) 1/4/94
34 * $FreeBSD: src/sys/vm/vm_meter.c,v 1.34.2.7 2002/10/10 19:28:22 dillon Exp $
35 * $DragonFly: src/sys/vm/vm_meter.c,v 1.15 2008/04/28 18:04:08 dillon Exp $
38 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/resource.h>
43 #include <sys/vmmeter.h>
46 #include <vm/vm_page.h>
47 #include <vm/vm_extern.h>
48 #include <vm/vm_param.h>
51 #include <vm/vm_map.h>
52 #include <vm/vm_object.h>
53 #include <sys/sysctl.h>
55 struct vmstats vmstats
;
57 static int maxslp
= MAXSLP
;
59 SYSCTL_UINT(_vm
, VM_V_FREE_MIN
, v_free_min
,
60 CTLFLAG_RW
, &vmstats
.v_free_min
, 0, "");
61 SYSCTL_UINT(_vm
, VM_V_FREE_TARGET
, v_free_target
,
62 CTLFLAG_RW
, &vmstats
.v_free_target
, 0, "");
63 SYSCTL_UINT(_vm
, VM_V_FREE_RESERVED
, v_free_reserved
,
64 CTLFLAG_RW
, &vmstats
.v_free_reserved
, 0, "");
65 SYSCTL_UINT(_vm
, VM_V_INACTIVE_TARGET
, v_inactive_target
,
66 CTLFLAG_RW
, &vmstats
.v_inactive_target
, 0, "");
67 SYSCTL_UINT(_vm
, VM_V_CACHE_MIN
, v_cache_min
,
68 CTLFLAG_RW
, &vmstats
.v_cache_min
, 0, "");
69 SYSCTL_UINT(_vm
, VM_V_CACHE_MAX
, v_cache_max
,
70 CTLFLAG_RW
, &vmstats
.v_cache_max
, 0, "");
71 SYSCTL_UINT(_vm
, VM_V_PAGEOUT_FREE_MIN
, v_pageout_free_min
,
72 CTLFLAG_RW
, &vmstats
.v_pageout_free_min
, 0, "");
73 SYSCTL_UINT(_vm
, OID_AUTO
, v_free_severe
,
74 CTLFLAG_RW
, &vmstats
.v_free_severe
, 0, "");
76 SYSCTL_STRUCT(_vm
, VM_LOADAVG
, loadavg
, CTLFLAG_RD
,
77 &averunnable
, loadavg
, "Machine loadaverage history");
79 static int do_vmtotal_callback(struct proc
*p
, void *data
);
82 do_vmtotal(SYSCTL_HANDLER_ARGS
)
85 struct vmtotal
*totalp
;
89 bzero(totalp
, sizeof *totalp
);
92 * Mark all objects as inactive.
94 for (object
= TAILQ_FIRST(&vm_object_list
);
96 object
= TAILQ_NEXT(object
,object_list
)) {
97 vm_object_clear_flag(object
, OBJ_ACTIVE
);
101 * Calculate process statistics.
103 allproc_scan(do_vmtotal_callback
, totalp
);
106 * Calculate object memory usage statistics.
108 for (object
= TAILQ_FIRST(&vm_object_list
);
110 object
= TAILQ_NEXT(object
, object_list
)) {
112 * devices, like /dev/mem, will badly skew our totals
114 if (object
->type
== OBJT_DEVICE
)
116 totalp
->t_vm
+= object
->size
;
117 totalp
->t_rm
+= object
->resident_page_count
;
118 if (object
->flags
& OBJ_ACTIVE
) {
119 totalp
->t_avm
+= object
->size
;
120 totalp
->t_arm
+= object
->resident_page_count
;
122 if (object
->shadow_count
> 1) {
124 totalp
->t_vmshr
+= object
->size
;
125 totalp
->t_rmshr
+= object
->resident_page_count
;
126 if (object
->flags
& OBJ_ACTIVE
) {
127 totalp
->t_avmshr
+= object
->size
;
128 totalp
->t_armshr
+= object
->resident_page_count
;
132 totalp
->t_free
= vmstats
.v_free_count
+ vmstats
.v_cache_count
;
133 return (sysctl_handle_opaque(oidp
, totalp
, sizeof total
, req
));
137 do_vmtotal_callback(struct proc
*p
, void *data
)
139 struct vmtotal
*totalp
= data
;
141 vm_map_entry_t entry
;
145 if (p
->p_flag
& P_SYSTEM
)
148 FOREACH_LWP_IN_PROC(lp
, p
) {
149 switch (lp
->lwp_stat
) {
152 if ((p
->p_flag
& P_SWAPPEDOUT
) == 0) {
153 if ((lp
->lwp_flag
& LWP_SINTR
) == 0)
155 else if (lp
->lwp_slptime
< maxslp
)
157 } else if (lp
->lwp_slptime
< maxslp
) {
160 if (lp
->lwp_slptime
>= maxslp
)
165 if (p
->p_flag
& P_SWAPPEDOUT
)
169 if (p
->p_stat
== SIDL
)
178 * Note active objects.
182 for (map
= &p
->p_vmspace
->vm_map
, entry
= map
->header
.next
;
183 entry
!= &map
->header
; entry
= entry
->next
) {
184 if (entry
->maptype
!= VM_MAPTYPE_NORMAL
&&
185 entry
->maptype
!= VM_MAPTYPE_VPAGETABLE
) {
188 if (entry
->object
.vm_object
== NULL
)
190 vm_object_set_flag(entry
->object
.vm_object
, OBJ_ACTIVE
);
191 paging
|= entry
->object
.vm_object
->paging_in_progress
;
201 do_vmstats(SYSCTL_HANDLER_ARGS
)
203 struct vmstats vms
= vmstats
;
204 return (sysctl_handle_opaque(oidp
, &vms
, sizeof(vms
), req
));
208 do_vmmeter(SYSCTL_HANDLER_ARGS
)
210 int boffset
= offsetof(struct vmmeter
, vmmeter_uint_begin
);
211 int eoffset
= offsetof(struct vmmeter
, vmmeter_uint_end
);
215 bzero(&vmm
, sizeof(vmm
));
216 for (i
= 0; i
< ncpus
; ++i
) {
218 struct globaldata
*gd
= globaldata_find(i
);
220 for (off
= boffset
; off
<= eoffset
; off
+= sizeof(u_int
)) {
221 *(u_int
*)((char *)&vmm
+ off
) +=
222 *(u_int
*)((char *)&gd
->gd_cnt
+ off
);
226 vmm
.v_intr
+= vmm
.v_ipi
+ vmm
.v_timer
;
227 return (sysctl_handle_opaque(oidp
, &vmm
, sizeof(vmm
), req
));
231 * vcnt() - accumulate statistics from the cnt structure for each cpu
233 * The vmmeter structure is now per-cpu as well as global. Those
234 * statistics which can be kept on a per-cpu basis (to avoid cache
235 * stalls between cpus) can be moved to the per-cpu vmmeter. Remaining
236 * statistics, such as v_free_reserved, are left in the global
239 * (sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req)
242 vcnt(SYSCTL_HANDLER_ARGS
)
248 for (i
= 0; i
< ncpus
; ++i
) {
249 struct globaldata
*gd
= globaldata_find(i
);
250 count
+= *(int *)((char *)&gd
->gd_cnt
+ offset
);
252 return(SYSCTL_OUT(req
, &count
, sizeof(int)));
256 vcnt_intr(SYSCTL_HANDLER_ARGS
)
261 for (i
= 0; i
< ncpus
; ++i
) {
262 struct globaldata
*gd
= globaldata_find(i
);
264 count
+= gd
->gd_cnt
.v_intr
+ gd
->gd_cnt
.v_ipi
+
267 return(SYSCTL_OUT(req
, &count
, sizeof(int)));
270 #define VMMETEROFF(var) offsetof(struct vmmeter, var)
272 SYSCTL_PROC(_vm
, OID_AUTO
, vmtotal
, CTLTYPE_OPAQUE
|CTLFLAG_RD
,
273 0, sizeof(struct vmtotal
), do_vmtotal
, "S,vmtotal",
274 "System virtual memory aggregate");
275 SYSCTL_PROC(_vm
, OID_AUTO
, vmstats
, CTLTYPE_OPAQUE
|CTLFLAG_RD
,
276 0, sizeof(struct vmstats
), do_vmstats
, "S,vmstats",
277 "System virtual memory statistics");
278 SYSCTL_PROC(_vm
, OID_AUTO
, vmmeter
, CTLTYPE_OPAQUE
|CTLFLAG_RD
,
279 0, sizeof(struct vmmeter
), do_vmmeter
, "S,vmmeter",
280 "System statistics");
281 SYSCTL_NODE(_vm
, OID_AUTO
, stats
, CTLFLAG_RW
, 0, "VM meter stats");
282 SYSCTL_NODE(_vm_stats
, OID_AUTO
, sys
, CTLFLAG_RW
, 0, "VM meter sys stats");
283 SYSCTL_NODE(_vm_stats
, OID_AUTO
, vm
, CTLFLAG_RW
, 0, "VM meter vm stats");
284 SYSCTL_NODE(_vm_stats
, OID_AUTO
, misc
, CTLFLAG_RW
, 0, "VM meter misc stats");
286 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_swtch
, CTLTYPE_UINT
|CTLFLAG_RD
,
287 0, VMMETEROFF(v_swtch
), vcnt
, "IU", "Context switches");
288 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_intrans_coll
, CTLTYPE_UINT
|CTLFLAG_RD
,
289 0, VMMETEROFF(v_intrans_coll
), vcnt
, "IU", "");
290 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_intrans_wait
, CTLTYPE_UINT
|CTLFLAG_RD
,
291 0, VMMETEROFF(v_intrans_wait
), vcnt
, "IU", "");
292 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_forwarded_ints
, CTLTYPE_UINT
|CTLFLAG_RD
,
293 0, VMMETEROFF(v_forwarded_ints
), vcnt
, "IU", "");
294 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_forwarded_hits
, CTLTYPE_UINT
|CTLFLAG_RD
,
295 0, VMMETEROFF(v_forwarded_hits
), vcnt
, "IU", "");
296 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_forwarded_misses
, CTLTYPE_UINT
|CTLFLAG_RD
,
297 0, VMMETEROFF(v_forwarded_misses
), vcnt
, "IU", "");
298 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_trap
, CTLTYPE_UINT
|CTLFLAG_RD
,
299 0, VMMETEROFF(v_trap
), vcnt
, "IU", "Traps");
300 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_syscall
, CTLTYPE_UINT
|CTLFLAG_RD
,
301 0, VMMETEROFF(v_syscall
), vcnt
, "IU", "Syscalls");
302 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_intr
, CTLTYPE_UINT
|CTLFLAG_RD
,
303 0, VMMETEROFF(v_intr
), vcnt_intr
, "IU", "Hardware interrupts");
304 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_ipi
, CTLTYPE_UINT
|CTLFLAG_RD
,
305 0, VMMETEROFF(v_ipi
), vcnt
, "IU", "Inter-processor interrupts");
306 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_timer
, CTLTYPE_UINT
|CTLFLAG_RD
,
307 0, VMMETEROFF(v_timer
), vcnt
, "IU", "LAPIC timer interrupts");
308 SYSCTL_PROC(_vm_stats_sys
, OID_AUTO
, v_soft
, CTLTYPE_UINT
|CTLFLAG_RD
,
309 0, VMMETEROFF(v_soft
), vcnt
, "IU", "Software interrupts");
310 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vm_faults
, CTLTYPE_UINT
|CTLFLAG_RD
,
311 0, VMMETEROFF(v_vm_faults
), vcnt
, "IU", "VM faults");
312 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_cow_faults
, CTLTYPE_UINT
|CTLFLAG_RD
,
313 0, VMMETEROFF(v_cow_faults
), vcnt
, "IU", "COW faults");
314 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_cow_optim
, CTLTYPE_UINT
|CTLFLAG_RD
,
315 0, VMMETEROFF(v_cow_optim
), vcnt
, "IU", "Optimized COW faults");
316 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_zfod
, CTLTYPE_UINT
|CTLFLAG_RD
,
317 0, VMMETEROFF(v_zfod
), vcnt
, "IU", "Zero fill");
318 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_ozfod
, CTLTYPE_UINT
|CTLFLAG_RD
,
319 0, VMMETEROFF(v_ozfod
), vcnt
, "IU", "Optimized zero fill");
320 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_swapin
, CTLTYPE_UINT
|CTLFLAG_RD
,
321 0, VMMETEROFF(v_swapin
), vcnt
, "IU", "Swapin operations");
322 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_swapout
, CTLTYPE_UINT
|CTLFLAG_RD
,
323 0, VMMETEROFF(v_swapout
), vcnt
, "IU", "Swapout operations");
324 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_swappgsin
, CTLTYPE_UINT
|CTLFLAG_RD
,
325 0, VMMETEROFF(v_swappgsin
), vcnt
, "IU", "Swapin pages");
326 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_swappgsout
, CTLTYPE_UINT
|CTLFLAG_RD
,
327 0, VMMETEROFF(v_swappgsout
), vcnt
, "IU", "Swapout pages");
328 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vnodein
, CTLTYPE_UINT
|CTLFLAG_RD
,
329 0, VMMETEROFF(v_vnodein
), vcnt
, "IU", "Vnodein operations");
330 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vnodeout
, CTLTYPE_UINT
|CTLFLAG_RD
,
331 0, VMMETEROFF(v_vnodeout
), vcnt
, "IU", "Vnodeout operations");
332 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vnodepgsin
, CTLTYPE_UINT
|CTLFLAG_RD
,
333 0, VMMETEROFF(v_vnodepgsin
), vcnt
, "IU", "Vnodein pages");
334 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vnodepgsout
, CTLTYPE_UINT
|CTLFLAG_RD
,
335 0, VMMETEROFF(v_vnodepgsout
), vcnt
, "IU", "Vnodeout pages");
336 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_intrans
, CTLTYPE_UINT
|CTLFLAG_RD
,
337 0, VMMETEROFF(v_intrans
), vcnt
, "IU", "In transit page blocking");
338 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_reactivated
, CTLTYPE_UINT
|CTLFLAG_RD
,
339 0, VMMETEROFF(v_reactivated
), vcnt
, "IU", "Reactivated pages");
340 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_pdwakeups
, CTLTYPE_UINT
|CTLFLAG_RD
,
341 0, VMMETEROFF(v_pdwakeups
), vcnt
, "IU", "Pagedaemon wakeups");
342 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_pdpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
343 0, VMMETEROFF(v_pdpages
), vcnt
, "IU", "Pagedaemon page scans");
344 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_dfree
, CTLTYPE_UINT
|CTLFLAG_RD
,
345 0, VMMETEROFF(v_dfree
), vcnt
, "IU", "");
346 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_pfree
, CTLTYPE_UINT
|CTLFLAG_RD
,
347 0, VMMETEROFF(v_pfree
), vcnt
, "IU", "");
348 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_tfree
, CTLTYPE_UINT
|CTLFLAG_RD
,
349 0, VMMETEROFF(v_tfree
), vcnt
, "IU", "");
350 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_forks
, CTLTYPE_UINT
|CTLFLAG_RD
,
351 0, VMMETEROFF(v_forks
), vcnt
, "IU", "Number of fork() calls");
352 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vforks
, CTLTYPE_UINT
|CTLFLAG_RD
,
353 0, VMMETEROFF(v_vforks
), vcnt
, "IU", "Number of vfork() calls");
354 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_rforks
, CTLTYPE_UINT
|CTLFLAG_RD
,
355 0, VMMETEROFF(v_rforks
), vcnt
, "IU", "Number of rfork() calls");
356 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_kthreads
, CTLTYPE_UINT
|CTLFLAG_RD
,
357 0, VMMETEROFF(v_kthreads
), vcnt
, "IU", "Number of fork() calls by kernel");
358 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_forkpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
359 0, VMMETEROFF(v_forkpages
), vcnt
, "IU", "VM pages affected by fork()");
360 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_vforkpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
361 0, VMMETEROFF(v_vforkpages
), vcnt
, "IU", "VM pages affected by vfork()");
362 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_rforkpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
363 0, VMMETEROFF(v_rforkpages
), vcnt
, "IU", "VM pages affected by rfork()");
364 SYSCTL_PROC(_vm_stats_vm
, OID_AUTO
, v_kthreadpages
, CTLTYPE_UINT
|CTLFLAG_RD
,
365 0, VMMETEROFF(v_kthreadpages
), vcnt
, "IU", "VM pages affected by fork() by kernel");
367 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
368 v_page_size
, CTLFLAG_RD
, &vmstats
.v_page_size
, 0, "");
369 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
370 v_page_count
, CTLFLAG_RD
, &vmstats
.v_page_count
, 0, "");
371 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
372 v_free_reserved
, CTLFLAG_RD
, &vmstats
.v_free_reserved
, 0, "");
373 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
374 v_free_target
, CTLFLAG_RD
, &vmstats
.v_free_target
, 0, "");
375 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
376 v_free_min
, CTLFLAG_RD
, &vmstats
.v_free_min
, 0, "");
377 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
378 v_free_count
, CTLFLAG_RD
, &vmstats
.v_free_count
, 0, "");
379 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
380 v_wire_count
, CTLFLAG_RD
, &vmstats
.v_wire_count
, 0, "");
381 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
382 v_active_count
, CTLFLAG_RD
, &vmstats
.v_active_count
, 0, "");
383 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
384 v_inactive_target
, CTLFLAG_RD
, &vmstats
.v_inactive_target
, 0, "");
385 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
386 v_inactive_count
, CTLFLAG_RD
, &vmstats
.v_inactive_count
, 0, "");
387 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
388 v_cache_count
, CTLFLAG_RD
, &vmstats
.v_cache_count
, 0, "");
389 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
390 v_cache_min
, CTLFLAG_RD
, &vmstats
.v_cache_min
, 0, "");
391 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
392 v_cache_max
, CTLFLAG_RD
, &vmstats
.v_cache_max
, 0, "");
393 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
394 v_pageout_free_min
, CTLFLAG_RD
, &vmstats
.v_pageout_free_min
, 0, "");
395 SYSCTL_UINT(_vm_stats_vm
, OID_AUTO
,
396 v_interrupt_free_min
, CTLFLAG_RD
, &vmstats
.v_interrupt_free_min
, 0, "");
397 SYSCTL_INT(_vm_stats_misc
, OID_AUTO
,
398 zero_page_count
, CTLFLAG_RD
, &vm_page_zero_count
, 0, "");
401 do_vmmeter_pcpu(SYSCTL_HANDLER_ARGS
)
403 int boffset
= offsetof(struct vmmeter
, vmmeter_uint_begin
);
404 int eoffset
= offsetof(struct vmmeter
, vmmeter_uint_end
);
405 struct globaldata
*gd
= arg1
;
409 bzero(&vmm
, sizeof(vmm
));
410 for (off
= boffset
; off
<= eoffset
; off
+= sizeof(u_int
)) {
411 *(u_int
*)((char *)&vmm
+ off
) +=
412 *(u_int
*)((char *)&gd
->gd_cnt
+ off
);
414 vmm
.v_intr
+= vmm
.v_ipi
+ vmm
.v_timer
;
415 return (sysctl_handle_opaque(oidp
, &vmm
, sizeof(vmm
), req
));
419 vmmeter_init(void *dummy __unused
)
423 for (i
= 0; i
< ncpus
; ++i
) {
424 struct sysctl_ctx_list
*ctx
;
425 struct sysctl_oid
*oid
;
426 struct globaldata
*gd
;
429 ksnprintf(name
, sizeof(name
), "cpu%d", i
);
431 ctx
= kmalloc(sizeof(*ctx
), M_TEMP
, M_WAITOK
);
432 sysctl_ctx_init(ctx
);
433 oid
= SYSCTL_ADD_NODE(ctx
, SYSCTL_STATIC_CHILDREN(_vm
),
434 OID_AUTO
, name
, CTLFLAG_RD
, 0, "");
436 gd
= globaldata_find(i
);
437 SYSCTL_ADD_PROC(ctx
, SYSCTL_CHILDREN(oid
), OID_AUTO
,
438 "vmmeter", CTLTYPE_OPAQUE
|CTLFLAG_RD
,
439 gd
, sizeof(struct vmmeter
), do_vmmeter_pcpu
,
440 "S,vmmeter", "System per-cpu statistics");
443 SYSINIT(vmmeter
, SI_SUB_PSEUDO
, SI_ORDER_ANY
, vmmeter_init
, 0);