1 /*	$OpenBSD: loadavg.h,v 1.3 2002/07/15 17:20:36 deraadt Exp $	*/
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  */
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  */
52 #if defined(mips) && !defined(__OpenBSD__)
53 # include <sys/fixpoint.h>
54 # if defined(FBITS) && !defined(FSCALE)
55 #  define FSCALE (1 << FBITS)	/* mips */
56 # endif
57 #endif
58 
59 #ifdef FSCALE
60 # define FIXED_LOADAVG FSCALE
61 # define FIXED_PCTCPU FSCALE
62 #endif
63 
64 #ifdef ibm032
65 # undef FIXED_LOADAVG
66 # undef FIXED_PCTCPU
67 # define FIXED_PCTCPU PCT_SCALE
68 #endif
69 
70 
71 #ifdef FIXED_PCTCPU
72   typedef long pctcpu;
73 # define pctdouble(p) ((double)(p) / FIXED_PCTCPU)
74 #else
75 typedef double pctcpu;
76 # define pctdouble(p) (p)
77 #endif
78 
79 #ifdef FIXED_LOADAVG
80   typedef long load_avg;
81 # define loaddouble(la) ((double)(la) / FIXED_LOADAVG)
82 # define intload(i) ((int)((i) * FIXED_LOADAVG))
83 #else
84   typedef double load_avg;
85 # define loaddouble(la) (la)
86 # define intload(i) ((double)(i))
87 #endif
88