Skip to content

Commit e114bde

Browse files
committed
Complete topology read in AMD
1 parent 7164409 commit e114bde

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

src/apic.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,19 @@ bool get_topology_from_apic(uint32_t cpuid_max_levels, struct topology** topo) {
243243

244244
return ret;
245245
}
246+
247+
// Used by AMD
248+
uint32_t is_smt_enabled(struct topology* topo) {
249+
uint32_t id;
250+
251+
for(int i = 0; i < topo->total_cores; i++) {
252+
if(!bind_to_cpu(i)) {
253+
printErr("Failed binding to CPU %d", i);
254+
return false;
255+
}
256+
id = get_apic_id(true) & 1; // get the last bit
257+
if(id == 1) return 2; // We assume there isn't any AMD CPU with more than 2th per core
258+
}
259+
260+
return 1;
261+
}

src/apic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ struct apic {
1313
};
1414

1515
bool get_topology_from_apic(uint32_t cpuid_max_levels, struct topology** topo);
16+
uint32_t is_smt_enabled(struct topology* topo);
1617

1718
#endif

src/args.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ bool parse_args(int argc, char* argv[]) {
173173
}
174174
args.style = parse_style(optarg);
175175
if(args.style == STYLE_INVALID) {
176-
printErr("Invalid style '%s'\n",optarg);
176+
printErr("Invalid style '%s'",optarg);
177177
return false;
178178
}
179179
}

src/cpuid.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,25 +315,29 @@ struct topology* get_topology_info(struct cpuInfo* cpu) {
315315
}
316316
else {
317317
printWarn("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", 0x8000001E, cpu->maxExtendedLevels);
318-
topo->smt_supported = 1;
319-
topo->smt_available = 1;
320-
}
321-
topo->physical_cores = topo->logical_cores / topo->smt_available;
318+
topo->smt_supported = 1;
319+
}
322320
}
323321
else {
324-
printWarn("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", 0x80000008, cpu->maxExtendedLevels);
322+
printErr("Can't read topology information from cpuid (needed extended level is 0x%.8X, max is 0x%.8X)", 0x80000008, cpu->maxExtendedLevels);
325323
topo->physical_cores = 1;
326324
topo->logical_cores = 1;
327-
topo->smt_supported = 1;
328-
topo->smt_available = 1;
325+
topo->smt_supported = 1;
329326
}
330327
if (cpu->maxLevels >= 0x0000000B) {
331-
//topo->smt_supported = is_smt_enabled(topo);
328+
topo->smt_available = is_smt_enabled(topo);
332329
}
333330
else {
334-
printWarn("Can't read topology information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x80000008, cpu->maxLevels);
335-
topo->smt_supported = 1;
331+
printWarn("Can't read topology information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x0000000B, cpu->maxLevels);
332+
topo->smt_available = 1;
336333
}
334+
topo->physical_cores = topo->logical_cores / topo->smt_available;
335+
336+
if(topo->smt_supported > 1)
337+
topo->sockets = topo->total_cores / topo->smt_supported / topo->physical_cores; // Idea borrowed from lscpu
338+
else
339+
topo->sockets = topo->total_cores / topo->physical_cores;
340+
337341
break;
338342
default:
339343
printBug("Cant get topology because VENDOR is empty");
@@ -760,7 +764,7 @@ char* get_str_cache_two(int32_t cache_size, uint32_t physical_cores) {
760764
printBug("get_value_as_smallest_unit: snprintf returned a negative value for input: %d\n", cache_size * physical_cores);
761765
return NULL;
762766
}
763-
767+
764768
uint32_t size = tmp1_len + 2 + tmp2_len + 7 + 1;
765769
sanity_ret = snprintf(string, size, "%s (%s Total)", tmp1, tmp2);
766770

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "cpuid.h"
77
#include "global.h"
88

9-
static const char* VERSION = "0.59";
9+
static const char* VERSION = "0.510";
1010

1111
void print_help(char *argv[]) {
1212
printf("Usage: %s [--version] [--help] [--levels] [--style fancy|retro|legacy] [--color 'R,G,B:R,G,B:R,G,B:R,G,B']\n\

0 commit comments

Comments
 (0)