Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/bin/relay/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ Pinning is off by default because every relay pins its workers to the same
first cores, so two relays on one host, or one limited to fewer CPUs than the
host has, would crowd onto them. Turn it on for a host the relay has to itself.

`io_uring` additionally needs Linux 6.12+; it
shares the same reloadable TLS identity and serves every configured version
like the shared runtime. A setting the host cannot deliver refuses to
`io_uring` additionally needs Linux 6.12+ on a 64-bit x86, ARM, RISC-V,
LoongArch, or POWER CPU; it shares the same reloadable TLS identity and serves
every configured version like the shared runtime. A setting the host cannot deliver refuses to
start rather than being ignored. Linux 6.14 up to the 7.3 fix (backported to
stable kernels) charges io\_uring rings to `RLIMIT_MEMLOCK`: if io\_uring workers
fail to start naming it, raise it (`LimitMEMLOCK=` under systemd).
Expand Down
39 changes: 36 additions & 3 deletions nix/Cargo.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions rs/moq-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,18 @@ tracing = { workspace = true }
url = { workspace = true, features = ["serde"] }
usage-rs = { workspace = true, features = ["completions", "config"] }

# Serves QUIC from io_uring workers (`--runtime-io-uring`), on the architectures
# io-uring ships prebuilt kernel bindings for; build.rs sets `cfg(uring)` to match.
[target.'cfg(all(target_os = "linux", any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "riscv64", target_arch = "loongarch64", target_arch = "powerpc64")))'.dependencies]
moq-uring = { workspace = true, features = ["quic"] }
# The WebTransport CONNECT response the io_uring listener answers with.
web-transport-proto = { workspace = true }

[target.'cfg(target_os = "linux")'.dependencies]
# `geteuid`, so a handoff only trusts a relay of the same user.
libc = { workspace = true }
# The reuseport group and descriptor passing a handoff carries the sockets with.
moq-sock = { workspace = true }
# Serves QUIC from io_uring workers (`--runtime-io-uring`).
moq-uring = { workspace = true, features = ["quic"] }
# The WebTransport CONNECT response the io_uring listener answers with.
web-transport-proto = { workspace = true }

[target.'cfg(unix)'.dependencies]
sd-notify = { workspace = true }
Expand Down Expand Up @@ -130,9 +133,11 @@ tracing-subscriber = { workspace = true }
web-transport-proto = { workspace = true }
workspace-hack = { path = "../workspace-hack" }

[target.'cfg(target_os = "linux")'.dev-dependencies]
[target.'cfg(all(target_os = "linux", any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "riscv64", target_arch = "loongarch64", target_arch = "powerpc64")))'.dev-dependencies]
# Workers built inside a runtime with a manual clock installed run on that clock.
moq-uring = { workspace = true, features = ["_manual"] }

[target.'cfg(target_os = "linux")'.dev-dependencies]
# Which sockets the process still holds, so the embed tests can prove a stopped
# relay closed its own without rebinding a port another test could take.
socket2 = { workspace = true, features = ["all"] }
Expand Down
15 changes: 15 additions & 0 deletions rs/moq-relay/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Sets `cfg(uring)` where the io_uring workers build: Linux on the architectures
//! io-uring ships prebuilt kernel bindings for. Keep the list in step with the
//! `moq-uring` dependency targets in Cargo.toml.
fn main() {
println!("cargo::rustc-check-cfg=cfg(uring)");
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
let bindings = matches!(
arch.as_str(),
"x86_64" | "aarch64" | "riscv64" | "loongarch64" | "powerpc64"
);
if os == "linux" && bindings {
println!("cargo::rustc-cfg=uring");
}
}
2 changes: 1 addition & 1 deletion rs/moq-relay/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ pub fn request_for(auth: &Auth, request: &moq_tokio::server::Request) -> Request
}

/// Build an auth request from the path, credential, role, and implementation carried in SETUP.
#[cfg(any(feature = "test-support", target_os = "linux"))]
#[cfg(any(feature = "test-support", uring))]
pub(crate) fn request_for_setup(
auth: &Auth,
setup: &moq_net::server::Handshake,
Expand Down
7 changes: 5 additions & 2 deletions rs/moq-relay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,11 @@ impl Config {
!io_uring || self.listen.bind.is_some(),
"runtime.io_uring requires listen.bind"
);
#[cfg(not(target_os = "linux"))]
anyhow::ensure!(!io_uring, "runtime.io_uring is Linux-only");
#[cfg(not(uring))]
anyhow::ensure!(
!io_uring,
"runtime.io_uring needs Linux on x86_64, aarch64, riscv64, loongarch64, or powerpc64"
);
// Refused rather than ignored: a group is the whole point of the setting, and
// silently serving from the shared runtime instead would look like it worked.
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-relay/src/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait Incoming: Sealed {}

impl Incoming for moq_tokio::server::Request {}

#[cfg(target_os = "linux")]
#[cfg(uring)]
impl Incoming for crate::uring::Request {}

#[cfg(feature = "test-support")]
Expand Down
26 changes: 13 additions & 13 deletions rs/moq-relay/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ use prometheus_client::{
/// list is always empty there and the renderer skips itself, rather than
/// `cfg`-ing the two fields, the two struct literals that fill them, and the
/// renderer's signature separately.
#[cfg(target_os = "linux")]
#[cfg(uring)]
type UringWorker = moq_uring::metrics::Metrics;

/// One io_uring worker's counters. See the io_uring build's alias.
#[cfg(not(target_os = "linux"))]
#[cfg(not(uring))]
type UringWorker = std::convert::Infallible;

/// Configuration for the internal (ops) listener.
Expand Down Expand Up @@ -229,7 +229,7 @@ impl Internal {
/// Register them before the threads start, so a worker that never came up
/// (or has died) still has a series that has stopped moving rather than no
/// series at all.
#[cfg(target_os = "linux")]
#[cfg(uring)]
pub(crate) fn with_uring(mut self, workers: impl IntoIterator<Item = UringWorker>) -> Self {
self.uring.extend(workers);
self
Expand Down Expand Up @@ -883,7 +883,7 @@ fn encode_accepts(encoder: &mut DescriptorEncoder, listeners: &[moq_tokio::accep
/// exists for. The pool gauges are the buffer space each worker has allocated,
/// which stays at its high-water mark after a burst; only the pages datagrams
/// have touched count toward RSS.
#[cfg(target_os = "linux")]
#[cfg(uring)]
fn encode_uring(encoder: &mut DescriptorEncoder, workers: &[UringWorker]) -> std::fmt::Result {
use moq_uring::metrics::Snapshot;

Expand Down Expand Up @@ -1046,17 +1046,17 @@ fn encode_uring(encoder: &mut DescriptorEncoder, workers: &[UringWorker]) -> std

/// Off the io_uring path there are no workers to describe, and [`UringWorker`]
/// is uninhabited, so the list handed here is always empty.
#[cfg(not(target_os = "linux"))]
#[cfg(not(uring))]
fn encode_uring(_encoder: &mut DescriptorEncoder, _workers: &[UringWorker]) -> std::fmt::Result {
Ok(())
}

/// An io_uring worker's histogram, whose cumulative buckets the encoder takes as
/// per-bucket counts.
#[cfg(target_os = "linux")]
#[cfg(uring)]
struct Distribution(moq_uring::metrics::Histogram);

#[cfg(target_os = "linux")]
#[cfg(uring)]
impl EncodeMetric for Distribution {
fn encode(&self, mut encoder: prometheus_client::encoding::MetricEncoder) -> std::fmt::Result {
let mut below = 0;
Expand Down Expand Up @@ -1409,7 +1409,7 @@ mod tests {
/// yet is empty rather than zero, so an alert on a worker whose receive pool
/// has started running dry is unwritable until it has already happened. A
/// worker that never started has to publish stuck zeros, not nothing.
#[cfg(target_os = "linux")]
#[cfg(uring)]
#[test]
fn uring_metrics_list_every_worker_from_zero() {
let workers = vec![
Expand Down Expand Up @@ -1490,7 +1490,7 @@ mod tests {
}

/// A worker's cumulative buckets come out cumulative again, not summed twice.
#[cfg(target_os = "linux")]
#[cfg(uring)]
#[test]
fn uring_histograms_keep_cumulative_buckets() {
let histogram = moq_uring::metrics::Histogram {
Expand Down Expand Up @@ -2022,9 +2022,9 @@ mod tests {
refusals: Some(refusals),
sessions: crate::session::Registry::new(),
listeners: vec![moq_tokio::accept::Health::new("tcp")],
#[cfg(target_os = "linux")]
#[cfg(uring)]
uring: vec![moq_uring::metrics::Metrics::default()],
#[cfg(not(target_os = "linux"))]
#[cfg(not(uring))]
uring: Vec::new(),
demux: Some(moq_tokio::quic::demux::Counters::default()),
shutdown: Some(shutdown),
Expand All @@ -2042,7 +2042,7 @@ mod tests {
actual.remove(panics);

let mut expected: Vec<String> = EXPECTED_SERIES.trim().lines().map(str::to_string).collect();
#[cfg(target_os = "linux")]
#[cfg(uring)]
expected.extend(EXPECTED_URING_SERIES.trim().lines().map(str::to_string));
expected.extend(EXPECTED_DEMUX_SERIES.trim().lines().map(str::to_string));
expected.sort();
Expand Down Expand Up @@ -2135,7 +2135,7 @@ gauge moq_relay_sessions_connected{state="active",tier="edge"} 0
gauge moq_relay_sessions_connected{state="idle",tier="edge"} 1
"#;

#[cfg(target_os = "linux")]
#[cfg(uring)]
const EXPECTED_URING_SERIES: &str = r#"
# TYPE moq_relay_uring_completions_total counter
# TYPE moq_relay_uring_cqes_per_enter histogram
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod sim;
pub mod stats;
#[cfg(feature = "test-support")]
mod test_support;
#[cfg(target_os = "linux")]
#[cfg(uring)]
pub(crate) mod uring;
/// The HTTP/HTTPS server: health, certificate fingerprint, announcements, fetch, and WebSocket sessions.
pub mod web;
Expand Down
Loading