Bladerf 2.0 buffer_size and num_buffers

Discussions related to embedded firmware, driver, and user mode application software development
Post Reply
kennyr
Posts: 3
Joined: Thu Jul 21, 2022 6:10 am

Bladerf 2.0 buffer_size and num_buffers

Post by kennyr »

Hi,

- what is the maximum size of buffer_size for bladerf 2.0?

I've seen BUFFER_SIZE = 32 * 1024 = 32768;
https://github.com/Nuand/bladeRF/blob/e ... src/main.c

- What is the difference between BUFFER_SIZE=2048 and num_buffers=1 and BUFFER_SIZE=1024 and num_buffers=2 for instance?

Thanks,
robert.ghilduta
Posts: 156
Joined: Thu Feb 28, 2013 11:14 pm

Re: Bladerf 2.0 buffer_size and num_buffers

Post by robert.ghilduta »

The parameter to bladerf_sync_config are host-side software settings. It is up to the OS to determine how much memory it will allow to be allocated to the user mode program that loaded libbadeRF. Generally a good rule of thumb is anything from as low as a few 10s of kilobytes to several seconds of captures worth of memory.

BUFFER_SIZE controls the size of the libusb call. A smaller BUFFER_SIZE fills up more quickly so it has lower "latency" but it incurs a performance impact by doubling the calls for libusb. BUFFER_SIZE should be at least 1024 but should be kept under 1048576.
kennyr
Posts: 3
Joined: Thu Jul 21, 2022 6:10 am

Re: Bladerf 2.0 buffer_size and num_buffers

Post by kennyr »

- should be at least 1024 but should be kept under 1048576

Is this for each port? Can I fetch 1048576 samples on each port or does it reduce when using more than one port?

Thank you
robert.ghilduta
Posts: 156
Joined: Thu Feb 28, 2013 11:14 pm

Re: Bladerf 2.0 buffer_size and num_buffers

Post by robert.ghilduta »

The buffer sizes are for individual IQ samples. When running in MIMO it will eat through the buffer space twice as "fast" based on the number of samples that are requested in bladerf_sync_rx()
kennyr
Posts: 3
Joined: Thu Jul 21, 2022 6:10 am

Re: Bladerf 2.0 buffer_size and num_buffers

Post by kennyr »

Sorry I still didn't understand.
Is it a shared buffer or each port supports a 2^20 samples?

Thanks,
peepyopee
Posts: 3
Joined: Fri Jul 08, 2022 6:13 pm
Location: Boston, MA

Re: Bladerf 2.0 buffer_size and num_buffers

Post by peepyopee »

Are these buffers a function of RAM on the device or on the host PC? For example, does the BladeRF fill up a 1048576 sample buffer and then it gets transferred over USB to the host PC or does the BladeRF try and DMA the samples over to a buffer of size 1048576 on the host or something else? My use case is more interested in recording as much contiguous data at the highest possible sample rate as possible and I don’t care about latency at all since I’m just writing it to the file system.
robert.ghilduta
Posts: 156
Joined: Thu Feb 28, 2013 11:14 pm

Re: Bladerf 2.0 buffer_size and num_buffers

Post by robert.ghilduta »

The buffers being allocated by libbladeRF are on the host PC. The buffer sizes are in bytes, the conversion into samples sizes has to be done by the program utilizing libbladeRF. User mode memory already isn't physically contiguous. Fortunately USB xHCIs tend to have scatter gather DMA engines so physically non-adjacent pages are "stitched" together by the kernel and DMA engine.
bekean
Posts: 3
Joined: Mon Feb 19, 2024 7:42 pm

Re: Bladerf 2.0 buffer_size and num_buffers

Post by bekean »

USB xHCIs (eXtensible Host Controller Interface) often have scatter-gather DMA engines. These engines can handle physically heardle non-adjacent memory pages and "stitch" them together during data transfer. This is facilitated by the kernel and the DMA engine working together.
Post Reply