Annotation of Net2/vm/vm_meter.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.