v4l2codecs: allocator: Keep dmabuf mapped
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 8 Apr 2021 18:53:52 +0000 (14:53 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 8 Apr 2021 19:22:49 +0000 (15:22 -0400)
DMABuf allocator already implements DMABuf Sync, meaning that doing
mmap/munmap (unless the mode have changed) is not required. In fact, on
systems with IOMMU it makes the kernel redo the mmu table which is visible
in the CPU usage.

This change reduces CPU usage when decoding
bbb_sunflower_2160p_60fps_normal.mp4 on RK3399 SoC from over 30% to
around 15%.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2152>

sys/v4l2codecs/gstv4l2codecallocator.c

index d18e8bb..e288698 100644 (file)
@@ -90,7 +90,8 @@ gst_v4l2_codec_buffer_new (GstAllocator * allocator, GstV4l2Decoder * decoder,
   buf->index = index;
   buf->num_mems = num_mems;
   for (i = 0; i < buf->num_mems; i++) {
-    GstMemory *mem = gst_dmabuf_allocator_alloc (allocator, fds[i], sizes[i]);
+    GstMemory *mem = gst_fd_allocator_alloc (allocator, fds[i], sizes[i],
+        GST_FD_MEMORY_FLAG_KEEP_MAPPED);
     gst_memory_resize (mem, offsets[i], sizes[i] - offsets[i]);
 
     GST_MINI_OBJECT (mem)->dispose = gst_v4l2_codec_allocator_release;