Closed jeroen-verfailie closed 1 year ago
Hi, thanks for this. I also get the segfault. This needs to be fixed in gstreamer1.0-plugin-imx though, not in libimxdmabuffer. The latter is not meant to be thread safe (for performance reasons). I'll think about how to address this properly.
Thanks for the response!
just let me know if you need any extra info / need a branch tested.
Try out latest git master. It should be fixed.
Tested with latest on our setup, works like a charm! Thanks for this!!
CPU: IMX6 DualLite Used camera: OV7740 Similar results when using ION and IPU allocator
Kernel version: 5.4.70-F+S gstreamer (and plugins) version: 1.16.2.imx-r0 gstreamer1.0-plugins-imx version: 2.1.0 (rev d14c9b4dce2062a58246740e7399d423a28a34a4) libimxvpuapi version: 2.2.2 libimxdmabuffer version: 1.1.2
All build with yocto 3.0.4 (Zeus)
Consider the following pipeline (called from a bash script), which splits the source into three sinks: (Some parameters, e.g. $mjpg_framerate, are passed to the shell script).
After a few frames (varying in amount; between 1 and typically 30) , this pipeline crashes with a SEGFAULT.
The line where it crashes is in video-frame.c in the gstreamer1.0-plugins base, where the source frame is copied to the destination:
The corresponding backtrace can be found here:
Very probable cause for this crash is a threading problem when mapping / unmapping the buffer:
Take as example the
imx_dma_buffer_ion_allocator_unmap
inimxdmabuffer_ion_allocator.c
(all part of libimxdmabuffer). Without locking,imx_ion_buffer->mapping_refcount--;
could be called by two or more threads at the same time, resulting in a never unmapped buffer. This would cause the allocator to never be unallocated, resulting in an ever shrinking available CMA memory space. This was observed with our pipeline.Likewise,
imx_ion_buffer->mapping_refcount--
inimxdmabuffer_ion_allocator.c
andimx_ion_buffer->mapping_refcount++
could conflict in a similar way, resulting in an unmapped buffer before the frame was copied, resulting in the SEGFAULT.As a test (real patch can be found further below), we fixed this issue by adding a lock around
imx_dma_buffer_unmap
andimx_dma_buffer_map
ingstimxdmabufallocator.c
:in
gst_imx_dmabuf_allocator_mem_map_full
:in
gst_imx_dmabuf_allocator_mem_unmap_full
:Other allocators would require locks in other places, e.g. in
gstimxdefaultallocator.c
. Alternatively, the issue could be fixed in the libimxdmabuffer repo.This solved our issue: All three video streams runs smoothly without SEGFAULT.
At the moment, we solved our issue by applying the patch below to libimxdmabuffer:
0002-make-threadsafe.patch
I'm not sure if it would be better to either fix this issue in the gstreamer1.0-plugin-imx, or in the libimxdmabuffer. Either way, a lock resolved our issues.
The reason I'm posting this: Is this an issue that requires resolving by the maintainers of either this or the libimxdmabuffer repo, or are we doing something weird / wrong, resulting in this threading problem?