Skip to content

Commit

Permalink
Add Jefe::restart_me and use it for net watchdog.
Browse files Browse the repository at this point in the history
This adds a method for tasks to restart themselves without indicating a
fault, which has the advantage of bypassing Jefe's crash-dump logic for
deliberate restarts.

Currently the only case of a deliberate restart is in net, for the
receive watchdog. This should knock about 66ms off each firing of that
watchdog.

I initially implemented this as a syscall, but @mkeeter noted it could
be done entirely outside the kernel -- and so here it is. Long live the
emokernel.
  • Loading branch information
cbiffle committed Jun 16, 2023
1 parent 921b931 commit e52078a
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/demo-stm32h7-nucleo/app-h743.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ uses = ["eth", "eth_dma", "tim16"]
start = true
notifications = ["eth-irq", "mdio-timer-irq", "wake-timer"]
interrupts = {"eth.irq" = "eth-irq", "tim16.irq" = "mdio-timer-irq"}
task-slots = ["sys"]
task-slots = ["sys", "jefe"]

[tasks.user_leds]
name = "drv-user-leds"
Expand Down
2 changes: 1 addition & 1 deletion app/demo-stm32h7-nucleo/app-h753.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ uses = ["eth", "eth_dma", "tim16"]
start = true
notifications = ["eth-irq", "mdio-timer-irq", "wake-timer"]
interrupts = {"eth.irq" = "eth-irq", "tim16.irq" = "mdio-timer-irq"}
task-slots = ["sys"]
task-slots = ["sys", "jefe"]

[tasks.user_leds]
name = "drv-user-leds"
Expand Down
2 changes: 1 addition & 1 deletion app/gimletlet/app-mgmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sections = {eth_bulk = "sram1"}
uses = ["eth", "eth_dma", "tim16", "spi2"]
start = true
notifications = ["eth-irq", "mdio-timer-irq", "spi-irq", "wake-timer"]
task-slots = ["sys", "user_leds"]
task-slots = ["sys", "user_leds", "jefe"]

[tasks.net.interrupts]
"eth.irq" = "eth-irq"
Expand Down
2 changes: 1 addition & 1 deletion app/gimletlet/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ max-sizes = {flash = 131072, ram = 65536, sram1 = 16384}
sections = {eth_bulk = "sram1"}
uses = ["eth", "eth_dma", "tim16", "spi4"]
start = true
task-slots = ["sys"]
task-slots = ["sys", "jefe"]
notifications = ["eth-irq", "mdio-timer-irq", "spi-irq", "wake-timer"]

[tasks.net.interrupts]
Expand Down
2 changes: 1 addition & 1 deletion app/sidecar/rev-b.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sections = {eth_bulk = "sram1"}
uses = ["eth", "eth_dma", "tim16", "spi3"]
start = true
notifications = ["eth-irq", "mdio-timer-irq", "spi-irq", "wake-timer"]
task-slots = ["sys", "packrat", { seq = "sequencer" }]
task-slots = ["sys", "packrat", { seq = "sequencer" }, "jefe"]

[tasks.net.interrupts]
"eth.irq" = "eth-irq"
Expand Down
2 changes: 1 addition & 1 deletion app/sidecar/rev-c.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sections = {eth_bulk = "sram1"}
uses = ["eth", "eth_dma", "tim16", "spi3"]
start = true
notifications = ["eth-irq", "mdio-timer-irq", "spi-irq", "wake-timer"]
task-slots = ["sys", "packrat", { seq = "sequencer" }]
task-slots = ["sys", "packrat", { seq = "sequencer" }, "jefe"]

[tasks.net.interrupts]
"eth.irq" = "eth-irq"
Expand Down
12 changes: 12 additions & 0 deletions idl/jefe.idol
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,17 @@ Interface(
),
encoding: Hubpack,
),

// Note: this is the "raw" API; there is a nice wrapper in the client
// crate.
"restart_me_raw": (
description: "restarts the caller without recording a fault",
args: {},
// Note: this will not actually return, but Idol can't currently
// describe a noreturn IPC, so, we have a placeholder:
reply: Simple("()"),
encoding: Hubpack,
idempotent: true,
),
},
)
9 changes: 9 additions & 0 deletions task/jefe-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ pub enum DumpAreaError {
AlreadyInUse,
}

impl Jefe {
/// Asks the supervisor to restart the current task without recording a
/// fault.
pub fn restart_me(&self) -> ! {
self.restart_me_raw();
unreachable!()
}
}

include!(concat!(env!("OUT_DIR"), "/client_stub.rs"));
13 changes: 13 additions & 0 deletions task/jefe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ impl idl::InOrderJefeImpl for ServerImpl<'_> {
Ok(())
}

