]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/cpu_threads.c
xnu-1486.2.11.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_threads.c
index 6d539ffb1942f426c8986858d09f65c864bb7274..d6c63c252850b3922b0c693eea0925ce374cd813 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2003-2008 Apple Inc. All rights reserved.
+ * Copyright (c) 2003-2009 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  */
 #include <vm/vm_kern.h>
 #include <kern/kalloc.h>
  */
 #include <vm/vm_kern.h>
 #include <kern/kalloc.h>
+#include <kern/etimer.h>
 #include <mach/machine.h>
 #include <i386/cpu_threads.h>
 #include <i386/cpuid.h>
 #include <i386/machine_cpu.h>
 #include <mach/machine.h>
 #include <i386/cpu_threads.h>
 #include <i386/cpuid.h>
 #include <i386/machine_cpu.h>
-#include <i386/lock.h>
-#include <i386/perfmon.h>
 #include <i386/pmCPU.h>
 #include <i386/pmCPU.h>
+#include <i386/lock.h>
 
 //#define TOPO_DEBUG           1
 #if TOPO_DEBUG
 
 //#define TOPO_DEBUG           1
 #if TOPO_DEBUG
@@ -43,8 +43,11 @@ void debug_topology_print(void);
 #define DBG(x...)
 #endif /* TOPO_DEBUG */
 
 #define DBG(x...)
 #endif /* TOPO_DEBUG */
 
+
 void validate_topology(void);
 
 void validate_topology(void);
 
+/* Only for 32bit values */
+#define bit(n)                 (1U << (n))
 #define bitmask(h,l)   ((bit(h)|(bit(h)-1)) & ~(bit(l)-1))
 #define bitfield(x,h,l)        (((x) & bitmask(h,l)) >> l)
 
 #define bitmask(h,l)   ((bit(h)|(bit(h)-1)) & ~(bit(l)-1))
 #define bitfield(x,h,l)        (((x) & bitmask(h,l)) >> l)
 
@@ -178,7 +181,8 @@ x86_LLC_info(void)
      */
     topoParms.maxSharingLLC = nCPUsSharing;
 
      */
     topoParms.maxSharingLLC = nCPUsSharing;
 
-    topoParms.nCoresSharingLLC = nCPUsSharing;
+    topoParms.nCoresSharingLLC = nCPUsSharing / (cpuinfo->thread_count /
+                                                cpuinfo->core_count);
     topoParms.nLCPUsSharingLLC = nCPUsSharing;
 
     /*
     topoParms.nLCPUsSharingLLC = nCPUsSharing;
 
     /*
@@ -239,6 +243,12 @@ initTopoParms(void)
     topoParms.nLThreadsPerPackage = topoParms.nLThreadsPerCore * topoParms.nLCoresPerPackage;
     topoParms.nPThreadsPerPackage = topoParms.nPThreadsPerCore * topoParms.nPCoresPerPackage;
 
     topoParms.nLThreadsPerPackage = topoParms.nLThreadsPerCore * topoParms.nLCoresPerPackage;
     topoParms.nPThreadsPerPackage = topoParms.nPThreadsPerCore * topoParms.nPCoresPerPackage;
 
+    DBG("\nCache Topology Parameters:\n");
+    DBG("\tLLC Depth:           %d\n", topoParms.LLCDepth);
+    DBG("\tCores Sharing LLC:   %d\n", topoParms.nCoresSharingLLC);
+    DBG("\tThreads Sharing LLC: %d\n", topoParms.nLCPUsSharingLLC);
+    DBG("\tmax Sharing of LLC:  %d\n", topoParms.maxSharingLLC);
+
     DBG("\nLogical Topology Parameters:\n");
     DBG("\tThreads per Core:  %d\n", topoParms.nLThreadsPerCore);
     DBG("\tCores per Die:     %d\n", topoParms.nLCoresPerDie);
     DBG("\nLogical Topology Parameters:\n");
     DBG("\tThreads per Core:  %d\n", topoParms.nLThreadsPerCore);
     DBG("\tCores per Die:     %d\n", topoParms.nLCoresPerDie);
@@ -314,6 +324,9 @@ x86_cache_list(void)
 
        cur->type = bitfield(cache_info[eax], 4, 0);
        cur->level = bitfield(cache_info[eax], 7, 5);
 
        cur->type = bitfield(cache_info[eax], 4, 0);
        cur->level = bitfield(cache_info[eax], 7, 5);
+       cur->nlcpus = (bitfield(cache_info[eax], 25, 14) + 1);
+       if (cpuid_info()->cpuid_model == 26)
+               cur->nlcpus /= cpu_is_hyperthreaded() ? 1 : 2;
        cur->maxcpus = (bitfield(cache_info[eax], 25, 14) + 1);
        cur->line_size = bitfield(cache_info[ebx], 11, 0) + 1;
        cur->partitions = bitfield(cache_info[ebx], 21, 12) + 1;
        cur->maxcpus = (bitfield(cache_info[eax], 25, 14) + 1);
        cur->line_size = bitfield(cache_info[ebx], 11, 0) + 1;
        cur->partitions = bitfield(cache_info[ebx], 21, 12) + 1;
@@ -340,7 +353,7 @@ static x86_cpu_cache_t *
 x86_match_cache(x86_cpu_cache_t *list, x86_cpu_cache_t *matcher)
 {
     x86_cpu_cache_t    *cur_cache;
 x86_match_cache(x86_cpu_cache_t *list, x86_cpu_cache_t *matcher)
 {
     x86_cpu_cache_t    *cur_cache;
-
     cur_cache = list;
     while (cur_cache != NULL) {
        if (cur_cache->maxcpus  == matcher->maxcpus
     cur_cache = list;
     while (cur_cache != NULL) {
        if (cur_cache->maxcpus  == matcher->maxcpus
@@ -861,13 +874,6 @@ cpu_thread_alloc(int cpu)
 
     x86_lcpu_init(cpu);
 
 
     x86_lcpu_init(cpu);
 
-     /*
-     * Allocate performance counter structure.
-     */
-    simple_unlock(&x86_topo_lock);
-    cpup->lcpu.pmc = pmc_alloc();
-    simple_lock(&x86_topo_lock);
-
     /*
      * Assume that all cpus have the same features.
      */
     /*
      * Assume that all cpus have the same features.
      */
@@ -1089,7 +1095,7 @@ validate_topology(void)
            /*
             * Make sure that the die has the correct number of cores.
             */
            /*
             * Make sure that the die has the correct number of cores.
             */
-           DBG("Die(%d)->cores: ");
+           DBG("Die(%d)->cores: ", die->pdie_num);
            nCores = 0;
            core = die->cores;
            while (core != NULL) {
            nCores = 0;
            core = die->cores;
            while (core != NULL) {
@@ -1160,7 +1166,7 @@ validate_topology(void)
             */
            nCPUs = 0;
            lcpu = core->lcpus;
             */
            nCPUs = 0;
            lcpu = core->lcpus;
-           DBG("Core(%d)->lcpus: ");
+           DBG("Core(%d)->lcpus: ", core->pcore_num);
            while (lcpu != NULL) {
                if (lcpu->core == NULL)
                    panic("CPU(%d)->core is NULL",
            while (lcpu != NULL) {
                if (lcpu->core == NULL)
                    panic("CPU(%d)->core is NULL",