Strongly type RTT data in the throughput tracker to reduce confusion.

This commit is contained in:
Herbert Wolverson
2024-03-15 13:03:49 -05:00
parent b8937bf9c2
commit 6ce7e7a3f9
3 changed files with 13 additions and 12 deletions

View File

@@ -364,8 +364,8 @@ pub fn xdp_pping_compat() -> BusResponse {
let mut valid_samples: Vec<u32> = data
.recent_rtt_data
.iter()
.filter(|d| **d > 0)
.copied()
.filter(|d| d.as_millis_times_100() > 0.0)
.map(|d| d.as_millis_times_100() as u32)
.collect();
let samples = valid_samples.len() as u32;
if samples > 0 {
@@ -405,15 +405,15 @@ pub fn rtt_histogram() -> BusResponse {
.iter()
.filter(|d| retire_check(reader_cycle, d.most_recent_cycle))
{
let valid_samples: Vec<u32> = data
let valid_samples: Vec<f64> = data
.recent_rtt_data
.iter()
.filter(|d| **d > 0)
.copied()
.filter(|d| d.as_millis() > 0.0)
.map(|d| d.as_millis())
.collect();
let samples = valid_samples.len() as u32;
if samples > 0 {
let median = valid_samples[valid_samples.len() / 2] as f32 / 10.0;
let median = valid_samples[valid_samples.len() / 2] as f32;
let median = f32::min(200.0, median);
let column = median as usize;
result[usize::min(column, 19)] += 1;

View File

@@ -1,4 +1,5 @@
use lqos_bus::TcHandle;
use super::flow_data::RttData;
#[derive(Debug)]
pub(crate) struct ThroughputEntry {
@@ -13,7 +14,7 @@ pub(crate) struct ThroughputEntry {
pub(crate) bytes_per_second: (u64, u64),
pub(crate) packets_per_second: (u64, u64),
pub(crate) tc_handle: TcHandle,
pub(crate) recent_rtt_data: [u32; 60],
pub(crate) recent_rtt_data: [RttData; 60],
pub(crate) last_fresh_rtt_data_cycle: u64,
pub(crate) last_seen: u64, // Last seen in kernel time since boot
}
@@ -33,8 +34,8 @@ impl ThroughputEntry {
let mut shifted: Vec<f32> = self
.recent_rtt_data
.iter()
.filter(|n| **n != 0)
.map(|n| *n as f32 / 10.0)
.filter(|n| n.as_nanos() != 0)
.map(|n| n.as_millis() as f32)
.collect();
if shifted.len() < 5 {
return None;

View File

@@ -49,7 +49,7 @@ impl ThroughputTracker {
if self_cycle > RETIRE_AFTER_SECONDS
&& v.last_fresh_rtt_data_cycle < self_cycle - RETIRE_AFTER_SECONDS
{
v.recent_rtt_data = [0; 60];
v.recent_rtt_data = [RttData::from_nanos(0); 60];
}
});
}
@@ -150,7 +150,7 @@ impl ThroughputTracker {
bytes_per_second: (0, 0),
packets_per_second: (0, 0),
tc_handle: TcHandle::zero(),
recent_rtt_data: [0; 60],
recent_rtt_data: [RttData::from_nanos(0); 60],
last_fresh_rtt_data_cycle: 0,
last_seen: 0,
};
@@ -226,7 +226,7 @@ impl ThroughputTracker {
for i in 1..60 {
tracker.recent_rtt_data[i] = tracker.recent_rtt_data[i - 1];
}
tracker.recent_rtt_data[0] = rtt[i].as_millis() as u32;
tracker.recent_rtt_data[0] = rtt[i];
tracker.last_fresh_rtt_data_cycle = self_cycle;
if let Some(parents) = &tracker.network_json_parents {
let net_json = NETWORK_JSON.write().unwrap();