[PATCH] D43981: [XRay] [compiler-rt] [macosx] Add getTSCFrequency implementation for macOS.
Nicholas Levin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 1 16:32:40 PST 2018
nglevin created this revision.
nglevin added a reviewer: dberris.
Herald added subscribers: Sanitizers, llvm-commits, delcypher.
Use mach_absolute_time and mach_timebase as an alternative to clock_gettime(2) on macOS platforms, to support earlier versions of the OS.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D43981
Files:
lib/xray/xray_x86_64.cc
Index: lib/xray/xray_x86_64.cc
===================================================================
--- lib/xray/xray_x86_64.cc
+++ lib/xray/xray_x86_64.cc
@@ -6,6 +6,8 @@
#if SANITIZER_FREEBSD || SANITIZER_NETBSD
#include <sys/types.h>
#include <sys/sysctl.h>
+#elif SANITIZER_MAC
+#include <mach/mach_time.h>
#endif
#include <atomic>
@@ -92,6 +94,18 @@
return 0;
}
+#elif SANITIZER_MAC
+static mach_timebase_info_data_t TimebaseInfo;
+
+uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
+ if (TimebaseInfo.denom == 0) {
+ mach_timebase_info(&TimebaseInfo);
+ }
+ uint64_t currentTime = mach_absolute_time();
+ currentTime *= TimebaseInfo.numer;
+ currentTime /= TimebaseInfo.denom;
+ return currentTime;
+}
#else
uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
/* Not supported */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43981.136636.patch
Type: text/x-patch
Size: 835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180302/f54c3501/attachment.bin>
More information about the llvm-commits
mailing list