Message ID | 20241112100051.4071443-3-chenghaoyang@chromium.org |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Harvey Yang <chenghaoyang@chromium.org> writes: > 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@chromium.org> Reviewed-by: Milan Zamazal <mzamazal@redhat.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..852e14f20 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.get(), DmaBufAllocator::SyncType::Read); > + > + for (const FrameBuffer::Plane &plane : output->planes()) > + dmaSyncers.emplace_back(plane.fd.get(), DmaBufAllocator::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 &&
diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index cf5ecdf7a..852e14f20 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.get(), DmaBufAllocator::SyncType::Read); + + for (const FrameBuffer::Plane &plane : output->planes()) + dmaSyncers.emplace_back(plane.fd.get(), DmaBufAllocator::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 &&
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@chromium.org> --- src/libcamera/software_isp/debayer_cpu.cpp | 29 ++++++---------------- 1 file changed, 8 insertions(+), 21 deletions(-)