summaryrefslogtreecommitdiff
path: root/parallel/glunix/patches/patch-aj
blob: 994ec58a2685c4e223eec27b83bcdda609d7db7b (plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
$NetBSD: patch-aj,v 1.1.1.1 1998/10/21 19:59:29 garbled Exp $

--- glunix/src/idle/didle_sysinfo.cc~	Thu Sep 18 12:04:55 1997
+++ glunix/src/idle/didle_sysinfo.cc	Fri Feb 27 06:42:28 1998
@@ -97,2 +97,12 @@
 #include <stdio.h>
+
+#ifdef __NetBSD__
+#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <miscfs/procfs/procfs.h>
+#include <vm/vm_swap.h>
+#include <sys/sysctl.h>
+#else
 #include <sys/proc.h>
@@ -102,5 +112,10 @@
 #include <sys/time.h>
+#endif
+
 #include <unistd.h>
 #include <bsd.h>
+
+#ifndef __NetBSD__
 #include <vm/anon.h>  // Contains defns for swap virtual memory info
+#endif
 
@@ -122,8 +137,47 @@
 #define HASH(x) ((x) >> 1)
+
+#ifdef __NetBSD__
+int getpsize()
+{
+  FILE *file;
+  char *buf;
+
+  file = fopen("/kern/pagesize","r");
+  fscanf(file,"%s",buf);
+  fclose(file);
+  return atoi(buf);
+}
+#define PAGETOK(size) (size) * getpsize()
+
+#else
 #define PAGETOK(size) (size) << 3     // 8K pages
+#endif
 
+#ifndef __NetBSD__
 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
-
+#endif
 /*****************************************************************************/
 
+#ifdef __NetBSD__
+static struct nlist nlst[] = {
+#define X_CCPU          0
+    { "_ccpu" },                /* 0 */
+#define X_CP_TIME       1
+    { "_cp_time" },             /* 1 */
+#define X_HZ            2
+    { "_hz" },                  /* 2 */
+#define X_STATHZ        3
+    { "_stathz" },              /* 3 */
+#define X_AVENRUN       4
+    { "_averunnable" },         /* 4 */
+#define X_CNT           5
+    { "_cnt" },
+
+    { 0 }
+};
+
+static ulong cp_time_offset,cnt_offset;
+
+#else
+
 /* definitions for indices in the nlist array */
@@ -167,3 +221,3 @@
 static ulong avenrunOffset, availrmemOffset, anoninfoOffset, swapfsOffset;
-
+#endif
 /*****************************************************************************/
@@ -239,2 +293,41 @@
  *****************************************************************************/
+#ifdef __NetBSD__
+Bool
+Idle_InitializeSysinfo(void)
+{
+    int  notFound;
+    int  i;
+
+    if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) {
+	kd = NULL;
+	perror("(dile)Idle_InitializeSysinfo: kvm_open");
+	return -1;
+    }
+    /* get the list of symbols we want to access in the kernel */
+    if ((notFound = kvm_nlist(kd, nlst)) < 0) {
+	fprintf(stderr, "res: nlist failed\n");
+	return False;
+    }
+    numCpus=1;
+    cp_time_offset = nlst[X_CP_TIME].n_value;
+    cnt_offset = nlst[X_CNT].n_value;
+
+    if (!(procdir = opendir(PROCFS))) {
+	(void) fprintf(stderr, "Unable to open %s\n", PROCFS);
+	return False;
+    }
+    /* handy for later on when we're reading it */
+    if (chdir(PROCFS)) {
+	(void) fprintf(stderr, "Unable to chdir to %s\n", PROCFS);
+	return False;
+    }
+
+    for (i = 0; i < USAGE_TABLE_SIZE; i++) {
+	procUsageTable[i].pid = -1;
+	procUsageTable[i].cpuUsage = 0.0;
+    }
+
+    return True;
+}
+#else
 Bool
@@ -303,3 +396,3 @@
 }
-
+#endif
 /******************************************************************************
@@ -335,4 +428,9 @@
  *****************************************************************************/
+#ifdef __NetBSD__
+static ProcUsage *
+FindEntry(pid_t pid, double usage)
+#else
 static ProcUsage *
 FindEntry(struct prpsinfo *targProc, double usage)
