Skip to content

task_slot: Bind at compile time instead of post-link patchup - #2764

Merged
jamesmunns merged 3 commits into
masterfrom
james/no-post-link
Nov 6, 2026
Merged

jamesmunns merged 3 commits into
masterfrom
james/no-post-link

Conversation

@jamesmunns

@jamesmunns jamesmunns commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

This is an extract of the task-slot binding mechanism I was building in #2736.

I think with today's const (and xtask), we can actually skip the post-linking patchup entirely, instead directly patching in via environment variables, as xtask is aware of all renames/remappings prior to building any tasks.

I won't be able to test this on hardware until tomorrow (but will do so!), and I wanted to see what CI thought of it as well.

@jamesmunns
jamesmunns requested review from labbott and mkeeter November 5, 2026 19:19
Comment thread sys/userlib/src/task_slot.rs Resolved
@jamesmunns

Copy link
Copy Markdown
Contributor Author

Tested on an grapefruit-a, device seems generally in good spirits. In particular, the spartan7-loader task uses task-slot remapping (spi = "spi2_driver"):

[tasks.spartan7_loader]
name = "drv-spartan7-loader"
features = ["h753"]
priority = 4
max-sizes = {flash = 131072, ram = 16384 }
stacksize = 2600
start = true
task-slots = ["sys", {spi = "spi2_driver"}, "auxflash"]

And seems happy in practice:

humility: ring buffer drv_spartan7_loader::__RINGBUF in spartan7_loader:
   TOTAL VARIANT
   10553 ContinueBitstreamLoad
       1 FpgaInit
       1 WaitForDone
       1 Programmed
 NDX LINE      GEN    COUNT PAYLOAD
  95  163       50       21 ContinueBitstreamLoad(0x200)
  96  163       50        1 ContinueBitstreamLoad(0x100)
...
  91  163       51       15 ContinueBitstreamLoad(0x80)
  92  163       51        1 ContinueBitstreamLoad(0x3f)
  93  177       51        1 WaitForDone
  94  186       51        1 Programmed { load_time_ms: 0x12bf }

Will fix merge conflicts and make a docs pass.

@jamesmunns

Copy link
Copy Markdown
Contributor Author

I've also looked through humility, and as far as I can tell, we don't inspect tasks slots anywhere, and do not expect this to cause any breakage there either.

panic!("task slot index is not a decimal number");
}
value = match value.checked_mul(10) {
Some(v) => match v.checked_add((digit - b'0') as u16) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried rewriting this with and_then + into, but alas neither of those are stable in a const context 🥲

Comment on lines +11 to +17
/// Parse a slot index from the given string, e.g. "11".
///
/// The mapping is provided via an `env!` var inserted by `xtask`.
/// See the `task_slot!` macro for more details.
///
/// Calling get_task_id() on an unbound TaskSlot will cause a fault from the
/// kernel.
pub const UNBOUND: Self = Self(VolatileConst::new(TaskId::UNBOUND.0));
/// This is intended to (only) be used at compile time, and panics if
/// `index` cannot be parsed as a `u16`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behold the power of const. I think this works really well!

@jamesmunns
jamesmunns merged commit 2af2af4 into master Nov 6, 2026
199 checks passed
@jamesmunns
jamesmunns deleted the james/no-post-link branch November 6, 2026 15:09
jamesmunns added a commit that referenced this pull request Nov 6, 2026
This has been replaced by the changes introduced by
#2764
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants