Repository navigation
services/flash: defer erase instead of blocking the whole server - #703
JesseMelon wants to merge 6 commits into
Conversation
9f67041 to
7e8a29c
Compare
EnmanuelParache
left a comment
There was a problem hiding this comment.
This changes look good and serve the purpose of deferring erase operation.
I just have a couple observations that could be discussed in a separate issue.
-
We could make use of embedded_hal_nb when implementing drivers that would block
-
Flakiness tests for flash_service:flash_evb_test failed 3 of 3 runs on the board. Every run ended identically:
flash server: ready
read: offset 0x00100000, size 0x1000, flash ptr 0x88100000
[ERR] flash server stopped
TEST_RESULT:FAIL1275a4f to
9425efb
Compare
9425efb to
9ad05b1
Compare
Test flakiness resolved after rebasing onto main |
|
Let's hold off merging this code until I analyze the earlgrey and veer cases with this code. |
rusty1968
left a comment
There was a problem hiding this comment.
Please hold-off merging until I carefully review this against earlgrey and veer
… DeferredErase Proposal on top of OpenPRoT#703. BlockingFlash::erase goes back to start_erase, wait_for_notification, complete_op, so correctness does not depend on is_busy and the AST10x0 blocking path is bounded again. Deferral becomes an explicit capability instead of a change to every driver's semantics: - hal_flash_driver::DeferredErase: a driver that can start an erase without waiting (contract: is_busy is accurate until complete_op). - hal_flash::DeferredFlash<D: DeferredErase, B>: wraps BlockingFlash; erase/read/program delegate unchanged, start_erase uses start_erase_nowait and poll_erase consults is_busy/complete_op. - BlockingFlash keeps the Flash defaults (blocking start_erase, poll_erase == Done). FlashDriver is untouched. AST10x0: start_erase uses the blocking erase_sector again; the non-blocking start_erase_sector is exposed through DeferredErase, and the flash_service server uses DeferredFlash. Earlgrey and VeeR are unchanged and stay on BlockingFlash until they opt in. Tests: erase does not touch is_busy or the nowait start (also through DeferredFlash); BlockingFlash::start_erase is synchronous; the deferred path reports Busy then Done; complete_op errors surface from poll_erase. Only //hal/blocking/flash:flash_test was run. The AST10x0 backend and server changes were not built, and ./pw presubmit was not run. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
DeferredFlash::poll_erase never went through Blocking, so for a driver with an interrupt-backed Blocking (Earlgrey) the completion signal of a deferred erase would be left pending. The next blocking program/erase would then return from wait_for_notification at once and fail in complete_op with FLASH_GENERIC_BUSY. On the Busy -> Done transition, call wait_for_notification once, before complete_op. The operation has already finished, so this returns promptly and consumes the notification. It is a no-op for NoWaitBlocking (AST10x0) and NoWait (VeeR). Contract: a driver implementing DeferredErase must only report !is_busy() once its completion notification has been raised. Test: a counting Blocking checks that start and Busy polls do not wait and that the Done poll waits exactly once. Only //hal/blocking/flash:flash_test was run. The AST10x0 backend and server changes, the services/flash server tests and ./pw presubmit were not run. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…n drain The docs still said a deferred erase never goes through Blocking, which stopped being true when poll_erase began consuming the completion notification on the Busy -> Done transition. State the rule once, on DeferredErase: is_busy must not return false until the completion notification has been raised, and DeferredFlash consumes it exactly once on Done. DeferredFlash and poll_erase now refer to it. Comment-only; no code change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
I opened a proposal against Jesse's branch: JesseMelon#26. It keeps |
|
@yvettewu1 , can you comment on the behavior of the Flash ? |
|
@rusty1968 yes. I think making deferral an opt-in DeferredErase capability with a DeferredFlash wrapper is a much safer approach. This preserves the existing blocking behavior while adding non-blocking erase support without affecting existing users of BlockingFlash. |
swenson
left a comment
There was a problem hiding this comment.
Few small things, code overall looks good.
|
|
||
| /// Polls an erase begun with [`start_erase`](Self::start_erase). | ||
| /// | ||
| /// `Err` must mean the busy check already came back false, same as `Done`. |
There was a problem hiding this comment.
This comment is a bit confusing. What is the same as done? What does it mean for the busy check to come back false and why is that an error?
Also, do we want to have a default implementation for this?
|
|
||
| /// Outcome of polling an operation started with [`Flash::start_erase`]. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum OpPoll { |
There was a problem hiding this comment.
If this is only for erase polling and we don't anticipate supporting other uses for this enum, I might suggest changing the name to something like EraseStatus or OpErasePoll?
| fn program(&mut self, start_addr: FlashAddress, data: &[u8]) -> Result<(), Self::Error> { | ||
| self.0.program(start_addr, data) | ||
| } | ||
| /// Starts the erase and returns without waiting; `poll_erase` reports its real status. |
There was a problem hiding this comment.
Not sure if this comment is adding anything that the parent trait comment doesn't say.
| loop { | ||
| if let Event::Request { channel, len } = service.next(Instant::MAX, buf)? { | ||
| serve(&mut service, servers, channel, buf, len); | ||
| let needs_poll = |s: &ChannelState| !matches!(s, ChannelState::Idle | ChannelState::Dead); |
There was a problem hiding this comment.
Slightly confusing to have this as a !matches!. Why not just use a positive matches!, and why not just a method on the enum itself instead of an inline function here?
| match self.handle_request(buf, len) { | ||
| Ok(Outcome::Pending) => Outcome::Pending, | ||
| Ok(Outcome::Done(reply_len)) => { | ||
| Outcome::Done(Self::write_status_frame(buf, 0, reply_len)) |
There was a problem hiding this comment.
rather than using a magic value of 0 for the status to indicate no error, I think it would be more Rust idiomatic to use an enum that is either Done or a NonZero error code and have it implement something like Into<u32> or Into<[u8; 4]>
yvettewu1
left a comment
There was a problem hiding this comment.
I don't think these changes will affect the underlying flash erase operation. However, please validate the deferred erase functionality on actual AST10x0 hardware, including access to another chip select while an erase is in progress.
Summary
Addresses #691: a slow or stuck erase no longer blocks every other channel's requests.
FlashDriver::start_erase/is_busyon the AST1060 FMC backend are now genuinely non-blocking (SpiNorFlashgets a splitstart_erase_sector/write_in_progress), instead ofis_busyhardcodingfalse.services/flash/serverreportsOutcome::Pendingfor an erase that isn't done yet;services/flash/server-runtimeusesServiceLoop::defer/completeto take that channel out of the WaitGroup so other channels keep being served, polling at 1ms with a 5s timeout rather than waiting forever.GET_INFOuntil a background poll confirms the driver actually went idle — a client giving up does not let a new client race hardware that may still be executing a command.BlockingFlash::erase/program's wait loop is fixed to actually checkis_busyinstead of assuming one wait always means done (a latent bug this change would otherwise have exposed).Deliberately out of scope:
programis not deferred — a multi-window program needs its own cross-poll state machine to defer safely, which is a larger, separate change.BlockingFlash::erase's own direct blocking path has no timeout bound (nothing calls it directly today; bounding it needs a way to construct a driver-specific error from generic code, a design question rather than a quick fix).Tests added in
services/flash/server/tests/server.rscover the defer/poll/abandon/recover paths with a fake that reports busy for a fixed number of polls — this path had no coverage before.