+#endif
 {
@@ -340,5 +438,8 @@
     ProcUsage  *candidate;
+#ifdef __NetBSD__
+    index = HASH(pid);
+#else
     ASSERT(targProc != NULL);
-    
     index = HASH(targProc->pr_pid);
+#endif
     start = index;
@@ -346,3 +447,7 @@
 	candidate = &(procUsageTable[index]);
+#ifdef __NetBSD__
+	if (candidate->pid == pid) {
+#else
 	if (candidate->pid == targProc->pr_pid) {
+#endif
 	    /* Has this pid been recycled?  Are we hitting a very old process?
@@ -355,3 +460,7 @@
 	if (candidate->pid == -1) {
+#ifdef __NetBSD__
+	    candidate->pid = pid;
+#else
 	    candidate->pid = targProc->pr_pid;
+#endif
 	    candidate->cpuUsage = 0;
@@ -381,2 +490,8 @@
  *****************************************************************************/
+
+#ifdef __NetBSD__
+static void
+UpdateEntry(ProcUsage *entry, double usage)
+{
+#else
 static void
@@ -385,2 +500,3 @@
     UNUSED_PARAM(proc);
+#endif
     ASSERT(entry != NULL);
@@ -410,3 +526,11 @@
 {
+
+#ifndef __NetBSD__
     struct prpsinfo  currproc;	/* pointer to current proc structure	*/
+#else
+    struct kinfo_proc *procs;
+    int mib[3],i;
+    size_t size;
+#endif
+
     int              fd;
@@ -461,2 +585,29 @@
     numProcs = 0;
+
+#ifdef __NetBSD__
+    size = 0;
+    mib[0] = CTL_KERN;
+    mib[1] = KERN_PROC;
+    mib[2] = KERN_PROC_ALL;
+
+    sysctl(mib, 3, NULL, &size, NULL, 0);
+    procs = (struct kinfo_proc *)malloc(size);
+    sysctl(mib, 3, procs, &size, NULL, 0);
+    numProcs = size / sizeof(struct kinfo_proc);
+
+    for (i=0; i<numProcs; i++) {
+      activeMemory[TOTAL] += procs[i].kp_eproc.e_xrssize;
+      vmInUse[TOTAL] += procs[i].kp_eproc.e_xsize;
+      currUsage = procs[i].kp_proc.p_rtime.tv_sec * 1.0e9 + procs[i].kp_proc.p_rtime.tv_usec * 1000;
+      oldProc = FindEntry(procs[i].kp_proc.p_pid, currUsage);
+      percentCpu = (currUsage - oldProc->cpuUsage) / timeDiff;
+      UpdateEntry(oldProc, currUsage);
+      cpuUsage[TOTAL] += (int) (percentCpu * 10.0);
+      if (glunixProcs->KeySearch(procs[i].kp_proc.p_pid) == NULL) {
+	activeMemory[SEQUENTIAL] += procs[i].kp_eproc.e_xrssize;
+	vmInUse[SEQUENTIAL] += procs[i].kp_eproc.e_xsize;
+	cpuUsage[SEQUENTIAL] += (int) (percentCpu * 10.0);
+      }
+    }
+#else
     rewinddir(procdir);
@@ -495,2 +646,3 @@
     }
+#endif
     total->mem = activeMemory[TOTAL];
@@ -505,6 +657,15 @@
 {
-    struct anoninfo anoninfo;
+#ifndef __NetBSD__
+    int      i;
     long     avenrun[3];
+    struct anoninfo anoninfo;
     int      ani_max, ani_resv, availrmem, swapfs_minfree;
-    int      i;
+#else
+    int i;
+    double  avenrun[3];
+    struct  vmmeter sum;
+    struct  swapent *sep;
+    int     totalsize, size, totalinuse, inuse, ncounted;
+    int     rnswap, nswap;
+#endif
 
@@ -517,3 +678,37 @@
     }
+#ifdef __NetBSD__
 
+    getloadavg(avenrun,3);
+    for (i = 0; i < 3; i++) {
+	sysLoad->loadAvg[i] = avenrun[i];
+    }
+
+    kvm_read(kd, cnt_offset, (int *)(&sum), sizeof(sum));
+    sep = NULL;
+    do {
+        nswap = swapctl(SWAP_NSWAP, 0, 0);
+        if (nswap < 1)
+                break;
+        sep = (struct swapent *)malloc(nswap * sizeof(*sep));
+        if (sep == NULL)
+                break;
+        rnswap = swapctl(SWAP_STATS, (void *)sep, nswap);
+        if (nswap != rnswap)
+                break;
+
+        totalsize = totalinuse = ncounted = 0;
+        for (; rnswap-- > 0; sep++) {
+            ncounted++;
+            size = sep->se_nblks;
+            inuse = sep->se_inuse;
+            totalsize += size;
+            totalinuse += inuse;
+        }
+
+    } while (0);
+    if (sep)
+            free(sep);
+
+    sysLoad->memory = PAGETOK(dbtob(totalsize) - dbtob(totalinuse) + sum.v_free_count);
+#else
     /* get load average array */
@@ -541,2 +736,3 @@
 
+#endif
     return;