raspberrypi / userland

Source code for ARM side libraries for interfacing to Raspberry Pi GPU.
BSD 3-Clause "New" or "Revised" License
2.05k stars 1.09k forks source link

raspivid:Turn off buffering on fwrite(3) #718

Closed dsugisawa-mixi closed 2 years ago

dsugisawa-mixi commented 2 years ago

This change makes low-latency udp streaming more stable in the BCM2835:Zero W environment. (BCM2835 provides a 128KB system L2 cache, which is used primarily by the GPU)

JamesH65 commented 2 years ago

@6by9 I have no idea on this one, have you?

pelwell commented 2 years ago

It needs some explanation by the submitter beyond two statements and a patch, none of which are obviously related.

dsugisawa-mixi commented 2 years ago

fwrite(3) is implemented in buffering mode by default, I thought it will be L2 cache polluting, and then resuls in poor performance.

it was also the case in the BCM2711.

./build/bin/raspivid -w 640 -h 360 -o udp://192.168.15.202:50002 -fps 30 --codec H264 -n -t 0

image

6by9 commented 2 years ago

https://www.cplusplus.com/reference/cstdio/setvbuf/

_IONBF No buffering: No buffer is used. Each I/O operation is written as soon as possible. In this case, the buffer and size parameters are ignored.

Nothing to do with CPU caches.

You're not saving much anyway as there is already an option for flushing after every packet with -fl. UDP supports a max 65507 bytes when over IPv4 (65535 - 8 byte UDP header - 20 byte IP header), and then then needs to be fragmented down to a typically max 1500 byte ethernet frame.

dsugisawa-mixi commented 2 years ago

I agree, and thanks your comments.