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    /// Bounded drain budget for one gossip worker pass.
81    pub gossip_channel_consume_capacity: QueueCapacity,
82    /// Gossip socket-consume worker count.
83    pub gossip_consume_threads: usize,
84    /// Gossip listen worker count.
85    pub gossip_listen_threads: usize,
86    /// Gossip run/push-pull worker count.
87    pub gossip_run_threads: usize,
88    /// Semantic shred dedupe capacity.
89    pub shred_dedup_capacity: usize,
90}
91
92/// Gossip queue budget exposed as a compact planning view.
93#[derive(Debug, Clone, Copy, PartialEq, Eq)]
94pub struct PendingGossipQueuePlan {
95    /// Target gossip receiver queue capacity.
96    pub gossip_receiver_channel_capacity: QueueCapacity,
97    /// Target socket consume queue capacity.
98    pub socket_consume_channel_capacity: QueueCapacity,
99    /// Target gossip response queue capacity.
100    pub gossip_response_channel_capacity: QueueCapacity,
101    /// Desired receiver fanout profile for future integration.
102    pub fanout: ReceiverFanoutProfile,
103}
104
105/// Gossip queue knobs exposed through SOF's bundled gossip backend.
106#[derive(Debug, Clone, Copy, PartialEq, Eq)]
107pub struct GossipChannelTuning {
108    /// Receiver socket -> gossip request channel capacity.
109    pub gossip_receiver_channel_capacity: QueueCapacity,
110    /// Socket consume channel capacity.
111    pub socket_consume_channel_capacity: QueueCapacity,
112    /// Gossip response channel capacity.
113    pub gossip_response_channel_capacity: QueueCapacity,
114}
115
116/// Host-specific aggregate root for one gossip tuning profile.
117#[derive(Debug, Clone, Copy, PartialEq, Eq)]
118pub struct GossipTuningProfile {
119    /// Host profile label.
120    pub preset: HostProfilePreset,
121    /// SOF-supported runtime tuning.
122    pub runtime: SofRuntimeTuning,
123    /// Gossip internal queue tuning.
124    pub channels: GossipChannelTuning,
125    /// Desired receiver fanout posture.
126    pub fanout: ReceiverFanoutProfile,
127}