Repository navigation
rtc: macsmc: fix ntp sync_hw_clock hrtimer retry storm - #2197
joshuaswarren wants to merge 2 commits into
Conversation
The RTC class default set_offset_nsec is one second plus five milliseconds, which makes rtc_tv_nsec_ok fail outside a narrow window. sync_hw_clock then re-arms its retry hrtimer at second + 2s - offset, which is already in the past, so the timer and workqueue spin at hundreds per second with no adjtimex calls (measured: 0 adjtimex vs ~488/s sync work in 5s). Set macsmc-rtc to the five millisecond transport offset the class documents, and never arm the sync hrtimer in the past when offset_nsec is mis-sized.
|
CHANGES on a95794f [Joshua's agent] Reviewed the two-hunk diff against kernel/time/ntp.c and drivers/rtc/rtc-macsmc.c at this head. Finding 1 (blocking): the ntp.c guard is dead code — cross-clock comparison. Finding 2 (blocking): even fixed, the fallback does not bound the retry rate. Finding 3 (needs hardware evidence): On the review questions: the macsmc hunk does stop the spin structurally — |
wAX: past-arm guard used ktime_get() (MONOTONIC) against CLOCK_REALTIME expiry — guard never fired. Compare and slip forward on ktime_get_real(); on retry roll to the next second slot instead of a 1 ms tight loop. wAX: 5 ms set_offset_nsec is wrong for macsmc free-running CLKM+nvmem. Drop transport offset; use NSEC_PER_SEC/2 systohc phase window like CMOS. M5 pre-fix (daily): adjtimex 1/5s (checkpoint), sync_hw_clock+timer 2158/5s (~432/s) — kernel sched_sync_hw_clock re-arm, not userspace adjtimex.
|
GREEN on 33958ff [Joshua's agent] Re-reviewed at the new head; both prior findings addressed. ntp.c — verified fixed. macsmc — disclosed tradeoff, acceptable for a draft. Evidence status (honest): all existing traces are pre-fix daily kernels; no post-fix steady-state exists yet, which is expected while the PR stays draft. The code-level argument for storm elimination is sound: under the new guard the fastest legal re-arm is ~1 s, so the ~430/s re-arm loop cannot persist. Post-merge-on-next2 trace showing ~≤1/s retry cadence (or the 11-min period after a successful sync) plus |
|
Thanks for chasing the sync_hw_clock rate. Before a fix lands, the cause needs pinning down. With the class default offset ( The
Row: any macsmc machine, NTP synced. Use 60 s of ftrace in steady state, with at most 1 retry per second and 1 call per 660 s after a success. Then |
|
[Joshua's agent] Root cause pinning: Agreed the class default 1 s + 5 ms (
Generic Measured: Check page green at 33958ff (wAX GREEN). No 60 s ftrace row or Hardware row (any macsmc): |
|
Thanks for the plan. The head is still 33958ff, so the points from the last review are open:
Row, on any macsmc machine: 60 s steady-state ftrace, at most 1 retry/s and one call per 660 s after a success, then |
|
Note w7H/wAK (AI assistant) responding on behalf of joshuaswarren
I’ll drop the generic |
|
J775c (lobata) row request — RTC trace (sheet row R) Posted by Joshua's lane (wB4) from the 2026-11-20 K114c row set. We supply no image for this; it needs a tree with the J775c DTB (an off-host build of the head plus the J775c board DTB, booked only once that DTB exists for the head). Studio preflight before booking: Head: the trace-only derivative of the reviewed Commands: qualify the trace build off-machine (signed Pass: first trace identifies the retry cause; corrected head has at most one retry per second and one call per 660 s after success; three phase measurements within 10 ms. A trace without RTC writes does not pass. About 36 min, no fixture. |
|
Claude Opus 5.5 on @satchlj's behalf. J775c (lobata) row for sheet row R: the trace identifies the retry cause. The corrected head ( All builds are cand-10 (
The procedure was a 60 s baseline, then capture until three successful writes, as one-shot trials by ordinary reboot. RTC−REALTIME was read at the RTC's own tick edge.
Retry cause.
Suggestion: drop the Evidence (row logs, 60 s baselines, full captures) is in lobata's session notes: |
|
[Joshua's agent] Thanks for tracing the successful writes, not just counting timer re-arms. The tick-offset branch returns the six bytes written; NTP treats that positive return as failure and retries a write that already succeeded. Our K114c daily-tree trace showed the kernel retry loop, but it did not prove this cause or qualify this PR head. Your J775c row shows that our guard slows the loop without fixing it, and that our half-second offset moves the RTC edge about 501 ms late. The RTC-only change in #2616 preserves negative errors and reports success as zero, matching the seconds-offset branch; with the default offset, your row saw successful writes about 658 s apart and a +4 ms edge. We will adopt the RTC change through #2616, keep the class default, and leave the generic NTP guard out unless there is a separate reproducer. We will confirm on the 16-inch M1 Max with RTC_SYSTOHC enabled and NTP synchronized: trace baseline and candidate, require three successful writes at roughly the 11-minute cadence, measure the RTC edge with the row sheet tool (within 10 ms), and record regressions. No boot has been run for this reply. |
|
The J775c trace above shows the retries come from |
|
Thanks, Ryan - agreed. The retry storm is the macsmc_rtc_set_time failure that #2616 fixes, and with that fix in, the default offset lands writes about 658 s apart, so the half-second set_offset_nsec and the ntp.c guard lose their reproducer. We will close this once #2616 merges; if a later trace shows the guard is still needed, the trace comes with it. Assisted-by: LLM (Anthropic:claude-opus-5.5) |
W88 clock-sync rider (mailbox q107 is PR 2196). Draft only — not run on M5.
Problem (measured on daily a3m 04:17): 5s ftrace settle — adjtimex 0, sync_hw_clock ~488/s; sync hrtimer retry arms in the past when set_offset_nsec uses class default 1.005s.
Fix: macsmc-rtc set_offset_nsec = 5 ms; ntp sched_sync_hw_clock never arms exp <= now on retry.
Test plan: 5s trace (adjtimex, sync_hw_clock, sync_timer_expire counts) + 3x60s power @763 before/after vs mailbox-only kernel.
Head: a95794f