Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU usage is too high when clone device by v4l2loopback #549

Open
trungthanhnguyen0502 opened this issue Jul 20, 2023 · 5 comments
Open
Assignees
Labels
needs triage new issues

Comments

@trungthanhnguyen0502
Copy link

trungthanhnguyen0502 commented Jul 20, 2023

I use v4l2loopback + Gstreamer to clone device. Sometimes Using this plugin results in very high CPU usage.

Step 2: Environment

  • v4l2loopback version: v0.12.7 and main (9ba7e29)
  • kernel version: 5.10.104-tegra
  • Distribution (+version): Ubuntu 20.04.5 LTS
  • Jetson xavier nx: JetPack 5.0.2.
  • Deepstream and Gstreamer version are 6.1.1 and 1.16.3.

Step 3: Describe the problem:

Steps to reproduce:

  1. Create virtual devices:
    sudo modprove v4l2loopback devices=3

  2. Clone the data stream from the original device to virtual devices.

gst-launch-1.0 v4l2src device=/dev/video0 ! videorate drop-only=true ! "video/x-raw,framerate=(fraction)30/1" !
tee name=t ! queue ! v4l2sink device=/dev/video1 sync=false async=true
t. ! queue ! v4l2sink device=/dev/video2 sync=false async=true
t. ! queue ! v4l2sink device=/dev/video3 sync=false async=true

Observed Results:

  • In good case, CPU usage like that:

low-cpu

  • but most of the cases i run this gst-launch command, CPU usage is too high. like that:

high-cpu

Or worst case like that:
Screenshot from 2023-07-20 15-56-46

I've checked and not see any strange programs that can cause this problem. I see that someone else had the same problem, Nvidia supporter said "For CPU usage, it is probably v4l2loopback as well causing high CPU load. high-cpu-usage-for-video-capturing

Screenshot from 2023-07-20 15-06-23

Expected Results:

I want to know why CPU usage is too high and how to fix it. Because this problem affects my system a lot.

@trungthanhnguyen0502 trungthanhnguyen0502 changed the title To much CPU usage when clone device by v4l2loopback CPU usage too high when clone device by v4l2loopback Jul 20, 2023
@trungthanhnguyen0502 trungthanhnguyen0502 changed the title CPU usage too high when clone device by v4l2loopback CPU usage is too high when clone device by v4l2loopback Jul 20, 2023
@umlaeute
Copy link
Owner

hmm, well.
the high CPU load you see is obviously in user-space (the green bar), which is GStreamer.
the load in kernel-space (the red bar), which is where you would see anything done by v4l2loopback, seems to be pretty constant.

so i conclude that the v4l2loopback is not doing any excessive work, but instead GStreamer is.
(it could still be a problem with v4l2loopback that makes GStreamer burn your CPU cycles).

so, if I were you, i would do some analysis where GStreamer is spending its time (and see whether something can be done on the v4l2loopback side of things)

@trungthanhnguyen0502
Copy link
Author

I tried some analysis with simple gstreamer command. When I run
gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! appsink
CPU usage is 17%.

But when I replace appsink with v4l2sink (to a virtual device created by v4l2loopback). CPU usage is 60%.

@chrisiberg
Copy link

I think your problem hast to do with missing DMA support, or am I wrong? @umlaeute
#501

@sanbrother
Copy link
Contributor

sanbrother commented Sep 4, 2023

I think your problem hast to do with missing DMA support, or am I wrong? @umlaeute #501

Will copy without DMA consume a lot of CPU? mmap still costs high CPU usage?

@angeelalg
Copy link

  • kernel version: 5.10.104-tegra
  • Distribution (+version): Ubuntu 20.04.5 LTS
  • Jetson xavier nx: JetPack 5.0.2.
  • Deepstream and Gstreamer version are 6.1.1 and 1.16.3.

Hello @trungthanhnguyen0502 , good morning.

How did you get v4l2loopback working for you? I'm trying to get my Jetson NX to work, with the same kernel version and it's impossible. I keep getting this error when running modprobe v4l2loopback:
modprobe: ERROR: could not insert 'v4l2loopback': Operation not permitted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage new issues
Projects
None yet
Development

No branches or pull requests

5 participants