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

jiuzhudong 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 bb562cf8bff arch/armv8-r64: userspace PMU access
bb562cf8bff is described below

commit bb562cf8bffc118374ce76302f871b5d676ddc23
Author: hujun5 <[email protected]>
AuthorDate: Mon Jun 23 15:59:17 2025 +0800

    arch/armv8-r64: userspace PMU access
    
    Enable ARCH_HAVE_PERF_EVENTS_USER_ACCESS capability for Cortex-R82 to
    allow userspace applications to directly access hardware performance
    counters. Move up_perf_gettime() outside kernel-only block so it can
    be called from userspace for efficient profiling.
    
    Signed-off-by: hujun5 <[email protected]>
---
 arch/arm64/Kconfig                   |  1 +
 arch/arm64/src/common/CMakeLists.txt |  5 +++++
 arch/arm64/src/common/Make.defs      |  4 ++++
 arch/arm64/src/common/arm64_perf.c   | 21 ++++++++++++---------
 4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index d465216c7ef..b67086be943 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -340,6 +340,7 @@ config ARCH_CORTEX_R82
        select ARCH_HAVE_CLUSTER_PMU
        select ARCH_HAVE_TESTSET
        select ARM64_HAVE_NEON
+       select ARCH_HAVE_PERF_EVENTS_USER_ACCESS if !ARCH_CLUSTER_PMU
 
 config ARCH_CPU_UNKNOWN
        bool
diff --git a/arch/arm64/src/common/CMakeLists.txt 
b/arch/arm64/src/common/CMakeLists.txt
index 28b9f589de9..9ea89c4d0d9 100644
--- a/arch/arm64/src/common/CMakeLists.txt
+++ b/arch/arm64/src/common/CMakeLists.txt
@@ -142,6 +142,11 @@ endif()
 
 target_sources(arch PRIVATE ${SRCS})
 
+if(NOT CONFIG_BUILD_FLAT AND CONFIG_ARCH_HAVE_PERF_EVENTS_USER_ACCESS)
+  target_sources(arch_interface PRIVATE arm64_perf.c)
+  target_include_directories(arch_interface PRIVATE ${NUTTX_CHIP_ABS_DIR})
+endif()
+
 nuttx_add_aux_library(STARTUP_OBJS crt0.c)
 
 target_compile_options(
diff --git a/arch/arm64/src/common/Make.defs b/arch/arm64/src/common/Make.defs
index 28608e8ae4b..f41ed4f096a 100644
--- a/arch/arm64/src/common/Make.defs
+++ b/arch/arm64/src/common/Make.defs
@@ -141,3 +141,7 @@ endif
 ifeq ($(CONFIG_ARM64_SEMIHOSTING_HOSTFS),y)
   CMN_CSRCS += arm64_hostfs.c
 endif
+
+ifeq ($(CONFIG_ARCH_HAVE_PERF_EVENTS_USER_ACCESS),y)
+  CMN_UCSRCS += arm64_perf.c
+endif
diff --git a/arch/arm64/src/common/arm64_perf.c 
b/arch/arm64/src/common/arm64_perf.c
index 6d042ee7780..509c983c0d6 100644
--- a/arch/arm64/src/common/arm64_perf.c
+++ b/arch/arm64/src/common/arm64_perf.c
@@ -30,6 +30,7 @@
 
 #ifdef CONFIG_ARCH_HAVE_PERF_EVENTS
 
+#  if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -64,15 +65,6 @@ unsigned long up_perf_getfreq(void)
   return g_cpu_freq;
 }
 
-clock_t up_perf_gettime(void)
-{
-#ifdef CONFIG_ARCH_CLUSTER_PMU
-  return pmu_get_cluccntr();
-#else
-  return pmu_get_ccntr();
-#endif
-}
-
 void up_perf_convert(clock_t elapsed, struct timespec *ts)
 {
   clock_t left;
@@ -81,4 +73,15 @@ void up_perf_convert(clock_t elapsed, struct timespec *ts)
   left        = elapsed - ts->tv_sec * g_cpu_freq;
   ts->tv_nsec = NSEC_PER_SEC * left / g_cpu_freq;
 }
+#  endif /* CONFIG_BUILD_FLAT || __KERNEL__ */
+
+clock_t up_perf_gettime(void)
+{
+#  ifdef CONFIG_ARCH_CLUSTER_PMU
+  return pmu_get_cluccntr();
+#  else
+  return pmu_get_ccntr();
+#  endif
+}
+
 #endif

Reply via email to