diff --git a/src/common/cpu.h b/src/common/cpu.h index f2fb41c..b386d7c 100644 --- a/src/common/cpu.h +++ b/src/common/cpu.h @@ -151,6 +151,10 @@ struct cpuInfo { // the next_cpu field struct cpuInfo* next_cpu; uint8_t num_cpus; +#ifdef ARCH_X86 + // The index of the first core in the module + uint32_t first_core_id; +#endif #endif }; diff --git a/src/x86/apic.c b/src/x86/apic.c index 865a9e3..2d9ecf7 100644 --- a/src/x86/apic.c +++ b/src/x86/apic.c @@ -151,7 +151,7 @@ int get_total_cores_module(int total_cores, int module) { return false; } - printf("Module %d has %d cores\n", module, cores_in_module); + //printf("Module %d has %d cores\n", module, cores_in_module); return cores_in_module; } @@ -395,7 +395,7 @@ bool fill_apic_ids(uint32_t* apic_ids, int first_core, int n, bool x2apic_id) { return true; } -bool get_topology_from_apic(struct cpuInfo* cpu, struct topology* topo, int module) { +bool get_topology_from_apic(struct cpuInfo* cpu, struct topology* topo) { uint32_t apic_id; uint32_t* apic_ids = emalloc(sizeof(uint32_t) * topo->total_cores_module); uint32_t* apic_pkg = emalloc(sizeof(uint32_t) * topo->total_cores_module); @@ -436,13 +436,9 @@ bool get_topology_from_apic(struct cpuInfo* cpu, struct topology* topo, int modu return false; } - // TODO: Fix this - int first_core = 0; - if(module == 1) first_core = 16; - get_cache_topology_from_apic(topo); - if(!fill_apic_ids(apic_ids, first_core, topo->total_cores_module, x2apic_id)) + if(!fill_apic_ids(apic_ids, cpu->first_core_id, topo->total_cores_module, x2apic_id)) return false; for(int i=0; i < topo->total_cores_module; i++) { diff --git a/src/x86/apic.h b/src/x86/apic.h index 51891f6..98b6337 100644 --- a/src/x86/apic.h +++ b/src/x86/apic.h @@ -14,7 +14,7 @@ struct apic { uint32_t* cache_id_apic; }; -bool get_topology_from_apic(struct cpuInfo* cpu, struct topology* topo, int module); +bool get_topology_from_apic(struct cpuInfo* cpu, struct topology* topo); uint32_t is_smt_enabled_amd(struct topology* topo); #ifndef __APPLE__ diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index 5863454..73c1b42 100644 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -354,7 +354,7 @@ struct features* get_features_info(struct cpuInfo* cpu) { return feat; } -bool set_cpu_module(int m, int total_modules) { +bool set_cpu_module(int m, int total_modules, int32_t* first_core) { if(total_modules > 1) { // We have a hybrid architecture. // 1. Find the first core from module m @@ -390,7 +390,9 @@ bool set_cpu_module(int m, int total_modules) { i++; } - printf("Module %d: Core %d\n", m, core_id); + *first_core = core_id; + + //printf("Module %d: Core %d\n", m, core_id); // 2. Now bind to that core if(!bind_to_cpu(core_id)) { return false; @@ -469,7 +471,8 @@ struct cpuInfo* get_cpu_info() { struct cpuInfo* ptr = cpu; for(uint32_t i=0; i < modules; i++) { - set_cpu_module(i, modules); + int32_t first_core; + set_cpu_module(i, modules, &first_core); if(i > 0) { ptr->next_cpu = emalloc(sizeof(struct cpuInfo)); @@ -487,6 +490,7 @@ struct cpuInfo* get_cpu_info() { ptr->hybrid_flag = cpu->hybrid_flag; } + ptr->first_core_id = first_core; ptr->feat = get_features_info(ptr); // If any field of the struct is NULL, @@ -633,7 +637,7 @@ struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, int switch(cpu->cpu_vendor) { case CPU_VENDOR_INTEL: if (cpu->maxLevels >= 0x00000004) { - bool toporet = get_topology_from_apic(cpu, topo, module); + bool toporet = get_topology_from_apic(cpu, topo); if(!toporet) { #ifdef __linux__ printWarn("Failed to retrieve topology from APIC, using udev...\n");