From: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx> In GuC mode LRC pinning lifetime depends exclusively on the request liftime. Since that is terminated by the seqno update that opens up a race condition between GPU finishing writing out the context image and the driver unpinning the LRC. To extend the LRC lifetime we will employ a similar approach to what legacy ringbuffer submission does. We will start tracking the last submitted context per engine and keep it pinned until it is replaced by another one. Note that the driver unload path is a bit fragile and could benefit greatly from efforts to unify the legacy and exec list submission code paths. At the moment i915_gem_context_fini has special casing for the two which are potentialy not needed, and also depends on i915_gem_cleanup_ringbuffer running before itself. v2: * Move pinning into engine->emit_request and actually fix the reference/unreference logic. (Chris Wilson) * ring->dev can be NULL on driver unload so use a different route towards it. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx> Issue: VIZ-4277 Cc: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> Cc: Nick Hoath <nicholas.hoath@xxxxxxxxx> --- I cannot test this with GuC but it passes BAT with execlists and some real world smoke tests. --- drivers/gpu/drm/i915/i915_gem_context.c | 4 +++- drivers/gpu/drm/i915/intel_lrc.c | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index c25083c78ba7..0b419e165836 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -438,7 +438,9 @@ void i915_gem_context_fini(struct drm_device *dev) for (i = 0; i < I915_NUM_RINGS; i++) { struct intel_engine_cs *ring = &dev_priv->ring[i]; - if (ring->last_context) + if (ring->last_context && i915.enable_execlists) + intel_lr_context_unpin(ring->last_context, ring); + else if (ring->last_context) i915_gem_context_unreference(ring->last_context); ring->default_context = NULL; diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c index e7c273acac1e..72ed176e091d 100644 --- a/drivers/gpu/drm/i915/intel_lrc.c +++ b/drivers/gpu/drm/i915/intel_lrc.c @@ -1120,7 +1120,7 @@ void intel_lr_context_unpin(struct intel_context *ctx, { struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state; - WARN_ON(!mutex_is_locked(&engine->dev->struct_mutex)); + WARN_ON(!mutex_is_locked(&ctx->i915->dev->struct_mutex)); if (WARN_ON_ONCE(!ctx_obj)) return; @@ -1859,6 +1859,13 @@ static int gen8_emit_request(struct drm_i915_gem_request *request) u32 cmd; int ret; + if (ring->last_context != request->ctx) { + if (ring->last_context) + intel_lr_context_unpin(ring->last_context, ring); + intel_lr_context_pin(request->ctx, ring); + ring->last_context = request->ctx; + } + /* * Reserve space for 2 NOOPs at the end of each request to be * used as a workaround for not being allowed to do lite -- 1.9.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/intel-gfx