All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] clock_gettime01: avoid zero exec runtime due to irq and steal time accounting
@ 2021-07-23 13:19 Jan Stancek
  2021-07-23 15:09 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Stancek @ 2021-07-23 13:19 UTC (permalink / raw)
  To: ltp

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(+)

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,
 };
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH] clock_gettime01: avoid zero exec runtime due to irq and steal time accounting
  2021-07-23 13:19 [LTP] [PATCH] clock_gettime01: avoid zero exec runtime due to irq and steal time accounting Jan Stancek
@ 2021-07-23 15:09 ` Cyril Hrubis
  2021-07-28 11:27   ` Jan Stancek
  0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2021-07-23 15:09 UTC (permalink / raw)
  To: ltp

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

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [LTP] [PATCH] clock_gettime01: avoid zero exec runtime due to irq and steal time accounting
  2021-07-23 15:09 ` Cyril Hrubis
@ 2021-07-28 11:27   ` Jan Stancek
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Stancek @ 2021-07-28 11:27 UTC (permalink / raw)
  To: ltp

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210728/6e8cc8a8/attachment.htm>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-28 11:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 13:19 [LTP] [PATCH] clock_gettime01: avoid zero exec runtime due to irq and steal time accounting Jan Stancek
2021-07-23 15:09 ` Cyril Hrubis
2021-07-28 11:27   ` Jan Stancek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.