From patchwork Thu Jul 16 10:37:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 6805971 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 0E749C05AC for ; Thu, 16 Jul 2015 10:39:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D1AD2207C1 for ; Thu, 16 Jul 2015 10:39:38 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id AA82B207BF for ; Thu, 16 Jul 2015 10:39:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 21E956EC3A; Thu, 16 Jul 2015 03:39:36 -0700 (PDT) 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 00B176EC3A for ; Thu, 16 Jul 2015 03:39:33 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 16 Jul 2015 03:39:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,487,1432623600"; d="scan'208";a="763707056" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by fmsmga002.fm.intel.com with ESMTP; 16 Jul 2015 03:39:27 -0700 Received: from mwiniars-desk1.igk.intel.com (172.28.173.140) by IRSMSX103.ger.corp.intel.com (163.33.3.157) with Microsoft SMTP Server id 14.3.224.2; Thu, 16 Jul 2015 11:39:25 +0100 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Thu, 16 Jul 2015 12:37:55 +0200 Message-ID: <1437043075-812-1-git-send-email-michal.winiarski@intel.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1437037619-32743-1-git-send-email-michal.winiarski@intel.com> References: <1437037619-32743-1-git-send-email-michal.winiarski@intel.com> MIME-Version: 1.0 X-Originating-IP: [172.28.173.140] Subject: [Intel-gfx] [PATCH v2] tests/gem_reg_read: Extend and check for valid 36b counter 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: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.5 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 When reading the timestamp register with single 64b read, we are observing invalid values on x86_64: [f = valid counter value | X = garbage] i386: 0x0000000fffffffff x86_64: 0xffffffffXXXXXXXX Test checks if the counter is moving and increasing. Add a check to see if we can use (reg | 1) flag to get a proper 36b timestamp, shifting the value on x86_64 if we can't. v2: More iterations of monotonic test, comments, minor fixups (Chris) Cc: Chris Wilson Signed-off-by: Micha? Winiarski --- tests/gem_reg_read.c | 137 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 116 insertions(+), 21 deletions(-) diff --git a/tests/gem_reg_read.c b/tests/gem_reg_read.c index d3e68d9..b512866 100644 --- a/tests/gem_reg_read.c +++ b/tests/gem_reg_read.c @@ -28,10 +28,15 @@ #include #include #include +#include +#include #include "ioctl_wrappers.h" #include "drmtest.h" +static bool is_x86_64; +static bool has_proper_timestamp; + struct local_drm_i915_reg_read { __u64 offset; __u64 val; /* Return value */ @@ -39,39 +44,129 @@ struct local_drm_i915_reg_read { #define REG_READ_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x31, struct local_drm_i915_reg_read) -static uint64_t timer_query(int fd) +#define RENDER_RING_TIMESTAMP 0x2358 + +static int read_register(int fd, uint64_t offset, uint64_t * val) { + int ret; struct local_drm_i915_reg_read reg_read; + reg_read.offset = offset; - reg_read.offset = 0x2358; - igt_fail_on_f(drmIoctl(fd, REG_READ_IOCTL, ®_read), - "positive test case failed: "); + ret = drmIoctl(fd, REG_READ_IOCTL, ®_read); - return reg_read.val; + *val = reg_read.val; + + return ret; } -igt_simple_main +static bool check_kernel_x86_64(void) { - struct local_drm_i915_reg_read reg_read; - int fd, ret; + int ret; + struct utsname uts; - fd = drm_open_any(); + ret = uname(&uts); + igt_assert(ret == 0); - reg_read.offset = 0x2358; - ret = drmIoctl(fd, REG_READ_IOCTL, ®_read); - igt_assert(ret == 0 || errno == EINVAL); - igt_require(ret == 0); + if (!strcmp(uts.machine, "x86_64")) + return true; + + return false; +} + +static bool check_timestamp(int fd) +{ + int ret; + uint64_t val; - reg_read.val = timer_query(fd); + ret = read_register(fd, RENDER_RING_TIMESTAMP | 1, &val); + + return ret == 0; +} + +static uint64_t timer_query(int fd, uint64_t * val) +{ + uint64_t offset; + int ret; + + offset = RENDER_RING_TIMESTAMP; + if (has_proper_timestamp) + offset |= 1; + + ret = read_register(fd, offset, val); + +/* + * When reading the timestamp register with single 64b read, we are observing + * invalid values on x86_64: + * + * [f = valid counter value | X = garbage] + * + * i386: 0x0000000fffffffff + * x86_64: 0xffffffffXXXXXXXX + * + * In the absence of a corrected register read ioctl, attempt + * to fix up the return value to be vaguely useful. + */ + + if (is_x86_64 && !has_proper_timestamp) + *val >>= 32; + + return ret; +} + +static void test_timestamp_moving(int fd) +{ + uint64_t first_val, second_val; + + igt_fail_on(timer_query(fd, &first_val) != 0); sleep(1); - /* Check that timer is moving and isn't busted. */ - igt_assert(timer_query(fd) != reg_read.val); + igt_fail_on(timer_query(fd, &second_val) != 0); + igt_assert(second_val != first_val); +} - /* bad reg */ - reg_read.offset = 0x12345678; - ret = drmIoctl(fd, REG_READ_IOCTL, ®_read); +static void test_timestamp_monotonic(int fd) +{ + uint64_t first_val, second_val; + time_t start; + bool retry = true; + + igt_fail_on(timer_query(fd, &first_val) != 0); + time(&start); + do { +retry: + igt_fail_on(timer_query(fd, &second_val) != 0); + if (second_val < first_val && retry) { + /* We may hit timestamp overflow once */ + retry = false; + first_val = second_val; + goto retry; + } + igt_assert(second_val >= first_val); + } while(difftime(time(NULL), start) < 5); + +} + +igt_main +{ + uint64_t val = 0; + int fd = -1; + + igt_fixture { + fd = drm_open_any(); + is_x86_64 = check_kernel_x86_64(); + has_proper_timestamp = check_timestamp(fd); + } + + igt_subtest("bad-register") + igt_assert(read_register(fd, 0x12345678, &val) == -1 && + errno == EINVAL); + + igt_subtest("timestamp-moving") + test_timestamp_moving(fd); - igt_assert(ret != 0 && errno == EINVAL); + igt_subtest("timestamp-monotonic") + test_timestamp_monotonic(fd); - close(fd); + igt_fixture { + close(fd); + } }