1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
$NetBSD: patch-dm,v 1.1 2006/03/19 22:03:29 joerg Exp $
--- agent/mibgroup/ucd-snmp/vmstat_freebsd2.c.orig 2004-06-29 12:14:32.000000000 +0000
+++ agent/mibgroup/ucd-snmp/vmstat_freebsd2.c
@@ -9,9 +9,15 @@
*/
#include <sys/param.h>
#include <sys/time.h>
+#if defined(dragonfly)
+#include <sys/user.h>
+#else
#include <sys/proc.h>
+#endif
#if defined(freebsd5) && __FreeBSD_version >= 500101
#include <sys/resource.h>
+#elif defined(dragonfly)
+#include <kinfo.h>
#else
#include <sys/dkstat.h>
#endif
@@ -168,11 +174,18 @@ var_extensible_vmstat(struct variable *v
static time_t time_old;
static time_t time_diff;
+#if defined(dragonfly)
+ static struct kinfo_cputime cpu_old, cpu_new, cpu_diff;
+ static uint64_t cpu_total;
+ uint64_t cpu_sum;
+ static int pagesize;
+#else
static long cpu_old[CPUSTATES];
static long cpu_new[CPUSTATES];
static long cpu_diff[CPUSTATES];
static long cpu_total;
long cpu_sum;
+#endif
double cpu_prc;
static struct vmmeter mem_old, mem_new;
@@ -180,6 +193,11 @@ var_extensible_vmstat(struct variable *v
static long long_ret;
static char errmsg[300];
+#if defined(dragonfly)
+ if (pagesize == 0)
+ pagesize = getpagesize() >> 10;
+#endif
+
long_ret = 0; /* set to 0 as default */
if (header_generic(vp, name, length, exact, var_len, write_method))
@@ -195,15 +213,27 @@ var_extensible_vmstat(struct variable *v
/*
* CPU usage
*/
- auto_nlist(CPTIME_SYMBOL, (char *) cpu_new, sizeof(cpu_new));
+ cpu_total = 0;
- cpu_total = 0;
+#if defined(dragonfly)
+ kinfo_get_sched_cputime(&cpu_new);
+#define CP_UPDATE(field) cpu_diff.field = cpu_new.field - cpu_old.field; cpu_total += cpu_diff.field;
+ CP_UPDATE(cp_user);
+ CP_UPDATE(cp_nice);
+ CP_UPDATE(cp_sys);
+ CP_UPDATE(cp_intr);
+ CP_UPDATE(cp_idle);
+ cpu_old = cpu_new;
+#undef CP_UPDATE
+#else
+ auto_nlist(CPTIME_SYMBOL, (char *) cpu_new, sizeof(cpu_new));
for (loop = 0; loop < CPUSTATES; loop++) {
cpu_diff[loop] = cpu_new[loop] - cpu_old[loop];
cpu_old[loop] = cpu_new[loop];
cpu_total += cpu_diff[loop];
}
+#endif
if (cpu_total == 0)
cpu_total = 1;
@@ -223,7 +253,11 @@ var_extensible_vmstat(struct variable *v
/*
* Page-to-kb macro
*/
+#if defined(dragonfly)
+#define ptok(p) ((p) * pagesize)
+#else
#define ptok(p) ((p) * (mem_new.v_page_size >> 10))
+#endif
switch (vp->magic) {
case MIBINDEX:
@@ -270,37 +304,73 @@ var_extensible_vmstat(struct variable *v
long_ret = rate(mem_new.v_swtch - mem_old.v_swtch);
return ((u_char *) (&long_ret));
case CPUUSER:
+#if defined(dragonfly)
+ cpu_sum = cpu_diff.cp_user + cpu_diff.cp_nice;
+#else
cpu_sum = cpu_diff[CP_USER] + cpu_diff[CP_NICE];
+#endif
cpu_prc = (float) cpu_sum / (float) cpu_total;
long_ret = cpu_prc * CPU_PRC;
return ((u_char *) (&long_ret));
case CPUSYSTEM:
+#if defined(dragonfly)
+ cpu_sum = cpu_diff.cp_sys + cpu_diff.cp_intr;
+#else
cpu_sum = cpu_diff[CP_SYS] + cpu_diff[CP_INTR];
+#endif
cpu_prc = (float) cpu_sum / (float) cpu_total;
long_ret = cpu_prc * CPU_PRC;
return ((u_char *) (&long_ret));
case CPUIDLE:
+#if defined(dragonfly)
+ cpu_sum = cpu_diff.cp_idle;
+#else
cpu_sum = cpu_diff[CP_IDLE];
+#endif
cpu_prc = (float) cpu_sum / (float) cpu_total;
long_ret = cpu_prc * CPU_PRC;
return ((u_char *) (&long_ret));
case CPURAWUSER:
+#if defined(dragonfly)
+ cpu_sum = cpu_new.cp_user;
+#else
long_ret = cpu_new[CP_USER];
+#endif
return ((u_char *) (&long_ret));
case CPURAWNICE:
+#if defined(dragonfly)
+ cpu_sum = cpu_new.cp_nice;
+#else
long_ret = cpu_new[CP_NICE];
+#endif
return ((u_char *) (&long_ret));
case CPURAWSYSTEM:
+#if defined(dragonfly)
+ cpu_sum = cpu_new.cp_sys + cpu_new.cp_intr;
+#else
long_ret = cpu_new[CP_SYS] + cpu_new[CP_INTR];
+#endif
return ((u_char *) (&long_ret));
case CPURAWIDLE:
+#if defined(dragonfly)
+ cpu_sum = cpu_new.cp_idle;
+#else
long_ret = cpu_new[CP_IDLE];
+#endif
return ((u_char *) (&long_ret));
case CPURAWKERNEL:
+#if defined(dragonfly)
+ cpu_sum = cpu_new.cp_sys;
+#else
long_ret = cpu_new[CP_SYS];
+#endif
return ((u_char *) (&long_ret));
case CPURAWINTR:
+#if defined(dragonfly)
+ cpu_sum = cpu_new.cp_intr;
+#else
long_ret = cpu_new[CP_INTR];
+#endif
return ((u_char *) (&long_ret));
case SYSRAWINTERRUPTS:
long_ret = mem_new.v_intr;
|