From patchwork Mon Jul 3 10:14:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9822415 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 A90D2603FB for ; Mon, 3 Jul 2017 10:14:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BF212810E for ; Mon, 3 Jul 2017 10:14:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90CBB2811A; Mon, 3 Jul 2017 10:14:27 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 E921C28505 for ; Mon, 3 Jul 2017 10:14:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 110876E0DF; Mon, 3 Jul 2017 10:14:25 +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 D3F8F89FAD for ; Mon, 3 Jul 2017 10:14:23 +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 7571757-1500050 for multiple; Mon, 03 Jul 2017 11:14:20 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Mon, 03 Jul 2017 11:14:19 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Mon, 3 Jul 2017 11:14:12 +0100 Message-Id: <20170703101412.30820-4-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170703101412.30820-1-chris@chris-wilson.co.uk> References: <20170703101412.30820-1-chris@chris-wilson.co.uk> X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Subject: [Intel-gfx] [PATCH 4/4] drm/i915: Make fence->pin_count atomic to allow unlocked unpinning 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 When we unpin a fence, we do no other operation than mark it available. This we can do outside of any locking by making the operation atomic. Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/gvt/aperture_gm.c | 2 +- drivers/gpu/drm/i915/i915_debugfs.c | 2 +- drivers/gpu/drm/i915/i915_gem_fence_reg.c | 15 ++++++++------- drivers/gpu/drm/i915/i915_gem_fence_reg.h | 2 +- drivers/gpu/drm/i915/i915_vma.h | 9 ++++++--- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/aperture_gm.c b/drivers/gpu/drm/i915/gvt/aperture_gm.c index 325618d969fe..c34cd56eb83a 100644 --- a/drivers/gpu/drm/i915/gvt/aperture_gm.c +++ b/drivers/gpu/drm/i915/gvt/aperture_gm.c @@ -196,7 +196,7 @@ static int alloc_vgpu_fence(struct intel_vgpu *vgpu) i = 0; list_for_each_safe(pos, q, &dev_priv->mm.fence_list) { reg = list_entry(pos, struct drm_i915_fence_reg, link); - if (reg->pin_count || reg->vma) + if (atomic_read(®->pin_count) || reg->vma) continue; list_del(pos); vgpu->fence.regs[i] = reg; diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index 9fdafed9a601..cee9d2e8832e 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -965,7 +965,7 @@ static int i915_gem_fence_regs_info(struct seq_file *m, void *data) struct i915_vma *vma = dev_priv->fence_regs[i].vma; seq_printf(m, "Fence %d, pin count = %d, object = ", - i, dev_priv->fence_regs[i].pin_count); + i, atomic_read(&dev_priv->fence_regs[i].pin_count)); if (!vma) seq_puts(m, "unused"); else diff --git a/drivers/gpu/drm/i915/i915_gem_fence_reg.c b/drivers/gpu/drm/i915/i915_gem_fence_reg.c index d0cd051c19fd..02d487c44a77 100644 --- a/drivers/gpu/drm/i915/i915_gem_fence_reg.c +++ b/drivers/gpu/drm/i915/i915_gem_fence_reg.c @@ -340,7 +340,7 @@ int i915_vma_put_fence(struct i915_vma *vma) GEM_BUG_ON(fence->vma != vma); - if (fence->pin_count) + if (atomic_read(&fence->pin_count)) return -EBUSY; return fence_update(fence, NULL); @@ -353,7 +353,7 @@ static struct drm_i915_fence_reg *fence_find(struct drm_i915_private *dev_priv) list_for_each_entry(fence, &dev_priv->mm.fence_list, link) { GEM_BUG_ON(fence->vma && fence->vma->fence != fence); - if (fence->pin_count) + if (atomic_read(&fence->pin_count)) continue; return fence; @@ -400,7 +400,7 @@ i915_vma_pin_fence(struct i915_vma *vma) fence = vma->fence; if (fence) { GEM_BUG_ON(fence->vma != vma); - fence->pin_count++; + atomic_inc(&fence->pin_count); if (!fence->dirty) { err = i915_gem_active_retire(&fence->pipelined, &fence->i915->drm.struct_mutex); @@ -415,7 +415,8 @@ i915_vma_pin_fence(struct i915_vma *vma) fence = fence_find(vma->vm->i915); if (IS_ERR(fence)) return PTR_ERR(fence); - fence->pin_count++; + + atomic_inc(&fence->pin_count); } else return 0; @@ -426,7 +427,7 @@ i915_vma_pin_fence(struct i915_vma *vma) return 0; err_unpin: - fence->pin_count--; + atomic_dec(&fence->pin_count); return err; } @@ -459,7 +460,7 @@ int i915_vma_reserve_fence(struct i915_vma *vma) fence->vma = vma; fence->dirty = true; } - fence->pin_count++; + atomic_inc(&fence->pin_count); list_move_tail(&fence->link, &fence->i915->mm.fence_list); GEM_BUG_ON(!i915_gem_object_is_tiled(vma->obj)); @@ -478,7 +479,7 @@ int i915_vma_emit_pipelined_fence(struct i915_vma *vma, int err; lockdep_assert_held(&vma->vm->i915->drm.struct_mutex); - GEM_BUG_ON(fence && !fence->pin_count); + GEM_BUG_ON(fence && !atomic_read(&fence->pin_count)); if (!fence) goto out; diff --git a/drivers/gpu/drm/i915/i915_gem_fence_reg.h b/drivers/gpu/drm/i915/i915_gem_fence_reg.h index ce45972fc5c6..f69d894997fb 100644 --- a/drivers/gpu/drm/i915/i915_gem_fence_reg.h +++ b/drivers/gpu/drm/i915/i915_gem_fence_reg.h @@ -36,7 +36,7 @@ struct drm_i915_fence_reg { struct list_head link; struct drm_i915_private *i915; struct i915_vma *vma; - int pin_count; + atomic_t pin_count; int id; /** * Whether the tiling parameters for the currently diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h index f0dc6eaebeab..9d95fdae017c 100644 --- a/drivers/gpu/drm/i915/i915_vma.h +++ b/drivers/gpu/drm/i915/i915_vma.h @@ -347,8 +347,8 @@ int __must_check i915_vma_put_fence(struct i915_vma *vma); static inline void __i915_vma_unpin_fence(struct i915_vma *vma) { - GEM_BUG_ON(vma->fence->pin_count <= 0); - vma->fence->pin_count--; + GEM_BUG_ON(atomic_read(&vma->fence->pin_count) <= 0); + atomic_dec(&vma->fence->pin_count); } /** @@ -362,7 +362,10 @@ static inline void __i915_vma_unpin_fence(struct i915_vma *vma) static inline void i915_vma_unpin_fence(struct i915_vma *vma) { - lockdep_assert_held(&vma->obj->base.dev->struct_mutex); + /* The assumption is if the caller has a fence, the caller owns a pin + * on that fence, i.e. that vma->fence cannot become NULL prior to us + * releasing our pin. + */ if (vma->fence) __i915_vma_unpin_fence(vma); }