code wiki / (root) / nx_linkqual.nx

nx_linkqual.nx

buildroot/runtime/nx_linkqual.nx

12417 B305 linesdepth 2pulls 2 transitivereach 7 importersview sourcekind librarytopic linkqual
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_linkqual.nx nx_linkqual_bench.nx nx_linkqual_cycles.nx nx_linkqual_test.nx nx_mediapath.nx

imports: nx_syscalls.nx

imported by: nx_linkqual_bench.nxnx_linkqual_cycles.nxnx_linkqual_test.nxnx_mediapath.nx

structs

40struct LinkFlow
72struct GameAdvice { delay_frames: i64, score: i64, verdict: i64 }

consts

27const LQ_MAGIC_32768: i64 = 32768
28const LQ_MAGIC_65536: i64 = 65536
30const LQ_NBUCKETS: i64 = 32
31const LQ_SRTT_SH: i64 = 3 // SRTT stored *8
32const LQ_RTTVAR_SH: i64 = 2 // RTTVAR stored *4
33const LQ_JIT_SH: i64 = 4 // jitter stored *16 (RFC 3550 A.8)
34const LQ_RATE_SH: i64 = 3 // throughput EWMA gain 1/8
35const LQ_Q16: i64 = 16 // Q16.16 fixed-point shift (loss fraction)
36const LQ_RTO_MIN_MS: i64 = 200 // (RFC6298 says 1000; 200 fits real-time UDP)
37const LQ_RTO_MAX_MS: i64 = 60000
58const LQ_FLOW_HDR_BYTES: i64 = 128
59const LQ_FLOW_BYTES: i64 = 384
62const LQ_EXCELLENT: i64 = 0
63const LQ_GOOD: i64 = 1
64const LQ_FAIR: i64 = 2
65const LQ_POOR: i64 = 3
68const LQ_PROD_GAME: i64 = 0
69const LQ_PROD_VIDEO: i64 = 1
70const LQ_PROD_STREAM: i64 = 2
73const LQ_GAME_ADVICE_BYTES: i64 = 24

functions

75func lq_flow_new() -> *LinkFlow
83func lq_on_rtt(f: *LinkFlow, r_ms: i64) -> i64
called by 3: mainmainmain
103func lq_srtt_ms(f: *LinkFlow) -> i64 { return f.srtt_x8 >> LQ_SRTT_SH }
104func lq_rttvar_ms(f: *LinkFlow) -> i64 { return f.rttvar_x4 >> LQ_RTTVAR_SH }
called by 1: main
107func lq_on_arrival(f: *LinkFlow, send_ts: i64, recv_ts: i64) -> i64
called by 3: mainmainmain
124func lq_jitter_ms(f: *LinkFlow) -> i64 { return f.jitter_x16 >> LQ_JIT_SH }
127func lq_on_seq(f: *LinkFlow, seq: i64) -> i64
called by 3: mainmainmain
134func lq_loss_tick(f: *LinkFlow) -> i64
called by 1: main
148func lq_loss_pct(f: *LinkFlow) -> i64 { return (f.loss_frac_q16 * 100 + LQ_MAGIC_32768) >> LQ_Q16 }
151func lq_on_delivery(f: *LinkFlow, bytes: i64, interval_ms: i64) -> i64
160func lq_buckets(f: *LinkFlow) -> *i64 { return ((f as i64) + LQ_FLOW_HDR_BYTES) as *i64 }
164func lq_bucket_of(lat_ms: i64) -> i64
called by 1: lq_record_latency
173func lq_record_latency(f: *LinkFlow, lat_ms: i64) -> i64
called by 3: mainmainmain calls 2: lq_bucketslq_bucket_of
182func lq_quantile_ms(f: *LinkFlow, p: i64) -> i64
called by 2: lq_bitrate_decisionmain calls 1: lq_buckets
198func lq_score(f: *LinkFlow) -> i64
215func lq_verdict_band(score: i64) -> i64
225func lq_game_advise(f: *LinkFlow, fps: i64, out: *GameAdvice) -> i64
241func lq_jitter_buffer_ms(f: *LinkFlow) -> i64
254func lq_bitrate_decision(f: *LinkFlow) -> i64
265func lq_band_word(b: i64) -> i64
called by 2: lq_rendermp_render calls 1: sys_write
272func lq_dec(n: i64) -> i64
283func lq_render(f: *LinkFlow, product: i64) -> i64