Skip to content

openamp: fix CMake dcache option#18858

Merged
simbit18 merged 1 commit intoapache:masterfrom
Jiaqi-YP7:fix/openamp-cmake-dcache
May 10, 2026
Merged

openamp: fix CMake dcache option#18858
simbit18 merged 1 commit intoapache:masterfrom
Jiaqi-YP7:fix/openamp-cmake-dcache

Conversation

@Jiaqi-YP7
Copy link
Copy Markdown
Contributor

OpenAMP 2025.10.0 removed the deprecated WITH_DCACHE_VRINGS, WITH_DCACHE_BUFFERS and WITH_DCACHE_RSC_TABLE CMake options. The replacement is WITH_DCACHE, which enables VIRTIO_USE_DCACHE for vrings, buffers and resource table cache operations.

Use WITH_DCACHE for CONFIG_OPENAMP_CACHE in the CMake integration so the CMake build matches the Makefile path, which already defines VIRTIO_USE_DCACHE directly.

Note: Please adhere to Contributing Guidelines.

Summary

Fix the OpenAMP CMake integration to use the cache option supported by the
current OpenAMP version.

NuttX selects OpenAMP 2025.10.0 in both build integrations:

set(OPENAMP_VERSION 2025.10.0)
OPENAMP_VERSION ?= 2025.10.0

For this OpenAMP version, WITH_DCACHE_VRINGS is no longer consumed by
OpenAMP CMake. The supported option is WITH_DCACHE, which defines
VIRTIO_USE_DCACHE:

option (WITH_DCACHE "Build with all cache operations enabled" OFF)

if (WITH_DCACHE)
  add_definitions(-DVIRTIO_USE_DCACHE)
endif()

The OpenAMP cache maintenance helpers are guarded by VIRTIO_USE_DCACHE.
For example:

#if defined(VIRTIO_USE_DCACHE)
#define VRING_FLUSH(x, s)       metal_cache_flush(x, s)
#define VRING_INVALIDATE(x, s)  metal_cache_invalidate(x, s)
#else
#define VRING_FLUSH(x, s)       do { } while (0)
#define VRING_INVALIDATE(x, s)  do { } while (0)
#endif

The Makefile integration already uses the correct macro directly:

ifeq ($(CONFIG_OPENAMP_CACHE),y)
  CFLAGS += -DVIRTIO_USE_DCACHE
endif

This change updates the CMake integration to set WITH_DCACHE when
CONFIG_OPENAMP_CACHE is enabled, matching the Makefile behavior.

Impact

This affects CMake builds with CONFIG_OPENAMP_CACHE=y.

Before this change, the CMake build set WITH_DCACHE_VRINGS, a deprecated
OpenAMP option that is no longer consumed by OpenAMP 2025.10.0. As a result,
VIRTIO_USE_DCACHE was not enabled through OpenAMP CMake.

After this change, CMake builds enable the intended OpenAMP cache maintenance
path for vrings, RPMsg buffers, and resource table.

Makefile builds are not affected, since they already define
VIRTIO_USE_DCACHE directly.

Testing

Host:

Ubuntu 20.04.6 LTS x86_64
GCC 9.4.0
CMake 3.22.3

The validation was done by building the OpenAMP CMake target directly with the
same OpenAMP source selected by NuttX. This isolates the CMake option mapping
and proves whether VIRTIO_USE_DCACHE is passed to OpenAMP compilation.

Before: old option does not enable OpenAMP cache code

Configured OpenAMP with the old option used by NuttX CMake before this change:

cmake -S nuttx/openamp/open-amp \
      -B /tmp/openamp-cmake-before \
      -DWITH_LIBMETAL_FIND=OFF \
      -DWITH_PROXY=OFF \
      -DWITH_SHARED_LIB=OFF \
      -DWITH_STATIC_LIB=ON \
      -DWITH_DCACHE_VRINGS=ON \
      -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
      -DCMAKE_C_FLAGS=-I/home/yjq/nuttx/include

CMake reported that the old option is not used:

CMake Warning:
  Manually-specified variables were not used by the project:

    WITH_DCACHE_VRINGS

Built OpenAMP:

cmake --build /tmp/openamp-cmake-before --target open_amp-static -j8

Output:

[100%] Linking C static library libopen_amp.a
[100%] Built target open_amp-static

Checked whether VIRTIO_USE_DCACHE was added to compile commands:

grep -n "WITH_DCACHE_VRINGS\|VIRTIO_USE_DCACHE" \
     /tmp/openamp-cmake-before/CMakeCache.txt \
     /tmp/openamp-cmake-before/compile_commands.json

Output:

/tmp/openamp-cmake-before/CMakeCache.txt:190:WITH_DCACHE_VRINGS:UNINITIALIZED=ON

VIRTIO_USE_DCACHE was absent from compile_commands.json.

Checked the OpenAMP objects:

for o in \
  /tmp/openamp-cmake-before/lib/CMakeFiles/open_amp-static.dir/virtio/virtqueue.c.o \
  /tmp/openamp-cmake-before/lib/CMakeFiles/open_amp-static.dir/rpmsg/rpmsg_virtio.c.o \
  /tmp/openamp-cmake-before/lib/CMakeFiles/open_amp-static.dir/remoteproc/remoteproc_virtio.c.o; do
  echo "== ${o##*/} =="
  nm "$o" | grep -E "metal_cache_(flush|invalidate)" || echo "no metal_cache symbols"
done

Output:

== virtqueue.c.o ==
no metal_cache symbols
== rpmsg_virtio.c.o ==
no metal_cache symbols
== remoteproc_virtio.c.o ==
no metal_cache symbols

