Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
likewhatevs committed Sep 11, 2024
1 parent 71274d3 commit 6e253c3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 52 deletions.
4 changes: 1 addition & 3 deletions rust/scx_utils/src/bpf_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,6 @@ mod tests {

println!("vmlinux.h: ver={:?}", &ver);

assert!(regex::Regex::new(r"^[a-f0-9]{7}$")
.unwrap()
.is_match(&ver));
assert!(regex::Regex::new(r"^[a-f0-9]{7}$").unwrap().is_match(&ver));
}
}
54 changes: 27 additions & 27 deletions rust/scx_utils/src/user_exit_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ macro_rules! uei_report {
#[derive(Debug, Default)]
pub struct UserExitInfo {
r#type: i32,
// exit_code: i64,
// exit_code: i64,
reason: Option<String>,
msg: Option<String>,
// dump: Option<String>,
// dump: Option<String>,
}

impl UserExitInfo {
Expand Down Expand Up @@ -164,24 +164,24 @@ impl UserExitInfo {
.filter(|s| !s.is_empty()),
);

// let dump = if dump_ptr.is_null() {
// None
// } else {
// Some(
// unsafe { CStr::from_ptr(dump_ptr) }
// .to_str()
// .expect("Failed to convert msg to string")
// .to_string(),
// )
// .filter(|s| !s.is_empty())
// };
// let dump = if dump_ptr.is_null() {
// None
// } else {
// Some(
// unsafe { CStr::from_ptr(dump_ptr) }
// .to_str()
// .expect("Failed to convert msg to string")
// .to_string(),
// )
// .filter(|s| !s.is_empty())
// };

Self {
r#type,
// exit_code,
reason,
msg,
// dump,
// dump,
}
}

Expand All @@ -193,22 +193,22 @@ impl UserExitInfo {
return Ok(());
}

// if let Some(dump) = &self.dump {
// eprintln!("\nDEBUG DUMP");
// eprintln!("================================================================================\n");
// eprintln!("{}", dump);
// eprintln!("================================================================================\n");
// }
// if let Some(dump) = &self.dump {
// eprintln!("\nDEBUG DUMP");
// eprintln!("================================================================================\n");
// eprintln!("{}", dump);
// eprintln!("================================================================================\n");
// }

let why = match (&self.reason, &self.msg) {
(Some(reason), None) => format!("EXIT: {}", reason),
(Some(reason), Some(msg)) => format!("EXIT: {} ({})", reason, msg),
_ => "<UNKNOWN>".into(),
};
let why = match (&self.reason, &self.msg) {
(Some(reason), None) => format!("EXIT: {}", reason),
(Some(reason), Some(msg)) => format!("EXIT: {} ({})", reason, msg),
_ => "<UNKNOWN>".into(),
};

if why != "<UNKNOWN>"{
if why != "<UNKNOWN>" {
eprintln!("{}", why);
}
}

// if self.kind <= ScxExitKind::UnregKern as i32 {
// eprintln!("{}", why);
Expand Down
44 changes: 27 additions & 17 deletions scheds/rust/scx_layered/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.
// mod bpf_skel;
mod stats;
pub mod bpf_skel;
mod stats;
pub use bpf_skel::*;
pub mod bpf_intf;
use core::ffi::CStr;
use stats::LayerStats;
use stats::StatsReq;
use stats::StatsRes;
Expand All @@ -15,7 +16,6 @@ use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::HashMap;
use std::ffi::CString;
use core::ffi::CStr;
use std::fs;
use std::io::Read;
use std::io::Write;
Expand Down Expand Up @@ -457,7 +457,9 @@ enum LayerGrowthAlgo {
}

impl Default for LayerGrowthAlgo {
fn default() -> Self { LayerGrowthAlgo::Sticky }
fn default() -> Self {
LayerGrowthAlgo::Sticky
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -888,7 +890,6 @@ impl Stats {
}
}


#[derive(Debug, Default)]
struct UserExitInfo {
kind: i32,
Expand Down Expand Up @@ -1152,11 +1153,7 @@ impl CpuPool {
}
}

fn layer_core_order(
growth_algo: LayerGrowthAlgo,
layer_idx: usize,
topo: &Topology
) -> Vec<usize> {
fn layer_core_order(growth_algo: LayerGrowthAlgo, layer_idx: usize, topo: &Topology) -> Vec<usize> {
let mut core_order = vec![];
match growth_algo {
LayerGrowthAlgo::Sticky => {
Expand Down Expand Up @@ -1262,8 +1259,18 @@ impl Layer {
bail!("invalid util_range {:?}", util_range);
}
}
LayerKind::Grouped { growth_algo, nodes, llcs, .. } |
LayerKind::Open { growth_algo, nodes, llcs, .. } => {
LayerKind::Grouped {
growth_algo,
nodes,
llcs,
..
}
| LayerKind::Open {
growth_algo,
nodes,
llcs,
..
} => {
layer_growth_algo = growth_algo.clone();
if nodes.len() == 0 && llcs.len() == 0 {
allowed_cpus.fill(true);
Expand Down Expand Up @@ -1686,7 +1693,9 @@ impl<'a, 'b> Scheduler<'a, 'b> {
let mut skel_builder = BpfSkelBuilder::default();
skel_builder.obj_builder.debug(opts.verbose > 1);
init_libbpf_logging(None);
let mut skel = skel_builder.open(open_object).context("failed to open BPF program")?;
let mut skel = skel_builder
.open(open_object)
.context("failed to open BPF program")?;

// scheduler_tick() got renamed to sched_tick() during v6.10-rc.
let sched_tick_name = match compat::ksym_exists("sched_tick")? {
Expand Down Expand Up @@ -1768,9 +1777,9 @@ impl<'a, 'b> Scheduler<'a, 'b> {
};

sched
.skel
.attach()
.context("Failed to attach BPF program")?;
.skel
.attach()
.context("Failed to attach BPF program")?;

sched.struct_ops = Some(
sched
Expand Down Expand Up @@ -1909,7 +1918,9 @@ impl<'a, 'b> Scheduler<'a, 'b> {
let mut next_sched_at = Instant::now() + self.sched_intv;
let mut cpus_ranges = HashMap::<ThreadId, Vec<(usize, usize)>>::new();

while !shutdown.load(Ordering::Relaxed) && !UserExitInfo::exited(&self.skel.maps.bss_data.uei)? {
while !shutdown.load(Ordering::Relaxed)
&& !UserExitInfo::exited(&self.skel.maps.bss_data.uei)?
{
let now = Instant::now();

if now >= next_sched_at {
Expand Down Expand Up @@ -2162,4 +2173,3 @@ fn main() -> Result<()> {
let mut sched = Scheduler::init(&opts, &layer_config.specs, &mut open_object)?;
sched.run(shutdown.clone())
}

6 changes: 5 additions & 1 deletion scheds/rust/scx_layered/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ impl LayerStats {
}
};
let calc_frac = |a, b| {
if b != 0.0 { a / b * 100.0 } else { 0.0 }
if b != 0.0 {
a / b * 100.0
} else {
0.0
}
};

let is_excl = match &layer.kind {
Expand Down
9 changes: 5 additions & 4 deletions scheds/rust/scx_rusty/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ pub mod load_balance;
use load_balance::LoadBalancer;

mod stats;
use core::ffi::CStr;
use std::collections::BTreeMap;
use std::ffi::CString;
use std::mem::MaybeUninit;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
Expand All @@ -25,8 +27,6 @@ use std::time::Duration;
use std::time::Instant;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
use std::ffi::CString;
use core::ffi::CStr;

use stats::ClusterStats;
use stats::NodeStats;
Expand Down Expand Up @@ -575,7 +575,9 @@ impl<'a> Scheduler<'a> {

self.skel.maps.stats.value_size() as usize;

while !shutdown.load(Ordering::Relaxed) && !UserExitInfo::exited(&self.skel.maps.bss_data.uei)? {
while !shutdown.load(Ordering::Relaxed)
&& !UserExitInfo::exited(&self.skel.maps.bss_data.uei)?
{
let now = Instant::now();

if now >= next_tune_at {
Expand Down Expand Up @@ -733,4 +735,3 @@ impl UserExitInfo {
}
}
}

0 comments on commit 6e253c3

Please sign in to comment.