Skip to content

cell M6: re-phasing a live cell (F1 v19, channel-switch IE v2) - #575

Merged
josephnef merged 3 commits into
masterfrom
feat/m6-rephase
Nov 14, 2026
Merged

josephnef merged 3 commits into
masterfrom
feat/m6-rephase

Conversation

@josephnef

Copy link
Copy Markdown
Collaborator

#566 item: more than three cells, and re-phasing live cells. This PR covers the re-phasing; a fourth cell needs a seventh radio, and the full tour needs #563's range.

Why. The planner places only joining cells. A cell that started at a bad phase, such as a fixed CELL_PHASE_US or one that joined before its neighbours, stays there and keeps paying for suspend gaps: 1–2 uplinks in 20.

What. A live phase move, the channel switch with a TSF step instead of a retune.

  • CU (RAN_REPHASE=1, RAN_REPHASE_MIN_GAIN [1.0], RAN_REPHASE_AT_S): scores each running DU's phase against its plan with the others left in place, and moves the one with the largest gain. Ties go to the highest id, so the oldest cell stays the reference. One DU at a time, never during a handover. ran.rephase is logged at the decision and ran.cs_done once the report shows the phase.
  • F1 v19: ChannelSwitchCmd.phase_us (−1 = a channel move).
  • ChannelSwitch.h: IE v2 carries step_us and at_us. rephase_plan() picks an instant idle in both grids: after the old active span, landing after the new one, before the next TBTT. The superframe count runs on, and it prefers a negative step so Kestrel's one stale old-phase beacon stays in idle time.
  • DU: stages the move (refusing no_window or a different channel), announces it for ≥ 3 superframes, then steps the TSF. Its discipline takes the new phase via set_phase (plus stepped() for ledger parts), the network offset follows, and the neighbours' offsets are recomputed. The runtime phase is now an atomic for the RX and F1 threads.
  • UE: at the same instant, shifts its view of the DU clock by the step, then stops, re-places and restarts its uplink beacon, as after a handover switch.
  • Tests: cell_m5 covers the IE v2 round-trip and tamper check, rephase_plan at the rig's phases (including the positive-step and no-window cases) and the F1 v19 round-trip.
  • Docs: new docs/cell-m6.md section "Re-phasing a live cell", plus PhasePlan.h comments.

Rig (testrig scripts/m6_rephase.sh, 2 runs per case, all pass): cell 1 on ch149 at phase 0, cell 2 on ch157 started at 20000, suspend gaps one in 20.

DU hears its UE (share of superframes) suspend gaps per UE idle gaps hearing the other cell
before the move 0.898–0.952 12–14 0
after the move (cell 2, 20000 → 51200) 0.997–1.000 0 78–81
baseline, no re-phase 0.90–0.95 53 0
  • The move: DU2 stepped −31200 µs at 52700 µs, 6–9 µs late; UE2 shifted 70–74 µs after it.
  • Its cost: 1–2 of the moved UE's uplinks were out of slot (the one in flight at the old phase, and Kestrel's stale beacon), then 100 % in slot. The DL gap across the move was 133 ms, the stream's own cadence.

Not covered: a chain of moves, where one move makes another worthwhile, has run only as a single move.

ctest: 95/95 pass.

🤖 Generated with Claude Code

RAN_REPHASE=1: the CU moves a running DU whose phase plan (the others
where they are) scores at least RAN_REPHASE_MIN_GAIN higher, with its
UEs: the DU steps its TSF at an instant idle in both grids
(rephase_plan: after the old active span, landing after the new one;
the superframe count runs on), the discipline takes the new phase and
the network offset follows; its UEs shift their view of its clock by
the same step and re-place their uplink beacon. Announced in the
channel-switch IE (v2: step, instant); F1 ChannelSwitchCmd.phase_us.

Rig (testrig m6_rephase.sh, 2 runs per case): cell 2 moved
20000 -> 51200 live; 1-2 uplinks of the moved UE out of slot at the
move, then 100 %; afterwards no suspend gaps, each UE measures the
other cell in idle gaps, and each DU hears its UE in 0.997-1.000 of
superframes (0.90-0.95 before and in the baseline).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Re-phase running cells with coordinated DU and UE clock steps

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Enable CU-directed re-phasing of running cells to improve idle-gap measurements and avoid suspend
 gaps.
• Extend F1 and authenticated beacon announcements to coordinate timed clock steps across DUs and
 UEs.
• Document the workflow and test protocol integrity, timing plans, and message round-trips.
Diagram

