From 0a7161cbc73bcc588237096ce6a69846ee892340 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 9 Mar 2024 11:51:40 +0100 Subject: [PATCH 1/2] scx_rustland: limit range of task weight Some high-priority tasks may have a weight too high, that can potentially disrupt the slice boost optimization logic, causing interactive tasks to be less responsive. In line with rustland's focus on prioritizing interactive tasks, prevent giving too much CPU bandwidth to such high-priority tasks by limiting the maximum task weight to 1000. This allows to maintain a good level of system responsiveness even in presence of tasks with a really high priority. Signed-off-by: Andrea Righi --- scheds/rust/scx_rustland/src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scheds/rust/scx_rustland/src/main.rs b/scheds/rust/scx_rustland/src/main.rs index d31ce534b..948b826b3 100644 --- a/scheds/rust/scx_rustland/src/main.rs +++ b/scheds/rust/scx_rustland/src/main.rs @@ -391,10 +391,13 @@ impl<'a> Scheduler<'a> { // NOTE: we should make this threshold a tunable, but for now let's assume that a moving // average of 10 voluntary context switch per second is enough to classify the task as // interactive. + // + // NOTE: some tasks may have a very high weight, that can potentially disrupt our slice + // boost optimizations, therefore always limit the task priority to a max of 1000. let weight = if task_info.avg_nvcsw >= 10 { - task.weight * self.slice_boost.max(1) + task.weight.min(1000) * self.slice_boost.max(1) } else { - task.weight + task.weight.min(1000) }; // Scale the time slice by the task's priority (weight). From 155444e1c0ef45e937cf70e35d3426437bb7221d Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 9 Mar 2024 11:51:29 +0100 Subject: [PATCH 2/2] scx_rustland: set default time slice to 5ms In line with rustland's focus on prioritizing interactive tasks, set the default base time slice to 5ms. This allows to mitigate potential audio craking issues or system lags when the system is overloaded or under memory pressure condition (i.e., https://github.com/sched-ext/scx/issues/96#issuecomment-1978154324). A downside of this change is to introduce potential regressions in the throughput of CPU-intensive workloads, but in such scenarios rustland may not be the optimal choice and alternative schedulers may be preferred. Signed-off-by: Andrea Righi --- scheds/rust/scx_rustland/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scheds/rust/scx_rustland/src/main.rs b/scheds/rust/scx_rustland/src/main.rs index 948b826b3..3c32d94a2 100644 --- a/scheds/rust/scx_rustland/src/main.rs +++ b/scheds/rust/scx_rustland/src/main.rs @@ -79,8 +79,8 @@ const SCHEDULER_NAME: &'static str = "RustLand"; /// #[derive(Debug, Parser)] struct Opts { - /// Scheduling slice duration in microseconds. - #[clap(short = 's', long, default_value = "20000")] + /// Scheduling slice duration in microseconds (default is 5ms). + #[clap(short = 's', long, default_value = "5000")] slice_us: u64, /// Time slice boost: increasing this value enhances performance of interactive applications