diff mbox series

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

Message ID 15dd5ab99369da3cba33a748d1bf05be145ef373.1627046193.git.jstancek@redhat.com
State Accepted, archived
Headers show
Series clock_gettime01: avoid zero exec runtime due to irq and steal time accounting | expand

Commit Message

Jan Stancek July 23, 2021, 1:19 p.m. UTC
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.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .../kernel/syscalls/clock_gettime/clock_gettime01.c      | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Cyril Hrubis July 23, 2021, 3:09 p.m. UTC | #1
Hi!
Looks good: Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Jan Stancek July 28, 2021, 11:27 a.m. UTC | #2
On Fri, Jul 23, 2021 at 5:35 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Hi!
> Looks good: Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
>

Thanks for review, pushed.
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c
index be9573afcc8e..11da39cf07cf 100644
--- a/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c
@@ -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,
 };