libbladeRF: fix unit mix-up in ts_remaining() for X2 layouts - #1080
Open
wormuz wants to merge 1 commit into
Open
libbladeRF: fix unit mix-up in ts_remaining() for X2 layouts#1080wormuz wants to merge 1 commit into
wormuz wants to merge 1 commit into
Conversation
curr_msg_off counts samples: it is advanced by samples_to_copy and
compared against samples_per_msg. ts_remaining() subtracted it from
samples_per_msg / samples_per_ts, which counts TIME STEPS per message.
The units only coincide for single-channel layouts (samples_per_ts == 1).
In X2 mode the unsigned subtraction underflows as soon as the offset
passes half a message. With assertions enabled a bladerf_sync_rx() call
that seeks to a timestamp inside the current message aborts the process:
sync.c:451: ts_remaining: Assertion 'ret <= UINT_MAX' failed.
With NDEBUG the huge result sends the seek logic into the 'fast forward
within the current message' branch when the target lies beyond it, and
curr_msg_off runs past the message boundary - the stream stalls instead
of crashing. This matches the dual-channel stalls reported in Nuand#944.
Reproduced on a bladeRF 2.0 micro xA4 (FX3 2.6.0, FPGA 0.16.0) with an
RX_X2 SC16_Q11_META stream reading back-to-back explicit timestamps:
the abort fires within the first few reads. With the units fixed the
same sequence completes 3000/3000 contiguous reads with no timestamp
drift, and single-channel metadata reads are unaffected.
Subtract the sample offset first, then convert to time steps. The new
assertion documents the invariant the old expression silently assumed.
(cherry picked from commit 0960e7f)
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.
curr_msg_offcounts samples: it is advanced bysamples_to_copyand compared againstsamples_per_msg.ts_remaining()subtracted it fromsamples_per_msg / samples_per_ts, which counts time steps per message. The units only coincide for single-channel layouts, wheresamples_per_ts == 1.In X2 mode the unsigned subtraction underflows as soon as the offset passes half a message:
bladerf_sync_rx()call that seeks to a timestamp inside the current message aborts the whole process:sync.c:451: ts_remaining: Assertion 'ret <= UINT_MAX' failed.NDEBUG, the huge result sends the seek logic into the fast forward within the current message branch when the target actually lies beyond it, andcurr_msg_offruns past the message boundary — the stream stalls instead of crashing. This looks like the dual-channel stall reported in Dual-channel async receive with metadata broken for FPGA code 0.12.0 through 0.15.0 (xA9)? #944.Reproduced on a bladeRF 2.0 micro xA4 (FX3 2.6.0, FPGA 0.16.0) with an RX_X2
SC16_Q11_METAstream reading back-to-back explicit timestamps: the abort fires within the first few reads. With the units fixed, the same sequence completes 3000/3000 contiguous reads with no timestamp drift (past the ~1794-buffer stall point reported in #944), and single-channel metadata reads are unaffected.The fix subtracts the sample offset first and then converts to time steps; a new assertion documents the invariant (
curr_msg_off <= samples_per_msg) the old expression silently assumed.