From patchwork Tue Jan 28 17:02:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucas A. M. Magalhaes" X-Patchwork-Id: 37588 X-Patchwork-Delegate: carlos@redhat.com Received: (qmail 57363 invoked by alias); 28 Jan 2020 17:02:35 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 57355 invoked by uid 89); 28 Jan 2020 17:02:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=intermittently, HContent-Transfer-Encoding:8bit X-HELO: mx0a-001b2d01.pphosted.com From: "Lucas A. M. Magalhaes" To: libc-alpha@sourceware.org Subject: [PATCH] Fix time/tst-cpuclock1 intermitent failures Date: Tue, 28 Jan 2020 14:02:29 -0300 Message-Id: <20200128170229.11180-1-lamm@linux.ibm.com> In-Reply-To: <157987065952.20871.5636395108788791350@localhost.localdomain> References: <157987065952.20871.5636395108788791350@localhost.localdomain> MIME-Version: 1.0 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",