From 79f65d4db7ec0fa85a376555b1e93be689ec3a7e Mon Sep 17 00:00:00 2001 From: Adithya Baglody Date: Mon, 23 Jul 2018 13:57:06 +0530 Subject: [PATCH] tests: benchmarks: timing_info: Enable benchmarks for nios2. This patch provides support needed to get timing related information from nios2 based SOC. Signed-off-by: Adithya Baglody --- arch/common/timing_info_bench.c | 18 +++++++ arch/nios2/core/irq_manage.c | 10 ++++ arch/nios2/core/swap.S | 54 +++++++++++++++++++ drivers/timer/altera_avalon_timer_hal.c | 10 ++++ .../benchmarks/timing_info/src/timing_info.h | 18 +++++++ tests/benchmarks/timing_info/testcase.yaml | 2 +- 6 files changed, 111 insertions(+), 1 deletion(-) diff --git a/arch/common/timing_info_bench.c b/arch/common/timing_info_bench.c index 1424dc9a2b..1dbc3e7840 100644 --- a/arch/common/timing_info_bench.c +++ b/arch/common/timing_info_bench.c @@ -58,6 +58,24 @@ u64_t __common_var_swap_end_time; #define TIMING_INFO_GET_TIMER_VALUE() (k_cycle_get_32()) #define SUBTRACT_CLOCK_CYCLES(val) ((u32_t)val) +#elif CONFIG_NIOS2 +#include "altera_avalon_timer_regs.h" +#define TIMING_INFO_PRE_READ() \ + (IOWR_ALTERA_AVALON_TIMER_SNAPL(TIMER_0_BASE, 10)) + +#define TIMING_INFO_OS_GET_TIME() (SUBTRACT_CLOCK_CYCLES(\ + ((u32_t)IORD_ALTERA_AVALON_TIMER_SNAPH(TIMER_0_BASE) << 16)\ + | ((u32_t)IORD_ALTERA_AVALON_TIMER_SNAPL(TIMER_0_BASE)))) + +#define TIMING_INFO_GET_TIMER_VALUE() (\ + ((u32_t)IORD_ALTERA_AVALON_TIMER_SNAPH(TIMER_0_BASE) << 16)\ + | ((u32_t)IORD_ALTERA_AVALON_TIMER_SNAPL(TIMER_0_BASE))) + +#define SUBTRACT_CLOCK_CYCLES(val) \ + ((IORD_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE) \ + << 16 | \ + (IORD_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE))) \ + - ((u32_t)val)) #else /* Default case */ #error "Benchmarks have not been implemented for this architecture" diff --git a/arch/nios2/core/irq_manage.c b/arch/nios2/core/irq_manage.c index 6c5f69b301..4ca97ba9bd 100644 --- a/arch/nios2/core/irq_manage.c +++ b/arch/nios2/core/irq_manage.c @@ -72,6 +72,11 @@ void _enter_irq(u32_t ipending) { int index; +#ifdef CONFIG_EXECUTION_BENCHMARKING + extern void read_timer_start_of_isr(void); + read_timer_start_of_isr(); +#endif + _kernel.nested++; #ifdef CONFIG_IRQ_OFFLOAD @@ -89,6 +94,11 @@ void _enter_irq(u32_t ipending) ipending &= ~(1 << index); ite = &_sw_isr_table[index]; + +#ifdef CONFIG_EXECUTION_BENCHMARKING + extern void read_timer_end_of_isr(void); + read_timer_end_of_isr(); +#endif ite->isr(ite->arg); } diff --git a/arch/nios2/core/swap.S b/arch/nios2/core/swap.S index a8688b6f22..eceecdf7ce 100644 --- a/arch/nios2/core/swap.S +++ b/arch/nios2/core/swap.S @@ -22,6 +22,33 @@ GTEXT(_k_neg_eagain) */ SECTION_FUNC(exception.other, __swap) +#ifdef CONFIG_EXECUTION_BENCHMARKING + /* Get a reference to _kernel in r10 */ + movhi r10, %hi(_kernel) + ori r10, r10, %lo(_kernel) + + /* Get the pointer to kernel->current */ + ldw r11, _kernel_offset_to_current(r10) + stw r2, _thread_offset_to_r16(r11) + stw r3, _thread_offset_to_r17(r11) + stw r4, _thread_offset_to_r18(r11) + stw ra, _thread_offset_to_ra(r11) + stw sp, _thread_offset_to_sp(r11) + + call read_timer_start_of_swap + /* Get a reference to _kernel in r10 */ + movhi r10, %hi(_kernel) + ori r10, r10, %lo(_kernel) + + /* Get the pointer to kernel->current */ + ldw r11, _kernel_offset_to_current(r10) + ldw r2, _thread_offset_to_r16(r11) + ldw r3, _thread_offset_to_r17(r11) + ldw r4, _thread_offset_to_r18(r11) + ldw ra, _thread_offset_to_ra(r11) + ldw sp, _thread_offset_to_sp(r11) + +#endif /* Get a reference to _kernel in r10 */ movhi r10, %hi(_kernel) ori r10, r10, %lo(_kernel) @@ -114,6 +141,33 @@ no_unlock: #else wrctl status, r3 #endif + +#ifdef CONFIG_EXECUTION_BENCHMARKING + /* Get a reference to _kernel in r10 */ + movhi r10, %hi(_kernel) + ori r10, r10, %lo(_kernel) + + ldw r11, _kernel_offset_to_current(r10) + stw r2, _thread_offset_to_r16(r11) + stw r3, _thread_offset_to_r17(r11) + stw r4, _thread_offset_to_r18(r11) + stw ra, _thread_offset_to_ra(r11) + stw sp, _thread_offset_to_sp(r11) + + call read_timer_end_of_swap + + /* Get a reference to _kernel in r10 */ + movhi r10, %hi(_kernel) + ori r10, r10, %lo(_kernel) + + /* Get the pointer to kernel->current */ + ldw r11, _kernel_offset_to_current(r10) + ldw r2, _thread_offset_to_r16(r11) + ldw r3, _thread_offset_to_r17(r11) + ldw r4, _thread_offset_to_r18(r11) + ldw ra, _thread_offset_to_ra(r11) + ldw sp, _thread_offset_to_sp(r11) +#endif ret diff --git a/drivers/timer/altera_avalon_timer_hal.c b/drivers/timer/altera_avalon_timer_hal.c index d7c0936cf2..822c71167a 100644 --- a/drivers/timer/altera_avalon_timer_hal.c +++ b/drivers/timer/altera_avalon_timer_hal.c @@ -19,12 +19,22 @@ static void timer_irq_handler(void *unused) { ARG_UNUSED(unused); +#ifdef CONFIG_EXECUTION_BENCHMARKING + extern void read_timer_start_of_tick_handler(void); + read_timer_start_of_tick_handler(); +#endif + accumulated_cycle_count += sys_clock_hw_cycles_per_tick; /* Clear the interrupt */ alt_handle_irq((void *)TIMER_0_BASE, TIMER_0_IRQ); _sys_clock_tick_announce(); + +#ifdef CONFIG_EXECUTION_BENCHMARKING + extern void read_timer_end_of_tick_handler(void); + read_timer_end_of_tick_handler(); +#endif } int _sys_clock_driver_init(struct device *device) diff --git a/tests/benchmarks/timing_info/src/timing_info.h b/tests/benchmarks/timing_info/src/timing_info.h index 6bd45a4a03..834e579147 100644 --- a/tests/benchmarks/timing_info/src/timing_info.h +++ b/tests/benchmarks/timing_info/src/timing_info.h @@ -68,6 +68,24 @@ #define TIMING_INFO_GET_TIMER_VALUE() (k_cycle_get_32()) #define SUBTRACT_CLOCK_CYCLES(val) ((u32_t)val) +#elif CONFIG_NIOS2 +#include "altera_avalon_timer_regs.h" +#define TIMING_INFO_PRE_READ() \ + (IOWR_ALTERA_AVALON_TIMER_SNAPL(TIMER_0_BASE, 10)) + +#define TIMING_INFO_OS_GET_TIME() (SUBTRACT_CLOCK_CYCLES(\ + ((u32_t)IORD_ALTERA_AVALON_TIMER_SNAPH(TIMER_0_BASE) << 16)\ + | ((u32_t)IORD_ALTERA_AVALON_TIMER_SNAPL(TIMER_0_BASE)))) + +#define TIMING_INFO_GET_TIMER_VALUE() (\ + ((u32_t)IORD_ALTERA_AVALON_TIMER_SNAPH(TIMER_0_BASE) << 16)\ + | ((u32_t)IORD_ALTERA_AVALON_TIMER_SNAPL(TIMER_0_BASE))) + +#define SUBTRACT_CLOCK_CYCLES(val) \ + ((IORD_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE) \ + << 16 | \ + (IORD_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE))) \ + - ((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 0059ab8e86..fc2306047e 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 xtensa + arch_whitelist: x86 arm arc xtensa nios2 tags: benchmark benchmark.timing.userspace: filter: CONFIG_ARCH_HAS_USERSPACE