From e5b414a6e969ab763953477e06e3cadb045b76a2 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Wed, 29 Jul 2026 14:04:14 +0200 Subject: [PATCH] testing/ostest: build the perf test only where it can link perf_gettime() and perf_getfreq() are kernel functions, defined in sched/clock/clock_perf.c. Neither appears in syscall.csv, and libc supplies only perf_gettime(), under CONFIG_ARCH_HAVE_PERF_EVENTS_USER_ACCESS. So a protected or kernel build cannot resolve either of them from user space: ostest/perf_gettime.c:91: undefined reference to `perf_gettime' ostest/perf_gettime.c:184: undefined reference to `perf_getfreq' make[1]: *** [nuttx_user.elf] Error 1 The call in user_main() is guarded by CONFIG_ARCH_PERF_EVENTS && !CONFIG_ARCH_PERF_EVENTS_USER_ACCESS -- which is exactly the case where the symbols are kernel-only -- so every such configuration fails to link. mps3-an547:knsh is one: it sets CONFIG_SCHED_IRQMONITOR, which makes ARCH_PERF_EVENTS default y. mps2-an521:knsh escapes only because it sets neither monitor, leaving ARCH_PERF_EVENTS off, so the call compiles out and the archive member is never pulled in. Require CONFIG_BUILD_FLAT, where ostest links against the kernel's own copy. No configuration that runs the test today stops running it. Signed-off-by: Marco Casaroli Assisted-by: Claude Opus 5 (1M context) --- testing/ostest/CMakeLists.txt | 5 ++++- testing/ostest/Makefile | 5 +++++ testing/ostest/ostest.h | 2 +- testing/ostest/ostest_main.c | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/testing/ostest/CMakeLists.txt b/testing/ostest/CMakeLists.txt index 74103db4118..180d7090a7b 100644 --- a/testing/ostest/CMakeLists.txt +++ b/testing/ostest/CMakeLists.txt @@ -161,7 +161,10 @@ if(CONFIG_TESTING_OSTEST) list(APPEND SRCS nxevent.c) endif() - if(CONFIG_ARCH_HAVE_PERF_EVENTS) + # perf_gettime() and perf_getfreq() live in the kernel and are not system + # calls, so only a flat build can reach them from here. + + if(CONFIG_ARCH_HAVE_PERF_EVENTS AND CONFIG_BUILD_FLAT) list(APPEND SRCS perf_gettime.c) endif() diff --git a/testing/ostest/Makefile b/testing/ostest/Makefile index f443ecb0b39..4919a6204f9 100644 --- a/testing/ostest/Makefile +++ b/testing/ostest/Makefile @@ -164,9 +164,14 @@ CSRCS += nxevent.c endif endif +# perf_gettime() and perf_getfreq() live in the kernel and are not system +# calls, so only a flat build can reach them from here. + ifeq ($(CONFIG_ARCH_HAVE_PERF_EVENTS),y) +ifeq ($(CONFIG_BUILD_FLAT),y) CSRCS += perf_gettime.c endif +endif ifeq ($(CONFIG_BUILD_FLAT),y) CSRCS += wdog.c spinlock.c diff --git a/testing/ostest/ostest.h b/testing/ostest/ostest.h index 5e01626c0e2..2be54de5a68 100644 --- a/testing/ostest/ostest.h +++ b/testing/ostest/ostest.h @@ -304,7 +304,7 @@ void spinlock_test(void); /* perf_gettime.c ***********************************************************/ -#ifdef CONFIG_ARCH_HAVE_PERF_EVENTS +#if defined(CONFIG_ARCH_HAVE_PERF_EVENTS) && defined(CONFIG_BUILD_FLAT) void perf_gettime_test(void); #endif diff --git a/testing/ostest/ostest_main.c b/testing/ostest/ostest_main.c index 92224701f9b..964771d907c 100644 --- a/testing/ostest/ostest_main.c +++ b/testing/ostest/ostest_main.c @@ -656,7 +656,8 @@ static int user_main(int argc, char *argv[]) check_test_memory_usage(); #endif -#if defined(CONFIG_ARCH_PERF_EVENTS) && !defined(CONFIG_ARCH_PERF_EVENTS_USER_ACCESS) +#if defined(CONFIG_ARCH_PERF_EVENTS) && \ + !defined(CONFIG_ARCH_PERF_EVENTS_USER_ACCESS) && defined(CONFIG_BUILD_FLAT) /* Verify performance event time counter */ printf("\nuser_main: performance event time counter test\n");