nx_bandwidth_meter.nx
buildroot/runtime/nx_bandwidth_meter.nx
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
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
structs
| none |
consts
| 37 | const NX_MAGIC_9500: i64 = 9500 |
| 38 | const NX_MAGIC_10500: i64 = 10500 |
| 39 | const NX_MAGIC_100000: i64 = 100000 |
| 41 | const NX_BM_Q: i64 = 16384 |
| 44 | const NX_BM_EWMA_ALPHA_Q14: i64 = 2048 |
| 46 | const NX_BM_HDR_BYTES_PER_SEC_Q14: nx_int = 0 |
| 47 | const NX_BM_HDR_RTT_MS_Q14: nx_int = 1 |
| 48 | const NX_BM_HDR_LOSS_RATE_Q14: nx_int = 2 |
| 49 | const NX_BM_HDR_TOTAL_BYTES: nx_int = 3 |
| 50 | const NX_BM_HDR_TOTAL_SAMPLES: nx_int = 4 |
| 51 | const NX_BM_HDR_TOTAL_LOSSES: nx_int = 5 |
| 52 | const NX_BM_HDR_LAST_OBS_TICK: nx_int = 6 |
| 53 | const NX_BM_HDR_SIZE: nx_int = 7 |
functions
| 57 | func nx_bandwidth_meter_new() -> *i64 |
| 70 | func _bm_ewma(old_q14: i64, sample_q14: i64) -> i64 |
| 79 | func nx_bandwidth_meter_observe_bytes( |
| 95 | func nx_bandwidth_meter_observe_rtt_ms(m: *i64, rtt_ms: nx_int) -> nx_int |
| 111 | func nx_bandwidth_meter_observe_loss( |
| 125 | func nx_bandwidth_meter_bytes_per_sec(m: *i64) -> i64 |
| 130 | func nx_bandwidth_meter_rtt_ms(m: *i64) -> i64 |
| 135 | func nx_bandwidth_meter_loss_rate_q14(m: *i64) -> i64 |
| 140 | func nx_bandwidth_meter_total_bytes(m: *i64) -> i64 called by 1: main |
| 147 | func main() -> i64 |