mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
u/time: Implement QPC related functions
This commit is contained in:
parent
3b1e34ee20
commit
1debb2e015
|
@ -115,3 +115,27 @@ time_state_ts_to_monotonic_ns(struct time_state const *state, timepoint_ns times
|
||||||
|
|
||||||
return timestamp + state->offset;
|
return timestamp + state->offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XRT_OS_WINDOWS
|
||||||
|
extern "C" void
|
||||||
|
time_state_to_win32perfcounter(struct time_state const *state, timepoint_ns timestamp, LARGE_INTEGER *out_qpc_ticks)
|
||||||
|
{
|
||||||
|
assert(state != NULL);
|
||||||
|
assert(out_qpc_ticks != NULL);
|
||||||
|
|
||||||
|
uint64_t ns = time_state_ts_to_monotonic_ns(state, timestamp);
|
||||||
|
|
||||||
|
out_qpc_ticks->QuadPart = ns / os_ns_per_qpc_tick_get();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" timepoint_ns
|
||||||
|
time_state_from_win32perfcounter(struct time_state const *state, const LARGE_INTEGER *qpc_ticks)
|
||||||
|
{
|
||||||
|
assert(state != NULL);
|
||||||
|
assert(qpc_ticks != NULL);
|
||||||
|
|
||||||
|
uint64_t ns = qpc_ticks->QuadPart * os_ns_per_qpc_tick_get();
|
||||||
|
|
||||||
|
return time_state_monotonic_to_ts_ns(state, ns);
|
||||||
|
}
|
||||||
|
#endif // XRT_OS_WINDOWS
|
||||||
|
|
|
@ -17,9 +17,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "xrt/xrt_compiler.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -285,6 +288,30 @@ time_state_monotonic_to_ts_ns(struct time_state const *state, uint64_t monotonic
|
||||||
uint64_t
|
uint64_t
|
||||||
time_state_ts_to_monotonic_ns(struct time_state const *state, timepoint_ns timestamp);
|
time_state_ts_to_monotonic_ns(struct time_state const *state, timepoint_ns timestamp);
|
||||||
|
|
||||||
|
#if defined(XRT_OS_WINDOWS) || defined(XRT_DOXYGEN)
|
||||||
|
/*!
|
||||||
|
* Converts a timestamp to Win32 "QPC" ticks.
|
||||||
|
*
|
||||||
|
* Should not be called simultaneously with time_state_get_now_and_update.
|
||||||
|
*
|
||||||
|
* @public @memberof time_state
|
||||||
|
* @ingroup aux_util
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
time_state_to_win32perfcounter(struct time_state const *state, timepoint_ns timestamp, LARGE_INTEGER *out_qpc_ticks);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Converts from Win32 "QPC" ticks to timestamp.
|
||||||
|
*
|
||||||
|
* Should not be called simultaneously with time_state_get_now_and_update.
|
||||||
|
*
|
||||||
|
* @public @memberof time_state
|
||||||
|
* @ingroup aux_util
|
||||||
|
*/
|
||||||
|
timepoint_ns
|
||||||
|
time_state_from_win32perfcounter(struct time_state const *state, const LARGE_INTEGER *qpc_ticks);
|
||||||
|
#endif // defined(XRT_OS_WINDOWS) || defined(XRT_DOXYGEN)
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue