[PATCH] D42579: [sanitizer] Implement MonotonicNanoTime for Windows
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 26 08:48:55 PST 2018
cryptoad created this revision.
cryptoad added reviewers: rnk, alekseyshl.
Herald added subscribers: Sanitizers, delcypher, kubamracek.
Implement `MonotonicNanoTime` using `QueryPerformanceCounter`.
This function is used by Scudo & the 64-bit Primary allocator. Implementing it
now means that the release-to-OS mechanism of the Primary will kick in (it
never did since the function returned 0 always), but `ReleaseMemoryPagesToOS` is
still not currently implemented for Windows.
Performance wise, this adds a syscall & a 64-bit division per call to
`MonotonicNanoTime` so the impact might not be negligible, but I don't think
there is a way around it.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D42579
Files:
lib/sanitizer_common/sanitizer_win.cc
Index: lib/sanitizer_common/sanitizer_win.cc
===================================================================
--- lib/sanitizer_common/sanitizer_win.cc
+++ lib/sanitizer_common/sanitizer_win.cc
@@ -506,7 +506,18 @@
}
u64 MonotonicNanoTime() {
- return 0;
+ static LARGE_INTEGER base, frequency = {0};
+ LARGE_INTEGER current, ns;
+ if (UNLIKELY(frequency.QuadPart == 0)) {
+ QueryPerformanceFrequency(&frequency);
+ QueryPerformanceCounter(&base);
+ CHECK_NE(frequency.QuadPart, 0);
+ }
+ QueryPerformanceCounter(¤t);
+ ns.QuadPart = current.QuadPart - base.QuadPart;
+ ns.QuadPart *= 1000U * 1000000U;
+ ns.QuadPart /= frequency.QuadPart;
+ return ns.QuadPart;
}
void Abort() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42579.131595.patch
Type: text/x-patch
Size: 715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180126/3ad47f3c/attachment.bin>
More information about the llvm-commits
mailing list