2 * Copyright (c) 2003-2004. Hiten Pandya <hmp@backplane.com>.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY HITEN PANDYA AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL HITEN PANDYA OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * $DragonFly: src/lib/libkvm/kvm_util.c,v 1.1 2004/04/02 05:46:02 hmp Exp $
34 * Useful functions that are used across the source base for
38 #include <sys/param.h>
39 #include <sys/nchstats.h>
40 #include <sys/sysctl.h>
48 * Aggregate the per-cpu counters we retrieved via sysctl(2)
49 * to give the total across the CPUs. Use a nasty trick to
50 * aggregate the counters in the structure! YYY
53 kvm_nch_cpuagg(struct nchstats *unagg, struct nchstats *ttl, int cpucnt)
56 siz = sizeof(struct nchstats);
63 /* kick hmp@ for this nasty loop! :-) */
64 for (i = 0; i < cpucnt; ++i) {
65 for (off = 0; off < siz; off += sizeof(u_long)) {
66 *(u_long *)((char *)(*(&ttl)) + off) +=
67 *(u_long *)((char *)&unagg[i] + off);