diff --git a/platform/linux-generic/include/odp_config_internal.h b/platform/linux-generic/include/odp_config_internal.h index e4f8d6d6d76..c5f717ffd3b 100644 --- a/platform/linux-generic/include/odp_config_internal.h +++ b/platform/linux-generic/include/odp_config_internal.h @@ -189,6 +189,9 @@ extern "C" { */ #define CONFIG_TIMER_128BIT_ATOMICS 1 +/* Enable timer scan performance benchmark. This works with inline enabled. */ +#define CONFIG_TIMER_PROFILE_INLINE 0 + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 6281bee7507..bb0eaa9b194 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -611,5 +611,6 @@ void odp_sys_config_print(void) _ODP_PRINT("CONFIG_POOL_MAX_NUM: %i\n", CONFIG_POOL_MAX_NUM); _ODP_PRINT("CONFIG_POOL_CACHE_MAX_SIZE: %i\n", CONFIG_POOL_CACHE_MAX_SIZE); _ODP_PRINT("CONFIG_TIMER_128BIT_ATOMICS: %i\n", CONFIG_TIMER_128BIT_ATOMICS); + _ODP_PRINT("CONFIG_TIMER_PROFILE_INLINE: %i\n", CONFIG_TIMER_PROFILE_INLINE); _ODP_PRINT("\n"); } diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 8219c59a2f7..dbfbc7abae8 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -235,6 +235,10 @@ typedef struct timer_local_t { odp_time_t last_run; int run_cnt; uint8_t poll_shared; +#if CONFIG_TIMER_PROFILE_INLINE + uint64_t prof_nsec; + uint64_t prof_rounds; +#endif } timer_local_t; @@ -872,7 +876,17 @@ void _odp_timer_run_inline(int dec) } /* Check the timer pools. */ +#if CONFIG_TIMER_PROFILE_INLINE + odp_time_t t1 = odp_time_local_strict(); + + timer_pool_scan_inline(num, now); + odp_time_t t2 = odp_time_local_strict(); + + timer_local.prof_nsec += odp_time_diff_ns(t2, t1); + timer_local.prof_rounds++; +#else timer_pool_scan_inline(num, now); +#endif } /****************************************************************************** @@ -2119,6 +2133,10 @@ int _odp_timer_init_local(void) timer_local.last_run = odp_time_global_from_ns(0); timer_local.run_cnt = 1; timer_local.poll_shared = 0; +#if CONFIG_TIMER_PROFILE_INLINE + timer_local.prof_nsec = 0; + timer_local.prof_rounds = 0; +#endif /* Timer feature disabled */ if (timer_global == NULL) @@ -2140,5 +2158,18 @@ int _odp_timer_init_local(void) int _odp_timer_term_local(void) { +#if CONFIG_TIMER_PROFILE_INLINE + if (timer_local.prof_rounds) { + int thr = odp_thread_id(); + + odp_ticketlock_lock(&timer_global->lock); + _ODP_PRINT("Inline timer profiling for thread %i:\n", thr); + _ODP_PRINT(" scan rounds: %" PRIu64 "\n", timer_local.prof_rounds); + _ODP_PRINT(" ave scan nsec: %.1f\n", + (double)timer_local.prof_nsec / timer_local.prof_rounds); + odp_ticketlock_unlock(&timer_global->lock); + } +#endif + return 0; }