mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.81][ARM][Refactoring] Refactoring and very basic ARM support
This commit is contained in:
@@ -4,11 +4,15 @@
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../common/udev.h"
|
||||
#include "midr.h"
|
||||
|
||||
#define STRING_UNKNOWN "Unknown"
|
||||
|
||||
struct cpuInfo* get_cpu_info() {
|
||||
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
|
||||
|
||||
cpu->midr = get_midr_from_cpuinfo(0);
|
||||
cpu->cpu_vendor = CPU_VENDOR_UNKNOWN;
|
||||
cpu->cpu_name = malloc(sizeof(char) * CPU_NAME_MAX_LENGTH);
|
||||
strcpy(cpu->cpu_name, "Unknown");
|
||||
@@ -34,13 +38,13 @@ void init_cache_struct(struct cache* cach) {
|
||||
cach->L1d = malloc(sizeof(struct cach));
|
||||
cach->L2 = malloc(sizeof(struct cach));
|
||||
cach->L3 = malloc(sizeof(struct cach));
|
||||
|
||||
|
||||
cach->cach_arr = malloc(sizeof(struct cach*) * 4);
|
||||
cach->cach_arr[0] = cach->L1i;
|
||||
cach->cach_arr[1] = cach->L1d;
|
||||
cach->cach_arr[2] = cach->L2;
|
||||
cach->cach_arr[3] = cach->L3;
|
||||
|
||||
|
||||
cach->max_cache_level = 0;
|
||||
cach->L1i->exists = false;
|
||||
cach->L1d->exists = false;
|
||||
@@ -51,57 +55,72 @@ void init_cache_struct(struct cache* cach) {
|
||||
struct cache* get_cache_info(struct cpuInfo* cpu) {
|
||||
struct cache* cach = malloc(sizeof(struct cache));
|
||||
init_cache_struct(cach);
|
||||
|
||||
cach->max_cache_level = 2;
|
||||
for(int i=0; i < cach->max_cache_level + 1; i++) {
|
||||
cach->cach_arr[i]->exists = true;
|
||||
cach->cach_arr[i]->size = 0;
|
||||
}
|
||||
|
||||
return cach;
|
||||
}
|
||||
|
||||
struct frequency* get_frequency_info(struct cpuInfo* cpu) {
|
||||
struct frequency* get_frequency_info(struct cpuInfo* cpu) {
|
||||
struct frequency* freq = malloc(sizeof(struct frequency));
|
||||
|
||||
|
||||
freq->base = UNKNOWN_FREQ;
|
||||
freq->max = UNKNOWN_FREQ;
|
||||
|
||||
return freq;
|
||||
freq->max = get_max_freq_from_file();
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach) {
|
||||
struct topology* topo = malloc(sizeof(struct topology));
|
||||
struct topology* topo = malloc(sizeof(struct topology));
|
||||
init_topology_struct(topo, cach);
|
||||
|
||||
topo->total_cores = get_ncores_from_cpuinfo();
|
||||
topo->physical_cores = topo->total_cores;
|
||||
topo->logical_cores = topo->total_cores;
|
||||
topo->smt_available = 1;
|
||||
topo->smt_supported = 0;
|
||||
topo->sockets = 1;
|
||||
|
||||
return topo;
|
||||
}
|
||||
|
||||
VENDOR get_cpu_vendor(struct cpuInfo* cpu) {
|
||||
return cpu->cpu_vendor;
|
||||
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket) {
|
||||
uint32_t size = 3+7+1;
|
||||
char* string = malloc(sizeof(char)*size);
|
||||
snprintf(string, size, "%d cores", topo->physical_cores);
|
||||
|
||||
return string;
|
||||
}
|
||||
uint32_t get_nsockets(struct topology* topo) { return 0; }
|
||||
int64_t get_freq(struct frequency* freq) { return 0; }
|
||||
|
||||
char* get_str_cpu_name(struct cpuInfo* cpu) {
|
||||
return cpu->cpu_name;
|
||||
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq) {
|
||||
//7 for GFLOP/s and 6 for digits,eg 412.14
|
||||
uint32_t size = 7+6+1+1;
|
||||
assert(strlen(STRING_UNKNOWN)+1 <= size);
|
||||
char* string = malloc(sizeof(char)*size);
|
||||
|
||||
//First check we have consistent data
|
||||
if(freq == UNKNOWN_FREQ) {
|
||||
snprintf(string,strlen(STRING_UNKNOWN)+1,STRING_UNKNOWN);
|
||||
return string;
|
||||
}
|
||||
|
||||
double flops = topo->physical_cores * topo->sockets * (freq*1000000);
|
||||
|
||||
if(flops >= (double)1000000000000.0)
|
||||
snprintf(string,size,"%.2f TFLOP/s",flops/1000000000000);
|
||||
else if(flops >= 1000000000.0)
|
||||
snprintf(string,size,"%.2f GFLOP/s",flops/1000000000);
|
||||
else
|
||||
snprintf(string,size,"%.2f MFLOP/s",flops/1000000);
|
||||
|
||||
return string;
|
||||
}
|
||||
char* get_str_ncores(struct cpuInfo* cpu){ return NULL; }
|
||||
char* get_str_avx(struct cpuInfo* cpu){ char* tmp = malloc(sizeof(char) * 10); strcpy(tmp, "No"); return tmp; }
|
||||
char* get_str_sse(struct cpuInfo* cpu){ return NULL; }
|
||||
char* get_str_fma(struct cpuInfo* cpu){ char* tmp = malloc(sizeof(char) * 10); strcpy(tmp, "No"); return tmp; }
|
||||
char* get_str_aes(struct cpuInfo* cpu){ return NULL; }
|
||||
char* get_str_sha(struct cpuInfo* cpu){ return NULL; }
|
||||
|
||||
char* get_str_l1i(struct cache* cach){ char* tmp = malloc(sizeof(char) * 10); strcpy(tmp, "0 KB"); return tmp; }
|
||||
char* get_str_l1d(struct cache* cach){ char* tmp = malloc(sizeof(char) * 10); strcpy(tmp, "0 KB"); return tmp; }
|
||||
char* get_str_l2(struct cache* cach){ char* tmp = malloc(sizeof(char) * 10); strcpy(tmp, "0 KB"); return tmp; }
|
||||
char* get_str_l3(struct cache* cach){ char* tmp = malloc(sizeof(char) * 10); strcpy(tmp, "0 KB"); return tmp; }
|
||||
void free_topo_struct(struct topology* topo) {
|
||||
free(topo);
|
||||
}
|
||||
|
||||
char* get_str_freq(struct frequency* freq){ char* tmp = malloc(sizeof(char) * 10); strcpy(tmp, "0 MHz"); return tmp; }
|
||||
|
||||
char* get_str_sockets(struct topology* topo){ return NULL; }
|
||||
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket){ char* tmp = malloc(sizeof(char) * 10); strcpy(tmp, "0 cores"); return tmp; }
|
||||
|
||||
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq) { char* tmp = malloc(sizeof(char) * 10); strcpy(tmp, "0 MFLOP/s"); return tmp; }
|
||||
|
||||
void free_cache_struct(struct cache* cach){ }
|
||||
void free_topo_struct(struct topology* topo){ }
|
||||
void free_freq_struct(struct frequency* freq){ }
|
||||
void free_cpuinfo_struct(struct cpuInfo* cpu){ }
|
||||
|
||||
void debug_cpu_info(struct cpuInfo* cpu){ }
|
||||
void debug_cache(struct cache* cach){ }
|
||||
void debug_frequency(struct frequency* freq){ }
|
||||
|
||||
Reference in New Issue
Block a user