# V4l2 high cpu usage

**URL:** <https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721>\
**Category:** Jetson Xavier NX\
**Tags:** camera\
**Created:** [January 16, 2023, 9:58am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721 "2023-01-16T09:58:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 16, 2023, 9:58am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/1 "2023-01-16T09:58:10Z")

</div>

Hello, we now use the nx module to connect 4 cameras. our program is made by v4l2.  
When a program is stress-test(streamon, streamclose), the CPU occupies 100%. and program freezes.

We test jetpack 4.6.1

The top command output is as follows:

 ![save](https://global.discourse-cdn.com/nvidia/original/3X/2/7/27a4bbd5bd35c814632a9abbd4b5b0d5f5be23d9.png)

How can I reduce the CPU usage

I referenced

> [@Orin in jp5.0.2 camera \[vi output, imx1\] process cpu occupies 100%](https://forums.developer.nvidia.com/t/orin-in-jp5-0-2-camera-vi-output-imx1-process-cpu-occupies-100/233703):
>
> Hello, we now use the orin module to connect 6 cameras. When a camera is disconnected, the CPU occupies 100%. The top command output is as follows: 8459 root 20 0 0 0 0 R 100.0 0.0 54:25.96 [vi-output, imx1] At the same time, other normal camera outputs are as follows: 8454 root 20 0 0 0 0 D 0.3 0.0 0:06.38 [vi-output, imx1] 8456 root 20 0 0 0 0 S 0.3 0.0 0:04.68 [vi-output, imx1] How can I reduce the CPU usage

> [@V4L2 timeout leads to NULL pointer dereference in kernel in jetpack 4.6](https://forums.developer.nvidia.com/t/v4l2-timeout-leads-to-null-pointer-dereference-in-kernel-in-jetpack-4-6/187824/18):
>
> Hi Jerry, I got the same log as below, user@localhost:~$ [473.931631] tegra194-vi5 15c10000.vi: no reply from camera processor [473.931790] tegra194-vi5 15c10000.vi: uncorr\_err: request timed out after 2500 ms [473.931971] tegra194-vi5 15c10000.vi: err\_rec: attempting to reset the capture channel [473.935223] Unable to handle kernel NULL pointer dereference at virtual address 00000010 [473.935391] Mem abort info: [473.935478] ESR = 0x96000005 [473.935539] Exception cla…

There was no effect.

---

<div class="post-metadata">

**Author:** ![JerryChang](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jerrychang/32/14043_2.png) [@JerryChang](https://forums.developer.nvidia.com/u/JerryChang)\
**Post date:** [January 17, 2023, 2:37am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/3 "2023-01-17T02:37:00Z")

</div>

> [@rlatae123](#):
>
> When a program is stress-test(streamon, streamclose), the CPU occupies 100%. and program freezes.

hello rlatae123,

you may try using `renice` utility to configure the program to have higher priority, this should ensure your program to grant CPU resources.  
however, this looks unreal use-case, stress tool intent to fully occupy CPU resources.

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 17, 2023, 6:44am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/4 "2023-01-17T06:44:14Z")

</div>

but when i tested jetpack 4.4.1 no errors occur.

it could be our program’s fault, so we additionally tested it using v4l2-ctl

we met same error

 ![Screenshot from 2023-01-17 15-32-10](https://global.discourse-cdn.com/nvidia/original/3X/d/6/d6a12a1c4e264e7f0a1b45e1057cca671ff875ff.jpeg)  
e

---

<div class="post-metadata">

**Author:** ![JerryChang](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jerrychang/32/14043_2.png) [@JerryChang](https://forums.developer.nvidia.com/u/JerryChang)\
**Post date:** [January 17, 2023, 7:49am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/5 "2023-01-17T07:49:16Z")

</div>

hello rlatae123,

there shows discarding frame messages, which is VI driver side to drop capture buffers due to unsuccessful capture state.  
have you try using `renice` utility to configure the program to have higher priority, is this helps?

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 17, 2023, 8:27am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/6 "2023-01-17T08:27:53Z")

</div>

we using renice but same error

 ![Screenshot from 2023-01-17 17-20-54](https://global.discourse-cdn.com/nvidia/original/3X/5/4/5415e1a53cabe3249bdfd8c831f68f5ed20d7922.png)

when I debuging our program,  
randomly the one video channel(ex. video0 ~ 3) is meet select timeout error between v4l2 stream on and v4l2 dqbuf

---

<div class="post-metadata">

**Author:** ![JerryChang](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jerrychang/32/14043_2.png) [@JerryChang](https://forums.developer.nvidia.com/u/JerryChang)\
**Post date:** [January 17, 2023, 8:34am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/7 "2023-01-17T08:34:05Z")

</div>

hello rlatae123,

there’re some fixes check-in to refine buffer handling for Xavier series driver.  
is it possible for moving to latest release, i.e. JetPack-4.6.3/ L4T 32.7.3 for testing?

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 17, 2023, 8:39am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/8 "2023-01-17T08:39:49Z")

</div>

Okay I’ll test it

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 17, 2023, 10:17am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/9 "2023-01-17T10:17:45Z")

</div>

hello @JerryChang

we test 4.6.3

vi-output process appears first and then disappears. But the issues are the same.

randomly the one video channel(ex. video0 ~ 3) is meet select timeout error between v4l2 stream on and v4l2 dqbuf

hear are our test code

where the error occurs:

> type = V4L2\_TYPE;  
> xioctl(g\_fd, VIDIOC\_STREAMON, &type);

```
CLEAR(G_DELAY_BUF);
G_DELAY_BUF.type = V4L2_TYPE;
G_DELAY_BUF.memory = V4L2_MEMORY_MMAP;

do {
	FD_ZERO(&fds);
	FD_SET(g_fd, &fds);

	/* Timeout. */
	tv.tv_sec = 2;
	tv.tv_usec = 0;

	r = select(g_fd + 1, &fds, NULL, NULL, &tv);
} while ((r == -1 && (errno = EINTR)));
if (r == -1) { perror("select"); return errno; }

if(-1 == xioctl(g_fd, VIDIOC_DQBUF, &G_DELAY_BUF)) {
		errno_exit("VIDIOC_DQBUF");
}

```

 ![Screenshot from 2023-01-17 19-07-28](https://global.discourse-cdn.com/nvidia/original/3X/9/f/9face874ff798225ec9094a3360b8dbf6a14a73e.png)

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 18, 2023, 1:24am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/10 "2023-01-18T01:24:24Z")

</div>

our v4l2-ctl device setting:

 ![Screenshot from 2023-01-18 10-17-41](https://global.discourse-cdn.com/nvidia/original/3X/2/4/24510cb3793673f0ab19f88b8da27878ed13160b.png)

trace log :  
[log.txt](https://forums.developer.nvidia.com/uploads/short-url/sPdnGbKH3czD9npyjZHKQXMhCdw.txt) (7.3 MB)

we test vi5 debug

> sudo echo ‘file csi5\_fops.c +p’ \> /sys/kernel/debug/dynamic\_debug/control

but error is the same

---

<div class="post-metadata">

**Author:** ![JerryChang](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jerrychang/32/14043_2.png) [@JerryChang](https://forums.developer.nvidia.com/u/JerryChang)\
**Post date:** [January 18, 2023, 2:03am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/11 "2023-01-18T02:03:40Z")

</div>

hello rlatae123,

just for confirmation. could you please check this is related to CPU heavy loading. is it continuous stream-on/off to increase the CPU usage?  
in other words, please narrow down the issue, please check you have good camera stability. is your normal camera stream use-case works as expect?

besides,  
we’ll also gather resources to setup an environment to reproduce the issue locally.

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 18, 2023, 2:25am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/12 "2023-01-18T02:25:08Z")

</div>

so how can i test camera stability?

Can I get some advice?

---

<div class="post-metadata">

**Author:** ![JerryChang](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jerrychang/32/14043_2.png) [@JerryChang](https://forums.developer.nvidia.com/u/JerryChang)\
**Post date:** [January 18, 2023, 2:41am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/13 "2023-01-18T02:41:38Z")

</div>

hello rlatae123,

please refer to developer guide, [Approaches for Validating and Testing the V4L2 Driver](https://docs.nvidia.com/jetson/archives/l4t-archived/l4t-3273/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/jetson_xavier_camera_soft_archi.html#wwpID0E0YB0HA).  
you may check… `$ v4l2-ctl -d /dev/video0 --list-formats-ext` for your sensor supported formats.  
please see-also below sample pipelines to test your stream, please update the settings with your sensor supported formats accordingly.  
for example,  
`$ v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=RG10 --set-ctrl bypass_mode=0 --stream-mmap --stream-count=100`

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 18, 2023, 3:54am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/14 "2023-01-18T03:54:01Z")

</div>

Sorry I thought the errors were gone but it wasn’t

we test v4l2-ctl command in jetpack 4.6.3

errors appear after serveral repetitions

Is this a camera problem?

error\_1ch

 ![error_1ch](https://global.discourse-cdn.com/nvidia/original/3X/0/3/03ddc819d2bab19cf889423ba375ebfd2172a9a4.jpeg)

error\_3ch

 ![error](https://global.discourse-cdn.com/nvidia/original/3X/c/2/c26c6e5dd940346d77417a3f9d4d62e874f1b33e.jpeg)

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 18, 2023, 10:39am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/17 "2023-01-18T10:39:42Z")

</div>

@JerryChang

Is there anything else I can check?

---

<div class="post-metadata">

**Author:** ![JerryChang](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jerrychang/32/14043_2.png) [@JerryChang](https://forums.developer.nvidia.com/u/JerryChang)\
**Post date:** [January 19, 2023, 2:21am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/18 "2023-01-19T02:21:37Z")

</div>

hello rlatae123,

we cannot reproduce the same failure.  
the test script also execute v4l pipelines to test camera stream repeatedly, it’s passing 1000 test cycles without failures.  
in addition, our test results show consistency CPU loading, it keeps around 2% CPU usage.

> [@rlatae123](#):
>
> we now use the nx module to connect 4 cameras.

may I know who’s the camera vendor, you may contact with them for digging into sensor side.

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 19, 2023, 3:34am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/19 "2023-01-19T03:34:15Z")

</div>

Okay I will check then I have question

1. we test our product in jetpack 4.4.1 What’s the difference between 4.4.1 and 4.6.1

2. Does it matter if I apply 4.4.1 to the 4.6.1 driver?

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 19, 2023, 12:05pm UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/20 "2023-01-19T12:05:20Z")

</div>

We using imx390 sensor

We ran a new test with JETPACK 5.0.2 and no errors occurred.

Right now the situation is only coming from version 4.6.x

Is there anything more suspicious than the camera sensor?

---

<div class="post-metadata">

**Author:** ![JerryChang](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jerrychang/32/14043_2.png) [@JerryChang](https://forums.developer.nvidia.com/u/JerryChang)\
**Post date:** [January 30, 2023, 2:13am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/21 "2023-01-30T02:13:42Z")

</div>

hello rlatae123,

sorry for late reply due to public holiday.

_\>\> What’s the difference between 4.4.1 and 4.6.1_  
you may check release note for details, it basically bug fixes for kernel and also pre-built binaries.

_\>\> Does it matter if I apply 4.4.1 to the 4.6.1 driver?_  
it may not works, because there’s version dependency between kernel layer and user-space.

_\>\> We ran a new test with JETPACK 5.0.2 and no errors occurred._  
this is great news.  
however, JP-4.6.x and JP-5.0.x were using different kernel version. i.e. k-4.9 v.s. k-5.10.  
besides, is it possible for using the latest JetPack release for development?

---

<div class="post-metadata">

**Author:** ![rlatae123](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@rlatae123](https://forums.developer.nvidia.com/u/rlatae123)\
**Post date:** [January 30, 2023, 10:56am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/22 "2023-01-30T10:56:54Z")

</div>

hello Jerry

I want to develop on 5.0.2 but gave up due to too long boot time.

I ran out of time and temporarily fixed the problem by modifying the code.

However, it seems that the root cause needs to be found later.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [February 21, 2023, 5:04am UTC](https://forums.developer.nvidia.com/t/v4l2-high-cpu-usage/239721/24 "2023-02-21T05:04:03Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
