Mimic what is done for CPU binding.
---
 kern/sched_prim.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/kern/sched_prim.c b/kern/sched_prim.c
index 605f7001..ad6fe6cb 100644
--- a/kern/sched_prim.c
+++ b/kern/sched_prim.c
@@ -550,7 +550,9 @@ static thread_t thread_select(
                            (thread->processor_set == pset) &&
 #endif /* MACH_HOST */
                            ((thread->bound_processor == PROCESSOR_NULL) ||
-                            (thread->bound_processor == myprocessor))) {
+                            (thread->bound_processor == myprocessor)) &&
+                           ((thread->has_affinity == FALSE) ||
+                            cpu_affinity_test(&thread->affinity, 
myprocessor->slot_num))) {
 
                                simple_unlock(&pset->runq.lock);
                                thread_lock(thread);
@@ -1264,7 +1266,7 @@ void thread_setrun(
         */
        if ((processor = th->bound_processor) == PROCESSOR_NULL) {
            /*
-            *  Not bound, any processor in the processor set is ok.
+            *  Not bound.
             */
            pset = th->processor_set;
 #if    HW_FOOTPRINT
@@ -1279,7 +1281,8 @@ void thread_setrun(
 #if    MACH_HOST
                        && (processor->processor_set == pset)
 #endif /* MACH_HOST */
-                       ) {
+                       && ((th->has_affinity == FALSE) ||
+                           cpu_affinity_test(&th->affinity, 
processor->slot_num))) {
                            queue_remove(&pset->idle_queue, processor,
                                processor_t, processor_queue);
                            pset->idle_count--;
@@ -1299,7 +1302,17 @@ void thread_setrun(
            if (pset->idle_count > 0) {
                pset_idle_lock();
                if (pset->idle_count > 0) {
-                   processor = (processor_t) queue_first(&pset->idle_queue);
+                   if (th->has_affinity == FALSE) {
+                       processor = (processor_t) 
queue_first(&pset->idle_queue);
+                   } else {
+                       queue_iterate(&pset->idle_queue, processor, 
processor_t, processor_queue) {
+                           if (cpu_affinity_test(&th->affinity, 
processor->slot_num)) {
+                               goto found_idle_processor;
+                           }
+                       }
+                       goto no_idle_processor;
+                   }
+found_idle_processor:
                    queue_remove(&(pset->idle_queue), processor, processor_t,
                                processor_queue);
                    pset->idle_count--;
@@ -1310,6 +1323,7 @@ void thread_setrun(
                        cause_ast_check(processor);
                    return;
                }
+no_idle_processor:
                pset_idle_unlock();
            }
            rq = &(pset->runq);
-- 
2.53.0


Reply via email to