mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[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:
@@ -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(¤tCPU);
|
||||
CPU_SET(cpu_id, ¤tCPU);
|
||||
if (sched_setaffinity (0, sizeof(currentCPU), ¤tCPU) == -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(¤tCPU);
|
||||
CPU_SET(cpu_id, ¤tCPU);
|
||||
if(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), ¤tCPU) == -1) {
|
||||
perror("cpuset_setaffinity");
|
||||
printWarn("cpuset_setaffinity: %s", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user