Skip to content

Commit bfc5e01

Browse files
lazy Scheduling Context rebind
Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
1 parent 8e19777 commit bfc5e01

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed

libmicrokit/src/main.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,5 @@ void main(void)
128128
{
129129
run_init_funcs();
130130
init();
131-
132-
/*
133-
* If we are passive, now our initialisation is complete we can
134-
* signal the monitor to unbind our scheduling context and bind
135-
* it to our notification object.
136-
* We delay this signal so we are ready waiting on a recv() syscall
137-
*/
138-
if (microkit_passive) {
139-
microkit_have_signal = seL4_True;
140-
microkit_signal_msg = seL4_MessageInfo_new(0, 0, 0, 0);
141-
microkit_signal_cap = MONITOR_EP;
142-
}
143-
144131
handler_loop();
145132
}

monitor/src/main.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct pd_metadata {
3737
char name[MAX_NAME_LEN];
3838
/* For reporting potential stack overflows, keep track of the stack regions for each PD. */
3939
seL4_Word stack_bottom;
40+
seL4_Word passive;
4041
} __attribute__((packed));
4142

4243
/* Correspond to `struct VmMetadata` in tool/microkit/src/symbols.rs */
@@ -740,25 +741,6 @@ static void monitor(void)
740741
seL4_Word pd_id = badge - 1;
741742
seL4_Word tcb_cap = BASE_PD_TCB_CAP + pd_id;
742743

743-
if (label == seL4_Fault_NullFault && pd_id < MAX_PDS) {
744-
/* This is a request from our PD to become passive */
745-
err = seL4_SchedContext_UnbindObject(BASE_SCHED_CONTEXT_CAP + pd_id, tcb_cap);
746-
if (err != seL4_NoError) {
747-
puts("MON|ERROR: could not unbind scheduling context from thread control block\n");
748-
} else {
749-
err = seL4_SchedContext_Bind(BASE_SCHED_CONTEXT_CAP + pd_id, BASE_NOTIFICATION_CAP + pd_id);
750-
if (err != seL4_NoError) {
751-
puts("MON|ERROR: could not bind scheduling context to notification object\n");
752-
} else {
753-
puts("MON|INFO: PD '");
754-
puts(pd_metadata[pd_id].name);
755-
puts("' is now passive!\n");
756-
}
757-
}
758-
759-
continue;
760-
}
761-
762744
puts("MON|ERROR: received message ");
763745
puthex32(label);
764746
puts(" badge: ");
@@ -898,6 +880,8 @@ static void monitor(void)
898880

899881
void main(void)
900882
{
883+
puts("MON|INFO: Microkit Monitor started!\n");
884+
901885
#if CONFIG_DEBUG_BUILD
902886
/*
903887
* Assign PD/VM names to each TCB with seL4, this helps debugging when an error
@@ -911,7 +895,28 @@ void main(void)
911895
}
912896
#endif
913897

914-
puts("MON|INFO: Microkit Monitor started!\n");
898+
/* If there are passive PDs in the system, lazily rebind it's Scheduling Context to it's Notification.
899+
* To workaround https://github.com/seL4/seL4/issues/1617 by applying https://github.com/seL4/seL4/pull/523
900+
*/
901+
for (unsigned idx = 0; idx < pd_metadata_len; idx++) {
902+
if (pd_metadata[idx].passive) {
903+
seL4_Error err = seL4_SchedContext_Bind(BASE_SCHED_CONTEXT_CAP + idx, BASE_NOTIFICATION_CAP + idx);
904+
if (err != seL4_NoError) {
905+
puts("MON|ERROR: could not bind scheduling context to notification object\n");
906+
continue;
907+
}
908+
909+
err = seL4_TCB_Resume(BASE_PD_TCB_CAP + idx);
910+
if (err != seL4_NoError) {
911+
puts("MON|ERROR: could not bind resume passive PD TCB\n");
912+
continue;
913+
}
914+
915+
puts("MON|INFO: PD '");
916+
puts(pd_metadata[idx].name);
917+
puts("' is now passive!\n");
918+
}
919+
}
915920

916921
monitor();
917922
}

tool/microkit/src/capdl/builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,8 @@ pub fn build_capdl_spec(
979979
pd_tcb.extra.master_fault_ep = None; // Not used on MCS kernel.
980980
pd_tcb.extra.prio = pd.priority;
981981
pd_tcb.extra.max_prio = pd.priority;
982-
pd_tcb.extra.resume = true;
982+
// Passive PDs are resumed by the Monitor
983+
pd_tcb.extra.resume = !pd.passive;
983984

984985
pd_tcb.slots.extend(caps_to_bind_to_tcb);
985986
// Stylistic purposes only

tool/microkit/src/symbols.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{
1919
struct PdMetadata {
2020
pub name: [u8; PD_MAX_NAME_LENGTH],
2121
pub stack_bottom: u64,
22+
pub passive: u64,
2223
}
2324

2425
/// Correspond to `struct vm_metadata` in monitor/src/main.c
@@ -47,6 +48,7 @@ pub fn patch_symbols(
4748
let mut metadata = PdMetadata {
4849
name: [0u8; PD_MAX_NAME_LENGTH],
4950
stack_bottom: kernel_config.pd_stack_bottom(pd.stack_size),
51+
passive: if pd.passive { 1 } else { 0 },
5052
};
5153

5254
copy_and_clip_string(pd.name.as_bytes(), &mut metadata.name);

0 commit comments

Comments
 (0)