This confirms that the old CMake option does not enable OpenAMP cache
maintenance code.

After: new option enables OpenAMP cache code

Configured OpenAMP with the option used by this change:

cmake -S nuttx/openamp/open-amp \
      -B /tmp/openamp-cmake-after \
      -DWITH_LIBMETAL_FIND=OFF \
      -DWITH_PROXY=OFF \
      -DWITH_SHARED_LIB=OFF \
      -DWITH_STATIC_LIB=ON \
      -DWITH_DCACHE=ON \ 
      -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
      -DCMAKE_C_FLAGS=-I/home/lixiang/yjq/nuttx/include

Built OpenAMP:

cmake --build /tmp/openamp-cmake-after --target open_amp-static -j8

Output:

[100%] Linking C static library libopen_amp.a
[100%] Built target open_amp-static

Checked that VIRTIO_USE_DCACHE is present in compile commands:

grep -n "WITH_DCACHE:BOOL\|VIRTIO_USE_DCACHE" \
     /tmp/openamp-cmake-after/CMakeCache.txt \
     /tmp/openamp-cmake-after/compile_commands.json

Output excerpt:

/tmp/openamp-cmake-after/CMakeCache.txt:187:WITH_DCACHE:BOOL=ON
/tmp/openamp-cmake-after/compile_commands.json:14:  "command": "/usr/bin/cc -DVIRTIO_DEVICE_SUPPORT=1 -DVIRTIO_DRIVER_SUPPORT=1 -DVIRTIO_USE_DCACHE -DVQ_RX_EMPTY_NOTIFY=0 ... -c /home/lixiang/learning/opennuttx/nuttx/openamp/open-amp/lib/virtio/virtqueue.c",
/tmp/openamp-cmake-after/compile_commands.json:24:  "command": "/usr/bin/cc -DVIRTIO_DEVICE_SUPPORT=1 -DVIRTIO_DRIVER_SUPPORT=1 -DVIRTIO_USE_DCACHE -DVQ_RX_EMPTY_NOTIFY=0 ... -c /home/lixiang/learning/opennuttx/nuttx/openamp/open-amp/lib/rpmsg/rpmsg_virtio.c",
/tmp/openamp-cmake-after/compile_commands.json:39:  "command": "/usr/bin/cc -DVIRTIO_DEVICE_SUPPORT=1 -DVIRTIO_DRIVER_SUPPORT=1 -DVIRTIO_USE_DCACHE -DVQ_RX_EMPTY_NOTIFY=0 ... -c /home/lixiang/learning/opennuttx/nuttx/openamp/open-amp/lib/remoteproc/remoteproc_virtio.c",

Checked the OpenAMP objects:

for o in \
  /tmp/openamp-cmake-after/lib/CMakeFiles/open_amp-static.dir/virtio/virtqueue.c.o \
  /tmp/openamp-cmake-after/lib/CMakeFiles/open_amp-static.dir/rpmsg/rpmsg_virtio.c.o \
  /tmp/openamp-cmake-after/lib/CMakeFiles/open_amp-static.dir/remoteproc/remoteproc_virtio.c.o; do
  echo "== ${o##*/} =="
  nm "$o" | grep -E "metal_cache_(flush|invalidate)"
done

Output:

== virtqueue.c.o ==
0000000000000340 t __metal_cache_flush
000000000000034e t __metal_cache_invalidate
000000000000035c t metal_cache_flush
000000000000037f t metal_cache_invalidate
== rpmsg_virtio.c.o ==
00000000000002d2 t __metal_cache_flush
00000000000002e0 t __metal_cache_invalidate
00000000000002ee t metal_cache_flush
0000000000000311 t metal_cache_invalidate
== remoteproc_virtio.c.o ==
0000000000000454 t __metal_cache_flush
0000000000000462 t __metal_cache_invalidate
0000000000000470 t metal_cache_flush
0000000000000493 t metal_cache_invalidate

This confirms that WITH_DCACHE enables VIRTIO_USE_DCACHE and compiles in
the OpenAMP cache maintenance helpers.

@Jiaqi-YP7 Jiaqi-YP7 requested a review from xiaoxiang781216 as a code owner May 9, 2026 05:43
@github-actions github-actions Bot added the Size: XS The size of the change in this PR is very small label May 9, 2026
@lupyuen
Copy link
Copy Markdown
Member

lupyuen commented May 10, 2026

Hi: Could you Rebase your PR with the Master Branch? We fixed the Config Error for esp32p4-function-ev-board. Thanks :-)

OpenAMP 2025.10.0 removed the deprecated WITH_DCACHE_VRINGS, WITH_DCACHE_BUFFERS and WITH_DCACHE_RSC_TABLE CMake options. The replacement is WITH_DCACHE, which enables VIRTIO_USE_DCACHE for vrings, buffers and resource table cache operations.

Use WITH_DCACHE for CONFIG_OPENAMP_CACHE in the CMake integration so the CMake build matches the Makefile path, which already defines VIRTIO_USE_DCACHE directly.

Signed-off-by: yaojiaqi <yaojiaqi@lixiang.com>
@Jiaqi-YP7 Jiaqi-YP7 force-pushed the fix/openamp-cmake-dcache branch from ff8c6eb to c4453c3 Compare May 10, 2026 05:48
@Jiaqi-YP7
Copy link
Copy Markdown
Contributor Author

Hi: Could you Rebase your PR with the Master Branch? We fixed the Config Error for esp32p4-function-ev-board. Thanks :-)

Thanks for the heads-up and the fix! I've rebased my PR with the master branch.

@simbit18 simbit18 merged commit b17e448 into apache:master May 10, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants