drm/i915: Automatic i915_switch_context for legacy
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 20 Nov 2017 10:20:02 +0000 (10:20 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 20 Nov 2017 15:56:16 +0000 (15:56 +0000)
During request construction, after pinning the context we know whether
or not we have to emit a context switch. So move this common operation
from every caller into i915_gem_request_alloc() itself.

v2: Always submit the request if we emitted some commands during request
construction, as typically it also involves changes in global state.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171120102002.22254-2-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_gem_context.c
drivers/gpu/drm/i915/i915_gem_execbuffer.c
drivers/gpu/drm/i915/i915_gem_request.c
drivers/gpu/drm/i915/i915_perf.c
drivers/gpu/drm/i915/intel_ringbuffer.c
drivers/gpu/drm/i915/selftests/huge_pages.c
drivers/gpu/drm/i915/selftests/i915_gem_context.c
drivers/gpu/drm/i915/selftests/i915_gem_request.c
drivers/gpu/drm/i915/selftests/intel_hangcheck.c

index 61ba321e9970a9214ad60b39db2bb32cdf413854..e07eb0beef13b3dd3020ecf0ccc7b1de4eb24b87 100644 (file)
@@ -5045,7 +5045,7 @@ static int __intel_engines_record_defaults(struct drm_i915_private *i915)
                        goto out_ctx;
                }
 
-               err = i915_switch_context(rq);
+               err = 0;
                if (engine->init_context)
                        err = engine->init_context(rq);
 
index 2db0406950356100282747db836a57582b2be17a..c1efbaf02bf2adb28e02f6c563d800b41ee6ed1e 100644 (file)
@@ -842,8 +842,7 @@ int i915_switch_context(struct drm_i915_gem_request *req)
        struct intel_engine_cs *engine = req->engine;
 
        lockdep_assert_held(&req->i915->drm.struct_mutex);
-       if (i915_modparams.enable_execlists)
-               return 0;
+       GEM_BUG_ON(i915_modparams.enable_execlists);
 
        if (!req->ctx->engine[engine->id].state) {
                struct i915_gem_context *to = req->ctx;
@@ -899,7 +898,6 @@ int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv)
 
        for_each_engine(engine, dev_priv, id) {
                struct drm_i915_gem_request *req;
-               int ret;
 
                if (engine_has_idle_kernel_context(engine))
                        continue;
@@ -922,10 +920,7 @@ int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv)
                                                                 GFP_KERNEL);
                }
 
-               ret = i915_switch_context(req);
                i915_add_request(req);
-               if (ret)
-                       return ret;
        }
 
        return 0;
index b7895788bc752571c7986e23db5981ebde71594e..14d9e61a1e06d0672df91521c8009f6727c33751 100644 (file)
@@ -1111,10 +1111,6 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb,
        if (err)
                goto err_request;
 
-       err = i915_switch_context(rq);
-       if (err)
-               goto err_request;
-
        err = eb->engine->emit_bb_start(rq,
                                        batch->node.start, PAGE_SIZE,
                                        cache->gen > 5 ? 0 : I915_DISPATCH_SECURE);
@@ -1960,10 +1956,6 @@ static int eb_submit(struct i915_execbuffer *eb)
        if (err)
                return err;
 
-       err = i915_switch_context(eb->request);
-       if (err)
-               return err;
-
        if (eb->args->flags & I915_EXEC_GEN7_SOL_RESET) {
                err = i915_reset_gen7_sol_offsets(eb->request);
                if (err)
index 91eae1b20c42826bcd747fcd99c01ae1fc2da653..86e2346357cf99042e22e8bda1bcca3e06969601 100644 (file)
@@ -624,6 +624,10 @@ i915_gem_request_alloc(struct intel_engine_cs *engine,
        if (ret)
                goto err_unpin;
 
+       ret = intel_ring_wait_for_space(ring, MIN_SPACE_FOR_ADD_REQUEST);
+       if (ret)
+               goto err_unreserve;
+
        /* Move the oldest request to the slab-cache (if not in use!) */
        req = list_first_entry_or_null(&engine->timeline->requests,
                                       typeof(*req), link);
index 0f48e666098df3ab3f664f74d0ae4bc2ffcf9247..fd150099978caa4bce6d1ecc4a084d337d6c026c 100644 (file)
@@ -1726,10 +1726,9 @@ static int gen8_switch_to_updated_kernel_context(struct drm_i915_private *dev_pr
                                                         GFP_KERNEL);
        }
 
-       ret = i915_switch_context(req);
        i915_add_request(req);
 
-       return ret;
+       return 0;
 }
 
 /*
index 12e734b29463d491ff21526bfcee59e0436149a5..be98868115bf96f36a3cdf52c233b93054e1469f 100644 (file)
@@ -1592,6 +1592,10 @@ static int ring_request_alloc(struct drm_i915_gem_request *request)
        if (ret)
                return ret;
 
+       ret = i915_switch_context(request);
+       if (ret)
+               return ret;
+
        request->reserved_space -= LEGACY_REQUEST_SIZE;
        return 0;
 }
index 159a2cb6876583c8e48896eec8cbf195e1043c7b..db7a0a1f2960eeeed6f9015a4d1e0dd605a303f2 100644 (file)
@@ -989,13 +989,9 @@ static int gpu_write(struct i915_vma *vma,
        i915_vma_unpin(batch);
        i915_vma_close(batch);
 
-       err = i915_switch_context(rq);
-       if (err)
-               goto err_request;
-
-       err = rq->engine->emit_bb_start(rq,
-                                       batch->node.start, batch->node.size,
-                                       flags);
+       err = engine->emit_bb_start(rq,
+                                   batch->node.start, batch->node.size,
+                                   flags);
        if (err)
                goto err_request;
 
index 4ff30b9af1fec0b4cd0a7aac0b737e9aa4dba2a9..09340b3c1156256aa33f977c9c8787d21ea577a2 100644 (file)
@@ -158,10 +158,6 @@ static int gpu_fill(struct drm_i915_gem_object *obj,
                goto err_batch;
        }
 
-       err = i915_switch_context(rq);
-       if (err)
-               goto err_request;
-
        flags = 0;
        if (INTEL_GEN(vm->i915) <= 5)
                flags |= I915_DISPATCH_SECURE;
index d7bf53ff8f84ed39d11b7c5c09a81ab25f2a0803..647bf2bbd7993672d6b94042cca45d7877d4563c 100644 (file)
@@ -459,10 +459,6 @@ empty_request(struct intel_engine_cs *engine,
        if (IS_ERR(request))
                return request;
 
-       err = i915_switch_context(request);
-       if (err)
-               goto out_request;
-
        err = engine->emit_bb_start(request,
                                    batch->node.start,
                                    batch->node.size,
@@ -671,9 +667,6 @@ static int live_all_engines(void *arg)
                        goto out_request;
                }
 
-               err = i915_switch_context(request[id]);
-               GEM_BUG_ON(err);
-
                err = engine->emit_bb_start(request[id],
                                            batch->node.start,
                                            batch->node.size,
@@ -790,9 +783,6 @@ static int live_sequential_engines(void *arg)
                        }
                }
 
-               err = i915_switch_context(request[id]);
-               GEM_BUG_ON(err);
-
                err = engine->emit_bb_start(request[id],
                                            batch->node.start,
                                            batch->node.size,
index 145bdc26553c0880f4ca281a44d6aae1a04b9d9c..1bbb8c46e2d9c2ba59aba54002b694c3ddcb93b0 100644 (file)
@@ -114,10 +114,6 @@ static int emit_recurse_batch(struct hang *h,
        if (err)
                goto unpin_vma;
 
-       err = i915_switch_context(rq);
-       if (err)
-               goto unpin_hws;
-
        i915_vma_move_to_active(vma, rq, 0);
        if (!i915_gem_object_has_active_reference(vma->obj)) {
                i915_gem_object_get(vma->obj);
@@ -169,7 +165,6 @@ static int emit_recurse_batch(struct hang *h,
 
        err = rq->engine->emit_bb_start(rq, vma->node.start, PAGE_SIZE, flags);
 
-unpin_hws:
        i915_vma_unpin(hws);
 unpin_vma:
        i915_vma_unpin(vma);