This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e1eee13d5e arch/arm/imx6: Start the perf counter with 
ARCH_PERF_EVENTS.
3e1eee13d5e is described below

commit 3e1eee13d5e1d4b741e438a4fe581e0386f2c89a
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Nov 4 14:57:54 2026 +0100

    arch/arm/imx6: Start the perf counter with ARCH_PERF_EVENTS.
    
    The i.MX6 never calls up_perf_init(), so the PMU cycle counter does not
    run and its rate stays ULONG_MAX.  With ARCH_PERF_EVENTS (the default with
    SCHED_CRITMONITOR) all perf times are then 0, and ostest perf_gettime_test
    fails.
    
    Call up_perf_init() at the end of arm_boot(), and
    arm_perf_secondary_init() in arm_cpu_boot(), as the qemu, goldfish and
    rtl8730e chips do.  The cycle counter counts CPU clocks.  NuttX keeps the
    clock from U-Boot, which board.h and imx_clockconfig.c give as 792 MHz, so
    add BOARD_CPU_FREQUENCY with this value to board.h.  up_perf_init(0) is
    not correct here: it reads CNTFRQ, and the Cortex-A9 has no generic timer.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 arch/arm/src/imx6/imx_boot.c                | 6 ++++++
 arch/arm/src/imx6/imx_cpuboot.c             | 4 ++++
 boards/arm/imx6/sabre-6quad/include/board.h | 2 ++
 3 files changed, 12 insertions(+)

diff --git a/arch/arm/src/imx6/imx_boot.c b/arch/arm/src/imx6/imx_boot.c
index 91cedbb65ac..1635e767669 100644
--- a/arch/arm/src/imx6/imx_boot.c
+++ b/arch/arm/src/imx6/imx_boot.c
@@ -497,6 +497,12 @@ void arm_boot(void)
   PROGRESS('P');
 #endif
 
+#ifdef CONFIG_ARCH_PERF_EVENTS
+  /* Start the cycle counter of this CPU */
+
+  up_perf_init((void *)BOARD_CPU_FREQUENCY);
+#endif
+
   /* Now we can enable all other CPUs.  The enabled CPUs will start execution
    * at __cpuN_start and, after very low-level CPU initialization has been
    * performed, will branch to arm_cpu_boot()
diff --git a/arch/arm/src/imx6/imx_cpuboot.c b/arch/arm/src/imx6/imx_cpuboot.c
index 5e13cd65003..8dbc3ba49f0 100644
--- a/arch/arm/src/imx6/imx_cpuboot.c
+++ b/arch/arm/src/imx6/imx_cpuboot.c
@@ -261,6 +261,10 @@ void arm_cpu_boot(int cpu)
 
   up_irqinitialize();
 
+#ifdef CONFIG_ARCH_PERF_EVENTS
+  arm_perf_secondary_init();
+#endif
+
   /* The next thing that we expect to happen is for logic running on CPU0
    * to call up_cpu_start() which generate an SGI and a context switch to
    * the configured NuttX IDLE task.
diff --git a/boards/arm/imx6/sabre-6quad/include/board.h 
b/boards/arm/imx6/sabre-6quad/include/board.h
index 219daf63d21..8a841d33afe 100644
--- a/boards/arm/imx6/sabre-6quad/include/board.h
+++ b/boards/arm/imx6/sabre-6quad/include/board.h
@@ -73,6 +73,8 @@
  * For now, NuttX simply leaves the clocking at 792MHz.
  */
 
+#define BOARD_CPU_FREQUENCY 792000000
+
 /* LED definitions **********************************************************/
 
 /* LEDs

Reply via email to