Skip to content

Commit

Permalink
Retrieve the number of online CPUs on OpenBSD and NetBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
brad0 committed Feb 4, 2025
1 parent 4a805f9 commit 42d2ab4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/sysinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ ValueUnion GetSysctlImp(std::string const& name) {
int mib[2];

mib[0] = CTL_HW;
if ((name == "hw.ncpu") || (name == "hw.cpuspeed")) {
if ((name == "hw.ncpuonline") || (name == "hw.cpuspeed")) {
ValueUnion buff(sizeof(int));

if (name == "hw.ncpu") {
mib[1] = HW_NCPU;
if (name == "hw.ncpuonline") {
mib[1] = HW_NCPUONLINE;
} else {
mib[1] = HW_CPUSPEED;
}
Expand Down Expand Up @@ -482,7 +482,11 @@ std::string GetSystemName() {
int GetNumCPUsImpl() {
#ifdef BENCHMARK_HAS_SYSCTL
int num_cpu = -1;
#ifdef HW_NCPUONLINE
if (GetSysctl("hw.ncpuonline", &num_cpu)) return num_cpu;
#else
if (GetSysctl("hw.ncpu", &num_cpu)) return num_cpu;
#endif
PrintErrorAndDie("Err: ", strerror(errno));
#elif defined(BENCHMARK_OS_WINDOWS)
SYSTEM_INFO sysinfo;
Expand Down

0 comments on commit 42d2ab4

Please sign in to comment.