[dpdk-dev] eal: optimize timer routines

Message ID 20170501191207.6480-1-jerin.jacob@caviumnetworks.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

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

Commit Message

Jerin Jacob May 1, 2017, 7:12 p.m. UTC
  Since DPDK has only two timer sources,
Avoid &eal_timer_source memory read and followed
by the switch case statement when
RTE_LIBEAL_USE_HPET is not defined.

Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
---
 lib/librte_eal/common/include/generic/rte_cycles.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
  

Comments

Thomas Monjalon May 1, 2017, 7:52 p.m. UTC | #1
01/05/2017 21:12, Jerin Jacob:
> Since DPDK has only two timer sources,
> Avoid &eal_timer_source memory read and followed
> by the switch case statement when
> RTE_LIBEAL_USE_HPET is not defined.
[...]
>  static inline uint64_t
>  rte_get_timer_cycles(void)
>  {
> +#ifdef RTE_LIBEAL_USE_HPET
>  	switch(eal_timer_source) {
>  	case EAL_TIMER_TSC:
>  		return rte_get_tsc_cycles();
>  	case EAL_TIMER_HPET:
> -#ifdef RTE_LIBEAL_USE_HPET
>  		return rte_get_hpet_cycles();
> -#endif
>  	default: rte_panic("Invalid timer source specified\n");
>  	}
> +#else
> +	return rte_get_tsc_cycles();
> +#endif

I think I would prefer avoiding the #else part by
"unifdef" the first occurence of rte_get_tsc_cycles:

static inline uint64_t
rte_get_timer_cycles(void)
{
#ifdef RTE_LIBEAL_USE_HPET
	switch(eal_timer_source) {
	case EAL_TIMER_TSC:
#endif
		return rte_get_tsc_cycles();
#ifdef RTE_LIBEAL_USE_HPET
	case EAL_TIMER_HPET:
		return rte_get_hpet_cycles();
	default: rte_panic("Invalid timer source specified\n");
	}
#endif
  

Patch

diff --git a/lib/librte_eal/common/include/generic/rte_cycles.h b/lib/librte_eal/common/include/generic/rte_cycles.h
index 00103ca9f..2f3dea06e 100644
--- a/lib/librte_eal/common/include/generic/rte_cycles.h
+++ b/lib/librte_eal/common/include/generic/rte_cycles.h
@@ -150,15 +150,17 @@  int rte_eal_hpet_init(int make_default);
 static inline uint64_t
 rte_get_timer_cycles(void)
 {
+#ifdef RTE_LIBEAL_USE_HPET
 	switch(eal_timer_source) {
 	case EAL_TIMER_TSC:
 		return rte_get_tsc_cycles();
 	case EAL_TIMER_HPET:
-#ifdef RTE_LIBEAL_USE_HPET
 		return rte_get_hpet_cycles();
-#endif
 	default: rte_panic("Invalid timer source specified\n");
 	}
+#else
+	return rte_get_tsc_cycles();
+#endif
 }
 
 /**
@@ -170,15 +172,17 @@  rte_get_timer_cycles(void)
 static inline uint64_t
 rte_get_timer_hz(void)
 {
+#ifdef RTE_LIBEAL_USE_HPET
 	switch(eal_timer_source) {
 	case EAL_TIMER_TSC:
 		return rte_get_tsc_hz();
 	case EAL_TIMER_HPET:
-#ifdef RTE_LIBEAL_USE_HPET
 		return rte_get_hpet_hz();
-#endif
 	default: rte_panic("Invalid timer source specified\n");
 	}
+#else
+	return rte_get_tsc_hz();
+#endif
 }
 /**
  * Wait at least us microseconds.