Annotation of Gnu-Mach/kern/mach_factor.c, revision 1.1.1.3

1.1.1.2   root        1: /*
1.1       root        2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
                      4:  * All Rights Reserved.
1.1.1.2   root        5:  *
1.1       root        6:  * Permission to use, copy, modify and distribute this software and its
                      7:  * documentation is hereby granted, provided that both the copyright
                      8:  * notice and this permission notice appear in all copies of the
                      9:  * software, derivative works or modified versions, and any portions
                     10:  * thereof, and that both notices appear in supporting documentation.
1.1.1.2   root       11:  *
1.1       root       12:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     13:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     14:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1.1.1.2   root       15:  *
1.1       root       16:  * Carnegie Mellon requests users of this software to return to
1.1.1.2   root       17:  *
1.1       root       18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
1.1.1.2   root       22:  *
1.1       root       23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
                     26: /*
                     27:  *     File:   kern/mach_factor.c
                     28:  *     Author: Avadis Tevanian, Jr.
                     29:  *     Date:   1986
                     30:  *
                     31:  *     Compute the Mach Factor.
                     32:  */
                     33: 
                     34: #include <mach/machine.h>
                     35: #include <mach/processor_info.h>
1.1.1.3 ! root       36: #include <kern/mach_clock.h>
1.1       root       37: #include <kern/sched.h>
                     38: #include <kern/processor.h>
                     39: #include <mach/kern_return.h>
                     40: #include <mach/port.h>
                     41: 
1.1.1.3 ! root       42: #include "mach_factor.h"
1.1       root       43: 
                     44: long   avenrun[3] = {0, 0, 0};
                     45: long   mach_factor[3] = {0, 0, 0};
                     46: 
                     47: /*
                     48:  * Values are scaled by LOAD_SCALE, defined in processor_info.h
                     49:  */
                     50: static long    fract[3] = {
                     51:        800,                    /* (4.0/5.0) 5 second average */
                     52:        966,                    /* (29.0/30.0) 30 second average */
                     53:        983,                    /* (59.0/60.) 1 minute average */
                     54: };
                     55: 
1.1.1.3 ! root       56: void compute_mach_factor(void)
1.1       root       57: {
                     58:        register processor_set_t        pset;
                     59:        register processor_t            processor;
                     60:        register int            ncpus;
                     61:        register int            nthreads;
                     62:        register long           factor_now;
                     63:        register long           average_now;
                     64:        register long           load_now;
                     65: 
                     66:        simple_lock(&all_psets_lock);
                     67:        pset = (processor_set_t) queue_first(&all_psets);
                     68:        while (!queue_end(&all_psets, (queue_entry_t)pset)) {
                     69: 
                     70:            /*
                     71:             *  If no processors, this pset is in suspended animation.
                     72:             *  No load calculations are performed.
                     73:             */
                     74:            pset_lock(pset);
                     75:            if((ncpus = pset->processor_count) > 0) {
                     76: 
                     77:                /*
                     78:                 *      Count number of threads.
                     79:                 */
                     80:                nthreads = pset->runq.count;
                     81:                processor = (processor_t) queue_first(&pset->processors);
                     82:                while (!queue_end(&pset->processors,
                     83:                    (queue_entry_t)processor)) {
                     84:                        nthreads += processor->runq.count;
                     85:                        processor =
                     86:                            (processor_t) queue_next(&processor->processors);
                     87:                }
                     88: 
                     89:                /*
                     90:                 * account for threads on cpus.
                     91:                 */
1.1.1.2   root       92:                nthreads += ncpus - pset->idle_count;
1.1       root       93: 
                     94:                /*
                     95:                 *      The current thread (running this calculation)
                     96:                 *      doesn't count; it's always in the default pset.
                     97:                 */
                     98:                if (pset == &default_pset)
                     99:                   nthreads -= 1;
                    100: 
                    101:                if (nthreads > ncpus) {
                    102:                        factor_now = (ncpus * LOAD_SCALE) / (nthreads + 1);
                    103:                        load_now = (nthreads << SCHED_SHIFT) / ncpus;
                    104:                }
                    105:                else {
                    106:                        factor_now = (ncpus - nthreads) * LOAD_SCALE;
                    107:                        load_now = SCHED_SCALE;
                    108:                }
                    109: 
                    110:                /*
                    111:                 *      Load average and mach factor calculations for
                    112:                 *      those that ask about these things.
                    113:                 */
                    114: 
                    115:                average_now = nthreads * LOAD_SCALE;
                    116: 
                    117:                pset->mach_factor =
                    118:                        ((pset->mach_factor << 2) + factor_now)/5;
                    119:                pset->load_average =
                    120:                        ((pset->load_average << 2) + average_now)/5;
                    121: 
                    122:                /*
                    123:                 *      And some ugly stuff to keep w happy.
                    124:                 */
                    125:                if (pset == &default_pset) {
                    126:                    register int i;
                    127: 
                    128:                    for (i = 0; i < 3; i++) {
                    129:                        mach_factor[i] = ( (mach_factor[i]*fract[i])
                    130:                                 + (factor_now*(LOAD_SCALE-fract[i])) )
                    131:                                / LOAD_SCALE;
                    132:                        avenrun[i] = ( (avenrun[i]*fract[i])
                    133:                                 + (average_now*(LOAD_SCALE-fract[i])) )
                    134:                                / LOAD_SCALE;
                    135:                    }
                    136:                }
                    137: 
                    138:                /*
                    139:                 *      sched_load is the only thing used by scheduler.
                    140:                 *      It is always at least 1 (i.e. SCHED_SCALE).
                    141:                 */
                    142:                pset->sched_load = (pset->sched_load + load_now) >> 1;
                    143:            }
                    144: 
                    145:            pset_unlock(pset);
                    146:            pset = (processor_set_t) queue_next(&pset->all_psets);
                    147:        }
                    148: 
                    149:        simple_unlock(&all_psets_lock);
                    150: }

unix.superglobalmegacorp.com

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