From 4008b11d0c2388dd7712915046368526a4df856c Mon Sep 17 00:00:00 2001 From: Gabriel Wang Date: Sat, 6 Jul 2024 07:19:50 +0100 Subject: [PATCH] add __perfc_sync_barrier__(); --- perf_counter.c | 1 + perf_counter.h | 15 ++++++++++++++- perfc_port_default.h | 5 +++++ perfc_port_pmu.h | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/perf_counter.c b/perf_counter.c index b74fb0f..74b6f01 100644 --- a/perf_counter.c +++ b/perf_counter.c @@ -146,6 +146,7 @@ void update_perf_counter(void) __IRQ_SAFE { g_lLastTimeStamp = get_system_ticks(); + __perfc_sync_barrier__(); g_nOffset = get_system_ticks() - g_lLastTimeStamp; } } diff --git a/perf_counter.h b/perf_counter.h index 56e6ab4..7e9b445 100644 --- a/perf_counter.h +++ b/perf_counter.h @@ -333,6 +333,17 @@ __super_loop_monitor__() __asm(".global __ensure_systick_wrapper\n\t"); # endif +#ifndef __perfc_sync_barrier__ + +/* default implementation */ +#if defined(__clang__) || __IS_COMPILER_GCC__ +# define __perfc_sync_barrier__(...) __sync_synchronize() +#else +# define __perfc_sync_barrier__(...) +#endif + +#endif + #endif /*! @} */ @@ -358,7 +369,9 @@ __asm(".global __ensure_systick_wrapper\n\t"); */ #define __cycleof__(__STR, ...) \ using(int64_t _ = get_system_ticks(), __cycle_count__ = _, \ - _=_, { \ + {__perfc_sync_barrier__();}, \ + { \ + __perfc_sync_barrier__(); \ _ = get_system_ticks() - _ - g_nOffset; \ __cycle_count__ = _; \ if (__PLOOC_VA_NUM_ARGS(__VA_ARGS__) == 0) { \ diff --git a/perfc_port_default.h b/perfc_port_default.h index e7fedac..8247d89 100644 --- a/perfc_port_default.h +++ b/perfc_port_default.h @@ -27,6 +27,11 @@ /*============================ MACROS ========================================*/ /*============================ MACROFIED FUNCTIONS ===========================*/ + +#ifndef __perfc_sync_barrier__ +# define __perfc_sync_barrier__(...) do {__DSB();__ISB();} while(0) +#endif + /*============================ TYPES =========================================*/ typedef uint32_t perfc_global_interrupt_status_t; diff --git a/perfc_port_pmu.h b/perfc_port_pmu.h index 2962c1e..044f82d 100644 --- a/perfc_port_pmu.h +++ b/perfc_port_pmu.h @@ -23,6 +23,11 @@ /*============================ MACROS ========================================*/ /*============================ MACROFIED FUNCTIONS ===========================*/ +#ifndef __perfc_sync_barrier__ +# define __perfc_sync_barrier__(...) do {__DSB();__ISB();} while(0) +#endif + + #define __cpu_perf__(__str, ...) \ using( \ struct { \