From patchwork Tue Nov 17 12:18:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonas Lahtinen X-Patchwork-Id: 7636831 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F392ABF90C for ; Tue, 17 Nov 2015 12:18:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 305F1205B1 for ; Tue, 17 Nov 2015 12:18:18 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id F0A60205AA for ; Tue, 17 Nov 2015 12:18:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7A67D6E377; Tue, 17 Nov 2015 04:18:16 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 14ED26E377 for ; Tue, 17 Nov 2015 04:18:15 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 17 Nov 2015 04:18:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,307,1444719600"; d="scan'208";a="687469276" Received: from jlahtine-mobl1.ger.corp.intel.com ([10.252.25.207]) by orsmga003.jf.intel.com with ESMTP; 17 Nov 2015 04:18:13 -0800 From: Joonas Lahtinen To: Intel graphics driver community testing & development Date: Tue, 17 Nov 2015 14:18:09 +0200 Message-Id: <1447762689-3635-1-git-send-email-joonas.lahtinen@linux.intel.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <20151117104021.GW569@nuc-i3427.alporthouse.com> References: <20151117104021.GW569@nuc-i3427.alporthouse.com> Cc: Thomas Wood Subject: [Intel-gfx] [PATCH i-g-t v2] lib/igt_core: Prefer CLOCK_MONOTONIC_RAW X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP CLOCK_MONOTONIC_RAW is not affected by NTP, so it should be THE clock used for timing execution of tests. v2: - Cache the used clock (Chris) - Do not change the clock during execution - Spit out and error if monotonic time can not be read Cc: Thomas Wood Cc: Chris Wilson Signed-off-by: Joonas Lahtinen --- lib/igt_core.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/igt_core.c b/lib/igt_core.c index 04a0ab2..c56bc15 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -220,6 +220,7 @@ static char *run_single_subtest = NULL; static bool run_single_subtest_found = false; static const char *in_subtest = NULL; static struct timespec subtest_time; +static clockid_t igt_clock = (clockid_t)-1; static bool in_fixture = false; static bool test_with_subtests = false; static bool in_atexit_handler = false; @@ -341,10 +342,25 @@ static void gettime(struct timespec *ts) { memset(ts, 0, sizeof(*ts)); + // Stay on the same clock for consistency. + if (igt_clock != (clockid_t)-1) { + clock_gettime(igt_clock, ts); + return; + } + +#ifdef CLOCK_MONOTONIC_RAW + if (!clock_gettime(igt_clock = CLOCK_MONOTONIC_RAW, ts)) + return; +#endif #ifdef CLOCK_MONOTONIC_COARSE - if (clock_gettime(CLOCK_MONOTONIC_COARSE, ts)) + if (!clock_gettime(igt_clock = CLOCK_MONOTONIC_COARSE, ts)) + return; #endif - clock_gettime(CLOCK_MONOTONIC, ts); + if (!clock_gettime(igt_clock = CLOCK_MONOTONIC, ts)) + return; + + igt_warn("Unable to get monotonic time!\n"); + exit(IGT_EXIT_FAILURE); } bool __igt_fixture(void)