mirror of
https://github.com/JakeHillion/scx.git
synced 2024-12-01 21:37:12 +00:00
scx_rusty: Move stats structs to stats.rs and rename for consistency
This commit is contained in:
parent
5cf4212330
commit
4834dec684
@ -105,7 +105,7 @@
|
||||
//!
|
||||
//! Statistics are exported as a vector of NumaStat objects, which each
|
||||
//! contains load balancing statistics for that NUMA node, as well as
|
||||
//! statistics for any Domains contained therein as DomainStat objects.
|
||||
//! statistics for any Domains contained therein as DomainStats objects.
|
||||
//!
|
||||
//! Future Improvements
|
||||
//! -------------------
|
||||
@ -134,6 +134,8 @@ use core::cmp::Ordering;
|
||||
|
||||
use crate::bpf_intf;
|
||||
use crate::bpf_skel::*;
|
||||
use crate::stats::DomainStats;
|
||||
use crate::stats::NodeStats;
|
||||
use crate::DomainGroup;
|
||||
|
||||
use std::cell::Cell;
|
||||
@ -443,15 +445,15 @@ impl NumaNode {
|
||||
self.load.add_load(delta);
|
||||
}
|
||||
|
||||
fn numa_stat(&self) -> NumaStat {
|
||||
let mut n_stat = NumaStat {
|
||||
fn node_stats(&self) -> NodeStats {
|
||||
let mut n_stat = NodeStats {
|
||||
id: self.id,
|
||||
load: self.load.clone(),
|
||||
domains: Vec::new(),
|
||||
};
|
||||
|
||||
for dom in self.domains.iter() {
|
||||
n_stat.domains.push(DomainStat {
|
||||
n_stat.domains.push(DomainStats {
|
||||
id: dom.id,
|
||||
load: dom.load.clone(),
|
||||
});
|
||||
@ -471,55 +473,6 @@ impl LoadOrdered for NumaNode {
|
||||
}
|
||||
impl_ord_for_type!(NumaNode);
|
||||
|
||||
pub struct DomainStat {
|
||||
pub id: usize,
|
||||
pub load: LoadEntity,
|
||||
}
|
||||
|
||||
fn fmt_balance_stat(
|
||||
f: &mut fmt::Formatter<'_>,
|
||||
load: &LoadEntity,
|
||||
preamble: String,
|
||||
) -> fmt::Result {
|
||||
let imbal = load.imbal();
|
||||
let load_sum = load.load_sum();
|
||||
let load_delta = load.delta();
|
||||
let get_fmt = |num: f64| {
|
||||
if num >= 0.0f64 {
|
||||
format!("{:+4.2}", num)
|
||||
} else {
|
||||
format!("{:4.2}", num)
|
||||
}
|
||||
};
|
||||
|
||||
write!(
|
||||
f,
|
||||
"{} load={:4.2} imbal={} load_delta={}",
|
||||
preamble,
|
||||
load_sum,
|
||||
get_fmt(imbal),
|
||||
get_fmt(load_delta)
|
||||
)
|
||||
}
|
||||
|
||||
impl fmt::Display for DomainStat {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt_balance_stat(f, &self.load, format!(" DOMAIN[{:02}]", self.id))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NumaStat {
|
||||
pub id: usize,
|
||||
pub load: LoadEntity,
|
||||
pub domains: Vec<DomainStat>,
|
||||
}
|
||||
|
||||
impl fmt::Display for NumaStat {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt_balance_stat(f, &self.load, format!("NODE[{:02}]", self.id))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LoadBalancer<'a, 'b> {
|
||||
skel: &'a mut BpfSkel<'b>,
|
||||
dom_group: Arc<DomainGroup>,
|
||||
@ -576,10 +529,10 @@ impl<'a, 'b> LoadBalancer<'a, 'b> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_stats(&self) -> Vec<NumaStat> {
|
||||
pub fn get_stats(&self) -> Vec<NodeStats> {
|
||||
let mut numa_stats = Vec::with_capacity(self.dom_group.nr_nodes());
|
||||
for node in self.nodes.iter() {
|
||||
numa_stats.push(node.numa_stat());
|
||||
numa_stats.push(node.node_stats());
|
||||
}
|
||||
|
||||
numa_stats.sort_by(|x, y| x.id.partial_cmp(&y.id).unwrap());
|
||||
|
@ -14,7 +14,9 @@ use tuner::Tuner;
|
||||
|
||||
pub mod load_balance;
|
||||
use load_balance::LoadBalancer;
|
||||
use load_balance::NumaStat;
|
||||
|
||||
mod stats;
|
||||
use stats::NodeStats;
|
||||
|
||||
use std::mem::MaybeUninit;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
@ -456,7 +458,7 @@ impl<'a> Scheduler<'a> {
|
||||
bpf_stats: &[u64],
|
||||
cpu_busy: f64,
|
||||
processing_dur: Duration,
|
||||
lb_stats: &[NumaStat],
|
||||
node_stats: &[NodeStats],
|
||||
) {
|
||||
let stat = |idx| bpf_stats[idx as usize];
|
||||
let total = stat(bpf_intf::stat_idx_RUSTY_STAT_WAKE_SYNC)
|
||||
@ -471,8 +473,8 @@ impl<'a> Scheduler<'a> {
|
||||
+ stat(bpf_intf::stat_idx_RUSTY_STAT_GREEDY_LOCAL)
|
||||
+ stat(bpf_intf::stat_idx_RUSTY_STAT_GREEDY_XNUMA);
|
||||
|
||||
let numa_load_avg = lb_stats[0].load.load_avg();
|
||||
let dom_load_avg = lb_stats[0].domains[0].load.load_avg();
|
||||
let numa_load_avg = node_stats[0].load.load_avg();
|
||||
let dom_load_avg = node_stats[0].domains[0].load.load_avg();
|
||||
info!(
|
||||
"cpu={:7.2} bal={} numa_load_avg={:8.2} dom_load_avg={:8.2} task_err={} lb_data_err={} proc={:?}ms",
|
||||
cpu_busy * 100.0,
|
||||
@ -528,7 +530,7 @@ impl<'a> Scheduler<'a> {
|
||||
info!("direct_greedy_cpumask={}", self.tuner.direct_greedy_mask);
|
||||
info!(" kick_greedy_cpumask={}", self.tuner.kick_greedy_mask);
|
||||
|
||||
for node in lb_stats.iter() {
|
||||
for node in node_stats.iter() {
|
||||
info!("{}", node);
|
||||
for dom in node.domains.iter() {
|
||||
info!("{}", dom);
|
||||
|
51
scheds/rust/scx_rusty/src/stats.rs
Normal file
51
scheds/rust/scx_rusty/src/stats.rs
Normal file
@ -0,0 +1,51 @@
|
||||
use crate::load_balance::LoadEntity;
|
||||
use std::fmt;
|
||||
|
||||
fn fmt_balance_stat(
|
||||
f: &mut fmt::Formatter<'_>,
|
||||
load: &LoadEntity,
|
||||
preamble: String,
|
||||
) -> fmt::Result {
|
||||
let imbal = load.imbal();
|
||||
let load_sum = load.load_sum();
|
||||
let load_delta = load.delta();
|
||||
let get_fmt = |num: f64| {
|
||||
if num >= 0.0f64 {
|
||||
format!("{:+4.2}", num)
|
||||
} else {
|
||||
format!("{:4.2}", num)
|
||||
}
|
||||
};
|
||||
|
||||
write!(
|
||||
f,
|
||||
"{} load={:4.2} imbal={} load_delta={}",
|
||||
preamble,
|
||||
load_sum,
|
||||
get_fmt(imbal),
|
||||
get_fmt(load_delta)
|
||||
)
|
||||
}
|
||||
|
||||
pub struct DomainStats {
|
||||
pub id: usize,
|
||||
pub load: LoadEntity,
|
||||
}
|
||||
|
||||
impl fmt::Display for DomainStats {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt_balance_stat(f, &self.load, format!(" DOMAIN[{:02}]", self.id))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NodeStats {
|
||||
pub id: usize,
|
||||
pub load: LoadEntity,
|
||||
pub domains: Vec<DomainStats>,
|
||||
}
|
||||
|
||||
impl fmt::Display for NodeStats {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt_balance_stat(f, &self.load, format!("NODE[{:02}]", self.id))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user