|
|
1.1 root 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: *
1.1.1.2 ! root 33: * from: @(#)vm_meter.c 7.11 (Berkeley) 4/20/91
! 34: * vm_meter.c,v 1.3 1993/06/27 06:34:40 andrew Exp
1.1 root 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:
45: fixpt_t averunnable[3]; /* load average, of runnable procs */
46:
47: int maxslp = MAXSLP;
48: int saferss = SAFERSS;
49:
50:
1.1.1.2 ! root 51: void
1.1 root 52: vmmeter()
53: {
54: register unsigned *cp, *rp, *sp;
55:
56: if (time.tv_sec % 5 == 0)
57: vmtotal();
58: if (proc0.p_slptime > maxslp/2)
59: wakeup((caddr_t)&proc0);
60: }
61:
62: vmtotal()
63: {
64: register struct proc *p;
65: int nrun = 0;
66:
67: total.t_vm = 0;
68: total.t_avm = 0;
69: total.t_rm = 0;
70: total.t_arm = 0;
71: total.t_rq = 0;
72: total.t_dw = 0;
73: total.t_pw = 0;
74: total.t_sl = 0;
75: total.t_sw = 0;
76: for (p = allproc; p != NULL; p = p->p_nxt) {
77: if (p->p_flag & SSYS)
78: continue;
79: if (p->p_stat) {
80: switch (p->p_stat) {
81:
82: case SSLEEP:
83: if (p->p_pri <= PZERO && p->p_slptime == 0)
84: nrun++;
85: /* fall through */
86: case SSTOP:
87: #ifdef notdef
88: if (p->p_flag & SPAGE)
89: total.t_pw++;
90: else
91: #endif
92: if (p->p_flag & SLOAD) {
93: if (p->p_pri <= PZERO)
94: total.t_dw++;
95: else if (p->p_slptime < maxslp)
96: total.t_sl++;
97: } else if (p->p_slptime < maxslp)
98: total.t_sw++;
99: if (p->p_slptime < maxslp)
100: goto active;
101: break;
102:
103: case SRUN:
104: case SIDL:
105: nrun++;
106: if (p->p_flag & SLOAD)
107: total.t_rq++;
108: else
109: total.t_sw++;
110: active:
111: break;
112: }
113: }
114: }
115: loadav(averunnable, nrun);
116: }
117:
118: /*
119: * Constants for averages over 1, 5, and 15 minutes
120: * when sampling at 5 second intervals.
121: */
122: fixpt_t cexp[3] = {
123: 0.9200444146293232 * FSCALE, /* exp(-1/12) */
124: 0.9834714538216174 * FSCALE, /* exp(-1/60) */
125: 0.9944598480048967 * FSCALE, /* exp(-1/180) */
126: };
127:
128: /*
129: * Compute a tenex style load average of a quantity on
130: * 1, 5 and 15 minute intervals.
131: */
132: loadav(avg, n)
133: register fixpt_t *avg;
134: int n;
135: {
136: register int i;
137:
138: for (i = 0; i < 3; i++)
139: avg[i] = (cexp[i] * avg[i] + n * FSCALE * (FSCALE - cexp[i]))
140: >> FSHIFT;
141: #if defined(COMPAT_43) && (defined(vax) || defined(tahoe))
142: for (i = 0; i < 3; i++)
143: avenrun[i] = (double) averunnable[i] / FSCALE;
144: #endif /* COMPAT_43 */
145: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.