sequenceDiagram
    participant CU as RAN CU
    participant Planner as Phase planner
    participant F1 as F1 v19
    participant DU as Serving DU
    participant IE as Beacon IE v2
    participant UE as Attached UE
    CU->>Planner: score live phases
    Planner-->>CU: best eligible move
    CU->>F1: phase switch command
    F1->>DU: schedule move
    DU->>IE: advertise step and instant
    IE-->>UE: announce move
    DU->>DU: step TSF and update grid
    UE->>UE: shift clock and uplink
    DU->>F1: report new phase
    F1-->>CU: confirm completion
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Stop and rejoin the cell
  • ➕ Reuses joining-cell phase planning without a coordinated live clock step.
  • ➖ Interrupts service and forces attached UEs to reacquire the cell.
  • ➖ Cannot deliver the PR's low-disruption live move.

Recommendation: Keep the live TSF-step approach: it reuses the channel-switch announcement while preserving service and superframe continuity. Stop-and-rejoin is simpler but has a materially worse availability cost; multi-step moves for phases with no idle window can remain a separate extension.

Files changed (8) +420 / -30

Enhancement (5) +304 / -24
main.cppExecute and follow timed phase moves in DU and UE runtimes +154/-17

Execute and follow timed phase moves in DU and UE runtimes

• The DU validates and announces phase commands, steps its TSF, updates discipline and network timing, and recalculates neighbour offsets. An atomic exposes the live phase across threads; the UE shifts its DU clock view and re-places its uplink beacon at the announced instant.

examples/cell/main.cpp

ChannelSwitch.hAdd phase-step beacon IE and idle-window planner +56/-2

Add phase-step beacon IE and idle-window planner

• Version 2 adds signed step and instant fields to the authenticated channel-switch IE. The new rephase_plan selects a guarded instant idle on both grids, preferring a negative step and rejecting moves without a suitable window.

src/cell/ChannelSwitch.h

F1.hCarry target phase in F1 channel-switch commands +9/-3

Carry target phase in F1 channel-switch commands

• F1 version 19 adds ChannelSwitchCmd.phase_us to distinguish a live phase move from a channel move. Encoding and decoding include the field and reject values below the channel-move sentinel.

src/cell/F1.h

TsfDiscipline.hAccount for externally initiated TSF steps +7/-0

Account for externally initiated TSF steps

• Adds stepped() so a caller-initiated phase move is booked in ledger-based discipline fits after the phase target changes.

src/cell/TsfDiscipline.h

main.cppSelect and track beneficial live-cell phase moves +78/-2

Select and track beneficial live-cell phase moves

• Adds opt-in re-phasing settings and selects the running DU with the greatest qualifying phase-score gain when no handover or switch is in flight. Sends the F1 command, logs the decision, and confirms completion from the reported phase.

tools/ran-controller/main.cpp

Tests (1) +38 / -0
cell_m5_selftest.cppTest phase-move encoding and timing choices +38/-0

Test phase-move encoding and timing choices

• Covers IE v2 round-trip and tamper rejection, F1 v19 phase-command round-trip, and negative-step, positive-step, and no-window planner cases.

tests/cell_m5_selftest.cpp

Documentation (2) +78 / -6
cell-m6.mdDocument live re-phasing and rig results +75/-4

Document live re-phasing and rig results

• Explains CU selection, the shared idle-window step, DU and UE behavior, and measured effects on suspend gaps and uplinks. Updates the remaining-work section to distinguish completed re-phasing from untested chains of moves.

docs/cell-m6.md

PhasePlan.hClarify planning for joining versus running cells +3/-2

Clarify planning for joining versus running cells

• Comments explain that joining-cell planning remains unchanged while the CU may separately move a running cell when the gain warrants moving its UEs.

src/cell/PhasePlan.h

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. UEs move even when their cell does not ✓ Resolved
Description
run_ue applies the announced clock step at its deadline without knowing whether run_du completed
the TSF write. If the DU misses the instant, has not announced the move enough times, or fails the
write, its UEs shift to a grid the DU never adopted and must recover through later beacon
synchronization.


Remediation recommended

2. Re-phasing docs can drift from header ✓ Resolved
Description
The new re-phasing section in docs/cell-m6.md restates the instant, stale-beacon, and step-sign
rules that ChannelSwitch.h v2 and rephase_plan() already document, plus the TSF-fit note that
TsfDiscipline::stepped() owns. When the header changes, this copy stays stale, and a later reader
gets two sources that can disagree.

3. An ungranted UE keeps its old beacon ✓ Resolved
Description
run_ue sets rephase_place only if the grant map at the shifted superframe contains the UE. When
that grant is absent, it still clears cs_pending, so an already-running beacon is neither stopped
nor placed on the moved grid.

