code wiki / (root) / nx_bandwidth_meter.nx

nx_bandwidth_meter.nx

buildroot/runtime/nx_bandwidth_meter.nx

7607 B205 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_bandwidth_meter.nx -- per-session bandwidth + RTT observation. Tracks the realized over-the-wire bytes/sec and RTT of a multiplayer session so upstream code (nx_adaptive_bitrate) can pick a quality tier matched to the player's actual link. Bytes accumulator: EWMA (exponentially-weighted moving average) over recent send + receive events. EWMA alpha = 1/8 in Q14 (~0.125) by default which gives ~1-second smoothing at 60 Hz updates. RTT accumulator: same EWMA pattern over round-trip-time samples. Caller provides RTT samples in milliseconds via observe_rtt_ms(). Loss accumulator: caller increments observe_loss() each time a packet/sample is detected dropped; the meter tracks loss-rate. All math in Q14 fixed-point per substrate convention. Source references (open): - RFC 6298 (TCP RTT calculation, srtt/rttvar) - RFC 8312 (CUBIC congestion control RTT/loss observations) - BBR paper (Cardwell et al 2016) -- bottleneck bandwidth estimation Composes with nx_adaptive_bitrate for the verdict. genealogy_id: rfc6298_tcp_rtt + bbr_bottleneck_bw + ewma_smoothing lineage_id: per_session_link_observation

dependencies 2 imports · 1 importers

nx_syscalls.nx nx_tier.nx nx_bandwidth_meter.nx nx_adaptive_bitrate.nx

imports: nx_syscalls.nxnx_tier.nx

imported by: nx_adaptive_bitrate.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_bandwidth_meter_new sys_mmap nx_bandwidth_meter_bytes_p nx_bandwidth_meter_rtt_ms nx_bandwidth_meter_observe _bm_ewma nx_bandwidth_meter_observe _bm_ewma ↻ nx_bandwidth_meter_observe _bm_ewma ↻ nx_bandwidth_meter_loss_ra nx_bandwidth_meter_total_b

structs

none

consts

37const NX_MAGIC_9500: i64 = 9500
38const NX_MAGIC_10500: i64 = 10500
39const NX_MAGIC_100000: i64 = 100000
41const NX_BM_Q: i64 = 16384
44const NX_BM_EWMA_ALPHA_Q14: i64 = 2048
46const NX_BM_HDR_BYTES_PER_SEC_Q14: nx_int = 0
47const NX_BM_HDR_RTT_MS_Q14: nx_int = 1
48const NX_BM_HDR_LOSS_RATE_Q14: nx_int = 2
49const NX_BM_HDR_TOTAL_BYTES: nx_int = 3
50const NX_BM_HDR_TOTAL_SAMPLES: nx_int = 4
51const NX_BM_HDR_TOTAL_LOSSES: nx_int = 5
52const NX_BM_HDR_LAST_OBS_TICK: nx_int = 6
53const NX_BM_HDR_SIZE: nx_int = 7

functions

57func nx_bandwidth_meter_new() -> *i64
called by 2: mainmain calls 1: sys_mmap
70func _bm_ewma(old_q14: i64, sample_q14: i64) -> i64
79func nx_bandwidth_meter_observe_bytes(
called by 2: mainmain calls 1: _bm_ewma
95func nx_bandwidth_meter_observe_rtt_ms(m: *i64, rtt_ms: nx_int) -> nx_int
called by 2: mainmain calls 1: _bm_ewma
111func nx_bandwidth_meter_observe_loss(
called by 2: mainmain calls 1: _bm_ewma
125func nx_bandwidth_meter_bytes_per_sec(m: *i64) -> i64
130func nx_bandwidth_meter_rtt_ms(m: *i64) -> i64
135func nx_bandwidth_meter_loss_rate_q14(m: *i64) -> i64
140func nx_bandwidth_meter_total_bytes(m: *i64) -> i64
called by 1: main
147func main() -> i64