-
Notifications
You must be signed in to change notification settings - Fork 91
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_bpfland: use scx_utils::Cpumask #522
Conversation
rust/scx_utils/src/cpumask.rs
Outdated
|
||
// Treat the last chunk separately, because it may not require the 16 hex digits padding. | ||
if let Some(last) = slice.last() { | ||
write!(f, "{:x}", last)?; |
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.
One problem with this is that if the leading hexes are zero, they'll be omitted even for possible CPUs leading to unaligned outputs. How about something like the following?
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut masks: Vec<u32> = self
.as_raw_slice()
.iter()
.map(|x| [*x as u32, (x >> 32) as u32])
.flatten()
.collect();
// Throw out possible stray from u64 -> u32.
masks.truncate((*NR_CPU_IDS + 31) / 32);
// Print the highest 32bit. Trim digits beyond NR_CPU_IDS.
let width = match (*NR_CPU_IDS + 3) / 4 % 8 {
0 => 8,
v => v,
};
write!(f, "{:0width$x}", masks.pop().unwrap(), width = width)?;
// The rest in descending order.
for submask in masks.iter().rev() {
write!(f, " {:08x}", submask)?;
}
Ok(())
}
This also cuts it on 32bit boundaries which is close to how kernel prints out cpumasks and easier to read.
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.
One problem with this is that if the leading hexes are zero, they'll be omitted even for possible CPUs leading to unaligned outputs. How about something like the following?
Oh I see, even if it's equivalent, it'd be nicer to print all the bits for all the possible CPUs.
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut masks: Vec<u32> = self .as_raw_slice() .iter() .map(|x| [*x as u32, (x >> 32) as u32]) .flatten() .collect(); // Throw out possible stray from u64 -> u32. masks.truncate((*NR_CPU_IDS + 31) / 32); // Print the highest 32bit. Trim digits beyond NR_CPU_IDS. let width = match (*NR_CPU_IDS + 3) / 4 % 8 { 0 => 8, v => v, }; write!(f, "{:0width$x}", masks.pop().unwrap(), width = width)?; // The rest in descending order. for submask in masks.iter().rev() { write!(f, " {:08x}", submask)?; } Ok(()) }
This also cuts it on 32bit boundaries which is close to how kernel prints out cpumasks and easier to read.
I like this, also with the extra space between each 32-bit chunk to make the cpumask more readable. I'll apply this change and do some tests, thanks!
1f453b2
to
c872e7a
Compare
Allow to format a Cpumask as an hex string, implementing the proper formatter LowerHex / UpperHex traits. Signed-off-by: Tejun Heo <[email protected]> Signed-off-by: Andrea Righi <[email protected]>
Rely on scx_utils::Cpumask instead of re-implementing a custom struct to parse and manage CPU masks. Signed-off-by: Andrea Righi <[email protected]>
c872e7a
to
a9f5aaa
Compare
Added @htejun's fmt() and refactored the code a bit to avoid code duplication. |
Rely on
scx_utils::Cpumask
instead of re-implementing a customCpuMask
struct.This is just some code refactoring, no functional change.