[LTP] [PATCH] clock_gettime04: Retry on transient preemption delays
Wake Liu
wakel@google.com
Mon Nov 16 07:31:53 CET 2026
clock_gettime04 performs 10,000 iterations of back-to-back clock
readings across multiple syscall and vDSO variants, requiring every
consecutive pair of readings to be within 5 ms. On preemptible kernels,
if the test process is preempted or migrated by the scheduler between
two readings, the elapsed off-CPU time can exceed 5 ms and cause a
false failure even when all clock interfaces are accurate.
Unlike a persistent vDSO synchronization bug (such as 5b43bd184530), a
scheduler preemption spike is transient. Allow up to 10 retries per
clock by repeating the current iteration when a reading gap exceeds
delta, failing only if the discrepancy persists.
Signed-off-by: Wake Liu <wakel@google.com>
---
testcases/kernel/syscalls/clock_gettime/clock_gettime04.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c
index ca6c42d14..ead68d1c2 100644
--- a/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime04.c
@@ -107,7 +107,7 @@ static void run(unsigned int i)
struct tst_ts ts;
long long start, end = 0, diff, slack;
struct time64_variants *tv;
- int count = 10000, ret;
+ int count = 10000, retries = 10, ret;
unsigned int j;
if (clks[i] == CLOCK_REALTIME_COARSE || clks[i] == CLOCK_MONOTONIC_COARSE)
@@ -166,6 +166,12 @@ static void run(unsigned int i)
diff /= 1000000;
if (diff >= delta) {
+ if (retries > 0) {
+ retries--;
+ count++;
+ break;
+ }
+
tst_res(TFAIL, "%s(%s): Difference between successive readings greater than %lld ms (%d): %lld",
tst_clock_name(clks[i]), tv->desc, delta, j, diff);
return;
--
2.56.0.611.g1030f0b940-goog
More information about the ltp
mailing list