Skip to content

Commit

Permalink
Retrieve the number of online CPUs on OpenBSD and NetBSD (#1916)
Browse files Browse the repository at this point in the history
* Retrieve the number of online CPUs on OpenBSD and NetBSD

* Spacing adjustment

---------

Co-authored-by: dominic <[email protected]>
  • Loading branch information
brad0 and dmah42 authored Feb 6, 2025
1 parent 47bc26c commit 41e81b1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 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,13 @@ std::string GetSystemName() {
int GetNumCPUsImpl() {
#ifdef BENCHMARK_HAS_SYSCTL
int num_cpu = -1;
if (GetSysctl("hw.ncpu", &num_cpu)) return num_cpu;
constexpr auto* hwncpu =
#ifdef HW_NCPUONLINE
"hw.ncpuonline";
#else
"hw.ncpu";
#endif
if (GetSysctl(hwncpu, &num_cpu)) return num_cpu;
PrintErrorAndDie("Err: ", strerror(errno));
#elif defined(BENCHMARK_OS_WINDOWS)
SYSTEM_INFO sysinfo;
Expand Down

0 comments on commit 41e81b1

Please sign in to comment.