From patchwork Wed Jun 17 17:37:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 6627361 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 200379F1C1 for ; Wed, 17 Jun 2015 17:37:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1AFCA20856 for ; Wed, 17 Jun 2015 17:37:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 127012084B for ; Wed, 17 Jun 2015 17:37:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 91F8E6EAED; Wed, 17 Jun 2015 10:37:38 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [87.106.93.118]) by gabe.freedesktop.org (Postfix) with ESMTP id 5574D6EAED for ; Wed, 17 Jun 2015 10:37:37 -0700 (PDT) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 41208537-1500048 for multiple; Wed, 17 Jun 2015 18:37:48 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Wed, 17 Jun 2015 18:37:30 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 17 Jun 2015 18:37:29 +0100 Message-Id: <1434562649-359-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Cc: Daniel Vetter Subject: [Intel-gfx] [PATCH] igt: Add gem_eio for inducing expected EIO 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=-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 A few entry points in the GEM API are expected to raise EIO if we encounter a wedged GPU. This testcase aims to do so by first injecting a GPU hang with GPU resets disabled (thus causing the GPU to become wedged) and then exercises the various API to check for the expected errors. Signed-off-by: Chris Wilson --- tests/Makefile.sources | 1 + tests/gem_eio.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 tests/gem_eio.c diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 551c600..15d8382 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -20,6 +20,7 @@ TESTS_progs_M = \ gem_ctx_bad_exec \ gem_ctx_exec \ gem_dummy_reloc_loop \ + gem_eio \ gem_evict_alignment \ gem_evict_everything \ gem_exec_bad_domains \ diff --git a/tests/gem_eio.c b/tests/gem_eio.c new file mode 100644 index 0000000..8c85e3a --- /dev/null +++ b/tests/gem_eio.c @@ -0,0 +1,168 @@ +/* + * Copyright © 2015 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +/* + * Testcase: Test that ioctl report a wedged GPU. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "drmtest.h" +#include "ioctl_wrappers.h" +#include "igt_core.h" +#include "igt_aux.h" +#include "igt_gt.h" + +IGT_TEST_DESCRIPTION("Test that ioctls report a wedged GPU (EIO)."); + +static bool gpu_reset_control(bool enable) +{ + const char *path = "/sys/module/i915/parameters/reset"; + int fd, ret; + + igt_debug("%s GPU reset\n", enable ? "Enabling" : "Disabling"); + + fd = open(path, O_RDWR); + igt_require(fd >= 0); + + ret = write(fd, &"NY"[enable], 1); + close(fd); + + return ret == 1; +} + +static bool gpu_wedged_control(void) +{ + int fd, ret; + + igt_debug("Triggering GPU reset\n"); + + fd = igt_debugfs_open("i915_wedged", O_RDWR); + igt_require(fd >= 0); + + ret = write(fd, "1\n", 2) == 2; + close(fd); + + return ret; +} + +static void trigger_reset(int fd) +{ + igt_assert(gpu_wedged_control()); + + /* And just check the gpu is indeed running again */ + gem_quiescent_gpu(fd); +} + +static int throttle(int fd) +{ + int err = 0; + if (drmIoctl(fd, DRM_IOCTL_I915_GEM_THROTTLE, NULL)) + err = -errno; + return err; +} + +static void wedge_gpu(int fd) +{ + igt_hang_ring_t hang; + + igt_debug("Wedging GPU by injecting hang\n"); + igt_require(gpu_reset_control(false)); + hang = igt_hang_ring(fd, I915_EXEC_DEFAULT); + + igt_debug("Waiting for GPU hang\n"); + igt_post_hang_ring(fd, hang); + igt_assert(gpu_reset_control(true)); +} + +static void test_throttle(int fd) +{ + wedge_gpu(fd); + + igt_assert_eq(throttle(fd), -EIO); + + trigger_reset(fd); +} + +static int __gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *eb) +{ + int err = 0; + if (drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, eb)) + err = -errno; + return err; +} + +static void test_execbuf(int fd) +{ + struct drm_i915_gem_execbuffer2 execbuf; + struct drm_i915_gem_exec_object2 exec; + uint32_t tmp[] = { MI_BATCH_BUFFER_END }; + + memset(&exec, 0, sizeof(exec)); + memset(&execbuf, 0, sizeof(execbuf)); + + exec.handle = gem_create(fd, 4096); + gem_write(fd, exec.handle, 0, tmp, sizeof(tmp)); + + execbuf.buffers_ptr = (uintptr_t)&exec; + execbuf.buffer_count = 1; + + wedge_gpu(fd); + + igt_assert_eq(__gem_execbuf(fd, &execbuf), -EIO); + gem_close(fd, exec.handle); + + trigger_reset(fd); +} + +igt_main +{ + int fd; + + igt_skip_on_simulation(); + + igt_fixture { + fd = drm_open_any(); + igt_require_hang_ring(fd, -1); + } + + igt_subtest("throttle") + test_throttle(fd); + + igt_subtest("execbuf") + test_execbuf(fd); + + igt_fixture + close(fd); +}