In practice, the frequency is often not a nice round number, while the estimation results are rather accurate, just a couple of KHz away from the kernel's tsc_khz value, so it should suffice.
Rounding to 10MHz can cause a significant drift from real time, up to a second per 10 minutes. See also bugzilla: 959 Signed-off-by: Isaac Boukris <ibouk...@gmail.com> --- lib/eal/linux/eal_timer.c | 6 +++--- lib/eal/windows/eal_timer.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c index 1cb1e92193..f56a7ae15b 100644 --- a/lib/eal/linux/eal_timer.c +++ b/lib/eal/linux/eal_timer.c @@ -192,7 +192,7 @@ get_tsc_freq(void) { #ifdef CLOCK_MONOTONIC_RAW #define NS_PER_SEC 1E9 -#define CYC_PER_10MHZ 1E7 +#define CYC_PER_100KHZ 1E5 struct timespec sleeptime = {.tv_nsec = NS_PER_SEC / 10 }; /* 1/10 second */ @@ -209,8 +209,8 @@ get_tsc_freq(void) double secs = (double)ns/NS_PER_SEC; tsc_hz = (uint64_t)((end - start)/secs); - /* Round up to 10Mhz. 1E7 ~ 10Mhz */ - return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_10MHZ); + /* Round up to 100Khz. 1E5 ~ 100Khz */ + return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_100KHZ); } #endif return 0; diff --git a/lib/eal/windows/eal_timer.c b/lib/eal/windows/eal_timer.c index b070cb7751..4003541b08 100644 --- a/lib/eal/windows/eal_timer.c +++ b/lib/eal/windows/eal_timer.c @@ -12,7 +12,7 @@ #include "eal_private.h" #define US_PER_SEC 1E6 -#define CYC_PER_10MHZ 1E7 +#define CYC_PER_100KHZ 1E5 void rte_delay_us_sleep(unsigned int us) @@ -81,8 +81,8 @@ get_tsc_freq(void) double secs = ((double)elapsed_us.QuadPart)/US_PER_SEC; tsc_hz = (uint64_t)((end - start)/secs); - /* Round up to 10Mhz. 1E7 ~ 10Mhz */ - return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_10MHZ); + /* Round up to 100Khz. 1E5 ~ 100Khz */ + return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_100KHZ); } -- 2.45.0