]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/sched.h
xnu-517.11.1.tar.gz
[apple/xnu.git] / osfmk / kern / sched.h
index 01f2d3ada72c24b39db1d6c53bcf4c1467581d93..c6870f82bfc1ac08d7db4127c88968c52208223e 100644 (file)
@@ -70,6 +70,7 @@
 #include <kern/lock.h>
 #include <kern/macro_help.h>
 #include <kern/timer_call.h>
+#include <kern/ast.h>
 
 #if    STAT_TIME
 
@@ -87,8 +88,8 @@
 
 #endif /* STAT_TIME */
 
-#define        NRQS            128                             /* 128 run queues per cpu */
-#define NRQBM          (NRQS / 32)             /* number of run queue bit maps */
+#define        NRQS            128                             /* 128 levels per run queue */
+#define NRQBM          (NRQS / 32)             /* number of words per bit map */
 
 #define MAXPRI         (NRQS-1)
 #define MINPRI         IDLEPRI                 /* lowest legal priority schedulable */
  *************************************************************************
  */
 
+#define BASEPRI_RTQUEUES       (BASEPRI_REALTIME + 1)                          /* 97 */
 #define BASEPRI_REALTIME       (MAXPRI - (NRQS / 4) + 1)                       /* 96 */
 
 #define MAXPRI_STANDARD                (BASEPRI_REALTIME - 1)                          /* 95 */
 
 #define MAXPRI_KERNEL          MAXPRI_STANDARD                                         /* 95 */
 #define BASEPRI_PREEMPT                (MAXPRI_KERNEL - 2)                                     /* 93 */
+#define BASEPRI_KERNEL         (MINPRI_KERNEL + 1)                                     /* 81 */
 #define MINPRI_KERNEL          (MAXPRI_KERNEL - (NRQS / 8) + 1)        /* 80 */
 
 #define MAXPRI_SYSTEM          (MINPRI_KERNEL - 1)                                     /* 79 */
 #define MINPRI_SYSTEM          (MAXPRI_SYSTEM - (NRQS / 8) + 1)        /* 64 */
 
 #define MAXPRI_USER                    (MINPRI_SYSTEM - 1)                                     /* 63 */
+#define BASEPRI_CONTROL                (BASEPRI_DEFAULT + 17)                          /* 48 */
+#define BASEPRI_FOREGROUND     (BASEPRI_DEFAULT + 16)                          /* 47 */
+#define BASEPRI_BACKGROUND     (BASEPRI_DEFAULT + 15)                          /* 46 */
 #define BASEPRI_DEFAULT                (MAXPRI_USER - (NRQS / 4))                      /* 31 */
 #define MINPRI_USER                    MINPRI                                                          /*  0 */
 
 #define invalid_pri(pri) ((pri) < MINPRI || (pri) > MAXPRI)
 
 struct run_queue {
-       queue_head_t            queues[NRQS];           /* one for each priority */
-       decl_simple_lock_data(,lock)                    /* one lock for all queues */
-       int                                     bitmap[NRQBM];          /* run queue bitmap array */
        int                                     highq;                          /* highest runnable queue */
-       int                                     count;                          /* # of runnable threads */
+       int                                     bitmap[NRQBM];          /* run queue bitmap array */
+       int                                     count;                          /* # of threads total */
+       int                                     urgency;                        /* level of preemption urgency */
+       queue_head_t            queues[NRQS];           /* one for each priority */
 };
 
 typedef struct run_queue       *run_queue_t;
 #define RUN_QUEUE_NULL         ((run_queue_t) 0)
 
-#define first_quantum(processor)       ((processor)->slice_quanta > 0)
+#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 =                                                     \
+               ((thread)->sched_mode & TH_MODE_REALTIME)?                      \
+                       (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_quantum(processor)?                                                                                              \
+       (first_timeslice(processor)?                                                                                    \
         ((processor)->runq.highq > (thread)->sched_pri                         ||                      \
          (processor)->processor_set->runq.highq > (thread)->sched_pri) :               \
         ((processor)->runq.highq >= (thread)->sched_pri                        ||                      \
@@ -200,7 +221,7 @@ typedef struct run_queue    *run_queue_t;
  */
 
 /* Remove thread from its run queue */
-extern run_queue_t     rem_runq(
+extern run_queue_t     run_queue_remove(
                                                thread_t        thread);
 
 /* Periodic computation of load factors */
@@ -211,6 +232,11 @@ 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);
+
 extern uint32_t        std_quantum, min_std_quantum;
 extern uint32_t        std_quantum_us;
 
@@ -242,10 +268,9 @@ extern unsigned    sched_tick;
 /*
  *     thread_timer_delta macro takes care of both thread timers.
  */
-
 #define thread_timer_delta(thread)                                             \
 MACRO_BEGIN                                                                                                    \
-       register unsigned       delta;                                                          \
+       register uint32_t       delta;                                                          \
                                                                                                                        \
        delta = 0;                                                                                              \
        TIMER_DELTA((thread)->system_timer,                                             \