Mercurial > emacs
annotate src/getloadavg.c @ 16740:202689a911b7
(set_point): Use virtual bounds, not real bounds,
in the abort test for POSITION.
Skip the intangibility test if POSITION is at either end of buffer.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 20 Dec 1996 18:15:52 +0000 |
parents | 79ff1c263f5d |
children | 16ef2bd09de7 |
rev | line source |
---|---|
2928 | 1 /* Get the system load averages. |
10363 | 2 Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995 |
2928 | 3 Free Software Foundation, Inc. |
4 | |
5 This program is free software; you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 2, or (at your option) | |
8 any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
14457 | 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18 USA. */ | |
2928 | 19 |
20 /* Compile-time symbols that this file uses: | |
21 | |
22 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. | |
23 KERNEL_FILE Pathname of the kernel to nlist. | |
24 LDAV_CVT() Scale the load average from the kernel. | |
25 Returns a double. | |
26 LDAV_SYMBOL Name of kernel symbol giving load average. | |
27 LOAD_AVE_TYPE Type of the load average array in the kernel. | |
28 Must be defined unless one of | |
29 apollo, DGUX, NeXT, or UMAX is defined; | |
30 otherwise, no load average is available. | |
31 NLIST_STRUCT Include nlist.h, not a.out.h, and | |
32 the nlist n_name element is a pointer, | |
33 not an array. | |
34 NLIST_NAME_UNION struct nlist has an n_un member, not n_name. | |
4349 | 35 LINUX_LDAV_FILE [__linux__]: File containing load averages. |
2928 | 36 |
37 Specific system predefines this file uses, aside from setting | |
38 default values if not emacs: | |
39 | |
40 apollo | |
41 BSD Real BSD, not just BSD-like. | |
12332
443ebb2a278a
[convex] (LOAD_AVE_TYPE, LDAV_CVT): Define to double, no conversion.
Roland McGrath <roland@gnu.org>
parents:
11788
diff
changeset
|
42 convex |
2928 | 43 DGUX |
44 eunice UNIX emulator under VMS. | |
45 hpux | |
15281
dd275783c873
[WIN32]: No-op as for [MSDOS].
Roland McGrath <roland@gnu.org>
parents:
14457
diff
changeset
|
46 MSDOS No-op for MSDOS. |
2928 | 47 NeXT |
48 sgi | |
49 sequent Sequent Dynix 3.x.x (BSD) | |
50 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV) | |
51 sony_news NEWS-OS (works at least for 4.1C) | |
52 UMAX | |
53 UMAX4_3 | |
54 VMS | |
15281
dd275783c873
[WIN32]: No-op as for [MSDOS].
Roland McGrath <roland@gnu.org>
parents:
14457
diff
changeset
|
55 WIN32 No-op for Windows95/NT. |
4349 | 56 __linux__ Linux: assumes /proc filesystem mounted. |
2928 | 57 Support from Michael K. Johnson. |
4807 | 58 __NetBSD__ NetBSD: assumes /kern filesystem mounted. |
2928 | 59 |
60 In addition, to avoid nesting many #ifdefs, we internally set | |
61 LDAV_DONE to indicate that the load average has been computed. | |
62 | |
63 We also #define LDAV_PRIVILEGED if a program will require | |
64 special installation to be able to call getloadavg. */ | |
65 | |
10363 | 66 /* This should always be first. */ |
67 #ifdef HAVE_CONFIG_H | |
68 #include <config.h> | |
69 #endif | |
70 | |
2928 | 71 #include <sys/types.h> |
72 | |
73 /* Both the Emacs and non-Emacs sections want this. Some | |
74 configuration files' definitions for the LOAD_AVE_CVT macro (like | |
75 sparc.h's) use macros like FSCALE, defined here. */ | |
76 #ifdef unix | |
77 #include <sys/param.h> | |
78 #endif | |
79 | |
80 | |
7784
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
81 /* Exclude all the code except the test program at the end |
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
82 if the system has its own `getloadavg' function. |
4409 | 83 |
7784
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
84 The declaration of `errno' is needed by the test program |
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
85 as well as the function itself, so it comes first. */ |
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
86 |
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
87 #include <errno.h> |
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
88 |
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
89 #ifndef errno |
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
90 extern int errno; |
fd03010db0c6
Put #include of errno.h and decl of errno before #ifndef HAVE_GETLOADAVG.
Roland McGrath <roland@gnu.org>
parents:
4907
diff
changeset
|
91 #endif |
4409 | 92 |
93 #ifndef HAVE_GETLOADAVG | |
94 | |
95 | |
2928 | 96 /* The existing Emacs configuration files define a macro called |
97 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and | |
98 returns the load average multiplied by 100. What we actually want | |
99 is a macro called LDAV_CVT, which returns the load average as an | |
100 unmultiplied double. | |
101 | |
102 For backwards compatibility, we'll define LDAV_CVT in terms of | |
103 LOAD_AVE_CVT, but future machine config files should just define | |
104 LDAV_CVT directly. */ | |
105 | |
106 #if !defined(LDAV_CVT) && defined(LOAD_AVE_CVT) | |
107 #define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0) | |
108 #endif | |
109 | |
110 #if !defined (BSD) && defined (ultrix) | |
111 /* Ultrix behaves like BSD on Vaxen. */ | |
112 #define BSD | |
113 #endif | |
114 | |
115 #ifdef NeXT | |
116 /* NeXT in the 2.{0,1,2} releases defines BSD in <sys/param.h>, which | |
117 conflicts with the definition understood in this file, that this | |
118 really is BSD. */ | |
119 #undef BSD | |
120 | |
121 /* NeXT defines FSCALE in <sys/param.h>. However, we take FSCALE being | |
122 defined to mean that the nlist method should be used, which is not true. */ | |
123 #undef FSCALE | |
124 #endif | |
125 | |
126 /* Set values that are different from the defaults, which are | |
127 set a little farther down with #ifndef. */ | |
128 | |
129 | |
130 /* Some shorthands. */ | |
131 | |
132 #if defined (HPUX) && !defined (hpux) | |
133 #define hpux | |
134 #endif | |
135 | |
16413
79ff1c263f5d
[__hpux]: Define hpux. From Eric Backus.
Jim Meyering <jim@meyering.net>
parents:
16151
diff
changeset
|
136 #if defined (__hpux) && !defined (hpux) |
79ff1c263f5d
[__hpux]: Define hpux. From Eric Backus.
Jim Meyering <jim@meyering.net>
parents:
16151
diff
changeset
|
137 #define hpux |
79ff1c263f5d
[__hpux]: Define hpux. From Eric Backus.
Jim Meyering <jim@meyering.net>
parents:
16151
diff
changeset
|
138 #endif |
79ff1c263f5d
[__hpux]: Define hpux. From Eric Backus.
Jim Meyering <jim@meyering.net>
parents:
16151
diff
changeset
|
139 |
79ff1c263f5d
[__hpux]: Define hpux. From Eric Backus.
Jim Meyering <jim@meyering.net>
parents:
16151
diff
changeset
|
140 #if defined (__sun) && !defined (sun) |
79ff1c263f5d
[__hpux]: Define hpux. From Eric Backus.
Jim Meyering <jim@meyering.net>
parents:
16151
diff
changeset
|
141 #define sun |
79ff1c263f5d
[__hpux]: Define hpux. From Eric Backus.
Jim Meyering <jim@meyering.net>
parents:
16151
diff
changeset
|
142 #endif |
79ff1c263f5d
[__hpux]: Define hpux. From Eric Backus.
Jim Meyering <jim@meyering.net>
parents:
16151
diff
changeset
|
143 |
2928 | 144 #if defined(hp300) && !defined(hpux) |
145 #define MORE_BSD | |
146 #endif | |
147 | |
148 #if defined(ultrix) && defined(mips) | |
149 #define decstation | |
150 #endif | |
151 | |
15294 | 152 #if (defined(sun) && defined(SVR4)) || defined (SOLARIS2) |
2928 | 153 #define SUNOS_5 |
154 #endif | |
155 | |
4296 | 156 #if defined (__osf__) && (defined (__alpha) || defined (__alpha__)) |
2928 | 157 #define OSF_ALPHA |
8816
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
158 #include <sys/table.h> |
2928 | 159 #endif |
160 | |
161 #if defined (__osf__) && (defined (mips) || defined (__mips__)) | |
162 #define OSF_MIPS | |
163 #include <sys/table.h> | |
164 #endif | |
165 | |
166 /* UTek's /bin/cc on the 4300 has no architecture specific cpp define by | |
167 default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine | |
168 that with a couple of other things and we'll have a unique match. */ | |
169 #if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES) | |
170 #define tek4300 /* Define by emacs, but not by other users. */ | |
171 #endif | |
172 | |
173 | |
3587 | 174 /* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */ |
3597 | 175 #ifndef LOAD_AVE_TYPE |
176 | |
3587 | 177 #ifdef MORE_BSD |
178 #define LOAD_AVE_TYPE long | |
179 #endif | |
180 | |
181 #ifdef sun | |
182 #define LOAD_AVE_TYPE long | |
183 #endif | |
184 | |
185 #ifdef decstation | |
186 #define LOAD_AVE_TYPE long | |
187 #endif | |
188 | |
189 #ifdef _SEQUENT_ | |
190 #define LOAD_AVE_TYPE long | |
191 #endif | |
192 | |
193 #ifdef sgi | |
194 #define LOAD_AVE_TYPE long | |
195 #endif | |
196 | |
197 #ifdef SVR4 | |
198 #define LOAD_AVE_TYPE long | |
199 #endif | |
200 | |
201 #ifdef sony_news | |
202 #define LOAD_AVE_TYPE long | |
203 #endif | |
204 | |
205 #ifdef sequent | |
206 #define LOAD_AVE_TYPE long | |
207 #endif | |
208 | |
209 #ifdef OSF_ALPHA | |
210 #define LOAD_AVE_TYPE long | |
211 #endif | |
212 | |
3597 | 213 #if defined (ardent) && defined (titan) |
3587 | 214 #define LOAD_AVE_TYPE long |
215 #endif | |
216 | |
3597 | 217 #ifdef tek4300 |
2928 | 218 #define LOAD_AVE_TYPE long |
219 #endif | |
220 | |
9172
393a55341859
[alliant && i860] (LOAD_AVE_TYPE, FSCALE, NLIST_STRUCT): Define.
Roland McGrath <roland@gnu.org>
parents:
9096
diff
changeset
|
221 #if defined(alliant) && defined(i860) /* Alliant FX/2800 */ |
393a55341859
[alliant && i860] (LOAD_AVE_TYPE, FSCALE, NLIST_STRUCT): Define.
Roland McGrath <roland@gnu.org>
parents:
9096
diff
changeset
|
222 #define LOAD_AVE_TYPE long |
393a55341859
[alliant && i860] (LOAD_AVE_TYPE, FSCALE, NLIST_STRUCT): Define.
Roland McGrath <roland@gnu.org>
parents:
9096
diff
changeset
|
223 #endif |
393a55341859
[alliant && i860] (LOAD_AVE_TYPE, FSCALE, NLIST_STRUCT): Define.
Roland McGrath <roland@gnu.org>
parents:
9096
diff
changeset
|
224 |
11788
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
225 #ifdef _AIX |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
226 #define LOAD_AVE_TYPE long |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
227 #endif |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
228 |
12332
443ebb2a278a
[convex] (LOAD_AVE_TYPE, LDAV_CVT): Define to double, no conversion.
Roland McGrath <roland@gnu.org>
parents:
11788
diff
changeset
|
229 #ifdef convex |
443ebb2a278a
[convex] (LOAD_AVE_TYPE, LDAV_CVT): Define to double, no conversion.
Roland McGrath <roland@gnu.org>
parents:
11788
diff
changeset
|
230 #define LOAD_AVE_TYPE double |
443ebb2a278a
[convex] (LOAD_AVE_TYPE, LDAV_CVT): Define to double, no conversion.
Roland McGrath <roland@gnu.org>
parents:
11788
diff
changeset
|
231 #ifndef LDAV_CVT |
443ebb2a278a
[convex] (LOAD_AVE_TYPE, LDAV_CVT): Define to double, no conversion.
Roland McGrath <roland@gnu.org>
parents:
11788
diff
changeset
|
232 #define LDAV_CVT(n) (n) |
443ebb2a278a
[convex] (LOAD_AVE_TYPE, LDAV_CVT): Define to double, no conversion.
Roland McGrath <roland@gnu.org>
parents:
11788
diff
changeset
|
233 #endif |
443ebb2a278a
[convex] (LOAD_AVE_TYPE, LDAV_CVT): Define to double, no conversion.
Roland McGrath <roland@gnu.org>
parents:
11788
diff
changeset
|
234 #endif |
443ebb2a278a
[convex] (LOAD_AVE_TYPE, LDAV_CVT): Define to double, no conversion.
Roland McGrath <roland@gnu.org>
parents:
11788
diff
changeset
|
235 |
3597 | 236 #endif /* No LOAD_AVE_TYPE. */ |
2928 | 237 |
4422 | 238 #ifdef OSF_ALPHA |
239 /* <sys/param.h> defines an incorrect value for FSCALE on Alpha OSF/1, | |
240 according to ghazi@noc.rutgers.edu. */ | |
241 #undef FSCALE | |
242 #define FSCALE 1024.0 | |
243 #endif | |
244 | |
9723
ba541f60aa46
[alliant && i860] (FSCALE): Move defn before #ifndef FSCALE.
Roland McGrath <roland@gnu.org>
parents:
9172
diff
changeset
|
245 #if defined(alliant) && defined(i860) /* Alliant FX/2800 */ |
ba541f60aa46
[alliant && i860] (FSCALE): Move defn before #ifndef FSCALE.
Roland McGrath <roland@gnu.org>
parents:
9172
diff
changeset
|
246 /* <sys/param.h> defines an incorrect value for FSCALE on an |
ba541f60aa46
[alliant && i860] (FSCALE): Move defn before #ifndef FSCALE.
Roland McGrath <roland@gnu.org>
parents:
9172
diff
changeset
|
247 Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu. */ |
ba541f60aa46
[alliant && i860] (FSCALE): Move defn before #ifndef FSCALE.
Roland McGrath <roland@gnu.org>
parents:
9172
diff
changeset
|
248 #undef FSCALE |
ba541f60aa46
[alliant && i860] (FSCALE): Move defn before #ifndef FSCALE.
Roland McGrath <roland@gnu.org>
parents:
9172
diff
changeset
|
249 #define FSCALE 100.0 |
ba541f60aa46
[alliant && i860] (FSCALE): Move defn before #ifndef FSCALE.
Roland McGrath <roland@gnu.org>
parents:
9172
diff
changeset
|
250 #endif |
ba541f60aa46
[alliant && i860] (FSCALE): Move defn before #ifndef FSCALE.
Roland McGrath <roland@gnu.org>
parents:
9172
diff
changeset
|
251 |
4422 | 252 |
2928 | 253 #ifndef FSCALE |
254 | |
255 /* SunOS and some others define FSCALE in sys/param.h. */ | |
256 | |
257 #ifdef MORE_BSD | |
258 #define FSCALE 2048.0 | |
259 #endif | |
260 | |
261 #if defined(MIPS) || defined(SVR4) || defined(decstation) | |
262 #define FSCALE 256 | |
263 #endif | |
264 | |
265 #if defined (sgi) || defined (sequent) | |
4288 | 266 /* Sometimes both MIPS and sgi are defined, so FSCALE was just defined |
267 above under #ifdef MIPS. But we want the sgi value. */ | |
268 #undef FSCALE | |
2928 | 269 #define FSCALE 1000.0 |
270 #endif | |
271 | |
272 #if defined (ardent) && defined (titan) | |
273 #define FSCALE 65536.0 | |
274 #endif | |
275 | |
276 #ifdef tek4300 | |
277 #define FSCALE 100.0 | |
278 #endif | |
279 | |
11788
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
280 #ifdef _AIX |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
281 #define FSCALE 65536.0 |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
282 #endif |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
283 |
2928 | 284 #endif /* Not FSCALE. */ |
285 | |
286 #if !defined (LDAV_CVT) && defined (FSCALE) | |
287 #define LDAV_CVT(n) (((double) (n)) / FSCALE) | |
288 #endif | |
289 | |
3587 | 290 /* VAX C can't handle multi-line #ifs, or lines longer that 256 characters. */ |
291 #ifndef NLIST_STRUCT | |
292 | |
293 #ifdef MORE_BSD | |
294 #define NLIST_STRUCT | |
295 #endif | |
296 | |
297 #ifdef sun | |
298 #define NLIST_STRUCT | |
299 #endif | |
300 | |
301 #ifdef decstation | |
302 #define NLIST_STRUCT | |
303 #endif | |
304 | |
305 #ifdef hpux | |
306 #define NLIST_STRUCT | |
307 #endif | |
308 | |
309 #if defined (_SEQUENT_) || defined (sequent) | |
310 #define NLIST_STRUCT | |
311 #endif | |
312 | |
313 #ifdef sgi | |
2928 | 314 #define NLIST_STRUCT |
315 #endif | |
316 | |
3587 | 317 #ifdef SVR4 |
318 #define NLIST_STRUCT | |
319 #endif | |
320 | |
321 #ifdef sony_news | |
322 #define NLIST_STRUCT | |
323 #endif | |
324 | |
325 #ifdef OSF_ALPHA | |
326 #define NLIST_STRUCT | |
327 #endif | |
328 | |
329 #if defined (ardent) && defined (titan) | |
330 #define NLIST_STRUCT | |
331 #endif | |
332 | |
9172
393a55341859
[alliant && i860] (LOAD_AVE_TYPE, FSCALE, NLIST_STRUCT): Define.
Roland McGrath <roland@gnu.org>
parents:
9096
diff
changeset
|
333 #ifdef tek4300 |
3587 | 334 #define NLIST_STRUCT |
335 #endif | |
336 | |
337 #ifdef butterfly | |
338 #define NLIST_STRUCT | |
339 #endif | |
340 | |
9172
393a55341859
[alliant && i860] (LOAD_AVE_TYPE, FSCALE, NLIST_STRUCT): Define.
Roland McGrath <roland@gnu.org>
parents:
9096
diff
changeset
|
341 #if defined(alliant) && defined(i860) /* Alliant FX/2800 */ |
393a55341859
[alliant && i860] (LOAD_AVE_TYPE, FSCALE, NLIST_STRUCT): Define.
Roland McGrath <roland@gnu.org>
parents:
9096
diff
changeset
|
342 #define NLIST_STRUCT |
393a55341859
[alliant && i860] (LOAD_AVE_TYPE, FSCALE, NLIST_STRUCT): Define.
Roland McGrath <roland@gnu.org>
parents:
9096
diff
changeset
|
343 #endif |
393a55341859
[alliant && i860] (LOAD_AVE_TYPE, FSCALE, NLIST_STRUCT): Define.
Roland McGrath <roland@gnu.org>
parents:
9096
diff
changeset
|
344 |
11788
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
345 #ifdef _AIX |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
346 #define NLIST_STRUCT |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
347 #endif |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
348 |
3587 | 349 #endif /* defined (NLIST_STRUCT) */ |
350 | |
2928 | 351 |
352 #if defined(sgi) || (defined(mips) && !defined(BSD)) | |
353 #define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31)) | |
354 #endif | |
355 | |
356 | |
357 #if !defined (KERNEL_FILE) && defined (sequent) | |
358 #define KERNEL_FILE "/dynix" | |
359 #endif | |
360 | |
361 #if !defined (KERNEL_FILE) && defined (hpux) | |
362 #define KERNEL_FILE "/hp-ux" | |
363 #endif | |
364 | |
365 #if !defined(KERNEL_FILE) && (defined(_SEQUENT_) || defined(MIPS) || defined(SVR4) || defined(ISC) || defined (sgi) || defined(SVR4) || (defined (ardent) && defined (titan))) | |
366 #define KERNEL_FILE "/unix" | |
367 #endif | |
368 | |
369 | |
370 #if !defined (LDAV_SYMBOL) && defined (alliant) | |
371 #define LDAV_SYMBOL "_Loadavg" | |
372 #endif | |
373 | |
11788
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
374 #if !defined(LDAV_SYMBOL) && ((defined(hpux) && !defined(hp9000s300)) || defined(_SEQUENT_) || defined(SVR4) || defined(ISC) || defined(sgi) || (defined (ardent) && defined (titan)) || defined (_AIX)) |
2928 | 375 #define LDAV_SYMBOL "avenrun" |
376 #endif | |
377 | |
378 #ifdef HAVE_UNISTD_H | |
379 #include <unistd.h> | |
380 #endif | |
381 | |
382 #include <stdio.h> | |
383 | |
384 /* LOAD_AVE_TYPE should only get defined if we're going to use the | |
385 nlist method. */ | |
386 #if !defined(LOAD_AVE_TYPE) && (defined(BSD) || defined(LDAV_CVT) || defined(KERNEL_FILE) || defined(LDAV_SYMBOL)) | |
387 #define LOAD_AVE_TYPE double | |
388 #endif | |
389 | |
390 #ifdef LOAD_AVE_TYPE | |
391 | |
392 #ifndef VMS | |
393 #ifndef NLIST_STRUCT | |
394 #include <a.out.h> | |
395 #else /* NLIST_STRUCT */ | |
396 #include <nlist.h> | |
397 #endif /* NLIST_STRUCT */ | |
398 | |
399 #ifdef SUNOS_5 | |
400 #include <fcntl.h> | |
401 #include <kvm.h> | |
16151
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
402 #include <kstat.h> |
2928 | 403 #endif |
404 | |
405 #ifndef KERNEL_FILE | |
406 #define KERNEL_FILE "/vmunix" | |
407 #endif /* KERNEL_FILE */ | |
408 | |
409 #ifndef LDAV_SYMBOL | |
410 #define LDAV_SYMBOL "_avenrun" | |
411 #endif /* LDAV_SYMBOL */ | |
412 | |
413 #else /* VMS */ | |
414 | |
415 #ifndef eunice | |
416 #include <iodef.h> | |
417 #include <descrip.h> | |
418 #else /* eunice */ | |
419 #include <vms/iodef.h> | |
420 #endif /* eunice */ | |
421 #endif /* VMS */ | |
422 | |
423 #ifndef LDAV_CVT | |
424 #define LDAV_CVT(n) ((double) (n)) | |
425 #endif /* !LDAV_CVT */ | |
426 | |
427 #endif /* LOAD_AVE_TYPE */ | |
428 | |
429 #ifdef NeXT | |
430 #ifdef HAVE_MACH_MACH_H | |
431 #include <mach/mach.h> | |
432 #else | |
433 #include <mach.h> | |
434 #endif | |
435 #endif /* NeXT */ | |
436 | |
437 #ifdef sgi | |
438 #include <sys/sysmp.h> | |
439 #endif /* sgi */ | |
440 | |
441 #ifdef UMAX | |
442 #include <stdio.h> | |
443 #include <signal.h> | |
444 #include <sys/time.h> | |
445 #include <sys/wait.h> | |
446 #include <sys/syscall.h> | |
447 | |
448 #ifdef UMAX_43 | |
449 #include <machine/cpu.h> | |
450 #include <inq_stats/statistics.h> | |
451 #include <inq_stats/sysstats.h> | |
452 #include <inq_stats/cpustats.h> | |
453 #include <inq_stats/procstats.h> | |
454 #else /* Not UMAX_43. */ | |
455 #include <sys/sysdefs.h> | |
456 #include <sys/statistics.h> | |
457 #include <sys/sysstats.h> | |
458 #include <sys/cpudefs.h> | |
459 #include <sys/cpustats.h> | |
460 #include <sys/procstats.h> | |
461 #endif /* Not UMAX_43. */ | |
462 #endif /* UMAX */ | |
463 | |
464 #ifdef DGUX | |
465 #include <sys/dg_sys_info.h> | |
466 #endif | |
467 | |
468 #if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION) | |
469 #include <fcntl.h> | |
470 #else | |
471 #include <sys/file.h> | |
472 #endif | |
473 | |
474 /* Avoid static vars inside a function since in HPUX they dump as pure. */ | |
475 | |
476 #ifdef NeXT | |
477 static processor_set_t default_set; | |
478 static int getloadavg_initialized; | |
479 #endif /* NeXT */ | |
480 | |
481 #ifdef UMAX | |
482 static unsigned int cpus = 0; | |
483 static unsigned int samples; | |
484 #endif /* UMAX */ | |
485 | |
486 #ifdef DGUX | |
487 static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ | |
488 #endif /* DGUX */ | |
489 | |
490 #ifdef LOAD_AVE_TYPE | |
491 /* File descriptor open to /dev/kmem or VMS load ave driver. */ | |
492 static int channel; | |
493 /* Nonzero iff channel is valid. */ | |
494 static int getloadavg_initialized; | |
495 /* Offset in kmem to seek to read load average, or 0 means invalid. */ | |
496 static long offset; | |
497 | |
498 #if !defined(VMS) && !defined(sgi) | |
499 static struct nlist nl[2]; | |
500 #endif /* Not VMS or sgi */ | |
501 | |
502 #ifdef SUNOS_5 | |
503 static kvm_t *kd; | |
504 #endif /* SUNOS_5 */ | |
505 | |
506 #endif /* LOAD_AVE_TYPE */ | |
507 | |
508 /* Put the 1 minute, 5 minute and 15 minute load averages | |
509 into the first NELEM elements of LOADAVG. | |
4064
d14ba65a1363
*** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents:
4011
diff
changeset
|
510 Return the number written (never more than 3, but may be less than NELEM), |
2928 | 511 or -1 if an error occurred. */ |
512 | |
513 int | |
514 getloadavg (loadavg, nelem) | |
515 double loadavg[]; | |
516 int nelem; | |
517 { | |
518 int elem = 0; /* Return value. */ | |
519 | |
3037 | 520 #ifdef NO_GET_LOAD_AVG |
521 #define LDAV_DONE | |
522 /* Set errno to zero to indicate that there was no particular error; | |
523 this function just can't work at all on this system. */ | |
524 errno = 0; | |
525 elem = -1; | |
526 #endif | |
527 | |
16151
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
528 #if !defined (LDAV_DONE) && defined (SUNOS_5) |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
529 /* Use libkstat because we don't have to be root. */ |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
530 #define LDAV_DONE |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
531 kstat_ctl_t *kc; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
532 kstat_t *ksp; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
533 kstat_named_t *kn; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
534 |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
535 kc = kstat_open (); |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
536 if (kc == 0) return -1; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
537 ksp = kstat_lookup (kc, "unix", 0, "system_misc"); |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
538 if (ksp == 0 ) return -1; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
539 if (kstat_read (kc, ksp, 0) == -1) return -1; |
16413
79ff1c263f5d
[__hpux]: Define hpux. From Eric Backus.
Jim Meyering <jim@meyering.net>
parents:
16151
diff
changeset
|
540 |
16151
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
541 |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
542 kn = kstat_data_lookup (ksp, "avenrun_1min"); |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
543 if (kn == 0) |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
544 { |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
545 /* Return -1 if no load average information is available. */ |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
546 nelem = 0; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
547 elem = -1; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
548 } |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
549 |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
550 if (nelem >= 1) |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
551 loadavg[elem++] = (double) kn->value.ul/FSCALE; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
552 |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
553 if (nelem >= 2) |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
554 { |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
555 kn = kstat_data_lookup (ksp, "avenrun_5min"); |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
556 if (kn != 0) |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
557 { |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
558 loadavg[elem++] = (double) kn->value.ul/FSCALE; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
559 |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
560 if (nelem >= 3) |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
561 { |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
562 kn = kstat_data_lookup (ksp, "avenrun_15min"); |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
563 if (kn != 0) |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
564 loadavg[elem++] = (double) kn->value.ul/FSCALE; |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
565 } |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
566 } |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
567 } |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
568 |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
569 kstat_close (kc); |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
570 #endif /* SUNOS_5 */ |
481c5be39150
(getloadavg): Add new code for SUNOS_5 to use -lkstat.
Richard M. Stallman <rms@gnu.org>
parents:
15294
diff
changeset
|
571 |
4349 | 572 #if !defined (LDAV_DONE) && defined (__linux__) |
2928 | 573 #define LDAV_DONE |
574 #undef LOAD_AVE_TYPE | |
575 | |
576 #ifndef LINUX_LDAV_FILE | |
577 #define LINUX_LDAV_FILE "/proc/loadavg" | |
578 #endif | |
579 | |
580 char ldavgbuf[40]; | |
581 double load_ave[3]; | |
582 int fd, count; | |
583 | |
584 fd = open (LINUX_LDAV_FILE, O_RDONLY); | |
585 if (fd == -1) | |
586 return -1; | |
587 count = read (fd, ldavgbuf, 40); | |
588 (void) close (fd); | |
589 if (count <= 0) | |
590 return -1; | |
591 | |
592 count = sscanf (ldavgbuf, "%lf %lf %lf", | |
593 &load_ave[0], &load_ave[1], &load_ave[2]); | |
594 if (count < 1) | |
595 return -1; | |
596 | |
597 for (elem = 0; elem < nelem && elem < count; elem++) | |
598 loadavg[elem] = load_ave[elem]; | |
599 | |
600 return elem; | |
601 | |
4349 | 602 #endif /* __linux__ */ |
2928 | 603 |
4807 | 604 #if !defined (LDAV_DONE) && defined (__NetBSD__) |
605 #define LDAV_DONE | |
606 #undef LOAD_AVE_TYPE | |
607 | |
608 #ifndef NETBSD_LDAV_FILE | |
609 #define NETBSD_LDAV_FILE "/kern/loadavg" | |
610 #endif | |
611 | |
612 unsigned long int load_ave[3], scale; | |
613 int count; | |
614 FILE *fp; | |
615 | |
4907 | 616 fp = fopen (NETBSD_LDAV_FILE, "r"); |
4807 | 617 if (fp == NULL) |
618 return -1; | |
619 count = fscanf (fp, "%lu %lu %lu %lu\n", | |
620 &load_ave[0], &load_ave[1], &load_ave[2], | |
621 &scale); | |
622 (void) fclose (fp); | |
623 if (count != 4) | |
624 return -1; | |
625 | |
626 for (elem = 0; elem < nelem; elem++) | |
627 loadavg[elem] = (double) load_ave[elem] / (double) scale; | |
628 | |
629 return elem; | |
630 | |
631 #endif /* __NetBSD__ */ | |
632 | |
2928 | 633 #if !defined (LDAV_DONE) && defined (NeXT) |
634 #define LDAV_DONE | |
635 /* The NeXT code was adapted from iscreen 3.2. */ | |
636 | |
637 host_t host; | |
638 struct processor_set_basic_info info; | |
639 unsigned info_count; | |
640 | |
4064
d14ba65a1363
*** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents:
4011
diff
changeset
|
641 /* We only know how to get the 1-minute average for this system, |
d14ba65a1363
*** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents:
4011
diff
changeset
|
642 so even if the caller asks for more than 1, we only return 1. */ |
2928 | 643 |
644 if (!getloadavg_initialized) | |
645 { | |
646 if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS) | |
647 getloadavg_initialized = 1; | |
648 } | |
649 | |
650 if (getloadavg_initialized) | |
651 { | |
652 info_count = PROCESSOR_SET_BASIC_INFO_COUNT; | |
653 if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, | |
654 (processor_set_info_t) &info, &info_count) | |
655 != KERN_SUCCESS) | |
656 getloadavg_initialized = 0; | |
657 else | |
658 { | |
659 if (nelem > 0) | |
660 loadavg[elem++] = (double) info.load_average / LOAD_SCALE; | |
661 } | |
662 } | |
663 | |
664 if (!getloadavg_initialized) | |
665 return -1; | |
666 #endif /* NeXT */ | |
667 | |
668 #if !defined (LDAV_DONE) && defined (UMAX) | |
669 #define LDAV_DONE | |
670 /* UMAX 4.2, which runs on the Encore Multimax multiprocessor, does not | |
671 have a /dev/kmem. Information about the workings of the running kernel | |
672 can be gathered with inq_stats system calls. | |
673 We only know how to get the 1-minute average for this system. */ | |
674 | |
675 struct proc_summary proc_sum_data; | |
676 struct stat_descr proc_info; | |
677 double load; | |
678 register unsigned int i, j; | |
679 | |
680 if (cpus == 0) | |
681 { | |
682 register unsigned int c, i; | |
683 struct cpu_config conf; | |
684 struct stat_descr desc; | |
685 | |
686 desc.sd_next = 0; | |
687 desc.sd_subsys = SUBSYS_CPU; | |
688 desc.sd_type = CPUTYPE_CONFIG; | |
689 desc.sd_addr = (char *) &conf; | |
690 desc.sd_size = sizeof conf; | |
691 | |
692 if (inq_stats (1, &desc)) | |
693 return -1; | |
694 | |
695 c = 0; | |
696 for (i = 0; i < conf.config_maxclass; ++i) | |
697 { | |
698 struct class_stats stats; | |
699 bzero ((char *) &stats, sizeof stats); | |
700 | |
701 desc.sd_type = CPUTYPE_CLASS; | |
702 desc.sd_objid = i; | |
703 desc.sd_addr = (char *) &stats; | |
704 desc.sd_size = sizeof stats; | |
705 | |
706 if (inq_stats (1, &desc)) | |
707 return -1; | |
708 | |
709 c += stats.class_numcpus; | |
710 } | |
711 cpus = c; | |
712 samples = cpus < 2 ? 3 : (2 * cpus / 3); | |
713 } | |
714 | |
715 proc_info.sd_next = 0; | |
716 proc_info.sd_subsys = SUBSYS_PROC; | |
717 proc_info.sd_type = PROCTYPE_SUMMARY; | |
718 proc_info.sd_addr = (char *) &proc_sum_data; | |
719 proc_info.sd_size = sizeof (struct proc_summary); | |
720 proc_info.sd_sizeused = 0; | |
721 | |
722 if (inq_stats (1, &proc_info) != 0) | |
723 return -1; | |
724 | |
725 load = proc_sum_data.ps_nrunnable; | |
726 j = 0; | |
727 for (i = samples - 1; i > 0; --i) | |
728 { | |
729 load += proc_sum_data.ps_nrun[j]; | |
730 if (j++ == PS_NRUNSIZE) | |
731 j = 0; | |
732 } | |
733 | |
734 if (nelem > 0) | |
735 loadavg[elem++] = load / samples / cpus; | |
736 #endif /* UMAX */ | |
737 | |
738 #if !defined (LDAV_DONE) && defined (DGUX) | |
739 #define LDAV_DONE | |
740 /* This call can return -1 for an error, but with good args | |
741 it's not supposed to fail. The first argument is for no | |
742 apparent reason of type `long int *'. */ | |
743 dg_sys_info ((long int *) &load_info, | |
744 DG_SYS_INFO_LOAD_INFO_TYPE, | |
745 DG_SYS_INFO_LOAD_VERSION_0); | |
746 | |
747 if (nelem > 0) | |
748 loadavg[elem++] = load_info.one_minute; | |
749 if (nelem > 1) | |
750 loadavg[elem++] = load_info.five_minute; | |
751 if (nelem > 2) | |
752 loadavg[elem++] = load_info.fifteen_minute; | |
753 #endif /* DGUX */ | |
754 | |
755 #if !defined (LDAV_DONE) && defined (apollo) | |
756 #define LDAV_DONE | |
757 /* Apollo code from lisch@mentorg.com (Ray Lischner). | |
758 | |
759 This system call is not documented. The load average is obtained as | |
760 three long integers, for the load average over the past minute, | |
761 five minutes, and fifteen minutes. Each value is a scaled integer, | |
762 with 16 bits of integer part and 16 bits of fraction part. | |
763 | |
764 I'm not sure which operating system first supported this system call, | |
765 but I know that SR10.2 supports it. */ | |
766 | |
767 extern void proc1_$get_loadav (); | |
768 unsigned long load_ave[3]; | |
769 | |
770 proc1_$get_loadav (load_ave); | |
771 | |
772 if (nelem > 0) | |
773 loadavg[elem++] = load_ave[0] / 65536.0; | |
774 if (nelem > 1) | |
775 loadavg[elem++] = load_ave[1] / 65536.0; | |
776 if (nelem > 2) | |
777 loadavg[elem++] = load_ave[2] / 65536.0; | |
778 #endif /* apollo */ | |
779 | |
780 #if !defined (LDAV_DONE) && defined (OSF_MIPS) | |
781 #define LDAV_DONE | |
782 | |
783 struct tbl_loadavg load_ave; | |
784 table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); | |
3037 | 785 loadavg[elem++] |
786 = (load_ave.tl_lscale == 0 | |
787 ? load_ave.tl_avenrun.d[0] | |
788 : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); | |
2928 | 789 #endif /* OSF_MIPS */ |
790 | |
15281
dd275783c873
[WIN32]: No-op as for [MSDOS].
Roland McGrath <roland@gnu.org>
parents:
14457
diff
changeset
|
791 #if !defined (LDAV_DONE) && (defined (MSDOS) || defined (WIN32)) |
13882
2631a29a614c
(getloadavg) [MSDOS]: Return 0 load instead of failing the call.
Richard M. Stallman <rms@gnu.org>
parents:
12799
diff
changeset
|
792 #define LDAV_DONE |
2631a29a614c
(getloadavg) [MSDOS]: Return 0 load instead of failing the call.
Richard M. Stallman <rms@gnu.org>
parents:
12799
diff
changeset
|
793 |
2631a29a614c
(getloadavg) [MSDOS]: Return 0 load instead of failing the call.
Richard M. Stallman <rms@gnu.org>
parents:
12799
diff
changeset
|
794 /* A faithful emulation is going to have to be saved for a rainy day. */ |
15281
dd275783c873
[WIN32]: No-op as for [MSDOS].
Roland McGrath <roland@gnu.org>
parents:
14457
diff
changeset
|
795 for ( ; elem < nelem; elem++) |
13882
2631a29a614c
(getloadavg) [MSDOS]: Return 0 load instead of failing the call.
Richard M. Stallman <rms@gnu.org>
parents:
12799
diff
changeset
|
796 { |
2631a29a614c
(getloadavg) [MSDOS]: Return 0 load instead of failing the call.
Richard M. Stallman <rms@gnu.org>
parents:
12799
diff
changeset
|
797 loadavg[elem] = 0.0; |
2631a29a614c
(getloadavg) [MSDOS]: Return 0 load instead of failing the call.
Richard M. Stallman <rms@gnu.org>
parents:
12799
diff
changeset
|
798 } |
2631a29a614c
(getloadavg) [MSDOS]: Return 0 load instead of failing the call.
Richard M. Stallman <rms@gnu.org>
parents:
12799
diff
changeset
|
799 #endif /* MSDOS */ |
2631a29a614c
(getloadavg) [MSDOS]: Return 0 load instead of failing the call.
Richard M. Stallman <rms@gnu.org>
parents:
12799
diff
changeset
|
800 |
8816
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
801 #if !defined (LDAV_DONE) && defined (OSF_ALPHA) |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
802 #define LDAV_DONE |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
803 |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
804 struct tbl_loadavg load_ave; |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
805 table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
806 for (elem = 0; elem < nelem; elem++) |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
807 loadavg[elem] |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
808 = (load_ave.tl_lscale == 0 |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
809 ? load_ave.tl_avenrun.d[elem] |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
810 : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
811 #endif /* OSF_ALPHA */ |
fbc29f1ddd08
(getloadavg): Add OSF_ALPHA support.
Richard M. Stallman <rms@gnu.org>
parents:
7784
diff
changeset
|
812 |
2928 | 813 #if !defined (LDAV_DONE) && defined (VMS) |
814 /* VMS specific code -- read from the Load Ave driver. */ | |
815 | |
816 LOAD_AVE_TYPE load_ave[3]; | |
817 static int getloadavg_initialized = 0; | |
818 #ifdef eunice | |
819 struct | |
820 { | |
821 int dsc$w_length; | |
822 char *dsc$a_pointer; | |
823 } descriptor; | |
824 #endif | |
825 | |
826 /* Ensure that there is a channel open to the load ave device. */ | |
827 if (!getloadavg_initialized) | |
828 { | |
829 /* Attempt to open the channel. */ | |
830 #ifdef eunice | |
831 descriptor.dsc$w_length = 18; | |
832 descriptor.dsc$a_pointer = "$$VMS_LOAD_AVERAGE"; | |
833 #else | |
834 $DESCRIPTOR (descriptor, "LAV0:"); | |
835 #endif | |
836 if (sys$assign (&descriptor, &channel, 0, 0) & 1) | |
837 getloadavg_initialized = 1; | |
838 } | |
839 | |
840 /* Read the load average vector. */ | |
841 if (getloadavg_initialized | |
842 && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0, | |
843 load_ave, 12, 0, 0, 0, 0) & 1)) | |
844 { | |
845 sys$dassgn (channel); | |
846 getloadavg_initialized = 0; | |
847 } | |
848 | |
849 if (!getloadavg_initialized) | |
850 return -1; | |
851 #endif /* VMS */ | |
852 | |
853 #if !defined (LDAV_DONE) && defined(LOAD_AVE_TYPE) && !defined(VMS) | |
854 | |
855 /* UNIX-specific code -- read the average from /dev/kmem. */ | |
856 | |
857 #define LDAV_PRIVILEGED /* This code requires special installation. */ | |
858 | |
859 LOAD_AVE_TYPE load_ave[3]; | |
860 | |
861 /* Get the address of LDAV_SYMBOL. */ | |
862 if (offset == 0) | |
863 { | |
864 #ifndef sgi | |
865 #ifndef NLIST_STRUCT | |
866 strcpy (nl[0].n_name, LDAV_SYMBOL); | |
867 strcpy (nl[1].n_name, ""); | |
868 #else /* NLIST_STRUCT */ | |
869 #ifdef NLIST_NAME_UNION | |
870 nl[0].n_un.n_name = LDAV_SYMBOL; | |
871 nl[1].n_un.n_name = 0; | |
872 #else /* not NLIST_NAME_UNION */ | |
873 nl[0].n_name = LDAV_SYMBOL; | |
874 nl[1].n_name = 0; | |
875 #endif /* not NLIST_NAME_UNION */ | |
876 #endif /* NLIST_STRUCT */ | |
877 | |
4011
1117ec91799c
*** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents:
3597
diff
changeset
|
878 #ifndef SUNOS_5 |
11788
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
879 if ( |
12799
a252e42dabcc
[ps2]: Use nlist instead of knlist #ifdef _AIX.
Roland McGrath <roland@gnu.org>
parents:
12738
diff
changeset
|
880 #if !(defined (_AIX) && !defined (ps2)) |
11788
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
881 nlist (KERNEL_FILE, nl) |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
882 #else /* _AIX */ |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
883 knlist (nl, 1, sizeof (nl[0])) |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
884 #endif |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
885 >= 0) |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
886 /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */ |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
887 { |
2928 | 888 #ifdef FIXUP_KERNEL_SYMBOL_ADDR |
11788
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
889 FIXUP_KERNEL_SYMBOL_ADDR (nl); |
2928 | 890 #endif |
11788
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
891 offset = nl[0].n_value; |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
892 } |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
893 #endif /* !SUNOS_5 */ |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
894 #else /* sgi */ |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
895 int ldav_off; |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
896 |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
897 ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
898 if (ldav_off != -1) |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
899 offset = (long) ldav_off & 0x7fffffff; |
3a2d34fad6fb
AIX support from Tim Bell <tbel@afsmail.cern.ch>:
Roland McGrath <roland@gnu.org>
parents:
10363
diff
changeset
|
900 #endif /* sgi */ |
2928 | 901 } |
902 | |
903 /* Make sure we have /dev/kmem open. */ | |
904 if (!getloadavg_initialized) | |
905 { | |
906 #ifndef SUNOS_5 | |
907 channel = open ("/dev/kmem", 0); | |
908 if (channel >= 0) | |
12738
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
909 { |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
910 /* Set the channel to close on exec, so it does not |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
911 litter any child's descriptor table. */ |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
912 #ifdef FD_SETFD |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
913 #ifndef FD_CLOEXEC |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
914 #define FD_CLOEXEC 1 |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
915 #endif |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
916 (void) fcntl (channel, F_SETFD, FD_CLOEXEC); |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
917 #endif |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
918 getloadavg_initialized = 1; |
d06973e701f8
(getloadavg): Set FD_CLOEXEC flag on /dev/kmem file descriptor.
Roland McGrath <roland@gnu.org>
parents:
12332
diff
changeset
|
919 } |
2928 | 920 #else /* SUNOS_5 */ |
4011
1117ec91799c
*** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents:
3597
diff
changeset
|
921 /* We pass 0 for the kernel, corefile, and swapfile names |
1117ec91799c
*** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents:
3597
diff
changeset
|
922 to use the currently running kernel. */ |
2928 | 923 kd = kvm_open (0, 0, 0, O_RDONLY, 0); |
15281
dd275783c873
[WIN32]: No-op as for [MSDOS].
Roland McGrath <roland@gnu.org>
parents:
14457
diff
changeset
|
924 if (kd != 0) |
2928 | 925 { |
4011
1117ec91799c
*** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents:
3597
diff
changeset
|
926 /* nlist the currently running kernel. */ |
2928 | 927 kvm_nlist (kd, nl); |
4011
1117ec91799c
*** empty log message ***
David J. MacKenzie <djm@gnu.org>
parents:
3597
diff
changeset
|
928 offset = nl[0].n_value; |
2928 | 929 getloadavg_initialized = 1; |
930 } | |
931 #endif /* SUNOS_5 */ | |
932 } | |
933 | |
934 /* If we can, get the load average values. */ | |
935 if (offset && getloadavg_initialized) | |
936 { | |
937 /* Try to read the load. */ | |
938 #ifndef SUNOS_5 | |
939 if (lseek (channel, offset, 0) == -1L | |
940 || read (channel, (char *) load_ave, sizeof (load_ave)) | |
941 != sizeof (load_ave)) | |
942 { | |
943 close (channel); | |
944 getloadavg_initialized = 0; | |
945 } | |
946 #else /* SUNOS_5 */ | |
947 if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) | |
948 != sizeof (load_ave)) | |
949 { | |
950 kvm_close (kd); | |
951 getloadavg_initialized = 0; | |
952 } | |
953 #endif /* SUNOS_5 */ | |
954 } | |
955 | |
956 if (offset == 0 || !getloadavg_initialized) | |
957 return -1; | |
958 #endif /* LOAD_AVE_TYPE and not VMS */ | |
959 | |
960 #if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */ | |
961 if (nelem > 0) | |
962 loadavg[elem++] = LDAV_CVT (load_ave[0]); | |
963 if (nelem > 1) | |
964 loadavg[elem++] = LDAV_CVT (load_ave[1]); | |
965 if (nelem > 2) | |
966 loadavg[elem++] = LDAV_CVT (load_ave[2]); | |
967 | |
968 #define LDAV_DONE | |
969 #endif /* !LDAV_DONE && LOAD_AVE_TYPE */ | |
970 | |
971 #ifdef LDAV_DONE | |
972 return elem; | |
973 #else | |
974 /* Set errno to zero to indicate that there was no particular error; | |
975 this function just can't work at all on this system. */ | |
976 errno = 0; | |
977 return -1; | |
978 #endif | |
979 } | |
4409 | 980 |
981 #endif /* ! HAVE_GETLOADAVG */ | |
2928 | 982 |
983 #ifdef TEST | |
984 void | |
985 main (argc, argv) | |
986 int argc; | |
987 char **argv; | |
988 { | |
989 int naptime = 0; | |
990 | |
991 if (argc > 1) | |
992 naptime = atoi (argv[1]); | |
993 | |
994 while (1) | |
995 { | |
996 double avg[3]; | |
997 int loads; | |
998 | |
999 errno = 0; /* Don't be misled if it doesn't set errno. */ | |
1000 loads = getloadavg (avg, 3); | |
1001 if (loads == -1) | |
1002 { | |
1003 perror ("Error getting load average"); | |
1004 exit (1); | |
1005 } | |
1006 if (loads > 0) | |
1007 printf ("1-minute: %f ", avg[0]); | |
1008 if (loads > 1) | |
1009 printf ("5-minute: %f ", avg[1]); | |
1010 if (loads > 2) | |
1011 printf ("15-minute: %f ", avg[2]); | |
1012 if (loads > 0) | |
1013 putchar ('\n'); | |
4398 | 1014 |
1015 if (naptime == 0) | |
1016 break; | |
2928 | 1017 sleep (naptime); |
1018 } | |
4398 | 1019 |
1020 exit (0); | |
2928 | 1021 } |
1022 #endif /* TEST */ |