diff mbox series

[v3,2/2] eal: roundup tsc frequency when estimating

Message ID 20190316190119.6142-2-pbhagavatula@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series [v3,1/2] eal: add macro to align value to the nearest multiple | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Pavan Nikhilesh Bhagavatula March 16, 2019, 7:01 p.m. UTC
From: Pavan Nikhilesh <pbhagavatula@marvell.com>

When estimating tsc frequency using sleep/gettime round it up to the
nearest multiple of 10Mhz for more accuracy.

Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 Useful in case of ARM64 if we enable RTE_ARM_EAL_RDTSC_USE_PMU,
 get_tsc_freq_arch() will return 0 as there is no instruction to determine
 the clk of PMU and eal falls back to sleep(1).

 lib/librte_eal/common/eal_common_timer.c | 4 +++-
 lib/librte_eal/linux/eal/eal_timer.c     | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

--
2.21.0

Comments

Thomas Monjalon March 27, 2019, 10:43 p.m. UTC | #1
16/03/2019 20:01, Pavan Nikhilesh Bhagavatula:
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
> 
> When estimating tsc frequency using sleep/gettime round it up to the
> nearest multiple of 10Mhz for more accuracy.
> 
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
> Reviewed-by: Keith Wiles <keith.wiles@intel.com>

Series applied, thanks
diff mbox series

Patch

diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
index dcf26bfea..68d67e684 100644
--- a/lib/librte_eal/common/eal_common_timer.c
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -64,12 +64,14 @@  rte_get_tsc_hz(void)
 static uint64_t
 estimate_tsc_freq(void)
 {
+#define CYC_PER_10MHZ 1E7
 	RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly"
 		" - clock timings may be less accurate.\n");
 	/* assume that the sleep(1) will sleep for 1 second */
 	uint64_t start = rte_rdtsc();
 	sleep(1);
-	return rte_rdtsc() - start;
+	/* Round up to 10Mhz. 1E7 ~ 10Mhz */
+	return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);
 }

 void
diff --git a/lib/librte_eal/linux/eal/eal_timer.c b/lib/librte_eal/linux/eal/eal_timer.c
index bc8f05199..76ec17034 100644
--- a/lib/librte_eal/linux/eal/eal_timer.c
+++ b/lib/librte_eal/linux/eal/eal_timer.c
@@ -232,6 +232,7 @@  get_tsc_freq(void)
 {
 #ifdef CLOCK_MONOTONIC_RAW
 #define NS_PER_SEC 1E9
+#define CYC_PER_10MHZ 1E7

 	struct timespec sleeptime = {.tv_nsec = NS_PER_SEC / 10 }; /* 1/10 second */

@@ -248,7 +249,8 @@  get_tsc_freq(void)

 		double secs = (double)ns/NS_PER_SEC;
 		tsc_hz = (uint64_t)((end - start)/secs);
-		return tsc_hz;
+		/* Round up to 10Mhz. 1E7 ~ 10Mhz */
+		return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_10MHZ);
 	}
 #endif
 	return 0;