]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/sched_average.c
xnu-2050.7.9.tar.gz
[apple/xnu.git] / osfmk / kern / sched_average.c
index 5545079938c988daef49e5b983e3afb8ca0a6fb0..d2a2ce6cb98bb191691de4e79edb7ba229ec1696 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -72,6 +72,7 @@
 uint32_t       avenrun[3] = {0, 0, 0};
 uint32_t       mach_factor[3] = {0, 0, 0};
 
+#if defined(CONFIG_SCHED_TRADITIONAL)
 /*
  * Values are scaled by LOAD_SCALE, defined in processor_info.h
  */
@@ -87,21 +88,25 @@ static uint32_t             fract[3] = {
 #undef base
 #undef frac
 
+#endif /* CONFIG_SCHED_TRADITIONAL */
+
 static unsigned int            sched_nrun;
 
 typedef void   (*sched_avg_comp_t)(
                                        void                    *param);
 
-#define SCHED_AVG_SECS(n)      ((n) << SCHED_TICK_SHIFT)
-
 static struct sched_average {
        sched_avg_comp_t        comp;
        void                            *param;
-       int                                     period;
-       int                                     tick;                   
+       int                                     period; /* in seconds */
+       uint64_t                        deadline;                       
 } sched_average[] = {
-       { compute_averunnable, &sched_nrun, SCHED_AVG_SECS(5), 0 },
-       { compute_stack_target, NULL, SCHED_AVG_SECS(5), 1 },
+       { compute_averunnable, &sched_nrun, 5, 0 },
+       { compute_stack_target, NULL, 5, 1 },
+       { compute_memory_pressure, NULL, 1, 0 },
+       { compute_zone_gc_throttle, NULL, 60, 0 },
+       { compute_pageout_gc_throttle, NULL, 1, 0 },
+       { compute_pmap_gc_throttle, NULL, 60, 0 },
        { NULL, NULL, 0, 0 }
 };
 
@@ -110,76 +115,69 @@ typedef struct sched_average      *sched_average_t;
 void
 compute_averages(void)
 {
-       register processor_set_t        pset = &default_pset;
-       register int                            ncpus;
-       register int                            nthreads, nshared;
-       sched_average_t                         avg;
-       register uint32_t                       factor_now = 0;
-       register uint32_t                       average_now = 0;
-       register uint32_t                       load_now = 0;
-
-       if ((ncpus = pset->processor_count) > 0) {
-               /*
-                *      Retrieve counts, ignoring
-                *      the current thread.
-                */
-               nthreads = pset->run_count - 1;
-               nshared = pset->share_count;
-
-               /*
-                *      Load average and mach factor calculations for
-                *      those which ask about these things.
-                */
-               average_now = nthreads * LOAD_SCALE;
-
-               if (nthreads > ncpus)
-                       factor_now = (ncpus * LOAD_SCALE) / (nthreads + 1);
+       int                                     ncpus, nthreads, nshared;
+       uint32_t                        factor_now, average_now, load_now = 0;
+       sched_average_t         avg;
+       uint64_t                        abstime;
+       
+       /*
+        *      Retrieve counts, ignoring
+        *      the current thread.
+        */
+       ncpus = processor_avail_count;
+       nthreads = sched_run_count - 1;
+       nshared = sched_share_count;
+
+       /*
+        *      Load average and mach factor calculations for
+        *      those which ask about these things.
+        */
+       average_now = nthreads * LOAD_SCALE;
+
+       if (nthreads > ncpus)
+               factor_now = (ncpus * LOAD_SCALE) / (nthreads + 1);
+       else
+               factor_now = (ncpus - nthreads) * LOAD_SCALE;
+
+       sched_mach_factor =     ((sched_mach_factor << 2) + factor_now) / 5;
+       sched_load_average = ((sched_load_average << 2) + average_now) / 5;
+
+       /*
+        *      Compute the timeshare priority
+        *      conversion factor based on loading.
+        */
+       if (nshared > nthreads)
+               nshared = nthreads;
+
+       if (nshared > ncpus) {
+               if (ncpus > 1)
+                       load_now = nshared / ncpus;
                else
-                       factor_now = (ncpus - nthreads) * LOAD_SCALE;
-
-               pset->mach_factor =     ((pset->mach_factor << 2) + factor_now) / 5;
-               pset->load_average = ((pset->load_average << 2) + average_now) / 5;
-
-               /*
-                *      Compute the timeshare priority
-                *      conversion factor based on loading.
-                */
-               if (nshared > nthreads)
-                       nshared = nthreads;
-
-               if (nshared > ncpus) {
-                       if (ncpus > 1)
-                               load_now = nshared / ncpus;
-                       else
-                               load_now = nshared;
-
-                       if (load_now > NRQS - 1)
-                               load_now = NRQS - 1;
-               }
+                       load_now = nshared;
 
-               /*
-                *      The conversion factor consists of
-                *      two components: a fixed value based
-                *      on the absolute time unit, and a
-                *      dynamic portion based on loading.
-                *
-                *      Zero loading results in a out of range
-                *      shift count.  Accumulated usage is ignored
-                *      during conversion and new usage deltas
-                *      are discarded.
-                */
-               pset->pri_shift = sched_pri_shift - sched_load_shifts[load_now];
-       }
-       else {
-               pset->mach_factor = pset->load_average = 0;
-               pset->pri_shift = INT8_MAX;
-               nthreads = pset->run_count;
+               if (load_now > NRQS - 1)
+                       load_now = NRQS - 1;
        }
 
        /*
         *      Sample total running threads.
         */
        sched_nrun = nthreads;
+       
+#if defined(CONFIG_SCHED_TRADITIONAL)
+
+       /*
+        *      The conversion factor consists of
+        *      two components: a fixed value based
+        *      on the absolute time unit, and a
+        *      dynamic portion based on loading.
+        *
+        *      Zero loading results in a out of range
+        *      shift count.  Accumulated usage is ignored
+        *      during conversion and new usage deltas
+        *      are discarded.
+        */
+       sched_pri_shift = sched_fixed_shift - sched_load_shifts[load_now];
 
        /*
         * Compute old-style Mach load averages.
@@ -195,14 +193,16 @@ compute_averages(void)
                                                (average_now * (LOAD_SCALE - fract[i]))) / LOAD_SCALE;
                }
        }
+#endif /* CONFIG_SCHED_TRADITIONAL */
 
        /*
         *      Compute averages in other components.
         */
+       abstime = mach_absolute_time();
        for (avg = sched_average; avg->comp != NULL; ++avg) {
-               if (++avg->tick >= avg->period) {
+               if (abstime >= avg->deadline) {
                        (*avg->comp)(avg->param);
-                       avg->tick = 0;
+                       avg->deadline = abstime + avg->period * sched_one_second_interval;
                }
        }
 }