annotate src/getloadavg.c @ 18:d95e72db5c07 r19-15b92

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