4. Some uplinks get the wrong network time ✓ Resolved
Description
run_du publishes net_off and phase_live with separate atomic stores, while forward_ul reads
them separately to calculate net_us. For a move that changes the network-superframe offset, a
concurrent receive can combine values from opposite sides of the move and assign an uplink a
timestamp and sequence from the wrong superframe.

View review recommended (3)
5. Cells can remain at a costly phase ✓ Resolved
Description
The controller asks plan_phase for its single highest-scoring phase and discards that candidate if
rephase_plan cannot reach it directly. When a lower-scoring but still beneficial phase has a safe
move window, the controller never evaluates it, so the cell remains at its current phase.

6. Small forward phase moves fire a stale beacon on top of the new one ✓ Resolved
Description
In rephase_plan's negative-step branch, the only check is that the step instant at = lo + P - d
falls before hi. It never checks that Kestrel's stale old-phase beacon, which fires at d into
the lengthened last superframe, also clears hi = P - guard. When the new phase is a little after
the old one (new = old + x with x below the guard), the plan is accepted with step −x, and the stale
beacon fires x µs before the cell's own new TBTT. This breaks the plan's "idle in both grids"
guarantee and the documented "phases closer than about the active span … the DU refuses".

7. A failed TSF write during a phase move leaves the RX clock trusted ✓ Resolved
Description
In the DU's phase-move path, a failed WriteTsf only calls disc.wrote(false). It neither re-reads
the TSF/free-run pair through publish_clock nor sets clk.valid = false, although the comment
itself says the write may have half-updated the TSF. RX attribution and uplink net_us therefore
keep using a clock offset that may be wrong until the next discipline write. The ordinary discipline
path avoids this by re-reading after every write attempt.


Informational

8. Neighbour offsets can stay on the old phase after a move ✓ Resolved
Description
The F1 neighbour handler reads phase_live and computes offsets before acquiring f1_mu, then
writes those offsets to nb_list under the lock. If a phase move publishes a new phase and
recalculates nb_list in between, the F1 handler replaces the new-phase offsets with old-phase ones
that reach UEs in the beacon’s NL IE until the CU’s next neighbour round.

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

josephnef and others added 2 commits November 14, 2026 09:28
…does a move the DU did not make (test: CELL_DU_TEST_REPHASE_FAIL); stops its beacon on every move; the stale beacon checked for small forward moves; the CU takes the best reachable phase; one net_base value; re-read after any write; neighbour offsets under f1_mu; docs point at the headers

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@josephnef

Copy link
Copy Markdown
Collaborator Author

All eight findings were valid. Fixed in bd68d9db:

  1. UEs shift when the DU does not move. After a move, the UE now watches its clock fit for up to 30 superframes. If the fit confirms the opposite step, the DU did not move (missed, refused, or a failed write), so the UE re-places its uplink beacon on the grid that stands (cell.ue.cs_rephase_undone). The fit absorbs the step itself. To exercise this path, a test-only CELL_DU_TEST_REPHASE_FAIL=1 makes a DU announce and not move. On the rig the undone case passes in 2/2 runs: the fit undoes the step after its 6 confirming beacons, the re-placement follows, and that costs 8 uplinks out of slot before the UE is back in slot.
  2. Docs duplicated the header. The mechanism bullets now point to rephase_plan() and TsfDiscipline::set_phase/stepped(). The outcome, the cost and the rig table stay in the docs.
  3. An ungranted UE kept its old beacon. The beacon now stops on every accepted move. It is placed and restarted only when the UE has a slot.
  4. Torn network time. net_base = phase + net_off·P is one atomic, written by the main thread and read once for an uplink's net_us.
  5. Reachability. plan_phase takes an optional allowed filter, and the CU passes rephase_plan reachability, so it picks the best reachable phase. Selftest: an excluded optimum yields the next best reachable phase; none allowed gives a score of 0.
  6. Small forward moves. The negative branch now also requires d < hi. Selftest: 0 → 500 is refused.
  7. Clock after a failed write. The clock is re-read after any write attempt, success or failure, as the discipline does.
  8. Racing neighbour update. The F1 handler now reads the phase and builds the offsets under f1_mu. The move publishes the phase and recomputes the offsets under the same lock.

Rig re-run on the fixed build (m6_rephase.sh --runs 2): all 6 runs pass (rephase, stay, undone). ctest: 95/95 pass.

@josephnef josephnef added the skip-qodo-gate Bypass the Qodo review gate (outage / maintainer decision) label Nov 14, 2026
@josephnef
josephnef merged commit accc521 into master Nov 14, 2026
30 of 31 checks passed
@josephnef
josephnef deleted the feat/m6-rephase branch November 14, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-qodo-gate Bypass the Qodo review gate (outage / maintainer decision)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant