Annotation of src/usr.bin/top/loadavg.h, Revision 1.4
1.4 ! deraadt 1: /* $OpenBSD: loadavg.h,v 1.3 2002/07/15 17:20:36 deraadt Exp $ */
1.3 deraadt 2:
3: /*
4: * Top users/processes display for Unix
5: * Version 3
6: *
7: * Copyright (c) 1984, 1989, William LeFebvre, Rice University
8: * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22: * IN NO EVENT SHALL THE AUTHOR OR HIS EMPLOYER BE LIABLE FOR ANY DIRECT, INDIRECT,
23: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29: */
1.1 downsj 30:
31: /*
32: * Top - a top users display for Berkeley Unix
33: *
34: * Defines required to access load average figures.
35: *
36: * This include file sets up everything we need to access the load average
37: * values in the kernel in a machine independent way. First, it sets the
38: * typedef "load_avg" to be either double or long (depending on what is
39: * needed), then it defines these macros appropriately:
40: *
41: * loaddouble(la) - convert load_avg to double.
42: * intload(i) - convert integer to load_avg.
43: */
44:
45: /*
46: * We assume that if FSCALE is defined, then avenrun and ccpu are type long.
47: * If your machine is an exception (mips, perhaps?) then make adjustments
48: * here.
49: *
50: * Defined types: load_avg for load averages, pctcpu for cpu percentages.
51: */
1.2 downsj 52: #if defined(mips) && !defined(__OpenBSD__)
1.1 downsj 53: # include <sys/fixpoint.h>
54: # if defined(FBITS) && !defined(FSCALE)
55: # define FSCALE (1 << FBITS) /* mips */
56: # endif
1.4 ! deraadt 57: #endif
! 58:
! 59: #ifdef __OpenBSD__
! 60: #undef FSCALE
! 61: #define FSCALE fscale /* fetched via sysctl(3) */
1.1 downsj 62: #endif
63:
64: #ifdef FSCALE
65: # define FIXED_LOADAVG FSCALE
66: # define FIXED_PCTCPU FSCALE
67: #endif
68:
69: #ifdef ibm032
70: # undef FIXED_LOADAVG
71: # undef FIXED_PCTCPU
72: # define FIXED_PCTCPU PCT_SCALE
73: #endif
74:
75:
76: #ifdef FIXED_PCTCPU
77: typedef long pctcpu;
78: # define pctdouble(p) ((double)(p) / FIXED_PCTCPU)
79: #else
80: typedef double pctcpu;
81: # define pctdouble(p) (p)
82: #endif
83:
84: #ifdef FIXED_LOADAVG
85: typedef long load_avg;
86: # define loaddouble(la) ((double)(la) / FIXED_LOADAVG)
87: # define intload(i) ((int)((i) * FIXED_LOADAVG))
88: #else
89: typedef double load_avg;
90: # define loaddouble(la) (la)
91: # define intload(i) ((double)(i))
92: #endif