Skip to contentSkip to conversation

clock_gettime01: avoid zero exec runtime due to irq and steal time accounting

PATCH New Jan Stancek 2 participants 3 messages Jul 23, 2021 – Jul 28, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clock_gettime01: avoid zero exec runtime due to irq and steal time accounting

Test is sporadically failing on KVM guests with zero-ed timespec returned by CLOCK_{PROCESS,THREAD}_CPUTIME_ID. This can be reproduced on kernels v4.18 and v5.13-rc3 which have IRQ and PARAVIRT TIME ACCOUNTING enabled.

Task exectime is usually updated on call of clock_gettime(). But update_rq_clock_task() may not update clock_task if there's more unaccounted irq or steal time than rq->clock delta since last call. In this instance rq->clock_task does not advance and it is left for next update to account rest. Because LTP test is quick and checks only once, it sometimes sees zero timespec and treats it as failure.

Add a small warm-up to setup() in form of busy loop, to make sure that clock_task advanced. In case of bug we would either hit a timeout or still report zeroed timespec.

---
 .../kernel/syscalls/clock_gettime/clock_gettime01.c      | 9 +++++++++
 1 file changed, 9 insertions(+)
testcases/kernel/syscalls/clock_gettime/clock_gettime01.c +9 -0
index be9573afcc8e..11da39cf07cf 100644
@@ -73,7 +73,15 @@ static struct time64_variants variants[] = {
 
 static void setup(void)
 {
+	long unsigned utime;
+
 	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
+	do {
+		SAFE_FILE_SCANF("/proc/self/stat",
+			"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu",
+			&utime);
+	} while (utime == 0);
 }
 
 static void verify_clock_gettime(unsigned int i)
@@ -118,4 +126,5 @@ static struct tst_test test = {
 	.test_variants = ARRAY_SIZE(variants),
 	.setup = setup,
 	.needs_root = 1,
+	.timeout = 10,
 };
Signature · 1 line
2.27.0