[v1.02][x86] Small fixes to hybrid core detection

This commit is contained in:
Dr-Noob
2022-11-05 18:28:10 +00:00
parent 1eb1a5246e
commit 77510c260a
4 changed files with 16 additions and 12 deletions

View File

@@ -151,6 +151,10 @@ struct cpuInfo {
// the next_cpu field // the next_cpu field
struct cpuInfo* next_cpu; struct cpuInfo* next_cpu;
uint8_t num_cpus; uint8_t num_cpus;
#ifdef ARCH_X86
// The index of the first core in the module
uint32_t first_core_id;
#endif
#endif #endif
}; };

View File

@@ -151,7 +151,7 @@ int get_total_cores_module(int total_cores, int module) {
return false; 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; 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; 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_id;
uint32_t* apic_ids = emalloc(sizeof(uint32_t) * topo->total_cores_module); uint32_t* apic_ids = emalloc(sizeof(uint32_t) * topo->total_cores_module);
uint32_t* apic_pkg = 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; return false;
} }
// TODO: Fix this
int first_core = 0;
if(module == 1) first_core = 16;
get_cache_topology_from_apic(topo); 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; return false;
for(int i=0; i < topo->total_cores_module; i++) { for(int i=0; i < topo->total_cores_module; i++) {

View File

@@ -14,7 +14,7 @@ struct apic {
uint32_t* cache_id_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); uint32_t is_smt_enabled_amd(struct topology* topo);
#ifndef __APPLE__ #ifndef __APPLE__

View File

@@ -354,7 +354,7 @@ struct features* get_features_info(struct cpuInfo* cpu) {
return feat; 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) { if(total_modules > 1) {
// We have a hybrid architecture. // We have a hybrid architecture.
// 1. Find the first core from module m // 1. Find the first core from module m
@@ -390,7 +390,9 @@ bool set_cpu_module(int m, int total_modules) {
i++; 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 // 2. Now bind to that core
if(!bind_to_cpu(core_id)) { if(!bind_to_cpu(core_id)) {
return false; return false;
@@ -469,7 +471,8 @@ struct cpuInfo* get_cpu_info() {
struct cpuInfo* ptr = cpu; struct cpuInfo* ptr = cpu;
for(uint32_t i=0; i < modules; i++) { 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) { if(i > 0) {
ptr->next_cpu = emalloc(sizeof(struct cpuInfo)); ptr->next_cpu = emalloc(sizeof(struct cpuInfo));
@@ -487,6 +490,7 @@ struct cpuInfo* get_cpu_info() {
ptr->hybrid_flag = cpu->hybrid_flag; ptr->hybrid_flag = cpu->hybrid_flag;
} }
ptr->first_core_id = first_core;
ptr->feat = get_features_info(ptr); ptr->feat = get_features_info(ptr);
// If any field of the struct is NULL, // 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) { switch(cpu->cpu_vendor) {
case CPU_VENDOR_INTEL: case CPU_VENDOR_INTEL:
if (cpu->maxLevels >= 0x00000004) { if (cpu->maxLevels >= 0x00000004) {
bool toporet = get_topology_from_apic(cpu, topo, module); bool toporet = get_topology_from_apic(cpu, topo);
if(!toporet) { if(!toporet) {
#ifdef __linux__ #ifdef __linux__
printWarn("Failed to retrieve topology from APIC, using udev...\n"); printWarn("Failed to retrieve topology from APIC, using udev...\n");