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 <zhangyuan29@xiaomi.com>
This commit is contained in:
zhangyuan29 2026-05-20 11:42:32 +08:00 committed by Lup Yuen Lee
parent 426a5154d9
commit 4f98bb32ae
4 changed files with 75 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,69 @@
/****************************************************************************
* arch/tricore/src/common/tricore_perf.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/arch.h>
#include <nuttx/clock.h>
#include "tricore_internal.h"
#ifdef CONFIG_ARCH_PERF_EVENTS
/****************************************************************************
* Private Data
****************************************************************************/
static unsigned long g_cpu_freq = ULONG_MAX;
/****************************************************************************
* Public Functions
****************************************************************************/
void up_perf_init(void *arg)
{
g_cpu_freq = (unsigned long)(uintptr_t)arg;
IfxCpu_resetAndStartCounters(IfxCpu_CounterMode_normal);
}
unsigned long up_perf_getfreq(void)
{
return g_cpu_freq;
}
clock_t up_perf_gettime(void)
{
return (clock_t)IfxCpu_getClockCounter();
}
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