diff --git a/Makefile b/Makefile index 463e90d..dfad59a 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,8 @@ ifneq ($(OS),Windows_NT) else # Assume ARM SRC_DIR=src/arm/ - SOURCE += $(COMMON_SRC) $(SRC_DIR)midr.c $(SRC_DIR)uarch.c $(SRC_DIR)soc.c $(SRC_DIR)udev.c - HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_DIR)soc.h $(SRC_DIR)udev.c $(SRC_DIR)socs.h + 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 $(SRC_DIR)sysctl.h CFLAGS += -DARCH_ARM -Wno-unused-parameter -std=c99 endif diff --git a/src/arm/midr.c b/src/arm/midr.c index 6c0b5f3..16a2e08 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -7,7 +7,9 @@ #ifdef __linux__ #include - #include + #include +#elif defined __APPLE__ || __MACH__ + #include "sysctl.h" #endif #include "../common/global.h" @@ -232,7 +234,7 @@ void get_cpu_info_mach(struct cpuInfo* cpu) { cpu->cach = get_cache_info(cpu); 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->base = UNKNOWN_FREQ; cpu->freq->max = 1000000000; diff --git a/src/arm/sysctl.c b/src/arm/sysctl.c new file mode 100644 index 0000000..94f4a3f --- /dev/null +++ b/src/arm/sysctl.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +#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; +} + diff --git a/src/arm/sysctl.h b/src/arm/sysctl.h new file mode 100644 index 0000000..8d4bade --- /dev/null +++ b/src/arm/sysctl.h @@ -0,0 +1,6 @@ +#ifndef __SYSCTL__ +#define __SYSCTL__ + +struct topology* get_topology_from_sysctl(); + +#endif