-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scx_rustland: dynamic time slice #73
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a generally useful idea. I really like it. Left a minor comment. Please feel free to merge as-is or after an update. Thanks.
scheds/rust/scx_rustland/src/bpf.rs
Outdated
// Get current value of time slice (slice_ns). | ||
#[allow(dead_code)] | ||
pub fn get_slice_us(&mut self) -> u64 { | ||
let slice_ns = self.skel.bss().sched_slice_ns; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is confusing. Maybe dynamic_slice_ns
or effective_slice_ns
would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like effective_slice_ns
, it's a lot more clear, I'll go with that. Thanks!
Add to BpfScheduler() the new methods set_effective_slice_us() and get_effective_slice_us(). These methods can be used by the user-space scheduler to dynamically adjust (and retrieve) the effective time slice used to dispatch tasks within the BPF dispatcher. Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Implement a simple logic in the user-space scheduler to automatically adjust the tasks' time slice: reduce the time slice by a scaling factor of (nr_waiting / nr_cpus + 1), where nr_waiting is the amount of tasks waiting in the scheduler and nr_cpus is the amount of CPUs in the system. Using a fine-grained time slice as the number of tasks in the system grows, improves responsiveness of low-latency activities (e.g., audio, video games), also in presence of other CPU-intensive tasks that are concurrently running in the system. On the other hand, extending the time slice when only a limited number of tasks are active in the system contributes to an enhancement in the overall system throughput and a reduced amount of context switches. Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
With the introduction of a variable time slice that scales down in function of the amount of waiting tasks, the scheduler is able to handle a steady stream of newly spawned tasks, without having to de-prioritize them to guarantee a good level of system responsiveness. Hence, the logic for de-prioritizing new tasks can be removed, as it currently doesn't provide any measurable benefits. In fact, it even proves counterproductive as it can implicitly slow down the interactive performance of shell sessions when the system is overloaded with a significant amount of CPU hogs (e.g, `stress-ng -c 128`). Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
79cb7a1
to
fa6915c
Compare
Provide a new abstraction for the user-space scheduler to dynamically adjust the time slice used to dispatch tasks. Moreover, implement a mechanism in the user-space scheduler to dynamically scale the time slice as a function of the waiting tasks and the available CPUs in the system.
Apart for the benefits of having an additional scheduling abstraction (that can be beneficial for potential developers interested in expanding RustLand), this change also significantly improves the interactive performance of the scheduler, especially when the system is overloaded by a massive amount of CPU hogs (e.g.,
stress-ng -c 256
).Before this change the stress-ng command above could make my system pretty much unresponsive (triggering the sched-ext watchdog / stall detector). With this change applied the scheduler survives and I'm still able to run commands.