From c45b08a2bb8b7b42e0f158fbbbfb41a651f1fca7 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Fri, 22 Dec 2023 14:54:44 +0100 Subject: [PATCH] scx_rustland: handle graceful vs non-graceful exit 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 --- scheds/rust/scx_rustland/src/main.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scheds/rust/scx_rustland/src/main.rs b/scheds/rust/scx_rustland/src/main.rs index b1e0b5a1c..d8cf90274 100644 --- a/scheds/rust/scx_rustland/src/main.rs +++ b/scheds/rust/scx_rustland/src/main.rs @@ -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(()) } }