Skip to content

Commit

Permalink
Merge branch 'master' into host-dtrace-support
Browse files Browse the repository at this point in the history
  • Loading branch information
jgallagher authored Oct 2, 2023
2 parents 43b24da + 6d6daa6 commit 5f6ee09
Show file tree
Hide file tree
Showing 14 changed files with 361 additions and 54 deletions.
81 changes: 70 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/lpc55xpresso/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extern-regions = ["sram2"]
[tasks.attest]
name = "task-attest"
priority = 5
max-sizes = {flash = 13600, ram = 16384}
max-sizes = {flash = 14800, ram = 16384}
stacksize = 9304
start = true
extern-regions = ["dice_alias", "dice_certs"]
Expand Down
4 changes: 2 additions & 2 deletions app/oxide-rot-1/app-dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ task-slots = ["syscon_driver"]
[tasks.sprot]
name = "drv-lpc55-sprot-server"
priority = 6
max-sizes = {flash = 45792, ram = 32768}
max-sizes = {flash = 46300, ram = 32768}
uses = ["flexcomm8", "bootrom"]
features = ["spi0"]
start = true
Expand Down Expand Up @@ -158,7 +158,7 @@ binary_path = "../../target/gimlet-c/dist/default/final.bin"
[tasks.attest]
name = "task-attest"
priority = 5
max-sizes = {flash = 13600, ram = 16384}
max-sizes = {flash = 14800, ram = 16384}
stacksize = 9304
start = true
extern-regions = ["dice_alias", "dice_certs"]
Expand Down
4 changes: 2 additions & 2 deletions app/oxide-rot-1/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ task-slots = ["syscon_driver"]
[tasks.sprot]
name = "drv-lpc55-sprot-server"
priority = 6
max-sizes = {flash = 45792, ram = 32768}
max-sizes = {flash = 46300, ram = 32768}
uses = ["flexcomm8", "bootrom"]
features = ["spi0"]
start = true
Expand Down Expand Up @@ -137,7 +137,7 @@ task-slots = ["swd"]
[tasks.attest]
name = "task-attest"
priority = 5
max-sizes = {flash = 13600, ram = 16384}
max-sizes = {flash = 14800, ram = 16384}
stacksize = 9304
start = true
extern-regions = ["dice_alias", "dice_certs"]
Expand Down
6 changes: 3 additions & 3 deletions app/rot-carrier/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ task-slots = ["syscon_driver"]
[tasks.sprot]
name = "drv-lpc55-sprot-server"
priority = 6
max-sizes = {flash = 45792, ram = 32768}
max-sizes = {flash = 46300, ram = 32768}
uses = ["flexcomm8", "bootrom"]
features = ["spi0"]
start = true
Expand Down Expand Up @@ -204,8 +204,8 @@ binary_path = "../../target/gemini-bu/dist/final.bin"
[tasks.attest]
name = "task-attest"
priority = 5
max-sizes = {flash = 13600, ram = 16384}
stacksize = 9304
max-sizes = {flash = 14800, ram = 16384}
stacksize = 9952
start = true
extern-regions = ["dice_alias", "dice_certs"]

Expand Down
36 changes: 22 additions & 14 deletions doc/tr1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ Here are some highlights.
As with most operating systems, tasks can be in a number of states: stopped,
runnable, blocked, etc. A common way to express this might be:

....
[source,rust]
----
struct Task {
state: State,
// other stuff omitted
Expand All @@ -302,14 +303,15 @@ enum State {
Runnable,
Blocked,
}
....
----

A fault event causes a task to no longer be schedulable, until the fault is
resolved or the task is restarted. A fault cannot *replace* the task's state,
because we want to remember it -- for debugging, at the least. And so we might
be tempted to do this:

....
[source,rust]
----
struct Task {
state: State,
fault: Option<Fault>,
Expand All @@ -326,19 +328,20 @@ enum Fault {
MemoryAccess(Address),
OtherReasons,
}
....
----

But this makes it really easy to schedule a faulted task _by accident,_ in a way
that's hard to spot with local reasoning. Specifically:

....
[source,rust]
----
for task in tasks {
if task.state == State::Runnable {
schedule(task);
break;
}
}
....
----

Looks correct! Is not correct. (The same issue could happen when replying to a
blocked task, setting it runnable without noticing a fault.)
Expand All @@ -349,7 +352,9 @@ but are _not_: a fault makes the other state temporarily irrelevant.
We can express this at the type level to make this class of mistake much less
likely:

....

[source,rust]
----
struct Task {
state: HealthState,
// other stuff omitted
Expand All @@ -373,7 +378,7 @@ enum Fault {
MemoryAccess(Address),
OtherReasons,
}
....
----

That is, while the original `State` is preserved when a fault is taken, it's
moved inside the `HealthState::Faulted` variant where it's structurally distinct
Expand All @@ -382,14 +387,15 @@ from `Healthy`.
Our scheduler loop above no longer compiles, because `task.state` is not a
`State`. Instead, we write the code like this:

....
[source,rust]
----
for task in tasks {
if task.state == HealthState::Healthy(State::Runnable) {
schedule(task);
break;
}
}
....
----

Any faulted state fails that equality test without further thought.

Expand All @@ -412,14 +418,15 @@ the next scheduling round without checking.

Hubris currently addresses this with the `NextTask` enum, which looks like this:

....
[source,rust]
----
#[must_use]
enum NextTask {
Same,
Specific(usize),
Other,
}
....
----

An operation returns `NextTask` if it *may* affect scheduling. `Same` indicates
that no context switch is required; `Specific(x)` indicates that a switch to a
Expand All @@ -440,7 +447,8 @@ When two `NextTask` values meet, they can be combined; this provides better
composition of operations than a simple "switch needed" flag. Combining two
`NextTask` values works as follows (expressed as a Rust `match`):

....
[source,rust]
----
match (self, other) {
// If both agree, our job is easy.
(x, y) if x == y => x,
Expand All @@ -454,7 +462,7 @@ match (self, other) {
// All we have left is...
(Same, Same) => Same,
}
....
----

(That's copied verbatim from the kernel source.)

Expand Down
Loading

0 comments on commit 5f6ee09

Please sign in to comment.