mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.94] Refactor CPU features in a separate struct. Remove x86 debug functions
This commit is contained in:
@@ -119,35 +119,36 @@ uint32_t fill_ids_from_midr(uint32_t* midr_array, int32_t* freq_array, uint32_t*
|
||||
}
|
||||
|
||||
void init_cpu_info(struct cpuInfo* cpu) {
|
||||
cpu->NEON = false;
|
||||
cpu->AES = false;
|
||||
cpu->SHA1 = false;
|
||||
cpu->SHA2 = false;
|
||||
cpu->CRC32 = false;
|
||||
cpu->next_cpu = NULL;
|
||||
}
|
||||
|
||||
// We assume all cpus share the same hardware
|
||||
// capabilities but I'm not sure it is always
|
||||
// true...
|
||||
void fill_cpu_features(struct cpuInfo* cpu) {
|
||||
struct features* get_features_info() {
|
||||
struct features* feat = malloc(sizeof(struct features));
|
||||
bool *ptr = &(feat->AES);
|
||||
for(int i = 0; i < sizeof(struct features)/sizeof(bool); i++, *ptr++) {
|
||||
*ptr = false;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
long hwcaps = getauxval(AT_HWCAP);
|
||||
|
||||
if(errno == ENOENT) {
|
||||
printWarn("Unable to retrieve AT_HWCAP using getauxval");
|
||||
printWarn("Unable to retrieve AT_HWCAP using getauxval");
|
||||
}
|
||||
#ifdef __aarch64__
|
||||
else {
|
||||
cpu->AES = hwcaps & HWCAP_AES;
|
||||
cpu->CRC32 = hwcaps & HWCAP_CRC32;
|
||||
cpu->SHA1 = hwcaps & HWCAP_SHA1;
|
||||
cpu->SHA2 = hwcaps & HWCAP_SHA2;
|
||||
cpu->NEON = hwcaps & HWCAP_ASIMD;
|
||||
feat->AES = hwcaps & HWCAP_AES;
|
||||
feat->CRC32 = hwcaps & HWCAP_CRC32;
|
||||
feat->SHA1 = hwcaps & HWCAP_SHA1;
|
||||
feat->SHA2 = hwcaps & HWCAP_SHA2;
|
||||
feat->NEON = hwcaps & HWCAP_ASIMD;
|
||||
}
|
||||
#else
|
||||
else {
|
||||
cpu->NEON = hwcaps & HWCAP_NEON;
|
||||
feat->NEON = hwcaps & HWCAP_NEON;
|
||||
}
|
||||
|
||||
hwcaps = getauxval(AT_HWCAP2);
|
||||
@@ -155,12 +156,14 @@ void fill_cpu_features(struct cpuInfo* cpu) {
|
||||
printWarn("Unable to retrieve AT_HWCAP2 using getauxval");
|
||||
}
|
||||
else {
|
||||
cpu->AES = hwcaps & HWCAP2_AES;
|
||||
cpu->CRC32 = hwcaps & HWCAP2_CRC32;
|
||||
cpu->SHA1 = hwcaps & HWCAP2_SHA1;
|
||||
cpu->SHA2 = hwcaps & HWCAP2_SHA2;
|
||||
feat->AES = hwcaps & HWCAP2_AES;
|
||||
feat->CRC32 = hwcaps & HWCAP2_CRC32;
|
||||
feat->SHA1 = hwcaps & HWCAP2_SHA1;
|
||||
feat->SHA2 = hwcaps & HWCAP2_SHA2;
|
||||
}
|
||||
#endif
|
||||
|
||||
return feat;
|
||||
}
|
||||
|
||||
struct cpuInfo* get_cpu_info() {
|
||||
@@ -188,7 +191,6 @@ struct cpuInfo* get_cpu_info() {
|
||||
}
|
||||
}
|
||||
uint32_t sockets = fill_ids_from_midr(midr_array, freq_array, ids_array, ncores);
|
||||
fill_cpu_features(cpu);
|
||||
|
||||
struct cpuInfo* ptr = cpu;
|
||||
int midr_idx = 0;
|
||||
@@ -207,6 +209,7 @@ struct cpuInfo* get_cpu_info() {
|
||||
ptr->midr = midr_array[midr_idx];
|
||||
ptr->arch = get_uarch_from_midr(ptr->midr, ptr);
|
||||
|
||||
ptr->feat = get_features_info();
|
||||
ptr->freq = get_frequency_info(midr_idx);
|
||||
ptr->cach = get_cache_info(ptr);
|
||||
ptr->topo = get_topology_info(ptr, ptr->cach, midr_array, i, ncores);
|
||||
@@ -249,7 +252,7 @@ char* get_str_peak_performance(struct cpuInfo* cpu) {
|
||||
for(int i=0; i < cpu->num_cpus; ptr = ptr->next_cpu, i++) {
|
||||
flops += ptr->topo->total_cores * (get_freq(ptr->freq) * 1000000);
|
||||
}
|
||||
if(cpu->NEON) flops = flops * 4;
|
||||
if(cpu->feat->NEON) flops = flops * 4;
|
||||
|
||||
if(flops >= (double)1000000000000.0)
|
||||
snprintf(string,size,"%.2f TFLOP/s",flops/1000000000000);
|
||||
@@ -262,26 +265,27 @@ char* get_str_peak_performance(struct cpuInfo* cpu) {
|
||||
}
|
||||
|
||||
char* get_str_features(struct cpuInfo* cpu) {
|
||||
char* string = malloc(sizeof(char) * 100); //TODO: Fix
|
||||
struct features* feat = cpu->feat;
|
||||
char* string = malloc(sizeof(char) * 25);
|
||||
uint32_t len = 0;
|
||||
|
||||
if(cpu->NEON) {
|
||||
if(feat->NEON) {
|
||||
strcat(string, "NEON,");
|
||||
len += 5;
|
||||
}
|
||||
if(cpu->SHA1) {
|
||||
if(feat->SHA1) {
|
||||
strcat(string, "SHA1,");
|
||||
len += 5;
|
||||
}
|
||||
if(cpu->SHA2) {
|
||||
if(feat->SHA2) {
|
||||
strcat(string, "SHA2,");
|
||||
len += 5;
|
||||
}
|
||||
if(cpu->AES) {
|
||||
if(feat->AES) {
|
||||
strcat(string, "AES,");
|
||||
len += 4;
|
||||
}
|
||||
if(cpu->CRC32) {
|
||||
if(feat->CRC32) {
|
||||
strcat(string, "CRC32,");
|
||||
len += 6;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user