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

Cache object: 82c785c34997094daf487eb7fa6bae7e


[ 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.