Skip to content

testing/ostest: build the perf test only where it can link - #3676

Open
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:ostest-perf-flat-only
Open

testing/ostest: build the perf test only where it can link#3676
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:ostest-perf-flat-only

Conversation

@casaroli

Copy link
Copy Markdown
Contributor

Summary

testing/ostest cannot link in a protected or kernel build whenever
CONFIG_ARCH_PERF_EVENTS is set.

perf_gettime() and perf_getfreq() are kernel functions, defined in
sched/clock/clock_perf.c. Neither appears in syscall.csv, and
libs/libc/sched/clock_perf.c supplies only perf_gettime(), gated on
CONFIG_ARCH_HAVE_PERF_EVENTS_USER_ACCESS. So user space has no way to reach
either symbol unless the build is flat.

The pieces disagree about when to use them:

  • testing/ostest/Makefile / CMakeLists.txt compile perf_gettime.c when
    CONFIG_ARCH_HAVE_PERF_EVENTS is set.
  • ostest_main.c calls perf_gettime_test() when CONFIG_ARCH_PERF_EVENTS
    is set and CONFIG_ARCH_PERF_EVENTS_USER_ACCESS is not — which is exactly
    the case where the symbols are kernel-only.

So any protected/kernel configuration with ARCH_PERF_EVENTS=y fails to link:

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

mps3-an547:knsh is one, because its defconfig sets CONFIG_SCHED_IRQMONITOR,
which makes ARCH_PERF_EVENTS default y. mps2-an521:knsh and
mps2-an500:knsh escape only because they set neither SCHED_IRQMONITOR nor
SCHED_CRITMONITOR, so ARCH_PERF_EVENTS is off, the call compiles out and
the archive member is never pulled in.

This adds CONFIG_BUILD_FLAT to all four sites, which is where ostest links
against the kernel's own copy of these functions.

Impact

No configuration that runs this test today stops running it — flat builds are
untouched. Protected and kernel builds that previously could not link ostest
at all now build, and skip the one test they could never have executed.

Users affected: anyone enabling TESTING_OSTEST on a BUILD_PROTECTED or
BUILD_KERNEL target with SCHED_IRQMONITOR, SCHED_CRITMONITOR,
RPMSG_PING or SEGGER_SYSVIEW enabled (the four that make
ARCH_PERF_EVENTS default y).

No API, Kconfig or documentation change.

Testing

Host: macOS 15.5 (Darwin 25.5.0), Apple Silicon; arm-none-eabi-gcc 14.2.Rel1;
QEMU 11.0.3.

Target: mps3-an547:knsh — Armv8-M, Cortex-M55, BUILD_PROTECTED, the
configuration that exposed this.

Before — link fails:

arm-none-eabi-ld: apps/testing/ostest/perf_gettime.c:91:(.text.perf_gettime_test+0x12):
    undefined reference to `perf_gettime'
arm-none-eabi-ld: apps/testing/ostest/perf_gettime.c:184:(.text.perf_gettime_test+0x1bc):
    undefined reference to `perf_getfreq'
make[1]: *** [nuttx_user.elf] Error 1
make: *** [nuttx] Error 2

After — both blobs link:

   text	   data	    bss	    dec	    hex	filename
 256663	   1020	  10160	 267843	  41643	nuttx
 176857	    640	   3088	 180585	  2c169	nuttx_user.elf

and the image boots to NSH and runs ostest under
qemu-system-arm -M mps3-an547.

The flat path is unchanged by construction — the patch only ever adds a
condition, so no build that compiled perf_gettime.c before and still
satisfies CONFIG_BUILD_FLAT is affected.

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 <marco.casaroli@gmail.com>

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants