Not able to do highspeed writes using USB 3.1 on Jetson Xavier NX

I am trying to save data using threads. I am very new to multithreading. The rough idea is one thread will put the raw dummy data packets (12 MB) into a circular queue. The other thread will capture webcam image (OpenCV using C++) and put it in another circular queue. Now a third thread will synchronise the dummy data packet and image using timestamps and dump the data (i.e. synchronised ) into SSD Via USB 3.1. The code structure is as below

datapacketthread()

{

While(true)

{

//Generated dummy data packet. Used malloc to allocate the required size.

//Get Timestamp

packetqueue.enqueue()

}

}

camerathread()

{

//Initialise camera

// Set resolution

While(true)

{

//Capture a frame

//Get Timestamp

cameraqueue.enqueue()

}

}

savethread()

{

//Suggest any good synchronising mechanism … (one dummy data packet and a matching camera frame taken at the time of dummy packet generation)

fwrite(dummypacket);

imwrite(image); // in JPG format, Size around 70kB,

}

Main()

{

//initialisations

//Calling all three threads simultaneously

}

Now I have implemented this code without any synchronisation. The dummy packets and images are getting stored but the frame rate is only 14-15fps on my Jetson Xavier. If I disable the camera thread and store only dummy packets the frame rate is around 28 fps.

I have done a Read Write Benchmark Test using IOZONE and the obtained write speed around 8Gbps.(More info on IOZONE: http://www.iozone.org/)

But when I have timed the fwrite and it is around 38 ms (For a 12MB file speed is 2.6Gbps) if the camera thread is off. But once I turn on the camera thread the fwrite time is jumping upto 70ms(For a 12MB file speed is 1.4Gbps) and hence decreasing my fps. Can anyone help me out with any possible reason or explanation?

Once I am able to store the data with frame rate above 25fps, I would like to synchronise both the dummy data packet and the camera frame. Can anyone suggest any good way to synchronise and then save these to SSD via USB 3.1?

Does pull up the cpu freq with jetsonclocks help this issue?

BTW, why do you think the slow camera thread is due to usb write speed is too slow?

There is no improvement with jetsonclocks.

If the camera thread is turned off, the USB 3.1 write speed is 2.6Gbps, but once i turn on the camera thread, the USB 3.1 write speed is only 1.4Gbps. Due to this i feel that camera thread is slowing down the speed.

Can you describe your whole system setup? I think it is a little complicated to understand your system here.

Could you give us a brief introduction that what is connected on your system?

Are you trying to write the image from camera to ssd through usb interface? Is that camera using usb too?

Thank you for your response.
Its a Jetson Xavier NX developer kit with a camera and SSD attached to it. Yes both the camera and SSD are connected through USB.

hello,

The R/W speed is complicated. Not only affect by the USB transfer speed but also affect by the device R/W perf.
Packet size, Transfer file size, random R/W are also affect the perf.

However, IMO, the problem is not the R/W perf on the XNX but the shared BW on XNX.
The typeA ports on XNX are all connected to an onboard hub and then connected to one single USB 3.1 gne2 root hub port. Thus, all the devices behind the type A ports on XNX share one USB3.1 gen2 BW.