Skip to contentSkip to conversation

sys_rtc01: TCONF on system time mismatch when STA_UNSYNC is unset

PATCH In review Cyril Hrubis 3 participants 3 messages Nov 18 – Nov 19

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sys_rtc01: TCONF on system time mismatch when STA_UNSYNC is unset

It turns out that the STA_UNSYNC flag is set at boot and cleared by ntp, so we should skip the TFAIL when the flag is cleared, since that means that NTP have adjusted the system time and it's possibly out of sync with RTC.

Fixes 3d11e5dd622e "sys_rtc01: Report TCONF on system time mismatch when STA_UNSYNC is set"
---
 testcases/kernel/sysfs/class/rtc/sys_rtc01.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
testcases/kernel/sysfs/class/rtc/sys_rtc01.c +7 -10
index 0e1c69f95..4857d4a8b 100644
@@ -43,12 +43,9 @@
  * test performs, so on a long-running system a purely fixed slack would
  * eventually produce false failures even on perfectly healthy hardware.
  *
- * If the system was booted with an RTC that was off the current time and the
- * system clock was later stepped in userspace via :manpage:`clock_settime(2)`
- * or :manpage:`settimeofday(2)` without updating the RTC, the kernel sets
- * STA_UNSYNC and CONFIG_RTC_SYSTOHC does not write the system clock back to
- * the RTC while hctosys remains 1. Report TCONF instead of TFAIL when
- * since_epoch diverges from system time while STA_UNSYNC is set.
+ * If system time was corrected by NTP the kernel clears STA_UNSYNC flag.
+ * Report TCONF instead of TFAIL when since_epoch diverges from system time
+ * when STA_UNSYNC is not set.
  *
  * Under virtualization the slack is additionally multiplied, since a VM's
  * clock (and thus its emulated RTC) commonly lags real time by tens of
@@ -112,14 +109,14 @@ static long read_hctosys(const char *name)
 	return TST_SYSFS_READ_LI(PATH_CLASS_RTC "/%s/hctosys", name);
 }
 
-static int is_clock_unsynced(void)
+static int clock_is_synced(void)
 {
 	struct timex tx = { .modes = 0 };
 
 	if (adjtimex(&tx) == -1)
 		tst_brk(TBROK | TERRNO, "adjtimex() failed");
 
-	return !!(tx.status & STA_UNSYNC);
+	return !(tx.status & STA_UNSYNC);
 }
 
 static void read_rtc_snapshot(const char *name, char *date, size_t date_size,
@@ -217,9 +214,9 @@ static void check_rtc(const char *name, int any_hctosys)
 			"%s: since_epoch (%lld), system time (%lld), diff %llds <= slack %lds",
 			name, (long long)since_epoch, (long long)sys_epoch,
 			diff, slack);
-	} else if (is_clock_unsynced()) {
+	} else if (clock_is_synced()) {
 		tst_res(TCONF,
-			"%s: since_epoch (%lld), system time (%lld), diff %llds > slack %lds (STA_UNSYNC is set)",
+			"%s: since_epoch (%lld), system time (%lld), diff %llds > slack %lds (STA_UNSYNC is not set)",
 			name, (long long)since_epoch, (long long)sys_epoch,
 			diff, slack);
 	} else {
Signature · 5 lines
2.55.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Cyril,

Quoted 1 line · Cyril Hrubis

sys_rtc01: TCONF on system time mismatch when STA_UNSYNC is unset

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Wei Gao on v1 1/1
#2 lore raw
In reply to Cyril Hrubis
Quoted 6 lines · Cyril Hrubis

It turns out that the STA_UNSYNC flag is set at boot and cleared by ntp, so we should skip the TFAIL when the flag is cleared, since that means that NTP have adjusted the system time and it's possibly out of sync with RTC.

Fixes 3d11e5dd622e "sys_rtc01: Report TCONF on system time mismatch when STA_UNSYNC is set"

Very nit comments:
Standard Fixes tag syntax encloses the commit title in parentheses:

Fixes 3d11e5dd622e ("sys_rtc01: Report TCONF on system time mismatch when STA_UNSYNC is set")
Quoted 60 lines
---
 testcases/kernel/sysfs/class/rtc/sys_rtc01.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
testcases/kernel/sysfs/class/rtc/sys_rtc01.c +7 -10
index 0e1c69f95..4857d4a8b 100644
@@ -43,12 +43,9 @@
  * test performs, so on a long-running system a purely fixed slack would
  * eventually produce false failures even on perfectly healthy hardware.
  *
- * If the system was booted with an RTC that was off the current time and the
- * system clock was later stepped in userspace via :manpage:`clock_settime(2)`
- * or :manpage:`settimeofday(2)` without updating the RTC, the kernel sets
- * STA_UNSYNC and CONFIG_RTC_SYSTOHC does not write the system clock back to
- * the RTC while hctosys remains 1. Report TCONF instead of TFAIL when
- * since_epoch diverges from system time while STA_UNSYNC is set.
+ * If system time was corrected by NTP the kernel clears STA_UNSYNC flag.
+ * Report TCONF instead of TFAIL when since_epoch diverges from system time
+ * when STA_UNSYNC is not set.
  *
  * Under virtualization the slack is additionally multiplied, since a VM's
  * clock (and thus its emulated RTC) commonly lags real time by tens of
@@ -112,14 +109,14 @@ static long read_hctosys(const char *name)
 	return TST_SYSFS_READ_LI(PATH_CLASS_RTC "/%s/hctosys", name);
 }
 
-static int is_clock_unsynced(void)
+static int clock_is_synced(void)
 {
 	struct timex tx = { .modes = 0 };
 
 	if (adjtimex(&tx) == -1)
 		tst_brk(TBROK | TERRNO, "adjtimex() failed");
 
-	return !!(tx.status & STA_UNSYNC);
+	return !(tx.status & STA_UNSYNC);
 }
 
 static void read_rtc_snapshot(const char *name, char *date, size_t date_size,
@@ -217,9 +214,9 @@ static void check_rtc(const char *name, int any_hctosys)
 			"%s: since_epoch (%lld), system time (%lld), diff %llds <= slack %lds",
 			name, (long long)since_epoch, (long long)sys_epoch,
 			diff, slack);
-	} else if (is_clock_unsynced()) {
+	} else if (clock_is_synced()) {
 		tst_res(TCONF,
-			"%s: since_epoch (%lld), system time (%lld), diff %llds > slack %lds (STA_UNSYNC is set)",
+			"%s: since_epoch (%lld), system time (%lld), diff %llds > slack %lds (STA_UNSYNC is not set)",
 			name, (long long)since_epoch, (long long)sys_epoch,
 			diff, slack);
 	} else {
Signature · 5 lines
2.55.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp