From bb918d85f82853340b889c784323bbde841de67f Mon Sep 17 00:00:00 2001 From: Adithya Baglody Date: Mon, 23 Jul 2018 13:49:26 +0530 Subject: [PATCH] tests: benchmarks: timing_info: Enable benchmarks for xtensa. This patch provides support needed to get timing related information from xtensa based SOC. Signed-off-by: Adithya Baglody --- arch/common/timing_info_bench.c | 25 ++++++++++++++----- arch/xtensa/core/xtensa-asm2-util.S | 4 +++ drivers/timer/xtensa_sys_timer.c | 10 ++++++++ kernel/include/kswap.h | 5 ++++ .../benchmarks/timing_info/src/timing_info.h | 7 ++++++ tests/benchmarks/timing_info/testcase.yaml | 2 +- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/arch/common/timing_info_bench.c b/arch/common/timing_info_bench.c index 375a34e4a51..1424dc9a2b3 100644 --- a/arch/common/timing_info_bench.c +++ b/arch/common/timing_info_bench.c @@ -19,6 +19,9 @@ u64_t __end_drop_to_usermode_time; u32_t __read_swap_end_time_value; u64_t __common_var_swap_end_time; +#if CONFIG_ARM +#include +#endif #ifdef CONFIG_NRF_RTC_TIMER /* To get current count of timer, first 1 need to be written into @@ -47,14 +50,26 @@ u64_t __common_var_swap_end_time; #define TIMING_INFO_OS_GET_TIME() (k_cycle_get_32()) #define TIMING_INFO_GET_TIMER_VALUE() (_arc_v2_aux_reg_read(_ARC_V2_TMR0_COUNT)) #define SUBTRACT_CLOCK_CYCLES(val) ((u32_t)val) + +#elif CONFIG_XTENSA +#include +#define TIMING_INFO_PRE_READ() +#define TIMING_INFO_OS_GET_TIME() (k_cycle_get_32()) +#define TIMING_INFO_GET_TIMER_VALUE() (k_cycle_get_32()) +#define SUBTRACT_CLOCK_CYCLES(val) ((u32_t)val) + +#else +/* Default case */ +#error "Benchmarks have not been implemented for this architecture" #endif /* CONFIG_NRF_RTC_TIMER */ -#if defined(CONFIG_ARM) || defined(CONFIG_ARC) void read_timer_start_of_swap(void) { - TIMING_INFO_PRE_READ(); - __start_swap_time = (u32_t) TIMING_INFO_OS_GET_TIME(); + if (__read_swap_end_time_value == 1) { + TIMING_INFO_PRE_READ(); + __start_swap_time = (u32_t) TIMING_INFO_OS_GET_TIME(); + } } void read_timer_end_of_swap(void) @@ -62,7 +77,7 @@ void read_timer_end_of_swap(void) if (__read_swap_end_time_value == 1) { TIMING_INFO_PRE_READ(); __read_swap_end_time_value = 2; - __common_var_swap_end_time = TIMING_INFO_OS_GET_TIME(); + __common_var_swap_end_time = (u64_t)TIMING_INFO_OS_GET_TIME(); } } @@ -98,5 +113,3 @@ void read_timer_end_of_userspace_enter(void) TIMING_INFO_PRE_READ(); __end_drop_to_usermode_time = (u32_t) TIMING_INFO_GET_TIMER_VALUE(); } - -#endif /* CONFIG_ARM */ diff --git a/arch/xtensa/core/xtensa-asm2-util.S b/arch/xtensa/core/xtensa-asm2-util.S index 33b41370010..df783844b24 100644 --- a/arch/xtensa/core/xtensa-asm2-util.S +++ b/arch/xtensa/core/xtensa-asm2-util.S @@ -220,6 +220,10 @@ xtensa_switch: * sanity. */ l32i a1, a2, BSA_A2_OFF + +#ifdef CONFIG_EXECUTION_BENCHMARKING + call4 read_timer_end_of_swap +#endif j _restore_context _switch_restore_pc: retw diff --git a/drivers/timer/xtensa_sys_timer.c b/drivers/timer/xtensa_sys_timer.c index c404e72817a..1d152c07a3b 100644 --- a/drivers/timer/xtensa_sys_timer.c +++ b/drivers/timer/xtensa_sys_timer.c @@ -489,6 +489,11 @@ void _timer_int_handler(void *params) { ARG_UNUSED(params); +#ifdef CONFIG_EXECUTION_BENCHMARKING + extern void read_timer_start_of_tick_handler(void); + read_timer_start_of_tick_handler(); +#endif + #ifdef CONFIG_XTENSA_ASM2 /* FIXME: the legacy xtensa code did this in the assembly * hook, and was a little more sophisticated. We should track @@ -536,6 +541,11 @@ void _timer_int_handler(void *params) /* Announce the tick event to the kernel. */ _sys_clock_final_tick_announce(); #endif /* CONFIG_TICKLESS_KERNEL */ + +#ifdef CONFIG_EXECUTION_BENCHMARKING + extern void read_timer_end_of_tick_handler(void); + read_timer_end_of_tick_handler(); +#endif } diff --git a/kernel/include/kswap.h b/kernel/include/kswap.h index 5fa0d2e563d..e2e2cb94915 100644 --- a/kernel/include/kswap.h +++ b/kernel/include/kswap.h @@ -46,6 +46,11 @@ static inline unsigned int _Swap(unsigned int key) struct k_thread *new_thread, *old_thread; int ret = 0; +#ifdef CONFIG_EXECUTION_BENCHMARKING + extern void read_timer_start_of_swap(void); + read_timer_start_of_swap(); +#endif + old_thread = _current; _check_stack_sentinel(); diff --git a/tests/benchmarks/timing_info/src/timing_info.h b/tests/benchmarks/timing_info/src/timing_info.h index d8183f36bc7..6bd45a4a03a 100644 --- a/tests/benchmarks/timing_info/src/timing_info.h +++ b/tests/benchmarks/timing_info/src/timing_info.h @@ -61,6 +61,13 @@ #define TIMING_INFO_OS_GET_TIME() (k_cycle_get_32()) #define TIMING_INFO_GET_TIMER_VALUE() (_arc_v2_aux_reg_read(_ARC_V2_TMR0_COUNT)) #define SUBTRACT_CLOCK_CYCLES(val) ((u32_t)val) + +#elif CONFIG_XTENSA +#define TIMING_INFO_PRE_READ() +#define TIMING_INFO_OS_GET_TIME() (k_cycle_get_32()) +#define TIMING_INFO_GET_TIMER_VALUE() (k_cycle_get_32()) +#define SUBTRACT_CLOCK_CYCLES(val) ((u32_t)val) + #endif /* CONFIG_NRF_RTC_TIMER */ /******************************************************************************/ diff --git a/tests/benchmarks/timing_info/testcase.yaml b/tests/benchmarks/timing_info/testcase.yaml index fe2a05c0302..0059ab8e865 100644 --- a/tests/benchmarks/timing_info/testcase.yaml +++ b/tests/benchmarks/timing_info/testcase.yaml @@ -1,6 +1,6 @@ tests: benchmark.timing.default_kernel: - arch_whitelist: x86 arm arc + arch_whitelist: x86 arm arc xtensa tags: benchmark benchmark.timing.userspace: filter: CONFIG_ARCH_HAS_USERSPACE