[v0.98][Refactoring] Simplify x86 get_str_topology

This commit is contained in:
Dr-Noob
2021-08-07 10:27:41 +02:00
parent 2e08b10652
commit fba69daee0

View File

@@ -702,42 +702,30 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
} }
// STRING FUNCTIONS // STRING FUNCTIONS
// TODO: Refactoring
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket) { char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket) {
int topo_sockets = dual_socket ? topo->sockets : 1;
char* string; char* string;
if(topo->smt_supported > 1) { if(topo->smt_supported > 1) {
//3 for digits, 21 for ' cores (SMT disabled)' which is the longest possible output // 4 for digits, 21 for ' cores (SMT disabled)' which is the longest possible output
uint32_t size = 3+21+1; uint32_t max_size = 4+21+1;
string = emalloc(sizeof(char)*size); string = emalloc(sizeof(char) * max_size);
if(dual_socket) {
if(topo->smt_available > 1) if(topo->smt_available > 1)
snprintf(string, size, "%d cores (%d threads)",topo->physical_cores * topo->sockets, topo->logical_cores * topo->sockets); snprintf(string, max_size, "%d cores (%d threads)", topo->physical_cores * topo_sockets, topo->logical_cores * topo_sockets);
else { else {
if(cpu->cpu_vendor == CPU_VENDOR_AMD) if(cpu->cpu_vendor == CPU_VENDOR_AMD)
snprintf(string, size, "%d cores (SMT disabled)",topo->physical_cores * topo->sockets); snprintf(string, max_size, "%d cores (SMT disabled)", topo->physical_cores * topo_sockets);
else else
snprintf(string, size, "%d cores (HT disabled)",topo->physical_cores * topo->sockets); snprintf(string, max_size, "%d cores (HT disabled)", topo->physical_cores * topo_sockets);
} }
} }
else { else {
if(topo->smt_available > 1) uint32_t max_size = 4+7+1;
snprintf(string, size, "%d cores (%d threads)",topo->physical_cores,topo->logical_cores); string = emalloc(sizeof(char) * max_size);
else { snprintf(string, max_size, "%d cores",topo->physical_cores * topo_sockets);
if(cpu->cpu_vendor == CPU_VENDOR_AMD)
snprintf(string, size, "%d cores (SMT disabled)",topo->physical_cores);
else
snprintf(string, size, "%d cores (HT disabled)",topo->physical_cores);
}
}
}
else {
uint32_t size = 3+7+1;
string = emalloc(sizeof(char)*size);
if(dual_socket)
snprintf(string, size, "%d cores",topo->physical_cores * topo->sockets);
else
snprintf(string, size, "%d cores",topo->physical_cores);
} }
return string; return string;
} }