drm/i915: Seal races between async GPU cancellation, retirement and signaling
Subsystems (7)
PATCH 1/45 drm/i915: Seal races between async GPU cancellation, retirement and signaling
Currently there is an underlying assumption that i915_request_unsubmit() is synchronous wrt the GPU -- that is the request is no longer in flight as we remove it. In the near future that may change, and this may upset our signaling as we can process an interrupt for that request while it is no longer in flight.
CPU0 CPU1intel_engine_breadcrumbs_irq
(queue request completion)
i915_request_cancel_signaling
... ...
i915_request_enable_signalingdma_fence_signal
Hence in the time it took us to drop the lock to signal the request, a preemption event may have occurred and re-queued the request. In the process, that request would have seen I915_FENCE_FLAG_SIGNAL clear and so reused the rq->signal_link that was in use on CPU0, leading to bad pointer chasing in intel_engine_breadcrumbs_irq.
A related issue was that if someone started listening for a signal on a completed but no longer in-flight request, we missed the opportunity to immediately signal that request.
Furthermore, as intel_contexts may be immediately released during request retirement, in order to be entirely sure that intel_engine_breadcrumbs_irq may no longer dereference the intel_context (ce->signals and ce->signal_link), we must wait for irq spinlock.
In order to prevent the race, we use a bit in the fence.flags to signal the transfer onto the signal list inside intel_engine_breadcrumbs_irq. For simplicity, we use the DMA_FENCE_FLAG_SIGNALED_BIT as it then quickly signals to any outside observer that the fence is indeed signaled.
--- drivers/dma-buf/dma-fence.c | 1 + drivers/gpu/drm/i915/gt/intel_breadcrumbs.c | 58 +++++++++++++-------- drivers/gpu/drm/i915/i915_request.c | 1 + 3 files changed, 39 insertions(+), 21 deletions(-)
drivers/dma-buf/dma-fence.c +1 -0
@@ -29,6 +29,7 @@EXPORT_TRACEPOINT_SYMBOL (dma_fence_emit);EXPORT_TRACEPOINT_SYMBOL (dma_fence_enable_signal); +EXPORT_TRACEPOINT_SYMBOL (dma_fence_signaled);static DEFINE_SPINLOCK (dma_fence_stub_lock);static struct dma_fence dma_fence_stub;
drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +37 -21
113 lines not on this page · raw message
drivers/gpu/drm/i915/i915_request.c +1 -0
@@ -417,6 +417,7 @@ void __i915_request_submit(struct i915_request *request)set_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags);if (test_bit (DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT , &request->fence.flags) && + !test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &request->fence.flags) && !i915_request_enable_breadcrumb (request))intel_engine_queue_breadcrumbs (engine);
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/45 drm/i915/gvt: Pin the per-engine GVT shadow contexts
Our eventual goal is to rid request construction of struct_mutex, with the short term step of lifting the struct_mutex requirements into the higher levels (i.e. the caller must ensure that the context is already pinned into the GTT). In this patch, we pin GVT's shadow context upon allocation and so keep them pinned into the GGTT for as long as the virtual machine is alive, and so we can use the simpler request construction path safe in the knowledge that the hard work is already done.
--- drivers/gpu/drm/i915/gvt/gvt.h | 2 +- drivers/gpu/drm/i915/gvt/kvmgt.c | 2 +- drivers/gpu/drm/i915/gvt/mmio_context.c | 3 +- drivers/gpu/drm/i915/gvt/scheduler.c | 137 ++++++++++++------------ 4 files changed, 73 insertions(+), 71 deletions(-)
drivers/gpu/drm/i915/gvt/gvt.h +1 -1
@@ -149,9 +149,9 @@ struct intel_vgpu_submission_ops {struct intel_vgpu_submission {struct intel_vgpu_execlist execlist[I915_NUM_ENGINES ];struct list_head workload_q_head[I915_NUM_ENGINES ]; +struct intel_context *shadow[I915_NUM_ENGINES ];struct kmem_cache *workloads;atomic_t running_workload_num; -struct i915_gem_context *shadow_ctx;union {u64 i915_context_pml4;u64 i915_context_pdps[GEN8_3LVL_PDPES ];
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
@@ -1576,7 +1576,7 @@ hw_id_show(struct device *dev, struct device_attribute *attr,struct intel_vgpu *vgpu = (struct intel_vgpu *)mdev_get_drvdata (mdev);return sprintf (buf,"%u\n" , - vgpu->submission.shadow_ctx->hw_id); + vgpu->submission.shadow[0 ]->gem_context->hw_id); }return sprintf (buf,"\n" ); }
drivers/gpu/drm/i915/gvt/mmio_context.c +1 -2
@@ -495,8 +495,7 @@ static void switch_mmio(struct intel_vgpu *pre,* itself. */ if (mmio->in_context && - !is_inhibit_context (intel_context_lookup (s->shadow_ctx, - dev_priv->engine[ring_id]))) + !is_inhibit_context (s->shadow[ring_id]))continue ;if (mmio->mask)
drivers/gpu/drm/i915/gvt/scheduler.c +70 -67
272 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/45 drm/i915: Export intel_context_instance()
In reply to Chris WilsonWe want to pass in a intel_context into intel_context_pin() and that requires us to first be able to lookup the intel_context!
--- drivers/gpu/drm/i915/gt/intel_context.c | 37 +++++++++++----------- drivers/gpu/drm/i915/gt/intel_context.h | 19 +++++++---- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 8 ++++- drivers/gpu/drm/i915/gt/mock_engine.c | 8 ++++- drivers/gpu/drm/i915/gvt/scheduler.c | 7 +++- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 +++++-- drivers/gpu/drm/i915/i915_perf.c | 21 ++++++++---- drivers/gpu/drm/i915/i915_request.c | 11 ++++++- 8 files changed, 83 insertions(+), 39 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +18 -19
@@ -104,7 +104,7 @@ void __intel_context_remove(struct intel_context *ce)spin_unlock (&ctx->hw_contexts_lock); } -static struct intel_context * +struct intel_context *intel_context_instance (struct i915_gem_context *ctx,struct intel_engine_cs *engine) {
@@ -112,7 +112,7 @@ intel_context_instance(struct i915_gem_context *ctx, ce =intel_context_lookup (ctx, engine);if (likely (ce)) -return ce; +return intel_context_get (ce); ce =intel_context_alloc ();if (!ce)
@@ -125,7 +125,7 @@ intel_context_instance(struct i915_gem_context *ctx,intel_context_free (ce);GEM_BUG_ON (intel_context_lookup (ctx, engine) != pos); -return pos; +return intel_context_get (pos); } struct intel_context *
@@ -139,30 +139,30 @@ intel_context_pin_lock(struct i915_gem_context *ctx,if (IS_ERR (ce))return ce; -if (mutex_lock_interruptible (&ce->pin_mutex)) +if (mutex_lock_interruptible (&ce->pin_mutex)) { +intel_context_put (ce);return ERR_PTR (-EINTR ); + }return ce; } -struct intel_context * -intel_context_pin (struct i915_gem_context *ctx, -struct intel_engine_cs *engine) +void intel_context_pin_unlock (struct intel_context *ce) + __releases(ce->pin_mutex) { -struct intel_context *ce; -int err; - - ce =intel_context_instance (ctx, engine); -if (IS_ERR (ce)) -return ce; +mutex_unlock (&ce->pin_mutex); +intel_context_put (ce); +} -if (likely (atomic_inc_not_zero (&ce->pin_count))) -return ce; +int __intel_context_do_pin (struct intel_context *ce) +{ +int err;if (mutex_lock_interruptible (&ce->pin_mutex)) -return ERR_PTR (-EINTR ); +return -EINTR ;if (likely (!atomic_read (&ce->pin_count))) { +struct i915_gem_context *ctx = ce->gem_context;intel_wakeref_t wakeref; err =0 ;
@@ -172,7 +172,6 @@ intel_context_pin(struct i915_gem_context *ctx, goto err;i915_gem_context_get (ctx); -GEM_BUG_ON (ce->gem_context != ctx);mutex_lock (&ctx->mutex);list_add (&ce->active_link, &ctx->active_engines);
@@ -186,11 +185,11 @@ intel_context_pin(struct i915_gem_context *ctx,GEM_BUG_ON (!intel_context_is_pinned (ce));/* no overflow! */ mutex_unlock (&ce->pin_mutex); -return ce; +return 0 ; err:mutex_unlock (&ce->pin_mutex); -return ERR_PTR (err); +return err; }void intel_context_unpin (struct intel_context *ce)
drivers/gpu/drm/i915/gt/intel_context.h +13 -6
@@ -49,11 +49,7 @@ intel_context_is_pinned(struct intel_context *ce)return atomic_read (&ce->pin_count); } -static inline void intel_context_pin_unlock (struct intel_context *ce) -__releases(ce->pin_mutex) -{ -mutex_unlock (&ce->pin_mutex); -} +void intel_context_pin_unlock (struct intel_context *ce);struct intel_context * __intel_context_insert(struct i915_gem_context *ctx,
@@ -63,7 +59,18 @@ void __intel_context_remove(struct intel_context *ce);struct intel_context * -intel_context_pin (struct i915_gem_context *ctx,struct intel_engine_cs *engine); +intel_context_instance (struct i915_gem_context *ctx, +struct intel_engine_cs *engine); + +int __intel_context_do_pin (struct intel_context *ce); + +static inline int intel_context_pin (struct intel_context *ce) +{ +if (likely (atomic_inc_not_zero (&ce->pin_count))) +return 0 ; + +return __intel_context_do_pin (ce); +}static inline void __intel_context_pin (struct intel_context *ce) {
drivers/gpu/drm/i915/gt/intel_engine_cs.c +7 -1
@@ -697,11 +697,17 @@ static int pin_context(struct i915_gem_context *ctx, struct intel_context **out) {struct intel_context *ce; +int err; - ce =intel_context_pin (ctx, engine); + ce =intel_context_instance (ctx, engine);if (IS_ERR (ce))return PTR_ERR (ce); + err =intel_context_pin (ce); +intel_context_put (ce); +if (err) +return err; + *out = ce;return 0 ; }
drivers/gpu/drm/i915/gt/mock_engine.c +7 -1
@@ -239,6 +239,7 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, int id) {struct mock_engine *engine; +int err;GEM_BUG_ON (id >=I915_NUM_ENGINES );
@@ -278,10 +279,15 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915,INIT_LIST_HEAD (&engine->hw_queue); engine->base.kernel_context = -intel_context_pin (i915->kernel_context, &engine->base); +intel_context_instance (i915->kernel_context, &engine->base);if (IS_ERR (engine->base.kernel_context)) goto err_breadcrumbs; + err =intel_context_pin (engine->base.kernel_context); +intel_context_put (engine->base.kernel_context); +if (err) + goto err_breadcrumbs; +return &engine->base; err_breadcrumbs:
drivers/gpu/drm/i915/gvt/scheduler.c +6 -1
@@ -1188,12 +1188,17 @@ int intel_vgpu_setup_submission(struct intel_vgpu *vgpu)INIT_LIST_HEAD (&s->workload_q_head[i]); s->shadow[i] =ERR_PTR (-EINVAL ); - ce =intel_context_pin (ctx, engine); + ce =intel_context_instance (ctx, engine);if (IS_ERR (ce)) { ret =PTR_ERR (ce); goto out_shadow_ctx; } + ret =intel_context_pin (ce); +intel_context_put (ce); +if (ret) + goto out_shadow_ctx; + s->shadow[i] = ce; }
drivers/gpu/drm/i915/i915_gem_execbuffer.c +8 -3
@@ -2100,14 +2100,19 @@ static int eb_pin_context(struct i915_execbuffer *eb,if (err)return err; + ce =intel_context_instance (eb->gem_context, engine); +if (IS_ERR (ce)) +return PTR_ERR (ce); +/* * Pinning the contexts may generate requests in order to acquire * GGTT space, so do this first before we reserve a seqno for * ourselves. */ - ce =intel_context_pin (eb->gem_context, engine); -if (IS_ERR (ce)) -return PTR_ERR (ce); + err =intel_context_pin (ce); +intel_context_put (ce); +if (err) +return err; eb->engine = engine; eb->context = ce;
drivers/gpu/drm/i915/i915_perf.c +14 -7
@@ -1205,11 +1205,17 @@ static struct intel_context *oa_pin_context(struct drm_i915_private *i915, {struct intel_engine_cs *engine = i915->engine[RCS0 ];struct intel_context *ce; -int ret; +int err; - ret =i915_mutex_lock_interruptible (&i915->drm); -if (ret) -return ERR_PTR (ret); + ce =intel_context_instance (ctx, engine); +if (IS_ERR (ce)) +return ce; + + err =i915_mutex_lock_interruptible (&i915->drm); +if (err) { +intel_context_put (ce); +return ERR_PTR (err); + }/* * As the ID is the gtt offset of the context's vma we
@@ -1217,10 +1223,11 @@ static struct intel_context *oa_pin_context(struct drm_i915_private *i915,* * NB: implied RCS engine... */ - ce =intel_context_pin (ctx, engine); + err =intel_context_pin (ce);mutex_unlock (&i915->drm.struct_mutex); -if (IS_ERR (ce)) -return ce; +intel_context_put (ce); +if (err) +return ERR_PTR (err); i915->perf.oa.pinned_ctx = ce;
drivers/gpu/drm/i915/i915_request.c +10 -1
@@ -786,6 +786,7 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)struct drm_i915_private *i915 = engine->i915;struct intel_context *ce;struct i915_request *rq; +int err;/* * Preempt contexts are reserved for exclusive use to inject a
@@ -799,13 +800,21 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)* GGTT space, so do this first before we reserve a seqno for * ourselves. */ - ce =intel_context_pin (ctx, engine); + ce =intel_context_instance (ctx, engine);if (IS_ERR (ce))return ERR_CAST (ce); + err =intel_context_pin (ce); +if (err) { + rq =ERR_PTR (err); + goto err_put; + } + rq =i915_request_create (ce);intel_context_unpin (ce); +err_put: +intel_context_put (ce);return rq; }
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/45 drm/i915/selftests: Use the real kernel context for sseu isolation tests
In reply to Chris WilsonSimply the setup slightly for the sseu selftests to use the actual kernel_context.
--- .../gpu/drm/i915/selftests/i915_gem_context.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/selftests/i915_gem_context.c +4 -13
@@ -957,7 +957,6 @@ __sseu_finish(struct drm_i915_private *i915,const char *name, unsigned int flags, struct i915_gem_context *ctx, - struct i915_gem_context *kctx, struct intel_engine_cs *engine, struct drm_i915_gem_object *obj, unsigned int expected,
@@ -979,7 +978,8 @@ __sseu_finish(struct drm_i915_private *i915,if (ret) goto out; - ret =__read_slice_count (i915, kctx, engine, obj,NULL , &rpcs); + ret =__read_slice_count (i915, i915->kernel_context, engine, obj, +NULL , &rpcs); ret =__check_rpcs (name, rpcs, ret, slices,"Kernel context" ,"!" ); out:
@@ -1011,22 +1011,17 @@ __sseu_test(struct drm_i915_private *i915, struct intel_sseu sseu) {struct igt_spinner *spin =NULL ; -struct i915_gem_context *kctx;int ret; - kctx =kernel_context (i915); -if (IS_ERR (kctx)) -return PTR_ERR (kctx); - ret =__sseu_prepare (i915, name, flags, ctx, engine, &spin);if (ret) - goto out_context; +return ret; ret =__i915_gem_context_reconfigure_sseu (ctx, engine, sseu);if (ret) goto out_spin; - ret =__sseu_finish (i915, name, flags, ctx, kctx, engine, obj, + ret =__sseu_finish (i915, name, flags, ctx, engine, obj,hweight32 (sseu.slice_mask), spin); out_spin:
@@ -1035,10 +1030,6 @@ __sseu_test(struct drm_i915_private *i915,igt_spinner_fini (spin);kfree (spin); } - -out_context: -kernel_context_close (kctx); -return ret; }
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 5/45 drm/i915/selftests: Pass around intel_context for sseu
In reply to Chris WilsonCombine the (i915_gem_context, intel_engine) into a single parameter, the intel_context for convenience and later simplification.
--- .../gpu/drm/i915/selftests/i915_gem_context.c | 74 +++++++++++-------- 1 file changed, 44 insertions(+), 30 deletions(-)
drivers/gpu/drm/i915/selftests/i915_gem_context.c +44 -30
@@ -755,8 +755,7 @@ static struct i915_vma *rpcs_query_batch(struct i915_vma *vma)static int emit_rpcs_query (struct drm_i915_gem_object *obj, -struct i915_gem_context *ctx, -struct intel_engine_cs *engine, +struct intel_context *ce,struct i915_request **rq_out) {struct i915_request *rq;
@@ -764,9 +763,9 @@ emit_rpcs_query(struct drm_i915_gem_object *obj,struct i915_vma *vma;int err; -GEM_BUG_ON (!intel_engine_can_store_dword (engine)); +GEM_BUG_ON (!intel_engine_can_store_dword (ce->engine)); - vma =i915_vma_instance (obj, &ctx->ppgtt->vm,NULL ); + vma =i915_vma_instance (obj, &ce->gem_context->ppgtt->vm,NULL );if (IS_ERR (vma))return PTR_ERR (vma);
@@ -784,13 +783,15 @@ emit_rpcs_query(struct drm_i915_gem_object *obj, goto err_vma; } - rq =i915_request_alloc (engine, ctx); + rq =i915_request_create (ce);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto err_batch; } - err = engine->emit_bb_start (rq, batch->node.start, batch->node.size,0 ); + err = rq->engine->emit_bb_start (rq, + batch->node.start, batch->node.size, +0 );if (err) goto err_request;
@@ -834,8 +835,7 @@ static int __sseu_prepare(struct drm_i915_private *i915, const char *name, unsigned int flags, - struct i915_gem_context *ctx, - struct intel_engine_cs *engine, + struct intel_context *ce, struct igt_spinner **spin) { struct i915_request *rq;
@@ -853,7 +853,10 @@ __sseu_prepare(struct drm_i915_private *i915,if (ret) goto err_free; - rq =igt_spinner_create_request (*spin, ctx, engine,MI_NOOP ); + rq =igt_spinner_create_request (*spin, + ce->gem_context, + ce->engine, +MI_NOOP );if (IS_ERR (rq)) { ret =PTR_ERR (rq); goto err_fini;
@@ -880,8 +883,7 @@ __sseu_prepare(struct drm_i915_private *i915,static int __read_slice_count (struct drm_i915_private *i915, -struct i915_gem_context *ctx, -struct intel_engine_cs *engine, +struct intel_context *ce,struct drm_i915_gem_object *obj,struct igt_spinner *spin,u32 *rpcs)
@@ -892,7 +894,7 @@ __read_slice_count(struct drm_i915_private *i915,u32 *buf, val;long ret; - ret =emit_rpcs_query (obj, ctx, engine, &rq); + ret =emit_rpcs_query (obj, ce, &rq);if (ret)return ret;
@@ -956,29 +958,28 @@ static int __sseu_finish(struct drm_i915_private *i915, const char *name, unsigned int flags, - struct i915_gem_context *ctx, - struct intel_engine_cs *engine, + struct intel_context *ce, struct drm_i915_gem_object *obj, unsigned int expected, struct igt_spinner *spin) { - unsigned int slices = hweight32(engine->sseu.slice_mask); + unsigned int slices = hweight32(ce->engine->sseu.slice_mask);u32 rpcs =0 ;int ret =0 ;if (flags &TEST_RESET ) { - ret =i915_reset_engine (engine,"sseu" ); + ret =i915_reset_engine (ce->engine,"sseu" );if (ret) goto out; } - ret =__read_slice_count (i915, ctx, engine, obj, + ret =__read_slice_count (i915, ce, obj, flags &TEST_RESET ?NULL : spin, &rpcs); ret =__check_rpcs (name, rpcs, ret, expected,"Context" ,"!" );if (ret) goto out; - ret =__read_slice_count (i915, i915->kernel_context, engine, obj, + ret =__read_slice_count (i915, ce->engine->kernel_context, obj,NULL , &rpcs); ret =__check_rpcs (name, rpcs, ret, slices,"Kernel context" ,"!" );
@@ -993,7 +994,7 @@ __sseu_finish(struct drm_i915_private *i915,if (ret)return ret; - ret =__read_slice_count (i915, ctx, engine, obj,NULL , &rpcs); + ret =__read_slice_count (i915, ce, obj,NULL , &rpcs); ret =__check_rpcs (name, rpcs, ret, expected,"Context" ," after idle!" ); }
@@ -1005,23 +1006,22 @@ static int __sseu_test(struct drm_i915_private *i915, const char *name, unsigned int flags, - struct i915_gem_context *ctx, - struct intel_engine_cs *engine, + struct intel_context *ce, struct drm_i915_gem_object *obj, struct intel_sseu sseu) { struct igt_spinner *spin = NULL;int ret; - ret =__sseu_prepare (i915, name, flags, ctx, engine, &spin); + ret =__sseu_prepare (i915, name, flags, ce, &spin);if (ret)return ret; - ret =__i915_gem_context_reconfigure_sseu (ctx, engine, sseu); + ret =__i915_gem_context_reconfigure_sseu (ce->gem_context, ce->engine, sseu);if (ret) goto out_spin; - ret =__sseu_finish (i915, name, flags, ctx, engine, obj, + ret =__sseu_finish (i915, name, flags, ce, obj,hweight32 (sseu.slice_mask), spin); out_spin:
@@ -1042,6 +1042,7 @@ __igt_ctx_sseu(struct drm_i915_private *i915,struct intel_sseu default_sseu = engine->sseu;struct drm_i915_gem_object *obj;struct i915_gem_context *ctx; +struct intel_context *ce;struct intel_sseu pg_sseu;intel_wakeref_t wakeref;struct drm_file *file;
@@ -1093,23 +1094,33 @@ __igt_ctx_sseu(struct drm_i915_private *i915, wakeref =intel_runtime_pm_get (i915); + ce =intel_context_instance (ctx, i915->engine[RCS0 ]); +if (IS_ERR (ce)) { + ret =PTR_ERR (ce); + goto out_rpm; + } + + ret =intel_context_pin (ce); +if (ret) + goto out_context; +/* First set the default mask. */ - ret =__sseu_test (i915, name, flags, ctx, engine, obj, default_sseu); + ret =__sseu_test (i915, name, flags, ce, obj, default_sseu);if (ret) goto out_fail;/* Then set a power-gated configuration. */ - ret =__sseu_test (i915, name, flags, ctx, engine, obj, pg_sseu); + ret =__sseu_test (i915, name, flags, ce, obj, pg_sseu);if (ret) goto out_fail;/* Back to defaults. */ - ret =__sseu_test (i915, name, flags, ctx, engine, obj, default_sseu); + ret =__sseu_test (i915, name, flags, ce, obj, default_sseu);if (ret) goto out_fail;/* One last power-gated configuration for the road. */ - ret =__sseu_test (i915, name, flags, ctx, engine, obj, pg_sseu); + ret =__sseu_test (i915, name, flags, ce, obj, pg_sseu);if (ret) goto out_fail;
@@ -1117,9 +1128,12 @@ __igt_ctx_sseu(struct drm_i915_private *i915,if (igt_flush_test (i915,I915_WAIT_LOCKED )) ret = -EIO ; -i915_gem_object_put (obj); - +intel_context_unpin (ce); +out_context: +intel_context_put (ce); +out_rpm:intel_runtime_pm_put (i915, wakeref); +i915_gem_object_put (obj); out_unlock:mutex_unlock (&i915->drm.struct_mutex);
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 6/45 drm/i915: Pass intel_context to intel_context_pin_lock()
In reply to Chris WilsonMove the intel_context_instance() to the caller so that we can decouple ourselves from one context instance per engine.
v2: Rename pin_lock() to lock_pinned(), hopefully that is clearer.
--- drivers/gpu/drm/i915/gt/intel_context.c | 26 ------ drivers/gpu/drm/i915/gt/intel_context.h | 34 +++++-- drivers/gpu/drm/i915/i915_gem_context.c | 92 +++++++++++-------- .../gpu/drm/i915/selftests/i915_gem_context.c | 2 +- 4 files changed, 82 insertions(+), 72 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +0 -26
@@ -128,32 +128,6 @@ intel_context_instance(struct i915_gem_context *ctx,return intel_context_get (pos); } -struct intel_context * -intel_context_pin_lock (struct i915_gem_context *ctx, -struct intel_engine_cs *engine) - __acquires(ce->pin_mutex) -{ -struct intel_context *ce; - - ce =intel_context_instance (ctx, engine); -if (IS_ERR (ce)) -return ce; - -if (mutex_lock_interruptible (&ce->pin_mutex)) { -intel_context_put (ce); -return ERR_PTR (-EINTR ); - } - -return ce; -} - -void intel_context_pin_unlock (struct intel_context *ce) - __releases(ce->pin_mutex) -{ -mutex_unlock (&ce->pin_mutex); -intel_context_put (ce); -} -int __intel_context_do_pin (struct intel_context *ce) {int err;
drivers/gpu/drm/i915/gt/intel_context.h +27 -7
@@ -31,25 +31,45 @@ intel_context_lookup(struct i915_gem_context *ctx, struct intel_engine_cs *engine);/** -* intel_context_pin_lock - Stablises the 'pinned' status of the HW context -* @ctx - the parent GEM context -* @engine - the target HW engine +* intel_context_lock_pinned - Stablises the 'pinned' status of the HW context +* @ce - the context * * Acquire a lock on the pinned status of the HW context, such that the context * can neither be bound to the GPU or unbound whilst the lock is held, i.e. * intel_context_is_pinned() remains stable. */ -struct intel_context * -intel_context_pin_lock (struct i915_gem_context *ctx, -struct intel_engine_cs *engine); +static inline int intel_context_lock_pinned (struct intel_context *ce) + __acquires(ce->pin_mutex) +{ +return mutex_lock_interruptible (&ce->pin_mutex); +} +/** +* intel_context_is_pinned - Reports the 'pinned' status +* @ce - the context +* +* While in use by the GPU, the context, along with its ring and page +* tables is pinned into memory and the GTT. +* +* Returns: true if the context is currently pinned for use by the GPU. +*/ static inline bool intel_context_is_pinned (struct intel_context *ce) {return atomic_read (&ce->pin_count); } -void intel_context_pin_unlock (struct intel_context *ce); +/** +* intel_context_unlock_pinned - Releases the earlier locking of 'pinned' status +* @ce - the context +* +* Releases the lock earlier acquired by intel_context_unlock_pinned(). +*/ +static inline void intel_context_unlock_pinned (struct intel_context *ce) + __releases(ce->pin_mutex) +{ +mutex_unlock (&ce->pin_mutex); +}struct intel_context * __intel_context_insert(struct i915_gem_context *ctx,
drivers/gpu/drm/i915/i915_gem_context.c +54 -38
167 lines not on this page · raw message
drivers/gpu/drm/i915/selftests/i915_gem_context.c +1 -1
@@ -1017,7 +1017,7 @@ __sseu_test(struct drm_i915_private *i915,if (ret)return ret; - ret =__i915_gem_context_reconfigure_sseu (ce->gem_context, ce->engine, sseu); + ret =__intel_context_reconfigure_sseu (ce, sseu);if (ret) goto out_spin;
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 7/45 drm/i915: Split engine setup/init into two phases
In reply to Chris WilsonIn the next patch, we require the engine vfuncs setup prior to initialising the pinned kernel contexts, so split the vfunc setup from the engine initialisation and call it earlier.
v2: s/setup_xcs/setup_common/ for intel_ring_submission_setup()
--- drivers/gpu/drm/i915/gt/intel_engine.h | 8 +- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 99 ++++---- drivers/gpu/drm/i915/gt/intel_lrc.c | 74 ++---- drivers/gpu/drm/i915/gt/intel_lrc.h | 5 +- drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 232 +++++++++--------- drivers/gpu/drm/i915/gt/intel_workarounds.c | 3 +- drivers/gpu/drm/i915/gt/mock_engine.c | 48 ++-- drivers/gpu/drm/i915/gt/mock_engine.h | 2 + drivers/gpu/drm/i915/i915_gem.c | 6 + .../gpu/drm/i915/selftests/mock_gem_device.c | 12 +- 10 files changed, 245 insertions(+), 244 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine.h +3 -5
@@ -362,14 +362,12 @@ __intel_ring_space(unsigned int head, unsigned int tail, unsigned int size)return (head - tail -CACHELINE_BYTES ) & (size -1 ); } -int intel_engine_setup_common (struct intel_engine_cs *engine); +int intel_engines_setup (struct drm_i915_private *i915);int intel_engine_init_common (struct intel_engine_cs *engine);void intel_engine_cleanup_common (struct intel_engine_cs *engine); -int intel_init_render_ring_buffer (struct intel_engine_cs *engine); -int intel_init_bsd_ring_buffer (struct intel_engine_cs *engine); -int intel_init_blt_ring_buffer (struct intel_engine_cs *engine); -int intel_init_vebox_ring_buffer (struct intel_engine_cs *engine); +int intel_ring_submission_setup (struct intel_engine_cs *engine); +int intel_ring_submission_init (struct intel_engine_cs *engine);int intel_engine_stop_cs (struct intel_engine_cs *engine);void intel_engine_cancel_stop_cs (struct intel_engine_cs *engine);
drivers/gpu/drm/i915/gt/intel_engine_cs.c +58 -41
163 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_lrc.c +19 -55
108 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_lrc.h +3 -2
@@ -66,8 +66,9 @@ enum {/* Logical Rings */ void intel_logical_ring_cleanup (struct intel_engine_cs *engine); -int logical_render_ring_init (struct intel_engine_cs *engine); -int logical_xcs_ring_init (struct intel_engine_cs *engine); + +int intel_execlists_submission_setup (struct intel_engine_cs *engine); +int intel_execlists_submission_init (struct intel_engine_cs *engine);/* Logical Ring Contexts */
drivers/gpu/drm/i915/gt/intel_ringbuffer.c +116 -116
330 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_workarounds.c +2 -1
@@ -1077,7 +1077,8 @@ void intel_engine_init_whitelist(struct intel_engine_cs *engine)struct drm_i915_private *i915 = engine->i915;struct i915_wa_list *w = &engine->whitelist; -GEM_BUG_ON (engine->id !=RCS0 ); +if (engine->class !=RENDER_CLASS ) +return ;wa_init_start (w,"whitelist" );
drivers/gpu/drm/i915/gt/mock_engine.c +27 -21
71 lines not on this page · raw message
drivers/gpu/drm/i915/gt/mock_engine.h +2 -0
@@ -42,6 +42,8 @@ struct mock_engine {struct intel_engine_cs *mock_engine (struct drm_i915_private *i915,const char *name,int id); +int mock_engine_init (struct intel_engine_cs *engine); +void mock_engine_flush (struct intel_engine_cs *engine);void mock_engine_reset (struct intel_engine_cs *engine);void mock_engine_free (struct intel_engine_cs *engine);
drivers/gpu/drm/i915/i915_gem.c +6 -0
@@ -4517,6 +4517,12 @@ int i915_gem_init(struct drm_i915_private *dev_priv) goto err_ggtt; } + ret =intel_engines_setup (dev_priv); +if (ret) { +GEM_BUG_ON (ret == -EIO ); + goto err_unlock; + } + ret =i915_gem_contexts_init (dev_priv);if (ret) {GEM_BUG_ON (ret == -EIO );
drivers/gpu/drm/i915/selftests/mock_gem_device.c +9 -3
@@ -209,12 +209,16 @@ struct drm_i915_private *mock_gem_device(void)mock_init_ggtt (i915, &i915->ggtt);mkwrite_device_info (i915)->engine_mask =BIT (0 ); - i915->kernel_context =mock_context (i915,NULL ); -if (!i915->kernel_context) - goto err_unlock; i915->engine[RCS0 ] =mock_engine (i915,"mock" ,RCS0 );if (!i915->engine[RCS0 ]) + goto err_unlock; + + i915->kernel_context =mock_context (i915,NULL ); +if (!i915->kernel_context) + goto err_engine; + +if (mock_engine_init (i915->engine[RCS0 ])) goto err_context;mutex_unlock (&i915->drm.struct_mutex);
@@ -225,6 +229,8 @@ struct drm_i915_private *mock_gem_device(void) err_context:i915_gem_contexts_fini (i915); +err_engine: +mock_engine_free (i915->engine[RCS0 ]); err_unlock:mutex_unlock (&i915->drm.struct_mutex);i915_timelines_fini (i915);
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 8/45 drm/i915: Switch back to an array of logical per-engine HW contexts
In reply to Chris WilsonWe switched to a tree of per-engine HW context to accommodate the introduction of virtual engines. However, we plan to also support multiple instances of the same engine within the GEM context, defeating our use of the engine as a key to looking up the HW context. Just allocate a logical per-engine instance and always use an index into the ctx->engines[]. Later on, this ctx->engines[] may be replaced by a user specified map.
v2: Add for_each_gem_engine() helper to iterator within the engines lock
v3: intel_context_create_request() helper
v4: s/unsigned long/unsigned int/ 4 billion engines is quite enough.
v5: Push iterator locking to caller
--- drivers/gpu/drm/i915/gt/intel_context.c | 112 ++++-------------- drivers/gpu/drm/i915/gt/intel_context.h | 27 +---- drivers/gpu/drm/i915/gt/intel_context_types.h | 2 - drivers/gpu/drm/i915/gt/intel_engine_cs.c | 2 +- drivers/gpu/drm/i915/gt/mock_engine.c | 3 +- drivers/gpu/drm/i915/gvt/scheduler.c | 2 +- drivers/gpu/drm/i915/i915_gem.c | 24 ++-- drivers/gpu/drm/i915/i915_gem_context.c | 99 ++++++++++++++-- drivers/gpu/drm/i915/i915_gem_context.h | 58 +++++++++ drivers/gpu/drm/i915/i915_gem_context_types.h | 40 ++++++- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 70 +++++------ drivers/gpu/drm/i915/i915_perf.c | 80 +++++++------ drivers/gpu/drm/i915/i915_request.c | 15 +-- drivers/gpu/drm/i915/intel_guc_submission.c | 22 ++-- .../gpu/drm/i915/selftests/i915_gem_context.c | 2 +- drivers/gpu/drm/i915/selftests/mock_context.c | 14 ++- 16 files changed, 331 insertions(+), 241 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +21 -91
@@ -17,7 +17,7 @@ static struct i915_global_context {struct kmem_cache *slab_ce; } global; -struct intel_context *intel_context_alloc (void ) +static struct intel_context *intel_context_alloc (void ) {return kmem_cache_zalloc (global.slab_ce,GFP_KERNEL ); }
@@ -28,104 +28,17 @@ void intel_context_free(struct intel_context *ce) }struct intel_context * -intel_context_lookup (struct i915_gem_context *ctx, +intel_context_create (struct i915_gem_context *ctx,struct intel_engine_cs *engine) { -struct intel_context *ce =NULL ; -struct rb_node *p; - -spin_lock (&ctx->hw_contexts_lock); - p = ctx->hw_contexts.rb_node; -while (p) { -struct intel_context *this = - rb_entry(p, struct intel_context, node); - -if (this->engine == engine) { -GEM_BUG_ON (this->gem_context != ctx); - ce = this; -break ; - } - -if (this->engine < engine) - p = p->rb_right; -else - p = p->rb_left; - } -spin_unlock (&ctx->hw_contexts_lock); - -return ce; -} - -struct intel_context * -__intel_context_insert (struct i915_gem_context *ctx, -struct intel_engine_cs *engine, -struct intel_context *ce) -{ -struct rb_node **p, *parent; -int err =0 ; - -spin_lock (&ctx->hw_contexts_lock); - - parent =NULL ; - p = &ctx->hw_contexts.rb_node; -while (*p) { -struct intel_context *this; - - parent = *p; - this = rb_entry(parent, struct intel_context, node); - -if (this->engine == engine) { - err = -EEXIST ; - ce = this; -break ; - } - -if (this->engine < engine) - p = &parent->rb_right; -else - p = &parent->rb_left; - } -if (!err) { -rb_link_node (&ce->node, parent, p); -rb_insert_color (&ce->node, &ctx->hw_contexts); - } - -spin_unlock (&ctx->hw_contexts_lock); - -return ce; -} - -void __intel_context_remove (struct intel_context *ce) -{ -struct i915_gem_context *ctx = ce->gem_context; - -spin_lock (&ctx->hw_contexts_lock); -rb_erase (&ce->node, &ctx->hw_contexts); -spin_unlock (&ctx->hw_contexts_lock); -} - -struct intel_context * -intel_context_instance (struct i915_gem_context *ctx, -struct intel_engine_cs *engine) -{ -struct intel_context *ce, *pos; - - ce =intel_context_lookup (ctx, engine); -if (likely (ce)) -return intel_context_get (ce); +struct intel_context *ce; ce =intel_context_alloc ();if (!ce)return ERR_PTR (-ENOMEM );intel_context_init (ce, ctx, engine); - - pos =__intel_context_insert (ctx, engine, ce); -if (unlikely (pos != ce))/* Beaten! Use their HW context instead */ -intel_context_free (ce); - -GEM_BUG_ON (intel_context_lookup (ctx, engine) != pos); -return intel_context_get (pos); +return ce; }int __intel_context_do_pin (struct intel_context *ce)
@@ -204,6 +117,8 @@ intel_context_init(struct intel_context *ce,struct i915_gem_context *ctx, struct intel_engine_cs *engine) { + GEM_BUG_ON(!engine->cops); +kref_init (&ce->ref); ce->gem_context = ctx;
@@ -254,3 +169,18 @@ void intel_context_exit_engine(struct intel_context *ce) {intel_engine_pm_put (ce->engine); } + +struct i915_request *intel_context_create_request (struct intel_context *ce) +{ +struct i915_request *rq; +int err; + + err =intel_context_pin (ce); +if (unlikely (err)) +return ERR_PTR (err); + + rq =i915_request_create (ce); +intel_context_unpin (ce); + +return rq; +}
drivers/gpu/drm/i915/gt/intel_context.h +5 -22
@@ -12,24 +12,16 @@#include "intel_context_types.h" #include "intel_engine_types.h" -struct intel_context *intel_context_alloc (void ); -void intel_context_free (struct intel_context *ce); -void intel_context_init (struct intel_context *ce,struct i915_gem_context *ctx,struct intel_engine_cs *engine); -/** -* intel_context_lookup - Find the matching HW context for this (ctx, engine) -* @ctx - the parent GEM context -* @engine - the target HW engine -* -* May return NULL if the HW context hasn't been instantiated (i.e. unused). -*/ struct intel_context * -intel_context_lookup (struct i915_gem_context *ctx, +intel_context_create (struct i915_gem_context *ctx,struct intel_engine_cs *engine); +void intel_context_free (struct intel_context *ce); +/** * intel_context_lock_pinned - Stablises the 'pinned' status of the HW context * @ce - the context
@@ -71,17 +63,6 @@ static inline void intel_context_unlock_pinned(struct intel_context *ce)mutex_unlock (&ce->pin_mutex); } -struct intel_context * -__intel_context_insert (struct i915_gem_context *ctx, -struct intel_engine_cs *engine, -struct intel_context *ce); -void -__intel_context_remove (struct intel_context *ce); - -struct intel_context * -intel_context_instance (struct i915_gem_context *ctx, -struct intel_engine_cs *engine); -int __intel_context_do_pin (struct intel_context *ce);static inline int intel_context_pin (struct intel_context *ce)
@@ -144,4 +125,6 @@ static inline void intel_context_timeline_unlock(struct intel_context *ce) mutex_unlock(&ce->ring->timeline->mutex); } +struct i915_request *intel_context_create_request (struct intel_context *ce); +#endif /* __INTEL_CONTEXT_H__ */
drivers/gpu/drm/i915/gt/intel_context_types.h +0 -2
@@ -10,7 +10,6 @@#include <linux/kref.h> #include <linux/list.h> #include <linux/mutex.h> -#include <linux/rbtree.h> #include <linux/types.h> #include "i915_active_types.h"
@@ -61,7 +60,6 @@ struct intel_context {struct i915_active_request active_tracker;const struct intel_context_ops *ops; -struct rb_node node;/** sseu: Control eu/slice partitioning */ struct intel_sseu sseu;
drivers/gpu/drm/i915/gt/intel_engine_cs.c +1 -1
@@ -716,7 +716,7 @@ static int pin_context(struct i915_gem_context *ctx,struct intel_context *ce;int err; - ce =intel_context_instance (ctx, engine); + ce =i915_gem_context_get_engine (ctx, engine->id);if (IS_ERR (ce))return PTR_ERR (ce);
drivers/gpu/drm/i915/gt/mock_engine.c +2 -1
@@ -23,6 +23,7 @@*/ #include "i915_drv.h" +#include "i915_gem_context.h" #include "intel_context.h" #include "intel_engine_pm.h"
@@ -286,7 +287,7 @@ int mock_engine_init(struct intel_engine_cs *engine)i915_timeline_set_subclass (&engine->timeline,TIMELINE_ENGINE ); engine->kernel_context = -intel_context_instance (i915->kernel_context, engine); +i915_gem_context_get_engine (i915->kernel_context, engine->id);if (IS_ERR (engine->kernel_context)) goto err_timeline;
drivers/gpu/drm/i915/gvt/scheduler.c +1 -1
@@ -1188,7 +1188,7 @@ int intel_vgpu_setup_submission(struct intel_vgpu *vgpu)INIT_LIST_HEAD (&s->workload_q_head[i]); s->shadow[i] =ERR_PTR (-EINVAL ); - ce =intel_context_instance (ctx, engine); + ce =i915_gem_context_get_engine (ctx, i);if (IS_ERR (ce)) { ret =PTR_ERR (ce); goto out_shadow_ctx;
drivers/gpu/drm/i915/i915_gem.c +12 -12
@@ -4289,8 +4289,9 @@ int i915_gem_init_hw(struct drm_i915_private *dev_priv)static int __intel_engines_record_defaults (struct drm_i915_private *i915) { -struct i915_gem_context *ctx;struct intel_engine_cs *engine; +struct i915_gem_context *ctx; +struct i915_gem_engines *e;enum intel_engine_id id;int err =0 ;
@@ -4307,18 +4308,21 @@ static int __intel_engines_record_defaults(struct drm_i915_private *i915)if (IS_ERR (ctx))return PTR_ERR (ctx); + e =i915_gem_context_lock_engines (ctx); +for_each_engine (engine, i915, id) { +struct intel_context *ce = e->engines[id];struct i915_request *rq; - rq =i915_request_alloc (engine, ctx); + rq =intel_context_create_request (ce);if (IS_ERR (rq)) { err =PTR_ERR (rq); - goto out_ctx; + goto err_active; } err =0 ; -if (engine->init_context) - err = engine->init_context (rq); +if (rq->engine->init_context) + err = rq->engine->init_context (rq);i915_request_add (rq);if (err)
@@ -4332,15 +4336,10 @@ static int __intel_engines_record_defaults(struct drm_i915_private *i915) }for_each_engine (engine, i915, id) { -struct intel_context *ce; -struct i915_vma *state; +struct intel_context *ce = e->engines[id]; +struct i915_vma *state = ce->state;void *vaddr; - ce =intel_context_lookup (ctx, engine); -if (!ce) -continue ; - - state = ce->state;if (!state)continue ;
@@ -4396,6 +4395,7 @@ static int __intel_engines_record_defaults(struct drm_i915_private *i915) } out_ctx: +i915_gem_context_unlock_engines (ctx);i915_gem_context_set_closed (ctx);i915_gem_context_put (ctx);return err;
drivers/gpu/drm/i915/i915_gem_context.c +86 -13
170 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_context.h +58 -0
64 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_context_types.h +36 -4
@@ -29,6 +29,18 @@ struct i915_hw_ppgtt;struct i915_timeline ;struct intel_ring ; +struct i915_gem_engines { +struct rcu_work rcu; +struct drm_i915_private *i915; +unsigned int num_engines; +struct intel_context *engines[]; +}; + +struct i915_gem_engines_iter { +unsigned int idx; +const struct i915_gem_engines *engines; +}; +/** * struct i915_gem_context - client state *
@@ -42,6 +54,30 @@ struct i915_gem_context {/** file_priv: owning file descriptor */ struct drm_i915_file_private *file_priv; +/** +* @engines: User defined engines for this context +* +* Various uAPI offer the ability to lookup up an +* index from this array to select an engine operate on. +* +* Multiple logically distinct instances of the same engine +* may be defined in the array, as well as composite virtual +* engines. +* +* Execbuf uses the I915_EXEC_RING_MASK as an index into this +* array to select which HW context + engine to execute on. For +* the default array, the user_ring_map[] is used to translate +* the legacy uABI onto the approprate index (e.g. both +* I915_EXEC_DEFAULT and I915_EXEC_RENDER select the same +* context, and I915_EXEC_BSD is weird). For a use defined +* array, execbuf uses I915_EXEC_RING_MASK as a plain index. +* +* User defined by I915_CONTEXT_PARAM_ENGINE (when the +* CONTEXT_USER_ENGINES flag is set). +*/ +struct i915_gem_engines __rcu *engines; +struct mutex engines_mutex;/* guards writes to engines */ +struct i915_timeline *timeline;/**
@@ -134,10 +170,6 @@ struct i915_gem_context {struct i915_sched_attr sched; -/** hw_contexts: per-engine logical HW state */ -struct rb_root hw_contexts; -spinlock_t hw_contexts_lock; -/** ring_size: size for allocating the per-engine ring buffer */ u32 ring_size;/** desc_template: invariant fields for the HW context descriptor */
drivers/gpu/drm/i915/i915_gem_execbuffer.c +37 -33
122 lines not on this page · raw message
drivers/gpu/drm/i915/i915_perf.c +46 -34
118 lines not on this page · raw message
drivers/gpu/drm/i915/i915_request.c +3 -12
@@ -786,7 +786,6 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)struct drm_i915_private *i915 = engine->i915;struct intel_context *ce;struct i915_request *rq; -int err;/* * Preempt contexts are reserved for exclusive use to inject a
@@ -800,21 +799,13 @@ i915_request_alloc(struct intel_engine_cs *engine, struct i915_gem_context *ctx)* GGTT space, so do this first before we reserve a seqno for * ourselves. */ - ce =intel_context_instance (ctx, engine); + ce =i915_gem_context_get_engine (ctx, engine->id);if (IS_ERR (ce))return ERR_CAST (ce); - err =intel_context_pin (ce); -if (err) { - rq =ERR_PTR (err); - goto err_put; - } - - rq =i915_request_create (ce); -intel_context_unpin (ce); - -err_put: + rq =intel_context_create_request (ce);intel_context_put (ce); +return rq; }
drivers/gpu/drm/i915/intel_guc_submission.c +12 -10
@@ -364,11 +364,10 @@ static void guc_stage_desc_pool_destroy(struct intel_guc *guc)static void guc_stage_desc_init (struct intel_guc_client *client) {struct intel_guc *guc = client->guc; -struct drm_i915_private *dev_priv =guc_to_i915 (guc); -struct intel_engine_cs *engine;struct i915_gem_context *ctx = client->owner; +struct i915_gem_engines_iter it;struct guc_stage_desc *desc; -unsigned int tmp; +struct intel_context *ce;u32 gfx_addr; desc =__get_stage_desc (client);
@@ -382,10 +381,11 @@ static void guc_stage_desc_init(struct intel_guc_client *client) desc->priority = client->priority; desc->db_id = client->doorbell_id; -for_each_engine_masked (engine, dev_priv, client->engines, tmp) { -struct intel_context *ce =intel_context_lookup (ctx, engine); -u32 guc_engine_id = engine->guc_id; -struct guc_execlist_context *lrc = &desc->lrc[guc_engine_id]; +for_each_gem_engine (ce,i915_gem_context_lock_engines (ctx), it) { +struct guc_execlist_context *lrc; + +if (!(ce->engine->mask & client->engines)) +continue ;/* TODO: We have a design issue to be solved here. Only when we * receive the first batch, we know which engine is used by the
@@ -394,7 +394,7 @@ static void guc_stage_desc_init(struct intel_guc_client *client)* for now who owns a GuC client. But for future owner of GuC * client, need to make sure lrc is pinned prior to enter here. */ -if (!ce || !ce->state) +if (!ce->state)break ;/* XXX: continue? */ /*
@@ -404,6 +404,7 @@ static void guc_stage_desc_init(struct intel_guc_client *client)* Instead, the GuC uses the LRCA of the user mode context (see * guc_add_request below). */ + lrc = &desc->lrc[ce->engine->guc_id]; lrc->context_desc =lower_32_bits (ce->lrc_desc);/* The state page is after PPHWSP */
@@ -414,15 +415,16 @@ static void guc_stage_desc_init(struct intel_guc_client *client)* here. In proxy submission, it wants the stage id */ lrc->context_id = (client->stage_id <<GUC_ELC_CTXID_OFFSET ) | - (guc_engine_id <<GUC_ELC_ENGINE_OFFSET ); + (ce->engine->guc_id <<GUC_ELC_ENGINE_OFFSET ); lrc->ring_begin =intel_guc_ggtt_offset (guc, ce->ring->vma); lrc->ring_end = lrc->ring_begin + ce->ring->size -1 ; lrc->ring_next_free_location = lrc->ring_begin; lrc->ring_current_tail_pointer_value =0 ; - desc->engines_used |= (1 << guc_engine_id); + desc->engines_used |=BIT (ce->engine->guc_id); } +i915_gem_context_unlock_engines (ctx);DRM_DEBUG_DRIVER ("Host engines 0x%x => GuC engines used 0x%x\n" , client->engines, desc->engines_used);
drivers/gpu/drm/i915/selftests/i915_gem_context.c +1 -1
@@ -1094,7 +1094,7 @@ __igt_ctx_sseu(struct drm_i915_private *i915, wakeref =intel_runtime_pm_get (i915); - ce =intel_context_instance (ctx, i915->engine[RCS0 ]); + ce =i915_gem_context_get_engine (ctx,RCS0 );if (IS_ERR (ce)) { ret =PTR_ERR (ce); goto out_rpm;
drivers/gpu/drm/i915/selftests/mock_context.c +10 -4
@@ -30,6 +30,7 @@ mock_context(struct drm_i915_private *i915, const char *name) {struct i915_gem_context *ctx; +struct i915_gem_engines *e;int ret; ctx =kzalloc (sizeof (*ctx),GFP_KERNEL );
@@ -40,8 +41,11 @@ mock_context(struct drm_i915_private *i915,INIT_LIST_HEAD (&ctx->link); ctx->i915 = i915; - ctx->hw_contexts =RB_ROOT ; -spin_lock_init (&ctx->hw_contexts_lock); +mutex_init (&ctx->engines_mutex); + e =default_engines (ctx); +if (IS_ERR (e)) + goto err_free; +RCU_INIT_POINTER (ctx->engines, e);INIT_RADIX_TREE (&ctx->handles_vma,GFP_KERNEL );INIT_LIST_HEAD (&ctx->handles_list);
@@ -51,7 +55,7 @@ mock_context(struct drm_i915_private *i915, ret =i915_gem_context_pin_hw_id (ctx);if (ret <0 ) - goto err_handles; + goto err_engines;if (name) {struct i915_hw_ppgtt *ppgtt;
@@ -69,7 +73,9 @@ mock_context(struct drm_i915_private *i915,return ctx; -err_handles: +err_engines: +free_engines (rcu_access_pointer (ctx->engines)); +err_free:kfree (ctx);return NULL ;
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 9/45 drm/i915: Remove intel_context.active_link
In reply to Chris WilsonWe no longer need to track the active intel_contexts within each engine, allowing us to drop a tricky mutex_lock from inside unpin (which may occur inside fs_reclaim).
--- drivers/gpu/drm/i915/gt/intel_context.c | 11 +---------- drivers/gpu/drm/i915/gt/intel_context_types.h | 1 - drivers/gpu/drm/i915/i915_debugfs.c | 11 +++++++++-- drivers/gpu/drm/i915/i915_gem_context.c | 2 -- drivers/gpu/drm/i915/i915_gem_context_types.h | 1 - drivers/gpu/drm/i915/selftests/i915_gem_context.c | 1 - drivers/gpu/drm/i915/selftests/mock_context.c | 1 - 7 files changed, 10 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +1 -10
@@ -49,7 +49,6 @@ int __intel_context_do_pin(struct intel_context *ce)return -EINTR ;if (likely (!atomic_read (&ce->pin_count))) { -struct i915_gem_context *ctx = ce->gem_context;intel_wakeref_t wakeref; err =0 ;
@@ -58,11 +57,7 @@ int __intel_context_do_pin(struct intel_context *ce)if (err) goto err; -i915_gem_context_get (ctx); - -mutex_lock (&ctx->mutex); -list_add (&ce->active_link, &ctx->active_engines); -mutex_unlock (&ctx->mutex); +i915_gem_context_get (ce->gem_context);/* for ctx->ppgtt */ intel_context_get (ce);smp_mb__before_atomic ();/* flush pin before it is visible */
@@ -91,10 +86,6 @@ void intel_context_unpin(struct intel_context *ce)if (likely (atomic_dec_and_test (&ce->pin_count))) { ce->ops->unpin (ce); -mutex_lock (&ce->gem_context->mutex); -list_del (&ce->active_link); -mutex_unlock (&ce->gem_context->mutex); -i915_gem_context_put (ce->gem_context);intel_context_put (ce); }
drivers/gpu/drm/i915/gt/intel_context_types.h +0 -1
@@ -38,7 +38,6 @@ struct intel_context {struct intel_engine_cs *engine;struct intel_engine_cs *active; -struct list_head active_link;struct list_head signal_link;struct list_head signals;
drivers/gpu/drm/i915/i915_debugfs.c +9 -2
@@ -34,6 +34,7 @@#include "gt/intel_reset.h" +#include "i915_gem_context.h" #include "intel_dp.h" #include "intel_drv.h" #include "intel_fbc.h"
@@ -396,14 +397,17 @@ static void print_context_stats(struct seq_file *m,struct i915_gem_context *ctx;list_for_each_entry (ctx, &i915->contexts.list, link) { +struct i915_gem_engines_iter it;struct intel_context *ce; -list_for_each_entry (ce, &ctx->active_engines, active_link) { +for_each_gem_engine (ce, +i915_gem_context_lock_engines (ctx), it) {if (ce->state)per_file_stats (0 , ce->state->obj, &kstats);if (ce->ring)per_file_stats (0 , ce->ring->vma->obj, &kstats); } +i915_gem_context_unlock_engines (ctx);if (!IS_ERR_OR_NULL (ctx->file_priv)) {struct file_stats stats = { .vm = &ctx->ppgtt->vm, };
@@ -1893,6 +1897,7 @@ static int i915_context_status(struct seq_file *m, void *unused)return ret;list_for_each_entry (ctx, &dev_priv->contexts.list, link) { +struct i915_gem_engines_iter it;struct intel_context *ce;seq_puts (m,"HW context " );
@@ -1917,7 +1922,8 @@ static int i915_context_status(struct seq_file *m, void *unused)seq_putc (m, ctx->remap_slice ?'R' :'r' );seq_putc (m,'\n' ); -list_for_each_entry (ce, &ctx->active_engines, active_link) { +for_each_gem_engine (ce, +i915_gem_context_lock_engines (ctx), it) {seq_printf (m,"%s: " , ce->engine->name);if (ce->state)describe_obj (m, ce->state->obj);
@@ -1925,6 +1931,7 @@ static int i915_context_status(struct seq_file *m, void *unused)describe_ctx_ring (m, ce->ring);seq_putc (m,'\n' ); } +i915_gem_context_unlock_engines (ctx);seq_putc (m,'\n' ); }
drivers/gpu/drm/i915/i915_gem_context.c +0 -2
@@ -289,7 +289,6 @@ static void i915_gem_context_free(struct i915_gem_context *ctx) {lockdep_assert_held (&ctx->i915->drm.struct_mutex);GEM_BUG_ON (!i915_gem_context_is_closed (ctx)); -GEM_BUG_ON (!list_empty (&ctx->active_engines));release_hw_id (ctx);i915_ppgtt_put (ctx->ppgtt);
@@ -416,7 +415,6 @@ __create_context(struct drm_i915_private *dev_priv)list_add_tail (&ctx->link, &dev_priv->contexts.list); ctx->i915 = dev_priv; ctx->sched.priority =I915_USER_PRIORITY (I915_PRIORITY_NORMAL ); -INIT_LIST_HEAD (&ctx->active_engines);mutex_init (&ctx->mutex);mutex_init (&ctx->engines_mutex);
drivers/gpu/drm/i915/i915_gem_context_types.h +0 -1
@@ -165,7 +165,6 @@ struct i915_gem_context {atomic_t hw_id_pin_count;struct list_head hw_id_link; -struct list_head active_engines;struct mutex mutex;struct i915_sched_attr sched;
drivers/gpu/drm/i915/selftests/i915_gem_context.c +0 -1
@@ -1675,7 +1675,6 @@ static int mock_context_barrier(void *arg) goto out; }i915_request_add (rq); -GEM_BUG_ON (list_empty (&ctx->active_engines)); counter =0 ; context_barrier_inject_fault =BIT (RCS0 );
drivers/gpu/drm/i915/selftests/mock_context.c +0 -1
@@ -50,7 +50,6 @@ mock_context(struct drm_i915_private *i915,INIT_RADIX_TREE (&ctx->handles_vma,GFP_KERNEL );INIT_LIST_HEAD (&ctx->handles_list);INIT_LIST_HEAD (&ctx->hw_id_link); -INIT_LIST_HEAD (&ctx->active_engines);mutex_init (&ctx->mutex); ret =i915_gem_context_pin_hw_id (ctx);
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 10/45 drm/i915: Move i915_request_alloc into selftests/
In reply to Chris WilsonHaving transitioned GEM over to using intel_context as its primary means of tracking the GEM context and engine combined and using i915_request_create(), we can move the older i915_request_alloc() helper function into selftests/ where the remaining users are confined.
--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 9 +++-- drivers/gpu/drm/i915/gt/selftest_lrc.c | 13 ++++--- .../gpu/drm/i915/gt/selftest_workarounds.c | 15 +++----- drivers/gpu/drm/i915/i915_request.c | 38 ------------------- drivers/gpu/drm/i915/i915_request.h | 3 -- drivers/gpu/drm/i915/selftests/huge_pages.c | 3 +- drivers/gpu/drm/i915/selftests/i915_gem.c | 5 ++- .../gpu/drm/i915/selftests/i915_gem_context.c | 13 ++++--- .../gpu/drm/i915/selftests/i915_gem_evict.c | 3 +- drivers/gpu/drm/i915/selftests/i915_request.c | 4 +- .../gpu/drm/i915/selftests/igt_gem_utils.c | 34 +++++++++++++++++ .../gpu/drm/i915/selftests/igt_gem_utils.h | 17 +++++++++ drivers/gpu/drm/i915/selftests/igt_spinner.c | 3 +- drivers/gpu/drm/i915/selftests/mock_request.c | 3 +- 15 files changed, 89 insertions(+), 75 deletions(-) create mode 100644 drivers/gpu/drm/i915/selftests/igt_gem_utils.c create mode 100644 drivers/gpu/drm/i915/selftests/igt_gem_utils.h
drivers/gpu/drm/i915/Makefile +1 -0
@@ -193,6 +193,7 @@ i915-$(CONFIG_DRM_I915_SELFTEST) += \ selftests/i915_random.o \ selftests/i915_selftest.o \ selftests/igt_flush_test.o \ + selftests/igt_gem_utils.o \ selftests/igt_live_test.o \ selftests/igt_reset.o \ selftests/igt_spinner.o
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +5 -4
@@ -29,6 +29,7 @@#include "i915_selftest.h" #include "selftests/i915_random.h" #include "selftests/igt_flush_test.h" +#include "selftests/igt_gem_utils.h" #include "selftests/igt_reset.h" #include "selftests/igt_wedge_me.h"
@@ -175,7 +176,7 @@ hang_create_request(struct hang *h, struct intel_engine_cs *engine)if (err) goto unpin_vma; - rq =i915_request_alloc (engine, h->ctx); + rq =igt_request_alloc (h->ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto unpin_hws;
@@ -455,7 +456,7 @@ static int igt_reset_nop(void *arg)for (i =0 ; i <16 ; i++) {struct i915_request *rq; - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq);break ;
@@ -554,7 +555,7 @@ static int igt_reset_nop_engine(void *arg)for (i =0 ; i <16 ; i++) {struct i915_request *rq; - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq);break ;
@@ -800,7 +801,7 @@ static int active_engine(void *data)struct i915_request *new;mutex_lock (&engine->i915->drm.struct_mutex); - new =i915_request_alloc (engine, ctx[idx]); + new =igt_request_alloc (ctx[idx], engine);if (IS_ERR (new)) {mutex_unlock (&engine->i915->drm.struct_mutex); err =PTR_ERR (new);
drivers/gpu/drm/i915/gt/selftest_lrc.c +7 -6
@@ -10,6 +10,7 @@#include "i915_selftest.h" #include "selftests/i915_random.h" #include "selftests/igt_flush_test.h" +#include "selftests/igt_gem_utils.h" #include "selftests/igt_live_test.h" #include "selftests/igt_spinner.h" #include "selftests/mock_context.h"
@@ -148,7 +149,7 @@ static int live_busywait_preempt(void *arg)* fails, we hang instead. */ - lo =i915_request_alloc (engine, ctx_lo); + lo =igt_request_alloc (ctx_lo, engine);if (IS_ERR (lo)) { err =PTR_ERR (lo); goto err_vma;
@@ -192,7 +193,7 @@ static int live_busywait_preempt(void *arg) goto err_vma; } - hi =i915_request_alloc (engine, ctx_hi); + hi =igt_request_alloc (ctx_hi, engine);if (IS_ERR (hi)) { err =PTR_ERR (hi); goto err_vma;
@@ -857,13 +858,13 @@ static int live_chain_preempt(void *arg)i915_request_add (rq);for (i =0 ; i < count; i++) { - rq =i915_request_alloc (engine, lo.ctx); + rq =igt_request_alloc (lo.ctx, engine);if (IS_ERR (rq)) goto err_wedged;i915_request_add (rq); } - rq =i915_request_alloc (engine, hi.ctx); + rq =igt_request_alloc (hi.ctx, engine);if (IS_ERR (rq)) goto err_wedged;i915_request_add (rq);
@@ -882,7 +883,7 @@ static int live_chain_preempt(void *arg) }igt_spinner_end (&lo.spin); - rq =i915_request_alloc (engine, lo.ctx); + rq =igt_request_alloc (lo.ctx, engine);if (IS_ERR (rq)) goto err_wedged;i915_request_add (rq);
@@ -1087,7 +1088,7 @@ static int smoke_submit(struct preempt_smoke *smoke, ctx->sched.priority = prio; - rq =i915_request_alloc (smoke->engine, ctx); + rq =igt_request_alloc (ctx, smoke->engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto unpin;
drivers/gpu/drm/i915/gt/selftest_workarounds.c +5 -10
@@ -8,6 +8,7 @@#include "intel_reset.h" #include "selftests/igt_flush_test.h" +#include "selftests/igt_gem_utils.h" #include "selftests/igt_reset.h" #include "selftests/igt_spinner.h" #include "selftests/igt_wedge_me.h"
@@ -102,7 +103,7 @@ read_nonprivs(struct i915_gem_context *ctx, struct intel_engine_cs *engine)if (err) goto err_obj; - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto err_pin;
@@ -511,7 +512,7 @@ static int check_dirty_whitelist(struct i915_gem_context *ctx,i915_gem_object_unpin_map (batch->obj);i915_gem_chipset_flush (ctx->i915); - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto out_batch;
@@ -701,14 +702,11 @@ static int read_whitelisted_registers(struct i915_gem_context *ctx,struct intel_engine_cs *engine, struct i915_vma *results) { - intel_wakeref_t wakeref; struct i915_request *rq;int i, err =0 ;u32 srm, *cs; - rq =ERR_PTR (-ENODEV ); -with_intel_runtime_pm (engine->i915, wakeref) - rq = i915_request_alloc(engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq))return PTR_ERR (rq);
@@ -744,7 +742,6 @@ static int read_whitelisted_registers(struct i915_gem_context *ctx,static int scrub_whitelisted_registers (struct i915_gem_context *ctx,struct intel_engine_cs *engine) { -intel_wakeref_t wakeref;struct i915_request *rq;struct i915_vma *batch;int i, err =0 ;
@@ -770,9 +767,7 @@ static int scrub_whitelisted_registers(struct i915_gem_context *ctx,i915_gem_object_flush_map (batch->obj);i915_gem_chipset_flush (ctx->i915); - rq =ERR_PTR (-ENODEV ); -with_intel_runtime_pm (engine->i915, wakeref) - rq = i915_request_alloc(engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto err_unpin;
drivers/gpu/drm/i915/i915_request.c +0 -38
@@ -771,44 +771,6 @@ i915_request_create(struct intel_context *ce)return rq; } -/** -* i915_request_alloc - allocate a request structure -* -* @engine: engine that we wish to issue the request on. -* @ctx: context that the request will be associated with. -* -* Returns a pointer to the allocated request if successful, -* or an error code if not. -*/ -struct i915_request * -i915_request_alloc (struct intel_engine_cs *engine,struct i915_gem_context *ctx) -{ -struct drm_i915_private *i915 = engine->i915; -struct intel_context *ce; -struct i915_request *rq; - -/* -* Preempt contexts are reserved for exclusive use to inject a -* preemption context switch. They are never to be used for any trivial -* request! -*/ -GEM_BUG_ON (ctx == i915->preempt_context); - -/* -* Pinning the contexts may generate requests in order to acquire -* GGTT space, so do this first before we reserve a seqno for -* ourselves. -*/ - ce =i915_gem_context_get_engine (ctx, engine->id); -if (IS_ERR (ce)) -return ERR_CAST (ce); - - rq =intel_context_create_request (ce); -intel_context_put (ce); - -return rq; -} - static int emit_semaphore_wait(struct i915_request *to, struct i915_request *from,
drivers/gpu/drm/i915/i915_request.h +0 -3
@@ -246,9 +246,6 @@ i915_request_create(struct intel_context *ce);struct i915_request *__i915_request_commit (struct i915_request *request); -struct i915_request *__must_check -i915_request_alloc (struct intel_engine_cs *engine, -struct i915_gem_context *ctx);void i915_request_retire_upto (struct i915_request *rq); static inline struct i915_request *
drivers/gpu/drm/i915/selftests/huge_pages.c +2 -1
@@ -26,6 +26,7 @@#include <linux/prime_numbers.h> +#include "igt_gem_utils.h" #include "mock_drm.h" #include "i915_random.h"
@@ -980,7 +981,7 @@ static int gpu_write(struct i915_vma *vma,if (IS_ERR (batch))return PTR_ERR (batch); - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto err_batch;
drivers/gpu/drm/i915/selftests/i915_gem.c +3 -2
@@ -8,8 +8,9 @@#include "../i915_selftest.h" -#include "mock_context.h" +#include "igt_gem_utils.h" #include "igt_flush_test.h" +#include "mock_context.h" static int switch_to_context (struct drm_i915_private *i915,struct i915_gem_context *ctx)
@@ -20,7 +21,7 @@ static int switch_to_context(struct drm_i915_private *i915,for_each_engine (engine, i915, id) {struct i915_request *rq; - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq))return PTR_ERR (rq);
drivers/gpu/drm/i915/selftests/i915_gem_context.c +7 -6
@@ -29,6 +29,7 @@#include "i915_random.h" #include "igt_flush_test.h" +#include "igt_gem_utils.h" #include "igt_live_test.h" #include "igt_reset.h" #include "igt_spinner.h"
@@ -91,7 +92,7 @@ static int live_nop_switch(void *arg) times[0 ] =ktime_get_raw ();for (n =0 ; n < nctx; n++) { - rq =i915_request_alloc (engine, ctx[n]); + rq =igt_request_alloc (ctx[n], engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto out_unlock;
@@ -121,7 +122,7 @@ static int live_nop_switch(void *arg) times[1 ] =ktime_get_raw ();for (n =0 ; n < prime; n++) { - rq =i915_request_alloc (engine, ctx[n % nctx]); + rq =igt_request_alloc (ctx[n % nctx], engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto out_unlock;
@@ -301,7 +302,7 @@ static int gpu_fill(struct drm_i915_gem_object *obj, goto err_vma; } - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto err_batch;
@@ -1350,7 +1351,7 @@ static int write_to_scratch(struct i915_gem_context *ctx,if (err) goto err_unpin; - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto err_unpin;
@@ -1445,7 +1446,7 @@ static int read_from_scratch(struct i915_gem_context *ctx,if (err) goto err_unpin; - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto err_unpin;
@@ -1669,7 +1670,7 @@ static int mock_context_barrier(void *arg) goto out; } - rq =i915_request_alloc (i915->engine[RCS0 ], ctx); + rq =igt_request_alloc (ctx, i915->engine[RCS0 ]);if (IS_ERR (rq)) {pr_err ("Request allocation failed!\n" ); goto out;
drivers/gpu/drm/i915/selftests/i915_gem_evict.c +2 -1
@@ -24,6 +24,7 @@#include "../i915_selftest.h" +#include "igt_gem_utils.h" #include "lib_sw_fence.h" #include "mock_context.h" #include "mock_drm.h"
@@ -460,7 +461,7 @@ static int igt_evict_contexts(void *arg)/* We will need some GGTT space for the rq's context */ igt_evict_ctl.fail_if_busy = true; - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine); igt_evict_ctl.fail_if_busy = false;if (IS_ERR (rq)) {
drivers/gpu/drm/i915/selftests/i915_request.c +2 -2
@@ -267,7 +267,7 @@ static struct i915_request * __live_request_alloc(struct i915_gem_context *ctx, struct intel_engine_cs *engine) { - return i915_request_alloc(engine, ctx); + return igt_request_alloc(ctx, engine); }static int __igt_breadcrumbs_smoketest (void *arg)
@@ -1074,7 +1074,7 @@ max_batches(struct i915_gem_context *ctx, struct intel_engine_cs *engine)if (HAS_EXECLISTS (ctx->i915))return INT_MAX ; - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { ret =PTR_ERR (rq); }else {
drivers/gpu/drm/i915/selftests/igt_gem_utils.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* SPDX-License-Identifier: MIT +* +* Copyright © 2018 Intel Corporation +*/ + +#include "igt_gem_utils.h" + +#include "gt/intel_context.h" + +#include "../i915_gem_context.h" +#include "../i915_gem_pm.h" +#include "../i915_request.h" + +struct i915_request * +igt_request_alloc (struct i915_gem_context *ctx,struct intel_engine_cs *engine) +{ +struct intel_context *ce; +struct i915_request *rq; + +/* +* Pinning the contexts may generate requests in order to acquire +* GGTT space, so do this first before we reserve a seqno for +* ourselves. +*/ + ce =i915_gem_context_get_engine (ctx, engine->id); +if (IS_ERR (ce)) +return ERR_CAST (ce); + + rq =intel_context_create_request (ce); +intel_context_put (ce); + +return rq; +}
drivers/gpu/drm/i915/selftests/igt_gem_utils.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* SPDX-License-Identifier: MIT +* +* Copyright © 2018 Intel Corporation +*/ + +#ifndef __IGT_GEM_UTILS_H__ +#define __IGT_GEM_UTILS_H__ + +struct i915_request ; +struct i915_gem_context ; +struct intel_engine_cs ; + +struct i915_request * +igt_request_alloc (struct i915_gem_context *ctx,struct intel_engine_cs *engine); + +#endif /* __IGT_GEM_UTILS_H__ */
drivers/gpu/drm/i915/selftests/igt_spinner.c +2 -1
@@ -4,6 +4,7 @@* Copyright © 2018 Intel Corporation */ +#include "igt_gem_utils.h" #include "igt_spinner.h" int igt_spinner_init (struct igt_spinner *spin,struct drm_i915_private *i915)
@@ -114,7 +115,7 @@ igt_spinner_create_request(struct igt_spinner *spin,if (err) goto unpin_vma; - rq =i915_request_alloc (engine, ctx); + rq =igt_request_alloc (ctx, engine);if (IS_ERR (rq)) { err =PTR_ERR (rq); goto unpin_hws;
drivers/gpu/drm/i915/selftests/mock_request.c +2 -1
@@ -24,6 +24,7 @@#include "gt/mock_engine.h" +#include "igt_gem_utils.h" #include "mock_request.h" struct i915_request *
@@ -34,7 +35,7 @@ mock_request(struct intel_engine_cs *engine,struct i915_request *request;/* NB the i915->requests slab cache is enlarged to fit mock_request */ - request =i915_request_alloc (engine, context); + request =igt_request_alloc (context, engine);if (IS_ERR (request))return NULL ;
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 11/45 drm/i915/execlists: Flush the tasklet on parking
In reply to Chris WilsonTidy up the cleanup sequence by always ensure that the tasklet is flushed on parking (before we cleanup). The parking provides a convenient point to ensure that the backend is truly idle.
--- drivers/gpu/drm/i915/gt/intel_lrc.c | 25 +++++++-------------- drivers/gpu/drm/i915/intel_guc_submission.c | 1 + 2 files changed, 9 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/gt/intel_lrc.c +8 -17
@@ -2331,27 +2331,18 @@ static int gen8_init_rcs_context(struct i915_request *rq)return i915_gem_render_state_emit (rq); } +static void execlists_park (struct intel_engine_cs *engine) +{ +tasklet_kill (&engine->execlists.tasklet); +} +/** * intel_logical_ring_cleanup() - deallocate the Engine Command Streamer * @engine: Engine Command Streamer. */ void intel_logical_ring_cleanup (struct intel_engine_cs *engine) { -struct drm_i915_private *dev_priv; - -/* -* Tasklet cannot be active at this point due intel_mark_active/idle -* so this is just for documentation. -*/ -if (WARN_ON (test_bit (TASKLET_STATE_SCHED , - &engine->execlists.tasklet.state))) -tasklet_kill (&engine->execlists.tasklet); - - dev_priv = engine->i915; - -if (engine->buffer) { -WARN_ON ((ENGINE_READ (engine,RING_MI_MODE ) &MODE_IDLE ) ==0 ); - } +struct drm_i915_private *i915 = engine->i915;if (engine->cleanup) engine->cleanup (engine);
@@ -2361,7 +2352,7 @@ void intel_logical_ring_cleanup(struct intel_engine_cs *engine)lrc_destroy_wa_ctx (engine); engine->i915 =NULL ; - dev_priv->engine[engine->id] =NULL ; + i915->engine[engine->id] =NULL ;kfree (engine); }
@@ -2376,7 +2367,7 @@ void intel_execlists_set_default_submission(struct intel_engine_cs *engine) engine->reset.reset = execlists_reset; engine->reset.finish = execlists_reset_finish; - engine->park =NULL ; + engine->park = execlists_park; engine->unpark =NULL ; engine->flags |=I915_ENGINE_SUPPORTS_STATS ;
drivers/gpu/drm/i915/intel_guc_submission.c +1 -0
@@ -1363,6 +1363,7 @@ static void guc_interrupts_release(struct drm_i915_private *dev_priv)static void guc_submission_park (struct intel_engine_cs *engine) { +tasklet_kill (&engine->execlists.tasklet);intel_engine_unpin_breadcrumbs_irq (engine); engine->flags &= ~I915_ENGINE_NEEDS_BREADCRUMB_TASKLET ; }
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 12/45 drm/i915: Move the engine->destroy() vfunc onto the engine
In reply to Chris WilsonMake the engine responsible for cleaning itself up!
--- drivers/gpu/drm/i915/gt/intel_engine.h | 4 ++ drivers/gpu/drm/i915/gt/intel_engine_cs.c | 63 ++++++++++---------- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 +- drivers/gpu/drm/i915/gt/intel_lrc.c | 30 ++++------ drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 35 +++++------ drivers/gpu/drm/i915/i915_drv.h | 6 -- drivers/gpu/drm/i915/i915_gem.c | 19 +----- 7 files changed, 66 insertions(+), 93 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine.h +4 -0
@@ -362,7 +362,11 @@ __intel_ring_space(unsigned int head, unsigned int tail, unsigned int size)return (head - tail -CACHELINE_BYTES ) & (size -1 ); } +int intel_engines_init_mmio (struct drm_i915_private *i915);int intel_engines_setup (struct drm_i915_private *i915); +int intel_engines_init (struct drm_i915_private *i915); +void intel_engines_cleanup (struct drm_i915_private *i915); +int intel_engine_init_common (struct intel_engine_cs *engine);void intel_engine_cleanup_common (struct intel_engine_cs *engine);
drivers/gpu/drm/i915/gt/intel_engine_cs.c +33 -30
129 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_engine_types.h +1 -1
@@ -420,7 +420,7 @@ struct intel_engine_cs {*/ void (*cancel_requests)(struct intel_engine_cs *engine); -void (*cleanup)(struct intel_engine_cs *engine); +void (*destroy)(struct intel_engine_cs *engine);struct intel_engine_execlists execlists;
drivers/gpu/drm/i915/gt/intel_lrc.c +10 -20
@@ -2336,26 +2336,6 @@ static void execlists_park(struct intel_engine_cs *engine)tasklet_kill (&engine->execlists.tasklet); } -/** -* intel_logical_ring_cleanup() - deallocate the Engine Command Streamer -* @engine: Engine Command Streamer. -*/ -void intel_logical_ring_cleanup (struct intel_engine_cs *engine) -{ -struct drm_i915_private *i915 = engine->i915; - -if (engine->cleanup) - engine->cleanup (engine); - -intel_engine_cleanup_common (engine); - -lrc_destroy_wa_ctx (engine); - - engine->i915 =NULL ; - i915->engine[engine->id] =NULL ; -kfree (engine); -} -void intel_execlists_set_default_submission (struct intel_engine_cs *engine) { engine->submit_request = execlists_submit_request;
@@ -2378,10 +2358,20 @@ void intel_execlists_set_default_submission(struct intel_engine_cs *engine) engine->flags |=I915_ENGINE_HAS_PREEMPTION ; } +static void execlists_destroy (struct intel_engine_cs *engine) +{ +intel_engine_cleanup_common (engine); + +lrc_destroy_wa_ctx (engine); +kfree (engine); +} +static void logical_ring_default_vfuncs (struct intel_engine_cs *engine) {/* Default vfuncs which can be overriden by each engine. */ + + engine->destroy = execlists_destroy; engine->resume = execlists_resume; engine->reset.prepare = execlists_reset_prepare;
drivers/gpu/drm/i915/gt/intel_ringbuffer.c +16 -19
@@ -1520,25 +1520,6 @@ static const struct intel_context_ops ring_context_ops = { .destroy = ring_context_destroy, }; -void intel_engine_cleanup (struct intel_engine_cs *engine) -{ -struct drm_i915_private *dev_priv = engine->i915; - -WARN_ON (INTEL_GEN (dev_priv) >2 && - (ENGINE_READ (engine,RING_MI_MODE ) &MODE_IDLE ) ==0 ); - -intel_ring_unpin (engine->buffer); -intel_ring_put (engine->buffer); - -if (engine->cleanup) - engine->cleanup (engine); - -intel_engine_cleanup_common (engine); - - dev_priv->engine[engine->id] =NULL ; -kfree (engine); -} -static int load_pd_dir (struct i915_request *rq,const struct i915_hw_ppgtt *ppgtt) {
@@ -2130,6 +2111,20 @@ static void gen6_bsd_set_default_submission(struct intel_engine_cs *engine) engine->submit_request = gen6_bsd_submit_request; } +static void ring_destroy (struct intel_engine_cs *engine) +{ +struct drm_i915_private *dev_priv = engine->i915; + +WARN_ON (INTEL_GEN (dev_priv) >2 && + (ENGINE_READ (engine,RING_MI_MODE ) &MODE_IDLE ) ==0 ); + +intel_ring_unpin (engine->buffer); +intel_ring_put (engine->buffer); + +intel_engine_cleanup_common (engine); +kfree (engine); +} +static void setup_irq (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;
@@ -2158,6 +2153,8 @@ static void setup_common(struct intel_engine_cs *engine)setup_irq (engine); + engine->destroy = ring_destroy; + engine->resume = xcs_resume; engine->reset.prepare = reset_prepare; engine->reset.reset = reset_ring;
drivers/gpu/drm/i915/i915_drv.h +0 -6
@@ -1995,8 +1995,6 @@ struct drm_i915_private {/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */ struct { -void (*cleanup_engine)(struct intel_engine_cs *engine); - struct i915_gt_timelines { struct mutex mutex; /* protects list, tainted by GPU */ struct list_head active_list;
@@ -2722,9 +2720,6 @@ extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);extern void i915_update_gfx_val (struct drm_i915_private *dev_priv);int vlv_force_gfx_clock (struct drm_i915_private *dev_priv,bool on); -int intel_engines_init_mmio (struct drm_i915_private *dev_priv); -int intel_engines_init (struct drm_i915_private *dev_priv); -u32 intel_calculate_mcr_s_ss_select (struct drm_i915_private *dev_priv);/* intel_hotplug.c */
@@ -3132,7 +3127,6 @@ int __must_check i915_gem_init(struct drm_i915_private *dev_priv);int __must_check i915_gem_init_hw (struct drm_i915_private *dev_priv);void i915_gem_init_swizzling (struct drm_i915_private *dev_priv);void i915_gem_fini (struct drm_i915_private *dev_priv); -void i915_gem_cleanup_engines (struct drm_i915_private *dev_priv);int i915_gem_wait_for_idle (struct drm_i915_private *dev_priv,unsigned int flags,long timeout);void i915_gem_suspend (struct drm_i915_private *dev_priv);
drivers/gpu/drm/i915/i915_gem.c +2 -17
@@ -4476,11 +4476,6 @@ int i915_gem_init(struct drm_i915_private *dev_priv) dev_priv->mm.unordered_timeline =dma_fence_context_alloc (1 ); -if (HAS_LOGICAL_RING_CONTEXTS (dev_priv)) - dev_priv->gt.cleanup_engine = intel_logical_ring_cleanup; -else - dev_priv->gt.cleanup_engine = intel_engine_cleanup; -i915_timelines_init (dev_priv); ret =i915_gem_init_userptr (dev_priv);
@@ -4601,7 +4596,7 @@ int i915_gem_init(struct drm_i915_private *dev_priv) err_pm:if (ret != -EIO ) {intel_cleanup_gt_powersave (dev_priv); -i915_gem_cleanup_engines (dev_priv); +intel_engines_cleanup (dev_priv); } err_context:if (ret != -EIO )
@@ -4661,7 +4656,7 @@ void i915_gem_fini(struct drm_i915_private *dev_priv)mutex_lock (&dev_priv->drm.struct_mutex);intel_uc_fini_hw (dev_priv);intel_uc_fini (dev_priv); -i915_gem_cleanup_engines (dev_priv); +intel_engines_cleanup (dev_priv);i915_gem_contexts_fini (dev_priv);i915_gem_fini_scratch (dev_priv);mutex_unlock (&dev_priv->drm.struct_mutex);
@@ -4684,16 +4679,6 @@ void i915_gem_init_mmio(struct drm_i915_private *i915)i915_gem_sanitize (i915); } -void -i915_gem_cleanup_engines (struct drm_i915_private *dev_priv) -{ -struct intel_engine_cs *engine; -enum intel_engine_id id; - -for_each_engine (engine, dev_priv, id) - dev_priv->gt.cleanup_engine (engine); -} -void i915_gem_load_init_fences (struct drm_i915_private *dev_priv) {
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 12/45] drm/i915: Move the engine->destroy() vfunc onto the engine
Quoted 1 line · Chris Wilson
Make the engine responsible for cleaning itself up!
Why? (Just a hint to explain in the commit message.)
Quoted 33 lines
Signed-off-by Chris Wilson <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine.h | 4 ++ drivers/gpu/drm/i915/gt/intel_engine_cs.c | 63 ++++++++++---------- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 +- drivers/gpu/drm/i915/gt/intel_lrc.c | 30 ++++------ drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 35 +++++------ drivers/gpu/drm/i915/i915_drv.h | 6 -- drivers/gpu/drm/i915/i915_gem.c | 19 +----- 7 files changed, 66 insertions(+), 93 deletions(-)drivers/gpu/drm/i915/gt/intel_engine.h +4
-0@@ -362,7 +362,11 @@ __intel_ring_space(unsigned int head, unsigned int tail, unsigned int size)return (head - tail -CACHELINE_BYTES ) & (size -1 ); } +int intel_engines_init_mmio (struct drm_i915_private *i915);int intel_engines_setup (struct drm_i915_private *i915); +int intel_engines_init (struct drm_i915_private *i915); +void intel_engines_cleanup (struct drm_i915_private *i915); +int intel_engine_init_common (struct intel_engine_cs *engine);void intel_engine_cleanup_common (struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/intel_engine_cs.c +0
-0
drivers/gpu/drm/i915/gt/intel_engine_cs.c intel_engine_setup(struct drm_i915_private *dev_priv, · line 310
Quoted 8 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +5
-0@@ -303,6 +303,12 @@ intel_engine_setup(struct drm_i915_private *dev_priv, engine->class = info->class; engine->instance = info->instance; +/* +* To be overridden by the backend on setup, however to facilitate +* cleanup on error during setup we always provide the destroy vfunc. +*/ + engine->destroy = (typeof(engine->destroy))kfree;
Scheme overall is nice but has one fragile point in it.
I think we want a wrapper and then add some WARN_ON type safety if the engine has state allocated and the destroy vfunc accidentally still points to this one.
I suspect easiest would be to set an engine flag once it has been initialized.
Quoted 42 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +19
-5+ engine->uabi_class = intel_engine_classes[info->class].uabi_class; engine->context_size = __intel_engine_context_size(dev_priv,@@ -327,18 +333,31 @@ intel_engine_setup(struct drm_i915_private *dev_priv,return 0 ; } +/** +* intel_engines_cleanup() - free the resources allocated for Command Streamers +* @dev_priv: i915 device private +*/ +void intel_engines_cleanup (struct drm_i915_private *i915) +{ +struct intel_engine_cs *engine; +enum intel_engine_id id; + +for_each_engine (engine, i915, id) { + engine->destroy (engine); + i915->engine[id] =NULL ; + } +} +/** * intel_engines_init_mmio() - allocate and prepare the Engine Command Streamers * @dev_priv: i915 device private * * Return: non-zero if the initialization failed. */ -int intel_engines_init_mmio (struct drm_i915_private *dev_priv) +int intel_engines_init_mmio (struct drm_i915_private *i915) { -struct intel_device_info *device_info =mkwrite_device_info (dev_priv); -const unsigned int engine_mask =INTEL_INFO (dev_priv)->engine_mask; -struct intel_engine_cs *engine; -enum intel_engine_id id; +struct intel_device_info *device_info =mkwrite_device_info (i915); +const unsigned int engine_mask =INTEL_INFO (i915)->engine_mask;unsigned int mask =0 ;unsigned int i;int err;
drivers/gpu/drm/i915/gt/intel_engine_cs.c int intel_engines_init_mmio(struct drm_i915_private *dev_priv) · line 376
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +2
-2@@ -351,10 +370,10 @@ int intel_engines_init_mmio(struct drm_i915_private *dev_priv)return -ENODEV ;for (i =0 ; i <ARRAY_SIZE (intel_engines); i++) { -if (!HAS_ENGINE (dev_priv, i)) +if (!HAS_ENGINE (i915, i))continue ; - err =intel_engine_setup (dev_priv, i); + err =intel_engine_setup (i915, i);
While nosing around I noticed there is mmio access in setup. :(
Quoted 275 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +7
-23if (err) goto cleanup;@@ -370,20 +389,19 @@ int intel_engines_init_mmio(struct drm_i915_private *dev_priv) device_info->engine_mask = mask;/* We always presume we have at least RCS available for later probing */ -if (WARN_ON (!HAS_ENGINE (dev_priv,RCS0 ))) { +if (WARN_ON (!HAS_ENGINE (i915,RCS0 ))) { err = -ENODEV ; goto cleanup; } -RUNTIME_INFO (dev_priv)->num_engines =hweight32 (mask); +RUNTIME_INFO (i915)->num_engines =hweight32 (mask); -i915_check_and_clear_faults (dev_priv); +i915_check_and_clear_faults (i915);return 0 ; cleanup: -for_each_engine (engine, dev_priv, id) -kfree (engine); +intel_engines_cleanup (i915);return err; }@@ -397,7 +415,7 @@ int intel_engines_init(struct drm_i915_private *i915) {int (*init)(struct intel_engine_cs *engine);struct intel_engine_cs *engine; -enum intel_engine_id id, err_id; +enum intel_engine_id id;int err;if (HAS_EXECLISTS (i915))@@ -406,8 +424,6 @@ int intel_engines_init(struct drm_i915_private *i915) init = intel_ring_submission_init;for_each_engine (engine, i915, id) { - err_id = id; - err =init (engine);if (err) goto cleanup;@@ -416,14 +432,7 @@ int intel_engines_init(struct drm_i915_private *i915)return 0 ; cleanup: -for_each_engine (engine, i915, id) { -if (id >= err_id) { -kfree (engine); - i915->engine[id] =NULL ; - }else { - i915->gt.cleanup_engine (engine); - } - } +intel_engines_cleanup (i915);return err; }@@ -609,13 +618,7 @@ int intel_engines_setup(struct drm_i915_private *i915)return 0 ; cleanup: -for_each_engine (engine, i915, id) { -if (engine->cops) - i915->gt.cleanup_engine (engine); -else -kfree (engine); - i915->engine[id] =NULL ; - } +intel_engines_cleanup (i915);return err; }drivers/gpu/drm/i915/gt/intel_engine_types.h +1
-1@@ -420,7 +420,7 @@ struct intel_engine_cs {*/ void (*cancel_requests)(struct intel_engine_cs *engine); -void (*cleanup)(struct intel_engine_cs *engine); +void (*destroy)(struct intel_engine_cs *engine);struct intel_engine_execlists execlists;drivers/gpu/drm/i915/gt/intel_lrc.c +10
-20@@ -2336,26 +2336,6 @@ static void execlists_park(struct intel_engine_cs *engine)tasklet_kill (&engine->execlists.tasklet); } -/** -* intel_logical_ring_cleanup() - deallocate the Engine Command Streamer -* @engine: Engine Command Streamer. -*/ -void intel_logical_ring_cleanup (struct intel_engine_cs *engine) -{ -struct drm_i915_private *i915 = engine->i915; - -if (engine->cleanup) - engine->cleanup (engine); - -intel_engine_cleanup_common (engine); - -lrc_destroy_wa_ctx (engine); - - engine->i915 =NULL ; - i915->engine[engine->id] =NULL ; -kfree (engine); -} -void intel_execlists_set_default_submission (struct intel_engine_cs *engine) { engine->submit_request = execlists_submit_request;@@ -2378,10 +2358,20 @@ void intel_execlists_set_default_submission(struct intel_engine_cs *engine) engine->flags |=I915_ENGINE_HAS_PREEMPTION ; } +static void execlists_destroy (struct intel_engine_cs *engine) +{ +intel_engine_cleanup_common (engine); + +lrc_destroy_wa_ctx (engine); +kfree (engine); +} +static void logical_ring_default_vfuncs (struct intel_engine_cs *engine) {/* Default vfuncs which can be overriden by each engine. */ + + engine->destroy = execlists_destroy; engine->resume = execlists_resume; engine->reset.prepare = execlists_reset_prepare;drivers/gpu/drm/i915/gt/intel_ringbuffer.c +16
-19@@ -1520,25 +1520,6 @@ static const struct intel_context_ops ring_context_ops = { .destroy = ring_context_destroy, }; -void intel_engine_cleanup (struct intel_engine_cs *engine) -{ -struct drm_i915_private *dev_priv = engine->i915; - -WARN_ON (INTEL_GEN (dev_priv) >2 && - (ENGINE_READ (engine,RING_MI_MODE ) &MODE_IDLE ) ==0 ); - -intel_ring_unpin (engine->buffer); -intel_ring_put (engine->buffer); - -if (engine->cleanup) - engine->cleanup (engine); - -intel_engine_cleanup_common (engine); - - dev_priv->engine[engine->id] =NULL ; -kfree (engine); -} -static int load_pd_dir (struct i915_request *rq,const struct i915_hw_ppgtt *ppgtt) {@@ -2130,6 +2111,20 @@ static void gen6_bsd_set_default_submission(struct intel_engine_cs *engine) engine->submit_request = gen6_bsd_submit_request; } +static void ring_destroy (struct intel_engine_cs *engine) +{ +struct drm_i915_private *dev_priv = engine->i915; + +WARN_ON (INTEL_GEN (dev_priv) >2 && + (ENGINE_READ (engine,RING_MI_MODE ) &MODE_IDLE ) ==0 ); + +intel_ring_unpin (engine->buffer); +intel_ring_put (engine->buffer); + +intel_engine_cleanup_common (engine); +kfree (engine); +} +static void setup_irq (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;@@ -2158,6 +2153,8 @@ static void setup_common(struct intel_engine_cs *engine)setup_irq (engine); + engine->destroy = ring_destroy; + engine->resume = xcs_resume; engine->reset.prepare = reset_prepare; engine->reset.reset = reset_ring;drivers/gpu/drm/i915/i915_drv.h +0
-6@@ -1995,8 +1995,6 @@ struct drm_i915_private {/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */ struct { -void (*cleanup_engine)(struct intel_engine_cs *engine); - struct i915_gt_timelines { struct mutex mutex; /* protects list, tainted by GPU */ struct list_head active_list;@@ -2722,9 +2720,6 @@ extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);extern void i915_update_gfx_val (struct drm_i915_private *dev_priv);int vlv_force_gfx_clock (struct drm_i915_private *dev_priv,bool on); -int intel_engines_init_mmio (struct drm_i915_private *dev_priv); -int intel_engines_init (struct drm_i915_private *dev_priv); -u32 intel_calculate_mcr_s_ss_select (struct drm_i915_private *dev_priv);/* intel_hotplug.c */ @@ -3132,7 +3127,6 @@ int __must_check i915_gem_init(struct drm_i915_private *dev_priv);int __must_check i915_gem_init_hw (struct drm_i915_private *dev_priv);void i915_gem_init_swizzling (struct drm_i915_private *dev_priv);void i915_gem_fini (struct drm_i915_private *dev_priv); -void i915_gem_cleanup_engines (struct drm_i915_private *dev_priv);int i915_gem_wait_for_idle (struct drm_i915_private *dev_priv,unsigned int flags,long timeout);void i915_gem_suspend (struct drm_i915_private *dev_priv);drivers/gpu/drm/i915/i915_gem.c +2
-10@@ -4476,11 +4476,6 @@ int i915_gem_init(struct drm_i915_private *dev_priv) dev_priv->mm.unordered_timeline =dma_fence_context_alloc (1 ); -if (HAS_LOGICAL_RING_CONTEXTS (dev_priv)) - dev_priv->gt.cleanup_engine = intel_logical_ring_cleanup; -else - dev_priv->gt.cleanup_engine = intel_engine_cleanup; -i915_timelines_init (dev_priv); ret =i915_gem_init_userptr (dev_priv);@@ -4601,7 +4596,7 @@ int i915_gem_init(struct drm_i915_private *dev_priv) err_pm:if (ret != -EIO ) {intel_cleanup_gt_powersave (dev_priv); -i915_gem_cleanup_engines (dev_priv); +intel_engines_cleanup (dev_priv); } err_context:if (ret != -EIO )@@ -4661,7 +4656,7 @@ void i915_gem_fini(struct drm_i915_private *dev_priv)mutex_lock (&dev_priv->drm.struct_mutex);intel_uc_fini_hw (dev_priv);intel_uc_fini (dev_priv); -i915_gem_cleanup_engines (dev_priv); +intel_engines_cleanup (dev_priv);i915_gem_contexts_fini (dev_priv);i915_gem_fini_scratch (dev_priv);mutex_unlock (&dev_priv->drm.struct_mutex);@@ -4684,16 +4679,6 @@ void i915_gem_init_mmio(struct drm_i915_private *i915)i915_gem_sanitize (i915); } -void -i915_gem_cleanup_engines (struct drm_i915_private *dev_priv) -{
drivers/gpu/drm/i915/i915_gem.c void i915_gem_init_mmio(struct drm_i915_private *i915) · line 4684
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +0
-7-struct intel_engine_cs *engine; -enum intel_engine_id id; - -for_each_engine (engine, dev_priv, id) - dev_priv->gt.cleanup_engine (engine); -} -void i915_gem_load_init_fences (struct drm_i915_private *dev_priv) {
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 12/45] drm/i915: Move the engine->destroy() vfunc onto the engine
Quoting Tvrtko Ursulin (2019-04-25 12:01:36)
Quoted 5 lines · Chris Wilson
Quoted 1 line
Make the engine responsible for cleaning itself up!
Why? (Just a hint to explain in the commit message.)
... so we can remove the vfunc stuck away inside the i915->gt that has been annoying the reader for the last several years.
Quoted 16 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c intel_engine_setup(struct drm_i915_private *dev_priv, · line 310
Quoted 13 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +5
-0@@ -303,6 +303,12 @@ intel_engine_setup(struct drm_i915_private *dev_priv, engine->class = info->class; engine->instance = info->instance; +/* +* To be overridden by the backend on setup, however to facilitate +* cleanup on error during setup we always provide the destroy vfunc. +*/ + engine->destroy = (typeof(engine->destroy))kfree;Scheme overall is nice but has one fragile point in it.
Quoted 6 lines
I think we want a wrapper and then add some
WARN_ONtype safety if the engine has state allocated and the destroy vfunc accidentally still points to this one.I suspect easiest would be to set an engine flag once it has been initialized.
Hmm, still fragile since you rely on the user? And if you don't rely on the user, we just put a GEM_BUG_ON(engine->destroy == kfree) at the point where we expect the backend to take control, i.e. after a successful call to setup() in intel_engines_setup.
@@ -617,6 +617,9 @@ int intel_engines_setup(struct drm_i915_private *i915)
if (err)
goto cleanup;+ /* We expect the backend to take control over its state */
+ GEM_BUG_ON(engine->destroy == (typeof(engine->destroy))kfree);
+
GEM_BUG_ON(!engine->cops);
Quoted 50 lines
Quoted 50 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +20
-6+ engine->uabi_class = intel_engine_classes[info->class].uabi_class; engine->context_size = __intel_engine_context_size(dev_priv,@@ -327,18 +333,31 @@ intel_engine_setup(struct drm_i915_private *dev_priv,return 0 ; } +/** +* intel_engines_cleanup() - free the resources allocated for Command Streamers +* @dev_priv: i915 device private +*/ +void intel_engines_cleanup (struct drm_i915_private *i915) +{ +struct intel_engine_cs *engine; +enum intel_engine_id id; + +for_each_engine (engine, i915, id) { + engine->destroy (engine); + i915->engine[id] =NULL ; + } +} +/** * intel_engines_init_mmio() - allocate and prepare the Engine Command Streamers * @dev_priv: i915 device private * * Return: non-zero if the initialization failed. */ -int intel_engines_init_mmio (struct drm_i915_private *dev_priv) +int intel_engines_init_mmio (struct drm_i915_private *i915) { -struct intel_device_info *device_info =mkwrite_device_info (dev_priv); -const unsigned int engine_mask =INTEL_INFO (dev_priv)->engine_mask; -struct intel_engine_cs *engine; -enum intel_engine_id id; +struct intel_device_info *device_info =mkwrite_device_info (i915); +const unsigned int engine_mask =INTEL_INFO (i915)->engine_mask;unsigned int mask =0 ;unsigned int i;int err;@@ -351,10 +370,10 @@ int intel_engines_init_mmio(struct drm_i915_private *dev_priv)return -ENODEV ;for (i =0 ; i <ARRAY_SIZE (intel_engines); i++) { -if (!HAS_ENGINE (dev_priv, i)) +if (!HAS_ENGINE (i915, i))continue ;
Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c int intel_engines_init_mmio(struct drm_i915_private *dev_priv) · line 376
Quoted 2 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +1
-1- err =intel_engine_setup (dev_priv, i); + err =intel_engine_setup (i915, i);While nosing around I noticed there is mmio access in setup. :(
Yeah, we can take another step or two to split up the phases between sw setup and HW setup.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 1/1 drm/i915: Move the engine->destroy() vfunc onto the engine
In reply to Tvrtko UrsulinMake the engine responsible for cleaning itself up!
This removes the i915->gt.cleanup vfunc that has been annoying the casual reader and myself for the last several years, and helps keep a future patch to add more cleanup tidy.
v2: Assert that engine->destroy is set after the backend starts allocating its own state.
--- drivers/gpu/drm/i915/gt/intel_engine.h | 4 ++ drivers/gpu/drm/i915/gt/intel_engine_cs.c | 66 +++++++++++--------- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 +- drivers/gpu/drm/i915/gt/intel_lrc.c | 29 +++------ drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 35 +++++------ drivers/gpu/drm/i915/i915_drv.h | 6 -- drivers/gpu/drm/i915/i915_gem.c | 19 +----- 7 files changed, 68 insertions(+), 93 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine.h +4 -0
@@ -362,7 +362,11 @@ __intel_ring_space(unsigned int head, unsigned int tail, unsigned int size)return (head - tail -CACHELINE_BYTES ) & (size -1 ); } +int intel_engines_init_mmio (struct drm_i915_private *i915);int intel_engines_setup (struct drm_i915_private *i915); +int intel_engines_init (struct drm_i915_private *i915); +void intel_engines_cleanup (struct drm_i915_private *i915); +int intel_engine_init_common (struct intel_engine_cs *engine);void intel_engine_cleanup_common (struct intel_engine_cs *engine);
drivers/gpu/drm/i915/gt/intel_engine_cs.c +36 -30
138 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_engine_types.h +1 -1
@@ -420,7 +420,7 @@ struct intel_engine_cs {*/ void (*cancel_requests)(struct intel_engine_cs *engine); -void (*cleanup)(struct intel_engine_cs *engine); +void (*destroy)(struct intel_engine_cs *engine);struct intel_engine_execlists execlists;
drivers/gpu/drm/i915/gt/intel_lrc.c +9 -20
@@ -2336,26 +2336,6 @@ static void execlists_park(struct intel_engine_cs *engine)tasklet_kill (&engine->execlists.tasklet); } -/** -* intel_logical_ring_cleanup() - deallocate the Engine Command Streamer -* @engine: Engine Command Streamer. -*/ -void intel_logical_ring_cleanup (struct intel_engine_cs *engine) -{ -struct drm_i915_private *i915 = engine->i915; - -if (engine->cleanup) - engine->cleanup (engine); - -intel_engine_cleanup_common (engine); - -lrc_destroy_wa_ctx (engine); - - engine->i915 =NULL ; - i915->engine[engine->id] =NULL ; -kfree (engine); -} -void intel_execlists_set_default_submission (struct intel_engine_cs *engine) { engine->submit_request = execlists_submit_request;
@@ -2378,10 +2358,19 @@ void intel_execlists_set_default_submission(struct intel_engine_cs *engine) engine->flags |=I915_ENGINE_HAS_PREEMPTION ; } +static void execlists_destroy (struct intel_engine_cs *engine) +{ +intel_engine_cleanup_common (engine); +lrc_destroy_wa_ctx (engine); +kfree (engine); +} +static void logical_ring_default_vfuncs (struct intel_engine_cs *engine) {/* Default vfuncs which can be overriden by each engine. */ + + engine->destroy = execlists_destroy; engine->resume = execlists_resume; engine->reset.prepare = execlists_reset_prepare;
drivers/gpu/drm/i915/gt/intel_ringbuffer.c +16 -19
@@ -1520,25 +1520,6 @@ static const struct intel_context_ops ring_context_ops = { .destroy = ring_context_destroy, }; -void intel_engine_cleanup (struct intel_engine_cs *engine) -{ -struct drm_i915_private *dev_priv = engine->i915; - -WARN_ON (INTEL_GEN (dev_priv) >2 && - (ENGINE_READ (engine,RING_MI_MODE ) &MODE_IDLE ) ==0 ); - -intel_ring_unpin (engine->buffer); -intel_ring_put (engine->buffer); - -if (engine->cleanup) - engine->cleanup (engine); - -intel_engine_cleanup_common (engine); - - dev_priv->engine[engine->id] =NULL ; -kfree (engine); -} -static int load_pd_dir (struct i915_request *rq,const struct i915_hw_ppgtt *ppgtt) {
@@ -2130,6 +2111,20 @@ static void gen6_bsd_set_default_submission(struct intel_engine_cs *engine) engine->submit_request = gen6_bsd_submit_request; } +static void ring_destroy (struct intel_engine_cs *engine) +{ +struct drm_i915_private *dev_priv = engine->i915; + +WARN_ON (INTEL_GEN (dev_priv) >2 && + (ENGINE_READ (engine,RING_MI_MODE ) &MODE_IDLE ) ==0 ); + +intel_ring_unpin (engine->buffer); +intel_ring_put (engine->buffer); + +intel_engine_cleanup_common (engine); +kfree (engine); +} +static void setup_irq (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;
@@ -2158,6 +2153,8 @@ static void setup_common(struct intel_engine_cs *engine)setup_irq (engine); + engine->destroy = ring_destroy; + engine->resume = xcs_resume; engine->reset.prepare = reset_prepare; engine->reset.reset = reset_ring;
drivers/gpu/drm/i915/i915_drv.h +0 -6
@@ -1995,8 +1995,6 @@ struct drm_i915_private {/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */ struct { -void (*cleanup_engine)(struct intel_engine_cs *engine); - struct i915_gt_timelines { struct mutex mutex; /* protects list, tainted by GPU */ struct list_head active_list;
@@ -2722,9 +2720,6 @@ extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);extern void i915_update_gfx_val (struct drm_i915_private *dev_priv);int vlv_force_gfx_clock (struct drm_i915_private *dev_priv,bool on); -int intel_engines_init_mmio (struct drm_i915_private *dev_priv); -int intel_engines_init (struct drm_i915_private *dev_priv); -u32 intel_calculate_mcr_s_ss_select (struct drm_i915_private *dev_priv);/* intel_hotplug.c */
@@ -3132,7 +3127,6 @@ int __must_check i915_gem_init(struct drm_i915_private *dev_priv);int __must_check i915_gem_init_hw (struct drm_i915_private *dev_priv);void i915_gem_init_swizzling (struct drm_i915_private *dev_priv);void i915_gem_fini (struct drm_i915_private *dev_priv); -void i915_gem_cleanup_engines (struct drm_i915_private *dev_priv);int i915_gem_wait_for_idle (struct drm_i915_private *dev_priv,unsigned int flags,long timeout);void i915_gem_suspend (struct drm_i915_private *dev_priv);
drivers/gpu/drm/i915/i915_gem.c +2 -17
@@ -4476,11 +4476,6 @@ int i915_gem_init(struct drm_i915_private *dev_priv) dev_priv->mm.unordered_timeline =dma_fence_context_alloc (1 ); -if (HAS_LOGICAL_RING_CONTEXTS (dev_priv)) - dev_priv->gt.cleanup_engine = intel_logical_ring_cleanup; -else - dev_priv->gt.cleanup_engine = intel_engine_cleanup; -i915_timelines_init (dev_priv); ret =i915_gem_init_userptr (dev_priv);
@@ -4601,7 +4596,7 @@ int i915_gem_init(struct drm_i915_private *dev_priv) err_pm:if (ret != -EIO ) {intel_cleanup_gt_powersave (dev_priv); -i915_gem_cleanup_engines (dev_priv); +intel_engines_cleanup (dev_priv); } err_context:if (ret != -EIO )
@@ -4661,7 +4656,7 @@ void i915_gem_fini(struct drm_i915_private *dev_priv)mutex_lock (&dev_priv->drm.struct_mutex);intel_uc_fini_hw (dev_priv);intel_uc_fini (dev_priv); -i915_gem_cleanup_engines (dev_priv); +intel_engines_cleanup (dev_priv);i915_gem_contexts_fini (dev_priv);i915_gem_fini_scratch (dev_priv);mutex_unlock (&dev_priv->drm.struct_mutex);
@@ -4684,16 +4679,6 @@ void i915_gem_init_mmio(struct drm_i915_private *i915)i915_gem_sanitize (i915); } -void -i915_gem_cleanup_engines (struct drm_i915_private *dev_priv) -{ -struct intel_engine_cs *engine; -enum intel_engine_id id; - -for_each_engine (engine, dev_priv, id) - dev_priv->gt.cleanup_engine (engine); -} -void i915_gem_load_init_fences (struct drm_i915_private *dev_priv) {
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2] drm/i915: Move the engine->destroy() vfunc onto the engine
Quoted 384 lines · Chris Wilson
Make the engine responsible for cleaning itself up!
This removes the
i915->gt.cleanupvfunc that has been annoying the casual reader and myself for the last several years, and helps keep a future patch to add more cleanup tidy.v2: Assert that
engine->destroyis set after the backend starts allocating its own state.Signed-off-by Chris Wilson <[email protected]>Cc Tvrtko Ursulin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine.h | 4 ++ drivers/gpu/drm/i915/gt/intel_engine_cs.c | 66 +++++++++++--------- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 +- drivers/gpu/drm/i915/gt/intel_lrc.c | 29 +++------ drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 35 +++++------ drivers/gpu/drm/i915/i915_drv.h | 6 -- drivers/gpu/drm/i915/i915_gem.c | 19 +----- 7 files changed, 68 insertions(+), 93 deletions(-)drivers/gpu/drm/i915/gt/intel_engine.h +4
-0@@ -362,7 +362,11 @@ __intel_ring_space(unsigned int head, unsigned int tail, unsigned int size)return (head - tail -CACHELINE_BYTES ) & (size -1 ); } +int intel_engines_init_mmio (struct drm_i915_private *i915);int intel_engines_setup (struct drm_i915_private *i915); +int intel_engines_init (struct drm_i915_private *i915); +void intel_engines_cleanup (struct drm_i915_private *i915); +int intel_engine_init_common (struct intel_engine_cs *engine);void intel_engine_cleanup_common (struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/intel_engine_cs.c +36
-30@@ -303,6 +303,12 @@ intel_engine_setup(struct drm_i915_private *dev_priv, engine->class = info->class; engine->instance = info->instance; +/* +* To be overridden by the backend on setup. However to facilitate +* cleanup on error during setup, we always provide the destroy vfunc. +*/ + engine->destroy = (typeof(engine->destroy))kfree; + engine->uabi_class = intel_engine_classes[info->class].uabi_class; engine->context_size = __intel_engine_context_size(dev_priv,@@ -327,18 +333,31 @@ intel_engine_setup(struct drm_i915_private *dev_priv,return 0 ; } +/** +* intel_engines_cleanup() - free the resources allocated for Command Streamers +* @i915: the i915 device private +*/ +void intel_engines_cleanup (struct drm_i915_private *i915) +{ +struct intel_engine_cs *engine; +enum intel_engine_id id; + +for_each_engine (engine, i915, id) { + engine->destroy (engine); + i915->engine[id] =NULL ; + } +} +/** * intel_engines_init_mmio() - allocate and prepare the Engine Command Streamers * @dev_priv: i915 device private * * Return: non-zero if the initialization failed. */ -int intel_engines_init_mmio (struct drm_i915_private *dev_priv) +int intel_engines_init_mmio (struct drm_i915_private *i915) { -struct intel_device_info *device_info =mkwrite_device_info (dev_priv); -const unsigned int engine_mask =INTEL_INFO (dev_priv)->engine_mask; -struct intel_engine_cs *engine; -enum intel_engine_id id; +struct intel_device_info *device_info =mkwrite_device_info (i915); +const unsigned int engine_mask =INTEL_INFO (i915)->engine_mask;unsigned int mask =0 ;unsigned int i;int err;@@ -351,10 +370,10 @@ int intel_engines_init_mmio(struct drm_i915_private *dev_priv)return -ENODEV ;for (i =0 ; i <ARRAY_SIZE (intel_engines); i++) { -if (!HAS_ENGINE (dev_priv, i)) +if (!HAS_ENGINE (i915, i))continue ; - err =intel_engine_setup (dev_priv, i); + err =intel_engine_setup (i915, i);if (err) goto cleanup;@@ -370,20 +389,19 @@ int intel_engines_init_mmio(struct drm_i915_private *dev_priv) device_info->engine_mask = mask;/* We always presume we have at least RCS available for later probing */ -if (WARN_ON (!HAS_ENGINE (dev_priv,RCS0 ))) { +if (WARN_ON (!HAS_ENGINE (i915,RCS0 ))) { err = -ENODEV ; goto cleanup; } -RUNTIME_INFO (dev_priv)->num_engines =hweight32 (mask); +RUNTIME_INFO (i915)->num_engines =hweight32 (mask); -i915_check_and_clear_faults (dev_priv); +i915_check_and_clear_faults (i915);return 0 ; cleanup: -for_each_engine (engine, dev_priv, id) -kfree (engine); +intel_engines_cleanup (i915);return err; }@@ -397,7 +415,7 @@ int intel_engines_init(struct drm_i915_private *i915) {int (*init)(struct intel_engine_cs *engine);struct intel_engine_cs *engine; -enum intel_engine_id id, err_id; +enum intel_engine_id id;int err;if (HAS_EXECLISTS (i915))@@ -406,8 +424,6 @@ int intel_engines_init(struct drm_i915_private *i915) init = intel_ring_submission_init;for_each_engine (engine, i915, id) { - err_id = id; - err =init (engine);if (err) goto cleanup;@@ -416,14 +432,7 @@ int intel_engines_init(struct drm_i915_private *i915)return 0 ; cleanup: -for_each_engine (engine, i915, id) { -if (id >= err_id) { -kfree (engine); - i915->engine[id] =NULL ; - }else { - i915->gt.cleanup_engine (engine); - } - } +intel_engines_cleanup (i915);return err; }@@ -603,19 +612,16 @@ int intel_engines_setup(struct drm_i915_private *i915)if (err) goto cleanup; +/* We expect the backend to take control over its state */ + GEM_BUG_ON(engine->destroy == (typeof(engine->destroy))kfree); +GEM_BUG_ON (!engine->cops); }return 0 ; cleanup: -for_each_engine (engine, i915, id) { -if (engine->cops) - i915->gt.cleanup_engine (engine); -else -kfree (engine); - i915->engine[id] =NULL ; - } +intel_engines_cleanup (i915);return err; }drivers/gpu/drm/i915/gt/intel_engine_types.h +1
-1@@ -420,7 +420,7 @@ struct intel_engine_cs {*/ void (*cancel_requests)(struct intel_engine_cs *engine); -void (*cleanup)(struct intel_engine_cs *engine); +void (*destroy)(struct intel_engine_cs *engine);struct intel_engine_execlists execlists;drivers/gpu/drm/i915/gt/intel_lrc.c +9
-20@@ -2336,26 +2336,6 @@ static void execlists_park(struct intel_engine_cs *engine)tasklet_kill (&engine->execlists.tasklet); } -/** -* intel_logical_ring_cleanup() - deallocate the Engine Command Streamer -* @engine: Engine Command Streamer. -*/ -void intel_logical_ring_cleanup (struct intel_engine_cs *engine) -{ -struct drm_i915_private *i915 = engine->i915; - -if (engine->cleanup) - engine->cleanup (engine); - -intel_engine_cleanup_common (engine); - -lrc_destroy_wa_ctx (engine); - - engine->i915 =NULL ; - i915->engine[engine->id] =NULL ; -kfree (engine); -} -void intel_execlists_set_default_submission (struct intel_engine_cs *engine) { engine->submit_request = execlists_submit_request;@@ -2378,10 +2358,19 @@ void intel_execlists_set_default_submission(struct intel_engine_cs *engine) engine->flags |=I915_ENGINE_HAS_PREEMPTION ; } +static void execlists_destroy (struct intel_engine_cs *engine) +{ +intel_engine_cleanup_common (engine); +lrc_destroy_wa_ctx (engine); +kfree (engine); +} +static void logical_ring_default_vfuncs (struct intel_engine_cs *engine) {/* Default vfuncs which can be overriden by each engine. */ + + engine->destroy = execlists_destroy; engine->resume = execlists_resume; engine->reset.prepare = execlists_reset_prepare;drivers/gpu/drm/i915/gt/intel_ringbuffer.c +16
-19@@ -1520,25 +1520,6 @@ static const struct intel_context_ops ring_context_ops = { .destroy = ring_context_destroy, }; -void intel_engine_cleanup (struct intel_engine_cs *engine) -{ -struct drm_i915_private *dev_priv = engine->i915; - -WARN_ON (INTEL_GEN (dev_priv) >2 && - (ENGINE_READ (engine,RING_MI_MODE ) &MODE_IDLE ) ==0 ); - -intel_ring_unpin (engine->buffer); -intel_ring_put (engine->buffer); - -if (engine->cleanup) - engine->cleanup (engine); - -intel_engine_cleanup_common (engine); - - dev_priv->engine[engine->id] =NULL ; -kfree (engine); -} -static int load_pd_dir (struct i915_request *rq,const struct i915_hw_ppgtt *ppgtt) {@@ -2130,6 +2111,20 @@ static void gen6_bsd_set_default_submission(struct intel_engine_cs *engine) engine->submit_request = gen6_bsd_submit_request; } +static void ring_destroy (struct intel_engine_cs *engine) +{ +struct drm_i915_private *dev_priv = engine->i915; + +WARN_ON (INTEL_GEN (dev_priv) >2 && + (ENGINE_READ (engine,RING_MI_MODE ) &MODE_IDLE ) ==0 ); + +intel_ring_unpin (engine->buffer); +intel_ring_put (engine->buffer); + +intel_engine_cleanup_common (engine); +kfree (engine); +} +static void setup_irq (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;@@ -2158,6 +2153,8 @@ static void setup_common(struct intel_engine_cs *engine)setup_irq (engine); + engine->destroy = ring_destroy; + engine->resume = xcs_resume; engine->reset.prepare = reset_prepare; engine->reset.reset = reset_ring;drivers/gpu/drm/i915/i915_drv.h +0
-6@@ -1995,8 +1995,6 @@ struct drm_i915_private {/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */ struct { -void (*cleanup_engine)(struct intel_engine_cs *engine); - struct i915_gt_timelines { struct mutex mutex; /* protects list, tainted by GPU */ struct list_head active_list;@@ -2722,9 +2720,6 @@ extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);extern void i915_update_gfx_val (struct drm_i915_private *dev_priv);int vlv_force_gfx_clock (struct drm_i915_private *dev_priv,bool on); -int intel_engines_init_mmio (struct drm_i915_private *dev_priv); -int intel_engines_init (struct drm_i915_private *dev_priv); -u32 intel_calculate_mcr_s_ss_select (struct drm_i915_private *dev_priv);/* intel_hotplug.c */ @@ -3132,7 +3127,6 @@ int __must_check i915_gem_init(struct drm_i915_private *dev_priv);int __must_check i915_gem_init_hw (struct drm_i915_private *dev_priv);void i915_gem_init_swizzling (struct drm_i915_private *dev_priv);void i915_gem_fini (struct drm_i915_private *dev_priv); -void i915_gem_cleanup_engines (struct drm_i915_private *dev_priv);int i915_gem_wait_for_idle (struct drm_i915_private *dev_priv,unsigned int flags,long timeout);void i915_gem_suspend (struct drm_i915_private *dev_priv);drivers/gpu/drm/i915/i915_gem.c +2
-10@@ -4476,11 +4476,6 @@ int i915_gem_init(struct drm_i915_private *dev_priv) dev_priv->mm.unordered_timeline =dma_fence_context_alloc (1 ); -if (HAS_LOGICAL_RING_CONTEXTS (dev_priv)) - dev_priv->gt.cleanup_engine = intel_logical_ring_cleanup; -else - dev_priv->gt.cleanup_engine = intel_engine_cleanup; -i915_timelines_init (dev_priv); ret =i915_gem_init_userptr (dev_priv);@@ -4601,7 +4596,7 @@ int i915_gem_init(struct drm_i915_private *dev_priv) err_pm:if (ret != -EIO ) {intel_cleanup_gt_powersave (dev_priv); -i915_gem_cleanup_engines (dev_priv); +intel_engines_cleanup (dev_priv); } err_context:if (ret != -EIO )@@ -4661,7 +4656,7 @@ void i915_gem_fini(struct drm_i915_private *dev_priv)mutex_lock (&dev_priv->drm.struct_mutex);intel_uc_fini_hw (dev_priv);intel_uc_fini (dev_priv); -i915_gem_cleanup_engines (dev_priv); +intel_engines_cleanup (dev_priv);i915_gem_contexts_fini (dev_priv);i915_gem_fini_scratch (dev_priv);mutex_unlock (&dev_priv->drm.struct_mutex);@@ -4684,16 +4679,6 @@ void i915_gem_init_mmio(struct drm_i915_private *i915)i915_gem_sanitize (i915); } -void -i915_gem_cleanup_engines (struct drm_i915_private *dev_priv) -{
drivers/gpu/drm/i915/i915_gem.c void i915_gem_init_mmio(struct drm_i915_private *i915) · line 4684
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +0
-7-struct intel_engine_cs *engine; -enum intel_engine_id id; - -for_each_engine (engine, dev_priv, id) - dev_priv->gt.cleanup_engine (engine); -} -void i915_gem_load_init_fences (struct drm_i915_private *dev_priv) {
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 13/45 drm/i915: Convert inconsistent static engine tables into an init error
In reply to Chris WilsonRemove the modification of the "constant" device info by promoting the inconsistent intel_engine static table into an initialisation error. Now, if we add a new engine into the device_info, we must first add that engine information into the intel_engines.
--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 28 ++++++++--------------- 1 file changed, 9 insertions(+), 19 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +9 -19
@@ -356,15 +356,14 @@ void intel_engines_cleanup(struct drm_i915_private *i915)*/ int intel_engines_init_mmio (struct drm_i915_private *i915) { -struct intel_device_info *device_info =mkwrite_device_info (i915); -const unsigned int engine_mask =INTEL_INFO (i915)->engine_mask; -unsigned int mask =0 ;unsigned int i;int err; -WARN_ON (engine_mask ==0 ); -WARN_ON (engine_mask & -GENMASK (BITS_PER_TYPE (mask) -1 ,I915_NUM_ENGINES )); +/* We always presume we have at least RCS available for later probing */ +if (GEM_WARN_ON (!HAS_ENGINE (i915,RCS0 ))) { + err = -ENODEV ; + goto cleanup; + }if (i915_inject_load_failure ())return -ENODEV ;
@@ -376,25 +375,16 @@ int intel_engines_init_mmio(struct drm_i915_private *i915) err =intel_engine_setup (i915, i);if (err) goto cleanup; - - mask |=BIT (i); } -/* -* Catch failures to update intel_engines table when the new engines -* are added to the driver by a warning and disabling the forgotten -* engines. -*/ -if (WARN_ON (mask != engine_mask)) - device_info->engine_mask = mask; - -/* We always presume we have at least RCS available for later probing */ -if (WARN_ON (!HAS_ENGINE (i915,RCS0 ))) { +/* Catch failures to update intel_engines table for new engines. */ +if (GEM_WARN_ON (INTEL_INFO (i915)->engine_mask >> i)) { err = -ENODEV ; goto cleanup; } -RUNTIME_INFO (i915)->num_engines =hweight32 (mask); +RUNTIME_INFO (i915)->num_engines = +hweight32 (INTEL_INFO (i915)->engine_mask);i915_check_and_clear_faults (i915);
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 14/45 drm/i915: Make engine_mask & num_engines static
In reply to Chris WilsonHaving removed the urge to modify the engine_mask at runtime, we can promote the num_engines from a runtime calculation to a static and push it into the device_info tables.
--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 3 -- drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 2 +- drivers/gpu/drm/i915/gt/selftest_lrc.c | 4 +- drivers/gpu/drm/i915/i915_pci.c | 45 +++++++++---------- drivers/gpu/drm/i915/intel_device_info.h | 3 +- .../gpu/drm/i915/selftests/i915_gem_context.c | 4 +- drivers/gpu/drm/i915/selftests/i915_request.c | 2 +- 7 files changed, 27 insertions(+), 36 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +0 -3
@@ -383,9 +383,6 @@ int intel_engines_init_mmio(struct drm_i915_private *i915) goto cleanup; } -RUNTIME_INFO (i915)->num_engines = -hweight32 (INTEL_INFO (i915)->engine_mask); -i915_check_and_clear_faults (i915);return 0 ;
drivers/gpu/drm/i915/gt/intel_ringbuffer.c +1 -1
@@ -1568,7 +1568,7 @@ static inline int mi_set_context(struct i915_request *rq, u32 flags)struct intel_engine_cs *engine = rq->engine;enum intel_engine_id id;const int num_engines = -IS_HSW_GT1 (i915) ?RUNTIME_INFO (i915)->num_engines -1 :0 ; +IS_HSW_GT1 (i915) ?INTEL_INFO (i915)->num_engines -1 :0 ;bool force_restore = false;int len;u32 *cs;
drivers/gpu/drm/i915/gt/selftest_lrc.c +2 -2
@@ -1185,7 +1185,7 @@ static int smoke_crescendo(struct preempt_smoke *smoke, unsigned int flags)pr_info ("Submitted %lu crescendo:%x requests across %d engines and %d contexts\n" , count, flags, -RUNTIME_INFO (smoke->i915)->num_engines, smoke->ncontext); +INTEL_INFO (smoke->i915)->num_engines, smoke->ncontext);return 0 ; }
@@ -1213,7 +1213,7 @@ static int smoke_random(struct preempt_smoke *smoke, unsigned int flags)pr_info ("Submitted %lu random:%x requests across %d engines and %d contexts\n" , count, flags, -RUNTIME_INFO (smoke->i915)->num_engines, smoke->ncontext); +INTEL_INFO (smoke->i915)->num_engines, smoke->ncontext);return 0 ; }
drivers/gpu/drm/i915/i915_pci.c +20 -25
207 lines not on this page · raw message
drivers/gpu/drm/i915/intel_device_info.h +1 -2
@@ -149,6 +149,7 @@ struct intel_device_info {u8 gen;u8 gt;/* GT number, 0 if undefined */ intel_engine_mask_t engine_mask;/* Engines supported by the HW */ +u8 num_engines;enum intel_platform platform;
@@ -202,8 +203,6 @@ struct intel_runtime_info {u8 num_sprites[I915_MAX_PIPES ];u8 num_scalers[I915_MAX_PIPES ]; -u8 num_engines; -/* Slice/subslice/EU info */ struct sseu_dev_info sseu;
drivers/gpu/drm/i915/selftests/i915_gem_context.c +2 -2
@@ -1257,7 +1257,7 @@ static int igt_ctx_readonly(void *arg) } }pr_info ("Submitted %lu dwords (across %u engines)\n" , - ndwords,RUNTIME_INFO (i915)->num_engines); + ndwords,INTEL_INFO (i915)->num_engines); dw =0 ; idx =0 ;
@@ -1586,7 +1586,7 @@ static int igt_vm_isolation(void *arg) count += this; }pr_info ("Checked %lu scratch offsets across %d engines\n" , - count,RUNTIME_INFO (i915)->num_engines); + count,INTEL_INFO (i915)->num_engines); out_rpm:intel_runtime_pm_put (i915, wakeref);
drivers/gpu/drm/i915/selftests/i915_request.c +1 -1
@@ -1211,7 +1211,7 @@ static int live_breadcrumbs_smoketest(void *arg) num_fences +=atomic_long_read (&t[id].num_fences); }pr_info ("Completed %lu waits for %lu fences across %d engines and %d cpus\n" , - num_waits, num_fences,RUNTIME_INFO (i915)->num_engines, ncpus); + num_waits, num_fences,INTEL_INFO (i915)->num_engines, ncpus);mutex_lock (&i915->drm.struct_mutex); ret =igt_live_test_end (&live) ?: ret;
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 14/45] drm/i915: Make engine_mask & num_engines static
Quoted 3 lines · Chris Wilson
Having removed the urge to modify the
engine_maskat runtime, we can promote thenum_enginesfrom a runtime calculation to a static and push it into thedevice_infotables.
\o/
Quoted 349 lines
Signed-off-by Chris Wilson <[email protected]>Cc Tvrtko Ursulin <[email protected]>Cc Jani Nikula <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 3 -- drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 2 +- drivers/gpu/drm/i915/gt/selftest_lrc.c | 4 +- drivers/gpu/drm/i915/i915_pci.c | 45 +++++++++---------- drivers/gpu/drm/i915/intel_device_info.h | 3 +- .../gpu/drm/i915/selftests/i915_gem_context.c | 4 +- drivers/gpu/drm/i915/selftests/i915_request.c | 2 +- 7 files changed, 27 insertions(+), 36 deletions(-)drivers/gpu/drm/i915/gt/intel_engine_cs.c +0
-3@@ -383,9 +383,6 @@ int intel_engines_init_mmio(struct drm_i915_private *i915) goto cleanup; } -RUNTIME_INFO (i915)->num_engines = -hweight32 (INTEL_INFO (i915)->engine_mask); -i915_check_and_clear_faults (i915);return 0 ;drivers/gpu/drm/i915/gt/intel_ringbuffer.c +1
-1@@ -1568,7 +1568,7 @@ static inline int mi_set_context(struct i915_request *rq, u32 flags)struct intel_engine_cs *engine = rq->engine;enum intel_engine_id id;const int num_engines = -IS_HSW_GT1 (i915) ?RUNTIME_INFO (i915)->num_engines -1 :0 ; +IS_HSW_GT1 (i915) ?INTEL_INFO (i915)->num_engines -1 :0 ;bool force_restore = false;int len;u32 *cs;drivers/gpu/drm/i915/gt/selftest_lrc.c +2
-2@@ -1185,7 +1185,7 @@ static int smoke_crescendo(struct preempt_smoke *smoke, unsigned int flags)pr_info ("Submitted %lu crescendo:%x requests across %d engines and %d contexts\n" , count, flags, -RUNTIME_INFO (smoke->i915)->num_engines, smoke->ncontext); +INTEL_INFO (smoke->i915)->num_engines, smoke->ncontext);return 0 ; }@@ -1213,7 +1213,7 @@ static int smoke_random(struct preempt_smoke *smoke, unsigned int flags)pr_info ("Submitted %lu random:%x requests across %d engines and %d contexts\n" , count, flags, -RUNTIME_INFO (smoke->i915)->num_engines, smoke->ncontext); +INTEL_INFO (smoke->i915)->num_engines, smoke->ncontext);return 0 ; }drivers/gpu/drm/i915/i915_pci.c +20
-25@@ -35,6 +35,7 @@#define PLATFORM (x) .platform = (x)#define GEN (x) .gen = (x), .gen_mask = BIT((x) - 1) +#define ENGINES (x) .engine_mask = (x), .num_engines = hweight8(x)#define I845_PIPE_OFFSETS \ .pipe_offsets = { \@@ -145,6 +146,7 @@#define I830_FEATURES \ GEN(2), \ + ENGINES(BIT(RCS0)), \ .is_mobile = 1, \ .num_pipes = 2, \ .display.has_overlay = 1, \@@ -154,7 +156,6 @@ .gpu_reset_clobbers_display = true, \ .hws_needs_physical = 1, \ .unfenced_needs_alignment = 1, \ - .engine_mask = BIT(RCS0), \ .has_snoop = true, \ .has_coherent_ggtt = false, \ I9XX_PIPE_OFFSETS, \@@ -164,6 +165,7 @@#define I845_FEATURES \ GEN(2), \ + ENGINES(BIT(RCS0)), \ .num_pipes = 1, \ .display.has_overlay = 1, \ .display.overlay_needs_physical = 1, \@@ -171,7 +173,6 @@ .gpu_reset_clobbers_display = true, \ .hws_needs_physical = 1, \ .unfenced_needs_alignment = 1, \ - .engine_mask = BIT(RCS0), \ .has_snoop = true, \ .has_coherent_ggtt = false, \ I845_PIPE_OFFSETS, \@@ -202,10 +203,10 @@ static const struct intel_device_info intel_i865g_info = {#define GEN3_FEATURES \ GEN(3), \ + ENGINES(BIT(RCS0)), \ .num_pipes = 2, \ .display.has_gmch = 1, \ .gpu_reset_clobbers_display = true, \ - .engine_mask = BIT(RCS0), \ .has_snoop = true, \ .has_coherent_ggtt = true, \ I9XX_PIPE_OFFSETS, \@@ -286,11 +287,11 @@ static const struct intel_device_info intel_pineview_m_info = {#define GEN4_FEATURES \ GEN(4), \ + ENGINES(BIT(RCS0)), \ .num_pipes = 2, \ .display.has_hotplug = 1, \ .display.has_gmch = 1, \ .gpu_reset_clobbers_display = true, \ - .engine_mask = BIT(RCS0), \ .has_snoop = true, \ .has_coherent_ggtt = true, \ I9XX_PIPE_OFFSETS, \@@ -320,25 +321,25 @@ static const struct intel_device_info intel_i965gm_info = {static const struct intel_device_info intel_g45_info = {GEN4_FEATURES ,PLATFORM (INTEL_G45 ), - .engine_mask =BIT (RCS0 ) |BIT (VCS0 ), +ENGINES (BIT (RCS0 ) |BIT (VCS0 )), .gpu_reset_clobbers_display = false, };static const struct intel_device_info intel_gm45_info = {GEN4_FEATURES ,PLATFORM (INTEL_GM45 ), +ENGINES (BIT (RCS0 ) |BIT (VCS0 )), .is_mobile =1 , .display.has_fbc =1 , .display.supports_tv =1 , - .engine_mask =BIT (RCS0 ) |BIT (VCS0 ), .gpu_reset_clobbers_display = false, };#define GEN5_FEATURES \ GEN(5), \ + ENGINES(BIT(RCS0) | BIT(VCS0)), \ .num_pipes = 2, \ .display.has_hotplug = 1, \ - .engine_mask = BIT(RCS0) | BIT(VCS0), \ .has_snoop = true, \ .has_coherent_ggtt = true, \/* ilk does support rc6, but we do not implement [power] contexts */ \@@ -362,10 +363,10 @@ static const struct intel_device_info intel_ironlake_m_info = {#define GEN6_FEATURES \ GEN(6), \ + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0)), \ .num_pipes = 2, \ .display.has_hotplug = 1, \ .display.has_fbc = 1, \ - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), \ .has_coherent_ggtt = true, \ .has_llc = 1, \ .has_rc6 = 1, \@@ -410,10 +411,10 @@ static const struct intel_device_info intel_sandybridge_m_gt2_info = {#define GEN7_FEATURES \ GEN(7), \ + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0)), \ .num_pipes = 3, \ .display.has_hotplug = 1, \ .display.has_fbc = 1, \ - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), \ .has_coherent_ggtt = true, \ .has_llc = 1, \ .has_rc6 = 1, \@@ -468,6 +469,7 @@ static const struct intel_device_info intel_ivybridge_q_info = {static const struct intel_device_info intel_valleyview_info = {PLATFORM (INTEL_VALLEYVIEW ),GEN (7 ), +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 )), .is_lp =1 , .num_pipes =2 , .has_runtime_pm =1 ,@@ -479,7 +481,6 @@ static const struct intel_device_info intel_valleyview_info = { .ppgtt_size = 31, .has_snoop = true, .has_coherent_ggtt = false, - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), .display_mmio_offset =VLV_DISPLAY_BASE ,I9XX_PIPE_OFFSETS , I9XX_CURSOR_OFFSETS,@@ -489,7 +490,7 @@ static const struct intel_device_info intel_valleyview_info = {#define G75_FEATURES \ GEN7_FEATURES, \ - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0), \ + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0)), \ .display.has_ddi = 1, \ .has_fpga_dbg = 1, \ .display.has_psr = 1, \@@ -553,18 +554,17 @@ static const struct intel_device_info intel_broadwell_rsvd_info = {static const struct intel_device_info intel_broadwell_gt3_info = {BDW_PLATFORM , +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 )), .gt =3 , - .engine_mask = -BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 ), };static const struct intel_device_info intel_cherryview_info = {PLATFORM (INTEL_CHERRYVIEW ),GEN (8 ), +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 )), .num_pipes =3 , .display.has_hotplug =1 , .is_lp =1 , - .engine_mask =BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ), .has_64bit_reloc =1 , .has_runtime_pm =1 , .has_rc6 =1 ,@@ -616,9 +616,7 @@ static const struct intel_device_info intel_skylake_gt2_info = {#define SKL_GT3_PLUS_PLATFORM \ SKL_PLATFORM, \ - .engine_mask = \ - BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1) - + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1))static const struct intel_device_info intel_skylake_gt3_info = {SKL_GT3_PLUS_PLATFORM ,@@ -632,9 +630,9 @@ static const struct intel_device_info intel_skylake_gt4_info = {#define GEN9_LP_FEATURES \ GEN(9), \ + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0)), \ .is_lp = 1, \ .display.has_hotplug = 1, \ - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0), \ .num_pipes = 3, \ .has_64bit_reloc = 1, \ .display.has_ddi = 1, \@@ -689,9 +687,8 @@ static const struct intel_device_info intel_kabylake_gt2_info = {static const struct intel_device_info intel_kabylake_gt3_info = {KBL_PLATFORM , +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 )), .gt =3 , - .engine_mask = -BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 ), };#define CFL_PLATFORM \@@ -710,9 +707,8 @@ static const struct intel_device_info intel_coffeelake_gt2_info = {static const struct intel_device_info intel_coffeelake_gt3_info = {CFL_PLATFORM , +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 )), .gt =3 , - .engine_mask = -BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 ), };#define GEN10_FEATURES \@@ -754,15 +750,14 @@ static const struct intel_device_info intel_cannonlake_info = {static const struct intel_device_info intel_icelake_11_info = {GEN11_FEATURES ,PLATFORM (INTEL_ICELAKE ), - .engine_mask = -BIT (RCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS0 ) |BIT (VCS2 ), +ENGINES (BIT (RCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS0 ) |BIT (VCS2 )), };static const struct intel_device_info intel_elkhartlake_info = {GEN11_FEATURES ,PLATFORM (INTEL_ELKHARTLAKE ), +ENGINES (BIT (RCS0 ) |BIT (BCS0 ) |BIT (VCS0 )), .is_alpha_support =1 , - .engine_mask =BIT (RCS0 ) |BIT (BCS0 ) |BIT (VCS0 ), .ppgtt_size =36 , };drivers/gpu/drm/i915/intel_device_info.h +1
-2@@ -149,6 +149,7 @@ struct intel_device_info {u8 gen;u8 gt;/* GT number, 0 if undefined */ intel_engine_mask_t engine_mask;/* Engines supported by the HW */ +u8 num_engines;enum intel_platform platform;@@ -202,8 +203,6 @@ struct intel_runtime_info {u8 num_sprites[I915_MAX_PIPES ];u8 num_scalers[I915_MAX_PIPES ]; -u8 num_engines; -/* Slice/subslice/EU info */ struct sseu_dev_info sseu;drivers/gpu/drm/i915/selftests/i915_gem_context.c +2
-2@@ -1257,7 +1257,7 @@ static int igt_ctx_readonly(void *arg) } }pr_info ("Submitted %lu dwords (across %u engines)\n" , - ndwords,RUNTIME_INFO (i915)->num_engines); + ndwords,INTEL_INFO (i915)->num_engines); dw =0 ; idx =0 ;@@ -1586,7 +1586,7 @@ static int igt_vm_isolation(void *arg) count += this; }pr_info ("Checked %lu scratch offsets across %d engines\n" , - count,RUNTIME_INFO (i915)->num_engines); + count,INTEL_INFO (i915)->num_engines); out_rpm:intel_runtime_pm_put (i915, wakeref);drivers/gpu/drm/i915/selftests/i915_request.c +1
-1@@ -1211,7 +1211,7 @@ static int live_breadcrumbs_smoketest(void *arg) num_fences +=atomic_long_read (&t[id].num_fences); }pr_info ("Completed %lu waits for %lu fences across %d engines and %d cpus\n" , - num_waits, num_fences,RUNTIME_INFO (i915)->num_engines, ncpus); + num_waits, num_fences,INTEL_INFO (i915)->num_engines, ncpus);mutex_lock (&i915->drm.struct_mutex); ret =igt_live_test_end (&live) ?: ret;
Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 14/45] drm/i915: Make engine_mask & num_engines static
In reply to Chris WilsonQuoted 3 lines · Chris Wilson
Having removed the urge to modify the
engine_maskat runtime, we can promote thenum_enginesfrom a runtime calculation to a static and push it into thedevice_infotables.
What about fused off engines (intel_device_info_init_mmio)?
I don't see the patch touching that so it doesn't remove the runtime modification of engine_mask and also makes num_engines wrong in those cases.
Regards,
Tvrtko
Quoted 341 lines
Signed-off-by Chris Wilson <[email protected]>Cc Tvrtko Ursulin <[email protected]>Cc Jani Nikula <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 3 -- drivers/gpu/drm/i915/gt/intel_ringbuffer.c | 2 +- drivers/gpu/drm/i915/gt/selftest_lrc.c | 4 +- drivers/gpu/drm/i915/i915_pci.c | 45 +++++++++---------- drivers/gpu/drm/i915/intel_device_info.h | 3 +- .../gpu/drm/i915/selftests/i915_gem_context.c | 4 +- drivers/gpu/drm/i915/selftests/i915_request.c | 2 +- 7 files changed, 27 insertions(+), 36 deletions(-)drivers/gpu/drm/i915/gt/intel_engine_cs.c +0
-3@@ -383,9 +383,6 @@ int intel_engines_init_mmio(struct drm_i915_private *i915) goto cleanup; } -RUNTIME_INFO (i915)->num_engines = -hweight32 (INTEL_INFO (i915)->engine_mask); -i915_check_and_clear_faults (i915);return 0 ;drivers/gpu/drm/i915/gt/intel_ringbuffer.c +1
-1@@ -1568,7 +1568,7 @@ static inline int mi_set_context(struct i915_request *rq, u32 flags)struct intel_engine_cs *engine = rq->engine;enum intel_engine_id id;const int num_engines = -IS_HSW_GT1 (i915) ?RUNTIME_INFO (i915)->num_engines -1 :0 ; +IS_HSW_GT1 (i915) ?INTEL_INFO (i915)->num_engines -1 :0 ;bool force_restore = false;int len;u32 *cs;drivers/gpu/drm/i915/gt/selftest_lrc.c +2
-2@@ -1185,7 +1185,7 @@ static int smoke_crescendo(struct preempt_smoke *smoke, unsigned int flags)pr_info ("Submitted %lu crescendo:%x requests across %d engines and %d contexts\n" , count, flags, -RUNTIME_INFO (smoke->i915)->num_engines, smoke->ncontext); +INTEL_INFO (smoke->i915)->num_engines, smoke->ncontext);return 0 ; }@@ -1213,7 +1213,7 @@ static int smoke_random(struct preempt_smoke *smoke, unsigned int flags)pr_info ("Submitted %lu random:%x requests across %d engines and %d contexts\n" , count, flags, -RUNTIME_INFO (smoke->i915)->num_engines, smoke->ncontext); +INTEL_INFO (smoke->i915)->num_engines, smoke->ncontext);return 0 ; }drivers/gpu/drm/i915/i915_pci.c +20
-25@@ -35,6 +35,7 @@#define PLATFORM (x) .platform = (x)#define GEN (x) .gen = (x), .gen_mask = BIT((x) - 1) +#define ENGINES (x) .engine_mask = (x), .num_engines = hweight8(x)#define I845_PIPE_OFFSETS \ .pipe_offsets = { \@@ -145,6 +146,7 @@#define I830_FEATURES \ GEN(2), \ + ENGINES(BIT(RCS0)), \ .is_mobile = 1, \ .num_pipes = 2, \ .display.has_overlay = 1, \@@ -154,7 +156,6 @@ .gpu_reset_clobbers_display = true, \ .hws_needs_physical = 1, \ .unfenced_needs_alignment = 1, \ - .engine_mask = BIT(RCS0), \ .has_snoop = true, \ .has_coherent_ggtt = false, \ I9XX_PIPE_OFFSETS, \@@ -164,6 +165,7 @@#define I845_FEATURES \ GEN(2), \ + ENGINES(BIT(RCS0)), \ .num_pipes = 1, \ .display.has_overlay = 1, \ .display.overlay_needs_physical = 1, \@@ -171,7 +173,6 @@ .gpu_reset_clobbers_display = true, \ .hws_needs_physical = 1, \ .unfenced_needs_alignment = 1, \ - .engine_mask = BIT(RCS0), \ .has_snoop = true, \ .has_coherent_ggtt = false, \ I845_PIPE_OFFSETS, \@@ -202,10 +203,10 @@ static const struct intel_device_info intel_i865g_info = {#define GEN3_FEATURES \ GEN(3), \ + ENGINES(BIT(RCS0)), \ .num_pipes = 2, \ .display.has_gmch = 1, \ .gpu_reset_clobbers_display = true, \ - .engine_mask = BIT(RCS0), \ .has_snoop = true, \ .has_coherent_ggtt = true, \ I9XX_PIPE_OFFSETS, \@@ -286,11 +287,11 @@ static const struct intel_device_info intel_pineview_m_info = {#define GEN4_FEATURES \ GEN(4), \ + ENGINES(BIT(RCS0)), \ .num_pipes = 2, \ .display.has_hotplug = 1, \ .display.has_gmch = 1, \ .gpu_reset_clobbers_display = true, \ - .engine_mask = BIT(RCS0), \ .has_snoop = true, \ .has_coherent_ggtt = true, \ I9XX_PIPE_OFFSETS, \@@ -320,25 +321,25 @@ static const struct intel_device_info intel_i965gm_info = {static const struct intel_device_info intel_g45_info = {GEN4_FEATURES ,PLATFORM (INTEL_G45 ), - .engine_mask =BIT (RCS0 ) |BIT (VCS0 ), +ENGINES (BIT (RCS0 ) |BIT (VCS0 )), .gpu_reset_clobbers_display = false, };static const struct intel_device_info intel_gm45_info = {GEN4_FEATURES ,PLATFORM (INTEL_GM45 ), +ENGINES (BIT (RCS0 ) |BIT (VCS0 )), .is_mobile =1 , .display.has_fbc =1 , .display.supports_tv =1 , - .engine_mask =BIT (RCS0 ) |BIT (VCS0 ), .gpu_reset_clobbers_display = false, };#define GEN5_FEATURES \ GEN(5), \ + ENGINES(BIT(RCS0) | BIT(VCS0)), \ .num_pipes = 2, \ .display.has_hotplug = 1, \ - .engine_mask = BIT(RCS0) | BIT(VCS0), \ .has_snoop = true, \ .has_coherent_ggtt = true, \/* ilk does support rc6, but we do not implement [power] contexts */ \@@ -362,10 +363,10 @@ static const struct intel_device_info intel_ironlake_m_info = {#define GEN6_FEATURES \ GEN(6), \ + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0)), \ .num_pipes = 2, \ .display.has_hotplug = 1, \ .display.has_fbc = 1, \ - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), \ .has_coherent_ggtt = true, \ .has_llc = 1, \ .has_rc6 = 1, \@@ -410,10 +411,10 @@ static const struct intel_device_info intel_sandybridge_m_gt2_info = {#define GEN7_FEATURES \ GEN(7), \ + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0)), \ .num_pipes = 3, \ .display.has_hotplug = 1, \ .display.has_fbc = 1, \ - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), \ .has_coherent_ggtt = true, \ .has_llc = 1, \ .has_rc6 = 1, \@@ -468,6 +469,7 @@ static const struct intel_device_info intel_ivybridge_q_info = {static const struct intel_device_info intel_valleyview_info = {PLATFORM (INTEL_VALLEYVIEW ),GEN (7 ), +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 )), .is_lp =1 , .num_pipes =2 , .has_runtime_pm =1 ,@@ -479,7 +481,6 @@ static const struct intel_device_info intel_valleyview_info = { .ppgtt_size = 31, .has_snoop = true, .has_coherent_ggtt = false, - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), .display_mmio_offset =VLV_DISPLAY_BASE ,I9XX_PIPE_OFFSETS , I9XX_CURSOR_OFFSETS,@@ -489,7 +490,7 @@ static const struct intel_device_info intel_valleyview_info = {#define G75_FEATURES \ GEN7_FEATURES, \ - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0), \ + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0)), \ .display.has_ddi = 1, \ .has_fpga_dbg = 1, \ .display.has_psr = 1, \@@ -553,18 +554,17 @@ static const struct intel_device_info intel_broadwell_rsvd_info = {static const struct intel_device_info intel_broadwell_gt3_info = {BDW_PLATFORM , +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 )), .gt =3 , - .engine_mask = -BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 ), };static const struct intel_device_info intel_cherryview_info = {PLATFORM (INTEL_CHERRYVIEW ),GEN (8 ), +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 )), .num_pipes =3 , .display.has_hotplug =1 , .is_lp =1 , - .engine_mask =BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ), .has_64bit_reloc =1 , .has_runtime_pm =1 , .has_rc6 =1 ,@@ -616,9 +616,7 @@ static const struct intel_device_info intel_skylake_gt2_info = {#define SKL_GT3_PLUS_PLATFORM \ SKL_PLATFORM, \ - .engine_mask = \ - BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1) - + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1))static const struct intel_device_info intel_skylake_gt3_info = {SKL_GT3_PLUS_PLATFORM ,@@ -632,9 +630,9 @@ static const struct intel_device_info intel_skylake_gt4_info = {#define GEN9_LP_FEATURES \ GEN(9), \ + ENGINES(BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0)), \ .is_lp = 1, \ .display.has_hotplug = 1, \ - .engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0), \ .num_pipes = 3, \ .has_64bit_reloc = 1, \ .display.has_ddi = 1, \@@ -689,9 +687,8 @@ static const struct intel_device_info intel_kabylake_gt2_info = {static const struct intel_device_info intel_kabylake_gt3_info = {KBL_PLATFORM , +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 )), .gt =3 , - .engine_mask = -BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 ), };#define CFL_PLATFORM \@@ -710,9 +707,8 @@ static const struct intel_device_info intel_coffeelake_gt2_info = {static const struct intel_device_info intel_coffeelake_gt3_info = {CFL_PLATFORM , +ENGINES (BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 )), .gt =3 , - .engine_mask = -BIT (RCS0 ) |BIT (VCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS1 ), };#define GEN10_FEATURES \@@ -754,15 +750,14 @@ static const struct intel_device_info intel_cannonlake_info = {static const struct intel_device_info intel_icelake_11_info = {GEN11_FEATURES ,PLATFORM (INTEL_ICELAKE ), - .engine_mask = -BIT (RCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS0 ) |BIT (VCS2 ), +ENGINES (BIT (RCS0 ) |BIT (BCS0 ) |BIT (VECS0 ) |BIT (VCS0 ) |BIT (VCS2 )), };static const struct intel_device_info intel_elkhartlake_info = {GEN11_FEATURES ,PLATFORM (INTEL_ELKHARTLAKE ), +ENGINES (BIT (RCS0 ) |BIT (BCS0 ) |BIT (VCS0 )), .is_alpha_support =1 , - .engine_mask =BIT (RCS0 ) |BIT (BCS0 ) |BIT (VCS0 ), .ppgtt_size =36 , };drivers/gpu/drm/i915/intel_device_info.h +1
-2@@ -149,6 +149,7 @@ struct intel_device_info {u8 gen;u8 gt;/* GT number, 0 if undefined */ intel_engine_mask_t engine_mask;/* Engines supported by the HW */ +u8 num_engines;enum intel_platform platform;@@ -202,8 +203,6 @@ struct intel_runtime_info {u8 num_sprites[I915_MAX_PIPES ];u8 num_scalers[I915_MAX_PIPES ]; -u8 num_engines; -/* Slice/subslice/EU info */ struct sseu_dev_info sseu;drivers/gpu/drm/i915/selftests/i915_gem_context.c +2
-2@@ -1257,7 +1257,7 @@ static int igt_ctx_readonly(void *arg) } }pr_info ("Submitted %lu dwords (across %u engines)\n" , - ndwords,RUNTIME_INFO (i915)->num_engines); + ndwords,INTEL_INFO (i915)->num_engines); dw =0 ; idx =0 ;@@ -1586,7 +1586,7 @@ static int igt_vm_isolation(void *arg) count += this; }pr_info ("Checked %lu scratch offsets across %d engines\n" , - count,RUNTIME_INFO (i915)->num_engines); + count,INTEL_INFO (i915)->num_engines); out_rpm:intel_runtime_pm_put (i915, wakeref);drivers/gpu/drm/i915/selftests/i915_request.c +0
-0
drivers/gpu/drm/i915/selftests/i915_request.c static int live_breadcrumbs_smoketest(void *arg) · line 1217
Quoted 8 lines
drivers/gpu/drm/i915/selftests/i915_request.c +1
-1@@ -1211,7 +1211,7 @@ static int live_breadcrumbs_smoketest(void *arg) num_fences +=atomic_long_read (&t[id].num_fences); }pr_info ("Completed %lu waits for %lu fences across %d engines and %d cpus\n" , - num_waits, num_fences,RUNTIME_INFO (i915)->num_engines, ncpus); + num_waits, num_fences,INTEL_INFO (i915)->num_engines, ncpus);mutex_lock (&i915->drm.struct_mutex); ret =igt_live_test_end (&live) ?: ret;
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 14/45] drm/i915: Make engine_mask & num_engines static
Quoting Tvrtko Ursulin (2019-04-25 11:20:47)
Quoted 7 lines · Chris Wilson
Quoted 3 lines
Having removed the urge to modify the
engine_maskat runtime, we can promote thenum_enginesfrom a runtime calculation to a static and push it into thedevice_infotables.What about fused off engines (
intel_device_info_init_mmio)?
Didn't notice. :((
Plan B was just to calculate num_engines at point of use, since it is rare enough.
Oh well, this pair of patches was just inspired because I touched the cleanup code and not important.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 14/45] drm/i915: Make engine_mask & num_engines static
Quoted 7 lines · Chris Wilson
Quoting Tvrtko Ursulin (2019-04-25 11:20:47)
Quoted 6 lines · Chris Wilson
Quoted 3 lines
Having removed the urge to modify the
engine_maskat runtime, we can promote thenum_enginesfrom a runtime calculation to a static and push it into thedevice_infotables.
Quoted 6 lines
Quoted 1 line
What about fused off engines (
intel_device_info_init_mmio)?Didn't notice. :((
Plan B was just to calculate
num_enginesat point of use, since it is rare enough.
I'd just leave it in runtime info for now. Don't see a benefit of moving it.
If I can find my last series which tried to eliminate mkwrite and reduce runtime info, there were some notes in the resulting threads about which fields have what problems associated with them. I only remember the gen field was looking like easy pickings..
Anyways...
Quoted 2 lines
Oh well, this pair of patches was just inspired because I touched the cleanup code and not important.
.. please restrain the inspiration if ahead of media scalability otherwise we will never be done with it! :))
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 15/45 drm/i915: Restore control over ppgtt for context creation ABI
In reply to Chris WilsonHaving hid the partially exposed new ABI from the PR, put it back again for completion of context recovery. A significant part of context recovery is the ability to reuse as much of the old context as is feasible (to avoid expensive reconstruction). The biggest chunk kept hidden at the moment is fine-control over the ctx->ppgtt (the GPU page tables and associated translation tables and kernel maps), so make control over the ctx->ppgtt explicit.
This allows userspace to create and share virtual memory address spaces (within the limits of a single fd) between contexts they own, along with the ability to query the contexts for the vm state.
--- drivers/gpu/drm/i915/i915_drv.c | 2 ++ drivers/gpu/drm/i915/i915_gem_context.c | 5 ----- include/uapi/drm/i915_drm.h | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -0
@@ -3150,6 +3150,8 @@ static const struct drm_ioctl_desc i915_ioctls[] = {DRM_IOCTL_DEF_DRV (I915_PERF_ADD_CONFIG , i915_perf_add_config_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (I915_PERF_REMOVE_CONFIG , i915_perf_remove_config_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (I915_QUERY , i915_query_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (I915_GEM_VM_CREATE , i915_gem_vm_create_ioctl,DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(I915_GEM_VM_DESTROY, i915_gem_vm_destroy_ioctl, DRM_RENDER_ALLOW), }; static struct drm_driver driver = {
drivers/gpu/drm/i915/i915_gem_context.c +0 -5
@@ -98,7 +98,6 @@#include "i915_user_extensions.h" #define I915_CONTEXT_CREATE_FLAGS_SINGLE_TIMELINE (1 << 1) -#define I915_CONTEXT_PARAM_VM 0x9#define ALL_L3_SLICES (dev) (1 << NUM_L3_SLICES(dev)) - 1
@@ -969,8 +968,6 @@ static int get_ppgtt(struct drm_i915_file_private *file_priv,struct i915_hw_ppgtt *ppgtt;int ret; -return -EINVAL ;/* nothing to see here; please move along */ -if (!ctx->ppgtt)return -ENODEV ;
@@ -1069,8 +1066,6 @@ static int set_ppgtt(struct drm_i915_file_private *file_priv,struct i915_hw_ppgtt *ppgtt, *old;int err; -return -EINVAL ;/* nothing to see here; please move along */ -if (args->size)return -EINVAL ;
include/uapi/drm/i915_drm.h +15 -0
@@ -355,6 +355,8 @@ typedef struct _drm_i915_sarea {#define DRM_I915_PERF_ADD_CONFIG 0x37#define DRM_I915_PERF_REMOVE_CONFIG 0x38#define DRM_I915_QUERY 0x39 +#define DRM_I915_GEM_VM_CREATE 0x3a +#define DRM_I915_GEM_VM_DESTROY 0x3b/* Must be kept compact -- no holes */ #define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
@@ -415,6 +417,8 @@ typedef struct _drm_i915_sarea {#define DRM_IOCTL_I915_PERF_ADD_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_I915_PERF_ADD_CONFIG, struct drm_i915_perf_oa_config)#define DRM_IOCTL_I915_PERF_REMOVE_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_I915_PERF_REMOVE_CONFIG, __u64)#define DRM_IOCTL_I915_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_QUERY, struct drm_i915_query) +#define DRM_IOCTL_I915_GEM_VM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_VM_CREATE, struct drm_i915_gem_vm_control) +#define DRM_IOCTL_I915_GEM_VM_DESTROY DRM_IOW (DRM_COMMAND_BASE + DRM_I915_GEM_VM_DESTROY, struct drm_i915_gem_vm_control)/* Allow drivers to submit batchbuffers directly to hardware, relying * on the security mechanisms provided by hardware.
@@ -1507,6 +1511,17 @@ struct drm_i915_gem_context_param {* On creation, all new contexts are marked as recoverable. */ #define I915_CONTEXT_PARAM_RECOVERABLE 0x8 + +/* +* The id of the associated virtual memory address space (ppGTT) of +* this context. Can be retrieved and passed to another context +* (on the same fd) for both to use the same ppGTT and so share +* address layouts, and avoid reloading the page tables on context +* switches between themselves. +* +* See DRM_I915_GEM_VM_CREATE and DRM_I915_GEM_VM_DESTROY. +*/ +#define I915_CONTEXT_PARAM_VM 0x9/* Must be kept compact -- no holes and well documented */ __u64 value;
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 16/45 drm/i915: Allow a context to define its set of engines
In reply to Chris WilsonOver the last few years, we have debated how to extend the user API to support an increase in the number of engines, that may be sparse and even be heterogeneous within a class (not all video decoders created equal). We settled on using (class, instance) tuples to identify a specific engine, with an API for the user to construct a map of engines to capabilities. Into this picture, we then add a challenge of virtual engines; one user engine that maps behind the scenes to any number of physical engines. To keep it general, we want the user to have full control over that mapping. To that end, we allow the user to constrain a context to define the set of engines that it can access, order fully controlled by the user via (class, instance). With such precise control in context setup, we can continue to use the existing execbuf uABI of specifying a single index; only now it doesn't automagically map onto the engines, it uses the user defined engine map from the context.
v2: Fixup freeing of local on success of get_engines()
v3: Allow empty engines[]
v4: s/nengine/num_engines/
v5: Replace 64 limit on num_engines with a note that execbuf is currently limited to only using the first 64 engines.
v6: Actually use the engines_mutex to guard the ctx->engines.
Testcase: igt/gem_ctx_engines
--- drivers/gpu/drm/i915/i915_gem_context.c | 219 +++++++++++++++++- drivers/gpu/drm/i915/i915_gem_context.h | 18 ++ drivers/gpu/drm/i915/i915_gem_context_types.h | 1 + drivers/gpu/drm/i915/i915_gem_execbuffer.c | 5 +- drivers/gpu/drm/i915/i915_utils.h | 36 +++ include/uapi/drm/i915_drm.h | 31 +++ 6 files changed, 303 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +213 -6
@@ -90,7 +90,6 @@#include <drm/i915_drm.h> #include "gt/intel_lrc_reg.h" -#include "gt/intel_workarounds.h" #include "i915_drv.h" #include "i915_globals.h"
@@ -143,13 +142,17 @@ static void lut_close(struct i915_gem_context *ctx)static struct intel_context *lookup_user_engine (struct i915_gem_context *ctx,u16 class,u16 instance) { -struct intel_engine_cs *engine; +if (!i915_gem_context_user_engines (ctx)) { +struct intel_engine_cs *engine; - engine =intel_engine_lookup_user (ctx->i915, class, instance); -if (!engine) -return ERR_PTR (-EINVAL ); + engine =intel_engine_lookup_user (ctx->i915, class, instance); +if (!engine) +return ERR_PTR (-EINVAL ); + + instance = engine->id; + } -return i915_gem_context_get_engine (ctx, engine->id); +return i915_gem_context_get_engine (ctx, instance); }static inline int new_hw_id (struct drm_i915_private *i915,gfp_t gfp)
@@ -257,6 +260,17 @@ static void free_engines(struct i915_gem_engines *e)__free_engines (e, e->num_engines); } +static void free_engines_rcu (struct work_struct *wrk) +{ +struct i915_gem_engines *e = + container_of(wrk, struct i915_gem_engines, rcu.work); +struct drm_i915_private *i915 = e->i915; + +mutex_lock (&i915->drm.struct_mutex); +free_engines (e); +mutex_unlock (&i915->drm.struct_mutex); +} +static struct i915_gem_engines *default_engines (struct i915_gem_context *ctx) {struct intel_engine_cs *engine;
@@ -1382,6 +1396,191 @@ static int set_sseu(struct i915_gem_context *ctx,return ret; } +struct set_engines { +struct i915_gem_context *ctx; +struct i915_gem_engines *engines; +}; + +static const i915_user_extension_fn set_engines__extensions[] = { +}; + +static int +set_engines (struct i915_gem_context *ctx, +const struct drm_i915_gem_context_param *args) +{ +struct i915_context_param_engines __user *user = +u64_to_user_ptr (args->value); +struct set_engines set = { .ctx = ctx }; +unsigned int num_engines, n; +u64 extensions; +int err; + +if (!args->size) {/* switch back to legacy user_ring_map */ +if (!i915_gem_context_user_engines (ctx)) +return 0 ; + + set.engines =default_engines (ctx); +if (IS_ERR (set.engines)) +return PTR_ERR (set.engines); + + goto replace; + } + +BUILD_BUG_ON (!IS_ALIGNED (sizeof (*user),sizeof (*user->engines))); +if (args->size <sizeof (*user) || + !IS_ALIGNED (args->size,sizeof (*user->engines))) { +DRM_DEBUG ("Invalid size for engine array: %d\n" , + args->size); +return -EINVAL ; + } + +/* +* Note that I915_EXEC_RING_MASK limits execbuf to only using the +* first 64 engines defined here. +*/ + num_engines = (args->size -sizeof (*user)) /sizeof (*user->engines); + + set.engines =kmalloc (struct_size (set.engines, engines, num_engines), +GFP_KERNEL ); +if (!set.engines) +return -ENOMEM ; + + set.engines->i915 = ctx->i915; +for (n =0 ; n < num_engines; n++) { +struct i915_engine_class_instance ci; +struct intel_engine_cs *engine; + +if (copy_from_user (&ci, &user->engines[n],sizeof (ci))) { +__free_engines (set.engines, n); +return -EFAULT ; + } + +if (ci.engine_class == (u16 )I915_ENGINE_CLASS_INVALID && + ci.engine_instance == (u16 )I915_ENGINE_CLASS_INVALID_NONE ) { + set.engines->engines[n] =NULL ; +continue ; + } + + engine =intel_engine_lookup_user (ctx->i915, + ci.engine_class, + ci.engine_instance); +if (!engine) { +DRM_DEBUG ("Invalid engine[%d]: { class:%d, instance:%d }\n" , + n, ci.engine_class, ci.engine_instance); +__free_engines (set.engines, n); +return -ENOENT ; + } + + set.engines->engines[n] =intel_context_create (ctx, engine); +if (!set.engines->engines[n]) { +__free_engines (set.engines, n); +return -ENOMEM ; + } + } + set.engines->num_engines = num_engines; + + err = -EFAULT ; +if (!get_user (extensions, &user->extensions)) + err =i915_user_extensions (u64_to_user_ptr (extensions), + set_engines__extensions, +ARRAY_SIZE (set_engines__extensions), + &set); +if (err) { +free_engines (set.engines); +return err; + } + +replace: +mutex_lock (&ctx->engines_mutex); +if (args->size) +i915_gem_context_set_user_engines (ctx); +else +i915_gem_context_clear_user_engines (ctx); +rcu_swap_protected (ctx->engines, set.engines,1 ); +mutex_unlock (&ctx->engines_mutex); + +INIT_RCU_WORK (&set.engines->rcu, free_engines_rcu); +queue_rcu_work (system_wq, &set.engines->rcu); + +return 0 ; +} + +static int +get_engines (struct i915_gem_context *ctx, +struct drm_i915_gem_context_param *args) +{ +struct i915_context_param_engines __user *user; +struct i915_gem_engines *e; +size_t n, count, size; +int err =0 ; + + err =mutex_lock_interruptible (&ctx->engines_mutex); +if (err) +return err; + +if (!i915_gem_context_user_engines (ctx)) { + args->size =0 ; + goto unlock; + } + + e =i915_gem_context_engines (ctx); + count = e->num_engines; + +/* Be paranoid in case we have an impedance mismatch */ +if (!check_struct_size (user, engines, count, &size)) { + err = -EINVAL ; + goto unlock; + } +if (overflows_type (size, args->size)) { + err = -EINVAL ; + goto unlock; + } + +if (!args->size) { + args->size = size; + goto unlock; + } + +if (args->size < size) { + err = -EINVAL ; + goto unlock; + } + + user =u64_to_user_ptr (args->value); +if (!access_ok (user, size)) { + err = -EFAULT ; + goto unlock; + } + +if (put_user (0 , &user->extensions)) { + err = -EFAULT ; + goto unlock; + } + +for (n =0 ; n < count; n++) { +struct i915_engine_class_instance ci = { + .engine_class =I915_ENGINE_CLASS_INVALID , + .engine_instance =I915_ENGINE_CLASS_INVALID_NONE , + }; + +if (e->engines[n]) { + ci.engine_class = e->engines[n]->engine->uabi_class; + ci.engine_instance = e->engines[n]->engine->instance; + } + +if (copy_to_user (&user->engines[n], &ci,sizeof (ci))) { + err = -EFAULT ; + goto unlock; + } + } + + args->size = size; + +unlock: +mutex_unlock (&ctx->engines_mutex); +return err; +} +static int ctx_setparam (struct drm_i915_file_private *fpriv,struct i915_gem_context *ctx,struct drm_i915_gem_context_param *args)
@@ -1455,6 +1654,10 @@ static int ctx_setparam(struct drm_i915_file_private *fpriv, ret =set_ppgtt (fpriv, ctx, args);break ; +case I915_CONTEXT_PARAM_ENGINES : + ret =set_engines (ctx, args); +break ; +case I915_CONTEXT_PARAM_BAN_PERIOD :default : ret = -EINVAL ;
@@ -1685,6 +1888,10 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, ret =get_ppgtt (file_priv, ctx, args);break ; +case I915_CONTEXT_PARAM_ENGINES : + ret =get_engines (ctx, args); +break ; +case I915_CONTEXT_PARAM_BAN_PERIOD :default : ret = -EINVAL ;
drivers/gpu/drm/i915/i915_gem_context.h +18 -0
@@ -112,6 +112,24 @@ static inline void i915_gem_context_set_force_single_submission(struct i915_gem___set_bit (CONTEXT_FORCE_SINGLE_SUBMISSION , &ctx->flags); } +static inline bool +i915_gem_context_user_engines (const struct i915_gem_context *ctx) +{ +return test_bit (CONTEXT_USER_ENGINES , &ctx->flags); +} + +static inline void +i915_gem_context_set_user_engines (struct i915_gem_context *ctx) +{ +set_bit (CONTEXT_USER_ENGINES , &ctx->flags); +} + +static inline void +i915_gem_context_clear_user_engines (struct i915_gem_context *ctx) +{ +clear_bit (CONTEXT_USER_ENGINES , &ctx->flags); +} +int __i915_gem_context_pin_hw_id (struct i915_gem_context *ctx);static inline int i915_gem_context_pin_hw_id (struct i915_gem_context *ctx) {
drivers/gpu/drm/i915/i915_gem_context_types.h +1 -0
@@ -146,6 +146,7 @@ struct i915_gem_context {#define CONTEXT_BANNED 0#define CONTEXT_CLOSED 1#define CONTEXT_FORCE_SINGLE_SUBMISSION 2 +#define CONTEXT_USER_ENGINES 3/** * @hw_id: - unique identifier for the context
drivers/gpu/drm/i915/i915_gem_execbuffer.c +4 -1
@@ -2165,7 +2165,10 @@ eb_select_engine(struct i915_execbuffer *eb,unsigned int idx;int err; - idx =eb_select_legacy_ring (eb, file, args); +if (i915_gem_context_user_engines (eb->gem_context)) + idx = args->flags &I915_EXEC_RING_MASK ; +else + idx =eb_select_legacy_ring (eb, file, args); ce =i915_gem_context_get_engine (eb->gem_context, idx);if (IS_ERR (ce))
drivers/gpu/drm/i915/i915_utils.h +36 -0
@@ -25,6 +25,9 @@#ifndef __I915_UTILS_H#define __I915_UTILS_H +#include <linux/kernel.h> +#include <linux/overflow.h> +#undef WARN_ON/* Many gcc seem to no see through this and fall over :( */ #if 0
@@ -73,6 +76,39 @@#define overflows_type (x,T ) \ (sizeof(x) > sizeof(T) && (x) >> BITS_PER_TYPE(T)) +static inline bool +__check_struct_size (size_t base,size_t arr,size_t count,size_t *size) +{ +size_t sz; + +if (check_mul_overflow (count, arr, &sz)) +return false; + +if (check_add_overflow (sz, base, &sz)) +return false; + + *size = sz; +return true; +} + +/** +* check_struct_size() - Calculate size of structure with trailing array. +* @p: Pointer to the structure. +* @member: Name of the array member. +* @n: Number of elements in the array. +* @sz: Total size of structure and array +* +* Calculates size of memory needed for structure @p followed by an +* array of @n @member elements, like struct_size() but reports +* whether it overflowed, and the resultant size in @sz +* +* Return: false if the calculation overflowed. +*/ +#define check_struct_size (p, member, n, sz) \ + likely(__check_struct_size(sizeof(*(p)), \ + sizeof(*(p)->member) + __must_be_array((p)->member), \ + n, sz)) +#define ptr_mask_bits (ptr, n) ({ \ unsigned long __v = (unsigned long)(ptr); \ (typeof(ptr))(__v & -BIT(n)); \
include/uapi/drm/i915_drm.h +31 -0
@@ -136,6 +136,7 @@ enum drm_i915_gem_engine_class {struct i915_engine_class_instance {__u16 engine_class;/* see enum drm_i915_gem_engine_class */ __u16 engine_instance; +#define I915_ENGINE_CLASS_INVALID_NONE -1 };/**
@@ -1522,6 +1523,26 @@ struct drm_i915_gem_context_param {* See DRM_I915_GEM_VM_CREATE and DRM_I915_GEM_VM_DESTROY. */ #define I915_CONTEXT_PARAM_VM 0x9 + +/* +* I915_CONTEXT_PARAM_ENGINES: +* +* Bind this context to operate on this subset of available engines. Henceforth, +* the I915_EXEC_RING selector for DRM_IOCTL_I915_GEM_EXECBUFFER2 operates as +* an index into this array of engines; I915_EXEC_DEFAULT selecting engine[0] +* and upwards. Slots 0...N are filled in using the specified (class, instance). +* Use +* engine_class: I915_ENGINE_CLASS_INVALID, +* engine_instance: I915_ENGINE_CLASS_INVALID_NONE +* to specify a gap in the array that can be filled in later, e.g. by a +* virtual engine used for load balancing. +* +* Setting the number of engines bound to the context to 0, by passing a zero +* sized argument, will revert back to default settings. +* +* See struct i915_context_param_engines. +*/ +#define I915_CONTEXT_PARAM_ENGINES 0xa/* Must be kept compact -- no holes and well documented */ __u64 value;
@@ -1585,6 +1606,16 @@ struct drm_i915_gem_context_param_sseu {__u32 rsvd; }; +struct i915_context_param_engines { +__u64 extensions;/* linked chain of extension blocks, 0 terminates */ +struct i915_engine_class_instance engines[0 ]; +} __attribute__((packed)); + +#define I915_DEFINE_CONTEXT_PARAM_ENGINES (name__,N__ ) struct { \ + __u64 extensions; \ + struct i915_engine_class_instance engines[N__]; \ +} __attribute__((packed)) name__ +struct drm_i915_gem_context_create_ext_setparam {#define I915_CONTEXT_CREATE_EXT_SETPARAM 0struct i915_user_extension base;
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 17/45 drm/i915: Re-expose SINGLE_TIMELINE flags for context creation
In reply to Chris WilsonThe SINGLE_TIMELINE flag can be used to create a context such that all engine instances within that context share a common timeline. This can be useful for mixing operations between real and virtual engines, or when using a composite context for a single client API context.
--- drivers/gpu/drm/i915/i915_gem_context.c | 4 ---- include/uapi/drm/i915_drm.h | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_gem_context.c +0 -4
@@ -96,8 +96,6 @@#include "i915_trace.h" #include "i915_user_extensions.h" -#define I915_CONTEXT_CREATE_FLAGS_SINGLE_TIMELINE (1 << 1) -#define ALL_L3_SLICES (dev) (1 << NUM_L3_SLICES(dev)) - 1 static struct i915_global_gem_context {
@@ -493,8 +491,6 @@ i915_gem_create_context(struct drm_i915_private *dev_priv, unsigned int flags)lockdep_assert_held (&dev_priv->drm.struct_mutex); -BUILD_BUG_ON (I915_CONTEXT_CREATE_FLAGS_SINGLE_TIMELINE & - ~I915_CONTEXT_CREATE_FLAGS_UNKNOWN );if (flags &I915_CONTEXT_CREATE_FLAGS_SINGLE_TIMELINE && !HAS_EXECLISTS (dev_priv))return ERR_PTR (-EINVAL );
include/uapi/drm/i915_drm.h +2 -1
@@ -1469,8 +1469,9 @@ struct drm_i915_gem_context_create_ext {__u32 ctx_id;/* output: id of new context*/ __u32 flags;#define I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS (1u << 0) +#define I915_CONTEXT_CREATE_FLAGS_SINGLE_TIMELINE (1u << 1)#define I915_CONTEXT_CREATE_FLAGS_UNKNOWN \ - (-(I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS << 1)) + (-(I915_CONTEXT_CREATE_FLAGS_SINGLE_TIMELINE << 1))__u64 extensions; };
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 18/45 drm/i915: Allow userspace to clone contexts on creation
In reply to Chris WilsonA usecase arose out of handling context recovery in mesa, whereby they wish to recreate a context with fresh logical state but preserving all other details of the original. Currently, they create a new context and iterate over which bits they want to copy across, but it would much more convenient if they were able to just pass in a target context to clone during creation. This essentially extends the setparam during creation to pull the details from a target context instead of the user supplied parameters.
The ideal here is that we don't expose control over anything more than can be obtained via CONTEXT_PARAM. That is userspace retains explicit control over all features, and this api is just convenience.
For example, you could replace
struct context_param p = { .param = CONTEXT_PARAM_VM };
param.ctx_id = old_id;
gem_context_get_param(&p.param);
new_id = gem_context_create();
param.ctx_id = new_id;
gem_context_set_param(&p.param);
gem_vm_destroy(param.value); /* drop the ref to VM_ID handle */with
struct create_ext_param p = {
{ .name = CONTEXT_CREATE_CLONE },
.clone_id = old_id,
.flags = CLONE_FLAGS_VM
}
new_id = gem_context_create_ext(&p);and not have to worry about stray namespace pollution etc.
--- drivers/gpu/drm/i915/i915_gem_context.c | 206 ++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 15 ++ 2 files changed, 221 insertions(+)
drivers/gpu/drm/i915/i915_gem_context.c +206 -0
@@ -1682,8 +1682,214 @@ static int create_setparam(struct i915_user_extension __user *ext, void *data)return ctx_setparam (arg->fpriv, arg->ctx, &local.param); } +static int clone_engines (struct i915_gem_context *dst, +struct i915_gem_context *src) +{ +struct i915_gem_engines *e =i915_gem_context_lock_engines (src); +struct i915_gem_engines *clone; +bool user_engines; +unsigned long n; + + clone =kmalloc (struct_size (e, engines, e->num_engines),GFP_KERNEL ); +if (!clone) + goto err_unlock; + + clone->i915 = dst->i915; +for (n =0 ; n < e->num_engines; n++) { +if (!e->engines[n]) { + clone->engines[n] =NULL ; +continue ; + } + + clone->engines[n] = +intel_context_create (dst, e->engines[n]->engine); +if (!clone->engines[n]) { +__free_engines (clone, n); + goto err_unlock; + } + } + clone->num_engines = n; + + user_engines =i915_gem_context_user_engines (src); +i915_gem_context_unlock_engines (src); + +free_engines (dst->engines); +RCU_INIT_POINTER (dst->engines, clone); +if (user_engines) +i915_gem_context_set_user_engines (dst); +else +i915_gem_context_clear_user_engines (dst); +return 0 ; + +err_unlock: +i915_gem_context_unlock_engines (src); +return -ENOMEM ; +} + +static int clone_flags (struct i915_gem_context *dst, +struct i915_gem_context *src) +{ + dst->user_flags = src->user_flags; +return 0 ; +} + +static int clone_schedattr (struct i915_gem_context *dst, +struct i915_gem_context *src) +{ + dst->sched = src->sched; +return 0 ; +} + +static int clone_sseu (struct i915_gem_context *dst, +struct i915_gem_context *src) +{ +struct i915_gem_engines *e =i915_gem_context_lock_engines (src); +struct i915_gem_engines *clone; +unsigned long n; +int err; + + clone = dst->engines;/* no locking required; sole access */ +if (e->num_engines != clone->num_engines) { + err = -EINVAL ; + goto unlock; + } + +for (n =0 ; n < e->num_engines; n++) { +struct intel_context *ce = e->engines[n]; + +if (clone->engines[n]->engine->class != ce->engine->class) { +/* Must have compatible engine maps! */ + err = -EINVAL ; + goto unlock; + } + +/* serialises with set_sseu */ + err =intel_context_lock_pinned (ce); +if (err) + goto unlock; + + clone->engines[n]->sseu = ce->sseu; +intel_context_unlock_pinned (ce); + } + + err =0 ; +unlock: +i915_gem_context_unlock_engines (src); +return err; +} + +static int clone_timeline (struct i915_gem_context *dst, +struct i915_gem_context *src) +{ +if (src->timeline) { +GEM_BUG_ON (src->timeline == dst->timeline); + +if (dst->timeline) +i915_timeline_put (dst->timeline); + dst->timeline =i915_timeline_get (src->timeline); + } + +return 0 ; +} + +static int clone_vm (struct i915_gem_context *dst, +struct i915_gem_context *src) +{ +struct i915_hw_ppgtt *ppgtt; + +rcu_read_lock (); +do { + ppgtt =READ_ONCE (src->ppgtt); +if (!ppgtt) +break ; + +if (!kref_get_unless_zero (&ppgtt->ref)) +continue ; + +/* +* This ppgtt may have be reallocated between +* the read and the kref, and reassigned to a third +* context. In order to avoid inadvertent sharing +* of this ppgtt with that third context (and not +* src), we have to confirm that we have the same +* ppgtt after passing through the strong memory +* barrier implied by a successful +* kref_get_unless_zero(). +* +* Once we have acquired the current ppgtt of src, +* we no longer care if it is released from src, as +* it cannot be reallocated elsewhere. +*/ + +if (ppgtt ==READ_ONCE (src->ppgtt)) +break ; + +i915_ppgtt_put (ppgtt); + }while (1 ); +rcu_read_unlock (); + +if (ppgtt) { +__assign_ppgtt (dst, ppgtt); +i915_ppgtt_put (ppgtt); + } + +return 0 ; +} + +static int create_clone (struct i915_user_extension __user *ext,void *data) +{ +static int (*const fn[])(struct i915_gem_context *dst, +struct i915_gem_context *src) = { +#define MAP(x, y) [ilog2(I915_CONTEXT_CLONE_##x)] = y +MAP (ENGINES , clone_engines), +MAP (FLAGS , clone_flags), +MAP (SCHEDATTR , clone_schedattr), +MAP (SSEU , clone_sseu), +MAP (TIMELINE , clone_timeline), +MAP (VM , clone_vm), +#undef MAP + }; +struct drm_i915_gem_context_create_ext_clone local; +const struct create_ext *arg = data; +struct i915_gem_context *dst = arg->ctx; +struct i915_gem_context *src; +int err, bit; + +if (copy_from_user (&local, ext,sizeof (local))) +return -EFAULT ; + +BUILD_BUG_ON (GENMASK (BITS_PER_TYPE (local.flags) -1 ,ARRAY_SIZE (fn)) != +I915_CONTEXT_CLONE_UNKNOWN ); + +if (local.flags &I915_CONTEXT_CLONE_UNKNOWN ) +return -EINVAL ; + +if (local.rsvd) +return -EINVAL ; + +rcu_read_lock (); + src =__i915_gem_context_lookup_rcu (arg->fpriv, local.clone_id); +rcu_read_unlock (); +if (!src) +return -ENOENT ; + +GEM_BUG_ON (src == dst); + +for (bit =0 ; bit <ARRAY_SIZE (fn); bit++) { +if (!(local.flags &BIT (bit))) +continue ; + + err = fn[bit](dst, src); +if (err) +return err; + } + +return 0 ; +} +static const i915_user_extension_fn create_extensions[] = { [I915_CONTEXT_CREATE_EXT_SETPARAM ] = create_setparam, + [I915_CONTEXT_CREATE_EXT_CLONE ] = create_clone, };static bool client_is_banned (struct drm_i915_file_private *file_priv)
include/uapi/drm/i915_drm.h +15 -0
@@ -1623,6 +1623,21 @@ struct drm_i915_gem_context_create_ext_setparam {struct drm_i915_gem_context_param param; }; +struct drm_i915_gem_context_create_ext_clone { +#define I915_CONTEXT_CREATE_EXT_CLONE 1 +struct i915_user_extension base; +__u32 clone_id; +__u32 flags; +#define I915_CONTEXT_CLONE_ENGINES (1u << 0) +#define I915_CONTEXT_CLONE_FLAGS (1u << 1) +#define I915_CONTEXT_CLONE_SCHEDATTR (1u << 2) +#define I915_CONTEXT_CLONE_SSEU (1u << 3) +#define I915_CONTEXT_CLONE_TIMELINE (1u << 4) +#define I915_CONTEXT_CLONE_VM (1u << 5) +#define I915_CONTEXT_CLONE_UNKNOWN -(I915_CONTEXT_CLONE_VM << 1) +__u64 rsvd; +}; +struct drm_i915_gem_context_destroy {__u32 ctx_id;__u32 pad;
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 19/45 drm/i915: Load balancing across a virtual engine
In reply to Chris WilsonHaving allowed the user to define a set of engines that they will want to only use, we go one step further and allow them to bind those engines into a single virtual instance. Submitting a batch to the virtual engine will then forward it to any one of the set in a manner as best to distribute load. The virtual engine has a single timeline across all engines (it operates as a single queue), so it is not able to concurrently run batches across multiple engines by itself; that is left up to the user to submit multiple concurrent batches to multiple queues. Multiple users will be load balanced across the system.
The mechanism used for load balancing in this patch is a late greedy balancer. When a request is ready for execution, it is added to each engine's queue, and when an engine is ready for its next request it claims it from the virtual engine. The first engine to do so, wins, i.e. the request is executed at the earliest opportunity (idle moment) in the system.
As not all HW is created equal, the user is still able to skip the virtual engine and execute the batch on a specific engine, all within the same queue. It will then be executed in order on the correct engine, with execution on other virtual engines being moved away due to the load detection.
A couple of areas for potential improvement left!
- The virtual engine always take priority over equal-priority tasks. Mostly broken up by applying FQ_CODEL rules for prioritising new clients, and hopefully the virtual and real engines are not then congested (i.e. all work is via virtual engines, or all work is to the real engine).
- We require the breadcrumb irq around every virtual engine request. For normal engines, we eliminate the need for the slow round trip via interrupt by using the submit fence and queueing in order. For virtual engines, we have to allow any job to transfer to a new ring, and cannot coalesce the submissions, so require the completion fence instead, forcing the persistent use of interrupts.
- We only drip feed single requests through each virtual engine and onto the physical engines, even if there was enough work to fill all ELSP, leaving small stalls with an idle CS event at the end of every request. Could we be greedy and fill both slots? Being lazy is virtuous for load distribution on less-than-full workloads though.
Other areas of improvement are more general, such as reducing lock contention, reducing dispatch overhead, looking at direct submission rather than bouncing around tasklets etc.
sseu: Lift the restriction to allow sseu to be reconfigured on virtual engines composed of RENDER_CLASS (rcs).
v2: macroize check_user_mbz()
v3: Cancel virtual engines on wedging
v4: Commence commenting
v5: Replace 64b sibling_mask with a list of class:instance
--- drivers/gpu/drm/i915/gt/intel_breadcrumbs.c | 6 +- drivers/gpu/drm/i915/gt/intel_engine_types.h | 8 + drivers/gpu/drm/i915/gt/intel_lrc.c | 656 ++++++++++++++++++- drivers/gpu/drm/i915/gt/intel_lrc.h | 9 + drivers/gpu/drm/i915/gt/selftest_lrc.c | 180 +++++ drivers/gpu/drm/i915/i915_gem.h | 5 + drivers/gpu/drm/i915/i915_gem_context.c | 118 +++- drivers/gpu/drm/i915/i915_scheduler.c | 18 +- drivers/gpu/drm/i915/i915_timeline_types.h | 1 + include/uapi/drm/i915_drm.h | 39 ++ 10 files changed, 1012 insertions(+), 28 deletions(-)
drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +5 -1
@@ -290,8 +290,12 @@ bool i915_request_enable_breadcrumb(struct i915_request *rq)break ; }list_add (&rq->signal_link, pos); -if (pos == &ce->signals)/* catch transitions from empty list */ +if (pos == &ce->signals) {/* catch transitions from empty */ list_move_tail (&ce->signal_link, &b->signalers); + }else if (ce->engine != rq->engine) {/* virtualised */ +list_move_tail (&ce->signal_link, &b->signalers); +intel_engine_queue_breadcrumbs (rq->engine); + }set_bit (I915_FENCE_FLAG_SIGNAL , &rq->fence.flags);spin_unlock (&b->irq_lock);
drivers/gpu/drm/i915/gt/intel_engine_types.h +8 -0
@@ -227,6 +227,7 @@ struct intel_engine_execlists {* @queue: queue of requests, in priority lists */ struct rb_root_cached queue; +struct rb_root_cached virtual;/** * @csb_write: control register for Context Switch buffer
@@ -445,6 +446,7 @@ struct intel_engine_cs {#define I915_ENGINE_HAS_PREEMPTION BIT(2)#define I915_ENGINE_HAS_SEMAPHORES BIT(3)#define I915_ENGINE_NEEDS_BREADCRUMB_TASKLET BIT(4) +#define I915_ENGINE_IS_VIRTUAL BIT(5)unsigned int flags;/*
@@ -534,6 +536,12 @@ intel_engine_needs_breadcrumb_tasklet(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_NEEDS_BREADCRUMB_TASKLET ; } +static inline bool +intel_engine_is_virtual (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_IS_VIRTUAL ; +} +#define instdone_slice_mask (dev_priv__) \ (IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)
drivers/gpu/drm/i915/gt/intel_lrc.c +636 -20
775 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_lrc.h +9 -0
@@ -114,4 +114,13 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine, const char *prefix), unsigned int max); +struct intel_context * +intel_execlists_create_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs **siblings, +unsigned int count); + +struct intel_context * +intel_execlists_clone_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs *src); +#endif /* _INTEL_LRC_H_ */
drivers/gpu/drm/i915/gt/selftest_lrc.c +180 -0
192 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem.h +5 -0
@@ -91,4 +91,9 @@ static inline bool __tasklet_enable(struct tasklet_struct *t) return atomic_dec_and_test(&t->count); } +static inline bool __tasklet_is_scheduled (struct tasklet_struct *t) +{ +return test_bit (TASKLET_STATE_SCHED , &t->state); +} +#endif /* __I915_GEM_H__ */
drivers/gpu/drm/i915/i915_gem_context.c +114 -4
148 lines not on this page · raw message
drivers/gpu/drm/i915/i915_scheduler.c +15 -3
@@ -248,17 +248,26 @@ sched_lock_engine(const struct i915_sched_node *node,struct intel_engine_cs *locked, struct sched_cache *cache) { - struct intel_engine_cs *engine = node_to_request(node)->engine; + const struct i915_request *rq = node_to_request(node); +struct intel_engine_cs *engine;GEM_BUG_ON (!locked); -if (engine != locked) { +/* +* Virtual engines complicate acquiring the engine timeline lock, +* as their rq->engine pointer is not stable until under that +* engine lock. The simple ploy we use is to take the lock then +* check that the rq still belongs to the newly locked engine. +*/ +while (locked != (engine =READ_ONCE (rq->engine))) {spin_unlock (&locked->timeline.lock);memset (cache,0 ,sizeof (*cache));spin_lock (&engine->timeline.lock); + locked = engine; } -return engine; +GEM_BUG_ON (locked != engine); +return locked; } static bool inflight(const struct i915_request *rq,
@@ -371,8 +380,11 @@ static void __i915_schedule(struct i915_request *rq,if (prio <= node->attr.priority ||node_signaled (node))continue ; +GEM_BUG_ON (node_to_request (node)->engine != engine); + node->attr.priority = prio;if (!list_empty (&node->link)) { +GEM_BUG_ON (intel_engine_is_virtual (engine));if (!cache.priolist) cache.priolist = i915_sched_lookup_priolist(engine,
drivers/gpu/drm/i915/i915_timeline_types.h +1 -0
@@ -26,6 +26,7 @@ struct i915_timeline {spinlock_t lock;#define TIMELINE_CLIENT 0/* default subclass */ #define TIMELINE_ENGINE 1 +#define TIMELINE_VIRTUAL 2struct mutex mutex;/* protects the flow of requests */ unsigned int pin_count;
include/uapi/drm/i915_drm.h +39 -0
@@ -137,6 +137,7 @@ struct i915_engine_class_instance {__u16 engine_class;/* see enum drm_i915_gem_engine_class */ __u16 engine_instance;#define I915_ENGINE_CLASS_INVALID_NONE -1 +#define I915_ENGINE_CLASS_INVALID_VIRTUAL -2 };/**
@@ -1607,8 +1608,46 @@ struct drm_i915_gem_context_param_sseu {__u32 rsvd; }; +/* +* i915_context_engines_load_balance: +* +* Enable load balancing across this set of engines. +* +* Into the I915_EXEC_DEFAULT slot [0], a virtual engine is created that when +* used will proxy the execbuffer request onto one of the set of engines +* in such a way as to distribute the load evenly across the set. +* +* The set of engines must be compatible (e.g. the same HW class) as they +* will share the same logical GPU context and ring. +* +* To intermix rendering with the virtual engine and direct rendering onto +* the backing engines (bypassing the load balancing proxy), the context must +* be defined to use a single timeline for all engines. +*/ +struct i915_context_engines_load_balance { +struct i915_user_extension base; + +__u16 engine_index; +__u16 num_siblings; +__u32 flags;/* all undefined flags must be zero */ + +__u64 mbz64[1 ];/* reserved for future use; must be zero */ + +struct i915_engine_class_instance engines[0 ]; +} __attribute__((packed)); + +#define I915_DEFINE_CONTEXT_ENGINES_LOAD_BALANCE (name__,N__ ) struct { \ + struct i915_user_extension base; \ + __u16 engine_index; \ + __u16 num_siblings; \ + __u32 flags; \ + __u64 mbz64[1]; \ + struct i915_engine_class_instance engines[N__]; \ +} __attribute__((packed)) name__ +struct i915_context_param_engines {__u64 extensions;/* linked chain of extension blocks, 0 terminates */ +#define I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE 0/* see i915_context_engines_load_balance */ struct i915_engine_class_instance engines[0 ]; } __attribute__((packed));
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 19/45] drm/i915: Load balancing across a virtual engine
Quoted 1,090 lines · Chris Wilson
Having allowed the user to define a set of engines that they will want to only use, we go one step further and allow them to bind those engines into a single virtual instance. Submitting a batch to the virtual engine will then forward it to any one of the set in a manner as best to distribute load. The virtual engine has a single timeline across all engines (it operates as a single queue), so it is not able to concurrently run batches across multiple engines by itself; that is left up to the user to submit multiple concurrent batches to multiple queues. Multiple users will be load balanced across the system.
The mechanism used for load balancing in this patch is a late greedy balancer. When a request is ready for execution, it is added to each engine's queue, and when an engine is ready for its next request it claims it from the virtual engine. The first engine to do so, wins, i.e. the request is executed at the earliest opportunity (idle moment) in the system.
As not all HW is created equal, the user is still able to skip the virtual engine and execute the batch on a specific engine, all within the same queue. It will then be executed in order on the correct engine, with execution on other virtual engines being moved away due to the load detection.
A couple of areas for potential improvement left!
- The virtual engine always take priority over equal-priority tasks. Mostly broken up by applying
FQ_CODELrules for prioritising new clients, and hopefully the virtual and real engines are not then congested (i.e. all work is via virtual engines, or all work is to the real engine).- We require the breadcrumb irq around every virtual engine request. For normal engines, we eliminate the need for the slow round trip via interrupt by using the submit fence and queueing in order. For virtual engines, we have to allow any job to transfer to a new ring, and cannot coalesce the submissions, so require the completion fence instead, forcing the persistent use of interrupts.
- We only drip feed single requests through each virtual engine and onto the physical engines, even if there was enough work to fill all ELSP, leaving small stalls with an idle CS event at the end of every request. Could we be greedy and fill both slots? Being lazy is virtuous for load distribution on less-than-full workloads though.
Other areas of improvement are more general, such as reducing lock contention, reducing dispatch overhead, looking at direct submission rather than bouncing around tasklets etc.
sseu: Lift the restriction to allow sseu to be reconfigured on virtual engines composed of
RENDER_CLASS(rcs).v2: macroize
check_user_mbz()
v3: Cancel virtual engines on wedging
v4: Commence commenting
v5: Replace 64bsibling_maskwith a list of class:instanceSigned-off-by Chris Wilson <[email protected]>Cc Tvrtko Ursulin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_breadcrumbs.c | 6 +- drivers/gpu/drm/i915/gt/intel_engine_types.h | 8 + drivers/gpu/drm/i915/gt/intel_lrc.c | 656 ++++++++++++++++++- drivers/gpu/drm/i915/gt/intel_lrc.h | 9 + drivers/gpu/drm/i915/gt/selftest_lrc.c | 180 +++++ drivers/gpu/drm/i915/i915_gem.h | 5 + drivers/gpu/drm/i915/i915_gem_context.c | 118 +++- drivers/gpu/drm/i915/i915_scheduler.c | 18 +- drivers/gpu/drm/i915/i915_timeline_types.h | 1 + include/uapi/drm/i915_drm.h | 39 ++ 10 files changed, 1012 insertions(+), 28 deletions(-)drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +5
-1@@ -290,8 +290,12 @@ bool i915_request_enable_breadcrumb(struct i915_request *rq)break ; }list_add (&rq->signal_link, pos); -if (pos == &ce->signals)/* catch transitions from empty list */ +if (pos == &ce->signals) {/* catch transitions from empty */ list_move_tail (&ce->signal_link, &b->signalers); + }else if (ce->engine != rq->engine) {/* virtualised */ +list_move_tail (&ce->signal_link, &b->signalers); +intel_engine_queue_breadcrumbs (rq->engine); + }set_bit (I915_FENCE_FLAG_SIGNAL , &rq->fence.flags);spin_unlock (&b->irq_lock);drivers/gpu/drm/i915/gt/intel_engine_types.h +8
-0@@ -227,6 +227,7 @@ struct intel_engine_execlists {* @queue: queue of requests, in priority lists */ struct rb_root_cached queue; +struct rb_root_cached virtual;/** * @csb_write: control register for Context Switch buffer @@ -445,6 +446,7 @@ struct intel_engine_cs {#define I915_ENGINE_HAS_PREEMPTION BIT(2)#define I915_ENGINE_HAS_SEMAPHORES BIT(3)#define I915_ENGINE_NEEDS_BREADCRUMB_TASKLET BIT(4) +#define I915_ENGINE_IS_VIRTUAL BIT(5)unsigned int flags;/* @@ -534,6 +536,12 @@ intel_engine_needs_breadcrumb_tasklet(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_NEEDS_BREADCRUMB_TASKLET ; } +static inline bool +intel_engine_is_virtual (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_IS_VIRTUAL ; +} +#define instdone_slice_mask (dev_priv__) \ (IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)drivers/gpu/drm/i915/gt/intel_lrc.c +636
-20@@ -136,6 +136,7 @@#include "i915_drv.h" #include "i915_gem_render_state.h" #include "i915_vgpu.h" +#include "intel_engine_pm.h" #include "intel_lrc_reg.h" #include "intel_mocs.h" #include "intel_reset.h" @@ -165,6 +166,41 @@#define ACTIVE_PRIORITY (I915_PRIORITY_NEWCLIENT | I915_PRIORITY_NOSEMAPHORE) +struct virtual_engine { +struct intel_engine_cs base; +struct intel_context context; + +/* +* We allow only a single request through the virtual engine at a time +* (each request in the timeline waits for the completion fence of +* the previous before being submitted). By restricting ourselves to +* only submitting a single request, each request is placed on to a +* physical to maximise load spreading (by virtue of the late greedy +* scheduling -- each real engine takes the next available request +* upon idling). +*/ +struct i915_request *request; + +/* +* We keep a rbtree of available virtual engines inside each physical +* engine, sorted by priority. Here we preallocate the nodes we need +* for the virtual engine, indexed by physical_engine->id. +*/ +struct ve_node { +struct rb_node rb; +int prio; + } nodes[I915_NUM_ENGINES ]; + +/* And finally, which physical engines this virtual engine maps onto. */ +unsigned int num_siblings; +struct intel_engine_cs *siblings[0 ]; +}; + +static struct virtual_engine *to_virtual_engine (struct intel_engine_cs *engine) +{ + return container_of(engine, struct virtual_engine, base); +} +static int execlists_context_deferred_alloc (struct intel_context *ce,struct intel_engine_cs *engine); static void execlists_init_reg_state(u32 *reg_state,@@ -228,7 +264,8 @@ static int queue_prio(const struct intel_engine_execlists *execlists) }static inline bool need_preempt (const struct intel_engine_cs *engine, -const struct i915_request *rq) +const struct i915_request *rq, +struct rb_node *rb) {int last_prio;@@ -263,6 +300,25 @@ static inline bool need_preempt(const struct intel_engine_cs *engine, rq_prio(list_next_entry(rq, link)) > last_prio)return true; +if (rb) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +bool preempt = false; + +if (engine == ve->siblings[0 ]) {/* only preempt one sibling */ +struct i915_request *next; + +rcu_read_lock (); + next =READ_ONCE (ve->request); +if (next) + preempt =rq_prio (next) > last_prio; +rcu_read_unlock (); + } + +if (preempt) +return preempt; + } +/* * If the inflight context did not trigger the preemption, then maybe * it was the set of queued requests? Pick the highest priority in @@ -381,6 +437,8 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)list_for_each_entry_safe_reverse (rq, rn, &engine->timeline.requests, link) { +struct intel_engine_cs *owner; +if (i915_request_completed (rq))break ;@@ -389,16 +447,32 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)GEM_BUG_ON (rq->hw_context->active); -GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID ); -if (rq_prio (rq) != prio) { - prio =rq_prio (rq); - pl =i915_sched_lookup_priolist (engine, prio); - } -GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); +/* +* Push the request back into the queue for later resubmission. +* If this request is not native to this physical engine (i.e. +* it came from a virtual source), push it back onto the virtual +* engine so that it can be moved across onto another physical +* engine as load dictates. +*/ + owner = rq->hw_context->engine; +if (likely (owner == engine)) { +GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID ); +if (rq_prio (rq) != prio) { + prio =rq_prio (rq); + pl =i915_sched_lookup_priolist (engine, prio); + } +GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); -list_add (&rq->sched.link, pl); +list_add (&rq->sched.link, pl); + active = rq; + }else { +if (__i915_request_has_started (rq)) + rq->sched.attr.priority |=ACTIVE_PRIORITY ; - active = rq; + rq->engine = owner; + owner->submit_request (rq); + active =NULL ; + } }/* @@ -418,7 +492,8 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)* in the priority queue, but they will not gain immediate access to * the GPU. */ -if (~prio &ACTIVE_PRIORITY &&__i915_request_has_started (active)) { +if ( ~prio &ACTIVE_PRIORITY && + active &&__i915_request_has_started (active)) { prio |=ACTIVE_PRIORITY ; active->sched.attr.priority = prio; list_move_tail(&active->sched.link,@@ -658,6 +733,72 @@ static void complete_preempt_context(struct intel_engine_execlists *execlists) execlists)); } +static void virtual_update_register_offsets (u32 *regs, +struct intel_engine_cs *engine) +{ +u32 base = engine->mmio_base; + + regs[CTX_CONTEXT_CONTROL ] = +i915_mmio_reg_offset (RING_CONTEXT_CONTROL (base)); + regs[CTX_RING_HEAD ] =i915_mmio_reg_offset (RING_HEAD (base)); + regs[CTX_RING_TAIL ] =i915_mmio_reg_offset (RING_TAIL (base)); + regs[CTX_RING_BUFFER_START ] =i915_mmio_reg_offset (RING_START (base)); + regs[CTX_RING_BUFFER_CONTROL ] =i915_mmio_reg_offset (RING_CTL (base)); + + regs[CTX_BB_HEAD_U ] =i915_mmio_reg_offset (RING_BBADDR_UDW (base)); + regs[CTX_BB_HEAD_L ] =i915_mmio_reg_offset (RING_BBADDR (base)); + regs[CTX_BB_STATE ] =i915_mmio_reg_offset (RING_BBSTATE (base)); + regs[CTX_SECOND_BB_HEAD_U ] = +i915_mmio_reg_offset (RING_SBBADDR_UDW (base)); + regs[CTX_SECOND_BB_HEAD_L ] =i915_mmio_reg_offset (RING_SBBADDR (base)); + regs[CTX_SECOND_BB_STATE ] =i915_mmio_reg_offset (RING_SBBSTATE (base)); + + regs[CTX_CTX_TIMESTAMP ] = +i915_mmio_reg_offset (RING_CTX_TIMESTAMP (base)); + regs[CTX_PDP3_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,3 )); + regs[CTX_PDP3_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,3 )); + regs[CTX_PDP2_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,2 )); + regs[CTX_PDP2_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,2 )); + regs[CTX_PDP1_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,1 )); + regs[CTX_PDP1_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,1 )); + regs[CTX_PDP0_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,0 )); + regs[CTX_PDP0_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,0 )); + +if (engine->class ==RENDER_CLASS ) { + regs[CTX_RCS_INDIRECT_CTX ] = +i915_mmio_reg_offset (RING_INDIRECT_CTX (base)); + regs[CTX_RCS_INDIRECT_CTX_OFFSET ] = +i915_mmio_reg_offset (RING_INDIRECT_CTX_OFFSET (base)); + regs[CTX_BB_PER_CTX_PTR ] = +i915_mmio_reg_offset (RING_BB_PER_CTX_PTR (base)); + + regs[CTX_R_PWR_CLK_STATE ] = +i915_mmio_reg_offset (GEN8_R_PWR_CLK_STATE ); + } +} + +static bool virtual_matches (const struct virtual_engine *ve, +const struct i915_request *rq, +const struct intel_engine_cs *engine) +{ +const struct intel_engine_cs *active; + +/* +* We track when the HW has completed saving the context image +* (i.e. when we have seen the final CS event switching out of +* the context) and must not overwrite the context image before +* then. This restricts us to only using the active engine +* while the previous virtualized request is inflight (so +* we reuse the register offsets). This is a very small +* hystersis on the greedy seelction algorithm. +*/ + active =READ_ONCE (ve->context.active); +if (active && active != engine) +return false; + +return true; +} +static void execlists_dequeue (struct intel_engine_cs *engine) {struct intel_engine_execlists *const execlists = &engine->execlists;@@ -690,6 +831,26 @@ static void execlists_dequeue(struct intel_engine_cs *engine)* and context switches) submission. */ +for (rb =rb_first_cached (&execlists->virtual); rb; ) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +struct i915_request *rq =READ_ONCE (ve->request); + +if (!rq) {/* lazily cleanup after another engine handled rq */ +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + rb =rb_first_cached (&execlists->virtual); +continue ; + } + +if (!virtual_matches (ve, rq, engine)) { + rb =rb_next (rb); +continue ; + } + +break ; + } +if (last) {/* * Don't resubmit or switch until all outstanding @@ -711,7 +872,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)if (!execlists_is_active (execlists,EXECLISTS_ACTIVE_HWACK ))return ; -if (need_preempt (engine, last)) { +if (need_preempt (engine, last, rb)) {inject_preempt_context (engine);return ; }@@ -751,6 +912,89 @@ static void execlists_dequeue(struct intel_engine_cs *engine) last->tail = last->wa_tail; } +while (rb) {/* XXX virtual is always taking precedence */ +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +struct i915_request *rq; + +spin_lock (&ve->base.timeline.lock); + + rq = ve->request; +if (unlikely (!rq)) {/* lost the race to a sibling */ +spin_unlock (&ve->base.timeline.lock); +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + rb =rb_first_cached (&execlists->virtual); +continue ; + } + +GEM_BUG_ON (rq != ve->request); +GEM_BUG_ON (rq->engine != &ve->base); +GEM_BUG_ON (rq->hw_context != &ve->context); + +if (rq_prio (rq) >=queue_prio (execlists)) { +if (!virtual_matches (ve, rq, engine)) { +spin_unlock (&ve->base.timeline.lock); + rb =rb_next (rb); +continue ; + } + +if (last && !can_merge_rq (last, rq)) { +spin_unlock (&ve->base.timeline.lock); +return ;/* leave this rq for another engine */ + } + +GEM_TRACE ("%s: virtual rq=%llx:%lld%s, new engine? %s\n" , + engine->name, + rq->fence.context, + rq->fence.seqno, +i915_request_completed (rq) ?"!" : +i915_request_started (rq) ?"*" : +"" , +yesno (engine != ve->siblings[0 ])); + + ve->request =NULL ; + ve->base.execlists.queue_priority_hint =INT_MIN ; +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + + rq->engine = engine; + +if (engine != ve->siblings[0 ]) { +u32 *regs = ve->context.lrc_reg_state; +unsigned int n; + +GEM_BUG_ON (READ_ONCE (ve->context.active)); +virtual_update_register_offsets (regs, engine); + +/* +* Move the bound engine to the top of the list +* for future execution. We then kick this +* tasklet first before checking others, so that +* we preferentially reuse this set of bound +* registers. +*/ +for (n =1 ; n < ve->num_siblings; n++) { +if (ve->siblings[n] == engine) { +swap (ve->siblings[n], + ve->siblings[0 ]); +break ; + } + } + +GEM_BUG_ON (ve->siblings[0 ] != engine); + } + +__i915_request_submit (rq); +trace_i915_request_in (rq,port_index (port, execlists)); + submit = true; + last = rq; + } + +spin_unlock (&ve->base.timeline.lock); +break ; + } +while ((rb =rb_first_cached (&execlists->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;@@ -1874,6 +2118,25 @@ static void reset_csb_pointers(struct intel_engine_execlists *execlists) &execlists->csb_status[reset_value]); } +static struct i915_request *active_request (struct i915_request *rq) +{ +const struct list_head *const list = &rq->engine->timeline.requests; +const struct intel_context *const context = rq->hw_context; +struct i915_request *active =NULL ; + +list_for_each_entry_from_reverse (rq, list, link) { +if (i915_request_completed (rq)) +break ; + +if (rq->hw_context != context) +break ; + + active = rq; + } + +return active; +} +static void __execlists_reset (struct intel_engine_cs *engine,bool stalled) {struct intel_engine_execlists *const execlists = &engine->execlists;@@ -1894,7 +2157,8 @@ static void __execlists_reset(struct intel_engine_cs *engine, bool stalled)if (!port_isset (execlists->port)) goto out_clear; - ce =port_request (execlists->port)->hw_context; + rq =port_request (execlists->port); + ce = rq->hw_context;/* * Catch up with any missed context-switch interrupts. @@ -1907,16 +2171,10 @@ static void __execlists_reset(struct intel_engine_cs *engine, bool stalled)*/ execlists_cancel_port_requests (execlists); -/* Push back any incomplete requests for replay after the reset. */ - rq =__unwind_incomplete_requests (engine); + rq =active_request (rq);if (!rq) goto out_replay; -if (rq->hw_context != ce) {/* caught just before a CS event */ - rq =NULL ; - goto out_replay; - } -/* * If this request hasn't started yet, e.g. it is waiting on a * semaphore, we need to avoid skipping the request or else we @@ -1963,13 +2221,16 @@ static void __execlists_reset(struct intel_engine_cs *engine, bool stalled) }execlists_init_reg_state (regs, ce, engine, ce->ring); -/* Rerun the request; its payload has been neutered (if guilty). */ out_replay: +/* Rerun the request; its payload has been neutered (if guilty). */ ce->ring->head = rq ?intel_ring_wrap (ce->ring, rq->head) : ce->ring->tail;intel_ring_update_space (ce->ring);__execlists_update_reg_state (ce, engine); +/* Push back any incomplete requests for replay after the reset. */ +__unwind_incomplete_requests (engine); + out_clear:execlists_clear_all_active (execlists); }@@ -2043,6 +2304,26 @@ static void execlists_cancel_requests(struct intel_engine_cs *engine)i915_priolist_free (p); } +/* Cancel all attached virtual engines */ +while ((rb =rb_first_cached (&execlists->virtual))) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); + +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + +spin_lock (&ve->base.timeline.lock); +if (ve->request) { + ve->request->engine = engine; +__i915_request_submit (ve->request); +dma_fence_set_error (&ve->request->fence, -EIO ); +i915_request_mark_complete (ve->request); + ve->base.execlists.queue_priority_hint =INT_MIN ; + ve->request =NULL ; + } +spin_unlock (&ve->base.timeline.lock); + } +/* Remaining _unready_ requests will be nop'ed when submitted */ execlists->queue_priority_hint =INT_MIN ;@@ -2760,6 +3041,318 @@ static int execlists_context_deferred_alloc(struct intel_context *ce,return ret; } +static void virtual_context_destroy (struct kref *kref) +{ +struct virtual_engine *ve = +container_of (kref,typeof (*ve), context.ref); +unsigned int n; + +GEM_BUG_ON (ve->request); +GEM_BUG_ON (ve->context.active); + +for (n =0 ; n < ve->num_siblings; n++) { +struct intel_engine_cs *sibling = ve->siblings[n]; +struct rb_node *node = &ve->nodes[sibling->id].rb; + +if (RB_EMPTY_NODE (node)) +continue ; + +spin_lock_irq (&sibling->timeline.lock); + +if (!RB_EMPTY_NODE (node)) +rb_erase_cached (node, &sibling->execlists.virtual); + +spin_unlock_irq (&sibling->timeline.lock); + } +GEM_BUG_ON (__tasklet_is_scheduled (&ve->base.execlists.tasklet)); + +if (ve->context.state) +__execlists_context_fini (&ve->context); + +i915_timeline_fini (&ve->base.timeline); +kfree (ve); +} + +static void virtual_engine_initial_hint (struct virtual_engine *ve) +{ +int swp; + +/* +* Pick a random sibling on starting to help spread the load around. +* +* New contexts are typically created with exactly the same order +* of siblings, and often started in batches. Due to the way we iterate +* the array of sibling when submitting requests, sibling[0] is +* prioritised for dequeuing. If we make sure that sibling[0] is fairly +* randomised across the system, we also help spread the load by the +* first engine we inspect being different each time. +* +* NB This does not force us to execute on this engine, it will just +* typically be the first we inspect for submission. +*/ + swp =prandom_u32_max (ve->num_siblings); +if (!swp) +return ; + +swap (ve->siblings[swp], ve->siblings[0 ]); +virtual_update_register_offsets (ve->context.lrc_reg_state, + ve->siblings[0 ]); +} + +static int virtual_context_pin (struct intel_context *ce) +{ +struct virtual_engine *ve =container_of (ce,typeof (*ve), context); +int err; + +/* Note: we must use a real engine class for setting up reg state */ + err =__execlists_context_pin (ce, ve->siblings[0 ]); +if (err) +return err; + +virtual_engine_initial_hint (ve); +return 0 ; +} + +static void virtual_context_enter (struct intel_context *ce) +{ +struct virtual_engine *ve =container_of (ce,typeof (*ve), context); +unsigned int n; + +for (n =0 ; n < ve->num_siblings; n++) +intel_engine_pm_get (ve->siblings[n]); +} + +static void virtual_context_exit (struct intel_context *ce) +{ +struct virtual_engine *ve =container_of (ce,typeof (*ve), context); +unsigned int n; + +for (n =0 ; n < ve->num_siblings; n++) +intel_engine_pm_put (ve->siblings[n]); +} + +static const struct intel_context_ops virtual_context_ops = { + .pin = virtual_context_pin, + .unpin = execlists_context_unpin, + + .enter = virtual_context_enter, + .exit = virtual_context_exit, + + .destroy = virtual_context_destroy, +}; + +static void virtual_submission_tasklet (unsigned long data) +{ +struct virtual_engine *const ve = (struct virtual_engine *)data; +const int prio = ve->base.execlists.queue_priority_hint; +unsigned int n; + +local_irq_disable (); +for (n =0 ;READ_ONCE (ve->request) && n < ve->num_siblings; n++) { +struct intel_engine_cs *sibling = ve->siblings[n]; +struct ve_node *const node = &ve->nodes[sibling->id]; +struct rb_node **parent, *rb; +bool first; + +spin_lock (&sibling->timeline.lock); + +if (!RB_EMPTY_NODE (&node->rb)) { +/* +* Cheat and avoid rebalancing the tree if we can +* reuse this node in situ. +*/ + first =rb_first_cached (&sibling->execlists.virtual) == + &node->rb; +if (prio == node->prio || (prio > node->prio && first)) + goto submit_engine; + +rb_erase_cached (&node->rb, &sibling->execlists.virtual); + } + + rb =NULL ; + first = true; + parent = &sibling->execlists.virtual.rb_root.rb_node; +while (*parent) { +struct ve_node *other; + + rb = *parent; + other =rb_entry (rb,typeof (*other), rb); +if (prio > other->prio) { + parent = &rb->rb_left; + }else { + parent = &rb->rb_right; + first = false; + } + } + +rb_link_node (&node->rb, rb, parent); +rb_insert_color_cached (&node->rb, + &sibling->execlists.virtual, + first); + +submit_engine: +GEM_BUG_ON (RB_EMPTY_NODE (&node->rb)); + node->prio = prio; +if (first && prio > sibling->execlists.queue_priority_hint) { + sibling->execlists.queue_priority_hint = prio; +tasklet_hi_schedule (&sibling->execlists.tasklet); + } + +spin_unlock (&sibling->timeline.lock); + } +local_irq_enable (); +} + +static void virtual_submit_request (struct i915_request *rq) +{ +struct virtual_engine *ve =to_virtual_engine (rq->engine); + +GEM_TRACE ("%s: rq=%llx:%lld\n" , + ve->base.name, + rq->fence.context, + rq->fence.seqno); + +GEM_BUG_ON (ve->base.submit_request != virtual_submit_request); + +GEM_BUG_ON (ve->request); + ve->base.execlists.queue_priority_hint =rq_prio (rq); +WRITE_ONCE (ve->request, rq); + +tasklet_schedule (&ve->base.execlists.tasklet); +} + +struct intel_context * +intel_execlists_create_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs **siblings, +unsigned int count) +{ +struct virtual_engine *ve; +unsigned int n; +int err; + +if (count ==0 ) +return ERR_PTR (-EINVAL ); + +if (count ==1 ) +return intel_context_create (ctx, siblings[0 ]); + + ve =kzalloc (struct_size (ve, siblings, count),GFP_KERNEL ); +if (!ve) +return ERR_PTR (-ENOMEM ); + + ve->base.i915 = ctx->i915; + ve->base.id =-1 ; + ve->base.class =OTHER_CLASS ; + ve->base.uabi_class =I915_ENGINE_CLASS_INVALID ; + ve->base.instance =I915_ENGINE_CLASS_INVALID_VIRTUAL ; + ve->base.flags =I915_ENGINE_IS_VIRTUAL ; + +snprintf (ve->base.name,sizeof (ve->base.name),"virtual" ); + + err =i915_timeline_init (ctx->i915, &ve->base.timeline,NULL ); +if (err) + goto err_put; +i915_timeline_set_subclass (&ve->base.timeline,TIMELINE_VIRTUAL ); + +intel_engine_init_execlists (&ve->base); + + ve->base.cops = &virtual_context_ops; + ve->base.request_alloc = execlists_request_alloc; + + ve->base.schedule = i915_schedule; + ve->base.submit_request = virtual_submit_request; + + ve->base.execlists.queue_priority_hint =INT_MIN ; +tasklet_init (&ve->base.execlists.tasklet, + virtual_submission_tasklet, + (unsigned long )ve); + +intel_context_init (&ve->context, ctx, &ve->base); + +for (n =0 ; n < count; n++) { +struct intel_engine_cs *sibling = siblings[n]; + +GEM_BUG_ON (!is_power_of_2 (sibling->mask)); +if (sibling->mask & ve->base.mask) { +DRM_DEBUG ("duplicate %s entry in load balancer\n" , + sibling->name); + err = -EINVAL ; + goto err_put; + } + +/* +* The virtual engine implementation is tightly coupled to +* the execlists backend -- we push out request directly +* into a tree inside each physical engine. We could support +* layering if we handle cloning of the requests and +* submitting a copy into each backend. +*/ +if (sibling->execlists.tasklet.func != + execlists_submission_tasklet) { + err = -ENODEV ; + goto err_put; + } + +GEM_BUG_ON (RB_EMPTY_NODE (&ve->nodes[sibling->id].rb)); +RB_CLEAR_NODE (&ve->nodes[sibling->id].rb); + + ve->siblings[ve->num_siblings++] = sibling; + ve->base.mask |= sibling->mask; + +/* +* All physical engines must be compatible for their emission +* functions (as we build the instructions during request +* construction and do not alter them before submission +* on the physical engine). We use the engine class as a guide +* here, although that could be refined. +*/ +if (ve->base.class !=OTHER_CLASS ) { +if (ve->base.class != sibling->class) { +DRM_DEBUG ("invalid mixing of engine class, sibling %d, already %d\n" , + sibling->class, ve->base.class); + err = -EINVAL ; + goto err_put; + } +continue ; + } + + ve->base.class = sibling->class; + ve->base.uabi_class = sibling->uabi_class; +snprintf (ve->base.name,sizeof (ve->base.name), +"v%dx%d" , ve->base.class, count); + ve->base.context_size = sibling->context_size; + + ve->base.emit_bb_start = sibling->emit_bb_start; + ve->base.emit_flush = sibling->emit_flush; + ve->base.emit_init_breadcrumb = sibling->emit_init_breadcrumb; + ve->base.emit_fini_breadcrumb = sibling->emit_fini_breadcrumb; + ve->base.emit_fini_breadcrumb_dw = + sibling->emit_fini_breadcrumb_dw; + } + +return &ve->context; + +err_put: +intel_context_put (&ve->context); +return ERR_PTR (err); +} + +struct intel_context * +intel_execlists_clone_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs *src) +{ +struct virtual_engine *se =to_virtual_engine (src); +struct intel_context *dst; + + dst =intel_execlists_create_virtual (ctx, + se->siblings, + se->num_siblings); +if (IS_ERR (dst)) +return dst; + +return dst; +} + void intel_execlists_show_requests(struct intel_engine_cs *engine, struct drm_printer *m, void (*show_request)(struct drm_printer *m,@@ -2817,6 +3410,29 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,show_request (m, last,"\t\tQ " ); } + last =NULL ; + count =0 ; +for (rb =rb_first_cached (&execlists->virtual); rb; rb =rb_next (rb)) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +struct i915_request *rq =READ_ONCE (ve->request); + +if (rq) { +if (count++ < max -1 ) +show_request (m, rq,"\t\tV " ); +else + last = rq; + } + } +if (last) { +if (count > max) { +drm_printf (m, +"\t\t...skipping %d virtual requests...\n" , + count - max); + } +show_request (m, last,"\t\tV " ); + } +spin_unlock_irqrestore (&engine->timeline.lock, flags); }drivers/gpu/drm/i915/gt/intel_lrc.h +9
-0@@ -114,4 +114,13 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine, const char *prefix), unsigned int max); +struct intel_context * +intel_execlists_create_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs **siblings, +unsigned int count); + +struct intel_context * +intel_execlists_clone_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs *src); +#endif /* _INTEL_LRC_H_ */ drivers/gpu/drm/i915/gt/selftest_lrc.c +146
-0@@ -1301,6 +1301,185 @@ static int live_preempt_smoke(void *arg)return err; } +static int nop_virtual_engine (struct drm_i915_private *i915, +struct intel_engine_cs **siblings, +unsigned int nsibling, +unsigned int nctx, +unsigned int flags) +#define CHAIN BIT(0) +{ +IGT_TIMEOUT (end_time); +struct i915_request *request[16 ]; +struct i915_gem_context *ctx[16 ]; +struct intel_context *ve[16 ]; +unsigned long n, prime, nc; +struct igt_live_test t; +ktime_t times[2 ] = {}; +int err; + +GEM_BUG_ON (!nctx || nctx >ARRAY_SIZE (ctx)); + +for (n =0 ; n < nctx; n++) { + ctx[n] =kernel_context (i915); +if (!ctx[n]) { + err = -ENOMEM ; + nctx = n; + goto out; + } + + ve[n] =intel_execlists_create_virtual (ctx[n], + siblings, nsibling); +if (IS_ERR (ve[n])) { +kernel_context_close (ctx[n]); + err =PTR_ERR (ve[n]); + nctx = n; + goto out; + } + + err =intel_context_pin (ve[n]); +if (err) { +intel_context_put (ve[n]); +kernel_context_close (ctx[n]); + nctx = n; + goto out; + } + } + + err =igt_live_test_begin (&t, i915, __func__, ve[0 ]->engine->name); +if (err) + goto out; + +for_each_prime_number_from (prime,1 ,8192 ) { + times[1 ] =ktime_get_raw (); + +if (flags &CHAIN ) { +for (nc =0 ; nc < nctx; nc++) { +for (n =0 ; n < prime; n++) { + request[nc] = +i915_request_create (ve[nc]); +if (IS_ERR (request[nc])) { + err =PTR_ERR (request[nc]); + goto out; + } + +i915_request_add (request[nc]); + } + } + }else { +for (n =0 ; n < prime; n++) { +for (nc =0 ; nc < nctx; nc++) { + request[nc] = +i915_request_create (ve[nc]); +if (IS_ERR (request[nc])) { + err =PTR_ERR (request[nc]); + goto out; + } + +i915_request_add (request[nc]); + } + } + } + +for (nc =0 ; nc < nctx; nc++) { +if (i915_request_wait (request[nc], +I915_WAIT_LOCKED , +HZ /10 ) <0 ) { +pr_err ("%s(%s): wait for %llx:%lld timed out\n" , + __func__, ve[0 ]->engine->name, + request[nc]->fence.context, + request[nc]->fence.seqno); + +GEM_TRACE ("%s(%s) failed at request %llx:%lld\n" , + __func__, ve[0 ]->engine->name, + request[nc]->fence.context, + request[nc]->fence.seqno); +GEM_TRACE_DUMP (); +i915_gem_set_wedged (i915); +break ; + } + } + + times[1 ] =ktime_sub (ktime_get_raw (), times[1 ]); +if (prime ==1 ) + times[0 ] = times[1 ]; + +if (__igt_timeout (end_time,NULL )) +break ; + } + + err =igt_live_test_end (&t); +if (err) + goto out; + +pr_info ("Requestx%d latencies on %s: 1 = %lluns, %lu = %lluns\n" , + nctx, ve[0 ]->engine->name,ktime_to_ns (times[0 ]), + prime,div64_u64 (ktime_to_ns (times[1 ]), prime)); + +out: +if (igt_flush_test (i915,I915_WAIT_LOCKED )) + err = -EIO ; + +for (nc =0 ; nc < nctx; nc++) { +intel_context_unpin (ve[nc]); +intel_context_put (ve[nc]); +kernel_context_close (ctx[nc]); + } +return err; +} + +static int live_virtual_engine (void *arg) +{ +struct drm_i915_private *i915 = arg; +struct intel_engine_cs *siblings[MAX_ENGINE_INSTANCE +1 ]; +struct intel_engine_cs *engine; +enum intel_engine_id id; +unsigned int class, inst; +int err = -ENODEV ; + +if (USES_GUC_SUBMISSION (i915)) +return 0 ; + +mutex_lock (&i915->drm.struct_mutex); + +for_each_engine (engine, i915, id) { + err =nop_virtual_engine (i915, &engine,1 ,1 ,0 ); +if (err) { +pr_err ("Failed to wrap engine %s: err=%d\n" , + engine->name, err); + goto out_unlock;
drivers/gpu/drm/i915/gt/selftest_lrc.c static int live_preempt_smoke(void *arg) · line 1459
Quoted 10 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +10
-0+ } + } + +for (class =0 ; class <=MAX_ENGINE_CLASS ; class++) { +int nsibling, n; + + nsibling =0 ; +for (inst =0 ; inst <=MAX_ENGINE_INSTANCE ; inst++) { +if (!i915->engine_class[class][inst]) +break ;
Continue I think, to be able to use vcs0 + vcs2 on Icelake.
drivers/gpu/drm/i915/gt/selftest_lrc.c static int live_preempt_smoke(void *arg) · line 1464
Quoted 5 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +5
-0+ + siblings[nsibling++] = i915->engine_class[class][inst]; + } +if (nsibling <2 ) +continue ;
Could test single, no?
Quoted 287 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +19
-0+ +for (n =1 ; n <= nsibling +1 ; n++) { + err =nop_virtual_engine (i915, siblings, nsibling, + n,0 ); +if (err) + goto out_unlock; + } + + err =nop_virtual_engine (i915, siblings, nsibling, n,CHAIN ); +if (err) + goto out_unlock; + } + +out_unlock: +mutex_unlock (&i915->drm.struct_mutex); +return err; +} +int intel_execlists_live_selftests (struct drm_i915_private *i915) {static const struct i915_subtest tests[] = {@@ -1313,6 +1492,7 @@ int intel_execlists_live_selftests(struct drm_i915_private *i915)SUBTEST (live_chain_preempt),SUBTEST (live_preempt_hang),SUBTEST (live_preempt_smoke), + SUBTEST(live_virtual_engine), };if (!HAS_EXECLISTS (i915))drivers/gpu/drm/i915/i915_gem.h +5
-0@@ -91,4 +91,9 @@ static inline bool __tasklet_enable(struct tasklet_struct *t) return atomic_dec_and_test(&t->count); } +static inline bool __tasklet_is_scheduled (struct tasklet_struct *t) +{ +return test_bit (TASKLET_STATE_SCHED , &t->state); +} +#endif /* __I915_GEM_H__ */ drivers/gpu/drm/i915/i915_gem_context.c +114
-4@@ -86,6 +86,7 @@*/ #include <linux/log2.h> +#include <linux/nospec.h> #include <drm/i915_drm.h> @@ -1209,7 +1210,6 @@ __intel_context_reconfigure_sseu(struct intel_context *ce,int ret;GEM_BUG_ON (INTEL_GEN (ce->gem_context->i915) <8 ); -GEM_BUG_ON (ce->engine->id !=RCS0 ); ret =intel_context_lock_pinned (ce);if (ret)@@ -1397,7 +1397,102 @@ struct set_engines {struct i915_gem_engines *engines; }; +static int +set_engines__load_balance (struct i915_user_extension __user *base,void *data) +{ +struct i915_context_engines_load_balance __user *ext = +container_of_user (base,typeof (*ext), base); +const struct set_engines *set = data; +struct intel_engine_cs *stack[16 ]; +struct intel_engine_cs **siblings; +struct intel_context *ce; +u16 num_siblings, idx; +unsigned int n; +int err; + +if (!HAS_EXECLISTS (set->ctx->i915)) +return -ENODEV ; + +if (USES_GUC_SUBMISSION (set->ctx->i915)) +return -ENODEV ;/* not implement yet */ + +if (get_user (idx, &ext->engine_index)) +return -EFAULT ; + +if (idx >= set->engines->num_engines) { +DRM_DEBUG ("Invalid placement value, %d >= %d\n" , + idx, set->engines->num_engines); +return -EINVAL ; + } + + idx =array_index_nospec (idx, set->engines->num_engines); +if (set->engines->engines[idx]) { +DRM_DEBUG ("Invalid placement[%d], already occupied\n" , idx); +return -EEXIST ; + } + +if (get_user (num_siblings, &ext->num_siblings)) +return -EFAULT ; + + err =check_user_mbz (&ext->flags); +if (err) +return err; + +for (n =0 ; n <ARRAY_SIZE (ext->mbz64); n++) { + err =check_user_mbz (&ext->mbz64[n]); +if (err) +return err; + } + + siblings = stack; +if (num_siblings >ARRAY_SIZE (stack)) { + siblings =kmalloc_array (num_siblings, +sizeof (*siblings), +GFP_KERNEL ); +if (!siblings) +return -ENOMEM ; + } + +for (n =0 ; n < num_siblings; n++) { +struct i915_engine_class_instance ci; + +if (copy_from_user (&ci, &ext->engines[n],sizeof (ci))) { + err = -EFAULT ; + goto out_siblings; + } + + siblings[n] =intel_engine_lookup_user (set->ctx->i915, + ci.engine_class, + ci.engine_instance); +if (!siblings[n]) { +DRM_DEBUG ("Invalid sibling[%d]: { class:%d, inst:%d }\n" , + n, ci.engine_class, ci.engine_instance); + err = -EINVAL ; + goto out_siblings; + } + } + + ce =intel_execlists_create_virtual (set->ctx, siblings, n); +if (IS_ERR (ce)) { + err =PTR_ERR (ce); + goto out_siblings; + } + +if (cmpxchg (&set->engines->engines[idx],NULL , ce)) { +intel_context_put (ce); + err = -EEXIST ; + goto out_siblings; + } + +out_siblings: +if (siblings != stack) +kfree (siblings); + +return err; +} +static const i915_user_extension_fn set_engines__extensions[] = { + [I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE ] = set_engines__load_balance, }; static int@@ -1696,14 +1791,29 @@ static int clone_engines(struct i915_gem_context *dst, clone->i915 = dst->i915;for (n =0 ; n < e->num_engines; n++) { +struct intel_engine_cs *engine; +if (!e->engines[n]) { clone->engines[n] =NULL ;continue ; } + engine = e->engines[n]->engine; - clone->engines[n] = -intel_context_create (dst, e->engines[n]->engine); -if (!clone->engines[n]) { +/* +* Virtual engines are singletons; they can only exist +* inside a single context, because they embed their +* HW context... As each virtual context implies a single +* timeline (each engine can only dequeue a single request +* at any time), it would be surprising for two contexts +* to use the same engine. So let's create a copy of +* the virtual engine instead. +*/ +if (intel_engine_is_virtual (engine)) + clone->engines[n] = +intel_execlists_clone_virtual (dst, engine); +else + clone->engines[n] =intel_context_create (dst, engine); +if (IS_ERR_OR_NULL (clone->engines[n])) {__free_engines (clone, n); goto err_unlock; }drivers/gpu/drm/i915/i915_scheduler.c +15
-3@@ -248,17 +248,26 @@ sched_lock_engine(const struct i915_sched_node *node,struct intel_engine_cs *locked, struct sched_cache *cache) { - struct intel_engine_cs *engine = node_to_request(node)->engine; + const struct i915_request *rq = node_to_request(node); +struct intel_engine_cs *engine;GEM_BUG_ON (!locked); -if (engine != locked) { +/* +* Virtual engines complicate acquiring the engine timeline lock, +* as their rq->engine pointer is not stable until under that +* engine lock. The simple ploy we use is to take the lock then +* check that the rq still belongs to the newly locked engine. +*/ +while (locked != (engine =READ_ONCE (rq->engine))) {spin_unlock (&locked->timeline.lock);memset (cache,0 ,sizeof (*cache));spin_lock (&engine->timeline.lock); + locked = engine; } -return engine; +GEM_BUG_ON (locked != engine); +return locked; } static bool inflight(const struct i915_request *rq,@@ -371,8 +380,11 @@ static void __i915_schedule(struct i915_request *rq,if (prio <= node->attr.priority ||node_signaled (node))continue ; +GEM_BUG_ON (node_to_request (node)->engine != engine); + node->attr.priority = prio;if (!list_empty (&node->link)) { +GEM_BUG_ON (intel_engine_is_virtual (engine));if (!cache.priolist) cache.priolist = i915_sched_lookup_priolist(engine,drivers/gpu/drm/i915/i915_timeline_types.h +1
-0@@ -26,6 +26,7 @@ struct i915_timeline {spinlock_t lock;#define TIMELINE_CLIENT 0/* default subclass */ #define TIMELINE_ENGINE 1 +#define TIMELINE_VIRTUAL 2struct mutex mutex;/* protects the flow of requests */ unsigned int pin_count;include/uapi/drm/i915_drm.h +15
-0@@ -137,6 +137,7 @@ struct i915_engine_class_instance {__u16 engine_class;/* see enum drm_i915_gem_engine_class */ __u16 engine_instance;#define I915_ENGINE_CLASS_INVALID_NONE -1 +#define I915_ENGINE_CLASS_INVALID_VIRTUAL -2 };/** @@ -1607,8 +1608,46 @@ struct drm_i915_gem_context_param_sseu {__u32 rsvd; }; +/* +* i915_context_engines_load_balance: +* +* Enable load balancing across this set of engines. +* +* Into the I915_EXEC_DEFAULT slot [0], a virtual engine is created that when +* used will proxy the execbuffer request onto one of the set of engines +* in such a way as to distribute the load evenly across the set. +* +* The set of engines must be compatible (e.g. the same HW class) as they +* will share the same logical GPU context and ring. +* +* To intermix rendering with the virtual engine and direct rendering onto +* the backing engines (bypassing the load balancing proxy), the context must
include/uapi/drm/i915_drm.h struct drm_i915_gem_context_param_sseu { · line 1634
Quoted 10 lines
include/uapi/drm/i915_drm.h +10
-0+* be defined to use a single timeline for all engines. +*/ +struct i915_context_engines_load_balance { +struct i915_user_extension base; + +__u16 engine_index; +__u16 num_siblings; +__u32 flags;/* all undefined flags must be zero */ + +__u64 mbz64[1 ];/* reserved for future use; must be zero */
Why array of one was a serious question?
Quoted 10 lines
include/uapi/drm/i915_drm.h +9
-0+ +struct i915_engine_class_instance engines[0 ]; +} __attribute__((packed)); + +#define I915_DEFINE_CONTEXT_ENGINES_LOAD_BALANCE (name__,N__ ) struct { \ + struct i915_user_extension base; \ + __u16 engine_index; \ + __u16 num_siblings; \ + __u32 flags; \
include/uapi/drm/i915_drm.h struct drm_i915_gem_context_param_sseu { · line 1653
Quoted 10 lines
include/uapi/drm/i915_drm.h +5
-0+__u64 mbz64[1 ]; \ +struct i915_engine_class_instance engines[N__ ]; \ +} __attribute__((packed))name__ + struct i915_context_param_engines {__u64 extensions;/* linked chain of extension blocks, 0 terminates */ +#define I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE 0/* see i915_context_engines_load_balance */ struct i915_engine_class_instance engines[0 ]; } __attribute__((packed));
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 19/45] drm/i915: Load balancing across a virtual engine
Quoting Tvrtko Ursulin (2019-04-25 13:14:00)
Quoted 1,404 lines · Chris Wilson
Quoted 1,090 lines
Having allowed the user to define a set of engines that they will want to only use, we go one step further and allow them to bind those engines into a single virtual instance. Submitting a batch to the virtual engine will then forward it to any one of the set in a manner as best to distribute load. The virtual engine has a single timeline across all engines (it operates as a single queue), so it is not able to concurrently run batches across multiple engines by itself; that is left up to the user to submit multiple concurrent batches to multiple queues. Multiple users will be load balanced across the system.
The mechanism used for load balancing in this patch is a late greedy balancer. When a request is ready for execution, it is added to each engine's queue, and when an engine is ready for its next request it claims it from the virtual engine. The first engine to do so, wins, i.e. the request is executed at the earliest opportunity (idle moment) in the system.
As not all HW is created equal, the user is still able to skip the virtual engine and execute the batch on a specific engine, all within the same queue. It will then be executed in order on the correct engine, with execution on other virtual engines being moved away due to the load detection.
A couple of areas for potential improvement left!
- The virtual engine always take priority over equal-priority tasks. Mostly broken up by applying
FQ_CODELrules for prioritising new clients, and hopefully the virtual and real engines are not then congested (i.e. all work is via virtual engines, or all work is to the real engine).- We require the breadcrumb irq around every virtual engine request. For normal engines, we eliminate the need for the slow round trip via interrupt by using the submit fence and queueing in order. For virtual engines, we have to allow any job to transfer to a new ring, and cannot coalesce the submissions, so require the completion fence instead, forcing the persistent use of interrupts.
- We only drip feed single requests through each virtual engine and onto the physical engines, even if there was enough work to fill all ELSP, leaving small stalls with an idle CS event at the end of every request. Could we be greedy and fill both slots? Being lazy is virtuous for load distribution on less-than-full workloads though.
Other areas of improvement are more general, such as reducing lock contention, reducing dispatch overhead, looking at direct submission rather than bouncing around tasklets etc.
sseu: Lift the restriction to allow sseu to be reconfigured on virtual engines composed of
RENDER_CLASS(rcs).v2: macroize
check_user_mbz()
v3: Cancel virtual engines on wedging
v4: Commence commenting
v5: Replace 64bsibling_maskwith a list of class:instanceSigned-off-by Chris Wilson <[email protected]>Cc Tvrtko Ursulin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_breadcrumbs.c | 6 +- drivers/gpu/drm/i915/gt/intel_engine_types.h | 8 + drivers/gpu/drm/i915/gt/intel_lrc.c | 656 ++++++++++++++++++- drivers/gpu/drm/i915/gt/intel_lrc.h | 9 + drivers/gpu/drm/i915/gt/selftest_lrc.c | 180 +++++ drivers/gpu/drm/i915/i915_gem.h | 5 + drivers/gpu/drm/i915/i915_gem_context.c | 118 +++- drivers/gpu/drm/i915/i915_scheduler.c | 18 +- drivers/gpu/drm/i915/i915_timeline_types.h | 1 + include/uapi/drm/i915_drm.h | 39 ++ 10 files changed, 1012 insertions(+), 28 deletions(-)drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +5
-1@@ -290,8 +290,12 @@ bool i915_request_enable_breadcrumb(struct i915_request *rq)break ; }list_add (&rq->signal_link, pos); -if (pos == &ce->signals)/* catch transitions from empty list */ +if (pos == &ce->signals) {/* catch transitions from empty */ list_move_tail (&ce->signal_link, &b->signalers); + }else if (ce->engine != rq->engine) {/* virtualised */ +list_move_tail (&ce->signal_link, &b->signalers); +intel_engine_queue_breadcrumbs (rq->engine); + }set_bit (I915_FENCE_FLAG_SIGNAL , &rq->fence.flags);spin_unlock (&b->irq_lock);drivers/gpu/drm/i915/gt/intel_engine_types.h +8
-0@@ -227,6 +227,7 @@ struct intel_engine_execlists {* @queue: queue of requests, in priority lists */ struct rb_root_cached queue; +struct rb_root_cached virtual;/** * @csb_write: control register for Context Switch buffer @@ -445,6 +446,7 @@ struct intel_engine_cs {#define I915_ENGINE_HAS_PREEMPTION BIT(2)#define I915_ENGINE_HAS_SEMAPHORES BIT(3)#define I915_ENGINE_NEEDS_BREADCRUMB_TASKLET BIT(4) +#define I915_ENGINE_IS_VIRTUAL BIT(5)unsigned int flags;/* @@ -534,6 +536,12 @@ intel_engine_needs_breadcrumb_tasklet(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_NEEDS_BREADCRUMB_TASKLET ; } +static inline bool +intel_engine_is_virtual (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_IS_VIRTUAL ; +} +#define instdone_slice_mask (dev_priv__) \ (IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)drivers/gpu/drm/i915/gt/intel_lrc.c +636
-20@@ -136,6 +136,7 @@#include "i915_drv.h" #include "i915_gem_render_state.h" #include "i915_vgpu.h" +#include "intel_engine_pm.h" #include "intel_lrc_reg.h" #include "intel_mocs.h" #include "intel_reset.h" @@ -165,6 +166,41 @@#define ACTIVE_PRIORITY (I915_PRIORITY_NEWCLIENT | I915_PRIORITY_NOSEMAPHORE) +struct virtual_engine { +struct intel_engine_cs base; +struct intel_context context; + +/* +* We allow only a single request through the virtual engine at a time +* (each request in the timeline waits for the completion fence of +* the previous before being submitted). By restricting ourselves to +* only submitting a single request, each request is placed on to a +* physical to maximise load spreading (by virtue of the late greedy +* scheduling -- each real engine takes the next available request +* upon idling). +*/ +struct i915_request *request; + +/* +* We keep a rbtree of available virtual engines inside each physical +* engine, sorted by priority. Here we preallocate the nodes we need +* for the virtual engine, indexed by physical_engine->id. +*/ +struct ve_node { +struct rb_node rb; +int prio; + } nodes[I915_NUM_ENGINES ]; + +/* And finally, which physical engines this virtual engine maps onto. */ +unsigned int num_siblings; +struct intel_engine_cs *siblings[0 ]; +}; + +static struct virtual_engine *to_virtual_engine (struct intel_engine_cs *engine) +{ + return container_of(engine, struct virtual_engine, base); +} +static int execlists_context_deferred_alloc (struct intel_context *ce,struct intel_engine_cs *engine); static void execlists_init_reg_state(u32 *reg_state,@@ -228,7 +264,8 @@ static int queue_prio(const struct intel_engine_execlists *execlists) }static inline bool need_preempt (const struct intel_engine_cs *engine, -const struct i915_request *rq) +const struct i915_request *rq, +struct rb_node *rb) {int last_prio;@@ -263,6 +300,25 @@ static inline bool need_preempt(const struct intel_engine_cs *engine, rq_prio(list_next_entry(rq, link)) > last_prio)return true; +if (rb) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +bool preempt = false; + +if (engine == ve->siblings[0 ]) {/* only preempt one sibling */ +struct i915_request *next; + +rcu_read_lock (); + next =READ_ONCE (ve->request); +if (next) + preempt =rq_prio (next) > last_prio; +rcu_read_unlock (); + } + +if (preempt) +return preempt; + } +/* * If the inflight context did not trigger the preemption, then maybe * it was the set of queued requests? Pick the highest priority in @@ -381,6 +437,8 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)list_for_each_entry_safe_reverse (rq, rn, &engine->timeline.requests, link) { +struct intel_engine_cs *owner; +if (i915_request_completed (rq))break ;@@ -389,16 +447,32 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)GEM_BUG_ON (rq->hw_context->active); -GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID ); -if (rq_prio (rq) != prio) { - prio =rq_prio (rq); - pl =i915_sched_lookup_priolist (engine, prio); - } -GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); +/* +* Push the request back into the queue for later resubmission. +* If this request is not native to this physical engine (i.e. +* it came from a virtual source), push it back onto the virtual +* engine so that it can be moved across onto another physical +* engine as load dictates. +*/ + owner = rq->hw_context->engine; +if (likely (owner == engine)) { +GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID ); +if (rq_prio (rq) != prio) { + prio =rq_prio (rq); + pl =i915_sched_lookup_priolist (engine, prio); + } +GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); -list_add (&rq->sched.link, pl); +list_add (&rq->sched.link, pl); + active = rq; + }else { +if (__i915_request_has_started (rq)) + rq->sched.attr.priority |=ACTIVE_PRIORITY ; - active = rq; + rq->engine = owner; + owner->submit_request (rq); + active =NULL ; + } }/* @@ -418,7 +492,8 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)* in the priority queue, but they will not gain immediate access to * the GPU. */ -if (~prio &ACTIVE_PRIORITY &&__i915_request_has_started (active)) { +if ( ~prio &ACTIVE_PRIORITY && + active &&__i915_request_has_started (active)) { prio |=ACTIVE_PRIORITY ; active->sched.attr.priority = prio; list_move_tail(&active->sched.link,@@ -658,6 +733,72 @@ static void complete_preempt_context(struct intel_engine_execlists *execlists) execlists)); } +static void virtual_update_register_offsets (u32 *regs, +struct intel_engine_cs *engine) +{ +u32 base = engine->mmio_base; + + regs[CTX_CONTEXT_CONTROL ] = +i915_mmio_reg_offset (RING_CONTEXT_CONTROL (base)); + regs[CTX_RING_HEAD ] =i915_mmio_reg_offset (RING_HEAD (base)); + regs[CTX_RING_TAIL ] =i915_mmio_reg_offset (RING_TAIL (base)); + regs[CTX_RING_BUFFER_START ] =i915_mmio_reg_offset (RING_START (base)); + regs[CTX_RING_BUFFER_CONTROL ] =i915_mmio_reg_offset (RING_CTL (base)); + + regs[CTX_BB_HEAD_U ] =i915_mmio_reg_offset (RING_BBADDR_UDW (base)); + regs[CTX_BB_HEAD_L ] =i915_mmio_reg_offset (RING_BBADDR (base)); + regs[CTX_BB_STATE ] =i915_mmio_reg_offset (RING_BBSTATE (base)); + regs[CTX_SECOND_BB_HEAD_U ] = +i915_mmio_reg_offset (RING_SBBADDR_UDW (base)); + regs[CTX_SECOND_BB_HEAD_L ] =i915_mmio_reg_offset (RING_SBBADDR (base)); + regs[CTX_SECOND_BB_STATE ] =i915_mmio_reg_offset (RING_SBBSTATE (base)); + + regs[CTX_CTX_TIMESTAMP ] = +i915_mmio_reg_offset (RING_CTX_TIMESTAMP (base)); + regs[CTX_PDP3_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,3 )); + regs[CTX_PDP3_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,3 )); + regs[CTX_PDP2_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,2 )); + regs[CTX_PDP2_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,2 )); + regs[CTX_PDP1_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,1 )); + regs[CTX_PDP1_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,1 )); + regs[CTX_PDP0_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,0 )); + regs[CTX_PDP0_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,0 )); + +if (engine->class ==RENDER_CLASS ) { + regs[CTX_RCS_INDIRECT_CTX ] = +i915_mmio_reg_offset (RING_INDIRECT_CTX (base)); + regs[CTX_RCS_INDIRECT_CTX_OFFSET ] = +i915_mmio_reg_offset (RING_INDIRECT_CTX_OFFSET (base)); + regs[CTX_BB_PER_CTX_PTR ] = +i915_mmio_reg_offset (RING_BB_PER_CTX_PTR (base)); + + regs[CTX_R_PWR_CLK_STATE ] = +i915_mmio_reg_offset (GEN8_R_PWR_CLK_STATE ); + } +} + +static bool virtual_matches (const struct virtual_engine *ve, +const struct i915_request *rq, +const struct intel_engine_cs *engine) +{ +const struct intel_engine_cs *active; + +/* +* We track when the HW has completed saving the context image +* (i.e. when we have seen the final CS event switching out of +* the context) and must not overwrite the context image before +* then. This restricts us to only using the active engine +* while the previous virtualized request is inflight (so +* we reuse the register offsets). This is a very small +* hystersis on the greedy seelction algorithm. +*/ + active =READ_ONCE (ve->context.active); +if (active && active != engine) +return false; + +return true; +} +static void execlists_dequeue (struct intel_engine_cs *engine) {struct intel_engine_execlists *const execlists = &engine->execlists;@@ -690,6 +831,26 @@ static void execlists_dequeue(struct intel_engine_cs *engine)* and context switches) submission. */ +for (rb =rb_first_cached (&execlists->virtual); rb; ) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +struct i915_request *rq =READ_ONCE (ve->request); + +if (!rq) {/* lazily cleanup after another engine handled rq */ +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + rb =rb_first_cached (&execlists->virtual); +continue ; + } + +if (!virtual_matches (ve, rq, engine)) { + rb =rb_next (rb); +continue ; + } + +break ; + } +if (last) {/* * Don't resubmit or switch until all outstanding @@ -711,7 +872,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)if (!execlists_is_active (execlists,EXECLISTS_ACTIVE_HWACK ))return ; -if (need_preempt (engine, last)) { +if (need_preempt (engine, last, rb)) {inject_preempt_context (engine);return ; }@@ -751,6 +912,89 @@ static void execlists_dequeue(struct intel_engine_cs *engine) last->tail = last->wa_tail; } +while (rb) {/* XXX virtual is always taking precedence */ +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +struct i915_request *rq; + +spin_lock (&ve->base.timeline.lock); + + rq = ve->request; +if (unlikely (!rq)) {/* lost the race to a sibling */ +spin_unlock (&ve->base.timeline.lock); +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + rb =rb_first_cached (&execlists->virtual); +continue ; + } + +GEM_BUG_ON (rq != ve->request); +GEM_BUG_ON (rq->engine != &ve->base); +GEM_BUG_ON (rq->hw_context != &ve->context); + +if (rq_prio (rq) >=queue_prio (execlists)) { +if (!virtual_matches (ve, rq, engine)) { +spin_unlock (&ve->base.timeline.lock); + rb =rb_next (rb); +continue ; + } + +if (last && !can_merge_rq (last, rq)) { +spin_unlock (&ve->base.timeline.lock); +return ;/* leave this rq for another engine */ + } + +GEM_TRACE ("%s: virtual rq=%llx:%lld%s, new engine? %s\n" , + engine->name, + rq->fence.context, + rq->fence.seqno, +i915_request_completed (rq) ?"!" : +i915_request_started (rq) ?"*" : +"" , +yesno (engine != ve->siblings[0 ])); + + ve->request =NULL ; + ve->base.execlists.queue_priority_hint =INT_MIN ; +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + + rq->engine = engine; + +if (engine != ve->siblings[0 ]) { +u32 *regs = ve->context.lrc_reg_state; +unsigned int n; + +GEM_BUG_ON (READ_ONCE (ve->context.active)); +virtual_update_register_offsets (regs, engine); + +/* +* Move the bound engine to the top of the list +* for future execution. We then kick this +* tasklet first before checking others, so that +* we preferentially reuse this set of bound +* registers. +*/ +for (n =1 ; n < ve->num_siblings; n++) { +if (ve->siblings[n] == engine) { +swap (ve->siblings[n], + ve->siblings[0 ]); +break ; + } + } + +GEM_BUG_ON (ve->siblings[0 ] != engine); + } + +__i915_request_submit (rq); +trace_i915_request_in (rq,port_index (port, execlists)); + submit = true; + last = rq; + } + +spin_unlock (&ve->base.timeline.lock); +break ; + } +while ((rb =rb_first_cached (&execlists->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;@@ -1874,6 +2118,25 @@ static void reset_csb_pointers(struct intel_engine_execlists *execlists) &execlists->csb_status[reset_value]); } +static struct i915_request *active_request (struct i915_request *rq) +{ +const struct list_head *const list = &rq->engine->timeline.requests; +const struct intel_context *const context = rq->hw_context; +struct i915_request *active =NULL ; + +list_for_each_entry_from_reverse (rq, list, link) { +if (i915_request_completed (rq)) +break ; + +if (rq->hw_context != context) +break ; + + active = rq; + } + +return active; +} +static void __execlists_reset (struct intel_engine_cs *engine,bool stalled) {struct intel_engine_execlists *const execlists = &engine->execlists;@@ -1894,7 +2157,8 @@ static void __execlists_reset(struct intel_engine_cs *engine, bool stalled)if (!port_isset (execlists->port)) goto out_clear; - ce =port_request (execlists->port)->hw_context; + rq =port_request (execlists->port); + ce = rq->hw_context;/* * Catch up with any missed context-switch interrupts. @@ -1907,16 +2171,10 @@ static void __execlists_reset(struct intel_engine_cs *engine, bool stalled)*/ execlists_cancel_port_requests (execlists); -/* Push back any incomplete requests for replay after the reset. */ - rq =__unwind_incomplete_requests (engine); + rq =active_request (rq);if (!rq) goto out_replay; -if (rq->hw_context != ce) {/* caught just before a CS event */ - rq =NULL ; - goto out_replay; - } -/* * If this request hasn't started yet, e.g. it is waiting on a * semaphore, we need to avoid skipping the request or else we @@ -1963,13 +2221,16 @@ static void __execlists_reset(struct intel_engine_cs *engine, bool stalled) }execlists_init_reg_state (regs, ce, engine, ce->ring); -/* Rerun the request; its payload has been neutered (if guilty). */ out_replay: +/* Rerun the request; its payload has been neutered (if guilty). */ ce->ring->head = rq ?intel_ring_wrap (ce->ring, rq->head) : ce->ring->tail;intel_ring_update_space (ce->ring);__execlists_update_reg_state (ce, engine); +/* Push back any incomplete requests for replay after the reset. */ +__unwind_incomplete_requests (engine); + out_clear:execlists_clear_all_active (execlists); }@@ -2043,6 +2304,26 @@ static void execlists_cancel_requests(struct intel_engine_cs *engine)i915_priolist_free (p); } +/* Cancel all attached virtual engines */ +while ((rb =rb_first_cached (&execlists->virtual))) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); + +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + +spin_lock (&ve->base.timeline.lock); +if (ve->request) { + ve->request->engine = engine; +__i915_request_submit (ve->request); +dma_fence_set_error (&ve->request->fence, -EIO ); +i915_request_mark_complete (ve->request); + ve->base.execlists.queue_priority_hint =INT_MIN ; + ve->request =NULL ; + } +spin_unlock (&ve->base.timeline.lock); + } +/* Remaining _unready_ requests will be nop'ed when submitted */ execlists->queue_priority_hint =INT_MIN ;@@ -2760,6 +3041,318 @@ static int execlists_context_deferred_alloc(struct intel_context *ce,return ret; } +static void virtual_context_destroy (struct kref *kref) +{ +struct virtual_engine *ve = +container_of (kref,typeof (*ve), context.ref); +unsigned int n; + +GEM_BUG_ON (ve->request); +GEM_BUG_ON (ve->context.active); + +for (n =0 ; n < ve->num_siblings; n++) { +struct intel_engine_cs *sibling = ve->siblings[n]; +struct rb_node *node = &ve->nodes[sibling->id].rb; + +if (RB_EMPTY_NODE (node)) +continue ; + +spin_lock_irq (&sibling->timeline.lock); + +if (!RB_EMPTY_NODE (node)) +rb_erase_cached (node, &sibling->execlists.virtual); + +spin_unlock_irq (&sibling->timeline.lock); + } +GEM_BUG_ON (__tasklet_is_scheduled (&ve->base.execlists.tasklet)); + +if (ve->context.state) +__execlists_context_fini (&ve->context); + +i915_timeline_fini (&ve->base.timeline); +kfree (ve); +} + +static void virtual_engine_initial_hint (struct virtual_engine *ve) +{ +int swp; + +/* +* Pick a random sibling on starting to help spread the load around. +* +* New contexts are typically created with exactly the same order +* of siblings, and often started in batches. Due to the way we iterate +* the array of sibling when submitting requests, sibling[0] is +* prioritised for dequeuing. If we make sure that sibling[0] is fairly +* randomised across the system, we also help spread the load by the +* first engine we inspect being different each time. +* +* NB This does not force us to execute on this engine, it will just +* typically be the first we inspect for submission. +*/ + swp =prandom_u32_max (ve->num_siblings); +if (!swp) +return ; + +swap (ve->siblings[swp], ve->siblings[0 ]); +virtual_update_register_offsets (ve->context.lrc_reg_state, + ve->siblings[0 ]); +} + +static int virtual_context_pin (struct intel_context *ce) +{ +struct virtual_engine *ve =container_of (ce,typeof (*ve), context); +int err; + +/* Note: we must use a real engine class for setting up reg state */ + err =__execlists_context_pin (ce, ve->siblings[0 ]); +if (err) +return err; + +virtual_engine_initial_hint (ve); +return 0 ; +} + +static void virtual_context_enter (struct intel_context *ce) +{ +struct virtual_engine *ve =container_of (ce,typeof (*ve), context); +unsigned int n; + +for (n =0 ; n < ve->num_siblings; n++) +intel_engine_pm_get (ve->siblings[n]); +} + +static void virtual_context_exit (struct intel_context *ce) +{ +struct virtual_engine *ve =container_of (ce,typeof (*ve), context); +unsigned int n; + +for (n =0 ; n < ve->num_siblings; n++) +intel_engine_pm_put (ve->siblings[n]); +} + +static const struct intel_context_ops virtual_context_ops = { + .pin = virtual_context_pin, + .unpin = execlists_context_unpin, + + .enter = virtual_context_enter, + .exit = virtual_context_exit, + + .destroy = virtual_context_destroy, +}; + +static void virtual_submission_tasklet (unsigned long data) +{ +struct virtual_engine *const ve = (struct virtual_engine *)data; +const int prio = ve->base.execlists.queue_priority_hint; +unsigned int n; + +local_irq_disable (); +for (n =0 ;READ_ONCE (ve->request) && n < ve->num_siblings; n++) { +struct intel_engine_cs *sibling = ve->siblings[n]; +struct ve_node *const node = &ve->nodes[sibling->id]; +struct rb_node **parent, *rb; +bool first; + +spin_lock (&sibling->timeline.lock); + +if (!RB_EMPTY_NODE (&node->rb)) { +/* +* Cheat and avoid rebalancing the tree if we can +* reuse this node in situ. +*/ + first =rb_first_cached (&sibling->execlists.virtual) == + &node->rb; +if (prio == node->prio || (prio > node->prio && first)) + goto submit_engine; + +rb_erase_cached (&node->rb, &sibling->execlists.virtual); + } + + rb =NULL ; + first = true; + parent = &sibling->execlists.virtual.rb_root.rb_node; +while (*parent) { +struct ve_node *other; + + rb = *parent; + other =rb_entry (rb,typeof (*other), rb); +if (prio > other->prio) { + parent = &rb->rb_left; + }else { + parent = &rb->rb_right; + first = false; + } + } + +rb_link_node (&node->rb, rb, parent); +rb_insert_color_cached (&node->rb, + &sibling->execlists.virtual, + first); + +submit_engine: +GEM_BUG_ON (RB_EMPTY_NODE (&node->rb)); + node->prio = prio; +if (first && prio > sibling->execlists.queue_priority_hint) { + sibling->execlists.queue_priority_hint = prio; +tasklet_hi_schedule (&sibling->execlists.tasklet); + } + +spin_unlock (&sibling->timeline.lock); + } +local_irq_enable (); +} + +static void virtual_submit_request (struct i915_request *rq) +{ +struct virtual_engine *ve =to_virtual_engine (rq->engine); + +GEM_TRACE ("%s: rq=%llx:%lld\n" , + ve->base.name, + rq->fence.context, + rq->fence.seqno); + +GEM_BUG_ON (ve->base.submit_request != virtual_submit_request); + +GEM_BUG_ON (ve->request); + ve->base.execlists.queue_priority_hint =rq_prio (rq); +WRITE_ONCE (ve->request, rq); + +tasklet_schedule (&ve->base.execlists.tasklet); +} + +struct intel_context * +intel_execlists_create_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs **siblings, +unsigned int count) +{ +struct virtual_engine *ve; +unsigned int n; +int err; + +if (count ==0 ) +return ERR_PTR (-EINVAL ); + +if (count ==1 ) +return intel_context_create (ctx, siblings[0 ]); + + ve =kzalloc (struct_size (ve, siblings, count),GFP_KERNEL ); +if (!ve) +return ERR_PTR (-ENOMEM ); + + ve->base.i915 = ctx->i915; + ve->base.id =-1 ; + ve->base.class =OTHER_CLASS ; + ve->base.uabi_class =I915_ENGINE_CLASS_INVALID ; + ve->base.instance =I915_ENGINE_CLASS_INVALID_VIRTUAL ; + ve->base.flags =I915_ENGINE_IS_VIRTUAL ; + +snprintf (ve->base.name,sizeof (ve->base.name),"virtual" ); + + err =i915_timeline_init (ctx->i915, &ve->base.timeline,NULL ); +if (err) + goto err_put; +i915_timeline_set_subclass (&ve->base.timeline,TIMELINE_VIRTUAL ); + +intel_engine_init_execlists (&ve->base); + + ve->base.cops = &virtual_context_ops; + ve->base.request_alloc = execlists_request_alloc; + + ve->base.schedule = i915_schedule; + ve->base.submit_request = virtual_submit_request; + + ve->base.execlists.queue_priority_hint =INT_MIN ; +tasklet_init (&ve->base.execlists.tasklet, + virtual_submission_tasklet, + (unsigned long )ve); + +intel_context_init (&ve->context, ctx, &ve->base); + +for (n =0 ; n < count; n++) { +struct intel_engine_cs *sibling = siblings[n]; + +GEM_BUG_ON (!is_power_of_2 (sibling->mask)); +if (sibling->mask & ve->base.mask) { +DRM_DEBUG ("duplicate %s entry in load balancer\n" , + sibling->name); + err = -EINVAL ; + goto err_put; + } + +/* +* The virtual engine implementation is tightly coupled to +* the execlists backend -- we push out request directly +* into a tree inside each physical engine. We could support +* layering if we handle cloning of the requests and +* submitting a copy into each backend. +*/ +if (sibling->execlists.tasklet.func != + execlists_submission_tasklet) { + err = -ENODEV ; + goto err_put; + } + +GEM_BUG_ON (RB_EMPTY_NODE (&ve->nodes[sibling->id].rb)); +RB_CLEAR_NODE (&ve->nodes[sibling->id].rb); + + ve->siblings[ve->num_siblings++] = sibling; + ve->base.mask |= sibling->mask; + +/* +* All physical engines must be compatible for their emission +* functions (as we build the instructions during request +* construction and do not alter them before submission +* on the physical engine). We use the engine class as a guide +* here, although that could be refined. +*/ +if (ve->base.class !=OTHER_CLASS ) { +if (ve->base.class != sibling->class) { +DRM_DEBUG ("invalid mixing of engine class, sibling %d, already %d\n" , + sibling->class, ve->base.class); + err = -EINVAL ; + goto err_put; + } +continue ; + } + + ve->base.class = sibling->class; + ve->base.uabi_class = sibling->uabi_class; +snprintf (ve->base.name,sizeof (ve->base.name), +"v%dx%d" , ve->base.class, count); + ve->base.context_size = sibling->context_size; + + ve->base.emit_bb_start = sibling->emit_bb_start; + ve->base.emit_flush = sibling->emit_flush; + ve->base.emit_init_breadcrumb = sibling->emit_init_breadcrumb; + ve->base.emit_fini_breadcrumb = sibling->emit_fini_breadcrumb; + ve->base.emit_fini_breadcrumb_dw = + sibling->emit_fini_breadcrumb_dw; + } + +return &ve->context; + +err_put: +intel_context_put (&ve->context); +return ERR_PTR (err); +} + +struct intel_context * +intel_execlists_clone_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs *src) +{ +struct virtual_engine *se =to_virtual_engine (src); +struct intel_context *dst; + + dst =intel_execlists_create_virtual (ctx, + se->siblings, + se->num_siblings); +if (IS_ERR (dst)) +return dst; + +return dst; +} + void intel_execlists_show_requests(struct intel_engine_cs *engine, struct drm_printer *m, void (*show_request)(struct drm_printer *m,@@ -2817,6 +3410,29 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,show_request (m, last,"\t\tQ " ); } + last =NULL ; + count =0 ; +for (rb =rb_first_cached (&execlists->virtual); rb; rb =rb_next (rb)) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +struct i915_request *rq =READ_ONCE (ve->request); + +if (rq) { +if (count++ < max -1 ) +show_request (m, rq,"\t\tV " ); +else + last = rq; + } + } +if (last) { +if (count > max) { +drm_printf (m, +"\t\t...skipping %d virtual requests...\n" , + count - max); + } +show_request (m, last,"\t\tV " ); + } +spin_unlock_irqrestore (&engine->timeline.lock, flags); }drivers/gpu/drm/i915/gt/intel_lrc.h +9
-0@@ -114,4 +114,13 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine, const char *prefix), unsigned int max); +struct intel_context * +intel_execlists_create_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs **siblings, +unsigned int count); + +struct intel_context * +intel_execlists_clone_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs *src); +#endif /* _INTEL_LRC_H_ */ drivers/gpu/drm/i915/gt/selftest_lrc.c +146
-0@@ -1301,6 +1301,185 @@ static int live_preempt_smoke(void *arg)return err; } +static int nop_virtual_engine (struct drm_i915_private *i915, +struct intel_engine_cs **siblings, +unsigned int nsibling, +unsigned int nctx, +unsigned int flags) +#define CHAIN BIT(0) +{ +IGT_TIMEOUT (end_time); +struct i915_request *request[16 ]; +struct i915_gem_context *ctx[16 ]; +struct intel_context *ve[16 ]; +unsigned long n, prime, nc; +struct igt_live_test t; +ktime_t times[2 ] = {}; +int err; + +GEM_BUG_ON (!nctx || nctx >ARRAY_SIZE (ctx)); + +for (n =0 ; n < nctx; n++) { + ctx[n] =kernel_context (i915); +if (!ctx[n]) { + err = -ENOMEM ; + nctx = n; + goto out; + } + + ve[n] =intel_execlists_create_virtual (ctx[n], + siblings, nsibling); +if (IS_ERR (ve[n])) { +kernel_context_close (ctx[n]); + err =PTR_ERR (ve[n]); + nctx = n; + goto out; + } + + err =intel_context_pin (ve[n]); +if (err) { +intel_context_put (ve[n]); +kernel_context_close (ctx[n]); + nctx = n; + goto out; + } + } + + err =igt_live_test_begin (&t, i915, __func__, ve[0 ]->engine->name); +if (err) + goto out; + +for_each_prime_number_from (prime,1 ,8192 ) { + times[1 ] =ktime_get_raw (); + +if (flags &CHAIN ) { +for (nc =0 ; nc < nctx; nc++) { +for (n =0 ; n < prime; n++) { + request[nc] = +i915_request_create (ve[nc]); +if (IS_ERR (request[nc])) { + err =PTR_ERR (request[nc]); + goto out; + } + +i915_request_add (request[nc]); + } + } + }else { +for (n =0 ; n < prime; n++) { +for (nc =0 ; nc < nctx; nc++) { + request[nc] = +i915_request_create (ve[nc]); +if (IS_ERR (request[nc])) { + err =PTR_ERR (request[nc]); + goto out; + } + +i915_request_add (request[nc]); + } + } + } + +for (nc =0 ; nc < nctx; nc++) { +if (i915_request_wait (request[nc], +I915_WAIT_LOCKED , +HZ /10 ) <0 ) { +pr_err ("%s(%s): wait for %llx:%lld timed out\n" , + __func__, ve[0 ]->engine->name, + request[nc]->fence.context, + request[nc]->fence.seqno); + +GEM_TRACE ("%s(%s) failed at request %llx:%lld\n" , + __func__, ve[0 ]->engine->name, + request[nc]->fence.context, + request[nc]->fence.seqno); +GEM_TRACE_DUMP (); +i915_gem_set_wedged (i915); +break ; + } + } + + times[1 ] =ktime_sub (ktime_get_raw (), times[1 ]); +if (prime ==1 ) + times[0 ] = times[1 ]; + +if (__igt_timeout (end_time,NULL )) +break ; + } + + err =igt_live_test_end (&t); +if (err) + goto out; + +pr_info ("Requestx%d latencies on %s: 1 = %lluns, %lu = %lluns\n" , + nctx, ve[0 ]->engine->name,ktime_to_ns (times[0 ]), + prime,div64_u64 (ktime_to_ns (times[1 ]), prime)); + +out: +if (igt_flush_test (i915,I915_WAIT_LOCKED )) + err = -EIO ; + +for (nc =0 ; nc < nctx; nc++) { +intel_context_unpin (ve[nc]); +intel_context_put (ve[nc]); +kernel_context_close (ctx[nc]); + } +return err; +} + +static int live_virtual_engine (void *arg) +{ +struct drm_i915_private *i915 = arg; +struct intel_engine_cs *siblings[MAX_ENGINE_INSTANCE +1 ]; +struct intel_engine_cs *engine; +enum intel_engine_id id; +unsigned int class, inst; +int err = -ENODEV ; + +if (USES_GUC_SUBMISSION (i915)) +return 0 ; + +mutex_lock (&i915->drm.struct_mutex); + +for_each_engine (engine, i915, id) { + err =nop_virtual_engine (i915, &engine,1 ,1 ,0 ); +if (err) { +pr_err ("Failed to wrap engine %s: err=%d\n" , + engine->name, err); + goto out_unlock;drivers/gpu/drm/i915/gt/selftest_lrc.c static int live_preempt_smoke(void *arg) · line 1459
Quoted 10 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +10
-0+ } + } + +for (class =0 ; class <=MAX_ENGINE_CLASS ; class++) { +int nsibling, n; + + nsibling =0 ; +for (inst =0 ; inst <=MAX_ENGINE_INSTANCE ; inst++) { +if (!i915->engine_class[class][inst]) +break ;Continue I think, to be able to use vcs0 + vcs2 on Icelake.
drivers/gpu/drm/i915/gt/selftest_lrc.c static int live_preempt_smoke(void *arg) · line 1464
Quoted 5 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +5
-0+ + siblings[nsibling++] = i915->engine_class[class][inst]; + } +if (nsibling <2 ) +continue ;Could test single, no?
Quoted 291 lines
drivers/gpu/drm/i915/gt/selftest_lrc.c +19
-0+ +for (n =1 ; n <= nsibling +1 ; n++) { + err =nop_virtual_engine (i915, siblings, nsibling, + n,0 ); +if (err) + goto out_unlock; + } + + err =nop_virtual_engine (i915, siblings, nsibling, n,CHAIN ); +if (err) + goto out_unlock; + } + +out_unlock: +mutex_unlock (&i915->drm.struct_mutex); +return err; +} +int intel_execlists_live_selftests (struct drm_i915_private *i915) {static const struct i915_subtest tests[] = {@@ -1313,6 +1492,7 @@ int intel_execlists_live_selftests(struct drm_i915_private *i915)SUBTEST (live_chain_preempt),SUBTEST (live_preempt_hang),SUBTEST (live_preempt_smoke), + SUBTEST(live_virtual_engine), };if (!HAS_EXECLISTS (i915))drivers/gpu/drm/i915/i915_gem.h +5
-0@@ -91,4 +91,9 @@ static inline bool __tasklet_enable(struct tasklet_struct *t) return atomic_dec_and_test(&t->count); } +static inline bool __tasklet_is_scheduled (struct tasklet_struct *t) +{ +return test_bit (TASKLET_STATE_SCHED , &t->state); +} +#endif /* __I915_GEM_H__ */ drivers/gpu/drm/i915/i915_gem_context.c +114
-4@@ -86,6 +86,7 @@*/ #include <linux/log2.h> +#include <linux/nospec.h> #include <drm/i915_drm.h> @@ -1209,7 +1210,6 @@ __intel_context_reconfigure_sseu(struct intel_context *ce,int ret;GEM_BUG_ON (INTEL_GEN (ce->gem_context->i915) <8 ); -GEM_BUG_ON (ce->engine->id !=RCS0 ); ret =intel_context_lock_pinned (ce);if (ret)@@ -1397,7 +1397,102 @@ struct set_engines {struct i915_gem_engines *engines; }; +static int +set_engines__load_balance (struct i915_user_extension __user *base,void *data) +{ +struct i915_context_engines_load_balance __user *ext = +container_of_user (base,typeof (*ext), base); +const struct set_engines *set = data; +struct intel_engine_cs *stack[16 ]; +struct intel_engine_cs **siblings; +struct intel_context *ce; +u16 num_siblings, idx; +unsigned int n; +int err; + +if (!HAS_EXECLISTS (set->ctx->i915)) +return -ENODEV ; + +if (USES_GUC_SUBMISSION (set->ctx->i915)) +return -ENODEV ;/* not implement yet */ + +if (get_user (idx, &ext->engine_index)) +return -EFAULT ; + +if (idx >= set->engines->num_engines) { +DRM_DEBUG ("Invalid placement value, %d >= %d\n" , + idx, set->engines->num_engines); +return -EINVAL ; + } + + idx =array_index_nospec (idx, set->engines->num_engines); +if (set->engines->engines[idx]) { +DRM_DEBUG ("Invalid placement[%d], already occupied\n" , idx); +return -EEXIST ; + } + +if (get_user (num_siblings, &ext->num_siblings)) +return -EFAULT ; + + err =check_user_mbz (&ext->flags); +if (err) +return err; + +for (n =0 ; n <ARRAY_SIZE (ext->mbz64); n++) { + err =check_user_mbz (&ext->mbz64[n]); +if (err) +return err; + } + + siblings = stack; +if (num_siblings >ARRAY_SIZE (stack)) { + siblings =kmalloc_array (num_siblings, +sizeof (*siblings), +GFP_KERNEL ); +if (!siblings) +return -ENOMEM ; + } + +for (n =0 ; n < num_siblings; n++) { +struct i915_engine_class_instance ci; + +if (copy_from_user (&ci, &ext->engines[n],sizeof (ci))) { + err = -EFAULT ; + goto out_siblings; + } + + siblings[n] =intel_engine_lookup_user (set->ctx->i915, + ci.engine_class, + ci.engine_instance); +if (!siblings[n]) { +DRM_DEBUG ("Invalid sibling[%d]: { class:%d, inst:%d }\n" , + n, ci.engine_class, ci.engine_instance); + err = -EINVAL ; + goto out_siblings; + } + } + + ce =intel_execlists_create_virtual (set->ctx, siblings, n); +if (IS_ERR (ce)) { + err =PTR_ERR (ce); + goto out_siblings; + } + +if (cmpxchg (&set->engines->engines[idx],NULL , ce)) { +intel_context_put (ce); + err = -EEXIST ; + goto out_siblings; + } + +out_siblings: +if (siblings != stack) +kfree (siblings); + +return err; +} +static const i915_user_extension_fn set_engines__extensions[] = { + [I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE ] = set_engines__load_balance, }; static int@@ -1696,14 +1791,29 @@ static int clone_engines(struct i915_gem_context *dst, clone->i915 = dst->i915;for (n =0 ; n < e->num_engines; n++) { +struct intel_engine_cs *engine; +if (!e->engines[n]) { clone->engines[n] =NULL ;continue ; } + engine = e->engines[n]->engine; - clone->engines[n] = -intel_context_create (dst, e->engines[n]->engine); -if (!clone->engines[n]) { +/* +* Virtual engines are singletons; they can only exist +* inside a single context, because they embed their +* HW context... As each virtual context implies a single +* timeline (each engine can only dequeue a single request +* at any time), it would be surprising for two contexts +* to use the same engine. So let's create a copy of +* the virtual engine instead. +*/ +if (intel_engine_is_virtual (engine)) + clone->engines[n] = +intel_execlists_clone_virtual (dst, engine); +else + clone->engines[n] =intel_context_create (dst, engine); +if (IS_ERR_OR_NULL (clone->engines[n])) {__free_engines (clone, n); goto err_unlock; }drivers/gpu/drm/i915/i915_scheduler.c +15
-3@@ -248,17 +248,26 @@ sched_lock_engine(const struct i915_sched_node *node,struct intel_engine_cs *locked, struct sched_cache *cache) { - struct intel_engine_cs *engine = node_to_request(node)->engine; + const struct i915_request *rq = node_to_request(node); +struct intel_engine_cs *engine;GEM_BUG_ON (!locked); -if (engine != locked) { +/* +* Virtual engines complicate acquiring the engine timeline lock, +* as their rq->engine pointer is not stable until under that +* engine lock. The simple ploy we use is to take the lock then +* check that the rq still belongs to the newly locked engine. +*/ +while (locked != (engine =READ_ONCE (rq->engine))) {spin_unlock (&locked->timeline.lock);memset (cache,0 ,sizeof (*cache));spin_lock (&engine->timeline.lock); + locked = engine; } -return engine; +GEM_BUG_ON (locked != engine); +return locked; } static bool inflight(const struct i915_request *rq,@@ -371,8 +380,11 @@ static void __i915_schedule(struct i915_request *rq,if (prio <= node->attr.priority ||node_signaled (node))continue ; +GEM_BUG_ON (node_to_request (node)->engine != engine); + node->attr.priority = prio;if (!list_empty (&node->link)) { +GEM_BUG_ON (intel_engine_is_virtual (engine));if (!cache.priolist) cache.priolist = i915_sched_lookup_priolist(engine,drivers/gpu/drm/i915/i915_timeline_types.h +1
-0@@ -26,6 +26,7 @@ struct i915_timeline {spinlock_t lock;#define TIMELINE_CLIENT 0/* default subclass */ #define TIMELINE_ENGINE 1 +#define TIMELINE_VIRTUAL 2struct mutex mutex;/* protects the flow of requests */ unsigned int pin_count;include/uapi/drm/i915_drm.h +19
-0@@ -137,6 +137,7 @@ struct i915_engine_class_instance {__u16 engine_class;/* see enum drm_i915_gem_engine_class */ __u16 engine_instance;#define I915_ENGINE_CLASS_INVALID_NONE -1 +#define I915_ENGINE_CLASS_INVALID_VIRTUAL -2 };/** @@ -1607,8 +1608,46 @@ struct drm_i915_gem_context_param_sseu {__u32 rsvd; }; +/* +* i915_context_engines_load_balance: +* +* Enable load balancing across this set of engines. +* +* Into the I915_EXEC_DEFAULT slot [0], a virtual engine is created that when +* used will proxy the execbuffer request onto one of the set of engines +* in such a way as to distribute the load evenly across the set. +* +* The set of engines must be compatible (e.g. the same HW class) as they +* will share the same logical GPU context and ring. +* +* To intermix rendering with the virtual engine and direct rendering onto +* the backing engines (bypassing the load balancing proxy), the context must +* be defined to use a single timeline for all engines. +*/ +struct i915_context_engines_load_balance { +struct i915_user_extension base;
Quoted 8 lines
include/uapi/drm/i915_drm.h struct drm_i915_gem_context_param_sseu { · line 1634
Quoted 6 lines
include/uapi/drm/i915_drm.h +6
-0+ +__u16 engine_index; +__u16 num_siblings; +__u32 flags;/* all undefined flags must be zero */ + +__u64 mbz64[1 ];/* reserved for future use; must be zero */ Why array of one was a serious question?
Sorry, I haven't actually pulled in the review comments yet from last time for this portion. The topic for today were the 10 patches in the previous series. This series only exists as it's ahead of the preempt-to-busy + timeslice and I wanted to start getting some feedback on those two.
(Optimistically hoping for Matthew to clear a few more of the GEM patches in the meantime.)
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 19/45] drm/i915: Load balancing across a virtual engine
In reply to Chris WilsonQuoted 159 lines · Chris Wilson
Having allowed the user to define a set of engines that they will want to only use, we go one step further and allow them to bind those engines into a single virtual instance. Submitting a batch to the virtual engine will then forward it to any one of the set in a manner as best to distribute load. The virtual engine has a single timeline across all engines (it operates as a single queue), so it is not able to concurrently run batches across multiple engines by itself; that is left up to the user to submit multiple concurrent batches to multiple queues. Multiple users will be load balanced across the system.
The mechanism used for load balancing in this patch is a late greedy balancer. When a request is ready for execution, it is added to each engine's queue, and when an engine is ready for its next request it claims it from the virtual engine. The first engine to do so, wins, i.e. the request is executed at the earliest opportunity (idle moment) in the system.
As not all HW is created equal, the user is still able to skip the virtual engine and execute the batch on a specific engine, all within the same queue. It will then be executed in order on the correct engine, with execution on other virtual engines being moved away due to the load detection.
A couple of areas for potential improvement left!
- The virtual engine always take priority over equal-priority tasks. Mostly broken up by applying
FQ_CODELrules for prioritising new clients, and hopefully the virtual and real engines are not then congested (i.e. all work is via virtual engines, or all work is to the real engine).- We require the breadcrumb irq around every virtual engine request. For normal engines, we eliminate the need for the slow round trip via interrupt by using the submit fence and queueing in order. For virtual engines, we have to allow any job to transfer to a new ring, and cannot coalesce the submissions, so require the completion fence instead, forcing the persistent use of interrupts.
- We only drip feed single requests through each virtual engine and onto the physical engines, even if there was enough work to fill all ELSP, leaving small stalls with an idle CS event at the end of every request. Could we be greedy and fill both slots? Being lazy is virtuous for load distribution on less-than-full workloads though.
Other areas of improvement are more general, such as reducing lock contention, reducing dispatch overhead, looking at direct submission rather than bouncing around tasklets etc.
sseu: Lift the restriction to allow sseu to be reconfigured on virtual engines composed of
RENDER_CLASS(rcs).v2: macroize
check_user_mbz()
v3: Cancel virtual engines on wedging
v4: Commence commenting
v5: Replace 64bsibling_maskwith a list of class:instanceSigned-off-by Chris Wilson <[email protected]>Cc Tvrtko Ursulin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_breadcrumbs.c | 6 +- drivers/gpu/drm/i915/gt/intel_engine_types.h | 8 + drivers/gpu/drm/i915/gt/intel_lrc.c | 656 ++++++++++++++++++- drivers/gpu/drm/i915/gt/intel_lrc.h | 9 + drivers/gpu/drm/i915/gt/selftest_lrc.c | 180 +++++ drivers/gpu/drm/i915/i915_gem.h | 5 + drivers/gpu/drm/i915/i915_gem_context.c | 118 +++- drivers/gpu/drm/i915/i915_scheduler.c | 18 +- drivers/gpu/drm/i915/i915_timeline_types.h | 1 + include/uapi/drm/i915_drm.h | 39 ++ 10 files changed, 1012 insertions(+), 28 deletions(-)drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +5
-1@@ -290,8 +290,12 @@ bool i915_request_enable_breadcrumb(struct i915_request *rq)break ; }list_add (&rq->signal_link, pos); -if (pos == &ce->signals)/* catch transitions from empty list */ +if (pos == &ce->signals) {/* catch transitions from empty */ list_move_tail (&ce->signal_link, &b->signalers); + }else if (ce->engine != rq->engine) {/* virtualised */ +list_move_tail (&ce->signal_link, &b->signalers); +intel_engine_queue_breadcrumbs (rq->engine); + }set_bit (I915_FENCE_FLAG_SIGNAL , &rq->fence.flags);spin_unlock (&b->irq_lock);drivers/gpu/drm/i915/gt/intel_engine_types.h +8
-0@@ -227,6 +227,7 @@ struct intel_engine_execlists {* @queue: queue of requests, in priority lists */ struct rb_root_cached queue; +struct rb_root_cached virtual;/** * @csb_write: control register for Context Switch buffer @@ -445,6 +446,7 @@ struct intel_engine_cs {#define I915_ENGINE_HAS_PREEMPTION BIT(2)#define I915_ENGINE_HAS_SEMAPHORES BIT(3)#define I915_ENGINE_NEEDS_BREADCRUMB_TASKLET BIT(4) +#define I915_ENGINE_IS_VIRTUAL BIT(5)unsigned int flags;/* @@ -534,6 +536,12 @@ intel_engine_needs_breadcrumb_tasklet(const struct intel_engine_cs *engine)return engine->flags &I915_ENGINE_NEEDS_BREADCRUMB_TASKLET ; } +static inline bool +intel_engine_is_virtual (const struct intel_engine_cs *engine) +{ +return engine->flags &I915_ENGINE_IS_VIRTUAL ; +} +#define instdone_slice_mask (dev_priv__) \ (IS_GEN(dev_priv__, 7) ? \ 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)drivers/gpu/drm/i915/gt/intel_lrc.c +23
-0@@ -136,6 +136,7 @@#include "i915_drv.h" #include "i915_gem_render_state.h" #include "i915_vgpu.h" +#include "intel_engine_pm.h" #include "intel_lrc_reg.h" #include "intel_mocs.h" #include "intel_reset.h" @@ -165,6 +166,41 @@#define ACTIVE_PRIORITY (I915_PRIORITY_NEWCLIENT | I915_PRIORITY_NOSEMAPHORE) +struct virtual_engine { +struct intel_engine_cs base; +struct intel_context context; + +/* +* We allow only a single request through the virtual engine at a time +* (each request in the timeline waits for the completion fence of +* the previous before being submitted). By restricting ourselves to +* only submitting a single request, each request is placed on to a +* physical to maximise load spreading (by virtue of the late greedy +* scheduling -- each real engine takes the next available request +* upon idling). +*/ +struct i915_request *request; + +/* +* We keep a rbtree of available virtual engines inside each physical +* engine, sorted by priority. Here we preallocate the nodes we need +* for the virtual engine, indexed by physical_engine->id. +*/ +struct ve_node { +struct rb_node rb;
drivers/gpu/drm/i915/gt/intel_lrc.c line 200
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +10
-0+int prio; + } nodes[I915_NUM_ENGINES ]; + +/* And finally, which physical engines this virtual engine maps onto. */ +unsigned int num_siblings; +struct intel_engine_cs *siblings[0 ]; +}; + +static struct virtual_engine *to_virtual_engine (struct intel_engine_cs *engine) +{
Would GEM_BUG_ON(!(engine->flags & ..VIRTUAL..)) be too much?
Regards,
Tvrtko
Quoted 1,243 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +603
-20+ return container_of(engine, struct virtual_engine, base); +} +static int execlists_context_deferred_alloc (struct intel_context *ce,struct intel_engine_cs *engine); static void execlists_init_reg_state(u32 *reg_state,@@ -228,7 +264,8 @@ static int queue_prio(const struct intel_engine_execlists *execlists) }static inline bool need_preempt (const struct intel_engine_cs *engine, -const struct i915_request *rq) +const struct i915_request *rq, +struct rb_node *rb) {int last_prio;@@ -263,6 +300,25 @@ static inline bool need_preempt(const struct intel_engine_cs *engine, rq_prio(list_next_entry(rq, link)) > last_prio)return true; +if (rb) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +bool preempt = false; + +if (engine == ve->siblings[0 ]) {/* only preempt one sibling */ +struct i915_request *next; + +rcu_read_lock (); + next =READ_ONCE (ve->request); +if (next) + preempt =rq_prio (next) > last_prio; +rcu_read_unlock (); + } + +if (preempt) +return preempt; + } +/* * If the inflight context did not trigger the preemption, then maybe * it was the set of queued requests? Pick the highest priority in @@ -381,6 +437,8 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)list_for_each_entry_safe_reverse (rq, rn, &engine->timeline.requests, link) { +struct intel_engine_cs *owner; +if (i915_request_completed (rq))break ;@@ -389,16 +447,32 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)GEM_BUG_ON (rq->hw_context->active); -GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID ); -if (rq_prio (rq) != prio) { - prio =rq_prio (rq); - pl =i915_sched_lookup_priolist (engine, prio); - } -GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); +/* +* Push the request back into the queue for later resubmission. +* If this request is not native to this physical engine (i.e. +* it came from a virtual source), push it back onto the virtual +* engine so that it can be moved across onto another physical +* engine as load dictates. +*/ + owner = rq->hw_context->engine; +if (likely (owner == engine)) { +GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID ); +if (rq_prio (rq) != prio) { + prio =rq_prio (rq); + pl =i915_sched_lookup_priolist (engine, prio); + } +GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); -list_add (&rq->sched.link, pl); +list_add (&rq->sched.link, pl); + active = rq; + }else { +if (__i915_request_has_started (rq)) + rq->sched.attr.priority |=ACTIVE_PRIORITY ; - active = rq; + rq->engine = owner; + owner->submit_request (rq); + active =NULL ; + } }/* @@ -418,7 +492,8 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)* in the priority queue, but they will not gain immediate access to * the GPU. */ -if (~prio &ACTIVE_PRIORITY &&__i915_request_has_started (active)) { +if ( ~prio &ACTIVE_PRIORITY && + active &&__i915_request_has_started (active)) { prio |=ACTIVE_PRIORITY ; active->sched.attr.priority = prio; list_move_tail(&active->sched.link,@@ -658,6 +733,72 @@ static void complete_preempt_context(struct intel_engine_execlists *execlists) execlists)); } +static void virtual_update_register_offsets (u32 *regs, +struct intel_engine_cs *engine) +{ +u32 base = engine->mmio_base; + + regs[CTX_CONTEXT_CONTROL ] = +i915_mmio_reg_offset (RING_CONTEXT_CONTROL (base)); + regs[CTX_RING_HEAD ] =i915_mmio_reg_offset (RING_HEAD (base)); + regs[CTX_RING_TAIL ] =i915_mmio_reg_offset (RING_TAIL (base)); + regs[CTX_RING_BUFFER_START ] =i915_mmio_reg_offset (RING_START (base)); + regs[CTX_RING_BUFFER_CONTROL ] =i915_mmio_reg_offset (RING_CTL (base)); + + regs[CTX_BB_HEAD_U ] =i915_mmio_reg_offset (RING_BBADDR_UDW (base)); + regs[CTX_BB_HEAD_L ] =i915_mmio_reg_offset (RING_BBADDR (base)); + regs[CTX_BB_STATE ] =i915_mmio_reg_offset (RING_BBSTATE (base)); + regs[CTX_SECOND_BB_HEAD_U ] = +i915_mmio_reg_offset (RING_SBBADDR_UDW (base)); + regs[CTX_SECOND_BB_HEAD_L ] =i915_mmio_reg_offset (RING_SBBADDR (base)); + regs[CTX_SECOND_BB_STATE ] =i915_mmio_reg_offset (RING_SBBSTATE (base)); + + regs[CTX_CTX_TIMESTAMP ] = +i915_mmio_reg_offset (RING_CTX_TIMESTAMP (base)); + regs[CTX_PDP3_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,3 )); + regs[CTX_PDP3_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,3 )); + regs[CTX_PDP2_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,2 )); + regs[CTX_PDP2_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,2 )); + regs[CTX_PDP1_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,1 )); + regs[CTX_PDP1_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,1 )); + regs[CTX_PDP0_UDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,0 )); + regs[CTX_PDP0_LDW ] =i915_mmio_reg_offset (GEN8_RING_PDP_LDW (base,0 )); + +if (engine->class ==RENDER_CLASS ) { + regs[CTX_RCS_INDIRECT_CTX ] = +i915_mmio_reg_offset (RING_INDIRECT_CTX (base)); + regs[CTX_RCS_INDIRECT_CTX_OFFSET ] = +i915_mmio_reg_offset (RING_INDIRECT_CTX_OFFSET (base)); + regs[CTX_BB_PER_CTX_PTR ] = +i915_mmio_reg_offset (RING_BB_PER_CTX_PTR (base)); + + regs[CTX_R_PWR_CLK_STATE ] = +i915_mmio_reg_offset (GEN8_R_PWR_CLK_STATE ); + } +} + +static bool virtual_matches (const struct virtual_engine *ve, +const struct i915_request *rq, +const struct intel_engine_cs *engine) +{ +const struct intel_engine_cs *active; + +/* +* We track when the HW has completed saving the context image +* (i.e. when we have seen the final CS event switching out of +* the context) and must not overwrite the context image before +* then. This restricts us to only using the active engine +* while the previous virtualized request is inflight (so +* we reuse the register offsets). This is a very small +* hystersis on the greedy seelction algorithm. +*/ + active =READ_ONCE (ve->context.active); +if (active && active != engine) +return false; + +return true; +} +static void execlists_dequeue (struct intel_engine_cs *engine) {struct intel_engine_execlists *const execlists = &engine->execlists;@@ -690,6 +831,26 @@ static void execlists_dequeue(struct intel_engine_cs *engine)* and context switches) submission. */ +for (rb =rb_first_cached (&execlists->virtual); rb; ) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +struct i915_request *rq =READ_ONCE (ve->request); + +if (!rq) {/* lazily cleanup after another engine handled rq */ +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + rb =rb_first_cached (&execlists->virtual); +continue ; + } + +if (!virtual_matches (ve, rq, engine)) { + rb =rb_next (rb); +continue ; + } + +break ; + } +if (last) {/* * Don't resubmit or switch until all outstanding @@ -711,7 +872,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)if (!execlists_is_active (execlists,EXECLISTS_ACTIVE_HWACK ))return ; -if (need_preempt (engine, last)) { +if (need_preempt (engine, last, rb)) {inject_preempt_context (engine);return ; }@@ -751,6 +912,89 @@ static void execlists_dequeue(struct intel_engine_cs *engine) last->tail = last->wa_tail; } +while (rb) {/* XXX virtual is always taking precedence */ +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +struct i915_request *rq; + +spin_lock (&ve->base.timeline.lock); + + rq = ve->request; +if (unlikely (!rq)) {/* lost the race to a sibling */ +spin_unlock (&ve->base.timeline.lock); +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + rb =rb_first_cached (&execlists->virtual); +continue ; + } + +GEM_BUG_ON (rq != ve->request); +GEM_BUG_ON (rq->engine != &ve->base); +GEM_BUG_ON (rq->hw_context != &ve->context); + +if (rq_prio (rq) >=queue_prio (execlists)) { +if (!virtual_matches (ve, rq, engine)) { +spin_unlock (&ve->base.timeline.lock); + rb =rb_next (rb); +continue ; + } + +if (last && !can_merge_rq (last, rq)) { +spin_unlock (&ve->base.timeline.lock); +return ;/* leave this rq for another engine */ + } + +GEM_TRACE ("%s: virtual rq=%llx:%lld%s, new engine? %s\n" , + engine->name, + rq->fence.context, + rq->fence.seqno, +i915_request_completed (rq) ?"!" : +i915_request_started (rq) ?"*" : +"" , +yesno (engine != ve->siblings[0 ])); + + ve->request =NULL ; + ve->base.execlists.queue_priority_hint =INT_MIN ; +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + + rq->engine = engine; + +if (engine != ve->siblings[0 ]) { +u32 *regs = ve->context.lrc_reg_state; +unsigned int n; + +GEM_BUG_ON (READ_ONCE (ve->context.active)); +virtual_update_register_offsets (regs, engine); + +/* +* Move the bound engine to the top of the list +* for future execution. We then kick this +* tasklet first before checking others, so that +* we preferentially reuse this set of bound +* registers. +*/ +for (n =1 ; n < ve->num_siblings; n++) { +if (ve->siblings[n] == engine) { +swap (ve->siblings[n], + ve->siblings[0 ]); +break ; + } + } + +GEM_BUG_ON (ve->siblings[0 ] != engine); + } + +__i915_request_submit (rq); +trace_i915_request_in (rq,port_index (port, execlists)); + submit = true; + last = rq; + } + +spin_unlock (&ve->base.timeline.lock); +break ; + } +while ((rb =rb_first_cached (&execlists->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;@@ -1874,6 +2118,25 @@ static void reset_csb_pointers(struct intel_engine_execlists *execlists) &execlists->csb_status[reset_value]); } +static struct i915_request *active_request (struct i915_request *rq) +{ +const struct list_head *const list = &rq->engine->timeline.requests; +const struct intel_context *const context = rq->hw_context; +struct i915_request *active =NULL ; + +list_for_each_entry_from_reverse (rq, list, link) { +if (i915_request_completed (rq)) +break ; + +if (rq->hw_context != context) +break ; + + active = rq; + } + +return active; +} +static void __execlists_reset (struct intel_engine_cs *engine,bool stalled) {struct intel_engine_execlists *const execlists = &engine->execlists;@@ -1894,7 +2157,8 @@ static void __execlists_reset(struct intel_engine_cs *engine, bool stalled)if (!port_isset (execlists->port)) goto out_clear; - ce =port_request (execlists->port)->hw_context; + rq =port_request (execlists->port); + ce = rq->hw_context;/* * Catch up with any missed context-switch interrupts. @@ -1907,16 +2171,10 @@ static void __execlists_reset(struct intel_engine_cs *engine, bool stalled)*/ execlists_cancel_port_requests (execlists); -/* Push back any incomplete requests for replay after the reset. */ - rq =__unwind_incomplete_requests (engine); + rq =active_request (rq);if (!rq) goto out_replay; -if (rq->hw_context != ce) {/* caught just before a CS event */ - rq =NULL ; - goto out_replay; - } -/* * If this request hasn't started yet, e.g. it is waiting on a * semaphore, we need to avoid skipping the request or else we @@ -1963,13 +2221,16 @@ static void __execlists_reset(struct intel_engine_cs *engine, bool stalled) }execlists_init_reg_state (regs, ce, engine, ce->ring); -/* Rerun the request; its payload has been neutered (if guilty). */ out_replay: +/* Rerun the request; its payload has been neutered (if guilty). */ ce->ring->head = rq ?intel_ring_wrap (ce->ring, rq->head) : ce->ring->tail;intel_ring_update_space (ce->ring);__execlists_update_reg_state (ce, engine); +/* Push back any incomplete requests for replay after the reset. */ +__unwind_incomplete_requests (engine); + out_clear:execlists_clear_all_active (execlists); }@@ -2043,6 +2304,26 @@ static void execlists_cancel_requests(struct intel_engine_cs *engine)i915_priolist_free (p); } +/* Cancel all attached virtual engines */ +while ((rb =rb_first_cached (&execlists->virtual))) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); + +rb_erase_cached (rb, &execlists->virtual); +RB_CLEAR_NODE (rb); + +spin_lock (&ve->base.timeline.lock); +if (ve->request) { + ve->request->engine = engine; +__i915_request_submit (ve->request); +dma_fence_set_error (&ve->request->fence, -EIO ); +i915_request_mark_complete (ve->request); + ve->base.execlists.queue_priority_hint =INT_MIN ; + ve->request =NULL ; + } +spin_unlock (&ve->base.timeline.lock); + } +/* Remaining _unready_ requests will be nop'ed when submitted */ execlists->queue_priority_hint =INT_MIN ;@@ -2760,6 +3041,318 @@ static int execlists_context_deferred_alloc(struct intel_context *ce,return ret; } +static void virtual_context_destroy (struct kref *kref) +{ +struct virtual_engine *ve = +container_of (kref,typeof (*ve), context.ref); +unsigned int n; + +GEM_BUG_ON (ve->request); +GEM_BUG_ON (ve->context.active); + +for (n =0 ; n < ve->num_siblings; n++) { +struct intel_engine_cs *sibling = ve->siblings[n]; +struct rb_node *node = &ve->nodes[sibling->id].rb; + +if (RB_EMPTY_NODE (node)) +continue ; + +spin_lock_irq (&sibling->timeline.lock); + +if (!RB_EMPTY_NODE (node)) +rb_erase_cached (node, &sibling->execlists.virtual); + +spin_unlock_irq (&sibling->timeline.lock); + } +GEM_BUG_ON (__tasklet_is_scheduled (&ve->base.execlists.tasklet)); + +if (ve->context.state) +__execlists_context_fini (&ve->context); + +i915_timeline_fini (&ve->base.timeline); +kfree (ve); +} + +static void virtual_engine_initial_hint (struct virtual_engine *ve) +{ +int swp; + +/* +* Pick a random sibling on starting to help spread the load around. +* +* New contexts are typically created with exactly the same order +* of siblings, and often started in batches. Due to the way we iterate +* the array of sibling when submitting requests, sibling[0] is +* prioritised for dequeuing. If we make sure that sibling[0] is fairly +* randomised across the system, we also help spread the load by the +* first engine we inspect being different each time. +* +* NB This does not force us to execute on this engine, it will just +* typically be the first we inspect for submission. +*/ + swp =prandom_u32_max (ve->num_siblings); +if (!swp) +return ; + +swap (ve->siblings[swp], ve->siblings[0 ]); +virtual_update_register_offsets (ve->context.lrc_reg_state, + ve->siblings[0 ]); +} + +static int virtual_context_pin (struct intel_context *ce) +{ +struct virtual_engine *ve =container_of (ce,typeof (*ve), context); +int err; + +/* Note: we must use a real engine class for setting up reg state */ + err =__execlists_context_pin (ce, ve->siblings[0 ]); +if (err) +return err; + +virtual_engine_initial_hint (ve); +return 0 ; +} + +static void virtual_context_enter (struct intel_context *ce) +{ +struct virtual_engine *ve =container_of (ce,typeof (*ve), context); +unsigned int n; + +for (n =0 ; n < ve->num_siblings; n++) +intel_engine_pm_get (ve->siblings[n]); +} + +static void virtual_context_exit (struct intel_context *ce) +{ +struct virtual_engine *ve =container_of (ce,typeof (*ve), context); +unsigned int n; + +for (n =0 ; n < ve->num_siblings; n++) +intel_engine_pm_put (ve->siblings[n]); +} + +static const struct intel_context_ops virtual_context_ops = { + .pin = virtual_context_pin, + .unpin = execlists_context_unpin, + + .enter = virtual_context_enter, + .exit = virtual_context_exit, + + .destroy = virtual_context_destroy, +}; + +static void virtual_submission_tasklet (unsigned long data) +{ +struct virtual_engine *const ve = (struct virtual_engine *)data; +const int prio = ve->base.execlists.queue_priority_hint; +unsigned int n; + +local_irq_disable (); +for (n =0 ;READ_ONCE (ve->request) && n < ve->num_siblings; n++) { +struct intel_engine_cs *sibling = ve->siblings[n]; +struct ve_node *const node = &ve->nodes[sibling->id]; +struct rb_node **parent, *rb; +bool first; + +spin_lock (&sibling->timeline.lock); + +if (!RB_EMPTY_NODE (&node->rb)) { +/* +* Cheat and avoid rebalancing the tree if we can +* reuse this node in situ. +*/ + first =rb_first_cached (&sibling->execlists.virtual) == + &node->rb; +if (prio == node->prio || (prio > node->prio && first)) + goto submit_engine; + +rb_erase_cached (&node->rb, &sibling->execlists.virtual); + } + + rb =NULL ; + first = true; + parent = &sibling->execlists.virtual.rb_root.rb_node; +while (*parent) { +struct ve_node *other; + + rb = *parent; + other =rb_entry (rb,typeof (*other), rb); +if (prio > other->prio) { + parent = &rb->rb_left; + }else { + parent = &rb->rb_right; + first = false; + } + } + +rb_link_node (&node->rb, rb, parent); +rb_insert_color_cached (&node->rb, + &sibling->execlists.virtual, + first); + +submit_engine: +GEM_BUG_ON (RB_EMPTY_NODE (&node->rb)); + node->prio = prio; +if (first && prio > sibling->execlists.queue_priority_hint) { + sibling->execlists.queue_priority_hint = prio; +tasklet_hi_schedule (&sibling->execlists.tasklet); + } + +spin_unlock (&sibling->timeline.lock); + } +local_irq_enable (); +} + +static void virtual_submit_request (struct i915_request *rq) +{ +struct virtual_engine *ve =to_virtual_engine (rq->engine); + +GEM_TRACE ("%s: rq=%llx:%lld\n" , + ve->base.name, + rq->fence.context, + rq->fence.seqno); + +GEM_BUG_ON (ve->base.submit_request != virtual_submit_request); + +GEM_BUG_ON (ve->request); + ve->base.execlists.queue_priority_hint =rq_prio (rq); +WRITE_ONCE (ve->request, rq); + +tasklet_schedule (&ve->base.execlists.tasklet); +} + +struct intel_context * +intel_execlists_create_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs **siblings, +unsigned int count) +{ +struct virtual_engine *ve; +unsigned int n; +int err; + +if (count ==0 ) +return ERR_PTR (-EINVAL ); + +if (count ==1 ) +return intel_context_create (ctx, siblings[0 ]); + + ve =kzalloc (struct_size (ve, siblings, count),GFP_KERNEL ); +if (!ve) +return ERR_PTR (-ENOMEM ); + + ve->base.i915 = ctx->i915; + ve->base.id =-1 ; + ve->base.class =OTHER_CLASS ; + ve->base.uabi_class =I915_ENGINE_CLASS_INVALID ; + ve->base.instance =I915_ENGINE_CLASS_INVALID_VIRTUAL ; + ve->base.flags =I915_ENGINE_IS_VIRTUAL ; + +snprintf (ve->base.name,sizeof (ve->base.name),"virtual" ); + + err =i915_timeline_init (ctx->i915, &ve->base.timeline,NULL ); +if (err) + goto err_put; +i915_timeline_set_subclass (&ve->base.timeline,TIMELINE_VIRTUAL ); + +intel_engine_init_execlists (&ve->base); + + ve->base.cops = &virtual_context_ops; + ve->base.request_alloc = execlists_request_alloc; + + ve->base.schedule = i915_schedule; + ve->base.submit_request = virtual_submit_request; + + ve->base.execlists.queue_priority_hint =INT_MIN ; +tasklet_init (&ve->base.execlists.tasklet, + virtual_submission_tasklet, + (unsigned long )ve); + +intel_context_init (&ve->context, ctx, &ve->base); + +for (n =0 ; n < count; n++) { +struct intel_engine_cs *sibling = siblings[n]; + +GEM_BUG_ON (!is_power_of_2 (sibling->mask)); +if (sibling->mask & ve->base.mask) { +DRM_DEBUG ("duplicate %s entry in load balancer\n" , + sibling->name); + err = -EINVAL ; + goto err_put; + } + +/* +* The virtual engine implementation is tightly coupled to +* the execlists backend -- we push out request directly +* into a tree inside each physical engine. We could support +* layering if we handle cloning of the requests and +* submitting a copy into each backend. +*/ +if (sibling->execlists.tasklet.func != + execlists_submission_tasklet) { + err = -ENODEV ; + goto err_put; + } + +GEM_BUG_ON (RB_EMPTY_NODE (&ve->nodes[sibling->id].rb)); +RB_CLEAR_NODE (&ve->nodes[sibling->id].rb); + + ve->siblings[ve->num_siblings++] = sibling; + ve->base.mask |= sibling->mask; + +/* +* All physical engines must be compatible for their emission +* functions (as we build the instructions during request +* construction and do not alter them before submission +* on the physical engine). We use the engine class as a guide +* here, although that could be refined. +*/ +if (ve->base.class !=OTHER_CLASS ) { +if (ve->base.class != sibling->class) { +DRM_DEBUG ("invalid mixing of engine class, sibling %d, already %d\n" , + sibling->class, ve->base.class); + err = -EINVAL ; + goto err_put; + } +continue ; + } + + ve->base.class = sibling->class; + ve->base.uabi_class = sibling->uabi_class; +snprintf (ve->base.name,sizeof (ve->base.name), +"v%dx%d" , ve->base.class, count); + ve->base.context_size = sibling->context_size; + + ve->base.emit_bb_start = sibling->emit_bb_start; + ve->base.emit_flush = sibling->emit_flush; + ve->base.emit_init_breadcrumb = sibling->emit_init_breadcrumb; + ve->base.emit_fini_breadcrumb = sibling->emit_fini_breadcrumb; + ve->base.emit_fini_breadcrumb_dw = + sibling->emit_fini_breadcrumb_dw; + } + +return &ve->context; + +err_put: +intel_context_put (&ve->context); +return ERR_PTR (err); +} + +struct intel_context * +intel_execlists_clone_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs *src) +{ +struct virtual_engine *se =to_virtual_engine (src); +struct intel_context *dst; + + dst =intel_execlists_create_virtual (ctx, + se->siblings, + se->num_siblings); +if (IS_ERR (dst)) +return dst; + +return dst; +} + void intel_execlists_show_requests(struct intel_engine_cs *engine, struct drm_printer *m, void (*show_request)(struct drm_printer *m,@@ -2817,6 +3410,29 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,show_request (m, last,"\t\tQ " ); } + last =NULL ; + count =0 ; +for (rb =rb_first_cached (&execlists->virtual); rb; rb =rb_next (rb)) { +struct virtual_engine *ve = +rb_entry (rb,typeof (*ve), nodes[engine->id].rb); +struct i915_request *rq =READ_ONCE (ve->request); + +if (rq) { +if (count++ < max -1 ) +show_request (m, rq,"\t\tV " ); +else + last = rq; + } + } +if (last) { +if (count > max) { +drm_printf (m, +"\t\t...skipping %d virtual requests...\n" , + count - max); + } +show_request (m, last,"\t\tV " ); + } +spin_unlock_irqrestore (&engine->timeline.lock, flags); }drivers/gpu/drm/i915/gt/intel_lrc.h +9
-0@@ -114,4 +114,13 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine, const char *prefix), unsigned int max); +struct intel_context * +intel_execlists_create_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs **siblings, +unsigned int count); + +struct intel_context * +intel_execlists_clone_virtual (struct i915_gem_context *ctx, +struct intel_engine_cs *src); +#endif /* _INTEL_LRC_H_ */ drivers/gpu/drm/i915/gt/selftest_lrc.c +180
-0@@ -1301,6 +1301,185 @@ static int live_preempt_smoke(void *arg)return err; } +static int nop_virtual_engine (struct drm_i915_private *i915, +struct intel_engine_cs **siblings, +unsigned int nsibling, +unsigned int nctx, +unsigned int flags) +#define CHAIN BIT(0) +{ +IGT_TIMEOUT (end_time); +struct i915_request *request[16 ]; +struct i915_gem_context *ctx[16 ]; +struct intel_context *ve[16 ]; +unsigned long n, prime, nc; +struct igt_live_test t; +ktime_t times[2 ] = {}; +int err; + +GEM_BUG_ON (!nctx || nctx >ARRAY_SIZE (ctx)); + +for (n =0 ; n < nctx; n++) { + ctx[n] =kernel_context (i915); +if (!ctx[n]) { + err = -ENOMEM ; + nctx = n; + goto out; + } + + ve[n] =intel_execlists_create_virtual (ctx[n], + siblings, nsibling); +if (IS_ERR (ve[n])) { +kernel_context_close (ctx[n]); + err =PTR_ERR (ve[n]); + nctx = n; + goto out; + } + + err =intel_context_pin (ve[n]); +if (err) { +intel_context_put (ve[n]); +kernel_context_close (ctx[n]); + nctx = n; + goto out; + } + } + + err =igt_live_test_begin (&t, i915, __func__, ve[0 ]->engine->name); +if (err) + goto out; + +for_each_prime_number_from (prime,1 ,8192 ) { + times[1 ] =ktime_get_raw (); + +if (flags &CHAIN ) { +for (nc =0 ; nc < nctx; nc++) { +for (n =0 ; n < prime; n++) { + request[nc] = +i915_request_create (ve[nc]); +if (IS_ERR (request[nc])) { + err =PTR_ERR (request[nc]); + goto out; + } + +i915_request_add (request[nc]); + } + } + }else { +for (n =0 ; n < prime; n++) { +for (nc =0 ; nc < nctx; nc++) { + request[nc] = +i915_request_create (ve[nc]); +if (IS_ERR (request[nc])) { + err =PTR_ERR (request[nc]); + goto out; + } + +i915_request_add (request[nc]); + } + } + } + +for (nc =0 ; nc < nctx; nc++) { +if (i915_request_wait (request[nc], +I915_WAIT_LOCKED , +HZ /10 ) <0 ) { +pr_err ("%s(%s): wait for %llx:%lld timed out\n" , + __func__, ve[0 ]->engine->name, + request[nc]->fence.context, + request[nc]->fence.seqno); + +GEM_TRACE ("%s(%s) failed at request %llx:%lld\n" , + __func__, ve[0 ]->engine->name, + request[nc]->fence.context, + request[nc]->fence.seqno); +GEM_TRACE_DUMP (); +i915_gem_set_wedged (i915); +break ; + } + } + + times[1 ] =ktime_sub (ktime_get_raw (), times[1 ]); +if (prime ==1 ) + times[0 ] = times[1 ]; + +if (__igt_timeout (end_time,NULL )) +break ; + } + + err =igt_live_test_end (&t); +if (err) + goto out; + +pr_info ("Requestx%d latencies on %s: 1 = %lluns, %lu = %lluns\n" , + nctx, ve[0 ]->engine->name,ktime_to_ns (times[0 ]), + prime,div64_u64 (ktime_to_ns (times[1 ]), prime)); + +out: +if (igt_flush_test (i915,I915_WAIT_LOCKED )) + err = -EIO ; + +for (nc =0 ; nc < nctx; nc++) { +intel_context_unpin (ve[nc]); +intel_context_put (ve[nc]); +kernel_context_close (ctx[nc]); + } +return err; +} + +static int live_virtual_engine (void *arg) +{ +struct drm_i915_private *i915 = arg; +struct intel_engine_cs *siblings[MAX_ENGINE_INSTANCE +1 ]; +struct intel_engine_cs *engine; +enum intel_engine_id id; +unsigned int class, inst; +int err = -ENODEV ; + +if (USES_GUC_SUBMISSION (i915)) +return 0 ; + +mutex_lock (&i915->drm.struct_mutex); + +for_each_engine (engine, i915, id) { + err =nop_virtual_engine (i915, &engine,1 ,1 ,0 ); +if (err) { +pr_err ("Failed to wrap engine %s: err=%d\n" , + engine->name, err); + goto out_unlock; + } + } + +for (class =0 ; class <=MAX_ENGINE_CLASS ; class++) { +int nsibling, n; + + nsibling =0 ; +for (inst =0 ; inst <=MAX_ENGINE_INSTANCE ; inst++) { +if (!i915->engine_class[class][inst]) +break ; + + siblings[nsibling++] = i915->engine_class[class][inst]; + } +if (nsibling <2 ) +continue ; + +for (n =1 ; n <= nsibling +1 ; n++) { + err =nop_virtual_engine (i915, siblings, nsibling, + n,0 ); +if (err) + goto out_unlock; + } + + err =nop_virtual_engine (i915, siblings, nsibling, n,CHAIN ); +if (err) + goto out_unlock; + } + +out_unlock: +mutex_unlock (&i915->drm.struct_mutex); +return err; +} +int intel_execlists_live_selftests (struct drm_i915_private *i915) {static const struct i915_subtest tests[] = {@@ -1313,6 +1492,7 @@ int intel_execlists_live_selftests(struct drm_i915_private *i915)SUBTEST (live_chain_preempt),SUBTEST (live_preempt_hang),SUBTEST (live_preempt_smoke), + SUBTEST(live_virtual_engine), };if (!HAS_EXECLISTS (i915))drivers/gpu/drm/i915/i915_gem.h +5
-0@@ -91,4 +91,9 @@ static inline bool __tasklet_enable(struct tasklet_struct *t) return atomic_dec_and_test(&t->count); } +static inline bool __tasklet_is_scheduled (struct tasklet_struct *t) +{ +return test_bit (TASKLET_STATE_SCHED , &t->state); +} +#endif /* __I915_GEM_H__ */ drivers/gpu/drm/i915/i915_gem_context.c +114
-4@@ -86,6 +86,7 @@*/ #include <linux/log2.h> +#include <linux/nospec.h> #include <drm/i915_drm.h> @@ -1209,7 +1210,6 @@ __intel_context_reconfigure_sseu(struct intel_context *ce,int ret;GEM_BUG_ON (INTEL_GEN (ce->gem_context->i915) <8 ); -GEM_BUG_ON (ce->engine->id !=RCS0 ); ret =intel_context_lock_pinned (ce);if (ret)@@ -1397,7 +1397,102 @@ struct set_engines {struct i915_gem_engines *engines; }; +static int +set_engines__load_balance (struct i915_user_extension __user *base,void *data) +{ +struct i915_context_engines_load_balance __user *ext = +container_of_user (base,typeof (*ext), base); +const struct set_engines *set = data; +struct intel_engine_cs *stack[16 ]; +struct intel_engine_cs **siblings; +struct intel_context *ce; +u16 num_siblings, idx; +unsigned int n; +int err; + +if (!HAS_EXECLISTS (set->ctx->i915)) +return -ENODEV ; + +if (USES_GUC_SUBMISSION (set->ctx->i915)) +return -ENODEV ;/* not implement yet */ + +if (get_user (idx, &ext->engine_index)) +return -EFAULT ; + +if (idx >= set->engines->num_engines) { +DRM_DEBUG ("Invalid placement value, %d >= %d\n" , + idx, set->engines->num_engines); +return -EINVAL ; + } + + idx =array_index_nospec (idx, set->engines->num_engines); +if (set->engines->engines[idx]) { +DRM_DEBUG ("Invalid placement[%d], already occupied\n" , idx); +return -EEXIST ; + } + +if (get_user (num_siblings, &ext->num_siblings)) +return -EFAULT ; + + err =check_user_mbz (&ext->flags); +if (err) +return err; + +for (n =0 ; n <ARRAY_SIZE (ext->mbz64); n++) { + err =check_user_mbz (&ext->mbz64[n]); +if (err) +return err; + } + + siblings = stack; +if (num_siblings >ARRAY_SIZE (stack)) { + siblings =kmalloc_array (num_siblings, +sizeof (*siblings), +GFP_KERNEL ); +if (!siblings) +return -ENOMEM ; + } + +for (n =0 ; n < num_siblings; n++) { +struct i915_engine_class_instance ci; + +if (copy_from_user (&ci, &ext->engines[n],sizeof (ci))) { + err = -EFAULT ; + goto out_siblings; + } + + siblings[n] =intel_engine_lookup_user (set->ctx->i915, + ci.engine_class, + ci.engine_instance); +if (!siblings[n]) { +DRM_DEBUG ("Invalid sibling[%d]: { class:%d, inst:%d }\n" , + n, ci.engine_class, ci.engine_instance); + err = -EINVAL ; + goto out_siblings; + } + } + + ce =intel_execlists_create_virtual (set->ctx, siblings, n); +if (IS_ERR (ce)) { + err =PTR_ERR (ce); + goto out_siblings; + } + +if (cmpxchg (&set->engines->engines[idx],NULL , ce)) { +intel_context_put (ce); + err = -EEXIST ; + goto out_siblings; + } + +out_siblings: +if (siblings != stack) +kfree (siblings); + +return err; +} +static const i915_user_extension_fn set_engines__extensions[] = { + [I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE ] = set_engines__load_balance, }; static int@@ -1696,14 +1791,29 @@ static int clone_engines(struct i915_gem_context *dst, clone->i915 = dst->i915;for (n =0 ; n < e->num_engines; n++) { +struct intel_engine_cs *engine; +if (!e->engines[n]) { clone->engines[n] =NULL ;continue ; } + engine = e->engines[n]->engine; - clone->engines[n] = -intel_context_create (dst, e->engines[n]->engine); -if (!clone->engines[n]) { +/* +* Virtual engines are singletons; they can only exist +* inside a single context, because they embed their +* HW context... As each virtual context implies a single +* timeline (each engine can only dequeue a single request +* at any time), it would be surprising for two contexts +* to use the same engine. So let's create a copy of +* the virtual engine instead. +*/ +if (intel_engine_is_virtual (engine)) + clone->engines[n] = +intel_execlists_clone_virtual (dst, engine); +else + clone->engines[n] =intel_context_create (dst, engine); +if (IS_ERR_OR_NULL (clone->engines[n])) {__free_engines (clone, n); goto err_unlock; }drivers/gpu/drm/i915/i915_scheduler.c +15
-3@@ -248,17 +248,26 @@ sched_lock_engine(const struct i915_sched_node *node,struct intel_engine_cs *locked, struct sched_cache *cache) { - struct intel_engine_cs *engine = node_to_request(node)->engine; + const struct i915_request *rq = node_to_request(node); +struct intel_engine_cs *engine;GEM_BUG_ON (!locked); -if (engine != locked) { +/* +* Virtual engines complicate acquiring the engine timeline lock, +* as their rq->engine pointer is not stable until under that +* engine lock. The simple ploy we use is to take the lock then +* check that the rq still belongs to the newly locked engine. +*/ +while (locked != (engine =READ_ONCE (rq->engine))) {spin_unlock (&locked->timeline.lock);memset (cache,0 ,sizeof (*cache));spin_lock (&engine->timeline.lock); + locked = engine; } -return engine; +GEM_BUG_ON (locked != engine); +return locked; } static bool inflight(const struct i915_request *rq,@@ -371,8 +380,11 @@ static void __i915_schedule(struct i915_request *rq,if (prio <= node->attr.priority ||node_signaled (node))continue ; +GEM_BUG_ON (node_to_request (node)->engine != engine); + node->attr.priority = prio;if (!list_empty (&node->link)) { +GEM_BUG_ON (intel_engine_is_virtual (engine));if (!cache.priolist) cache.priolist = i915_sched_lookup_priolist(engine,drivers/gpu/drm/i915/i915_timeline_types.h +1
-0@@ -26,6 +26,7 @@ struct i915_timeline {spinlock_t lock;#define TIMELINE_CLIENT 0/* default subclass */ #define TIMELINE_ENGINE 1 +#define TIMELINE_VIRTUAL 2struct mutex mutex;/* protects the flow of requests */ unsigned int pin_count;include/uapi/drm/i915_drm.h +34
-0@@ -137,6 +137,7 @@ struct i915_engine_class_instance {__u16 engine_class;/* see enum drm_i915_gem_engine_class */ __u16 engine_instance;#define I915_ENGINE_CLASS_INVALID_NONE -1 +#define I915_ENGINE_CLASS_INVALID_VIRTUAL -2 };/** @@ -1607,8 +1608,46 @@ struct drm_i915_gem_context_param_sseu {__u32 rsvd; }; +/* +* i915_context_engines_load_balance: +* +* Enable load balancing across this set of engines. +* +* Into the I915_EXEC_DEFAULT slot [0], a virtual engine is created that when +* used will proxy the execbuffer request onto one of the set of engines +* in such a way as to distribute the load evenly across the set. +* +* The set of engines must be compatible (e.g. the same HW class) as they +* will share the same logical GPU context and ring. +* +* To intermix rendering with the virtual engine and direct rendering onto +* the backing engines (bypassing the load balancing proxy), the context must +* be defined to use a single timeline for all engines. +*/ +struct i915_context_engines_load_balance { +struct i915_user_extension base; + +__u16 engine_index; +__u16 num_siblings; +__u32 flags;/* all undefined flags must be zero */ + +__u64 mbz64[1 ];/* reserved for future use; must be zero */ + +struct i915_engine_class_instance engines[0 ]; +} __attribute__((packed)); + +#define I915_DEFINE_CONTEXT_ENGINES_LOAD_BALANCE (name__,N__ ) struct { \ + struct i915_user_extension base; \ + __u16 engine_index; \ + __u16 num_siblings; \ + __u32 flags; \
include/uapi/drm/i915_drm.h struct drm_i915_gem_context_param_sseu { · line 1653
Quoted 10 lines
include/uapi/drm/i915_drm.h +5
-0+__u64 mbz64[1 ]; \ +struct i915_engine_class_instance engines[N__ ]; \ +} __attribute__((packed))name__ + struct i915_context_param_engines {__u64 extensions;/* linked chain of extension blocks, 0 terminates */ +#define I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE 0/* see i915_context_engines_load_balance */ struct i915_engine_class_instance engines[0 ]; } __attribute__((packed));
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 20/45 drm/i915: Apply an execution_mask to the virtual_engine
In reply to Chris WilsonAllow the user to direct which physical engines of the virtual engine they wish to execute one, as sometimes it is necessary to override the load balancing algorithm.
v2: Only kick the virtual engines on context-out if required
--- drivers/gpu/drm/i915/gt/intel_lrc.c | 67 +++++++++++++ drivers/gpu/drm/i915/gt/selftest_lrc.c | 131 +++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_request.c | 1 + drivers/gpu/drm/i915/i915_request.h | 3 + 4 files changed, 202 insertions(+)
drivers/gpu/drm/i915/gt/intel_lrc.c +67 -0
@@ -549,6 +549,15 @@ execlists_context_schedule_in(struct i915_request *rq) rq->hw_context->active = rq->engine; } +static void kick_siblings (struct i915_request *rq) +{ +struct virtual_engine *ve =to_virtual_engine (rq->hw_context->engine); +struct i915_request *next =READ_ONCE (ve->request); + +if (next && next->execution_mask & ~rq->execution_mask) +tasklet_schedule (&ve->base.execlists.tasklet); +} +static inline void execlists_context_schedule_out (struct i915_request *rq,unsigned long status) {
@@ -556,6 +565,18 @@ execlists_context_schedule_out(struct i915_request *rq, unsigned long status)intel_engine_context_out (rq->engine);execlists_context_status_change (rq, status);trace_i915_request_out (rq); + +/* +* If this is part of a virtual engine, its next request may have +* been blocked waiting for access to the active context. We have +* to kick all the siblings again in case we need to switch (e.g. +* the next request is not runnable on this engine). Hopefully, +* we will already have submitted the next request before the +* tasklet runs and do not need to rebuild each virtual tree +* and kick everyone again. +*/ +if (rq->engine != rq->hw_context->engine) +kick_siblings (rq); }static u64 execlists_update_context (struct i915_request *rq)
@@ -783,6 +804,9 @@ static bool virtual_matches(const struct virtual_engine *ve, {const struct intel_engine_cs *active; +if (!(rq->execution_mask & engine->mask))/* We peeked too soon! */ +return false; +/* * We track when the HW has completed saving the context image * (i.e. when we have seen the final CS event switching out of
@@ -3141,12 +3165,44 @@ static const struct intel_context_ops virtual_context_ops = { .destroy = virtual_context_destroy, }; +static intel_engine_mask_t virtual_submission_mask (struct virtual_engine *ve) +{ +struct i915_request *rq; +intel_engine_mask_t mask; + + rq =READ_ONCE (ve->request); +if (!rq) +return 0 ; + +/* The rq is ready for submission; rq->execution_mask is now stable. */ + mask = rq->execution_mask; +if (unlikely (!mask)) { +/* Invalid selection, submit to a random engine in error */ +i915_request_skip (rq, -ENODEV ); + mask = ve->siblings[0 ]->mask; + } + +GEM_TRACE ("%s: rq=%llx:%lld, mask=%x, prio=%d\n" , + ve->base.name, + rq->fence.context, rq->fence.seqno, + mask, ve->base.execlists.queue_priority_hint); + +return mask; +} +static void virtual_submission_tasklet (unsigned long data) {struct virtual_engine *const ve = (struct virtual_engine *)data;const int prio = ve->base.execlists.queue_priority_hint; +intel_engine_mask_t mask;unsigned int n; +rcu_read_lock (); + mask =virtual_submission_mask (ve); +rcu_read_unlock (); +if (unlikely (!mask)) +return ; +local_irq_disable ();for (n =0 ;READ_ONCE (ve->request) && n < ve->num_siblings; n++) {struct intel_engine_cs *sibling = ve->siblings[n];
@@ -3154,6 +3210,17 @@ static void virtual_submission_tasklet(unsigned long data)struct rb_node **parent, *rb;bool first; +if (unlikely (!(mask & sibling->mask))) { +if (!RB_EMPTY_NODE (&node->rb)) { +spin_lock (&sibling->timeline.lock); +rb_erase_cached (&node->rb, + &sibling->execlists.virtual); +RB_CLEAR_NODE (&node->rb); +spin_unlock (&sibling->timeline.lock); + } +continue ; + } +spin_lock (&sibling->timeline.lock);if (!RB_EMPTY_NODE (&node->rb)) {
drivers/gpu/drm/i915/gt/selftest_lrc.c +131 -0
143 lines not on this page · raw message
drivers/gpu/drm/i915/i915_request.c +1 -0
@@ -688,6 +688,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) rq->batch =NULL ; rq->capture_list =NULL ; rq->waitboost = false; + rq->execution_mask =ALL_ENGINES ;INIT_LIST_HEAD (&rq->active_list);INIT_LIST_HEAD (&rq->execute_cb);
drivers/gpu/drm/i915/i915_request.h +3 -0
@@ -28,6 +28,8 @@#include <linux/dma-fence.h> #include <linux/lockdep.h> +#include "gt/intel_engine_types.h" +#include "i915_gem.h" #include "i915_scheduler.h" #include "i915_selftest.h"
@@ -156,6 +158,7 @@ struct i915_request {*/ struct i915_sched_node sched;struct i915_dependency dep; +intel_engine_mask_t execution_mask;/* * A convenience pointer to the current breadcrumb value stored in
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 20/45] drm/i915: Apply an execution_mask to the virtual_engine
Quoted 94 lines · Chris Wilson
Allow the user to direct which physical engines of the virtual engine they wish to execute one, as sometimes it is necessary to override the load balancing algorithm.
v2: Only kick the virtual engines on context-out if required
Signed-off-by Chris Wilson <[email protected]>Cc Tvrtko Ursulin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_lrc.c | 67 +++++++++++++ drivers/gpu/drm/i915/gt/selftest_lrc.c | 131 +++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_request.c | 1 + drivers/gpu/drm/i915/i915_request.h | 3 + 4 files changed, 202 insertions(+)drivers/gpu/drm/i915/gt/intel_lrc.c +49
-0@@ -549,6 +549,15 @@ execlists_context_schedule_in(struct i915_request *rq) rq->hw_context->active = rq->engine; } +static void kick_siblings (struct i915_request *rq) +{ +struct virtual_engine *ve =to_virtual_engine (rq->hw_context->engine); +struct i915_request *next =READ_ONCE (ve->request); + +if (next && next->execution_mask & ~rq->execution_mask) +tasklet_schedule (&ve->base.execlists.tasklet); +} +static inline void execlists_context_schedule_out (struct i915_request *rq,unsigned long status) {@@ -556,6 +565,18 @@ execlists_context_schedule_out(struct i915_request *rq, unsigned long status)intel_engine_context_out (rq->engine);execlists_context_status_change (rq, status);trace_i915_request_out (rq); + +/* +* If this is part of a virtual engine, its next request may have +* been blocked waiting for access to the active context. We have +* to kick all the siblings again in case we need to switch (e.g. +* the next request is not runnable on this engine). Hopefully, +* we will already have submitted the next request before the +* tasklet runs and do not need to rebuild each virtual tree +* and kick everyone again. +*/ +if (rq->engine != rq->hw_context->engine) +kick_siblings (rq); }static u64 execlists_update_context (struct i915_request *rq)@@ -783,6 +804,9 @@ static bool virtual_matches(const struct virtual_engine *ve, {const struct intel_engine_cs *active; +if (!(rq->execution_mask & engine->mask))/* We peeked too soon! */ +return false; +/* * We track when the HW has completed saving the context image * (i.e. when we have seen the final CS event switching out of @@ -3141,12 +3165,44 @@ static const struct intel_context_ops virtual_context_ops = { .destroy = virtual_context_destroy, }; +static intel_engine_mask_t virtual_submission_mask (struct virtual_engine *ve) +{ +struct i915_request *rq; +intel_engine_mask_t mask; + + rq =READ_ONCE (ve->request); +if (!rq) +return 0 ; + +/* The rq is ready for submission; rq->execution_mask is now stable. */ + mask = rq->execution_mask; +if (unlikely (!mask)) { +/* Invalid selection, submit to a random engine in error */ +i915_request_skip (rq, -ENODEV ); + mask = ve->siblings[0 ]->mask; + } + +GEM_TRACE ("%s: rq=%llx:%lld, mask=%x, prio=%d\n" , + ve->base.name, + rq->fence.context, rq->fence.seqno, + mask, ve->base.execlists.queue_priority_hint); + +return mask; +} +static void virtual_submission_tasklet (unsigned long data)
drivers/gpu/drm/i915/gt/intel_lrc.c static const struct intel_context_ops virtual_context_ops = { · line 3203
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +5
-0{struct virtual_engine *const ve = (struct virtual_engine *)data;const int prio = ve->base.execlists.queue_priority_hint; +intel_engine_mask_t mask;unsigned int n; +rcu_read_lock (); + mask =virtual_submission_mask (ve); +rcu_read_unlock (); +if (unlikely (!mask))
Is the rcu_lock think solely for the same protection against wedging in submit_notify?
Regards,
Tvrtko
Quoted 199 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +13
-0+return ; +local_irq_disable ();for (n =0 ;READ_ONCE (ve->request) && n < ve->num_siblings; n++) {struct intel_engine_cs *sibling = ve->siblings[n];@@ -3154,6 +3210,17 @@ static void virtual_submission_tasklet(unsigned long data)struct rb_node **parent, *rb;bool first; +if (unlikely (!(mask & sibling->mask))) { +if (!RB_EMPTY_NODE (&node->rb)) { +spin_lock (&sibling->timeline.lock); +rb_erase_cached (&node->rb, + &sibling->execlists.virtual); +RB_CLEAR_NODE (&node->rb); +spin_unlock (&sibling->timeline.lock); + } +continue ; + } +spin_lock (&sibling->timeline.lock);if (!RB_EMPTY_NODE (&node->rb)) {drivers/gpu/drm/i915/gt/selftest_lrc.c +131
-0@@ -1480,6 +1480,136 @@ static int live_virtual_engine(void *arg)return err; } +static int mask_virtual_engine (struct drm_i915_private *i915, +struct intel_engine_cs **siblings, +unsigned int nsibling) +{ +struct i915_request *request[MAX_ENGINE_INSTANCE +1 ]; +struct i915_gem_context *ctx; +struct intel_context *ve; +struct igt_live_test t; +unsigned int n; +int err; + +/* +* Check that by setting the execution mask on a request, we can +* restrict it to our desired engine within the virtual engine. +*/ + + ctx =kernel_context (i915); +if (!ctx) +return -ENOMEM ; + + ve =intel_execlists_create_virtual (ctx, siblings, nsibling); +if (IS_ERR (ve)) { + err =PTR_ERR (ve); + goto out_close; + } + + err =intel_context_pin (ve); +if (err) + goto out_put; + + err =igt_live_test_begin (&t, i915, __func__, ve->engine->name); +if (err) + goto out_unpin; + +for (n =0 ; n < nsibling; n++) { + request[n] =i915_request_create (ve); +if (IS_ERR (request)) { + err =PTR_ERR (request); + nsibling = n; + goto out; + } + +/* Reverse order as it's more likely to be unnatural */ + request[n]->execution_mask = siblings[nsibling - n -1 ]->mask; + +i915_request_get (request[n]); +i915_request_add (request[n]); + } + +for (n =0 ; n < nsibling; n++) { +if (i915_request_wait (request[n],I915_WAIT_LOCKED ,HZ /10 ) <0 ) { +pr_err ("%s(%s): wait for %llx:%lld timed out\n" , + __func__, ve->engine->name, + request[n]->fence.context, + request[n]->fence.seqno); + +GEM_TRACE ("%s(%s) failed at request %llx:%lld\n" , + __func__, ve->engine->name, + request[n]->fence.context, + request[n]->fence.seqno); +GEM_TRACE_DUMP (); +i915_gem_set_wedged (i915); + err = -EIO ; + goto out; + } + +if (request[n]->engine != siblings[nsibling - n -1 ]) { +pr_err ("Executed on wrong sibling '%s', expected '%s'\n" , + request[n]->engine->name, + siblings[nsibling - n -1 ]->name); + err = -EINVAL ; + goto out; + } + } + + err =igt_live_test_end (&t); +if (err) + goto out; + +out: +if (igt_flush_test (i915,I915_WAIT_LOCKED )) + err = -EIO ; + +for (n =0 ; n < nsibling; n++) +i915_request_put (request[n]); + +out_unpin: +intel_context_unpin (ve); +out_put: +intel_context_put (ve); +out_close: +kernel_context_close (ctx); +return err; +} + +static int live_virtual_mask (void *arg) +{ +struct drm_i915_private *i915 = arg; +struct intel_engine_cs *siblings[MAX_ENGINE_INSTANCE +1 ]; +unsigned int class, inst; +int err =0 ; + +if (USES_GUC_SUBMISSION (i915)) +return 0 ; + +mutex_lock (&i915->drm.struct_mutex); + +for (class =0 ; class <=MAX_ENGINE_CLASS ; class++) { +unsigned int nsibling; + + nsibling =0 ; +for (inst =0 ; inst <=MAX_ENGINE_INSTANCE ; inst++) { +if (!i915->engine_class[class][inst]) +break ; + + siblings[nsibling++] = i915->engine_class[class][inst]; + } +if (nsibling <2 ) +continue ; + + err =mask_virtual_engine (i915, siblings, nsibling); +if (err) + goto out_unlock; + } + +out_unlock: +mutex_unlock (&i915->drm.struct_mutex); +return err; +} +int intel_execlists_live_selftests (struct drm_i915_private *i915) {static const struct i915_subtest tests[] = {@@ -1493,6 +1623,7 @@ int intel_execlists_live_selftests(struct drm_i915_private *i915)SUBTEST (live_preempt_hang),SUBTEST (live_preempt_smoke),SUBTEST (live_virtual_engine), + SUBTEST(live_virtual_mask), };if (!HAS_EXECLISTS (i915))drivers/gpu/drm/i915/i915_request.c +1
-0@@ -688,6 +688,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) rq->batch =NULL ; rq->capture_list =NULL ; rq->waitboost = false; + rq->execution_mask =ALL_ENGINES ;INIT_LIST_HEAD (&rq->active_list);INIT_LIST_HEAD (&rq->execute_cb);drivers/gpu/drm/i915/i915_request.h +2
-0@@ -28,6 +28,8 @@#include <linux/dma-fence.h> #include <linux/lockdep.h> +#include "gt/intel_engine_types.h" +#include "i915_gem.h" #include "i915_scheduler.h" #include "i915_selftest.h"
drivers/gpu/drm/i915/i915_request.h struct i915_request { · line 164
Quoted 7 lines
drivers/gpu/drm/i915/i915_request.h +1
-0@@ -156,6 +158,7 @@ struct i915_request {*/ struct i915_sched_node sched;struct i915_dependency dep; +intel_engine_mask_t execution_mask;/* * A convenience pointer to the current breadcrumb value stored in
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 20/45] drm/i915: Apply an execution_mask to the virtual_engine
Quoting Tvrtko Ursulin (2019-04-29 15:12:23)
Quoted 9 lines · Chris Wilson
Quoted 7 lines
static void
virtual_submission_tasklet(unsigned long data){ struct virtual_engine * const ve = (struct virtual_engine *)data; const int prio = ve->base.execlists.queue_priority_hint; + intel_engine_mask_t mask; unsigned int n;
Quoted 7 lines
drivers/gpu/drm/i915/gt/intel_lrc.c static const struct intel_context_ops virtual_context_ops = { · line 3203
Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +4
-0+rcu_read_lock (); + mask =virtual_submission_mask (ve); +rcu_read_unlock (); +if (unlikely (!mask))Is the
rcu_lockthink solely for the same protection against wedging insubmit_notify?
No. We may still be in the rbtree of the physical engines and ve->request may be plucked out from underneath us as we read it. And in the time it takes to tracek, that request may have been executed, retired and freed. To prevent the dangling stale dereference, we use rcu_read_lock() here as we peek into the request, and spinlocks around the actual transfer to the execution backend.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 20/45] drm/i915: Apply an execution_mask to the virtual_engine
Quoted 18 lines · Chris Wilson
Quoting Tvrtko Ursulin (2019-04-29 15:12:23)
Quoted 9 lines · Chris Wilson
Quoted 7 lines
static void virtual_submission_tasklet(unsigned long data) { struct virtual_engine * const ve = (struct virtual_engine *)data; const int prio = ve->base.execlists.queue_priority_hint; + intel_engine_mask_t mask; unsigned int n;Quoted 7 lines
drivers/gpu/drm/i915/gt/intel_lrc.c static const struct intel_context_ops virtual_context_ops = { · line 3203
Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +4
-0+rcu_read_lock (); + mask =virtual_submission_mask (ve); +rcu_read_unlock (); +if (unlikely (!mask))Is the
rcu_lockthink solely for the same protection against wedging insubmit_notify?
Quoted 6 lines
No. We may still be in the rbtree of the physical engines and
ve->requestmay be plucked out from underneath us as we read it. And in the time it takes to tracek, that request may have been executed, retired and freed. To prevent the dangling stale dereference, we usercu_read_lock()here as we peek into the request, and spinlocks around the actual transfer to the execution backend.
So it's not actually about ve->request as s member pointer, but the request object itself. That could make sense, but then wouldn't you need to hold the rcu_read_lock over the whole tasklet? There is another ve->request read in the for loop just below, although not an actual dereference. I guess I just answered it to myself. Okay, looks good then.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 21/45 drm/i915: Extend execution fence to support a callback
In reply to Chris WilsonIn the next patch, we will want to configure the slave request depending on which physical engine the master request is executed on. For this, we introduce a callback from the execute fence to convey this information.
--- drivers/gpu/drm/i915/i915_request.c | 84 +++++++++++++++++++++++++++-- drivers/gpu/drm/i915/i915_request.h | 4 ++ 2 files changed, 83 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_request.c +79 -5
@@ -38,6 +38,8 @@ struct execute_cb {struct list_head link;struct irq_work work;struct i915_sw_fence *fence; +void (*hook)(struct i915_request *rq,struct dma_fence *signal); +struct i915_request *signal; }; static struct i915_global_request {
@@ -329,6 +331,17 @@ static void irq_execute_cb(struct irq_work *wrk)kmem_cache_free (global.slab_execute_cbs, cb); } +static void irq_execute_cb_hook (struct irq_work *wrk) +{ +struct execute_cb *cb =container_of (wrk,typeof (*cb), work); + + cb->hook(container_of(cb->fence, struct i915_request, submit), + &cb->signal->fence); +i915_request_put (cb->signal); + +irq_execute_cb (wrk); +} +static void __notify_execute_cb (struct i915_request *rq) {struct execute_cb *cb;
@@ -355,14 +368,19 @@ static void __notify_execute_cb(struct i915_request *rq) }static int -i915_request_await_execution (struct i915_request *rq, -struct i915_request *signal, -gfp_t gfp) +__i915_request_await_execution (struct i915_request *rq, +struct i915_request *signal, +void (*hook)(struct i915_request *rq, +struct dma_fence *signal), +gfp_t gfp) {struct execute_cb *cb; -if (i915_request_is_active (signal)) +if (i915_request_is_active (signal)) { +if (hook) +hook (rq, &signal->fence);return 0 ; + } cb =kmem_cache_alloc (global.slab_execute_cbs, gfp);if (!cb)
@@ -372,8 +390,18 @@ i915_request_await_execution(struct i915_request *rq,i915_sw_fence_await (cb->fence);init_irq_work (&cb->work, irq_execute_cb); +if (hook) { + cb->hook = hook; + cb->signal =i915_request_get (signal); + cb->work.func = irq_execute_cb_hook; + } +spin_lock_irq (&signal->lock);if (i915_request_is_active (signal)) { +if (hook) { +hook (rq, &signal->fence); +i915_request_put (signal); + }i915_sw_fence_complete (cb->fence);kmem_cache_free (global.slab_execute_cbs, cb); }else {
@@ -802,7 +830,7 @@ emit_semaphore_wait(struct i915_request *to,return err;/* Only submit our spinner after the signaler is running! */ - err =i915_request_await_execution (to, from, gfp); + err =__i915_request_await_execution (to, from,NULL , gfp);if (err)return err;
@@ -923,6 +951,52 @@ i915_request_await_dma_fence(struct i915_request *rq, struct dma_fence *fence)return 0 ; } +int +i915_request_await_execution (struct i915_request *rq, +struct dma_fence *fence, +void (*hook)(struct i915_request *rq, +struct dma_fence *signal)) +{ +struct dma_fence **child = &fence; +unsigned int nchild =1 ; +int ret; + +if (dma_fence_is_array (fence)) { +struct dma_fence_array *array =to_dma_fence_array (fence); + +/* XXX Error for signal-on-any fence arrays */ + + child = array->fences; + nchild = array->num_fences; +GEM_BUG_ON (!nchild); + } + +do { + fence = *child++; +if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags)) +continue ; + +/* +* We don't squash repeated fence dependencies here as we +* want to run our callback in all cases. +*/ + +if (dma_fence_is_i915 (fence)) + ret =__i915_request_await_execution (rq, +to_request (fence), + hook, +I915_FENCE_GFP ); +else + ret =i915_sw_fence_await_dma_fence (&rq->submit, fence, +I915_FENCE_TIMEOUT , +GFP_KERNEL ); +if (ret <0 ) +return ret; + }while (--nchild); + +return 0 ; +} +/** * i915_request_await_object - set this request to (async) wait upon a bo * @to: request we are wishing to use
drivers/gpu/drm/i915/i915_request.h +4 -0
@@ -283,6 +283,10 @@ int i915_request_await_object(struct i915_request *to, bool write);int i915_request_await_dma_fence (struct i915_request *rq,struct dma_fence *fence); +int i915_request_await_execution (struct i915_request *rq, +struct dma_fence *fence, +void (*hook)(struct i915_request *rq, +struct dma_fence *signal));void i915_request_add (struct i915_request *rq);
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 22/45 drm/i915/execlists: Virtual engine bonding
In reply to Chris WilsonSome users require that when a master batch is executed on one particular engine, a companion batch is run simultaneously on a specific slave engine. For this purpose, we introduce virtual engine bonding, allowing maps of master:slaves to be constructed to constrain which physical engines a virtual engine may select given a fence on a master engine.
For the moment, we continue to ignore the issue of preemption deferring the master request for later. Ideally, we would like to then also remove the slave and run something else rather than have it stall the pipeline. With load balancing, we should be able to move workload around it, but there is a similar stall on the master pipeline while it may wait for the slave to be executed. At the cost of more latency for the bonded request, it may be interesting to launch both on their engines in lockstep. (Bubbles abound.)
Opens: Also what about bonding an engine as its own master? It doesn't break anything internally, so allow the silliness.
v2: Emancipate the bonds
v3: Couple in delayed scheduling for the selftests
v4: Handle invalid mutually exclusive bonding
v5: Mention what the uapi does
v6: s/nbond/num_bonds/
--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 7 + drivers/gpu/drm/i915/gt/intel_lrc.c | 98 +++++++++ drivers/gpu/drm/i915/gt/intel_lrc.h | 4 + drivers/gpu/drm/i915/gt/selftest_lrc.c | 191 ++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_context.c | 84 ++++++++ drivers/gpu/drm/i915/selftests/lib_sw_fence.c | 3 + include/uapi/drm/i915_drm.h | 44 ++++ 7 files changed, 431 insertions(+)
drivers/gpu/drm/i915/gt/intel_engine_types.h +7 -0
@@ -405,6 +405,13 @@ struct intel_engine_cs {*/ void (*submit_request)(struct i915_request *rq); +/* +* Called on signaling of a SUBMIT_FENCE, passing along the signaling +* request down to the bonded pairs. +*/ +void (*bond_execute)(struct i915_request *rq, +struct dma_fence *signal); +/* * Call when the priority on a request has changed and it and its * dependencies may need rescheduling. Note the request itself may
drivers/gpu/drm/i915/gt/intel_lrc.c +98 -0
137 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_lrc.h +4 -0
@@ -123,4 +123,8 @@ struct intel_context * intel_execlists_clone_virtual(struct i915_gem_context *ctx, struct intel_engine_cs *src); +int intel_virtual_engine_attach_bond (struct intel_engine_cs *engine, +const struct intel_engine_cs *master, +const struct intel_engine_cs *sibling); +#endif /* _INTEL_LRC_H_ */
drivers/gpu/drm/i915/gt/selftest_lrc.c +191 -0
209 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_context.c +84 -0
92 lines not on this page · raw message
drivers/gpu/drm/i915/selftests/lib_sw_fence.c +3 -0
@@ -45,6 +45,9 @@ void __onstack_fence_init(struct i915_sw_fence *fence,void onstack_fence_fini (struct i915_sw_fence *fence) { +if (!fence->flags) +return ; +i915_sw_fence_commit (fence);i915_sw_fence_fini (fence); }
include/uapi/drm/i915_drm.h +44 -0
59 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 22/45] drm/i915/execlists: Virtual engine bonding
Quoted 597 lines · Chris Wilson
Some users require that when a master batch is executed on one particular engine, a companion batch is run simultaneously on a specific slave engine. For this purpose, we introduce virtual engine bonding, allowing maps of master:slaves to be constructed to constrain which physical engines a virtual engine may select given a fence on a master engine.
For the moment, we continue to ignore the issue of preemption deferring the master request for later. Ideally, we would like to then also remove the slave and run something else rather than have it stall the pipeline. With load balancing, we should be able to move workload around it, but there is a similar stall on the master pipeline while it may wait for the slave to be executed. At the cost of more latency for the bonded request, it may be interesting to launch both on their engines in lockstep. (Bubbles abound.)
Opens: Also what about bonding an engine as its own master? It doesn't break anything internally, so allow the silliness.
v2: Emancipate the bonds
v3: Couple in delayed scheduling for the selftests
v4: Handle invalid mutually exclusive bonding
v5: Mention what the uapi does
v6: s/nbond/num_bonds/Signed-off-by Chris Wilson <[email protected]>Cc Tvrtko Ursulin <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 7 + drivers/gpu/drm/i915/gt/intel_lrc.c | 98 +++++++++ drivers/gpu/drm/i915/gt/intel_lrc.h | 4 + drivers/gpu/drm/i915/gt/selftest_lrc.c | 191 ++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_context.c | 84 ++++++++ drivers/gpu/drm/i915/selftests/lib_sw_fence.c | 3 + include/uapi/drm/i915_drm.h | 44 ++++ 7 files changed, 431 insertions(+)drivers/gpu/drm/i915/gt/intel_engine_types.h +7
-0@@ -405,6 +405,13 @@ struct intel_engine_cs {*/ void (*submit_request)(struct i915_request *rq); +/* +* Called on signaling of a SUBMIT_FENCE, passing along the signaling +* request down to the bonded pairs. +*/ +void (*bond_execute)(struct i915_request *rq, +struct dma_fence *signal); +/* * Call when the priority on a request has changed and it and its * dependencies may need rescheduling. Note the request itself may drivers/gpu/drm/i915/gt/intel_lrc.c +98
-0@@ -191,6 +191,18 @@ struct virtual_engine {int prio; } nodes[I915_NUM_ENGINES ]; +/* +* Keep track of bonded pairs -- restrictions upon on our selection +* of physical engines any particular request may be submitted to. +* If we receive a submit-fence from a master engine, we will only +* use one of sibling_mask physical engines. +*/ +struct ve_bond { +const struct intel_engine_cs *master; +intel_engine_mask_t sibling_mask; + } *bonds; +unsigned int num_bonds; +/* And finally, which physical engines this virtual engine maps onto. */ unsigned int num_siblings;struct intel_engine_cs *siblings[0 ];@@ -982,6 +994,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)rb_erase_cached (rb, &execlists->virtual);RB_CLEAR_NODE (rb); +GEM_BUG_ON (!(rq->execution_mask & engine->mask)); rq->engine = engine;if (engine != ve->siblings[0 ]) {@@ -3093,6 +3106,8 @@ static void virtual_context_destroy(struct kref *kref)if (ve->context.state)__execlists_context_fini (&ve->context); +kfree (ve->bonds); +i915_timeline_fini (&ve->base.timeline);kfree (ve); }@@ -3288,6 +3303,38 @@ static void virtual_submit_request(struct i915_request *rq)tasklet_schedule (&ve->base.execlists.tasklet); } +static struct ve_bond * +virtual_find_bond (struct virtual_engine *ve, +const struct intel_engine_cs *master) +{ +int i; + +for (i =0 ; i < ve->num_bonds; i++) { +if (ve->bonds[i].master == master) +return &ve->bonds[i]; + } + +return NULL ; +} + +static void +virtual_bond_execute (struct i915_request *rq,struct dma_fence *signal) +{ +struct virtual_engine *ve =to_virtual_engine (rq->engine); +struct ve_bond *bond; + + bond =virtual_find_bond (ve,to_request (signal)->engine); +if (bond) { +intel_engine_mask_t old, new, cmp; + + cmp =READ_ONCE (rq->execution_mask); +do { + old = cmp; + new = cmp & bond->sibling_mask; + }while ((cmp =cmpxchg (&rq->execution_mask, old, new)) != old); + } +} +struct intel_context * intel_execlists_create_virtual(struct i915_gem_context *ctx, struct intel_engine_cs **siblings,@@ -3328,6 +3375,7 @@ intel_execlists_create_virtual(struct i915_gem_context *ctx, ve->base.schedule = i915_schedule; ve->base.submit_request = virtual_submit_request; + ve->base.bond_execute = virtual_bond_execute; ve->base.execlists.queue_priority_hint =INT_MIN ; tasklet_init(&ve->base.execlists.tasklet,@@ -3417,9 +3465,59 @@ intel_execlists_clone_virtual(struct i915_gem_context *ctx,if (IS_ERR (dst))return dst; +if (se->num_bonds) { +struct virtual_engine *de =to_virtual_engine (dst->engine); + + de->bonds =kmemdup (se->bonds, +sizeof (*se->bonds) * se->num_bonds, +GFP_KERNEL ); +if (!de->bonds) { +intel_context_put (dst); +return ERR_PTR (-ENOMEM ); + } + + de->num_bonds = se->num_bonds; + } +return dst; } +int intel_virtual_engine_attach_bond (struct intel_engine_cs *engine, +const struct intel_engine_cs *master, +const struct intel_engine_cs *sibling) +{ +struct virtual_engine *ve =to_virtual_engine (engine); +struct ve_bond *bond; +int n; + +/* Sanity check the sibling is part of the virtual engine */ +for (n =0 ; n < ve->num_siblings; n++) +if (sibling == ve->siblings[n]) +break ; +if (n == ve->num_siblings) +return -EINVAL ; + + bond =virtual_find_bond (ve, master); +if (bond) { + bond->sibling_mask |= sibling->mask; +return 0 ; + } + + bond =krealloc (ve->bonds, +sizeof (*bond) * (ve->num_bonds +1 ), +GFP_KERNEL ); +if (!bond) +return -ENOMEM ; + + bond[ve->num_bonds].master = master; + bond[ve->num_bonds].sibling_mask = sibling->mask; + + ve->bonds = bond; + ve->num_bonds++; + +return 0 ; +} + void intel_execlists_show_requests(struct intel_engine_cs *engine, struct drm_printer *m, void (*show_request)(struct drm_printer *m,drivers/gpu/drm/i915/gt/intel_lrc.h +4
-0@@ -123,4 +123,8 @@ struct intel_context * intel_execlists_clone_virtual(struct i915_gem_context *ctx, struct intel_engine_cs *src); +int intel_virtual_engine_attach_bond (struct intel_engine_cs *engine, +const struct intel_engine_cs *master, +const struct intel_engine_cs *sibling); +#endif /* _INTEL_LRC_H_ */ drivers/gpu/drm/i915/gt/selftest_lrc.c +191
-0@@ -13,6 +13,7 @@#include "selftests/igt_gem_utils.h" #include "selftests/igt_live_test.h" #include "selftests/igt_spinner.h" +#include "selftests/lib_sw_fence.h" #include "selftests/mock_context.h" static int live_sanitycheck (void *arg)@@ -1610,6 +1611,195 @@ static int live_virtual_mask(void *arg)return err; } +static int bond_virtual_engine (struct drm_i915_private *i915, +unsigned int class, +struct intel_engine_cs **siblings, +unsigned int nsibling, +unsigned int flags) +#define BOND_SCHEDULE BIT(0) +{ +struct intel_engine_cs *master; +struct i915_gem_context *ctx; +struct i915_request *rq[16 ]; +enum intel_engine_id id; +unsigned long n; +int err; + +GEM_BUG_ON (nsibling >=ARRAY_SIZE (rq) -1 ); + + ctx =kernel_context (i915); +if (!ctx) +return -ENOMEM ; + + err =0 ; + rq[0 ] =ERR_PTR (-ENOMEM ); +for_each_engine (master, i915, id) { +struct i915_sw_fence fence = {}; + +if (master->class == class) +continue ; + +memset_p ((void *)rq,ERR_PTR (-EINVAL ),ARRAY_SIZE (rq)); + + rq[0 ] =igt_request_alloc (ctx, master); +if (IS_ERR (rq[0 ])) { + err =PTR_ERR (rq[0 ]); + goto out; + } +i915_request_get (rq[0 ]); + +if (flags &BOND_SCHEDULE ) { +onstack_fence_init (&fence); + err =i915_sw_fence_await_sw_fence_gfp (&rq[0 ]->submit, + &fence, +GFP_KERNEL ); + } +i915_request_add (rq[0 ]); +if (err <0 ) + goto out; + +for (n =0 ; n < nsibling; n++) { +struct intel_context *ve; + + ve =intel_execlists_create_virtual (ctx, + siblings, + nsibling); +if (IS_ERR (ve)) { + err =PTR_ERR (ve); +onstack_fence_fini (&fence); + goto out; + } + + err =intel_virtual_engine_attach_bond (ve->engine, + master, + siblings[n]); +if (err) { +intel_context_put (ve); +onstack_fence_fini (&fence); + goto out; + } + + err =intel_context_pin (ve); +intel_context_put (ve); +if (err) { +onstack_fence_fini (&fence); + goto out; + } + + rq[n +1 ] =i915_request_create (ve); +intel_context_unpin (ve); +if (IS_ERR (rq[n +1 ])) { + err =PTR_ERR (rq[n +1 ]); +onstack_fence_fini (&fence); + goto out; + } +i915_request_get (rq[n +1 ]); + + err =i915_request_await_execution (rq[n +1 ], + &rq[0 ]->fence, + ve->engine->bond_execute); +i915_request_add (rq[n +1 ]); +if (err <0 ) { +onstack_fence_fini (&fence); + goto out; + } + } +onstack_fence_fini (&fence); + +if (i915_request_wait (rq[0 ], +I915_WAIT_LOCKED , +HZ /10 ) <0 ) { +pr_err ("Master request did not execute (on %s)!\n" , + rq[0 ]->engine->name); + err = -EIO ; + goto out; + } + +for (n =0 ; n < nsibling; n++) { +if (i915_request_wait (rq[n +1 ], +I915_WAIT_LOCKED , +MAX_SCHEDULE_TIMEOUT ) <0 ) { + err = -EIO ; + goto out; + } + +if (rq[n +1 ]->engine != siblings[n]) { +pr_err ("Bonded request did not execute on target engine: expected %s, used %s; master was %s\n" , + siblings[n]->name, + rq[n +1 ]->engine->name, + rq[0 ]->engine->name); + err = -EINVAL ; + goto out; + } + } + +for (n =0 ; !IS_ERR (rq[n]); n++) +i915_request_put (rq[n]); + rq[0 ] =ERR_PTR (-ENOMEM ); + } + +out: +for (n =0 ; !IS_ERR (rq[n]); n++) +i915_request_put (rq[n]); +if (igt_flush_test (i915,I915_WAIT_LOCKED )) + err = -EIO ; + +kernel_context_close (ctx); +return err; +} + +static int live_virtual_bond (void *arg) +{ +static const struct phase { +const char *name; +unsigned int flags; + } phases[] = { + {"" ,0 }, + {"schedule" ,BOND_SCHEDULE }, + { }, + }; +struct drm_i915_private *i915 = arg; +struct intel_engine_cs *siblings[MAX_ENGINE_INSTANCE +1 ]; +unsigned int class, inst; +int err =0 ; + +if (USES_GUC_SUBMISSION (i915)) +return 0 ; + +mutex_lock (&i915->drm.struct_mutex); + +for (class =0 ; class <=MAX_ENGINE_CLASS ; class++) { +const struct phase *p; +int nsibling; + + nsibling =0 ; +for (inst =0 ; inst <=MAX_ENGINE_INSTANCE ; inst++) { +if (!i915->engine_class[class][inst]) +break ; + +GEM_BUG_ON (nsibling ==ARRAY_SIZE (siblings)); + siblings[nsibling++] = i915->engine_class[class][inst]; + } +if (nsibling <2 ) +continue ; + +for (p = phases; p->name; p++) { + err =bond_virtual_engine (i915, + class, siblings, nsibling, + p->flags); +if (err) { +pr_err ("%s(%s): failed class=%d, nsibling=%d, err=%d\n" , + __func__, p->name, class, nsibling, err); + goto out_unlock; + } + } + } + +out_unlock: +mutex_unlock (&i915->drm.struct_mutex); +return err; +} +int intel_execlists_live_selftests (struct drm_i915_private *i915) {static const struct i915_subtest tests[] = {@@ -1624,6 +1814,7 @@ int intel_execlists_live_selftests(struct drm_i915_private *i915)SUBTEST (live_preempt_smoke),SUBTEST (live_virtual_engine),SUBTEST (live_virtual_mask), + SUBTEST(live_virtual_bond), };if (!HAS_EXECLISTS (i915))drivers/gpu/drm/i915/i915_gem_context.c +84
-0@@ -1491,8 +1491,92 @@ set_engines__load_balance(struct i915_user_extension __user *base, void *data)return err; } +static int +set_engines__bond (struct i915_user_extension __user *base,void *data) +{ +struct i915_context_engines_bond __user *ext = +container_of_user (base,typeof (*ext), base); +const struct set_engines *set = data; +struct i915_engine_class_instance ci; +struct intel_engine_cs *virtual; +struct intel_engine_cs *master; +u16 idx, num_bonds; +int err, n; + +if (get_user (idx, &ext->virtual_index)) +return -EFAULT ; + +if (idx >= set->engines->num_engines) { +DRM_DEBUG ("Invalid index for virtual engine: %d >= %d\n" , + idx, set->engines->num_engines); +return -EINVAL ; + } + + idx =array_index_nospec (idx, set->engines->num_engines); +if (!set->engines->engines[idx]) { +DRM_DEBUG ("Invalid engine at %d\n" , idx); +return -EINVAL ; + } + virtual = set->engines->engines[idx]->engine; + + err =check_user_mbz (&ext->flags); +if (err) +return err; + +for (n =0 ; n <ARRAY_SIZE (ext->mbz64); n++) { + err =check_user_mbz (&ext->mbz64[n]); +if (err) +return err; + } + +if (copy_from_user (&ci, &ext->master,sizeof (ci))) +return -EFAULT ; + + master =intel_engine_lookup_user (set->ctx->i915, + ci.engine_class, ci.engine_instance); +if (!master) { +DRM_DEBUG ("Unrecognised master engine: { class:%u, instance:%u }\n" , + ci.engine_class, ci.engine_instance); +return -EINVAL ; + } + +if (get_user (num_bonds, &ext->num_bonds)) +return -EFAULT ; + +for (n =0 ; n < num_bonds; n++) { +struct intel_engine_cs *bond; + +if (copy_from_user (&ci, &ext->engines[n],sizeof (ci))) +return -EFAULT ; + + bond =intel_engine_lookup_user (set->ctx->i915, + ci.engine_class, + ci.engine_instance); +if (!bond) { +DRM_DEBUG ("Unrecognised engine[%d] for bonding: { class:%d, instance: %d }\n" , + n, ci.engine_class, ci.engine_instance); +return -EINVAL ; + } + +/* +* A non-virtual engine has no siblings to choose between; and +* a submit fence will always be directed to the one engine. +*/ +if (intel_engine_is_virtual (virtual)) { + err =intel_virtual_engine_attach_bond (virtual, + master, + bond); +if (err) +return err; + } + } + +return 0 ; +} +static const i915_user_extension_fn set_engines__extensions[] = { [I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE ] = set_engines__load_balance, + [I915_CONTEXT_ENGINES_EXT_BOND ] = set_engines__bond, }; static intdrivers/gpu/drm/i915/selftests/lib_sw_fence.c +3
-0@@ -45,6 +45,9 @@ void __onstack_fence_init(struct i915_sw_fence *fence,void onstack_fence_fini (struct i915_sw_fence *fence) { +if (!fence->flags) +return ; +i915_sw_fence_commit (fence);i915_sw_fence_fini (fence); }include/uapi/drm/i915_drm.h +40
-0@@ -1543,6 +1543,10 @@ struct drm_i915_gem_context_param {* sized argument, will revert back to default settings. * * See struct i915_context_param_engines. +* +* Extensions: +* i915_context_engines_load_balance (I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE) +* i915_context_engines_bond (I915_CONTEXT_ENGINES_EXT_BOND) */ #define I915_CONTEXT_PARAM_ENGINES 0xa/* Must be kept compact -- no holes and well documented */ @@ -1645,9 +1649,49 @@ struct i915_context_engines_load_balance {struct i915_engine_class_instance engines[N__ ]; \ } __attribute__((packed))name__ +/* +* i915_context_engines_bond: +* +* Constructed bonded pairs for execution within a virtual engine. +* +* All engines are equal, but some are more equal than others. Given +* the distribution of resources in the HW, it may be preferable to run +* a request on a given subset of engines in parallel to a request on a +* specific engine. We enable this selection of engines within a virtual +* engine by specifying bonding pairs, for any given master engine we will +* only execute on one of the corresponding siblings within the virtual engine. +* +* To execute a request in parallel on the master engine and a sibling requires +* coordination with a I915_EXEC_FENCE_SUBMIT. +*/ +struct i915_context_engines_bond { +struct i915_user_extension base; + +struct i915_engine_class_instance master; + +__u16 virtual_index;/* index of virtual engine in ctx->engines[] */ +__u16 num_bonds; + +__u64 flags;/* all undefined flags must be zero */ +__u64 mbz64[4 ];/* reserved for future use; must be zero */ + +struct i915_engine_class_instance engines[0 ]; +} __attribute__((packed)); + +#define I915_DEFINE_CONTEXT_ENGINES_BOND (name__,N__ ) struct { \ + struct i915_user_extension base; \ + struct i915_engine_class_instance master; \ + __u16 virtual_index; \ + __u16 num_bonds; \ + __u64 flags; \ + __u64 mbz64[4]; \
include/uapi/drm/i915_drm.h struct i915_context_engines_load_balance { · line 1697
Quoted 10 lines
include/uapi/drm/i915_drm.h +4
-0+struct i915_engine_class_instance engines[N__ ]; \ +} __attribute__((packed))name__ + struct i915_context_param_engines {__u64 extensions;/* linked chain of extension blocks, 0 terminates */ #define I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE 0/* see i915_context_engines_load_balance */ +#define I915_CONTEXT_ENGINES_EXT_BOND 1/* see i915_context_engines_bond */ struct i915_engine_class_instance engines[0 ]; } __attribute__((packed));
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 23/45 drm/i915: Allow specification of parallel execbuf
In reply to Chris WilsonThere is a desire to split a task onto two engines and have them run at the same time, e.g. scanline interleaving to spread the workload evenly. Through the use of the out-fence from the first execbuf, we can coordinate secondary execbuf to only become ready simultaneously with the first, so that with all things idle the second execbufs are executed in parallel with the first. The key difference here between the new EXEC_FENCE_SUBMIT and the existing EXEC_FENCE_IN is that the in-fence waits for the completion of the first request (so that all of its rendering results are visible to the second execbuf, the more common userspace fence requirement).
Since we only have a single input fence slot, userspace cannot mix an in-fence and a submit-fence. It has to use one or the other! This is not such a harsh requirement, since by virtue of the submit-fence, the secondary execbuf inherit all of the dependencies from the first request, and for the application the dependencies should be common between the primary and secondary execbuf.
Testcase: igt/gem_exec_fence/parallel
--- drivers/gpu/drm/i915/i915_drv.c | 1 + drivers/gpu/drm/i915/i915_gem_execbuffer.c | 25 +++++++++++++++++++++- include/uapi/drm/i915_drm.h | 17 ++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +1 -0
@@ -435,6 +435,7 @@ static int i915_getparam_ioctl(struct drm_device *dev, void *data,case I915_PARAM_HAS_EXEC_CAPTURE :case I915_PARAM_HAS_EXEC_BATCH_FIRST :case I915_PARAM_HAS_EXEC_FENCE_ARRAY : +case I915_PARAM_HAS_EXEC_SUBMIT_FENCE :/* For the time being all of these are always true; * if some supported hardware does not have one of these * features this value needs to be provided from
drivers/gpu/drm/i915/i915_gem_execbuffer.c +24 -1
@@ -2318,6 +2318,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, {struct i915_execbuffer eb;struct dma_fence *in_fence =NULL ; +struct dma_fence *exec_fence =NULL ;struct sync_file *out_fence =NULL ;int out_fence_fd =-1 ;int err;
@@ -2360,11 +2361,24 @@ i915_gem_do_execbuffer(struct drm_device *dev,return -EINVAL ; } +if (args->flags &I915_EXEC_FENCE_SUBMIT ) { +if (in_fence) { + err = -EINVAL ; + goto err_in_fence; + } + + exec_fence =sync_file_get_fence (lower_32_bits (args->rsvd2)); +if (!exec_fence) { + err = -EINVAL ; + goto err_in_fence; + } + } +if (args->flags &I915_EXEC_FENCE_OUT ) { out_fence_fd =get_unused_fd_flags (O_CLOEXEC );if (out_fence_fd <0 ) { err = out_fence_fd; - goto err_in_fence; + goto err_exec_fence; } }
@@ -2494,6 +2508,13 @@ i915_gem_do_execbuffer(struct drm_device *dev, goto err_request; } +if (exec_fence) { + err =i915_request_await_execution (eb.request, exec_fence, + eb.engine->bond_execute); +if (err <0 ) + goto err_request; + } +if (fences) { err =await_fence_array (&eb, fences);if (err)
@@ -2555,6 +2576,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, err_out_fence:if (out_fence_fd !=-1 )put_unused_fd (out_fence_fd); +err_exec_fence: +dma_fence_put (exec_fence); err_in_fence:dma_fence_put (in_fence);return err;
include/uapi/drm/i915_drm.h +16 -1
@@ -604,6 +604,12 @@ typedef struct drm_i915_irq_wait {*/ #define I915_PARAM_MMAP_GTT_COHERENT 52 +/* +* Query whether DRM_I915_GEM_EXECBUFFER2 supports coordination of parallel +* execution through use of explicit fence support. +* See I915_EXEC_FENCE_OUT and I915_EXEC_FENCE_SUBMIT. +*/ +#define I915_PARAM_HAS_EXEC_SUBMIT_FENCE 53/* Must be kept compact -- no holes and well documented */ typedef struct drm_i915_getparam {
@@ -1126,7 +1132,16 @@ struct drm_i915_gem_execbuffer2 {*/ #define I915_EXEC_FENCE_ARRAY (1<<19) -#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_FENCE_ARRAY<<1)) +/* +* Setting I915_EXEC_FENCE_SUBMIT implies that lower_32_bits(rsvd2) represent +* a sync_file fd to wait upon (in a nonblocking manner) prior to executing +* the batch. +* +* Returns -EINVAL if the sync_file fd cannot be found. +*/ +#define I915_EXEC_FENCE_SUBMIT (1 << 20) + +#define __I915_EXEC_UNKNOWN_FLAGS (-(I915_EXEC_FENCE_SUBMIT << 1))#define I915_EXEC_CONTEXT_ID_MASK (0xffffffff)#define i915_execbuffer2_set_context_id (eb2, context) \
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 24/45 drm/i915: Split GEM object type definition to its own header
In reply to Chris WilsonFor convenience in avoiding inline spaghetti, keep the type definition as a separate header.
--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/gem/Makefile | 1 + drivers/gpu/drm/i915/gem/Makefile.header-test | 16 + .../gpu/drm/i915/gem/i915_gem_object_types.h | 285 +++++++++++++++++ drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 + drivers/gpu/drm/i915/i915_drv.h | 3 +- drivers/gpu/drm/i915/i915_gem_batch_pool.h | 3 +- drivers/gpu/drm/i915/i915_gem_gtt.h | 1 + drivers/gpu/drm/i915/i915_gem_object.h | 295 +----------------- 9 files changed, 312 insertions(+), 294 deletions(-) create mode 100644 drivers/gpu/drm/i915/gem/Makefile create mode 100644 drivers/gpu/drm/i915/gem/Makefile.header-test create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_object_types.h
drivers/gpu/drm/i915/Makefile +1 -0
@@ -85,6 +85,7 @@ gt-$(CONFIG_DRM_I915_SELFTEST) += \ i915-y += $(gt-y) # GEM (Graphics Execution Management) code +obj-y += gem/ i915-y += \ i915_active.o \ i915_cmd_parser.o \
drivers/gpu/drm/i915/gem/Makefile new file +1 -0
@@ -0,0 +1 @@ +include $(src)/Makefile.header-test # Extra header tests
drivers/gpu/drm/i915/gem/Makefile.header-test new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: MIT +# Copyright © 2019 Intel Corporation + +# Test the headers are compilable as standalone units +header_test := $(notdir $(wildcard $(src)/*.h)) + +quiet_cmd_header_test = HDRTEST $@ + cmd_header_test = echo "\#include \"$(<F)\"" > $@ + +header_test_%.c: %.h + $(call cmd,header_test) + +extra-$(CONFIG_DRM_I915_WERROR) += \ + $(foreach h,$(header_test),$(patsubst %.h,header_test_%.o,$(h))) + +clean-files += $(foreach h,$(header_test),$(patsubst %.h,header_test_%.c,$(h)))
drivers/gpu/drm/i915/gem/i915_gem_object_types.h new file +285 -0
285 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_engine_types.h +1 -0
@@ -29,6 +29,7 @@#define I915_CMD_HASH_ORDER 9struct dma_fence ; +struct drm_i915_gem_object ;struct drm_i915_reg_table ;struct i915_gem_context ;struct i915_request ;
drivers/gpu/drm/i915/i915_drv.h +2 -1
@@ -80,7 +80,6 @@#include "i915_gem.h" #include "i915_gem_context.h" #include "i915_gem_fence_reg.h" -#include "i915_gem_object.h" #include "i915_gem_gtt.h" #include "i915_gpu_error.h" #include "i915_request.h"
@@ -135,6 +134,8 @@ bool i915_error_injected(void);__i915_printk (i915,i915_error_injected () ?KERN_DEBUG :KERN_ERR , \ fmt, ##__VA_ARGS__) +struct drm_i915_gem_object ; +enum hpd_pin {HPD_NONE =0 ,HPD_TV =HPD_NONE ,/* TV is known to be unreliable */
drivers/gpu/drm/i915/i915_gem_batch_pool.h +2 -1
@@ -9,6 +9,7 @@#include <linux/types.h> +struct drm_i915_gem_object ;struct intel_engine_cs ;struct i915_gem_batch_pool {
@@ -19,7 +20,7 @@ struct i915_gem_batch_pool {void i915_gem_batch_pool_init (struct i915_gem_batch_pool *pool,struct intel_engine_cs *engine);void i915_gem_batch_pool_fini (struct i915_gem_batch_pool *pool); -struct drm_i915_gem_object * +struct drm_i915_gem_object *i915_gem_batch_pool_get (struct i915_gem_batch_pool *pool,size_t size);#endif /* I915_GEM_BATCH_POOL_H */
drivers/gpu/drm/i915/i915_gem_gtt.h +1 -0
@@ -61,6 +61,7 @@struct drm_i915_file_private ;struct drm_i915_fence_reg ; +struct drm_i915_gem_object ;struct i915_vma ;typedef u32 gen6_pte_t ;
drivers/gpu/drm/i915/i915_gem_object.h +3 -292
311 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 24/45] drm/i915: Split GEM object type definition to its own header
Quoted 25 lines · Chris Wilson
For convenience in avoiding inline spaghetti, keep the type definition as a separate header.
Signed-off-by Chris Wilson <[email protected]>Reviewed-by Matthew Auld <[email protected]>--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/gem/Makefile | 1 + drivers/gpu/drm/i915/gem/Makefile.header-test | 16 + .../gpu/drm/i915/gem/i915_gem_object_types.h | 285 +++++++++++++++++ drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 + drivers/gpu/drm/i915/i915_drv.h | 3 +- drivers/gpu/drm/i915/i915_gem_batch_pool.h | 3 +- drivers/gpu/drm/i915/i915_gem_gtt.h | 1 + drivers/gpu/drm/i915/i915_gem_object.h | 295 +----------------- 9 files changed, 312 insertions(+), 294 deletions(-) create mode 100644 drivers/gpu/drm/i915/gem/Makefile create mode 100644 drivers/gpu/drm/i915/gem/Makefile.header-test create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_object_types.hdrivers/gpu/drm/i915/Makefile +0
-0
drivers/gpu/drm/i915/Makefile gt-$(CONFIG_DRM_I915_SELFTEST) += \ · line 88
Quoted 4 lines
drivers/gpu/drm/i915/Makefile +1
-0@@ -85,6 +85,7 @@ gt-$(CONFIG_DRM_I915_SELFTEST) += \ i915-y += $(gt-y) # GEM (Graphics Execution Management) code +obj-y += gem/
I think this warrants similar treatment as gt/. Posted standalone instead of hidden in a series, explicit acks.
Provided the split makes sense to Joonas,
Quoted 705 lines
drivers/gpu/drm/i915/Makefile +0
-0i915-y += \ i915_active.o \ i915_cmd_parser.o \drivers/gpu/drm/i915/gem/Makefile new file +1
-0@@ -0,0 +1 @@ +include $(src)/Makefile.header-test # Extra header testsdrivers/gpu/drm/i915/gem/Makefile.header-test new file +16
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: MIT +# Copyright © 2019 Intel Corporation + +# Test the headers are compilable as standalone units +header_test := $(notdir $(wildcard $(src)/*.h)) + +quiet_cmd_header_test = HDRTEST $@ + cmd_header_test = echo "\#include \"$(<F)\"" > $@ + +header_test_%.c: %.h + $(call cmd,header_test) + +extra-$(CONFIG_DRM_I915_WERROR) += \ + $(foreach h,$(header_test),$(patsubst %.h,header_test_%.o,$(h))) + +clean-files += $(foreach h,$(header_test),$(patsubst %.h,header_test_%.c,$(h)))drivers/gpu/drm/i915/gem/i915_gem_object_types.h new file +285
-0@@ -0,0 +1,285 @@ +/* +* SPDX-License-Identifier: MIT +* +* Copyright © 2016 Intel Corporation +*/ + +#ifndef __I915_GEM_OBJECT_TYPES_H__ +#define __I915_GEM_OBJECT_TYPES_H__ + +#include <linux/reservation.h> + +#include <drm/drm_gem.h> + +#include "../i915_active.h" +#include "../i915_selftest.h" + +struct drm_i915_gem_object ; + +/* +* struct i915_lut_handle tracks the fast lookups from handle to vma used +* for execbuf. Although we use a radixtree for that mapping, in order to +* remove them as the object or context is closed, we need a secondary list +* and a translation entry (i915_lut_handle). +*/ +struct i915_lut_handle { +struct list_head obj_link; +struct list_head ctx_link; +struct i915_gem_context *ctx; +u32 handle; +}; + +struct drm_i915_gem_object_ops { +unsigned int flags; +#define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0) +#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(1) +#define I915_GEM_OBJECT_IS_PROXY BIT(2) +#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(3) + +/* Interface between the GEM object and its backing storage. +* get_pages() is called once prior to the use of the associated set +* of pages before to binding them into the GTT, and put_pages() is +* called after we no longer need them. As we expect there to be +* associated cost with migrating pages between the backing storage +* and making them available for the GPU (e.g. clflush), we may hold +* onto the pages after they are no longer referenced by the GPU +* in case they may be used again shortly (for example migrating the +* pages to a different memory domain within the GTT). put_pages() +* will therefore most likely be called when the object itself is +* being released or under memory pressure (where we attempt to +* reap pages for the shrinker). +*/ +int (*get_pages)(struct drm_i915_gem_object *obj); +void (*put_pages)(struct drm_i915_gem_object *obj, +struct sg_table *pages); + +int (*pwrite)(struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pwrite *arg); + +int (*dmabuf_export)(struct drm_i915_gem_object *obj); +void (*release)(struct drm_i915_gem_object *obj); +}; + +struct drm_i915_gem_object { +struct drm_gem_object base; + +const struct drm_i915_gem_object_ops *ops; + +struct { +/** +* @vma.lock: protect the list/tree of vmas +*/ +spinlock_t lock; + +/** +* @vma.list: List of VMAs backed by this object +* +* The VMA on this list are ordered by type, all GGTT vma are +* placed at the head and all ppGTT vma are placed at the tail. +* The different types of GGTT vma are unordered between +* themselves, use the @vma.tree (which has a defined order +* between all VMA) to quickly find an exact match. +*/ +struct list_head list; + +/** +* @vma.tree: Ordered tree of VMAs backed by this object +* +* All VMA created for this object are placed in the @vma.tree +* for fast retrieval via a binary search in +* i915_vma_instance(). They are also added to @vma.list for +* easy iteration. +*/ +struct rb_root tree; + } vma; + +/** +* @lut_list: List of vma lookup entries in use for this object. +* +* If this object is closed, we need to remove all of its VMA from +* the fast lookup index in associated contexts; @lut_list provides +* this translation from object to context->handles_vma. +*/ +struct list_head lut_list; + +/** Stolen memory for this object, instead of being backed by shmem. */ +struct drm_mm_node *stolen; +union { +struct rcu_head rcu; +struct llist_node freed; + }; + +/** +* Whether the object is currently in the GGTT mmap. +*/ +unsigned int userfault_count; +struct list_head userfault_link; + +struct list_head batch_pool_link; + I915_SELFTEST_DECLARE(struct list_head st_link); + +unsigned long flags; + +/** +* Have we taken a reference for the object for incomplete GPU +* activity? +*/ +#define I915_BO_ACTIVE_REF 0 + +/* +* Is the object to be mapped as read-only to the GPU +* Only honoured if hardware has relevant pte bit +*/ +unsigned int cache_level:3 ; +unsigned int cache_coherent:2 ; +#define I915_BO_CACHE_COHERENT_FOR_READ BIT(0) +#define I915_BO_CACHE_COHERENT_FOR_WRITE BIT(1) +unsigned int cache_dirty:1 ; + +/** +* @read_domains: Read memory domains. +* +* These monitor which caches contain read/write data related to the +* object. When transitioning from one set of domains to another, +* the driver is called to ensure that caches are suitably flushed and +* invalidated. +*/ +u16 read_domains; + +/** +* @write_domain: Corresponding unique write memory domain. +*/ +u16 write_domain; + +atomic_t frontbuffer_bits; +unsigned int frontbuffer_ggtt_origin;/* write once */ +struct i915_active_request frontbuffer_write; + +/** Current tiling stride for the object, if it's tiled. */ +unsigned int tiling_and_stride; +#define FENCE_MINIMUM_STRIDE 128/* See i915_tiling_ok() */ +#define TILING_MASK (FENCE_MINIMUM_STRIDE - 1) +#define STRIDE_MASK (~TILING_MASK) + +/** Count of VMA actually bound by this object */ +unsigned int bind_count; +unsigned int active_count; +/** Count of how many global VMA are currently pinned for use by HW */ +unsigned int pin_global; + +struct { +struct mutex lock;/* protects the pages and their use */ +atomic_t pages_pin_count; + +struct sg_table *pages; +void *mapping; + +/* TODO: whack some of this into the error state */ +struct i915_page_sizes { +/** +* The sg mask of the pages sg_table. i.e the mask of +* of the lengths for each sg entry. +*/ +unsigned int phys; + +/** +* The gtt page sizes we are allowed to use given the +* sg mask and the supported page sizes. This will +* express the smallest unit we can use for the whole +* object, as well as the larger sizes we may be able +* to use opportunistically. +*/ +unsigned int sg; + +/** +* The actual gtt page size usage. Since we can have +* multiple vma associated with this object we need to +* prevent any trampling of state, hence a copy of this +* struct also lives in each vma, therefore the gtt +* value here should only be read/write through the vma. +*/ +unsigned int gtt; + } page_sizes; + + I915_SELFTEST_DECLARE(unsigned int page_mask); + +struct i915_gem_object_page_iter { +struct scatterlist *sg_pos; +unsigned int sg_idx;/* in pages, but 32bit eek! */ + +struct radix_tree_root radix; +struct mutex lock;/* protects this cache */ + } get_page; + +/** +* Element within i915->mm.unbound_list or i915->mm.bound_list, +* locked by i915->mm.obj_lock. +*/ +struct list_head link; + +/** +* Advice: are the backing pages purgeable? +*/ +unsigned int madv:2 ; + +/** +* This is set if the object has been written to since the +* pages were last acquired. +*/ +bool dirty:1 ; + +/** +* This is set if the object has been pinned due to unknown +* swizzling. +*/ +bool quirked:1 ; + } mm; + +/** Breadcrumb of last rendering to the buffer. +* There can only be one writer, but we allow for multiple readers. +* If there is a writer that necessarily implies that all other +* read requests are complete - but we may only be lazily clearing +* the read requests. A read request is naturally the most recent +* request on a ring, so we may have two different write and read +* requests on one ring where the write request is older than the +* read request. This allows for the CPU to read from an active +* buffer by only waiting for the write to complete. +*/ +struct reservation_object *resv; + +/** References from framebuffers, locks out tiling changes. */ +unsigned int framebuffer_references; + +/** Record of address bit 17 of each page at last unbind. */ +unsigned long *bit_17; + +union { +struct i915_gem_userptr { +uintptr_t ptr; + +struct i915_mm_struct *mm; +struct i915_mmu_object *mmu_object; +struct work_struct *work; + } userptr; + +unsigned long scratch; + +void *gvt_info; + }; + +/** for phys allocated objects */ +struct drm_dma_handle *phys_handle; + +struct reservation_object __builtin_resv; +}; + +static inline struct drm_i915_gem_object * +to_intel_bo (struct drm_gem_object *gem) +{ +/* Assert that to_intel_bo(NULL) == NULL */ +BUILD_BUG_ON (offsetof(struct drm_i915_gem_object , base)); + + return container_of(gem, struct drm_i915_gem_object, base); +} + +#endif drivers/gpu/drm/i915/gt/intel_engine_types.h +1
-0@@ -29,6 +29,7 @@#define I915_CMD_HASH_ORDER 9struct dma_fence ; +struct drm_i915_gem_object ;struct drm_i915_reg_table ;struct i915_gem_context ;struct i915_request ;drivers/gpu/drm/i915/i915_drv.h +2
-1@@ -80,7 +80,6 @@#include "i915_gem.h" #include "i915_gem_context.h" #include "i915_gem_fence_reg.h" -#include "i915_gem_object.h" #include "i915_gem_gtt.h" #include "i915_gpu_error.h" #include "i915_request.h" @@ -135,6 +134,8 @@ bool i915_error_injected(void);__i915_printk (i915,i915_error_injected () ?KERN_DEBUG :KERN_ERR , \ fmt, ##__VA_ARGS__) +struct drm_i915_gem_object ; +enum hpd_pin {HPD_NONE =0 ,HPD_TV =HPD_NONE ,/* TV is known to be unreliable */ drivers/gpu/drm/i915/i915_gem_batch_pool.h +2
-1@@ -9,6 +9,7 @@#include <linux/types.h> +struct drm_i915_gem_object ;struct intel_engine_cs ;struct i915_gem_batch_pool {@@ -19,7 +20,7 @@ struct i915_gem_batch_pool {void i915_gem_batch_pool_init (struct i915_gem_batch_pool *pool,struct intel_engine_cs *engine);void i915_gem_batch_pool_fini (struct i915_gem_batch_pool *pool); -struct drm_i915_gem_object * +struct drm_i915_gem_object *i915_gem_batch_pool_get (struct i915_gem_batch_pool *pool,size_t size);#endif /* I915_GEM_BATCH_POOL_H */ drivers/gpu/drm/i915/i915_gem_gtt.h +1
-0@@ -61,6 +61,7 @@struct drm_i915_file_private ;struct drm_i915_fence_reg ; +struct drm_i915_gem_object ;struct i915_vma ;typedef u32 gen6_pte_t ;drivers/gpu/drm/i915/i915_gem_object.h +3
-292@@ -1,308 +1,19 @@/* -* Copyright © 2016 Intel Corporation -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice (including the next -* paragraph) shall be included in all copies or substantial portions of the -* Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -* IN THE SOFTWARE. +* SPDX-License-Identifier: MIT * +* Copyright © 2016 Intel Corporation */ #ifndef __I915_GEM_OBJECT_H__#define __I915_GEM_OBJECT_H__ -#include <linux/reservation.h> - -#include <drm/drm_vma_manager.h> #include <drm/drm_gem.h> #include <drm/drm_file.h> #include <drm/drm_device.h> #include <drm/i915_drm.h> -#include "i915_request.h" -#include "i915_selftest.h" - -struct drm_i915_gem_object ; - -/* -* struct i915_lut_handle tracks the fast lookups from handle to vma used -* for execbuf. Although we use a radixtree for that mapping, in order to -* remove them as the object or context is closed, we need a secondary list -* and a translation entry (i915_lut_handle). -*/ -struct i915_lut_handle { -struct list_head obj_link; -struct list_head ctx_link; -struct i915_gem_context *ctx; -u32 handle; -}; - -struct drm_i915_gem_object_ops { -unsigned int flags; -#define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0) -#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(1) -#define I915_GEM_OBJECT_IS_PROXY BIT(2) -#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(3) - -/* Interface between the GEM object and its backing storage. -* get_pages() is called once prior to the use of the associated set -* of pages before to binding them into the GTT, and put_pages() is -* called after we no longer need them. As we expect there to be -* associated cost with migrating pages between the backing storage -* and making them available for the GPU (e.g. clflush), we may hold -* onto the pages after they are no longer referenced by the GPU -* in case they may be used again shortly (for example migrating the -* pages to a different memory domain within the GTT). put_pages() -* will therefore most likely be called when the object itself is -* being released or under memory pressure (where we attempt to -* reap pages for the shrinker). -*/ -int (*get_pages)(struct drm_i915_gem_object *); -void (*put_pages)(struct drm_i915_gem_object *,struct sg_table *); - -int (*pwrite)(struct drm_i915_gem_object *, -const struct drm_i915_gem_pwrite *); - -int (*dmabuf_export)(struct drm_i915_gem_object *); -void (*release)(struct drm_i915_gem_object *); -}; - -struct drm_i915_gem_object { -struct drm_gem_object base; - -const struct drm_i915_gem_object_ops *ops; - -struct { -/** -* @vma.lock: protect the list/tree of vmas -*/ -spinlock_t lock; - -/** -* @vma.list: List of VMAs backed by this object -* -* The VMA on this list are ordered by type, all GGTT vma are -* placed at the head and all ppGTT vma are placed at the tail. -* The different types of GGTT vma are unordered between -* themselves, use the @vma.tree (which has a defined order -* between all VMA) to quickly find an exact match. -*/ -struct list_head list; - -/** -* @vma.tree: Ordered tree of VMAs backed by this object -* -* All VMA created for this object are placed in the @vma.tree -* for fast retrieval via a binary search in -* i915_vma_instance(). They are also added to @vma.list for -* easy iteration. -*/ -struct rb_root tree; - } vma; - -/** -* @lut_list: List of vma lookup entries in use for this object. -* -* If this object is closed, we need to remove all of its VMA from -* the fast lookup index in associated contexts; @lut_list provides -* this translation from object to context->handles_vma. -*/ -struct list_head lut_list; - -/** Stolen memory for this object, instead of being backed by shmem. */ -struct drm_mm_node *stolen; -union { -struct rcu_head rcu; -struct llist_node freed; - }; - -/** -* Whether the object is currently in the GGTT mmap. -*/ -unsigned int userfault_count; -struct list_head userfault_link; - -struct list_head batch_pool_link; - I915_SELFTEST_DECLARE(struct list_head st_link); - -unsigned long flags; - -/** -* Have we taken a reference for the object for incomplete GPU -* activity? -*/ -#define I915_BO_ACTIVE_REF 0 - -/* -* Is the object to be mapped as read-only to the GPU -* Only honoured if hardware has relevant pte bit -*/ -unsigned int cache_level:3 ; -unsigned int cache_coherent:2 ; -#define I915_BO_CACHE_COHERENT_FOR_READ BIT(0) -#define I915_BO_CACHE_COHERENT_FOR_WRITE BIT(1) -unsigned int cache_dirty:1 ; - -/** -* @read_domains: Read memory domains. -* -* These monitor which caches contain read/write data related to the -* object. When transitioning from one set of domains to another, -* the driver is called to ensure that caches are suitably flushed and -* invalidated. -*/ -u16 read_domains; - -/** -* @write_domain: Corresponding unique write memory domain. -*/ -u16 write_domain; - -atomic_t frontbuffer_bits; -unsigned int frontbuffer_ggtt_origin;/* write once */ -struct i915_active_request frontbuffer_write; - -/** Current tiling stride for the object, if it's tiled. */ -unsigned int tiling_and_stride; -#define FENCE_MINIMUM_STRIDE 128/* See i915_tiling_ok() */ -#define TILING_MASK (FENCE_MINIMUM_STRIDE-1) -#define STRIDE_MASK (~TILING_MASK) - -/** Count of VMA actually bound by this object */ -unsigned int bind_count; -unsigned int active_count; -/** Count of how many global VMA are currently pinned for use by HW */ -unsigned int pin_global; - -struct { -struct mutex lock;/* protects the pages and their use */ -atomic_t pages_pin_count; - -struct sg_table *pages; -void *mapping; - -/* TODO: whack some of this into the error state */ -struct i915_page_sizes { -/** -* The sg mask of the pages sg_table. i.e the mask of -* of the lengths for each sg entry. -*/ -unsigned int phys; - -/** -* The gtt page sizes we are allowed to use given the -* sg mask and the supported page sizes. This will -* express the smallest unit we can use for the whole -* object, as well as the larger sizes we may be able -* to use opportunistically. -*/ -unsigned int sg; - -/** -* The actual gtt page size usage. Since we can have -* multiple vma associated with this object we need to -* prevent any trampling of state, hence a copy of this -* struct also lives in each vma, therefore the gtt -* value here should only be read/write through the vma. -*/ -unsigned int gtt; - } page_sizes; - - I915_SELFTEST_DECLARE(unsigned int page_mask); - -struct i915_gem_object_page_iter { -struct scatterlist *sg_pos; -unsigned int sg_idx;/* in pages, but 32bit eek! */ - -struct radix_tree_root radix; -struct mutex lock;/* protects this cache */ - } get_page; - -/** -* Element within i915->mm.unbound_list or i915->mm.bound_list, -* locked by i915->mm.obj_lock. -*/ -struct list_head link; - -/** -* Advice: are the backing pages purgeable? -*/ -unsigned int madv:2 ; - -/** -* This is set if the object has been written to since the -* pages were last acquired. -*/ -bool dirty:1 ; - -/** -* This is set if the object has been pinned due to unknown -* swizzling. -*/ -bool quirked:1 ; - } mm; - -/** Breadcrumb of last rendering to the buffer. -* There can only be one writer, but we allow for multiple readers. -* If there is a writer that necessarily implies that all other -* read requests are complete - but we may only be lazily clearing -* the read requests. A read request is naturally the most recent -* request on a ring, so we may have two different write and read -* requests on one ring where the write request is older than the -* read request. This allows for the CPU to read from an active -* buffer by only waiting for the write to complete. -*/ -struct reservation_object *resv; - -/** References from framebuffers, locks out tiling changes. */ -unsigned int framebuffer_references; - -/** Record of address bit 17 of each page at last unbind. */ -unsigned long *bit_17; - -union { -struct i915_gem_userptr { -uintptr_t ptr; - -struct i915_mm_struct *mm; -struct i915_mmu_object *mmu_object; -struct work_struct *work; - } userptr; - -unsigned long scratch; - -void *gvt_info; - }; - -/** for phys allocated objects */ -struct drm_dma_handle *phys_handle; - -struct reservation_object __builtin_resv; -}; - -static inline struct drm_i915_gem_object * -to_intel_bo (struct drm_gem_object *gem) -{ -/* Assert that to_intel_bo(NULL) == NULL */ -BUILD_BUG_ON (offsetof(struct drm_i915_gem_object , base)); - - return container_of(gem, struct drm_i915_gem_object, base); -} +#include "gem/i915_gem_object_types.h" struct drm_i915_gem_object *i915_gem_object_alloc (void );void i915_gem_object_free (struct drm_i915_gem_object *obj);
Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 24/45] drm/i915: Split GEM object type definition to its own header
Quoting Jani Nikula (2019-04-26 15:12:49)
Quoted 34 lines · Chris Wilson
Quoted 25 lines
For convenience in avoiding inline spaghetti, keep the type definition as a separate header.
Signed-off-by Chris Wilson <[email protected]>Reviewed-by Matthew Auld <[email protected]>--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/gem/Makefile | 1 + drivers/gpu/drm/i915/gem/Makefile.header-test | 16 + .../gpu/drm/i915/gem/i915_gem_object_types.h | 285 +++++++++++++++++ drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 + drivers/gpu/drm/i915/i915_drv.h | 3 +- drivers/gpu/drm/i915/i915_gem_batch_pool.h | 3 +- drivers/gpu/drm/i915/i915_gem_gtt.h | 1 + drivers/gpu/drm/i915/i915_gem_object.h | 295 +----------------- 9 files changed, 312 insertions(+), 294 deletions(-) create mode 100644 drivers/gpu/drm/i915/gem/Makefile create mode 100644 drivers/gpu/drm/i915/gem/Makefile.header-test create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_object_types.hdrivers/gpu/drm/i915/Makefile +0
-0drivers/gpu/drm/i915/Makefile gt-$(CONFIG_DRM_I915_SELFTEST) += \ · line 88
Quoted 4 lines
drivers/gpu/drm/i915/Makefile +1
-0@@ -85,6 +85,7 @@ gt-$(CONFIG_DRM_I915_SELFTEST) += \ i915-y += $(gt-y) # GEM (Graphics Execution Management) code +obj-y += gem/I think this warrants similar treatment as gt/. Posted standalone instead of hidden in a series, explicit acks.
Quoted 3 lines
Provided the split makes sense to Joonas,
Acked-by Jani Nikula <[email protected]>
Yeah, makes sense to me.
Regards, Joonas
Quoted 705 lines
Quoted 705 lines
drivers/gpu/drm/i915/Makefile +0
-0i915-y += \ i915_active.o \ i915_cmd_parser.o \drivers/gpu/drm/i915/gem/Makefile new file +1
-0@@ -0,0 +1 @@ +include $(src)/Makefile.header-test # Extra header testsdrivers/gpu/drm/i915/gem/Makefile.header-test new file +16
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: MIT +# Copyright © 2019 Intel Corporation + +# Test the headers are compilable as standalone units +header_test := $(notdir $(wildcard $(src)/*.h)) + +quiet_cmd_header_test = HDRTEST $@ + cmd_header_test = echo "\#include \"$(<F)\"" > $@ + +header_test_%.c: %.h + $(call cmd,header_test) + +extra-$(CONFIG_DRM_I915_WERROR) += \ + $(foreach h,$(header_test),$(patsubst %.h,header_test_%.o,$(h))) + +clean-files += $(foreach h,$(header_test),$(patsubst %.h,header_test_%.c,$(h)))drivers/gpu/drm/i915/gem/i915_gem_object_types.h new file +285
-0@@ -0,0 +1,285 @@ +/* +* SPDX-License-Identifier: MIT +* +* Copyright © 2016 Intel Corporation +*/ + +#ifndef __I915_GEM_OBJECT_TYPES_H__ +#define __I915_GEM_OBJECT_TYPES_H__ + +#include <linux/reservation.h> + +#include <drm/drm_gem.h> + +#include "../i915_active.h" +#include "../i915_selftest.h" + +struct drm_i915_gem_object ; + +/* +* struct i915_lut_handle tracks the fast lookups from handle to vma used +* for execbuf. Although we use a radixtree for that mapping, in order to +* remove them as the object or context is closed, we need a secondary list +* and a translation entry (i915_lut_handle). +*/ +struct i915_lut_handle { +struct list_head obj_link; +struct list_head ctx_link; +struct i915_gem_context *ctx; +u32 handle; +}; + +struct drm_i915_gem_object_ops { +unsigned int flags; +#define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0) +#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(1) +#define I915_GEM_OBJECT_IS_PROXY BIT(2) +#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(3) + +/* Interface between the GEM object and its backing storage. +* get_pages() is called once prior to the use of the associated set +* of pages before to binding them into the GTT, and put_pages() is +* called after we no longer need them. As we expect there to be +* associated cost with migrating pages between the backing storage +* and making them available for the GPU (e.g. clflush), we may hold +* onto the pages after they are no longer referenced by the GPU +* in case they may be used again shortly (for example migrating the +* pages to a different memory domain within the GTT). put_pages() +* will therefore most likely be called when the object itself is +* being released or under memory pressure (where we attempt to +* reap pages for the shrinker). +*/ +int (*get_pages)(struct drm_i915_gem_object *obj); +void (*put_pages)(struct drm_i915_gem_object *obj, +struct sg_table *pages); + +int (*pwrite)(struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pwrite *arg); + +int (*dmabuf_export)(struct drm_i915_gem_object *obj); +void (*release)(struct drm_i915_gem_object *obj); +}; + +struct drm_i915_gem_object { +struct drm_gem_object base; + +const struct drm_i915_gem_object_ops *ops; + +struct { +/** +* @vma.lock: protect the list/tree of vmas +*/ +spinlock_t lock; + +/** +* @vma.list: List of VMAs backed by this object +* +* The VMA on this list are ordered by type, all GGTT vma are +* placed at the head and all ppGTT vma are placed at the tail. +* The different types of GGTT vma are unordered between +* themselves, use the @vma.tree (which has a defined order +* between all VMA) to quickly find an exact match. +*/ +struct list_head list; + +/** +* @vma.tree: Ordered tree of VMAs backed by this object +* +* All VMA created for this object are placed in the @vma.tree +* for fast retrieval via a binary search in +* i915_vma_instance(). They are also added to @vma.list for +* easy iteration. +*/ +struct rb_root tree; + } vma; + +/** +* @lut_list: List of vma lookup entries in use for this object. +* +* If this object is closed, we need to remove all of its VMA from +* the fast lookup index in associated contexts; @lut_list provides +* this translation from object to context->handles_vma. +*/ +struct list_head lut_list; + +/** Stolen memory for this object, instead of being backed by shmem. */ +struct drm_mm_node *stolen; +union { +struct rcu_head rcu; +struct llist_node freed; + }; + +/** +* Whether the object is currently in the GGTT mmap. +*/ +unsigned int userfault_count; +struct list_head userfault_link; + +struct list_head batch_pool_link; + I915_SELFTEST_DECLARE(struct list_head st_link); + +unsigned long flags; + +/** +* Have we taken a reference for the object for incomplete GPU +* activity? +*/ +#define I915_BO_ACTIVE_REF 0 + +/* +* Is the object to be mapped as read-only to the GPU +* Only honoured if hardware has relevant pte bit +*/ +unsigned int cache_level:3 ; +unsigned int cache_coherent:2 ; +#define I915_BO_CACHE_COHERENT_FOR_READ BIT(0) +#define I915_BO_CACHE_COHERENT_FOR_WRITE BIT(1) +unsigned int cache_dirty:1 ; + +/** +* @read_domains: Read memory domains. +* +* These monitor which caches contain read/write data related to the +* object. When transitioning from one set of domains to another, +* the driver is called to ensure that caches are suitably flushed and +* invalidated. +*/ +u16 read_domains; + +/** +* @write_domain: Corresponding unique write memory domain. +*/ +u16 write_domain; + +atomic_t frontbuffer_bits; +unsigned int frontbuffer_ggtt_origin;/* write once */ +struct i915_active_request frontbuffer_write; + +/** Current tiling stride for the object, if it's tiled. */ +unsigned int tiling_and_stride; +#define FENCE_MINIMUM_STRIDE 128/* See i915_tiling_ok() */ +#define TILING_MASK (FENCE_MINIMUM_STRIDE - 1) +#define STRIDE_MASK (~TILING_MASK) + +/** Count of VMA actually bound by this object */ +unsigned int bind_count; +unsigned int active_count; +/** Count of how many global VMA are currently pinned for use by HW */ +unsigned int pin_global; + +struct { +struct mutex lock;/* protects the pages and their use */ +atomic_t pages_pin_count; + +struct sg_table *pages; +void *mapping; + +/* TODO: whack some of this into the error state */ +struct i915_page_sizes { +/** +* The sg mask of the pages sg_table. i.e the mask of +* of the lengths for each sg entry. +*/ +unsigned int phys; + +/** +* The gtt page sizes we are allowed to use given the +* sg mask and the supported page sizes. This will +* express the smallest unit we can use for the whole +* object, as well as the larger sizes we may be able +* to use opportunistically. +*/ +unsigned int sg; + +/** +* The actual gtt page size usage. Since we can have +* multiple vma associated with this object we need to +* prevent any trampling of state, hence a copy of this +* struct also lives in each vma, therefore the gtt +* value here should only be read/write through the vma. +*/ +unsigned int gtt; + } page_sizes; + + I915_SELFTEST_DECLARE(unsigned int page_mask); + +struct i915_gem_object_page_iter { +struct scatterlist *sg_pos; +unsigned int sg_idx;/* in pages, but 32bit eek! */ + +struct radix_tree_root radix; +struct mutex lock;/* protects this cache */ + } get_page; + +/** +* Element within i915->mm.unbound_list or i915->mm.bound_list, +* locked by i915->mm.obj_lock. +*/ +struct list_head link; + +/** +* Advice: are the backing pages purgeable? +*/ +unsigned int madv:2 ; + +/** +* This is set if the object has been written to since the +* pages were last acquired. +*/ +bool dirty:1 ; + +/** +* This is set if the object has been pinned due to unknown +* swizzling. +*/ +bool quirked:1 ; + } mm; + +/** Breadcrumb of last rendering to the buffer. +* There can only be one writer, but we allow for multiple readers. +* If there is a writer that necessarily implies that all other +* read requests are complete - but we may only be lazily clearing +* the read requests. A read request is naturally the most recent +* request on a ring, so we may have two different write and read +* requests on one ring where the write request is older than the +* read request. This allows for the CPU to read from an active +* buffer by only waiting for the write to complete. +*/ +struct reservation_object *resv; + +/** References from framebuffers, locks out tiling changes. */ +unsigned int framebuffer_references; + +/** Record of address bit 17 of each page at last unbind. */ +unsigned long *bit_17; + +union { +struct i915_gem_userptr { +uintptr_t ptr; + +struct i915_mm_struct *mm; +struct i915_mmu_object *mmu_object; +struct work_struct *work; + } userptr; + +unsigned long scratch; + +void *gvt_info; + }; + +/** for phys allocated objects */ +struct drm_dma_handle *phys_handle; + +struct reservation_object __builtin_resv; +}; + +static inline struct drm_i915_gem_object * +to_intel_bo (struct drm_gem_object *gem) +{ +/* Assert that to_intel_bo(NULL) == NULL */ +BUILD_BUG_ON (offsetof(struct drm_i915_gem_object , base)); + + return container_of(gem, struct drm_i915_gem_object, base); +} + +#endif drivers/gpu/drm/i915/gt/intel_engine_types.h +1
-0@@ -29,6 +29,7 @@#define I915_CMD_HASH_ORDER 9struct dma_fence ; +struct drm_i915_gem_object ;struct drm_i915_reg_table ;struct i915_gem_context ;struct i915_request ;drivers/gpu/drm/i915/i915_drv.h +2
-1@@ -80,7 +80,6 @@#include "i915_gem.h" #include "i915_gem_context.h" #include "i915_gem_fence_reg.h" -#include "i915_gem_object.h" #include "i915_gem_gtt.h" #include "i915_gpu_error.h" #include "i915_request.h" @@ -135,6 +134,8 @@ bool i915_error_injected(void);__i915_printk (i915,i915_error_injected () ?KERN_DEBUG :KERN_ERR , \ fmt, ##__VA_ARGS__) +struct drm_i915_gem_object ; +enum hpd_pin {HPD_NONE =0 ,HPD_TV =HPD_NONE ,/* TV is known to be unreliable */ drivers/gpu/drm/i915/i915_gem_batch_pool.h +2
-1@@ -9,6 +9,7 @@#include <linux/types.h> +struct drm_i915_gem_object ;struct intel_engine_cs ;struct i915_gem_batch_pool {@@ -19,7 +20,7 @@ struct i915_gem_batch_pool {void i915_gem_batch_pool_init (struct i915_gem_batch_pool *pool,struct intel_engine_cs *engine);void i915_gem_batch_pool_fini (struct i915_gem_batch_pool *pool); -struct drm_i915_gem_object * +struct drm_i915_gem_object *i915_gem_batch_pool_get (struct i915_gem_batch_pool *pool,size_t size);#endif /* I915_GEM_BATCH_POOL_H */ drivers/gpu/drm/i915/i915_gem_gtt.h +1
-0@@ -61,6 +61,7 @@struct drm_i915_file_private ;struct drm_i915_fence_reg ; +struct drm_i915_gem_object ;struct i915_vma ;typedef u32 gen6_pte_t ;drivers/gpu/drm/i915/i915_gem_object.h +3
-292@@ -1,308 +1,19 @@/* -* Copyright © 2016 Intel Corporation -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice (including the next -* paragraph) shall be included in all copies or substantial portions of the -* Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -* IN THE SOFTWARE. +* SPDX-License-Identifier: MIT * +* Copyright © 2016 Intel Corporation */ #ifndef __I915_GEM_OBJECT_H__#define __I915_GEM_OBJECT_H__ -#include <linux/reservation.h> - -#include <drm/drm_vma_manager.h> #include <drm/drm_gem.h> #include <drm/drm_file.h> #include <drm/drm_device.h> #include <drm/i915_drm.h> -#include "i915_request.h" -#include "i915_selftest.h" - -struct drm_i915_gem_object ; - -/* -* struct i915_lut_handle tracks the fast lookups from handle to vma used -* for execbuf. Although we use a radixtree for that mapping, in order to -* remove them as the object or context is closed, we need a secondary list -* and a translation entry (i915_lut_handle). -*/ -struct i915_lut_handle { -struct list_head obj_link; -struct list_head ctx_link; -struct i915_gem_context *ctx; -u32 handle; -}; - -struct drm_i915_gem_object_ops { -unsigned int flags; -#define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0) -#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(1) -#define I915_GEM_OBJECT_IS_PROXY BIT(2) -#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(3) - -/* Interface between the GEM object and its backing storage. -* get_pages() is called once prior to the use of the associated set -* of pages before to binding them into the GTT, and put_pages() is -* called after we no longer need them. As we expect there to be -* associated cost with migrating pages between the backing storage -* and making them available for the GPU (e.g. clflush), we may hold -* onto the pages after they are no longer referenced by the GPU -* in case they may be used again shortly (for example migrating the -* pages to a different memory domain within the GTT). put_pages() -* will therefore most likely be called when the object itself is -* being released or under memory pressure (where we attempt to -* reap pages for the shrinker). -*/ -int (*get_pages)(struct drm_i915_gem_object *); -void (*put_pages)(struct drm_i915_gem_object *,struct sg_table *); - -int (*pwrite)(struct drm_i915_gem_object *, -const struct drm_i915_gem_pwrite *); - -int (*dmabuf_export)(struct drm_i915_gem_object *); -void (*release)(struct drm_i915_gem_object *); -}; - -struct drm_i915_gem_object { -struct drm_gem_object base; - -const struct drm_i915_gem_object_ops *ops; - -struct { -/** -* @vma.lock: protect the list/tree of vmas -*/ -spinlock_t lock; - -/** -* @vma.list: List of VMAs backed by this object -* -* The VMA on this list are ordered by type, all GGTT vma are -* placed at the head and all ppGTT vma are placed at the tail. -* The different types of GGTT vma are unordered between -* themselves, use the @vma.tree (which has a defined order -* between all VMA) to quickly find an exact match. -*/ -struct list_head list; - -/** -* @vma.tree: Ordered tree of VMAs backed by this object -* -* All VMA created for this object are placed in the @vma.tree -* for fast retrieval via a binary search in -* i915_vma_instance(). They are also added to @vma.list for -* easy iteration. -*/ -struct rb_root tree; - } vma; - -/** -* @lut_list: List of vma lookup entries in use for this object. -* -* If this object is closed, we need to remove all of its VMA from -* the fast lookup index in associated contexts; @lut_list provides -* this translation from object to context->handles_vma. -*/ -struct list_head lut_list; - -/** Stolen memory for this object, instead of being backed by shmem. */ -struct drm_mm_node *stolen; -union { -struct rcu_head rcu; -struct llist_node freed; - }; - -/** -* Whether the object is currently in the GGTT mmap. -*/ -unsigned int userfault_count; -struct list_head userfault_link; - -struct list_head batch_pool_link; - I915_SELFTEST_DECLARE(struct list_head st_link); - -unsigned long flags; - -/** -* Have we taken a reference for the object for incomplete GPU -* activity? -*/ -#define I915_BO_ACTIVE_REF 0 - -/* -* Is the object to be mapped as read-only to the GPU -* Only honoured if hardware has relevant pte bit -*/ -unsigned int cache_level:3 ; -unsigned int cache_coherent:2 ; -#define I915_BO_CACHE_COHERENT_FOR_READ BIT(0) -#define I915_BO_CACHE_COHERENT_FOR_WRITE BIT(1) -unsigned int cache_dirty:1 ; - -/** -* @read_domains: Read memory domains. -* -* These monitor which caches contain read/write data related to the -* object. When transitioning from one set of domains to another, -* the driver is called to ensure that caches are suitably flushed and -* invalidated. -*/ -u16 read_domains; - -/** -* @write_domain: Corresponding unique write memory domain. -*/ -u16 write_domain; - -atomic_t frontbuffer_bits; -unsigned int frontbuffer_ggtt_origin;/* write once */ -struct i915_active_request frontbuffer_write; - -/** Current tiling stride for the object, if it's tiled. */ -unsigned int tiling_and_stride; -#define FENCE_MINIMUM_STRIDE 128/* See i915_tiling_ok() */ -#define TILING_MASK (FENCE_MINIMUM_STRIDE-1) -#define STRIDE_MASK (~TILING_MASK) - -/** Count of VMA actually bound by this object */ -unsigned int bind_count; -unsigned int active_count; -/** Count of how many global VMA are currently pinned for use by HW */ -unsigned int pin_global; - -struct { -struct mutex lock;/* protects the pages and their use */ -atomic_t pages_pin_count; - -struct sg_table *pages; -void *mapping; - -/* TODO: whack some of this into the error state */ -struct i915_page_sizes { -/** -* The sg mask of the pages sg_table. i.e the mask of -* of the lengths for each sg entry. -*/ -unsigned int phys; - -/** -* The gtt page sizes we are allowed to use given the -* sg mask and the supported page sizes. This will -* express the smallest unit we can use for the whole -* object, as well as the larger sizes we may be able -* to use opportunistically. -*/ -unsigned int sg; - -/** -* The actual gtt page size usage. Since we can have -* multiple vma associated with this object we need to -* prevent any trampling of state, hence a copy of this -* struct also lives in each vma, therefore the gtt -* value here should only be read/write through the vma. -*/ -unsigned int gtt; - } page_sizes; - - I915_SELFTEST_DECLARE(unsigned int page_mask); - -struct i915_gem_object_page_iter { -struct scatterlist *sg_pos; -unsigned int sg_idx;/* in pages, but 32bit eek! */ - -struct radix_tree_root radix; -struct mutex lock;/* protects this cache */ - } get_page; - -/** -* Element within i915->mm.unbound_list or i915->mm.bound_list, -* locked by i915->mm.obj_lock. -*/ -struct list_head link; - -/** -* Advice: are the backing pages purgeable? -*/ -unsigned int madv:2 ; - -/** -* This is set if the object has been written to since the -* pages were last acquired. -*/ -bool dirty:1 ; - -/** -* This is set if the object has been pinned due to unknown -* swizzling. -*/ -bool quirked:1 ; - } mm; - -/** Breadcrumb of last rendering to the buffer. -* There can only be one writer, but we allow for multiple readers. -* If there is a writer that necessarily implies that all other -* read requests are complete - but we may only be lazily clearing -* the read requests. A read request is naturally the most recent -* request on a ring, so we may have two different write and read -* requests on one ring where the write request is older than the -* read request. This allows for the CPU to read from an active -* buffer by only waiting for the write to complete. -*/ -struct reservation_object *resv; - -/** References from framebuffers, locks out tiling changes. */ -unsigned int framebuffer_references; - -/** Record of address bit 17 of each page at last unbind. */ -unsigned long *bit_17; - -union { -struct i915_gem_userptr { -uintptr_t ptr; - -struct i915_mm_struct *mm; -struct i915_mmu_object *mmu_object; -struct work_struct *work; - } userptr; - -unsigned long scratch; - -void *gvt_info; - }; - -/** for phys allocated objects */ -struct drm_dma_handle *phys_handle; - -struct reservation_object __builtin_resv; -}; - -static inline struct drm_i915_gem_object * -to_intel_bo (struct drm_gem_object *gem) -{ -/* Assert that to_intel_bo(NULL) == NULL */ -BUILD_BUG_ON (offsetof(struct drm_i915_gem_object , base)); - - return container_of(gem, struct drm_i915_gem_object, base); -} +#include "gem/i915_gem_object_types.h"
Quoted 5 lines
Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_object.h +0
-0struct drm_i915_gem_object *i915_gem_object_alloc (void );void i915_gem_object_free (struct drm_i915_gem_object *obj);Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 24/45] drm/i915: Split GEM object type definition to its own header
Quoted 37 lines · Joonas Lahtinen
Quoting Jani Nikula (2019-04-26 15:12:49)
Quoted 36 lines · Chris Wilson
Quoted 25 lines
For convenience in avoiding inline spaghetti, keep the type definition as a separate header.
Signed-off-by Chris Wilson <[email protected]>Reviewed-by Matthew Auld <[email protected]>--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/gem/Makefile | 1 + drivers/gpu/drm/i915/gem/Makefile.header-test | 16 + .../gpu/drm/i915/gem/i915_gem_object_types.h | 285 +++++++++++++++++ drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 + drivers/gpu/drm/i915/i915_drv.h | 3 +- drivers/gpu/drm/i915/i915_gem_batch_pool.h | 3 +- drivers/gpu/drm/i915/i915_gem_gtt.h | 1 + drivers/gpu/drm/i915/i915_gem_object.h | 295 +----------------- 9 files changed, 312 insertions(+), 294 deletions(-) create mode 100644 drivers/gpu/drm/i915/gem/Makefile create mode 100644 drivers/gpu/drm/i915/gem/Makefile.header-test create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_object_types.hdrivers/gpu/drm/i915/Makefile +0
-0drivers/gpu/drm/i915/Makefile gt-$(CONFIG_DRM_I915_SELFTEST) += \ · line 88
Quoted 4 lines
drivers/gpu/drm/i915/Makefile +1
-0@@ -85,6 +85,7 @@ gt-$(CONFIG_DRM_I915_SELFTEST) += \ i915-y += $(gt-y) # GEM (Graphics Execution Management) code +obj-y += gem/I think this warrants similar treatment as gt/. Posted standalone instead of hidden in a series, explicit acks.
Provided the split makes sense to Joonas,
Quoted 7 lines
Quoted 1 line
Acked-by Jani Nikula <[email protected]>Yeah, makes sense to me.
Acked-by Joonas Lahtinen <[email protected]>Regards, Joonas
I liked the idea of splitting gem from gt, so:
Quoted 711 lines
Quoted 706 lines
Quoted 706 lines
drivers/gpu/drm/i915/Makefile +0
-0i915-y += \ i915_active.o \ i915_cmd_parser.o \drivers/gpu/drm/i915/gem/Makefile new file +1
-0@@ -0,0 +1 @@ +include $(src)/Makefile.header-test # Extra header testsdrivers/gpu/drm/i915/gem/Makefile.header-test new file +16
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: MIT +# Copyright © 2019 Intel Corporation + +# Test the headers are compilable as standalone units +header_test := $(notdir $(wildcard $(src)/*.h)) + +quiet_cmd_header_test = HDRTEST $@ + cmd_header_test = echo "\#include \"$(<F)\"" > $@ + +header_test_%.c: %.h + $(call cmd,header_test) + +extra-$(CONFIG_DRM_I915_WERROR) += \ + $(foreach h,$(header_test),$(patsubst %.h,header_test_%.o,$(h))) + +clean-files += $(foreach h,$(header_test),$(patsubst %.h,header_test_%.c,$(h)))drivers/gpu/drm/i915/gem/i915_gem_object_types.h new file +285
-0@@ -0,0 +1,285 @@ +/* +* SPDX-License-Identifier: MIT +* +* Copyright © 2016 Intel Corporation +*/ + +#ifndef __I915_GEM_OBJECT_TYPES_H__ +#define __I915_GEM_OBJECT_TYPES_H__ + +#include <linux/reservation.h> + +#include <drm/drm_gem.h> + +#include "../i915_active.h" +#include "../i915_selftest.h" + +struct drm_i915_gem_object ; + +/* +* struct i915_lut_handle tracks the fast lookups from handle to vma used +* for execbuf. Although we use a radixtree for that mapping, in order to +* remove them as the object or context is closed, we need a secondary list +* and a translation entry (i915_lut_handle). +*/ +struct i915_lut_handle { +struct list_head obj_link; +struct list_head ctx_link; +struct i915_gem_context *ctx; +u32 handle; +}; + +struct drm_i915_gem_object_ops { +unsigned int flags; +#define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0) +#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(1) +#define I915_GEM_OBJECT_IS_PROXY BIT(2) +#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(3) + +/* Interface between the GEM object and its backing storage. +* get_pages() is called once prior to the use of the associated set +* of pages before to binding them into the GTT, and put_pages() is +* called after we no longer need them. As we expect there to be +* associated cost with migrating pages between the backing storage +* and making them available for the GPU (e.g. clflush), we may hold +* onto the pages after they are no longer referenced by the GPU +* in case they may be used again shortly (for example migrating the +* pages to a different memory domain within the GTT). put_pages() +* will therefore most likely be called when the object itself is +* being released or under memory pressure (where we attempt to +* reap pages for the shrinker). +*/ +int (*get_pages)(struct drm_i915_gem_object *obj); +void (*put_pages)(struct drm_i915_gem_object *obj, +struct sg_table *pages); + +int (*pwrite)(struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pwrite *arg); + +int (*dmabuf_export)(struct drm_i915_gem_object *obj); +void (*release)(struct drm_i915_gem_object *obj); +}; + +struct drm_i915_gem_object { +struct drm_gem_object base; + +const struct drm_i915_gem_object_ops *ops; + +struct { +/** +* @vma.lock: protect the list/tree of vmas +*/ +spinlock_t lock; + +/** +* @vma.list: List of VMAs backed by this object +* +* The VMA on this list are ordered by type, all GGTT vma are +* placed at the head and all ppGTT vma are placed at the tail. +* The different types of GGTT vma are unordered between +* themselves, use the @vma.tree (which has a defined order +* between all VMA) to quickly find an exact match. +*/ +struct list_head list; + +/** +* @vma.tree: Ordered tree of VMAs backed by this object +* +* All VMA created for this object are placed in the @vma.tree +* for fast retrieval via a binary search in +* i915_vma_instance(). They are also added to @vma.list for +* easy iteration. +*/ +struct rb_root tree; + } vma; + +/** +* @lut_list: List of vma lookup entries in use for this object. +* +* If this object is closed, we need to remove all of its VMA from +* the fast lookup index in associated contexts; @lut_list provides +* this translation from object to context->handles_vma. +*/ +struct list_head lut_list; + +/** Stolen memory for this object, instead of being backed by shmem. */ +struct drm_mm_node *stolen; +union { +struct rcu_head rcu; +struct llist_node freed; + }; + +/** +* Whether the object is currently in the GGTT mmap. +*/ +unsigned int userfault_count; +struct list_head userfault_link; + +struct list_head batch_pool_link; + I915_SELFTEST_DECLARE(struct list_head st_link); + +unsigned long flags; + +/** +* Have we taken a reference for the object for incomplete GPU +* activity? +*/ +#define I915_BO_ACTIVE_REF 0 + +/* +* Is the object to be mapped as read-only to the GPU +* Only honoured if hardware has relevant pte bit +*/ +unsigned int cache_level:3 ; +unsigned int cache_coherent:2 ; +#define I915_BO_CACHE_COHERENT_FOR_READ BIT(0) +#define I915_BO_CACHE_COHERENT_FOR_WRITE BIT(1) +unsigned int cache_dirty:1 ; + +/** +* @read_domains: Read memory domains. +* +* These monitor which caches contain read/write data related to the +* object. When transitioning from one set of domains to another, +* the driver is called to ensure that caches are suitably flushed and +* invalidated. +*/ +u16 read_domains; + +/** +* @write_domain: Corresponding unique write memory domain. +*/ +u16 write_domain; + +atomic_t frontbuffer_bits; +unsigned int frontbuffer_ggtt_origin;/* write once */ +struct i915_active_request frontbuffer_write; + +/** Current tiling stride for the object, if it's tiled. */ +unsigned int tiling_and_stride; +#define FENCE_MINIMUM_STRIDE 128/* See i915_tiling_ok() */ +#define TILING_MASK (FENCE_MINIMUM_STRIDE - 1) +#define STRIDE_MASK (~TILING_MASK) + +/** Count of VMA actually bound by this object */ +unsigned int bind_count; +unsigned int active_count; +/** Count of how many global VMA are currently pinned for use by HW */ +unsigned int pin_global; + +struct { +struct mutex lock;/* protects the pages and their use */ +atomic_t pages_pin_count; + +struct sg_table *pages; +void *mapping; + +/* TODO: whack some of this into the error state */ +struct i915_page_sizes { +/** +* The sg mask of the pages sg_table. i.e the mask of +* of the lengths for each sg entry. +*/ +unsigned int phys; + +/** +* The gtt page sizes we are allowed to use given the +* sg mask and the supported page sizes. This will +* express the smallest unit we can use for the whole +* object, as well as the larger sizes we may be able +* to use opportunistically. +*/ +unsigned int sg; + +/** +* The actual gtt page size usage. Since we can have +* multiple vma associated with this object we need to +* prevent any trampling of state, hence a copy of this +* struct also lives in each vma, therefore the gtt +* value here should only be read/write through the vma. +*/ +unsigned int gtt; + } page_sizes; + + I915_SELFTEST_DECLARE(unsigned int page_mask); + +struct i915_gem_object_page_iter { +struct scatterlist *sg_pos; +unsigned int sg_idx;/* in pages, but 32bit eek! */ + +struct radix_tree_root radix; +struct mutex lock;/* protects this cache */ + } get_page; + +/** +* Element within i915->mm.unbound_list or i915->mm.bound_list, +* locked by i915->mm.obj_lock. +*/ +struct list_head link; + +/** +* Advice: are the backing pages purgeable? +*/ +unsigned int madv:2 ; + +/** +* This is set if the object has been written to since the +* pages were last acquired. +*/ +bool dirty:1 ; + +/** +* This is set if the object has been pinned due to unknown +* swizzling. +*/ +bool quirked:1 ; + } mm; + +/** Breadcrumb of last rendering to the buffer. +* There can only be one writer, but we allow for multiple readers. +* If there is a writer that necessarily implies that all other +* read requests are complete - but we may only be lazily clearing +* the read requests. A read request is naturally the most recent +* request on a ring, so we may have two different write and read +* requests on one ring where the write request is older than the +* read request. This allows for the CPU to read from an active +* buffer by only waiting for the write to complete. +*/ +struct reservation_object *resv; + +/** References from framebuffers, locks out tiling changes. */ +unsigned int framebuffer_references; + +/** Record of address bit 17 of each page at last unbind. */ +unsigned long *bit_17; + +union { +struct i915_gem_userptr { +uintptr_t ptr; + +struct i915_mm_struct *mm; +struct i915_mmu_object *mmu_object; +struct work_struct *work; + } userptr; + +unsigned long scratch; + +void *gvt_info; + }; + +/** for phys allocated objects */ +struct drm_dma_handle *phys_handle; + +struct reservation_object __builtin_resv; +}; + +static inline struct drm_i915_gem_object * +to_intel_bo (struct drm_gem_object *gem) +{ +/* Assert that to_intel_bo(NULL) == NULL */ +BUILD_BUG_ON (offsetof(struct drm_i915_gem_object , base)); + + return container_of(gem, struct drm_i915_gem_object, base); +} + +#endif drivers/gpu/drm/i915/gt/intel_engine_types.h +1
-0@@ -29,6 +29,7 @@#define I915_CMD_HASH_ORDER 9struct dma_fence ; +struct drm_i915_gem_object ;struct drm_i915_reg_table ;struct i915_gem_context ;struct i915_request ;drivers/gpu/drm/i915/i915_drv.h +2
-1@@ -80,7 +80,6 @@#include "i915_gem.h" #include "i915_gem_context.h" #include "i915_gem_fence_reg.h" -#include "i915_gem_object.h" #include "i915_gem_gtt.h" #include "i915_gpu_error.h" #include "i915_request.h" @@ -135,6 +134,8 @@ bool i915_error_injected(void);__i915_printk (i915,i915_error_injected () ?KERN_DEBUG :KERN_ERR , \ fmt, ##__VA_ARGS__) +struct drm_i915_gem_object ; +enum hpd_pin {HPD_NONE =0 ,HPD_TV =HPD_NONE ,/* TV is known to be unreliable */ drivers/gpu/drm/i915/i915_gem_batch_pool.h +2
-1@@ -9,6 +9,7 @@#include <linux/types.h> +struct drm_i915_gem_object ;struct intel_engine_cs ;struct i915_gem_batch_pool {@@ -19,7 +20,7 @@ struct i915_gem_batch_pool {void i915_gem_batch_pool_init (struct i915_gem_batch_pool *pool,struct intel_engine_cs *engine);void i915_gem_batch_pool_fini (struct i915_gem_batch_pool *pool); -struct drm_i915_gem_object * +struct drm_i915_gem_object *i915_gem_batch_pool_get (struct i915_gem_batch_pool *pool,size_t size);#endif /* I915_GEM_BATCH_POOL_H */ drivers/gpu/drm/i915/i915_gem_gtt.h +1
-0@@ -61,6 +61,7 @@struct drm_i915_file_private ;struct drm_i915_fence_reg ; +struct drm_i915_gem_object ;struct i915_vma ;typedef u32 gen6_pte_t ;drivers/gpu/drm/i915/i915_gem_object.h +3
-292@@ -1,308 +1,19 @@/* -* Copyright © 2016 Intel Corporation -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice (including the next -* paragraph) shall be included in all copies or substantial portions of the -* Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -* IN THE SOFTWARE. +* SPDX-License-Identifier: MIT * +* Copyright © 2016 Intel Corporation */ #ifndef __I915_GEM_OBJECT_H__#define __I915_GEM_OBJECT_H__ -#include <linux/reservation.h> - -#include <drm/drm_vma_manager.h> #include <drm/drm_gem.h> #include <drm/drm_file.h> #include <drm/drm_device.h> #include <drm/i915_drm.h> -#include "i915_request.h" -#include "i915_selftest.h" - -struct drm_i915_gem_object ; - -/* -* struct i915_lut_handle tracks the fast lookups from handle to vma used -* for execbuf. Although we use a radixtree for that mapping, in order to -* remove them as the object or context is closed, we need a secondary list -* and a translation entry (i915_lut_handle). -*/ -struct i915_lut_handle { -struct list_head obj_link; -struct list_head ctx_link; -struct i915_gem_context *ctx; -u32 handle; -}; - -struct drm_i915_gem_object_ops { -unsigned int flags; -#define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0) -#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(1) -#define I915_GEM_OBJECT_IS_PROXY BIT(2) -#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(3) - -/* Interface between the GEM object and its backing storage. -* get_pages() is called once prior to the use of the associated set -* of pages before to binding them into the GTT, and put_pages() is -* called after we no longer need them. As we expect there to be -* associated cost with migrating pages between the backing storage -* and making them available for the GPU (e.g. clflush), we may hold -* onto the pages after they are no longer referenced by the GPU -* in case they may be used again shortly (for example migrating the -* pages to a different memory domain within the GTT). put_pages() -* will therefore most likely be called when the object itself is -* being released or under memory pressure (where we attempt to -* reap pages for the shrinker). -*/ -int (*get_pages)(struct drm_i915_gem_object *); -void (*put_pages)(struct drm_i915_gem_object *,struct sg_table *); - -int (*pwrite)(struct drm_i915_gem_object *, -const struct drm_i915_gem_pwrite *); - -int (*dmabuf_export)(struct drm_i915_gem_object *); -void (*release)(struct drm_i915_gem_object *); -}; - -struct drm_i915_gem_object { -struct drm_gem_object base; - -const struct drm_i915_gem_object_ops *ops; - -struct { -/** -* @vma.lock: protect the list/tree of vmas -*/ -spinlock_t lock; - -/** -* @vma.list: List of VMAs backed by this object -* -* The VMA on this list are ordered by type, all GGTT vma are -* placed at the head and all ppGTT vma are placed at the tail. -* The different types of GGTT vma are unordered between -* themselves, use the @vma.tree (which has a defined order -* between all VMA) to quickly find an exact match. -*/ -struct list_head list; - -/** -* @vma.tree: Ordered tree of VMAs backed by this object -* -* All VMA created for this object are placed in the @vma.tree -* for fast retrieval via a binary search in -* i915_vma_instance(). They are also added to @vma.list for -* easy iteration. -*/ -struct rb_root tree; - } vma; - -/** -* @lut_list: List of vma lookup entries in use for this object. -* -* If this object is closed, we need to remove all of its VMA from -* the fast lookup index in associated contexts; @lut_list provides -* this translation from object to context->handles_vma. -*/ -struct list_head lut_list; - -/** Stolen memory for this object, instead of being backed by shmem. */ -struct drm_mm_node *stolen; -union { -struct rcu_head rcu; -struct llist_node freed; - }; - -/** -* Whether the object is currently in the GGTT mmap. -*/ -unsigned int userfault_count; -struct list_head userfault_link; - -struct list_head batch_pool_link; - I915_SELFTEST_DECLARE(struct list_head st_link); - -unsigned long flags; - -/** -* Have we taken a reference for the object for incomplete GPU -* activity? -*/ -#define I915_BO_ACTIVE_REF 0 - -/* -* Is the object to be mapped as read-only to the GPU -* Only honoured if hardware has relevant pte bit -*/ -unsigned int cache_level:3 ; -unsigned int cache_coherent:2 ; -#define I915_BO_CACHE_COHERENT_FOR_READ BIT(0) -#define I915_BO_CACHE_COHERENT_FOR_WRITE BIT(1) -unsigned int cache_dirty:1 ; - -/** -* @read_domains: Read memory domains. -* -* These monitor which caches contain read/write data related to the -* object. When transitioning from one set of domains to another, -* the driver is called to ensure that caches are suitably flushed and -* invalidated. -*/ -u16 read_domains; - -/** -* @write_domain: Corresponding unique write memory domain. -*/ -u16 write_domain; - -atomic_t frontbuffer_bits; -unsigned int frontbuffer_ggtt_origin;/* write once */ -struct i915_active_request frontbuffer_write; - -/** Current tiling stride for the object, if it's tiled. */ -unsigned int tiling_and_stride; -#define FENCE_MINIMUM_STRIDE 128/* See i915_tiling_ok() */ -#define TILING_MASK (FENCE_MINIMUM_STRIDE-1) -#define STRIDE_MASK (~TILING_MASK) - -/** Count of VMA actually bound by this object */ -unsigned int bind_count; -unsigned int active_count; -/** Count of how many global VMA are currently pinned for use by HW */ -unsigned int pin_global; - -struct { -struct mutex lock;/* protects the pages and their use */ -atomic_t pages_pin_count; - -struct sg_table *pages; -void *mapping; - -/* TODO: whack some of this into the error state */ -struct i915_page_sizes { -/** -* The sg mask of the pages sg_table. i.e the mask of -* of the lengths for each sg entry. -*/ -unsigned int phys; - -/** -* The gtt page sizes we are allowed to use given the -* sg mask and the supported page sizes. This will -* express the smallest unit we can use for the whole -* object, as well as the larger sizes we may be able -* to use opportunistically. -*/ -unsigned int sg; - -/** -* The actual gtt page size usage. Since we can have -* multiple vma associated with this object we need to -* prevent any trampling of state, hence a copy of this -* struct also lives in each vma, therefore the gtt -* value here should only be read/write through the vma. -*/ -unsigned int gtt; - } page_sizes; - - I915_SELFTEST_DECLARE(unsigned int page_mask); - -struct i915_gem_object_page_iter { -struct scatterlist *sg_pos; -unsigned int sg_idx;/* in pages, but 32bit eek! */ - -struct radix_tree_root radix; -struct mutex lock;/* protects this cache */ - } get_page; - -/** -* Element within i915->mm.unbound_list or i915->mm.bound_list, -* locked by i915->mm.obj_lock. -*/ -struct list_head link; - -/** -* Advice: are the backing pages purgeable? -*/ -unsigned int madv:2 ; - -/** -* This is set if the object has been written to since the -* pages were last acquired. -*/ -bool dirty:1 ; - -/** -* This is set if the object has been pinned due to unknown -* swizzling. -*/ -bool quirked:1 ; - } mm; - -/** Breadcrumb of last rendering to the buffer. -* There can only be one writer, but we allow for multiple readers. -* If there is a writer that necessarily implies that all other -* read requests are complete - but we may only be lazily clearing -* the read requests. A read request is naturally the most recent -* request on a ring, so we may have two different write and read -* requests on one ring where the write request is older than the -* read request. This allows for the CPU to read from an active -* buffer by only waiting for the write to complete. -*/ -struct reservation_object *resv; - -/** References from framebuffers, locks out tiling changes. */ -unsigned int framebuffer_references; - -/** Record of address bit 17 of each page at last unbind. */ -unsigned long *bit_17; - -union { -struct i915_gem_userptr { -uintptr_t ptr; - -struct i915_mm_struct *mm; -struct i915_mmu_object *mmu_object; -struct work_struct *work; - } userptr; - -unsigned long scratch; - -void *gvt_info; - }; - -/** for phys allocated objects */ -struct drm_dma_handle *phys_handle; - -struct reservation_object __builtin_resv; -}; - -static inline struct drm_i915_gem_object * -to_intel_bo (struct drm_gem_object *gem) -{ -/* Assert that to_intel_bo(NULL) == NULL */ -BUILD_BUG_ON (offsetof(struct drm_i915_gem_object , base)); - - return container_of(gem, struct drm_i915_gem_object, base); -} +#include "gem/i915_gem_object_types.h" Quoted 5 lines
Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_object.h +0
-0struct drm_i915_gem_object *i915_gem_object_alloc (void );void i915_gem_object_free (struct drm_i915_gem_object *obj);Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 25/45 drm/i915: Pull GEM ioctls interface to its own file
In reply to Chris WilsonDeclutter i915_drv/gem.h by moving the ioctl API into its own header.
--- drivers/gpu/drm/i915/gem/i915_gem_ioctls.h | 52 ++++++++++++++++++++++ drivers/gpu/drm/i915/i915_drv.c | 1 + drivers/gpu/drm/i915/i915_drv.h | 38 ---------------- drivers/gpu/drm/i915/i915_gem.c | 1 + drivers/gpu/drm/i915/i915_gem_execbuffer.c | 1 + drivers/gpu/drm/i915/i915_gem_tiling.c | 3 ++ drivers/gpu/drm/i915/i915_gem_userptr.c | 12 +++-- 7 files changed, 66 insertions(+), 42 deletions(-) create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_ioctls.h
drivers/gpu/drm/i915/gem/i915_gem_ioctls.h new file +52 -0
@@ -0,0 +1,52 @@ +/* +* SPDX-License-Identifier: MIT +* +* Copyright © 2019 Intel Corporation +*/ + +#ifndef I915_GEM_IOCTLS_H +#define I915_GEM_IOCTLS_H + +struct drm_device ; +struct drm_file ; + +int i915_gem_busy_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_create_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_execbuffer_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_execbuffer2_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_get_aperture_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_get_caching_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_get_tiling_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_madvise_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_mmap_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_mmap_gtt_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_pread_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_pwrite_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_set_caching_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_set_domain_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_set_tiling_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_sw_finish_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_throttle_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_userptr_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int i915_gem_wait_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); + +#endif
drivers/gpu/drm/i915/i915_drv.c +1 -0
@@ -47,6 +47,7 @@#include <drm/drm_probe_helper.h> #include <drm/i915_drm.h> +#include "gem/i915_gem_ioctls.h" #include "gt/intel_gt_pm.h" #include "gt/intel_reset.h" #include "gt/intel_workarounds.h"
drivers/gpu/drm/i915/i915_drv.h +0 -38
@@ -2824,46 +2824,8 @@ ibx_disable_display_interrupt(struct drm_i915_private *dev_priv, u32 bits) }/* i915_gem.c */ -int i915_gem_create_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_pread_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_pwrite_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_mmap_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_mmap_gtt_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_set_domain_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_sw_finish_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_execbuffer_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_execbuffer2_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_busy_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_get_caching_ioctl (struct drm_device *dev,void *data, -struct drm_file *file); -int i915_gem_set_caching_ioctl (struct drm_device *dev,void *data, -struct drm_file *file); -int i915_gem_throttle_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_madvise_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_set_tiling_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_get_tiling_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv);int i915_gem_init_userptr (struct drm_i915_private *dev_priv);void i915_gem_cleanup_userptr (struct drm_i915_private *dev_priv); -int i915_gem_userptr_ioctl (struct drm_device *dev,void *data, -struct drm_file *file); -int i915_gem_get_aperture_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv); -int i915_gem_wait_ioctl (struct drm_device *dev,void *data, -struct drm_file *file_priv);void i915_gem_sanitize (struct drm_i915_private *i915);int i915_gem_init_early (struct drm_i915_private *dev_priv);void i915_gem_cleanup_early (struct drm_i915_private *dev_priv);
drivers/gpu/drm/i915/i915_gem.c +1 -0
@@ -39,6 +39,7 @@#include <linux/dma-buf.h> #include <linux/mman.h> +#include "gem/i915_gem_ioctls.h" #include "gt/intel_engine_pm.h" #include "gt/intel_gt_pm.h" #include "gt/intel_mocs.h"
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -0
@@ -34,6 +34,7 @@#include <drm/drm_syncobj.h> #include <drm/i915_drm.h> +#include "gem/i915_gem_ioctls.h" #include "gt/intel_gt_pm.h" #include "i915_drv.h"
drivers/gpu/drm/i915/i915_gem_tiling.c +3 -0
@@ -28,6 +28,9 @@#include <linux/string.h> #include <linux/bitops.h> #include <drm/i915_drm.h> + +#include "gem/i915_gem_ioctls.h" +#include "i915_drv.h" /**
drivers/gpu/drm/i915/i915_gem_userptr.c +8 -4
@@ -22,16 +22,20 @@* */ -#include <drm/i915_drm.h> -#include "i915_drv.h" -#include "i915_trace.h" -#include "intel_drv.h" #include <linux/mmu_context.h> #include <linux/mmu_notifier.h> #include <linux/mempolicy.h> #include <linux/swap.h> #include <linux/sched/mm.h> +#include <drm/i915_drm.h> + +#include "gem/i915_gem_ioctls.h" + +#include "i915_drv.h" +#include "i915_trace.h" +#include "intel_drv.h" +struct i915_mm_struct {struct mm_struct *mm;struct drm_i915_private *i915;
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 26/45 drm/i915: Move object->pages API to i915_gem_object.[ch]
In reply to Chris WilsonCurrently the code for manipulating the pages on an object is still residing in i915_gem.c, move it to i915_gem_object.c
---
drivers/gpu/drm/i915/Makefile | 4 +-
.../gpu/drm/i915/{ => gem}/i915_gem_object.c | 5 +-
.../gpu/drm/i915/{ => gem}/i915_gem_object.h | 127 +++++++++++++++-
drivers/gpu/drm/i915/i915_drv.h | 137 +-----------------
drivers/gpu/drm/i915/i915_globals.c | 2 +-
drivers/gpu/drm/i915/i915_vma.h | 2 +-
drivers/gpu/drm/i915/intel_frontbuffer.h | 2 +-
7 files changed, 141 insertions(+), 138 deletions(-)
rename drivers/gpu/drm/i915/{ => gem}/i915_gem_object.c (97%)
rename drivers/gpu/drm/i915/{ => gem}/i915_gem_object.h (59%)drivers/gpu/drm/i915/Makefile +3 -1
@@ -86,7 +86,10 @@ i915-y += $(gt-y) # GEM (Graphics Execution Management) code obj-y += gem/ +gem-y += \ + gem/i915_gem_object.o i915-y += \ + $(gem-y) \ i915_active.o \ i915_cmd_parser.o \ i915_gem_batch_pool.o \
@@ -99,7 +102,6 @@ i915-y += \ i915_gem_gtt.o \ i915_gem_internal.o \ i915_gem.o \ - i915_gem_object.o \ i915_gem_pm.o \ i915_gem_render_state.o \ i915_gem_shrinker.o \
drivers/gpu/drm/i915/gem/i915_gem_object.c renamed from drivers/gpu/drm/i915/i915_gem_object.c +3 -2
@@ -22,9 +22,10 @@* */ -#include "i915_drv.h" #include "i915_gem_object.h" -#include "i915_globals.h" + +#include "../i915_drv.h" +#include "../i915_globals.h" static struct i915_global_object { struct i915_global base;
drivers/gpu/drm/i915/gem/i915_gem_object.h renamed from drivers/gpu/drm/i915/i915_gem_object.h +126 -1
139 lines not on this page · raw message
drivers/gpu/drm/i915/i915_drv.h +6 -131
147 lines not on this page · raw message
drivers/gpu/drm/i915/i915_globals.c +1 -1
@@ -9,7 +9,7 @@#include "i915_active.h" #include "i915_gem_context.h" -#include "i915_gem_object.h" +#include "gem/i915_gem_object.h" #include "i915_globals.h" #include "i915_request.h" #include "i915_scheduler.h"
drivers/gpu/drm/i915/i915_vma.h +1 -1
@@ -32,7 +32,7 @@#include "i915_gem_gtt.h" #include "i915_gem_fence_reg.h" -#include "i915_gem_object.h" +#include "gem/i915_gem_object.h" #include "i915_active.h" #include "i915_request.h"
drivers/gpu/drm/i915/intel_frontbuffer.h +1 -1
@@ -24,7 +24,7 @@#ifndef __INTEL_FRONTBUFFER_H__#define __INTEL_FRONTBUFFER_H__ -#include "i915_gem_object.h" +#include "gem/i915_gem_object.h" struct drm_i915_private ;struct drm_i915_gem_object ;
Signature · 6 lines
2.20.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx