drm/i915: Skip switch to kernel context if already done
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 29 Dec 2016 14:40:37 +0000 (14:40 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 16 Jan 2017 12:21:20 +0000 (12:21 +0000)
Some engines are never user or already sitting idle in the kernel
context and for those we can skip flushing the current context for
i915_gem_switch_to_kernel_context(). We used to perform this
optimisation but that was removed for convenience of converting over to
multiple timelines and handling the pending request queues.

From the perspective of writing selftests, reducing the number of
background operations on the engines makes defining assertions easier.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: http://patchwork.freedesktop.org/patch/msgid/20170114162334.10271-2-chris@chris-wilson.co.uk
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_gem_context.c

index d4c59b53532e8eb2f40ade9e8a97d48ed7247aa7..83cd2eff37af73f840bc301d1fd4daf442358d99 100644 (file)
@@ -4140,7 +4140,8 @@ static void assert_kernel_context_is_current(struct drm_i915_private *dev_priv)
        enum intel_engine_id id;
 
        for_each_engine(engine, dev_priv, id)
-               GEM_BUG_ON(!i915_gem_context_is_kernel(engine->last_retired_context));
+               GEM_BUG_ON(engine->last_retired_context &&
+                          !i915_gem_context_is_kernel(engine->last_retired_context));
 }
 
 int i915_gem_suspend(struct drm_i915_private *dev_priv)
index ae99c25397ca23ff9cf0c22a245390370d65272c..0a4728fdecdc7408ab80dbeef98994ea7aa868a6 100644 (file)
@@ -877,6 +877,26 @@ int i915_switch_context(struct drm_i915_gem_request *req)
        return do_rcs_switch(req);
 }
 
+static bool engine_has_kernel_context(struct intel_engine_cs *engine)
+{
+       struct i915_gem_timeline *timeline;
+
+       list_for_each_entry(timeline, &engine->i915->gt.timelines, link) {
+               struct intel_timeline *tl;
+
+               if (timeline == &engine->i915->gt.global_timeline)
+                       continue;
+
+               tl = &timeline->engine[engine->id];
+               if (i915_gem_active_peek(&tl->last_request,
+                                        &engine->i915->drm.struct_mutex))
+                       return false;
+       }
+
+       return (!engine->last_retired_context ||
+               i915_gem_context_is_kernel(engine->last_retired_context));
+}
+
 int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv)
 {
        struct intel_engine_cs *engine;
@@ -885,10 +905,15 @@ int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv)
 
        lockdep_assert_held(&dev_priv->drm.struct_mutex);
 
+       i915_gem_retire_requests(dev_priv);
+
        for_each_engine(engine, dev_priv, id) {
                struct drm_i915_gem_request *req;
                int ret;
 
+               if (engine_has_kernel_context(engine))
+                       continue;
+
                req = i915_gem_request_alloc(engine, dev_priv->kernel_context);
                if (IS_ERR(req))
                        return PTR_ERR(req);