Skip to content

Commit

Permalink
gimlet-seq: Die more politely (#1611)
Browse files Browse the repository at this point in the history
Sleeping for 100ms in a loop is not a particularly efficient way for a
task to die permanently. Thanks to suggestions from @labbott and
@cbiffle, I've changed this so that the sequencer task now dies by
waiting for a notification with an empty notification mask, essentially
waiting forever for a notification that should never happen. This is
much more respectful of other tasks that might still be trying to do
stuff, and would like to be scheduled to do that stuff.

Also, I've cleaned up a couple other things based on some of Cliff's
suggestions. Because we no longer set the state when dying, we can pass
the `jefe` handle into `init` by value, which is a bit nicer.
  • Loading branch information
hawkw committed Feb 14, 2024
1 parent 2ba350a commit 66b9453
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions drv/gimlet-seq-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn main() -> ! {
let jefe = Jefe::from(JEFE.get_task_id());
let spi = drv_spi_api::Spi::from(SPI.get_task_id());
let hf = hf_api::HostFlash::from(HF.get_task_id());
match ServerImpl::init(&sys, &jefe, spi, hf) {
match ServerImpl::init(&sys, jefe, spi, hf) {
// Set up everything nicely, time to start serving incoming messages.
Ok(mut server) => {
let mut buffer = [0; idl::INCOMING_SIZE];
Expand All @@ -138,7 +138,16 @@ fn main() -> ! {
// All these moments will be lost in time, like tears in rain...
// Time to die.
loop {
hl::sleep_for(100);
// Sleeping with all bits in the notification mask clear means
// we should never be notified --- and if one never wakes up,
// the difference between sleeping and dying seems kind of
// irrelevant. But, `rustc` doesn't realize that this should
// never return, we'll stick it in a `loop` anyway so the main
// function can return `!`
//
// We don't care if this returns an error, because we're just
// doing it to die as politely as possible.
let _ = sys_recv_closed(&mut [], 0, TaskId::KERNEL);
}
}
}
Expand All @@ -158,7 +167,7 @@ const TIMER_INTERVAL: u64 = 10;
impl<S: SpiServer + Clone> ServerImpl<S> {
fn init(
sys: &sys_api::Sys,
jefe: &Jefe,
jefe: Jefe,
spi: S,
hf: hf_api::HostFlash,
) -> Result<Self, i2c::ResponseCode> {
Expand Down Expand Up @@ -435,7 +444,7 @@ impl<S: SpiServer + Clone> ServerImpl<S> {
state: PowerState::A2,
sys: sys.clone(),
seq,
jefe: jefe.clone(),
jefe,
hf,
deadline: 0,
};
Expand Down

0 comments on commit 66b9453

Please sign in to comment.