Skip to content

Commit

Permalink
feat: add backlog_wait_time_actual in status message
Browse files Browse the repository at this point in the history
This is a rather new field, seemingly present since the 5.9 kernel.
  • Loading branch information
vthib committed Jul 21, 2023
1 parent fd45e42 commit ac6e4ce
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const BACKLOG: Field = 28..32;
pub const MINIMAL_STATUS_MESSAGE_LEN: usize = BACKLOG.end;
const FEATURE_BITMAP: Field = 32..36;
const BACKLOG_WAIT_TIME: Field = 36..40;
pub const MAXIMAL_STATUS_MESSAGE_LEN: usize = BACKLOG_WAIT_TIME.end;
const BACKLOG_WAIT_TIME_ACTUAL: Field = 36..40;
pub const MAXIMAL_STATUS_MESSAGE_LEN: usize = BACKLOG_WAIT_TIME_ACTUAL.end;

#[derive(Debug, PartialEq, Eq, Clone, Default)]
#[non_exhaustive]
Expand All @@ -47,6 +48,8 @@ pub struct StatusMessage {
pub feature_bitmap: Option<u32>,
/// Message queue wait timeout
pub backlog_wait_time: Option<u32>,
/// Time spent waiting while message limit exceeded
pub backlog_wait_time_actual: Option<u32>,
}

impl StatusMessage {
Expand Down Expand Up @@ -139,6 +142,15 @@ impl<T: AsRef<[u8]>> StatusMessageBuffer<T> {
Some(NativeEndian::read_u32(&buf[BACKLOG_WAIT_TIME]))
}
}

pub fn backlog_wait_time_actual(&self) -> Option<u32> {
let buf = self.buffer.as_ref();
if buf.len() < BACKLOG_WAIT_TIME_ACTUAL.end {
None
} else {
Some(NativeEndian::read_u32(&buf[BACKLOG_WAIT_TIME_ACTUAL]))
}
}
}

impl<T: AsRef<[u8]> + AsMut<[u8]>> StatusMessageBuffer<T> {
Expand Down Expand Up @@ -187,6 +199,13 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> StatusMessageBuffer<T> {
NativeEndian::write_u32(&mut buf[BACKLOG_WAIT_TIME], value)
}
}

pub fn set_backlog_wait_time_actual(&mut self, value: u32) {
let buf = &mut self.buffer.as_mut();
if buf.len() >= BACKLOG_WAIT_TIME_ACTUAL.end {
NativeEndian::write_u32(&mut buf[BACKLOG_WAIT_TIME_ACTUAL], value)
}
}
}

impl<T: AsRef<[u8]>> Parseable<StatusMessageBuffer<T>> for StatusMessage {
Expand All @@ -203,6 +222,7 @@ impl<T: AsRef<[u8]>> Parseable<StatusMessageBuffer<T>> for StatusMessage {
backlog: buf.backlog(),
feature_bitmap: buf.feature_bitmap(),
backlog_wait_time: buf.backlog_wait_time(),
backlog_wait_time_actual: buf.backlog_wait_time_actual(),
})
}
}
Expand All @@ -228,5 +248,8 @@ impl Emitable for StatusMessage {
if let Some(backlog_wait_time) = self.backlog_wait_time {
buffer.set_backlog_wait_time(backlog_wait_time);
}
if let Some(backlog_wait_time_actual) = self.backlog_wait_time_actual {
buffer.set_backlog_wait_time_actual(backlog_wait_time_actual);
}
}
}

0 comments on commit ac6e4ce

Please sign in to comment.