[LTP] sys_rtc01: Report TCONF on system time mismatch when STA_UNSYNC is set

Wake Liu wakel@google.com
Wed Nov 18 14:18:08 CET 2026


Hi Cyril,

> Hmm, I guess that the logic should be the other way, if STA_UNSYNC is
> not set the clock was modified by NTP and the test should be skipped:

I think the logic in 3d11e5dd622e as applied is the right way around;
inverting it would bring back the failure this patch fixes.

In kernel/time/ntp.c, the kernel writes the system time back to the RTC
only while STA_UNSYNC is clear: sync_hw_clock() returns early if
!ntp_synced(), and do_adjtimex() queues sync_work via
ntp_notify_cmos_timer() once an NTP daemon clears STA_UNSYNC. With
CONFIG_RTC_SYSTOHC=y on a writable RTC, the NTP-corrected time is
written to the RTC within a few seconds and then every 11 minutes, so
since_epoch is expected to match system time. (That is also how
leapsec01 ended up writing its fake 23:59:58 into rtc0 when it cleared
STA_UNSYNC [1].)

Conversely, STA_UNSYNC set is the state where nothing keeps the RTC in
sync: it is set at boot, and every clock_settime(), settimeofday(), or
ADJ_SETOFFSET sets it again via ntp_clear(). On Android test devices,
for example, the harness sets the clock with date(1) after boot and no
NTP daemon clears STA_UNSYNC, so rtc0 stays at its boot-time offset
("diff 24441s > slack 10s"). chronyd without rtcsync behaves the same
way: it disciplines the system clock while leaving STA_UNSYNC set. With
the inverted check, all of these would hit TFAIL again, while systems
actively syncing the RTC via SYSTOHC would report TCONF.

The reviewer is right on two limitations:
1. When STA_UNSYNC is set, userspace cannot tell a broken RTC apart
   from a system clock stepped after boot, though the since_epoch vs
   date/time check still runs on all systems.
2. When STA_UNSYNC is clear, the RTC can still diverge if
   CONFIG_RTC_SYSTOHC is disabled (or points to a different RTC), or if
   the RTC driver is read-only / does not support set_time.

Do you think it is worth sending a follow-up to also check
CONFIG_RTC_SYSTOHC / CONFIG_RTC_SYSTOHC_DEVICE (when kernel config is
available), or would you prefer to keep 3d11e5dd622e as-is and just
note the read-only / non-SYSTOHC case in the comment?

[1] https://lore.kernel.org/ltp/20261116064205.2360040-1-wakel@google.com/

Best regards,
Wake


More information about the ltp mailing list