-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alan Jowett <[email protected]>
- Loading branch information
Alan Jowett
committed
Nov 14, 2024
1 parent
870b23b
commit 273b464
Showing
14 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
|
||
#if !defined(CMAKE_NUGET) | ||
#include <catch2/catch_all.hpp> | ||
#else | ||
#include <catch2/catch.hpp> | ||
#endif | ||
#include "cxplat.h" | ||
|
||
#include <Windows.h> | ||
|
||
TEST_CASE("query_time_precise_include_suspend", "[time]") | ||
{ | ||
uint64_t time1 = cxplat_query_time_since_boot_precise(true); | ||
Sleep(2); | ||
uint64_t time2 = cxplat_query_time_since_boot_precise(true); | ||
|
||
// The time difference should be at least 10000 filetime units (1ms) | ||
REQUIRE(time2 - time1 >= 10000); | ||
} | ||
|
||
TEST_CASE("query_time_precise", "[time]") | ||
{ | ||
uint64_t time1 = cxplat_query_time_since_boot_precise(false); | ||
Sleep(2); | ||
uint64_t time2 = cxplat_query_time_since_boot_precise(false); | ||
|
||
// The time difference should be at least 10000 filetime units (1ms) | ||
REQUIRE(time2 - time1 >= 10000); | ||
} | ||
|
||
TEST_CASE("query_time_approximate_include_suspend", "[time]") | ||
{ | ||
uint64_t time1 = cxplat_query_time_since_boot_approximate(true); | ||
Sleep(2); | ||
uint64_t time2 = cxplat_query_time_since_boot_approximate(true); | ||
|
||
// The time difference should be at least 10000 filetime units (1ms) | ||
REQUIRE(time2 - time1 >= 10000); | ||
} | ||
|
||
TEST_CASE("query_time_approximate", "[time]") | ||
{ | ||
uint64_t time1 = cxplat_query_time_since_boot_approximate(false); | ||
Sleep(2); | ||
uint64_t time2 = cxplat_query_time_since_boot_approximate(false); | ||
|
||
// The time difference should be at least 10000 filetime units (1ms) | ||
REQUIRE(time2 - time1 >= 10000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
CXPLAT_EXTERN_C_BEGIN | ||
|
||
uint64_t | ||
cxplat_query_time_since_boot_precise(bool include_suspended_time); | ||
|
||
uint64_t | ||
cxplat_query_time_since_boot_approximate(bool include_suspended_time); | ||
|
||
CXPLAT_EXTERN_C_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
#include "cxplat.h" | ||
#include "wdm.h" | ||
|
||
uint64_t | ||
cxplat_query_time_since_boot_precise(bool include_suspended_time) | ||
{ | ||
uint64_t qpc_time; | ||
if (include_suspended_time) { | ||
// KeQueryUnbiasedInterruptTimePrecise returns the current interrupt-time count in 100-nanosecond units. | ||
// Unbiased Interrupt time is the total time since boot including time spent suspended. | ||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-kequeryunbiasedinterrupttimeprecise | ||
return KeQueryUnbiasedInterruptTimePrecise(&qpc_time); | ||
} else { | ||
// KeQueryInterruptTimePrecise returns the current interrupt-time count in 100-nanosecond units. | ||
// (Biased) Interrupt time is the total time since boot excluding time spent suspended. | ||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-kequeryinterrupttimeprecise | ||
return KeQueryInterruptTimePrecise(&qpc_time); | ||
} | ||
} | ||
|
||
uint64_t | ||
cxplat_query_time_since_boot_approximate(bool include_suspended_time) | ||
{ | ||
if (include_suspended_time) { | ||
// KeQueryUnbiasedInterruptTime returns the current interrupt-time count in 100-nanosecond units. | ||
// Unbiased Interrupt time is the total time since boot including time spent suspended. | ||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-kequeryunbiasedinterrupttime | ||
return KeQueryUnbiasedInterruptTime(); | ||
} else { | ||
// KeQueryInterruptTimePrecise returns the current interrupt-time count in 100-nanosecond units. | ||
// (Biased) Interrupt time is the total time since boot excluding time spent suspended. | ||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-kequeryinterrupttime | ||
return KeQueryInterruptTime(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
#include "cxplat.h" | ||
#include "realtimeapiset.h" | ||
|
||
#pragma comment(lib, "Mincore.lib") | ||
|
||
uint64_t | ||
cxplat_query_time_since_boot_precise(bool include_suspended_time) | ||
{ | ||
uint64_t qpc_time; | ||
if (include_suspended_time) { | ||
// KeQueryUnbiasedInterruptTimePrecise returns the current interrupt-time count in 100-nanosecond units. | ||
// Unbiased Interrupt time is the total time since boot including time spent suspended. | ||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-kequeryunbiasedinterrupttimeprecise | ||
QueryUnbiasedInterruptTimePrecise(&qpc_time); | ||
} else { | ||
// KeQueryInterruptTimePrecise returns the current interrupt-time count in 100-nanosecond units. | ||
// (Biased) Interrupt time is the total time since boot excluding time spent suspended. | ||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-kequeryinterrupttimeprecise | ||
QueryInterruptTimePrecise(&qpc_time); | ||
} | ||
return qpc_time; | ||
} | ||
|
||
uint64_t | ||
cxplat_query_time_since_boot_approximate(bool include_suspended_time) | ||
{ | ||
uint64_t qpc_time; | ||
if (include_suspended_time) { | ||
// KeQueryUnbiasedInterruptTime returns the current interrupt-time count in 100-nanosecond units. | ||
// Unbiased Interrupt time is the total time since boot including time spent suspended. | ||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-kequeryunbiasedinterrupttime | ||
QueryUnbiasedInterruptTime(&qpc_time); | ||
} else { | ||
// KeQueryInterruptTimePrecise returns the current interrupt-time count in 100-nanosecond units. | ||
// (Biased) Interrupt time is the total time since boot excluding time spent suspended. | ||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-kequeryinterrupttime | ||
QueryInterruptTime(&qpc_time); | ||
} | ||
|
||
return qpc_time; | ||
} |