Use 4 CPU for Multithreading using C in xavier NX

Hi everyone,
I need to use 4 thread parallely for reading mipi-csi2 data from 4 VC using C program. In that how to assign a separate CPU for each thread using priority scheduling, Is any document is there for reference. Could you please give me any suggestion.

Thanks for your time.

1 Like

You can use taskset to assign CPU for the task.

http://manpages.ubuntu.com/manpages/trusty/man1/taskset.1.html

Hi ShaneCC,
Thanks for your support, I tried,
I am trying to read 40fps from 4 virtual channel, When am read one channel I can able to read 40fps but when am reading 4virtual channel using 4 thread it not reading all frames. Is any other C API is there for reading 4 channel in parallel using v4l2 userptr.

Is cudav4l2 C API is suitable for this application. Is it suitable please share some reference code or document to do multithreading in cudav4l2 using C.

thanks for your time

It’s better to use mmap instead of userptr for the performance.
The tegra_multimedia_api should have relative sample code.

Hi ShaneCC,
Thanks for your support, Can I use V4l2loopback driver for reading four VC data in xavier NX. If we can means, please suggest some idea.

Thanks for your time

What’s your camera output format?
If bayer below can be reference.

Hi ShaneCC,
Thanks for your support, My sensor is custom sensor which send data in RG8 format, which hold 4VC data and transmit sequentially . I can read 40fps when am reading single channel using v4l2 API but when I am using 4 VC it’s reading only 2fps per VC. Could you please suggest any Idea to read 40fps per second from each VC.

Thanks for your time

Have you try the v4l2-ctl --stream-mmap to confirm with 4 channel?

A combination of:

https://man7.org/linux/man-pages/man2/sched_setscheduler.2.html

and

https://man7.org/linux/man-pages/man2/sched_setaffinity.2.html

should help you with setting each thread’s CPU affinity in your C program. As @ShaneCCC mentioned, taskset(1) is also another method to move threads to desired CPU.

Hi ShaneCC, AnishAney,
Thanks for your support, Here I have attached the output of command. In command itsself not reading 40fps. where will be the issue.
v4l2-ctl -d /dev/video0 --set-fmt-video=width=4096,height=1,pixelformat=RG8 --set-ctrl bypass_mode=0 --stream-mmap --stream-count=10 --stream-to=test.raw
<< 0.61 fps
< 0.61 fps
< 0.61 fps
< 0.61 fps
< 0.61 fps
< 0.61 fps
< 0.61 fps
< 0.61 fps
< 0.61 fps
Is it the issue of driver.
Thanks for your time

Hi,
After increase echo 1036800000 > vi/rate I can read 4 fps. But I want read frames 40 to 120FPS, How to attain it.

Note
My default $cat vi/max_rate is 409600000 I changed to 1036800000 using forum link: RAW capture over CSI works half speed only - #12 by ShaneCCC
Is any thing I want to change in dtsi file to attain max Vi/rate and how to set max vi/rate through driver and what is the max vi/rate.

My present nvcsi/rate is 314000000. is I want to increase it

Is any other config affect drop in fps .
Thanks for your Time

Try to max the nvcsi/vi clocks and remove the --stream-to=test.raw from the pipeline to clarify.

Hi ShaneCC,
Thanks for your support, In dtsi file where I can set max nvcsi/vi clock.

Boost them by below command.

sudo su
echo 1 > /sys/kernel/debug/bpmp/debug/clk/vi/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/isp/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/nvcsi/mrq_rate_locked
cat /sys/kernel/debug/bpmp/debug/clk/vi/max_rate |tee /sys/kernel/debug/bpmp/debug/clk/vi/rate
cat /sys/kernel/debug/bpmp/debug/clk/isp/max_rate | tee  /sys/kernel/debug/bpmp/debug/clk/isp/rate
cat /sys/kernel/debug/bpmp/debug/clk/nvcsi/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/nvcsi/rate

Hi ShaneCC,
Thanks for your support, I tried this, but my fps increase to 5fps per second but I want to read 40 to 120fps. why there is a frame drop I don’t know could you please suggest any idea.
Thanks for your time.

How did you make sure the sensor is output 120fps as expect?

Hi ShaneCC,
Yes its giving 120fps. We checked.

It’s doesn’t make sense to me. v4l2-ctl command just a simple pipeline shouldn’t have such frame drop problem. Have you try boost the system as performance by nvpmode and jetson_clocks?
How do you check the output?

Hi ShaneCC,
Thanks for your support, Yes I boost the system as performance by nvpmode and jetson_clocks. but it’s reading 4fps, then I added mmap=3 it increase fps to 6FPS. Here I have attached command which is reading 6FPS.

v4l2-ctl -d /dev/video0 --set-fmt-video=width=4096,height=1,pixelformat=RG8 --set-ctrl bypass_mode=0 --stream-mmap=3 --stream-count=100 --stream-to=test1.raw\

Thanks for your time.

What’s the result for below command?

v4l2-ctl -d /dev/video0 --set-fmt-video=width=4096,height=1,pixelformat=RG8 --set-ctrl bypass_mode=0 --stream-mmap --stream-count=100