[v0.98][Refactoring] Use printWarn + strerror(errno) instead of perror. Use fallback in ppc in case total_cores cannot be retrieved

This commit is contained in:
Dr-Noob
2021-08-07 08:43:46 +02:00
parent c24dd7cbb6
commit 2b21326167
5 changed files with 19 additions and 21 deletions

View File

@@ -27,7 +27,7 @@ int get_ncores_from_cpuinfo() {
int filelen;
char* buf;
if((buf = read_file(_PATH_CPUS_PRESENT, &filelen)) == NULL) {
perror("open");
printWarn("read_file: %s: %s\n", _PATH_CPUS_PRESENT, strerror(errno));
return UNKNOWN;
}
@@ -50,7 +50,7 @@ int get_ncores_from_cpuinfo() {
errno = 0;
ncores = strtol(ncores_str, &end, 10) + 1;
if(errno != 0) {
perror("strtol");
printWarn("strtol: %s:\n", strerror(errno));
return UNKNOWN;
}
@@ -68,7 +68,7 @@ long parse_cpuinfo_field(char* buf, char* field_str, int field_base) {
errno = 0;
long ret = strtol(tmp, &end, field_base);
if(errno != 0) {
perror("strtol");
printWarn("strtol: %s:\n", strerror(errno));
return -1;
}
@@ -81,7 +81,7 @@ uint32_t get_midr_from_cpuinfo(uint32_t core, bool* success) {
char* buf;
*success = true;
if((buf = read_file(_PATH_CPUINFO, &filelen)) == NULL) {
perror("open");
printWarn("read_file: %s: %s\n", _PATH_CPUINFO, strerror(errno));
*success = false;
return 0;
}
@@ -108,35 +108,35 @@ uint32_t get_midr_from_cpuinfo(uint32_t core, bool* success) {
long ret;
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_IMPLEMENTER_STR, 16)) < 0) {
printf("Failed parsing cpu_implementer\n");
printBug("get_midr_from_cpuinfo: Failed parsing cpu_implementer\n");
*success = false;
return 0;
}
cpu_implementer = (uint32_t) ret;
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_ARCHITECTURE_STR, 10)) < 0) {
printf("Failed parsing cpu_architecture\n");
printBug("get_midr_from_cpuinfo: Failed parsing cpu_architecture\n");
*success = false;
return 0;
}
cpu_architecture = (uint32_t) 0xF; // Why?
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_VARIANT_STR, 16)) < 0) {
printf("Failed parsing cpu_variant\n");
printBug("get_midr_from_cpuinfo: Failed parsing cpu_variant\n");
*success = false;
return 0;
}
cpu_variant = (uint32_t) ret;
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_PART_STR, 16)) < 0) {
printf("Failed parsing cpu_part\n");
printBug("get_midr_from_cpuinfo: Failed parsing cpu_part\n");
*success = false;
return 0;
}
cpu_part = (uint32_t) ret;
if ((ret = parse_cpuinfo_field(tmp, CPUINFO_CPU_REVISION_STR, 10)) < 0) {
printf("Failed parsing cpu_revision\n");
printBug("get_midr_from_cpuinfo: Failed parsing cpu_revision\n");
*success = false;
return 0;
}
@@ -155,7 +155,7 @@ char* get_field_from_cpuinfo(char* CPUINFO_FIELD) {
int filelen;
char* buf;
if((buf = read_file(_PATH_CPUINFO, &filelen)) == NULL) {
perror("open");
printWarn("read_file: %s: %s:\n", _PATH_CPUINFO, strerror(errno));
return NULL;
}

View File

@@ -44,8 +44,7 @@ long get_freq_from_file(char* path, bool hv_present) {
errno = 0;
long ret = strtol(buf, &end, 10);
if(errno != 0) {
perror("strtol");
printBug("Failed parsing '%s' file. Read data was: '%s'", path, buf);
printBug("strtol: %s", strerror(errno));
free(buf);
return UNKNOWN_FREQ;
}
@@ -77,8 +76,7 @@ long get_cache_size_from_file(char* path) {
errno = 0;
long ret = strtol(buf, &end, 10);
if(errno != 0) {
perror("strtol");
printBug("Failed parsing '%s' file. Read data was: '%s'", path, buf);
printBug("strtol: %s", strerror(errno));
free(buf);
return -1;
}
@@ -146,8 +144,7 @@ int get_num_caches_from_files(char** paths, int num_paths) {
errno = 0;
long ret = strtol(buf, &end, 16);
if(errno != 0) {
perror("strtol");
printBug("Failed parsing '%s' file. Read data was: '%s'", paths[i], buf);
printBug("strtol: %s", strerror(errno));
free(buf);
return -1;
}

View File

@@ -50,8 +50,8 @@ struct topology* get_topology_info(struct cache* cach) {
// 1. Total cores detection
if((topo->total_cores = sysconf(_SC_NPROCESSORS_ONLN)) == -1) {
perror("sysconf");
return NULL;
printWarn("sysconf(_SC_NPROCESSORS_ONLN): %s", strerror(errno));
topo->total_cores = 1; // fallback
}
// To find physical cores, we use topo->total_cores and core_ids

View File

@@ -16,6 +16,7 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include "apic.h"
#include "cpuid_asm.h"
@@ -84,7 +85,7 @@ bool bind_to_cpu(int cpu_id) {
CPU_ZERO(&currentCPU);
CPU_SET(cpu_id, &currentCPU);
if (sched_setaffinity (0, sizeof(currentCPU), &currentCPU) == -1) {
perror("sched_setaffinity");
printWarn("sched_setaffinity: %s", strerror(errno));
return false;
}
return true;
@@ -93,7 +94,7 @@ bool bind_to_cpu(int cpu_id) {
CPU_ZERO(&currentCPU);
CPU_SET(cpu_id, &currentCPU);
if(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &currentCPU) == -1) {
perror("cpuset_setaffinity");
printWarn("cpuset_setaffinity: %s", strerror(errno));
return false;
}
return true;

View File

@@ -435,7 +435,7 @@ struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach) {
topo->total_cores = info.dwNumberOfProcessors;
#else
if((topo->total_cores = sysconf(_SC_NPROCESSORS_ONLN)) == -1) {
perror("sysconf");
printWarn("sysconf(_SC_NPROCESSORS_ONLN): %s", strerror(errno));
topo->total_cores = topo->logical_cores; // fallback
}
#endif