fn restart_me_raw(
&mut self,
msg: &userlib::RecvMessage,
) -> Result<(), RequestError<Infallible>> {
kipc::restart_task(msg.sender.index(), true);

// Note: the returned value here won't go anywhere because we just
// unblocked the caller. So this is doing a small amount of unnecessary
// work. This is a compromise because Idol can't easily describe an IPC
// that won't return at this time.
Ok(())
}

cfg_if::cfg_if! {
if #[cfg(feature = "dump")] {
fn get_dump_area(
Expand Down
6 changes: 2 additions & 4 deletions task/net/src/bsp/gimlet_bcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ use task_jefe_api::Jefe;
use task_net_api::{
ManagementCounters, ManagementLinkStatus, MgmtError, PhyError,
};
use userlib::{sys_recv_closed, task_slot, FromPrimitive, TaskId};
use userlib::{sys_recv_closed, FromPrimitive, TaskId};
use vsc7448_pac::types::PhyRegisterAddress;

task_slot!(JEFE, jefe);

////////////////////////////////////////////////////////////////////////////////

pub struct BspImpl(mgmt::Bsp);
Expand Down Expand Up @@ -56,7 +54,7 @@ impl crate::bsp_support::Bsp for BspImpl {
fn preinit() {
// Wait for the sequencer to turn on the clock. This requires that Jefe
// state change notifications are routed to our notification bit 3.
let jefe = Jefe::from(JEFE.get_task_id());
let jefe = Jefe::from(crate::JEFE.get_task_id());

loop {
// This laborious list is intended to ensure that new power states
Expand Down
6 changes: 2 additions & 4 deletions task/net/src/bsp/psc_a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ use task_jefe_api::Jefe;
use task_net_api::{
ManagementCounters, ManagementLinkStatus, MgmtError, PhyError,
};
use userlib::{sys_recv_closed, task_slot, FromPrimitive, TaskId};
use userlib::{sys_recv_closed, FromPrimitive, TaskId};
use vsc7448_pac::types::PhyRegisterAddress;

task_slot!(JEFE, jefe);

////////////////////////////////////////////////////////////////////////////////

pub struct BspImpl(mgmt::Bsp);
Expand Down Expand Up @@ -55,7 +53,7 @@ impl bsp_support::Bsp for BspImpl {

fn preinit() {
// Wait for the sequencer to turn read our VPD.
let jefe = Jefe::from(JEFE.get_task_id());
let jefe = Jefe::from(crate::JEFE.get_task_id());

loop {
// This laborious list is intended to ensure that new power states
Expand Down
6 changes: 2 additions & 4 deletions task/net/src/bsp/psc_bc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ use task_jefe_api::Jefe;
use task_net_api::{
ManagementCounters, ManagementLinkStatus, MgmtError, PhyError,
};
use userlib::{sys_recv_closed, task_slot, FromPrimitive, TaskId};
use userlib::{sys_recv_closed, FromPrimitive, TaskId};
use vsc7448_pac::types::PhyRegisterAddress;

task_slot!(JEFE, jefe);

////////////////////////////////////////////////////////////////////////////////

pub struct BspImpl(mgmt::Bsp);
Expand Down Expand Up @@ -60,7 +58,7 @@ impl bsp_support::Bsp for BspImpl {

fn preinit() {
// Wait for the sequencer to turn read our VPD.
let jefe = Jefe::from(JEFE.get_task_id());
let jefe = Jefe::from(crate::JEFE.get_task_id());

loop {
// This laborious list is intended to ensure that new power states
Expand Down
7 changes: 6 additions & 1 deletion task/net/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
use enum_map::Enum;
use multitimer::{Multitimer, Repeat};
use task_net_api::MacAddressBlock;
use task_jefe_api::Jefe;
use zerocopy::{AsBytes, U16};

#[cfg(feature = "h743")]
Expand All @@ -74,6 +75,7 @@ use crate::bsp::BspImpl;
use crate::bsp_support::Bsp;

task_slot!(SYS, sys);
task_slot!(JEFE, jefe);

#[cfg(feature = "vpd-mac")]
task_slot!(PACKRAT, packrat);
Expand Down Expand Up @@ -153,6 +155,7 @@ static ITER_COUNT: AtomicU32 = AtomicU32::new(0);
fn main() -> ! {
let sys = SYS.get_task_id();
let sys = Sys::from(sys);
let jefe = Jefe::from(JEFE.get_task_id());

// Do any preinit tasks specific to this board. For hardware which requires
// explicit clock configuration, this is where the `net` tasks waits for
Expand Down Expand Up @@ -265,7 +268,9 @@ fn main() -> ! {
server.wake();
// timer is set to auto-repeat
}
Timers::Watchdog => panic!("MAC RX watchdog"),
Timers::Watchdog => {
jefe.restart_me();
}
}
}
let mut msgbuf = [0u8; idl::INCOMING_SIZE];
Expand Down

0 comments on commit e52078a

Please sign in to comment.