Jiaqi-YP7 opened a new pull request, #18858:
URL: https://github.com/apache/nuttx/pull/18858

   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](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## 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:
   
   ```cmake
   set(OPENAMP_VERSION 2025.10.0)
   ```
   
   ```make
   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`:
   
   ```cmake
   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:
   
   ```c
   #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:
   
   ```make
   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:
   
   ```text
   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:
   
   ```sh
   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:
   
   ```text
   CMake Warning:
     Manually-specified variables were not used by the project:
   
       WITH_DCACHE_VRINGS
   ```
   
   Built OpenAMP:
   
   ```sh
   cmake --build /tmp/openamp-cmake-before --target open_amp-static -j8
   ```
   
   Output:
   
   ```text
   [100%] Linking C static library libopen_amp.a
   [100%] Built target open_amp-static
   ```
   
   Checked whether `VIRTIO_USE_DCACHE` was added to compile commands:
   
   ```sh
   grep -n "WITH_DCACHE_VRINGS\|VIRTIO_USE_DCACHE" \
        /tmp/openamp-cmake-before/CMakeCache.txt \
        /tmp/openamp-cmake-before/compile_commands.json
   ```
   
   Output:
   
   ```text
   
/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:
   
   ```sh
   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:
   
   ```text
   == 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:
   
   ```sh
   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:
   
   ```sh
   cmake --build /tmp/openamp-cmake-after --target open_amp-static -j8
   ```
   
   Output:
   
   ```text
   [100%] Linking C static library libopen_amp.a
   [100%] Built target open_amp-static
   ```
   
   Checked that `VIRTIO_USE_DCACHE` is present in compile commands:
   
   ```sh
   grep -n "WITH_DCACHE:BOOL\|VIRTIO_USE_DCACHE" \
        /tmp/openamp-cmake-after/CMakeCache.txt \
        /tmp/openamp-cmake-after/compile_commands.json
   ```
   
   Output excerpt:
   
   ```text
   /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:
   
   ```sh
   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:
   
   ```text
   == 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.
   
   


-- 
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