From patchwork Fri Feb 17 21:17:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9580803 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 3608B6049F for ; Fri, 17 Feb 2017 21:18:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 270182878C for ; Fri, 17 Feb 2017 21:18:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A2B82878F; Fri, 17 Feb 2017 21:18: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 1E5422878C for ; Fri, 17 Feb 2017 21:18:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0F7E76E027; Fri, 17 Feb 2017 21:18:02 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id C13D26E027 for ; Fri, 17 Feb 2017 21:18:00 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id i10so6483715wrb.0 for ; Fri, 17 Feb 2017 13:18:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=CgGwTW9yZAKs2cpfdFqUSjRcXHrNCu06K+wkX/AhUXE=; b=ZLzc0hgmCwsu5XgyYYq1e4zgyek+rb/deDg5oRtFeiPUi6OwZzmpMxEOGv+YxxDK8u OnqOPX/qVfMFtCN3trtkSZtoS0qRij2Ke2cDvSKKWTEhf3oodKkz8ydIgiO+oJ5twKuh aYrD9ALfT9PTLlcyZOXnzQmdQmflPJwZH339B2fuLkHmtgk9rEXQPNRLEEp9guf942Ck q8li+AcOxKpXv0KhALBvGscwLdT06fTFfKobqh9FE6iBMrlT/EhhTJoeV12aRypfnZ5+ /wPckFDNHaswnQ4bFqDoaX6TlDvTJ187VNSbS9TznTNpNQ+g5jx5MjRruBwgRqxRDeSZ 3b0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=CgGwTW9yZAKs2cpfdFqUSjRcXHrNCu06K+wkX/AhUXE=; b=XlNjoqGDRptP59L8zP75ftGu6eI+kgsmZ+6VEwHRmIxf+1CqbSwudwbjAPLaaXjV+2 pssIpb1eariYSKdj5aoMB7o149gEXggq0PukQGoHAOYpQ/eOc6lslPRb74vWx0HiyIkt +wVYVf2IqmsPD4wbryhQmEUf+GxsEWaDxKYehqs2B48VLq1dztkENjG0PWw8DviPHY0k COVLMtNSArpO8uFHDjvQnJe8hybemdwGXe2VNnOXUlQCXKS14ovZJ1js7P0+Snwu4/N9 JoWRiRqgJLcpb9V4IcrJMQUSYCpR7RzI0c7jdalXCMgV01KVGXLQPin7XVtv32eQcsVc jAJA== X-Gm-Message-State: AMke39kP+qEgjeAAgMja6QOj0/7+ofGKIeAUZODIiFa5owBMADjxZUKqgLKWsU2QfzuDjg== X-Received: by 10.223.130.114 with SMTP id 105mr1948287wrb.41.1487366279184; Fri, 17 Feb 2017 13:17:59 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id o59sm14210752wrc.56.2017.02.17.13.17.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 13:17:58 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Fri, 17 Feb 2017 21:17:57 +0000 Message-Id: <20170217211757.1900-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 Cc: Jason Ekstrand Subject: [Intel-gfx] [RFC] drm/i915: Extract the in-fence from a dma-buf reservation object 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 The dma-buf holds an array of fences, which unlike the sync_file are not sealed and may be modified at runtime. For the purpose of computing dependencies, we can take a snapshot of the fences within the dma-buf's reservation object (converting them into a fence-array) and uses that as our input fence to this execbuf. It also provides a means for us to pass in an array of fences and ask to only wait on the first being signaled. In short, it allows dma-buf to be used as a *reusable* container for multiple signaling objects, and for scheduling execbuf between clients. Signed-off-by: Chris Wilson Cc: Tvrtko Ursulin Cc: Mika Kuoppala Cc: Joonas Lahtinen Cc: Jason Ekstrand Cc: Gustavo Padovan --- drivers/gpu/drm/i915/i915_drv.c | 1 + drivers/gpu/drm/i915/i915_gem_execbuffer.c | 57 ++++++++++++++++++++++++++++-- include/uapi/drm/i915_drm.h | 26 ++++++++++++-- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 43da9cf65233..de8f40b0bd58 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -352,6 +352,7 @@ static int i915_getparam(struct drm_device *dev, void *data, case I915_PARAM_HAS_EXEC_SOFTPIN: case I915_PARAM_HAS_EXEC_ASYNC: case I915_PARAM_HAS_EXEC_FENCE: + case I915_PARAM_HAS_EXEC_FENCE_DMABUF: /* For the time being all of these are always true; * if some supported hardware does not have one of these * features this value needs to be provided from diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index da0846fe2ad6..957d57524483 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -26,6 +26,7 @@ * */ +#include #include #include #include @@ -1576,6 +1577,44 @@ eb_select_engine(struct drm_i915_private *dev_priv, return engine; } +static struct dma_fence * +dma_buf_get_fence(int fd, unsigned int flags) +{ + struct dma_buf *dmabuf; + struct dma_fence_array *array; + struct dma_fence **shared, *excl; + unsigned int count, i; + + dmabuf = dma_buf_get(fd); + if (IS_ERR(dmabuf)) + return ERR_CAST(dmabuf); + + shared = NULL; + count = 0; + if (flags & I915_EXEC_FENCE_EXCL) { + excl = reservation_object_get_excl_rcu(obj->resv); + } else { + if (reservation_object_get_fences_rcu(dmabuf->resv, + &excl, &count, &shared)) + goto out_put; + } + + if (excl) + array = dma_fence_array_create(1, &excl, 0, 0, false); + else if (shared) + array = dma_fence_array_create(count, shared, 0, 0, + flags & I915_EXEC_FENCE_ANY); + else + array = NULL; + + for (i = 0 ; i < count; i++) + dma_fence_put(shared[i]); + kfree(shared); +out_put: + dma_buf_put(dmabuf); + return &array->base; +} + static int i915_gem_do_execbuffer(struct drm_device *dev, void *data, struct drm_file *file, @@ -1640,9 +1679,21 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, } if (args->flags & I915_EXEC_FENCE_IN) { - in_fence = sync_file_get_fence(lower_32_bits(args->rsvd2)); - if (!in_fence) - return -EINVAL; + int fd = lower_32_bits(args->rsvd2); + + in_fence = dma_buf_get_fence(fd, args->flags); + if (IS_ERR(in_fence)) { + if (in_fence == ERR_PTR(-EINVAL)) { + if (args->flags & (I915_EXEC_FENCE_ANY | I915_EXEC_FENCE_EXCL)) + return -EINVAL; + + in_fence = sync_file_get_fence(fd); + if (!in_fence) + return -EINVAL; + } else { + return PTR_ERR(in_fance); + } + } } if (args->flags & I915_EXEC_FENCE_OUT) { diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index 3554495bef13..ebc7641b5252 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -412,6 +412,12 @@ typedef struct drm_i915_irq_wait { */ #define I915_PARAM_HAS_EXEC_FENCE 44 +/* Query whether DRM_I915_GEM_EXECBUFFER2 supports using a dma-buf fd as the + * in-fence for explicit fence support. See I915_EXEC_FENCE_IN and + * I915_EXEC_FENCE_ANY. + */ +#define I915_PARAM_HAS_EXEC_FENCE_DMABUF 45 + typedef struct drm_i915_getparam { __s32 param; /* @@ -865,8 +871,8 @@ struct drm_i915_gem_execbuffer2 { #define I915_EXEC_RESOURCE_STREAMER (1<<15) /* Setting I915_EXEC_FENCE_IN implies that lower_32_bits(rsvd2) represent - * a sync_file fd to wait upon (in a nonblocking manner) prior to executing - * the batch. + * a sync_file or dma-buf fd to wait upon (in a nonblocking manner) prior + * to executing the batch. * * Returns -EINVAL if the sync_file fd cannot be found. */ @@ -889,7 +895,21 @@ struct drm_i915_gem_execbuffer2 { */ #define I915_EXEC_FENCE_OUT (1<<17) -#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_FENCE_OUT<<1)) +/* If the I915_EXEC_FENCE_IN refers to a dma-buf fd, a fence is created from + * its reservation object and it may contain just the exclusive fence, or + * an array of all shared fences. Setting I915_EXEC_FENCE_EXCL implies that + * the execbuf should only wait for the current exclusive fence to be signaled + * before execution. + */ +#define I915_EXEC_FENCE_EXCL (1<<18) + +/* If the I915_EXEC_FENCE_IN refers to a dma-buf fd, a fence is created from + * its reservation object and it may either be signaled on the first fence + * within to complet or it may wait for all fences within to be complete. + */ +#define I915_EXEC_FENCE_ANY (1<<19) + +#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_FENCE_ANY<<1)) #define I915_EXEC_CONTEXT_ID_MASK (0xffffffff) #define i915_execbuffer2_set_context_id(eb2, context) \