annotate src/getloadavg.c @ 2586:196ee3cd1ac5

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