From patchwork Mon May 4 19:31:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11527479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61C33912 for ; Mon, 4 May 2020 19:31:24 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A12520705 for ; Mon, 4 May 2020 19:31:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A12520705 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DF93B89487; Mon, 4 May 2020 19:31:22 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id E077F893D0; Mon, 4 May 2020 19:31:20 +0000 (UTC) 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 21111043-1500050 for multiple; Mon, 04 May 2020 20:31:15 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Mon, 4 May 2020 20:31:12 +0100 Message-Id: <20200504193112.2382452-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t] i915/gem_ctx_exec: Exploit resource contention to verify execbuf independence X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, Chris Wilson Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Even if one client is blocked on a resource, that should not impact another client. Signed-off-by: Chris Wilson --- tests/i915/gem_ctx_exec.c | 122 +++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/tests/i915/gem_ctx_exec.c b/tests/i915/gem_ctx_exec.c index ad2f9e545..d7cd56424 100644 --- a/tests/i915/gem_ctx_exec.c +++ b/tests/i915/gem_ctx_exec.c @@ -35,8 +35,9 @@ #include #include #include -#include #include +#include +#include #include #include @@ -331,6 +332,122 @@ static void nohangcheck_hostile(int i915) close(i915); } +static void kill_children(int sig) +{ + sighandler_t old; + + old = signal(sig, SIG_IGN); + kill(-getpgrp(), sig); + signal(sig, old); +} + +static bool has_persistence(int i915) +{ + struct drm_i915_gem_context_param p = { + .param = I915_CONTEXT_PARAM_PERSISTENCE, + }; + uint64_t saved; + + if (__gem_context_get_param(i915, &p)) + return false; + + saved = p.value; + p.value = 0; + if (__gem_context_set_param(i915, &p)) + return false; + + p.value = saved; + return __gem_context_set_param(i915, &p) == 0; +} + +static void pi_active(int i915) +{ + igt_spin_t *spin = igt_spin_new(i915); + unsigned long count = 0; + bool blocked = false; + struct pollfd pfd; + int lnk[2]; + int *done; + + igt_require(gem_scheduler_enabled(i915)); + igt_require(has_persistence(i915)); /* for graceful error recovery */ + + done = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + igt_assert(done != MAP_FAILED); + + igt_assert(pipe(lnk) == 0); + + igt_fork(child, 1) { + struct sigaction sa = { .sa_handler = alarm_handler }; + + sigaction(SIGHUP, &sa, NULL); + + do { + uint32_t ctx; + + if (__gem_context_clone(i915, 0, + I915_CONTEXT_CLONE_ENGINES | + I915_CONTEXT_CLONE_VM, + 0, &ctx)) + break; + + gem_context_set_persistence(i915, ctx, false); + if (READ_ONCE(*done)) + break; + + spin->execbuf.rsvd1 = ctx; + if (__execbuf(i915, &spin->execbuf)) + break; + + count++; + write(lnk[1], &count, sizeof(count)); + } while (1); + } + + pfd.fd = lnk[0]; + pfd.events = POLLIN; + close(lnk[1]); + + igt_until_timeout(90) { + if (poll(&pfd, 1, 1000) == 0) { + igt_info("Child blocked after %lu active contexts\n", + count); + blocked = true; + break; + } + read(pfd.fd, &count, sizeof(count)); + } + + if (blocked) { + struct sigaction old_sa, sa = { .sa_handler = alarm_handler }; + struct itimerval itv; + + sigaction(SIGALRM, &sa, &old_sa); + itv.it_value.tv_sec = 0; + itv.it_value.tv_usec = 250000; /* 250ms */ + setitimer(ITIMER_REAL, &itv, NULL); + + igt_assert_f(__execbuf(i915, &spin->execbuf) == 0, + "Active execbuf blocked for more than 250ms by %lu child contexts\n", + count); + + memset(&itv, 0, sizeof(itv)); + setitimer(ITIMER_REAL, &itv, NULL); + sigaction(SIGALRM, &old_sa, NULL); + } else { + igt_info("Not blocked after %lu active contexts\n", + count); + } + + *done = 1; + kill_children(SIGHUP); + igt_waitchildren(); + gem_quiescent_gpu(i915); + close(lnk[0]); + + munmap(done, 4096); +} + igt_main { const uint32_t batch[2] = { 0, MI_BATCH_BUFFER_END }; @@ -375,6 +492,9 @@ igt_main igt_subtest("basic-nohangcheck") nohangcheck_hostile(fd); + igt_subtest("basic-pi-active") + pi_active(fd); + igt_subtest("reset-pin-leak") { int i;