[PATCH] D42579: [sanitizer] Implement NanoTime & MonotonicNanoTime for Windows

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 12:08:29 PST 2018


cryptoad updated this revision to Diff 132447.
cryptoad added a comment.

As per review comments, disable release-to-os by default on Windows (& Fuchsia).
Neither of those platforms implement `ReleaseMemoryPagesToOS`, but since we
are implementing `MonotonicNanoTime`, this would trigger spurious scanning of
the memory pages.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42579

Files:
  lib/sanitizer_common/sanitizer_flags.inc
  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
@@ -502,12 +502,19 @@
 }
 
 u64 NanoTime() {
-  return 0;
+  static LARGE_INTEGER frequency = {0};
+  LARGE_INTEGER counter;
+  if (UNLIKELY(frequency.QuadPart == 0)) {
+    QueryPerformanceFrequency(&frequency);
+    CHECK_NE(frequency.QuadPart, 0);
+  }
+  QueryPerformanceCounter(&counter);
+  counter.QuadPart *= 1000ULL * 1000000ULL;
+  counter.QuadPart /= frequency.QuadPart;
+  return counter.QuadPart;
 }
 
-u64 MonotonicNanoTime() {
-  return 0;
-}
+u64 MonotonicNanoTime() { return NanoTime(); }
 
 void Abort() {
   internal__exit(3);
Index: lib/sanitizer_common/sanitizer_flags.inc
===================================================================
--- lib/sanitizer_common/sanitizer_flags.inc
+++ lib/sanitizer_common/sanitizer_flags.inc
@@ -132,7 +132,8 @@
             " This limit does not affect memory allocations other than"
             " malloc/new.")
 COMMON_FLAG(bool, heap_profile, false, "Experimental heap profiler, asan-only")
-COMMON_FLAG(s32, allocator_release_to_os_interval_ms, 5000,
+COMMON_FLAG(s32, allocator_release_to_os_interval_ms,
+            (SANITIZER_FUCHSIA || SANITIZER_WINDOWS) ? -1 : 5000,
             "Only affects a 64-bit allocator. If set, tries to release unused "
             "memory to the OS, but not more often than this interval (in "
             "milliseconds). Negative values mean do not attempt to release "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42579.132447.patch
Type: text/x-patch
Size: 1570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180201/43b1abcd/attachment.bin>


More information about the llvm-commits mailing list