Repository navigation
Certify cleanly stopped live recordings: seal, finish, replayed stop and close accounting - #26
Closed
erikwb wants to merge 4 commits into
Conversation
The live daemon records through a disk worker thread, which writes and flushes its queue only once the queue closes. Nothing waited for it: after a clean stop the daemon returned from main and the process could end with records still queued or buffered, cutting the recording's last record and the account spans of the stop. Add Recorder::finish(): flush, close the queue and wait for the worker, at most a timeout. The final save calls it, with 2 s. Only the clean stop waits; dropping a recorder (on a full queue or a failed rotation, in the governing tick) still never blocks. Signed-off-by: Erik Bourget <erik@ebourget.net>
A ring recording, the kind the live daemon writes, that ends without a Z record reads as cut short: replay marks "the recording stopped here" and refuses to certify it. Only the size limit wrote a Z, so a recording the daemon ended with a clean stop could never certify. Seal it: once the final save has written the state, the recorder writes a Z with a new END_CLEAN code. The reader ends a recording at a clean seal without marking it, and keeps treating END_FULL and an unsealed ring as an early end. A crash or kill still leaves the file unsealed. Older readers see the new code as an early end, which is safe. Signed-off-by: Erik Bourget <erik@ebourget.net>
At a clean stop the live daemon gives the lock up, waits for the card to drain, and charges its last span in the final save. The replay ran the guard only to the end of the live account, so the stop's lock transition was "live only" and its last span was cooled instead of charged, and certification failed on every cleanly stopped recording. When the recording holds the live "stopping" permit, wake there, stop the replayed guard, tick until it is released, and run the final save, as the daemon's main loop does. The final save's end comes from the daemon's own clock reads, which a replay cannot reproduce; advance to the live account's end first, within 100 ms. A replayed stop gives the lock up too, but is not counted as a hand-off. A clean stop while not armed records no "stopping" permit: such a recording is sealed but still does not certify. Signed-off-by: Erik Bourget <erik@ebourget.net>
At a stream's end the live daemon reads the tail, places it, and charges the time after it up to when it is done, which its own processing decides (about 2 to 3 ms on a J713). The replay's clock does not move meanwhile, so it charged a fraction of that span and cooled the rest from its next look: every recording with a stream close failed the account check. Add Hw::closed_at(from), the time up to which a closing stream is charged from where its account had reached. Live it is now(), as before. The replay takes the end of the span the live daemon charged from there (its account records it), within 100 ms. Also read a tail at its recorded time, as read_period does with a period, and carry the capture position across the difference. The fake card gains a close_delay: time that passes in closed_at(), as the daemon's own processing does before it charges a closing stream. Signed-off-by: Erik Bourget <erik@ebourget.net>
Contributor
|
The base branch |
Contributor
|
@erikwb this targets |
Contributor
Author
|
No plans to port the recorder to v2, so closing this. The branch stays for reference. |
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.
Certification of a live recording could not pass: a recording the daemon made and ended with a clean stop was always refused. These four fixes make a clean live run certify. The live daemon's protection decisions don't change.
Found on a J713 running this integration branch (a9daa66) as its speaker protection, with the J713 profile from #10.
What was wrong, and the fixes
record: Let a clean stop wait for the last records). The disk worker writes and flushes its queue only once the queue closes, and nothing waited for it: the process could exit after a clean stop with records still queued.Recorder::finish(timeout)flushes, closes the queue and waits for the worker's result, at most 2 s. Onlyfinal_savecalls it, after the state is written and the lock is released.record: Seal a live recording at a clean stop). A ring recording without aZis treated as truncated, and only the size limit wrote one.final_savenow seals withZand a newEND_CLEANcode, and the reader ends there without marking the recording ambiguous.END_FULLand an unsealed ring are still an early end, so a crash or kill leaves the file unsealed. Older readers seeEND_CLEANas an early end, which is safe.replay: Stop where the live daemon stopped cleanly). The stop's lock transition came out "live only" and its last span was cooled instead of charged.maindoes.replay: Account a closing stream as the live daemon did). The live daemon charges a closing stream up to when it's done with it, which its own processing decides: 2–3 ms on the J713. The replay's clock didn't move meanwhile, so it charged a fraction of that and cooled the rest.Hw::closed_at(from)returnsnow()live, so nothing changes there. The replay takes the end of the span the live daemon charged from the guard'saccount_to, within 100 ms.read_tailalso reads at its recorded time, asread_perioddoes.Tests
Each fix has a test, and each test fails with its fix reverted:
finishing_an_async_recorder_writes_everything;a_clean_stop_seals_a_live_recording;a_cleanly_stopped_live_recording_certifies;a_slow_close_replays_as_the_live_daemon_charged_it, where the fake card gains aclose_delayin itsclosed_at.The seal and certification tests record through the synchronous ring recorder (
Recorder::create). On the fake card a test outruns the async worker, whose full queue drops records.stalled_writer_drops_recording_without_delaying_governingstill passes.cargo test --release:The same 2 fail on both (
j616_ordinary_quiet_programme_has_zero_extra_attenuation,ordinary_quiet_programme_costs_at_most_one_db).On the J713
A live run with this build as the J713's protection and #10's profile: three silent streams, a chord, short blips, and blip pairs 90–150 ms apart, then a clean stop. Its replay:
The recording is j713-certified.rec.zst (5.0 MB; decompressed SHA-256
ba4167cc7e539ab1929f2b9ab7962cd3eb458195a6aafb5785ee93e77b10f148), test sounds only. Replay it with--model j713and #10'sj713.conf.That run also has clean sense data at its stream ends thanks to a kernel fix, aurora-silicon/linux#663. Without it, the J713's right tweeter voltage sense reads full scale for a moment at every stream stop, which shows up here as clipped, ambiguous periods.