Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) 1982, 1986, 1989 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
1284e777 | 33 | * from: @(#)vm_meter.c 7.11 (Berkeley) 4/20/91 |
4c45483e | 34 | * $Id: vm_meter.c,v 1.3 1993/11/07 17:54:17 wollman Exp $ |
15637ed4 RG |
35 | */ |
36 | ||
37 | #include "param.h" | |
38 | #include "proc.h" | |
39 | #include "systm.h" | |
40 | #include "kernel.h" | |
41 | ||
42 | #include "vm_param.h" | |
43 | #include "vmmeter.h" | |
44 | ||
bbc3f849 GW |
45 | struct vmtotal total; |
46 | struct vmmeter cnt, rate, sum; | |
47 | ||
48 | #include "dkstat.h" /* a convenient place to put these */ | |
49 | long cp_time[CPUSTATES]; /* cpu time per state */ | |
50 | int dk_busy; /* number of busy disks */ | |
51 | long dk_time[DK_NDRIVE]; /* access time per disk */ | |
52 | long dk_seek[DK_NDRIVE]; /* seeks per disk */ | |
53 | long dk_wds[DK_NDRIVE]; /* */ | |
54 | long dk_wpms[DK_NDRIVE]; /* */ | |
55 | long dk_xfer[DK_NDRIVE]; /* */ | |
56 | long tk_nin; /* total characters in */ | |
57 | long tk_nout; /* total characters out */ | |
58 | long tk_cancc; /* total canonical characters */ | |
59 | long tk_rawcc; /* total raw characters */ | |
60 | ||
15637ed4 RG |
61 | fixpt_t averunnable[3]; /* load average, of runnable procs */ |
62 | ||
4c45483e GW |
63 | static void vmtotal(void); |
64 | static void loadav(fixpt_t *, int); | |
65 | ||
15637ed4 RG |
66 | int maxslp = MAXSLP; |
67 | int saferss = SAFERSS; | |
68 | ||
69 | ||
4c45483e | 70 | void |
15637ed4 RG |
71 | vmmeter() |
72 | { | |
73 | register unsigned *cp, *rp, *sp; | |
74 | ||
75 | if (time.tv_sec % 5 == 0) | |
76 | vmtotal(); | |
77 | if (proc0.p_slptime > maxslp/2) | |
78 | wakeup((caddr_t)&proc0); | |
79 | } | |
80 | ||
4c45483e | 81 | static void |
15637ed4 RG |
82 | vmtotal() |
83 | { | |
84 | register struct proc *p; | |
85 | int nrun = 0; | |
86 | ||
87 | total.t_vm = 0; | |
88 | total.t_avm = 0; | |
89 | total.t_rm = 0; | |
90 | total.t_arm = 0; | |
91 | total.t_rq = 0; | |
92 | total.t_dw = 0; | |
93 | total.t_pw = 0; | |
94 | total.t_sl = 0; | |
95 | total.t_sw = 0; | |
96 | for (p = allproc; p != NULL; p = p->p_nxt) { | |
97 | if (p->p_flag & SSYS) | |
98 | continue; | |
99 | if (p->p_stat) { | |
100 | switch (p->p_stat) { | |
101 | ||
102 | case SSLEEP: | |
103 | if (p->p_pri <= PZERO && p->p_slptime == 0) | |
104 | nrun++; | |
105 | /* fall through */ | |
106 | case SSTOP: | |
107 | #ifdef notdef | |
108 | if (p->p_flag & SPAGE) | |
109 | total.t_pw++; | |
110 | else | |
111 | #endif | |
112 | if (p->p_flag & SLOAD) { | |
113 | if (p->p_pri <= PZERO) | |
114 | total.t_dw++; | |
115 | else if (p->p_slptime < maxslp) | |
116 | total.t_sl++; | |
117 | } else if (p->p_slptime < maxslp) | |
118 | total.t_sw++; | |
119 | if (p->p_slptime < maxslp) | |
120 | goto active; | |
121 | break; | |
122 | ||
123 | case SRUN: | |
124 | case SIDL: | |
125 | nrun++; | |
126 | if (p->p_flag & SLOAD) | |
127 | total.t_rq++; | |
128 | else | |
129 | total.t_sw++; | |
130 | active: | |
131 | break; | |
132 | } | |
133 | } | |
134 | } | |
135 | loadav(averunnable, nrun); | |
136 | } | |
137 | ||
138 | /* | |
139 | * Constants for averages over 1, 5, and 15 minutes | |
140 | * when sampling at 5 second intervals. | |
141 | */ | |
142 | fixpt_t cexp[3] = { | |
143 | 0.9200444146293232 * FSCALE, /* exp(-1/12) */ | |
144 | 0.9834714538216174 * FSCALE, /* exp(-1/60) */ | |
145 | 0.9944598480048967 * FSCALE, /* exp(-1/180) */ | |
146 | }; | |
147 | ||
148 | /* | |
149 | * Compute a tenex style load average of a quantity on | |
150 | * 1, 5 and 15 minute intervals. | |
151 | */ | |
4c45483e | 152 | void |
15637ed4 RG |
153 | loadav(avg, n) |
154 | register fixpt_t *avg; | |
155 | int n; | |
156 | { | |
157 | register int i; | |
158 | ||
159 | for (i = 0; i < 3; i++) | |
160 | avg[i] = (cexp[i] * avg[i] + n * FSCALE * (FSCALE - cexp[i])) | |
161 | >> FSHIFT; | |
162 | #if defined(COMPAT_43) && (defined(vax) || defined(tahoe)) | |
163 | for (i = 0; i < 3; i++) | |
164 | avenrun[i] = (double) averunnable[i] / FSCALE; | |
165 | #endif /* COMPAT_43 */ | |
166 | } |