Basic GuC submission support in the i915
Subsystems (3)
Re: [Intel-gfx] [RFC PATCH 44/97] drm/i915/guc: Implement GuC submission tasklet
In reply to Matthew BrostQuoted 61 lines · Matthew Brost
Implement GuC submission tasklet for new interface. The new GuC interface uses H2G to submit contexts to the GuC. Since H2G use a single channel, a single tasklet submits is used for the submission path. As such a global struct
intel_engine_cshas been added to leverage the existing scheduling code.Also the per engine interrupt handler has been updated to disable the rescheduling of the physical engine tasklet, when using GuC scheduling, as the physical engine tasklet is no longer used.
In this patch the field,
guc_id, has been added tointel_contextand is not assigned. Patches later in the series will assign this value.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context_types.h | 9 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 233 +++++++++--------- 3 files changed, 127 insertions(+), 119 deletions(-)drivers/gpu/drm/i915/gt/intel_context_types.h +9
-0@@ -136,6 +136,15 @@ struct intel_context {struct intel_sseu sseu;u8 wa_bb_page;/* if set, page num reserved for context workarounds */ + +/* GuC scheduling state that does not require a lock. */ +atomic_t guc_sched_state_no_lock; + +/* +* GuC lrc descriptor ID - Not assigned in this patch but future patches +* in the series will. +*/ + u16 guc_id; };#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -30,6 +30,10 @@ struct intel_guc {struct intel_guc_log log;struct intel_guc_ct ct; +/* Global engine used to submit requests to GuC */ +struct i915_sched_engine *sched_engine; +struct i915_request *stalled_request; +/* intel_guc_recv interrupt related state */ spinlock_t irq_lock;unsigned int msg_enabled_mask;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c line 68
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0@@ -60,6 +60,30 @@#define GUC_REQUEST_SIZE 64/* bytes */ +/* +* Below is a set of functions which control the GuC scheduling state which do +* not require a lock as all state transitions are mutually exclusive. i.e. It +* is not possible for the context pinning code and submission, for the same +* context, to be executing simultaneously. +*/
Is the statement that some other locks, or other guarantees, serialise modification of this state, and if so, why is it using atomics?
Regards,
Tvrtko
Quoted 340 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +101
-119+#define SCHED_STATE_NO_LOCK_ENABLED BIT(0) +static inline bool context_enabled (struct intel_context *ce) +{ +return (atomic_read (&ce->guc_sched_state_no_lock) & +SCHED_STATE_NO_LOCK_ENABLED ); +} + +static inline void set_context_enabled (struct intel_context *ce) +{ +atomic_or (SCHED_STATE_NO_LOCK_ENABLED , &ce->guc_sched_state_no_lock); +} + +static inline void clr_context_enabled (struct intel_context *ce) +{ +atomic_and ((u32 )~SCHED_STATE_NO_LOCK_ENABLED , + &ce->guc_sched_state_no_lock); +} +static inline struct i915_priolist *to_priolist (struct rb_node *rb) { return rb_entry(rb, struct i915_priolist, node);@@ -122,37 +146,29 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } -static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) { -/* Leaving stub as this function will be used in future patches */ -} +int err; +struct intel_context *ce = rq->context; +u32 action[3 ]; +int len =0 ; +bool enabled =context_enabled (ce); -/* -* When we're doing submissions using regular execlists backend, writing to -* ELSP from CPU side is enough to make sure that writes to ringbuffer pages -* pinned in mappable aperture portion of GGTT are visible to command streamer. -* Writes done by GuC on our behalf are not guaranteeing such ordering, -* therefore, to ensure the flush, we're issuing a POSTING READ. -*/ -static void flush_ggtt_writes (struct i915_vma *vma) -{ -if (i915_vma_is_map_and_fenceable (vma)) -intel_uncore_posting_read_fw (vma->vm->gt->uncore, -GUC_STATUS ); -} +if (!enabled) { + action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; + action[len++] = ce->guc_id; + action[len++] =GUC_CONTEXT_ENABLE ; + }else { + action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; + action[len++] = ce->guc_id; + } -static void guc_submit (struct intel_engine_cs *engine, -struct i915_request **out, -struct i915_request **end) -{ -struct intel_guc *guc = &engine->gt->uc.guc; + err =intel_guc_send_nb (guc, action, len); -do { -struct i915_request *rq = *out++; +if (!enabled && !err) +set_context_enabled (ce); -flush_ggtt_writes (rq->ring->vma); -guc_add_request (guc, rq); - }while (out != end); +return err; }static inline int rq_prio (const struct i915_request *rq)@@ -160,125 +176,88 @@ static inline int rq_prio(const struct i915_request *rq)return rq->sched.attr.priority; } -static struct i915_request *schedule_in (struct i915_request *rq,int idx) -{ -trace_i915_request_in (rq, idx); - -/* -* Currently we are not tracking the rq->context being inflight -* (ce->inflight = rq->engine). It is only used by the execlists -* backend at the moment, a similar counting strategy would be -* required if we generalise the inflight tracking. -*/ - -__intel_gt_pm_get (rq->engine->gt); -return i915_request_get (rq); -} - -static void schedule_out (struct i915_request *rq) -{ -trace_i915_request_out (rq); - -intel_gt_pm_put_async (rq->engine->gt); -i915_request_put (rq); -} - -static void __guc_dequeue (struct intel_engine_cs *engine) +static int guc_dequeue_one_context (struct intel_guc *guc) { -struct i915_sched_engine *const sched_engine = engine->sched_engine; -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_request **first = execlists->inflight; -struct i915_request **const last_port = first + execlists->port_mask; -struct i915_request *last = first[0 ]; -struct i915_request **port; +struct i915_sched_engine *const sched_engine = guc->sched_engine; +struct i915_request *last =NULL ;bool submit = false;struct rb_node *rb; +int ret; -lockdep_assert_held (&engine->sched_engine->lock); - -if (last) { -if (*++first) -return ; +lockdep_assert_held (&sched_engine->lock); - last =NULL ; +if (guc->stalled_request) { + submit = true; + last = guc->stalled_request; + goto resubmit; } -/* -* We write directly into the execlists->inflight queue and don't use -* the execlists->pending queue, as we don't have a distinct switch -* event. -*/ - port = first;while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;priolist_for_each_request_consume (rq, rn, p) { -if (last && rq->context != last->context) { -if (port == last_port) - goto done; - - *port =schedule_in (last, - port - execlists->inflight); - port++; - } +if (last && rq->context != last->context) + goto done;list_del_init (&rq->sched.link); +__i915_request_submit (rq); - submit = true; + +trace_i915_request_in (rq,0 ); last = rq; + submit = true; }rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); } done: - sched_engine->queue_priority_hint = - rb ?to_priolist (rb)->priority :INT_MIN ;if (submit) { - *port =schedule_in (last, port - execlists->inflight); - *++port =NULL ; -guc_submit (engine, first, port); + last->context->lrc_reg_state[CTX_RING_TAIL ] = +intel_ring_set_tail (last->ring, last->tail); +resubmit: +/* +* We only check for -EBUSY here even though it is possible for +* -EDEADLK to be returned. If -EDEADLK is returned, the GuC has +* died and a full GPU needs to be done. The hangcheck will +* eventually detect that the GuC has died and trigger this +* reset so no need to handle -EDEADLK here. +*/ + ret =guc_add_request (guc, last); +if (ret == -EBUSY ) { +i915_sched_engine_kick (sched_engine); + guc->stalled_request = last; +return false; + } } - execlists->active = execlists->inflight; + + guc->stalled_request =NULL ; +return submit; }static void guc_submission_tasklet (struct tasklet_struct *t) {struct i915_sched_engine *sched_engine =from_tasklet (sched_engine, t, tasklet); -struct intel_engine_cs *const engine = sched_engine->engine; -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_request **port, *rq;unsigned long flags; +bool loop; -spin_lock_irqsave (&engine->sched_engine->lock, flags); - -for (port = execlists->inflight; (rq = *port); port++) { -if (!i915_request_completed (rq)) -break ; +spin_lock_irqsave (&sched_engine->lock, flags); -schedule_out (rq); - } -if (port != execlists->inflight) { -int idx = port - execlists->inflight; -int rem =ARRAY_SIZE (execlists->inflight) - idx; -memmove (execlists->inflight, port, rem *sizeof (*port)); - } - -__guc_dequeue (engine); +do { + loop =guc_dequeue_one_context (&sched_engine->engine->gt->uc.guc); + }while (loop); -i915_sched_engine_reset_on_empty (engine->sched_engine); +i915_sched_engine_reset_on_empty (sched_engine); -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); }static void cs_irq_handler (struct intel_engine_cs *engine,u16 iir) { -if (iir >_RENDER_USER_INTERRUPT ) { +if (iir >_RENDER_USER_INTERRUPT )intel_engine_signal_breadcrumbs (engine); -i915_sched_engine_hi_kick (engine->sched_engine); - } }static void guc_reset_prepare (struct intel_engine_cs *engine)@@ -351,6 +330,10 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)struct rb_node *rb;unsigned long flags; +/* Can be called during boot if GuC fails to load */ +if (!engine->gt) +return ; +ENGINE_TRACE (engine,"\n" );/* @@ -437,8 +420,11 @@ int intel_guc_submission_init(struct intel_guc *guc)void intel_guc_submission_fini (struct intel_guc *guc) { -if (guc->lrc_desc_pool) -guc_lrc_desc_pool_destroy (guc); +if (!guc->lrc_desc_pool) +return ; + +guc_lrc_desc_pool_destroy (guc); +i915_sched_engine_put (guc->sched_engine); }static int guc_context_alloc (struct intel_context *ce)@@ -503,32 +489,32 @@ static int guc_request_alloc(struct i915_request *request)return 0 ; } -static inline void queue_request (struct intel_engine_cs *engine, +static inline void queue_request (struct i915_sched_engine *sched_engine,struct i915_request *rq,int prio) {GEM_BUG_ON (!list_empty (&rq->sched.link));list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (engine->sched_engine, prio)); +i915_sched_lookup_priolist (sched_engine, prio));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); }static void guc_submit_request (struct i915_request *rq) { -struct intel_engine_cs *engine = rq->engine; +struct i915_sched_engine *sched_engine = rq->engine->sched_engine;unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->sched_engine->lock, flags); +spin_lock_irqsave (&sched_engine->lock, flags); -queue_request (engine, rq,rq_prio (rq)); +queue_request (sched_engine, rq,rq_prio (rq)); -GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine)); +GEM_BUG_ON (i915_sched_engine_is_empty (sched_engine));GEM_BUG_ON (list_empty (&rq->sched.link)); -i915_sched_engine_hi_kick (engine->sched_engine); +i915_sched_engine_hi_kick (sched_engine); -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); }static void sanitize_hwsp (struct intel_engine_cs *engine)@@ -606,8 +592,6 @@ static void guc_release(struct intel_engine_cs *engine) { engine->sanitize =NULL ;/* no longer in control, nothing to sanitize */ -tasklet_kill (&engine->sched_engine->tasklet); -intel_engine_cleanup_common (engine);lrc_fini_wa_ctx (engine); }@@ -678,6 +662,7 @@ static inline void guc_default_irqs(struct intel_engine_cs *engine)int intel_guc_submission_setup (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915; +struct intel_guc *guc = &engine->gt->uc.guc;/* * The setup relies on several assumptions (e.g. irqs always enabled) @@ -685,8 +670,18 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)*/ GEM_BUG_ON (INTEL_GEN (i915) <11 ); -tasklet_setup (&engine->sched_engine->tasklet, guc_submission_tasklet); - engine->sched_engine->schedule = i915_schedule; +if (!guc->sched_engine) { + guc->sched_engine =i915_sched_engine_create (ENGINE_VIRTUAL ); +if (!guc->sched_engine) +return -ENOMEM ; +
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_setup(struct intel_engine_cs *engine) · line 687
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0+ guc->sched_engine->schedule = i915_schedule; + guc->sched_engine->engine = engine; +tasklet_setup (&guc->sched_engine->tasklet, + guc_submission_tasklet); + } +i915_sched_engine_put (engine->sched_engine); + engine->sched_engine =i915_sched_engine_get (guc->sched_engine);guc_default_vfuncs (engine);guc_default_irqs (engine);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 44/97] drm/i915/guc: Implement GuC submission tasklet
Quoted 62 lines · Tvrtko Ursulin
Quoted 60 lines · Matthew Brost
Implement GuC submission tasklet for new interface. The new GuC interface uses H2G to submit contexts to the GuC. Since H2G use a single channel, a single tasklet submits is used for the submission path. As such a global struct
intel_engine_cshas been added to leverage the existing scheduling code.Also the per engine interrupt handler has been updated to disable the rescheduling of the physical engine tasklet, when using GuC scheduling, as the physical engine tasklet is no longer used.
In this patch the field,
guc_id, has been added tointel_contextand is not assigned. Patches later in the series will assign this value.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context_types.h | 9 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 233 +++++++++--------- 3 files changed, 127 insertions(+), 119 deletions(-)drivers/gpu/drm/i915/gt/intel_context_types.h +9
-0@@ -136,6 +136,15 @@ struct intel_context {struct intel_sseu sseu;u8 wa_bb_page;/* if set, page num reserved for context workarounds */ + +/* GuC scheduling state that does not require a lock. */ +atomic_t guc_sched_state_no_lock; + +/* +* GuC lrc descriptor ID - Not assigned in this patch but future patches +* in the series will. +*/ + u16 guc_id; };#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -30,6 +30,10 @@ struct intel_guc {struct intel_guc_log log;struct intel_guc_ct ct; +/* Global engine used to submit requests to GuC */ +struct i915_sched_engine *sched_engine; +struct i915_request *stalled_request; +/* intel_guc_recv interrupt related state */ spinlock_t irq_lock;unsigned int msg_enabled_mask;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -60,6 +60,30 @@#define GUC_REQUEST_SIZE 64/* bytes */ +/*
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c line 68
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+* Below is a set of functions which control the GuC scheduling state which do +* not require a lock as all state transitions are mutually exclusive. i.e. It +* is not possible for the context pinning code and submission, for the same +* context, to be executing simultaneously. +*/ Is the statement that some other locks, or other guarantees, serialise modification of this state, and if so, why is it using atomics?
This should probably be reworded. For the atomics the transitions are happen at the same time but the transitions are safe, for the ones protected by the locks some other state choices are made so we need a lock when transitioning the state.
Matt
Quoted 318 lines
Regards,
Tvrtko
Quoted 314 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +108
-119+#define SCHED_STATE_NO_LOCK_ENABLED BIT(0) +static inline bool context_enabled (struct intel_context *ce) +{ +return (atomic_read (&ce->guc_sched_state_no_lock) & +SCHED_STATE_NO_LOCK_ENABLED ); +} + +static inline void set_context_enabled (struct intel_context *ce) +{ +atomic_or (SCHED_STATE_NO_LOCK_ENABLED , &ce->guc_sched_state_no_lock); +} + +static inline void clr_context_enabled (struct intel_context *ce) +{ +atomic_and ((u32 )~SCHED_STATE_NO_LOCK_ENABLED , + &ce->guc_sched_state_no_lock); +} +static inline struct i915_priolist *to_priolist (struct rb_node *rb) { return rb_entry(rb, struct i915_priolist, node);@@ -122,37 +146,29 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } -static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) { -/* Leaving stub as this function will be used in future patches */ -} +int err; +struct intel_context *ce = rq->context; +u32 action[3 ]; +int len =0 ; +bool enabled =context_enabled (ce); -/* -* When we're doing submissions using regular execlists backend, writing to -* ELSP from CPU side is enough to make sure that writes to ringbuffer pages -* pinned in mappable aperture portion of GGTT are visible to command streamer. -* Writes done by GuC on our behalf are not guaranteeing such ordering, -* therefore, to ensure the flush, we're issuing a POSTING READ. -*/ -static void flush_ggtt_writes (struct i915_vma *vma) -{ -if (i915_vma_is_map_and_fenceable (vma)) -intel_uncore_posting_read_fw (vma->vm->gt->uncore, -GUC_STATUS ); -} +if (!enabled) { + action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; + action[len++] = ce->guc_id; + action[len++] =GUC_CONTEXT_ENABLE ; + }else { + action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; + action[len++] = ce->guc_id; + } -static void guc_submit (struct intel_engine_cs *engine, -struct i915_request **out, -struct i915_request **end) -{ -struct intel_guc *guc = &engine->gt->uc.guc; + err =intel_guc_send_nb (guc, action, len); -do { -struct i915_request *rq = *out++; +if (!enabled && !err) +set_context_enabled (ce); -flush_ggtt_writes (rq->ring->vma); -guc_add_request (guc, rq); - }while (out != end); +return err; }static inline int rq_prio (const struct i915_request *rq)@@ -160,125 +176,88 @@ static inline int rq_prio(const struct i915_request *rq)return rq->sched.attr.priority; } -static struct i915_request *schedule_in (struct i915_request *rq,int idx) -{ -trace_i915_request_in (rq, idx); - -/* -* Currently we are not tracking the rq->context being inflight -* (ce->inflight = rq->engine). It is only used by the execlists -* backend at the moment, a similar counting strategy would be -* required if we generalise the inflight tracking. -*/ - -__intel_gt_pm_get (rq->engine->gt); -return i915_request_get (rq); -} - -static void schedule_out (struct i915_request *rq) -{ -trace_i915_request_out (rq); - -intel_gt_pm_put_async (rq->engine->gt); -i915_request_put (rq); -} - -static void __guc_dequeue (struct intel_engine_cs *engine) +static int guc_dequeue_one_context (struct intel_guc *guc) { -struct i915_sched_engine *const sched_engine = engine->sched_engine; -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_request **first = execlists->inflight; -struct i915_request **const last_port = first + execlists->port_mask; -struct i915_request *last = first[0 ]; -struct i915_request **port; +struct i915_sched_engine *const sched_engine = guc->sched_engine; +struct i915_request *last =NULL ;bool submit = false;struct rb_node *rb; +int ret; -lockdep_assert_held (&engine->sched_engine->lock); - -if (last) { -if (*++first) -return ; +lockdep_assert_held (&sched_engine->lock); - last =NULL ; +if (guc->stalled_request) { + submit = true; + last = guc->stalled_request; + goto resubmit; } -/* -* We write directly into the execlists->inflight queue and don't use -* the execlists->pending queue, as we don't have a distinct switch -* event. -*/ - port = first;while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;priolist_for_each_request_consume (rq, rn, p) { -if (last && rq->context != last->context) { -if (port == last_port) - goto done; - - *port =schedule_in (last, - port - execlists->inflight); - port++; - } +if (last && rq->context != last->context) + goto done;list_del_init (&rq->sched.link); +__i915_request_submit (rq); - submit = true; + +trace_i915_request_in (rq,0 ); last = rq; + submit = true; }rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); } done: - sched_engine->queue_priority_hint = - rb ?to_priolist (rb)->priority :INT_MIN ;if (submit) { - *port =schedule_in (last, port - execlists->inflight); - *++port =NULL ; -guc_submit (engine, first, port); + last->context->lrc_reg_state[CTX_RING_TAIL ] = +intel_ring_set_tail (last->ring, last->tail); +resubmit: +/* +* We only check for -EBUSY here even though it is possible for +* -EDEADLK to be returned. If -EDEADLK is returned, the GuC has +* died and a full GPU needs to be done. The hangcheck will +* eventually detect that the GuC has died and trigger this +* reset so no need to handle -EDEADLK here. +*/ + ret =guc_add_request (guc, last); +if (ret == -EBUSY ) { +i915_sched_engine_kick (sched_engine); + guc->stalled_request = last; +return false; + } } - execlists->active = execlists->inflight; + + guc->stalled_request =NULL ; +return submit; }static void guc_submission_tasklet (struct tasklet_struct *t) {struct i915_sched_engine *sched_engine =from_tasklet (sched_engine, t, tasklet); -struct intel_engine_cs *const engine = sched_engine->engine; -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_request **port, *rq;unsigned long flags; +bool loop; -spin_lock_irqsave (&engine->sched_engine->lock, flags); - -for (port = execlists->inflight; (rq = *port); port++) { -if (!i915_request_completed (rq)) -break ; +spin_lock_irqsave (&sched_engine->lock, flags); -schedule_out (rq); - } -if (port != execlists->inflight) { -int idx = port - execlists->inflight; -int rem =ARRAY_SIZE (execlists->inflight) - idx; -memmove (execlists->inflight, port, rem *sizeof (*port)); - } - -__guc_dequeue (engine); +do { + loop =guc_dequeue_one_context (&sched_engine->engine->gt->uc.guc); + }while (loop); -i915_sched_engine_reset_on_empty (engine->sched_engine); +i915_sched_engine_reset_on_empty (sched_engine); -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); }static void cs_irq_handler (struct intel_engine_cs *engine,u16 iir) { -if (iir >_RENDER_USER_INTERRUPT ) { +if (iir >_RENDER_USER_INTERRUPT )intel_engine_signal_breadcrumbs (engine); -i915_sched_engine_hi_kick (engine->sched_engine); - } }static void guc_reset_prepare (struct intel_engine_cs *engine)@@ -351,6 +330,10 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)struct rb_node *rb;unsigned long flags; +/* Can be called during boot if GuC fails to load */ +if (!engine->gt) +return ; +ENGINE_TRACE (engine,"\n" );/* @@ -437,8 +420,11 @@ int intel_guc_submission_init(struct intel_guc *guc)void intel_guc_submission_fini (struct intel_guc *guc) { -if (guc->lrc_desc_pool) -guc_lrc_desc_pool_destroy (guc); +if (!guc->lrc_desc_pool) +return ; + +guc_lrc_desc_pool_destroy (guc); +i915_sched_engine_put (guc->sched_engine); }static int guc_context_alloc (struct intel_context *ce)@@ -503,32 +489,32 @@ static int guc_request_alloc(struct i915_request *request)return 0 ; } -static inline void queue_request (struct intel_engine_cs *engine, +static inline void queue_request (struct i915_sched_engine *sched_engine,struct i915_request *rq,int prio) {GEM_BUG_ON (!list_empty (&rq->sched.link));list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (engine->sched_engine, prio)); +i915_sched_lookup_priolist (sched_engine, prio));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); }static void guc_submit_request (struct i915_request *rq) { -struct intel_engine_cs *engine = rq->engine; +struct i915_sched_engine *sched_engine = rq->engine->sched_engine;unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->sched_engine->lock, flags); +spin_lock_irqsave (&sched_engine->lock, flags); -queue_request (engine, rq,rq_prio (rq)); +queue_request (sched_engine, rq,rq_prio (rq)); -GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine)); +GEM_BUG_ON (i915_sched_engine_is_empty (sched_engine));GEM_BUG_ON (list_empty (&rq->sched.link)); -i915_sched_engine_hi_kick (engine->sched_engine); +i915_sched_engine_hi_kick (sched_engine); -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); }static void sanitize_hwsp (struct intel_engine_cs *engine)@@ -606,8 +592,6 @@ static void guc_release(struct intel_engine_cs *engine) { engine->sanitize =NULL ;/* no longer in control, nothing to sanitize */ -tasklet_kill (&engine->sched_engine->tasklet); -intel_engine_cleanup_common (engine);lrc_fini_wa_ctx (engine); }@@ -678,6 +662,7 @@ static inline void guc_default_irqs(struct intel_engine_cs *engine)int intel_guc_submission_setup (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915; +struct intel_guc *guc = &engine->gt->uc.guc;/* * The setup relies on several assumptions (e.g. irqs always enabled) @@ -685,8 +670,18 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)*/ GEM_BUG_ON (INTEL_GEN (i915) <11 ); -tasklet_setup (&engine->sched_engine->tasklet, guc_submission_tasklet); - engine->sched_engine->schedule = i915_schedule; +if (!guc->sched_engine) { + guc->sched_engine =i915_sched_engine_create (ENGINE_VIRTUAL ); +if (!guc->sched_engine) +return -ENOMEM ; + + guc->sched_engine->schedule = i915_schedule; + guc->sched_engine->engine = engine; +tasklet_setup (&guc->sched_engine->tasklet, + guc_submission_tasklet); + } +i915_sched_engine_put (engine->sched_engine); + engine->sched_engine =i915_sched_engine_get (guc->sched_engine);guc_default_vfuncs (engine);guc_default_irqs (engine);
RFC PATCH 45/97 drm/i915/guc: Add bypass tasklet submission path to GuC
In reply to Matthew BrostAdd bypass tasklet submission path to GuC. The tasklet is only used if H2G channel has backpresure.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +29 -8
@@ -171,6 +171,12 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)return err; } +static inline void guc_set_lrc_tail (struct i915_request *rq) +{ + rq->context->lrc_reg_state[CTX_RING_TAIL ] = +intel_ring_set_tail (rq->ring, rq->tail); +} +static inline int rq_prio (const struct i915_request *rq) {return rq->sched.attr.priority;
@@ -214,8 +220,7 @@ static int guc_dequeue_one_context(struct intel_guc *guc) } done:if (submit) { - last->context->lrc_reg_state[CTX_RING_TAIL ] = -intel_ring_set_tail (last->ring, last->tail); +guc_set_lrc_tail (last); resubmit:/* * We only check for -EBUSY here even though it is possible for
@@ -499,20 +504,36 @@ static inline void queue_request(struct i915_sched_engine *sched_engine,set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); } +static int guc_bypass_tasklet_submit (struct intel_guc *guc, +struct i915_request *rq) +{ +int ret; + +__i915_request_submit (rq); + +trace_i915_request_in (rq,0 ); + +guc_set_lrc_tail (rq); + ret =guc_add_request (guc, rq); +if (ret == -EBUSY ) + guc->stalled_request = rq; + +return ret; +} +static void guc_submit_request (struct i915_request *rq) {struct i915_sched_engine *sched_engine = rq->engine->sched_engine; +struct intel_guc *guc = &rq->engine->gt->uc.guc;unsigned long flags;/* Will be called from irq-context when using foreign fences. */ spin_lock_irqsave (&sched_engine->lock, flags); -queue_request (sched_engine, rq,rq_prio (rq)); - -GEM_BUG_ON (i915_sched_engine_is_empty (sched_engine)); -GEM_BUG_ON (list_empty (&rq->sched.link)); - -i915_sched_engine_hi_kick (sched_engine); +if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) +queue_request (sched_engine, rq,rq_prio (rq)); +else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY ) +i915_sched_engine_hi_kick (sched_engine);spin_unlock_irqrestore (&sched_engine->lock, flags); }
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 46/97 drm/i915/guc: Implement GuC context operations for new inteface
In reply to Matthew BrostImplement GuC context operations which includes GuC specific operations pin, unpin, and destroy.
--- drivers/gpu/drm/i915/gt/intel_context.c | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 22 +- drivers/gpu/drm/i915/gt/intel_lrc_reg.h | 1 - drivers/gpu/drm/i915/gt/uc/intel_guc.h | 34 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 7 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 663 ++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + 8 files changed, 680 insertions(+), 54 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +5 -0
@@ -383,6 +383,11 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)mutex_init (&ce->pin_mutex); +spin_lock_init (&ce->guc_state.lock); + + ce->guc_id =GUC_INVALID_LRC_ID ; +INIT_LIST_HEAD (&ce->guc_id_link); +i915_active_init (&ce->active, __intel_context_active, __intel_context_retire,0 ); }
drivers/gpu/drm/i915/gt/intel_context_types.h +19 -3
@@ -95,6 +95,7 @@ struct intel_context {#define CONTEXT_BANNED 6#define CONTEXT_FORCE_SINGLE_SUBMISSION 7#define CONTEXT_NOPREEMPT 8 +#define CONTEXT_LRCA_DIRTY 9struct {u64 timeout_us;
@@ -137,14 +138,29 @@ struct intel_context {u8 wa_bb_page;/* if set, page num reserved for context workarounds */ +struct { +/** lock: protects everything in guc_state */ +spinlock_t lock; +/** +* sched_state: scheduling state of this context using GuC +* submission +*/ +u8 sched_state; + } guc_state; +/* GuC scheduling state that does not require a lock. */ atomic_t guc_sched_state_no_lock; +/* GuC lrc descriptor ID */ +u16 guc_id; + +/* GuC lrc descriptor reference count */ +atomic_t guc_id_ref; +/* -* GuC lrc descriptor ID - Not assigned in this patch but future patches -* in the series will. +* GuC ID link - in list when unpinned but guc_id still valid in GuC */ - u16 guc_id; + struct list_head guc_id_link; };#endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/intel_lrc_reg.h +0 -1
@@ -87,7 +87,6 @@#define GEN11_CSB_WRITE_PTR_MASK (GEN11_CSB_PTR_MASK << 0)#define MAX_CONTEXT_HW_ID (1 << 21)/* exclusive */ -#define MAX_GUC_CONTEXT_HW_ID (1 << 20)/* exclusive */ #define GEN11_MAX_CONTEXT_HW_ID (1 << 11)/* exclusive */ /* in Gen12 ID 0x7FF is reserved to indicate idle */ #define GEN12_MAX_CONTEXT_HW_ID (GEN11_MAX_CONTEXT_HW_ID - 1)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +34 -0
@@ -45,6 +45,14 @@ struct intel_guc {void (*disable)(struct intel_guc *guc); } interrupts; +/* +* contexts_lock protects the pool of free guc ids and a linked list of +* guc ids available to be stolden +*/ +spinlock_t contexts_lock; +struct ida guc_ids; +struct list_head guc_id_list; +bool submission_selected;struct i915_vma *ads_vma;
@@ -103,6 +111,29 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, response_buf, response_buf_size, 0); } +static inline int intel_guc_send_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +bool loop) +{ +int err; + +/* No sleeping with spin locks, just busy loop */ +might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); + +retry: + err =intel_guc_send_nb (guc, action, len); +if (unlikely (err == -EBUSY && loop)) { +if (likely (!in_atomic () && !irqs_disabled ())) +cond_resched (); +else +cpu_relax (); + goto retry; + } + +return err; +} +static inline void intel_guc_to_host_event_handler (struct intel_guc *guc) {intel_guc_ct_event_handler (&guc->ct);
@@ -204,6 +235,9 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine); +int intel_guc_deregister_done_process_msg (struct intel_guc *guc, +const u32 *msg,u32 len); +void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);#endif
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7 -0
@@ -893,6 +893,13 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *rcase INTEL_GUC_ACTION_DEFAULT : ret =intel_guc_to_host_process_recv_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE : + ret =intel_guc_deregister_done_process_msg (guc, payload, + len); +if (unlikely (ret)) +CT_ERROR (ct,"deregister context failed %x %*ph\n" , + action,4 * len, payload); +break ;default : ret = -EOPNOTSUPP ;break ;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +613 -50
754 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +1 -0
@@ -4127,6 +4127,7 @@ enum { FAULT_AND_CONTINUE /* Unsupported */ }; +#define CTX_GTT_ADDRESS_MASK GENMASK(31, 12)#define GEN8_CTX_VALID (1 << 0)#define GEN8_CTX_FORCE_PD_RESTORE (1 << 1)#define GEN8_CTX_FORCE_RESTORE (1 << 2)
drivers/gpu/drm/i915/i915_request.c +1 -0
@@ -419,6 +419,7 @@ bool i915_request_retire(struct i915_request *rq)*/ if (!list_empty (&rq->sched.link))remove_from_engine (rq); +atomic_dec (&rq->context->guc_id_ref);GEM_BUG_ON (!llist_empty (&rq->execute_cb));__list_del_entry (&rq->link);/* poison neither prev/next (RCU walks) */
Signature · 1 line
2.28.0
Re: [RFC PATCH 46/97] drm/i915/guc: Implement GuC context operations for new inteface
Quoted 61 lines · Matthew Brost
Implement GuC context operations which includes GuC specific operations pin, unpin, and destroy.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 22 +- drivers/gpu/drm/i915/gt/intel_lrc_reg.h | 1 - drivers/gpu/drm/i915/gt/uc/intel_guc.h | 34 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 7 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 663 ++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + 8 files changed, 680 insertions(+), 54 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +5
-0@@ -383,6 +383,11 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)mutex_init (&ce->pin_mutex); +spin_lock_init (&ce->guc_state.lock); + + ce->guc_id =GUC_INVALID_LRC_ID ; +INIT_LIST_HEAD (&ce->guc_id_link); +i915_active_init (&ce->active, __intel_context_active, __intel_context_retire,0 ); }drivers/gpu/drm/i915/gt/intel_context_types.h +11
-0@@ -95,6 +95,7 @@ struct intel_context {#define CONTEXT_BANNED 6#define CONTEXT_FORCE_SINGLE_SUBMISSION 7#define CONTEXT_NOPREEMPT 8 +#define CONTEXT_LRCA_DIRTY 9struct {u64 timeout_us;@@ -137,14 +138,29 @@ struct intel_context {u8 wa_bb_page;/* if set, page num reserved for context workarounds */ +struct { +/** lock: protects everything in guc_state */ +spinlock_t lock; +/** +* sched_state: scheduling state of this context using GuC +* submission +*/ +u8 sched_state; + } guc_state; +/* GuC scheduling state that does not require a lock. */ atomic_t guc_sched_state_no_lock;
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 161
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +7
-2+/* GuC lrc descriptor ID */ +u16 guc_id; + +/* GuC lrc descriptor reference count */ +atomic_t guc_id_ref; +/* -* GuC lrc descriptor ID - Not assigned in this patch but future patches -* in the series will. +* GuC ID link - in list when unpinned but guc_id still valid in GuC
nit: now there is no need for multi-line comment
Quoted 23 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +1
-1*/ - u16 guc_id; + struct list_head guc_id_link; };#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/intel_lrc_reg.h +0
-1@@ -87,7 +87,6 @@#define GEN11_CSB_WRITE_PTR_MASK (GEN11_CSB_PTR_MASK << 0)#define MAX_CONTEXT_HW_ID (1 << 21)/* exclusive */ -#define MAX_GUC_CONTEXT_HW_ID (1 << 20)/* exclusive */ #define GEN11_MAX_CONTEXT_HW_ID (1 << 11)/* exclusive */ /* in Gen12 ID 0x7FF is reserved to indicate idle */ #define GEN12_MAX_CONTEXT_HW_ID (GEN11_MAX_CONTEXT_HW_ID - 1)drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 50
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +3
-0@@ -45,6 +45,14 @@ struct intel_guc {void (*disable)(struct intel_guc *guc); } interrupts; +/* +* contexts_lock protects the pool of free guc ids and a linked list of +* guc ids available to be stolden
typo
Quoted 53 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +31
-0+*/ +spinlock_t contexts_lock; +struct ida guc_ids; +struct list_head guc_id_list; +bool submission_selected;struct i915_vma *ads_vma;@@ -103,6 +111,29 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, response_buf, response_buf_size, 0); } +static inline int intel_guc_send_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +bool loop) +{ +int err; + +/* No sleeping with spin locks, just busy loop */ +might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); + +retry: + err =intel_guc_send_nb (guc, action, len); +if (unlikely (err == -EBUSY && loop)) { +if (likely (!in_atomic () && !irqs_disabled ())) +cond_resched (); +else +cpu_relax (); + goto retry; + } + +return err; +} +static inline void intel_guc_to_host_event_handler (struct intel_guc *guc) {intel_guc_ct_event_handler (&guc->ct);@@ -204,6 +235,9 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine); +int intel_guc_deregister_done_process_msg (struct intel_guc *guc, +const u32 *msg,u32 len); +void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);#endif drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *r · line 901
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0@@ -893,6 +893,13 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *rcase INTEL_GUC_ACTION_DEFAULT : ret =intel_guc_to_host_process_recv_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE : + ret =intel_guc_deregister_done_process_msg (guc, payload, + len); +if (unlikely (ret)) +CT_ERROR (ct,"deregister context failed %x %*ph\n" , + action,4 * len, payload);
errors like this should be printed directly from GuC submission code, not from here and definitely not as CT_ERROR
and btw, handler function should rather return error only if there was CTB related failure (like truncated/corrupted message)
Quoted 352 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+break ;default : ret = -EOPNOTSUPP ;break ;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +308
-2@@ -13,7 +13,9 @@#include "gt/intel_gt.h" #include "gt/intel_gt_irq.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt_requests.h" #include "gt/intel_lrc.h" +#include "gt/intel_lrc_reg.h" #include "gt/intel_mocs.h" #include "gt/intel_ring.h" @@ -84,6 +86,73 @@ static inline void clr_context_enabled(struct intel_context *ce) &ce->guc_sched_state_no_lock); } +/* +* Below is a set of functions which control the GuC scheduling state which +* require a lock, aside from the special case where the functions are called +* from guc_lrc_desc_pin(). In that case it isn't possible for any other code +* path to be executing on the context. +*/ +#define SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER BIT(0) +#define SCHED_STATE_DESTROYED BIT(1) +static inline void init_sched_state (struct intel_context *ce) +{ +/* Only should be called from guc_lrc_desc_pin() */ +atomic_set (&ce->guc_sched_state_no_lock,0 ); + ce->guc_state.sched_state =0 ; +} + +static inline bool +context_wait_for_deregister_to_register (struct intel_context *ce) +{ +return (ce->guc_state.sched_state & +SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ); +} + +static inline void +set_context_wait_for_deregister_to_register (struct intel_context *ce) +{ +/* Only should be called from guc_lrc_desc_pin() */ + ce->guc_state.sched_state |= +SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ; +} + +static inline void +clr_context_wait_for_deregister_to_register (struct intel_context *ce) +{ +lockdep_assert_held (&ce->guc_state.lock); + ce->guc_state.sched_state = + (ce->guc_state.sched_state & + ~SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ); +} + +static inline bool +context_destroyed (struct intel_context *ce) +{ +return (ce->guc_state.sched_state &SCHED_STATE_DESTROYED ); +} + +static inline void +set_context_destroyed (struct intel_context *ce) +{ +lockdep_assert_held (&ce->guc_state.lock); + ce->guc_state.sched_state |=SCHED_STATE_DESTROYED ; +} + +static inline bool context_guc_id_invalid (struct intel_context *ce) +{ +return (ce->guc_id ==GUC_INVALID_LRC_ID ); +} + +static inline void set_context_guc_id_invalid (struct intel_context *ce) +{ + ce->guc_id =GUC_INVALID_LRC_ID ; +} + +static inline struct intel_guc *ce_to_guc (struct intel_context *ce) +{ +return &ce->engine->gt->uc.guc; +} +static inline struct i915_priolist *to_priolist (struct rb_node *rb) { return rb_entry(rb, struct i915_priolist, node);@@ -154,6 +223,9 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)int len =0 ;bool enabled =context_enabled (ce); +GEM_BUG_ON (!atomic_read (&ce->guc_id_ref)); +GEM_BUG_ON (context_guc_id_invalid (ce)); +if (!enabled) { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; action[len++] = ce->guc_id;@@ -420,6 +492,10 @@ int intel_guc_submission_init(struct intel_guc *guc)xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +spin_lock_init (&guc->contexts_lock); +INIT_LIST_HEAD (&guc->guc_id_list); +ida_init (&guc->guc_ids); +return 0 ; }@@ -432,9 +508,303 @@ void intel_guc_submission_fini(struct intel_guc *guc)i915_sched_engine_put (guc->sched_engine); } -static int guc_context_alloc (struct intel_context *ce) +static inline void queue_request (struct i915_sched_engine *sched_engine, +struct i915_request *rq, +int prio) { -return lrc_alloc (ce, ce->engine); +GEM_BUG_ON (!list_empty (&rq->sched.link)); +list_add_tail (&rq->sched.link, +i915_sched_lookup_priolist (sched_engine, prio)); +set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); +} + +static int guc_bypass_tasklet_submit (struct intel_guc *guc, +struct i915_request *rq) +{ +int ret; + +__i915_request_submit (rq); + +trace_i915_request_in (rq,0 ); + +guc_set_lrc_tail (rq); + ret =guc_add_request (guc, rq); +if (ret == -EBUSY ) + guc->stalled_request = rq; + +return ret; +} + +static void guc_submit_request (struct i915_request *rq) +{ +struct i915_sched_engine *sched_engine = rq->engine->sched_engine; +struct intel_guc *guc = &rq->engine->gt->uc.guc; +unsigned long flags; + +/* Will be called from irq-context when using foreign fences. */ +spin_lock_irqsave (&sched_engine->lock, flags); + +if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) +queue_request (sched_engine, rq,rq_prio (rq)); +else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY ) +i915_sched_engine_hi_kick (sched_engine); + +spin_unlock_irqrestore (&sched_engine->lock, flags); +} + +#define GUC_ID_START 64/* First 64 guc_ids reserved */ +static int new_guc_id (struct intel_guc *guc) +{ +return ida_simple_get (&guc->guc_ids,GUC_ID_START , +GUC_MAX_LRC_DESCRIPTORS ,GFP_KERNEL | + __GFP_RETRY_MAYFAIL | __GFP_NOWARN); +} + +static void __release_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +if (!context_guc_id_invalid (ce)) { +ida_simple_remove (&guc->guc_ids, ce->guc_id); +reset_lrc_desc (guc, ce->guc_id); +set_context_guc_id_invalid (ce); + } +if (!list_empty (&ce->guc_id_link)) +list_del_init (&ce->guc_id_link); +} + +static void release_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +unsigned long flags; + +spin_lock_irqsave (&guc->contexts_lock, flags); +__release_guc_id (guc, ce); +spin_unlock_irqrestore (&guc->contexts_lock, flags); +} + +static int steal_guc_id (struct intel_guc *guc) +{ +struct intel_context *ce; +int guc_id; + +if (!list_empty (&guc->guc_id_list)) { + ce =list_first_entry (&guc->guc_id_list, + struct intel_context, + guc_id_link); + +GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); +GEM_BUG_ON (context_guc_id_invalid (ce)); + +list_del_init (&ce->guc_id_link); + guc_id = ce->guc_id; +set_context_guc_id_invalid (ce); +return guc_id; + }else { +return -EAGAIN ; + } +} + +static int assign_guc_id (struct intel_guc *guc,u16 *out) +{ +int ret; + + ret =new_guc_id (guc); +if (unlikely (ret <0 )) { + ret =steal_guc_id (guc); +if (ret <0 ) +return ret; + } + + *out = ret; +return 0 ; +} + +#define PIN_GUC_ID_TRIES 4 +static int pin_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +int ret =0 ; +unsigned long flags, tries =PIN_GUC_ID_TRIES ; + +GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); + +try_again: +spin_lock_irqsave (&guc->contexts_lock, flags); + +if (context_guc_id_invalid (ce)) { + ret =assign_guc_id (guc, &ce->guc_id); +if (ret) + goto out_unlock; + ret =1 ;// Indidcates newly assigned HW context + } +if (!list_empty (&ce->guc_id_link)) +list_del_init (&ce->guc_id_link); +atomic_inc (&ce->guc_id_ref); + +out_unlock: +spin_unlock_irqrestore (&guc->contexts_lock, flags); + +/* +* -EAGAIN indicates no guc_ids are available, let's retire any +* outstanding requests to see if that frees up a guc_id. If the first +* retire didn't help, insert a sleep with the timeslice duration before +* attempting to retire more requests. Double the sleep period each +* subsequent pass before finally giving up. The sleep period has max of +* 100ms and minimum of 1ms. +*/ +if (ret == -EAGAIN && --tries) { +if (PIN_GUC_ID_TRIES - tries >1 ) { +unsigned int timeslice_shifted = + ce->engine->props.timeslice_duration_ms << + (PIN_GUC_ID_TRIES - tries -2 ); + unsigned int max = min_t(unsigned int, 100, + timeslice_shifted); + + msleep(max_t(unsigned int, max, 1)); + } +intel_gt_retire_requests (guc_to_gt (guc)); + goto try_again; + } + +return ret; +} + +static void unpin_guc_id (struct intel_guc *guc,struct intel_context *ce) +{ +unsigned long flags; + +GEM_BUG_ON (atomic_read (&ce->guc_id_ref) <0 ); + +spin_lock_irqsave (&guc->contexts_lock, flags); +if (!context_guc_id_invalid (ce) &&list_empty (&ce->guc_id_link) && + !atomic_read (&ce->guc_id_ref)) +list_add_tail (&ce->guc_id_link, &guc->guc_id_list); +spin_unlock_irqrestore (&guc->contexts_lock, flags); +} + +static int __guc_action_register_context (struct intel_guc *guc, +u32 guc_id, +u32 offset) +{ +u32 action[] = { +INTEL_GUC_ACTION_REGISTER_CONTEXT , + guc_id, + offset, + }; + +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +} + +static int register_context (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +u32 offset =intel_guc_ggtt_offset (guc, guc->lrc_desc_pool) + + ce->guc_id *sizeof (struct guc_lrc_desc ); + +return __guc_action_register_context (guc, ce->guc_id, offset); +} + +static int __guc_action_deregister_context (struct intel_guc *guc, +u32 guc_id) +{ +u32 action[] = { +INTEL_GUC_ACTION_DEREGISTER_CONTEXT , + guc_id, + }; + +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +} + +static int deregister_context (struct intel_context *ce,u32 guc_id) +{ +struct intel_guc *guc =ce_to_guc (ce); + +return __guc_action_deregister_context (guc, guc_id); +} + +static intel_engine_mask_t adjust_engine_mask (u8 class,intel_engine_mask_t mask) +{ +switch (class) { +case RENDER_CLASS : +return mask >>RCS0 ; +case VIDEO_ENHANCEMENT_CLASS : +return mask >>VECS0 ; +case VIDEO_DECODE_CLASS : +return mask >>VCS0 ; +case COPY_ENGINE_CLASS : +return mask >>BCS0 ; +default : +GEM_BUG_ON ("Invalid Class" ); +return 0 ; + } +} + +static void guc_context_policy_init (struct intel_engine_cs *engine, +struct guc_lrc_desc *desc) +{ + desc->policy_flags =0 ; +
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_fini(struct intel_guc *guc) · line 753
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+ desc->execution_quantum =CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US ; + desc->preemption_timeout =CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US ; +} + +static int guc_lrc_desc_pin (struct intel_context *ce) +{ +struct intel_runtime_pm *runtime_pm = + &ce->engine->gt->i915->runtime_pm; +struct intel_engine_cs *engine = ce->engine; +struct intel_guc *guc = &engine->gt->uc.guc;
can you reorder/optimize above locals?
Quoted 24 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +24
-0+u32 desc_idx = ce->guc_id; +struct guc_lrc_desc *desc; +bool context_registered; +intel_wakeref_t wakeref; +int ret =0 ; + +GEM_BUG_ON (!engine->mask); + +/* +* Ensure LRC + CT vmas are is same region as write barrier is done +* based on CT vma region. +*/ +GEM_BUG_ON (i915_gem_object_is_lmem (guc->ct.vma->obj) != +i915_gem_object_is_lmem (ce->ring->vma->obj)); + + context_registered =lrc_desc_registered (guc, desc_idx); + +reset_lrc_desc (guc, desc_idx); +set_lrc_desc_registered (guc, desc_idx, ce); + + desc =__get_lrc_desc (guc, desc_idx); + desc->engine_class =engine_class_to_guc_class (engine->class); + desc->engine_submit_mask =adjust_engine_mask (engine->class, + engine->mask);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_fini(struct intel_guc *guc) · line 787
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+ desc->hw_context_desc = ce->lrc.lrca; + desc->priority =GUC_CLIENT_PRIORITY_KMD_NORMAL ; + desc->context_flags =CONTEXT_REGISTRATION_FLAG_KMD ; +guc_context_policy_init (engine, desc); +init_sched_state (ce); + +/* +* The context_lookup xarray is used to determine if the hardware +* context is currently registered. There are two cases in which it +* could be regisgered either the guc_id has been stole from from
typo
Quoted 401 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +261
-48+* another context or the lrc descriptor address of this context has +* changed. In either case the context needs to be deregistered with the +* GuC before registering this context. +*/ +if (context_registered) { +set_context_wait_for_deregister_to_register (ce); +intel_context_get (ce); + +/* +* If stealing the guc_id, this ce has the same guc_id as the +* context whos guc_id was stole. +*/ +with_intel_runtime_pm (runtime_pm, wakeref) + ret = deregister_context(ce, ce->guc_id); + }else { +with_intel_runtime_pm (runtime_pm, wakeref) + ret = register_context(ce); + } + +return ret; } static int guc_context_pre_pin(struct intel_context *ce,@@ -446,36 +816,137 @@ static int guc_context_pre_pin(struct intel_context *ce,static int guc_context_pin (struct intel_context *ce,void *vaddr) { +if (i915_ggtt_offset (ce->state) != + (ce->lrc.lrca &CTX_GTT_ADDRESS_MASK )) +set_bit (CONTEXT_LRCA_DIRTY , &ce->flags); +return lrc_pin (ce, ce->engine, vaddr); } +static void guc_context_unpin (struct intel_context *ce) +{ +unpin_guc_id (ce_to_guc (ce), ce); +lrc_unpin (ce); +} + +static void guc_context_post_unpin (struct intel_context *ce) +{ +lrc_post_unpin (ce); +} + +static inline void guc_lrc_desc_unpin (struct intel_context *ce) +{ +struct intel_engine_cs *engine = ce->engine; +struct intel_guc *guc = &engine->gt->uc.guc; +unsigned long flags; + +GEM_BUG_ON (!lrc_desc_registered (guc, ce->guc_id)); +GEM_BUG_ON (ce !=__get_context (guc, ce->guc_id)); + +spin_lock_irqsave (&ce->guc_state.lock, flags); +set_context_destroyed (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags); + +deregister_context (ce, ce->guc_id); +} + +static void guc_context_destroy (struct kref *kref) +{ +struct intel_context *ce =container_of (kref,typeof (*ce), ref); +struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm; +struct intel_guc *guc = &ce->engine->gt->uc.guc; +intel_wakeref_t wakeref; +unsigned long flags; + +/* +* If the guc_id is invalid this context has been stolen and we can free +* it immediately. Also can be freed immediately if the context is not +* registered with the GuC. +*/ +if (context_guc_id_invalid (ce) || + !lrc_desc_registered (guc, ce->guc_id)) { +release_guc_id (guc, ce); +lrc_destroy (kref); +return ; + } + +/* +* We have to acquire the context spinlock and check guc_id again, if it +* is valid it hasn't been stolen and needs to be deregistered. We +* delete this context from the list of unpinned guc_ids available to +* stole to seal a race with guc_lrc_desc_pin(). When the G2H CTB +* returns indicating this context has been deregistered the guc_id is +* returned to the pool of available guc_ids. +*/ +spin_lock_irqsave (&guc->contexts_lock, flags); +if (context_guc_id_invalid (ce)) { +__release_guc_id (guc, ce); +spin_unlock_irqrestore (&guc->contexts_lock, flags); +lrc_destroy (kref); +return ; + } + +if (!list_empty (&ce->guc_id_link)) +list_del_init (&ce->guc_id_link); +spin_unlock_irqrestore (&guc->contexts_lock, flags); + +/* +* We defer GuC context deregistration until the context is destroyed +* in order to save on CTBs. With this optimization ideally we only need +* 1 CTB to register the context during the first pin and 1 CTB to +* deregister the context when the context is destroyed. Without this +* optimization, a CTB would be needed every pin & unpin. +* +* XXX: Need to acqiure the runtime wakeref as this can be triggered +* from context_free_worker when not runtime wakeref is held. +* guc_lrc_desc_unpin requires the runtime as a GuC register is written +* in H2G CTB to deregister the context. A future patch may defer this +* H2G CTB if the runtime wakeref is zero. +*/ + with_intel_runtime_pm(runtime_pm, wakeref) +guc_lrc_desc_unpin (ce); +} + +static int guc_context_alloc (struct intel_context *ce) +{ +return lrc_alloc (ce, ce->engine); +} +static const struct intel_context_ops guc_context_ops = { .alloc = guc_context_alloc, .pre_pin = guc_context_pre_pin, .pin = guc_context_pin, - .unpin = lrc_unpin, - .post_unpin = lrc_post_unpin, + .unpin = guc_context_unpin, + .post_unpin = guc_context_post_unpin, .enter = intel_context_enter_engine, .exit = intel_context_exit_engine, .reset = lrc_reset, - .destroy = lrc_destroy, + .destroy = guc_context_destroy, }; -static int guc_request_alloc (struct i915_request *request) +static bool context_needs_register (struct intel_context *ce,bool new_guc_id) +{ +return new_guc_id ||test_bit (CONTEXT_LRCA_DIRTY , &ce->flags) || + !lrc_desc_registered (ce_to_guc (ce), ce->guc_id); +} + +static int guc_request_alloc (struct i915_request *rq) { +struct intel_context *ce = rq->context; +struct intel_guc *guc =ce_to_guc (ce);int ret; -GEM_BUG_ON (!intel_context_is_pinned (request->context)); +GEM_BUG_ON (!intel_context_is_pinned (rq->context));/* * Flush enough space to reduce the likelihood of waiting after * we start building the request - in which case we will just * have to repeat work. */ - request->reserved_space +=GUC_REQUEST_SIZE ; + rq->reserved_space +=GUC_REQUEST_SIZE ;/* * Note that after this point, we have committed to using @@ -486,56 +957,48 @@ static int guc_request_alloc(struct i915_request *request)*/ /* Unconditionally invalidate GPU caches and TLBs. */ - ret = request->engine->emit_flush (request,EMIT_INVALIDATE ); + ret = rq->engine->emit_flush (rq,EMIT_INVALIDATE );if (ret)return ret; - request->reserved_space -=GUC_REQUEST_SIZE ; -return 0 ; -} - -static inline void queue_request (struct i915_sched_engine *sched_engine, -struct i915_request *rq, -int prio) -{ -GEM_BUG_ON (!list_empty (&rq->sched.link)); -list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (sched_engine, prio)); -set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); -} - -static int guc_bypass_tasklet_submit (struct intel_guc *guc, -struct i915_request *rq) -{ -int ret; + rq->reserved_space -=GUC_REQUEST_SIZE ; -__i915_request_submit (rq); - -trace_i915_request_in (rq,0 ); - -guc_set_lrc_tail (rq); - ret =guc_add_request (guc, rq); -if (ret == -EBUSY ) - guc->stalled_request = rq; - -return ret; -} +/* +* Call pin_guc_id here rather than in the pinning step as with +* dma_resv, contexts can be repeatedly pinned / unpinned trashing the +* guc_ids and creating horrible race conditions. This is especially bad +* when guc_ids are being stolen due to over subscription. By the time +* this function is reached, it is guaranteed that the guc_id will be +* persistent until the generated request is retired. Thus, sealing these +* race conditions. It is still safe to fail here if guc_ids are +* exhausted and return -EAGAIN to the user indicating that they can try +* again in the future. +* +* There is no need for a lock here as the timeline mutex ensures at +* most one context can be executing this code path at once. The +* guc_id_ref is incremented once for every request in flight and +* decremented on each retire. When it is zero, a lock around the +* increment (in pin_guc_id) is needed to seal a race with unpin_guc_id. +*/ +if (atomic_add_unless (&ce->guc_id_ref,1 ,0 )) +return 0 ; -static void guc_submit_request (struct i915_request *rq) -{ -struct i915_sched_engine *sched_engine = rq->engine->sched_engine; -struct intel_guc *guc = &rq->engine->gt->uc.guc; -unsigned long flags; + ret =pin_guc_id (guc, ce);/* returns 1 if new guc_id assigned */ +if (unlikely (ret <0 )) +return ret;; -/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&sched_engine->lock, flags); +if (context_needs_register (ce, !!ret)) { + ret =guc_lrc_desc_pin (ce); +if (unlikely (ret)) {/* unwind */ +atomic_dec (&ce->guc_id_ref); +unpin_guc_id (guc, ce); +return ret; + } + } -if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) -queue_request (sched_engine, rq,rq_prio (rq)); -else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY ) -i915_sched_engine_hi_kick (sched_engine); +clear_bit (CONTEXT_LRCA_DIRTY , &ce->flags); -spin_unlock_irqrestore (&sched_engine->lock, flags); +return 0 ; }static void sanitize_hwsp (struct intel_engine_cs *engine)@@ -609,6 +1072,46 @@ static void guc_set_default_submission(struct intel_engine_cs *engine) engine->submit_request = guc_submit_request; } +static inline void guc_kernel_context_pin (struct intel_guc *guc, +struct intel_context *ce) +{ +if (context_guc_id_invalid (ce)) +pin_guc_id (guc, ce); +guc_lrc_desc_pin (ce); +} + +static inline void guc_init_lrc_mapping (struct intel_guc *guc) +{ +struct intel_gt *gt =guc_to_gt (guc); +struct intel_engine_cs *engine; +enum intel_engine_id id; + +/* make sure all descriptors are clean... */ +xa_destroy (&guc->context_lookup); + +/* +* Some contexts might have been pinned before we enabled GuC +* submission, so we need to add them to the GuC bookeeping. +* Also, after a reset the GuC we want to make sure that the information +* shared with GuC is properly reset. The kernel lrcs are not attached +* to the gem_context, so they need to be added separately. +* +* Note: we purposely do not check the error return of +* guc_lrc_desc_pin, because that function can only fail in two cases. +* One, if there aren't enough free IDs, but we're guaranteed to have +* enough here (we're either only pinning a handful of lrc on first boot +* or we're re-pinning lrcs that were already pinned before the reset). +* Two, if the GuC has died and CTBs can't make forward progress. +* Presumably, the GuC should be alive as this function is called on +* driver load or after a reset. Even if it is dead, another full GPU +* reset will be triggered and this function would be called again. +*/ + +for_each_engine (engine, gt, id) +if (engine->kernel_context) +guc_kernel_context_pin (guc, engine->kernel_context); +} +static void guc_release (struct intel_engine_cs *engine) { engine->sanitize =NULL ;/* no longer in control, nothing to sanitize */ @@ -721,6 +1224,7 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)void intel_guc_submission_enable (struct intel_guc *guc) { +guc_init_lrc_mapping (guc); }void intel_guc_submission_disable (struct intel_guc *guc)@@ -746,3 +1250,62 @@ void intel_guc_submission_init_early(struct intel_guc *guc) { guc->submission_selected =__guc_submission_selected (guc); } + +static inline struct intel_context * +g2h_context_lookup (struct intel_guc *guc,u32 desc_idx) +{ +struct intel_context *ce; + +if (unlikely (desc_idx >=GUC_MAX_LRC_DESCRIPTORS )) { +drm_dbg (&guc_to_gt (guc)->i915->drm, +"Invalid desc_idx %u" , desc_idx); +return NULL ; + } + + ce =__get_context (guc, desc_idx); +if (unlikely (!ce)) { +drm_dbg (&guc_to_gt (guc)->i915->drm, +"Context is NULL, desc_idx %u" , desc_idx); +return NULL ; + } + +return ce; +} + +int intel_guc_deregister_done_process_msg (struct intel_guc *guc, +const u32 *msg, +u32 len) +{ +struct intel_context *ce; +u32 desc_idx = msg[0 ]; + +if (unlikely (len <1 )) { +drm_dbg (&guc_to_gt (guc)->i915->drm,"Invalid length %u" , len); +return -EPROTO ; + } + + ce =g2h_context_lookup (guc, desc_idx); +if (unlikely (!ce)) +return -EPROTO ; + +if (context_wait_for_deregister_to_register (ce)) { +struct intel_runtime_pm *runtime_pm = + &ce->engine->gt->i915->runtime_pm; +intel_wakeref_t wakeref; + +/* +* Previous owner of this guc_id has been deregistered, now safe +* register this context. +*/ + with_intel_runtime_pm(runtime_pm, wakeref) +register_context (ce); +clr_context_wait_for_deregister_to_register (ce); +intel_context_put (ce); + }else if (context_destroyed (ce)) { +/* Context has been destroyed */ +release_guc_id (guc, ce); +lrc_destroy (&ce->ref); + } + +return 0 ; +}drivers/gpu/drm/i915/i915_reg.h +1
-0@@ -4127,6 +4127,7 @@ enum { FAULT_AND_CONTINUE /* Unsupported */ }; +#define CTX_GTT_ADDRESS_MASK GENMASK(31, 12)#define GEN8_CTX_VALID (1 << 0)#define GEN8_CTX_FORCE_PD_RESTORE (1 << 1)#define GEN8_CTX_FORCE_RESTORE (1 << 2)drivers/gpu/drm/i915/i915_request.c +1
-0@@ -419,6 +419,7 @@ bool i915_request_retire(struct i915_request *rq)*/ if (!list_empty (&rq->sched.link))remove_from_engine (rq); +atomic_dec (&rq->context->guc_id_ref);GEM_BUG_ON (!llist_empty (&rq->execute_cb));__list_del_entry (&rq->link);/* poison neither prev/next (RCU walks) */
RFC PATCH 47/97 drm/i915/guc: Insert fence on context when deregistering
In reply to Matthew BrostSometime during context pinning a context with the same guc_id is registered with the GuC. In this a case deregister must be before before the context can be registered. A fence is inserted on all requests while the deregister is in flight. Once the G2H is received indicating the deregistration is complete the context is registered and the fence is released.
--- drivers/gpu/drm/i915/gt/intel_context.c | 1 + drivers/gpu/drm/i915/gt/intel_context_types.h | 5 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 51 ++++++++++++++++++- drivers/gpu/drm/i915/i915_request.h | 8 +++ 4 files changed, 63 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +1 -0
@@ -384,6 +384,7 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)mutex_init (&ce->pin_mutex);spin_lock_init (&ce->guc_state.lock); +INIT_LIST_HEAD (&ce->guc_state.fences); ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link);
drivers/gpu/drm/i915/gt/intel_context_types.h +5 -0
@@ -146,6 +146,11 @@ struct intel_context {* submission */ u8 sched_state; +/* +* fences: maintains of list of requests that have a submit +* fence related to GuC submission +*/ +struct list_head fences; } guc_state;/* GuC scheduling state that does not require a lock. */
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +49 -2
81 lines not on this page · raw message
drivers/gpu/drm/i915/i915_request.h +8 -0
@@ -285,6 +285,14 @@ struct i915_request {struct hrtimer timer; } watchdog; +/* +* Requests may need to be stalled when using GuC submission waiting for +* certain GuC operations to complete. If that is the case, stalled +* requests are added to a per context list of stalled requests. The +* below list_head is the link in that list. +*/ +struct list_head guc_fence_link; + I915_SELFTEST_DECLARE(struct { struct list_head link; unsigned long delay;
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 48/97 drm/i915/guc: Defer context unpin until scheduling is disabled
In reply to Matthew BrostWith GuC scheduling, it isn't safe to unpin a context while scheduling is enabled for that context as the GuC may touch some of the pinned state (e.g. LRC). To ensure scheduling isn't enabled when an unpin is done, a call back is added to intel_context_unpin when pin count == 1 to disable scheduling for that context. When the response CTB is received it is safe to do the final unpin.
Future patches may add a heuristic / delay to schedule the disable call back to avoid thrashing on schedule enable / disable.
--- drivers/gpu/drm/i915/gt/intel_context.c | 4 +- drivers/gpu/drm/i915/gt/intel_context.h | 21 ++- drivers/gpu/drm/i915/gt/intel_context_types.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 6 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 145 +++++++++++++++++- 6 files changed, 176 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +2 -2
@@ -306,9 +306,9 @@ int __intel_context_do_pin(struct intel_context *ce)return err; } -void intel_context_unpin (struct intel_context *ce) +void __intel_context_do_unpin (struct intel_context *ce,int sub) { -if (!atomic_dec_and_test (&ce->pin_count)) +if (!atomic_sub_and_test (sub, &ce->pin_count))return ;CE_TRACE (ce,"unpin\n" );
drivers/gpu/drm/i915/gt/intel_context.h +20 -1
@@ -113,7 +113,26 @@ static inline void __intel_context_pin(struct intel_context *ce)atomic_inc (&ce->pin_count); } -void intel_context_unpin (struct intel_context *ce); +void __intel_context_do_unpin (struct intel_context *ce,int sub); + +static inline void intel_context_sched_disable_unpin (struct intel_context *ce) +{ +__intel_context_do_unpin (ce,2 ); +} + +static inline void intel_context_unpin (struct intel_context *ce) +{ +if (!ce->ops->sched_disable) { +__intel_context_do_unpin (ce,1 ); + }else { +while (!atomic_add_unless (&ce->pin_count,-1 ,1 )) { +if (atomic_cmpxchg (&ce->pin_count,1 ,2 ) ==1 ) { + ce->ops->sched_disable (ce); +break ; + } + } + } +}void intel_context_enter_engine (struct intel_context *ce);void intel_context_exit_engine (struct intel_context *ce);
drivers/gpu/drm/i915/gt/intel_context_types.h +2 -0
@@ -43,6 +43,8 @@ struct intel_context_ops {void (*enter)(struct intel_context *ce);void (*exit)(struct intel_context *ce); +void (*sched_disable)(struct intel_context *ce); +void (*reset)(struct intel_context *ce);void (*destroy)(struct kref *kref); };
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
@@ -237,6 +237,8 @@ int intel_guc_reset_engine(struct intel_guc *guc,int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len); +int intel_guc_sched_done_process_msg (struct intel_guc *guc, +const u32 *msg,u32 len);void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6 -0
@@ -900,6 +900,12 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *rCT_ERROR (ct,"deregister context failed %x %*ph\n" , action,4 * len, payload);break ; +case INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE : + ret =intel_guc_sched_done_process_msg (guc, payload, len); +if (unlikely (ret)) +CT_ERROR (ct,"schedule context failed %x %*ph\n" , + action,4 * len, payload); +break ;default : ret = -EOPNOTSUPP ;break ;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +144 -1
203 lines not on this page · raw message
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 49/97 drm/i915/guc: Disable engine barriers with GuC during unpin
In reply to Matthew BrostDisable engine barriers for unpinning with GuC. This feature isn't needed with the GuC as it disables context scheduling before unpinning which guarantees the HW will not reference the context. Hence it is not necessary to defer unpinning until a kernel context request completes on each engine in the context engine mask.
--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.h | 1 + drivers/gpu/drm/i915/gt/selftest_context.c | 10 ++++++++++ drivers/gpu/drm/i915/i915_active.c | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/intel_context.c +1 -1
@@ -80,7 +80,7 @@ static int intel_context_active_acquire(struct intel_context *ce)__i915_active_acquire (&ce->active); -if (intel_context_is_barrier (ce)) +if (intel_context_is_barrier (ce) ||intel_engine_uses_guc (ce->engine))return 0 ;/* Preallocate tracking nodes */
drivers/gpu/drm/i915/gt/intel_context.h +1 -0
@@ -16,6 +16,7 @@#include "intel_engine_types.h" #include "intel_ring_types.h" #include "intel_timeline_types.h" +#include "uc/intel_guc_submission.h" #define CE_TRACE (ce, fmt, ...) do { \ const struct intel_context *ce__ = (ce); \
drivers/gpu/drm/i915/gt/selftest_context.c +10 -0
@@ -209,7 +209,13 @@ static int __live_active_context(struct intel_engine_cs *engine)* This test makes sure that the context is kept alive until a * subsequent idle-barrier (emitted when the engine wakeref hits 0 * with no more outstanding requests). +* +* In GuC submission mode we don't use idle barriers and we instead +* get a message from the GuC to signal that it is safe to unpin the +* context from memory. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",
@@ -357,7 +363,11 @@ static int __live_remote_context(struct intel_engine_cs *engine)* on the context image remotely (intel_context_prepare_remote_request), * which inserts foreign fences into intel_context.active, does not * clobber the idle-barrier. +* +* In GuC submission mode we don't use idle barriers. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",
drivers/gpu/drm/i915/i915_active.c +3 -0
@@ -968,6 +968,9 @@ void i915_active_acquire_barrier(struct i915_active *ref)GEM_BUG_ON (i915_active_is_idle (ref)); +if (llist_empty (&ref->preallocated_barriers)) +return ; +/* * Transfer the list of preallocated barriers into the * i915_active rbtree, but only as proto-nodes. They will be
Signature · 1 line
2.28.0
Re: [RFC PATCH 49/97] drm/i915/guc: Disable engine barriers with GuC during unpin
Quoted 9 lines · Matthew Brost
Disable engine barriers for unpinning with GuC. This feature isn't needed with the GuC as it disables context scheduling before unpinning which guarantees the HW will not reference the context. Hence it is not necessary to defer unpinning until a kernel context request completes on each engine in the context engine mask.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>
Instead of these ifs in the code, can we push this barrier business down into backends?
Not in this series, but as one of the things to sort out as part of the conversion to drm/scheduler.
-Daniel
Quoted 79 lines
--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.h | 1 + drivers/gpu/drm/i915/gt/selftest_context.c | 10 ++++++++++ drivers/gpu/drm/i915/i915_active.c | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_context.c +1
-1@@ -80,7 +80,7 @@ static int intel_context_active_acquire(struct intel_context *ce)__i915_active_acquire (&ce->active); -if (intel_context_is_barrier (ce)) +if (intel_context_is_barrier (ce) ||intel_engine_uses_guc (ce->engine))return 0 ;/* Preallocate tracking nodes */ drivers/gpu/drm/i915/gt/intel_context.h +1
-0@@ -16,6 +16,7 @@#include "intel_engine_types.h" #include "intel_ring_types.h" #include "intel_timeline_types.h" +#include "uc/intel_guc_submission.h" #define CE_TRACE (ce, fmt, ...) do { \ const struct intel_context *ce__ = (ce); \drivers/gpu/drm/i915/gt/selftest_context.c +10
-0@@ -209,7 +209,13 @@ static int __live_active_context(struct intel_engine_cs *engine)* This test makes sure that the context is kept alive until a * subsequent idle-barrier (emitted when the engine wakeref hits 0 * with no more outstanding requests). +* +* In GuC submission mode we don't use idle barriers and we instead +* get a message from the GuC to signal that it is safe to unpin the +* context from memory. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",@@ -357,7 +363,11 @@ static int __live_remote_context(struct intel_engine_cs *engine)* on the context image remotely (intel_context_prepare_remote_request), * which inserts foreign fences into intel_context.active, does not * clobber the idle-barrier. +* +* In GuC submission mode we don't use idle barriers. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",drivers/gpu/drm/i915/i915_active.c +3
-0@@ -968,6 +968,9 @@ void i915_active_acquire_barrier(struct i915_active *ref)GEM_BUG_ON (i915_active_is_idle (ref)); +if (llist_empty (&ref->preallocated_barriers)) +return ; +/* * Transfer the list of preallocated barriers into the * i915_active rbtree, but only as proto-nodes. They will be Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [RFC PATCH 49/97] drm/i915/guc: Disable engine barriers with GuC during unpin
Quoted 7 lines · Daniel Vetter
Quoted 6 lines · Matthew Brost
Disable engine barriers for unpinning with GuC. This feature isn't needed with the GuC as it disables context scheduling before unpinning which guarantees the HW will not reference the context. Hence it is not necessary to defer unpinning until a kernel context request completes on each engine in the context engine mask.
Quoted 7 lines
Quoted 3 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>Instead of these ifs in the code, can we push this barrier business down into backends?
Not a bad idea. This is an example of what I think of implict behavior of the backend creeping into the higher levels.
Quoted 2 lines
Not in this series, but as one of the things to sort out as part of the conversion to drm/scheduler.
Agree. After basic GuC submission gets merged maybe we go through the code and remove all the implict backend assumptions.
Matt
Quoted 86 lines
-Daniel
Quoted 79 lines
--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.h | 1 + drivers/gpu/drm/i915/gt/selftest_context.c | 10 ++++++++++ drivers/gpu/drm/i915/i915_active.c | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_context.c +1
-1@@ -80,7 +80,7 @@ static int intel_context_active_acquire(struct intel_context *ce)__i915_active_acquire (&ce->active); -if (intel_context_is_barrier (ce)) +if (intel_context_is_barrier (ce) ||intel_engine_uses_guc (ce->engine))return 0 ;/* Preallocate tracking nodes */ drivers/gpu/drm/i915/gt/intel_context.h +1
-0@@ -16,6 +16,7 @@#include "intel_engine_types.h" #include "intel_ring_types.h" #include "intel_timeline_types.h" +#include "uc/intel_guc_submission.h" #define CE_TRACE (ce, fmt, ...) do { \ const struct intel_context *ce__ = (ce); \drivers/gpu/drm/i915/gt/selftest_context.c +10
-0@@ -209,7 +209,13 @@ static int __live_active_context(struct intel_engine_cs *engine)* This test makes sure that the context is kept alive until a * subsequent idle-barrier (emitted when the engine wakeref hits 0 * with no more outstanding requests). +* +* In GuC submission mode we don't use idle barriers and we instead +* get a message from the GuC to signal that it is safe to unpin the +* context from memory. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",@@ -357,7 +363,11 @@ static int __live_remote_context(struct intel_engine_cs *engine)* on the context image remotely (intel_context_prepare_remote_request), * which inserts foreign fences into intel_context.active, does not * clobber the idle-barrier. +* +* In GuC submission mode we don't use idle barriers. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",drivers/gpu/drm/i915/i915_active.c +3
-0@@ -968,6 +968,9 @@ void i915_active_acquire_barrier(struct i915_active *ref)GEM_BUG_ON (i915_active_is_idle (ref)); +if (llist_empty (&ref->preallocated_barriers)) +return ; +/* * Transfer the list of preallocated barriers into the * i915_active rbtree, but only as proto-nodes. They will be Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [RFC PATCH 49/97] drm/i915/guc: Disable engine barriers with GuC during unpin
In reply to Matthew BrostQuoted 2 lines · Matthew Brost
Disable engine barriers for unpinning with GuC. This feature isn't needed with the GuC as it disables context scheduling before unpinning
Just isn't needed or causes a problem somehow?
Quoted 3 lines
which guarantees the HW will not reference the context. Hence it is not necessary to defer unpinning until a kernel context request completes on each engine in the context engine mask.
Hm context engine mask does not come across as something used in this patch.
Engine PM works fine with this change - i915 does not turn of the engine/gt too early? I mean context unpin is on retire and the guc disable of context scheduling is sync or async? Even when the kernel context request gets emitted on engine pm put there is no race?
Quoted 71 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.h | 1 + drivers/gpu/drm/i915/gt/selftest_context.c | 10 ++++++++++ drivers/gpu/drm/i915/i915_active.c | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_context.c +1
-1@@ -80,7 +80,7 @@ static int intel_context_active_acquire(struct intel_context *ce)__i915_active_acquire (&ce->active); -if (intel_context_is_barrier (ce)) +if (intel_context_is_barrier (ce) ||intel_engine_uses_guc (ce->engine))return 0 ;/* Preallocate tracking nodes */ drivers/gpu/drm/i915/gt/intel_context.h +1
-0@@ -16,6 +16,7 @@#include "intel_engine_types.h" #include "intel_ring_types.h" #include "intel_timeline_types.h" +#include "uc/intel_guc_submission.h" #define CE_TRACE (ce, fmt, ...) do { \ const struct intel_context *ce__ = (ce); \drivers/gpu/drm/i915/gt/selftest_context.c +10
-0@@ -209,7 +209,13 @@ static int __live_active_context(struct intel_engine_cs *engine)* This test makes sure that the context is kept alive until a * subsequent idle-barrier (emitted when the engine wakeref hits 0 * with no more outstanding requests). +* +* In GuC submission mode we don't use idle barriers and we instead +* get a message from the GuC to signal that it is safe to unpin the +* context from memory. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",@@ -357,7 +363,11 @@ static int __live_remote_context(struct intel_engine_cs *engine)* on the context image remotely (intel_context_prepare_remote_request), * which inserts foreign fences into intel_context.active, does not * clobber the idle-barrier. +* +* In GuC submission mode we don't use idle barriers. */ +if (intel_engine_uses_guc (engine)) +return 0 ;if (intel_engine_pm_is_awake (engine)) { pr_err("%s is awake before starting %s!\n",drivers/gpu/drm/i915/i915_active.c +0
-0
drivers/gpu/drm/i915/i915_active.c void i915_active_acquire_barrier(struct i915_active *ref) · line 972
Quoted 5 lines
drivers/gpu/drm/i915/i915_active.c +2
-0@@ -968,6 +968,9 @@ void i915_active_acquire_barrier(struct i915_active *ref)GEM_BUG_ON (i915_active_is_idle (ref)); +if (llist_empty (&ref->preallocated_barriers)) +return ;
This hunk is not needed since the effectively same check is few lines below.
Regards,
Tvrtko
drivers/gpu/drm/i915/i915_active.c void i915_active_acquire_barrier(struct i915_active *ref) · line 976
Quoted 5 lines
drivers/gpu/drm/i915/i915_active.c +1
-0+/* * Transfer the list of preallocated barriers into the * i915_active rbtree, but only as proto-nodes. They will be
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 50/97 drm/i915/guc: Extend deregistration fence to schedule disable
In reply to Matthew BrostExtend the deregistration context fence to fence whne a GuC context has scheduling disable pending.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +30 -7
@@ -921,7 +921,19 @@ static void guc_context_sched_disable(struct intel_context *ce) goto unpin;spin_lock_irqsave (&ce->guc_state.lock, flags); + +/* +* We have to check if the context has been pinned again as another pin +* operation is allowed to pass this function. Checking the pin count +* here synchronizes this function with guc_request_alloc ensuring a +* request doesn't slip through the 'context_pending_disable' fence. +*/ +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +return ; + } guc_id =prep_context_pending_disable (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags);with_intel_runtime_pm (runtime_pm, wakeref)
@@ -1127,19 +1139,22 @@ static int guc_request_alloc(struct i915_request *rq) out:/* * We block all requests on this context if a G2H is pending for a -* context deregistration as the GuC will fail a context registration -* while this G2H is pending. Once a G2H returns, the fence is released -* that is blocking these requests (see guc_signal_context_fence). +* schedule disable or context deregistration as the GuC will fail a +* schedule enable or context registration if either G2H is pending +* respectfully. Once a G2H returns, the fence is released that is +* blocking these requests (see guc_signal_context_fence). * -* We can safely check the below field outside of the lock as it isn't -* possible for this field to transition from being clear to set but +* We can safely check the below fields outside of the lock as it isn't +* possible for these fields to transition from being clear to set but * converse is possible, hence the need for the check within the lock. */ -if (likely (!context_wait_for_deregister_to_register (ce))) +if (likely (!context_wait_for_deregister_to_register (ce) && + !context_pending_disable (ce)))return 0 ;spin_lock_irqsave (&ce->guc_state.lock, flags); -if (context_wait_for_deregister_to_register (ce)) { +if (context_wait_for_deregister_to_register (ce) || +context_pending_disable (ce)) {i915_sw_fence_await (&rq->submit);list_add_tail (&rq->guc_fence_link, &ce->guc_state.fences);
@@ -1488,10 +1503,18 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,if (context_pending_enable (ce)) {clr_context_pending_enable (ce); }else if (context_pending_disable (ce)) { +/* +* Unpin must be done before __guc_signal_context_fence, +* otherwise a race exists between the requests getting +* submitted + retired before this unpin completes resulting in +* the pin_count going to zero and the context still being +* enabled. +*/ intel_context_sched_disable_unpin (ce);spin_lock_irqsave (&ce->guc_state.lock, flags);clr_context_pending_disable (ce); +__guc_signal_context_fence (ce);spin_unlock_irqrestore (&ce->guc_state.lock, flags); }
Signature · 1 line
2.28.0
RFC PATCH 51/97 drm/i915: Disable preempt busywait when using GuC scheduling
In reply to Matthew BrostDisable preempt busywait when using GuC scheduling. This isn't need as the GuC control preemption when scheduling.
--- drivers/gpu/drm/i915/gt/gen8_engine_cs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/gen8_engine_cs.c +4 -2
@@ -506,7 +506,8 @@ gen8_emit_fini_breadcrumb_tail(struct i915_request *rq, u32 *cs) *cs++ =MI_USER_INTERRUPT ; *cs++ =MI_ARB_ON_OFF |MI_ARB_ENABLE ; -if (intel_engine_has_semaphores (rq->engine)) +if (intel_engine_has_semaphores (rq->engine) && + !intel_uc_uses_guc_submission (&rq->engine->gt->uc)) cs =emit_preempt_busywait (rq, cs); rq->tail =intel_ring_offset (rq, cs);
@@ -598,7 +599,8 @@ gen12_emit_fini_breadcrumb_tail(struct i915_request *rq, u32 *cs) *cs++ =MI_USER_INTERRUPT ; *cs++ =MI_ARB_ON_OFF |MI_ARB_ENABLE ; -if (intel_engine_has_semaphores (rq->engine)) +if (intel_engine_has_semaphores (rq->engine) && + !intel_uc_uses_guc_submission (&rq->engine->gt->uc)) cs =gen12_emit_preempt_busywait (rq, cs); rq->tail =intel_ring_offset (rq, cs);
Signature · 1 line
2.28.0
RFC PATCH 52/97 drm/i915/guc: Ensure request ordering via completion fences
In reply to Matthew BrostIf two requests are on the same ring, they are explicitly ordered by the HW. So, a submission fence is sufficient to ensure ordering when using the new GuC submission interface. Conversely, if two requests share a timeline and are on the same physical engine but different context this doesn't ensure ordering on the new GuC submission interface. So, a completion fence needs to be used to ensure ordering.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 1 - drivers/gpu/drm/i915/i915_request.c | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0 -1
@@ -929,7 +929,6 @@ static void guc_context_sched_disable(struct intel_context *ce)* request doesn't slip through the 'context_pending_disable' fence. */ if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { -spin_unlock_irqrestore (&ce->guc_state.lock, flags);return ; } guc_id =prep_context_pending_disable (ce);
drivers/gpu/drm/i915/i915_request.c +13 -4
@@ -444,6 +444,7 @@ void i915_request_retire_upto(struct i915_request *rq)do { tmp =list_first_entry (&tl->requests,typeof (*tmp), link); +GEM_BUG_ON (!i915_request_completed (tmp)); }while (i915_request_retire (tmp) && tmp != rq); }
@@ -1405,6 +1406,9 @@ i915_request_await_external(struct i915_request *rq, struct dma_fence *fence)return err; } +static int +i915_request_await_request (struct i915_request *to,struct i915_request *from); + int i915_request_await_execution(struct i915_request *rq, struct dma_fence *fence,
@@ -1464,12 +1468,13 @@ await_request_submit(struct i915_request *to, struct i915_request *from)* the waiter to be submitted immediately to the physical engine * as it may then bypass the virtual request. */ -if (to->engine ==READ_ONCE (from->engine)) +if (to->engine ==READ_ONCE (from->engine)) {return i915_sw_fence_await_sw_fence_gfp (&to->submit, &from->submit,I915_FENCE_GFP ); -else + }else {return __i915_request_await_execution (to, from,NULL ); + } } static int
@@ -1493,7 +1498,8 @@ i915_request_await_request(struct i915_request *to, struct i915_request *from)return ret; } -if (is_power_of_2 (to->execution_mask |READ_ONCE (from->execution_mask))) +if (!intel_engine_uses_guc (to->engine) && +is_power_of_2 (to->execution_mask |READ_ONCE (from->execution_mask))) ret =await_request_submit (to, from);else ret =emit_semaphore_wait (to, from,I915_FENCE_GFP );
@@ -1654,6 +1660,8 @@ __i915_request_add_to_timeline(struct i915_request *rq) prev =to_request (__i915_active_fence_set (&timeline->last_request, &rq->fence));if (prev && !__i915_request_is_complete (prev)) { +bool uses_guc =intel_engine_uses_guc (rq->engine); +/* * The requests are supposed to be kept in order. However, * we need to be wary in case the timeline->last_request
@@ -1664,7 +1672,8 @@ __i915_request_add_to_timeline(struct i915_request *rq)i915_seqno_passed (prev->fence.seqno, rq->fence.seqno)); -if (is_power_of_2 (READ_ONCE (prev->engine)->mask | rq->engine->mask)) +if ((!uses_guc &&is_power_of_2 (READ_ONCE (prev->engine)->mask | rq->engine->mask)) || + (uses_guc && prev->context == rq->context))i915_sw_fence_await_sw_fence (&rq->submit, &prev->submit, &rq->submitq);
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 53/97 drm/i915/guc: Disable semaphores when using GuC scheduling
In reply to Matthew BrostDisable semaphores when using GuC scheduling as semaphores are broken in the current GuC firmware.
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +4 -2
@@ -230,7 +230,8 @@ static void intel_context_set_gem(struct intel_context *ce, ce->timeline =intel_timeline_get (ctx->timeline);if (ctx->sched.priority >=I915_PRIORITY_NORMAL && -intel_engine_has_timeslices (ce->engine)) +intel_engine_has_timeslices (ce->engine) && +intel_engine_has_semaphores (ce->engine))__set_bit (CONTEXT_USE_SEMAPHORES , &ce->flags);intel_context_set_watchdog_us (ce, ctx->watchdog.timeout_us);
@@ -1939,7 +1940,8 @@ static int __apply_priority(struct intel_context *ce, void *arg)if (!intel_engine_has_timeslices (ce->engine))return 0 ; -if (ctx->sched.priority >=I915_PRIORITY_NORMAL ) +if (ctx->sched.priority >=I915_PRIORITY_NORMAL && +intel_engine_has_semaphores (ce->engine))intel_context_set_use_semaphores (ce);else intel_context_clear_use_semaphores (ce);
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 53/97] drm/i915/guc: Disable semaphores when using GuC scheduling
Quoted 2 lines · Matthew Brost
Disable semaphores when using GuC scheduling as semaphores are broken in the current GuC firmware.
What is "current"? Given that the patch itself is like year and a half old.
Regards,
Tvrtko
Quoted 22 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +2
-1@@ -230,7 +230,8 @@ static void intel_context_set_gem(struct intel_context *ce, ce->timeline =intel_timeline_get (ctx->timeline);if (ctx->sched.priority >=I915_PRIORITY_NORMAL && -intel_engine_has_timeslices (ce->engine)) +intel_engine_has_timeslices (ce->engine) && +intel_engine_has_semaphores (ce->engine))__set_bit (CONTEXT_USE_SEMAPHORES , &ce->flags);intel_context_set_watchdog_us (ce, ctx->watchdog.timeout_us);
drivers/gpu/drm/i915/gem/i915_gem_context.c static int __apply_priority(struct intel_context *ce, void *arg) · line 1947
Quoted 9 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +2
-1@@ -1939,7 +1940,8 @@ static int __apply_priority(struct intel_context *ce, void *arg)if (!intel_engine_has_timeslices (ce->engine))return 0 ; -if (ctx->sched.priority >=I915_PRIORITY_NORMAL ) +if (ctx->sched.priority >=I915_PRIORITY_NORMAL && +intel_engine_has_semaphores (ce->engine))intel_context_set_use_semaphores (ce);else intel_context_clear_use_semaphores (ce);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 53/97] drm/i915/guc: Disable semaphores when using GuC scheduling
Quoted 7 lines · Tvrtko Ursulin
Quoted 2 lines · Matthew Brost
Disable semaphores when using GuC scheduling as semaphores are broken in the current GuC firmware.
What is "current"? Given that the patch itself is like year and a half old.
Stale comment. Semaphore work with the firmware we just haven't enabled them in the i915 with GuC submission as this an optimization and not required for functionality.
Matt
Quoted 32 lines
Regards,
Tvrtko
Quoted 28 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +4
-2@@ -230,7 +230,8 @@ static void intel_context_set_gem(struct intel_context *ce, ce->timeline =intel_timeline_get (ctx->timeline);if (ctx->sched.priority >=I915_PRIORITY_NORMAL && -intel_engine_has_timeslices (ce->engine)) +intel_engine_has_timeslices (ce->engine) && +intel_engine_has_semaphores (ce->engine))__set_bit (CONTEXT_USE_SEMAPHORES , &ce->flags);intel_context_set_watchdog_us (ce, ctx->watchdog.timeout_us);@@ -1939,7 +1940,8 @@ static int __apply_priority(struct intel_context *ce, void *arg)if (!intel_engine_has_timeslices (ce->engine))return 0 ; -if (ctx->sched.priority >=I915_PRIORITY_NORMAL ) +if (ctx->sched.priority >=I915_PRIORITY_NORMAL && +intel_engine_has_semaphores (ce->engine))intel_context_set_use_semaphores (ce);else intel_context_clear_use_semaphores (ce);
Re: [Intel-gfx] [RFC PATCH 53/97] drm/i915/guc: Disable semaphores when using GuC scheduling
Quoted 6 lines · Matthew Brost
Quoted 5 lines · Tvrtko Ursulin
Quoted 2 lines · Matthew Brost
Disable semaphores when using GuC scheduling as semaphores are broken in the current GuC firmware.
Quoted 6 lines
Quoted 2 lines
What is "current"? Given that the patch itself is like year and a half old.
Stale comment. Semaphore work with the firmware we just haven't enabled them in the i915 with GuC submission as this an optimization and not required for functionality.
How will the updated commit message look in terms of remaining reasons why semaphores won't/can't be enabled?
They were a nice performance win on some media workloads although granted a lot of tweaking was required to find a good balance on when to use them and when not to.
Regards,
Tvrtko
Quoted 26 lines
Matt
Quoted 24 lines
Regards,
Tvrtko
Quoted 20 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +2
-1@@ -230,7 +230,8 @@ static void intel_context_set_gem(struct intel_context *ce, ce->timeline =intel_timeline_get (ctx->timeline);if (ctx->sched.priority >=I915_PRIORITY_NORMAL && -intel_engine_has_timeslices (ce->engine)) +intel_engine_has_timeslices (ce->engine) && +intel_engine_has_semaphores (ce->engine))__set_bit (CONTEXT_USE_SEMAPHORES , &ce->flags);intel_context_set_watchdog_us (ce, ctx->watchdog.timeout_us);@@ -1939,7 +1940,8 @@ static int __apply_priority(struct intel_context *ce, void *arg)if (!intel_engine_has_timeslices (ce->engine))
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c static int __apply_priority(struct intel_context *ce, void *arg)
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +2
-1return 0 ; -if (ctx->sched.priority >=I915_PRIORITY_NORMAL ) +if (ctx->sched.priority >=I915_PRIORITY_NORMAL && +intel_engine_has_semaphores (ce->engine))intel_context_set_use_semaphores (ce);else intel_context_clear_use_semaphores (ce);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 53/97] drm/i915/guc: Disable semaphores when using GuC scheduling
Quoted 11 lines · Tvrtko Ursulin
Quoted 9 lines · Matthew Brost
Quoted 7 lines · Tvrtko Ursulin
Quoted 2 lines · Matthew Brost
Disable semaphores when using GuC scheduling as semaphores are broken in the current GuC firmware.
What is "current"? Given that the patch itself is like year and a half old.
Quoted 7 lines
Quoted 3 lines
Stale comment. Semaphore work with the firmware we just haven't enabled them in the i915 with GuC submission as this an optimization and not required for functionality.
How will the updated commit message look in terms of remaining reasons why semaphores won't/can't be enabled?
Semaphores are an optimization and not required for basic GuC submission to work properly. Disable until we have time to do the implementation to enable semaphores and tune them for performance.
Quoted 4 lines
They were a nice performance win on some media workloads although granted a lot of tweaking was required to find a good balance on when to use them and when not to.
The same tweaking would have to be done for with GuC submission. Let's get basic submission then tweak for performance.
Matt
Quoted 30 lines
Regards,
Tvrtko
Quoted 26 lines
Matt
Quoted 24 lines
Regards,
Tvrtko
Quoted 20 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +2
-1@@ -230,7 +230,8 @@ static void intel_context_set_gem(struct intel_context *ce, ce->timeline =intel_timeline_get (ctx->timeline);if (ctx->sched.priority >=I915_PRIORITY_NORMAL && -intel_engine_has_timeslices (ce->engine)) +intel_engine_has_timeslices (ce->engine) && +intel_engine_has_semaphores (ce->engine))__set_bit (CONTEXT_USE_SEMAPHORES , &ce->flags);intel_context_set_watchdog_us (ce, ctx->watchdog.timeout_us);@@ -1939,7 +1940,8 @@ static int __apply_priority(struct intel_context *ce, void *arg)if (!intel_engine_has_timeslices (ce->engine))
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c static int __apply_priority(struct intel_context *ce, void *arg)
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +2
-1return 0 ; -if (ctx->sched.priority >=I915_PRIORITY_NORMAL ) +if (ctx->sched.priority >=I915_PRIORITY_NORMAL && +intel_engine_has_semaphores (ce->engine))intel_context_set_use_semaphores (ce);else intel_context_clear_use_semaphores (ce);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 53/97] drm/i915/guc: Disable semaphores when using GuC scheduling
Quoted 24 lines · Matthew Brost
Quoted 11 lines · Tvrtko Ursulin
Quoted 9 lines · Matthew Brost
Quoted 7 lines · Tvrtko Ursulin
Quoted 2 lines · Matthew Brost
Disable semaphores when using GuC scheduling as semaphores are broken in the current GuC firmware.
What is "current"? Given that the patch itself is like year and a half old.
Quoted 7 lines
Quoted 3 lines
Stale comment. Semaphore work with the firmware we just haven't enabled them in the i915 with GuC submission as this an optimization and not required for functionality.
How will the updated commit message look in terms of remaining reasons why semaphores won't/can't be enabled?
Semaphores are an optimization and not required for basic GuC submission to work properly. Disable until we have time to do the implementation to enable semaphores and tune them for performance.
Quoted 7 lines
Quoted 4 lines
They were a nice performance win on some media workloads although granted a lot of tweaking was required to find a good balance on when to use them and when not to.
The same tweaking would have to be done for with GuC submission. Let's get basic submission then tweak for performance.
I don't have fundamental complaints as longs as commit message is improved and it is understood the absence of semaphores is extremely likely to regress transcode performance tests. Latter probably doesn't matter (for some definition of it) unless either there will be a platform where both GuC and execlists can be supported, or there will be two separate platforms similar in hw performance in theory, both relevant to transcode customers, one using execlists and one using GuC.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 53/97] drm/i915/guc: Disable semaphores when using GuC scheduling
Quoted 34 lines · Tvrtko Ursulin
Quoted 24 lines · Matthew Brost
Quoted 11 lines · Tvrtko Ursulin
Quoted 9 lines · Matthew Brost
Quoted 7 lines · Tvrtko Ursulin
Quoted 2 lines · Matthew Brost
Disable semaphores when using GuC scheduling as semaphores are broken in the current GuC firmware.
What is "current"? Given that the patch itself is like year and a half old.
Quoted 7 lines
Quoted 3 lines
Stale comment. Semaphore work with the firmware we just haven't enabled them in the i915 with GuC submission as this an optimization and not required for functionality.
How will the updated commit message look in terms of remaining reasons why semaphores won't/can't be enabled?
Semaphores are an optimization and not required for basic GuC submission to work properly. Disable until we have time to do the implementation to enable semaphores and tune them for performance.
Quoted 7 lines
Quoted 4 lines
They were a nice performance win on some media workloads although granted a lot of tweaking was required to find a good balance on when to use them and when not to.
The same tweaking would have to be done for with GuC submission. Let's get basic submission then tweak for performance.
Quoted 8 lines
I don't have fundamental complaints as longs as commit message is improved and it is understood the absence of semaphores is extremely likely to regress transcode performance tests. Latter probably doesn't matter (for some definition of it) unless either there will be a platform where both GuC and execlists can be supported, or there will be two separate platforms similar in hw performance in theory, both relevant to transcode customers, one using execlists and one using GuC.
Sounds good. Already have this commit message updated in my branch and will be included in the next post.
Matt
Quoted 5 lines
Regards,
Tvrtko
RFC PATCH 54/97 drm/i915/guc: Ensure G2H response has space in buffer
In reply to Matthew BrostEnsure G2H response has space in the buffer before sending H2G CTB as the GuC can't handle any backpressure on the G2H interface.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 13 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 74 +++++++++++++++---- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 13 ++-- 5 files changed, 85 insertions(+), 23 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +10 -3
@@ -96,11 +96,17 @@ inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len) }#define INTEL_GUC_SEND_NB BIT(31) +#define INTEL_GUC_SEND_G2H_DW_SHIFT 0 +#define INTEL_GUC_SEND_G2H_DW_MASK (0xff << INTEL_GUC_SEND_G2H_DW_SHIFT) +#define MAKE_SEND_FLAGS (len) \ + ({GEM_BUG_ON(!FIELD_FIT(INTEL_GUC_SEND_G2H_DW_MASK, len)); \ + (FIELD_PREP(INTEL_GUC_SEND_G2H_DW_MASK, len) | INTEL_GUC_SEND_NB);})static -inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len, +u32 g2h_len_dw) {return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , -INTEL_GUC_SEND_NB ); +MAKE_SEND_FLAGS (g2h_len_dw)); } static inline int
@@ -114,6 +120,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,static inline int intel_guc_send_busy_loop (struct intel_guc * guc,const u32 *action,u32 len, +u32 g2h_len_dw,bool loop) {int err;
@@ -122,7 +129,7 @@ static inline int intel_guc_send_busy_loop(struct intel_guc* guc,might_sleep_if (loop && (!in_atomic () && !irqs_disabled ())); retry: - err =intel_guc_send_nb (guc, action, len); + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (unlikely (err == -EBUSY && loop)) {if (likely (!in_atomic () && !irqs_disabled ()))cond_resched ();
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +60 -14
184 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3 -1
@@ -33,6 +33,7 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @resv_space: reserved space in buffer in dwords * @head: local shadow copy of head in dwords * @tail: local shadow copy of tail in dwords * @space: local shadow copy of space in dwords
@@ -43,9 +44,10 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 resv_space;u32 tail;u32 head; -u32 space; +atomic_t space;bool broken; };
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +4 -0
@@ -17,6 +17,10 @@#include "abi/guc_messages_abi.h" #include "gt/intel_engine_types.h" +/* Payload length only i.e. don't include G2H header length */ +#define G2H_LEN_DW_SCHED_CONTEXT_MODE_SET 2 +#define G2H_LEN_DW_DEREGISTER_CONTEXT 1 +#define GUC_CONTEXT_DISABLE 0#define GUC_CONTEXT_ENABLE 1
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8 -5
@@ -259,6 +259,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)struct intel_context *ce = rq->context;u32 action[3 ];int len =0 ; +u32 g2h_len_dw =0 ;bool enabled =context_enabled (ce);GEM_BUG_ON (!atomic_read (&ce->guc_id_ref));
@@ -270,13 +271,13 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) action[len++] =GUC_CONTEXT_ENABLE ;set_context_pending_enable (ce);intel_context_get (ce); + g2h_len_dw =G2H_LEN_DW_SCHED_CONTEXT_MODE_SET ; }else { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT ; action[len++] = ce->guc_id; } - err =intel_guc_send_nb (guc, action, len); - + err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) {set_context_enabled (ce); }else if (!enabled) {
@@ -733,7 +734,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)
@@ -753,7 +754,8 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_DEREGISTER_CONTEXT , true); }static int deregister_context (struct intel_context *ce,u32 guc_id)
@@ -892,7 +894,8 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), true); +intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }static u16 prep_context_pending_disable (struct intel_context *ce)
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 55/97 drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
In reply to Matthew BrostWhen running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in intel_gt_wait_for_idle to idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.
--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 18 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 7 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 91 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 + drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2 -1
@@ -634,7 +634,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;
drivers/gpu/drm/i915/gt/intel_gt.c +18 -0
@@ -574,6 +574,24 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long rtimeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &rtimeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, rtimeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;
drivers/gpu/drm/i915/gt/intel_gt.h +2 -0
@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);
drivers/gpu/drm/i915/gt/intel_gt_requests.c +6 -16
@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" static bool retire_requests (struct intel_timeline *tl) {
@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout) {struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;
@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (rtimeout) + *rtimeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)
drivers/gpu/drm/i915/gt/intel_gt_requests.h +3 -4
@@ -10,10 +10,11 @@ struct intel_engine_cs;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);
@@ -21,8 +22,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4 -0
@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {bool enabled;void (*reset)(struct intel_guc *guc);
@@ -239,6 +241,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1 -0
@@ -111,6 +111,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_init (&ct->receive_tasklet, ct_receive_tasklet_func, (unsigned long )ct); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4 -0
@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h"
@@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +87 -4
145 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_uc.h +5 -0
@@ -81,6 +81,11 @@ uc_state_checkers(guc, guc_submission);#undef uc_state_checkers#undef __uc_state_checker +static inline int intel_uc_wait_for_idle (struct intel_uc *uc,long timeout) +{ +return intel_guc_wait_for_idle (&uc->guc, timeout); +} +#define intel_uc_ops_function (_NAME, _OPS, _TYPE, _RET) \ static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ { \
drivers/gpu/drm/i915/i915_debugfs.c +1 -0
@@ -36,6 +36,7 @@#include "gt/intel_gt_clock_utils.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "gt/intel_reset.h" #include "gt/intel_rc6.h"
drivers/gpu/drm/i915/i915_gem_evict.c +1 -0
@@ -27,6 +27,7 @@*/ #include "gem/i915_gem_context.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h"
drivers/gpu/drm/i915/selftests/igt_live_test.c +1 -1
@@ -5,7 +5,7 @@*/ #include "i915_drv.h" -#include "gt/intel_gt_requests.h" +#include "gt/intel_gt.h" #include "../i915_selftest.h" #include "igt_flush_test.h"
drivers/gpu/drm/i915/selftests/mock_gem_device.c +2 -1
@@ -51,7 +51,8 @@ void mock_device_flush(struct drm_i915_private *i915)do {for_each_engine (engine, gt, id)mock_engine_flush (engine); - }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT )); + }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT , +NULL )); }static void mock_device_release (struct drm_device *dev)
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
kernel test robot
build botRe: [Intel-gfx] [RFC PATCH 55/97] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Matthew,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on drm-tip/drm-tip]
[also build test ERROR on drm-exynos/exynos-drm-next next-20210506]
[cannot apply to drm-intel/for-linux-next tegra-drm/drm/tegra/for-next drm/drm-next v5.12] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Matthew-Brost/Basic-GuC-submission-support-in-the-i915/20210507-030308 base: git://anongit.freedesktop.org/drm/drm-tip drm-tip config: x86_64-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/8ff6471d76f4a613b9e61d2178d97e0f2e78f2ee git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Matthew-Brost/Basic-GuC-submission-support-in-the-i915/20210507-030308 git checkout 8ff6471d76f4a613b9e61d2178d97e0f2e78f2ee # save the attached .config to linux build tree make W=1 W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from <command-line>:
drivers/gpu/drm/i915/gt/intel_gt_requests.h: In function 'intel_gt_retire_requests':
>> drivers/gpu/drm/i915/gt/intel_gt_requests.h:17:42: error: 'NULL' undeclared (first use in this function)
17 | intel_gt_retire_requests_timeout(gt, 0, NULL);
| ^~~~
drivers/gpu/drm/i915/gt/intel_gt_requests.h:1:1: note: 'NULL' is defined in header '<stddef.h>'; did you forget to '#include <stddef.h>'?
+++ |+#include <stddef.h>
1 | /* SPDX-License-Identifier: MIT */
drivers/gpu/drm/i915/gt/intel_gt_requests.h:17:42: note: each undeclared identifier is reported only once for each function it appears in
17 | intel_gt_retire_requests_timeout(gt, 0, NULL);
| ^~~~vim +/NULL +17 drivers/gpu/drm/i915/gt/intel_gt_requests.h
12
13 long intel_gt_retire_requests_timeout(struct intel_gt *gt, long timeout,
14 long *rtimeout);
15 static inline void intel_gt_retire_requests(struct intel_gt *gt)
16 {
> 17 intel_gt_retire_requests_timeout(gt, 0, NULL);
18 }
19 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [Intel-gfx] [RFC PATCH 55/97] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
In reply to Matthew BrostQuoted 93 lines · Matthew Brost
When running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in
intel_gt_wait_for_idleto idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 18 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 7 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 91 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 + drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-1@@ -634,7 +634,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;drivers/gpu/drm/i915/gt/intel_gt.c +18
-0@@ -574,6 +574,24 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long rtimeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &rtimeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, rtimeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;drivers/gpu/drm/i915/gt/intel_gt.h +2
-0@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);drivers/gpu/drm/i915/gt/intel_gt_requests.c +1
-0@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" static bool retire_requests (struct intel_timeline *tl) {
drivers/gpu/drm/i915/gt/intel_gt_requests.c void intel_engine_fini_retire(struct intel_engine_cs *engine) · line 135
Quoted 6 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +2
-1@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout)
What is 'rtimeout', I know remaining, but it can be more self-descriptive to start with.
It feels a bit churny for what it is. How plausible would be alternatives to either change existing timeout to in/out, or measure sleep internally in this function, or just risk sleeping twice as long by passing the original timeout to uc idle as well?
Quoted 166 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +3
-15{struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (rtimeout) + *rtimeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)drivers/gpu/drm/i915/gt/intel_gt_requests.h +3
-4@@ -10,10 +10,11 @@ struct intel_engine_cs;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);@@ -21,8 +22,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {bool enabled;void (*reset)(struct intel_guc *guc);@@ -239,6 +241,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -111,6 +111,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_init (&ct->receive_tasklet, ct_receive_tasklet_func, (unsigned long )ct); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +46
-0@@ -253,6 +253,74 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } +static int guc_submission_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +u32 g2h_len_dw, +bool loop) +{ +int err; + + err =intel_guc_send_busy_loop (guc, action, len, g2h_len_dw, loop); + +if (!err && g2h_len_dw) +atomic_inc (&guc->outstanding_submission_g2h); + +return err; +} + +static int guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout) +{ +const int state = interruptible ? +TASK_INTERRUPTIBLE :TASK_UNINTERRUPTIBLE ; +DEFINE_WAIT (wait); + +might_sleep (); +GEM_BUG_ON (timeout <0 ); + +if (!atomic_read (wait_var)) +return 0 ; + +if (!timeout) +return -ETIME ; + +for (;;) { +prepare_to_wait (&guc->ct.wq, &wait, state); + +if (!atomic_read (wait_var)) +break ; + +if (signal_pending_state (state, current)) { + timeout = -ERESTARTSYS ; +break ; + } + +if (!timeout) {
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 311
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+ timeout = -ETIME ; +break ; + } + + timeout =io_schedule_timeout (timeout); + } +finish_wait (&guc->ct.wq, &wait); + +return (timeout <0 ) ? timeout :0 ; +}
See if it is possible to simplify all this with wait_var_event and wake_up_var.
Quoted 62 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +19
-4+ +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) +{ +bool interruptible = true; + +if (unlikely (timeout <0 )) + timeout = -timeout, interruptible = false; + +return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); +} +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -279,6 +347,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {clr_context_pending_enable (ce);@@ -734,7 +803,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -754,7 +823,7 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_DEREGISTER_CONTEXT , true); }@@ -871,7 +940,9 @@ static int guc_context_pin(struct intel_context *ce, void *vaddr)static void guc_context_unpin (struct intel_context *ce) { -unpin_guc_id (ce_to_guc (ce), ce); +struct intel_guc *guc =ce_to_guc (ce); + +unpin_guc_id (guc, ce);lrc_unpin (ce); }@@ -894,7 +965,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c g2h_context_lookup(struct intel_guc *guc, u32 desc_idx) · line 1516
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0@@ -1437,6 +1508,15 @@ g2h_context_lookup(struct intel_guc *guc, u32 desc_idx)return ce; } +static void decr_outstanding_submission_g2h (struct intel_guc *guc) +{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) { +smp_mb (); +if (waitqueue_active (&guc->ct.wq)) +wake_up_all (&guc->ct.wq);
I keep pointing out this pattern is racy and at least needs comment why it is safe.
Regards,
Tvrtko
Quoted 82 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+ } +} +int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len)@@ -1472,6 +1552,8 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,lrc_destroy (&ce->ref); } +decr_outstanding_submission_g2h (guc); +return 0 ; }@@ -1520,6 +1602,7 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,spin_unlock_irqrestore (&ce->guc_state.lock, flags); } +decr_outstanding_submission_g2h (guc);intel_context_put (ce);return 0 ;drivers/gpu/drm/i915/gt/uc/intel_uc.h +5
-0@@ -81,6 +81,11 @@ uc_state_checkers(guc, guc_submission);#undef uc_state_checkers#undef __uc_state_checker +static inline int intel_uc_wait_for_idle (struct intel_uc *uc,long timeout) +{ +return intel_guc_wait_for_idle (&uc->guc, timeout); +} +#define intel_uc_ops_function (_NAME, _OPS, _TYPE, _RET) \ static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ { \drivers/gpu/drm/i915/i915_debugfs.c +1
-0@@ -36,6 +36,7 @@#include "gt/intel_gt_clock_utils.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "gt/intel_reset.h" #include "gt/intel_rc6.h" drivers/gpu/drm/i915/i915_gem_evict.c +1
-0@@ -27,6 +27,7 @@*/ #include "gem/i915_gem_context.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h" drivers/gpu/drm/i915/selftests/igt_live_test.c +1
-1@@ -5,7 +5,7 @@*/ #include "i915_drv.h" -#include "gt/intel_gt_requests.h" +#include "gt/intel_gt.h" #include "../i915_selftest.h" #include "igt_flush_test.h" drivers/gpu/drm/i915/selftests/mock_gem_device.c +0
-0
drivers/gpu/drm/i915/selftests/mock_gem_device.c void mock_device_flush(struct drm_i915_private *i915) · line 58
Quoted 9 lines
drivers/gpu/drm/i915/selftests/mock_gem_device.c +2
-1@@ -51,7 +51,8 @@ void mock_device_flush(struct drm_i915_private *i915)do {for_each_engine (engine, gt, id)mock_engine_flush (engine); - }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT )); + }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT , +NULL )); }static void mock_device_release (struct drm_device *dev)
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 55/97] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
Quoted 89 lines · Tvrtko Ursulin
Quoted 87 lines · Matthew Brost
When running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in
intel_gt_wait_for_idleto idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 18 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 7 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 91 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 + drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-1@@ -634,7 +634,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;drivers/gpu/drm/i915/gt/intel_gt.c +18
-0@@ -574,6 +574,24 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long rtimeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &rtimeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, rtimeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;drivers/gpu/drm/i915/gt/intel_gt.h +2
-0@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);drivers/gpu/drm/i915/gt/intel_gt_requests.c +1
-0@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" static bool retire_requests (struct intel_timeline *tl) {@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c void intel_engine_fini_retire(struct intel_engine_cs *engine) · line 135
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +2
-1GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout)What is 'rtimeout', I know remaining, but it can be more self-descriptive to start with.
'remaining_timeout' it is.
Quoted 5 lines
It feels a bit churny for what it is. How plausible would be alternatives to either change existing timeout to in/out, or measure sleep internally in this function, or just risk sleeping twice as long by passing the original timeout to uc idle as well?
Originally had it just passing in the same value, got review feedback saying I should pass in the adjusted value. Hard to make everyone happy.
Quoted 155 lines
Quoted 155 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +3
-15{struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (rtimeout) + *rtimeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)drivers/gpu/drm/i915/gt/intel_gt_requests.h +3
-4@@ -10,10 +10,11 @@ struct intel_engine_cs;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);@@ -21,8 +22,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {bool enabled;void (*reset)(struct intel_guc *guc);@@ -239,6 +241,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -111,6 +111,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_init (&ct->receive_tasklet, ct_receive_tasklet_func, (unsigned long )ct); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +51
-0@@ -253,6 +253,74 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } +static int guc_submission_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +u32 g2h_len_dw, +bool loop) +{ +int err; + + err =intel_guc_send_busy_loop (guc, action, len, g2h_len_dw, loop); + +if (!err && g2h_len_dw) +atomic_inc (&guc->outstanding_submission_g2h); + +return err; +} + +static int guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout) +{ +const int state = interruptible ? +TASK_INTERRUPTIBLE :TASK_UNINTERRUPTIBLE ; +DEFINE_WAIT (wait); + +might_sleep (); +GEM_BUG_ON (timeout <0 ); + +if (!atomic_read (wait_var)) +return 0 ; + +if (!timeout) +return -ETIME ; + +for (;;) { +prepare_to_wait (&guc->ct.wq, &wait, state); + +if (!atomic_read (wait_var)) +break ; + +if (signal_pending_state (state, current)) { + timeout = -ERESTARTSYS ; +break ; + } + +if (!timeout) { + timeout = -ETIME ; +break ; + } + + timeout =io_schedule_timeout (timeout);
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 311
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+ } +finish_wait (&guc->ct.wq, &wait); + +return (timeout <0 ) ? timeout :0 ; +}See if it is possible to simplify all this with
wait_var_eventandwake_up_var.
Let me check on that.
Quoted 55 lines
Quoted 55 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +20
-4+ +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) +{ +bool interruptible = true; + +if (unlikely (timeout <0 )) + timeout = -timeout, interruptible = false; + +return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); +} +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -279,6 +347,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {clr_context_pending_enable (ce);@@ -734,7 +803,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -754,7 +823,7 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_DEREGISTER_CONTEXT , true); }@@ -871,7 +940,9 @@ static int guc_context_pin(struct intel_context *ce, void *vaddr)static void guc_context_unpin (struct intel_context *ce) { -unpin_guc_id (ce_to_guc (ce), ce); +struct intel_guc *guc =ce_to_guc (ce); + +unpin_guc_id (guc, ce);lrc_unpin (ce); }@@ -894,7 +965,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }@@ -1437,6 +1508,15 @@ g2h_context_lookup(struct intel_guc *guc, u32 desc_idx)return ce; } +static void decr_outstanding_submission_g2h (struct intel_guc *guc)
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c g2h_context_lookup(struct intel_guc *guc, u32 desc_idx) · line 1516
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) { +smp_mb (); +if (waitqueue_active (&guc->ct.wq)) +wake_up_all (&guc->ct.wq);I keep pointing out this pattern is racy and at least needs comment why it is safe.
There is a comment in wake queue code header saying why this is safe. I don't think we need to repeat this here.
Matt
Quoted 85 lines
Regards,
Tvrtko
Quoted 81 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+ } +} +int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len)@@ -1472,6 +1552,8 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,lrc_destroy (&ce->ref); } +decr_outstanding_submission_g2h (guc); +return 0 ; }@@ -1520,6 +1602,7 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,spin_unlock_irqrestore (&ce->guc_state.lock, flags); } +decr_outstanding_submission_g2h (guc);intel_context_put (ce);return 0 ;drivers/gpu/drm/i915/gt/uc/intel_uc.h +5
-0@@ -81,6 +81,11 @@ uc_state_checkers(guc, guc_submission);#undef uc_state_checkers#undef __uc_state_checker +static inline int intel_uc_wait_for_idle (struct intel_uc *uc,long timeout) +{ +return intel_guc_wait_for_idle (&uc->guc, timeout); +} +#define intel_uc_ops_function (_NAME, _OPS, _TYPE, _RET) \ static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ { \drivers/gpu/drm/i915/i915_debugfs.c +1
-0@@ -36,6 +36,7 @@#include "gt/intel_gt_clock_utils.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "gt/intel_reset.h" #include "gt/intel_rc6.h" drivers/gpu/drm/i915/i915_gem_evict.c +1
-0@@ -27,6 +27,7 @@*/ #include "gem/i915_gem_context.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h" drivers/gpu/drm/i915/selftests/igt_live_test.c +1
-1@@ -5,7 +5,7 @@*/ #include "i915_drv.h" -#include "gt/intel_gt_requests.h" +#include "gt/intel_gt.h" #include "../i915_selftest.h" #include "igt_flush_test.h" drivers/gpu/drm/i915/selftests/mock_gem_device.c +2
-1@@ -51,7 +51,8 @@ void mock_device_flush(struct drm_i915_private *i915)do {for_each_engine (engine, gt, id)mock_engine_flush (engine); - }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT )); + }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT , +NULL )); }static void mock_device_release (struct drm_device *dev)
Re: [Intel-gfx] [RFC PATCH 55/97] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
Quoted 102 lines · Matthew Brost
Quoted 89 lines · Tvrtko Ursulin
Quoted 87 lines · Matthew Brost
When running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in
intel_gt_wait_for_idleto idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 18 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 7 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 91 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 + drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-1@@ -634,7 +634,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;drivers/gpu/drm/i915/gt/intel_gt.c +18
-0@@ -574,6 +574,24 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long rtimeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &rtimeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, rtimeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;drivers/gpu/drm/i915/gt/intel_gt.h +2
-0@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);drivers/gpu/drm/i915/gt/intel_gt_requests.c +1
-0@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" static bool retire_requests (struct intel_timeline *tl) {@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c void intel_engine_fini_retire(struct intel_engine_cs *engine) · line 135
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +2
-1GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout)What is 'rtimeout', I know remaining, but it can be more self-descriptive to start with.
'
remaining_timeout' it is.
Quoted 8 lines
Quoted 5 lines
It feels a bit churny for what it is. How plausible would be alternatives to either change existing timeout to in/out, or measure sleep internally in this function, or just risk sleeping twice as long by passing the original timeout to uc idle as well?
Originally had it just passing in the same value, got review feedback saying I should pass in the adjusted value. Hard to make everyone happy.
Ok.
Quoted 233 lines
Quoted 156 lines
Quoted 156 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +3
-15{struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (rtimeout) + *rtimeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)drivers/gpu/drm/i915/gt/intel_gt_requests.h +3
-4@@ -10,10 +10,11 @@ struct intel_engine_cs;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);@@ -21,8 +22,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {bool enabled;void (*reset)(struct intel_guc *guc);@@ -239,6 +241,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -111,6 +111,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_init (&ct->receive_tasklet, ct_receive_tasklet_func, (unsigned long )ct); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +51
-0@@ -253,6 +253,74 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } +static int guc_submission_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +u32 g2h_len_dw, +bool loop) +{ +int err; + + err =intel_guc_send_busy_loop (guc, action, len, g2h_len_dw, loop); + +if (!err && g2h_len_dw) +atomic_inc (&guc->outstanding_submission_g2h); + +return err; +} + +static int guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout) +{ +const int state = interruptible ? +TASK_INTERRUPTIBLE :TASK_UNINTERRUPTIBLE ; +DEFINE_WAIT (wait); + +might_sleep (); +GEM_BUG_ON (timeout <0 ); + +if (!atomic_read (wait_var)) +return 0 ; + +if (!timeout) +return -ETIME ; + +for (;;) { +prepare_to_wait (&guc->ct.wq, &wait, state); + +if (!atomic_read (wait_var)) +break ; + +if (signal_pending_state (state, current)) { + timeout = -ERESTARTSYS ; +break ; + } + +if (!timeout) { + timeout = -ETIME ; +break ; + } + + timeout =io_schedule_timeout (timeout);Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 311
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+ } +finish_wait (&guc->ct.wq, &wait); + +return (timeout <0 ) ? timeout :0 ; +}See if it is possible to simplify all this with
wait_var_eventandwake_up_var.Let me check on that.
Quoted 55 lines
Quoted 55 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +20
-4+ +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) +{ +bool interruptible = true; + +if (unlikely (timeout <0 )) + timeout = -timeout, interruptible = false; + +return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); +} +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -279,6 +347,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {clr_context_pending_enable (ce);@@ -734,7 +803,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -754,7 +823,7 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_DEREGISTER_CONTEXT , true); }@@ -871,7 +940,9 @@ static int guc_context_pin(struct intel_context *ce, void *vaddr)static void guc_context_unpin (struct intel_context *ce) { -unpin_guc_id (ce_to_guc (ce), ce); +struct intel_guc *guc =ce_to_guc (ce); + +unpin_guc_id (guc, ce);lrc_unpin (ce); }@@ -894,7 +965,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }@@ -1437,6 +1508,15 @@ g2h_context_lookup(struct intel_guc *guc, u32 desc_idx)return ce; } +static void decr_outstanding_submission_g2h (struct intel_guc *guc)Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c g2h_context_lookup(struct intel_guc *guc, u32 desc_idx) · line 1516
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) { +smp_mb (); +if (waitqueue_active (&guc->ct.wq)) +wake_up_all (&guc->ct.wq);I keep pointing out this pattern is racy and at least needs comment why it is safe.
Quoted 2 lines
There is a comment in wake queue code header saying why this is safe. I don't think we need to repeat this here.
Yeah, _describing how to make it safe_, after it starts with:
* NOTE: this function is lockless and requires care, incorrect usage _will_
* lead to sporadic and non-obvious failure.
Then it also says:
* Also note that this 'optimization' trades a spin_lock() for an smp_mb(),
* which (when the lock is uncontended) are of roughly equal cost.
I question the need to optimize this path since it means reader has to figure out if it is safe while a simple wake_up_all after atomic_dec_and_test would have done it.
Is the case of no waiters a predominant one? It at least deserves a comment explaining why the optimisation is important.
Regards,
Tvrtko
Quoted 80 lines
Matt
Quoted 77 lines
Regards,
Tvrtko
Quoted 73 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+ } +} +int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len)@@ -1472,6 +1552,8 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,lrc_destroy (&ce->ref); } +decr_outstanding_submission_g2h (guc); +return 0 ; }@@ -1520,6 +1602,7 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,spin_unlock_irqrestore (&ce->guc_state.lock, flags); } +decr_outstanding_submission_g2h (guc);intel_context_put (ce);return 0 ;drivers/gpu/drm/i915/gt/uc/intel_uc.h +5
-0@@ -81,6 +81,11 @@ uc_state_checkers(guc, guc_submission);#undef uc_state_checkers#undef __uc_state_checker +static inline int intel_uc_wait_for_idle (struct intel_uc *uc,long timeout) +{ +return intel_guc_wait_for_idle (&uc->guc, timeout); +} +#define intel_uc_ops_function (_NAME, _OPS, _TYPE, _RET) \ static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ { \drivers/gpu/drm/i915/i915_debugfs.c +1
-0@@ -36,6 +36,7 @@#include "gt/intel_gt_clock_utils.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "gt/intel_reset.h" #include "gt/intel_rc6.h" drivers/gpu/drm/i915/i915_gem_evict.c +1
-0@@ -27,6 +27,7 @@*/ #include "gem/i915_gem_context.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h" drivers/gpu/drm/i915/selftests/igt_live_test.c +1
-1@@ -5,7 +5,7 @@*/ #include "i915_drv.h" -#include "gt/intel_gt_requests.h" +#include "gt/intel_gt.h" #include "../i915_selftest.h" #include "igt_flush_test.h" drivers/gpu/drm/i915/selftests/mock_gem_device.c +0
-0@@ -51,7 +51,8 @@ void mock_device_flush(struct drm_i915_private *i915) do {
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/selftests/mock_gem_device.c void mock_device_flush(struct drm_i915_private *i915)
Quoted 8 lines
drivers/gpu/drm/i915/selftests/mock_gem_device.c +2
-1for_each_engine (engine, gt, id)mock_engine_flush (engine); - }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT )); + }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT , +NULL )); }static void mock_device_release (struct drm_device *dev)
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 55/97] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
Quoted 354 lines · Tvrtko Ursulin
Quoted 102 lines · Matthew Brost
Quoted 89 lines · Tvrtko Ursulin
Quoted 87 lines · Matthew Brost
When running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in
intel_gt_wait_for_idleto idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 18 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 7 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 91 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 + drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-1@@ -634,7 +634,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;drivers/gpu/drm/i915/gt/intel_gt.c +18
-0@@ -574,6 +574,24 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long rtimeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &rtimeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, rtimeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;drivers/gpu/drm/i915/gt/intel_gt.h +2
-0@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);drivers/gpu/drm/i915/gt/intel_gt_requests.c +1
-0@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" static bool retire_requests (struct intel_timeline *tl) {@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c void intel_engine_fini_retire(struct intel_engine_cs *engine) · line 135
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +2
-1GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout)What is 'rtimeout', I know remaining, but it can be more self-descriptive to start with.
'
remaining_timeout' it is.Quoted 8 lines
Quoted 5 lines
It feels a bit churny for what it is. How plausible would be alternatives to either change existing timeout to in/out, or measure sleep internally in this function, or just risk sleeping twice as long by passing the original timeout to uc idle as well?
Originally had it just passing in the same value, got review feedback saying I should pass in the adjusted value. Hard to make everyone happy.
Ok.
Quoted 231 lines
Quoted 155 lines
Quoted 155 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +3
-15{struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (rtimeout) + *rtimeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)drivers/gpu/drm/i915/gt/intel_gt_requests.h +3
-4@@ -10,10 +10,11 @@ struct intel_engine_cs;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);@@ -21,8 +22,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {bool enabled;void (*reset)(struct intel_guc *guc);@@ -239,6 +241,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -111,6 +111,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_init (&ct->receive_tasklet, ct_receive_tasklet_func, (unsigned long )ct); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +51
-0@@ -253,6 +253,74 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } +static int guc_submission_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +u32 g2h_len_dw, +bool loop) +{ +int err; + + err =intel_guc_send_busy_loop (guc, action, len, g2h_len_dw, loop); + +if (!err && g2h_len_dw) +atomic_inc (&guc->outstanding_submission_g2h); + +return err; +} + +static int guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout) +{ +const int state = interruptible ? +TASK_INTERRUPTIBLE :TASK_UNINTERRUPTIBLE ; +DEFINE_WAIT (wait); + +might_sleep (); +GEM_BUG_ON (timeout <0 ); + +if (!atomic_read (wait_var)) +return 0 ; + +if (!timeout) +return -ETIME ; + +for (;;) { +prepare_to_wait (&guc->ct.wq, &wait, state); + +if (!atomic_read (wait_var)) +break ; + +if (signal_pending_state (state, current)) { + timeout = -ERESTARTSYS ; +break ; + } + +if (!timeout) { + timeout = -ETIME ; +break ; + } + + timeout =io_schedule_timeout (timeout);Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 311
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+ } +finish_wait (&guc->ct.wq, &wait); + +return (timeout <0 ) ? timeout :0 ; +}See if it is possible to simplify all this with
wait_var_eventandwake_up_var.Let me check on that.
Quoted 55 lines
Quoted 55 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +20
-4+ +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) +{ +bool interruptible = true; + +if (unlikely (timeout <0 )) + timeout = -timeout, interruptible = false; + +return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); +} +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -279,6 +347,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {clr_context_pending_enable (ce);@@ -734,7 +803,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -754,7 +823,7 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_DEREGISTER_CONTEXT , true); }@@ -871,7 +940,9 @@ static int guc_context_pin(struct intel_context *ce, void *vaddr)static void guc_context_unpin (struct intel_context *ce) { -unpin_guc_id (ce_to_guc (ce), ce); +struct intel_guc *guc =ce_to_guc (ce); + +unpin_guc_id (guc, ce);lrc_unpin (ce); }@@ -894,7 +965,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }@@ -1437,6 +1508,15 @@ g2h_context_lookup(struct intel_guc *guc, u32 desc_idx)return ce; } +static void decr_outstanding_submission_g2h (struct intel_guc *guc)Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c g2h_context_lookup(struct intel_guc *guc, u32 desc_idx) · line 1516
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) { +smp_mb (); +if (waitqueue_active (&guc->ct.wq)) +wake_up_all (&guc->ct.wq);I keep pointing out this pattern is racy and at least needs comment why it is safe.
Quoted 2 lines
There is a comment in wake queue code header saying why this is safe. I don't think we need to repeat this here.
Yeah,
_describinghow to make itsafe_, after it starts with:* NOTE: this function is lockless and requires care, incorrect usage _will_
* lead to sporadic and non-obvious failure.
Quoted 9 lines
Then it also says:
* Also note that this 'optimization' trades a
spin_lock()for ansmp_mb(),
* which (when the lock is uncontended) are of roughly equal cost.I question the need to optimize this path since it means reader has to figure out if it is safe while a simple
wake_up_allafteratomic_dec_and_testwould have done it.Is the case of no waiters a predominant one? It at least deserves a comment explaining why the optimisation is important.
I just didn't want to add a spin_lock if there is known working code path without one and our code fits into that path. I can add a comment but I don't really think it necessary.
Matt
Quoted 84 lines
Regards,
Tvrtko
Quoted 80 lines
Matt
Quoted 77 lines
Regards,
Tvrtko
Quoted 73 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+ } +} +int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len)@@ -1472,6 +1552,8 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,lrc_destroy (&ce->ref); } +decr_outstanding_submission_g2h (guc); +return 0 ; }@@ -1520,6 +1602,7 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,spin_unlock_irqrestore (&ce->guc_state.lock, flags); } +decr_outstanding_submission_g2h (guc);intel_context_put (ce);return 0 ;drivers/gpu/drm/i915/gt/uc/intel_uc.h +5
-0@@ -81,6 +81,11 @@ uc_state_checkers(guc, guc_submission);#undef uc_state_checkers#undef __uc_state_checker +static inline int intel_uc_wait_for_idle (struct intel_uc *uc,long timeout) +{ +return intel_guc_wait_for_idle (&uc->guc, timeout); +} +#define intel_uc_ops_function (_NAME, _OPS, _TYPE, _RET) \ static inline _TYPE intel_uc_##_NAME(struct intel_uc *uc) \ { \drivers/gpu/drm/i915/i915_debugfs.c +1
-0@@ -36,6 +36,7 @@#include "gt/intel_gt_clock_utils.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "gt/intel_reset.h" #include "gt/intel_rc6.h" drivers/gpu/drm/i915/i915_gem_evict.c +1
-0@@ -27,6 +27,7 @@*/ #include "gem/i915_gem_context.h" +#include "gt/intel_gt.h" #include "gt/intel_gt_requests.h" #include "i915_drv.h" drivers/gpu/drm/i915/selftests/igt_live_test.c +1
-1@@ -5,7 +5,7 @@*/ #include "i915_drv.h" -#include "gt/intel_gt_requests.h" +#include "gt/intel_gt.h" #include "../i915_selftest.h" #include "igt_flush_test.h" drivers/gpu/drm/i915/selftests/mock_gem_device.c +0
-0@@ -51,7 +51,8 @@ void mock_device_flush(struct drm_i915_private *i915) do {
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/selftests/mock_gem_device.c void mock_device_flush(struct drm_i915_private *i915)
Quoted 8 lines
drivers/gpu/drm/i915/selftests/mock_gem_device.c +2
-1for_each_engine (engine, gt, id)mock_engine_flush (engine); - }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT )); + }while (intel_gt_retire_requests_timeout (gt,MAX_SCHEDULE_TIMEOUT , +NULL )); }static void mock_device_release (struct drm_device *dev)
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 55/97] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
Quoted 360 lines · Matthew Brost
Quoted 359 lines · Tvrtko Ursulin
Quoted 102 lines · Matthew Brost
Quoted 89 lines · Tvrtko Ursulin
Quoted 87 lines · Matthew Brost
When running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in
intel_gt_wait_for_idleto idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 18 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 7 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 91 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 + drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-1@@ -634,7 +634,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;drivers/gpu/drm/i915/gt/intel_gt.c +18
-0@@ -574,6 +574,24 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long rtimeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &rtimeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, rtimeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;drivers/gpu/drm/i915/gt/intel_gt.h +2
-0@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);drivers/gpu/drm/i915/gt/intel_gt_requests.c +1
-0@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" static bool retire_requests (struct intel_timeline *tl) {@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c void intel_engine_fini_retire(struct intel_engine_cs *engine) · line 135
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +2
-1GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout)What is 'rtimeout', I know remaining, but it can be more self-descriptive to start with.
'
remaining_timeout' it is.Quoted 8 lines
Quoted 5 lines
It feels a bit churny for what it is. How plausible would be alternatives to either change existing timeout to in/out, or measure sleep internally in this function, or just risk sleeping twice as long by passing the original timeout to uc idle as well?
Originally had it just passing in the same value, got review feedback saying I should pass in the adjusted value. Hard to make everyone happy.
Ok.
Quoted 231 lines
Quoted 155 lines
Quoted 155 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +3
-15{struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (rtimeout) + *rtimeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)drivers/gpu/drm/i915/gt/intel_gt_requests.h +3
-4@@ -10,10 +10,11 @@ struct intel_engine_cs;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);@@ -21,8 +22,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {bool enabled;void (*reset)(struct intel_guc *guc);@@ -239,6 +241,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -111,6 +111,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_init (&ct->receive_tasklet, ct_receive_tasklet_func, (unsigned long )ct); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +51
-0@@ -253,6 +253,74 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } +static int guc_submission_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +u32 g2h_len_dw, +bool loop) +{ +int err; + + err =intel_guc_send_busy_loop (guc, action, len, g2h_len_dw, loop); + +if (!err && g2h_len_dw) +atomic_inc (&guc->outstanding_submission_g2h); + +return err; +} + +static int guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout) +{ +const int state = interruptible ? +TASK_INTERRUPTIBLE :TASK_UNINTERRUPTIBLE ; +DEFINE_WAIT (wait); + +might_sleep (); +GEM_BUG_ON (timeout <0 ); + +if (!atomic_read (wait_var)) +return 0 ; + +if (!timeout) +return -ETIME ; + +for (;;) { +prepare_to_wait (&guc->ct.wq, &wait, state); + +if (!atomic_read (wait_var)) +break ; + +if (signal_pending_state (state, current)) { + timeout = -ERESTARTSYS ; +break ; + } + +if (!timeout) { + timeout = -ETIME ; +break ; + } + + timeout =io_schedule_timeout (timeout);Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 311
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+ } +finish_wait (&guc->ct.wq, &wait); + +return (timeout <0 ) ? timeout :0 ; +}See if it is possible to simplify all this with
wait_var_eventandwake_up_var.Let me check on that.
Quoted 55 lines
Quoted 55 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +20
-4+ +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) +{ +bool interruptible = true; + +if (unlikely (timeout <0 )) + timeout = -timeout, interruptible = false; + +return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); +} +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -279,6 +347,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {clr_context_pending_enable (ce);@@ -734,7 +803,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -754,7 +823,7 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_DEREGISTER_CONTEXT , true); }@@ -871,7 +940,9 @@ static int guc_context_pin(struct intel_context *ce, void *vaddr)static void guc_context_unpin (struct intel_context *ce) { -unpin_guc_id (ce_to_guc (ce), ce); +struct intel_guc *guc =ce_to_guc (ce); + +unpin_guc_id (guc, ce);lrc_unpin (ce); }@@ -894,7 +965,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }@@ -1437,6 +1508,15 @@ g2h_context_lookup(struct intel_guc *guc, u32 desc_idx)return ce; } +static void decr_outstanding_submission_g2h (struct intel_guc *guc)Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c g2h_context_lookup(struct intel_guc *guc, u32 desc_idx) · line 1516
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) { +smp_mb (); +if (waitqueue_active (&guc->ct.wq)) +wake_up_all (&guc->ct.wq);I keep pointing out this pattern is racy and at least needs comment why it is safe.
Quoted 2 lines
There is a comment in wake queue code header saying why this is safe. I don't think we need to repeat this here.
Yeah,
_describinghow to make itsafe_, after it starts with:* NOTE: this function is lockless and requires care, incorrect usage _will_
* lead to sporadic and non-obvious failure.Then it also says:
* Also note that this 'optimization' trades a
spin_lock()for ansmp_mb(),
* which (when the lock is uncontended) are of roughly equal cost.
Quoted 8 lines
Quoted 4 lines
I question the need to optimize this path since it means reader has to figure out if it is safe while a simple
wake_up_allafteratomic_dec_and_testwould have done it.Is the case of no waiters a predominant one? It at least deserves a comment explaining why the optimisation is important.
I just didn't want to add a
spin_lockif there is known working code path without one and our code fits into that path. I can add a comment but I don't really think it necessary.
Lock already exists in the wake_up_all, it is not about adding your own.
As premature optimisations are usually best avoided it is simply about how do you justify a):
+static void decr_outstanding_submission_g2h(struct intel_guc *guc) +{
+ if (atomic_dec_and_test(&guc->outstanding_submission_g2h)) {
+ smp_mb();
+ if (waitqueue_active(&guc->ct.wq))
+ wake_up_all(&guc->ct.wq);
When the easy alternative (easy to read, easy to review, easy to maintain) is b):
+static void decr_outstanding_submission_g2h(struct intel_guc *guc) +{
+ if (atomic_dec_and_test(&guc->outstanding_submission_g2h))
+ wake_up_all(&guc->ct.wq);
For me as external reader the question seems to be, I will say it again, is the case of no waiters a common one and is this a hot path to justify avoiding a function call by adding the mental complexity explained in the waitqueue_active comment? Here and in the other places in the GuC backend waitqueue_active is used.
Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 55/97] drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC
Quoted 387 lines · Tvrtko Ursulin
Quoted 360 lines · Matthew Brost
Quoted 359 lines · Tvrtko Ursulin
Quoted 102 lines · Matthew Brost
Quoted 89 lines · Tvrtko Ursulin
Quoted 87 lines · Matthew Brost
When running the GuC the GPU can't be considered idle if the GuC still has contexts pinned. As such, a call has been added in
intel_gt_wait_for_idleto idle the UC and in turn the GuC by waiting for the number of unpinned contexts to go to zero.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 18 ++++ drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 ++--- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 7 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 91 ++++++++++++++++++- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 5 + drivers/gpu/drm/i915/i915_debugfs.c | 1 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 14 files changed, 137 insertions(+), 27 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-1@@ -634,7 +634,8 @@ mmap_offset_attach(struct drm_i915_gem_object *obj, goto insert;/* Attempt to reap some mmap space from dead objects */ - err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT ); + err =intel_gt_retire_requests_timeout (&i915->gt,MAX_SCHEDULE_TIMEOUT , +NULL );if (err) goto err;drivers/gpu/drm/i915/gt/intel_gt.c +18
-0@@ -574,6 +574,24 @@ static void __intel_gt_disable(struct intel_gt *gt)GEM_BUG_ON (intel_gt_pm_is_awake (gt)); } +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) +{ +long rtimeout; + +/* If the device is asleep, we have no requests outstanding */ +if (!intel_gt_pm_is_awake (gt)) +return 0 ; + +while ((timeout =intel_gt_retire_requests_timeout (gt, timeout, + &rtimeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, rtimeout); +} +int intel_gt_init (struct intel_gt *gt) {int err;drivers/gpu/drm/i915/gt/intel_gt.h +2
-0@@ -48,6 +48,8 @@ void intel_gt_driver_release(struct intel_gt *gt);void intel_gt_driver_late_release (struct intel_gt *gt); +int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); +void intel_gt_check_and_clear_faults (struct intel_gt *gt);void intel_gt_clear_error_registers (struct intel_gt *gt,intel_engine_mask_t engine_mask);drivers/gpu/drm/i915/gt/intel_gt_requests.c +1
-0@@ -13,6 +13,7 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" #include "intel_timeline.h" +#include "uc/intel_uc.h" static bool retire_requests (struct intel_timeline *tl) {@@ -130,7 +131,8 @@ void intel_engine_fini_retire(struct intel_engine_cs *engine)Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c void intel_engine_fini_retire(struct intel_engine_cs *engine) · line 135
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +2
-1GEM_BUG_ON (engine->retire); } -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout) +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout)What is 'rtimeout', I know remaining, but it can be more self-descriptive to start with.
'
remaining_timeout' it is.Quoted 8 lines
Quoted 5 lines
It feels a bit churny for what it is. How plausible would be alternatives to either change existing timeout to in/out, or measure sleep internally in this function, or just risk sleeping twice as long by passing the original timeout to uc idle as well?
Originally had it just passing in the same value, got review feedback saying I should pass in the adjusted value. Hard to make everyone happy.
Ok.
Quoted 231 lines
Quoted 155 lines
Quoted 155 lines
drivers/gpu/drm/i915/gt/intel_gt_requests.c +3
-15{struct intel_gt_timelines *timelines = >->timelines;struct intel_timeline *tl, *tn;@@ -195,22 +197,10 @@ out_active: spin_lock(&timelines->lock);if (flush_submission (gt, timeout))/* Wait, there's more! */ active_count++; -return active_count ? timeout :0 ; -} - -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout) -{ -/* If the device is asleep, we have no requests outstanding */ -if (!intel_gt_pm_is_awake (gt)) -return 0 ; - -while ((timeout =intel_gt_retire_requests_timeout (gt, timeout)) >0 ) { -cond_resched (); -if (signal_pending (current)) -return -EINTR ; - } +if (rtimeout) + *rtimeout = timeout; -return timeout; +return active_count ? timeout :0 ; }static void retire_work_handler (struct work_struct *work)drivers/gpu/drm/i915/gt/intel_gt_requests.h +3
-4@@ -10,10 +10,11 @@ struct intel_engine_cs;struct intel_gt ;struct intel_timeline ; -long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout); +long intel_gt_retire_requests_timeout (struct intel_gt *gt,long timeout, +long *rtimeout);static inline void intel_gt_retire_requests (struct intel_gt *gt) { -intel_gt_retire_requests_timeout (gt,0 ); +intel_gt_retire_requests_timeout (gt,0 ,NULL ); }void intel_engine_init_retire (struct intel_engine_cs *engine);@@ -21,8 +22,6 @@ void intel_engine_add_retire(struct intel_engine_cs *engine, struct intel_timeline *tl);void intel_engine_fini_retire (struct intel_engine_cs *engine); -int intel_gt_wait_for_idle (struct intel_gt *gt,long timeout); -void intel_gt_init_requests (struct intel_gt *gt);void intel_gt_park_requests (struct intel_gt *gt);void intel_gt_unpark_requests (struct intel_gt *gt);drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0@@ -38,6 +38,8 @@ struct intel_guc {spinlock_t irq_lock;unsigned int msg_enabled_mask; +atomic_t outstanding_submission_g2h; +struct {bool enabled;void (*reset)(struct intel_guc *guc);@@ -239,6 +241,8 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)spin_unlock_irq (&guc->irq_lock); } +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); +int intel_guc_reset_engine (struct intel_guc *guc,struct intel_engine_cs *engine);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -111,6 +111,7 @@ void intel_guc_ct_init_early(struct intel_guc_ct *ct)INIT_LIST_HEAD (&ct->requests.incoming);INIT_WORK (&ct->requests.worker, ct_incoming_request_worker_func);tasklet_init (&ct->receive_tasklet, ct_receive_tasklet_func, (unsigned long )ct); +init_waitqueue_head (&ct->wq); }static inline const char *guc_ct_buffer_type_to_str (u32 type)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -10,6 +10,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/ktime.h> +#include <linux/wait.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct tasklet_struct receive_tasklet; +/** @wq: wait queue for g2h chanenl */ +wait_queue_head_t wq; +struct {u16 last_fence;/* last fence used to send request */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +51
-0@@ -253,6 +253,74 @@ static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); } +static int guc_submission_busy_loop (struct intel_guc * guc, +const u32 *action, +u32 len, +u32 g2h_len_dw, +bool loop) +{ +int err; + + err =intel_guc_send_busy_loop (guc, action, len, g2h_len_dw, loop); + +if (!err && g2h_len_dw) +atomic_inc (&guc->outstanding_submission_g2h); + +return err; +} + +static int guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout) +{ +const int state = interruptible ? +TASK_INTERRUPTIBLE :TASK_UNINTERRUPTIBLE ; +DEFINE_WAIT (wait); + +might_sleep (); +GEM_BUG_ON (timeout <0 ); + +if (!atomic_read (wait_var)) +return 0 ; + +if (!timeout) +return -ETIME ; + +for (;;) { +prepare_to_wait (&guc->ct.wq, &wait, state); + +if (!atomic_read (wait_var)) +break ; + +if (signal_pending_state (state, current)) { + timeout = -ERESTARTSYS ; +break ; + } + +if (!timeout) { + timeout = -ETIME ; +break ; + } + + timeout =io_schedule_timeout (timeout);Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id, · line 311
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+ } +finish_wait (&guc->ct.wq, &wait); + +return (timeout <0 ) ? timeout :0 ; +}See if it is possible to simplify all this with
wait_var_eventandwake_up_var.Let me check on that.
Quoted 55 lines
Quoted 55 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +20
-4+ +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) +{ +bool interruptible = true; + +if (unlikely (timeout <0 )) + timeout = -timeout, interruptible = false; + +return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); +} +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -279,6 +347,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {clr_context_pending_enable (ce);@@ -734,7 +803,7 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }static int register_context (struct intel_context *ce)@@ -754,7 +823,7 @@ static int __guc_action_deregister_context(struct intel_guc *guc, guc_id, }; -return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_DEREGISTER_CONTEXT , true); }@@ -871,7 +940,9 @@ static int guc_context_pin(struct intel_context *ce, void *vaddr)static void guc_context_unpin (struct intel_context *ce) { -unpin_guc_id (ce_to_guc (ce), ce); +struct intel_guc *guc =ce_to_guc (ce); + +unpin_guc_id (guc, ce);lrc_unpin (ce); }@@ -894,7 +965,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,intel_context_get (ce); -intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action), +guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true); }@@ -1437,6 +1508,15 @@ g2h_context_lookup(struct intel_guc *guc, u32 desc_idx)return ce; } +static void decr_outstanding_submission_g2h (struct intel_guc *guc)Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c g2h_context_lookup(struct intel_guc *guc, u32 desc_idx) · line 1516
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) { +smp_mb (); +if (waitqueue_active (&guc->ct.wq)) +wake_up_all (&guc->ct.wq);I keep pointing out this pattern is racy and at least needs comment why it is safe.
Quoted 2 lines
There is a comment in wake queue code header saying why this is safe. I don't think we need to repeat this here.
Yeah,
_describinghow to make itsafe_, after it starts with:* NOTE: this function is lockless and requires care, incorrect usage _will_
* lead to sporadic and non-obvious failure.Then it also says:
* Also note that this 'optimization' trades a
spin_lock()for ansmp_mb(),
* which (when the lock is uncontended) are of roughly equal cost.Quoted 8 lines
Quoted 4 lines
I question the need to optimize this path since it means reader has to figure out if it is safe while a simple
wake_up_allafteratomic_dec_and_testwould have done it.Is the case of no waiters a predominant one? It at least deserves a comment explaining why the optimisation is important.
I just didn't want to add a
spin_lockif there is known working code path without one and our code fits into that path. I can add a comment but I don't really think it necessary.Lock already exists in the
wake_up_all, it is not about adding your own.As premature optimisations are usually best avoided it is simply about how do you justify a):
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+static void decr_outstanding_submission_g2h (struct intel_guc *guc) +{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) { +smp_mb (); +if (waitqueue_active (&guc->ct.wq)) +wake_up_all (&guc->ct.wq);When the easy alternative (easy to read, easy to review, easy to maintain) is b):
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c g2h_context_lookup(struct intel_guc *guc, u32 desc_idx) · line 1516
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +4
-0+static void decr_outstanding_submission_g2h (struct intel_guc *guc) +{ +if (atomic_dec_and_test (&guc->outstanding_submission_g2h)) +wake_up_all (&guc->ct.wq);
I'll go with option B.
Matt
Quoted 9 lines
For me as external reader the question seems to be, I will say it again, is the case of no waiters a common one and is this a hot path to justify avoiding a function call by adding the mental complexity explained in the
waitqueue_activecomment? Here and in the other places in the GuC backendwaitqueue_activeis used.Regards,
Tvrtko
RFC PATCH 56/97 drm/i915/guc: Update GuC debugfs to support new GuC
In reply to Matthew BrostUpdate GuC debugfs to support the new GuC structures.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 22 ++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 ++ .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 23 +++++++- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 52 +++++++++++++++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.h | 4 ++ drivers/gpu/drm/i915/i915_debugfs.c | 1 + 6 files changed, 104 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +22 -0
@@ -1131,3 +1131,25 @@ void intel_guc_ct_event_handler(struct intel_guc_ct *ct)ct_try_receive_message (ct); } + +void intel_guc_log_ct_info (struct intel_guc_ct *ct, +struct drm_printer *p) +{ +if (!ct->enabled) { +drm_puts (p,"CT disabled\n" ); +return ; + } + +drm_printf (p,"H2G Space: %u\n" , +atomic_read (&ct->ctbs.send.space) *4 ); +drm_printf (p,"Head: %u\n" , + ct->ctbs.send.desc->head); +drm_printf (p,"Tail: %u\n" , + ct->ctbs.send.desc->tail); +drm_printf (p,"G2H Space: %u\n" , +atomic_read (&ct->ctbs.recv.space) *4 ); +drm_printf (p,"Head: %u\n" , + ct->ctbs.recv.desc->head); +drm_printf (p,"Tail: %u\n" , + ct->ctbs.recv.desc->tail); +}
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3 -0
@@ -16,6 +16,7 @@struct i915_vma ;struct intel_guc ; +struct drm_printer ;/** * DOC: Command Transport (CT).
@@ -106,4 +107,6 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size, u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct); +void intel_guc_log_ct_info (struct intel_guc_ct *ct,struct drm_printer *p); +#endif /* _INTEL_GUC_CT_H_ */
drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +22 -1
@@ -9,6 +9,8 @@#include "intel_guc.h" #include "intel_guc_debugfs.h" #include "intel_guc_log_debugfs.h" +#include "gt/uc/intel_guc_ct.h" +#include "gt/uc/intel_guc_submission.h" static int guc_info_show (struct seq_file *m,void *data) {
@@ -22,16 +24,35 @@ static int guc_info_show(struct seq_file *m, void *data)drm_puts (&p,"\n" );intel_guc_log_info (&guc->log, &p); -/* Add more as required ... */ +if (!intel_guc_submission_is_used (guc)) +return 0 ; + +intel_guc_log_ct_info (&guc->ct, &p); +intel_guc_log_submission_info (guc, &p);return 0 ; }DEFINE_GT_DEBUGFS_ATTRIBUTE (guc_info); +static int guc_registered_contexts_show (struct seq_file *m,void *data) +{ +struct intel_guc *guc = m->private; +struct drm_printer p =drm_seq_file_printer (m); + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + +intel_guc_log_context_info (guc, &p); + +return 0 ; +} +DEFINE_GT_DEBUGFS_ATTRIBUTE (guc_registered_contexts); +void intel_guc_debugfs_register (struct intel_guc *guc,struct dentry *root) {static const struct debugfs_gt_file files[] = { {"guc_info" , &guc_info_fops,NULL }, + {"guc_registered_contexts" , &guc_registered_contexts_fops,NULL }, };if (!intel_guc_is_supported (guc))
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +52 -0
55 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +4 -0
@@ -10,6 +10,7 @@#include "intel_guc.h" +struct drm_printer ;struct intel_engine_cs ;void intel_guc_submission_init_early (struct intel_guc *guc);
@@ -20,6 +21,9 @@ void intel_guc_submission_fini(struct intel_guc *guc);int intel_guc_preempt_work_create (struct intel_guc *guc);void intel_guc_preempt_work_destroy (struct intel_guc *guc);int intel_guc_submission_setup (struct intel_engine_cs *engine); +void intel_guc_log_submission_info (struct intel_guc *guc, +struct drm_printer *p); +void intel_guc_log_context_info (struct intel_guc *guc,struct drm_printer *p);static inline bool intel_guc_submission_is_supported (struct intel_guc *guc) {
drivers/gpu/drm/i915/i915_debugfs.c +1 -0
@@ -50,6 +50,7 @@#include "i915_trace.h" #include "intel_pm.h" #include "intel_sideband.h" +#include "gt/intel_lrc_reg.h" static inline struct drm_i915_private *node_to_i915 (struct drm_info_node *node) {
Signature · 1 line
2.28.0
RFC PATCH 57/97 drm/i915/guc: Add several request trace points
In reply to Matthew BrostAdd trace points for request dependencies and GuC submit. Extended existing request trace points to include submit fence value,, guc_id, and ring tail value.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 3 ++ drivers/gpu/drm/i915/i915_request.c | 3 ++ drivers/gpu/drm/i915/i915_trace.h | 39 ++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3 -0
@@ -421,6 +421,7 @@ static int guc_dequeue_one_context(struct intel_guc *guc) guc->stalled_request = last;return false; } +trace_i915_request_guc_submit (last); } guc->stalled_request =NULL ;
@@ -645,6 +646,8 @@ static int guc_bypass_tasklet_submit(struct intel_guc *guc, ret =guc_add_request (guc, rq);if (ret == -EBUSY ) guc->stalled_request = rq; +else +trace_i915_request_guc_submit (rq);return ret; }
drivers/gpu/drm/i915/i915_request.c +3 -0
@@ -1344,6 +1344,9 @@ __i915_request_await_execution(struct i915_request *to,return err; } +trace_i915_request_dep_to (to); +trace_i915_request_dep_from (from); +/* Couple the dependency tree for PI on this exposed to->fence */ if (to->engine->sched_engine->schedule) { err = i915_sched_node_add_dependency(&to->sched,
drivers/gpu/drm/i915/i915_trace.h +37 -2
@@ -794,22 +794,27 @@ DECLARE_EVENT_CLASS(i915_request,TP_STRUCT__entry (__field (u32 ,dev )__field (u64, ctx) +__field (u32, guc_id)__field (u16, class)__field (u16, instance)__field (u32, seqno) +__field (u32, tail) ),TP_fast_assign ( __entry->dev = rq->engine->i915->drm.primary->index; __entry->class = rq->engine->uabi_class; __entry->instance = rq->engine->uabi_instance; + __entry->guc_id = rq->context->guc_id; __entry->ctx = rq->fence.context; __entry->seqno = rq->fence.seqno; + __entry->tail = rq->tail; ), -TP_printk ("dev=%u, engine=%u:%u, ctx=%llu, seqno=%u" , +TP_printk ("dev=%u, engine=%u:%u, guc_id=%u, ctx=%llu, seqno=%u, tail=%u" , __entry->dev, __entry->class, __entry->instance, - __entry->ctx, __entry->seqno) + __entry->guc_id, __entry->ctx, __entry->seqno, + __entry->tail) ); DEFINE_EVENT(i915_request, i915_request_add,
@@ -818,6 +823,21 @@ DEFINE_EVENT(i915_request, i915_request_add, );#if defined(CONFIG_DRM_I915_LOW_LEVEL_TRACEPOINTS ) +DEFINE_EVENT (i915_request, i915_request_dep_to, + TP_PROTO(struct i915_request *rq), +TP_ARGS (rq) +); + +DEFINE_EVENT (i915_request, i915_request_dep_from, + TP_PROTO(struct i915_request *rq), +TP_ARGS (rq) +); + +DEFINE_EVENT (i915_request, i915_request_guc_submit, + TP_PROTO(struct i915_request *rq), +TP_ARGS (rq) +); +DEFINE_EVENT (i915_request, i915_request_submit, TP_PROTO(struct i915_request *rq), TP_ARGS(rq)
@@ -887,6 +907,21 @@ TRACE_EVENT(i915_request_out, #else #if !defined(TRACE_HEADER_MULTI_READ) +static inline void +trace_i915_request_dep_to(struct i915_request *rq) +{ +} + +static inline void +trace_i915_request_dep_from(struct i915_request *rq) +{ +} + +static inline void +trace_i915_request_guc_submit(struct i915_request *rq) +{ +} + static inline void trace_i915_request_submit(struct i915_request *rq) {
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 58/97 drm/i915: Add intel_context tracing
In reply to Matthew BrostAdd intel_context tracing. These trace points are particular helpful when debugging the GuC firmware and can be enabled via CONFIG_DRM_I915_LOW_LEVEL_TRACEPOINTS kernel config option.
--- drivers/gpu/drm/i915/gt/intel_context.c | 6 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 14 ++ drivers/gpu/drm/i915/i915_trace.h | 148 +++++++++++++++++- 3 files changed, 166 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +6 -0
@@ -8,6 +8,7 @@#include "i915_drv.h" #include "i915_globals.h" +#include "i915_trace.h" #include "intel_context.h" #include "intel_engine.h"
@@ -28,6 +29,7 @@ static void rcu_context_free(struct rcu_head *rcu) {struct intel_context *ce =container_of (rcu,typeof (*ce), rcu); +trace_intel_context_free (ce);kmem_cache_free (global.slab_ce, ce); }
@@ -46,6 +48,7 @@ intel_context_create(struct intel_engine_cs *engine)return ERR_PTR (-ENOMEM );intel_context_init (ce, engine); +trace_intel_context_create (ce);return ce; }
@@ -268,6 +271,8 @@ int __intel_context_do_pin_ww(struct intel_context *ce,GEM_BUG_ON (!intel_context_is_pinned (ce));/* no overflow! */ +trace_intel_context_do_pin (ce); + err_unlock:mutex_unlock (&ce->pin_mutex); err_post_unpin:
@@ -323,6 +328,7 @@ void __intel_context_do_unpin(struct intel_context *ce, int sub)*/ intel_context_get (ce);intel_context_active_release (ce); +trace_intel_context_do_unpin (ce);intel_context_put (ce); }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +14 -0
@@ -347,6 +347,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq) err =intel_guc_send_nb (guc, action, len, g2h_len_dw);if (!enabled && !err) { +trace_intel_context_sched_enable (ce);atomic_inc (&guc->outstanding_submission_g2h);set_context_enabled (ce); }else if (!enabled) {
@@ -815,6 +816,8 @@ static int register_context(struct intel_context *ce)u32 offset =intel_guc_ggtt_offset (guc, guc->lrc_desc_pool) + ce->guc_id *sizeof (struct guc_lrc_desc ); +trace_intel_context_register (ce); +return __guc_action_register_context (guc, ce->guc_id, offset); }
@@ -834,6 +837,8 @@ static int deregister_context(struct intel_context *ce, u32 guc_id) {struct intel_guc *guc =ce_to_guc (ce); +trace_intel_context_deregister (ce); +return __guc_action_deregister_context (guc, guc_id); }
@@ -908,6 +913,7 @@ static int guc_lrc_desc_pin(struct intel_context *ce)* GuC before registering this context. */ if (context_registered) { +trace_intel_context_steal_guc_id (ce);set_context_wait_for_deregister_to_register (ce);intel_context_get (ce);
@@ -966,6 +972,7 @@ static void __guc_context_sched_disable(struct intel_guc *guc,GEM_BUG_ON (guc_id ==GUC_INVALID_LRC_ID ); +trace_intel_context_sched_disable (ce);intel_context_get (ce); guc_submission_busy_loop(guc, action, ARRAY_SIZE(action),
@@ -1122,6 +1129,9 @@ static void __guc_signal_context_fence(struct intel_context *ce)lockdep_assert_held (&ce->guc_state.lock); +if (!list_empty (&ce->guc_state.fences)) +trace_intel_context_fence_release (ce); +list_for_each_entry (rq, &ce->guc_state.fences, guc_fence_link)i915_sw_fence_complete (&rq->submit);
@@ -1536,6 +1546,8 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,if (unlikely (!ce))return -EPROTO ; +trace_intel_context_deregister_done (ce); +if (context_wait_for_deregister_to_register (ce)) {struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;
@@ -1587,6 +1599,8 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,return -EPROTO ; } +trace_intel_context_sched_done (ce); +if (context_pending_enable (ce)) {clr_context_pending_enable (ce); }else if (context_pending_disable (ce)) {
drivers/gpu/drm/i915/i915_trace.h +146 -2
166 lines not on this page · raw message
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 59/97 drm/i915/guc: GuC virtual engines
In reply to Matthew BrostImplement GuC virtual engines. Rather simple implementation, basically just allocate an engine, setup context enter / exit function to virtual engine specific functions, set all other variables / functions to guc versions, and set the engine mask to that of all the siblings.
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 19 +- drivers/gpu/drm/i915/gem/i915_gem_context.h | 1 + drivers/gpu/drm/i915/gt/intel_context_types.h | 10 + drivers/gpu/drm/i915/gt/intel_engine.h | 45 +++- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 14 + .../drm/i915/gt/intel_execlists_submission.c | 186 +++++++------ .../drm/i915/gt/intel_execlists_submission.h | 11 - drivers/gpu/drm/i915/gt/selftest_execlists.c | 20 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 253 +++++++++++++++++- .../gpu/drm/i915/gt/uc/intel_guc_submission.h | 2 + 10 files changed, 429 insertions(+), 132 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +5 -14
@@ -72,7 +72,6 @@#include "gt/intel_context_param.h" #include "gt/intel_engine_heartbeat.h" #include "gt/intel_engine_user.h" -#include "gt/intel_execlists_submission.h" /* virtual_engine */ #include "gt/intel_gpu_commands.h" #include "gt/intel_ring.h"
@@ -1569,9 +1568,6 @@ set_engines__load_balance(struct i915_user_extension __user *base, void *data)if (!HAS_EXECLISTS (i915))return -ENODEV ; -if (intel_uc_uses_guc_submission (&i915->gt.uc)) -return -ENODEV ;/* not implement yet */ -if (get_user (idx, &ext->engine_index))return -EFAULT ;
@@ -1628,7 +1624,7 @@ set_engines__load_balance(struct i915_user_extension __user *base, void *data) } } - ce =intel_execlists_create_virtual (siblings, n); + ce =intel_engine_create_virtual (siblings, n);if (IS_ERR (ce)) { err =PTR_ERR (ce); goto out_siblings;
@@ -1724,13 +1720,9 @@ set_engines__bond(struct i915_user_extension __user *base, void *data)* 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; - } + err =intel_engine_attach_bond (virtual, master, bond); +if (err) +return err; }return 0 ;
@@ -2117,8 +2109,7 @@ static int clone_engines(struct i915_gem_context *dst,* the virtual engine instead. */ if (intel_engine_is_virtual (engine)) - clone->engines[n] = -intel_execlists_clone_virtual (engine); + clone->engines[n] =intel_engine_clone_virtual (engine);else clone->engines[n] =intel_context_create (engine);if (IS_ERR_OR_NULL (clone->engines[n])) {
drivers/gpu/drm/i915/gem/i915_gem_context.h +1 -0
@@ -10,6 +10,7 @@#include "i915_gem_context_types.h" #include "gt/intel_context.h" +#include "gt/intel_engine.h" #include "i915_drv.h" #include "i915_gem.h"
drivers/gpu/drm/i915/gt/intel_context_types.h +10 -0
@@ -47,6 +47,16 @@ struct intel_context_ops {void (*reset)(struct intel_context *ce);void (*destroy)(struct kref *kref); + +/* virtual engine/context interface */ +struct intel_context *(*create_virtual)(struct intel_engine_cs **engine, +unsigned int count); +struct intel_context *(*clone_virtual)(struct intel_engine_cs *engine); +struct intel_engine_cs *(*get_sibling)(struct intel_engine_cs *engine, +unsigned int sibling); +int (*attach_bond)(struct intel_engine_cs *engine, +const struct intel_engine_cs *master, +const struct intel_engine_cs *sibling); };struct intel_context {
drivers/gpu/drm/i915/gt/intel_engine.h +44 -1
57 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_engine_cs.c +14 -0
@@ -1792,6 +1792,20 @@ ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine, ktime_t *now)return total; } +struct intel_context * +intel_engine_create_virtual (struct intel_engine_cs **siblings, +unsigned int count) +{ +if (count ==0 ) +return ERR_PTR (-EINVAL ); + +if (count ==1 ) +return intel_context_create (siblings[0 ]); + +GEM_BUG_ON (!siblings[0 ]->cops->create_virtual); +return siblings[0 ]->cops->create_virtual (siblings, count); +} +static bool match_ring (struct i915_request *rq) {u32 ring =ENGINE_READ (rq->engine,RING_START );
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +99 -87
233 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_execlists_submission.h +0 -11
@@ -32,15 +32,4 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine, int indent), unsigned int max); -struct intel_context * -intel_execlists_create_virtual (struct intel_engine_cs **siblings, -unsigned int count); - -struct intel_context * -intel_execlists_clone_virtual (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_EXECLISTS_SUBMISSION_H__ */
drivers/gpu/drm/i915/gt/selftest_execlists.c +10 -10
@@ -3710,7 +3710,7 @@ static int nop_virtual_engine(struct intel_gt *gt,GEM_BUG_ON (!nctx || nctx >ARRAY_SIZE (ve));for (n =0 ; n < nctx; n++) { - ve[n] =intel_execlists_create_virtual (siblings, nsibling); + ve[n] =intel_engine_create_virtual (siblings, nsibling);if (IS_ERR (ve[n])) { err =PTR_ERR (ve[n]); nctx = n;
@@ -3906,7 +3906,7 @@ static int mask_virtual_engine(struct intel_gt *gt,* restrict it to our desired engine within the virtual engine. */ - ve =intel_execlists_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (siblings, nsibling);if (IS_ERR (ve)) { err =PTR_ERR (ve); goto out_close;
@@ -4037,7 +4037,7 @@ static int slicein_virtual_engine(struct intel_gt *gt,i915_request_add (rq); } - ce =intel_execlists_create_virtual (siblings, nsibling); + ce =intel_engine_create_virtual (siblings, nsibling);if (IS_ERR (ce)) { err =PTR_ERR (ce); goto out;
@@ -4089,7 +4089,7 @@ static int sliceout_virtual_engine(struct intel_gt *gt,/* XXX We do not handle oversubscription and fairness with normal rq */ for (n =0 ; n < nsibling; n++) { - ce =intel_execlists_create_virtual (siblings, nsibling); + ce =intel_engine_create_virtual (siblings, nsibling);if (IS_ERR (ce)) { err =PTR_ERR (ce); goto out;
@@ -4191,7 +4191,7 @@ static int preserved_virtual_engine(struct intel_gt *gt,if (err) goto out_scratch; - ve =intel_execlists_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (siblings, nsibling);if (IS_ERR (ve)) { err =PTR_ERR (ve); goto out_scratch;
@@ -4414,16 +4414,16 @@ static int bond_virtual_engine(struct intel_gt *gt,for (n =0 ; n < nsibling; n++) {struct intel_context *ve; - ve =intel_execlists_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (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]); + err =intel_engine_attach_bond (ve->engine, + master, + siblings[n]);if (err) {intel_context_put (ve);onstack_fence_fini (&fence);
@@ -4559,7 +4559,7 @@ static int reset_virtual_engine(struct intel_gt *gt,if (igt_spinner_init (&spin, gt))return -ENOMEM ; - ve =intel_execlists_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (siblings, nsibling);if (IS_ERR (ve)) { err =PTR_ERR (ve); goto out_spin;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +244 -9
312 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +2 -0
@@ -25,6 +25,8 @@ void intel_guc_log_submission_info(struct intel_guc *guc, struct drm_printer *p);void intel_guc_log_context_info (struct intel_guc *guc,struct drm_printer *p); +bool intel_guc_virtual_engine_has_heartbeat (const struct intel_engine_cs *ve); +static inline bool intel_guc_submission_is_supported (struct intel_guc *guc) {/* XXX: GuC submission is unavailable for now */
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 60/97 drm/i915: Track 'serial' counts for virtual engines
In reply to Matthew BrostFrom: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++ .../gpu/drm/i915/gt/intel_execlists_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/intel_ring_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/mock_engine.c | 6 ++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 16 ++++++++++++++++ drivers/gpu/drm/i915/i915_request.c | 4 +++- 6 files changed, 39 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/intel_engine_types.h +2 -0
@@ -389,6 +389,8 @@ struct intel_engine_cs {void (*park)(struct intel_engine_cs *engine);void (*unpark)(struct intel_engine_cs *engine); +void (*bump_serial)(struct intel_engine_cs *engine); +void (*set_default_submission)(struct intel_engine_cs *engine);const struct intel_context_ops *cops;
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +6 -0
@@ -3199,6 +3199,11 @@ static void execlists_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void execlist_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void logical_ring_default_vfuncs (struct intel_engine_cs *engine) {
@@ -3208,6 +3213,7 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; + engine->bump_serial = execlist_bump_serial; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;
drivers/gpu/drm/i915/gt/intel_ring_submission.c +6 -0
@@ -1045,6 +1045,11 @@ static void setup_irq(struct intel_engine_cs *engine) } } +static void ring_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void setup_common (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;
@@ -1064,6 +1069,7 @@ static void setup_common(struct intel_engine_cs *engine) engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; + engine->bump_serial = ring_bump_serial;/* * Using a global execution timeline; the previous final breadcrumb is
drivers/gpu/drm/i915/gt/mock_engine.c +6 -0
@@ -292,6 +292,11 @@ static void mock_engine_release(struct intel_engine_cs *engine)intel_engine_fini_retire (engine); } +static void mock_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +struct intel_engine_cs *mock_engine (struct drm_i915_private *i915,const char *name,int id)
@@ -318,6 +323,7 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, engine->base.cops = &mock_context_ops; engine->base.request_alloc = mock_request_alloc; + engine->base.bump_serial = mock_bump_serial; engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16 -0
@@ -1500,6 +1500,20 @@ static void guc_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void guc_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + +static void virtual_guc_bump_serial (struct intel_engine_cs *engine) +{ +struct intel_engine_cs *e; +intel_engine_mask_t tmp, mask = engine->mask; + +for_each_engine_masked (e, engine->gt, mask, tmp) + e->serial++; +} +static void guc_default_vfuncs (struct intel_engine_cs *engine) {/* Default vfuncs which can be overridden by each engine. */
@@ -1508,6 +1522,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; + engine->bump_serial = guc_bump_serial; engine->sched_engine->schedule = i915_schedule;
@@ -1843,6 +1858,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.cops = &virtual_guc_context_ops; ve->base.request_alloc = guc_request_alloc; + ve->base.bump_serial = virtual_guc_bump_serial; ve->base.submit_request = guc_submit_request;
drivers/gpu/drm/i915/i915_request.c +3 -1
@@ -692,7 +692,9 @@ bool __i915_request_submit(struct i915_request *request) request->ring->vaddr + request->postfix);trace_i915_request_execute (request); - engine->serial++; +if (engine->bump_serial) + engine->bump_serial (engine); + result = true;GEM_BUG_ON (test_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags));
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
Quoted 11 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
Quoted 5 lines
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Commit text sounds a bit defeatist. I think instead of making up the serial counts, which has downsides (could you please document in the commit what they are), we should think how to design things properly.
Regards,
Tvrtko
Quoted 143 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++ .../gpu/drm/i915/gt/intel_execlists_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/intel_ring_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/mock_engine.c | 6 ++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 16 ++++++++++++++++ drivers/gpu/drm/i915/i915_request.c | 4 +++- 6 files changed, 39 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_engine_types.h +2
-0@@ -389,6 +389,8 @@ struct intel_engine_cs {void (*park)(struct intel_engine_cs *engine);void (*unpark)(struct intel_engine_cs *engine); +void (*bump_serial)(struct intel_engine_cs *engine); +void (*set_default_submission)(struct intel_engine_cs *engine);const struct intel_context_ops *cops;drivers/gpu/drm/i915/gt/intel_execlists_submission.c +6
-0@@ -3199,6 +3199,11 @@ static void execlists_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void execlist_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void logical_ring_default_vfuncs (struct intel_engine_cs *engine) {@@ -3208,6 +3213,7 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; + engine->bump_serial = execlist_bump_serial; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;drivers/gpu/drm/i915/gt/intel_ring_submission.c +6
-0@@ -1045,6 +1045,11 @@ static void setup_irq(struct intel_engine_cs *engine) } } +static void ring_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void setup_common (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;@@ -1064,6 +1069,7 @@ static void setup_common(struct intel_engine_cs *engine) engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; + engine->bump_serial = ring_bump_serial;/* * Using a global execution timeline; the previous final breadcrumb is drivers/gpu/drm/i915/gt/mock_engine.c +6
-0@@ -292,6 +292,11 @@ static void mock_engine_release(struct intel_engine_cs *engine)intel_engine_fini_retire (engine); } +static void mock_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +struct intel_engine_cs *mock_engine (struct drm_i915_private *i915,const char *name,int id)@@ -318,6 +323,7 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, engine->base.cops = &mock_context_ops; engine->base.request_alloc = mock_request_alloc; + engine->base.bump_serial = mock_bump_serial; engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16
-0@@ -1500,6 +1500,20 @@ static void guc_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void guc_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + +static void virtual_guc_bump_serial (struct intel_engine_cs *engine) +{ +struct intel_engine_cs *e; +intel_engine_mask_t tmp, mask = engine->mask; + +for_each_engine_masked (e, engine->gt, mask, tmp) + e->serial++; +} +static void guc_default_vfuncs (struct intel_engine_cs *engine) {/* Default vfuncs which can be overridden by each engine. */ @@ -1508,6 +1522,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; + engine->bump_serial = guc_bump_serial; engine->sched_engine->schedule = i915_schedule;@@ -1843,6 +1858,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.cops = &virtual_guc_context_ops; ve->base.request_alloc = guc_request_alloc; + ve->base.bump_serial = virtual_guc_bump_serial; ve->base.submit_request = guc_submit_request;drivers/gpu/drm/i915/i915_request.c +0
-0
drivers/gpu/drm/i915/i915_request.c bool __i915_request_submit(struct i915_request *request) · line 700
Quoted 10 lines
drivers/gpu/drm/i915/i915_request.c +3
-1@@ -692,7 +692,9 @@ bool __i915_request_submit(struct i915_request *request) request->ring->vaddr + request->postfix);trace_i915_request_execute (request); - engine->serial++; +if (engine->bump_serial) + engine->bump_serial (engine); + result = true;GEM_BUG_ON (test_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags));
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
Quoted 19 lines · Tvrtko Ursulin
Quoted 11 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
Quoted 5 lines
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Quoted 4 lines
Commit text sounds a bit defeatist. I think instead of making up the serial counts, which has downsides (could you please document in the commit what they are), we should think how to design things properly.
IMO, I don't think fixing serial counts is the scope of this series. We should focus on getting GuC submission in not cleaning up all the crap that is in the i915. Let's make a note of this though so we can revisit later.
Matt
Quoted 138 lines
Regards,
Tvrtko
Quoted 134 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++ .../gpu/drm/i915/gt/intel_execlists_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/intel_ring_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/mock_engine.c | 6 ++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 16 ++++++++++++++++ drivers/gpu/drm/i915/i915_request.c | 4 +++- 6 files changed, 39 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_engine_types.h +2
-0@@ -389,6 +389,8 @@ struct intel_engine_cs {void (*park)(struct intel_engine_cs *engine);void (*unpark)(struct intel_engine_cs *engine); +void (*bump_serial)(struct intel_engine_cs *engine); +void (*set_default_submission)(struct intel_engine_cs *engine);const struct intel_context_ops *cops;drivers/gpu/drm/i915/gt/intel_execlists_submission.c +6
-0@@ -3199,6 +3199,11 @@ static void execlists_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void execlist_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void logical_ring_default_vfuncs (struct intel_engine_cs *engine) {@@ -3208,6 +3213,7 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; + engine->bump_serial = execlist_bump_serial; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;drivers/gpu/drm/i915/gt/intel_ring_submission.c +6
-0@@ -1045,6 +1045,11 @@ static void setup_irq(struct intel_engine_cs *engine) } } +static void ring_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void setup_common (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;@@ -1064,6 +1069,7 @@ static void setup_common(struct intel_engine_cs *engine) engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; + engine->bump_serial = ring_bump_serial;/* * Using a global execution timeline; the previous final breadcrumb is drivers/gpu/drm/i915/gt/mock_engine.c +6
-0@@ -292,6 +292,11 @@ static void mock_engine_release(struct intel_engine_cs *engine)intel_engine_fini_retire (engine); } +static void mock_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +struct intel_engine_cs *mock_engine (struct drm_i915_private *i915,const char *name,int id)@@ -318,6 +323,7 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, engine->base.cops = &mock_context_ops; engine->base.request_alloc = mock_request_alloc; + engine->base.bump_serial = mock_bump_serial; engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16
-0@@ -1500,6 +1500,20 @@ static void guc_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void guc_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + +static void virtual_guc_bump_serial (struct intel_engine_cs *engine) +{ +struct intel_engine_cs *e; +intel_engine_mask_t tmp, mask = engine->mask; + +for_each_engine_masked (e, engine->gt, mask, tmp) + e->serial++; +} +static void guc_default_vfuncs (struct intel_engine_cs *engine) {/* Default vfuncs which can be overridden by each engine. */ @@ -1508,6 +1522,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; + engine->bump_serial = guc_bump_serial; engine->sched_engine->schedule = i915_schedule;@@ -1843,6 +1858,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.cops = &virtual_guc_context_ops; ve->base.request_alloc = guc_request_alloc; + ve->base.bump_serial = virtual_guc_bump_serial; ve->base.submit_request = guc_submit_request;drivers/gpu/drm/i915/i915_request.c +3
-1@@ -692,7 +692,9 @@ bool __i915_request_submit(struct i915_request *request) request->ring->vaddr + request->postfix);trace_i915_request_execute (request); - engine->serial++; +if (engine->bump_serial) + engine->bump_serial (engine); + result = true;GEM_BUG_ON (test_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags));
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
Quoted 25 lines · Matthew Brost
Quoted 19 lines · Tvrtko Ursulin
Quoted 11 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
Quoted 5 lines
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Quoted 4 lines
Commit text sounds a bit defeatist. I think instead of making up the serial counts, which has downsides (could you please document in the commit what they are), we should think how to design things properly.
Quoted 4 lines
IMO, I don't think fixing serial counts is the scope of this series. We should focus on getting GuC submission in not cleaning up all the crap that is in the i915. Let's make a note of this though so we can revisit later.
I will say again - commit message implies it is introducing an unspecified downside by not fully fixing an also unspecified issue. It is completely reasonable, and customary even, to ask for both to be documented in the commit message.
If we are abandoning the normal review process someone please say so I don't waste my time reading it.
Regards,
Tvrtko
Quoted 132 lines
Matt
Quoted 130 lines
Regards,
Tvrtko
Quoted 126 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++ .../gpu/drm/i915/gt/intel_execlists_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/intel_ring_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/mock_engine.c | 6 ++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 16 ++++++++++++++++ drivers/gpu/drm/i915/i915_request.c | 4 +++- 6 files changed, 39 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_engine_types.h +2
-0@@ -389,6 +389,8 @@ struct intel_engine_cs {void (*park)(struct intel_engine_cs *engine);void (*unpark)(struct intel_engine_cs *engine); +void (*bump_serial)(struct intel_engine_cs *engine); +void (*set_default_submission)(struct intel_engine_cs *engine);const struct intel_context_ops *cops;drivers/gpu/drm/i915/gt/intel_execlists_submission.c +6
-0@@ -3199,6 +3199,11 @@ static void execlists_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void execlist_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void logical_ring_default_vfuncs (struct intel_engine_cs *engine) {@@ -3208,6 +3213,7 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; + engine->bump_serial = execlist_bump_serial; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;drivers/gpu/drm/i915/gt/intel_ring_submission.c +6
-0@@ -1045,6 +1045,11 @@ static void setup_irq(struct intel_engine_cs *engine) } } +static void ring_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void setup_common (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;@@ -1064,6 +1069,7 @@ static void setup_common(struct intel_engine_cs *engine) engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; + engine->bump_serial = ring_bump_serial;/* * Using a global execution timeline; the previous final breadcrumb is drivers/gpu/drm/i915/gt/mock_engine.c +6
-0@@ -292,6 +292,11 @@ static void mock_engine_release(struct intel_engine_cs *engine)intel_engine_fini_retire (engine); } +static void mock_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +struct intel_engine_cs *mock_engine (struct drm_i915_private *i915,const char *name,int id)@@ -318,6 +323,7 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, engine->base.cops = &mock_context_ops; engine->base.request_alloc = mock_request_alloc; + engine->base.bump_serial = mock_bump_serial; engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16
-0@@ -1500,6 +1500,20 @@ static void guc_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void guc_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + +static void virtual_guc_bump_serial (struct intel_engine_cs *engine) +{ +struct intel_engine_cs *e; +intel_engine_mask_t tmp, mask = engine->mask; + +for_each_engine_masked (e, engine->gt, mask, tmp) + e->serial++; +} +static void guc_default_vfuncs (struct intel_engine_cs *engine) {/* Default vfuncs which can be overridden by each engine. */ @@ -1508,6 +1522,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; + engine->bump_serial = guc_bump_serial; engine->sched_engine->schedule = i915_schedule;@@ -1843,6 +1858,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.cops = &virtual_guc_context_ops; ve->base.request_alloc = guc_request_alloc; + ve->base.bump_serial = virtual_guc_bump_serial; ve->base.submit_request = guc_submit_request;drivers/gpu/drm/i915/i915_request.c +0
-0@@ -692,7 +692,9 @@ bool __i915_request_submit(struct i915_request *request) request->ring->vaddr + request->postfix);
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.c bool __i915_request_submit(struct i915_request *request)
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.c +3
-1trace_i915_request_execute (request); - engine->serial++; +if (engine->bump_serial) + engine->bump_serial (engine); + result = true;GEM_BUG_ON (test_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags));
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
Quoted 26 lines · Tvrtko Ursulin
Quoted 25 lines · Matthew Brost
Quoted 23 lines · Tvrtko Ursulin
Quoted 11 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
Quoted 5 lines
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Commit text sounds a bit defeatist. I think instead of making up the serial counts, which has downsides (could you please document in the commit what they are), we should think how to design things properly.
Quoted 6 lines
Quoted 4 lines
IMO, I don't think fixing serial counts is the scope of this series. We should focus on getting GuC submission in not cleaning up all the crap that is in the i915. Let's make a note of this though so we can revisit later.
I will say again - commit message implies it is introducing an unspecified downside by not fully fixing an also unspecified issue. It is completely reasonable, and customary even, to ask for both to be documented in the commit message.
Not sure what exactly is 'unspecified'. I thought the commit message described both the problem (heartbeat not running when using virtual engines) and the result (heartbeat running on more engines than strictly necessary). But in greater detail...
The serial number tracking is a hack for the heartbeat code to know whether an engine is busy or idle, and therefore whether it should be pinged for aliveness. Whenever a submission is made to an engine, the serial number is incremented. The heartbeat code keeps a copy of the value. If the value has changed, the engine is busy and needs to be pinged.
This works fine for execlist mode where virtual engine decomposition is done inside i915. It fails miserably for GuC mode where the decomposition is done by the hardware. The reason being that the heartbeat code only looks at physical engines but the serial count is only incremented on the virtual engine. Thus, the heartbeat sees everything as idle and does not ping.
This patch decomposes the virtual engines for the sake of incrementing the serial count on each sub-engine in order to keep the heartbeat code happy. The downside is that now the heartbeat sees all sub-engines as busy rather than only the one the submission actually ends up on. There really isn't much that can be done about that. The heartbeat code is in i915 not GuC, the scheduler is in GuC not i915. The only way to improve it is to either move the heartbeat code into GuC as well and completely disable the i915 side, or add some way for i915 to interrogate GuC as to which engines are or are not active. Technically, we do have both. GuC has (or at least had) an option to force a context switch on every execution quantum pre-emption. However, that is much, much, more heavy weight than the heartbeat. For the latter, we do (almost) have the engine usage statistics for PMU and such like. I'm not sure how much effort it would be to wire that up to the heartbeat code instead of using the serial count.
In short, the serial count is ever so slightly inefficient in that it causes heartbeat pings on engines which are idle. On the other hand, it is way more efficient and simpler than the current alternatives.
Does that answer the questions?
John.
Quoted 162 lines
If we are abandoning the normal review process someone please say so I don't waste my time reading it.
Regards,
Tvrtko
Quoted 143 lines
Matt
Quoted 141 lines
Regards,
Tvrtko
Quoted 137 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++.../gpu/drm/i915/gt/intel_execlists_submission.c| 6 ++++++ drivers/gpu/drm/i915/gt/intel_ring_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/mock_engine.c | 6 ++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 16
++++++++++++++++
drivers/gpu/drm/i915/i915_request.c | 4 +++-6 files changed, 39 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_engine_types.h +2
-0@@ -389,6 +389,8 @@ struct intel_engine_cs { void (*park)(struct intel_engine_cs *engine); void (*unpark)(struct intel_engine_cs *engine); + void (*bump_serial)(struct intel_engine_cs *engine); + void (*set_default_submission)(struct intel_engine_cs *engine); const struct intel_context_ops *cops;drivers/gpu/drm/i915/gt/intel_execlists_submission.c +5
-0@@ -3199,6 +3199,11 @@ static void execlists_release(struct intel_engine_cs *engine) lrc_fini_wa_ctx(engine); } +static void execlist_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void
logical_ring_default_vfuncs(struct intel_engine_cs *engine){drivers/gpu/drm/i915/gt/intel_execlists_submission.c +1
-0@@ -3208,6 +3213,7 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; + engine->bump_serial = execlist_bump_serial; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;drivers/gpu/drm/i915/gt/intel_ring_submission.c +6
-0@@ -1045,6 +1045,11 @@ static void setup_irq(struct intel_engine_cs *engine) } } +static void ring_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + static void setup_common(struct intel_engine_cs *engine) { struct drm_i915_private *i915 = engine->i915;@@ -1064,6 +1069,7 @@ static void setup_common(struct intel_engine_cs *engine) engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; + engine->bump_serial = ring_bump_serial; /** Using a global execution timeline; the previous final breadcrumb is drivers/gpu/drm/i915/gt/mock_engine.c +6
-0@@ -292,6 +292,11 @@ static void mock_engine_release(struct intel_engine_cs *engine) intel_engine_fini_retire(engine); } +static void mock_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, const char *name, int id)@@ -318,6 +323,7 @@ struct intel_engine_cs *mock_engine(structdrm_i915_private *i915, engine->base.cops = &mock_context_ops; engine->base.request_alloc = mock_request_alloc; + engine->base.bump_serial = mock_bump_serial; engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16
-0@@ -1500,6 +1500,20 @@ static void guc_release(struct intel_engine_cs *engine) lrc_fini_wa_ctx(engine); } +static void guc_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + +static void virtual_guc_bump_serial (struct intel_engine_cs *engine) +{ + struct intel_engine_cs *e; + intel_engine_mask_t tmp, mask = engine->mask; + + for_each_engine_masked(e, engine->gt, mask, tmp) + e->serial++; +} + static void guc_default_vfuncs(struct intel_engine_cs *engine) { /* Default vfuncs which can be overridden by each engine. */@@ -1508,6 +1522,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; + engine->bump_serial = guc_bump_serial; engine->sched_engine->schedule = i915_schedule;@@ -1843,6 +1858,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.cops = &virtual_guc_context_ops; ve->base.request_alloc = guc_request_alloc; + ve->base.bump_serial = virtual_guc_bump_serial; ve->base.submit_request = guc_submit_request;drivers/gpu/drm/i915/i915_request.c +0
-0@@ -692,7 +692,9 @@ bool __i915_request_submit(struct i915_request *request) request->ring->vaddr + request->postfix);Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.c bool __i915_request_submit(struct i915_request *request)
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.c +3
-1trace_i915_request_execute(request); - engine->serial++; + if (engine->bump_serial) + engine->bump_serial(engine); + result = true; GEM_BUG_ON(test_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags));_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
Quoted 32 lines · John Harrison
Quoted 31 lines · Tvrtko Ursulin
Quoted 29 lines · Matthew Brost
Quoted 19 lines · Tvrtko Ursulin
Quoted 11 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
Quoted 5 lines
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Quoted 4 lines
Commit text sounds a bit defeatist. I think instead of making up the serial counts, which has downsides (could you please document in the commit what they are), we should think how to design things properly.
IMO, I don't think fixing serial counts is the scope of this series. We should focus on getting GuC submission in not cleaning up all the crap that is in the i915. Let's make a note of this though so we can revisit later.
Quoted 6 lines
Quoted 1 line
I will say again - commit message implies it is introducing an unspecified downside by not fully fixing an also unspecified issue. It is completely reasonable, and customary even, to ask for both to be documented in the commit message.
Not sure what exactly is 'unspecified'. I thought the commit message described both the problem (heartbeat not running when using virtual engines) and the result (heartbeat running on more engines than strictly necessary). But in greater detail...
The serial number tracking is a hack for the heartbeat code to know whether an engine is busy or idle, and therefore whether it should be pinged for aliveness. Whenever a submission is made to an engine, the serial number is incremented. The heartbeat code keeps a copy of the value. If the value has changed, the engine is busy and needs to be pinged.
This works fine for execlist mode where virtual engine decomposition is done inside i915. It fails miserably for GuC mode where the decomposition is done by the hardware. The reason being that the heartbeat code only looks at physical engines but the serial count is only incremented on the virtual engine. Thus, the heartbeat sees everything as idle and does not ping.
So hangcheck does not work. Or it works because GuC does it anyway. Either way, that's one thing to explicitly state in the commit message.
Quoted 3 lines
This patch decomposes the virtual engines for the sake of incrementing the serial count on each sub-engine in order to keep the heartbeat code happy. The downside is that now the heartbeat sees all sub-engines as busy rather than only the one the submission actually ends up on. There really isn't much that can be done about that. The heartbeat code is in i915 not GuC, the scheduler is in GuC not i915. The only way to improve it is to either move the heartbeat code into GuC as well and completely disable the i915 side, or add some way for i915 to interrogate GuC as to which engines are or are not active. Technically, we do have both. GuC has (or at least had) an option to force a context switch on every execution quantum pre-emption. However, that is much, much, more heavy weight than the heartbeat. For the latter, we do (almost) have the engine usage statistics for PMU and such like. I'm not sure how much effort it would be to wire that up to the heartbeat code instead of using the serial count.
In short, the serial count is ever so slightly inefficient in that it causes heartbeat pings on engines which are idle. On the other hand, it is way more efficient and simpler than the current alternatives.
And the hack to make hangcheck work creates this inefficiency where heartbeats are sent to idle engines. Which is probably fine just needs to be explained.
Quoted 1 line
Does that answer the questions?
With the two points I re-raise clearly explained, possibly even patch title changed, yeah. I am just wanting for it to be more easily obvious to patch reader what it is functionally about - not just what implementation details have been change but why as well.
Regards,
Tvrtko
Quoted 166 lines
John.
Quoted 162 lines
If we are abandoning the normal review process someone please say so I don't waste my time reading it.
Regards,
Tvrtko
Quoted 143 lines
Matt
Quoted 141 lines
Regards,
Tvrtko
Quoted 137 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++.../gpu/drm/i915/gt/intel_execlists_submission.c| 6 ++++++ drivers/gpu/drm/i915/gt/intel_ring_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/mock_engine.c | 6 ++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 16
++++++++++++++++
drivers/gpu/drm/i915/i915_request.c | 4 +++-6 files changed, 39 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_engine_types.h +2
-0@@ -389,6 +389,8 @@ struct intel_engine_cs { void (*park)(struct intel_engine_cs *engine); void (*unpark)(struct intel_engine_cs *engine); + void (*bump_serial)(struct intel_engine_cs *engine); + void (*set_default_submission)(struct intel_engine_cs *engine); const struct intel_context_ops *cops;drivers/gpu/drm/i915/gt/intel_execlists_submission.c +5
-0@@ -3199,6 +3199,11 @@ static void execlists_release(struct intel_engine_cs *engine) lrc_fini_wa_ctx(engine); } +static void execlist_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void
logical_ring_default_vfuncs(struct intel_engine_cs *engine){drivers/gpu/drm/i915/gt/intel_execlists_submission.c +1
-0@@ -3208,6 +3213,7 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; + engine->bump_serial = execlist_bump_serial; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;drivers/gpu/drm/i915/gt/intel_ring_submission.c +6
-0@@ -1045,6 +1045,11 @@ static void setup_irq(struct intel_engine_cs *engine) } } +static void ring_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + static void setup_common(struct intel_engine_cs *engine) { struct drm_i915_private *i915 = engine->i915;@@ -1064,6 +1069,7 @@ static void setup_common(struct intel_engine_cs *engine) engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; + engine->bump_serial = ring_bump_serial; /** Using a global execution timeline; the previous final breadcrumb is drivers/gpu/drm/i915/gt/mock_engine.c +6
-0@@ -292,6 +292,11 @@ static void mock_engine_release(struct intel_engine_cs *engine) intel_engine_fini_retire(engine); } +static void mock_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, const char *name, int id)@@ -318,6 +323,7 @@ struct intel_engine_cs *mock_engine(structdrm_i915_private *i915, engine->base.cops = &mock_context_ops; engine->base.request_alloc = mock_request_alloc; + engine->base.bump_serial = mock_bump_serial; engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16
-0@@ -1500,6 +1500,20 @@ static void guc_release(struct intel_engine_cs *engine) lrc_fini_wa_ctx(engine); } +static void guc_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + +static void virtual_guc_bump_serial (struct intel_engine_cs *engine) +{ + struct intel_engine_cs *e; + intel_engine_mask_t tmp, mask = engine->mask; + + for_each_engine_masked(e, engine->gt, mask, tmp) + e->serial++; +} + static void guc_default_vfuncs(struct intel_engine_cs *engine) { /* Default vfuncs which can be overridden by each engine. */@@ -1508,6 +1522,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; + engine->bump_serial = guc_bump_serial; engine->sched_engine->schedule = i915_schedule;@@ -1843,6 +1858,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.cops = &virtual_guc_context_ops; ve->base.request_alloc = guc_request_alloc; + ve->base.bump_serial = virtual_guc_bump_serial; ve->base.submit_request = guc_submit_request;drivers/gpu/drm/i915/i915_request.c +0
-0@@ -692,7 +692,9 @@ bool __i915_request_submit(struct i915_request *request) request->ring->vaddr + request->postfix);Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.c bool __i915_request_submit(struct i915_request *request)
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.c +3
-1trace_i915_request_execute(request); - engine->serial++; + if (engine->bump_serial) + engine->bump_serial(engine); + result = true; GEM_BUG_ON(test_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags));_______________________________________________
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
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
Quoted 44 lines · Tvrtko Ursulin
Quoted 32 lines · John Harrison
Quoted 31 lines · Tvrtko Ursulin
Quoted 29 lines · Matthew Brost
Quoted 19 lines · Tvrtko Ursulin
Quoted 11 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
Quoted 5 lines
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Quoted 4 lines
Commit text sounds a bit defeatist. I think instead of making up the serial counts, which has downsides (could you please document in the commit what they are), we should think how to design things properly.
IMO, I don't think fixing serial counts is the scope of this series. We should focus on getting GuC submission in not cleaning up all the crap that is in the i915. Let's make a note of this though so we can revisit later.
Quoted 6 lines
Quoted 1 line
I will say again - commit message implies it is introducing an unspecified downside by not fully fixing an also unspecified issue. It is completely reasonable, and customary even, to ask for both to be documented in the commit message.
Not sure what exactly is 'unspecified'. I thought the commit message described both the problem (heartbeat not running when using virtual engines) and the result (heartbeat running on more engines than strictly necessary). But in greater detail...
The serial number tracking is a hack for the heartbeat code to know whether an engine is busy or idle, and therefore whether it should be pinged for aliveness. Whenever a submission is made to an engine, the serial number is incremented. The heartbeat code keeps a copy of the value. If the value has changed, the engine is busy and needs to be pinged.
This works fine for execlist mode where virtual engine decomposition is done inside i915. It fails miserably for GuC mode where the decomposition is done by the hardware. The reason being that the heartbeat code only looks at physical engines but the serial count is only incremented on the virtual engine. Thus, the heartbeat sees everything as idle and does not ping.
So hangcheck does not work. Or it works because GuC does it anyway. Either way, that's one thing to explicitly state in the commit message.
Quoted 2 lines
This patch decomposes the virtual engines for the sake of incrementing the serial count on each sub-engine in order to keep the heartbeat code happy. The downside is that now the heartbeat sees all sub-engines as busy rather than only the one the submission actually ends up on. There really isn't much that can be done about that. The heartbeat code is in i915 not GuC, the scheduler is in GuC not i915. The only way to improve it is to either move the heartbeat code into GuC as well and completely disable the i915 side, or add some way for i915 to interrogate GuC as to which engines are or are not active. Technically, we do have both. GuC has (or at least had) an option to force a context switch on every execution quantum pre-emption. However, that is much, much, more heavy weight than the heartbeat. For the latter, we do (almost) have the engine usage statistics for PMU and such like. I'm not sure how much effort it would be to wire that up to the heartbeat code instead of using the serial count.
Quoted 8 lines
Quoted 1 line
In short, the serial count is ever so slightly inefficient in that it causes heartbeat pings on engines which are idle. On the other hand, it is way more efficient and simpler than the current alternatives.
And the hack to make hangcheck work creates this inefficiency where heartbeats are sent to idle engines. Which is probably fine just needs to be explained.
Quoted 1 line
Does that answer the questions?
With the two points I re-raise clearly explained, possibly even patch title changed, yeah. I am just wanting for it to be more easily obvious to patch reader what it is functionally about - not just what implementation details have been change but why as well.
My understanding is that we don't explain every piece of code in minute detail in every checkin email that touches it. I thought my description was already pretty verbose. I've certainly seen way less informative checkins that apparently made it through review without issue.
Regarding the problem statement, I thought this was fairly clear that the heartbeat was broken for virtual engines:
This would mean that the heart beat code
thinks the physical engines are idle due to the serial number not incrementing.
Regarding the inefficiency about heartbeating all physical engines in a virtual engine, again, this seems clear to me:
decompose virtual engines into
their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine.
For the subject, I guess you could say "Track 'heartbeat serial' counts for virtual engines". However, the serial tracking count is not explicitly named for heartbeats so it seems inaccurate to rename it for a checkin email subject.
If you have a suggestion for better wording then feel free to propose something.
John.
Quoted 170 lines
Regards,
Tvrtko
Quoted 166 lines
John.
Quoted 162 lines
If we are abandoning the normal review process someone please say so I don't waste my time reading it.
Regards,
Tvrtko
Quoted 143 lines
Matt
Quoted 141 lines
Regards,
Tvrtko
Quoted 137 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>---
drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++.../gpu/drm/i915/gt/intel_execlists_submission.c| 6 ++++++ drivers/gpu/drm/i915/gt/intel_ring_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/mock_engine.c | 6 ++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 16
++++++++++++++++
drivers/gpu/drm/i915/i915_request.c | 4 +++-6 files changed, 39 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_engine_types.h +2
-0@@ -389,6 +389,8 @@ struct intel_engine_cs { void (*park)(struct intel_engine_cs *engine); void (*unpark)(struct intel_engine_cs *engine); + void (*bump_serial)(struct intel_engine_cs *engine); + void (*set_default_submission)(struct intel_engine_cs *engine); const struct intel_context_ops *cops;drivers/gpu/drm/i915/gt/intel_execlists_submission.c +5
-0@@ -3199,6 +3199,11 @@ static void execlists_release(struct intel_engine_cs *engine) lrc_fini_wa_ctx(engine); } +static void execlist_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void
logical_ring_default_vfuncs(struct intel_engine_cs *engine){drivers/gpu/drm/i915/gt/intel_execlists_submission.c +1
-0@@ -3208,6 +3213,7 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; + engine->bump_serial = execlist_bump_serial; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;drivers/gpu/drm/i915/gt/intel_ring_submission.c +6
-0@@ -1045,6 +1045,11 @@ static void setup_irq(struct intel_engine_cs *engine) } } +static void ring_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + static void setup_common(struct intel_engine_cs *engine) { struct drm_i915_private *i915 = engine->i915;@@ -1064,6 +1069,7 @@ static void setup_common(struct intel_engine_cs *engine) engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; + engine->bump_serial = ring_bump_serial; /** Using a global execution timeline; the previous final breadcrumb is drivers/gpu/drm/i915/gt/mock_engine.c +6
-0@@ -292,6 +292,11 @@ static void mock_engine_release(struct intel_engine_cs *engine) intel_engine_fini_retire(engine); } +static void mock_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, const char *name, int id)@@ -318,6 +323,7 @@ struct intel_engine_cs *mock_engine(structdrm_i915_private *i915, engine->base.cops = &mock_context_ops; engine->base.request_alloc = mock_request_alloc; + engine->base.bump_serial = mock_bump_serial; engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16
-0@@ -1500,6 +1500,20 @@ static void guc_release(struct intel_engine_cs *engine) lrc_fini_wa_ctx(engine); } +static void guc_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + +static void virtual_guc_bump_serial (struct intel_engine_cs *engine) +{ + struct intel_engine_cs *e; + intel_engine_mask_t tmp, mask = engine->mask; + + for_each_engine_masked(e, engine->gt, mask, tmp) + e->serial++; +} + static void guc_default_vfuncs(struct intel_engine_cs *engine) { /* Default vfuncs which can be overridden by each engine. */@@ -1508,6 +1522,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; + engine->bump_serial = guc_bump_serial; engine->sched_engine->schedule = i915_schedule;@@ -1843,6 +1858,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.cops = &virtual_guc_context_ops; ve->base.request_alloc = guc_request_alloc; + ve->base.bump_serial = virtual_guc_bump_serial; ve->base.submit_request = guc_submit_request;drivers/gpu/drm/i915/i915_request.c +0
-0@@ -692,7 +692,9 @@ bool __i915_request_submit(struct i915_request *request) request->ring->vaddr + request->postfix);Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.c bool __i915_request_submit(struct i915_request *request)
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.c +3
-1trace_i915_request_execute(request); - engine->serial++; + if (engine->bump_serial) + engine->bump_serial(engine); + result = true; GEM_BUG_ON(test_bit(I915_FENCE_FLAG_ACTIVE, &request->fence.flags));_______________________________________________
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
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
Quoted 70 lines · John Harrison
Quoted 44 lines · Tvrtko Ursulin
Quoted 32 lines · John Harrison
Quoted 31 lines · Tvrtko Ursulin
Quoted 29 lines · Matthew Brost
Quoted 19 lines · Tvrtko Ursulin
Quoted 11 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
Quoted 5 lines
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Quoted 4 lines
Commit text sounds a bit defeatist. I think instead of making up the serial counts, which has downsides (could you please document in the commit what they are), we should think how to design things properly.
IMO, I don't think fixing serial counts is the scope of this series. We should focus on getting GuC submission in not cleaning up all the crap that is in the i915. Let's make a note of this though so we can revisit later.
Quoted 6 lines
Quoted 1 line
I will say again - commit message implies it is introducing an unspecified downside by not fully fixing an also unspecified issue. It is completely reasonable, and customary even, to ask for both to be documented in the commit message.
Not sure what exactly is 'unspecified'. I thought the commit message described both the problem (heartbeat not running when using virtual engines) and the result (heartbeat running on more engines than strictly necessary). But in greater detail...
The serial number tracking is a hack for the heartbeat code to know whether an engine is busy or idle, and therefore whether it should be pinged for aliveness. Whenever a submission is made to an engine, the serial number is incremented. The heartbeat code keeps a copy of the value. If the value has changed, the engine is busy and needs to be pinged.
This works fine for execlist mode where virtual engine decomposition is done inside i915. It fails miserably for GuC mode where the decomposition is done by the hardware. The reason being that the heartbeat code only looks at physical engines but the serial count is only incremented on the virtual engine. Thus, the heartbeat sees everything as idle and does not ping.
So hangcheck does not work. Or it works because GuC does it anyway. Either way, that's one thing to explicitly state in the commit message.
Quoted 2 lines
This patch decomposes the virtual engines for the sake of incrementing the serial count on each sub-engine in order to keep the heartbeat code happy. The downside is that now the heartbeat sees all sub-engines as busy rather than only the one the submission actually ends up on. There really isn't much that can be done about that. The heartbeat code is in i915 not GuC, the scheduler is in GuC not i915. The only way to improve it is to either move the heartbeat code into GuC as well and completely disable the i915 side, or add some way for i915 to interrogate GuC as to which engines are or are not active. Technically, we do have both. GuC has (or at least had) an option to force a context switch on every execution quantum pre-emption. However, that is much, much, more heavy weight than the heartbeat. For the latter, we do (almost) have the engine usage statistics for PMU and such like. I'm not sure how much effort it would be to wire that up to the heartbeat code instead of using the serial count.
Quoted 8 lines
Quoted 1 line
In short, the serial count is ever so slightly inefficient in that it causes heartbeat pings on engines which are idle. On the other hand, it is way more efficient and simpler than the current alternatives.
And the hack to make hangcheck work creates this inefficiency where heartbeats are sent to idle engines. Which is probably fine just needs to be explained.
Quoted 1 line
Does that answer the questions?
With the two points I re-raise clearly explained, possibly even patch title changed, yeah. I am just wanting for it to be more easily obvious to patch reader what it is functionally about - not just what implementation details have been change but why as well.
My understanding is that we don't explain every piece of code in minute detail in every checkin email that touches it. I thought my description was already pretty verbose. I've certainly seen way less informative checkins that apparently made it through review without issue.
Regarding the problem statement, I thought this was fairly clear that the heartbeat was broken for virtual engines:
This would mean that the heart beat code
thinks the physical engines are idle due to the serial number not incrementing.Regarding the inefficiency about heartbeating all physical engines in a virtual engine, again, this seems clear to me:
decompose virtual engines into
their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine.
Quoted 3 lines
For the subject, I guess you could say "Track 'heartbeat serial' counts for virtual engines". However, the serial tracking count is not explicitly named for heartbeats so it seems inaccurate to rename it for a checkin email subject.
If you have a suggestion for better wording then feel free to propose something.
Sigh, I am not asking for more low level detail but for more up to point high level naming and high level description.
"drm/i915: Fix hangchek for guc virtual engines"
"..Blah blah, but hack because it is not ideal due xyz which needlessly wakes up all engines which has an effect on power yes/no? Latency? Throughput when high prio pulse triggers pointless preemption?"
Also, can we fix it properly without introducing inefficiencies? Do we even need heartbeats when GuC is in charge of engine resets? And if we do can we make them work better?
Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
Quoted 71 lines · Tvrtko Ursulin
Quoted 70 lines · John Harrison
Quoted 44 lines · Tvrtko Ursulin
Quoted 32 lines · John Harrison
Quoted 31 lines · Tvrtko Ursulin
Quoted 29 lines · Matthew Brost
Quoted 19 lines · Tvrtko Ursulin
Quoted 11 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
Quoted 5 lines
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Quoted 4 lines
Commit text sounds a bit defeatist. I think instead of making up the serial counts, which has downsides (could you please document in the commit what they are), we should think how to design things properly.
IMO, I don't think fixing serial counts is the scope of this series. We should focus on getting GuC submission in not cleaning up all the crap that is in the i915. Let's make a note of this though so we can revisit later.
Quoted 6 lines
Quoted 1 line
I will say again - commit message implies it is introducing an unspecified downside by not fully fixing an also unspecified issue. It is completely reasonable, and customary even, to ask for both to be documented in the commit message.
Not sure what exactly is 'unspecified'. I thought the commit message described both the problem (heartbeat not running when using virtual engines) and the result (heartbeat running on more engines than strictly necessary). But in greater detail...
The serial number tracking is a hack for the heartbeat code to know whether an engine is busy or idle, and therefore whether it should be pinged for aliveness. Whenever a submission is made to an engine, the serial number is incremented. The heartbeat code keeps a copy of the value. If the value has changed, the engine is busy and needs to be pinged.
This works fine for execlist mode where virtual engine decomposition is done inside i915. It fails miserably for GuC mode where the decomposition is done by the hardware. The reason being that the heartbeat code only looks at physical engines but the serial count is only incremented on the virtual engine. Thus, the heartbeat sees everything as idle and does not ping.
So hangcheck does not work. Or it works because GuC does it anyway. Either way, that's one thing to explicitly state in the commit message.
Quoted 2 lines
This patch decomposes the virtual engines for the sake of incrementing the serial count on each sub-engine in order to keep the heartbeat code happy. The downside is that now the heartbeat sees all sub-engines as busy rather than only the one the submission actually ends up on. There really isn't much that can be done about that. The heartbeat code is in i915 not GuC, the scheduler is in GuC not i915. The only way to improve it is to either move the heartbeat code into GuC as well and completely disable the i915 side, or add some way for i915 to interrogate GuC as to which engines are or are not active. Technically, we do have both. GuC has (or at least had) an option to force a context switch on every execution quantum pre-emption. However, that is much, much, more heavy weight than the heartbeat. For the latter, we do (almost) have the engine usage statistics for PMU and such like. I'm not sure how much effort it would be to wire that up to the heartbeat code instead of using the serial count.
Quoted 8 lines
Quoted 1 line
In short, the serial count is ever so slightly inefficient in that it causes heartbeat pings on engines which are idle. On the other hand, it is way more efficient and simpler than the current alternatives.
And the hack to make hangcheck work creates this inefficiency where heartbeats are sent to idle engines. Which is probably fine just needs to be explained.
Quoted 1 line
Does that answer the questions?
With the two points I re-raise clearly explained, possibly even patch title changed, yeah. I am just wanting for it to be more easily obvious to patch reader what it is functionally about - not just what implementation details have been change but why as well.
My understanding is that we don't explain every piece of code in minute detail in every checkin email that touches it. I thought my description was already pretty verbose. I've certainly seen way less informative checkins that apparently made it through review without issue.
Regarding the problem statement, I thought this was fairly clear that the heartbeat was broken for virtual engines:
This would mean that the heart beat code
thinks the physical engines are idle due to the serial number not incrementing.Regarding the inefficiency about heartbeating all physical engines in a virtual engine, again, this seems clear to me:
decompose virtual engines into
their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine.
Quoted 7 lines
Quoted 3 lines
For the subject, I guess you could say "Track 'heartbeat serial' counts for virtual engines". However, the serial tracking count is not explicitly named for heartbeats so it seems inaccurate to rename it for a checkin email subject.
If you have a suggestion for better wording then feel free to propose something.
Sigh, I am not asking for more low level detail but for more up to point high level naming and high level description.
"drm/i915: Fix hangchek for guc virtual engines"
I would argue that the bug is not a with hangcheck bug and only tangentially a GuC bug. It is really a bug with the serial number tracking of virtual engines in general and the lack of support for non-execlist backends in the serial number implementation. Hangcheck makes use of the serial number. It is not clear from the code whether anything else does currently or used to previously use them. Certainly, there is no documentation on the serial number declaration in the engine structure to explain its purpose. Likewise, there is nothing GuC specific about delaying the decomposition of virtual engines. Any externally scheduled backed end would do similar. E.g. once the execlist backend moves to using the DRM scheduler then maybe it will have delayed decomposition as well, and therefore also fall foul of the missing serial number updates.
Quoted 2 lines
"..Blah blah, but hack because it is not ideal due xyz which needlessly wakes up all engines which has an effect on power yes/no? Latency? Throughput when high prio pulse triggers pointless preemption?"
Yes to all the above but that is already true of the heartbeat mechanism in general and I do not see any documentation in the code as to what the effect of the heartbeat mechanism is on power, latency, throughput, etc. My assumption is that the heartbeat is considered slow enough periodicity that any performance impact is negligible. And if the system is loaded to the point where the heartbeat is having an impact then all engines within the virtual set are going to be in use (because if they aren't then the system is obviously not heavily loaded), in which case the heartbeat would be pinging all engines anyway.
Quoted 2 lines
Also, can we fix it properly without introducing inefficiencies? Do we even need heartbeats when GuC is in charge of engine resets? And if we do can we make them work better?
In short, no, not easily.
The GuC's internal hang detection and recovery mechanism relies on pre-emption timeouts for the detection part. However, if only one context is active on a given engine, there will be no pre-emptions and thus the GuC will not be able to detect if that context is making forward progress or not. That's where the heartbeat comes in. It sends a dummy request on a different context and thus causes a pre-emption to occur. So the architecture level decision was to keep the heartbeat enabled even with the GuC submission backend. Unless you are running OpenCL of course, in which case we turn everything off :(.
As for doing something better, not easily. GuC is not able to generate requests itself, so it can't replicate the heartbeat's operation internally. There is an option to force a context switch to idle on every quantum expiration. However, that is deemed too intrusive and costly from a performance viewpoint. It might be possible to add an independent heartbeat timer to the GuC firmware and use that to trigger less frequent forced pre-emptions. That would be more efficient and more targetted. Whether it is worth the effort required is another matter given how small an impact the heartbeat itself currently is.
I would still be my view that the serial count should be fixed anyway. It is broken for virtual engines. End of story. Whether that actually affects the users of the count is a separate issue that is dependent upon those users. But that just changes the severity of the bug, not its validity.
John.
Quoted 4 lines
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
Quoted 72 lines · John Harrison
Quoted 71 lines · Tvrtko Ursulin
Quoted 70 lines · John Harrison
Quoted 44 lines · Tvrtko Ursulin
Quoted 32 lines · John Harrison
Quoted 31 lines · Tvrtko Ursulin
Quoted 29 lines · Matthew Brost
Quoted 19 lines · Tvrtko Ursulin
Quoted 11 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
Quoted 5 lines
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Quoted 4 lines
Commit text sounds a bit defeatist. I think instead of making up the serial counts, which has downsides (could you please document in the commit what they are), we should think how to design things properly.
IMO, I don't think fixing serial counts is the scope of this series. We should focus on getting GuC submission in not cleaning up all the crap that is in the i915. Let's make a note of this though so we can revisit later.
Quoted 6 lines
Quoted 1 line
I will say again - commit message implies it is introducing an unspecified downside by not fully fixing an also unspecified issue. It is completely reasonable, and customary even, to ask for both to be documented in the commit message.
Not sure what exactly is 'unspecified'. I thought the commit message described both the problem (heartbeat not running when using virtual engines) and the result (heartbeat running on more engines than strictly necessary). But in greater detail...
The serial number tracking is a hack for the heartbeat code to know whether an engine is busy or idle, and therefore whether it should be pinged for aliveness. Whenever a submission is made to an engine, the serial number is incremented. The heartbeat code keeps a copy of the value. If the value has changed, the engine is busy and needs to be pinged.
This works fine for execlist mode where virtual engine decomposition is done inside i915. It fails miserably for GuC mode where the decomposition is done by the hardware. The reason being that the heartbeat code only looks at physical engines but the serial count is only incremented on the virtual engine. Thus, the heartbeat sees everything as idle and does not ping.
So hangcheck does not work. Or it works because GuC does it anyway. Either way, that's one thing to explicitly state in the commit message.
Quoted 2 lines
This patch decomposes the virtual engines for the sake of incrementing the serial count on each sub-engine in order to keep the heartbeat code happy. The downside is that now the heartbeat sees all sub-engines as busy rather than only the one the submission actually ends up on. There really isn't much that can be done about that. The heartbeat code is in i915 not GuC, the scheduler is in GuC not i915. The only way to improve it is to either move the heartbeat code into GuC as well and completely disable the i915 side, or add some way for i915 to interrogate GuC as to which engines are or are not active. Technically, we do have both. GuC has (or at least had) an option to force a context switch on every execution quantum pre-emption. However, that is much, much, more heavy weight than the heartbeat. For the latter, we do (almost) have the engine usage statistics for PMU and such like. I'm not sure how much effort it would be to wire that up to the heartbeat code instead of using the serial count.
Quoted 8 lines
Quoted 1 line
In short, the serial count is ever so slightly inefficient in that it causes heartbeat pings on engines which are idle. On the other hand, it is way more efficient and simpler than the current alternatives.
And the hack to make hangcheck work creates this inefficiency where heartbeats are sent to idle engines. Which is probably fine just needs to be explained.
Quoted 1 line
Does that answer the questions?
With the two points I re-raise clearly explained, possibly even patch title changed, yeah. I am just wanting for it to be more easily obvious to patch reader what it is functionally about - not just what implementation details have been change but why as well.
My understanding is that we don't explain every piece of code in minute detail in every checkin email that touches it. I thought my description was already pretty verbose. I've certainly seen way less informative checkins that apparently made it through review without issue.
Regarding the problem statement, I thought this was fairly clear that the heartbeat was broken for virtual engines:
This would mean that the heart beat code
thinks the physical engines are idle due to the serial number not incrementing.Regarding the inefficiency about heartbeating all physical engines in a virtual engine, again, this seems clear to me:
decompose virtual engines into
their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
For the subject, I guess you could say "Track 'heartbeat serial' counts for virtual engines". However, the serial tracking count is not explicitly named for heartbeats so it seems inaccurate to rename it for a checkin email subject.
If you have a suggestion for better wording then feel free to propose something.
Sigh, I am not asking for more low level detail but for more up to point high level naming and high level description.
"drm/i915: Fix hangchek for guc virtual engines"
I would argue that the bug is not a with hangcheck bug and only tangentially a GuC bug. It is really a bug with the serial number tracking of virtual engines in general and the lack of support for
You argue it is a bug in general but nothing is currently broken apart from hangcheck with GuC virtual engines? :) That could mean, say, that it is not actually broken but designed for the current code base.
Maybe "drm/i915: Make hangcheck work with GuC virtual engines" then if you object on the word fix? Would that make it immediately clear why is this patch must have/desirable?
Quoted 1 line
non-execlist backends in the serial number implementation. Hangcheck makes use of the serial number. It is not clear from the code whether anything else does currently or used to previously use them. Certainly,
Engine pm clearly uses it to know when it is safe to park the engine. I think I asked earlier in the series have the interactions in that area been looked at. I don't know myself, since I think that GuC changes how engine parking is done, but not really familiar. Now that I think of it, there possibly is a patch which keeps all engines unparked for virtual engines, so that's looking okay.
Quoted 1 line
there is no documentation on the serial number declaration in the engine structure to explain its purpose. Likewise, there is nothing GuC specific about delaying the decomposition of virtual engines. Any externally scheduled backed end would do similar. E.g. once the execlist backend moves to using the DRM scheduler then maybe it will have delayed decomposition as well, and therefore also fall foul of the missing serial number updates.
I don't think we know yet how drm/scheduler will be used to go that far.
Quoted 2 lines
Quoted 1 line
"..Blah blah, but hack because it is not ideal due xyz which needlessly wakes up all engines which has an effect on power yes/no? Latency? Throughput when high prio pulse triggers pointless preemption?"
Yes to all the above but that is already true of the heartbeat mechanism in general and I do not see any documentation in the code as to what the effect of the heartbeat mechanism is on power, latency, throughput, etc.
Difference is current code does not emit heartbeats on idle engines. So if we have a virtual engine built of say four some class engines, then the proposal here is to keep pinging all four in parallel. Even if only single context is executing. I am not saying that cost is big but honestly I don't understand why it is difficult to mention this in the commit message using clear and direct language.
Quoted 9 lines
My assumption is that the heartbeat is considered slow enough periodicity that any performance impact is negligible. And if the system is loaded to the point where the heartbeat is having an impact then all engines within the virtual set are going to be in use (because if they aren't then the system is obviously not heavily loaded), in which case the heartbeat would be pinging all engines anyway.
Quoted 2 lines
Also, can we fix it properly without introducing inefficiencies? Do we even need heartbeats when GuC is in charge of engine resets? And if we do can we make them work better?
In short, no, not easily.
The GuC's internal hang detection and recovery mechanism relies on pre-emption timeouts for the detection part. However, if only one context is active on a given engine, there will be no pre-emptions and thus the GuC will not be able to detect if that context is making forward progress or not. That's where the heartbeat comes in. It sends a dummy request on a different context and thus causes a pre-emption to occur. So the architecture level decision was to keep the heartbeat enabled even with the GuC submission backend. Unless you are running OpenCL of course, in which case we turn everything off :(.
As for doing something better, not easily. GuC is not able to generate requests itself, so it can't replicate the heartbeat's operation internally. There is an option to force a context switch to idle on every quantum expiration. However, that is deemed too intrusive and costly from a performance viewpoint. It might be possible to add an independent heartbeat timer to the GuC firmware and use that to trigger less frequent forced pre-emptions. That would be more efficient and more targetted. Whether it is worth the effort required is another matter given how small an impact the heartbeat itself currently is.
Well GuC could obviously do it in many ways and not all are expensive. If it can force a context switch on quantum expiration, it could force it on hearbeat expiration as you say. That would actually be more proper design than this kludge which leaves a bad taste regardless how little cost it has. Or it could perhaps track some sort of serials in a shared memory page.
But anyway, all I am asking here is that patch subject and commit message are made clear and direct. Here, I add two sentences as what I think is minimum:
drm/i915/guc: Make hangcheck work with GuC virtual engines
The serial number tracking of engines happens at the backend of
request submission and was expecting to only be given physical
engines. However, in GuC submission mode, the decomposition of virtual
to physical engines does not happen in i915. Instead, requests are
submitted to their virtual engine mask all the way through to the
hardware (i.e. to GuC). This would mean that the heart beat code
thinks the physical engines are idle due to the serial number not
incrementing. <added>Which in turns means hangcheck does not work for GuC virtual engines.</added>
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
<added>Downside of this is that all physical engines constituting a GuC virtual engine will be periodically unparked (even during just a single context executing) in order to be pinged with a heartbeat request. However the power and performance cost of this is not expected to be measurable (due low frequency of heartbeat pulses) and it is considered an easier option than trying to make changes to GuC firmware.</added>
Quoted 1 line
I would still be my view that the serial count should be fixed anyway. It is broken for virtual engines. End of story. Whether that actually affects the users of the count is a separate issue that is dependent upon those users. But that just changes the severity of the bug, not its validity.
It is clearly not broken for the current codebase, otherwise this patch would come with virtual_execlists_bump_serial and would be called like "drm/i915: Fix hangcheck on virtual engines". :)
Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 60/97] drm/i915: Track 'serial' counts for virtual engines
In reply to Matthew BrostQuoted 159 lines · Matthew Brost
From: John Harrison <[email protected]>
The serial number tracking of engines happens at the backend of request submission and was expecting to only be given physical engines. However, in GuC submission mode, the decomposition of virtual to physical engines does not happen in i915. Instead, requests are submitted to their virtual engine mask all the way through to the hardware (i.e. to GuC). This would mean that the heart beat code thinks the physical engines are idle due to the serial number not incrementing.
This patch updates the tracking to decompose virtual engines into their physical constituents and tracks the request against each. This is not entirely accurate as the GuC will only be issuing the request to one physical engine. However, it is the best that i915 can do given that it has no knowledge of the GuC's scheduling decisions.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++ .../gpu/drm/i915/gt/intel_execlists_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/intel_ring_submission.c | 6 ++++++ drivers/gpu/drm/i915/gt/mock_engine.c | 6 ++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 16 ++++++++++++++++ drivers/gpu/drm/i915/i915_request.c | 4 +++- 6 files changed, 39 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/intel_engine_types.h +2
-0@@ -389,6 +389,8 @@ struct intel_engine_cs {void (*park)(struct intel_engine_cs *engine);void (*unpark)(struct intel_engine_cs *engine); +void (*bump_serial)(struct intel_engine_cs *engine); +void (*set_default_submission)(struct intel_engine_cs *engine);const struct intel_context_ops *cops;drivers/gpu/drm/i915/gt/intel_execlists_submission.c +6
-0@@ -3199,6 +3199,11 @@ static void execlists_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void execlist_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void logical_ring_default_vfuncs (struct intel_engine_cs *engine) {@@ -3208,6 +3213,7 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; + engine->bump_serial = execlist_bump_serial; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;drivers/gpu/drm/i915/gt/intel_ring_submission.c +6
-0@@ -1045,6 +1045,11 @@ static void setup_irq(struct intel_engine_cs *engine) } } +static void ring_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +static void setup_common (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;@@ -1064,6 +1069,7 @@ static void setup_common(struct intel_engine_cs *engine) engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; + engine->bump_serial = ring_bump_serial;/* * Using a global execution timeline; the previous final breadcrumb is drivers/gpu/drm/i915/gt/mock_engine.c +6
-0@@ -292,6 +292,11 @@ static void mock_engine_release(struct intel_engine_cs *engine)intel_engine_fini_retire (engine); } +static void mock_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} +struct intel_engine_cs *mock_engine (struct drm_i915_private *i915,const char *name,int id)@@ -318,6 +323,7 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, engine->base.cops = &mock_context_ops; engine->base.request_alloc = mock_request_alloc; + engine->base.bump_serial = mock_bump_serial; engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16
-0@@ -1500,6 +1500,20 @@ static void guc_release(struct intel_engine_cs *engine)lrc_fini_wa_ctx (engine); } +static void guc_bump_serial (struct intel_engine_cs *engine) +{ + engine->serial++; +} + +static void virtual_guc_bump_serial (struct intel_engine_cs *engine) +{ +struct intel_engine_cs *e; +intel_engine_mask_t tmp, mask = engine->mask; + +for_each_engine_masked (e, engine->gt, mask, tmp) + e->serial++; +} +static void guc_default_vfuncs (struct intel_engine_cs *engine) {/* Default vfuncs which can be overridden by each engine. */ @@ -1508,6 +1522,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; + engine->bump_serial = guc_bump_serial; engine->sched_engine->schedule = i915_schedule;@@ -1843,6 +1858,7 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.cops = &virtual_guc_context_ops; ve->base.request_alloc = guc_request_alloc; + ve->base.bump_serial = virtual_guc_bump_serial; ve->base.submit_request = guc_submit_request;drivers/gpu/drm/i915/i915_request.c +0
-0
drivers/gpu/drm/i915/i915_request.c bool __i915_request_submit(struct i915_request *request) · line 697
Quoted 7 lines
drivers/gpu/drm/i915/i915_request.c +3
-1@@ -692,7 +692,9 @@ bool __i915_request_submit(struct i915_request *request) request->ring->vaddr + request->postfix);trace_i915_request_execute (request); - engine->serial++; +if (engine->bump_serial) + engine->bump_serial (engine); +
As long as you have to handle null vfunc, you could make the patch way smaller by doing:
if (engine->bump_serial)
engine->bump_serial(engine); else engine->serial++;
Added bonus you avoid a function call with execlists making the patch not introduce a double penalty. Or just make bump_serial always point to a valid/default function. No need for both a new branch *and* a function call I think. I'd prefer the code snippet as above though.
Regards,
Tvrtko
Quoted 4 lines
drivers/gpu/drm/i915/i915_request.c +0
-0result = true;GEM_BUG_ON (test_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags));
RFC PATCH 61/97 drm/i915: Hold reference to intel_context over life of i915_request
In reply to Matthew BrostHold a reference to the intel_context over life of an i915_request. Without this an i915_request can exist after the context has been destroyed (e.g. request retired, context closed, but user space holds a reference to the request from an out fence). In the case of GuC submission + virtual engine, the engine that the request references is also destroyed which can trigger bad pointer dref in fence ops (e.g. i915_fence_get_driver_name). We could likely change i915_fence_get_driver_name to avoid touching the engine but let's just be safe and hold the intel_context reference.
--- drivers/gpu/drm/i915/i915_request.c | 54 ++++++++++++----------------- 1 file changed, 22 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/i915_request.c +22 -32
@@ -126,39 +126,17 @@ static void i915_fence_release(struct dma_fence *fence)i915_sw_fence_fini (&rq->semaphore);/* -* Keep one request on each engine for reserved use under mempressure -* -* We do not hold a reference to the engine here and so have to be -* very careful in what rq->engine we poke. The virtual engine is -* referenced via the rq->context and we released that ref during -* i915_request_retire(), ergo we must not dereference a virtual -* engine here. Not that we would want to, as the only consumer of -* the reserved engine->request_pool is the power management parking, -* which must-not-fail, and that is only run on the physical engines. -* -* Since the request must have been executed to be have completed, -* we know that it will have been processed by the HW and will -* not be unsubmitted again, so rq->engine and rq->execution_mask -* at this point is stable. rq->execution_mask will be a single -* bit if the last and _only_ engine it could execution on was a -* physical engine, if it's multiple bits then it started on and -* could still be on a virtual engine. Thus if the mask is not a -* power-of-two we assume that rq->engine may still be a virtual -* engine and so a dangling invalid pointer that we cannot dereference -* -* For example, consider the flow of a bonded request through a virtual -* engine. The request is created with a wide engine mask (all engines -* that we might execute on). On processing the bond, the request mask -* is reduced to one or more engines. If the request is subsequently -* bound to a single engine, it will then be constrained to only -* execute on that engine and never returned to the virtual engine -* after timeslicing away, see __unwind_incomplete_requests(). Thus we -* know that if the rq->execution_mask is a single bit, rq->engine -* can be a physical engine with the exact corresponding mask. +* Keep one request on each engine for reserved use under mempressure, +* do not use with virtual engines as this really is only needed for +* kernel contexts. */ -if (is_power_of_2 (rq->execution_mask) && - !cmpxchg (&rq->engine->request_pool,NULL , rq)) +if (!intel_engine_is_virtual (rq->engine) && + !cmpxchg (&rq->engine->request_pool,NULL , rq)) { +intel_context_put (rq->context);return ; + } + +intel_context_put (rq->context);kmem_cache_free (global.slab_requests, rq); }
@@ -977,7 +955,18 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) } } - rq->context = ce; +/* +* Hold a reference to the intel_context over life of an i915_request. +* Without this an i915_request can exist after the context has been +* destroyed (e.g. request retired, context closed, but user space holds +* a reference to the request from an out fence). In the case of GuC +* submission + virtual engine, the engine that the request references +* is also destroyed which can trigger bad pointer dref in fence ops +* (e.g. i915_fence_get_driver_name). We could likely change these +* functions to avoid touching the engine but let's just be safe and +* hold the intel_context reference. +*/ + rq->context =intel_context_get (ce); rq->engine = ce->engine; rq->ring = ce->ring; rq->execution_mask = ce->engine->mask;
@@ -1054,6 +1043,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)GEM_BUG_ON (!list_empty (&rq->sched.waiters_list)); err_free: +intel_context_put (ce);kmem_cache_free (global.slab_requests, rq); err_unreserve:intel_context_unpin (ce);
Signature · 1 line
2.28.0
Re: [Intel-gfx] [RFC PATCH 61/97] drm/i915: Hold reference to intel_context over life of i915_request
Quoted 9 lines · Matthew Brost
Hold a reference to the
intel_contextover life of ani915_request. Without this ani915_requestcan exist after the context has been destroyed (e.g. request retired, context closed, but user space holds a reference to the request from an out fence). In the case of GuC submission + virtual engine, the engine that the request references is also destroyed which can trigger bad pointer dref in fence ops (e.g.i915_fence_get_driver_name). We could likely changei915_fence_get_driver_nameto avoid touching the engine but let's just be safe and hold theintel_contextreference.
Isn't this a bug in present upstream as well? Like calling sync fence info on retired requests or something else?
If it is a bug in upstream then I think a single patch to deal with the issue should be posted independently. It may be as simple as checking for the signaled bit in i915_fence_get_driver_name and dereferencing with rcu protection.
Regards,
Tvrtko
Quoted 80 lines
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/i915_request.c | 54 ++++++++++++----------------- 1 file changed, 22 insertions(+), 32 deletions(-)drivers/gpu/drm/i915/i915_request.c +21
-32@@ -126,39 +126,17 @@ static void i915_fence_release(struct dma_fence *fence)i915_sw_fence_fini (&rq->semaphore);/* -* Keep one request on each engine for reserved use under mempressure -* -* We do not hold a reference to the engine here and so have to be -* very careful in what rq->engine we poke. The virtual engine is -* referenced via the rq->context and we released that ref during -* i915_request_retire(), ergo we must not dereference a virtual -* engine here. Not that we would want to, as the only consumer of -* the reserved engine->request_pool is the power management parking, -* which must-not-fail, and that is only run on the physical engines. -* -* Since the request must have been executed to be have completed, -* we know that it will have been processed by the HW and will -* not be unsubmitted again, so rq->engine and rq->execution_mask -* at this point is stable. rq->execution_mask will be a single -* bit if the last and _only_ engine it could execution on was a -* physical engine, if it's multiple bits then it started on and -* could still be on a virtual engine. Thus if the mask is not a -* power-of-two we assume that rq->engine may still be a virtual -* engine and so a dangling invalid pointer that we cannot dereference -* -* For example, consider the flow of a bonded request through a virtual -* engine. The request is created with a wide engine mask (all engines -* that we might execute on). On processing the bond, the request mask -* is reduced to one or more engines. If the request is subsequently -* bound to a single engine, it will then be constrained to only -* execute on that engine and never returned to the virtual engine -* after timeslicing away, see __unwind_incomplete_requests(). Thus we -* know that if the rq->execution_mask is a single bit, rq->engine -* can be a physical engine with the exact corresponding mask. +* Keep one request on each engine for reserved use under mempressure, +* do not use with virtual engines as this really is only needed for +* kernel contexts. */ -if (is_power_of_2 (rq->execution_mask) && - !cmpxchg (&rq->engine->request_pool,NULL , rq)) +if (!intel_engine_is_virtual (rq->engine) && + !cmpxchg (&rq->engine->request_pool,NULL , rq)) { +intel_context_put (rq->context);return ; + } + +intel_context_put (rq->context);kmem_cache_free (global.slab_requests, rq); }@@ -977,7 +955,18 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) } } - rq->context = ce; +/* +* Hold a reference to the intel_context over life of an i915_request. +* Without this an i915_request can exist after the context has been +* destroyed (e.g. request retired, context closed, but user space holds +* a reference to the request from an out fence). In the case of GuC +* submission + virtual engine, the engine that the request references +* is also destroyed which can trigger bad pointer dref in fence ops +* (e.g. i915_fence_get_driver_name). We could likely change these +* functions to avoid touching the engine but let's just be safe and +* hold the intel_context reference. +*/ + rq->context =intel_context_get (ce); rq->engine = ce->engine; rq->ring = ce->ring; rq->execution_mask = ce->engine->mask;
drivers/gpu/drm/i915/i915_request.c __i915_request_create(struct intel_context *ce, gfp_t gfp) · line 1049
Quoted 7 lines
drivers/gpu/drm/i915/i915_request.c +1
-0@@ -1054,6 +1043,7 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)GEM_BUG_ON (!list_empty (&rq->sched.waiters_list)); err_free: +intel_context_put (ce);kmem_cache_free (global.slab_requests, rq); err_unreserve:intel_context_unpin (ce);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 62/97 drm/i915/guc: Disable bonding extension with GuC submission
In reply to Matthew BrostUpdate the bonding extension to return -ENODEV when using GuC submission as this extension fundamentally will not work with the GuC submission interface.
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_context.c +5 -0
@@ -1675,6 +1675,11 @@ set_engines__bond(struct i915_user_extension __user *base, void *data) } virtual = set->engines->engines[idx]->engine; +if (intel_engine_uses_guc (virtual)) { +DRM_DEBUG ("bonding extension not supported with GuC submission" ); +return -ENODEV ; + } + err =check_user_mbz (&ext->flags);if (err)return err;
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 63/97 drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs
In reply to Matthew BrostWith GuC virtual engines the physical engine which a request executes and completes on isn't known to the i915. Therefore we can't attach a request to a physical engines breadcrumbs. To work around this we create a single breadcrumbs per engine class when using GuC submission and direct all physical engine interrupts to this breadcrumbs.
--- drivers/gpu/drm/i915/gt/intel_breadcrumbs.c | 41 +++++------- drivers/gpu/drm/i915/gt/intel_breadcrumbs.h | 14 +++- .../gpu/drm/i915/gt/intel_breadcrumbs_types.h | 7 ++ drivers/gpu/drm/i915/gt/intel_engine.h | 3 + drivers/gpu/drm/i915/gt/intel_engine_cs.c | 28 +++++++- drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 - .../drm/i915/gt/intel_execlists_submission.c | 4 +- drivers/gpu/drm/i915/gt/mock_engine.c | 4 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 67 +++++++++++++++++-- 9 files changed, 133 insertions(+), 36 deletions(-)
drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +17 -24
@@ -15,28 +15,14 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" -static bool irq_enable (struct intel_engine_cs *engine) +static bool irq_enable (struct intel_breadcrumbs *b) { -if (!engine->irq_enable) -return false; - -/* Caller disables interrupts */ -spin_lock (&engine->gt->irq_lock); - engine->irq_enable (engine); -spin_unlock (&engine->gt->irq_lock); - -return true; +return intel_engine_irq_enable (b->irq_engine); } -static void irq_disable (struct intel_engine_cs *engine) +static void irq_disable (struct intel_breadcrumbs *b) { -if (!engine->irq_disable) -return ; - -/* Caller disables interrupts */ -spin_lock (&engine->gt->irq_lock); - engine->irq_disable (engine); -spin_unlock (&engine->gt->irq_lock); +intel_engine_irq_disable (b->irq_engine); }static void __intel_breadcrumbs_arm_irq (struct intel_breadcrumbs *b)
@@ -57,7 +43,7 @@ static void __intel_breadcrumbs_arm_irq(struct intel_breadcrumbs *b)WRITE_ONCE (b->irq_armed, true);/* Requests may have completed before we could enable the interrupt. */ -if (!b->irq_enabled++ &&irq_enable (b->irq_engine)) +if (!b->irq_enabled++ && b->irq_enable (b))irq_work_queue (&b->irq_work); }
@@ -76,7 +62,7 @@ static void __intel_breadcrumbs_disarm_irq(struct intel_breadcrumbs *b) {GEM_BUG_ON (!b->irq_enabled);if (!--b->irq_enabled) -irq_disable (b->irq_engine); + b->irq_disable (b);WRITE_ONCE (b->irq_armed, false);intel_gt_pm_put_async (b->irq_engine->gt);
@@ -281,7 +267,7 @@ intel_breadcrumbs_create(struct intel_engine_cs *irq_engine)if (!b)return NULL ; - b->irq_engine = irq_engine; +kref_init (&b->ref);spin_lock_init (&b->signalers_lock);INIT_LIST_HEAD (&b->signalers);
@@ -290,6 +276,10 @@ intel_breadcrumbs_create(struct intel_engine_cs *irq_engine)spin_lock_init (&b->irq_lock);init_irq_work (&b->irq_work, signal_irq_work); + b->irq_engine = irq_engine; + b->irq_enable = irq_enable; + b->irq_disable = irq_disable; +return b; }
@@ -303,9 +293,9 @@ void intel_breadcrumbs_reset(struct intel_breadcrumbs *b)spin_lock_irqsave (&b->irq_lock, flags);if (b->irq_enabled) -irq_enable (b->irq_engine); + b->irq_enable (b);else -irq_disable (b->irq_engine); + b->irq_disable (b);spin_unlock_irqrestore (&b->irq_lock, flags); }
@@ -325,11 +315,14 @@ void __intel_breadcrumbs_park(struct intel_breadcrumbs *b) } } -void intel_breadcrumbs_free (struct intel_breadcrumbs *b) +void intel_breadcrumbs_free (struct kref *kref) { +struct intel_breadcrumbs *b =container_of (kref,typeof (*b), ref); +irq_work_sync (&b->irq_work);GEM_BUG_ON (!list_empty (&b->signalers));GEM_BUG_ON (b->irq_armed); +kfree (b); }
drivers/gpu/drm/i915/gt/intel_breadcrumbs.h +13 -1
@@ -17,7 +17,7 @@ struct intel_breadcrumbs;struct intel_breadcrumbs *intel_breadcrumbs_create (struct intel_engine_cs *irq_engine); -void intel_breadcrumbs_free (struct intel_breadcrumbs *b); +void intel_breadcrumbs_free (struct kref *kref);void intel_breadcrumbs_reset (struct intel_breadcrumbs *b);void __intel_breadcrumbs_park (struct intel_breadcrumbs *b);
@@ -48,4 +48,16 @@ void i915_request_cancel_breadcrumb(struct i915_request *request);void intel_context_remove_breadcrumbs (struct intel_context *ce,struct intel_breadcrumbs *b); +static inline struct intel_breadcrumbs * +intel_breadcrumbs_get (struct intel_breadcrumbs *b) +{ +kref_get (&b->ref); +return b; +} + +static inline void intel_breadcrumbs_put (struct intel_breadcrumbs *b) +{ +kref_put (&b->ref, intel_breadcrumbs_free); +} +#endif /* __INTEL_BREADCRUMBS__ */
drivers/gpu/drm/i915/gt/intel_breadcrumbs_types.h +7 -0
@@ -7,10 +7,13 @@#define __INTEL_BREADCRUMBS_TYPES__#include <linux/irq_work.h> +#include <linux/kref.h> #include <linux/list.h> #include <linux/spinlock.h> #include <linux/types.h> +typedef u8 intel_engine_mask_t ; +/* * Rather than have every client wait upon all user interrupts, * with the herd waking after every interrupt and each doing the
@@ -29,6 +32,7 @@* the overhead of waking that client is much preferred. */ struct intel_breadcrumbs { +struct kref ref;atomic_t active;spinlock_t signalers_lock;/* protects the list of signalers */
@@ -42,7 +46,10 @@ struct intel_breadcrumbs {bool irq_armed;/* Not all breadcrumbs are attached to physical HW */ +intel_engine_mask_t engine_mask;struct intel_engine_cs *irq_engine; +bool (*irq_enable)(struct intel_breadcrumbs *b); + void (*irq_disable)(struct intel_breadcrumbs *b); };#endif /* __INTEL_BREADCRUMBS_TYPES__ */
drivers/gpu/drm/i915/gt/intel_engine.h +3 -0
@@ -209,6 +209,9 @@ void intel_engine_get_instdone(const struct intel_engine_cs *engine,void intel_engine_init_execlists (struct intel_engine_cs *engine); +bool intel_engine_irq_enable (struct intel_engine_cs *engine); +void intel_engine_irq_disable (struct intel_engine_cs *engine); +static inline void __intel_engine_reset (struct intel_engine_cs *engine,bool stalled) {
drivers/gpu/drm/i915/gt/intel_engine_cs.c +26 -2
@@ -765,7 +765,7 @@ static int engine_setup_common(struct intel_engine_cs *engine) err_cmd_parser:i915_sched_engine_put (engine->sched_engine); err_sched_engine: -intel_breadcrumbs_free (engine->breadcrumbs); +intel_breadcrumbs_put (engine->breadcrumbs); err_status:cleanup_status_page (engine);return err;
@@ -965,7 +965,7 @@ void intel_engine_cleanup_common(struct intel_engine_cs *engine) {GEM_BUG_ON (!list_empty (&engine->sched_engine->requests)); -intel_breadcrumbs_free (engine->breadcrumbs); +intel_breadcrumbs_put (engine->breadcrumbs);i915_sched_engine_put (engine->sched_engine);intel_engine_fini_retire (engine);
@@ -1320,6 +1320,30 @@ bool intel_engines_are_idle(struct intel_gt *gt)return true; } +bool intel_engine_irq_enable (struct intel_engine_cs *engine) +{ +if (!engine->irq_enable) +return false; + +/* Caller disables interrupts */ +spin_lock (&engine->gt->irq_lock); + engine->irq_enable (engine); +spin_unlock (&engine->gt->irq_lock); + +return true; +} + +void intel_engine_irq_disable (struct intel_engine_cs *engine) +{ +if (!engine->irq_disable) +return ; + +/* Caller disables interrupts */ +spin_lock (&engine->gt->irq_lock); + engine->irq_disable (engine); +spin_unlock (&engine->gt->irq_lock); +} +void intel_engines_reset_default_submission (struct intel_gt *gt) {struct intel_engine_cs *engine;
drivers/gpu/drm/i915/gt/intel_engine_types.h +0 -1
@@ -64,7 +64,6 @@ struct intel_gt;struct intel_ring ;struct intel_uncore ; -typedef u8 intel_engine_mask_t ;#define ALL_ENGINES ((intel_engine_mask_t)~0ul)struct intel_hw_status_page {
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +3 -1
@@ -3418,9 +3418,11 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)lrc_fini (&ve->context);intel_context_fini (&ve->context); -intel_breadcrumbs_free (ve->base.breadcrumbs); +if (ve->base.breadcrumbs) +intel_breadcrumbs_put (ve->base.breadcrumbs);if (ve->base.sched_engine)i915_sched_engine_put (ve->base.sched_engine); +intel_engine_free_request_pool (&ve->base);kfree (ve->bonds);
drivers/gpu/drm/i915/gt/mock_engine.c +2 -2
@@ -284,7 +284,7 @@ static void mock_engine_release(struct intel_engine_cs *engine)GEM_BUG_ON (timer_pending (&mock->hw_delay));i915_sched_engine_put (engine->sched_engine); -intel_breadcrumbs_free (engine->breadcrumbs); +intel_breadcrumbs_put (engine->breadcrumbs);intel_context_unpin (engine->kernel_context);intel_context_put (engine->kernel_context);
@@ -376,7 +376,7 @@ int mock_engine_init(struct intel_engine_cs *engine)return 0 ; err_breadcrumbs: -intel_breadcrumbs_free (engine->breadcrumbs); +intel_breadcrumbs_put (engine->breadcrumbs); err_schedule:i915_sched_engine_put (engine->sched_engine);return -ENOMEM ;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +62 -5
97 lines not on this page · raw message
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 63/97] drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs
Quoted 158 lines · Matthew Brost
With GuC virtual engines the physical engine which a request executes and completes on isn't known to the i915. Therefore we can't attach a request to a physical engines breadcrumbs. To work around this we create a single breadcrumbs per engine class when using GuC submission and direct all physical engine interrupts to this breadcrumbs.
Signed-off-by Matthew Brost <[email protected]>CC John Harrison <[email protected]>--- drivers/gpu/drm/i915/gt/intel_breadcrumbs.c | 41 +++++------- drivers/gpu/drm/i915/gt/intel_breadcrumbs.h | 14 +++- .../gpu/drm/i915/gt/intel_breadcrumbs_types.h | 7 ++ drivers/gpu/drm/i915/gt/intel_engine.h | 3 + drivers/gpu/drm/i915/gt/intel_engine_cs.c | 28 +++++++- drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 - .../drm/i915/gt/intel_execlists_submission.c | 4 +- drivers/gpu/drm/i915/gt/mock_engine.c | 4 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 67 +++++++++++++++++-- 9 files changed, 133 insertions(+), 36 deletions(-)drivers/gpu/drm/i915/gt/intel_breadcrumbs.c +17
-24@@ -15,28 +15,14 @@#include "intel_gt_pm.h" #include "intel_gt_requests.h" -static bool irq_enable (struct intel_engine_cs *engine) +static bool irq_enable (struct intel_breadcrumbs *b) { -if (!engine->irq_enable) -return false; - -/* Caller disables interrupts */ -spin_lock (&engine->gt->irq_lock); - engine->irq_enable (engine); -spin_unlock (&engine->gt->irq_lock); - -return true; +return intel_engine_irq_enable (b->irq_engine); } -static void irq_disable (struct intel_engine_cs *engine) +static void irq_disable (struct intel_breadcrumbs *b) { -if (!engine->irq_disable) -return ; - -/* Caller disables interrupts */ -spin_lock (&engine->gt->irq_lock); - engine->irq_disable (engine); -spin_unlock (&engine->gt->irq_lock); +intel_engine_irq_disable (b->irq_engine); }static void __intel_breadcrumbs_arm_irq (struct intel_breadcrumbs *b)@@ -57,7 +43,7 @@ static void __intel_breadcrumbs_arm_irq(struct intel_breadcrumbs *b)WRITE_ONCE (b->irq_armed, true);/* Requests may have completed before we could enable the interrupt. */ -if (!b->irq_enabled++ &&irq_enable (b->irq_engine)) +if (!b->irq_enabled++ && b->irq_enable (b))irq_work_queue (&b->irq_work); }@@ -76,7 +62,7 @@ static void __intel_breadcrumbs_disarm_irq(struct intel_breadcrumbs *b) {GEM_BUG_ON (!b->irq_enabled);if (!--b->irq_enabled) -irq_disable (b->irq_engine); + b->irq_disable (b);WRITE_ONCE (b->irq_armed, false);intel_gt_pm_put_async (b->irq_engine->gt);@@ -281,7 +267,7 @@ intel_breadcrumbs_create(struct intel_engine_cs *irq_engine)if (!b)return NULL ; - b->irq_engine = irq_engine; +kref_init (&b->ref);spin_lock_init (&b->signalers_lock);INIT_LIST_HEAD (&b->signalers);@@ -290,6 +276,10 @@ intel_breadcrumbs_create(struct intel_engine_cs *irq_engine)spin_lock_init (&b->irq_lock);init_irq_work (&b->irq_work, signal_irq_work); + b->irq_engine = irq_engine; + b->irq_enable = irq_enable; + b->irq_disable = irq_disable; +return b; }@@ -303,9 +293,9 @@ void intel_breadcrumbs_reset(struct intel_breadcrumbs *b)spin_lock_irqsave (&b->irq_lock, flags);if (b->irq_enabled) -irq_enable (b->irq_engine); + b->irq_enable (b);else -irq_disable (b->irq_engine); + b->irq_disable (b);spin_unlock_irqrestore (&b->irq_lock, flags); }@@ -325,11 +315,14 @@ void __intel_breadcrumbs_park(struct intel_breadcrumbs *b) } } -void intel_breadcrumbs_free (struct intel_breadcrumbs *b) +void intel_breadcrumbs_free (struct kref *kref) { +struct intel_breadcrumbs *b =container_of (kref,typeof (*b), ref); +irq_work_sync (&b->irq_work);GEM_BUG_ON (!list_empty (&b->signalers));GEM_BUG_ON (b->irq_armed); +kfree (b); }drivers/gpu/drm/i915/gt/intel_breadcrumbs.h +13
-1@@ -17,7 +17,7 @@ struct intel_breadcrumbs;struct intel_breadcrumbs *intel_breadcrumbs_create (struct intel_engine_cs *irq_engine); -void intel_breadcrumbs_free (struct intel_breadcrumbs *b); +void intel_breadcrumbs_free (struct kref *kref);void intel_breadcrumbs_reset (struct intel_breadcrumbs *b);void __intel_breadcrumbs_park (struct intel_breadcrumbs *b);@@ -48,4 +48,16 @@ void i915_request_cancel_breadcrumb(struct i915_request *request);void intel_context_remove_breadcrumbs (struct intel_context *ce,struct intel_breadcrumbs *b); +static inline struct intel_breadcrumbs * +intel_breadcrumbs_get (struct intel_breadcrumbs *b) +{ +kref_get (&b->ref); +return b; +} + +static inline void intel_breadcrumbs_put (struct intel_breadcrumbs *b) +{ +kref_put (&b->ref, intel_breadcrumbs_free); +} +#endif /* __INTEL_BREADCRUMBS__ */ drivers/gpu/drm/i915/gt/intel_breadcrumbs_types.h +0
-0
drivers/gpu/drm/i915/gt/intel_breadcrumbs_types.h line 15
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_breadcrumbs_types.h +2
-0@@ -7,10 +7,13 @@#define __INTEL_BREADCRUMBS_TYPES__#include <linux/irq_work.h> +#include <linux/kref.h> #include <linux/list.h> #include <linux/spinlock.h> #include <linux/types.h> +typedef u8 intel_engine_mask_t ;
Why not include engine types? Engine mask so belongs there and I wouldn't move it. Especially since over there otherwise a "dangling" #define ALL_ENGINES ((intel_engine_mask_t)~0ul) remains.
Quoted 183 lines
drivers/gpu/drm/i915/gt/intel_breadcrumbs_types.h +5
-0+/* * Rather than have every client wait upon all user interrupts, * with the herd waking after every interrupt and each doing the @@ -29,6 +32,7 @@* the overhead of waking that client is much preferred. */ struct intel_breadcrumbs { +struct kref ref;atomic_t active;spinlock_t signalers_lock;/* protects the list of signalers */ @@ -42,7 +46,10 @@ struct intel_breadcrumbs {bool irq_armed;/* Not all breadcrumbs are attached to physical HW */ +intel_engine_mask_t engine_mask;struct intel_engine_cs *irq_engine; +bool (*irq_enable)(struct intel_breadcrumbs *b); + void (*irq_disable)(struct intel_breadcrumbs *b); };#endif /* __INTEL_BREADCRUMBS_TYPES__ */ drivers/gpu/drm/i915/gt/intel_engine.h +3
-0@@ -209,6 +209,9 @@ void intel_engine_get_instdone(const struct intel_engine_cs *engine,void intel_engine_init_execlists (struct intel_engine_cs *engine); +bool intel_engine_irq_enable (struct intel_engine_cs *engine); +void intel_engine_irq_disable (struct intel_engine_cs *engine); +static inline void __intel_engine_reset (struct intel_engine_cs *engine,bool stalled) {drivers/gpu/drm/i915/gt/intel_engine_cs.c +26
-2@@ -765,7 +765,7 @@ static int engine_setup_common(struct intel_engine_cs *engine) err_cmd_parser:i915_sched_engine_put (engine->sched_engine); err_sched_engine: -intel_breadcrumbs_free (engine->breadcrumbs); +intel_breadcrumbs_put (engine->breadcrumbs); err_status:cleanup_status_page (engine);return err;@@ -965,7 +965,7 @@ void intel_engine_cleanup_common(struct intel_engine_cs *engine) {GEM_BUG_ON (!list_empty (&engine->sched_engine->requests)); -intel_breadcrumbs_free (engine->breadcrumbs); +intel_breadcrumbs_put (engine->breadcrumbs);i915_sched_engine_put (engine->sched_engine);intel_engine_fini_retire (engine);@@ -1320,6 +1320,30 @@ bool intel_engines_are_idle(struct intel_gt *gt)return true; } +bool intel_engine_irq_enable (struct intel_engine_cs *engine) +{ +if (!engine->irq_enable) +return false; + +/* Caller disables interrupts */ +spin_lock (&engine->gt->irq_lock); + engine->irq_enable (engine); +spin_unlock (&engine->gt->irq_lock); + +return true; +} + +void intel_engine_irq_disable (struct intel_engine_cs *engine) +{ +if (!engine->irq_disable) +return ; + +/* Caller disables interrupts */ +spin_lock (&engine->gt->irq_lock); + engine->irq_disable (engine); +spin_unlock (&engine->gt->irq_lock); +} +void intel_engines_reset_default_submission (struct intel_gt *gt) {struct intel_engine_cs *engine;drivers/gpu/drm/i915/gt/intel_engine_types.h +0
-1@@ -64,7 +64,6 @@ struct intel_gt;struct intel_ring ;struct intel_uncore ; -typedef u8 intel_engine_mask_t ;#define ALL_ENGINES ((intel_engine_mask_t)~0ul)struct intel_hw_status_page {drivers/gpu/drm/i915/gt/intel_execlists_submission.c +3
-1@@ -3418,9 +3418,11 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)lrc_fini (&ve->context);intel_context_fini (&ve->context); -intel_breadcrumbs_free (ve->base.breadcrumbs); +if (ve->base.breadcrumbs) +intel_breadcrumbs_put (ve->base.breadcrumbs);if (ve->base.sched_engine)i915_sched_engine_put (ve->base.sched_engine); +intel_engine_free_request_pool (&ve->base);kfree (ve->bonds);drivers/gpu/drm/i915/gt/mock_engine.c +2
-2@@ -284,7 +284,7 @@ static void mock_engine_release(struct intel_engine_cs *engine)GEM_BUG_ON (timer_pending (&mock->hw_delay));i915_sched_engine_put (engine->sched_engine); -intel_breadcrumbs_free (engine->breadcrumbs); +intel_breadcrumbs_put (engine->breadcrumbs);intel_context_unpin (engine->kernel_context);intel_context_put (engine->kernel_context);@@ -376,7 +376,7 @@ int mock_engine_init(struct intel_engine_cs *engine)return 0 ; err_breadcrumbs: -intel_breadcrumbs_free (engine->breadcrumbs); +intel_breadcrumbs_put (engine->breadcrumbs); err_schedule:i915_sched_engine_put (engine->sched_engine);return -ENOMEM ;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +27
-0@@ -1077,6 +1077,9 @@ static void __guc_context_destroy(struct intel_context *ce)struct guc_virtual_engine *ve =container_of (ce,typeof (*ve), context); +if (ve->base.breadcrumbs) +intel_breadcrumbs_put (ve->base.breadcrumbs); +kfree (ve); }else {intel_context_free (ce);@@ -1381,6 +1384,62 @@ static const struct intel_context_ops virtual_guc_context_ops = { .get_sibling = guc_virtual_get_sibling, }; +static bool +guc_irq_enable_breadcrumbs (struct intel_breadcrumbs *b) +{ +struct intel_engine_cs *sibling; +intel_engine_mask_t tmp, mask = b->engine_mask; +bool result = false; + +for_each_engine_masked (sibling, b->irq_engine->gt, mask, tmp) + result |=intel_engine_irq_enable (sibling); + +return result; +} + +static void +guc_irq_disable_breadcrumbs (struct intel_breadcrumbs *b) +{ +struct intel_engine_cs *sibling; +intel_engine_mask_t tmp, mask = b->engine_mask; + +for_each_engine_masked (sibling, b->irq_engine->gt, mask, tmp) +intel_engine_irq_disable (sibling); +} + +static void guc_init_breadcrumbs (struct intel_engine_cs *engine)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static const struct intel_context_ops virtual_guc_context_ops = { · line 1420
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+{ +int i; + +/* +* In GuC submission mode we do not know which physical engine a request +* will be scheduled on, this creates a problem because the breadcrumb +* interrupt is per physical engine. To work around this we attach +* requests and direct all breadcrumb interrupts to the first instance +* of an engine per class. In addition all breadcrumb interrupts are +* enaled / disabled across an engine class in unison.
enabled
So the problem statement only applies to virtual engines but this code runs for physical engines as well..
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static const struct intel_context_ops virtual_guc_context_ops = { · line 1431
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +11
-0+*/ +for (i =0 ; i <MAX_ENGINE_INSTANCE ; ++i) { +struct intel_engine_cs *sibling = + engine->gt->engine_class[engine->class][i]; + +if (sibling) { +if (engine->breadcrumbs != sibling->breadcrumbs) { +intel_breadcrumbs_put (engine->breadcrumbs); + engine->breadcrumbs = +intel_breadcrumbs_get (sibling->breadcrumbs); + }
...and it frees the breadcrumb instances previously created, replacing it with..
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static const struct intel_context_ops virtual_guc_context_ops = { · line 1440
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +9
-0+break ; + } + } + +if (engine->breadcrumbs) { + engine->breadcrumbs->engine_mask |= engine->mask; + engine->breadcrumbs->irq_enable = guc_irq_enable_breadcrumbs; + engine->breadcrumbs->irq_disable = guc_irq_disable_breadcrumbs; + }
...patched up version of the breadcrumbs from the first engine instance?
It's too kludgy in my view. Rather than create and then destroy + patch up, setup code should just do the right thing from the start.
This means if the design is breadcrumbs tree per class, have that created and stored somehwere under gt.guc and then just kref assign if guc is in use instead of creating direct per engine breadcrumbs and then destroying them.
On a related note, it's unfortunate how the very thing which should off load from the CPU is actually creating more work for the CPU in several areas (breadcrumbs, engine serial, CT busy looping, probably more. ...). And we have no idea if and when will it come up overall better.
But yeah, I don't have any ideas on how to do it better on the high level. Clearly interrupts need to be enabled for all engines virtuals are composed off, and clearly there needs to be a single tree of all those so code can find them.
Actually, this approach doesn't work for mixed class virtual engines which were considered at one point. Oh well.. pain for another day.
Regards,
Tvrtko
Quoted 27 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-5+} +static void sanitize_hwsp (struct intel_engine_cs *engine) {struct intel_timeline *tl;@@ -1604,6 +1663,7 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)guc_default_vfuncs (engine);guc_default_irqs (engine); +guc_init_breadcrumbs (engine);if (engine->class ==RENDER_CLASS )rcs_submission_override (engine);@@ -1846,11 +1906,6 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.instance =I915_ENGINE_CLASS_INVALID_VIRTUAL ; ve->base.uabi_instance =I915_ENGINE_CLASS_INVALID_VIRTUAL ; ve->base.saturated =ALL_ENGINES ; - ve->base.breadcrumbs =intel_breadcrumbs_create (&ve->base); -if (!ve->base.breadcrumbs) { -kfree (ve); -return ERR_PTR (-ENOMEM ); - }snprintf (ve->base.name,sizeof (ve->base.name),"virtual" );
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) · line 1961
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0@@ -1899,6 +1954,8 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) sibling->emit_fini_breadcrumb; ve->base.emit_fini_breadcrumb_dw = sibling->emit_fini_breadcrumb_dw; + ve->base.breadcrumbs = +intel_breadcrumbs_get (sibling->breadcrumbs); ve->base.flags |= sibling->flags;
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 64/97 drm/i915/guc: Reset implementation for new GuC interface
In reply to Matthew BrostReset implementation for new GuC interface. This is the legacy reset implementation which is called when the i915 owns the engine hang check. Future patches will offload the engine hang check to GuC but we will continue to maintain this legacy path as a fallback and this code path is also required if the GuC dies.
With the new GuC interface it is not possible to reset individual engines - it is only possible to reset the GPU entirely. This patch forces an entire chip reset if any engine hangs.
--- drivers/gpu/drm/i915/gt/intel_context.c | 3 + drivers/gpu/drm/i915/gt/intel_context_types.h | 7 + drivers/gpu/drm/i915/gt/intel_engine_types.h | 6 + .../drm/i915/gt/intel_execlists_submission.c | 40 ++ drivers/gpu/drm/i915/gt/intel_gt_pm.c | 6 +- drivers/gpu/drm/i915/gt/intel_reset.c | 18 +- .../gpu/drm/i915/gt/intel_ring_submission.c | 22 + drivers/gpu/drm/i915/gt/mock_engine.c | 31 + drivers/gpu/drm/i915/gt/uc/intel_guc.c | 16 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 8 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 580 ++++++++++++++---- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 34 +- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 3 + drivers/gpu/drm/i915/i915_request.c | 41 +- drivers/gpu/drm/i915/i915_request.h | 2 + 15 files changed, 643 insertions(+), 174 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +3 -0
@@ -392,6 +392,9 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)spin_lock_init (&ce->guc_state.lock);INIT_LIST_HEAD (&ce->guc_state.fences); +spin_lock_init (&ce->guc_active.lock); +INIT_LIST_HEAD (&ce->guc_active.requests); + ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link);
drivers/gpu/drm/i915/gt/intel_context_types.h +7 -0
@@ -165,6 +165,13 @@ struct intel_context {struct list_head fences; } guc_state; +struct { +/** lock: protects everything in guc_active */ +spinlock_t lock; +/** requests: active requests on this context */ +struct list_head requests; + } guc_active; +/* GuC scheduling state that does not require a lock. */ atomic_t guc_sched_state_no_lock;
drivers/gpu/drm/i915/gt/intel_engine_types.h +6 -0
@@ -432,6 +432,12 @@ struct intel_engine_cs {*/ void (*release)(struct intel_engine_cs *engine); +/* +* Add / remove request from engine active tracking +*/ +void (*add_active_request)(struct i915_request *rq); +void (*remove_active_request)(struct i915_request *rq); +struct intel_engine_execlists execlists;/*
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +40 -0
@@ -3117,6 +3117,42 @@ static void execlists_park(struct intel_engine_cs *engine)cancel_timer (&engine->execlists.preempt); } +static void add_to_engine (struct i915_request *rq) +{ +lockdep_assert_held (&rq->engine->sched_engine->lock); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->requests); +} + +static void remove_from_engine (struct i915_request *rq) +{ +struct intel_engine_cs *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. +*/ + locked =READ_ONCE (rq->engine); +spin_lock_irq (&locked->sched_engine->lock); +while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { +spin_unlock (&locked->sched_engine->lock); +spin_lock (&engine->sched_engine->lock); + locked = engine; + } +list_del_init (&rq->sched.link); + +clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); +clear_bit (I915_FENCE_FLAG_HOLD , &rq->fence.flags); + +/* Prevent further __await_execution() registering a cb, then flush */ +set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); + +spin_unlock_irq (&locked->sched_engine->lock); + +i915_request_notify_execute_cb_imm (rq); +} +static bool can_preempt (struct intel_engine_cs *engine) {if (INTEL_GEN (engine->i915) >8 )
@@ -3214,6 +3250,8 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; engine->bump_serial = execlist_bump_serial; + engine->add_active_request = add_to_engine; + engine->remove_active_request = remove_from_engine; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;
@@ -3915,6 +3953,8 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.sched_engine->kick_backend = sibling->sched_engine->kick_backend; + ve->base.add_active_request = sibling->add_active_request; + ve->base.remove_active_request = sibling->remove_active_request; 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;
drivers/gpu/drm/i915/gt/intel_gt_pm.c +4 -2
@@ -174,8 +174,6 @@ static void gt_sanitize(struct intel_gt *gt, bool force)if (intel_gt_is_wedged (gt))intel_gt_unset_wedged (gt); -intel_uc_sanitize (>->uc); -for_each_engine (engine, gt, id)if (engine->reset.prepare) engine->reset.prepare (engine);
@@ -191,6 +189,8 @@ static void gt_sanitize(struct intel_gt *gt, bool force)__intel_engine_reset (engine, false); } +intel_uc_reset (>->uc, false); +for_each_engine (engine, gt, id)if (engine->reset.finish) engine->reset.finish (engine);
@@ -243,6 +243,8 @@ int intel_gt_resume(struct intel_gt *gt) goto err_wedged; } +intel_uc_reset_finish (>->uc); +intel_rps_enable (>->rps);intel_llc_enable (>->llc);
drivers/gpu/drm/i915/gt/intel_reset.c +12 -6
@@ -758,6 +758,8 @@ static int gt_reset(struct intel_gt *gt, intel_engine_mask_t stalled_mask)__intel_engine_reset (engine, stalled_mask & engine->mask);local_bh_enable (); +intel_uc_reset (>->uc, true); +intel_ggtt_restore_fences (gt->ggtt);return err;
@@ -782,6 +784,8 @@ static void reset_finish(struct intel_gt *gt, intel_engine_mask_t awake)if (awake & engine->mask)intel_engine_pm_put (engine); } + +intel_uc_reset_finish (>->uc); }static void nop_submit_request (struct i915_request *request)
@@ -835,6 +839,7 @@ static void __intel_gt_set_wedged(struct intel_gt *gt)for_each_engine (engine, gt, id)if (engine->reset.cancel) engine->reset.cancel (engine); +intel_uc_cancel_requests (>->uc);local_bh_enable ();reset_finish (gt, awake);
@@ -1123,6 +1128,9 @@ int __intel_engine_reset_bh(struct intel_engine_cs *engine, const char *msg)ENGINE_TRACE (engine,"flags=%lx\n" , gt->reset.flags);GEM_BUG_ON (!test_bit (I915_RESET_ENGINE + engine->id, >->reset.flags)); +if (intel_engine_uses_guc (engine)) +return -ENODEV ; +if (!intel_engine_pm_get_if_awake (engine))return 0 ;
@@ -1133,13 +1141,10 @@ int __intel_engine_reset_bh(struct intel_engine_cs *engine, const char *msg) "Resetting %s for %s\n", engine->name, msg);atomic_inc (&engine->i915->gpu_error.reset_engine_count[engine->uabi_class]); -if (intel_engine_uses_guc (engine)) - ret =intel_guc_reset_engine (&engine->gt->uc.guc, engine); -else - ret =intel_gt_reset_engine (engine); + ret =intel_gt_reset_engine (engine);if (ret) {/* If we fail here, we expect to fallback to a global reset */ -ENGINE_TRACE (engine,"Failed to reset, err: %d\n" , ret); +ENGINE_TRACE (engine,"Failed to reset %s, err: %d\n" , engine->name, ret); goto out; }
@@ -1273,7 +1278,8 @@ void intel_gt_handle_error(struct intel_gt *gt,* Try engine reset when available. We fall back to full reset if * single reset fails. */ -if (intel_has_reset_engine (gt) && !intel_gt_is_wedged (gt)) { +if (!intel_uc_uses_guc_submission (>->uc) && +intel_has_reset_engine (gt) && !intel_gt_is_wedged (gt)) {local_bh_disable ();for_each_engine_masked (engine, gt, engine_mask, tmp) {BUILD_BUG_ON (I915_RESET_MODESET >=I915_RESET_ENGINE );
drivers/gpu/drm/i915/gt/intel_ring_submission.c +22 -0
@@ -1050,6 +1050,25 @@ static void ring_bump_serial(struct intel_engine_cs *engine) engine->serial++; } +static void add_to_engine (struct i915_request *rq) +{ +lockdep_assert_held (&rq->engine->sched_engine->lock); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->requests); +} + +static void remove_from_engine (struct i915_request *rq) +{ +spin_lock_irq (&rq->engine->sched_engine->lock); +list_del_init (&rq->sched.link); + +/* Prevent further __await_execution() registering a cb, then flush */ +set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); + +spin_unlock_irq (&rq->engine->sched_engine->lock); + +i915_request_notify_execute_cb_imm (rq); +} +static void setup_common (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;
@@ -1067,6 +1086,9 @@ static void setup_common(struct intel_engine_cs *engine) engine->reset.cancel = reset_cancel; engine->reset.finish = reset_finish; + engine->add_active_request = add_to_engine; + engine->remove_active_request = remove_from_engine; + engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; engine->bump_serial = ring_bump_serial;
drivers/gpu/drm/i915/gt/mock_engine.c +31 -0
@@ -235,6 +235,35 @@ static void mock_submit_request(struct i915_request *request)spin_unlock_irqrestore (&engine->hw_lock, flags); } +static void mock_add_to_engine (struct i915_request *rq) +{ +lockdep_assert_held (&rq->engine->sched_engine->lock); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->requests); +} + +static void mock_remove_from_engine (struct i915_request *rq) +{ +struct intel_engine_cs *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. +*/ + + locked =READ_ONCE (rq->engine); +spin_lock_irq (&locked->sched_engine->lock); +while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { +spin_unlock (&locked->sched_engine->lock); +spin_lock (&engine->sched_engine->lock); + locked = engine; + } +list_del_init (&rq->sched.link); +spin_unlock_irq (&locked->sched_engine->lock); +} + +static void mock_reset_prepare (struct intel_engine_cs *engine) { }
@@ -327,6 +356,8 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request; + engine->base.add_active_request = mock_add_to_engine; + engine->base.remove_active_request = mock_remove_from_engine; engine->base.reset.prepare = mock_reset_prepare; engine->base.reset.rewind = mock_reset_rewind;
drivers/gpu/drm/i915/gt/uc/intel_guc.c +3 -13
@@ -146,6 +146,9 @@ static void gen11_disable_guc_interrupts(struct intel_guc *guc) {struct intel_gt *gt =guc_to_gt (guc); +if (!guc->interrupts.enabled) +return ; +spin_lock_irq (>->irq_lock); guc->interrupts.enabled = false;
@@ -579,19 +582,6 @@ int intel_guc_suspend(struct intel_guc *guc)return 0 ; } -/** -* intel_guc_reset_engine() - ask GuC to reset an engine -* @guc: intel_guc structure -* @engine: engine to be reset -*/ -int intel_guc_reset_engine (struct intel_guc *guc, -struct intel_engine_cs *engine) -{ -/* XXX: to be implemented with submission interface rework */ - -return -ENODEV ; -} -/** * intel_guc_resume() - notify GuC resuming from suspend state * @guc: the guc
drivers/gpu/drm/i915/gt/uc/intel_guc.h +5 -3
@@ -243,14 +243,16 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); -int intel_guc_reset_engine (struct intel_guc *guc, -struct intel_engine_cs *engine); -int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len);int intel_guc_sched_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len); +void intel_guc_submission_reset_prepare (struct intel_guc *guc); +void intel_guc_submission_reset (struct intel_guc *guc,bool stalled); +void intel_guc_submission_reset_finish (struct intel_guc *guc); +void intel_guc_submission_cancel_requests (struct intel_guc *guc); +void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);#endif
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +468 -112
876 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_uc.c +33 -1
@@ -565,12 +565,44 @@ void intel_uc_reset_prepare(struct intel_uc *uc) {struct intel_guc *guc = &uc->guc; +/* Firmware expected to be running when this function is called */ if (!intel_guc_is_ready (guc)) -return ; + goto sanitize; + +if (intel_uc_uses_guc_submission (uc)) +intel_guc_submission_reset_prepare (guc); +sanitize:__uc_sanitize (uc); } +void intel_uc_reset (struct intel_uc *uc,bool stalled) +{ +struct intel_guc *guc = &uc->guc; + +/* Firmware can not be running when this function is called */ +if (intel_uc_uses_guc_submission (uc)) +intel_guc_submission_reset (guc, stalled); +} + +void intel_uc_reset_finish (struct intel_uc *uc) +{ +struct intel_guc *guc = &uc->guc; + +/* Firmware expected to be running when this function is called */ +if (intel_guc_is_fw_running (guc) &&intel_uc_uses_guc_submission (uc)) +intel_guc_submission_reset_finish (guc); +} + +void intel_uc_cancel_requests (struct intel_uc *uc) +{ +struct intel_guc *guc = &uc->guc; + +/* Firmware can not be running when this function is called */ +if (intel_uc_uses_guc_submission (uc)) +intel_guc_submission_cancel_requests (guc); +} +void intel_uc_runtime_suspend (struct intel_uc *uc) {struct intel_guc *guc = &uc->guc;
drivers/gpu/drm/i915/gt/uc/intel_uc.h +3 -0
@@ -37,6 +37,9 @@ void intel_uc_driver_late_release(struct intel_uc *uc);void intel_uc_driver_remove (struct intel_uc *uc);void intel_uc_init_mmio (struct intel_uc *uc);void intel_uc_reset_prepare (struct intel_uc *uc); +void intel_uc_reset (struct intel_uc *uc,bool stalled); +void intel_uc_reset_finish (struct intel_uc *uc); +void intel_uc_cancel_requests (struct intel_uc *uc);void intel_uc_suspend (struct intel_uc *uc);void intel_uc_runtime_suspend (struct intel_uc *uc);int intel_uc_resume (struct intel_uc *uc);
drivers/gpu/drm/i915/i915_request.c +4 -37
71 lines not on this page · raw message
drivers/gpu/drm/i915/i915_request.h +2 -0
@@ -649,4 +649,6 @@ bool i915_request_active_engine(struct i915_request *rq, struct intel_engine_cs **active); +void i915_request_notify_execute_cb_imm (struct i915_request *rq); +#endif /* I915_REQUEST_H */
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 64/97] drm/i915/guc: Reset implementation for new GuC interface
Quoted 49 lines · Matthew Brost
Reset implementation for new GuC interface. This is the legacy reset implementation which is called when the i915 owns the engine hang check. Future patches will offload the engine hang check to GuC but we will continue to maintain this legacy path as a fallback and this code path is also required if the GuC dies.
With the new GuC interface it is not possible to reset individual engines - it is only possible to reset the GPU entirely. This patch forces an entire chip reset if any engine hangs.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 3 + drivers/gpu/drm/i915/gt/intel_context_types.h | 7 + drivers/gpu/drm/i915/gt/intel_engine_types.h | 6 + .../drm/i915/gt/intel_execlists_submission.c | 40 ++ drivers/gpu/drm/i915/gt/intel_gt_pm.c | 6 +- drivers/gpu/drm/i915/gt/intel_reset.c | 18 +- .../gpu/drm/i915/gt/intel_ring_submission.c | 22 + drivers/gpu/drm/i915/gt/mock_engine.c | 31 + drivers/gpu/drm/i915/gt/uc/intel_guc.c | 16 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 8 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 580 ++++++++++++++---- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 34 +- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 3 + drivers/gpu/drm/i915/i915_request.c | 41 +- drivers/gpu/drm/i915/i915_request.h | 2 + 15 files changed, 643 insertions(+), 174 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +3
-0@@ -392,6 +392,9 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)spin_lock_init (&ce->guc_state.lock);INIT_LIST_HEAD (&ce->guc_state.fences); +spin_lock_init (&ce->guc_active.lock); +INIT_LIST_HEAD (&ce->guc_active.requests); + ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link);drivers/gpu/drm/i915/gt/intel_context_types.h +0
-0
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 173
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +6
-0@@ -165,6 +165,13 @@ struct intel_context {struct list_head fences; } guc_state; +struct { +/** lock: protects everything in guc_active */ +spinlock_t lock; +/** requests: active requests on this context */ +struct list_head requests; + } guc_active;
More accounting, yeah, this is more of that where GuC gives with one hand and takes away with the other. :(
Quoted 42 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +1
-0+/* GuC scheduling state that does not require a lock. */ atomic_t guc_sched_state_no_lock;drivers/gpu/drm/i915/gt/intel_engine_types.h +6
-0@@ -432,6 +432,12 @@ struct intel_engine_cs {*/ void (*release)(struct intel_engine_cs *engine); +/* +* Add / remove request from engine active tracking +*/ +void (*add_active_request)(struct i915_request *rq); +void (*remove_active_request)(struct i915_request *rq); +struct intel_engine_execlists execlists;/* drivers/gpu/drm/i915/gt/intel_execlists_submission.c +13
-0@@ -3117,6 +3117,42 @@ static void execlists_park(struct intel_engine_cs *engine)cancel_timer (&engine->execlists.preempt); } +static void add_to_engine (struct i915_request *rq) +{ +lockdep_assert_held (&rq->engine->sched_engine->lock); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->requests); +} + +static void remove_from_engine (struct i915_request *rq) +{ +struct intel_engine_cs *engine, *locked; + +/* +* Virtual engines complicate acquiring the engine timeline lock, +* as their rq->engine pointer is not stable until under that
drivers/gpu/drm/i915/gt/intel_execlists_submission.c static void execlists_park(struct intel_engine_cs *engine) · line 3142
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +10
-0+* engine lock. The simple ploy we use is to take the lock then +* check that the rq still belongs to the newly locked engine. +*/ + locked =READ_ONCE (rq->engine); +spin_lock_irq (&locked->sched_engine->lock); +while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { +spin_unlock (&locked->sched_engine->lock); +spin_lock (&engine->sched_engine->lock); + locked = engine; + }
Could use i915_request_active_engine although tbf I don't remember why I did not convert all callers when I added it. Perhaps I just did not find them all.
Quoted 122 lines
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +17
-0+list_del_init (&rq->sched.link); + +clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); +clear_bit (I915_FENCE_FLAG_HOLD , &rq->fence.flags); + +/* Prevent further __await_execution() registering a cb, then flush */ +set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); + +spin_unlock_irq (&locked->sched_engine->lock); + +i915_request_notify_execute_cb_imm (rq); +} +static bool can_preempt (struct intel_engine_cs *engine) {if (INTEL_GEN (engine->i915) >8 )@@ -3214,6 +3250,8 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; engine->bump_serial = execlist_bump_serial; + engine->add_active_request = add_to_engine; + engine->remove_active_request = remove_from_engine; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;@@ -3915,6 +3953,8 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.sched_engine->kick_backend = sibling->sched_engine->kick_backend; + ve->base.add_active_request = sibling->add_active_request; + ve->base.remove_active_request = sibling->remove_active_request; 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;drivers/gpu/drm/i915/gt/intel_gt_pm.c +4
-2@@ -174,8 +174,6 @@ static void gt_sanitize(struct intel_gt *gt, bool force)if (intel_gt_is_wedged (gt))intel_gt_unset_wedged (gt); -intel_uc_sanitize (>->uc); -for_each_engine (engine, gt, id)if (engine->reset.prepare) engine->reset.prepare (engine);@@ -191,6 +189,8 @@ static void gt_sanitize(struct intel_gt *gt, bool force)__intel_engine_reset (engine, false); } +intel_uc_reset (>->uc, false); +for_each_engine (engine, gt, id)if (engine->reset.finish) engine->reset.finish (engine);@@ -243,6 +243,8 @@ int intel_gt_resume(struct intel_gt *gt) goto err_wedged; } +intel_uc_reset_finish (>->uc); +intel_rps_enable (>->rps);intel_llc_enable (>->llc);drivers/gpu/drm/i915/gt/intel_reset.c +10
-5@@ -758,6 +758,8 @@ static int gt_reset(struct intel_gt *gt, intel_engine_mask_t stalled_mask)__intel_engine_reset (engine, stalled_mask & engine->mask);local_bh_enable (); +intel_uc_reset (>->uc, true); +intel_ggtt_restore_fences (gt->ggtt);return err;@@ -782,6 +784,8 @@ static void reset_finish(struct intel_gt *gt, intel_engine_mask_t awake)if (awake & engine->mask)intel_engine_pm_put (engine); } + +intel_uc_reset_finish (>->uc); }static void nop_submit_request (struct i915_request *request)@@ -835,6 +839,7 @@ static void __intel_gt_set_wedged(struct intel_gt *gt)for_each_engine (engine, gt, id)if (engine->reset.cancel) engine->reset.cancel (engine); +intel_uc_cancel_requests (>->uc);local_bh_enable ();reset_finish (gt, awake);@@ -1123,6 +1128,9 @@ int __intel_engine_reset_bh(struct intel_engine_cs *engine, const char *msg)ENGINE_TRACE (engine,"flags=%lx\n" , gt->reset.flags);GEM_BUG_ON (!test_bit (I915_RESET_ENGINE + engine->id, >->reset.flags)); +if (intel_engine_uses_guc (engine)) +return -ENODEV ; +if (!intel_engine_pm_get_if_awake (engine))return 0 ;@@ -1133,13 +1141,10 @@ int __intel_engine_reset_bh(struct intel_engine_cs *engine, const char *msg) "Resetting %s for %s\n", engine->name, msg);atomic_inc (&engine->i915->gpu_error.reset_engine_count[engine->uabi_class]); -if (intel_engine_uses_guc (engine)) - ret =intel_guc_reset_engine (&engine->gt->uc.guc, engine); -else - ret =intel_gt_reset_engine (engine); + ret =intel_gt_reset_engine (engine);if (ret) {/* If we fail here, we expect to fallback to a global reset */ -ENGINE_TRACE (engine,"Failed to reset, err: %d\n" , ret); +ENGINE_TRACE (engine,"Failed to reset %s, err: %d\n" , engine->name, ret); goto out; }
drivers/gpu/drm/i915/gt/intel_reset.c void intel_gt_handle_error(struct intel_gt *gt, · line 1282
Quoted 6 lines
drivers/gpu/drm/i915/gt/intel_reset.c +2
-1@@ -1273,7 +1278,8 @@ void intel_gt_handle_error(struct intel_gt *gt,* Try engine reset when available. We fall back to full reset if * single reset fails. */ -if (intel_has_reset_engine (gt) && !intel_gt_is_wedged (gt)) { +if (!intel_uc_uses_guc_submission (>->uc) && +intel_has_reset_engine (gt) && !intel_gt_is_wedged (gt)) {
If with guc driver cannot do engine reset, could intel_has_reset_engine just say false in that case so guc check wouldn't have to be added here? Also noticed this is the same open I had in 2019. and someone said it can and would be folded. ;(
Quoted 298 lines
drivers/gpu/drm/i915/gt/intel_reset.c +0
-0local_bh_disable ();for_each_engine_masked (engine, gt, engine_mask, tmp) {BUILD_BUG_ON (I915_RESET_MODESET >=I915_RESET_ENGINE );drivers/gpu/drm/i915/gt/intel_ring_submission.c +22
-0@@ -1050,6 +1050,25 @@ static void ring_bump_serial(struct intel_engine_cs *engine) engine->serial++; } +static void add_to_engine (struct i915_request *rq) +{ +lockdep_assert_held (&rq->engine->sched_engine->lock); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->requests); +} + +static void remove_from_engine (struct i915_request *rq) +{ +spin_lock_irq (&rq->engine->sched_engine->lock); +list_del_init (&rq->sched.link); + +/* Prevent further __await_execution() registering a cb, then flush */ +set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); + +spin_unlock_irq (&rq->engine->sched_engine->lock); + +i915_request_notify_execute_cb_imm (rq); +} +static void setup_common (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;@@ -1067,6 +1086,9 @@ static void setup_common(struct intel_engine_cs *engine) engine->reset.cancel = reset_cancel; engine->reset.finish = reset_finish; + engine->add_active_request = add_to_engine; + engine->remove_active_request = remove_from_engine; + engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; engine->bump_serial = ring_bump_serial;drivers/gpu/drm/i915/gt/mock_engine.c +31
-0@@ -235,6 +235,35 @@ static void mock_submit_request(struct i915_request *request)spin_unlock_irqrestore (&engine->hw_lock, flags); } +static void mock_add_to_engine (struct i915_request *rq) +{ +lockdep_assert_held (&rq->engine->sched_engine->lock); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->requests); +} + +static void mock_remove_from_engine (struct i915_request *rq) +{ +struct intel_engine_cs *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. +*/ + + locked =READ_ONCE (rq->engine); +spin_lock_irq (&locked->sched_engine->lock); +while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { +spin_unlock (&locked->sched_engine->lock); +spin_lock (&engine->sched_engine->lock); + locked = engine; + } +list_del_init (&rq->sched.link); +spin_unlock_irq (&locked->sched_engine->lock); +} + +static void mock_reset_prepare (struct intel_engine_cs *engine) { }@@ -327,6 +356,8 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request; + engine->base.add_active_request = mock_add_to_engine; + engine->base.remove_active_request = mock_remove_from_engine; engine->base.reset.prepare = mock_reset_prepare; engine->base.reset.rewind = mock_reset_rewind;drivers/gpu/drm/i915/gt/uc/intel_guc.c +3
-13@@ -146,6 +146,9 @@ static void gen11_disable_guc_interrupts(struct intel_guc *guc) {struct intel_gt *gt =guc_to_gt (guc); +if (!guc->interrupts.enabled) +return ; +spin_lock_irq (>->irq_lock); guc->interrupts.enabled = false;@@ -579,19 +582,6 @@ int intel_guc_suspend(struct intel_guc *guc)return 0 ; } -/** -* intel_guc_reset_engine() - ask GuC to reset an engine -* @guc: intel_guc structure -* @engine: engine to be reset -*/ -int intel_guc_reset_engine (struct intel_guc *guc, -struct intel_engine_cs *engine) -{ -/* XXX: to be implemented with submission interface rework */ - -return -ENODEV ; -} -/** * intel_guc_resume() - notify GuC resuming from suspend state * @guc: the guc drivers/gpu/drm/i915/gt/uc/intel_guc.h +5
-3@@ -243,14 +243,16 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); -int intel_guc_reset_engine (struct intel_guc *guc, -struct intel_engine_cs *engine); -int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len);int intel_guc_sched_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len); +void intel_guc_submission_reset_prepare (struct intel_guc *guc); +void intel_guc_submission_reset (struct intel_guc *guc,bool stalled); +void intel_guc_submission_reset_finish (struct intel_guc *guc); +void intel_guc_submission_cancel_requests (struct intel_guc *guc); +void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);#endif drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +57
-15@@ -140,7 +140,7 @@ context_wait_for_deregister_to_register(struct intel_context *ce)static inline void set_context_wait_for_deregister_to_register (struct intel_context *ce) { -/* Only should be called from guc_lrc_desc_pin() */ +/* Only should be called from guc_lrc_desc_pin() without lock */ ce->guc_state.sched_state |=SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ; }@@ -240,15 +240,31 @@ static int guc_lrc_desc_pool_create(struct intel_guc *guc)static void guc_lrc_desc_pool_destroy (struct intel_guc *guc) { + guc->lrc_desc_pool_vaddr =NULL ;i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline bool guc_submission_initialized (struct intel_guc *guc) +{ +return guc->lrc_desc_pool_vaddr !=NULL ; +} +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) { -struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); +if (likely (guc_submission_initialized (guc))) { +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); +unsigned long flags; -memset (desc,0 ,sizeof (*desc)); -xa_erase_irq (&guc->context_lookup, id); +memset (desc,0 ,sizeof (*desc)); + +/* +* xarray API doesn't have xa_erase_irqsave wrapper, so calling +* the lower level functions directly. +*/ +xa_lock_irqsave (&guc->context_lookup, flags); +__xa_erase (&guc->context_lookup, id); +xa_unlock_irqrestore (&guc->context_lookup, flags); + } }static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id)@@ -259,7 +275,15 @@ static inline bool lrc_desc_registered(struct intel_guc *guc, u32 id)static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id,struct intel_context *ce) { -xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +unsigned long flags; + +/* +* xarray API doesn't have xa_save_irqsave wrapper, so calling the +* lower level functions directly. +*/ +xa_lock_irqsave (&guc->context_lookup, flags); +__xa_store (&guc->context_lookup, id, ce,GFP_ATOMIC ); +xa_unlock_irqrestore (&guc->context_lookup, flags); } static int guc_submission_busy_loop(struct intel_guc* guc,@@ -330,6 +354,8 @@ int intel_guc_wait_for_idle(struct intel_guc *guc, long timeout) interruptible, timeout); } +static int guc_lrc_desc_pin (struct intel_context *ce,bool loop); +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -337,11 +363,22 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)u32 action[3 ];int len =0 ;u32 g2h_len_dw =0 ; -bool enabled =context_enabled (ce); +bool enabled;GEM_BUG_ON (!atomic_read (&ce->guc_id_ref));GEM_BUG_ON (context_guc_id_invalid (ce)); +/* +* Corner case where the GuC firmware was blown away and reloaded while +* this context was pinned. +*/ +if (unlikely (!lrc_desc_registered (guc, ce->guc_id))) { + err =guc_lrc_desc_pin (ce, false); +if (unlikely (err)) + goto out; + } + enabled =context_enabled (ce); +if (!enabled) { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; action[len++] = ce->guc_id;@@ -364,6 +401,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)intel_context_put (ce); } +out:return err; }@@ -418,15 +456,10 @@ static int guc_dequeue_one_context(struct intel_guc *guc)if (submit) {guc_set_lrc_tail (last); resubmit: -/* -* We only check for -EBUSY here even though it is possible for -* -EDEADLK to be returned. If -EDEADLK is returned, the GuC has -* died and a full GPU needs to be done. The hangcheck will -* eventually detect that the GuC has died and trigger this -* reset so no need to handle -EDEADLK here. -*/ ret =guc_add_request (guc, last); -if (ret == -EBUSY ) { +if (unlikely (ret == -EDEADLK )) + goto deadlk; +else if (ret == -EBUSY ) {i915_sched_engine_kick (sched_engine); guc->stalled_request = last;return false;@@ -436,6 +469,11 @@ static int guc_dequeue_one_context(struct intel_guc *guc) guc->stalled_request =NULL ;return submit; + +deadlk: + sched_engine->tasklet.callback =NULL ; +tasklet_disable_nosync (&sched_engine->tasklet); +return false; }static void guc_submission_tasklet (struct tasklet_struct *t)@@ -462,29 +500,165 @@ static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir)intel_engine_signal_breadcrumbs (engine); } -static void guc_reset_prepare (struct intel_engine_cs *engine) +static void __guc_context_destroy (struct intel_context *ce); +static void release_guc_id (struct intel_guc *guc,struct intel_context *ce); +static void guc_signal_context_fence (struct intel_context *ce); + +static void scrub_guc_desc_for_outstanding_g2h (struct intel_guc *guc) {
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 516
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-2-struct i915_sched_engine *const sched_engine = engine->sched_engine; +struct intel_context *ce; +unsigned long index, flags; +bool pending_disable, pending_enable, deregister, destroyed; -ENGINE_TRACE (engine,"\n" ); +xa_for_each (&guc->context_lookup, index, ce) { +/* Flush context */ +spin_lock_irqsave (&ce->guc_state.lock, flags); +spin_unlock_irqrestore (&ce->guc_state.lock, flags);
Very unusual pattern - what does it do?
Quoted 23 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +23
-0+ +/* +* Once we are at this point submission_disabled() is guaranteed +* to visible to all callers who set the below flags (see above +* flush and flushes in reset_prepare). If submission_disabled() +* is set, the caller shouldn't set these flags. +*/ + + destroyed =context_destroyed (ce); + pending_enable =context_pending_enable (ce); + pending_disable =context_pending_disable (ce); + deregister =context_wait_for_deregister_to_register (ce); +init_sched_state (ce); + +if (pending_enable || destroyed || deregister) { +atomic_dec (&guc->outstanding_submission_g2h); +if (deregister) +guc_signal_context_fence (ce); +if (destroyed) { +release_guc_id (guc, ce); +__guc_context_destroy (ce); + } +if (pending_enable|| deregister)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 549
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+intel_context_put (ce); + } + +/* Not mutualy exclusive with above if statement. */ +if (pending_disable) { +guc_signal_context_fence (ce); +intel_context_sched_disable_unpin (ce); +atomic_dec (&guc->outstanding_submission_g2h); +intel_context_put (ce); + }
Yeah this function is a taste of the taste machine I think is _extremely_ hard to review and know with any confidence it does the right thing.
Quoted 20 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +20
-0+ } +} + +static inline bool +submission_disabled (struct intel_guc *guc) +{ +struct i915_sched_engine *const sched_engine = guc->sched_engine; + +return unlikely (!__tasklet_is_enabled (&sched_engine->tasklet)); +} + +static void disable_submission (struct intel_guc *guc) +{ +struct i915_sched_engine *const sched_engine = guc->sched_engine; + +if (__tasklet_is_enabled (&sched_engine->tasklet)) { +GEM_BUG_ON (!guc->ct.enabled); +__tasklet_disable_sync_once (&sched_engine->tasklet); + sched_engine->tasklet.callback =NULL ; + }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 579
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+} + +static void enable_submission (struct intel_guc *guc) +{ +struct i915_sched_engine *const sched_engine = guc->sched_engine; +unsigned long flags; + +spin_lock_irqsave (&guc->sched_engine->lock, flags); + sched_engine->tasklet.callback = guc_submission_tasklet; +wmb ();
All memory barriers must be documented.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0+if (!__tasklet_is_enabled (&sched_engine->tasklet) && +__tasklet_enable (&sched_engine->tasklet)) { +GEM_BUG_ON (!guc->ct.enabled); + +/* And kick in case we missed a new request submission. */ +i915_sched_engine_hi_kick (sched_engine); + }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 596
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+spin_unlock_irqrestore (&guc->sched_engine->lock, flags); +} + +static void guc_flush_submissions (struct intel_guc *guc) +{ +struct i915_sched_engine *const sched_engine = guc->sched_engine; +unsigned long flags; + +spin_lock_irqsave (&sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags);
Oh right, more of this. No idea.
Quoted 24 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +18
-4+} + +void intel_guc_submission_reset_prepare (struct intel_guc *guc) +{ +int i; + +if (unlikely (!guc_submission_initialized (guc))) +/* Reset called during driver load? GuC not yet initialised! */ +return ; + +disable_submission (guc); + guc->interrupts.disable (guc); + +/* Flush IRQ handler */ +spin_lock_irq (&guc_to_gt (guc)->irq_lock); +spin_unlock_irq (&guc_to_gt (guc)->irq_lock); + +guc_flush_submissions (guc);/* -* Prevent request submission to the hardware until we have -* completed the reset in i915_gem_reset_finish(). If a request -* is completed by one engine, it may then queue a request -* to a second via its sched_engine->tasklet *just* as we are
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 622
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-4-* calling engine->init_hw() and also writing the ELSP. -* Turning off the sched_engine->tasklet until the reset is over -* prevents the race. +* Handle any outstanding G2Hs before reset. Call IRQ handler directly +* each pass as interrupt have been disabled. We always scrub for +* outstanding G2H as it is possible for outstanding_submission_g2h to +* be incremented after the context state update. */ -__tasklet_disable_sync_once (&sched_engine->tasklet); +for (i =0 ; i <4 &&atomic_read (&guc->outstanding_submission_g2h); ++i) {
Why is four the magic number and what happens if it is not enough?
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+intel_guc_to_host_event_handler (guc); +#define wait_for_reset (guc, wait_var) \ + guc_wait_for_pending_msg(guc, wait_var, false, (HZ / 20)) +do { +wait_for_reset (guc, &guc->outstanding_submission_g2h); + }while (!list_empty (&guc->ct.requests.incoming)); + } +scrub_guc_desc_for_outstanding_g2h (guc); +} +
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 642
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+static struct intel_engine_cs * +guc_virtual_get_sibling (struct intel_engine_cs *ve,unsigned int sibling) +{ +struct intel_engine_cs *engine; +intel_engine_mask_t tmp, mask = ve->mask; +unsigned int num_siblings =0 ; + +for_each_engine_masked (engine, ve->gt, mask, tmp) +if (num_siblings++ == sibling) +return engine;
Not sure how often is this used overall and whether just storing the array in ve could be justified.
Quoted 52 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +31
-8+ +return NULL ; +} + +static inline struct intel_engine_cs * +__context_to_physical_engine (struct intel_context *ce) +{ +struct intel_engine_cs *engine = ce->engine; + +if (intel_engine_is_virtual (engine)) + engine =guc_virtual_get_sibling (engine,0 ); + +return engine; } -static void guc_reset_state (struct intel_context *ce, -struct intel_engine_cs *engine, -u32 head, -bool scrub) +static void guc_reset_state (struct intel_context *ce,u32 head,bool scrub) { +struct intel_engine_cs *engine =__context_to_physical_engine (ce); +GEM_BUG_ON (!intel_context_is_pinned (ce));/* @@ -502,42 +676,147 @@ static void guc_reset_state(struct intel_context *ce,lrc_update_regs (ce, engine, head); } -static void guc_reset_rewind (struct intel_engine_cs *engine,bool stalled) +static void guc_reset_nop (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_request *rq; +} + +static void guc_rewind_nop (struct intel_engine_cs *engine,bool stalled) +{ +} + +static void +__unwind_incomplete_requests (struct intel_context *ce) +{ +struct i915_request *rq, *rn; +struct list_head *pl; +int prio =I915_PRIORITY_INVALID ; +struct i915_sched_engine *const sched_engine = + ce->engine->sched_engine;unsigned long flags; -spin_lock_irqsave (&engine->sched_engine->lock, flags);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_reset_state(struct intel_context *ce, · line 706
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+spin_lock_irqsave (&sched_engine->lock, flags); +spin_lock (&ce->guc_active.lock); +list_for_each_entry_safe (rq, rn, + &ce->guc_active.requests, + sched.link) { +if (i915_request_completed (rq)) +continue ; + +list_del_init (&rq->sched.link); +spin_unlock (&ce->guc_active.lock);
Drops the lock and continues iterating the same list is safe? Comment needed I think and I do remember I worried about this, or similar instances, in GuC code before.
Quoted 97 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +83
-7+ +__i915_request_unsubmit (rq); + +/* Push the request back into the queue for later resubmission. */ +GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID ); +if (rq_prio (rq) != prio) { + prio =rq_prio (rq); + pl =i915_sched_lookup_priolist (sched_engine, prio); + } +GEM_BUG_ON (i915_sched_engine_is_empty (sched_engine)); -/* Push back any incomplete requests for replay after the reset. */ - rq =execlists_unwind_incomplete_requests (execlists); -if (!rq) - goto out_unlock; +list_add_tail (&rq->sched.link, pl); +set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); + +spin_lock (&ce->guc_active.lock); + } +spin_unlock (&ce->guc_active.lock); +spin_unlock_irqrestore (&sched_engine->lock, flags); +} + +static struct i915_request *context_find_active_request (struct intel_context *ce) +{ +struct i915_request *rq, *active =NULL ; +unsigned long flags; + +spin_lock_irqsave (&ce->guc_active.lock, flags); +list_for_each_entry_reverse (rq, &ce->guc_active.requests, + sched.link) { +if (i915_request_completed (rq)) +break ; + + active = rq; + } +spin_unlock_irqrestore (&ce->guc_active.lock, flags); + +return active; +} + +static void __guc_reset_context (struct intel_context *ce,bool stalled) +{ +struct i915_request *rq; +u32 head; + +/* +* GuC will implicitly mark the context as non-schedulable +* when it sends the reset notification. Make sure our state +* reflects this change. The context will be marked enabled +* on resubmission. +*/ +clr_context_enabled (ce); + + rq =context_find_active_request (ce); +if (!rq) { + head = ce->ring->tail; + stalled = false; + goto out_replay; + }if (!i915_request_started (rq)) stalled = false; +GEM_BUG_ON (i915_active_is_idle (&ce->active)); + head =intel_ring_wrap (ce->ring, rq->head);__i915_request_reset (rq, stalled); -guc_reset_state (rq->context, engine, rq->head, stalled); -out_unlock: -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +out_replay: +guc_reset_state (ce, head, stalled); +__unwind_incomplete_requests (ce); +} + +void intel_guc_submission_reset (struct intel_guc *guc,bool stalled) +{ +struct intel_context *ce; +unsigned long index; + +if (unlikely (!guc_submission_initialized (guc))) +/* Reset called during driver load? GuC not yet initialised! */ +return ; + +xa_for_each (&guc->context_lookup, index, ce) +if (intel_context_is_pinned (ce)) +__guc_reset_context (ce, stalled); + +/* GuC is blown away, drop all references to contexts */ +xa_destroy (&guc->context_lookup); +} + +static void guc_cancel_context_requests (struct intel_context *ce) +{ +struct i915_sched_engine *sched_engine =ce_to_guc (ce)->sched_engine;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_reset_state(struct intel_context *ce, · line 806
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+struct i915_request *rq; +unsigned long flags; + +/* Mark all executing requests as skipped. */ +spin_lock_irqsave (&sched_engine->lock, flags); +spin_lock (&ce->guc_active.lock); +list_for_each_entry (rq, &ce->guc_active.requests, sched.link) +i915_request_put (i915_request_mark_eio (rq)); +spin_unlock (&ce->guc_active.lock); +spin_unlock_irqrestore (&sched_engine->lock, flags);
I suppose somewhere it will need to be documented what are the two locks protecting and why both are needed at some places.
Quoted 81 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +25
-20} -static void guc_reset_cancel (struct intel_engine_cs *engine) +static void +guc_cancel_sched_engine_requests (struct i915_sched_engine *sched_engine) { -struct i915_sched_engine *const sched_engine = engine->sched_engine;struct i915_request *rq, *rn;struct rb_node *rb;unsigned long flags;/* Can be called during boot if GuC fails to load */ -if (!engine->gt) +if (!sched_engine)return ; -ENGINE_TRACE (engine,"\n" ); -/* * Before we call engine->cancel_requests(), we should have exclusive * access to the submission state. This is arranged for us by the @@ -552,13 +831,7 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)* submission's irq state, we also wish to remind ourselves that * it is irq state.) */ -spin_lock_irqsave (&engine->sched_engine->lock, flags); - -/* Mark all executing requests as skipped. */ -list_for_each_entry (rq, &engine->sched_engine->requests, sched.link) { -i915_request_set_error_once (rq, -EIO ); -i915_request_mark_complete (rq); - } +spin_lock_irqsave (&sched_engine->lock, flags);/* Flush the queued requests to the timeline list (for retiring). */ while ((rb =rb_first_cached (&sched_engine->queue))) {@@ -566,9 +839,10 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)priolist_for_each_request_consume (rq, rn, p) {list_del_init (&rq->sched.link); +__i915_request_submit (rq); -dma_fence_set_error (&rq->fence, -EIO ); -i915_request_mark_complete (rq); + +i915_request_put (i915_request_mark_eio (rq)); }rb_erase_cached (&p->node, &sched_engine->queue);@@ -580,19 +854,41 @@ static void guc_reset_cancel(struct intel_engine_cs *engine) sched_engine->queue_priority_hint =INT_MIN ; sched_engine->queue =RB_ROOT_CACHED ; -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); } -static void guc_reset_finish (struct intel_engine_cs *engine) +void intel_guc_submission_cancel_requests (struct intel_guc *guc) { -struct i915_sched_engine *const sched_engine = engine->sched_engine; +struct intel_context *ce; +unsigned long index; -if (__tasklet_enable (&sched_engine->tasklet)) -/* And kick in case we missed a new request submission. */ -i915_sched_engine_hi_kick (sched_engine); +xa_for_each (&guc->context_lookup, index, ce) +if (intel_context_is_pinned (ce)) +guc_cancel_context_requests (ce); + +guc_cancel_sched_engine_requests (guc->sched_engine); + +/* GuC is blown away, drop all references to contexts */ +xa_destroy (&guc->context_lookup); +} + +void intel_guc_submission_reset_finish (struct intel_guc *guc) +{ +/* Reset called during driver load or during wedge? */ + if (unlikely(!guc_submission_initialized(guc) ||
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_reset_cancel(struct intel_engine_cs *engine) · line 886
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-2+ test_bit(I915_WEDGED, &guc_to_gt(guc)->reset.flags))) + return; -ENGINE_TRACE (engine,"depth->%d\n" , -atomic_read (&sched_engine->tasklet.count)); +/* +* Technically possible for either of these values to be non-zero here, +* but very unlikely + harmless. Regardless let's add a warn so we can +* see in CI if this happens frequently / a precursor to taking down the +* machine.
And what did CI say over time this was in?
It needs to be explained when it can be non zero and whether or not it can go to non zero just after the atomic_set below. Or if not why not.
Quoted 99 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +21
-10+*/ +GEM_WARN_ON (atomic_read (&guc->outstanding_submission_g2h)); +atomic_set (&guc->outstanding_submission_g2h,0 ); + +enable_submission (guc); }/* @@ -659,6 +955,9 @@ static int guc_bypass_tasklet_submit(struct intel_guc *guc,else trace_i915_request_guc_submit (rq); +if (unlikely (ret == -EDEADLK )) +disable_submission (guc); +return ret; }@@ -671,7 +970,8 @@ static void guc_submit_request(struct i915_request *rq)/* Will be called from irq-context when using foreign fences. */ spin_lock_irqsave (&sched_engine->lock, flags); -if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) +if (submission_disabled (guc) || guc->stalled_request || + !i915_sched_engine_is_empty (sched_engine))queue_request (sched_engine, rq,rq_prio (rq));else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY )i915_sched_engine_hi_kick (sched_engine);@@ -808,7 +1108,8 @@ static void unpin_guc_id(struct intel_guc *guc, struct intel_context *ce)static int __guc_action_register_context (struct intel_guc *guc,u32 guc_id, -u32 offset) +u32 offset, +bool loop) {u32 action[] = {INTEL_GUC_ACTION_REGISTER_CONTEXT ,@@ -816,10 +1117,10 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , loop); } -static int register_context (struct intel_context *ce) +static int register_context (struct intel_context *ce,bool loop) {struct intel_guc *guc =ce_to_guc (ce); u32 offset = intel_guc_ggtt_offset(guc, guc->lrc_desc_pool) +@@ -827,11 +1128,12 @@ static int register_context(struct intel_context *ce)trace_intel_context_register (ce); -return __guc_action_register_context (guc, ce->guc_id, offset); +return __guc_action_register_context (guc, ce->guc_id, offset, loop); }static int __guc_action_deregister_context (struct intel_guc *guc, -u32 guc_id) +u32 guc_id, +bool loop) {u32 action[] = {INTEL_GUC_ACTION_DEREGISTER_CONTEXT ,@@ -839,16 +1141,16 @@ static int __guc_action_deregister_context(struct intel_guc *guc, };return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action), -G2H_LEN_DW_DEREGISTER_CONTEXT , true); +G2H_LEN_DW_DEREGISTER_CONTEXT , loop); } -static int deregister_context (struct intel_context *ce,u32 guc_id) +static int deregister_context (struct intel_context *ce,u32 guc_id,bool loop) {struct intel_guc *guc =ce_to_guc (ce);trace_intel_context_deregister (ce); -return __guc_action_deregister_context (guc, guc_id); +return __guc_action_deregister_context (guc, guc_id, loop); }static intel_engine_mask_t adjust_engine_mask (u8 class,intel_engine_mask_t mask)@@ -877,7 +1179,7 @@ static void guc_context_policy_init(struct intel_engine_cs *engine, desc->preemption_timeout =CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US ; } -static int guc_lrc_desc_pin (struct intel_context *ce) +static int guc_lrc_desc_pin (struct intel_context *ce,bool loop) {struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;@@ -923,18 +1225,44 @@ static int guc_lrc_desc_pin(struct intel_context *ce)*/ if (context_registered) {trace_intel_context_steal_guc_id (ce);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static int guc_lrc_desc_pin(struct intel_context *ce) · line 1235
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8
-2-set_context_wait_for_deregister_to_register (ce); -intel_context_get (ce); +if (!loop) { +set_context_wait_for_deregister_to_register (ce); +intel_context_get (ce); + }else { +bool disabled; +unsigned long flags; + +/* Seal race with Reset */
Needs to be more descriptive.
Quoted 103 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +29
-13+spin_lock_irqsave (&ce->guc_state.lock, flags); + disabled =submission_disabled (guc); +if (likely (!disabled)) { +set_context_wait_for_deregister_to_register (ce); +intel_context_get (ce); + } +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +if (unlikely (disabled)) { +reset_lrc_desc (guc, desc_idx); +return 0 ;/* Will get registered later */ + } + }/* * If stealing the guc_id, this ce has the same guc_id as the * context whos guc_id was stole. */ with_intel_runtime_pm (runtime_pm, wakeref) - ret = deregister_context(ce, ce->guc_id); + ret = deregister_context(ce, ce->guc_id, loop); +if (unlikely (ret == -EBUSY )) { +clr_context_wait_for_deregister_to_register (ce); +intel_context_put (ce); + } }else {with_intel_runtime_pm (runtime_pm, wakeref) - ret = register_context(ce); + ret = register_context(ce, loop); +if (unlikely (ret == -EBUSY )) +reset_lrc_desc (guc, desc_idx); +else if (unlikely (ret == -ENODEV )) + ret =0 ;/* Will get registered later */ }return ret;@@ -997,7 +1325,6 @@ static void __guc_context_sched_disable(struct intel_guc *guc,GEM_BUG_ON (guc_id ==GUC_INVALID_LRC_ID );trace_intel_context_sched_disable (ce); -intel_context_get (ce);guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true);@@ -1007,6 +1334,7 @@ static u16 prep_context_pending_disable(struct intel_context *ce) {set_context_pending_disable (ce);clr_context_enabled (ce); +intel_context_get (ce);return ce->guc_id; }@@ -1019,7 +1347,7 @@ static void guc_context_sched_disable(struct intel_context *ce)u16 guc_id;intel_wakeref_t wakeref; -if (context_guc_id_invalid (ce) || +if (submission_disabled (guc) ||context_guc_id_invalid (ce) || !lrc_desc_registered (guc, ce->guc_id)) {clr_context_enabled (ce); goto unpin;@@ -1053,19 +1381,13 @@ static void guc_context_sched_disable(struct intel_context *ce)static inline void guc_lrc_desc_unpin (struct intel_context *ce) { -struct intel_engine_cs *engine = ce->engine; -struct intel_guc *guc = &engine->gt->uc.guc; -unsigned long flags; +struct intel_guc *guc =ce_to_guc (ce);GEM_BUG_ON (!lrc_desc_registered (guc, ce->guc_id));GEM_BUG_ON (ce !=__get_context (guc, ce->guc_id));GEM_BUG_ON (context_enabled (ce)); -spin_lock_irqsave (&ce->guc_state.lock, flags); -set_context_destroyed (ce); -spin_unlock_irqrestore (&ce->guc_state.lock, flags); - -deregister_context (ce, ce->guc_id); +deregister_context (ce, ce->guc_id, true); }static void __guc_context_destroy (struct intel_context *ce)@@ -1093,13 +1415,15 @@ static void guc_context_destroy(struct kref *kref)struct intel_guc *guc = &ce->engine->gt->uc.guc;intel_wakeref_t wakeref;unsigned long flags; +bool disabled;/* * If the guc_id is invalid this context has been stolen and we can free * it immediately. Also can be freed immediately if the context is not * registered with the GuC. */ -if (context_guc_id_invalid (ce) || +if (submission_disabled (guc) || +context_guc_id_invalid (ce) || !lrc_desc_registered (guc, ce->guc_id)) {release_guc_id (guc, ce);__guc_context_destroy (ce);@@ -1126,6 +1450,18 @@ static void guc_context_destroy(struct kref *kref)list_del_init (&ce->guc_id_link);spin_unlock_irqrestore (&guc->contexts_lock, flags);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_context_destroy(struct kref *kref) · line 1462
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+/* Seal race with Reset */ +spin_lock_irqsave (&ce->guc_state.lock, flags); + disabled =submission_disabled (guc); +if (likely (!disabled)) +set_context_destroyed (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +if (unlikely (disabled)) { +release_guc_id (guc, ce); +__guc_context_destroy (ce); +return ;
Same as above, needs a better comment. It is also hard for reader to know if snapshot of disabled taked under the lock is still valid after the lock has been released and why.
Regards,
Tvrtko
Quoted 298 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +47
-25+ } +/* * We defer GuC context deregistration until the context is destroyed * in order to save on CTBs. With this optimization ideally we only need @@ -1148,6 +1484,33 @@ static int guc_context_alloc(struct intel_context *ce)return lrc_alloc (ce, ce->engine); } +static void add_to_context (struct i915_request *rq) +{ +struct intel_context *ce = rq->context; + +spin_lock (&ce->guc_active.lock); +list_move_tail (&rq->sched.link, &ce->guc_active.requests); +spin_unlock (&ce->guc_active.lock); +} + +static void remove_from_context (struct i915_request *rq) +{ +struct intel_context *ce = rq->context; + +spin_lock_irq (&ce->guc_active.lock); + +list_del_init (&rq->sched.link); +clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); + +/* Prevent further __await_execution() registering a cb, then flush */ +set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); + +spin_unlock_irq (&ce->guc_active.lock); + +atomic_dec (&ce->guc_id_ref); +i915_request_notify_execute_cb_imm (rq); +} +static const struct intel_context_ops guc_context_ops = { .alloc = guc_context_alloc,@@ -1186,8 +1549,6 @@ static void guc_signal_context_fence(struct intel_context *ce) {unsigned long flags; -GEM_BUG_ON (!context_wait_for_deregister_to_register (ce)); -spin_lock_irqsave (&ce->guc_state.lock, flags);clr_context_wait_for_deregister_to_register (ce);__guc_signal_context_fence (ce);@@ -1196,8 +1557,9 @@ static void guc_signal_context_fence(struct intel_context *ce)static bool context_needs_register (struct intel_context *ce,bool new_guc_id) { -return new_guc_id ||test_bit (CONTEXT_LRCA_DIRTY , &ce->flags) || - !lrc_desc_registered (ce_to_guc (ce), ce->guc_id); +return (new_guc_id ||test_bit (CONTEXT_LRCA_DIRTY , &ce->flags) || + !lrc_desc_registered (ce_to_guc (ce), ce->guc_id)) && + !submission_disabled (ce_to_guc (ce)); }static int guc_request_alloc (struct i915_request *rq)@@ -1256,8 +1618,10 @@ static int guc_request_alloc(struct i915_request *rq)return ret;;if (context_needs_register (ce, !!ret)) { - ret =guc_lrc_desc_pin (ce); + ret =guc_lrc_desc_pin (ce, true);if (unlikely (ret)) {/* unwind */ +if (ret == -EDEADLK ) +disable_submission (guc);atomic_dec (&ce->guc_id_ref);unpin_guc_id (guc, ce);return ret;@@ -1294,20 +1658,6 @@ static int guc_request_alloc(struct i915_request *rq)return 0 ; } -static struct intel_engine_cs * -guc_virtual_get_sibling (struct intel_engine_cs *ve,unsigned int sibling) -{ -struct intel_engine_cs *engine; -intel_engine_mask_t tmp, mask = ve->mask; -unsigned int num_siblings =0 ; - -for_each_engine_masked (engine, ve->gt, mask, tmp) -if (num_siblings++ == sibling) -return engine; - -return NULL ; -} -static int guc_virtual_context_pre_pin (struct intel_context *ce,struct i915_gem_ww_ctx *ww,void **vaddr)@@ -1516,7 +1866,7 @@ static inline void guc_kernel_context_pin(struct intel_guc *guc, {if (context_guc_id_invalid (ce))pin_guc_id (guc, ce); -guc_lrc_desc_pin (ce); +guc_lrc_desc_pin (ce, true); }static inline void guc_init_lrc_mapping (struct intel_guc *guc)@@ -1582,13 +1932,15 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; engine->bump_serial = guc_bump_serial; + engine->add_active_request = add_to_context; + engine->remove_active_request = remove_from_context; engine->sched_engine->schedule = i915_schedule; - engine->reset.prepare = guc_reset_prepare; - engine->reset.rewind = guc_reset_rewind; - engine->reset.cancel = guc_reset_cancel; - engine->reset.finish = guc_reset_finish; + engine->reset.prepare = guc_reset_nop; + engine->reset.rewind = guc_rewind_nop; + engine->reset.cancel = guc_reset_nop; + engine->reset.finish = guc_reset_nop; engine->emit_flush = gen8_emit_flush_xcs; engine->emit_init_breadcrumb = gen8_emit_init_breadcrumb;@@ -1764,7 +2116,7 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,* register this context. */ with_intel_runtime_pm(runtime_pm, wakeref) -register_context (ce); +register_context (ce, true);guc_signal_context_fence (ce);intel_context_put (ce); }else if (context_destroyed (ce)) {@@ -1946,6 +2298,10 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) "v%dx%d", ve->base.class, count); ve->base.context_size = sibling->context_size; + ve->base.add_active_request = + sibling->add_active_request; + ve->base.remove_active_request = + sibling->remove_active_request; ve->base.emit_bb_start = sibling->emit_bb_start; ve->base.emit_flush = sibling->emit_flush; ve->base.emit_init_breadcrumb =drivers/gpu/drm/i915/gt/uc/intel_uc.c +33
-1@@ -565,12 +565,44 @@ void intel_uc_reset_prepare(struct intel_uc *uc) {struct intel_guc *guc = &uc->guc; +/* Firmware expected to be running when this function is called */ if (!intel_guc_is_ready (guc)) -return ; + goto sanitize; + +if (intel_uc_uses_guc_submission (uc)) +intel_guc_submission_reset_prepare (guc); +sanitize:__uc_sanitize (uc); } +void intel_uc_reset (struct intel_uc *uc,bool stalled) +{ +struct intel_guc *guc = &uc->guc; + +/* Firmware can not be running when this function is called */ +if (intel_uc_uses_guc_submission (uc)) +intel_guc_submission_reset (guc, stalled); +} + +void intel_uc_reset_finish (struct intel_uc *uc) +{ +struct intel_guc *guc = &uc->guc; + +/* Firmware expected to be running when this function is called */ +if (intel_guc_is_fw_running (guc) &&intel_uc_uses_guc_submission (uc)) +intel_guc_submission_reset_finish (guc); +} + +void intel_uc_cancel_requests (struct intel_uc *uc) +{ +struct intel_guc *guc = &uc->guc; + +/* Firmware can not be running when this function is called */ +if (intel_uc_uses_guc_submission (uc)) +intel_guc_submission_cancel_requests (guc); +} +void intel_uc_runtime_suspend (struct intel_uc *uc) {struct intel_guc *guc = &uc->guc;drivers/gpu/drm/i915/gt/uc/intel_uc.h +3
-0@@ -37,6 +37,9 @@ void intel_uc_driver_late_release(struct intel_uc *uc);void intel_uc_driver_remove (struct intel_uc *uc);void intel_uc_init_mmio (struct intel_uc *uc);void intel_uc_reset_prepare (struct intel_uc *uc); +void intel_uc_reset (struct intel_uc *uc,bool stalled); +void intel_uc_reset_finish (struct intel_uc *uc); +void intel_uc_cancel_requests (struct intel_uc *uc);void intel_uc_suspend (struct intel_uc *uc);void intel_uc_runtime_suspend (struct intel_uc *uc);int intel_uc_resume (struct intel_uc *uc);drivers/gpu/drm/i915/i915_request.c +4
-37@@ -194,7 +194,7 @@ static bool irq_work_imm(struct irq_work *wrk)return false; } -static void __notify_execute_cb_imm (struct i915_request *rq) +void i915_request_notify_execute_cb_imm (struct i915_request *rq) {__notify_execute_cb (rq, irq_work_imm); }@@ -268,37 +268,6 @@ i915_request_active_engine(struct i915_request *rq,return ret; } - -static void remove_from_engine (struct i915_request *rq) -{ -struct intel_engine_cs *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. -*/ - locked =READ_ONCE (rq->engine); -spin_lock_irq (&locked->sched_engine->lock); -while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { -spin_unlock (&locked->sched_engine->lock); -spin_lock (&engine->sched_engine->lock); - locked = engine; - } -list_del_init (&rq->sched.link); - -clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); -clear_bit (I915_FENCE_FLAG_HOLD , &rq->fence.flags); - -/* Prevent further __await_execution() registering a cb, then flush */ -set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); - -spin_unlock_irq (&locked->sched_engine->lock); - -__notify_execute_cb_imm (rq); -} -static void __rq_init_watchdog (struct i915_request *rq) { rq->watchdog.timer.function =NULL ;@@ -395,9 +364,7 @@ bool i915_request_retire(struct i915_request *rq)* after removing the breadcrumb and signaling it, so that we do not * inadvertently attach the breadcrumb to a completed request. */ -if (!list_empty (&rq->sched.link)) -remove_from_engine (rq); -atomic_dec (&rq->context->guc_id_ref); + rq->engine->remove_active_request (rq);GEM_BUG_ON (!llist_empty (&rq->execute_cb));__list_del_entry (&rq->link);/* poison neither prev/next (RCU walks) */ @@ -539,7 +506,7 @@ __await_execution(struct i915_request *rq,if (llist_add (&cb->work.node.llist, &signal->execute_cb)) {if (i915_request_is_active (signal) ||__request_in_flight (signal)) -__notify_execute_cb_imm (signal); +i915_request_notify_execute_cb_imm (signal); }return 0 ;@@ -676,7 +643,7 @@ bool __i915_request_submit(struct i915_request *request) result = true;GEM_BUG_ON (test_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags)); -list_move_tail (&request->sched.link, &engine->sched_engine->requests); + engine->add_active_request (request); active:clear_bit (I915_FENCE_FLAG_PQUEUE , &request->fence.flags);set_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags);drivers/gpu/drm/i915/i915_request.h +2
-0@@ -649,4 +649,6 @@ bool i915_request_active_engine(struct i915_request *rq, struct intel_engine_cs **active); +void i915_request_notify_execute_cb_imm (struct i915_request *rq); +#endif /* I915_REQUEST_H */
Re: [Intel-gfx] [RFC PATCH 64/97] drm/i915/guc: Reset implementation for new GuC interface
Quoted 52 lines · Tvrtko Ursulin
Quoted 50 lines · Matthew Brost
Reset implementation for new GuC interface. This is the legacy reset implementation which is called when the i915 owns the engine hang check. Future patches will offload the engine hang check to GuC but we will continue to maintain this legacy path as a fallback and this code path is also required if the GuC dies.
With the new GuC interface it is not possible to reset individual engines - it is only possible to reset the GPU entirely. This patch forces an entire chip reset if any engine hangs.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 3 + drivers/gpu/drm/i915/gt/intel_context_types.h | 7 + drivers/gpu/drm/i915/gt/intel_engine_types.h | 6 + .../drm/i915/gt/intel_execlists_submission.c | 40 ++ drivers/gpu/drm/i915/gt/intel_gt_pm.c | 6 +- drivers/gpu/drm/i915/gt/intel_reset.c | 18 +- .../gpu/drm/i915/gt/intel_ring_submission.c | 22 + drivers/gpu/drm/i915/gt/mock_engine.c | 31 + drivers/gpu/drm/i915/gt/uc/intel_guc.c | 16 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 8 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 580 ++++++++++++++---- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 34 +- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 3 + drivers/gpu/drm/i915/i915_request.c | 41 +- drivers/gpu/drm/i915/i915_request.h | 2 + 15 files changed, 643 insertions(+), 174 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +3
-0@@ -392,6 +392,9 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)spin_lock_init (&ce->guc_state.lock);INIT_LIST_HEAD (&ce->guc_state.fences); +spin_lock_init (&ce->guc_active.lock); +INIT_LIST_HEAD (&ce->guc_active.requests); + ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link);drivers/gpu/drm/i915/gt/intel_context_types.h +1
-0@@ -165,6 +165,13 @@ struct intel_context {struct list_head fences; } guc_state; +struct {
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 173
Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +5
-0+/** lock: protects everything in guc_active */ +spinlock_t lock; +/** requests: active requests on this context */ +struct list_head requests; + } guc_active;More accounting, yeah, this is more of that where GuC gives with one hand and takes away with the other. :(
Yep but we probably can drop this once we switch to the DRM scheduler. The drm_gpu_scheduler has a list of jobs and if don't mind searching the whole thing on a reset that will probably work too. I think the only reason we have a per context list is because of feedback I received a a while go saying resets are per context with GuC so keep a list on the context and engine list didn't really fit either. I'll make a to circle back to this when we hook into the DRM scheduler.
Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +1
-0+/* GuC scheduling state that does not require a lock. */ atomic_t guc_sched_state_no_lock;drivers/gpu/drm/i915/gt/intel_engine_types.h +6
-0@@ -432,6 +432,12 @@ struct intel_engine_cs {*/ void (*release)(struct intel_engine_cs *engine); +/* +* Add / remove request from engine active tracking +*/ +void (*add_active_request)(struct i915_request *rq); +void (*remove_active_request)(struct i915_request *rq); +struct intel_engine_execlists execlists;/* drivers/gpu/drm/i915/gt/intel_execlists_submission.c +19
-0@@ -3117,6 +3117,42 @@ static void execlists_park(struct intel_engine_cs *engine)cancel_timer (&engine->execlists.preempt); } +static void add_to_engine (struct i915_request *rq) +{ +lockdep_assert_held (&rq->engine->sched_engine->lock); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->requests); +} + +static void remove_from_engine (struct i915_request *rq) +{ +struct intel_engine_cs *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. +*/ + locked =READ_ONCE (rq->engine); +spin_lock_irq (&locked->sched_engine->lock); +while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) {
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_execlists_submission.c static void execlists_park(struct intel_engine_cs *engine) · line 3142
Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +4
-0+spin_unlock (&locked->sched_engine->lock); +spin_lock (&engine->sched_engine->lock); + locked = engine; + }Could use
i915_request_active_enginealthough tbf I don't remember why I did not convert all callers when I added it. Perhaps I just did not find them all.
I think is a copy paste from the existing code or least at it should be. It just moves implicit execlists behavior from common code to a execlists specific vfunc.
Quoted 111 lines
Quoted 111 lines
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +17
-0+list_del_init (&rq->sched.link); + +clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); +clear_bit (I915_FENCE_FLAG_HOLD , &rq->fence.flags); + +/* Prevent further __await_execution() registering a cb, then flush */ +set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); + +spin_unlock_irq (&locked->sched_engine->lock); + +i915_request_notify_execute_cb_imm (rq); +} +static bool can_preempt (struct intel_engine_cs *engine) {if (INTEL_GEN (engine->i915) >8 )@@ -3214,6 +3250,8 @@ logical_ring_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &execlists_context_ops; engine->request_alloc = execlists_request_alloc; engine->bump_serial = execlist_bump_serial; + engine->add_active_request = add_to_engine; + engine->remove_active_request = remove_from_engine; engine->reset.prepare = execlists_reset_prepare; engine->reset.rewind = execlists_reset_rewind;@@ -3915,6 +3953,8 @@ execlists_create_virtual(struct intel_engine_cs **siblings, unsigned int count) ve->base.sched_engine->kick_backend = sibling->sched_engine->kick_backend; + ve->base.add_active_request = sibling->add_active_request; + ve->base.remove_active_request = sibling->remove_active_request; 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;drivers/gpu/drm/i915/gt/intel_gt_pm.c +4
-2@@ -174,8 +174,6 @@ static void gt_sanitize(struct intel_gt *gt, bool force)if (intel_gt_is_wedged (gt))intel_gt_unset_wedged (gt); -intel_uc_sanitize (>->uc); -for_each_engine (engine, gt, id)if (engine->reset.prepare) engine->reset.prepare (engine);@@ -191,6 +189,8 @@ static void gt_sanitize(struct intel_gt *gt, bool force)__intel_engine_reset (engine, false); } +intel_uc_reset (>->uc, false); +for_each_engine (engine, gt, id)if (engine->reset.finish) engine->reset.finish (engine);@@ -243,6 +243,8 @@ int intel_gt_resume(struct intel_gt *gt) goto err_wedged; } +intel_uc_reset_finish (>->uc); +intel_rps_enable (>->rps);intel_llc_enable (>->llc);drivers/gpu/drm/i915/gt/intel_reset.c +10
-5@@ -758,6 +758,8 @@ static int gt_reset(struct intel_gt *gt, intel_engine_mask_t stalled_mask)__intel_engine_reset (engine, stalled_mask & engine->mask);local_bh_enable (); +intel_uc_reset (>->uc, true); +intel_ggtt_restore_fences (gt->ggtt);return err;@@ -782,6 +784,8 @@ static void reset_finish(struct intel_gt *gt, intel_engine_mask_t awake)if (awake & engine->mask)intel_engine_pm_put (engine); } + +intel_uc_reset_finish (>->uc); }static void nop_submit_request (struct i915_request *request)@@ -835,6 +839,7 @@ static void __intel_gt_set_wedged(struct intel_gt *gt)for_each_engine (engine, gt, id)if (engine->reset.cancel) engine->reset.cancel (engine); +intel_uc_cancel_requests (>->uc);local_bh_enable ();reset_finish (gt, awake);@@ -1123,6 +1128,9 @@ int __intel_engine_reset_bh(struct intel_engine_cs *engine, const char *msg)ENGINE_TRACE (engine,"flags=%lx\n" , gt->reset.flags);GEM_BUG_ON (!test_bit (I915_RESET_ENGINE + engine->id, >->reset.flags)); +if (intel_engine_uses_guc (engine)) +return -ENODEV ; +if (!intel_engine_pm_get_if_awake (engine))return 0 ;@@ -1133,13 +1141,10 @@ int __intel_engine_reset_bh(struct intel_engine_cs *engine, const char *msg) "Resetting %s for %s\n", engine->name, msg);atomic_inc (&engine->i915->gpu_error.reset_engine_count[engine->uabi_class]); -if (intel_engine_uses_guc (engine)) - ret =intel_guc_reset_engine (&engine->gt->uc.guc, engine); -else - ret =intel_gt_reset_engine (engine); + ret =intel_gt_reset_engine (engine);if (ret) {/* If we fail here, we expect to fallback to a global reset */ -ENGINE_TRACE (engine,"Failed to reset, err: %d\n" , ret); +ENGINE_TRACE (engine,"Failed to reset %s, err: %d\n" , engine->name, ret); goto out; }@@ -1273,7 +1278,8 @@ void intel_gt_handle_error(struct intel_gt *gt,* Try engine reset when available. We fall back to full reset if * single reset fails. */
Quoted 9 lines
drivers/gpu/drm/i915/gt/intel_reset.c void intel_gt_handle_error(struct intel_gt *gt, · line 1282
Quoted 3 lines
drivers/gpu/drm/i915/gt/intel_reset.c +2
-1-if (intel_has_reset_engine (gt) && !intel_gt_is_wedged (gt)) { +if (!intel_uc_uses_guc_submission (>->uc) && +intel_has_reset_engine (gt) && !intel_gt_is_wedged (gt)) {If with guc driver cannot do engine reset, could
intel_has_reset_enginejust say false in that case so guc check wouldn't have to be added here? Also noticed this is the same open I had in 2019. and someone said it can and would be folded. ;(
Let me look into that before the next rev, I briefly looked at this and it does seem plausible this function could return false. Only concern here is reset code is notoriously delicate so I am wary to change this in this series. We have a live list of follow ups, this could be included if it doesn't get fixed in this patch.
Quoted 277 lines
Quoted 277 lines
drivers/gpu/drm/i915/gt/intel_reset.c +0
-0local_bh_disable ();for_each_engine_masked (engine, gt, engine_mask, tmp) {BUILD_BUG_ON (I915_RESET_MODESET >=I915_RESET_ENGINE );drivers/gpu/drm/i915/gt/intel_ring_submission.c +22
-0@@ -1050,6 +1050,25 @@ static void ring_bump_serial(struct intel_engine_cs *engine) engine->serial++; } +static void add_to_engine (struct i915_request *rq) +{ +lockdep_assert_held (&rq->engine->sched_engine->lock); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->requests); +} + +static void remove_from_engine (struct i915_request *rq) +{ +spin_lock_irq (&rq->engine->sched_engine->lock); +list_del_init (&rq->sched.link); + +/* Prevent further __await_execution() registering a cb, then flush */ +set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); + +spin_unlock_irq (&rq->engine->sched_engine->lock); + +i915_request_notify_execute_cb_imm (rq); +} +static void setup_common (struct intel_engine_cs *engine) {struct drm_i915_private *i915 = engine->i915;@@ -1067,6 +1086,9 @@ static void setup_common(struct intel_engine_cs *engine) engine->reset.cancel = reset_cancel; engine->reset.finish = reset_finish; + engine->add_active_request = add_to_engine; + engine->remove_active_request = remove_from_engine; + engine->cops = &ring_context_ops; engine->request_alloc = ring_request_alloc; engine->bump_serial = ring_bump_serial;drivers/gpu/drm/i915/gt/mock_engine.c +31
-0@@ -235,6 +235,35 @@ static void mock_submit_request(struct i915_request *request)spin_unlock_irqrestore (&engine->hw_lock, flags); } +static void mock_add_to_engine (struct i915_request *rq) +{ +lockdep_assert_held (&rq->engine->sched_engine->lock); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->requests); +} + +static void mock_remove_from_engine (struct i915_request *rq) +{ +struct intel_engine_cs *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. +*/ + + locked =READ_ONCE (rq->engine); +spin_lock_irq (&locked->sched_engine->lock); +while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { +spin_unlock (&locked->sched_engine->lock); +spin_lock (&engine->sched_engine->lock); + locked = engine; + } +list_del_init (&rq->sched.link); +spin_unlock_irq (&locked->sched_engine->lock); +} + +static void mock_reset_prepare (struct intel_engine_cs *engine) { }@@ -327,6 +356,8 @@ struct intel_engine_cs *mock_engine(struct drm_i915_private *i915, engine->base.emit_flush = mock_emit_flush; engine->base.emit_fini_breadcrumb = mock_emit_breadcrumb; engine->base.submit_request = mock_submit_request; + engine->base.add_active_request = mock_add_to_engine; + engine->base.remove_active_request = mock_remove_from_engine; engine->base.reset.prepare = mock_reset_prepare; engine->base.reset.rewind = mock_reset_rewind;drivers/gpu/drm/i915/gt/uc/intel_guc.c +3
-13@@ -146,6 +146,9 @@ static void gen11_disable_guc_interrupts(struct intel_guc *guc) {struct intel_gt *gt =guc_to_gt (guc); +if (!guc->interrupts.enabled) +return ; +spin_lock_irq (>->irq_lock); guc->interrupts.enabled = false;@@ -579,19 +582,6 @@ int intel_guc_suspend(struct intel_guc *guc)return 0 ; } -/** -* intel_guc_reset_engine() - ask GuC to reset an engine -* @guc: intel_guc structure -* @engine: engine to be reset -*/ -int intel_guc_reset_engine (struct intel_guc *guc, -struct intel_engine_cs *engine) -{ -/* XXX: to be implemented with submission interface rework */ - -return -ENODEV ; -} -/** * intel_guc_resume() - notify GuC resuming from suspend state * @guc: the guc drivers/gpu/drm/i915/gt/uc/intel_guc.h +5
-3@@ -243,14 +243,16 @@ static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout); -int intel_guc_reset_engine (struct intel_guc *guc, -struct intel_engine_cs *engine); -int intel_guc_deregister_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len);int intel_guc_sched_done_process_msg (struct intel_guc *guc,const u32 *msg,u32 len); +void intel_guc_submission_reset_prepare (struct intel_guc *guc); +void intel_guc_submission_reset (struct intel_guc *guc,bool stalled); +void intel_guc_submission_reset_finish (struct intel_guc *guc); +void intel_guc_submission_cancel_requests (struct intel_guc *guc); +void intel_guc_load_status (struct intel_guc *guc,struct drm_printer *p);#endif drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +59
-16@@ -140,7 +140,7 @@ context_wait_for_deregister_to_register(struct intel_context *ce)static inline void set_context_wait_for_deregister_to_register (struct intel_context *ce) { -/* Only should be called from guc_lrc_desc_pin() */ +/* Only should be called from guc_lrc_desc_pin() without lock */ ce->guc_state.sched_state |=SCHED_STATE_WAIT_FOR_DEREGISTER_TO_REGISTER ; }@@ -240,15 +240,31 @@ static int guc_lrc_desc_pool_create(struct intel_guc *guc)static void guc_lrc_desc_pool_destroy (struct intel_guc *guc) { + guc->lrc_desc_pool_vaddr =NULL ;i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline bool guc_submission_initialized (struct intel_guc *guc) +{ +return guc->lrc_desc_pool_vaddr !=NULL ; +} +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) { -struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); +if (likely (guc_submission_initialized (guc))) { +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); +unsigned long flags; -memset (desc,0 ,sizeof (*desc)); -xa_erase_irq (&guc->context_lookup, id); +memset (desc,0 ,sizeof (*desc)); + +/* +* xarray API doesn't have xa_erase_irqsave wrapper, so calling +* the lower level functions directly. +*/ +xa_lock_irqsave (&guc->context_lookup, flags); +__xa_erase (&guc->context_lookup, id); +xa_unlock_irqrestore (&guc->context_lookup, flags); + } }static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id)@@ -259,7 +275,15 @@ static inline bool lrc_desc_registered(struct intel_guc *guc, u32 id)static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id,struct intel_context *ce) { -xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +unsigned long flags; + +/* +* xarray API doesn't have xa_save_irqsave wrapper, so calling the +* lower level functions directly. +*/ +xa_lock_irqsave (&guc->context_lookup, flags); +__xa_store (&guc->context_lookup, id, ce,GFP_ATOMIC ); +xa_unlock_irqrestore (&guc->context_lookup, flags); } static int guc_submission_busy_loop(struct intel_guc* guc,@@ -330,6 +354,8 @@ int intel_guc_wait_for_idle(struct intel_guc *guc, long timeout) interruptible, timeout); } +static int guc_lrc_desc_pin (struct intel_context *ce,bool loop); +static int guc_add_request (struct intel_guc *guc,struct i915_request *rq) {int err;@@ -337,11 +363,22 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)u32 action[3 ];int len =0 ;u32 g2h_len_dw =0 ; -bool enabled =context_enabled (ce); +bool enabled;GEM_BUG_ON (!atomic_read (&ce->guc_id_ref));GEM_BUG_ON (context_guc_id_invalid (ce)); +/* +* Corner case where the GuC firmware was blown away and reloaded while +* this context was pinned. +*/ +if (unlikely (!lrc_desc_registered (guc, ce->guc_id))) { + err =guc_lrc_desc_pin (ce, false); +if (unlikely (err)) + goto out; + } + enabled =context_enabled (ce); +if (!enabled) { action[len++] =INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET ; action[len++] = ce->guc_id;@@ -364,6 +401,7 @@ static int guc_add_request(struct intel_guc *guc, struct i915_request *rq)intel_context_put (ce); } +out:return err; }@@ -418,15 +456,10 @@ static int guc_dequeue_one_context(struct intel_guc *guc)if (submit) {guc_set_lrc_tail (last); resubmit: -/* -* We only check for -EBUSY here even though it is possible for -* -EDEADLK to be returned. If -EDEADLK is returned, the GuC has -* died and a full GPU needs to be done. The hangcheck will -* eventually detect that the GuC has died and trigger this -* reset so no need to handle -EDEADLK here. -*/ ret =guc_add_request (guc, last); -if (ret == -EBUSY ) { +if (unlikely (ret == -EDEADLK )) + goto deadlk; +else if (ret == -EBUSY ) {i915_sched_engine_kick (sched_engine); guc->stalled_request = last;return false;@@ -436,6 +469,11 @@ static int guc_dequeue_one_context(struct intel_guc *guc) guc->stalled_request =NULL ;return submit; + +deadlk: + sched_engine->tasklet.callback =NULL ; +tasklet_disable_nosync (&sched_engine->tasklet); +return false; }static void guc_submission_tasklet (struct tasklet_struct *t)@@ -462,29 +500,165 @@ static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir)intel_engine_signal_breadcrumbs (engine); } -static void guc_reset_prepare (struct intel_engine_cs *engine) +static void __guc_context_destroy (struct intel_context *ce); +static void release_guc_id (struct intel_guc *guc,struct intel_context *ce); +static void guc_signal_context_fence (struct intel_context *ce); + +static void scrub_guc_desc_for_outstanding_g2h (struct intel_guc *guc) { -struct i915_sched_engine *const sched_engine = engine->sched_engine; +struct intel_context *ce; +unsigned long index, flags;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 516
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-1+bool pending_disable, pending_enable, deregister, destroyed; -ENGINE_TRACE (engine,"\n" ); +xa_for_each (&guc->context_lookup, index, ce) { +/* Flush context */ +spin_lock_irqsave (&ce->guc_state.lock, flags); +spin_unlock_irqrestore (&ce->guc_state.lock, flags);Very unusual pattern - what does it do?
The comment below tries to explain this. Basically by cycling the lock it guarantees submission_disabled() is visible to all callers that touch the below flags.
Quoted 28 lines
Quoted 28 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +28
-0+ +/* +* Once we are at this point submission_disabled() is guaranteed +* to visible to all callers who set the below flags (see above +* flush and flushes in reset_prepare). If submission_disabled() +* is set, the caller shouldn't set these flags. +*/ + + destroyed =context_destroyed (ce); + pending_enable =context_pending_enable (ce); + pending_disable =context_pending_disable (ce); + deregister =context_wait_for_deregister_to_register (ce); +init_sched_state (ce); + +if (pending_enable || destroyed || deregister) { +atomic_dec (&guc->outstanding_submission_g2h); +if (deregister) +guc_signal_context_fence (ce); +if (destroyed) { +release_guc_id (guc, ce); +__guc_context_destroy (ce); + } +if (pending_enable|| deregister) +intel_context_put (ce); + } + +/* Not mutualy exclusive with above if statement. */ +if (pending_disable) {
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 549
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+guc_signal_context_fence (ce); +intel_context_sched_disable_unpin (ce); +atomic_dec (&guc->outstanding_submission_g2h); +intel_context_put (ce); + }Yeah this function is a taste of the taste machine I think is _extremely_ hard to review and know with any confidence it does the right thing.
What is the other option? Block everytime we issue an asynchronous command to the GuC? If we want to do everyting asynchronously we have to track state and take further actions when the GuC finally responds. We also have to deal with the GuC dying and taking those actions on our own.
Luckily we do have several other aside from myself that do understand this quite well.
Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +24
-0+ } +} + +static inline bool +submission_disabled (struct intel_guc *guc) +{ +struct i915_sched_engine *const sched_engine = guc->sched_engine; + +return unlikely (!__tasklet_is_enabled (&sched_engine->tasklet)); +} + +static void disable_submission (struct intel_guc *guc) +{ +struct i915_sched_engine *const sched_engine = guc->sched_engine; + +if (__tasklet_is_enabled (&sched_engine->tasklet)) { +GEM_BUG_ON (!guc->ct.enabled); +__tasklet_disable_sync_once (&sched_engine->tasklet); + sched_engine->tasklet.callback =NULL ; + } +} + +static void enable_submission (struct intel_guc *guc) +{
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 579
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+struct i915_sched_engine *const sched_engine = guc->sched_engine; +unsigned long flags; + +spin_lock_irqsave (&guc->sched_engine->lock, flags); + sched_engine->tasklet.callback = guc_submission_tasklet; +wmb ();All memory barriers must be documented.
Found that out from checkpatch the other day, will fix.
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +11
-0+if (!__tasklet_is_enabled (&sched_engine->tasklet) && +__tasklet_enable (&sched_engine->tasklet)) { +GEM_BUG_ON (!guc->ct.enabled); + +/* And kick in case we missed a new request submission. */ +i915_sched_engine_hi_kick (sched_engine); + } +spin_unlock_irqrestore (&guc->sched_engine->lock, flags); +} + +static void guc_flush_submissions (struct intel_guc *guc)
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 596
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+{ +struct i915_sched_engine *const sched_engine = guc->sched_engine; +unsigned long flags; + +spin_lock_irqsave (&sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags);Oh right, more of this. No idea.
Same as above. If you change some state then cycle a lock it is guaranteed that state is visible next time someone grabs the lock. I do explain these races in the documentation patch near the end of the series. Without a BKL I don't see how else to avoid these reset races.
Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +19
-7+} + +void intel_guc_submission_reset_prepare (struct intel_guc *guc) +{ +int i; + +if (unlikely (!guc_submission_initialized (guc))) +/* Reset called during driver load? GuC not yet initialised! */ +return ; + +disable_submission (guc); + guc->interrupts.disable (guc); + +/* Flush IRQ handler */ +spin_lock_irq (&guc_to_gt (guc)->irq_lock); +spin_unlock_irq (&guc_to_gt (guc)->irq_lock); + +guc_flush_submissions (guc);/* -* Prevent request submission to the hardware until we have -* completed the reset in i915_gem_reset_finish(). If a request -* is completed by one engine, it may then queue a request -* to a second via its sched_engine->tasklet *just* as we are -* calling engine->init_hw() and also writing the ELSP. -* Turning off the sched_engine->tasklet until the reset is over -* prevents the race. +* Handle any outstanding G2Hs before reset. Call IRQ handler directly
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 622
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +4
-1+* each pass as interrupt have been disabled. We always scrub for +* outstanding G2H as it is possible for outstanding_submission_g2h to +* be incremented after the context state update. */ -__tasklet_disable_sync_once (&sched_engine->tasklet); +for (i =0 ; i <4 &&atomic_read (&guc->outstanding_submission_g2h); ++i) {Why is four the magic number and what happens if it is not enough?
I just picked a number. Regardless if the normal G2H path processes all the G2H we scrub all the context state for lost ones.
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +15
-0+intel_guc_to_host_event_handler (guc); +#define wait_for_reset (guc, wait_var) \ + guc_wait_for_pending_msg(guc, wait_var, false, (HZ / 20)) +do { +wait_for_reset (guc, &guc->outstanding_submission_g2h); + }while (!list_empty (&guc->ct.requests.incoming)); + } +scrub_guc_desc_for_outstanding_g2h (guc); +} + +static struct intel_engine_cs * +guc_virtual_get_sibling (struct intel_engine_cs *ve,unsigned int sibling) +{ +struct intel_engine_cs *engine; +intel_engine_mask_t tmp, mask = ve->mask;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) · line 642
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+unsigned int num_siblings =0 ; + +for_each_engine_masked (engine, ve->gt, mask, tmp) +if (num_siblings++ == sibling) +return engine;Not sure how often is this used overall and whether just storing the array in ve could be justified.
It really is only used with sibling == 0, so it should be fast.
Quoted 54 lines
Quoted 54 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +37
-8+ +return NULL ; +} + +static inline struct intel_engine_cs * +__context_to_physical_engine (struct intel_context *ce) +{ +struct intel_engine_cs *engine = ce->engine; + +if (intel_engine_is_virtual (engine)) + engine =guc_virtual_get_sibling (engine,0 ); + +return engine; } -static void guc_reset_state (struct intel_context *ce, -struct intel_engine_cs *engine, -u32 head, -bool scrub) +static void guc_reset_state (struct intel_context *ce,u32 head,bool scrub) { +struct intel_engine_cs *engine =__context_to_physical_engine (ce); +GEM_BUG_ON (!intel_context_is_pinned (ce));/* @@ -502,42 +676,147 @@ static void guc_reset_state(struct intel_context *ce,lrc_update_regs (ce, engine, head); } -static void guc_reset_rewind (struct intel_engine_cs *engine,bool stalled) +static void guc_reset_nop (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; -struct i915_request *rq; +} + +static void guc_rewind_nop (struct intel_engine_cs *engine,bool stalled) +{ +} + +static void +__unwind_incomplete_requests (struct intel_context *ce) +{ +struct i915_request *rq, *rn; +struct list_head *pl; +int prio =I915_PRIORITY_INVALID ; +struct i915_sched_engine *const sched_engine = + ce->engine->sched_engine;unsigned long flags; -spin_lock_irqsave (&engine->sched_engine->lock, flags); +spin_lock_irqsave (&sched_engine->lock, flags); +spin_lock (&ce->guc_active.lock); +list_for_each_entry_safe (rq, rn, + &ce->guc_active.requests, + sched.link) { +if (i915_request_completed (rq))
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_reset_state(struct intel_context *ce, · line 706
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +4
-0+continue ; + +list_del_init (&rq->sched.link); +spin_unlock (&ce->guc_active.lock);Drops the lock and continues iterating the same list is safe? Comment needed I think and I do remember I worried about this, or similar instances, in GuC code before.
We only need the active lock for ce->guc_active.requests list. It is indeed safe to drop the lock.
Quoted 98 lines
Quoted 98 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +88
-7+ +__i915_request_unsubmit (rq); + +/* Push the request back into the queue for later resubmission. */ +GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID ); +if (rq_prio (rq) != prio) { + prio =rq_prio (rq); + pl =i915_sched_lookup_priolist (sched_engine, prio); + } +GEM_BUG_ON (i915_sched_engine_is_empty (sched_engine)); -/* Push back any incomplete requests for replay after the reset. */ - rq =execlists_unwind_incomplete_requests (execlists); -if (!rq) - goto out_unlock; +list_add_tail (&rq->sched.link, pl); +set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); + +spin_lock (&ce->guc_active.lock); + } +spin_unlock (&ce->guc_active.lock); +spin_unlock_irqrestore (&sched_engine->lock, flags); +} + +static struct i915_request *context_find_active_request (struct intel_context *ce) +{ +struct i915_request *rq, *active =NULL ; +unsigned long flags; + +spin_lock_irqsave (&ce->guc_active.lock, flags); +list_for_each_entry_reverse (rq, &ce->guc_active.requests, + sched.link) { +if (i915_request_completed (rq)) +break ; + + active = rq; + } +spin_unlock_irqrestore (&ce->guc_active.lock, flags); + +return active; +} + +static void __guc_reset_context (struct intel_context *ce,bool stalled) +{ +struct i915_request *rq; +u32 head; + +/* +* GuC will implicitly mark the context as non-schedulable +* when it sends the reset notification. Make sure our state +* reflects this change. The context will be marked enabled +* on resubmission. +*/ +clr_context_enabled (ce); + + rq =context_find_active_request (ce); +if (!rq) { + head = ce->ring->tail; + stalled = false; + goto out_replay; + }if (!i915_request_started (rq)) stalled = false; +GEM_BUG_ON (i915_active_is_idle (&ce->active)); + head =intel_ring_wrap (ce->ring, rq->head);__i915_request_reset (rq, stalled); -guc_reset_state (rq->context, engine, rq->head, stalled); -out_unlock: -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +out_replay: +guc_reset_state (ce, head, stalled); +__unwind_incomplete_requests (ce); +} + +void intel_guc_submission_reset (struct intel_guc *guc,bool stalled) +{ +struct intel_context *ce; +unsigned long index; + +if (unlikely (!guc_submission_initialized (guc))) +/* Reset called during driver load? GuC not yet initialised! */ +return ; + +xa_for_each (&guc->context_lookup, index, ce) +if (intel_context_is_pinned (ce)) +__guc_reset_context (ce, stalled); + +/* GuC is blown away, drop all references to contexts */ +xa_destroy (&guc->context_lookup); +} + +static void guc_cancel_context_requests (struct intel_context *ce) +{ +struct i915_sched_engine *sched_engine =ce_to_guc (ce)->sched_engine; +struct i915_request *rq; +unsigned long flags; + +/* Mark all executing requests as skipped. */ +spin_lock_irqsave (&sched_engine->lock, flags);
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_reset_state(struct intel_context *ce, · line 806
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+spin_lock (&ce->guc_active.lock); +list_for_each_entry (rq, &ce->guc_active.requests, sched.link) +i915_request_put (i915_request_mark_eio (rq)); +spin_unlock (&ce->guc_active.lock); +spin_unlock_irqrestore (&sched_engine->lock, flags);I suppose somewhere it will need to be documented what are the two locks protecting and why both are needed at some places.
Yep, I have a locking section the doc patch near the end of the series. Basically here is we don't want any new submissions processed when we are canceling requests - that is the outer lock. The inner lock again ce->guc_active.requests list.
BTW - I think I am overly careful with the locks (when in doubt grab a lock) in the reset / cancel code as there is no expectation that this needs to perform well and resets are by far the racest code in the i915.
Quoted 75 lines
Quoted 75 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +27
-21} -static void guc_reset_cancel (struct intel_engine_cs *engine) +static void +guc_cancel_sched_engine_requests (struct i915_sched_engine *sched_engine) { -struct i915_sched_engine *const sched_engine = engine->sched_engine;struct i915_request *rq, *rn;struct rb_node *rb;unsigned long flags;/* Can be called during boot if GuC fails to load */ -if (!engine->gt) +if (!sched_engine)return ; -ENGINE_TRACE (engine,"\n" ); -/* * Before we call engine->cancel_requests(), we should have exclusive * access to the submission state. This is arranged for us by the @@ -552,13 +831,7 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)* submission's irq state, we also wish to remind ourselves that * it is irq state.) */ -spin_lock_irqsave (&engine->sched_engine->lock, flags); - -/* Mark all executing requests as skipped. */ -list_for_each_entry (rq, &engine->sched_engine->requests, sched.link) { -i915_request_set_error_once (rq, -EIO ); -i915_request_mark_complete (rq); - } +spin_lock_irqsave (&sched_engine->lock, flags);/* Flush the queued requests to the timeline list (for retiring). */ while ((rb =rb_first_cached (&sched_engine->queue))) {@@ -566,9 +839,10 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)priolist_for_each_request_consume (rq, rn, p) {list_del_init (&rq->sched.link); +__i915_request_submit (rq); -dma_fence_set_error (&rq->fence, -EIO ); -i915_request_mark_complete (rq); + +i915_request_put (i915_request_mark_eio (rq)); }rb_erase_cached (&p->node, &sched_engine->queue);@@ -580,19 +854,41 @@ static void guc_reset_cancel(struct intel_engine_cs *engine) sched_engine->queue_priority_hint =INT_MIN ; sched_engine->queue =RB_ROOT_CACHED ; -spin_unlock_irqrestore (&engine->sched_engine->lock, flags); +spin_unlock_irqrestore (&sched_engine->lock, flags); } -static void guc_reset_finish (struct intel_engine_cs *engine) +void intel_guc_submission_cancel_requests (struct intel_guc *guc) { -struct i915_sched_engine *const sched_engine = engine->sched_engine; +struct intel_context *ce; +unsigned long index; -if (__tasklet_enable (&sched_engine->tasklet)) -/* And kick in case we missed a new request submission. */ -i915_sched_engine_hi_kick (sched_engine); +xa_for_each (&guc->context_lookup, index, ce) +if (intel_context_is_pinned (ce)) +guc_cancel_context_requests (ce); + +guc_cancel_sched_engine_requests (guc->sched_engine); + +/* GuC is blown away, drop all references to contexts */ +xa_destroy (&guc->context_lookup); +} + +void intel_guc_submission_reset_finish (struct intel_guc *guc) +{ +/* Reset called during driver load or during wedge? */ +if (unlikely (!guc_submission_initialized (guc) || +test_bit (I915_WEDGED , &guc_to_gt (guc)->reset.flags))) +return ; - ENGINE_TRACE(engine, "depth->%d\n",
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_reset_cancel(struct intel_engine_cs *engine) · line 886
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-1- atomic_read(&sched_engine->tasklet.count)); +/* +* Technically possible for either of these values to be non-zero here, +* but very unlikely + harmless. Regardless let's add a warn so we can +* see in CI if this happens frequently / a precursor to taking down the +* machine. And what did CI say over time this was in?
It hasn't popped yet. This is more for upcoming code where we have a g2hs we can't scrub (i.e. a TLB invalidation, engine class scheduling disable, etc...).
Quoted 3 lines
It needs to be explained when it can be non zero and whether or not it can go to non zero just after the
atomic_setbelow. Or if not why not.
At this point we could probably turn this into a BUG_ON.
Quoted 87 lines
Quoted 87 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +23
-12+*/ +GEM_WARN_ON (atomic_read (&guc->outstanding_submission_g2h)); +atomic_set (&guc->outstanding_submission_g2h,0 ); + +enable_submission (guc); }/* @@ -659,6 +955,9 @@ static int guc_bypass_tasklet_submit(struct intel_guc *guc,else trace_i915_request_guc_submit (rq); +if (unlikely (ret == -EDEADLK )) +disable_submission (guc); +return ret; }@@ -671,7 +970,8 @@ static void guc_submit_request(struct i915_request *rq)/* Will be called from irq-context when using foreign fences. */ spin_lock_irqsave (&sched_engine->lock, flags); -if (guc->stalled_request || !i915_sched_engine_is_empty (sched_engine)) +if (submission_disabled (guc) || guc->stalled_request || + !i915_sched_engine_is_empty (sched_engine))queue_request (sched_engine, rq,rq_prio (rq));else if (guc_bypass_tasklet_submit (guc, rq) == -EBUSY )i915_sched_engine_hi_kick (sched_engine);@@ -808,7 +1108,8 @@ static void unpin_guc_id(struct intel_guc *guc, struct intel_context *ce)static int __guc_action_register_context (struct intel_guc *guc,u32 guc_id, -u32 offset) +u32 offset, +bool loop) {u32 action[] = {INTEL_GUC_ACTION_REGISTER_CONTEXT ,@@ -816,10 +1117,10 @@ static int __guc_action_register_context(struct intel_guc *guc, offset, }; -return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); +return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),0 , loop); } -static int register_context (struct intel_context *ce) +static int register_context (struct intel_context *ce,bool loop) {struct intel_guc *guc =ce_to_guc (ce); u32 offset = intel_guc_ggtt_offset(guc, guc->lrc_desc_pool) +@@ -827,11 +1128,12 @@ static int register_context(struct intel_context *ce)trace_intel_context_register (ce); -return __guc_action_register_context (guc, ce->guc_id, offset); +return __guc_action_register_context (guc, ce->guc_id, offset, loop); }static int __guc_action_deregister_context (struct intel_guc *guc, -u32 guc_id) +u32 guc_id, +bool loop) {u32 action[] = {INTEL_GUC_ACTION_DEREGISTER_CONTEXT ,@@ -839,16 +1141,16 @@ static int __guc_action_deregister_context(struct intel_guc *guc, };return guc_submission_busy_loop (guc, action,ARRAY_SIZE (action), -G2H_LEN_DW_DEREGISTER_CONTEXT , true); +G2H_LEN_DW_DEREGISTER_CONTEXT , loop); } -static int deregister_context (struct intel_context *ce,u32 guc_id) +static int deregister_context (struct intel_context *ce,u32 guc_id,bool loop) {struct intel_guc *guc =ce_to_guc (ce);trace_intel_context_deregister (ce); -return __guc_action_deregister_context (guc, guc_id); +return __guc_action_deregister_context (guc, guc_id, loop); }static intel_engine_mask_t adjust_engine_mask (u8 class,intel_engine_mask_t mask)@@ -877,7 +1179,7 @@ static void guc_context_policy_init(struct intel_engine_cs *engine, desc->preemption_timeout =CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US ; } -static int guc_lrc_desc_pin (struct intel_context *ce) +static int guc_lrc_desc_pin (struct intel_context *ce,bool loop) {struct intel_runtime_pm *runtime_pm = &ce->engine->gt->i915->runtime_pm;@@ -923,18 +1225,44 @@ static int guc_lrc_desc_pin(struct intel_context *ce)*/ if (context_registered) {trace_intel_context_steal_guc_id (ce); -set_context_wait_for_deregister_to_register (ce); -intel_context_get (ce); +if (!loop) { +set_context_wait_for_deregister_to_register (ce);
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static int guc_lrc_desc_pin(struct intel_context *ce) · line 1235
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+intel_context_get (ce); + }else { +bool disabled; +unsigned long flags; + +/* Seal race with Reset */ Needs to be more descriptive.
Again have comment about this the doc patch. Basically this goes back to your other questions about cycling a lock. You must check if submission_disabled() within a lock otherwise there is a race with resets and updating a contexts state.
Quoted 97 lines
Quoted 97 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +35
-13+spin_lock_irqsave (&ce->guc_state.lock, flags); + disabled =submission_disabled (guc); +if (likely (!disabled)) { +set_context_wait_for_deregister_to_register (ce); +intel_context_get (ce); + } +spin_unlock_irqrestore (&ce->guc_state.lock, flags); +if (unlikely (disabled)) { +reset_lrc_desc (guc, desc_idx); +return 0 ;/* Will get registered later */ + } + }/* * If stealing the guc_id, this ce has the same guc_id as the * context whos guc_id was stole. */ with_intel_runtime_pm (runtime_pm, wakeref) - ret = deregister_context(ce, ce->guc_id); + ret = deregister_context(ce, ce->guc_id, loop); +if (unlikely (ret == -EBUSY )) { +clr_context_wait_for_deregister_to_register (ce); +intel_context_put (ce); + } }else {with_intel_runtime_pm (runtime_pm, wakeref) - ret = register_context(ce); + ret = register_context(ce, loop); +if (unlikely (ret == -EBUSY )) +reset_lrc_desc (guc, desc_idx); +else if (unlikely (ret == -ENODEV )) + ret =0 ;/* Will get registered later */ }return ret;@@ -997,7 +1325,6 @@ static void __guc_context_sched_disable(struct intel_guc *guc,GEM_BUG_ON (guc_id ==GUC_INVALID_LRC_ID );trace_intel_context_sched_disable (ce); -intel_context_get (ce);guc_submission_busy_loop (guc, action,ARRAY_SIZE (action),G2H_LEN_DW_SCHED_CONTEXT_MODE_SET , true);@@ -1007,6 +1334,7 @@ static u16 prep_context_pending_disable(struct intel_context *ce) {set_context_pending_disable (ce);clr_context_enabled (ce); +intel_context_get (ce);return ce->guc_id; }@@ -1019,7 +1347,7 @@ static void guc_context_sched_disable(struct intel_context *ce)u16 guc_id;intel_wakeref_t wakeref; -if (context_guc_id_invalid (ce) || +if (submission_disabled (guc) ||context_guc_id_invalid (ce) || !lrc_desc_registered (guc, ce->guc_id)) {clr_context_enabled (ce); goto unpin;@@ -1053,19 +1381,13 @@ static void guc_context_sched_disable(struct intel_context *ce)static inline void guc_lrc_desc_unpin (struct intel_context *ce) { -struct intel_engine_cs *engine = ce->engine; -struct intel_guc *guc = &engine->gt->uc.guc; -unsigned long flags; +struct intel_guc *guc =ce_to_guc (ce);GEM_BUG_ON (!lrc_desc_registered (guc, ce->guc_id));GEM_BUG_ON (ce !=__get_context (guc, ce->guc_id));GEM_BUG_ON (context_enabled (ce)); -spin_lock_irqsave (&ce->guc_state.lock, flags); -set_context_destroyed (ce); -spin_unlock_irqrestore (&ce->guc_state.lock, flags); - -deregister_context (ce, ce->guc_id); +deregister_context (ce, ce->guc_id, true); }static void __guc_context_destroy (struct intel_context *ce)@@ -1093,13 +1415,15 @@ static void guc_context_destroy(struct kref *kref)struct intel_guc *guc = &ce->engine->gt->uc.guc;intel_wakeref_t wakeref;unsigned long flags; +bool disabled;/* * If the guc_id is invalid this context has been stolen and we can free * it immediately. Also can be freed immediately if the context is not * registered with the GuC. */ -if (context_guc_id_invalid (ce) || +if (submission_disabled (guc) || +context_guc_id_invalid (ce) || !lrc_desc_registered (guc, ce->guc_id)) {release_guc_id (guc, ce);__guc_context_destroy (ce);@@ -1126,6 +1450,18 @@ static void guc_context_destroy(struct kref *kref)list_del_init (&ce->guc_id_link);spin_unlock_irqrestore (&guc->contexts_lock, flags); +/* Seal race with Reset */ +spin_lock_irqsave (&ce->guc_state.lock, flags); + disabled =submission_disabled (guc); +if (likely (!disabled)) +set_context_destroyed (ce); +spin_unlock_irqrestore (&ce->guc_state.lock, flags);
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_context_destroy(struct kref *kref) · line 1462
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +4
-0+if (unlikely (disabled)) { +release_guc_id (guc, ce); +__guc_context_destroy (ce); +return ;Same as above, needs a better comment. It is also hard for reader to know if snapshot of disabled taked under the lock is still valid after the lock has been released and why.
Will pull in the doc comment into this patch.
Matt
Quoted 273 lines
Regards,
Tvrtko
Quoted 269 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +47
-25+ } +/* * We defer GuC context deregistration until the context is destroyed * in order to save on CTBs. With this optimization ideally we only need @@ -1148,6 +1484,33 @@ static int guc_context_alloc(struct intel_context *ce)return lrc_alloc (ce, ce->engine); } +static void add_to_context (struct i915_request *rq) +{ +struct intel_context *ce = rq->context; + +spin_lock (&ce->guc_active.lock); +list_move_tail (&rq->sched.link, &ce->guc_active.requests); +spin_unlock (&ce->guc_active.lock); +} + +static void remove_from_context (struct i915_request *rq) +{ +struct intel_context *ce = rq->context; + +spin_lock_irq (&ce->guc_active.lock); + +list_del_init (&rq->sched.link); +clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); + +/* Prevent further __await_execution() registering a cb, then flush */ +set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); + +spin_unlock_irq (&ce->guc_active.lock); + +atomic_dec (&ce->guc_id_ref); +i915_request_notify_execute_cb_imm (rq); +} +static const struct intel_context_ops guc_context_ops = { .alloc = guc_context_alloc,@@ -1186,8 +1549,6 @@ static void guc_signal_context_fence(struct intel_context *ce) {unsigned long flags; -GEM_BUG_ON (!context_wait_for_deregister_to_register (ce)); -spin_lock_irqsave (&ce->guc_state.lock, flags);clr_context_wait_for_deregister_to_register (ce);__guc_signal_context_fence (ce);@@ -1196,8 +1557,9 @@ static void guc_signal_context_fence(struct intel_context *ce)static bool context_needs_register (struct intel_context *ce,bool new_guc_id) { -return new_guc_id ||test_bit (CONTEXT_LRCA_DIRTY , &ce->flags) || - !lrc_desc_registered (ce_to_guc (ce), ce->guc_id); +return (new_guc_id ||test_bit (CONTEXT_LRCA_DIRTY , &ce->flags) || + !lrc_desc_registered (ce_to_guc (ce), ce->guc_id)) && + !submission_disabled (ce_to_guc (ce)); }static int guc_request_alloc (struct i915_request *rq)@@ -1256,8 +1618,10 @@ static int guc_request_alloc(struct i915_request *rq)return ret;;if (context_needs_register (ce, !!ret)) { - ret =guc_lrc_desc_pin (ce); + ret =guc_lrc_desc_pin (ce, true);if (unlikely (ret)) {/* unwind */ +if (ret == -EDEADLK ) +disable_submission (guc);atomic_dec (&ce->guc_id_ref);unpin_guc_id (guc, ce);return ret;@@ -1294,20 +1658,6 @@ static int guc_request_alloc(struct i915_request *rq)return 0 ; } -static struct intel_engine_cs * -guc_virtual_get_sibling (struct intel_engine_cs *ve,unsigned int sibling) -{ -struct intel_engine_cs *engine; -intel_engine_mask_t tmp, mask = ve->mask; -unsigned int num_siblings =0 ; - -for_each_engine_masked (engine, ve->gt, mask, tmp) -if (num_siblings++ == sibling) -return engine; - -return NULL ; -} -static int guc_virtual_context_pre_pin (struct intel_context *ce,struct i915_gem_ww_ctx *ww,void **vaddr)@@ -1516,7 +1866,7 @@ static inline void guc_kernel_context_pin(struct intel_guc *guc, {if (context_guc_id_invalid (ce))pin_guc_id (guc, ce); -guc_lrc_desc_pin (ce); +guc_lrc_desc_pin (ce, true); }static inline void guc_init_lrc_mapping (struct intel_guc *guc)@@ -1582,13 +1932,15 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; engine->bump_serial = guc_bump_serial; + engine->add_active_request = add_to_context; + engine->remove_active_request = remove_from_context; engine->sched_engine->schedule = i915_schedule; - engine->reset.prepare = guc_reset_prepare; - engine->reset.rewind = guc_reset_rewind; - engine->reset.cancel = guc_reset_cancel; - engine->reset.finish = guc_reset_finish; + engine->reset.prepare = guc_reset_nop; + engine->reset.rewind = guc_rewind_nop; + engine->reset.cancel = guc_reset_nop; + engine->reset.finish = guc_reset_nop; engine->emit_flush = gen8_emit_flush_xcs; engine->emit_init_breadcrumb = gen8_emit_init_breadcrumb;@@ -1764,7 +2116,7 @@ int intel_guc_deregister_done_process_msg(struct intel_guc *guc,* register this context. */ with_intel_runtime_pm(runtime_pm, wakeref) -register_context (ce); +register_context (ce, true);guc_signal_context_fence (ce);intel_context_put (ce); }else if (context_destroyed (ce)) {@@ -1946,6 +2298,10 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count) "v%dx%d", ve->base.class, count); ve->base.context_size = sibling->context_size; + ve->base.add_active_request = + sibling->add_active_request; + ve->base.remove_active_request = + sibling->remove_active_request; ve->base.emit_bb_start = sibling->emit_bb_start; ve->base.emit_flush = sibling->emit_flush; ve->base.emit_init_breadcrumb =drivers/gpu/drm/i915/gt/uc/intel_uc.c +33
-1@@ -565,12 +565,44 @@ void intel_uc_reset_prepare(struct intel_uc *uc) {struct intel_guc *guc = &uc->guc; +/* Firmware expected to be running when this function is called */ if (!intel_guc_is_ready (guc)) -return ; + goto sanitize; + +if (intel_uc_uses_guc_submission (uc)) +intel_guc_submission_reset_prepare (guc); +sanitize:__uc_sanitize (uc); } +void intel_uc_reset (struct intel_uc *uc,bool stalled) +{ +struct intel_guc *guc = &uc->guc; + +/* Firmware can not be running when this function is called */ +if (intel_uc_uses_guc_submission (uc)) +intel_guc_submission_reset (guc, stalled); +} + +void intel_uc_reset_finish (struct intel_uc *uc) +{ +struct intel_guc *guc = &uc->guc; + +/* Firmware expected to be running when this function is called */ +if (intel_guc_is_fw_running (guc) &&intel_uc_uses_guc_submission (uc)) +intel_guc_submission_reset_finish (guc); +} + +void intel_uc_cancel_requests (struct intel_uc *uc) +{ +struct intel_guc *guc = &uc->guc; + +/* Firmware can not be running when this function is called */ +if (intel_uc_uses_guc_submission (uc)) +intel_guc_submission_cancel_requests (guc); +} +void intel_uc_runtime_suspend (struct intel_uc *uc) {struct intel_guc *guc = &uc->guc;drivers/gpu/drm/i915/gt/uc/intel_uc.h +3
-0@@ -37,6 +37,9 @@ void intel_uc_driver_late_release(struct intel_uc *uc);void intel_uc_driver_remove (struct intel_uc *uc);void intel_uc_init_mmio (struct intel_uc *uc);void intel_uc_reset_prepare (struct intel_uc *uc); +void intel_uc_reset (struct intel_uc *uc,bool stalled); +void intel_uc_reset_finish (struct intel_uc *uc); +void intel_uc_cancel_requests (struct intel_uc *uc);void intel_uc_suspend (struct intel_uc *uc);void intel_uc_runtime_suspend (struct intel_uc *uc);int intel_uc_resume (struct intel_uc *uc);drivers/gpu/drm/i915/i915_request.c +4
-37@@ -194,7 +194,7 @@ static bool irq_work_imm(struct irq_work *wrk)return false; } -static void __notify_execute_cb_imm (struct i915_request *rq) +void i915_request_notify_execute_cb_imm (struct i915_request *rq) {__notify_execute_cb (rq, irq_work_imm); }@@ -268,37 +268,6 @@ i915_request_active_engine(struct i915_request *rq,return ret; } - -static void remove_from_engine (struct i915_request *rq) -{ -struct intel_engine_cs *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. -*/ - locked =READ_ONCE (rq->engine); -spin_lock_irq (&locked->sched_engine->lock); -while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { -spin_unlock (&locked->sched_engine->lock); -spin_lock (&engine->sched_engine->lock); - locked = engine; - } -list_del_init (&rq->sched.link); - -clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); -clear_bit (I915_FENCE_FLAG_HOLD , &rq->fence.flags); - -/* Prevent further __await_execution() registering a cb, then flush */ -set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); - -spin_unlock_irq (&locked->sched_engine->lock); - -__notify_execute_cb_imm (rq); -} -static void __rq_init_watchdog (struct i915_request *rq) { rq->watchdog.timer.function =NULL ;@@ -395,9 +364,7 @@ bool i915_request_retire(struct i915_request *rq)* after removing the breadcrumb and signaling it, so that we do not * inadvertently attach the breadcrumb to a completed request. */ -if (!list_empty (&rq->sched.link)) -remove_from_engine (rq); -atomic_dec (&rq->context->guc_id_ref); + rq->engine->remove_active_request (rq);GEM_BUG_ON (!llist_empty (&rq->execute_cb));__list_del_entry (&rq->link);/* poison neither prev/next (RCU walks) */ @@ -539,7 +506,7 @@ __await_execution(struct i915_request *rq,if (llist_add (&cb->work.node.llist, &signal->execute_cb)) {if (i915_request_is_active (signal) ||__request_in_flight (signal)) -__notify_execute_cb_imm (signal); +i915_request_notify_execute_cb_imm (signal); }return 0 ;@@ -676,7 +643,7 @@ bool __i915_request_submit(struct i915_request *request) result = true;GEM_BUG_ON (test_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags)); -list_move_tail (&request->sched.link, &engine->sched_engine->requests); + engine->add_active_request (request); active:clear_bit (I915_FENCE_FLAG_PQUEUE , &request->fence.flags);set_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags);drivers/gpu/drm/i915/i915_request.h +0
-1--- a/drivers/gpu/drm/i915/i915_request.h
Quoted 8 lines
drivers/gpu/drm/i915/i915_request.h bool · line 654
Quoted 8 lines
+++
b/drivers/gpu/drm/i915/i915_request.hdrivers/gpu/drm/i915/i915_request.h +2
-0@@ -649,4 +649,6 @@ bool i915_request_active_engine(struct i915_request *rq, struct intel_engine_cs **active); +void i915_request_notify_execute_cb_imm (struct i915_request *rq); +#endif /* I915_REQUEST_H */
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx