summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2022-05-20 20:14:33 +0100
committerAlex Lapenkou <lapenkov@fb.com>2022-06-08 15:13:55 -0700
commitdf8f7d10af15d549ab73ba807b2e14a9d7fe1cc2 (patch)
tree56cb5f12895c624ec1d24350788cf4639829a8f3
parentdf7ad8a9b6121c5c4b15bad5606b51bf734416a6 (diff)
downloadjemalloc-df8f7d10af15d549ab73ba807b2e14a9d7fe1cc2.tar.gz
Implement malloc_getcpu for amd64 and arm64 macOS
This enables per CPU arena on MacOS
-rw-r--r--configure.ac17
-rw-r--r--include/jemalloc/internal/jemalloc_internal_inlines_a.h9
2 files changed, 26 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 8248f52d..66eb7c91 100644
--- a/configure.ac
+++ b/configure.ac
@@ -510,6 +510,23 @@ typedef unsigned __int32 uint32_t;
else
AC_MSG_ERROR([cannot determine number of significant virtual address bits])
fi
+ AC_CACHE_CHECK([rdtscp support],
+ [je_cv_rdtscp],
+ AC_RUN_IFELSE([AC_LANG_PROGRAM(
+[[
+#include <stdint.h>
+]],
+[[
+ unsigned int dx;
+ asm volatile("rdtscp" : "=d"(dx) ::);
+ return 0;
+]])],
+ [je_cv_rdtscp=yes],
+ [je_cv_rdstcp=no],
+ [je_cv_rdtscp=no]))
+ if test "x${je_cv_rdtscp}" = "xyes"; then
+ AC_DEFINE([HAVE_RDTSCP], 1, [])
+ fi
fi
;;
*)
diff --git a/include/jemalloc/internal/jemalloc_internal_inlines_a.h b/include/jemalloc/internal/jemalloc_internal_inlines_a.h
index 9e27cc30..7686a9b7 100644
--- a/include/jemalloc/internal/jemalloc_internal_inlines_a.h
+++ b/include/jemalloc/internal/jemalloc_internal_inlines_a.h
@@ -14,6 +14,15 @@ malloc_getcpu(void) {
return GetCurrentProcessorNumber();
#elif defined(JEMALLOC_HAVE_SCHED_GETCPU)
return (malloc_cpuid_t)sched_getcpu();
+#elif defined(HAVE_RDTSCP)
+ unsigned int ax, cx, dx;
+ asm volatile("rdtscp" : "=a"(ax), "=d"(dx), "=c"(cx) ::);
+ return (malloc_cpuid_t)(dx & 0xfff);
+#elif defined(__aarch64__) && defined(__APPLE__)
+ /* Other oses most likely use tpidr_el0 instead */
+ uintptr_t c;
+ asm volatile("mrs %x0, tpidrro_el0" : "=r"(c) :: "memory");
+ return (malloc_cpuid_t)(c & (1 << 3) - 1);
#else
not_reached();
return -1;