1 $NetBSD: patch-aa,v 1.19 2007/12/17 22:08:12 veego Exp $
3 --- bsd/kernel.cc.orig 2006-02-18 08:36:06.000000000 +0100
4 +++ bsd/kernel.cc 2007-12-17 21:23:26.000000000 +0100
6 // in __NetBSD_Version__ for us if needed.
7 #if defined(XOSVIEW_NETBSD) && defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106010000)
10 +static int dmib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
13 +static int dmib[3] = {CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl)};
14 +#include <sys/iostat.h>
18 +#include "netmeter.h" /* For netIface_ */
20 #include "kernel.h" /* To grab CVSID stuff. */
26 + static int initialized = 0;
27 char unusederrorstring[_POSIX2_LINE_MAX];
29 - if (kd) return; // kd is non-NULL, so it has been initialized. BCG
30 + if (initialized) return;
33 /* Open it read-only, for a little added safety. */
34 /* If the first character of kernelFileName is not '\0', then use
37 if ((kd = kvm_openfiles ((kernelFileName[0]) ? kernelFileName : NULL,
38 NULL, NULL, O_RDONLY, unusederrorstring))
40 - err (-1, "OpenKDIfNeeded():kvm-open()");
42 + warn ("OpenKDIfNeeded():kvm-open()");
45 // Parenthetical note: FreeBSD kvm_openfiles() uses getbootfile() to get
46 // the correct kernel file if the 1st arg is NULL. As far as I can see,
47 // one should always use NULL in FreeBSD, but I suppose control is never a
49 static int mib[] = { CTL_KERN, KERN_CPUSTATS };
51 #if defined(XOSVIEW_NETBSD) && (__NetBSD_Version__ >= 104260000)
52 + uint64_t cp_time[CPUSTATES];
53 + size_t size = sizeof(cp_time[0]) * CPUSTATES;
54 static int mib[] = { CTL_KERN, KERN_CP_TIME };
59 errx (-1, "Error: xosview for *BSD expects 5 cpu states!\n");
60 #if defined(__NetBSD_Version__) && __NetBSD_Version__ > 104260000 /* > 1.4Z */
61 - struct schedstate_percpu ssp;
62 - size_t size = sizeof(ssp.spc_cp_time);
63 - if (sysctl(mib, 2, ssp.spc_cp_time, &size, NULL, 0) < 0) {
64 - fprintf(stderr, "can't get schedstate_percpu: %s\n", strerror(errno));
65 - memset(&ssp, 0, sizeof(ssp));
66 + if (sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) {
67 + fprintf(stderr, "xosview: sysctl kern.cp_time failed: %s\n", strerror(errno));
68 + bzero(&cp_time, size);
70 - for (size = 0; size < CPUSTATES; size++)
71 - timeArray[size] = (long) ssp.spc_cp_time[size];
72 + bcopy (cp_time, timeArray, size);
75 if (sysctl(mib, 2, &cpu, &size, NULL, 0) < 0) {
80 -BSDGetNetInOut (long long * inbytes, long long * outbytes) {
81 +NetMeter::BSDGetNetInOut (long long * inbytes, long long * outbytes) {
84 struct ifnet * ifnetp;
87 // Now, dereference the pointer to get the ifnet struct.
88 safe_kvm_read ((u_long) ifnetp, &ifnet, sizeof(ifnet));
90 +#ifdef XOSVIEW_NETBSD
91 + if (netIface_ != "False" ) {
93 #ifdef NETBSD_OLD_IFACE
94 // In pre-1.2A, getting the interface name was more complicated.
96 safe_kvm_read ((u_long) (((char*)ifnetp) + (&ifnet.if_xname[0] - (char*)&ifnet)), ifname, 256);
97 snprintf (ifname, 256, "%s", ifname);
100 printf ("Interface name is %s\n", ifname);
101 printf ("Ibytes: %8llu Obytes %8llu\n",
102 (unsigned long long) ifnet.if_ibytes,
103 (unsigned long long) ifnet.if_obytes);
104 printf ("Ipackets: %8llu\n", (unsigned long long) ifnet.if_ipackets);
106 +#endif /* NET_DEBUG */
107 + if (ifname != netIface_)
110 +#endif /* XOSVIEW_NETBSD */
111 *inbytes += ifnet.if_ibytes;
112 *outbytes += ifnet.if_obytes;
115 // Linked-list step taken from if.c in netstat source, line 120.
116 #ifdef XOSVIEW_FREEBSD
117 #if (__FreeBSD_version >= 300000)
118 @@ -773,13 +791,12 @@
120 // Do a sysctl with a NULL data pointer to get the size that would
121 // have been returned, and use that to figure out # drives.
122 - int mib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
124 - if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) {
125 + if (sysctl(dmib, 3, NULL, &size, NULL, 0) < 0) {
126 warnx("!!! The DiskMeter sysctl failed. Disabling DiskMeter.");
129 - NetBSD_N_Drives = size / sizeof(struct disk_sysctl);
130 + NetBSD_N_Drives = size / dmib[2];
133 return ValidSymbol(DISKLIST_SYM_INDEX);
134 @@ -816,19 +833,29 @@
136 #if defined(NETBSD_1_6A)
137 // Use the new sysctl to do this for us.
138 - int mib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
139 - size_t sysctl_sz = NetBSD_N_Drives * sizeof(struct disk_sysctl);
140 + size_t sysctl_sz = NetBSD_N_Drives * dmib[2];
142 struct disk_sysctl drive_stats[NetBSD_N_Drives];
145 + struct io_sysctl drive_stats[NetBSD_N_Drives];
149 - if (sysctl(mib, 3, drive_stats, &sysctl_sz, NULL, 0) < 0) {
150 + if (sysctl(dmib, 3, drive_stats, &sysctl_sz, NULL, 0) < 0) {
151 err(1, "sysctl hw.diskstats failed");
154 // Now accumulate the total.
155 unsigned long long xferred = 0;
156 for (unsigned int i = 0; i < NetBSD_N_Drives; i++) {
158 xferred += drive_stats[i].dk_rbytes + drive_stats[i].dk_wbytes;
161 + if (drive_stats[i].type == IOSTAT_DISK)
162 + xferred += drive_stats[i].rbytes + drive_stats[i].wbytes;
165 *bytesXferred = xferred;
167 @@ -1016,7 +1043,7 @@
169 while (evptr && i < NUM_INTR) {
171 - safe_kvm_read((unsigned int)evptr, &evcnt, sizeof(evcnt));
172 + safe_kvm_read((u_long)evptr, &evcnt, sizeof(evcnt));
174 evptr = evcnt.ev_list.tqe_next;
176 @@ -1024,7 +1051,7 @@
177 if (evcnt.ev_type != EVCNT_TYPE_INTR)
180 - safe_kvm_read((unsigned int)evcnt.ev_name, evname, evcnt.ev_namelen);
181 + safe_kvm_read((u_long)evcnt.ev_name, evname, evcnt.ev_namelen);
182 // If it's a soft interrupt (has a name that starts with "soft"), skip it.
183 if (!strncmp(evname, "soft", 4))