1 /* 2 * Copyright (c) 1982, 1986, 1989 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)vm_meter.c 7.10 (Berkeley) 12/05/90 8 */ 9 10 #include "param.h" 11 #include "systm.h" 12 #include "user.h" 13 #include "proc.h" 14 #include "kernel.h" 15 #include "machine/vmparam.h" 16 #include "vmmeter.h" 17 18 fixpt_t averunnable[3]; /* load average, of runnable procs */ 19 20 int maxslp = MAXSLP; 21 int saferss = SAFERSS; 22 23 24 vmmeter() 25 { 26 register unsigned *cp, *rp, *sp; 27 28 if (time.tv_sec % 5 == 0) 29 vmtotal(); 30 if (proc[0].p_slptime > maxslp/2) { 31 runout = 0; 32 wakeup((caddr_t)&runout); 33 } 34 } 35 36 vmtotal() 37 { 38 register struct proc *p; 39 int nrun = 0; 40 41 total.t_vm = 0; 42 total.t_avm = 0; 43 total.t_rm = 0; 44 total.t_arm = 0; 45 total.t_rq = 0; 46 total.t_dw = 0; 47 total.t_pw = 0; 48 total.t_sl = 0; 49 total.t_sw = 0; 50 for (p = allproc; p != NULL; p = p->p_nxt) { 51 if (p->p_flag & SSYS) 52 continue; 53 if (p->p_stat) { 54 switch (p->p_stat) { 55 56 case SSLEEP: 57 if (p->p_pri <= PZERO && p->p_slptime == 0) 58 nrun++; 59 /* fall through */ 60 case SSTOP: 61 if (p->p_flag & SPAGE) 62 total.t_pw++; 63 else if (p->p_flag & SLOAD) { 64 if (p->p_pri <= PZERO) 65 total.t_dw++; 66 else if (p->p_slptime < maxslp) 67 total.t_sl++; 68 } else if (p->p_slptime < maxslp) 69 total.t_sw++; 70 if (p->p_slptime < maxslp) 71 goto active; 72 break; 73 74 case SRUN: 75 case SIDL: 76 nrun++; 77 if (p->p_flag & SLOAD) 78 total.t_rq++; 79 else 80 total.t_sw++; 81 active: 82 break; 83 } 84 } 85 } 86 loadav(averunnable, nrun); 87 } 88 89 /* 90 * Constants for averages over 1, 5, and 15 minutes 91 * when sampling at 5 second intervals. 92 */ 93 fixpt_t cexp[3] = { 94 0.9200444146293232 * FSCALE, /* exp(-1/12) */ 95 0.9834714538216174 * FSCALE, /* exp(-1/60) */ 96 0.9944598480048967 * FSCALE, /* exp(-1/180) */ 97 }; 98 99 /* 100 * Compute a tenex style load average of a quantity on 101 * 1, 5 and 15 minute intervals. 102 */ 103 loadav(avg, n) 104 register fixpt_t *avg; 105 int n; 106 { 107 register int i; 108 109 for (i = 0; i < 3; i++) 110 avg[i] = (cexp[i] * avg[i] + n * FSCALE * (FSCALE - cexp[i])) 111 >> FSHIFT; 112 #if defined(COMPAT_43) && (defined(vax) || defined(tahoe)) 113 for (i = 0; i < 3; i++) 114 avenrun[i] = (double) averunnable[i] / FSCALE; 115 #endif /* COMPAT_43 */ 116 } 117