diff --git a/Makefile b/Makefile index 9fd44e5..25f1af2 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,13 @@ ifneq ($(OS),Windows_NT) arch := $(shell uname -m) ifeq ($(arch), x86_64) SRC_DIR=src/x86/ - SOURCE += $(COMMON_SRC) $(SRC_DIR)cpuid.c $(SRC_DIR)apic.c $(SRC_DIR)cpuid_asm.c $(SRC_DIR)uarch.c + SOURCE += $(COMMON_SRC) $(SRC_DIR)cpuid.c $(SRC_DIR)apic.c $(SRC_DIR)cpuid_asm.c $(SRC_DIR)uarch.c HEADERS += $(COMMON_HDR) $(SRC_DIR)cpuid.h $(SRC_DIR)apic.h $(SRC_DIR)cpuid_asm.h $(SRC_DIR)uarch.h CXXFLAGS += -DARCH_X86 else SRC_DIR=src/arm/ - SOURCE += $(COMMON_SRC) $(SRC_DIR)midr.c $(SRC_DIR)uarch.c - HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h + SOURCE += $(COMMON_SRC) $(SRC_DIR)midr.c $(SRC_DIR)uarch.c $(SRC_DIR)soc.c + HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_DIR)soc.h CXXFLAGS += -DARCH_ARM -Wno-unused-parameter endif diff --git a/src/arm/midr.c b/src/arm/midr.c index ee9924f..b4782b2 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -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) { diff --git a/src/arm/soc.c b/src/arm/soc.c new file mode 100644 index 0000000..f55687e --- /dev/null +++ b/src/arm/soc.c @@ -0,0 +1,55 @@ +#include +#include +#include + +#include "soc.h" + +#define STRING_UNKNOWN "Unknown" + +#ifdef __ANDROID__ +#include + +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; +} diff --git a/src/arm/soc.h b/src/arm/soc.h new file mode 100644 index 0000000..caa1620 --- /dev/null +++ b/src/arm/soc.h @@ -0,0 +1,10 @@ +#ifndef __SOC__ +#define __SOC__ + +struct system_on_chip { + char* raw_name; +}; + +struct system_on_chip* get_soc(); + +#endif diff --git a/src/common/cpu.h b/src/common/cpu.h index 05a28bb..57d783b 100644 --- a/src/common/cpu.h +++ b/src/common/cpu.h @@ -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