Skip to content

Commit

Permalink
scx_rustland: handle graceful vs non-graceful exit
Browse files Browse the repository at this point in the history
Do not report an exit error message if it's not needed. Moreover,
distinguish between a graceful exit vs a non-graceful exit.

NOTE: in the future the whole exit handling probably can be moved to a
more generic place (scx_utils) to prevent code duplication across
schedulers and also to prevent small inconsistencies like this one.

Signed-off-by: Andrea Righi <[email protected]>
  • Loading branch information
Andrea Righi committed Dec 22, 2023
1 parent c7b52d4 commit c45b08a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions scheds/rust/scx_rustland/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,32 @@ impl<'a> Scheduler<'a> {

// Called on exit to get exit code and exit message from the BPF part.
fn report_bpf_exit_kind(&mut self) -> Result<()> {
// Report msg if EXT_OPS_EXIT_ERROR.
match self.read_bpf_exit_kind() {
0 => Ok(()),
etype => {
// etype can be one of the following (from include/linux/sched/ext.h):
//
// enum scx_exit_kind {
// SCX_EXIT_NONE,
// SCX_EXIT_DONE,
//
// SCX_EXIT_UNREG = 64, /* BPF unregistration */
// SCX_EXIT_SYSRQ, /* requested by 'S' sysrq */
//
// SCX_EXIT_ERROR = 1024, /* runtime error, error msg contains details */
// SCX_EXIT_ERROR_BPF, /* ERROR but triggered through scx_bpf_error() */
// SCX_EXIT_ERROR_STALL, /* watchdog detected stalled runnable tasks */
// };
etype if etype > 64 => {
let cstr = unsafe { CStr::from_ptr(self.skel.bss().exit_msg.as_ptr() as *const _) };
let msg = cstr
.to_str()
.context("Failed to convert exit msg to string")
.unwrap();
info!("BPF exit_kind={} msg={}", etype, msg);
bail!("BPF exit_kind={} msg={}", etype, msg);
}
etype => {
info!("BPF exit_kind={}", etype);
Ok(())
}
}
Expand Down

0 comments on commit c45b08a

Please sign in to comment.