1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
7 #include <rte_windows.h>
8 #include <rte_common.h>
9 #include <rte_cycles.h>
11 #include <rte_errno.h>
12 #include "eal_private.h"
14 #define US_PER_SEC 1E6
15 #define CYC_PER_10MHZ 1E7
18 rte_delay_us_sleep(unsigned int us)
21 LARGE_INTEGER due_time;
23 /* create waitable timer */
24 timer = CreateWaitableTimer(NULL, TRUE, NULL);
26 RTE_LOG_WIN32_ERR("CreateWaitableTimer()");
32 * due_time's uom is 100 ns, multiply by 10 to convert to microseconds
33 * set us microseconds time for timer
35 due_time.QuadPart = -((int64_t)us * 10);
36 if (!SetWaitableTimer(timer, &due_time, 0, NULL, NULL, FALSE)) {
37 RTE_LOG_WIN32_ERR("SetWaitableTimer()");
41 /* start wait for timer for us microseconds */
42 if (WaitForSingleObject(timer, INFINITE) == WAIT_FAILED) {
43 RTE_LOG_WIN32_ERR("WaitForSingleObject()");
54 LARGE_INTEGER t_start, t_end, elapsed_us;
55 LARGE_INTEGER frequency;
59 QueryPerformanceFrequency(&frequency);
61 QueryPerformanceCounter(&t_start);
62 start = rte_get_tsc_cycles();
64 rte_delay_us_sleep(US_PER_SEC / 10); /* 1/10 second */
69 QueryPerformanceCounter(&t_end);
70 end = rte_get_tsc_cycles();
72 elapsed_us.QuadPart = t_end.QuadPart - t_start.QuadPart;
75 * To guard against loss-of-precision, convert to microseconds
76 * *before* dividing by ticks-per-second.
78 elapsed_us.QuadPart *= US_PER_SEC;
79 elapsed_us.QuadPart /= frequency.QuadPart;
81 double secs = ((double)elapsed_us.QuadPart)/US_PER_SEC;
82 tsc_hz = (uint64_t)((end - start)/secs);
84 /* Round up to 10Mhz. 1E7 ~ 10Mhz */
85 return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_10MHZ);
90 rte_eal_timer_init(void)