]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/sched.h
xnu-1456.1.26.tar.gz
[apple/xnu.git] / osfmk / kern / sched.h
index 26a59d5864f5b67a6876a73eb63baf2c6dd75c8e..e1e5ae4c0272b9ee64f4393287f731377ef2e4d0 100644 (file)
@@ -1,31 +1,29 @@
 /*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
  *
- * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * This file contains Original Code and/or Modifications of Original Code 
- * as defined in and that are subject to the Apple Public Source License 
- * Version 2.0 (the 'License'). You may not use this file except in 
- * compliance with the License.  The rights granted to you under the 
- * License may not be used to create, or enable the creation or 
- * redistribution of, unlawful or unlicensed copies of an Apple operating 
- * system, or to circumvent, violate, or enable the circumvention or 
- * violation of, any terms of an Apple operating system software license 
- * agreement.
- *
- * Please obtain a copy of the License at 
- * http://www.opensource.apple.com/apsl/ and read it before using this 
- * file.
- *
- * The Original Code and all software distributed under the License are 
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
- * Please see the License for the specific language governing rights and 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
  * limitations under the License.
- *
- * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
+ * 
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * @OSF_COPYRIGHT@
@@ -180,13 +178,6 @@ typedef struct run_queue   *run_queue_t;
 
 #define first_timeslice(processor)             ((processor)->timeslice > 0)
 
-#define        processor_timeslice_setup(processor, thread)                    \
-MACRO_BEGIN                                                                                                            \
-       (processor)->timeslice =                                                                        \
-               ((thread)->sched_mode & TH_MODE_TIMESHARE)?                             \
-                       (processor)->processor_set->timeshare_quanta: 1;        \
-MACRO_END
-
 #define thread_quantum_init(thread)                                                    \
 MACRO_BEGIN                                                                                                    \
        (thread)->current_quantum =                                                     \
@@ -194,21 +185,14 @@ MACRO_BEGIN                                                                                                       \
                        (thread)->realtime.computation: std_quantum;    \
 MACRO_END
 
-/* Invoked at splsched by a thread on itself */
-#define csw_needed(thread, processor) (                                                                                \
-       ((thread)->state & TH_SUSP)                                                                             ||              \
-       (first_timeslice(processor)?                                                                                    \
-        ((processor)->runq.highq > (thread)->sched_pri                         ||                      \
-         (processor)->processor_set->runq.highq > (thread)->sched_pri) :               \
-        ((processor)->runq.highq >= (thread)->sched_pri                        ||                      \
-         (processor)->processor_set->runq.highq >= (thread)->sched_pri))       )
+extern struct run_queue                rt_runq;
 
 /*
  *     Scheduler routines.
  */
 
 /* Remove thread from its run queue */
-extern run_queue_t     run_queue_remove(
+extern boolean_t       run_queue_remove(
                                                thread_t        thread);
 
 /* Handle quantum expiration for an executing thread */
@@ -216,10 +200,8 @@ extern void                thread_quantum_expire(
                                        timer_call_param_t      processor,
                                        timer_call_param_t      thread);
 
-/* Called at splsched by a thread on itself */
-extern ast_t   csw_check(
-                                       thread_t                thread,
-                                       processor_t             processor);
+/* Context switch check for current processor */
+extern ast_t   csw_check(processor_t           processor);
 
 extern uint32_t        std_quantum, min_std_quantum;
 extern uint32_t        std_quantum_us;
@@ -245,34 +227,56 @@ extern void               compute_averunnable(
 extern void            compute_stack_target(
                                        void                    *arg);
 
+extern void            compute_memory_pressure(
+                                       void                    *arg);
+
 /*
  *     Conversion factor from usage
  *     to priority.
  */
 extern uint32_t                sched_pri_shift;
-
-/*
- *     Scaling factor for usage
- *     based on load.
- */
+extern uint32_t                sched_fixed_shift;
 extern int8_t          sched_load_shifts[NRQS];
 
 extern int32_t         sched_poll_yield_shift;
 extern uint32_t                sched_safe_duration;
 
+extern uint32_t                sched_run_count, sched_share_count;
+extern uint32_t                sched_load_average, sched_mach_factor;
+
+extern uint32_t                avenrun[3], mach_factor[3];
+
 extern uint64_t                max_unsafe_computation;
 extern uint64_t                max_poll_computation;
 
-extern uint32_t                avenrun[3], mach_factor[3];
+#define sched_run_incr()                       \
+MACRO_BEGIN                                                                                                    \
+       machine_run_count(hw_atomic_add(&sched_run_count, 1));  \
+MACRO_END
+
+#define sched_run_decr()                       \
+MACRO_BEGIN                                                                                                    \
+       machine_run_count(hw_atomic_sub(&sched_run_count, 1));  \
+MACRO_END
+
+#define sched_share_incr()                     \
+MACRO_BEGIN                                                                                    \
+       (void)hw_atomic_add(&sched_share_count, 1);             \
+MACRO_END
+
+#define sched_share_decr()                     \
+MACRO_BEGIN                                                                                    \
+       (void)hw_atomic_sub(&sched_share_count, 1);             \
+MACRO_END
 
 /*
  *     thread_timer_delta macro takes care of both thread timers.
  */
 #define thread_timer_delta(thread, delta)                                      \
 MACRO_BEGIN                                                                                                    \
-       (delta) = timer_delta(&(thread)->system_timer,                  \
+       (delta) = (typeof(delta))timer_delta(&(thread)->system_timer,                   \
                                                        &(thread)->system_timer_save);  \
-       (delta) += timer_delta(&(thread)->user_timer,                   \
+       (delta) += (typeof(delta))timer_delta(&(thread)->user_timer,                    \
                                                        &(thread)->user_timer_save);    \
 MACRO_END