-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[benchmark] Sync a few commits from upstream to help with CPU count #126410
Conversation
@llvm/pr-subscribers-third-party-benchmark Author: Brad Smith (brad0) ChangesTry to use the _SC_NPROCESSORS_ONLN sysconf elsewhere (cherry picked from commit edb1e76d8cb080a396c7c992e5d4023e1a777bd1) Replace usage of deprecated sysctl on macOS Retrieve the number of online CPUs on OpenBSD and NetBSD (cherry picked from commit 41e81b1ca4bbb41d234f2d0f2c56591db78ebb83) Full diff: https://github.com/llvm/llvm-project/pull/126410.diff 1 Files Affected:
diff --git a/third-party/benchmark/src/sysinfo.cc b/third-party/benchmark/src/sysinfo.cc
index 8283a081ee80b4a..1bd61b6c259b515 100644
--- a/third-party/benchmark/src/sysinfo.cc
+++ b/third-party/benchmark/src/sysinfo.cc
@@ -160,11 +160,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;
}
@@ -482,27 +482,14 @@ std::string GetSystemName() {
}
int GetNumCPUsImpl() {
-#ifdef BENCHMARK_HAS_SYSCTL
- int num_cpu = -1;
- if (GetSysctl("hw.ncpu", &num_cpu)) return num_cpu;
- PrintErrorAndDie("Err: ", strerror(errno));
-#elif defined(BENCHMARK_OS_WINDOWS)
+#ifdef BENCHMARK_OS_WINDOWS
SYSTEM_INFO sysinfo;
// Use memset as opposed to = {} to avoid GCC missing initializer false
// positives.
std::memset(&sysinfo, 0, sizeof(SYSTEM_INFO));
GetSystemInfo(&sysinfo);
- return sysinfo.dwNumberOfProcessors; // number of logical
- // processors in the current
- // group
-#elif defined(__linux__) || defined(BENCHMARK_OS_SOLARIS)
- // Returns -1 in case of a failure.
- int num_cpu = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
- if (num_cpu < 0) {
- PrintErrorAndDie("sysconf(_SC_NPROCESSORS_ONLN) failed with error: ",
- strerror(errno));
- }
- return num_cpu;
+ // number of logical processors in the current group
+ return static_cast<int>(sysinfo.dwNumberOfProcessors);
#elif defined(BENCHMARK_OS_QNX)
return static_cast<int>(_syspage_ptr->num_cpu);
#elif defined(BENCHMARK_OS_QURT)
@@ -511,6 +498,26 @@ int GetNumCPUsImpl() {
hardware_threads.max_hthreads = 1;
}
return hardware_threads.max_hthreads;
+#elif defined(BENCHMARK_HAS_SYSCTL)
+ int num_cpu = -1;
+ constexpr auto* hwncpu =
+#if defined BENCHMARK_OS_MACOSX
+ "hw.logicalcpu";
+#elif defined(HW_NCPUONLINE)
+ "hw.ncpuonline";
+#else
+ "hw.ncpu";
+#endif
+ if (GetSysctl(hwncpu, &num_cpu)) return num_cpu;
+ PrintErrorAndDie("Err: ", strerror(errno));
+#elif defined(_SC_NPROCESSORS_ONLN)
+ // Returns -1 in case of a failure.
+ int num_cpu = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
+ if (num_cpu < 0) {
+ PrintErrorAndDie("sysconf(_SC_NPROCESSORS_ONLN) failed with error: ",
+ strerror(errno));
+ }
+ return num_cpu;
#endif
BENCHMARK_UNREACHABLE();
}
|
Try to use the _SC_NPROCESSORS_ONLN sysconf elsewhere (cherry picked from commit edb1e76d8cb080a396c7c992e5d4023e1a777bd1) Replace usage of deprecated sysctl on macOS (cherry picked from commit faaa266d33ff203e28b31dd31be9f90c29f28d04) Retrieve the number of online CPUs on OpenBSD and NetBSD (cherry picked from commit 41e81b1ca4bbb41d234f2d0f2c56591db78ebb83) Update error message now that /proc/cpuinfo is no longer in use (cherry picked from commit c35af58b61daa111c93924e0e7b65022871fadac) Fix runtime crash when parsing /proc/cpuinfo fails (cherry picked from commit 39be87d3004ff9ff4cdf736651af80c3d15e2497) another reversal of something that breaks on wasm (cherry picked from commit 44507bc91ff9a23ad8ad4120cfc6b0d9bd27e2ca)
…lvm#126410) Try to use the _SC_NPROCESSORS_ONLN sysconf elsewhere (cherry picked from commit edb1e76d8cb080a396c7c992e5d4023e1a777bd1) Replace usage of deprecated sysctl on macOS (cherry picked from commit faaa266d33ff203e28b31dd31be9f90c29f28d04) Retrieve the number of online CPUs on OpenBSD and NetBSD (cherry picked from commit 41e81b1ca4bbb41d234f2d0f2c56591db78ebb83) Update error message now that /proc/cpuinfo is no longer in use (cherry picked from commit c35af58b61daa111c93924e0e7b65022871fadac) Fix runtime crash when parsing /proc/cpuinfo fails (cherry picked from commit 39be87d3004ff9ff4cdf736651af80c3d15e2497) another reversal of something that breaks on wasm (cherry picked from commit 44507bc91ff9a23ad8ad4120cfc6b0d9bd27e2ca)
Try to use the _SC_NPROCESSORS_ONLN sysconf elsewhere
(cherry picked from commit edb1e76d8cb080a396c7c992e5d4023e1a777bd1)
Replace usage of deprecated sysctl on macOS
(cherry picked from commit faaa266d33ff203e28b31dd31be9f90c29f28d04)
Retrieve the number of online CPUs on OpenBSD and NetBSD
(cherry picked from commit 41e81b1ca4bbb41d234f2d0f2c56591db78ebb83)
Update error message now that /proc/cpuinfo is no longer in use
(cherry picked from commit c35af58b61daa111c93924e0e7b65022871fadac)
Fix runtime crash when parsing /proc/cpuinfo fails
(cherry picked from commit 39be87d3004ff9ff4cdf736651af80c3d15e2497)
another reversal of something that breaks on wasm
(cherry picked from commit 44507bc91ff9a23ad8ad4120cfc6b0d9bd27e2ca)