kawamuray / linux-taskstats-rs

Rust interface for Linux taskstats
MIT License
9 stars 7 forks source link

Listener for the exiting tasks #10

Closed qpmr closed 5 months ago

qpmr commented 5 months ago

Hi, I would like to suggest adding register/deregister/listener functionalities for exiting tasks to the Client interface. It looks like:

/// Register listener with the specific cpumask
///
/// # Arguments
/// * `cpu_mask` - cpumask is specified as an ascii string of comma-separated cpu ranges e.g.
///   to listen to exit data from cpus 1,2,3,5,7,8 the cpumask would be "1-3,5,7-8".
pub fn register_cpumask(&self, cpu_mask: &str) -> Result<()> {
...
}

/// Deregister listener with the specific cpumask
/// If userspace forgets to deregister interest in cpus before closing the listening socket,
/// the kernel cleans up its interest set over time. However, for the sake of efficiency,
/// an explicit deregistration is advisable.
///
/// # Arguments
/// * `cpu_mask` - cpumask is specified as an ascii string of comma-separated cpu ranges e.g.
///   to listen to exit data from cpus 1,2,3,5,7,8 the cpumask would be "1-3,5,7-8".
pub fn deregister_cpumask(&self, cpu_mask: &str) -> Result<()> {
...
}

/// Listen registered cpumask's
///
/// # Return
/// * `Ok(Vec<TaskStats>)`: vector with stats messages. If the current task is NOT the last
///   one in its thread group, only one message is returned in the vector.
///   However, if it is the last task, an additional element containing the per-thread
///   group ID (tgid) statistics is also included. This additional element sums up
///   the statistics for all threads within the thread group, both past and present
pub fn listen_registered(&self) -> Result<Vec<TaskStats>> {
...
}

/// Set receiver buffer size in bytes (SO_RCVBUF socket option, see socket(7))
///
/// # Arguments
/// * `payload` - buffer size in bytes. The kernel doubles this value
///   (to allow space for bookkeeping overhead). The default value is set by the
///   /proc/sys/net/core/rmem_default file, and the maximum allowed value is set by the
///   /proc/sys/net/core/rmem_max file. The minimum (doubled) value for this option is 256.
pub fn set_rx_buf_sz<T>(&self, payload: T) -> Result<()> {
...
}

/// Get receiver buffer size in bytes (SO_RCVBUF socket option, see socket(7))
///
/// # Return
/// * `usize` buffer size in bytes.
///   Kernel returns doubled value, that have been set using [set_rx_buf_sz]
pub fn get_rx_buf_sz(&self) -> Result<usize> {
...
}

Now I am waiting for approval from netlink-sys crate maintainer regarding the 'get_rx_buf_sz/set_rx_buf_sz' methods

kawamuray commented 5 months ago

SGTM :) Looking forward the PR.

qpmr commented 5 months ago

Hi, socket rx buffer control functions have been added to the netlink-sys (0.8.6), so I've created PR #11 based on this new version.