mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
This change enables performance monitoring unit (PMU) access from userspace on ARMv7-R architecture by adding CONFIG_ARCH_HAVE_PERF_EVENTS_USER_ACCESS support and building PMU code for userspace when needed. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -41,7 +41,7 @@ NSH (Flat Build)
|
||||
Configuring NuttX and compile::
|
||||
|
||||
$ ./tools/configure.sh -l qemu-armv7r:nsh
|
||||
$ make -j`nproc`
|
||||
$ make -j$(nproc)
|
||||
|
||||
Running with qemu::
|
||||
|
||||
@@ -58,7 +58,7 @@ with MPU support::
|
||||
|
||||
$ cd nuttx
|
||||
$ ./tools/configure.sh qemu-armv7r:pnsh
|
||||
$ make -j`nproc`
|
||||
$ make -j$(nproc)
|
||||
|
||||
Running with qemu (note: both nuttx and nuttx_user must be loaded)::
|
||||
|
||||
@@ -106,4 +106,93 @@ The nuttx ELF image can be debugged with QEMU.
|
||||
|
||||
$ arm-none-eabi-gdb -tui --eval-command='target remote localhost:1234' nuttx
|
||||
(gdb) add-symbol-file nuttx_user
|
||||
(gdb) c
|
||||
(gdb) c
|
||||
|
||||
=====================
|
||||
Userspace PMU Access
|
||||
=====================
|
||||
|
||||
Overview
|
||||
========
|
||||
|
||||
This document describes how to enable and use Performance Monitoring Unit (PMU)
|
||||
access from userspace applications on the ARM v7-R QEMU board. The PMU provides
|
||||
hardware performance counters that can be used to analyze and profile application
|
||||
performance.
|
||||
|
||||
1. ARM v7-R QEMU board support
|
||||
2. NuttX kernel with PMU support enabled
|
||||
3. User-space access permissions configured
|
||||
|
||||
Kernel Configuration
|
||||
--------------------
|
||||
|
||||
To enable PMU support and userspace access, add the following configuration
|
||||
options to your defconfig::
|
||||
|
||||
+CONFIG_ARCH_PERF_EVENTS_USER_ACCESS=y
|
||||
+CONFIG_ARCH_PERF_EVENTS=y
|
||||
|
||||
|
||||
Userspace API
|
||||
|
||||
**perf_gettime**
|
||||
================
|
||||
|
||||
Basic Usage
|
||||
-----------
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
clock_t start, end;
|
||||
unsigned long frequency;
|
||||
unsigned long cycles;
|
||||
|
||||
frequency = perf_getfreq();
|
||||
if (frequency == 0) {
|
||||
printf("ERROR: Performance frequency not available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Operation Profiling Results:\n");
|
||||
printf("CPU Frequency: %lu Hz\n\n", frequency);
|
||||
printf("%-40s | %-12s | %-12s\n", "Operation", "Cycles", "Time (us)");
|
||||
printf("%-40s-+-%-12s-+-%-12s\n",
|
||||
"----------------------------------------",
|
||||
"------------", "------------");
|
||||
|
||||
start = perf_gettime();
|
||||
result = 1;
|
||||
for (int i = 1; i < 1000; i++) {
|
||||
result *= i;
|
||||
}
|
||||
|
||||
end = perf_gettime();
|
||||
cycles = end - start;
|
||||
printf("%-40s | %12lu | %12lu\n", "Multiplication (1K times)", cycles, (cycles * 1000000UL) / frequency);
|
||||
|
||||
start = perf_gettime();
|
||||
result = 1000000;
|
||||
for (int i = 1; i < 1000; i++) {
|
||||
result /= (i + 1);
|
||||
}
|
||||
end = perf_gettime();
|
||||
cycles = end - start;
|
||||
|
||||
printf("%-40s | %12lu | %12lu\n", "Division (1K times)", cycles, (cycles * 1000000UL) / frequency);
|
||||
|
||||
Testing with QEMU
|
||||
=================
|
||||
|
||||
PNSH (Protected) Configuration
|
||||
-------------------------------
|
||||
|
||||
For protected build with userspace PMU access::
|
||||
|
||||
$ ./tools/configure.sh qemu-armv7r:pnsh
|
||||
$ make -j$(nproc)
|
||||
|
||||
2. Run QEMU (load both kernel and userspace)::
|
||||
|
||||
$ qemu-system-arm -M virt -semihosting -nographic -cpu cortex-r5f -device loader,file=nuttx_user -device loader,file=nuttx
|
||||
|
||||
|
||||
Reference in New Issue
Block a user