]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/cpu_topology.c
xnu-4570.71.2.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_topology.c
index 76a9e8edfe8f5c375ae486993f9bc22e431fb213..a4a460893cd2ad153ff3a0781d77bc0a9aeb95b2 100644 (file)
 #include <i386/cpu_topology.h>
 #include <i386/cpu_threads.h>
 #include <i386/machine_cpu.h>
 #include <i386/cpu_topology.h>
 #include <i386/cpu_threads.h>
 #include <i386/machine_cpu.h>
-#include <i386/lock.h>
+#include <i386/bit_routines.h>
 #include <i386/cpu_data.h>
 #include <i386/lapic.h>
 #include <i386/machine_routines.h>
 #include <i386/cpu_data.h>
 #include <i386/lapic.h>
 #include <i386/machine_routines.h>
+#include <stddef.h>
 
 __private_extern__ void qsort(
     void * array,
 
 __private_extern__ void qsort(
     void * array,
@@ -50,16 +51,28 @@ static x86_affinity_set_t *find_cache_affinity(x86_cpu_cache_t *L2_cachep);
 x86_affinity_set_t     *x86_affinities = NULL;
 static int             x86_affinity_count = 0;
 
 x86_affinity_set_t     *x86_affinities = NULL;
 static int             x86_affinity_count = 0;
 
+extern cpu_data_t cpshadows[];
+/* Re-sort double-mapped CPU data shadows after topology discovery sorts the
+ * primary CPU data structures by physical/APIC CPU ID.
+ */
+static void cpu_shadow_sort(int ncpus) {
+       for (int i = 0; i < ncpus; i++) {
+               cpu_data_t      *cpup = cpu_datap(i);
+               ptrdiff_t       coff = cpup - cpu_datap(0);
+
+               cpup->cd_shadow = &cpshadows[coff];
+       }
+}
+
 /*
 /*
- * cpu_topology_sort() is called after all processors have been registered
- * but before any non-boot processor id started.
- * We establish canonical logical processor numbering - logical cpus must be
- * contiguous, zero-based and assigned in physical (local apic id) order.
- * This step is required because the discovery/registration order is
- * non-deterministic - cores are registered in differing orders over boots.
- * Enforcing canonical numbering simplifies identification
- * of processors - in particular, for stopping/starting from CHUD.
- */ 
+ * cpu_topology_sort() is called after all processors have been registered but
+ * before any non-boot processor id started.  We establish canonical logical
+ * processor numbering - logical cpus must be contiguous, zero-based and
+ * assigned in physical (local apic id) order.  This step is required because
+ * the discovery/registration order is non-deterministic - cores are registered
+ * in differing orders over boots.  Enforcing canonical numbering simplifies
+ * identification of processors.
+ */
 void
 cpu_topology_sort(int ncpus)
 {
 void
 cpu_topology_sort(int ncpus)
 {
@@ -122,6 +135,7 @@ cpu_topology_sort(int ncpus)
                x86_set_logical_topology(&cpup->lcpu, cpup->cpu_phys_number, i);
        }
 
                x86_set_logical_topology(&cpup->lcpu, cpup->cpu_phys_number, i);
        }
 
+       cpu_shadow_sort(ncpus);
        x86_validate_topology();
 
        ml_set_interrupts_enabled(istate);
        x86_validate_topology();
 
        ml_set_interrupts_enabled(istate);
@@ -175,7 +189,7 @@ cpu_topology_sort(int ncpus)
                        if (lcpup->lnum == 0)
                                lprim = cpup->cpu_processor;
 
                        if (lcpup->lnum == 0)
                                lprim = cpup->cpu_processor;
 
-                       processor_meta_init(cpup->cpu_processor, lprim);
+                       processor_set_primary(cpup->cpu_processor, lprim);
                }
        }
 }
                }
        }
 }