This is an automated email from the ASF dual-hosted git repository. lupyuen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 4f98bb32aec6062efb7ff8c9e6bf362d9cdc17e1 Author: zhangyuan29 <[email protected]> AuthorDate: Wed May 20 11:42:32 2026 +0800 arch/tricore: add up_perf function for tricore Add performance counter support for TriCore architecture using the CPU clock counter (CCNT). Implements up_perf_init, up_perf_getfreq, up_perf_gettime and up_perf_convert interfaces. Signed-off-by: zhangyuan29 <[email protected]> --- arch/tricore/src/common/CMakeLists.txt | 1 + arch/tricore/src/common/Make.defs | 1 + arch/tricore/src/common/tricore_initialize.c | 4 ++ .../{tricore_initialize.c => tricore_perf.c} | 63 +++++++++------------- 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/arch/tricore/src/common/CMakeLists.txt b/arch/tricore/src/common/CMakeLists.txt index 19bcfe4f7eb..68a7c3553e1 100644 --- a/arch/tricore/src/common/CMakeLists.txt +++ b/arch/tricore/src/common/CMakeLists.txt @@ -35,6 +35,7 @@ set(SRCS tricore_irq.c tricore_main.c tricore_nputs.c + tricore_perf.c tricore_registerdump.c tricore_releasestack.c tricore_saveusercontext.c diff --git a/arch/tricore/src/common/Make.defs b/arch/tricore/src/common/Make.defs index 4817dc830c0..2a02e7d736a 100644 --- a/arch/tricore/src/common/Make.defs +++ b/arch/tricore/src/common/Make.defs @@ -36,6 +36,7 @@ CMN_CSRCS += tricore_initialstate.c CMN_CSRCS += tricore_irq.c CMN_CSRCS += tricore_main.c CMN_CSRCS += tricore_nputs.c +CMN_CSRCS += tricore_perf.c CMN_CSRCS += tricore_registerdump.c CMN_CSRCS += tricore_releasestack.c CMN_CSRCS += tricore_saveusercontext.c diff --git a/arch/tricore/src/common/tricore_initialize.c b/arch/tricore/src/common/tricore_initialize.c index 5757ea93435..8420b934521 100644 --- a/arch/tricore/src/common/tricore_initialize.c +++ b/arch/tricore/src/common/tricore_initialize.c @@ -62,6 +62,10 @@ volatile bool g_interrupt_context[CONFIG_SMP_NCPUS]; void up_initialize(void) { +#ifdef CONFIG_ARCH_PERF_EVENTS + up_perf_init((void *)IFX_CFG_CPU_CLOCK_FREQUENCY); +#endif + tricore_trapinit(); #ifdef CONFIG_ARCH_ICACHE diff --git a/arch/tricore/src/common/tricore_initialize.c b/arch/tricore/src/common/tricore_perf.c similarity index 54% copy from arch/tricore/src/common/tricore_initialize.c copy to arch/tricore/src/common/tricore_perf.c index 5757ea93435..e73c6ba3f0f 100644 --- a/arch/tricore/src/common/tricore_initialize.c +++ b/arch/tricore/src/common/tricore_perf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/tricore/src/common/tricore_initialize.c + * arch/tricore/src/common/tricore_perf.c * * SPDX-License-Identifier: Apache-2.0 * @@ -25,56 +25,45 @@ ****************************************************************************/ #include <nuttx/arch.h> -#include <nuttx/board.h> -#include <nuttx/cache.h> -#include <arch/board/board.h> +#include <nuttx/clock.h> #include "tricore_internal.h" +#ifdef CONFIG_ARCH_PERF_EVENTS + /**************************************************************************** - * Public Data + * Private Data ****************************************************************************/ -/* g_interrupt_context store irq status */ - -volatile bool g_interrupt_context[CONFIG_SMP_NCPUS]; +static unsigned long g_cpu_freq = ULONG_MAX; /**************************************************************************** * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: up_initialize - * - * Description: - * up_initialize will be called once during OS initialization after the - * basic OS services have been initialized. The architecture specific - * details of initializing the OS will be handled here. Such things as - * setting up interrupt service routines, starting the clock, and - * registering device drivers are some of the things that are different - * for each processor and hardware platform. - * - * up_initialize is called after the OS initialized but before the user - * initialization logic has been started and before the libraries have - * been initialized. OS services and driver services are available. - * - ****************************************************************************/ - -void up_initialize(void) +void up_perf_init(void *arg) { - tricore_trapinit(); + g_cpu_freq = (unsigned long)(uintptr_t)arg; -#ifdef CONFIG_ARCH_ICACHE - up_enable_icache(); -#endif + IfxCpu_resetAndStartCounters(IfxCpu_CounterMode_normal); +} -#ifdef CONFIG_ARCH_DCACHE - up_enable_dcache(); -#endif +unsigned long up_perf_getfreq(void) +{ + return g_cpu_freq; +} - /* Initialize the serial device driver */ +clock_t up_perf_gettime(void) +{ + return (clock_t)IfxCpu_getClockCounter(); +} -#ifdef USE_SERIALDRIVER - tricore_serialinit(); -#endif +void up_perf_convert(clock_t elapsed, struct timespec *ts) +{ + clock_t left; + + ts->tv_sec = elapsed / g_cpu_freq; + left = elapsed - ts->tv_sec * g_cpu_freq; + ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq; } +#endif
