diff --git a/abseil-cpp.spec b/abseil-cpp.spec index 64e9c3e7fbc7dbd43854f03266b9c70540230717..fc9111ac447c9e7ed477bc4293ae30c130caf3bb 100644 --- a/abseil-cpp.spec +++ b/abseil-cpp.spec @@ -7,7 +7,7 @@ Name: abseil-cpp # autofdo ships another copy of abseil-cpp, please keep it sync with this repo Version: 20250814.1 -Release: 1 +Release: 2 Summary: C++ Common Libraries License: Apache-2.0 @@ -16,6 +16,7 @@ Source0: https://github.com/abseil/abseil-cpp/archive/%{version}/%{name}- Patch1: abseil-cpp-20210324.2-sw.patch Patch100: 0001-add-loongarch-suopport-for-abseil-cpp.patch +Patch101: backport-identify-numcpus-on-linux.patch BuildRequires: cmake ninja-build BuildRequires: gcc-c++ @@ -161,6 +162,9 @@ Development headers for %{name} %{_libdir}/pkgconfig/*.pc %changelog +* Fri Nov 14 2025 shaojiansong - 20250814.1-2 +- Use possible CPUs to identify NumCPUs() on Linux, correctly handles offlined CPUs. + * Mon Oct 06 2025 Funda Wang - 20250814.1-1 - update to 20250814.1 diff --git a/backport-identify-numcpus-on-linux.patch b/backport-identify-numcpus-on-linux.patch new file mode 100644 index 0000000000000000000000000000000000000000..d870ac799f95dbc95b4319f003ff2891108a4ce4 --- /dev/null +++ b/backport-identify-numcpus-on-linux.patch @@ -0,0 +1,98 @@ +Origin Commit: https://github.com/abseil/abseil-cpp/commit/f040e96b93dba46e8ed3ca59c0444cbd6c0a0955 +From f040e96b93dba46e8ed3ca59c0444cbd6c0a0955 Mon Sep 17 00:00:00 2001 +From: Chris Kennelly +Date: Tue, 2 Sep 2025 12:11:25 -0700 +Subject: [PATCH] Use possible CPUs to identify NumCPUs() on Linux. + +This correctly handles offlined CPUs. + +PiperOrigin-RevId: 802241608 +Change-Id: Idad363516ed3b6027aa2656f3dbc3ee48fc50308 +--- + absl/base/internal/sysinfo.cc | 65 +++++++++++++++++++++++++++++++++++ + 1 file changed, 65 insertions(+) + +diff --git a/absl/base/internal/sysinfo.cc b/absl/base/internal/sysinfo.cc +index 1937db30796..6ac406eff69 100644 +--- a/absl/base/internal/sysinfo.cc ++++ b/absl/base/internal/sysinfo.cc +@@ -135,6 +135,69 @@ int Win32NumCPUs() { + + #endif + ++#if defined(__linux__) ++// Kinda like perror, but without allocating. At least, mostly... ++void PerrorNoAlloc(const char* msg) { ++ // strerror might allocate, theoretically. In practice, it doesn't do so on ++ // glibc unless you provide an invalid errno, and never allocates on musl. ++ char *errmsg = strerror(errno); ++ ++ // snprintf isn't technically on the async-signal-safe list, but, in practice, ++ // it doesn't allocate. ++ char buf[1024]; ++ int len = snprintf(buf, sizeof(buf), "%s: %s\n", msg, errmsg); ++ if (len > 0) { ++ if ((unsigned)len > sizeof(buf)) len = sizeof(buf); ++ ABSL_ATTRIBUTE_UNUSED auto ret = write(2, buf, static_cast(len)); ++ } ++} ++ ++// Returns the number of possible cpus by parsing a sysfs string. ++int ParseSysFsPossibleCPUs(const char* str, size_t len) { ++ if (len == 0) return 1; ++ // Find the last number in the line and parse that -- that'll be the highest ++ // cpu number. ++ for (int i = static_cast(len - 1); i >= 0; --i) { ++ if (!isdigit(str[i])) return atoi(&str[i+1]) + 1; // NOLINT ++ } ++ return atoi(str) + 1; // NOLINT ++} ++ ++int GetNumPossibleCpusFromSysfs() { ++ // The "possible" file exists since Linux 2.6.26. ++ // ++ // It contains a value such as "0-127" (meaning you have 128 CPUs, numbered 0 ++ // through 127). The format used here also supports strings like: "0,2,4-7" to ++ // describe discontiguous ids, but that cannot actually happen here, since ++ // "possible" CPU numbers are always contiguous from 0 to the maximum. ++ int fd; ++ do { ++ fd = open("/sys/devices/system/cpu/possible", O_RDONLY | O_CLOEXEC); ++ } while (fd < 0 && errno == EINTR); ++ ++ if (fd < 0) { ++ PerrorNoAlloc("GetNumPossibleCpusFromSysfs: open() failed"); ++ abort(); ++ } ++ ++ char buf[1024]; ++ ssize_t len; ++ do { ++ len = read(fd, buf, sizeof(buf) - 1); ++ } while (len < 0 && errno == EINTR); ++ ++ if (len <= 0) { ++ PerrorNoAlloc("GetNumPossibleCpusFromSysfs: read() failed"); ++ abort(); ++ } ++ close(fd); ++ ++ if (buf[len - 1] == '\n') --len; ++ buf[len] = '\0'; ++ return ParseSysFsPossibleCPUs(buf, static_cast(len)); ++} ++#endif ++ + } // namespace + + static int GetNumCPUs() { +@@ -145,6 +208,8 @@ static int GetNumCPUs() { + return hardware_concurrency ? hardware_concurrency : 1; + #elif defined(_AIX) + return sysconf(_SC_NPROCESSORS_ONLN); ++#elif defined(__linux__) ++ return GetNumPossibleCpusFromSysfs(); + #else + // Other possibilities: + // - Read /sys/devices/system/cpu/online and use cpumask_parse() +