Skip to main content

iris_core/lcore/
mod.rs

1//! Utilities for managing and monitoring Iris cores.
2
3pub(crate) mod monitor;
4// pub(crate) mod ring;
5pub(crate) mod rx_core;
6
7use crate::dpdk;
8
9use std::fmt;
10
11use serde::{Deserialize, Serialize};
12
13#[derive(Debug, Copy, Clone, Hash, Ord, Eq, PartialEq, PartialOrd)]
14pub(crate) struct SocketId(pub(crate) u32);
15
16impl SocketId {
17    // For DPDK functions
18    pub(crate) fn raw(&self) -> u32 {
19        self.0
20    }
21}
22
23impl fmt::Display for SocketId {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        write!(f, "{}", self.0)
26    }
27}
28
29/* --------------------------------------------------------------------------------- */
30
31/// An identifier for a core running Iris (sink, monitoring, or RX).
32#[derive(Debug, Copy, Clone, Hash, Ord, Eq, PartialEq, PartialOrd, Deserialize, Serialize)]
33pub struct CoreId(pub u32);
34
35impl CoreId {
36    pub(crate) fn socket_id(&self) -> SocketId {
37        unsafe { SocketId(dpdk::rte_lcore_to_socket_id(self.0)) }
38    }
39
40    /// The core ID as u32, primarily for DPDK functions
41    pub fn raw(&self) -> u32 {
42        self.0
43    }
44}
45
46impl fmt::Display for CoreId {
47    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48        write!(f, "{}", self.0)
49    }
50}