From patchwork Wed Jun 1 17:07:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Harrison X-Patchwork-Id: 9147861 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 3B04960777 for ; Wed, 1 Jun 2016 17:08:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28F25269DB for ; Wed, 1 Jun 2016 17:08:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DB1126C4D; Wed, 1 Jun 2016 17:08:41 +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]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C08D3269DB for ; Wed, 1 Jun 2016 17:08:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E08006EA02; Wed, 1 Jun 2016 17:08:39 +0000 (UTC) X-Original-To: Intel-GFX@lists.freedesktop.org Delivered-To: Intel-GFX@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 0AB526EA04 for ; Wed, 1 Jun 2016 17:08:33 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP; 01 Jun 2016 10:07:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,402,1459839600"; d="scan'208";a="114256373" Received: from johnharr-linux.isw.intel.com ([10.102.226.93]) by fmsmga004.fm.intel.com with ESMTP; 01 Jun 2016 10:07:36 -0700 From: John.C.Harrison@Intel.com To: Intel-GFX@Lists.FreeDesktop.Org Date: Wed, 1 Jun 2016 18:07:28 +0100 Message-Id: <1464800848-36672-7-git-send-email-John.C.Harrison@Intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1464800848-36672-1-git-send-email-John.C.Harrison@Intel.com> References: <1464800848-36672-1-git-send-email-John.C.Harrison@Intel.com> Organization: Intel Corporation (UK) Ltd. - Co. Reg. #1134945 - Pipers Way, Swindon SN3 1RJ Subject: [Intel-gfx] [PATCH v9 6/6] drm/i915: Cache last IRQ seqno to reduce IRQ overhead 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: John Harrison The notify function can be called many times without the seqno changing. Some are to prevent races due to the requirement of not enabling interrupts until requested. However, when interrupts are enabled the IRQ handler can be called multiple times without the ring's seqno value changing. E.g. two interrupts are generated by batch buffers completing in quick succession, the first call to the handler processes both completions but the handler still gets executed a second time. This patch reduces the overhead of these extra calls by caching the last processed seqno value and early exiting if it has not changed. v3: New patch for series. v5: Added comment about last_irq_seqno usage due to code review feedback (Tvrtko Ursulin). v6: Minor update to resolve a race condition with the wait_request optimisation. v7: Updated to newer nightly - lots of ring -> engine renaming plus an interface change to get_seqno(). For: VIZ-5190 Signed-off-by: John Harrison Cc: Maarten Lankhorst --- drivers/gpu/drm/i915/i915_gem.c | 26 ++++++++++++++++++++++---- drivers/gpu/drm/i915/intel_ringbuffer.h | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index a8b4887..67f65f8 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1368,6 +1368,7 @@ out: * request has not actually been fully processed yet. */ spin_lock_irq(&req->engine->fence_lock); + req->engine->last_irq_seqno = 0; i915_gem_request_notify(req->engine, true); spin_unlock_irq(&req->engine->fence_lock); } @@ -2599,9 +2600,12 @@ i915_gem_init_seqno(struct drm_i915_private *dev_priv, u32 seqno) i915_gem_retire_requests(dev_priv); /* Finally reset hw state */ - for_each_engine(engine, dev_priv) + for_each_engine(engine, dev_priv) { intel_ring_init_seqno(engine, seqno); + engine->last_irq_seqno = 0; + } + return 0; } @@ -2933,13 +2937,24 @@ void i915_gem_request_notify(struct intel_engine_cs *engine, bool fence_locked) return; } - if (!fence_locked) - spin_lock_irqsave(&engine->fence_lock, flags); - + /* + * Check for a new seqno. If it hasn't actually changed then early + * exit without even grabbing the spinlock. Note that this is safe + * because any corruption of last_irq_seqno merely results in doing + * the full processing when there is potentially no work to be done. + * It can never lead to not processing work that does need to happen. + */ if (engine->irq_seqno_barrier) engine->irq_seqno_barrier(engine); seqno = engine->get_seqno(engine); trace_i915_gem_request_notify(engine, seqno); + if (seqno == engine->last_irq_seqno) + return; + + if (!fence_locked) + spin_lock_irqsave(&engine->fence_lock, flags); + + engine->last_irq_seqno = seqno; list_for_each_entry_safe(req, req_next, &engine->fence_signal_list, signal_link) { if (!req->cancelled) { @@ -3234,7 +3249,10 @@ static void i915_gem_reset_engine_cleanup(struct drm_i915_private *dev_priv, * Tidy up anything left over. This includes a call to * i915_gem_request_notify() which will make sure that any requests * that were on the signal pending list get also cleaned up. + * NB: The seqno cache must be cleared otherwise the notify call will + * simply return immediately. */ + engine->last_irq_seqno = 0; i915_gem_retire_requests_ring(engine); /* Having flushed all requests from all queues, we know that all diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h index 51779b4..90de84e 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.h +++ b/drivers/gpu/drm/i915/intel_ringbuffer.h @@ -348,6 +348,7 @@ struct intel_engine_cs { spinlock_t fence_lock; struct list_head fence_signal_list; + uint32_t last_irq_seqno; struct work_struct request_work; };