-
Notifications
You must be signed in to change notification settings - Fork 98
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: Refactor proximity map iteration #1086
Conversation
scheds/rust/scx_layered/src/main.rs
Outdated
} | ||
vec.sort_by_key(|&num| { | ||
let diff = if num < x { x - num } else { num - x }; | ||
(diff, num < x) |
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.
((num - x).abs(), num < x)
?
scheds/rust/scx_layered/src/main.rs
Outdated
}); | ||
let mut result = Vec::new(); | ||
let left: Vec<usize> = vec[0..vec.len() / 2].iter().cloned().rev().collect(); | ||
let right: Vec<usize> = vec[vec.len() / 2..vec.len()].iter().cloned().collect(); |
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.
If it's already sorted by abs distance, I'm not sure what the lef/right interposing achieves. The "center" the order is radiating form is already at the beginning of the list, right?
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 guess it's the difference between:
23:01:54 [DEBUG] CPU[79] proximity map[2/40/40/80]: [79, 39, 78, 38, 77, 37, 76, 36, 75, 35, 74, 34, 73, 33, 72, 32, 71, 31, 70, 30, 69, 29, 68, 28, 67, 27, 66, 26, 65, 25, 64, 24, 63, 23, 62, 22, 61, 21, 60, 20, 59, 19, 58, 18, 57, 17, 56, 16, 55, 15, 54, 14, 53, 13, 52, 12, 51, 11, 50, 10, 49, 9, 48, 8, 47, 7, 46, 6, 45, 5, 44, 4, 43, 3, 42, 2, 41, 1, 40, 0]
vs
23:03:01 [DEBUG] CPU[79] proximity map[2/40/40/80]: [79, 39, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
One improvement may be sorting by the core_id distance and then using cpu_id distance as the sort sub-key. That way, the visiting order can be grouped by smt threads and that is a bit more orderly and might even have cache consequences. |
cf7ce2a
to
2535e98
Compare
I think that makes sense. Getting the order grouped by smt threads seems like the right approach, lemme rework this. |
2535e98
to
378365f
Compare
New ordering based on core id/cpu id:
|
83aeeef
to
682ae6b
Compare
scheds/rust/scx_layered/src/main.rs
Outdated
vec.sort_by_key(|&id| { | ||
( | ||
(topo.all_cpus.get(&id).unwrap().core_id as i32 - center_core as i32).abs(), | ||
center_cpu.cmp(&id), |
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.
Would it be better to also use abs distance from center_cpu here? Both sibling CPU IDs could be on the same side of the center and in such cases center_cpu.cmp(&id)
wouldn't order them in a deterministic way. This likely doesn't matter in any practical sense but it does make the code confusing as it's unclear what the second ordering is supposed to do. The same for goes for radiate
.
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.
That makes sense, it was completely backwards. Should be good now.
682ae6b
to
1bdf56a
Compare
Refactor proximity map iteration order to radiate based on distance from current cpu. Signed-off-by: Daniel Hodges <hodges.daniel.scott@gmail.com>
1bdf56a
to
bbebb6e
Compare
Refactor proximity map iteration order to radiate based on distance from current cpu. Example output from initialization: