From patchwork Fri Dec 22 13:13:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10130467 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9F9716019D for ; Fri, 22 Dec 2017 13:14:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AF4529F17 for ; Fri, 22 Dec 2017 13:14:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F9412A016; Fri, 22 Dec 2017 13:14:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0606329F17 for ; Fri, 22 Dec 2017 13:14:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BF42F6E132; Fri, 22 Dec 2017 13:14:01 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0A9F76E132 for ; Fri, 22 Dec 2017 13:13:59 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id v21so17195815wrc.0 for ; Fri, 22 Dec 2017 05:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=HcImFrfW/ELI3ZdYbfnfDxy5C0VsrPBlq1mMal5h7zA=; b=JI2KXaQC7IZC5F6kTKQ/kMC8+6MM97vomksZTYMGkqdUQ04Q6tsTT77ZjEAhU2V8T2 2M8X9PgbQ2O6fLuQDg2a+SFXi/q7iYQLJyVzBymAV8ln1yXcIbz1ktbVAx0bBVTNwM6D Sz/6lKTseh45+G3ABRwHRzW+RLreEu0HJnlPRCWZzqB7vlYLupXnNgNkMU8ruB5KIdDu vfjX8/0HLhiFmg5VxsEY9pcdCueE/NS4pjiG1Kpw1jEZQdZzDaA0ri8Nv0OsRRJ3tiF6 bHUtK1Td37x+6iCvV/J8giUgMvjz3u+VQq9+H7bO+jHdnrYOjjVa6QZhpDrKQB+Nfmg6 MtWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HcImFrfW/ELI3ZdYbfnfDxy5C0VsrPBlq1mMal5h7zA=; b=N+kYSV4A94ZsPb7laTKAER4ghiL1syw3o09QovXzKeY1jO3YKhjVLkR0JkBWjAbvRd Nz48H/2kPhBoJmjxxD6v9iXtz6XnMN8ujjED2W/f1/HA5IpQrkaJgRb9KrC1Rc8KMStm CMapJl7mHvZSHsBr+qtdod1KmI5CyHNwNnWJ9nfKr7BvzBwyEUYUKaR9XAO8iyHROk4a 7pm97npq7qqClEtAdO/uxaIGe21fPYs4fq6SfNOIHCa1TMyI0YlVsnE1dI2qhFTCRAcY mD48FtUt1smFdH9YbyHrEhfjWEzp5IGAh9/+ylTdz9I4PSbqYnJ406/jCPguH+3lk1xF ueQg== X-Gm-Message-State: AKGB3mKDvJQu9lhZNFSC2T0nQKicd9UDBLVi1nUPc8C+6cIbBMmfklBS sTiYwW2PJg6mS2F4EAgEUVHNp77e X-Google-Smtp-Source: ACJfBov6fNr6lLQ2KM1Qi52Ej+gzXtBnGgGvcUy7JRpixo/pO3HSi3U9R9ekVIIB0IQj41EyefNcXA== X-Received: by 10.223.178.173 with SMTP id g42mr15725779wrd.53.1513948438323; Fri, 22 Dec 2017 05:13:58 -0800 (PST) Received: from localhost.localdomain ([95.146.151.224]) by smtp.gmail.com with ESMTPSA id m68sm17284604wmi.28.2017.12.22.05.13.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Dec 2017 05:13:57 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Fri, 22 Dec 2017 13:13:47 +0000 Message-Id: <20171222131348.19628-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 Subject: [Intel-gfx] [PATCH i-g-t 1/2] lib/dummyload: Support returning output fence 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-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Support creating spin batches which return an output fence using new __igt_spin_batch_new_fence / igt_spin_batch_new_fence API. This will be used fromthe perf_pmu@interrupts test to ensure user interrupt generation from a batch with controlled duration. v2: Support out fence with multiple engines as well. (Chris Wilson) Signed-off-by: Tvrtko Ursulin Cc: Chris Wilson Reviewed-by: Chris Wilson (v1) Reviewed-by: Chris Wilson --- lib/igt_dummyload.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++------ lib/igt_dummyload.h | 10 +++++++ 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c index d19b4e5ea3d2..27eb402bb699 100644 --- a/lib/igt_dummyload.c +++ b/lib/igt_dummyload.c @@ -34,6 +34,7 @@ #include "intel_chipset.h" #include "intel_reg.h" #include "ioctl_wrappers.h" +#include "sw_sync.h" /** * SECTION:igt_dummyload @@ -70,9 +71,9 @@ fill_reloc(struct drm_i915_gem_relocation_entry *reloc, reloc->write_domain = write_domains; } -static void emit_recursive_batch(igt_spin_t *spin, - int fd, uint32_t ctx, unsigned engine, - uint32_t dep) +static int emit_recursive_batch(igt_spin_t *spin, + int fd, uint32_t ctx, unsigned engine, + uint32_t dep, bool out_fence) { #define SCRATCH 0 #define BATCH 1 @@ -82,6 +83,7 @@ static void emit_recursive_batch(igt_spin_t *spin, struct drm_i915_gem_execbuffer2 execbuf; unsigned int engines[16]; unsigned int nengine; + int fence_fd = -1; uint32_t *batch; int i; @@ -165,22 +167,44 @@ static void emit_recursive_batch(igt_spin_t *spin, execbuf.buffers_ptr = to_user_pointer(obj + (2 - execbuf.buffer_count)); execbuf.rsvd1 = ctx; + if (out_fence) + execbuf.flags |= I915_EXEC_FENCE_OUT; + for (i = 0; i < nengine; i++) { execbuf.flags &= ~ENGINE_MASK; - execbuf.flags = engines[i]; - gem_execbuf(fd, &execbuf); + execbuf.flags |= engines[i]; + gem_execbuf_wr(fd, &execbuf); + if (out_fence) { + int _fd = execbuf.rsvd2 >> 32; + + igt_assert(_fd >= 0); + if (fence_fd == -1) { + fence_fd = _fd; + } else { + int old_fd = fence_fd; + + fence_fd = sync_fence_merge(old_fd, _fd); + close(old_fd); + close(_fd); + } + igt_assert(fence_fd >= 0); + } } + + return fence_fd; } -igt_spin_t * -__igt_spin_batch_new(int fd, uint32_t ctx, unsigned engine, uint32_t dep) +static igt_spin_t * +___igt_spin_batch_new(int fd, uint32_t ctx, unsigned engine, uint32_t dep, + int out_fence) { igt_spin_t *spin; spin = calloc(1, sizeof(struct igt_spin)); igt_assert(spin); - emit_recursive_batch(spin, fd, ctx, engine, dep); + spin->out_fence = emit_recursive_batch(spin, fd, ctx, engine, dep, + out_fence); igt_assert(gem_bo_busy(fd, spin->handle)); pthread_mutex_lock(&list_lock); @@ -190,6 +214,12 @@ __igt_spin_batch_new(int fd, uint32_t ctx, unsigned engine, uint32_t dep) return spin; } +igt_spin_t * +__igt_spin_batch_new(int fd, uint32_t ctx, unsigned engine, uint32_t dep) +{ + return ___igt_spin_batch_new(fd, ctx, engine, dep, false); +} + /** * igt_spin_batch_new: * @fd: open i915 drm file descriptor @@ -213,6 +243,36 @@ igt_spin_batch_new(int fd, uint32_t ctx, unsigned engine, uint32_t dep) return __igt_spin_batch_new(fd, ctx, engine, dep); } +igt_spin_t * +__igt_spin_batch_new_fence(int fd, uint32_t ctx, unsigned engine) +{ + return ___igt_spin_batch_new(fd, ctx, engine, 0, true); +} + +/** + * igt_spin_batch_new_fence: + * @fd: open i915 drm file descriptor + * @engine: Ring to execute batch OR'd with execbuf flags. If value is less + * than 0, execute on all available rings. + * + * Start a recursive batch on a ring. Immediately returns a #igt_spin_t that + * contains the batch's handle that can be waited upon. The returned structure + * must be passed to igt_spin_batch_free() for post-processing. + * + * igt_spin_t will contain an output fence associtated with this batch. + * + * Returns: + * Structure with helper internal state for igt_spin_batch_free(). + */ +igt_spin_t * +igt_spin_batch_new_fence(int fd, uint32_t ctx, unsigned engine) +{ + igt_require_gem(fd); + igt_require(gem_has_exec_fence(fd)); + + return __igt_spin_batch_new_fence(fd, ctx, engine); +} + static void notify(union sigval arg) { igt_spin_t *spin = arg.sival_ptr; @@ -295,6 +355,10 @@ void igt_spin_batch_free(int fd, igt_spin_t *spin) gem_munmap(spin->batch, BATCH_SIZE); gem_close(fd, spin->handle); + + if (spin->out_fence >= 0) + close(spin->out_fence); + free(spin); } diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h index 215425f7c6c0..ffa7e351dea3 100644 --- a/lib/igt_dummyload.h +++ b/lib/igt_dummyload.h @@ -35,6 +35,7 @@ typedef struct igt_spin { timer_t timer; struct igt_list link; uint32_t *batch; + int out_fence; } igt_spin_t; igt_spin_t *__igt_spin_batch_new(int fd, @@ -45,6 +46,15 @@ igt_spin_t *igt_spin_batch_new(int fd, uint32_t ctx, unsigned engine, uint32_t dep); + +igt_spin_t *__igt_spin_batch_new_fence(int fd, + uint32_t ctx, + unsigned engine); + +igt_spin_t *igt_spin_batch_new_fence(int fd, + uint32_t ctx, + unsigned engine); + void igt_spin_batch_set_timeout(igt_spin_t *spin, int64_t ns); void igt_spin_batch_end(igt_spin_t *spin); void igt_spin_batch_free(int fd, igt_spin_t *spin);