Performance regression when using vcsm-cma instead of vcsm, with zero copy MMAL

Open
#5,286 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
c, linux

Research direction

Reproduce the regression by applying the linked patch to RaspiVid.c and running the resulting raspivid binary with '-o foo.h264'. Compare the first-20-row timings and CPU usage with vcsm and vcsm-cma, using the stated firmware and kernel versions; done means explaining or correcting the slowdown while preserving zero-copy MMAL behavior.

Written by the indexing model from the issue text.

Description

Describe the bug

When using MMAL_PARAMETER_ZERO_COPY in combination with vcsm-cma, using the cpu to read from frames captured by a camera in MMAL_ENCODING_I420 format slows down significantly -- taking over 30x longer in a particular benchmark, compared to using the previous vcsm implementation.

In addition to the greater time taken, the CPU usage reported by top is higher (~20% instead of ~2%). Removing the calls to set MMAL_PARAMETER_ZERO_COPY regains the faster timing, but CPU usage remains high.

Steps to reproduce the behaviour

The problem can be seen by applying the patch at https://gist.github.com/malc0/0a9ee21fd92ecc1e37a18fa6507b069e to RaspiVid.c from the current (54fd97ae4066a10b6b02089bc769ceed328737e0) userland repository, and comparing the output of running the resulting raspivid binary with '-o foo.h264'. Using the final 5.4 kernel from the firmware repository (8cd76653b88939baf25c3f9d9ce90657bcc19b76) the time to read the first 20 rows of a 1920 pixels-wide image is ~200 microseconds. Renaming /dev/vcsm to something else results in the vcsm-cma mechanism being used, and the same delay is typically greater than 6000 microseconds. Using the most recent 5.15.x firmware commit (494eb71e5adfca31ec65dd535fce73de3c7c2efa) shows similar times for vcsm-cma, but comparison to vcsm isn't possible.

Device (s)

Raspberry Pi 3 Mod. B+

System

OS: Raspbian GNU/Linux 11, dist-upgraded from jessie originally installed using https://github.com/debian-pi/raspbian-ua-netinst

vcgencmd version: Dec 12 2022 12:00:07
Copyright (c) 2012 Broadcom
version ed6f6b8fcdc6476410b9cf75d141633461d34bdd (clean) (release) (start_x)

uname -a: Linux localhost 5.15.83-v7+ #1607 SMP Thu Dec 15 12:55:05 GMT 2022 armv7l GNU/Linux

Logs

No response

Additional context

cmdline.txt:
dwc_otg.lpm_enable=0 dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

config.txt:
start_x=1
gpu_mem=256
dtoverlay=cma,cma-96
dtoverlay=disable-bt

Dominant language
C
Stars
13.2k
Forks
5.5k
Avg merge
2d 21h
Merged PRs (30d)
21

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/linux

All issues in raspberrypi/linux

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.