mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v0.98][ARM] Add simple topology detection using sysctlbyname in macOS
This commit is contained in:
4
Makefile
4
Makefile
@@ -25,8 +25,8 @@ ifneq ($(OS),Windows_NT)
|
|||||||
else
|
else
|
||||||
# Assume ARM
|
# Assume ARM
|
||||||
SRC_DIR=src/arm/
|
SRC_DIR=src/arm/
|
||||||
SOURCE += $(COMMON_SRC) $(SRC_DIR)midr.c $(SRC_DIR)uarch.c $(SRC_DIR)soc.c $(SRC_DIR)udev.c
|
SOURCE += $(COMMON_SRC) $(SRC_DIR)midr.c $(SRC_DIR)uarch.c $(SRC_DIR)soc.c $(SRC_DIR)udev.c $(SRC_DIR)sysctl.c
|
||||||
HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_DIR)soc.h $(SRC_DIR)udev.c $(SRC_DIR)socs.h
|
HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_DIR)soc.h $(SRC_DIR)udev.c $(SRC_DIR)socs.h $(SRC_DIR)sysctl.h
|
||||||
CFLAGS += -DARCH_ARM -Wno-unused-parameter -std=c99
|
CFLAGS += -DARCH_ARM -Wno-unused-parameter -std=c99
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <sys/auxv.h>
|
#include <sys/auxv.h>
|
||||||
#include <asm/hwcap.h>
|
#include <asm/hwcap.h>
|
||||||
|
#elif defined __APPLE__ || __MACH__
|
||||||
|
#include "sysctl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../common/global.h"
|
#include "../common/global.h"
|
||||||
@@ -232,7 +234,7 @@ void get_cpu_info_mach(struct cpuInfo* cpu) {
|
|||||||
|
|
||||||
cpu->cach = get_cache_info(cpu);
|
cpu->cach = get_cache_info(cpu);
|
||||||
cpu->feat = get_features_info();
|
cpu->feat = get_features_info();
|
||||||
cpu->topo = malloc(sizeof(struct topology));
|
cpu->topo = get_topology_from_sysctl();
|
||||||
cpu->freq = malloc(sizeof(struct frequency));
|
cpu->freq = malloc(sizeof(struct frequency));
|
||||||
cpu->freq->base = UNKNOWN_FREQ;
|
cpu->freq->base = UNKNOWN_FREQ;
|
||||||
cpu->freq->max = 1000000000;
|
cpu->freq->max = 1000000000;
|
||||||
|
|||||||
25
src/arm/sysctl.c
Normal file
25
src/arm/sysctl.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "../common/global.h"
|
||||||
|
#include "../common/cpu.h"
|
||||||
|
|
||||||
|
struct topology* get_topology_from_sysctl() {
|
||||||
|
struct topology* t = malloc(sizeof(struct topology));
|
||||||
|
size_t dummy;
|
||||||
|
|
||||||
|
if(sysctlbyname("hw.physicalcpu_max", &t->total_cores, &dummy, NULL, 0) != 0) {
|
||||||
|
printWarn("sysctlbyname(\"hw.physicalcpu_max\") failed: %s\n", strerror(errno));
|
||||||
|
t->total_cores = 1;
|
||||||
|
}
|
||||||
|
else if(t->total_cores <= 0) {
|
||||||
|
printWarn("sysctlbyname(\"hw.physicalcpu_max\") returned invalid value: %d\n", t->total_cores);
|
||||||
|
t->total_cores = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
6
src/arm/sysctl.h
Normal file
6
src/arm/sysctl.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef __SYSCTL__
|
||||||
|
#define __SYSCTL__
|
||||||
|
|
||||||
|
struct topology* get_topology_from_sysctl();
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user