[sanitizer] Implement NanoTime & MonotonicNanoTime for Windows

Summary:
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.

Reviewers: rnk, alekseyshl, amccarth

Reviewed By: alekseyshl, amccarth

Subscribers: amccarth, flowerhack, kubamracek, delcypher, llvm-commits, #sanitizers

Differential Revision: https://reviews.llvm.org/D42579

llvm-svn: 324011
This commit is contained in:
Kostya Kortchinsky 2018-02-01 21:38:14 +00:00
parent 0423fcac39
commit 298f224194
2 changed files with 13 additions and 5 deletions

View File

@ -132,7 +132,8 @@ COMMON_FLAG(uptr, soft_rss_limit_mb, 0,
" 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 "

View File

@ -502,12 +502,19 @@ void SleepForMillis(int millis) {
}
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);