Repository navigation
Sync next-10.1 into maintenance-11.x - #12266
Merged
Merged
Conversation
afatfs_getFreeBufferSpace() counted every unlocked sector that was empty or in sync, but afatfs_allocateCacheSector() never evicts one with a retain count: a contiguous file keeps its directory entry retained for as long as it is open, and the blackbox log and the free file are both contiguous. With a log open, two of the 8 sectors were reported as space the blackbox could write into, and could not be. Measured on a TBS Lucid H7 while the SD card held a write for 54 ms: afatfs_fwrite() refused bytes while this function still reported 1024 bytes free.
An SD card can hold a write for tens of milliseconds (the standard
allows 250). The blackbox keeps writing into the other cache sectors
meanwhile, and once none is left it drops what it writes. With 8
sectors, and 3 of them never free while a log is open, the cache held
about 30 ms of a 1 kHz log.
Measured on a TBS Lucid H7 whose card holds a write for 54 ms every
768 KB once it runs out of prepared blocks, 120 s logs:
sectors 1 kHz log (85 kB/s) 2 kHz log (170 kB/s)
rows lost rows lost
8 379 2178
12 8 1282
16 0 703
24 0 0
32 0 0 (also over a 20 minute log)
Now 32 sectors on H7 and 24 on F7, where RAM is plenty. On F4 with the
card on SPI the cache moves to CCM with 24 sectors: RAM is short there,
CCM mostly unused, and the CPU writes the card, so no DMA needs to
reach it. Elsewhere (F4 with SDIO, AT32) it stays at 8. A target can
set AFATFS_NUM_CACHE_SECTORS itself. Targets without an SD card do not
link the cache.
Walking the larger cache costs afatfs_poll() about 8 ns per sector on
the H7, in the scheduler's idle loop.
… full
While the SD card holds a write, afatfs keeps taking the log's bytes
into its cache, and once the cache is full afatfs_fwrite() drops what
does not fit, usually halfway through a frame. The decoder then misreads
frames until the next I frame.
Pause the log instead, as the BLACKBOX mode does: when what the log file
can still take (the free cache sectors and the rest of the sector being
written) is less than the most one iteration has written plus 64 bytes,
and never less than 256 bytes, skip iterations until it can take twice
that, and resume on an I frame with a LOGGING_RESUME event. The
iterations skipped are the ones that would have been lost anyway, but
the log no longer has corrupt frames in it. sd_info reports the pauses,
the iterations not logged and the largest iteration.
Measured on a TBS Lucid H7 with its 8 sector cache, three 120 s logs
each, rows missing per card stall and corrupt frames per log:
1 kHz log 2 kHz log
without the pause 32.3, 4.7 corrupt 97.2, 15.7 corrupt
with the pause 34.0, none 93.1, none
… switch, counts every skipped iteration and lends the card to terrain
…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.
The getters only copied them for the CLI. Same size on F405, F722, KAKUTEF7 and H743 (LTO inlined them).
afatfs: count only the cache sectors that can take data, and size the cache per MCU family
blackbox: pause instead of dropping frames while the SD card is busy
Author
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
Author
|
Test firmware build ready — commit Download firmware for PR #12266 252 targets built. Find your board's
|
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.
Automatic sync of
next-10.1intomaintenance-11.xcould not be completed (merge conflict or push refused). Mergenext-10.1intomaintenance-11.xlocally, resolve conflicts, and push. Use a merge commit, not squash or rebase. Do not use GitHub's "Resolve conflicts" button.