Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Config render params by 3.2.2 v4l2-ctl capture command

image-20240322-102852.png

4

...

Writing video data from V4L2 video buffer to the file system involves two issues:

  • CPU read memory speed

  • File system write speed

In the sp7350 environment, the file system write speed during testing can be resolved by writing data to /tmp(RAM).

There are some issues with the CPU reading speed when reading data generated by Camera, which will be explained in detail below:

Three memory management models(vb2_mem_ops) have been implemented under the V4L2 video buffer 2 framework, namely dma-contiguous, dma-scatter gas, and vmalloc. According to the hardware characteristics of sp7350, the V4L2 buffer model used to receive MIPICSI-RX data can only be defined as dma-contiguous. The DMA mappings type requested by dma-contiguous is Consistent DMA mappings.

Consistent DMA mappings which are usually mapped at driver initialization, unmapped at the end and for which the hardware should guarantee that the device and the CPU can access the data in parallel and will see updates made by each other without any explicit software flushing(This function is usually achieved by disabling the CPU cache).

When the CPU reads data from the V4L2 video buffer and writes it to a file, it cannot use CPU cache to read the contents of the V4L2 video buffer. The situation will cause an increase in the required number of reads and CPU loading when reading the same data.

4.1 Why remap V4L2 video buffer dma memory

By remapping the DMA buffer, the CPU can use CPU cache to read V4L2 video buffer, improving CPU read performance and reducing CPU loading.

4.2 How to remap V4L2 video buffer dma

After system startup, execute the following command to enable remapping V4L2 video buffer.(Default disbale)

Code Block
echo Y > /sys/module/videobuf2_dma_contig/parameters/dmaremap

Execute the following command to disable remapping V4L2 video buffer:

Code Block
echo N > /sys/module/videobuf2_dma_contig/parameters/dmaremap

4.3 Test report

UYVY 1920*1080@30FPS (bitrate 124.416MB/s):

Code Block
v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=UYVY --set-parm=30 --stream-mmap=10 --stream-to=/tmp/OV5640_UYVY_1080P_001.raw --stream-skip=3 --stream-count=180

...

CPU Loading

...

FPS

...

Enable remap

...

32%

...

30 fps

...

Disable remap

...

100%

...

15 fps

UYVY 1280*720@30FPS (bitrate 55.296 MB/s):

Code Block
v4l2-ctl -d /dev/video0 --set-fmt-video=width=1280,height=720,pixelformat=UYVY --set-parm=30 --stream-mmap=10 --stream-to=/tmp/OV5640_UYVY_720P_001.raw --stream-skip=3 --stream-count=180 

...

CPU Loading

...

FPS

...

Enable remap

...

14.6%

...

30 fps

...

Disable remap

...

88.1%

...

30 fps

UYVY 640*480@30FPS (bitrate 18.432MB/s):

Code Block
v4l2-ctl -d /dev/video0 --set-fmt-video=width=640,height=480,pixelformat=UYVY --set-parm=30 --stream-mmap=10 --stream-to=/tmp/OV5640_UYVY_480P_001.raw --stream-skip=3 --stream-count=180

...

CPU Loading

...

FPS

...

Enable remap

...

5.2%

...

30 fps

...

Disable remap

...

34.7%

...

30 fps

...

Performance testing of OV5640 on SP7350

rootfs:Yocto

tools:v4l2-ctl

...

test frame count: 300 Frame

...

4.1 Do not write camera data to rootfs

Test command:

Code Block
nohup v4l2-ctl -d /dev/video0 --set-fmt-video=width=1280,height=720,pixelformat=UYVY --set-parm=60 --stream-mmap=10 --stream-count=300 > my_script.log 2>&1 &
top -d 0.5 | grep "v4l2-ctl"

...

Frame size/Frame rate/Format

bitrate

CPU loading

memory

FPS

drop frame

1920*1080@30FPS UYVY

124.416MB/s

1.9%

0.0

30

NO

1920*1080@15FPS UYVY

62.208MB/s

1.9%

0.0

15

NO

1280*720@60FPS UYVY

110.592MB/s

2.0%

0.0

60

NO

1280*720@30FPS UYVY

55.296MB/s

1.9%

0.0

30

NO

1280*720@15FPS UYVY

27.648MB/s

2.0%

0.0

15

NO

640*480@60FPS UYVY

36.864MB/s

1.9%

0.0

60

NO

640*480@30FPS UYVY

18.432MB/s

1.9%

0.0

30

NO

640*480@15FPS UYVY

9.216MB/s

1.9%

0.0

15

NO

...

4.2 Write camera data to rootfs

Test command:

Code Block
echo Y > /sys/module/videobuf2_dma_contig/parameters/dmaremap
nohup v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=UYVY --set-parm=30 --stream-mmap=10 --stream-count=300 --stream-to=/tmp/OV5640_UYVY_1080P_30FPS.yuv > my_script.log 2>&1 &
top -d 0.5 | grep "v4l2-ctl"

...