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 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2025-06-23 15:59:17 +08:00
committed by Donny(董九柱)
parent dea1bc1121
commit bb562cf8bf
4 changed files with 22 additions and 9 deletions
+1
View File
@@ -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
+5
View File
@@ -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(
+4
View File
@@ -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
+12 -9
View File
@@ -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