You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2022/08/09 08:51:56 UTC

[arrow] branch master updated: ARROW-17341: [C++] Fix cpu_info.cc build error on musl libc (#13819)

This is an automated email from the ASF dual-hosted git repository.

apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 3148884ed7 ARROW-17341: [C++] Fix cpu_info.cc build error on musl libc (#13819)
3148884ed7 is described below

commit 3148884ed74a824ac6acc341fa50baef45c46669
Author: Yibo Cai <yi...@arm.com>
AuthorDate: Tue Aug 9 16:51:49 2022 +0800

    ARROW-17341: [C++] Fix cpu_info.cc build error on musl libc (#13819)
    
    Authored-by: Yibo Cai <yi...@arm.com>
    Signed-off-by: Antoine Pitrou <pi...@free.fr>
---
 cpp/src/arrow/util/cpu_info.cc | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/cpp/src/arrow/util/cpu_info.cc b/cpp/src/arrow/util/cpu_info.cc
index 0faf1e6f85..fbe55aec0c 100644
--- a/cpp/src/arrow/util/cpu_info.cc
+++ b/cpp/src/arrow/util/cpu_info.cc
@@ -296,35 +296,31 @@ void OsRetrieveCpuInfo(int64_t* hardware_flags, CpuInfo::Vendor* vendor,
 //------------------------------ LINUX ------------------------------//
 // Get cache size, return 0 on error
 int64_t LinuxGetCacheSize(int level) {
-  const struct {
-    int sysconf_name;
-    const char* sysfs_path;
-  } kCacheSizeEntries[] = {
-      {
-          _SC_LEVEL1_DCACHE_SIZE,
-          "/sys/devices/system/cpu/cpu0/cache/index0/size",  // l1d (index1 is l1i)
-      },
-      {
-          _SC_LEVEL2_CACHE_SIZE,
-          "/sys/devices/system/cpu/cpu0/cache/index2/size",  // l2
-      },
-      {
-          _SC_LEVEL3_CACHE_SIZE,
-          "/sys/devices/system/cpu/cpu0/cache/index3/size",  // l3
-      },
+  // get cache size by sysconf()
+#ifdef _SC_LEVEL1_DCACHE_SIZE
+  const int kCacheSizeConf[] = {
+      _SC_LEVEL1_DCACHE_SIZE,
+      _SC_LEVEL2_CACHE_SIZE,
+      _SC_LEVEL3_CACHE_SIZE,
   };
-  static_assert(sizeof(kCacheSizeEntries) / sizeof(kCacheSizeEntries[0]) == kCacheLevels,
-                "");
+  static_assert(sizeof(kCacheSizeConf) / sizeof(kCacheSizeConf[0]) == kCacheLevels, "");
 
-  // get cache size by sysconf()
   errno = 0;
-  const int64_t cache_size = sysconf(kCacheSizeEntries[level].sysconf_name);
+  const int64_t cache_size = sysconf(kCacheSizeConf[level]);
   if (errno == 0 && cache_size > 0) {
     return cache_size;
   }
+#endif
+
+  // get cache size from sysfs if sysconf() fails or not supported
+  const char* kCacheSizeSysfs[] = {
+      "/sys/devices/system/cpu/cpu0/cache/index0/size",  // l1d (index1 is l1i)
+      "/sys/devices/system/cpu/cpu0/cache/index2/size",  // l2
+      "/sys/devices/system/cpu/cpu0/cache/index3/size",  // l3
+  };
+  static_assert(sizeof(kCacheSizeSysfs) / sizeof(kCacheSizeSysfs[0]) == kCacheLevels, "");
 
-  // get cache size from sysfs if sysconf() fails (it does happen on Arm)
-  std::ifstream cacheinfo(kCacheSizeEntries[level].sysfs_path, std::ios::in);
+  std::ifstream cacheinfo(kCacheSizeSysfs[level], std::ios::in);
   if (!cacheinfo) {
     return 0;
   }