mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.98][PPC] Obtain microarchitecture using getauxval
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include "../x86/uarch.h"
|
#include "../x86/uarch.h"
|
||||||
#include "../x86/cpuid.h"
|
#include "../x86/cpuid.h"
|
||||||
#elif ARCH_PPC
|
#elif ARCH_PPC
|
||||||
|
#include "../ppc/uarch.h"
|
||||||
#include "../ppc/ppc.h"
|
#include "../ppc/ppc.h"
|
||||||
#else
|
#else
|
||||||
#include "../arm/uarch.h"
|
#include "../arm/uarch.h"
|
||||||
@@ -564,9 +565,8 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
|
|||||||
if(art == NULL)
|
if(art == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/*char* uarch = get_str_uarch(cpu);
|
char* uarch = get_str_uarch(cpu);
|
||||||
char* manufacturing_process = get_str_process(cpu);
|
char* manufacturing_process = get_str_process(cpu);
|
||||||
*/
|
|
||||||
char* sockets = get_str_sockets(cpu->topo);
|
char* sockets = get_str_sockets(cpu->topo);
|
||||||
// char* max_frequency = get_str_freq(cpu->freq);
|
// char* max_frequency = get_str_freq(cpu->freq);
|
||||||
char* n_cores = get_str_topology(cpu, cpu->topo, false);
|
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) {
|
if(cpu->hv->present) {
|
||||||
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
|
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
|
||||||
}
|
}*/
|
||||||
setAttribute(art,ATTRIBUTE_UARCH,uarch);
|
setAttribute(art,ATTRIBUTE_UARCH,uarch);
|
||||||
setAttribute(art,ATTRIBUTE_TECHNOLOGY,manufacturing_process);
|
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);
|
uint32_t socket_num = get_nsockets(cpu->topo);
|
||||||
if (socket_num > 1) {
|
if (socket_num > 1) {
|
||||||
setAttribute(art, ATTRIBUTE_SOCKETS, sockets);
|
setAttribute(art, ATTRIBUTE_SOCKETS, sockets);
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
cpu->cpu_name = malloc(sizeof(char) * strlen(STRING_UNKNOWN) + 1);
|
cpu->cpu_name = malloc(sizeof(char) * strlen(STRING_UNKNOWN) + 1);
|
||||||
snprintf(cpu->cpu_name, strlen(STRING_UNKNOWN) + 1, STRING_UNKNOWN);
|
snprintf(cpu->cpu_name, strlen(STRING_UNKNOWN) + 1, STRING_UNKNOWN);
|
||||||
|
|
||||||
|
cpu->arch = get_uarch_from_auxval(cpu);
|
||||||
cpu->cach = get_cache_info(cpu);
|
cpu->cach = get_cache_info(cpu);
|
||||||
cpu->topo = get_topology_info(cpu, cpu->cach);
|
cpu->topo = get_topology_info(cpu, cpu->cach);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,91 @@
|
|||||||
struct uarch {
|
#include <stdint.h>
|
||||||
int d;
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/auxv.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
#ifndef __UARCH__
|
#ifndef __UARCH__
|
||||||
#define __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);
|
void free_uarch_struct(struct uarch* arch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user