]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/sched_multiq.c
xnu-4570.51.1.tar.gz
[apple/xnu.git] / osfmk / kern / sched_multiq.c
index d37de1f3cb69011129859c70409606c85537a7e1..fd945ba1c8d9ef93b191d8f3cad09d95795400ce 100644 (file)
@@ -287,6 +287,9 @@ sched_multiq_processor_queue_shutdown(processor_t processor);
 static sched_mode_t
 sched_multiq_initial_thread_sched_mode(task_t parent_task);
 
+static bool
+sched_multiq_thread_avoid_processor(processor_t processor, thread_t thread);
+
 const struct sched_dispatch_table sched_multiq_dispatch = {
        .sched_name                                     = "multiq",
        .init                                           = sched_multiq_init,
@@ -319,6 +322,20 @@ const struct sched_dispatch_table sched_multiq_dispatch = {
        .direct_dispatch_to_idle_processors             = FALSE,
        .multiple_psets_enabled                         = FALSE,
        .sched_groups_enabled                           = TRUE,
+       .avoid_processor_enabled                        = TRUE,
+       .thread_avoid_processor                         = sched_multiq_thread_avoid_processor,
+       .processor_balance                              = sched_SMT_balance,
+
+       .rt_runq                                        = sched_rtglobal_runq,
+       .rt_init                                        = sched_rtglobal_init,
+       .rt_queue_shutdown                              = sched_rtglobal_queue_shutdown,
+       .rt_runq_scan                                   = sched_rtglobal_runq_scan,
+       .rt_runq_count_sum                              = sched_rtglobal_runq_count_sum,
+
+       .qos_max_parallelism                            = sched_qos_max_parallelism,
+       .check_spill                                    = sched_check_spill,
+       .ipi_policy                                     = sched_ipi_policy,
+       .thread_should_yield                            = sched_thread_should_yield,
 };
 
 
@@ -1183,6 +1200,10 @@ sched_multiq_processor_csw_check(processor_t processor)
        boolean_t       has_higher;
        int             pri;
 
+       if (sched_multiq_thread_avoid_processor(processor, current_thread())) {
+               return (AST_PREEMPT | AST_URGENT);
+       }
+
        entry_queue_t main_entryq = multiq_main_entryq(processor);
        run_queue_t   bound_runq  = multiq_bound_runq(processor);
 
@@ -1218,9 +1239,6 @@ sched_multiq_processor_queue_has_priority(
        run_queue_t main_runq  = multiq_main_entryq(processor);
        run_queue_t bound_runq = multiq_bound_runq(processor);
 
-       if (main_runq->count == 0 && bound_runq->count == 0)
-               return FALSE;
-
        int qpri = MAX(main_runq->highq, bound_runq->highq);
 
        if (gte)
@@ -1458,4 +1476,21 @@ sched_multiq_thread_update_scan(sched_update_scan_context_t scan_context)
        } while (restart_needed);
 }
 
+extern int sched_allow_rt_smt;
+
+/* Return true if this thread should not continue running on this processor */
+static bool
+sched_multiq_thread_avoid_processor(processor_t processor, thread_t thread)
+{
+       if (processor->processor_primary != processor) {
+               /*
+                * This is a secondary SMT processor.  If the primary is running
+                * a realtime thread, only allow realtime threads on the secondary.
+                */
+               if ((processor->processor_primary->current_pri >= BASEPRI_RTQUEUES) && ((thread->sched_pri < BASEPRI_RTQUEUES) || !sched_allow_rt_smt)) {
+                       return true;
+               }
+       }
 
+       return false;
+}