Skip to content

Commit 19b63d8

Browse files
authored
feat(s2n-quic-platform): prioritized socket for s2n-quic's IO (#3014)
1 parent 024b804 commit 19b63d8

15 files changed

Lines changed: 542 additions & 54 deletions

File tree

quic/s2n-quic-core/events/platform.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ enum PlatformFeatureConfiguration {
123123
MaxMtu { mtu: u16 },
124124
}
125125

126+
#[event("platform:rx_socket")]
127+
#[subject(endpoint)]
128+
/// Emitted for each receive socket with per-socket packet counts
129+
struct PlatformRxSocketStats {
130+
/// Whether this socket is the prioritized socket
131+
is_prioritized: bool,
132+
133+
/// The number of packets received on this socket since the last event
134+
#[counter("packets.total")]
135+
count: usize,
136+
}
137+
126138
#[event("platform:event_loop_wakeup")]
127139
#[subject(endpoint)]
128140
struct PlatformEventLoopWakeup {

quic/s2n-quic-core/src/event/generated.rs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,6 +3107,27 @@ pub mod api {
31073107
}
31083108
#[derive(Clone, Debug)]
31093109
#[non_exhaustive]
3110+
#[doc = " Emitted for each receive socket with per-socket packet counts"]
3111+
pub struct PlatformRxSocketStats {
3112+
#[doc = " Whether this socket is the prioritized socket"]
3113+
pub is_prioritized: bool,
3114+
#[doc = " The number of packets received on this socket since the last event"]
3115+
pub count: usize,
3116+
}
3117+
#[cfg(any(test, feature = "testing"))]
3118+
impl crate::event::snapshot::Fmt for PlatformRxSocketStats {
3119+
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
3120+
let mut fmt = fmt.debug_struct("PlatformRxSocketStats");
3121+
fmt.field("is_prioritized", &self.is_prioritized);
3122+
fmt.field("count", &self.count);
3123+
fmt.finish()
3124+
}
3125+
}
3126+
impl Event for PlatformRxSocketStats {
3127+
const NAME: &'static str = "platform:rx_socket";
3128+
}
3129+
#[derive(Clone, Debug)]
3130+
#[non_exhaustive]
31103131
pub struct PlatformEventLoopWakeup {
31113132
pub timeout_expired: bool,
31123133
pub rx_ready: bool,
@@ -4576,6 +4597,19 @@ pub mod tracing {
45764597
tracing :: event ! (target : "platform_feature_configured" , parent : parent , tracing :: Level :: DEBUG , { configuration = tracing :: field :: debug (configuration) });
45774598
}
45784599
#[inline]
4600+
fn on_platform_rx_socket_stats(
4601+
&mut self,
4602+
meta: &api::EndpointMeta,
4603+
event: &api::PlatformRxSocketStats,
4604+
) {
4605+
let parent = self.parent(meta);
4606+
let api::PlatformRxSocketStats {
4607+
is_prioritized,
4608+
count,
4609+
} = event;
4610+
tracing :: event ! (target : "platform_rx_socket_stats" , parent : parent , tracing :: Level :: DEBUG , { is_prioritized = tracing :: field :: debug (is_prioritized) , count = tracing :: field :: debug (count) });
4611+
}
4612+
#[inline]
45794613
fn on_platform_event_loop_wakeup(
45804614
&mut self,
45814615
meta: &api::EndpointMeta,
@@ -7009,6 +7043,27 @@ pub mod builder {
70097043
}
70107044
}
70117045
#[derive(Clone, Debug)]
7046+
#[doc = " Emitted for each receive socket with per-socket packet counts"]
7047+
pub struct PlatformRxSocketStats {
7048+
#[doc = " Whether this socket is the prioritized socket"]
7049+
pub is_prioritized: bool,
7050+
#[doc = " The number of packets received on this socket since the last event"]
7051+
pub count: usize,
7052+
}
7053+
impl IntoEvent<api::PlatformRxSocketStats> for PlatformRxSocketStats {
7054+
#[inline]
7055+
fn into_event(self) -> api::PlatformRxSocketStats {
7056+
let PlatformRxSocketStats {
7057+
is_prioritized,
7058+
count,
7059+
} = self;
7060+
api::PlatformRxSocketStats {
7061+
is_prioritized: is_prioritized.into_event(),
7062+
count: count.into_event(),
7063+
}
7064+
}
7065+
}
7066+
#[derive(Clone, Debug)]
70127067
pub struct PlatformEventLoopWakeup {
70137068
pub timeout_expired: bool,
70147069
pub rx_ready: bool,
@@ -7955,6 +8010,16 @@ mod traits {
79558010
let _ = meta;
79568011
let _ = event;
79578012
}
8013+
#[doc = "Called when the `PlatformRxSocketStats` event is triggered"]
8014+
#[inline]
8015+
fn on_platform_rx_socket_stats(
8016+
&mut self,
8017+
meta: &api::EndpointMeta,
8018+
event: &api::PlatformRxSocketStats,
8019+
) {
8020+
let _ = meta;
8021+
let _ = event;
8022+
}
79588023
#[doc = "Called when the `PlatformEventLoopWakeup` event is triggered"]
79598024
#[inline]
79608025
fn on_platform_event_loop_wakeup(
@@ -8676,6 +8741,15 @@ mod traits {
86768741
(self.1).on_platform_feature_configured(meta, event);
86778742
}
86788743
#[inline]
8744+
fn on_platform_rx_socket_stats(
8745+
&mut self,
8746+
meta: &api::EndpointMeta,
8747+
event: &api::PlatformRxSocketStats,
8748+
) {
8749+
(self.0).on_platform_rx_socket_stats(meta, event);
8750+
(self.1).on_platform_rx_socket_stats(meta, event);
8751+
}
8752+
#[inline]
86798753
fn on_platform_event_loop_wakeup(
86808754
&mut self,
86818755
meta: &api::EndpointMeta,
@@ -8771,6 +8845,8 @@ mod traits {
87718845
fn on_platform_rx_error(&mut self, event: builder::PlatformRxError);
87728846
#[doc = "Publishes a `PlatformFeatureConfigured` event to the publisher's subscriber"]
87738847
fn on_platform_feature_configured(&mut self, event: builder::PlatformFeatureConfigured);
8848+
#[doc = "Publishes a `PlatformRxSocketStats` event to the publisher's subscriber"]
8849+
fn on_platform_rx_socket_stats(&mut self, event: builder::PlatformRxSocketStats);
87748850
#[doc = "Publishes a `PlatformEventLoopWakeup` event to the publisher's subscriber"]
87758851
fn on_platform_event_loop_wakeup(&mut self, event: builder::PlatformEventLoopWakeup);
87768852
#[doc = "Publishes a `PlatformEventLoopSleep` event to the publisher's subscriber"]
@@ -8900,6 +8976,13 @@ mod traits {
89008976
self.subscriber.on_event(&self.meta, &event);
89018977
}
89028978
#[inline]
8979+
fn on_platform_rx_socket_stats(&mut self, event: builder::PlatformRxSocketStats) {
8980+
let event = event.into_event();
8981+
self.subscriber
8982+
.on_platform_rx_socket_stats(&self.meta, &event);
8983+
self.subscriber.on_event(&self.meta, &event);
8984+
}
8985+
#[inline]
89038986
fn on_platform_event_loop_wakeup(&mut self, event: builder::PlatformEventLoopWakeup) {
89048987
let event = event.into_event();
89058988
self.subscriber
@@ -9558,6 +9641,7 @@ pub mod testing {
95589641
pub platform_rx: u64,
95599642
pub platform_rx_error: u64,
95609643
pub platform_feature_configured: u64,
9644+
pub platform_rx_socket_stats: u64,
95619645
pub platform_event_loop_wakeup: u64,
95629646
pub platform_event_loop_sleep: u64,
95639647
pub platform_event_loop_started: u64,
@@ -9605,6 +9689,7 @@ pub mod testing {
96059689
platform_rx: 0,
96069690
platform_rx_error: 0,
96079691
platform_feature_configured: 0,
9692+
platform_rx_socket_stats: 0,
96089693
platform_event_loop_wakeup: 0,
96099694
platform_event_loop_sleep: 0,
96109695
platform_event_loop_started: 0,
@@ -9754,6 +9839,17 @@ pub mod testing {
97549839
let out = format!("{meta:?} {event:?}");
97559840
self.output.push(out);
97569841
}
9842+
fn on_platform_rx_socket_stats(
9843+
&mut self,
9844+
meta: &api::EndpointMeta,
9845+
event: &api::PlatformRxSocketStats,
9846+
) {
9847+
self.platform_rx_socket_stats += 1;
9848+
let meta = crate::event::snapshot::Fmt::to_snapshot(meta);
9849+
let event = crate::event::snapshot::Fmt::to_snapshot(event);
9850+
let out = format!("{meta:?} {event:?}");
9851+
self.output.push(out);
9852+
}
97579853
fn on_platform_event_loop_wakeup(
97589854
&mut self,
97599855
meta: &api::EndpointMeta,
@@ -9855,6 +9951,7 @@ pub mod testing {
98559951
pub platform_rx: u64,
98569952
pub platform_rx_error: u64,
98579953
pub platform_feature_configured: u64,
9954+
pub platform_rx_socket_stats: u64,
98589955
pub platform_event_loop_wakeup: u64,
98599956
pub platform_event_loop_sleep: u64,
98609957
pub platform_event_loop_started: u64,
@@ -9951,6 +10048,7 @@ pub mod testing {
995110048
platform_rx: 0,
995210049
platform_rx_error: 0,
995310050
platform_feature_configured: 0,
10051+
platform_rx_socket_stats: 0,
995410052
platform_event_loop_wakeup: 0,
995510053
platform_event_loop_sleep: 0,
995610054
platform_event_loop_started: 0,
@@ -10779,6 +10877,17 @@ pub mod testing {
1077910877
let out = format!("{meta:?} {event:?}");
1078010878
self.output.push(out);
1078110879
}
10880+
fn on_platform_rx_socket_stats(
10881+
&mut self,
10882+
meta: &api::EndpointMeta,
10883+
event: &api::PlatformRxSocketStats,
10884+
) {
10885+
self.platform_rx_socket_stats += 1;
10886+
let meta = crate::event::snapshot::Fmt::to_snapshot(meta);
10887+
let event = crate::event::snapshot::Fmt::to_snapshot(event);
10888+
let out = format!("{meta:?} {event:?}");
10889+
self.output.push(out);
10890+
}
1078210891
fn on_platform_event_loop_wakeup(
1078310892
&mut self,
1078410893
meta: &api::EndpointMeta,
@@ -10879,6 +10988,7 @@ pub mod testing {
1087910988
pub platform_rx: u64,
1088010989
pub platform_rx_error: u64,
1088110990
pub platform_feature_configured: u64,
10991+
pub platform_rx_socket_stats: u64,
1088210992
pub platform_event_loop_wakeup: u64,
1088310993
pub platform_event_loop_sleep: u64,
1088410994
pub platform_event_loop_started: u64,
@@ -10965,6 +11075,7 @@ pub mod testing {
1096511075
platform_rx: 0,
1096611076
platform_rx_error: 0,
1096711077
platform_feature_configured: 0,
11078+
platform_rx_socket_stats: 0,
1096811079
platform_event_loop_wakeup: 0,
1096911080
platform_event_loop_sleep: 0,
1097011081
platform_event_loop_started: 0,
@@ -11069,6 +11180,13 @@ pub mod testing {
1106911180
let out = format!("{event:?}");
1107011181
self.output.push(out);
1107111182
}
11183+
fn on_platform_rx_socket_stats(&mut self, event: builder::PlatformRxSocketStats) {
11184+
self.platform_rx_socket_stats += 1;
11185+
let event = event.into_event();
11186+
let event = crate::event::snapshot::Fmt::to_snapshot(&event);
11187+
let out = format!("{event:?}");
11188+
self.output.push(out);
11189+
}
1107211190
fn on_platform_event_loop_wakeup(&mut self, event: builder::PlatformEventLoopWakeup) {
1107311191
self.platform_event_loop_wakeup += 1;
1107411192
let event = event.into_event();

quic/s2n-quic-core/src/event/generated/metrics/aggregate.rs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ mod id {
185185
PLATFORM_RX__ERRORS__DROPPED,
186186
PLATFORM_RX_ERROR,
187187
PLATFORM_FEATURE_CONFIGURED,
188+
PLATFORM_RX_SOCKET_STATS,
189+
PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL,
188190
PLATFORM_EVENT_LOOP_WAKEUP,
189191
PLATFORM_EVENT_LOOP_SLEEP,
190192
PLATFORM_EVENT_LOOP_SLEEP__PROCESSING_DURATION,
@@ -409,6 +411,9 @@ mod id {
409411
pub const PLATFORM_RX__ERRORS__DROPPED: usize = InfoId::PLATFORM_RX__ERRORS__DROPPED as usize;
410412
pub const PLATFORM_RX_ERROR: usize = InfoId::PLATFORM_RX_ERROR as usize;
411413
pub const PLATFORM_FEATURE_CONFIGURED: usize = InfoId::PLATFORM_FEATURE_CONFIGURED as usize;
414+
pub const PLATFORM_RX_SOCKET_STATS: usize = InfoId::PLATFORM_RX_SOCKET_STATS as usize;
415+
pub const PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL: usize =
416+
InfoId::PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL as usize;
412417
pub const PLATFORM_EVENT_LOOP_WAKEUP: usize = InfoId::PLATFORM_EVENT_LOOP_WAKEUP as usize;
413418
pub const PLATFORM_EVENT_LOOP_SLEEP: usize = InfoId::PLATFORM_EVENT_LOOP_SLEEP as usize;
414419
pub const PLATFORM_EVENT_LOOP_SLEEP__PROCESSING_DURATION: usize =
@@ -496,6 +501,8 @@ mod id {
496501
COUNTERS_PLATFORM_RX__ERRORS__DROPPED__TOTAL,
497502
COUNTERS_PLATFORM_RX_ERROR,
498503
COUNTERS_PLATFORM_FEATURE_CONFIGURED,
504+
COUNTERS_PLATFORM_RX_SOCKET_STATS,
505+
COUNTERS_PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL,
499506
COUNTERS_PLATFORM_EVENT_LOOP_WAKEUP,
500507
COUNTERS_PLATFORM_EVENT_LOOP_SLEEP,
501508
COUNTERS_PLATFORM_EVENT_LOOP_STARTED,
@@ -619,6 +626,10 @@ mod id {
619626
pub const COUNTERS_PLATFORM_RX_ERROR: usize = Counters::COUNTERS_PLATFORM_RX_ERROR as usize;
620627
pub const COUNTERS_PLATFORM_FEATURE_CONFIGURED: usize =
621628
Counters::COUNTERS_PLATFORM_FEATURE_CONFIGURED as usize;
629+
pub const COUNTERS_PLATFORM_RX_SOCKET_STATS: usize =
630+
Counters::COUNTERS_PLATFORM_RX_SOCKET_STATS as usize;
631+
pub const COUNTERS_PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL: usize =
632+
Counters::COUNTERS_PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL as usize;
622633
pub const COUNTERS_PLATFORM_EVENT_LOOP_WAKEUP: usize =
623634
Counters::COUNTERS_PLATFORM_EVENT_LOOP_WAKEUP as usize;
624635
pub const COUNTERS_PLATFORM_EVENT_LOOP_SLEEP: usize =
@@ -911,7 +922,7 @@ mod id {
911922
pub const NOMINAL_TIMERS_SLOW_START_EXITED__LATENCY: usize =
912923
NominalTimers::NOMINAL_TIMERS_SLOW_START_EXITED__LATENCY as usize;
913924
}
914-
static INFO: &[Info; 172usize] = &[
925+
static INFO: &[Info; 174usize] = &[
915926
info::Builder {
916927
id: id::APPLICATION_PROTOCOL_INFORMATION,
917928
name: Str::new("application_protocol_information\0"),
@@ -1920,6 +1931,18 @@ static INFO: &[Info; 172usize] = &[
19201931
units: Units::None,
19211932
}
19221933
.build(),
1934+
info::Builder {
1935+
id: id::PLATFORM_RX_SOCKET_STATS,
1936+
name: Str::new("platform_rx_socket_stats\0"),
1937+
units: Units::None,
1938+
}
1939+
.build(),
1940+
info::Builder {
1941+
id: id::PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL,
1942+
name: Str::new("platform_rx_socket_stats.packets.total\0"),
1943+
units: Units::None,
1944+
}
1945+
.build(),
19231946
info::Builder {
19241947
id: id::PLATFORM_EVENT_LOOP_WAKEUP,
19251948
name: Str::new("platform_event_loop_wakeup\0"),
@@ -1952,7 +1975,7 @@ pub struct ConnectionContext {
19521975
}
19531976
pub struct Subscriber<R: Registry> {
19541977
#[allow(dead_code)]
1955-
counters: Box<[R::Counter; 82usize]>,
1978+
counters: Box<[R::Counter; 84usize]>,
19561979
#[allow(dead_code)]
19571980
bool_counters: Box<[R::BoolCounter; 3usize]>,
19581981
#[allow(dead_code)]
@@ -1987,7 +2010,7 @@ impl<R: Registry> Subscriber<R> {
19872010
#[allow(unused_mut)]
19882011
#[inline]
19892012
pub fn new(registry: R) -> Self {
1990-
let mut counters = Vec::with_capacity(82usize);
2013+
let mut counters = Vec::with_capacity(84usize);
19912014
let mut bool_counters = Vec::with_capacity(3usize);
19922015
let mut nominal_counters = Vec::with_capacity(31usize);
19932016
let mut nominal_counter_offsets = Vec::with_capacity(31usize);
@@ -2077,6 +2100,9 @@ impl<R: Registry> Subscriber<R> {
20772100
counters.push(registry.register_counter(&INFO[id::PLATFORM_RX__ERRORS__DROPPED__TOTAL]));
20782101
counters.push(registry.register_counter(&INFO[id::PLATFORM_RX_ERROR]));
20792102
counters.push(registry.register_counter(&INFO[id::PLATFORM_FEATURE_CONFIGURED]));
2103+
counters.push(registry.register_counter(&INFO[id::PLATFORM_RX_SOCKET_STATS]));
2104+
counters
2105+
.push(registry.register_counter(&INFO[id::PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL]));
20802106
counters.push(registry.register_counter(&INFO[id::PLATFORM_EVENT_LOOP_WAKEUP]));
20812107
counters.push(registry.register_counter(&INFO[id::PLATFORM_EVENT_LOOP_SLEEP]));
20822108
counters.push(registry.register_counter(&INFO[id::PLATFORM_EVENT_LOOP_STARTED]));
@@ -2746,6 +2772,12 @@ impl<R: Registry> Subscriber<R> {
27462772
id::COUNTERS_PLATFORM_FEATURE_CONFIGURED => {
27472773
(&INFO[id::PLATFORM_FEATURE_CONFIGURED], entry)
27482774
}
2775+
id::COUNTERS_PLATFORM_RX_SOCKET_STATS => {
2776+
(&INFO[id::PLATFORM_RX_SOCKET_STATS], entry)
2777+
}
2778+
id::COUNTERS_PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL => {
2779+
(&INFO[id::PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL], entry)
2780+
}
27492781
id::COUNTERS_PLATFORM_EVENT_LOOP_WAKEUP => {
27502782
(&INFO[id::PLATFORM_EVENT_LOOP_WAKEUP], entry)
27512783
}
@@ -4817,6 +4849,27 @@ impl<R: Registry> event::Subscriber for Subscriber<R> {
48174849
let _ = meta;
48184850
}
48194851
#[inline]
4852+
fn on_platform_rx_socket_stats(
4853+
&mut self,
4854+
meta: &api::EndpointMeta,
4855+
event: &api::PlatformRxSocketStats,
4856+
) {
4857+
#[allow(unused_imports)]
4858+
use api::*;
4859+
self.count(
4860+
id::PLATFORM_RX_SOCKET_STATS,
4861+
id::COUNTERS_PLATFORM_RX_SOCKET_STATS,
4862+
1usize,
4863+
);
4864+
self.count(
4865+
id::PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL,
4866+
id::COUNTERS_PLATFORM_RX_SOCKET_STATS__PACKETS__TOTAL,
4867+
event.count,
4868+
);
4869+
let _ = event;
4870+
let _ = meta;
4871+
}
4872+
#[inline]
48204873
fn on_platform_event_loop_wakeup(
48214874
&mut self,
48224875
meta: &api::EndpointMeta,

0 commit comments

Comments
 (0)