This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Fix time/tst-cpuclock1 intermitent failures
- From: "Lucas A. M. Magalhaes" <lamm at linux dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Date: Tue, 28 Jan 2020 14:02:29 -0300
- Subject: [PATCH] Fix time/tst-cpuclock1 intermitent failures
- References: <157987065952.20871.5636395108788791350@localhost.localdomain>
This test fails intermittently in systems with heavy load as
CLOCK_PROCESS_CPUTIME_ID is subject to scheduler pressure. Thus the
test boundaries where relaxed to keep it from fail on this systems.
--
Hi,
I tried to implement the solution suggested by Adhemerval and it worked
fine on my tests.
The curious thing I had much more problems with nanosleep returning a
lot earlier then expected. On the 1s sleep it many times returned in
0.2s for a heavy loaded system.
time/tst-cpuclock1.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/time/tst-cpuclock1.c b/time/tst-cpuclock1.c
index 0120906f23..4968038207 100644
--- a/time/tst-cpuclock1.c
+++ b/time/tst-cpuclock1.c
@@ -157,14 +157,17 @@ do_test (void)
struct timespec diff = { .tv_sec = after.tv_sec - before.tv_sec,
.tv_nsec = after.tv_nsec - before.tv_nsec };
+ /* In ideal scheduler pressure this diff should be closer to 0.5s. But in
+ a heavy loaded system the scheduler pressure can make this times to be
+ uncertain. That's why the upper bound is 0.7s and there is no lower bound
+ */
if (diff.tv_nsec < 0)
{
--diff.tv_sec;
diff.tv_nsec += 1000000000;
}
if (diff.tv_sec != 0
- || diff.tv_nsec > 600000000
- || diff.tv_nsec < 100000000)
+ || diff.tv_nsec > 700000000)
{
printf ("before - after %ju.%.9ju outside reasonable range\n",
(uintmax_t) diff.tv_sec, (uintmax_t) diff.tv_nsec);
@@ -196,13 +199,15 @@ do_test (void)
{
struct timespec d = { .tv_sec = afterns.tv_sec - after.tv_sec,
.tv_nsec = afterns.tv_nsec - after.tv_nsec };
+ /* scheduler pressure may affect sleep time so this test have relaxed
+ time restrictions. */
if (d.tv_nsec < 0)
{
--d.tv_sec;
d.tv_nsec += 1000000000;
}
if (d.tv_sec > 0
- || d.tv_nsec < sleeptime.tv_nsec
+ || d.tv_nsec < 100000000
|| d.tv_nsec > sleeptime.tv_nsec * 2)
{
printf ("nanosleep time %ju.%.9ju outside reasonable range\n",
--
2.20.1