diff --git a/src/common/printer.c b/src/common/printer.c index b7a7604..4ca4699 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -12,6 +12,7 @@ #include "../x86/uarch.h" #include "../x86/cpuid.h" #elif ARCH_PPC + #include "../ppc/uarch.h" #include "../ppc/ppc.h" #else #include "../arm/uarch.h" @@ -564,9 +565,8 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) { if(art == NULL) return false; - /*char* uarch = get_str_uarch(cpu); + char* uarch = get_str_uarch(cpu); char* manufacturing_process = get_str_process(cpu); - */ char* sockets = get_str_sockets(cpu->topo); // char* max_frequency = get_str_freq(cpu->freq); char* n_cores = get_str_topology(cpu, cpu->topo, false); @@ -584,10 +584,10 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) { /* if(cpu->hv->present) { setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name); - } + }*/ setAttribute(art,ATTRIBUTE_UARCH,uarch); setAttribute(art,ATTRIBUTE_TECHNOLOGY,manufacturing_process); - setAttribute(art,ATTRIBUTE_FREQUENCY,max_frequency);*/ + //setAttribute(art,ATTRIBUTE_FREQUENCY,max_frequency); uint32_t socket_num = get_nsockets(cpu->topo); if (socket_num > 1) { setAttribute(art, ATTRIBUTE_SOCKETS, sockets); diff --git a/src/ppc/ppc.c b/src/ppc/ppc.c index 9317cc9..4216b62 100644 --- a/src/ppc/ppc.c +++ b/src/ppc/ppc.c @@ -118,6 +118,7 @@ struct cpuInfo* get_cpu_info() { cpu->cpu_name = malloc(sizeof(char) * strlen(STRING_UNKNOWN) + 1); snprintf(cpu->cpu_name, strlen(STRING_UNKNOWN) + 1, STRING_UNKNOWN); + cpu->arch = get_uarch_from_auxval(cpu); cpu->cach = get_cache_info(cpu); cpu->topo = get_topology_info(cpu, cpu->cach); diff --git a/src/ppc/uarch.c b/src/ppc/uarch.c index 865aa10..e3e7b13 100644 --- a/src/ppc/uarch.c +++ b/src/ppc/uarch.c @@ -1,7 +1,91 @@ -struct uarch { - int d; +#include +#include +#include +#include +#include +#include +#include + +#include "uarch.h" +#include "../common/global.h" + +typedef uint32_t MICROARCH; + +#define STRING_UNKNOWN "Unknown" + +// Data not available +#define NA -1 + +// Unknown manufacturing process +#define UNK -1 + +enum { + UARCH_UNKNOWN, + UARCH_POWER9 }; -void free_uarch_struct(struct uarch* arch) { +struct uarch { + MICROARCH uarch; + char* uarch_str; + int32_t process; // measured in nanometers +}; +#define UARCH_START if (false) {} +#define CHECK_UARCH(arch, auxv_plat_ret, auxv_plat, str, uarch, process) \ + else if (strcmp(auxv_plat_ret, auxv_plat) == 0) fill_uarch(arch, str, uarch, process); +#define UARCH_END else { printBug("Unknown microarchitecture detected: '%s'", platform); fill_uarch(arch, "Unknown", UARCH_UNKNOWN, 0); } + +void fill_uarch(struct uarch* arch, char* str, MICROARCH u, uint32_t process) { + arch->uarch_str = malloc(sizeof(char) * (strlen(str)+1)); + strcpy(arch->uarch_str, str); + arch->uarch = u; + arch->process= process; +} + +struct uarch* get_uarch_from_auxval() { + struct uarch* arch = malloc(sizeof(struct uarch)); + + unsigned long ret = getauxval(AT_PLATFORM); + if(ret == 0 && errno == ENOENT) { + printErr("Entry AT_PLATFORM not found in getauxval"); + perror("getauxval"); + } + + char* platform = (char *) ret; + + UARCH_START + CHECK_UARCH(arch, platform, "power9", "POWER 9", UARCH_POWER9, 14) + UARCH_END + + return arch; +} + +char* get_str_uarch(struct cpuInfo* cpu) { + return cpu->arch->uarch_str; +} + +char* get_str_process(struct cpuInfo* cpu) { + char* str = malloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1)); + int32_t process = cpu->arch->process; + + if(process == UNK) { + snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN); + } + else if(process > 100) { + sprintf(str, "%.2fum", (double)process/100); + } + else if(process > 0){ + sprintf(str, "%dnm", process); + } + else { + snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN); + printBug("Found invalid process: '%d'", process); + } + + return str; +} + +void free_uarch_struct(struct uarch* arch) { + free(arch->uarch_str); + free(arch); } diff --git a/src/ppc/uarch.h b/src/ppc/uarch.h index 0fa2d44..585409a 100644 --- a/src/ppc/uarch.h +++ b/src/ppc/uarch.h @@ -1,6 +1,13 @@ #ifndef __UARCH__ #define __UARCH__ +#include "ppc.h" + +struct uarch; + +struct uarch* get_uarch_from_auxval(); +char* get_str_uarch(struct cpuInfo* cpu); +char* get_str_process(struct cpuInfo* cpu); void free_uarch_struct(struct uarch* arch); #endif