Repository navigation
blackbox: hand the device a block of bytes, not one byte per call - #12059
Conversation
The encoders write one byte at a time, and every byte went to the device on its own: one afatfs_fputc() or flashfsWriteByte() call per byte. Collect them in a 128 byte block and hand it over with one afatfs_fwrite() or flashfsWrite() call. The block goes out when it is full, before anything else reaches the device (header prints, flushes, the end of a log, the header budget) and at the end of every blackboxUpdate(), so nothing waits longer than one loop and the bytes keep their order; while the terrain code holds the SD card it waits until the card is back. Serial ports still get one byte at a time, since serialWriteBuf() would wait for room. On a TBS Lucid H7 logging to SD the blackbox takes 2.3% of the CPU at 1 kHz and 4.4% at 2 kHz; this cuts that time by 10 to 13%.
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoBatch blackbox writes and pause safely when the SD cache fills
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
1.
|
… switch, counts every skipped iteration and lends the card to terrain
…d did not take wait for it
|
Test firmware build ready — commit Download firmware for PR #12059 251 targets built. Find your board's
|
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
c6090ca to
99ed011
Compare
99ed011 to
887e88e
Compare
…ume iteration is not counted On the bench, sd_info counted one iteration too many for every pause the card ended: the iteration that resumes is logged. When the switch takes over a pause for the card and comes back on while the card is still behind, the resume wrote its I frame into what is left below the threshold, 80 to 255 bytes: enough in 8 runs, not after a large iteration. Now it waits, and those iterations count as lost to the card.
|
@sensei-hacker tested on two flash chips today, both from images merged on the current maintenance-10.x: a W25Q128 NOR on a Flywoo F722 Pro V2 (logs at 1 kHz and 200 Hz, 8 to 11 MB, decoded with no corrupt frame) and a W25N01G NAND on a Holybro Kakute H7 Mini (a 173 s log lost 8 iterations in two 12 ms stalls of the flash, nothing else); details in the description. F4 and other SD cards remain untested. Is there anything else you would like tested? |
Stacked on #12058 (the byte count per iteration it adds stays in
blackboxWrite()), which is stacked on #12057; their commits show here until they are merged.The frame encoders write one byte at a time, and every byte went to the device on its own: one
afatfs_fputc()orflashfsWriteByte()call per byte, each with its own checks and cache lookup.The change
blackboxWrite()collects the bytes in a 128 byte block, and the block goes to the device with oneafatfs_fwrite()or, on SITL,fwrite()call. It goes out:blackboxUpdate().So nothing waits longer than one loop and the bytes keep their order. While the terrain code has the SD card, the block waits until the card is back. Serial ports and flash chips still get one byte at a time:
serialWriteBuf()would wait for room, and an asynchronousflashfsWrite()drops a whole block the busy chip can't take.Results
On a TBS Lucid H7 logging to SD the blackbox takes 2.3% of the CPU at 1 kHz and 4.4% at 2 kHz; with this, 10 to 13% less. Logs decode the same.
Not tested:
Flash chips and F7 have run since: a W25Q128 on a Flywoo F722 Pro V2 and a W25N01G NAND on a Holybro Kakute H7 Mini, see below.
After review
Built on F4, F7, H7, AT32 and SITL; KAKUTEF7 and KAKUTEF7HDV fit their ITCM. On the TBS Lucid H7 Wing after review: a 60 s log at 1983 Hz, no iteration missing; with #12058's bench test of the switch (a card holding its write for 0.3 to 4 s, the switch moved around it), 13 logs with no corrupt frame. Not tested: flash chips (the Lucid has none).
Related PRs
blackbox.c, as with blackbox: pause instead of dropping frames while the SD card is busy #12058. Whichever is merged second, I'll rebase it.Tested on flash chips (2026-10-06)
Both from images merged on the current maintenance-10.x, which the branch has had merged in since 0a27742 (flash: guard flashFlush() against a NULL flush callback #11943, the flash flush fix, included).