From 0d24adf4dc3a26c684e7385d93d28aaf7e1e39ff Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 12 Jan 2026 15:55:28 -0800 Subject: [PATCH 1/5] jefe: move a biggish bit of jefe off the stack --- Cargo.lock | 1 + task/jefe/Cargo.toml | 1 + task/jefe/src/main.rs | 28 ++++++++++++++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ada0d1883b..be3b3c2b31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5861,6 +5861,7 @@ dependencies = [ "ringbuf", "serde", "ssmarshal", + "static-cell", "task-jefe-api", "userlib", "zerocopy 0.8.27", diff --git a/task/jefe/Cargo.toml b/task/jefe/Cargo.toml index 72ed229ec6..95919ab3a9 100644 --- a/task/jefe/Cargo.toml +++ b/task/jefe/Cargo.toml @@ -21,6 +21,7 @@ hubris-num-tasks = { path = "../../sys/num-tasks", features = ["task-enum"] } ringbuf = { path = "../../lib/ringbuf" } task-jefe-api = { path = "../jefe-api" } userlib = { path = "../../sys/userlib" } +static-cell = { path = "../../lib/static-cell" } [build-dependencies] anyhow = { workspace = true } diff --git a/task/jefe/src/main.rs b/task/jefe/src/main.rs index f2db0c5f20..285a836509 100644 --- a/task/jefe/src/main.rs +++ b/task/jefe/src/main.rs @@ -37,12 +37,12 @@ use core::convert::Infallible; use hubris_num_tasks::NUM_TASKS; use humpty::DumpArea; use idol_runtime::RequestError; +use static_cell::ClaimOnceCell; use task_jefe_api::{DumpAgentError, ResetReason}; use userlib::{kipc, Generation, TaskId}; -#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum Disposition { - #[default] Restart, Hold, } @@ -64,7 +64,11 @@ const MIN_RUN_TIME: u64 = 50; #[export_name = "main"] fn main() -> ! { - let mut task_states = [TaskStatus::default(); hubris_num_tasks::NUM_TASKS]; + let task_states = { + static STATES: ClaimOnceCell<[TaskStatus; NUM_TASKS]> = + ClaimOnceCell::new([TaskStatus::initial(); NUM_TASKS]); + STATES.claim() + }; for held_task in generated::HELD_TASKS { task_states[held_task as usize].disposition = Disposition::Hold; } @@ -77,7 +81,7 @@ fn main() -> ! { let mut server = ServerImpl { state: 0, deadline, - task_states: &mut task_states, + task_states, any_tasks_in_timeout: false, reset_reason: ResetReason::Unknown, @@ -322,7 +326,7 @@ impl idl::InOrderJefeImpl for ServerImpl<'_> { /// Structure we use for tracking the state of the tasks we supervise. There is /// one of these per supervised task. -#[derive(Copy, Clone, Debug, Default)] +#[derive(Copy, Clone, Debug)] struct TaskStatus { disposition: Disposition, state: TaskState, @@ -340,9 +344,17 @@ enum TaskState { }, } -impl Default for TaskState { - fn default() -> Self { - TaskState::Running { started_at: 0 } +impl TaskStatus { + /// This really ought to be a `Default` implementation, but it's used in a + /// `ClaimOnceCell` static initializer and `Default` cannot yet be `const + /// fn`. + /// + /// Whatever... + const fn initial() -> Self { + Self { + disposition: Disposition::Restart, + state: TaskState::Running { started_at: 0 }, + } } } From 6dfdbf1f8b1e9a7a237fae0756c1bba67ca2ee7a Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 12 Jan 2026 16:04:51 -0800 Subject: [PATCH 2/5] also what if we initialized the array at compile-time? --- sys/num-tasks/build.rs | 1 + task/jefe/src/main.rs | 34 ++++++++++++++++------------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/sys/num-tasks/build.rs b/sys/num-tasks/build.rs index 6b632b9ffe..caf62c2c5d 100644 --- a/sys/num-tasks/build.rs +++ b/sys/num-tasks/build.rs @@ -23,6 +23,7 @@ fn main() -> Result<(), Box> { if build_util::has_feature("task-enum") { writeln!(task_file, "#[allow(non_camel_case_types)]").unwrap(); + writeln!(task_file, "#[derive(Copy, Clone)]").unwrap(); writeln!(task_file, "pub enum Task {{").unwrap(); for line in task_enum { writeln!(task_file, "{line}").unwrap(); diff --git a/task/jefe/src/main.rs b/task/jefe/src/main.rs index 285a836509..7f5c227eb0 100644 --- a/task/jefe/src/main.rs +++ b/task/jefe/src/main.rs @@ -65,13 +65,25 @@ const MIN_RUN_TIME: u64 = 50; #[export_name = "main"] fn main() -> ! { let task_states = { + const fn initialize_task_states() -> [TaskStatus; NUM_TASKS] { + const INITIAL_STATE: TaskStatus = TaskStatus { + disposition: Disposition::Restart, + state: TaskState::Running { started_at: 0 }, + }; + let mut tasks = [INITIAL_STATE; NUM_TASKS]; + let mut i = 0; + while i < generated::HELD_TASKS.len() { + let held_task = generated::HELD_TASKS[i] as usize; + tasks[held_task].disposition = Disposition::Hold; + i += 1; + } + tasks + } + static STATES: ClaimOnceCell<[TaskStatus; NUM_TASKS]> = - ClaimOnceCell::new([TaskStatus::initial(); NUM_TASKS]); + ClaimOnceCell::new(initialize_task_states()); STATES.claim() }; - for held_task in generated::HELD_TASKS { - task_states[held_task as usize].disposition = Disposition::Hold; - } let deadline = userlib::set_timer_relative(TIMER_INTERVAL, notifications::TIMER_MASK); @@ -344,20 +356,6 @@ enum TaskState { }, } -impl TaskStatus { - /// This really ought to be a `Default` implementation, but it's used in a - /// `ClaimOnceCell` static initializer and `Default` cannot yet be `const - /// fn`. - /// - /// Whatever... - const fn initial() -> Self { - Self { - disposition: Disposition::Restart, - state: TaskState::Running { started_at: 0 }, - } - } -} - impl idol_runtime::NotificationHandler for ServerImpl<'_> { fn current_notification_mask(&self) -> u32 { notifications::FAULT_MASK | notifications::TIMER_MASK From 21210cb5771b43ef1f7382866bb1bea37732c750 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 12 Jan 2026 16:15:34 -0800 Subject: [PATCH 3/5] get rid of helper function --- task/jefe/src/main.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/task/jefe/src/main.rs b/task/jefe/src/main.rs index 7f5c227eb0..4abdd4aa32 100644 --- a/task/jefe/src/main.rs +++ b/task/jefe/src/main.rs @@ -65,7 +65,7 @@ const MIN_RUN_TIME: u64 = 50; #[export_name = "main"] fn main() -> ! { let task_states = { - const fn initialize_task_states() -> [TaskStatus; NUM_TASKS] { + static STATES: ClaimOnceCell<[TaskStatus; NUM_TASKS]> = { const INITIAL_STATE: TaskStatus = TaskStatus { disposition: Disposition::Restart, state: TaskState::Running { started_at: 0 }, @@ -77,11 +77,8 @@ fn main() -> ! { tasks[held_task].disposition = Disposition::Hold; i += 1; } - tasks - } - - static STATES: ClaimOnceCell<[TaskStatus; NUM_TASKS]> = - ClaimOnceCell::new(initialize_task_states()); + ClaimOnceCell::new(tasks) + }; STATES.claim() }; From 71adb46bbade73cc6f79a9c336c879227158cb32 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 12 Jan 2026 16:26:11 -0800 Subject: [PATCH 4/5] actually ensmallerate some of the little jefes --- app/demo-stm32g0-nucleo/app-g031.toml | 2 +- app/demo-stm32g0-nucleo/app-g070-mini.toml | 2 +- app/demo-stm32g0-nucleo/app-g070.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/demo-stm32g0-nucleo/app-g031.toml b/app/demo-stm32g0-nucleo/app-g031.toml index bb537f7d37..e4ab820fe1 100644 --- a/app/demo-stm32g0-nucleo/app-g031.toml +++ b/app/demo-stm32g0-nucleo/app-g031.toml @@ -15,7 +15,7 @@ name = "task-jefe" priority = 0 max-sizes = {flash = 4096, ram = 512} start = true -stacksize = 368 +stacksize = 200 notifications = ["fault", "timer"] [tasks.sys] diff --git a/app/demo-stm32g0-nucleo/app-g070-mini.toml b/app/demo-stm32g0-nucleo/app-g070-mini.toml index 12bcb86183..290b4ec9b5 100644 --- a/app/demo-stm32g0-nucleo/app-g070-mini.toml +++ b/app/demo-stm32g0-nucleo/app-g070-mini.toml @@ -21,7 +21,7 @@ name = "task-jefe" priority = 0 max-sizes = {flash = 4096, ram = 512} start = true -stacksize = 400 +stacksize = 200 notifications = ["fault", "timer"] [tasks.idle] diff --git a/app/demo-stm32g0-nucleo/app-g070.toml b/app/demo-stm32g0-nucleo/app-g070.toml index 57eabd710f..8017ba6945 100644 --- a/app/demo-stm32g0-nucleo/app-g070.toml +++ b/app/demo-stm32g0-nucleo/app-g070.toml @@ -16,7 +16,7 @@ name = "task-jefe" priority = 0 max-sizes = {flash = 4096, ram = 512} start = true -stacksize = 400 +stacksize = 200 notifications = ["fault", "timer"] [tasks.sys] From 8c356f6b60d4a3194a147bd35f611d7a4d2e8ff4 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Tue, 13 Jan 2026 10:22:41 -0800 Subject: [PATCH 5/5] ensmallerate Oxcon G0 demo board jefe --- app/oxcon2023g0/app.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/oxcon2023g0/app.toml b/app/oxcon2023g0/app.toml index 64e050c4f2..c88d020c58 100644 --- a/app/oxcon2023g0/app.toml +++ b/app/oxcon2023g0/app.toml @@ -6,7 +6,7 @@ board = "oxcon2023g0" [kernel] name = "oxcon2023g0" -requires = {flash = 11680, ram = 1296} +requires = {flash = 11744, ram = 1296} stacksize = 640 [tasks.jefe] @@ -15,7 +15,7 @@ priority = 0 max-sizes = {flash = 4096, ram = 512} start = true features = ["nano"] -stacksize = 368 +stacksize = 200 notifications = ["fault", "timer"] [tasks.sys]