mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
Complete topology read in AMD
This commit is contained in:
16
src/apic.c
16
src/apic.c
@@ -243,3 +243,19 @@ bool get_topology_from_apic(uint32_t cpuid_max_levels, struct topology** topo) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Used by AMD
|
||||
uint32_t is_smt_enabled(struct topology* topo) {
|
||||
uint32_t id;
|
||||
|
||||
for(int i = 0; i < topo->total_cores; i++) {
|
||||
if(!bind_to_cpu(i)) {
|
||||
printErr("Failed binding to CPU %d", i);
|
||||
return false;
|
||||
}
|
||||
id = get_apic_id(true) & 1; // get the last bit
|
||||
if(id == 1) return 2; // We assume there isn't any AMD CPU with more than 2th per core
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -13,5 +13,6 @@ struct apic {
|
||||
};
|
||||
|
||||
bool get_topology_from_apic(uint32_t cpuid_max_levels, struct topology** topo);
|
||||
uint32_t is_smt_enabled(struct topology* topo);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -173,7 +173,7 @@ bool parse_args(int argc, char* argv[]) {
|
||||
}
|
||||
args.style = parse_style(optarg);
|
||||
if(args.style == STYLE_INVALID) {
|
||||
printErr("Invalid style '%s'\n",optarg);
|
||||
printErr("Invalid style '%s'",optarg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
18
src/cpuid.c
18
src/cpuid.c
@@ -316,24 +316,28 @@ struct topology* get_topology_info(struct cpuInfo* cpu) {
|
||||
else {
|
||||
printWarn("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", 0x8000001E, cpu->maxExtendedLevels);
|
||||
topo->smt_supported = 1;
|
||||
topo->smt_available = 1;
|
||||
}
|
||||
topo->physical_cores = topo->logical_cores / topo->smt_available;
|
||||
}
|
||||
else {
|
||||
printWarn("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", 0x80000008, cpu->maxExtendedLevels);
|
||||
printErr("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", 0x80000008, cpu->maxExtendedLevels);
|
||||
topo->physical_cores = 1;
|
||||
topo->logical_cores = 1;
|
||||
topo->smt_supported = 1;
|
||||
topo->smt_available = 1;
|
||||
}
|
||||
if (cpu->maxLevels >= 0x0000000B) {
|
||||
//topo->smt_supported = is_smt_enabled(topo);
|
||||
topo->smt_available = is_smt_enabled(topo);
|
||||
}
|
||||
else {
|
||||
printWarn("Can't read topology information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x80000008, cpu->maxLevels);
|
||||
topo->smt_supported = 1;
|
||||
printWarn("Can't read topology information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x0000000B, cpu->maxLevels);
|
||||
topo->smt_available = 1;
|
||||
}
|
||||
topo->physical_cores = topo->logical_cores / topo->smt_available;
|
||||
|
||||
if(topo->smt_supported > 1)
|
||||
topo->sockets = topo->total_cores / topo->smt_supported / topo->physical_cores; // Idea borrowed from lscpu
|
||||
else
|
||||
topo->sockets = topo->total_cores / topo->physical_cores;
|
||||
|
||||
break;
|
||||
default:
|
||||
printBug("Cant get topology because VENDOR is empty");
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "cpuid.h"
|
||||
#include "global.h"
|
||||
|
||||
static const char* VERSION = "0.59";
|
||||
static const char* VERSION = "0.510";
|
||||
|
||||
void print_help(char *argv[]) {
|
||||
printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro|legacy] [--color 'R,G,B:R,G,B:R,G,B:R,G,B']\n\
|
||||
|
||||
Reference in New Issue
Block a user