Skip to main content

sof_gossip_tuning/domain/
model.rs

1//! Domain entities and enums for SOF gossip and ingest tuning.
2
3use crate::domain::value_objects::{
4    CpuCoreIndex, QueueCapacity, ReceiverCoalesceWindow, TvuReceiveSocketCount,
5};
6
7/// Receiver thread pinning policy.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum ReceiverPinningPolicy {
10    /// Leave receiver threads to the scheduler.
11    Inherit,
12    /// Pin all receiver threads to a single core.
13    FixedCore(CpuCoreIndex),
14    /// Let SOF pin receivers deterministically by port.
15    PinByPort,
16}
17
18/// High-level receiver fanout profile.
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum ReceiverFanoutProfile {
21    /// Keep receiver fanout minimal to reduce background overhead.
22    Conservative,
23    /// Balanced settings for a small VPS.
24    Balanced,
25    /// Aggressive fanout for dedicated hosts.
26    Aggressive,
27}
28
29/// Built-in host profile preset.
30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
31pub enum HostProfilePreset {
32    /// Home or low-end host with constrained ingress.
33    Home,
34    /// VPS or small dedicated instance.
35    Vps,
36    /// Dedicated high-throughput host.
37    Dedicated,
38}
39
40/// Current ingest queue mode supported by SOF runtime env.
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub enum IngestQueueMode {
43    /// Bounded channel mode.
44    Bounded,
45    /// Unbounded channel mode.
46    Unbounded,
47    /// Lock-free ring mode.
48    Lockfree,
49}
50
51impl IngestQueueMode {
52    /// Returns the SOF env string form.
53    #[must_use]
54    pub const fn as_str(self) -> &'static str {
55        match self {
56            Self::Bounded => "bounded",
57            Self::Unbounded => "unbounded",
58            Self::Lockfree => "lockfree",
59        }
60    }
61}
62
63/// SOF-supported receiver/runtime knobs that can be translated directly into runtime setup.
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub struct SofRuntimeTuning {
66    /// Ingest queue mode.
67    pub ingest_queue_mode: IngestQueueMode,
68    /// SOF ingest queue capacity.
69    pub ingest_queue_capacity: QueueCapacity,
70    /// UDP batch size.
71    pub udp_batch_size: u16,
72    /// Receiver coalesce window.
73    pub receiver_coalesce_window: ReceiverCoalesceWindow,
74    /// Optional fixed receiver core.
75    pub udp_receiver_core: Option<CpuCoreIndex>,
76    /// Whether SOF should pin receivers by port.
77    pub udp_receiver_pin_by_port: bool,
78    /// TVU receive socket count used by gossip bootstrap.
79    pub tvu_receive_sockets: TvuReceiveSocketCount,
80}
81
82/// Agave gossip-side queue knobs that are not yet wired through SOF bootstrap.
83#[derive(Debug, Clone, Copy, PartialEq, Eq)]
84pub struct PendingGossipQueuePlan {
85    /// Target gossip receiver queue capacity.
86    pub gossip_receiver_channel_capacity: QueueCapacity,
87    /// Target socket consume queue capacity.
88    pub socket_consume_channel_capacity: QueueCapacity,
89    /// Target gossip response queue capacity.
90    pub gossip_response_channel_capacity: QueueCapacity,
91    /// Desired receiver fanout profile for future integration.
92    pub fanout: ReceiverFanoutProfile,
93}
94
95/// Agave gossip-side queue knobs that are currently upstream-internal in practice.
96#[derive(Debug, Clone, Copy, PartialEq, Eq)]
97pub struct GossipChannelTuning {
98    /// Receiver socket -> gossip request channel capacity.
99    pub gossip_receiver_channel_capacity: QueueCapacity,
100    /// Socket consume channel capacity.
101    pub socket_consume_channel_capacity: QueueCapacity,
102    /// Gossip response channel capacity.
103    pub gossip_response_channel_capacity: QueueCapacity,
104}
105
106/// Host-specific aggregate root for one gossip tuning profile.
107#[derive(Debug, Clone, Copy, PartialEq, Eq)]
108pub struct GossipTuningProfile {
109    /// Host profile label.
110    pub preset: HostProfilePreset,
111    /// SOF-supported runtime tuning.
112    pub runtime: SofRuntimeTuning,
113    /// Gossip internal queue tuning.
114    pub channels: GossipChannelTuning,
115    /// Desired receiver fanout posture for future integration.
116    pub fanout: ReceiverFanoutProfile,
117}