[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 17:25:41 PST 2018
nglevin updated this revision to Diff 136654.
nglevin added a comment.
Transform mach_timebase_info_data_t into an "assured once" initialisation, per feedback.
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,19 @@
return 0;
}
+#elif SANITIZER_MAC
+static const mach_timebase_info_data_t TI = [] {
+ mach_timebase_info_data_t LocalTI;
+ mach_timebase_info(&LocalTI);
+ return LocalTI;
+}();
+
+uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
+ uint64_t currentTime = mach_absolute_time();
+ currentTime *= TI.numer;
+ currentTime /= TI.denom;
+ return currentTime;
+}
#else
uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
/* Not supported */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43981.136654.patch
Type: text/x-patch
Size: 828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180302/03301001/attachment.bin>
More information about the llvm-commits
mailing list