libbladeRF: reject stream configs that exceed the usbfs memory budget - #1075
Open
wormuz wants to merge 2 commits into
Open
libbladeRF: reject stream configs that exceed the usbfs memory budget#1075wormuz wants to merge 2 commits into
wormuz wants to merge 2 commits into
Conversation
Every in-flight USB transfer is pinned by the kernel, so a stream needs num_transfers * buffer_size_bytes of usbfs memory simultaneously. The default limit is 16 MiB. Exceeding it fails far from its cause: bladerf_sync_config() returns success, submit_transfer() then fails asynchronously with LIBUSB_ERROR_NO_MEM, and the caller only sees BLADERF_ERR_MEM from the first bladerf_sync_rx() - with nothing pointing at the transfer count. Measured on bladeRF 2.0 micro xA4 (FX3 2.6.0, FPGA 0.16.0), SC16_Q11_META at 61.44 Msps with buffer_size=131072 samples: num_transfers=31 -> ok num_transfers=32 -> ERR_MEM from the first sync_rx 32 * 512 KiB is exactly the 16 MiB limit. The larger GPIF buffers in FX3 2.6.0 make this easier to hit than before. Now checked up front: bladerf_sync_config() returns BLADERF_ERR_INVAL and logs the numbers plus the maximum transfer count that fits.
The number of in-flight transfers is bounded by the kernel's usbfs memory limit, not just by num_buffers. With the larger GPIF buffers in FX3 2.6.0 the default 16 MiB is easy to reach: 32 transfers of a 131072-sample SC16_Q11 buffer is exactly 16 MiB. Documents the limit and the error now returned for configurations that exceed it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every in-flight USB transfer is pinned by the kernel, so a stream needs
num_transfers * buffer_size_bytesof usbfs memory simultaneously. The default limit is 16 MiB.Exceeding it fails far from its cause:
bladerf_sync_config()returns success,submit_transfer()then fails asynchronously withLIBUSB_ERROR_NO_MEM, and the caller only seesBLADERF_ERR_MEMfrom the firstbladerf_sync_rx()— with nothing pointing at the transfer count.Measured on a bladeRF 2.0 micro xA4 (FX3 2.6.0, FPGA 0.16.0),
SC16_Q11_METAat 61.44 Msps withbuffer_size=131072samples:32 × 512 KiB is exactly the 16 MiB limit. The larger GPIF buffers in FX3 2.6.0 make this much easier to hit than before.
The check runs in
async_init_stream()and returnsBLADERF_ERR_INVALwith the numbers and the maximum transfer count that fits:The limit is read from sysfs on Linux and falls back to the kernel default of 16 MiB elsewhere. A second commit documents the constraint on the
num_transfersparameter.