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: #ifdef HAVE_CONFIG_H
85: # include <config.h>
86: #endif
87:
88: #include <sys/types.h>
89:
90:
91:
92:
93: #if defined (unix) || defined (__unix)
94: # include <sys/param.h>
95: #endif
96:
97:
98:
99:
100:
101:
102:
103:
104: #include <errno.h>
105:
106: #ifndef errno
107: extern int errno;
108: #endif
109:
110: #ifdef HAVE_LOCALE_H
111: # include <locale.h>
112: #endif
113: #ifndef HAVE_SETLOCALE
114: # define setlocale(Category, Locale)
115: #endif
116:
117: #ifndef HAVE_GETLOADAVG
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129: # if !defined(LDAV_CVT) && defined(LOAD_AVE_CVT)
130: # define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0)
131: # endif
132:
133: # if !defined (BSD) && defined (ultrix)
134:
135: # define BSD
136: # endif
137:
138: # ifdef NeXT
139:
140:
141:
142: # undef BSD
143:
144:
145:
146: # undef FSCALE
147: # endif
148:
149:
150: # ifdef __GNU__
151: # undef BSD
152: # undef FSCALE
153: # endif
154:
155:
156:
157:
158:
159:
160:
161: # if defined (HPUX) && !defined (hpux)
162: # define hpux
163: # endif
164:
165: # if defined (__hpux) && !defined (hpux)
166: # define hpux
167: # endif
168:
169: # if defined (__sun) && !defined (sun)
170: # define sun
171: # endif
172:
173: # if defined(hp300) && !defined(hpux)
174: # define MORE_BSD
175: # endif
176:
177: # if defined(ultrix) && defined(mips)
178: # define decstation
179: # endif
180:
181: # if defined (__SVR4) && !defined (SVR4)
182: # define SVR4
183: # endif
184:
185: # if (defined(sun) && defined(SVR4)) || defined (SOLARIS2)
186: # define SUNOS_5
187: # endif
188:
189: # if defined (__osf__) && (defined (__alpha) || defined (__alpha__))
190: # define OSF_ALPHA
191: # include <sys/mbuf.h>
192: # include <sys/socket.h>
193: # include <net/route.h>
194: # include <sys/table.h>
195: # endif
196:
197: # if defined (__osf__) && (defined (mips) || defined (__mips__))
198: # define OSF_MIPS
199: # include <sys/table.h>
200: # endif
201:
202:
203:
204:
205: # if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES)
206: # define tek4300
207: # endif
208:
209:
210:
211: # ifndef LOAD_AVE_TYPE
212:
213: # ifdef MORE_BSD
214: # define LOAD_AVE_TYPE long
215: # endif
216:
217: # ifdef sun
218: # define LOAD_AVE_TYPE long
219: # endif
220:
221: # ifdef decstation
222: # define LOAD_AVE_TYPE long
223: # endif
224:
225: # ifdef _SEQUENT_
226: # define LOAD_AVE_TYPE long
227: # endif
228:
229: # ifdef sgi
230: # define LOAD_AVE_TYPE long
231: # endif
232:
233: # ifdef SVR4
234: # define LOAD_AVE_TYPE long
235: # endif
236:
237: # ifdef sony_news
238: # define LOAD_AVE_TYPE long
239: # endif
240:
241: # ifdef sequent
242: # define LOAD_AVE_TYPE long
243: # endif
244:
245: # ifdef OSF_ALPHA
246: # define LOAD_AVE_TYPE long
247: # endif
248:
249: # if defined (ardent) && defined (titan)
250: # define LOAD_AVE_TYPE long
251: # endif
252:
253: # ifdef tek4300
254: # define LOAD_AVE_TYPE long
255: # endif
256:
257: # if defined(alliant) && defined(i860)
258: # define LOAD_AVE_TYPE long
259: # endif
260:
261: # ifdef _AIX
262: # define LOAD_AVE_TYPE long
263: # endif
264:
265: # ifdef convex
266: # define LOAD_AVE_TYPE double
267: # ifndef LDAV_CVT
268: # define LDAV_CVT(n) (n)
269: # endif
270: # endif
271:
272: # endif
273:
274: # ifdef OSF_ALPHA
275:
276:
277: # undef FSCALE
278: # define FSCALE 1024.0
279: # endif
280:
281: # if defined(alliant) && defined(i860)
282:
283:
284: # undef FSCALE
285: # define FSCALE 100.0
286: # endif
287:
288:
289: # ifndef FSCALE
290:
291:
292:
293: # ifdef MORE_BSD
294: # define FSCALE 2048.0
295: # endif
296:
297: # if defined(MIPS) || defined(SVR4) || defined(decstation)
298: # define FSCALE 256
299: # endif
300:
301: # if defined (sgi) || defined (sequent)
302:
303:
304: # undef FSCALE
305: # define FSCALE 1000.0
306: # endif
307:
308: # if defined (ardent) && defined (titan)
309: # define FSCALE 65536.0
310: # endif
311:
312: # ifdef tek4300
313: # define FSCALE 100.0
314: # endif
315:
316: # ifdef _AIX
317: # define FSCALE 65536.0
318: # endif
319:
320: # endif
321:
322: # if !defined (LDAV_CVT) && defined (FSCALE)
323: # define LDAV_CVT(n) (((double) (n)) / FSCALE)
324: # endif
325:
326: # ifndef NLIST_STRUCT
327: # if HAVE_NLIST_H
328: # define NLIST_STRUCT
329: # endif
330: # endif
331:
332: # if defined(sgi) || (defined(mips) && !defined(BSD))
333: # define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31))
334: # endif
335:
336:
337: # if !defined (KERNEL_FILE) && defined (sequent)
338: # define KERNEL_FILE "/dynix"
339: # endif
340:
341: # if !defined (KERNEL_FILE) && defined (hpux)
342: # define KERNEL_FILE "/hp-ux"
343: # endif
344:
345: # if !defined(KERNEL_FILE) && (defined(_SEQUENT_) || defined(MIPS) || defined(SVR4) || defined(ISC) || defined (sgi) || (defined (ardent) && defined (titan)))
346: # define KERNEL_FILE "/unix"
347: # endif
348:
349:
350: # if !defined (LDAV_SYMBOL) && defined (alliant)
351: # define LDAV_SYMBOL "_Loadavg"
352: # endif
353:
354: # if !defined(LDAV_SYMBOL) && ((defined(hpux) && !defined(hp9000s300)) || defined(_SEQUENT_) || defined(SVR4) || defined(ISC) || defined(sgi) || (defined (ardent) && defined (titan)) || defined (_AIX))
355: # define LDAV_SYMBOL "avenrun"
356: # endif
357:
358: # ifdef HAVE_UNISTD_H
359: # include <unistd.h>
360: # endif
361:
362: # include <stdio.h>
363:
364:
365:
366: # if !defined(LOAD_AVE_TYPE) && (defined(BSD) || defined(LDAV_CVT) || defined(KERNEL_FILE) || defined(LDAV_SYMBOL))
367: # define LOAD_AVE_TYPE double
368: # endif
369:
370: # ifdef LOAD_AVE_TYPE
371:
372: # ifndef VMS
373: # ifndef __linux__
374: # ifndef NLIST_STRUCT
375: # include <a.out.h>
376: # else
377: # include <nlist.h>
378: # endif
379:
380: # ifdef SUNOS_5
381: # include <fcntl.h>
382: # include <kvm.h>
383: # include <kstat.h>
384: # endif
385:
386: # if defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC)
387: # include <sys/pstat.h>
388: # endif
389:
390: # ifndef KERNEL_FILE
391: # define KERNEL_FILE "/vmunix"
392: # endif
393:
394: # ifndef LDAV_SYMBOL
395: # define LDAV_SYMBOL "_avenrun"
396: # endif
397: # endif
398:
399: # else
400:
401: # ifndef eunice
402: # include <iodef.h>
403: # include <descrip.h>
404: # else
405: # include <vms/iodef.h>
406: # endif
407: # endif
408:
409: # ifndef LDAV_CVT
410: # define LDAV_CVT(n) ((double) (n))
411: # endif
412:
413: # endif
414:
415: # if defined(__GNU__) && !defined (NeXT)
416:
417:
418:
419: # define NeXT
420: # define host_self mach_host_self
421: # endif
422:
423: # ifdef NeXT
424: # ifdef HAVE_MACH_MACH_H
425: # include <mach/mach.h>
426: # else
427: # include <mach.h>
428: # endif
429: # endif
430:
431: # ifdef sgi
432: # include <sys/sysmp.h>
433: # endif
434:
435: # ifdef UMAX
436: # include <stdio.h>
437: # include <signal.h>
438: # include <sys/time.h>
439: # include <sys/wait.h>
440: # include <sys/syscall.h>
441:
442: # ifdef UMAX_43
443: # include <machine/cpu.h>
444: # include <inq_stats/statistics.h>
445: # include <inq_stats/sysstats.h>
446: # include <inq_stats/cpustats.h>
447: # include <inq_stats/procstats.h>
448: # else
449: # include <sys/sysdefs.h>
450: # include <sys/statistics.h>
451: # include <sys/sysstats.h>
452: # include <sys/cpudefs.h>
453: # include <sys/cpustats.h>
454: # include <sys/procstats.h>
455: # endif
456: # endif
457:
458: # ifdef DGUX
459: # include <sys/dg_sys_info.h>
460: # endif
461:
462: # if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION)
463: # include <fcntl.h>
464: # else
465: # include <sys/file.h>
466: # endif
467: ^L
468:
469:
470: # ifdef NeXT
471: static processor_set_t default_set;
472: static int getloadavg_initialized;
473: # endif
474:
475: # ifdef UMAX
476: static unsigned int cpus = 0;
477: static unsigned int samples;
478: # endif
479:
480: # ifdef DGUX
481: static struct dg_sys_info_load_info load_info;
482: # endif
483:
484: #if !defined(HAVE_LIBKSTAT) && defined(LOAD_AVE_TYPE)
485:
486: static int channel;
487:
488: static int getloadavg_initialized;
489:
490: static long offset;
491:
492: # if !defined(VMS) && !defined(sgi) && !defined(__linux__)
493: static struct nlist nl[2];
494: # endif
495:
496: # ifdef SUNOS_5
497: static kvm_t *kd;
498: # endif
499:
500: #endif
501: ^L
502:
503:
504:
505:
506:
507: int
508: getloadavg (loadavg, nelem)
509: double loadavg[];
510: int nelem;
511: {
512: int elem = 0;
513:
514: # ifdef NO_GET_LOAD_AVG
515: # define LDAV_DONE
516:
517:
518: errno = 0;
519: elem = -1;
520: # endif
521:
522: # if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT)
523:
524: # define LDAV_DONE
525: kstat_ctl_t *kc;
526: kstat_t *ksp;
527: kstat_named_t *kn;
528:
529: kc = <