nx_linkqual.nx
buildroot/runtime/nx_linkqual.nx
about
nx_linkqual.nx -- ONE sovereign real-time LINK-QUALITY substrate that
improves GAME MULTIPLAYER, VIDEO ROOMS, and STREAMING from a single
per-flow metrics core. Integer-only (no float), pure/deterministic
(fed timestamped sample events -> KAT-able offline), raw-syscall-only
(imports only nx_syscalls), zero external/licensed deps.
Research-grounded (workflow wf_5c50a76d) in the canonical RFCs, all
re-implemented from the SPEC (concepts, not code):
- RTT smoothing: RFC 6298 / Jacobson-Karels (SRTT*8, RTTVAR*4, RTO).
- Interarrival jitter: RFC 3550 A.8 (J += (|D|-J)/16, pre-scaled *16).
- Loss fraction: RFC 3550 A.3 (expected-vs-received, Q16.16 fraction).
- Throughput EWMA (BBR-style delivery-rate, gain 1/8).
- Latency quantiles: HDR-style power-of-two magnitude buckets + a
first-class max (Tene: never discard the tail -- that IS the signal).
SUPERSEDES nx_bandwidth_meter for real-time use (adds jitter, quantiles,
proper RTTVAR/RTO it lacks); pairs with nx_adaptive_bitrate for tiers.
Consumers (the products): lq_game_advise (rollback input-delay frames),
lq_jitter_buffer_ms (video-room NetEQ-style target), lq_bitrate_decision
(streaming ABR up/hold/down), lq_score + lq_verdict_band (easy-for-
anyone Excellent/Good/Fair/Poor + one number).
Constants are bootstrap defaults destined for svc-config (CLAUDE.md 11).
license_tier: ORIGINAL
dependencies 1 imports · 4 importers
imports: nx_syscalls.nx
imported by: nx_linkqual_bench.nxnx_linkqual_cycles.nxnx_linkqual_test.nxnx_mediapath.nx
structs
| 40 | struct LinkFlow |
| 72 | struct GameAdvice { delay_frames: i64, score: i64, verdict: i64 } |
consts
| 27 | const LQ_MAGIC_32768: i64 = 32768 |
| 28 | const LQ_MAGIC_65536: i64 = 65536 |
| 30 | const LQ_NBUCKETS: i64 = 32 |
| 31 | const LQ_SRTT_SH: i64 = 3 // SRTT stored *8 |
| 32 | const LQ_RTTVAR_SH: i64 = 2 // RTTVAR stored *4 |
| 33 | const LQ_JIT_SH: i64 = 4 // jitter stored *16 (RFC 3550 A.8) |
| 34 | const LQ_RATE_SH: i64 = 3 // throughput EWMA gain 1/8 |
| 35 | const LQ_Q16: i64 = 16 // Q16.16 fixed-point shift (loss fraction) |
| 36 | const LQ_RTO_MIN_MS: i64 = 200 // (RFC6298 says 1000; 200 fits real-time UDP) |
| 37 | const LQ_RTO_MAX_MS: i64 = 60000 |
| 58 | const LQ_FLOW_HDR_BYTES: i64 = 128 |
| 59 | const LQ_FLOW_BYTES: i64 = 384 |
| 62 | const LQ_EXCELLENT: i64 = 0 |
| 63 | const LQ_GOOD: i64 = 1 |
| 64 | const LQ_FAIR: i64 = 2 |
| 65 | const LQ_POOR: i64 = 3 |
| 68 | const LQ_PROD_GAME: i64 = 0 |
| 69 | const LQ_PROD_VIDEO: i64 = 1 |
| 70 | const LQ_PROD_STREAM: i64 = 2 |
| 73 | const LQ_GAME_ADVICE_BYTES: i64 = 24 |
functions
| 75 | func lq_flow_new() -> *LinkFlow |
| 83 | func lq_on_rtt(f: *LinkFlow, r_ms: i64) -> i64 |
| 103 | func lq_srtt_ms(f: *LinkFlow) -> i64 { return f.srtt_x8 >> LQ_SRTT_SH } |
| 104 | func lq_rttvar_ms(f: *LinkFlow) -> i64 { return f.rttvar_x4 >> LQ_RTTVAR_SH } called by 1: main |
| 107 | func lq_on_arrival(f: *LinkFlow, send_ts: i64, recv_ts: i64) -> i64 |
| 124 | func lq_jitter_ms(f: *LinkFlow) -> i64 { return f.jitter_x16 >> LQ_JIT_SH } |
| 127 | func lq_on_seq(f: *LinkFlow, seq: i64) -> i64 |
| 134 | func lq_loss_tick(f: *LinkFlow) -> i64 called by 1: main |
| 148 | func lq_loss_pct(f: *LinkFlow) -> i64 { return (f.loss_frac_q16 * 100 + LQ_MAGIC_32768) >> LQ_Q16 } |
| 151 | func lq_on_delivery(f: *LinkFlow, bytes: i64, interval_ms: i64) -> i64 |
| 160 | func lq_buckets(f: *LinkFlow) -> *i64 { return ((f as i64) + LQ_FLOW_HDR_BYTES) as *i64 } |
| 164 | func lq_bucket_of(lat_ms: i64) -> i64 called by 1: lq_record_latency |
| 173 | func lq_record_latency(f: *LinkFlow, lat_ms: i64) -> i64 |
| 182 | func lq_quantile_ms(f: *LinkFlow, p: i64) -> i64 |
| 198 | func lq_score(f: *LinkFlow) -> i64 called by 7: lq_game_adviselq_rendermainmp_select_bestmp_decidemain+1 calls 3: lq_srtt_mslq_jitter_mslq_loss_pct |
| 215 | func lq_verdict_band(score: i64) -> i64 |
| 225 | func lq_game_advise(f: *LinkFlow, fps: i64, out: *GameAdvice) -> i64 |
| 241 | func lq_jitter_buffer_ms(f: *LinkFlow) -> i64 |
| 254 | func lq_bitrate_decision(f: *LinkFlow) -> i64 |
| 265 | func lq_band_word(b: i64) -> i64 |
| 272 | func lq_dec(n: i64) -> i64 |
| 283 | func lq_render(f: *LinkFlow, product: i64) -> i64 |