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

wesm 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 e7e43dd  ARROW-9110: [C++] Fix CPU cache size detection on macOS
e7e43dd is described below

commit e7e43dd63034abb402de0617e64d1093e6c8bdb2
Author: Krisztián Szűcs <[email protected]>
AuthorDate: Fri Jun 12 11:32:44 2020 -0500

    ARROW-9110: [C++] Fix CPU cache size detection on macOS
    
    Querying locally shows my RAM size at the first position:
    
    ```
    ❯ sysctl -a | grep hw\.cachesize
    hw.cachesize: 68719476736 32768 262144 16777216 0 0 0 0 0 0
    ```
    
    I'm unsure how to test it, it has fixed running the benchmarks locally for 
me.
    
    Closes #7408 from kszucs/ARROW-9110
    
    Authored-by: Krisztián Szűcs <[email protected]>
    Signed-off-by: Wes McKinney <[email protected]>
---
 cpp/src/arrow/util/cpu_info.cc | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/cpp/src/arrow/util/cpu_info.cc b/cpp/src/arrow/util/cpu_info.cc
index 2d77379..a72e9cc 100644
--- a/cpp/src/arrow/util/cpu_info.cc
+++ b/cpp/src/arrow/util/cpu_info.cc
@@ -301,14 +301,14 @@ void CpuInfo::Init() {
 
 #ifdef __APPLE__
   // On Mac OS X use sysctl() to get the cache sizes
-  size_t len = 0;
-  sysctlbyname("hw.cachesize", NULL, &len, NULL, 0);
-  uint64_t* data = static_cast<uint64_t*>(malloc(len));
-  sysctlbyname("hw.cachesize", data, &len, NULL, 0);
-  DCHECK_GE(len / sizeof(uint64_t), 3);
-  for (size_t i = 0; i < 3; ++i) {
-    cache_sizes_[i] = data[i];
-  }
+  size_t len = sizeof(int64_t);
+  int64_t data[1];
+  sysctlbyname("hw.l1dcachesize", data, &len, NULL, 0);
+  cache_sizes_[0] = data[0];
+  sysctlbyname("hw.l2cachesize", data, &len, NULL, 0);
+  cache_sizes_[1] = data[0];
+  sysctlbyname("hw.l3cachesize", data, &len, NULL, 0);
+  cache_sizes_[2] = data[0];
 #elif _WIN32
   if (!RetrieveCacheSize(cache_sizes_)) {
     SetDefaultCacheSize();

Reply via email to