[PATCH v3 2/2] debayer_cpu: Replace syncing DMABUFs with DmaSyncer

Kieran Bingham kieran.bingham at ideasonboard.com
Thu Nov 21 13:18:46 CET 2024


Quoting Harvey Yang (2024-11-21 05:51:32)
> As there's an existing helper class DmaSyncer that makes synchronizing
> DMABUFs more easily, this patch removes the self-defined function and
> reuse DmaSyncer.
> 
> Signed-off-by: Harvey Yang <chenghaoyang at chromium.org>
> Reviewed-by: Milan Zamazal <mzamazal at redhat.com>


Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

> ---
>  src/libcamera/software_isp/debayer_cpu.cpp | 29 ++++++----------------
>  1 file changed, 8 insertions(+), 21 deletions(-)
> 
> diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp
> index cf5ecdf7a..31ab96ab3 100644
> --- a/src/libcamera/software_isp/debayer_cpu.cpp
> +++ b/src/libcamera/software_isp/debayer_cpu.cpp
> @@ -20,6 +20,7 @@
>  #include <libcamera/formats.h>
>  
>  #include "libcamera/internal/bayer_format.h"
> +#include "libcamera/internal/dma_buf_allocator.h"
>  #include "libcamera/internal/framebuffer.h"
>  #include "libcamera/internal/mapped_framebuffer.h"
>  
> @@ -722,23 +723,6 @@ void DebayerCpu::process4(const uint8_t *src, uint8_t *dst)
>  
>  namespace {
>  
> -void syncBufferForCPU(FrameBuffer *buffer, uint64_t syncFlags)
> -{
> -       for (const FrameBuffer::Plane &plane : buffer->planes()) {
> -               const int fd = plane.fd.get();
> -               struct dma_buf_sync sync = { syncFlags };
> -               int ret;
> -
> -               ret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
> -               if (ret < 0) {
> -                       ret = errno;
> -                       LOG(Debayer, Error)
> -                               << "Syncing buffer FD " << fd << " with flags "
> -                               << syncFlags << " failed: " << strerror(ret);
> -               }
> -       }
> -}
> -
>  inline int64_t timeDiff(timespec &after, timespec &before)
>  {
>         return (after.tv_sec - before.tv_sec) * 1000000000LL +
> @@ -756,8 +740,12 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output
>                 clock_gettime(CLOCK_MONOTONIC_RAW, &frameStartTime);
>         }
>  
> -       syncBufferForCPU(input, DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ);
> -       syncBufferForCPU(output, DMA_BUF_SYNC_START | DMA_BUF_SYNC_WRITE);
> +       std::vector<DmaSyncer> dmaSyncers;
> +       for (const FrameBuffer::Plane &plane : input->planes())
> +               dmaSyncers.emplace_back(plane.fd, DmaSyncer::SyncType::Read);
> +
> +       for (const FrameBuffer::Plane &plane : output->planes())
> +               dmaSyncers.emplace_back(plane.fd, DmaSyncer::SyncType::Write);
>  
>         green_ = params.green;
>         red_ = swapRedBlueGains_ ? params.blue : params.red;
> @@ -786,8 +774,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output
>  
>         metadata.planes()[0].bytesused = out.planes()[0].size();
>  
> -       syncBufferForCPU(output, DMA_BUF_SYNC_END | DMA_BUF_SYNC_WRITE);
> -       syncBufferForCPU(input, DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ);
> +       dmaSyncers.clear();
>  
>         /* Measure before emitting signals */
>         if (measuredFrames_ < DebayerCpu::kLastFrameToMeasure &&
> -- 
> 2.47.0.338.g60cca15819-goog
>


More information about the libcamera-devel mailing list