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.11 (Berkeley) 04/20/91 8 */ 9 10 #include "param.h" 11 #include "proc.h" 12 #include "systm.h" 13 #include "kernel.h" 14 15 #include "vm_param.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 (proc0.p_slptime > maxslp/2) 31 wakeup((caddr_t)&proc0); 32 } 33 34 vmtotal() 35 { 36 register struct proc *p; 37 int nrun = 0; 38 39 total.t_vm = 0; 40 total.t_avm = 0; 41 total.t_rm = 0; 42 total.t_arm = 0; 43 total.t_rq = 0; 44 total.t_dw = 0; 45 total.t_pw = 0; 46 total.t_sl = 0; 47 total.t_sw = 0; 48 for (p = allproc; p != NULL; p = p->p_nxt) { 49 if (p->p_flag & SSYS) 50 continue; 51 if (p->p_stat) { 52 switch (p->p_stat) { 53 54 case SSLEEP: 55 if (p->p_pri <= PZERO && p->p_slptime == 0) 56 nrun++; 57 /* fall through */ 58 case SSTOP: 59 #ifdef notdef 60 if (p->p_flag & SPAGE) 61 total.t_pw++; 62 else 63 #endif 64 if (p->p_flag & SLOAD) { 65 if (p->p_pri <= PZERO) 66 total.t_dw++; 67 else if (p->p_slptime < maxslp) 68 total.t_sl++; 69 } else if (p->p_slptime < maxslp) 70 total.t_sw++; 71 if (p->p_slptime < maxslp) 72 goto active; 73 break; 74 75 case SRUN: 76 case SIDL: 77 nrun++; 78 if (p->p_flag & SLOAD) 79 total.t_rq++; 80 else 81 total.t_sw++; 82 active: 83 break; 84 } 85 } 86 } 87 loadav(averunnable, nrun); 88 } 89 90 /* 91 * Constants for averages over 1, 5, and 15 minutes 92 * when sampling at 5 second intervals. 93 */ 94 fixpt_t cexp[3] = { 95 0.9200444146293232 * FSCALE, /* exp(-1/12) */ 96 0.9834714538216174 * FSCALE, /* exp(-1/60) */ 97 0.9944598480048967 * FSCALE, /* exp(-1/180) */ 98 }; 99 100 /* 101 * Compute a tenex style load average of a quantity on 102 * 1, 5 and 15 minute intervals. 103 */ 104 loadav(avg, n) 105 register fixpt_t *avg; 106 int n; 107 { 108 register int i; 109 110 for (i = 0; i < 3; i++) 111 avg[i] = (cexp[i] * avg[i] + n * FSCALE * (FSCALE - cexp[i])) 112 >> FSHIFT; 113 #if defined(COMPAT_43) && (defined(vax) || defined(tahoe)) 114 for (i = 0; i < 3; i++) 115 avenrun[i] = (double) averunnable[i] / FSCALE; 116 #endif /* COMPAT_43 */ 117 } 118