[v0.88][ARM] Add very basic SoC detection (Android only)

This commit is contained in:
Dr-Noob
2020-11-23 18:29:15 +01:00
parent 8927048c95
commit eaa86522a4
5 changed files with 73 additions and 10 deletions

View File

@@ -8,6 +8,7 @@
#include "../common/global.h"
#include "midr.h"
#include "uarch.h"
#include "soc.h"
#define STRING_UNKNOWN "Unknown"
@@ -165,9 +166,7 @@ struct cpuInfo* get_cpu_info() {
cpu->num_cpus = sockets;
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);
cpu->soc = get_soc();
return cpu;
}
@@ -195,7 +194,7 @@ char* get_str_peak_performance(struct cpuInfo* cpu) {
}
}
double flops;
double flops = 0.0;
ptr = cpu;
for(int i=0; i < cpu->num_cpus; ptr = ptr->next_cpu, i++) {
@@ -213,7 +212,7 @@ char* get_str_peak_performance(struct cpuInfo* cpu) {
}
char* get_soc_name(struct cpuInfo* cpu) {
return cpu->soc_name;
return cpu->soc->raw_name;
}
void print_debug(struct cpuInfo* cpu) {

55
src/arm/soc.c Normal file
View File

@@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "soc.h"
#define STRING_UNKNOWN "Unknown"
#ifdef __ANDROID__
#include <sys/system_properties.h>
static inline int android_property_get(const char* key, char* value) {
return __system_property_get(key, value);
}
char* android_guess_soc() {
char* raw_name = NULL;
char tmp[100];
int property_len = 0;
property_len = android_property_get("ro.mediatek.platform", (char *) &tmp);
if(property_len > 0) {
raw_name = malloc(sizeof(char) * (property_len + 1));
strcpy(raw_name, tmp);
raw_name[property_len] = '\0';
return raw_name;
}
property_len = android_property_get("ro.product.board", (char *) &tmp);
if(property_len > 0) {
raw_name = malloc(sizeof(char) * (property_len + 1));
strcpy(raw_name, tmp);
raw_name[property_len] = '\0';
return raw_name;
}
return NULL;
}
#endif
struct system_on_chip* get_soc() {
struct system_on_chip* soc = malloc(sizeof(struct system_on_chip));
soc->raw_name = NULL;
#ifdef __ANDROID__
soc->raw_name = android_guess_soc();
#endif
if(soc->raw_name == NULL) {
soc->raw_name = malloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
snprintf(soc->raw_name, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
}
return soc;
}

10
src/arm/soc.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef __SOC__
#define __SOC__
struct system_on_chip {
char* raw_name;
};
struct system_on_chip* get_soc();
#endif

View File

@@ -124,8 +124,7 @@ struct cpuInfo {
#endif
#ifdef ARCH_ARM
VENDOR soc;
char* soc_name;
struct system_on_chip* soc;
// If SoC contains more than one CPU and they
// are different, the others will be stored in
// the next_cpu field