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_perf.c b/arch/tricore/src/common/tricore_perf.c new file mode 100644 index 00000000000..e73c6ba3f0f --- /dev/null +++ b/arch/tricore/src/common/tricore_perf.c @@ -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 +#include + +#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