The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/mach_factor.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* 
    2  * Mach Operating System
    3  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
    4  * All Rights Reserved.
    5  * 
    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.
   11  * 
   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.
   15  * 
   16  * Carnegie Mellon requests users of this software to return to
   17  * 
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  * 
   23  * any improvements or extensions that they make and grant Carnegie Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /*
   27  * HISTORY
   28  * $Log:        mach_factor.c,v $
   29  * Revision 2.7  92/08/03  17:38:15  jfriedl
   30  *      removed silly prototypes
   31  *      [92/08/02            jfriedl]
   32  * 
   33  * Revision 2.6  92/05/21  17:14:39  jfriedl
   34  *      Added void to to compute_mach_factor().
   35  *      [92/05/16            jfriedl]
   36  * 
   37  * Revision 2.5  91/05/14  16:44:18  mrt
   38  *      Correcting copyright
   39  * 
   40  * Revision 2.4  91/02/05  17:27:51  mrt
   41  *      Changed to new Mach copyright
   42  *      [91/02/01  16:14:56  mrt]
   43  * 
   44  * Revision 2.3  90/06/02  14:55:09  rpd
   45  *      Removed host_load; host_info/HOST_LOAD_INFO supercedes it.
   46  *      [90/06/02            rpd]
   47  * 
   48  *      Updated to new processor set and scheduling technology.
   49  *      [90/03/26  22:11:20  rpd]
   50  * 
   51  * Revision 2.2  90/03/14  21:10:38  rwd
   52  *      Added host_load call to get avenrun.
   53  *      [90/01/28            rwd]
   54  * 
   55  * Revision 2.1  89/08/03  15:46:37  rwd
   56  * Created.
   57  * 
   58  * 20-Oct-88  David Golub (dbg) at Carnegie-Mellon University
   59  *      Fixed for MACH_KERNEL.
   60  *
   61  * 25-Mar-88  David Black (dlb) at Carnegie-Mellon University
   62  *      Added sched_load calculation.
   63  *
   64  *  4-Dec-87  David Black (dlb) at Carnegie-Mellon University
   65  *      Fix calculation to correctly account for threads that are
   66  *      actually on cpus.  This used to work by accident because if a
   67  *      processor is not idle, its idle thread was on the local runq;
   68  *      this is no longer the case.
   69  *
   70  * 18-Nov-87  Avadis Tevanian (avie) at Carnegie-Mellon University
   71  *      Removed conditionals, compute every second.
   72  *
   73  */
   74 /*
   75  *      File:   kern/mach_factor.c
   76  *      Author: Avadis Tevanian, Jr.
   77  *      Date:   1986
   78  *
   79  *      Compute the Mach Factor.
   80  */
   81 
   82 #include <cpus.h>
   83 
   84 #include <mach/machine.h>
   85 #include <mach/processor_info.h>
   86 #include <kern/sched.h>
   87 #include <kern/processor.h>
   88 #include <kern/time_out.h>
   89 #if     MACH_KERNEL
   90 #include <mach/kern_return.h>
   91 #include <mach/port.h>
   92 #endif  MACH_KERNEL
   93 
   94 
   95 long    avenrun[3] = {0, 0, 0};
   96 long    mach_factor[3] = {0, 0, 0};
   97 
   98 /*
   99  * Values are scaled by LOAD_SCALE, defined in processor_info.h
  100  */
  101 static  long    fract[3] = {
  102         800,                    /* (4.0/5.0) 5 second average */
  103         966,                    /* (29.0/30.0) 30 second average */
  104         983,                    /* (59.0/60.) 1 minute average */
  105 };
  106 
  107 void compute_mach_factor()
  108 {
  109         register processor_set_t        pset;
  110         register processor_t            processor;
  111         register int            ncpus;
  112         register int            nthreads;
  113         register long           factor_now;
  114         register long           average_now;
  115         register long           load_now;
  116 
  117         simple_lock(&all_psets_lock);
  118         pset = (processor_set_t) queue_first(&all_psets);
  119         while (!queue_end(&all_psets, (queue_entry_t)pset)) {
  120 
  121             /*
  122              *  If no processors, this pset is in suspended animation.
  123              *  No load calculations are performed.
  124              */
  125             pset_lock(pset);
  126             if((ncpus = pset->processor_count) > 0) {
  127 
  128                 /*
  129                  *      Count number of threads.
  130                  */
  131                 nthreads = pset->runq.count;
  132                 processor = (processor_t) queue_first(&pset->processors);
  133                 while (!queue_end(&pset->processors,
  134                     (queue_entry_t)processor)) {
  135                         nthreads += processor->runq.count;
  136                         processor =
  137                             (processor_t) queue_next(&processor->processors);
  138                 }
  139 
  140                 /*
  141                  * account for threads on cpus.
  142                  */
  143                 nthreads += ncpus - pset->idle_count; 
  144 
  145                 /*
  146                  *      The current thread (running this calculation)
  147                  *      doesn't count; it's always in the default pset.
  148                  */
  149                 if (pset == &default_pset)
  150                    nthreads -= 1;
  151 
  152                 if (nthreads > ncpus) {
  153                         factor_now = (ncpus * LOAD_SCALE) / (nthreads + 1);
  154                         load_now = (nthreads << SCHED_SHIFT) / ncpus;
  155                 }
  156                 else {
  157                         factor_now = (ncpus - nthreads) * LOAD_SCALE;
  158                         load_now = SCHED_SCALE;
  159                 }
  160 
  161                 /*
  162                  *      Load average and mach factor calculations for
  163                  *      those that ask about these things.
  164                  */
  165 
  166                 average_now = nthreads * LOAD_SCALE;
  167 
  168                 pset->mach_factor =
  169                         ((pset->mach_factor << 2) + factor_now)/5;
  170                 pset->load_average =
  171                         ((pset->load_average << 2) + average_now)/5;
  172 
  173                 /*
  174                  *      And some ugly stuff to keep w happy.
  175                  */
  176                 if (pset == &default_pset) {
  177                     register int i;
  178 
  179                     for (i = 0; i < 3; i++) {
  180                         mach_factor[i] = ( (mach_factor[i]*fract[i])
  181                                  + (factor_now*(LOAD_SCALE-fract[i])) )
  182                                 / LOAD_SCALE;
  183                         avenrun[i] = ( (avenrun[i]*fract[i])
  184                                  + (average_now*(LOAD_SCALE-fract[i])) )
  185                                 / LOAD_SCALE;
  186                     }
  187                 }
  188 
  189                 /*
  190                  *      sched_load is the only thing used by scheduler.
  191                  *      It is always at least 1 (i.e. SCHED_SCALE).
  192                  */
  193                 pset->sched_load = (pset->sched_load + load_now) >> 1;
  194             }
  195 
  196             pset_unlock(pset);
  197             pset = (processor_set_t) queue_next(&pset->all_psets);
  198         }
  199 
  200         simple_unlock(&all_psets_lock);
  201 }

Cache object: 864d2198c3a1e1e5faef113f8deee9bd


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.