From 5da59c5d17467933e19b3962cb9f15bdde2c74b1 Mon Sep 17 00:00:00 2001 From: Joyce Kong Date: Thu, 27 Jul 2023 12:05:28 +0000 Subject: [PATCH] linux-gen: timer: add possibility to profile inline timer performance Add the branch to profile inline timer scan performance. Enable inline timer scan performance test by setting CONFIG_TIMER_PROFILE_INLINE in odp_config_internal.h. Signed-off-by: Joyce Kong Reviewed-by: Petri Savolainen --- .../include/odp_config_internal.h | 3 ++ platform/linux-generic/odp_system_info.c | 1 + platform/linux-generic/odp_timer.c | 28 +++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/include/odp_config_internal.h b/platform/linux-generic/include/odp_config_internal.h index f83a237e99..279a43687d 100644 --- a/platform/linux-generic/include/odp_config_internal.h +++ b/platform/linux-generic/include/odp_config_internal.h @@ -190,6 +190,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 6281bee750..bb0eaa9b19 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 8219c59a2f..c6d399d12f 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -235,7 +235,8 @@ typedef struct timer_local_t { odp_time_t last_run; int run_cnt; uint8_t poll_shared; - + uint64_t prof_nsec; + uint64_t prof_rounds; } timer_local_t; /* Points to timer global data */ @@ -872,7 +873,17 @@ void _odp_timer_run_inline(int dec) } /* Check the timer pools. */ - timer_pool_scan_inline(num, now); + 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); + } } /****************************************************************************** @@ -2119,6 +2130,8 @@ 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; + timer_local.prof_nsec = 0; + timer_local.prof_rounds = 0; /* Timer feature disabled */ if (timer_global == NULL) @@ -2140,5 +2153,16 @@ int _odp_timer_init_local(void) int _odp_timer_term_local(void) { + if (CONFIG_TIMER_PROFILE_INLINE) { + if (timer_local.prof_rounds) { + _ODP_PRINT("\n" + "Inline timer profiling for thread %i:\n" + "scan rounds: %" PRIu64 "\n" + "ave scan nsec: %.1f\n", + odp_thread_id(), timer_local.prof_rounds, + (double)timer_local.prof_nsec / timer_local.prof_rounds); + } + } + return 0; }