hujun260 opened a new pull request, #18214:
URL: https://github.com/apache/nuttx/pull/18214

   ## Summary
   Enable performance monitoring unit (PMU) access from userspace on ARMv7-R
   architecture by implementing `CONFIG_ARCH_HAVE_PERF_EVENTS_USER_ACCESS` 
support.
   This allows userspace applications to access PMU performance event counters 
for
   profiling and performance monitoring without requiring kernel privileges.
   
   ## Motivation and Problem
   Previously, performance monitoring functions were only available to kernel 
code.
   Applications requiring performance profiling, benchmarking, or real-time 
monitoring
   needed to rely on kernel-mode operations. By enabling userspace PMU access, 
   applications can directly measure performance metrics like cycle counts 
without
   the overhead of system calls or context switches to kernel mode.
   
   ## Changes
   - Add `CONFIG_ARCH_HAVE_PERF_EVENTS_USER_ACCESS` selection in Kconfig for 
ARMv7-R
   - Update CMakeLists.txt to compile arm_perf.c for userspace when not using 
flat build
   - Add userspace source (CMN_UCSRCS) compilation in Make.defs
   - Refactor arm_perf.c to conditionally expose PMU functions to userspace:
     - Move `up_perf_gettime()` outside kernel-only ifdef block
     - Keep internal PMU state management (g_cpu_freq) kernel-only
     - Enable direct userspace access to cp15_pmu_rdccr() for cycle counting
   
   ## Impact
   - **Performance Profiling**: Userspace applications can now measure PMU 
cycle counts
   - **Real-time Monitoring**: Applications can perform runtime performance 
analysis
   - **Reduced Overhead**: Direct userspace access eliminates system call 
overhead
   - **Backward Compatibility**: Kernel code behavior unchanged; flat builds 
unaffected
   - **Architecture Support**: Extends performance event support to userspace 
on ARMv7-R
   - **Performance**: No performance degradation; reduces overhead compared to 
syscall-based profiling
   
   ## Verification
   - [x] Code compiles without warnings on ARM GCC 10.x
   - [x] Verified on QEMU ARMv7-R simulator
   - [x] PMU cycle counting functions verified accessible from userspace
   - [x] Kernel PMU state management (g_cpu_freq) remains protected
   - [x] Flat build and kernel-only configurations unaffected
   - [x] No conflicts with existing kernel PMU code
   
   ## Testing
   Tested with:
   - ARM GCC 10.x compiler
   - QEMU ARMv7-R simulation
   - Non-flat build configurations with userspace PMU access enabled
   - PMU cycle counter access from userspace context
   - Kernel PMU operations in kernel code paths
   
   ## Related Issues
   Adds support for userspace performance event monitoring on ARMv7-R 
architecture.
   Reference: https://github.com/apache/nuttx/pull/17909
   
   ## Files Changed
   - `arch/arm/Kconfig` (1 line: 1 insertion, 0 deletions)
   - `arch/arm/src/armv7-r/CMakeLists.txt` (5 lines: 5 insertions, 0 deletions)
   - `arch/arm/src/armv7-r/Make.defs` (4 lines: 4 insertions, 0 deletions)
   - `arch/arm/src/armv7-r/arm_perf.c` (13 lines: 8 insertions, 5 deletions)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to