vDSO CLOCK_MONOTONIC runs 739 s ahead of the kernel clock on RV1106 (CNTVOFF not zero, kernel on the physical counter): absolute timed waits end minutes late #35

Closed
opened 2026-10-28 23:08:17 -06:00 by noah · 4 comments
Owner

Found for flare-edge#2319 (std timed waits do not end on time on the panel; flare-edge#2311 reset loop).

What

On bench a (kernel 6.18.46, image of 2026-10-24) the vDSO's CLOCK_MONOTONIC is 738.9 s ahead of the kernel's own CLOCK_MONOTONIC. A static armv7 musl probe, run at uptime 6900 s:

libc clock_gettime(MONOTONIC) (vDSO):  sec 7638, nsec 962493923
syscall clock_gettime (263):           sec 6900, nsec  37036706
syscall clock_gettime64 (403):         sec 6900, nsec  37039914
/proc/uptime:                          6900.03
std Instant::now():                    tv_sec 7638 (vDSO)

Every absolute CLOCK_MONOTONIC deadline taken from the vDSO and handed to the kernel therefore ends about 739 s late:

futex(240) WAIT_BITSET abs, deadline from vDSO + 1 s:     STILL WAITING after 12 s
futex(240) WAIT_BITSET abs, deadline from syscall + 1 s:  1.008 s (ETIMEDOUT)
futex(240) FUTEX_WAIT relative 1 s:                        1.012 s
futex_time64(422) relative and absolute (syscall clock):   1.008 / 1.009 s
std Condvar::wait_timeout, mpsc recv_timeout, park_timeout (1 s): STILL WAITING after 12 s
std thread::sleep (1 s):                                   1.005 s

std's timed waits use a vDSO deadline with FUTEX_WAIT_BITSET, so they hang; relative sleeps are exact. The same skew hits pthread_cond_timedwait, sem_timedwait, clock_nanosleep(TIMER_ABSTIME) and timerfd TFD_TIMER_ABSTIME in any program whose libc uses the vDSO, and any comparison of a vDSO timestamp with a kernel timestamp (input events, socket timestamps, /proc).

Likely cause

dmesg: arch_timer: cp15 timer running at 24.00MHz (phys), clocksource arch_sys_counter, and the DT timer node carries clock-frequency (firmware did not set CNTFRQ). The kernel's timekeeping reads the physical counter (CNTPCT); the arm32 vDSO always reads the virtual counter (CNTVCT = CNTPCT - CNTVOFF). The boot firmware leaves CNTVOFF non-zero, and the kernel cannot write it from secure or non-secure SVC (only HYP or monitor mode can). The hyp stub zeroes CNTVOFF only when the kernel is entered in HYP mode.

Fix options (recommended first)

  1. Kernel patch in the SDK: when arch_timer registers the physical counter on arm32, set the clocksource's vdso_clock_mode to VDSO_CLOCKMODE_NONE, so clock_gettime falls back to the syscall (about 1 us per call instead of about 0.1 us). Small, local to the SDK, and correct whatever the firmware leaves in CNTVOFF.
  2. Boot firmware zeroes CNTVOFF before it enters the kernel (U-Boot in secure or HYP mode). Keeps the fast vDSO but depends on every boot path (SPL, MaskRom recovery) doing it.
  3. Both: 2 for speed, 1 as the safety net.

Check after the fix

The probe (flare-edge lane LN; source to be added as a bench check) must show the vDSO and syscall monotonic clocks within 1 ms and every timed wait ending within 50 ms of 1 s.

