mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v0.88][ARM][BUGFIX] Fix some compilation issues
This commit is contained in:
@@ -128,13 +128,14 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
cpu->next_cpu = NULL;
|
cpu->next_cpu = NULL;
|
||||||
|
|
||||||
int ncores = get_ncores_from_cpuinfo();
|
int ncores = get_ncores_from_cpuinfo();
|
||||||
|
bool success = false;
|
||||||
uint32_t* midr_array = malloc(sizeof(uint32_t) * ncores);
|
uint32_t* midr_array = malloc(sizeof(uint32_t) * ncores);
|
||||||
uint32_t* ids_array = malloc(sizeof(uint32_t) * ncores);
|
uint32_t* ids_array = malloc(sizeof(uint32_t) * ncores);
|
||||||
|
|
||||||
for(int i=0; i < ncores; i++) {
|
for(int i=0; i < ncores; i++) {
|
||||||
midr_array[i] = get_midr_from_cpuinfo(i);
|
midr_array[i] = get_midr_from_cpuinfo(i, &success);
|
||||||
|
|
||||||
if(midr_array[i] == UNKNOWN) {
|
if(!success) {
|
||||||
printWarn("Unable to fetch MIDR for core %d. This is probably because the core is offline", i);
|
printWarn("Unable to fetch MIDR for core %d. This is probably because the core is offline", i);
|
||||||
midr_array[i] = midr_array[0];
|
midr_array[i] = midr_array[0];
|
||||||
}
|
}
|
||||||
@@ -217,14 +218,15 @@ char* get_soc_name(struct cpuInfo* cpu) {
|
|||||||
|
|
||||||
void print_debug(struct cpuInfo* cpu) {
|
void print_debug(struct cpuInfo* cpu) {
|
||||||
int ncores = get_ncores_from_cpuinfo();
|
int ncores = get_ncores_from_cpuinfo();
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
for(int i=0; i < ncores; i++) {
|
for(int i=0; i < ncores; i++) {
|
||||||
printf("[Core %d] ", i);
|
printf("[Core %d] ", i);
|
||||||
long freq = get_max_freq_from_file(i);
|
long freq = get_max_freq_from_file(i);
|
||||||
uint32_t midr = get_midr_from_cpuinfo(i);
|
uint32_t midr = get_midr_from_cpuinfo(i, &success);
|
||||||
if(midr == UNKNOWN) {
|
if(!success) {
|
||||||
printWarn("Unable to fetch MIDR for core %d. This is probably because the core is offline", i);
|
printWarn("Unable to fetch MIDR for core %d. This is probably because the core is offline", i);
|
||||||
printf("0x%.8X ", get_midr_from_cpuinfo(0));
|
printf("0x%.8X ", get_midr_from_cpuinfo(0, &success));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("0x%.8X ", midr);
|
printf("0x%.8X ", midr);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include "uarch.h"
|
#include "uarch.h"
|
||||||
#include "../common/global.h"
|
#include "../common/global.h"
|
||||||
|
|
||||||
|
#define STRING_UNKNOWN "Unknown"
|
||||||
|
|
||||||
// Data not available
|
// Data not available
|
||||||
#define NA -1
|
#define NA -1
|
||||||
|
|
||||||
@@ -276,8 +278,8 @@ char* get_str_uarch(struct cpuInfo* cpu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* get_str_process(struct cpuInfo* cpu) {
|
char* get_str_process(struct cpuInfo* cpu) {
|
||||||
char* str = malloc(sizeof(char) * (4+2+1));
|
char* str = malloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
|
||||||
sprintf(str, "%s", "Unknown");
|
snprintf(str, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -534,7 +534,8 @@ void print_ascii(struct ascii* art) {
|
|||||||
if(art->vendor == CPU_VENDOR_ARM)
|
if(art->vendor == CPU_VENDOR_ARM)
|
||||||
print_ascii_arm(art, longest_attribute);
|
print_ascii_arm(art, longest_attribute);
|
||||||
else {
|
else {
|
||||||
printBug("Invalid CPU vendor: %d\n", art->vendor);
|
printWarn("Invalid CPU vendor: %d\n", art->vendor);
|
||||||
|
print_ascii_arm(art, longest_attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -581,7 +582,7 @@ bool print_cpufetch_arm(struct ascii* art, struct cpuInfo* cpu, struct colors* c
|
|||||||
char* l2 = get_str_l2(ptr->cach);
|
char* l2 = get_str_l2(ptr->cach);
|
||||||
char* l3 = get_str_l3(ptr->cach);
|
char* l3 = get_str_l3(ptr->cach);
|
||||||
|
|
||||||
char* cpu_num = malloc(sizeof(char) * 6);
|
char* cpu_num = malloc(sizeof(char) * 9);
|
||||||
sprintf(cpu_num, "CPU %d:", i+1);
|
sprintf(cpu_num, "CPU %d:", i+1);
|
||||||
setAttribute(art, ATTRIBUTE_CPU_NUM, cpu_num);
|
setAttribute(art, ATTRIBUTE_CPU_NUM, cpu_num);
|
||||||
setAttribute(art, ATTRIBUTE_UARCH, uarch);
|
setAttribute(art, ATTRIBUTE_UARCH, uarch);
|
||||||
|
|||||||
@@ -164,12 +164,14 @@ long parse_cpuinfo_field(char* buf, char* field_str, int field_base) {
|
|||||||
}
|
}
|
||||||
// https://developer.arm.com/docs/ddi0595/h/aarch32-system-registers/midr
|
// https://developer.arm.com/docs/ddi0595/h/aarch32-system-registers/midr
|
||||||
// https://static.docs.arm.com/ddi0595/h/SysReg_xml_v86A-2020-06.pdf
|
// https://static.docs.arm.com/ddi0595/h/SysReg_xml_v86A-2020-06.pdf
|
||||||
uint32_t get_midr_from_cpuinfo(uint32_t core) {
|
uint32_t get_midr_from_cpuinfo(uint32_t core, bool* success) {
|
||||||
int fd = open(_PATH_CPUINFO, O_RDONLY);
|
int fd = open(_PATH_CPUINFO, O_RDONLY);
|
||||||
|
*success = true;
|
||||||
|
|
||||||
if(fd == -1) {
|
if(fd == -1) {
|
||||||
|
*success = false;
|
||||||
perror("open");
|
perror("open");
|
||||||
return UNKNOWN;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//File exists, read it
|
//File exists, read it
|
||||||
@@ -191,8 +193,10 @@ uint32_t get_midr_from_cpuinfo(uint32_t core) {
|
|||||||
tmp = strstr(tmp, CPUINFO_CPU_STRING);
|
tmp = strstr(tmp, CPUINFO_CPU_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL) {
|
||||||
return UNKNOWN;
|
*success = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t cpu_implementer;
|
uint32_t cpu_implementer;
|
||||||
uint32_t cpu_architecture;
|
uint32_t cpu_architecture;
|
||||||
@@ -204,30 +208,35 @@ uint32_t get_midr_from_cpuinfo(uint32_t core) {
|
|||||||
|
|
||||||
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_IMPLEMENTER_STR, 16)) < 0) {
|
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_IMPLEMENTER_STR, 16)) < 0) {
|
||||||
printf("Failed parsing cpu_implementer\n");
|
printf("Failed parsing cpu_implementer\n");
|
||||||
|
*success = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
cpu_implementer = (uint32_t) ret;
|
cpu_implementer = (uint32_t) ret;
|
||||||
|
|
||||||
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_ARCHITECTURE_STR, 10)) < 0) {
|
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_ARCHITECTURE_STR, 10)) < 0) {
|
||||||
printf("Failed parsing cpu_architecture\n");
|
printf("Failed parsing cpu_architecture\n");
|
||||||
|
*success = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
cpu_architecture = (uint32_t) 0xF; // Why?
|
cpu_architecture = (uint32_t) 0xF; // Why?
|
||||||
|
|
||||||
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_VARIANT_STR, 16)) < 0) {
|
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_VARIANT_STR, 16)) < 0) {
|
||||||
printf("Failed parsing cpu_variant\n");
|
printf("Failed parsing cpu_variant\n");
|
||||||
|
*success = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
cpu_variant = (uint32_t) ret;
|
cpu_variant = (uint32_t) ret;
|
||||||
|
|
||||||
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_PART_STR, 16)) < 0) {
|
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_PART_STR, 16)) < 0) {
|
||||||
printf("Failed parsing cpu_part\n");
|
printf("Failed parsing cpu_part\n");
|
||||||
|
*success = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
cpu_part = (uint32_t) ret;
|
cpu_part = (uint32_t) ret;
|
||||||
|
|
||||||
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_REVISION_STR, 10)) < 0) {
|
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_REVISION_STR, 10)) < 0) {
|
||||||
printf("Failed parsing cpu_revision\n");
|
printf("Failed parsing cpu_revision\n");
|
||||||
|
*success = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
cpu_revision = (uint32_t) ret;
|
cpu_revision = (uint32_t) ret;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define __UDEV__
|
#define __UDEV__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
long get_max_freq_from_file(uint32_t core);
|
long get_max_freq_from_file(uint32_t core);
|
||||||
long get_min_freq_from_file(uint32_t core);
|
long get_min_freq_from_file(uint32_t core);
|
||||||
@@ -9,7 +10,7 @@ long get_min_freq_from_file(uint32_t core);
|
|||||||
#ifdef ARCH_ARM
|
#ifdef ARCH_ARM
|
||||||
#define UNKNOWN -1
|
#define UNKNOWN -1
|
||||||
int get_ncores_from_cpuinfo();
|
int get_ncores_from_cpuinfo();
|
||||||
uint32_t get_midr_from_cpuinfo(uint32_t core);
|
uint32_t get_midr_from_cpuinfo(uint32_t core, bool* success);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user