mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.85][ARM] Add SoC field in ARM and remove CPU Name field, which is only valid in x86. Fix Makefile for some strict compilers
This commit is contained in:
@@ -87,6 +87,9 @@ struct cpuInfo* get_cpu_info() {
|
||||
|
||||
cpu->hv = malloc(sizeof(struct hypervisor));
|
||||
cpu->hv->present = false;
|
||||
cpu->soc = SOC_VENDOR_UNKNOWN;
|
||||
cpu->soc_name = malloc(sizeof(char)*(strlen(STRING_UNKNOWN)+1));
|
||||
snprintf(cpu->soc_name, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
||||
|
||||
return cpu;
|
||||
}
|
||||
@@ -188,6 +191,10 @@ char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64
|
||||
return string;
|
||||
}
|
||||
|
||||
char* get_soc_name(struct cpuInfo* cpu) {
|
||||
return cpu->soc_name;
|
||||
}
|
||||
|
||||
void free_topo_struct(struct topology* topo) {
|
||||
free(topo);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu);
|
||||
struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach);
|
||||
|
||||
uint32_t get_nsockets(struct topology* topo);
|
||||
char* get_soc_name(struct cpuInfo* cpu);
|
||||
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket);
|
||||
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ struct uarch {
|
||||
MICROARCH uarch;
|
||||
ISA isa;
|
||||
char* uarch_str;
|
||||
char* isa_str;
|
||||
// int32_t process; process depends on SoC
|
||||
};
|
||||
|
||||
@@ -154,14 +155,15 @@ static char* isas_string[] = {
|
||||
#define UARCH_END else { printBug("Unknown microarchitecture detected: IM=0x%.8X P=0x%.8X V=0x%.8X R=0x%.8X", im, p, v, r); fill_uarch(arch, cpu, "Unknown", UARCH_UNKNOWN, CPU_VENDOR_UNKNOWN); }
|
||||
|
||||
void fill_uarch(struct uarch* arch, struct cpuInfo* cpu, char* str, MICROARCH u, VENDOR vendor) {
|
||||
arch->uarch = u;
|
||||
arch->isa = isas_uarch[arch->uarch];
|
||||
cpu->cpu_vendor = vendor;
|
||||
|
||||
arch->uarch_str = malloc(sizeof(char) * (strlen(str)+1));
|
||||
strcpy(arch->uarch_str, str);
|
||||
arch->uarch = u;
|
||||
cpu->cpu_vendor = vendor;
|
||||
arch->isa = isas_uarch[arch->uarch];
|
||||
char* isa_str = isas_string[arch->isa];
|
||||
cpu->cpu_name = malloc(sizeof(char) * (strlen(isa_str)+1));
|
||||
strcpy(cpu->cpu_name, isa_str);
|
||||
|
||||
arch->isa_str = malloc(sizeof(char) * (strlen(isas_string[arch->isa])+1));
|
||||
strcpy(arch->isa_str, isas_string[arch->isa]);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -44,9 +44,11 @@ char* get_str_sockets(struct topology* topo) {
|
||||
return string;
|
||||
}
|
||||
|
||||
#ifdef ARCH_X86
|
||||
char* get_str_cpu_name(struct cpuInfo* cpu) {
|
||||
return cpu->cpu_name;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t get_value_as_smallest_unit(char ** str, uint32_t value) {
|
||||
int32_t sanity_ret;
|
||||
@@ -174,6 +176,8 @@ void free_hv_struct(struct hypervisor* hv) {
|
||||
void free_cpuinfo_struct(struct cpuInfo* cpu) {
|
||||
free_uarch_struct(cpu->arch);
|
||||
free_hv_struct(cpu->hv);
|
||||
#ifdef ARCH_X86
|
||||
free(cpu->cpu_name);
|
||||
#endif
|
||||
free(cpu);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@ enum {
|
||||
HV_VENDOR_INVALID
|
||||
};
|
||||
|
||||
enum {
|
||||
SOC_VENDOR_QUALCOMM,
|
||||
SOC_VENDOR_HUAWUEI,
|
||||
SOC_VENDOR_SAMSUNG,
|
||||
SOC_VENDOR_UNKNOWN
|
||||
};
|
||||
|
||||
#define UNKNOWN_FREQ -1
|
||||
#define CPU_NAME_MAX_LENGTH 64
|
||||
|
||||
@@ -67,11 +74,13 @@ struct cpuInfo {
|
||||
bool AES;
|
||||
bool SHA;
|
||||
|
||||
VENDOR cpu_vendor;
|
||||
|
||||
char* cpu_name;
|
||||
VENDOR cpu_vendor;
|
||||
struct uarch* arch;
|
||||
struct hypervisor* hv;
|
||||
|
||||
#ifdef ARCH_X86
|
||||
// CPU name from model
|
||||
char* cpu_name;
|
||||
// Max cpuids levels
|
||||
uint32_t maxLevels;
|
||||
// Max cpuids extended levels
|
||||
@@ -81,14 +90,13 @@ struct cpuInfo {
|
||||
uint32_t midr;
|
||||
#endif
|
||||
|
||||
struct uarch* arch;
|
||||
struct hypervisor* hv;
|
||||
|
||||
#ifdef ARCH_ARM
|
||||
VENDOR soc;
|
||||
char* soc_name;
|
||||
// If SoC contains more than one CPU and they
|
||||
// are different, the others will be stored in
|
||||
// the next_cpu field
|
||||
struct cpuInfo* next_cpu;
|
||||
struct cpuInfo* next_cpu;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -122,12 +130,15 @@ struct topology {
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef ARCH_X86
|
||||
char* get_str_cpu_name(struct cpuInfo* cpu);
|
||||
#endif
|
||||
|
||||
VENDOR get_cpu_vendor(struct cpuInfo* cpu);
|
||||
uint32_t get_nsockets(struct topology* topo);
|
||||
int64_t get_freq(struct frequency* freq);
|
||||
|
||||
char* get_str_sockets(struct topology* topo);
|
||||
char* get_str_cpu_name(struct cpuInfo* cpu);
|
||||
char* get_str_aes(struct cpuInfo* cpu);
|
||||
char* get_str_sha(struct cpuInfo* cpu);
|
||||
char* get_str_l1i(struct cache* cach);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "../arm/midr.h"
|
||||
#endif
|
||||
|
||||
static const char* VERSION = "0.84";
|
||||
static const char* VERSION = "0.85";
|
||||
|
||||
void print_help(char *argv[]) {
|
||||
#ifdef ARCH_X86
|
||||
|
||||
@@ -51,7 +51,11 @@
|
||||
#define RESET "\x1b[m"
|
||||
|
||||
enum {
|
||||
#ifdef ARCH_X86
|
||||
ATTRIBUTE_NAME,
|
||||
#elif ARCH_ARM
|
||||
ATTRIBUTE_SOC,
|
||||
#endif
|
||||
ATTRIBUTE_HYPERVISOR,
|
||||
ATTRIBUTE_UARCH,
|
||||
ATTRIBUTE_TECHNOLOGY,
|
||||
@@ -71,7 +75,11 @@ enum {
|
||||
};
|
||||
|
||||
static const char* ATTRIBUTE_FIELDS [] = {
|
||||
#ifdef ARCH_X86
|
||||
"Name:",
|
||||
#elif ARCH_ARM
|
||||
"SoC:",
|
||||
#endif
|
||||
"Hypervisor:",
|
||||
"Microarchitecture:",
|
||||
"Technology:",
|
||||
@@ -91,7 +99,11 @@ static const char* ATTRIBUTE_FIELDS [] = {
|
||||
};
|
||||
|
||||
static const int ATTRIBUTE_LIST[] = {
|
||||
#ifdef ARCH_X86
|
||||
ATTRIBUTE_NAME,
|
||||
#elif ARCH_ARM
|
||||
ATTRIBUTE_SOC,
|
||||
#endif
|
||||
ATTRIBUTE_HYPERVISOR,
|
||||
ATTRIBUTE_UARCH,
|
||||
ATTRIBUTE_TECHNOLOGY,
|
||||
@@ -381,6 +393,32 @@ void print_ascii_amd(struct ascii* art, uint32_t la) {
|
||||
|
||||
}
|
||||
|
||||
void print_ascii_arm(struct ascii* art, uint32_t la) {
|
||||
int attr_to_print = -1;
|
||||
uint32_t space_right;
|
||||
uint32_t space_up = (NUMBER_OF_LINES - art->n_attributes_set)/2;
|
||||
uint32_t space_down = NUMBER_OF_LINES - art->n_attributes_set - space_up;
|
||||
|
||||
printf("\n");
|
||||
for(uint32_t n=0;n<NUMBER_OF_LINES;n++) {
|
||||
for(int i=0;i<LINE_SIZE;i++) {
|
||||
if(art->art[n][i] == '#')
|
||||
printf("%s%c%s", art->color1_ascii, art->ascii_chars[0], art->reset);
|
||||
else
|
||||
printf("%c",art->art[n][i]);
|
||||
}
|
||||
|
||||
if(n > space_up-1 && n < NUMBER_OF_LINES-space_down) {
|
||||
attr_to_print = get_next_attribute(art, attr_to_print);
|
||||
space_right = 1 + (la - strlen(ATTRIBUTE_FIELDS[attr_to_print]));
|
||||
printf("%s%s%s%*s%s%s%s\n",art->color1_text, ATTRIBUTE_FIELDS[attr_to_print], art->reset, space_right, "", art->color2_text, art->attributes[attr_to_print], art->reset);
|
||||
}
|
||||
else printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
|
||||
uint32_t longest_attribute_length(struct ascii* art) {
|
||||
uint32_t max = 0;
|
||||
uint64_t len = 0;
|
||||
@@ -399,16 +437,20 @@ void print_ascii(struct ascii* art) {
|
||||
uint32_t longest_attribute = longest_attribute_length(art);
|
||||
if(art->vendor == CPU_VENDOR_INTEL)
|
||||
print_ascii_intel(art, longest_attribute);
|
||||
else
|
||||
else if(art->vendor == CPU_VENDOR_AMD)
|
||||
print_ascii_amd(art, longest_attribute);
|
||||
else if(art->vendor == CPU_VENDOR_ARM)
|
||||
print_ascii_arm(art, longest_attribute);
|
||||
else {
|
||||
printBug("Invalid CPU vendor: %d\n", art->vendor);
|
||||
}
|
||||
}
|
||||
|
||||
bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* freq, struct topology* topo, STYLE s, struct colors* cs) {
|
||||
struct ascii* art = set_ascii(get_cpu_vendor(cpu), s, cs);
|
||||
if(art == NULL)
|
||||
return false;
|
||||
|
||||
char* cpu_name = get_str_cpu_name(cpu);
|
||||
|
||||
char* uarch = get_str_uarch(cpu);
|
||||
char* manufacturing_process = get_str_process(cpu);
|
||||
char* sockets = get_str_sockets(topo);
|
||||
@@ -416,18 +458,22 @@ bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* f
|
||||
char* n_cores = get_str_topology(cpu, topo, false);
|
||||
char* n_cores_dual = get_str_topology(cpu, topo, true);
|
||||
#ifdef ARCH_X86
|
||||
char* cpu_name = get_str_cpu_name(cpu);
|
||||
char* avx = get_str_avx(cpu);
|
||||
char* fma = get_str_fma(cpu);
|
||||
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
|
||||
setAttribute(art,ATTRIBUTE_AVX,avx);
|
||||
setAttribute(art,ATTRIBUTE_FMA,fma);
|
||||
#elif ARCH_ARM
|
||||
char* soc_name = get_soc_name(cpu);
|
||||
setAttribute(art, ATTRIBUTE_SOC, soc_name);
|
||||
#endif
|
||||
char* l1i = get_str_l1i(topo->cach);
|
||||
char* l1d = get_str_l1d(topo->cach);
|
||||
char* l2 = get_str_l2(topo->cach);
|
||||
char* l3 = get_str_l3(topo->cach);
|
||||
char* pp = get_str_peak_performance(cpu,topo,get_freq(freq));
|
||||
|
||||
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
|
||||
|
||||
setAttribute(art,ATTRIBUTE_UARCH,uarch);
|
||||
setAttribute(art,ATTRIBUTE_TECHNOLOGY,manufacturing_process);
|
||||
setAttribute(art,ATTRIBUTE_FREQUENCY,max_frequency);
|
||||
|
||||
Reference in New Issue
Block a user