Skip to content

Commit

Permalink
scx_bpfland: When reporting stats, use interval deltas
Browse files Browse the repository at this point in the history
Three of the reported stats are cumulative. While they obviously can be
processed into delta values, that holds for the other direction too and the
cumulative values are difficult to make intutive sense of. Report interval
delta values instead.

Note that a stats client can reliably build back cumulative values even
under heavy system contention - the delta values reported between two
consecutive reads are guaranteed to be correct regardless of the duration of
the interval.
  • Loading branch information
htejun committed Aug 25, 2024
1 parent bd68e23 commit 152a847
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions scheds/rust/scx_bpfland/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,30 @@ impl Metrics {
)?;
Ok(())
}

fn delta(&self, rhs: &Self) -> Self {
Self {
nr_direct_dispatches: self.nr_direct_dispatches - rhs.nr_direct_dispatches,
nr_prio_dispatches: self.nr_prio_dispatches - rhs.nr_prio_dispatches,
nr_shared_dispatches: self.nr_shared_dispatches - rhs.nr_shared_dispatches,
..self.clone()
}
}
}

pub fn server_data() -> StatsServerData<(), Metrics> {
let open: Box<dyn StatsOpener<(), Metrics>> = Box::new(move |(_req_ch, _res_ch)| {
let open: Box<dyn StatsOpener<(), Metrics>> = Box::new(move |(req_ch, res_ch)| {
req_ch.send(())?;
let mut prev = res_ch.recv()?;

let read: Box<dyn StatsReader<(), Metrics>> = Box::new(move |_args, (req_ch, res_ch)| {
req_ch.send(())?;
let metrics = res_ch.recv()?;
metrics.to_json()
let cur = res_ch.recv()?;
let delta = cur.delta(&prev);
prev = cur;
delta.to_json()
});

Ok(read)
});

Expand Down

0 comments on commit 152a847

Please sign in to comment.