From b53e8251a10f772acf6d02e6bb7bb826ee1484db Mon Sep 17 00:00:00 2001 From: David Vernet Date: Wed, 6 Dec 2023 18:18:41 -0600 Subject: [PATCH] rusty: Fix calc_util() in rusty We were assigning curr to prev stats, and vice versa, in calc_util(). This was causing the following crash on debug builds: [void@maniforge scheds]$ sudo RUST_BACKTRACE=1 scx_rusty 00:00:56 [INFO] CPUs: online/possible = 32/32 00:00:56 [INFO] DOM[00] cpumask 0000000000FF00FF (16 cpus) 00:00:56 [INFO] DOM[01] cpumask 00000000FF00FF00 (16 cpus) 00:00:56 [INFO] Rusty Scheduler Attached thread 'main' panicked at /rustc/475c71da0710fd1d40c046f9cee04b733b5b2b51/library/core/src/ops/arith.rs:217:1: attempt to subtract with overflow stack backtrace: 0: rust_begin_unwind at /rustc/475c71da0710fd1d40c046f9cee04b733b5b2b51/library/std/src/panicking.rs:597:5 1: core::panicking::panic_fmt at /rustc/475c71da0710fd1d40c046f9cee04b733b5b2b51/library/core/src/panicking.rs:72:14 2: core::panicking::panic at /rustc/475c71da0710fd1d40c046f9cee04b733b5b2b51/library/core/src/panicking.rs:127:5 3: ::sub at /rustc/475c71da0710fd1d40c046f9cee04b733b5b2b51/library/core/src/ops/arith.rs:217:1 4: <&u64 as core::ops::arith::Sub<&u64>>::sub at /rustc/475c71da0710fd1d40c046f9cee04b733b5b2b51/library/core/src/internal_macros.rs:55:17 5: scx_rusty::calc_util at ./rust-user/scx_rusty/src/main.rs:216:29 6: scx_rusty::Tuner::step at ./rust-user/scx_rusty/src/main.rs:444:38 7: scx_rusty::Scheduler::run at ./rust-user/scx_rusty/src/main.rs:1198:17 8: scx_rusty::main at ./rust-user/scx_rusty/src/main.rs:1261:5 9: core::ops::function::FnOnce::call_once at /rustc/475c71da0710fd1d40c046f9cee04b733b5b2b51/library/core/src/ops/function.rs:250:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. Flip them to avoid the crash. Rusty now runs fine. Signed-off-by: David Vernet --- scheds/rust-user/scx_rusty/src/main.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scheds/rust-user/scx_rusty/src/main.rs b/scheds/rust-user/scx_rusty/src/main.rs index 3d802e27d..ff7cc9d80 100644 --- a/scheds/rust-user/scx_rusty/src/main.rs +++ b/scheds/rust-user/scx_rusty/src/main.rs @@ -190,17 +190,6 @@ fn read_total_cpu(reader: &procfs::ProcReader) -> Result { fn calc_util(curr: &procfs::CpuStat, prev: &procfs::CpuStat) -> Result { match (curr, prev) { ( - procfs::CpuStat { - user_usec: Some(prev_user), - nice_usec: Some(prev_nice), - system_usec: Some(prev_system), - idle_usec: Some(prev_idle), - iowait_usec: Some(prev_iowait), - irq_usec: Some(prev_irq), - softirq_usec: Some(prev_softirq), - stolen_usec: Some(prev_stolen), - .. - }, procfs::CpuStat { user_usec: Some(curr_user), nice_usec: Some(curr_nice), @@ -212,6 +201,17 @@ fn calc_util(curr: &procfs::CpuStat, prev: &procfs::CpuStat) -> Result { stolen_usec: Some(curr_stolen), .. }, + procfs::CpuStat { + user_usec: Some(prev_user), + nice_usec: Some(prev_nice), + system_usec: Some(prev_system), + idle_usec: Some(prev_idle), + iowait_usec: Some(prev_iowait), + irq_usec: Some(prev_irq), + softirq_usec: Some(prev_softirq), + stolen_usec: Some(prev_stolen), + .. + }, ) => { let idle_usec = curr_idle - prev_idle; let iowait_usec = curr_iowait - prev_iowait;