[v1.03][RISCV] Add basic SoC detection backend

This commit is contained in:
Dr-Noob
2023-04-03 12:41:59 +02:00
parent 9a69a7f58d
commit 14819c350e
9 changed files with 229 additions and 13 deletions

View File

@@ -5,6 +5,7 @@
#include "../common/global.h"
#include "../common/udev.h"
#include "soc.h"
struct frequency* get_frequency_info(uint32_t core) {
struct frequency* freq = emalloc(sizeof(struct frequency));
@@ -15,23 +16,45 @@ struct frequency* get_frequency_info(uint32_t core) {
return freq;
}
int64_t get_peak_performance(struct cpuInfo* cpu) {
//First check we have consistent data
if(get_freq(cpu->freq) == UNKNOWN_DATA) {
return -1;
}
int64_t flops = cpu->topo->total_cores * (get_freq(cpu->freq) * 1000000);
return flops;
}
struct cpuInfo* get_cpu_info(void) {
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
//init_cpu_info(cpu);
int ncores = get_ncores_from_cpuinfo();
struct topology* topo = emalloc(sizeof(struct topology));
topo->total_cores = get_ncores_from_cpuinfo();
topo->cach = NULL;
cpu->topo = topo;
cpu->hv = emalloc(sizeof(struct hypervisor));
cpu->hv->present = false;
//cpu->soc = get_soc();
//cpu->peak_performance = get_peak_performance(cpu);
cpu->peak_performance = 0;
cpu->soc = get_soc();
cpu->freq = get_frequency_info(0);
cpu->cpu_vendor = CPU_VENDOR_RISCV;
cpu->peak_performance = get_peak_performance(cpu);
return cpu;
}
//TODO: Might be worth refactoring with other archs
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo) {
return "Many cores";
uint32_t size = 3+7+1;
char* string = emalloc(sizeof(char)*size);
snprintf(string, size, "%d cores", topo->total_cores);
return string;
}
char* get_str_features(struct cpuInfo* cpu) {
return NULL;
}
void print_debug(struct cpuInfo* cpu) {