From patchwork Tue Sep 12 08:36:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 9948599 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 E0E1B60360 for ; Tue, 12 Sep 2017 08:40:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D02BF2839C for ; Tue, 12 Sep 2017 08:40:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C50642850D; Tue, 12 Sep 2017 08:40:22 +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 1AEF02839C for ; Tue, 12 Sep 2017 08:40:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A83766E57F; Tue, 12 Sep 2017 08:40:21 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id EDA6A6E580 for ; Tue, 12 Sep 2017 08:39:51 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2017 01:39:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,382,1500966000"; d="scan'208";a="134377982" Received: from rosetta.fi.intel.com ([10.237.72.186]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2017 01:39:49 -0700 Received: by rosetta.fi.intel.com (Postfix, from userid 1000) id E0D03840023; Tue, 12 Sep 2017 11:38:28 +0300 (EEST) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Tue, 12 Sep 2017 11:36:16 +0300 Message-Id: <20170912083618.13009-7-mika.kuoppala@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170912083618.13009-1-mika.kuoppala@intel.com> References: <20170912083618.13009-1-mika.kuoppala@intel.com> Subject: [Intel-gfx] [PATCH 6/8] drm/i915: Introduce execlist_port_* accessors 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 Instead of trusting that first available port is at index 0, use accessor to hide this. This allows us to just move the head on port completion instead of memmoving the array. Signed-off-by: Mika Kuoppala --- drivers/gpu/drm/i915/i915_guc_submission.c | 15 ++++++----- drivers/gpu/drm/i915/i915_irq.c | 2 +- drivers/gpu/drm/i915/intel_engine_cs.c | 2 +- drivers/gpu/drm/i915/intel_lrc.c | 29 +++++++++++----------- drivers/gpu/drm/i915/intel_ringbuffer.h | 40 ++++++++++++++++++++++++------ 5 files changed, 57 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c b/drivers/gpu/drm/i915/i915_guc_submission.c index c38a3e71e285..0dfb03a0cee4 100644 --- a/drivers/gpu/drm/i915/i915_guc_submission.c +++ b/drivers/gpu/drm/i915/i915_guc_submission.c @@ -662,9 +662,8 @@ static void port_assign(struct execlist_port *port, static bool i915_guc_dequeue(struct intel_engine_cs *engine) { struct intel_engine_execlist * const el = &engine->execlist; - struct execlist_port *port = el->port; - const struct execlist_port * const last_port = - &el->port[el->port_mask]; + struct execlist_port *port = execlist_port_head(el); + const struct execlist_port * const last_port = execlist_port_tail(el); struct drm_i915_gem_request *last = port_request(port); struct rb_node *rb; bool submit = false; @@ -686,7 +685,8 @@ static bool i915_guc_dequeue(struct intel_engine_cs *engine) if (submit) port_assign(port, last); - port++; + + port = execlist_port_next(el, port); } INIT_LIST_HEAD(&rq->priotree.link); @@ -717,9 +717,8 @@ static void i915_guc_irq_handler(unsigned long data) { struct intel_engine_cs * const engine = (struct intel_engine_cs *)data; struct intel_engine_execlist * const el = &engine->execlist; - struct execlist_port *port = el->port; - const struct execlist_port * const last_port = - &el->port[el->port_mask]; + struct execlist_port *port = execlist_port_head(el); + const struct execlist_port * const last_port = execlist_port_tail(el); struct drm_i915_gem_request *rq; bool submit; @@ -729,7 +728,7 @@ static void i915_guc_irq_handler(unsigned long data) trace_i915_gem_request_out(rq); i915_gem_request_put(rq); - execlist_port_complete(el, port); + port = execlist_port_complete(el, port); rq = port_request(port); } diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index e16fbea03823..1919ac0b7b0f 100644 --- a/drivers/gpu/drm/i915/i915_irq.c +++ b/drivers/gpu/drm/i915/i915_irq.c @@ -1312,7 +1312,7 @@ gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift) bool tasklet = false; if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift)) { - if (port_count(&el->port[0])) { + if (port_count(execlist_port_head(el))) { __set_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted); tasklet = true; } diff --git a/drivers/gpu/drm/i915/intel_engine_cs.c b/drivers/gpu/drm/i915/intel_engine_cs.c index 192ecc26f432..0fb5a1f99349 100644 --- a/drivers/gpu/drm/i915/intel_engine_cs.c +++ b/drivers/gpu/drm/i915/intel_engine_cs.c @@ -1334,7 +1334,7 @@ bool intel_engine_is_idle(struct intel_engine_cs *engine) return false; /* Both ports drained, no more ELSP submission? */ - if (port_request(&engine->execlist.port[0])) + if (port_request(execlist_port_head(&engine->execlist))) return false; /* ELSP is empty, but there are ready requests? */ diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index cfa21731b9c7..0bc42a3f9528 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -400,9 +400,8 @@ static void execlists_dequeue(struct intel_engine_cs *engine) { struct drm_i915_gem_request *last; struct intel_engine_execlist * const el = &engine->execlist; - struct execlist_port *port = el->port; - const struct execlist_port * const last_port = - &el->port[el->port_mask]; + struct execlist_port *port = execlist_port_head(el); + const struct execlist_port * const last_port = execlist_port_tail(el); struct rb_node *rb; bool submit = false; @@ -486,7 +485,8 @@ static void execlists_dequeue(struct intel_engine_cs *engine) if (submit) port_assign(port, last); - port++; + + port = execlist_port_next(el, port); GEM_BUG_ON(port_isset(port)); } @@ -516,11 +516,11 @@ static void execlists_dequeue(struct intel_engine_cs *engine) execlists_submit_ports(engine); } -static bool execlists_elsp_ready(const struct intel_engine_cs *engine) +static bool execlists_elsp_ready(struct intel_engine_execlist * const el) { - const struct execlist_port *port = engine->execlist.port; + struct execlist_port * const port = execlist_port_head(el); - return port_count(&port[0]) + port_count(&port[1]) < 2; + return port_count(port) + port_count(execlist_port_next(el, port)) < 2; } /* @@ -531,7 +531,7 @@ static void intel_lrc_irq_handler(unsigned long data) { struct intel_engine_cs * const engine = (struct intel_engine_cs *)data; struct intel_engine_execlist * const el = &engine->execlist; - struct execlist_port *port = el->port; + struct execlist_port *port = execlist_port_head(el); struct drm_i915_private *dev_priv = engine->i915; /* We can skip acquiring intel_runtime_pm_get() here as it was taken @@ -613,7 +613,7 @@ static void intel_lrc_irq_handler(unsigned long data) trace_i915_gem_request_out(rq); i915_gem_request_put(rq); - execlist_port_complete(el, port); + port = execlist_port_complete(el, port); } else { port_set(port, port_pack(rq, count)); } @@ -627,7 +627,7 @@ static void intel_lrc_irq_handler(unsigned long data) csb_mmio); } - if (execlists_elsp_ready(engine)) + if (execlists_elsp_ready(el)) execlists_dequeue(engine); intel_uncore_forcewake_put(dev_priv, el->fw_domains); @@ -701,6 +701,7 @@ insert_request(struct intel_engine_cs *engine, static void execlists_submit_request(struct drm_i915_gem_request *request) { struct intel_engine_cs *engine = request->engine; + struct intel_engine_execlist * const el = &engine->execlist; unsigned long flags; /* Will be called from irq-context when using foreign fences. */ @@ -709,11 +710,11 @@ static void execlists_submit_request(struct drm_i915_gem_request *request) if (insert_request(engine, &request->priotree, request->priotree.priority)) { - if (execlists_elsp_ready(engine)) - tasklet_hi_schedule(&engine->execlist.irq_tasklet); + if (execlists_elsp_ready(el)) + tasklet_hi_schedule(&el->irq_tasklet); } - GEM_BUG_ON(!engine->execlist.first); + GEM_BUG_ON(!el->first); GEM_BUG_ON(list_empty(&request->priotree.link)); spin_unlock_irqrestore(&engine->timeline->lock, flags); @@ -1333,7 +1334,7 @@ static void reset_common_ring(struct intel_engine_cs *engine, struct drm_i915_gem_request *request) { struct intel_engine_execlist * const el = &engine->execlist; - struct execlist_port *port = el->port; + struct execlist_port *port = execlist_port_head(el); struct intel_context *ce; /* diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h index 838d2d9b77c1..13d8e1115f3b 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.h +++ b/drivers/gpu/drm/i915/intel_ringbuffer.h @@ -244,6 +244,11 @@ struct intel_engine_execlist { unsigned int port_mask; /** + * @port_head: first used execlist port + */ + unsigned int port_head; + + /** * @queue: queue of requests, in priority lists */ struct rb_root queue; @@ -505,23 +510,44 @@ struct intel_engine_cs { #define for_each_execlist_port(el__, port__, n__) \ for ((n__) = 0; \ - (port__) = &(el__)->port[__port_idx(0, (n__), (el__)->port_mask)], (n__) < (el__)->port_mask + 1; \ + (port__) = &(el__)->port[__port_idx((el__)->port_head, (n__), (el__)->port_mask)], (n__) < (el__)->port_mask + 1; \ (n__)++) #define for_each_execlist_port_reverse(el__, port__, n__) \ for ((n__) = (el__)->port_mask + 1; \ - (port__) = &(el__)->port[__port_idx((el__)->port_mask, (n__), (el__)->port_mask)], (n__)--;) + (port__) = &(el__)->port[__port_idx((el__)->port_head - 1, (n__), (el__)->port_mask)], (n__)--;) -static inline void +static inline struct execlist_port * +execlist_port_head(struct intel_engine_execlist * const el) +{ + return &el->port[el->port_head]; +} + +static inline struct execlist_port * +execlist_port_tail(struct intel_engine_execlist * const el) +{ + return &el->port[__port_idx(el->port_head, el->port_mask, el->port_mask)]; +} + +static inline struct execlist_port * +execlist_port_next(struct intel_engine_execlist * const el, + const struct execlist_port * const port) +{ + const unsigned int i = port_index(port, el); + + return &el->port[__port_idx(i, 1, el->port_mask)]; +} + +static inline struct execlist_port * execlist_port_complete(struct intel_engine_execlist * const el, struct execlist_port * const port) { - const unsigned int m = el->port_mask; + GEM_DEBUG_BUG_ON(port_index(port, el) != el->port_head); - GEM_DEBUG_BUG_ON(port_index(port, el) != 0); + memset(port, 0, sizeof(struct execlist_port)); + el->port_head = __port_idx(el->port_head, 1, el->port_mask); - memmove(port, port + 1, m * sizeof(struct execlist_port)); - memset(port + m, 0, sizeof(struct execlist_port)); + return execlist_port_head(el); } void execlist_cancel_port_requests(struct intel_engine_execlist * const el);