mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.87][ARM] cpuInfo now holds all the structs (freq, cache, etc), instead of having them separated. This allows ARM to represent a single CPU, because from its pointer, it is able to access the specific frequency, cache, etc
This commit is contained in:
161
src/arm/midr.c
161
src/arm/midr.c
@@ -10,6 +10,71 @@
|
||||
|
||||
#define STRING_UNKNOWN "Unknown"
|
||||
|
||||
void init_topology_struct(struct topology* topo, struct cache* cach) {
|
||||
topo->total_cores = 0;
|
||||
topo->physical_cores = 0;
|
||||
topo->logical_cores = 0;
|
||||
topo->smt_available = 0;
|
||||
topo->smt_supported = 0;
|
||||
topo->sockets = 0;
|
||||
topo->cach = cach;
|
||||
}
|
||||
|
||||
void init_cache_struct(struct cache* cach) {
|
||||
cach->L1i = malloc(sizeof(struct 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;
|
||||
cach->L2->exists = false;
|
||||
cach->L3->exists = false;
|
||||
}
|
||||
|
||||
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* freq = malloc(sizeof(struct frequency));
|
||||
|
||||
freq->base = UNKNOWN_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));
|
||||
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;
|
||||
}
|
||||
|
||||
int count_distinct(uint32_t* arr, int n) {
|
||||
int res = 1;
|
||||
|
||||
@@ -81,10 +146,16 @@ struct cpuInfo* get_cpu_info() {
|
||||
while(midr_array[midr_idx] == midr_array[tmp_midr_idx]) tmp_midr_idx++;
|
||||
midr_idx = tmp_midr_idx;
|
||||
}
|
||||
ptr->next_cpu = NULL;
|
||||
|
||||
ptr->midr = midr_array[midr_idx];
|
||||
ptr->arch = get_uarch_from_midr(ptr->midr, ptr);
|
||||
|
||||
ptr->freq = get_frequency_info(ptr);
|
||||
ptr->cach = get_cache_info(ptr);
|
||||
ptr->topo = get_topology_info(ptr, ptr->cach);
|
||||
}
|
||||
|
||||
|
||||
cpu->num_cpus = sockets;
|
||||
cpu->hv = malloc(sizeof(struct hypervisor));
|
||||
cpu->hv->present = false;
|
||||
@@ -95,71 +166,6 @@ struct cpuInfo* get_cpu_info() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
void init_topology_struct(struct topology* topo, struct cache* cach) {
|
||||
topo->total_cores = 0;
|
||||
topo->physical_cores = 0;
|
||||
topo->logical_cores = 0;
|
||||
topo->smt_available = 0;
|
||||
topo->smt_supported = 0;
|
||||
topo->sockets = 0;
|
||||
topo->cach = cach;
|
||||
}
|
||||
|
||||
void init_cache_struct(struct cache* cach) {
|
||||
cach->L1i = malloc(sizeof(struct 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;
|
||||
cach->L2->exists = false;
|
||||
cach->L3->exists = false;
|
||||
}
|
||||
|
||||
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* freq = malloc(sizeof(struct frequency));
|
||||
|
||||
freq->base = UNKNOWN_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));
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -168,20 +174,28 @@ char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_soc
|
||||
return string;
|
||||
}
|
||||
|
||||
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq) {
|
||||
char* get_str_peak_performance(struct cpuInfo* cpu) {
|
||||
//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);
|
||||
|
||||
struct cpuInfo* ptr = cpu;
|
||||
|
||||
//First check we have consistent data
|
||||
if(freq == UNKNOWN_FREQ) {
|
||||
snprintf(string,strlen(STRING_UNKNOWN)+1,STRING_UNKNOWN);
|
||||
return string;
|
||||
for(int i=0; i < cpu->num_cpus; ptr = ptr->next_cpu, i++) {
|
||||
if(get_freq(ptr->freq) == UNKNOWN_FREQ) {
|
||||
snprintf(string, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
double flops = topo->physical_cores * topo->sockets * (freq*1000000);
|
||||
|
||||
double flops;
|
||||
|
||||
ptr = 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(flops >= (double)1000000000000.0)
|
||||
snprintf(string,size,"%.2f TFLOP/s",flops/1000000000000);
|
||||
else if(flops >= 1000000000.0)
|
||||
@@ -215,4 +229,3 @@ void print_debug(struct cpuInfo* cpu) {
|
||||
void free_topo_struct(struct topology* topo) {
|
||||
free(topo);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ 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);
|
||||
char* get_str_peak_performance(struct cpuInfo* cpu);
|
||||
|
||||
void print_debug(struct cpuInfo* cpu);
|
||||
void free_topo_struct(struct topology* topo);
|
||||
|
||||
Reference in New Issue
Block a user