annotate src/getloadavg.c @ 286:57709be46d1b r21-0b41

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