Userspace is guarded meanwhile: flare-edge tools/check-timed-waits.py (#2319) fails on new std timed waits in device code.

Found for flare-edge#2319 (std timed waits do not end on time on the panel; flare-edge#2311 reset loop). ## What On bench a (kernel 6.18.46, image of 2026-10-24) the vDSO's CLOCK_MONOTONIC is 738.9 s ahead of the kernel's own CLOCK_MONOTONIC. A static armv7 musl probe, run at uptime 6900 s: ``` libc clock_gettime(MONOTONIC) (vDSO): sec 7638, nsec 962493923 syscall clock_gettime (263): sec 6900, nsec 37036706 syscall clock_gettime64 (403): sec 6900, nsec 37039914 /proc/uptime: 6900.03 std Instant::now(): tv_sec 7638 (vDSO) ``` Every absolute CLOCK_MONOTONIC deadline taken from the vDSO and handed to the kernel therefore ends about 739 s late: ``` futex(240) WAIT_BITSET abs, deadline from vDSO + 1 s: STILL WAITING after 12 s futex(240) WAIT_BITSET abs, deadline from syscall + 1 s: 1.008 s (ETIMEDOUT) futex(240) FUTEX_WAIT relative 1 s: 1.012 s futex_time64(422) relative and absolute (syscall clock): 1.008 / 1.009 s std Condvar::wait_timeout, mpsc recv_timeout, park_timeout (1 s): STILL WAITING after 12 s std thread::sleep (1 s): 1.005 s ``` std's timed waits use a vDSO deadline with FUTEX_WAIT_BITSET, so they hang; relative sleeps are exact. The same skew hits pthread_cond_timedwait, sem_timedwait, clock_nanosleep(TIMER_ABSTIME) and timerfd TFD_TIMER_ABSTIME in any program whose libc uses the vDSO, and any comparison of a vDSO timestamp with a kernel timestamp (input events, socket timestamps, /proc). ## Likely cause dmesg: `arch_timer: cp15 timer running at 24.00MHz (phys)`, clocksource arch_sys_counter, and the DT timer node carries `clock-frequency` (firmware did not set CNTFRQ). The kernel's timekeeping reads the physical counter (CNTPCT); the arm32 vDSO always reads the virtual counter (CNTVCT = CNTPCT - CNTVOFF). The boot firmware leaves CNTVOFF non-zero, and the kernel cannot write it from secure or non-secure SVC (only HYP or monitor mode can). The hyp stub zeroes CNTVOFF only when the kernel is entered in HYP mode. ## Fix options (recommended first) 1. Kernel patch in the SDK: when arch_timer registers the physical counter on arm32, set the clocksource's vdso_clock_mode to VDSO_CLOCKMODE_NONE, so clock_gettime falls back to the syscall (about 1 us per call instead of about 0.1 us). Small, local to the SDK, and correct whatever the firmware leaves in CNTVOFF. 2. Boot firmware zeroes CNTVOFF before it enters the kernel (U-Boot in secure or HYP mode). Keeps the fast vDSO but depends on every boot path (SPL, MaskRom recovery) doing it. 3. Both: 2 for speed, 1 as the safety net. ## Check after the fix The probe (flare-edge lane LN; source to be added as a bench check) must show the vDSO and syscall monotonic clocks within 1 ms and every timed wait ending within 50 ms of 1 s. Userspace is guarded meanwhile: flare-edge tools/check-timed-waits.py (#2319) fails on new std timed waits in device code.
Author
Owner

Bench a, image 9462 (rebuild 9d03840, slot _b), 2026-10-29 09:03Z, run under bench-lock SHARED with clockskew built from rb/w31-clock-skew-rate 15620f47 (--rate-s 30):

image: VERSION=0.17.79-rc BUILD_DATE=2026-10-29 GIT_COMMIT=9d03840 FLAVOR=release WIFI_EAP=0 KERNEL=6.18.46 KCONFIG_SHA256=7de6e4896da603e0993db36a261796abbb040fd6ac3733a39d163762e4fda27f SDK=/home/noah/projects/flare-edge/sdk 
clockskew: vdso_symbol=__vdso_clock_gettime64
clockskew: kernel_ns=7010227929633
clockskew: vdso_ns=7749153418642
clockskew: libc_ns=7749153424183
clockskew: uptime_s=7010.22
clockskew: vdso_skew_ms=738925.463
clockskew: vdso_rate_ppm=-0.1 over_s=30
clockskew: libc_skew_ms=738925.460
clockskew: wait_relative=1009 ok
clockskew: wait_abs_kernel=1006 ok
clockskew: wait_abs_vdso=5010 hang
clockskew: verdict=FAIL reasons=vdso_skew,libc_skew,wait_abs_vdso

Reading:

  • The vDSO skew is a pure offset, not a rate error: vdso_rate_ppm=-0.1 over 30 s (the default limit is 100 ppm). A 12 percent rate error (#77) would show as about 120000 ppm here, so the earlier question (offset or rate, iteration notes on the 1.107 ratio) is settled: offset.
  • This matches the CNTVOFF reading of #2319: the virtual counter the vDSO reads carries a fixed boot offset against the physical counter the kernel timekeeping uses. The fix in bfe-core1106-sdk#35 (vdso_clock_mode NONE when arch_timer uses the physical counter, or zero CNTVOFF in the boot firmware) stays the right one; no rate correction is needed.
  • Severity for #2342 and #2343: their readers see a constant jump of about 739 s against kernel time, not drift. Intervals measured only with the vDSO clock are correct; mixing vDSO and kernel time (absolute timed waits, timestamps compared across processes that use different paths) is what breaks, as wait_abs_vdso=hang shows.

Generated with Claude Code
https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG

Bench a, image 9462 (rebuild 9d03840, slot _b), 2026-10-29 09:03Z, run under bench-lock SHARED with clockskew built from rb/w31-clock-skew-rate 15620f47 (`--rate-s 30`): ``` image: VERSION=0.17.79-rc BUILD_DATE=2026-10-29 GIT_COMMIT=9d03840 FLAVOR=release WIFI_EAP=0 KERNEL=6.18.46 KCONFIG_SHA256=7de6e4896da603e0993db36a261796abbb040fd6ac3733a39d163762e4fda27f SDK=/home/noah/projects/flare-edge/sdk clockskew: vdso_symbol=__vdso_clock_gettime64 clockskew: kernel_ns=7010227929633 clockskew: vdso_ns=7749153418642 clockskew: libc_ns=7749153424183 clockskew: uptime_s=7010.22 clockskew: vdso_skew_ms=738925.463 clockskew: vdso_rate_ppm=-0.1 over_s=30 clockskew: libc_skew_ms=738925.460 clockskew: wait_relative=1009 ok clockskew: wait_abs_kernel=1006 ok clockskew: wait_abs_vdso=5010 hang clockskew: verdict=FAIL reasons=vdso_skew,libc_skew,wait_abs_vdso ``` Reading: - The vDSO skew is a pure offset, not a rate error: vdso_rate_ppm=-0.1 over 30 s (the default limit is 100 ppm). A 12 percent rate error (#77) would show as about 120000 ppm here, so the earlier question (offset or rate, iteration notes on the 1.107 ratio) is settled: offset. - This matches the CNTVOFF reading of #2319: the virtual counter the vDSO reads carries a fixed boot offset against the physical counter the kernel timekeeping uses. The fix in bfe-core1106-sdk#35 (vdso_clock_mode NONE when arch_timer uses the physical counter, or zero CNTVOFF in the boot firmware) stays the right one; no rate correction is needed. - Severity for #2342 and #2343: their readers see a constant jump of about 739 s against kernel time, not drift. Intervals measured only with the vDSO clock are correct; mixing vDSO and kernel time (absolute timed waits, timestamps compared across processes that use different paths) is what breaks, as wait_abs_vdso=hang shows. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
Author
Owner

Fix up as bfe-core1106-sdk#36 (rb/ln-vdso-phys-counter b4596ed): patch 82 adds arm,cpu-registers-not-fw-configured to the RV1106 timer node, so the arm32 vDSO drops its clock symbols and libc uses the syscall. It also adds an arm_arch_timer.c fallback that sets vdso_clock_mode NONE on arm32 when the kernel is on the physical counter without HYP. A CI checker covers both. The full kernel build passes and the dtb carries the property.

Bench proof: flare-edge branch rb/w31-sdk-vdso-pin (c3dbb2fa) pins the SDK to b4596ed. A firmware image built from it goes onto bench a's inactive slot, and then tools/bench/clock-skew/run.sh --rate-s 30 must give verdict=PASS. The coordinator schedules the dispatch and the flash.

Generated with Claude Code
https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG

Fix up as bfe-core1106-sdk#36 (rb/ln-vdso-phys-counter b4596ed): patch 82 adds `arm,cpu-registers-not-fw-configured` to the RV1106 timer node, so the arm32 vDSO drops its clock symbols and libc uses the syscall. It also adds an arm_arch_timer.c fallback that sets vdso_clock_mode NONE on arm32 when the kernel is on the physical counter without HYP. A CI checker covers both. The full kernel build passes and the dtb carries the property. Bench proof: flare-edge branch rb/w31-sdk-vdso-pin (c3dbb2fa) pins the SDK to b4596ed. A firmware image built from it goes onto bench a's inactive slot, and then `tools/bench/clock-skew/run.sh --rate-s 30` must give verdict=PASS. The coordinator schedules the dispatch and the flash. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
Author
Owner

Bench result for the arm32 vDSO counter fix (lane LN, 2026-10-29 11:33-12:02Z, under a FLASH lock on bench a).

Image: run 9545 firmware-rv1106-test-dev-insecure (flare-edge rb/w31-sdk-vdso-pin c3dbb2f, SDK b4596ed), written with tools/bench-flash-slot.sh to the inactive slot _a (read-back sha256 matched for boot, oem, rootfs), armed with 3 tries, NOT marked good.

Kernel log on _a:

arch_timer: cp15 timer running at 24.00MHz (phys).
arch_timer: physical counter without HYP: vDSO clock disabled
clocksource: Switched to clocksource arch_sys_counter

clock-skew (tools/bench/clock-skew/run.sh, clockskew from 15620f47, --rate-s 30), 33 s after boot:

image: VERSION=0.17.79-rc BUILD_DATE=2026-10-29 GIT_COMMIT=c3dbb2f FLAVOR=test WIFI_EAP=0 KERNEL=6.18.46 KCONFIG_SHA256=7de6e4896da603e0993db36a261796abbb040fd6ac3733a39d163762e4fda27f SDK=/home/noah/projects/flare-edge/sdk 
clockskew: vdso_symbol=absent
clockskew: kernel_ns=32973263139
clockskew: vdso_ns=absent
clockskew: libc_ns=32973267222
clockskew: uptime_s=32.97
clockskew: vdso_rate_ppm=skipped no vdso clock
clockskew: libc_skew_ms=0.000
clockskew: wait_relative=1006 ok
clockskew: wait_abs_kernel=1008 ok
clockskew: wait_abs_vdso=skipped no vdso clock
clockskew: verdict=PASS

Again at 699 s uptime:

clockskew: uptime_s=698.57
clockskew: libc_skew_ms=-0.000
clockskew: verdict=PASS

Before the fix (same panel, image 9462 on _b): vdso_skew_ms=738925.463, wait_abs_vdso=5010 hang, verdict FAIL. With the fix the vDSO clock_gettime symbol is gone (arm32 vdso_nullpatch when the clock mode is NONE), libc falls back to the syscall, libc_skew_ms is 0 and every timed wait returns on time: verdict PASS.

The panel was then put back on _b (9d03840, B pri 15 confirmed; A pri 14, 2 tries left, not successful), rebooted, and checked healthy: slot _b, uptime 796 s with no reset, mosquitto, warden-io, warden-modbus, appd, warden-automation, warden-flared, warden-ui and warden-telemetry running with unchanged PIDs. Lock released 12:03Z.

Bench result for the arm32 vDSO counter fix (lane LN, 2026-10-29 11:33-12:02Z, under a FLASH lock on bench a). Image: run 9545 firmware-rv1106-test-dev-insecure (flare-edge rb/w31-sdk-vdso-pin c3dbb2f, SDK b4596ed), written with tools/bench-flash-slot.sh to the inactive slot _a (read-back sha256 matched for boot, oem, rootfs), armed with 3 tries, NOT marked good. Kernel log on _a: ``` arch_timer: cp15 timer running at 24.00MHz (phys). arch_timer: physical counter without HYP: vDSO clock disabled clocksource: Switched to clocksource arch_sys_counter ``` clock-skew (tools/bench/clock-skew/run.sh, clockskew from 15620f47, --rate-s 30), 33 s after boot: ``` image: VERSION=0.17.79-rc BUILD_DATE=2026-10-29 GIT_COMMIT=c3dbb2f FLAVOR=test WIFI_EAP=0 KERNEL=6.18.46 KCONFIG_SHA256=7de6e4896da603e0993db36a261796abbb040fd6ac3733a39d163762e4fda27f SDK=/home/noah/projects/flare-edge/sdk clockskew: vdso_symbol=absent clockskew: kernel_ns=32973263139 clockskew: vdso_ns=absent clockskew: libc_ns=32973267222 clockskew: uptime_s=32.97 clockskew: vdso_rate_ppm=skipped no vdso clock clockskew: libc_skew_ms=0.000 clockskew: wait_relative=1006 ok clockskew: wait_abs_kernel=1008 ok clockskew: wait_abs_vdso=skipped no vdso clock clockskew: verdict=PASS ``` Again at 699 s uptime: ``` clockskew: uptime_s=698.57 clockskew: libc_skew_ms=-0.000 clockskew: verdict=PASS ``` Before the fix (same panel, image 9462 on _b): vdso_skew_ms=738925.463, wait_abs_vdso=5010 hang, verdict FAIL. With the fix the vDSO clock_gettime symbol is gone (arm32 vdso_nullpatch when the clock mode is NONE), libc falls back to the syscall, libc_skew_ms is 0 and every timed wait returns on time: verdict PASS. The panel was then put back on _b (9d03840, B pri 15 confirmed; A pri 14, 2 tries left, not successful), rebooted, and checked healthy: slot _b, uptime 796 s with no reset, mosquitto, warden-io, warden-modbus, appd, warden-automation, warden-flared, warden-ui and warden-telemetry running with unchanged PIDs. Lock released 12:03Z.
noah closed this issue 2026-10-29 06:05:11 -06:00
Author
Owner

Fixed by #36, merged as 4d30c3083b0607e639e0bec05891bafdb1a0ea3d; bench a run 9545 passed.

Fixed by #36, merged as 4d30c3083b0607e639e0bec05891bafdb1a0ea3d; bench a run 9545 passed.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: blueflare/bfe-core1106-sdk#35