mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-24 23:40:39 +01:00
[v0.88][ARM] Add very basic SoC detection (Android only)
This commit is contained in:
6
Makefile
6
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
|
||||
|
||||
|
||||
@@ -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
55
src/arm/soc.c
Normal 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
10
src/arm/soc.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef __SOC__
|
||||
#define __SOC__
|
||||
|
||||
struct system_on_chip {
|
||||
char* raw_name;
|
||||
};
|
||||
|
||||
struct system_on_chip* get_soc();
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user