diff --git a/docs/cell-m6.md b/docs/cell-m6.md index 7e68f515..d1edb346 100644 --- a/docs/cell-m6.md +++ b/docs/cell-m6.md @@ -1401,9 +1401,9 @@ backlog, so the first fresh PDU waited. Now a DL frame takes the not-yet-offered PDUs first (`pick_dl_pdus`). Only the offered PDUs that the fresh one would push out of the UE's reorder window go before it (the answers may have been lost: the offered mark is not the UE's top), so a -lost answer's PDU is still a late copy, not a confirmed gap. The queue -after a switch normally spans no more than that window, and the fresh PDU -leads. +lost answer's PDU is still a late copy, not a confirmed gap. (The queue +after a switch spans ~41 sns on the rig; those out-of-window PDUs ride the +fresh one's frame — see *The DL cadence at the switch*.) Uplinks lost in the whole window, switch superframe included: 0 in 7 of the 8 visit runs, 1 in one. @@ -1414,11 +1414,73 @@ the 6 visit runs, 225 in 2. In all four 123 ms runs the first frame after the switch carried the next fresh PDU; in both 225 ms runs the target's queue held no fresh PDU yet when that frame was built (31 PDUs, all offered — the CU sends one per 100 ms), and the next frame led with it. -The rest of the 225 ms is PDU cadence, not queue order. Over all the runs -on this branch's builds, 18 of 24 visit runs were at 122–123 ms. The -target's queue spans ~39 sns behind the fresh PDU, so ~7 offered PDUs that -the fresh one would push out of the UE's window go before it, in the same -8-PDU frame. No UL was lost before the switch in any visit run. +Not queue order — but not the PDU cadence either, as first read: see +*The DL cadence at the switch* below. Over all the runs on this branch's +builds, 18 of 24 visit runs were at 122–123 ms. No UL was lost before the +switch in any visit run. + +### The DL cadence at the switch + +The remaining 225 ms switch gaps (about 1 run in 4) had three causes, each +found with timestamps on the target DU's clock (`cell.dl.pdu_in`: when +each PDU reached a DAPS target's queue; `cell.dl` `pick_ms`; the answers' +`t_ms`): + +- **The DU took a frame's PDUs a superframe early.** The DL loop built the + frame for superframe N right after sending N-1's, then slept to its slot: + a PDU arriving in those ~100 ms waited for N+1. Now the frame is picked + and built `CELL_DL_PICK_LEAD_US` (3 ms) before its slot. DL send lateness + unchanged (p50 3 µs, p99 8 µs). +- **The CU sent its PDUs up to 50 ms late.** Its loop polled with a fixed + 50 ms timeout and sent a due PDU only when something woke it, so PDUs + reached the DUs unevenly (one >119 ms after the previous). The poll now + also wakes for the next PDU: spacing at the target 99–102 ms in every run. +- **The fresh PDU did not fit the frame.** At the switch the target's queue + holds the command's backlog (16) and every PDU since (~25): ~41 sns. Every + queued PDU more than the reorder window behind the fresh one goes first + (review fix above) — up to 8 of them, the whole 8-PDU frame, and the + fresh one waited a superframe (seen directly: it had arrived 51 ms before + the pick). A DL frame now carries up to 32 PDU sns (fixed length: +96 + bytes, ~32 µs at 24 Mb/s), at least the queue's (64) out-of-window + maximum plus the fresh one (a `static_assert`). The DU's queue takes any + newer sn, so with gaps every slot could be out-of-window: `pick_dl_pdus` + keeps the first fresh PDU's place in any case (from the review). +- **A frame ready too late is not aired.** The pick and build now run inside + the lead; a frame whose submission would start more than + `CELL_DL_GUARD_US` (500 µs) into its slot is skipped (`cell.dl.late_skip`), + its PDUs and HARQ attempt given back. DL send lateness over the runs: + p99.9 12–13 µs before and after; single outliers of 319 µs (before this + change) and 264–373 µs (after), cause not established. +- **Found by that skip: a DU served its UEs in grant order, not slot + order.** With two UEs (a handed-over UE at position 1, the DU's own at + position 2; later 2 and 3), the UE whose slot comes first was served + after the other's slot. Every one of its frames went out ~4.1 ms late, + inside the other UE's slot (404 of 404 in a `m6_daps_dl` crossing run on + the code before this change). With the skip they were dropped (440 per + run), and that crossing lost 5–6 uplinks of the arriving UE where it had + lost 0–1; why dropped DL frames cost uplinks was not established. The DU + now serves in DL-slot order. On this build the `m6_daps_dl` crossing (DAPS, 2 runs) lost 0 + uplinks and 0 DL PDUs, and its longest DL silence was 0.39 and 1.03 s, + where the table above had 3.6–4.3 s. Those earlier runs aired every frame + to the arriving UE ~4 ms late; that this was the silence is likely, not + established. The 1.03 s ends before the command (the source fading before + the A3 fires); the 0.39 s is at a switch. + +**Rig result** (testrig `scripts/m6_daps_xch.sh`): 4 runs per case (cells 149 → 157). + +| case | UL lost before the switch | DL gap across the switch (ms) | first target frame | +|---|---|---|---| +| source dies, visits | 0 (all 4) | 122, 122, 123, 123 | fresh PDU in all 4 | +| source dies, no visits | 12–15 | 1395–1703 | — | +| source alive, visits | 0 (all 4) | 122, 123, 123, 166 | fresh PDU in all 4 | + +The 166 ms run: the source's own DL frame had delivered the newest PDU +43 ms before the last answer (which then had nothing new), so the gap +counts from there; the target's first frame carried the next one. Each +first target frame carried 32 PDUs. Before these fixes 6 of 24 visit runs +were at 225 ms. The longest DL silence elsewhere in a run reached 307 ms +in two runs, not at the switch; its cause was not established here. Regression passes: measgap, +three_ho, crossing3, handover, daps, daps_dl, crossing. ## Replay of a signed neighbour list diff --git a/examples/cell/cell.h b/examples/cell/cell.h index d68a4964..89ecfc2d 100644 --- a/examples/cell/cell.h +++ b/examples/cell/cell.h @@ -321,7 +321,12 @@ struct DlHarq { * used, the rest zero: a fixed length, so the DL slot budget is one size). * A HARQ retransmission carries the same ones. Under the tag: a forged sn * cannot make the UE drop a real PDU as a duplicate. */ -constexpr size_t kDlMaxPdus = 8; +/* 32: after a DAPS switch every queued PDU more than DlStreamRx's reorder + * window (32) behind the fresh one goes in the same frame as it (see + * pick_dl_pdus) — at most kDlQueueMax - 32 - 1 of them; with 8 the target's + * backlog (~41 sns at the switch on the rig) could fill a frame and hold the + * fresh PDU a superframe. */ +constexpr size_t kDlMaxPdus = 32; constexpr size_t kDlTaggedLen = 2 + 1 + 2 + 8 + 4 + 4 + 1 + 1 + 8 + 1 + 4 * kDlMaxPdus; constexpr size_t kDlBodyLen = kDlTaggedLen + kCellTagLen; @@ -402,8 +407,10 @@ inline std::optional parse_dl_frame(const uint8_t *p, size_t len, uint1 // fresh sn f moves that top to f and confirms as missing every sn more than // `window` behind it (DlStreamRx's reorder window). Every queued offered sn p // with f - p > window therefore goes before f, oldest first: a lost answer's -// PDU arrives as a late copy, never a confirmed gap. Normally (the queue -// spans at most `window` sns behind f) that is none, and f leads. +// PDU arrives as a late copy, never a confirmed gap — as many as fit with f +// in the frame: f always rides it (a frame's PDUs arrive together, so the +// order inside it does not matter). With a contiguous queue (the CU's sns) +// of at most kDlQueueMax they all fit a kDlMaxPdus frame. // Without an offered mark: plain queue order. inline std::vector pick_dl_pdus(std::deque &q, const std::optional &offered, size_t max, uint32_t window = 32) { @@ -411,6 +418,7 @@ inline std::vector pick_dl_pdus(std::deque &q, const std::op for (uint32_t sn : q) (offered && !devourer::cell::seq_lt(*offered, sn) ? old : fresh).push_back(sn); std::vector out; + bool fresh_in = false; /* the frame carries a fresh PDU */ while (out.size() < max && (!fresh.empty() || !old.empty())) { auto urgent = old.end(); if (!fresh.empty()) @@ -419,12 +427,15 @@ inline std::vector pick_dl_pdus(std::deque &q, const std::op urgent = it; break; } - if (urgent != old.end()) { + /* ... but never the first fresh one's place: with gaps in the queue (it + * takes any newer sn) every slot could be urgent. */ + if (urgent != old.end() && (fresh_in || out.size() + 1 < max)) { out.push_back(*urgent); old.erase(urgent); } else if (!fresh.empty()) { out.push_back(fresh.front()); fresh.pop_front(); + fresh_in = true; } else { out.push_back(old.front()); old.pop_front(); diff --git a/examples/cell/main.cpp b/examples/cell/main.cpp index a28430c1..a290df07 100644 --- a/examples/cell/main.cpp +++ b/examples/cell/main.cpp @@ -625,6 +625,11 @@ int run_du(IRadio *dev, const Cfg &c) { const double ta_gain = envf("CELL_TA_GAIN", 0.5, 0.0, 1.0); const int ta_every_s = static_cast(envl("CELL_TA_EVERY_S", 2, 1, 60)); const size_t pad = static_cast(envl("CELL_DL_PAD", 64, 0, 1400)); + /* How long before its slot a DL frame takes its PDUs and is built. */ + const int64_t dl_pick_lead_us = envl("CELL_DL_PICK_LEAD_US", 3000, 500, 100000); + /* A frame that would start later than this into its slot is not sent (the + * slot budget's guard, as du_budget_ok counts it). */ + const int64_t dl_guard_us = envl("CELL_DL_GUARD_US", 500, 0, 100000); const bool harq_on = envl("CELL_HARQ", 1, 0, 1) != 0; const bool la_on = harq_on && envl("CELL_LA", 1, 0, 1) != 0; HarqConfig hc; @@ -1218,6 +1223,10 @@ int run_du(IRadio *dev, const Cfg &c) { uint64_t dropped = 0, refused = 0; }; constexpr size_t kDlQueueMax = 64; + /* A contiguous queue's out-of-window PDUs (at most kDlQueueMax - 33) and the + * fresh one fit one frame; with gaps pick_dl_pdus still keeps the fresh + * one's place. */ + static_assert(kDlMaxPdus >= kDlQueueMax - devourer::cell::DlStreamRx::kReorder, "a DL frame too small"); std::map dlq; for (uint16_t ue : ues) dlue.emplace(ue, DlUe{HarqSender(hc), LinkAdapt({}, dl_rate0)}); @@ -1351,8 +1360,12 @@ int run_du(IRadio *dev, const Cfg &c) { unoffer(a.ue, a.prev_offered, a.offered); char l[200]; snprintf(l, sizeof l, - "{\"ev\":\"cell.daps.visit_dl\",\"ue\":%u,\"pdus\":%zu,\"first\":%u,\"sent\":%d,\"expired\":%d}", - a.ue, a.pdus, a.first, sent ? 1 : 0, expired ? 1 : 0); + "{\"ev\":\"cell.daps.visit_dl\",\"ue\":%u,\"pdus\":%zu,\"first\":%u,\"sent\":%d,\"expired\":%d," + "\"t_ms\":%lld}", + a.ue, a.pdus, a.first, sent ? 1 : 0, expired ? 1 : 0, + (long long)std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()) + .count()); emit(l); } }); @@ -1767,6 +1780,12 @@ int run_du(IRadio *dev, const Cfg &c) { q.last_sn = dp->sn; q.sns.push_back(dp->sn); q.last_push = std::chrono::steady_clock::now(); + if (q.offered) { /* a DAPS target's queue: when each PDU came (vs. the frames' picks) */ + char l[120]; + snprintf(l, sizeof l, "{\"ev\":\"cell.dl.pdu_in\",\"ue\":%u,\"sn\":%u,\"t_ms\":%lld}", dp->ue, dp->sn, + (long long)now_ms()); + emit(l); + } if (q.sns.size() > kDlQueueMax) { q.sns.pop_front(); ++q.dropped; @@ -2032,6 +2051,12 @@ int run_du(IRadio *dev, const Cfg &c) { std::vector served; for (const Grant &g : serving.grants) served.push_back(g.ue); + /* In DL-slot order (the slots are in time order): in grant order a UE + * whose slot comes first in the superframe was served after the other's + * slot, ~4 ms late into it (a handed-over UE at position 1 of a DU whose + * own UE has position 2). */ + std::sort(served.begin(), served.end(), + [&](uint16_t a, uint16_t b) { return serving.find(a)->dl_slot < serving.find(b)->dl_slot; }); /* Pace the pass to its superframe when there is no DL to wait for (a * DU with no UE, e.g. after its last one handed over): `sf` must track * the TSF, or the network superframe it reports runs away. */ @@ -2058,6 +2083,11 @@ int run_du(IRadio *dev, const Cfg &c) { } } const int64_t start = grid->slot_start_tsf(sf, idx); + /* The frame is picked and built just before its slot, not right after + * the previous one: a CU PDU that arrives in between rides THIS frame, + * not the next superframe's (after a DAPS switch that was the first + * target frame missing the next PDU: ~2 superframes of DL gap). */ + sleep_until_tsf(dev, start - dl_pick_lead_us); /* What to send: a due HARQ retransmission, else new data (or, with * HARQ off, a new frame every superframe). */ std::optional tx; @@ -2065,6 +2095,7 @@ int run_du(IRadio *dev, const Cfg &c) { uint64_t pdu_epoch = 0; size_t q_left = 0; std::optional offered_mark; /* the queue's DAPS-visit offered mark (logged) */ + const long long pick_ms = static_cast(now_ms()); { std::lock_guard lk(mu); DlUe &d = dlue.at(ue); @@ -2123,7 +2154,17 @@ int run_du(IRadio *dev, const Cfg &c) { rate, ue == atten_ue && atten_db != 0 ? std::optional(atten_db) : std::nullopt); pkt.insert(pkt.end(), f.begin(), f.end()); const int64_t sub = sleep_until_tsf(dev, start); - const bool ok = dev->send_packet(pkt.data(), pkt.size()); + /* Ready too late (the pick and build run after the lead's wait; a rare + * OS stall of a few hundred µs was seen before this, too): not aired + * past its slot's guard — its PDUs and HARQ attempt go back. */ + const bool late = sub - start > dl_guard_us; + if (late) { + char l[160]; + snprintf(l, sizeof l, "{\"ev\":\"cell.dl.late_skip\",\"ue\":%u,\"sf\":%lld,\"late_us\":%lld}", ue, + (long long)sf, (long long)(sub - start)); + emit(l); + } + const bool ok = !late && dev->send_packet(pkt.data(), pkt.size()); if (!ok) { std::lock_guard lk(mu); if (harq_on) @@ -2142,7 +2183,7 @@ int run_du(IRadio *dev, const Cfg &c) { for (uint32_t sn : pdus) fresh += devourer::cell::seq_lt(*offered_mark, sn) ? 1 : 0; pick = ",\"sn0\":" + std::to_string(pdus.front()) + ",\"fresh\":" + std::to_string(fresh) + - ",\"offered\":" + std::to_string(*offered_mark); + ",\"offered\":" + std::to_string(*offered_mark) + ",\"pick_ms\":" + std::to_string(pick_ms); } char l[320]; snprintf(l, sizeof l, diff --git a/tests/cell_node_selftest.cpp b/tests/cell_node_selftest.cpp index 205344e1..ca3f4d28 100644 --- a/tests/cell_node_selftest.cpp +++ b/tests/cell_node_selftest.cpp @@ -202,21 +202,33 @@ int main() { auto f = pick_dl_pdus(h, 139u, 8); CHECK(f.size() == 8 && f[0] == 140 && f[1] == 108); /* A 40-PDU offered backlog (100..139) whose answers were ALL lost (the - * UE's top is 99) and fresh 140..149: the UE's DlStreamRx confirms no - * gap — 100..107 go before 140 would push them out of its window. */ + * UE's top is 99) and fresh 140..149, a kDlMaxPdus frame: the UE's + * DlStreamRx confirms no gap — 100..107 ride with 140, which would push + * them out of its window. */ std::deque g; for (uint32_t s = 100; s < 150; ++s) g.push_back(s); devourer::cell::DlStreamRx rx; rx.accept(1, 99); - auto g1 = pick_dl_pdus(g, 139u, 8); - CHECK(g1 == std::vector({100, 101, 102, 103, 104, 105, 106, 107})); + auto g1 = pick_dl_pdus(g, 139u, kDlMaxPdus); + CHECK(g1.size() == kDlMaxPdus && + std::vector(g1.begin(), g1.begin() + 9) == + std::vector({100, 101, 102, 103, 104, 105, 106, 107, 140})); for (uint32_t sn : g1) rx.accept(1, sn); while (!g.empty()) - for (uint32_t sn : pick_dl_pdus(g, 139u, 8)) + for (uint32_t sn : pick_dl_pdus(g, 139u, kDlMaxPdus)) rx.accept(1, sn); CHECK(rx.missing_confirmed() == 0 && rx.missing_total() == 0 && rx.delivered() == 51); + /* A queue with gaps (it takes any newer sn): 1..32 offered, then 101 — + * every offered one is out of 101's window, yet 101 keeps its place. */ + std::deque gq; + for (uint32_t s = 1; s <= 32; ++s) + gq.push_back(s); + gq.push_back(101); + auto gf = pick_dl_pdus(gq, 32u, 32); + CHECK(gf.size() == 32 && std::find(gf.begin(), gf.end(), 101u) != gf.end() && gf.front() == 1 && + gq == std::deque({32})); } /* A DAPS-visit DL answer: broadcast RA, the target identity in the body, * tagged with the target cell's key; not a unicast DL frame. */ diff --git a/tools/ran-controller/main.cpp b/tools/ran-controller/main.cpp index 3dc8e947..ff466779 100644 --- a/tools/ran-controller/main.cpp +++ b/tools/ran-controller/main.cpp @@ -519,7 +519,18 @@ int main() { }; while (std::chrono::steady_clock::now() < deadline) { pollfd pf{fd, POLLIN, 0}; - if (poll(&pf, 1, 50) > 0 && (pf.revents & POLLIN)) { + /* Woken for the DL stream's next PDU too: with a fixed 50 ms the PDUs + * left up to 50 ms late (whenever a datagram or the timeout woke the + * loop), so a DU saw them unevenly — a PDU missing a DL frame's pick by + * a few ms waited a superframe. */ + int wait_ms = 50; + if (dl_ms > 0) { + const auto to_dl = std::chrono::ceil( + next_dl - std::chrono::steady_clock::now()) + .count(); + wait_ms = static_cast(std::clamp(to_dl, 0, 50)); + } + if (poll(&pf, 1, wait_ms) > 0 && (pf.revents & POLLIN)) { uint8_t buf[f1::kMaxDatagram]; sockaddr_in from{}; socklen_t fl = sizeof from;