Skip to content
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

Merged
merged 3 commits into from
Jan 8, 2024
Merged

Conversation

arighi
Copy link
Collaborator

@arighi arighi commented Jan 8, 2024

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.

Copy link
Contributor

@htejun htejun left a 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.

// 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;
Copy link
Contributor

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?

Copy link
Collaborator Author

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>
@arighi arighi force-pushed the scx-rustland-dynamic-timeslice branch from 79cb7a1 to fa6915c Compare January 8, 2024 07:50
@arighi arighi merged commit b008830 into main Jan 8, 2024
1 of 2 checks passed
@htejun htejun deleted the scx-rustland-dynamic-timeslice branch January 10, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants