From patchwork Sat Apr 8 16:26:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9671113 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 4E8F9601EB for ; Sat, 8 Apr 2017 16:26:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FF3728489 for ; Sat, 8 Apr 2017 16:26:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34ED0284F4; Sat, 8 Apr 2017 16:26:14 +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 D7CFB28489 for ; Sat, 8 Apr 2017 16:26:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 10C5088A56; Sat, 8 Apr 2017 16:26:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id B499D6E23A; Sat, 8 Apr 2017 16:26:09 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id u18so15835210wrc.1; Sat, 08 Apr 2017 09:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=0EKjq5M9+xSjbPsQk8j662x4ogB+zz/EHMUGcmR0jw0=; b=eheC4ZSp/udCtAmX7qeDIdds0fFmE3jJgk9nL0rqTr8/8ukh7gaaxeDYPvx0Hn1WHC RtNL67Z8J0gK3fE7TdC16VYwuWuRz2Fm0PGrjg8ATKeHrAJsFOZLzAF4vqcOoegpAVRk u4dQTNHtOJY/g1+QBskIr6duA94jNkfPbGlCsi9vkE7I7in3nIx5YRSTjf6AbKkDVI9S DYWC0VAkGlP9RDvxOTWo+dLpYWJkBkscg5fpIRDVTknj9M6r9l+iY1ulDqV/4V8R1q1l 81xNgcZurF2F1VG/I1+TMHS3QRE8/fKBdy8b2VctWCtkx9J7ARABrQEI+3+cEWKzLXJB hQPA== 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 :in-reply-to:references; bh=0EKjq5M9+xSjbPsQk8j662x4ogB+zz/EHMUGcmR0jw0=; b=P9Ul51KHF8FicoBkFcXKNo11z2tQHhiw8YmJxpvpCjVQKjhR8b1e6/nkXSqtNtSfGV GiWs8QpI1R7PkDhULD/25v+sJONmQLLliCR2dN5gXBG/b6ksMS850PcUNNc1/LCtWEro yVKfaxPrLsBv+/AIv9n8TTakgkkYoMxzJK1EOuhHP94a0KzrYGGyteifNnPl97C/dvxB 41Fzrq/6ho5WcIJyN53c21zUHd9noQPDBBiqPw4IdfyAjlQ+L2584JjfgI+u9Q7B1nrt mQm8vDEWKs3ZBtdbPmbCYhRnYDl9H0oj5e76LQ+LzbKkJLzMk+T1aNfV6zu7WHXrDeYA s5qw== X-Gm-Message-State: AFeK/H2JwTvBSWb/2IGcVRF8P9gwTtBwv82iQ5Zl1rxe78mbSfz+8wSNitsJ7TRgWglFIw== X-Received: by 10.223.155.130 with SMTP id d2mr40765107wrc.67.1491668768189; Sat, 08 Apr 2017 09:26:08 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id 191sm3256856wmv.25.2017.04.08.09.26.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Apr 2017 09:26:07 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm/i915: Squash repeated awaits on the same fence Date: Sat, 8 Apr 2017 17:26:03 +0100 Message-Id: <20170408162603.28305-3-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170408162603.28305-1-chris@chris-wilson.co.uk> References: <20170408162603.28305-1-chris@chris-wilson.co.uk> Cc: Joonas Lahtinen , intel-gfx@lists.freedesktop.org, Tvrtko Ursulin X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Track the latest fence waited upon on each context, and only add a new asynchronous wait if the new fence is more recent than the recorded fence for that context. This requires us to filter out unordered timelines, which are noted by DMA_FENCE_NO_CONTEXT. Signed-off-by: Chris Wilson Cc: Tvrtko Ursulin Cc: Joonas Lahtinen --- drivers/gpu/drm/i915/i915_gem_request.c | 33 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_request.h | 2 ++ lib/radix-tree.c | 1 + 3 files changed, 36 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_gem_request.c b/drivers/gpu/drm/i915/i915_gem_request.c index 313cdff7c6dd..c184f1d26f25 100644 --- a/drivers/gpu/drm/i915/i915_gem_request.c +++ b/drivers/gpu/drm/i915/i915_gem_request.c @@ -606,6 +606,7 @@ i915_gem_request_alloc(struct intel_engine_cs *engine, i915_priotree_init(&req->priotree); + INIT_RADIX_TREE(&req->waits, GFP_KERNEL); INIT_LIST_HEAD(&req->active_list); req->i915 = dev_priv; req->engine = engine; @@ -723,6 +724,27 @@ i915_gem_request_await_dma_fence(struct drm_i915_gem_request *req, if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) return 0; + /* Squash repeated waits to the same timelines, picking the latest */ + if (fence->context != DMA_FENCE_NO_CONTEXT) { + void __rcu **slot; + + slot = radix_tree_lookup_slot(&req->waits, fence->context); + if (!slot) { + ret = radix_tree_insert(&req->waits, + fence->context, fence); + if (ret) + return ret; + } else { + struct dma_fence *old = + rcu_dereference_protected(*slot, true); + + if (!dma_fence_is_later(fence, old)) + return 0; + + radix_tree_replace_slot(&req->waits, slot, fence); + } + } + if (dma_fence_is_i915(fence)) return i915_gem_request_await_request(req, to_request(fence)); @@ -843,6 +865,15 @@ static void i915_gem_mark_busy(const struct intel_engine_cs *engine) round_jiffies_up_relative(HZ)); } +static void free_radixtree(struct radix_tree_root *root) +{ + struct radix_tree_iter iter; + void __rcu **slot; + + radix_tree_for_each_slot(slot, root, &iter, 0) + radix_tree_iter_delete(root, &iter, slot); +} + /* * NB: This function is not allowed to fail. Doing so would mean the the * request is not being tracked for completion but the work itself is @@ -943,6 +974,8 @@ void __i915_add_request(struct drm_i915_gem_request *request, bool flush_caches) local_bh_disable(); i915_sw_fence_commit(&request->submit); local_bh_enable(); /* Kick the execlists tasklet if just scheduled */ + + free_radixtree(&request->waits); } static unsigned long local_clock_us(unsigned int *cpu) diff --git a/drivers/gpu/drm/i915/i915_gem_request.h b/drivers/gpu/drm/i915/i915_gem_request.h index a211c53c813f..638899b9c170 100644 --- a/drivers/gpu/drm/i915/i915_gem_request.h +++ b/drivers/gpu/drm/i915/i915_gem_request.h @@ -137,6 +137,8 @@ struct drm_i915_gem_request { struct i915_priotree priotree; struct i915_dependency dep; + struct radix_tree_root waits; + /** GEM sequence number associated with this request on the * global execution timeline. It is zero when the request is not * on the HW queue (i.e. not on the engine timeline list). diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 691a9ad48497..84cccf7138c4 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -2022,6 +2022,7 @@ void radix_tree_iter_delete(struct radix_tree_root *root, if (__radix_tree_delete(root, iter->node, slot)) iter->index = iter->next_index; } +EXPORT_SYMBOL(radix_tree_iter_delete); /** * radix_tree_delete_item - delete an item from a radix tree