Commit 7881e605 authored by Chris Wilson's avatar Chris Wilson

drm/i915: Only emit one semaphore per request

Ideally we only need one semaphore per ring to accommodate waiting on
multiple engines in parallel. However, since we do not know which fences
we will finally be waiting on, we emit a semaphore for every fence. It
turns out to be quite easy to trick ourselves into exhausting our
ringbuffer causing an error, just by feeding in a batch that depends on
several thousand contexts.

Since we never can be waiting on more than one semaphore in parallel
(other than perhaps the desire to busywait on multiple engines), just
pick the first fence for our semaphore. If we pick the wrong fence to
busywait on, we just miss an opportunity to reduce latency.

An adaption might be to use sched.flags as either a semaphore counter,
or to track the first busywait on each engine, converting it back to a
single use bit prior to closing the request.

v2: Track first semaphore used per-engine (this caters for our basic
igt that semaphores are working).
Reported-by: default avatarMika Kuoppala <mika.kuoppala@intel.com>
Testcase: igt/gem_exec_fence/long-history
Fixes: e8861964 ("drm/i915: Use HW semaphores for inter-engine synchronisation on gen8+")
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Mika Kuoppala <mika.kuoppala@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190401162641.10963-3-chris@chris-wilson.co.ukReviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
parent 8b74594a
...@@ -783,6 +783,12 @@ emit_semaphore_wait(struct i915_request *to, ...@@ -783,6 +783,12 @@ emit_semaphore_wait(struct i915_request *to,
GEM_BUG_ON(!from->timeline->has_initial_breadcrumb); GEM_BUG_ON(!from->timeline->has_initial_breadcrumb);
GEM_BUG_ON(INTEL_GEN(to->i915) < 8); GEM_BUG_ON(INTEL_GEN(to->i915) < 8);
/* Just emit the first semaphore we see as request space is limited. */
if (to->sched.semaphores & from->engine->mask)
return i915_sw_fence_await_dma_fence(&to->submit,
&from->fence, 0,
I915_FENCE_GFP);
/* We need to pin the signaler's HWSP until we are finished reading. */ /* We need to pin the signaler's HWSP until we are finished reading. */
err = i915_timeline_read_hwsp(from, to, &hwsp_offset); err = i915_timeline_read_hwsp(from, to, &hwsp_offset);
if (err) if (err)
...@@ -814,7 +820,8 @@ emit_semaphore_wait(struct i915_request *to, ...@@ -814,7 +820,8 @@ emit_semaphore_wait(struct i915_request *to,
*cs++ = 0; *cs++ = 0;
intel_ring_advance(to, cs); intel_ring_advance(to, cs);
to->sched.flags |= I915_SCHED_HAS_SEMAPHORE; to->sched.semaphores |= from->engine->mask;
to->sched.flags |= I915_SCHED_HAS_SEMAPHORE_CHAIN;
return 0; return 0;
} }
...@@ -1126,7 +1133,7 @@ void i915_request_add(struct i915_request *request) ...@@ -1126,7 +1133,7 @@ void i915_request_add(struct i915_request *request)
* far in the distance past over useful work, we keep a history * far in the distance past over useful work, we keep a history
* of any semaphore use along our dependency chain. * of any semaphore use along our dependency chain.
*/ */
if (!(request->sched.flags & I915_SCHED_HAS_SEMAPHORE)) if (!(request->sched.flags & I915_SCHED_HAS_SEMAPHORE_CHAIN))
attr.priority |= I915_PRIORITY_NOSEMAPHORE; attr.priority |= I915_PRIORITY_NOSEMAPHORE;
/* /*
......
...@@ -41,6 +41,7 @@ void i915_sched_node_init(struct i915_sched_node *node) ...@@ -41,6 +41,7 @@ void i915_sched_node_init(struct i915_sched_node *node)
INIT_LIST_HEAD(&node->waiters_list); INIT_LIST_HEAD(&node->waiters_list);
INIT_LIST_HEAD(&node->link); INIT_LIST_HEAD(&node->link);
node->attr.priority = I915_PRIORITY_INVALID; node->attr.priority = I915_PRIORITY_INVALID;
node->semaphores = 0;
node->flags = 0; node->flags = 0;
} }
...@@ -73,9 +74,9 @@ bool __i915_sched_node_add_dependency(struct i915_sched_node *node, ...@@ -73,9 +74,9 @@ bool __i915_sched_node_add_dependency(struct i915_sched_node *node,
dep->flags = flags; dep->flags = flags;
/* Keep track of whether anyone on this chain has a semaphore */ /* Keep track of whether anyone on this chain has a semaphore */
if (signal->flags & I915_SCHED_HAS_SEMAPHORE && if (signal->flags & I915_SCHED_HAS_SEMAPHORE_CHAIN &&
!node_started(signal)) !node_started(signal))
node->flags |= I915_SCHED_HAS_SEMAPHORE; node->flags |= I915_SCHED_HAS_SEMAPHORE_CHAIN;
ret = true; ret = true;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/list.h> #include <linux/list.h>
#include "i915_priolist_types.h" #include "i915_priolist_types.h"
#include "intel_engine_types.h"
struct drm_i915_private; struct drm_i915_private;
struct i915_request; struct i915_request;
...@@ -55,7 +56,8 @@ struct i915_sched_node { ...@@ -55,7 +56,8 @@ struct i915_sched_node {
struct list_head link; struct list_head link;
struct i915_sched_attr attr; struct i915_sched_attr attr;
unsigned int flags; unsigned int flags;
#define I915_SCHED_HAS_SEMAPHORE BIT(0) #define I915_SCHED_HAS_SEMAPHORE_CHAIN BIT(0)
intel_engine_mask_t semaphores;
}; };
struct i915_dependency { struct i915_dependency {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment