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_layered: Use topology for core selection #510

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

hodgesds
Copy link
Contributor

@hodgesds hodgesds commented Aug 19, 2024

Currently the core selection logic in scx_layered uses the first available core in the bitmask. This is suboptimal when the scheduler is configured with specific NUMA/LLC restrictions and with multiple layers. This refactors the core selection to use a preferred order of cores based on the layer index.

@hodgesds hodgesds requested a review from htejun August 19, 2024 14:40
@@ -1030,16 +1048,43 @@ impl Layer {
}
}

let mut nodes = topo.nodes().iter().collect::<Vec<_>>().clone();
let num_nodes = nodes.len();
nodes.rotate_left(if idx <= num_nodes { idx } else { idx % num_nodes });
Copy link
Contributor Author

@hodgesds hodgesds Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main logic, it makes use of rotate_left, which annoyingly will panic if the rotate size is too large. To get around that it mods by the number of nodes, llcs, or cores if the number of layers is larger than any of those values.

let available_cores = self.cpus_to_cores(&available_cpus).ok()?;

for alloc_core in layer.core_alloc_order() {
match available_cores.get(*alloc_core) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this goes from the core id to the bitmask bit for checking if the core is allowed to be used

let num_nodes = nodes.len();
let is_left = idx % 2 == 0;
if is_left {
nodes.rotate_left(if idx <= num_nodes { idx } else { idx % num_nodes });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe sth like let rot_by |idx, len| if idx <= len { idx } else { idx % len }; would help? Hmm... isn't this the same as idx % num_nodes?

Currently the core selection logic in scx_layered uses the first
available core in the bitmask. This is suboptimal when the scheduler is
configured with specific NUMA/LLC restrictions. The ideal core selection
logic should try to find the least used cores within the preferred
scheduling domain and allocate new cpus from shared cores within that
domain.

Signed-off-by: Daniel Hodges <[email protected]>
@hodgesds hodgesds merged commit 05a2721 into sched-ext:main Aug 20, 2024
1 of 2 checks passed
@hodgesds hodgesds deleted the layered-core-topo-selection branch August 20, 2024 00:01
hodgesds added a commit to hodgesds/scx that referenced this pull request Aug 21, 2024
Fix a bug introduced in sched-ext#510 where it assumed core ids are incremental.
This refactors the core ordering for layers to be far more simple and
provide some space for layer core isolation in low utilization.

Signed-off-by: Daniel Hodges <[email protected]>
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.

2 participants