Lines 1-339
Link Here
|
1 |
--- bsd/kernel.cc.orig 2006-02-18 08:36:06.000000000 +0100 |
|
|
2 |
+++ bsd/kernel.cc 2008-12-15 15:46:05.000000000 +0100 |
3 |
@@ -54,6 +54,7 @@ |
4 |
#endif |
5 |
|
6 |
#ifdef HAVE_DEVSTAT |
7 |
+#include <sys/dkstat.h> |
8 |
#include <devstat.h> |
9 |
#include <stdlib.h> /* For malloc(). */ |
10 |
void DevStat_Init(); |
11 |
@@ -83,6 +84,10 @@ |
12 |
#else |
13 |
#include <sys/dkstat.h> |
14 |
#endif |
15 |
+#if defined(XOSVIEW_FREEBSD) && (__FreeBSD_version >= 700000) |
16 |
+#include <sys/resource.h> |
17 |
+#include <sys/sysctl.h> |
18 |
+#endif |
19 |
|
20 |
#ifdef HAVE_SWAPCTL |
21 |
#include <unistd.h> /* For swapctl proto. */ |
22 |
@@ -135,7 +140,7 @@ |
23 |
// this later on. This keeps the indices within the nlist constant. |
24 |
#define DUMMY_SYM "dummy_sym" |
25 |
|
26 |
-#if defined(XOSVIEW_BSDI) || (defined(XOSVIEW_NETBSD) && (__NetBSD_Version__ >= 104260000)) |
27 |
+#if defined(XOSVIEW_BSDI) || (defined(XOSVIEW_NETBSD) && (__NetBSD_Version__ >= 104260000)) || (defined(XOSVIEW_FREEBSD) && (__FreeBSD_version >= 700000)) |
28 |
// BSDI and __NetBSD_Version__ >= 104260000 reads cp_time through sysctl |
29 |
{ DUMMY_SYM }, |
30 |
#define DUMMY_0 |
31 |
@@ -211,19 +216,28 @@ |
32 |
|
33 |
{ "_bufspace" }, |
34 |
#define BUFSPACE_SYM_INDEX 3 |
35 |
+#if __FreeBSD_version < 500000 |
36 |
{ "_intr_countp" }, |
37 |
#define INTRCOUNTP_SYM_INDEX 4 |
38 |
+{ DUMMY_SYM }, |
39 |
+#define DUMMY_5 5 |
40 |
+#else |
41 |
+{ "_intrnames" }, |
42 |
+#define INTRNAMES_SYM_INDEX 4 |
43 |
+{ "_eintrnames" }, |
44 |
+#define EINTRNAMES_SYM_INDEX 5 |
45 |
+#endif /* FreeBSD < 5.x */ |
46 |
{ "_intrcnt" }, |
47 |
-#define INTRCNT_SYM_INDEX 5 |
48 |
+#define INTRCNT_SYM_INDEX 6 |
49 |
{ "_eintrcnt" }, |
50 |
-#define EINTRCNT_SYM_INDEX 6 |
51 |
+#define EINTRCNT_SYM_INDEX 7 |
52 |
|
53 |
#ifndef HAVE_DEVSTAT |
54 |
|
55 |
{ "_dk_ndrive" }, |
56 |
-#define DK_NDRIVE_SYM_INDEX 7 |
57 |
+#define DK_NDRIVE_SYM_INDEX 8 |
58 |
{ "_dk_wds" }, |
59 |
-#define DK_WDS_SYM_INDEX 8 |
60 |
+#define DK_WDS_SYM_INDEX 9 |
61 |
|
62 |
#endif /*HAVE_DEVSTAT */ |
63 |
|
64 |
@@ -329,7 +343,12 @@ |
65 |
while (nlp && nlp->n_name && strncmp(nlp->n_name, DUMMY_SYM, strlen(DUMMY_SYM))) { |
66 |
if ((nlp->n_type == 0) || (nlp->n_value == 0)) |
67 |
/*errx (-1, "kvm_nlist() lookup failed for symbol '%s'.", nlp->n_name);*/ |
68 |
+#if defined(XOSVIEW_FREEBSD) && defined(__alpha__) |
69 |
+ /* XXX: this should be properly fixed. */ |
70 |
+ ; |
71 |
+#else |
72 |
warnx ("kvm_nlist() lookup failed for symbol '%s'.", nlp->n_name); |
73 |
+#endif |
74 |
nlp++; |
75 |
} |
76 |
#ifdef HAVE_DEVSTAT |
77 |
@@ -402,11 +421,17 @@ |
78 |
#if defined(XOSVIEW_NETBSD) && (__NetBSD_Version__ >= 104260000) |
79 |
static int mib[] = { CTL_KERN, KERN_CP_TIME }; |
80 |
#endif |
81 |
+#if defined(XOSVIEW_FREEBSD) && (__FreeBSD_version >= 700000) |
82 |
+ |
83 |
+ long cpu[CPUSTATES]; |
84 |
+ size_t size = sizeof(cpu); |
85 |
+ |
86 |
+#endif |
87 |
|
88 |
if (!timeArray) errx (-1, "BSDGetCPUTimes(): passed pointer was null!\n"); |
89 |
if (CPUSTATES != 5) |
90 |
errx (-1, "Error: xosview for *BSD expects 5 cpu states!\n"); |
91 |
-#if defined(__NetBSD_Version__) && __NetBSD_Version__ > 104260000 /* > 1.4Z */ |
92 |
+#if (defined(__NetBSD_Version__) && __NetBSD_Version__ > 104260000) /* > 1.4Z */ |
93 |
struct schedstate_percpu ssp; |
94 |
size_t size = sizeof(ssp.spc_cp_time); |
95 |
if (sysctl(mib, 2, ssp.spc_cp_time, &size, NULL, 0) < 0) { |
96 |
@@ -423,9 +448,18 @@ |
97 |
} |
98 |
bcopy (cpu.cp_time,timeArray,sizeof (long) * CPUSTATES); |
99 |
#else |
100 |
+#if defined(XOSVIEW_FREEBSD) && (__FreeBSD_version >= 700000) |
101 |
+ |
102 |
+ if (sysctlbyname("kern.cp_time", &cpu, &size, NULL, 0) < 0) { |
103 |
+ fprintf(stderr, "xosview: sysctl failed: %s\n", strerror(errno)); |
104 |
+ bzero(&cpu, sizeof(cpu)); |
105 |
+ } |
106 |
+ bcopy (cpu,timeArray,sizeof (long) * CPUSTATES); |
107 |
+#else |
108 |
safe_kvm_read_symbol (CP_TIME_SYM_INDEX, timeArray, sizeof (long) * CPUSTATES); |
109 |
#endif |
110 |
#endif |
111 |
+#endif |
112 |
} |
113 |
|
114 |
|
115 |
@@ -597,13 +631,21 @@ |
116 |
* Make sure that the userland devstat version matches the kernel |
117 |
* devstat version. |
118 |
*/ |
119 |
+#if __FreeBSD_version >= 500000 |
120 |
+ if (devstat_checkversion(kd) < 0) { |
121 |
+#else |
122 |
if (checkversion() < 0) { |
123 |
+#endif |
124 |
nodisk++; |
125 |
return; |
126 |
} |
127 |
|
128 |
/* find out how many devices we have */ |
129 |
+#if __FreeBSD_version >= 500000 |
130 |
+ if ((num_devices = devstat_getnumdevs(kd)) < 0) { |
131 |
+#else |
132 |
if ((num_devices = getnumdevs()) < 0) { |
133 |
+#endif |
134 |
nodisk++; |
135 |
return; |
136 |
} |
137 |
@@ -618,7 +660,11 @@ |
138 |
* changed here, since it almost certainly has. We only look for |
139 |
* errors. |
140 |
*/ |
141 |
+#if __FreeBSD_version >= 500000 |
142 |
+ if (devstat_getdevs(kd,&cur) == -1) { |
143 |
+#else |
144 |
if (getdevs(&cur) == -1) { |
145 |
+#endif |
146 |
nodisk++; |
147 |
return; |
148 |
} |
149 |
@@ -630,7 +676,11 @@ |
150 |
|
151 |
/* only interested in disks */ |
152 |
matches = NULL; |
153 |
+#if __FreeBSD_version >= 500000 |
154 |
+ if (devstat_buildmatch("da", &matches, &num_matches) != 0) { |
155 |
+#else |
156 |
if (buildmatch("da", &matches, &num_matches) != 0) { |
157 |
+#endif |
158 |
nodisk++; |
159 |
return; |
160 |
} |
161 |
@@ -645,13 +695,18 @@ |
162 |
* device list has changed, so we don't look for return values of 0 |
163 |
* or 1. If we get back -1, though, there is an error. |
164 |
*/ |
165 |
+#if __FreeBSD_version >= 500000 |
166 |
+ if (devstat_selectdevs(&dev_select, &num_selected, |
167 |
+#else |
168 |
if (selectdevs(&dev_select, &num_selected, |
169 |
+#endif |
170 |
&num_selections, &select_generation, |
171 |
generation, cur.dinfo->devices, num_devices, |
172 |
matches, num_matches, |
173 |
NULL, 0, |
174 |
select_mode, 10, 0) == -1) |
175 |
nodisk++; |
176 |
+ |
177 |
} |
178 |
|
179 |
int |
180 |
@@ -672,7 +727,11 @@ |
181 |
* the selection process again, in case a device that we |
182 |
* were previously displaying has gone away. |
183 |
*/ |
184 |
+#if __FreeBSD_version >= 500000 |
185 |
+ switch (devstat_getdevs(kd,&cur)) { |
186 |
+#else |
187 |
switch (getdevs(&cur)) { |
188 |
+#endif |
189 |
case -1: |
190 |
return (0); |
191 |
case 1: { |
192 |
@@ -680,7 +739,11 @@ |
193 |
|
194 |
num_devices = cur.dinfo->numdevs; |
195 |
generation = cur.dinfo->generation; |
196 |
+#if __FreeBSD_version >= 500000 |
197 |
+ retval = devstat_selectdevs(&dev_select, &num_selected, |
198 |
+#else |
199 |
retval = selectdevs(&dev_select, &num_selected, |
200 |
+#endif |
201 |
&num_selections, &select_generation, |
202 |
generation, cur.dinfo->devices, |
203 |
num_devices, matches, num_matches, |
204 |
@@ -704,14 +767,22 @@ |
205 |
* Calculate elapsed time up front, since it's the same for all |
206 |
* devices. |
207 |
*/ |
208 |
+#if __FreeBSD_version >= 500000 |
209 |
+ busy_seconds = cur.snap_time - last.snap_time; |
210 |
+#else |
211 |
busy_seconds = compute_etime(cur.busy_time, last.busy_time); |
212 |
+#endif |
213 |
|
214 |
/* this is the first time thru so just copy cur to last */ |
215 |
if (last.dinfo->numdevs == 0) { |
216 |
tmp_dinfo = last.dinfo; |
217 |
last.dinfo = cur.dinfo; |
218 |
cur.dinfo = tmp_dinfo; |
219 |
+#if __FreeBSD_version >= 500000 |
220 |
+ last.snap_time = cur.snap_time; |
221 |
+#else |
222 |
last.busy_time = cur.busy_time; |
223 |
+#endif |
224 |
return (0); |
225 |
} |
226 |
|
227 |
@@ -725,12 +796,15 @@ |
228 |
|
229 |
di = dev_select[dn].position; |
230 |
|
231 |
+#if __FreeBSD_version >= 500000 |
232 |
+ if (devstat_compute_statistics(&cur.dinfo->devices[di], |
233 |
+#else |
234 |
if (compute_stats(&cur.dinfo->devices[di], |
235 |
+#endif |
236 |
&last.dinfo->devices[di], busy_seconds, |
237 |
- &total_bytes, &total_transfers, |
238 |
- NULL, NULL, |
239 |
- NULL, NULL, |
240 |
- NULL, NULL)!= 0) |
241 |
+ DSM_TOTAL_BYTES, &total_bytes, |
242 |
+ DSM_TOTAL_TRANSFERS, &total_transfers, |
243 |
+ DSM_NONE)!= 0) |
244 |
break; |
245 |
total_xfers += (int)total_transfers; |
246 |
total_xbytes += (int)total_bytes; |
247 |
@@ -740,7 +814,11 @@ |
248 |
last.dinfo = cur.dinfo; |
249 |
cur.dinfo = tmp_dinfo; |
250 |
|
251 |
+#if __FreeBSD_version >= 500000 |
252 |
+ last.snap_time = cur.snap_time; |
253 |
+#else |
254 |
last.busy_time = cur.busy_time; |
255 |
+#endif |
256 |
|
257 |
} else { |
258 |
/* no disks found ? */ |
259 |
@@ -912,25 +990,26 @@ |
260 |
OpenKDIfNeeded(); |
261 |
nintr = (nlst[EINTRCNT_SYM_INDEX].n_value - |
262 |
nlst[INTRCNT_SYM_INDEX].n_value) / sizeof(int); |
263 |
-#ifdef XOSVIEW_FREEBSD |
264 |
- /* I'm not sure exactly how FreeBSD does things, but just do |
265 |
+#if defined(i386) |
266 |
+# if defined(XOSVIEW_FREEBSD) |
267 |
+ /* I'm not sure exactly how FreeBSD/i386 does things, but just do |
268 |
* 16 for now. bgrayson */ |
269 |
return 16; |
270 |
-#else |
271 |
-# if defined(i386) |
272 |
+# else |
273 |
/* On the 386 platform, we count stray interrupts between |
274 |
* intrct and eintrcnt, also, but we don't want to show these. */ |
275 |
return nintr/2; |
276 |
-# else |
277 |
- return nintr; |
278 |
# endif |
279 |
+#else |
280 |
+ return nintr; |
281 |
#endif |
282 |
} |
283 |
#endif /* XOSVIEW_OPENBSD */ |
284 |
|
285 |
void |
286 |
BSDGetIntrStats (unsigned long intrCount[NUM_INTR]) { |
287 |
-#ifdef XOSVIEW_FREEBSD |
288 |
+#if defined(XOSVIEW_FREEBSD) && defined(__i386__) |
289 |
+#if __FreeBSD_version < 500000 |
290 |
/* FreeBSD has an array of interrupt counts, indexed by device number. |
291 |
These are also indirected by IRQ num with intr_countp: */ |
292 |
safe_kvm_read (nlst[INTRCOUNTP_SYM_INDEX].n_value, |
293 |
@@ -944,6 +1023,46 @@ |
294 |
sizeof(unsigned long); |
295 |
intrCount[i] = kvm_intrcnt[idx]; |
296 |
} |
297 |
+#else /* FreeBSD 5.x and 6.x */ |
298 |
+ /* This code is stolen from vmstat */ |
299 |
+ unsigned long *kvm_intrcnt, *base_intrcnt; |
300 |
+ char *kvm_intrname, *base_intrname; |
301 |
+ size_t inamlen, intrcntlen; |
302 |
+ unsigned int i, nintr; |
303 |
+ int d; |
304 |
+ |
305 |
+ intrcntlen = (nlst[EINTRCNT_SYM_INDEX].n_value - nlst[INTRCNT_SYM_INDEX].n_value); |
306 |
+ inamlen = nlst[EINTRNAMES_SYM_INDEX].n_value - nlst[INTRNAMES_SYM_INDEX].n_value; |
307 |
+ nintr = intrcntlen / sizeof(unsigned long); |
308 |
+ |
309 |
+ if (((kvm_intrcnt = (unsigned long *)malloc(intrcntlen)) == NULL) || |
310 |
+ ((kvm_intrname = (char *)malloc(inamlen)) == NULL)) |
311 |
+ err(1, "malloc()"); |
312 |
+ |
313 |
+ // keep track of the mem we're given: |
314 |
+ base_intrcnt = kvm_intrcnt; |
315 |
+ base_intrname = kvm_intrname; |
316 |
+ |
317 |
+ safe_kvm_read (nlst[INTRCNT_SYM_INDEX].n_value, kvm_intrcnt, intrcntlen); |
318 |
+ safe_kvm_read (nlst[INTRNAMES_SYM_INDEX].n_value, kvm_intrname, inamlen); |
319 |
+ |
320 |
+ /* kvm_intrname has the ASCII names of the IRQs, every null-terminated |
321 |
+ * string corresponds to a value in the kvm_intrcnt array */ |
322 |
+ for (i=0; i < nintr; i++) { |
323 |
+ if (kvm_intrname[0] != '\0' && (*kvm_intrcnt != 0)) { |
324 |
+ /* Figure out which irq we have here */ |
325 |
+ if (1 == sscanf(kvm_intrname, "irq%d:", &d)) |
326 |
+ if (d < NUM_INTR) |
327 |
+ intrCount[d] = *kvm_intrcnt; |
328 |
+ } |
329 |
+ kvm_intrcnt++; |
330 |
+ kvm_intrname += strlen(kvm_intrname) + 1; |
331 |
+ } |
332 |
+ |
333 |
+ // Doh! somebody needs to free this stuff too... (pavel 20-Jan-2006) |
334 |
+ free(base_intrcnt); |
335 |
+ free(base_intrname); |
336 |
+#endif |
337 |
#elif defined (XOSVIEW_BSDI) |
338 |
int nintr = 16; |
339 |
#if _BSDI_VERSION >= 199802 /* BSD/OS 4.x */ |