GuC submission support
Subsystems (2)
PATCH 2/47 drm/i915/guc: Improve error message for unsolicited CT response
In reply to Matthew BrostImprove the error message when a unsolicited CT response is received by printing fence that couldn't be found, the last fence, and all requests with a response outstanding.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7 -3
@@ -730,12 +730,16 @@ static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r found = true;break ; } -spin_unlock_irqrestore (&ct->requests.lock, flags); -if (!found) {CT_ERROR (ct,"Unsolicited response (fence %u)\n" , fence); -return -ENOKEY ; +CT_ERROR (ct,"Could not find fence=%u, last_fence=%u\n" , fence, + ct->requests.last_fence); +list_for_each_entry (req, &ct->requests.pending, link) +CT_ERROR (ct,"request %u awaits response\n" , + req->fence); + err = -ENOKEY ; } +spin_unlock_irqrestore (&ct->requests.lock, flags);if (unlikely (err))return err;
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 10/47 drm/i915/guc: Add lrc descriptor context lookup array
In reply to Matthew BrostAdd lrc descriptor context lookup array which can resolve the intel_context from the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +5 -0
@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_ +#include "linux/xarray.h" +#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h"
@@ -46,6 +48,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr; +/* guc_id to intel_context lookup */ +struct xarray context_lookup; +/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +30 -2
@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;
@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;
@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, 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 ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */
@@ -400,6 +426,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool); +xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }
Signature · 1 line
2.28.0
PATCH 17/47 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
@@ -918,7 +918,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)
@@ -1123,19 +1135,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);
@@ -1484,10 +1499,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
cover GuC submission support
As discussed in [1], [2] we are enabling GuC submission support in the i915. This is a subset of the patches in step 5 described in [1], basically it is absolute to enable CI with GuC submission on gen11+ platforms.
This series itself will likely be broken down into smaller patch sets to merge. Likely into CTBs changes, basic submission, virtual engines, and resets.
A following series will address the missing patches remaining from [1].
Locally tested on TGL machine and basic tests seem to be passing.
[1] https://patchwork.freedesktop.org/series/89844/
[2] https://patchwork.freedesktop.org/series/91417/
Daniele Ceraolo Spurio (1):
drm/i915/guc: Unblock GuC submission on Gen11+
John Harrison (10):
drm/i915/guc: Module load failure test for CT buffer creation drm/i915: Track 'serial' counts for virtual engines drm/i915/guc: Provide mmio list to be saved/restored on engine reset drm/i915/guc: Don't complain about reset races drm/i915/guc: Enable GuC engine reset
drm/i915/guc: Fix for error capture after full GPU reset with GuC drm/i915/guc: Hook GuC scheduling policies up drm/i915/guc: Connect reset modparam updates to GuC policy flags drm/i915/guc: Include scheduling policies in the debugfs state dump drm/i915/guc: Add golden context to GuC ADS
Matthew Brost (36):
drm/i915/guc: Relax CTB response timeout
drm/i915/guc: Improve error message for unsolicited CT response drm/i915/guc: Increase size of CTB buffers
drm/i915/guc: Add non blocking CTB send function drm/i915/guc: Add stall timer to non blocking CTB send function drm/i915/guc: Optimize CTB writes and reads
drm/i915/guc: Add new GuC interface defines and structures drm/i915/guc: Remove GuC stage descriptor, add lrc descriptor drm/i915/guc: Add lrc descriptor context lookup array drm/i915/guc: Implement GuC submission tasklet drm/i915/guc: Add bypass tasklet submission path to GuC drm/i915/guc: Implement GuC context operations for new inteface drm/i915/guc: Insert fence on context when deregistering drm/i915/guc: Defer context unpin until scheduling is disabled drm/i915/guc: Disable engine barriers with GuC during unpin drm/i915/guc: Extend deregistration fence to schedule disable drm/i915: Disable preempt busywait when using GuC scheduling drm/i915/guc: Ensure request ordering via completion fences drm/i915/guc: Disable semaphores when using GuC scheduling drm/i915/guc: Ensure G2H response has space in buffer drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC drm/i915/guc: Update GuC debugfs to support new GuC drm/i915/guc: Add several request trace points
drm/i915: Add intel_context tracing
drm/i915/guc: GuC virtual engines
drm/i915: Hold reference to intel_context over life of i915_request drm/i915/guc: Disable bonding extension with GuC submission drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs drm/i915/guc: Reset implementation for new GuC interface drm/i915: Reset GPU immediately if submission is disabled drm/i915/guc: Add disable interrupts to guc sanitize drm/i915/guc: Suspend/resume implementation for new interface drm/i915/guc: Handle context reset notification drm/i915/guc: Handle engine reset failure notification drm/i915/guc: Enable the timer expired interrupt for GuC drm/i915/guc: Capture error state on context reset
drivers/gpu/drm/i915/gem/i915_gem_context.c | 30 +- drivers/gpu/drm/i915/gem/i915_gem_context.h | 1 + drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/gen8_engine_cs.c | 6 +- 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_context.c | 41 +- drivers/gpu/drm/i915/gt/intel_context.h | 31 +- drivers/gpu/drm/i915/gt/intel_context_types.h | 49 + drivers/gpu/drm/i915/gt/intel_engine.h | 72 +- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 182 +- .../gpu/drm/i915/gt/intel_engine_heartbeat.c | 71 +- .../gpu/drm/i915/gt/intel_engine_heartbeat.h | 4 + drivers/gpu/drm/i915/gt/intel_engine_types.h | 12 +- .../drm/i915/gt/intel_execlists_submission.c | 234 +- .../drm/i915/gt/intel_execlists_submission.h | 11 - drivers/gpu/drm/i915/gt/intel_gt.c | 21 + drivers/gpu/drm/i915/gt/intel_gt.h | 2 + drivers/gpu/drm/i915/gt/intel_gt_pm.c | 6 +- drivers/gpu/drm/i915/gt/intel_gt_requests.c | 22 +- drivers/gpu/drm/i915/gt/intel_gt_requests.h | 9 +- drivers/gpu/drm/i915/gt/intel_lrc_reg.h | 1 - drivers/gpu/drm/i915/gt/intel_reset.c | 20 +- .../gpu/drm/i915/gt/intel_ring_submission.c | 28 + drivers/gpu/drm/i915/gt/intel_rps.c | 4 + drivers/gpu/drm/i915/gt/intel_workarounds.c | 46 +- .../gpu/drm/i915/gt/intel_workarounds_types.h | 1 + drivers/gpu/drm/i915/gt/mock_engine.c | 41 +- drivers/gpu/drm/i915/gt/selftest_context.c | 10 + drivers/gpu/drm/i915/gt/selftest_execlists.c | 20 +- .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h | 15 + drivers/gpu/drm/i915/gt/uc/intel_guc.c | 82 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 106 +- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 460 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h | 3 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 318 ++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 22 +- .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 25 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 88 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 2197 +++++++++++++++-- .../gpu/drm/i915/gt/uc/intel_guc_submission.h | 17 +- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 102 +- drivers/gpu/drm/i915/gt/uc/intel_uc.h | 11 + drivers/gpu/drm/i915/i915_debugfs.c | 2 + drivers/gpu/drm/i915/i915_debugfs_params.c | 31 + drivers/gpu/drm/i915/i915_gem_evict.c | 1 + drivers/gpu/drm/i915/i915_gpu_error.c | 25 +- drivers/gpu/drm/i915/i915_reg.h | 2 + drivers/gpu/drm/i915/i915_request.c | 159 +- drivers/gpu/drm/i915/i915_request.h | 21 + drivers/gpu/drm/i915/i915_scheduler.c | 6 + drivers/gpu/drm/i915/i915_scheduler.h | 6 + drivers/gpu/drm/i915/i915_scheduler_types.h | 5 + drivers/gpu/drm/i915/i915_trace.h | 197 +- .../gpu/drm/i915/selftests/igt_live_test.c | 2 +- .../gpu/drm/i915/selftests/mock_gem_device.c | 3 +- 57 files changed, 4159 insertions(+), 787 deletions(-)
Signature · 1 line
2.28.0
PATCH 11/47 drm/i915/guc: Implement GuC submission tasklet
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.
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 to intel_context and is not assigned. Patches later in the series will assign this value.
--- 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 | 231 +++++++++--------- 3 files changed, 127 insertions(+), 117 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 +114 -117
349 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
PATCH 24/47 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
@@ -422,6 +422,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 ;
@@ -642,6 +643,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
PATCH 14/47 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
PATCH 5/47 drm/i915/guc: Add stall timer to non blocking CTB send function
In reply to Matthew BrostImplement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Also update to ct_write to return -EIO rather than -EPIPE on a corrupted descriptor.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 47 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 ++ 2 files changed, 48 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +44 -3
@@ -319,6 +319,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) goto err_deregister; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;
@@ -392,7 +393,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EIO ;if (unlikely (desc->status)) goto corrupted;
@@ -464,7 +465,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EIO ; }/**
@@ -507,6 +508,18 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +#define GUC_CTB_TIMEOUT_MS 1500 +static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +long timeout =GUC_CTB_TIMEOUT_MS ; +bool ret =ktime_ms_delta (ktime_get (), ct->stall_time) > timeout; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" ); + +return ret; +} +static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;
@@ -518,6 +531,26 @@ static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; } +static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct))) +return -EIO ; +else +return -EBUSY ; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,
@@ -530,7 +563,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =h2g_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;
@@ -574,11 +607,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EIO ; +cond_resched (); goto retry; } + ct->stall_time =KTIME_MAX ; + fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4 -0
@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h"
@@ -68,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time; };void intel_guc_ct_init_early (struct intel_guc_ct *ct);
Signature · 1 line
2.28.0
PATCH 1/47 drm/i915/guc: Relax CTB response timeout
In reply to Matthew BrostIn upcoming patch we will allow more CTB requests to be sent in parallel to the GuC for processing, so we shouldn't assume any more that GuC will always reply without 10ms.
Use bigger value hardcoded value of 1s instead.
v2: Add CONFIG_DRM_I915_GUC_CTB_TIMEOUT config option v3:
(Daniel Vetter)
- Use hardcoded value of 1s rather than config option
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4 -2
@@ -474,14 +474,16 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)/* * Fast commands should complete in less than 10us, so sample quickly * up to that length of time, then switch to a slower sleep-wait loop. -* No GuC command should ever take longer than 10ms. +* No GuC command should ever take longer than 10ms but many GuC +* commands can be inflight at time, so use a 1s timeout on the slower +* sleep-wait loop. */ #define done \ (FIELD_GET(GUC_HXG_MSG_0_ORIGIN, READ_ONCE(req->status)) == \ GUC_HXG_ORIGIN_GUC) err =wait_for_us (done,10 );if (err) - err =wait_for (done,10 ); + err =wait_for (done,1000 );#undef doneif (unlikely (err))
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 12/47 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
@@ -172,6 +172,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;
@@ -215,8 +221,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
@@ -496,20 +501,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)); - -tasklet_hi_schedule (&sched_engine->tasklet); +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 ) +tasklet_hi_schedule (&sched_engine->tasklet);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
PATCH 8/47 drm/i915/guc: Add new GuC interface defines and structures
In reply to Matthew BrostAdd new GuC interface defines and structures while maintaining old ones in parallel.
--- .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h | 14 +++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+)
drivers/gpu/drm/i915/gt/uc/abi/guc_actions_abi.h +14 -0
@@ -124,10 +124,24 @@ enum intel_guc_action {INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH =0x302 ,INTEL_GUC_ACTION_ENTER_S_STATE =0x501 ,INTEL_GUC_ACTION_EXIT_S_STATE =0x502 , +INTEL_GUC_ACTION_GLOBAL_SCHED_POLICY_CHANGE =0x506 , +INTEL_GUC_ACTION_SCHED_CONTEXT =0x1000 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET =0x1001 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE =0x1002 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_SET =0x1003 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_DONE =0x1004 , +INTEL_GUC_ACTION_SET_CONTEXT_PRIORITY =0x1005 , +INTEL_GUC_ACTION_SET_CONTEXT_EXECUTION_QUANTUM =0x1006 , +INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT =0x1007 , +INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION =0x1008 , +INTEL_GUC_ACTION_ENGINE_FAILURE_NOTIFICATION =0x1009 ,INTEL_GUC_ACTION_SLPC_REQUEST =0x3003 ,INTEL_GUC_ACTION_AUTHENTICATE_HUC =0x4000 , +INTEL_GUC_ACTION_REGISTER_CONTEXT =0x4502 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT =0x4503 ,INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER =0x4505 ,INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER =0x4506 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE =0x4600 ,INTEL_GUC_ACTION_LIMIT };
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +41 -0
59 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
PATCH 22/47 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.
v2: rtimeout -> remaining_timeout
--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 3 +- drivers/gpu/drm/i915/gt/intel_gt.c | 19 ++++ 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 | 9 +- 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 | 88 ++++++++++++++++++- 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
@@ -644,7 +644,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 +19 -0
@@ -585,6 +585,25 @@ 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 remaining_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, + &remaining_timeout)) >0 ) { +cond_resched (); +if (signal_pending (current)) +return -EINTR ; + } + +return timeout ? timeout :intel_uc_wait_for_idle (>->uc, + remaining_timeout); +} +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 *remaining_timeout) {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 (remaining_timeout) + *remaining_timeout = 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 +5 -4
@@ -6,14 +6,17 @@#ifndef INTEL_GT_REQUESTS_H #define INTEL_GT_REQUESTS_H +#include <stddef.h> +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 *remaining_timeout);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 +24,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 {void (*reset)(struct intel_guc *guc);void (*enable)(struct intel_guc *guc);
@@ -238,6 +240,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
@@ -109,6 +109,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_setup (&ct->receive_tasklet, ct_receive_tasklet_func); +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 +84 -4
142 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
@@ -52,7 +52,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
PATCH 4/47 drm/i915/guc: Add non blocking CTB send function
In reply to Matthew BrostAdd non blocking CTB send function, intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.
The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function, intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +10 -2
@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31) +static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int
@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +71 -6
133 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1 -2
@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking
@@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 21/47 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 | 76 +++++++++++++++---- 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, 87 insertions(+), 23 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +10 -3
@@ -95,11 +95,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
@@ -113,6 +119,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;
@@ -121,7 +128,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 +62 -14
186 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_communication_ctb_abi.h" #include "abi/guc_messages_abi.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
@@ -260,6 +260,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));
@@ -271,13 +272,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) {
@@ -730,7 +731,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)
@@ -750,7 +751,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)
@@ -889,7 +891,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
PATCH 7/47 drm/i915/guc: Module load failure test for CT buffer creation
In reply to Matthew BrostFrom: John Harrison <[email protected]>
Add several module failure load inject points in the CT buffer creation code path.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8 -0
@@ -175,6 +175,10 @@ static int ct_register_buffer(struct intel_guc_ct *ct, u32 type, {int err; + err =i915_inject_probe_error (guc_to_gt (ct_to_guc (ct))->i915, -ENXIO ); +if (unlikely (err)) +return err; + err =guc_action_register_ct_buffer (ct_to_guc (ct), type, desc_addr, buff_addr, size);if (unlikely (err))
@@ -226,6 +230,10 @@ int intel_guc_ct_init(struct intel_guc_ct *ct)u32 *cmds;int err; + err =i915_inject_probe_error (guc_to_gt (guc)->i915, -ENXIO ); +if (err) +return err; +GEM_BUG_ON (ct->vma); blob_size =2 *CTB_DESC_SIZE +CTB_H2G_BUFFER_SIZE +CTB_G2H_BUFFER_SIZE ;
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/47 drm/i915/guc: Increase size of CTB buffers
In reply to Matthew BrostWith the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8 -3
@@ -58,11 +58,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 2 dwords which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)struct ct_request {struct list_head link;
@@ -641,7 +646,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);GEM_BUG_ON (available <0 ); header = cmds[head];
Signature · 1 line
2.28.0
PATCH 43/47 drm/i915/guc: Hook GuC scheduling policies up
In reply to Matthew BrostFrom: John Harrison <[email protected]>
Use the official driver default scheduling policies for configuring the GuC scheduler rather than a bunch of hardcoded values.
--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 44 ++++++++++++++++++- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 11 +++-- 4 files changed, 53 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_types.h +1 -0
@@ -455,6 +455,7 @@ struct intel_engine_cs {#define I915_ENGINE_IS_VIRTUAL BIT(5)#define I915_ENGINE_HAS_RELATIVE_MMIO BIT(6)#define I915_ENGINE_REQUIRES_CMD_PARSER BIT(7) +#define I915_ENGINE_WANT_FORCED_PREEMPTION BIT(8)unsigned int flags;/*
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
@@ -270,6 +270,8 @@ int intel_guc_engine_failure_process_msg(struct intel_guc *guc,void intel_guc_find_hung_context (struct intel_engine_cs *engine); +int intel_guc_global_policies_update (struct intel_guc *guc); +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);
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +42 -2
63 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8 -3
@@ -873,6 +873,7 @@ void intel_guc_submission_reset_finish(struct intel_guc *guc)GEM_WARN_ON (atomic_read (&guc->outstanding_submission_g2h));atomic_set (&guc->outstanding_submission_g2h,0 ); +intel_guc_global_policies_update (guc);enable_submission (guc);intel_gt_unpark_heartbeats (guc_to_gt (guc)); }
@@ -1161,8 +1162,12 @@ static void guc_context_policy_init(struct intel_engine_cs *engine, { desc->policy_flags =0 ; - desc->execution_quantum =CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US ; - desc->preemption_timeout =CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US ; +if (engine->flags &I915_ENGINE_WANT_FORCED_PREEMPTION ) + desc->policy_flags |=CONTEXT_POLICY_FLAG_PREEMPT_TO_IDLE ; + +/* NB: For both of these, zero means disabled. */ + desc->execution_quantum = engine->props.timeslice_duration_ms *1000 ; + desc->preemption_timeout = engine->props.preempt_timeout_ms *1000 ; }static int guc_lrc_desc_pin (struct intel_context *ce,bool loop)
@@ -1945,13 +1950,13 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->set_default_submission = guc_set_default_submission; engine->flags |=I915_ENGINE_HAS_PREEMPTION ; + engine->flags |=I915_ENGINE_HAS_TIMESLICES ;/* * TODO: GuC supports timeslicing and semaphores as well, but they're * handled by the firmware so some minor tweaks are required before * enabling. * -* engine->flags |= I915_ENGINE_HAS_TIMESLICES; * engine->flags |= I915_ENGINE_HAS_SEMAPHORES; */
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 30/47 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 | 2 +- drivers/gpu/drm/i915/gt/mock_engine.c | 4 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 67 +++++++++++++++++-- 9 files changed, 131 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
@@ -212,6 +212,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
@@ -739,7 +739,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;
@@ -947,7 +947,7 @@ void intel_engine_cleanup_common(struct intel_engine_cs *engine)GEM_BUG_ON (!list_empty (&engine->sched_engine->requests));i915_sched_engine_put (engine->sched_engine); -intel_breadcrumbs_free (engine->breadcrumbs); +intel_breadcrumbs_put (engine->breadcrumbs);intel_engine_fini_retire (engine);intel_engine_cleanup_cmd_parser (engine);
@@ -1264,6 +1264,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 +1 -1
@@ -3419,7 +3419,7 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)intel_context_fini (&ve->context);if (ve->base.breadcrumbs) -intel_breadcrumbs_free (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);
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 · 1 line
2.28.0
PATCH 36/47 drm/i915/guc: Handle engine reset failure notification
In reply to Matthew BrostGuC will notify the driver, via G2H, if it fails to reset an engine. We recover by resorting to a full GPU reset.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 3 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 43 +++++++++++++++++++ 3 files changed, 48 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
@@ -264,6 +264,8 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc, const u32 *msg, u32 len);int intel_guc_context_reset_process_msg (struct intel_guc *guc,const u32 *msg,u32 len); +int intel_guc_engine_failure_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);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3 -0
@@ -948,6 +948,9 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *rcase INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION : ret =intel_guc_context_reset_process_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_ENGINE_FAILURE_NOTIFICATION : + ret =intel_guc_engine_failure_process_msg (guc, payload, len); +break ;default : ret = -EOPNOTSUPP ;break ;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +43 -0
49 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 18/47 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
PATCH 15/47 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 | 27 +++- 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 | 3 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 145 +++++++++++++++++- 6 files changed, 179 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 +26 -1
@@ -113,7 +113,32 @@ 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 { +/* +* Move ownership of this pin to the scheduling disable which is +* an async operation. When that operation completes the above +* intel_context_sched_disable_unpin is called potentially +* unpinning the context. +*/ +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
@@ -236,6 +236,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 +3 -0
@@ -905,6 +905,9 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *r ret =intel_guc_deregister_done_process_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE : + ret =intel_guc_sched_done_process_msg (guc, payload, len); +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 · 1 line
2.28.0
PATCH 31/47 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 | 13 - drivers/gpu/drm/i915/gt/uc/intel_guc.h | 8 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 581 ++++++++++++++---- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 39 +- 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, 649 insertions(+), 171 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
@@ -426,6 +426,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
@@ -3118,6 +3118,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 (GRAPHICS_VER (engine->i915) >8 )
@@ -3218,6 +3254,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;
@@ -3912,6 +3950,8 @@ execlists_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 = 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
@@ -826,6 +826,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;
@@ -850,6 +852,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)
@@ -903,6 +907,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);
@@ -1191,6 +1196,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 ;
@@ -1201,13 +1209,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; }
@@ -1341,7 +1346,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
@@ -1049,6 +1049,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;
@@ -1066,6 +1085,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 +0 -13
@@ -572,19 +572,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
@@ -242,14 +242,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 +472 -109
878 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_uc.c +38 -1
@@ -565,12 +565,49 @@ void intel_uc_reset_prepare(struct intel_uc *uc) {struct intel_guc *guc = &uc->guc; -if (!intel_guc_is_ready (guc)) + +/* Nothing to do if GuC isn't supported */ +if (!intel_uc_supports_guc (uc))return ; +/* Firmware expected to be running when this function is called */ +if (!intel_guc_is_ready (guc)) + 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 · 1 line
2.28.0
PATCH 6/47 drm/i915/guc: Optimize CTB writes and reads
In reply to Matthew BrostCTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail) which could result in accesses across the PCIe bus, store shadow local copies and only read/write the descriptor values when absolutely necessary. Also store the current space in the each channel locally.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 ++++++++++++++--------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 51 insertions(+), 31 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +45 -31
@@ -130,6 +130,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }
@@ -383,10 +387,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;
@@ -398,25 +400,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence)
@@ -457,7 +448,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;return 0 ;
@@ -473,7 +466,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value.
@@ -520,24 +513,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) { -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head); +if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;return space >= len_dw; }static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();
@@ -606,10 +610,10 @@ static int ct_send(struct intel_guc_ct *ct,*/ retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (ct_deadlocked (ct)))return -EIO ;
@@ -632,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (err)) goto unlink;
@@ -720,7 +724,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;
@@ -735,12 +739,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) { +CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;
@@ -790,6 +803,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +6 -0
@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands 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 * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {
@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;bool broken; };
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 13/47 drm/i915/guc: Implement GuC context operations for new inteface
In reply to Matthew BrostImplement GuC context operations which includes GuC specific operations alloc, 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 | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 664 ++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + 8 files changed, 677 insertions(+), 55 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
@@ -44,6 +44,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 stolen +*/ +spinlock_t contexts_lock; +struct ida guc_ids; +struct list_head guc_id_list; +bool submission_selected;struct i915_vma *ads_vma;
@@ -102,6 +110,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);
@@ -203,6 +234,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 +4 -0
@@ -901,6 +901,10 @@ 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); +break ;default : ret = -EOPNOTSUPP ;break ;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +613 -51
754 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +1 -0
@@ -4142,6 +4142,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
PATCH 26/47 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"
@@ -1568,9 +1567,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 ;
@@ -1627,7 +1623,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;
@@ -1723,13 +1719,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 ;
@@ -2116,8 +2108,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
@@ -1736,6 +1736,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
@@ -3727,7 +3727,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;
@@ -3923,7 +3923,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;
@@ -4054,7 +4054,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;
@@ -4106,7 +4106,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;
@@ -4208,7 +4208,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;
@@ -4431,16 +4431,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);
@@ -4576,7 +4576,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
PATCH 23/47 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
@@ -1135,3 +1135,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 · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 44/47 drm/i915/guc: Connect reset modparam updates to GuC policy flags
In reply to Matthew BrostFrom: John Harrison <[email protected]>
Changing the reset module parameter has no effect on a running GuC. The corresponding entry in the ADS must be updated and then the GuC informed via a Host2GuC message.
The new debugfs interface to module parameters allows this to happen. However, connecting the parameter data address back to anything useful is messy. One option would be to pass a new private data structure address through instead of just the parameter pointer. However, that means having a new (and different) data structure for each parameter and a new (and different) write function for each parameter. This method keeps everything generic by instead using a string lookup on the directory entry name.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 2 +- drivers/gpu/drm/i915/i915_debugfs_params.c | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +1 -1
@@ -99,7 +99,7 @@ static int guc_action_policies_update(struct intel_guc *guc, u32 policy_offset) policy_offset }; -return intel_guc_send (guc, action,ARRAY_SIZE (action)); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }int intel_guc_global_policies_update (struct intel_guc *guc)
drivers/gpu/drm/i915/i915_debugfs_params.c +31 -0
@@ -6,9 +6,20 @@#include <linux/kernel.h> #include "i915_debugfs_params.h" +#include "gt/intel_gt.h" +#include "gt/uc/intel_guc.h" #include "i915_drv.h" #include "i915_params.h" +#define MATCH_DEBUGFS_NODE_NAME (_file, _name) (strcmp((_file)->f_path.dentry->d_name.name, (_name)) == 0) + +#define GET_I915 (i915, name, ptr) \ + do { \ + struct i915_params *params; \ + params = container_of(((void *) (ptr)), typeof(*params), name); \ + (i915) = container_of(params, typeof(*(i915)), params); \ + } while(0) +/* int param */ static int i915_param_int_show (struct seq_file *m,void *data) {
@@ -24,6 +35,16 @@ static int i915_param_int_open(struct inode *inode, struct file *file)return single_open (file, i915_param_int_show, inode->i_private); } +static int notify_guc (struct drm_i915_private *i915) +{ +int ret =0 ; + +if (intel_uc_uses_guc_submission (&i915->gt.uc)) + ret =intel_guc_global_policies_update (&i915->gt.uc.guc); + +return ret; +} +static ssize_t i915_param_int_write (struct file *file,const char __user *ubuf,size_t len,loff_t *offp)
@@ -81,8 +102,10 @@ static ssize_t i915_param_uint_write(struct file *file, const char __user *ubuf, size_t len, loff_t *offp) { + struct drm_i915_private *i915;struct seq_file *m = file->private_data;unsigned int *value = m->private; +unsigned int old = *value;int ret; ret =kstrtouint_from_user (ubuf, len,0 , value);
@@ -95,6 +118,14 @@ static ssize_t i915_param_uint_write(struct file *file, *value = b; } +if (!ret &&MATCH_DEBUGFS_NODE_NAME (file,"reset" )) { +GET_I915 (i915, reset, value); + + ret =notify_guc (i915); +if (ret) + *value = old; + } +return ret ?: len; }
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 37/47 drm/i915/guc: Enable the timer expired interrupt for GuC
In reply to Matthew BrostThe GuC can implement execution qunatums, detect hung contexts and other such things but it requires the timer expired interrupt to do so.
--- drivers/gpu/drm/i915/gt/intel_rps.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/gt/intel_rps.c +4 -0
@@ -1877,6 +1877,10 @@ void intel_rps_init(struct intel_rps *rps)if (GRAPHICS_VER (i915) >=8 &&GRAPHICS_VER (i915) <11 ) rps->pm_intrmsk_mbz |=GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC ; + +/* GuC needs ARAT expired interrupt unmasked */ +if (intel_uc_uses_guc_submission (&rps_to_gt (rps)->uc)) + rps->pm_intrmsk_mbz |=ARAT_EXPIRED_INTRMSK ; }void intel_rps_sanitize (struct intel_rps *rps)
Signature · 1 line
2.28.0
PATCH 16/47 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 ++++++++++ 3 files changed, 12 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",
Signature · 1 line
2.28.0
PATCH 9/47 drm/i915/guc: Remove GuC stage descriptor, add lrc descriptor
In reply to Matthew BrostRemove old GuC stage descriptor, add lrc descriptor which will be used by the new GuC interface implemented in this patch series.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 65 ----------------- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 72 ++++++------------- 3 files changed, 25 insertions(+), 116 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -2
@@ -43,8 +43,8 @@ struct intel_guc {struct i915_vma *ads_vma;struct __guc_ads_blob *ads_blob; -struct i915_vma *stage_desc_pool; -void *stage_desc_pool_vaddr; +struct i915_vma *lrc_desc_pool; +void *lrc_desc_pool_vaddr;/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +0 -65
77 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +23 -49
121 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
PATCH 19/47 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
@@ -926,7 +926,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 · 1 line
2.28.0
PATCH 29/47 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
@@ -1674,6 +1674,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 · 1 line
2.28.0
PATCH 45/47 drm/i915/guc: Include scheduling policies in the debugfs state dump
In reply to Matthew BrostFrom: John Harrison <[email protected]>
Added the scheduling policy parameters to the 'guc_info' debugfs state dump.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 13 +++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h | 2 ++ drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 2 ++ 3 files changed, 17 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +13 -0
@@ -92,6 +92,19 @@ static void guc_policies_init(struct intel_guc *guc, struct guc_policies *polici policies->is_valid =1 ; } +void intel_guc_log_policy_info (struct intel_guc *guc,struct drm_printer *dp) +{ +struct __guc_ads_blob *blob = guc->ads_blob; + +if (unlikely (!blob)) +return ; + +drm_printf (dp,"Global scheduling policies:\n" ); +drm_printf (dp," DPC promote time = %u\n" , blob->policies.dpc_promote_time); +drm_printf (dp," Max num work items = %u\n" , blob->policies.max_num_work_items); +drm_printf (dp," Flags = %u\n" , blob->policies.global_flags); +} +static int guc_action_policies_update (struct intel_guc *guc,u32 policy_offset) {u32 action[] = {
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h +2 -0
@@ -7,9 +7,11 @@#define _INTEL_GUC_ADS_H_struct intel_guc ; +struct drm_printer ;int intel_guc_ads_create (struct intel_guc *guc);void intel_guc_ads_destroy (struct intel_guc *guc);void intel_guc_ads_reset (struct intel_guc *guc); +void intel_guc_log_policy_info (struct intel_guc *guc,struct drm_printer *p);#endif
drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +2 -0
@@ -10,6 +10,7 @@#include "intel_guc_debugfs.h" #include "intel_guc_log_debugfs.h" #include "gt/uc/intel_guc_ct.h" +#include "gt/uc/intel_guc_ads.h" #include "gt/uc/intel_guc_submission.h" static int guc_info_show (struct seq_file *m,void *data)
@@ -29,6 +30,7 @@ static int guc_info_show(struct seq_file *m, void *data)intel_guc_log_ct_info (&guc->ct, &p);intel_guc_log_submission_info (guc, &p); +intel_guc_log_policy_info (guc, &p);return 0 ; }
Signature · 1 line
2.28.0
PATCH 38/47 drm/i915/guc: Provide mmio list to be saved/restored on engine reset
In reply to Matthew BrostFrom: John Harrison <[email protected]>
The driver must provide GuC with a list of mmio registers that should be saved/restored during a GuC-based engine reset. Unfortunately, the list must be dynamically allocated as its size is variable. That means the driver must generate the list twice - once to work out the size and a second time to actually save it.
--- drivers/gpu/drm/i915/gt/intel_workarounds.c | 46 ++-- .../gpu/drm/i915/gt/intel_workarounds_types.h | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 199 +++++++++++++++++- drivers/gpu/drm/i915/i915_reg.h | 1 + 5 files changed, 222 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/gt/intel_workarounds.c +24 -22
@@ -150,13 +150,14 @@ static void _wa_add(struct i915_wa_list *wal, const struct i915_wa *wa) }static void wa_add (struct i915_wa_list *wal,i915_reg_t reg, -u32 clear,u32 set,u32 read_mask) +u32 clear,u32 set,u32 read_mask,bool masked_reg) {struct i915_wa wa = { .reg = reg, .clr = clear, .set = set, .read = read_mask, + .masked_reg = masked_reg, };_wa_add (wal, &wa);
@@ -165,7 +166,7 @@ static void wa_add(struct i915_wa_list *wal, i915_reg_t reg,static void wa_write_clr_set (struct i915_wa_list *wal,i915_reg_t reg,u32 clear,u32 set) { -wa_add (wal, reg, clear, set, clear); +wa_add (wal, reg, clear, set, clear, false); } static void
@@ -200,20 +201,20 @@ wa_write_clr(struct i915_wa_list *wal, i915_reg_t reg, u32 clr)static void wa_masked_en (struct i915_wa_list *wal,i915_reg_t reg,u32 val) { -wa_add (wal, reg,0 ,_MASKED_BIT_ENABLE (val), val); +wa_add (wal, reg,0 ,_MASKED_BIT_ENABLE (val), val, true); }static void wa_masked_dis (struct i915_wa_list *wal,i915_reg_t reg,u32 val) { -wa_add (wal, reg,0 ,_MASKED_BIT_DISABLE (val), val); +wa_add (wal, reg,0 ,_MASKED_BIT_DISABLE (val), val, true); }static void wa_masked_field_set (struct i915_wa_list *wal,i915_reg_t reg,u32 mask,u32 val) { -wa_add (wal, reg,0 ,_MASKED_FIELD (mask, val), mask); +wa_add (wal, reg,0 ,_MASKED_FIELD (mask, val), mask, true); } static void gen6_ctx_workarounds_init(struct intel_engine_cs *engine,
@@ -583,10 +584,10 @@ static void icl_ctx_workarounds_init(struct intel_engine_cs *engine, GEN11_BLEND_EMB_FIX_DISABLE_IN_RCC);/* WaEnableFloatBlendOptimization:icl */ -wa_write_clr_set (wal, -GEN10_CACHE_MODE_SS , -0 ,/* write-only, so skip validation */ -_MASKED_BIT_ENABLE (FLOAT_BLEND_OPTIMIZATION_ENABLE )); +wa_add (wal,GEN10_CACHE_MODE_SS ,0 , +_MASKED_BIT_ENABLE (FLOAT_BLEND_OPTIMIZATION_ENABLE ), +0 /* write-only, so skip validation */ , + true);/* WaDisableGPGPUMidThreadPreemption:icl */ wa_masked_field_set(wal, GEN8_CS_CHICKEN1,
@@ -631,7 +632,7 @@ static void gen12_ctx_gt_tuning_init(struct intel_engine_cs *engine,FF_MODE2 ,FF_MODE2_TDS_TIMER_MASK ,FF_MODE2_TDS_TIMER_128 , - 0); + 0, false); } static void gen12_ctx_workarounds_init(struct intel_engine_cs *engine,
@@ -669,7 +670,7 @@ static void gen12_ctx_workarounds_init(struct intel_engine_cs *engine,FF_MODE2 ,FF_MODE2_GS_TIMER_MASK ,FF_MODE2_GS_TIMER_224 , - 0); + 0, false); } static void dg1_ctx_workarounds_init(struct intel_engine_cs *engine,
@@ -840,7 +841,7 @@ hsw_gt_workarounds_init(struct drm_i915_private *i915, struct i915_wa_list *wal)wa_add (wal,HSW_ROW_CHICKEN3 ,0 ,_MASKED_BIT_ENABLE (HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE ), -0 /* XXX does this reg exist? */ ); +0 /* XXX does this reg exist? */ , true);/* WaVSRefCountFullforceMissDisable:hsw */ wa_write_clr (wal,GEN7_FF_THREAD_MODE ,GEN7_FF_VS_REF_CNT_FFME );
@@ -1929,10 +1930,10 @@ rcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal)* disable bit, which we don't touch here, but it's good * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). */ -wa_add (wal,GEN7_GT_MODE ,0 , -_MASKED_FIELD (GEN6_WIZ_HASHING_MASK , - GEN6_WIZ_HASHING_16x4), - GEN6_WIZ_HASHING_16x4); +wa_masked_field_set (wal, +GEN7_GT_MODE , +GEN6_WIZ_HASHING_MASK , + GEN6_WIZ_HASHING_16x4); }if (IS_GRAPHICS_VER (i915,6 ,7 ))
@@ -1982,10 +1983,10 @@ rcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal)* disable bit, which we don't touch here, but it's good * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). */ -wa_add (wal, -GEN6_GT_MODE ,0 , -_MASKED_FIELD (GEN6_WIZ_HASHING_MASK , GEN6_WIZ_HASHING_16x4), - GEN6_WIZ_HASHING_16x4); +wa_masked_field_set (wal, +GEN7_GT_MODE , +GEN6_WIZ_HASHING_MASK , + GEN6_WIZ_HASHING_16x4);/* WaDisable_RenderCache_OperationalFlush:snb */ wa_masked_dis (wal,CACHE_MODE_0 ,RC_OP_FLUSH_ENABLE );
@@ -2006,7 +2007,7 @@ rcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal)wa_add (wal,MI_MODE ,0 ,_MASKED_BIT_ENABLE (VS_TIMER_DISPATCH ),/* XXX bit doesn't stick on Broadwater */ -IS_I965G (i915) ?0 :VS_TIMER_DISPATCH ); +IS_I965G (i915) ?0 :VS_TIMER_DISPATCH , true);if (GRAPHICS_VER (i915) ==4 )/*
@@ -2021,7 +2022,8 @@ rcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal)*/ wa_add (wal,ECOSKPD ,0 ,_MASKED_BIT_ENABLE (ECO_CONSTANT_BUFFER_SR_DISABLE ), -0 /* XXX bit doesn't stick on Broadwater */ ); +0 /* XXX bit doesn't stick on Broadwater */ , + true); } static void
drivers/gpu/drm/i915/gt/intel_workarounds_types.h +1 -0
@@ -15,6 +15,7 @@ struct i915_wa {u32 clr;u32 set;u32 read; +bool masked_reg; };struct i915_wa_list {
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1 -0
@@ -58,6 +58,7 @@ struct intel_guc {struct i915_vma *ads_vma;struct __guc_ads_blob *ads_blob; +u32 ads_regset_size;struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr;
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +195 -4
250 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +1 -0
@@ -12289,6 +12289,7 @@ enum skl_power_gate {/* MOCS (Memory Object Control State) registers */ #define GEN9_LNCFCMOCS (i) _MMIO(0xb020 + (i) * 4)/* L3 Cache Control */ +#define GEN9_LNCFCMOCS_REG_COUNT 32#define __GEN9_RCS0_MOCS0 0xc800#define GEN9_GFX_MOCS (i) _MMIO(__GEN9_RCS0_MOCS0 + (i) * 4)
Signature · 1 line
2.28.0
PATCH 34/47 drm/i915/guc: Suspend/resume implementation for new interface
In reply to Matthew BrostThe new GuC interface introduces an MMIO H2G command, INTEL_GUC_ACTION_RESET_CLIENT, which is used to implement suspend. This MMIO tears down any active contexts generating a context reset G2H CTB for each. Once that step completes the GuC tears down the CTB channels. It is safe to suspend once this MMIO H2G command completes and all G2H CTBs have been processed. In practice the i915 will likely never receive a G2H as suspend should only be called after the GPU is idle.
Resume is implemented in the same manner as before - simply reload the GuC firmware and reinitialize everything (e.g. CTB channels, contexts, etc..).
--- .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc.c | 64 ++++++++----------- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 14 ++-- .../gpu/drm/i915/gt/uc/intel_guc_submission.h | 5 ++ drivers/gpu/drm/i915/gt/uc/intel_uc.c | 20 ++++-- 5 files changed, 53 insertions(+), 51 deletions(-)
drivers/gpu/drm/i915/gt/uc/abi/guc_actions_abi.h +1 -0
@@ -142,6 +142,7 @@ enum intel_guc_action {INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER =0x4505 ,INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER =0x4506 ,INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE =0x4600 , +INTEL_GUC_ACTION_RESET_CLIENT =0x5B01 , INTEL_GUC_ACTION_LIMIT };
drivers/gpu/drm/i915/gt/uc/intel_guc.c +26 -38
84 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7 -7
@@ -304,10 +304,10 @@ static int guc_submission_busy_loop(struct intel_guc* guc,return err; } -static int guc_wait_for_pending_msg (struct intel_guc *guc, -atomic_t *wait_var, -bool interruptible, -long timeout) +int intel_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 ;
@@ -352,8 +352,8 @@ int intel_guc_wait_for_idle(struct intel_guc *guc, long timeout)if (unlikely (timeout <0 )) timeout = -timeout, interruptible = false; -return guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, - interruptible, timeout); +return intel_guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + interruptible, timeout); }static int guc_lrc_desc_pin (struct intel_context *ce,bool loop);
@@ -625,7 +625,7 @@ void intel_guc_submission_reset_prepare(struct intel_guc *guc)for (i =0 ; i <4 &&atomic_read (&guc->outstanding_submission_g2h); ++i) {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)) + intel_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));
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +5 -0
@@ -27,6 +27,11 @@ 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); +int intel_guc_wait_for_pending_msg (struct intel_guc *guc, +atomic_t *wait_var, +bool interruptible, +long timeout); +static inline bool intel_guc_submission_is_supported (struct intel_guc *guc) {/* XXX: GuC submission is unavailable for now */
drivers/gpu/drm/i915/gt/uc/intel_uc.c +14 -6
@@ -596,14 +596,18 @@ void intel_uc_cancel_requests(struct intel_uc *uc)void intel_uc_runtime_suspend (struct intel_uc *uc) {struct intel_guc *guc = &uc->guc; -int err;if (!intel_guc_is_ready (guc))return ; - err =intel_guc_suspend (guc); -if (err) -DRM_DEBUG_DRIVER ("Failed to suspend GuC, err=%d" , err); +/* +* Wait for any outstanding CTB before tearing down communication /w the +* GuC. +*/ +#define OUTSTANDING_CTB_TIMEOUT_PERIOD (HZ / 5) +intel_guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, + false,OUTSTANDING_CTB_TIMEOUT_PERIOD ); +GEM_WARN_ON (atomic_read (&guc->outstanding_submission_g2h));guc_disable_communication (guc); }
@@ -612,12 +616,16 @@ void intel_uc_suspend(struct intel_uc *uc) {struct intel_guc *guc = &uc->guc;intel_wakeref_t wakeref; +int err;if (!intel_guc_is_ready (guc))return ; - with_intel_runtime_pm(uc_to_gt(uc)->uncore->rpm, wakeref) -intel_uc_runtime_suspend (uc); + with_intel_runtime_pm(&uc_to_gt(uc)->i915->runtime_pm, wakeref) { + err =intel_guc_suspend (guc); +if (err) +DRM_DEBUG_DRIVER ("Failed to suspend GuC, err=%d" , err); + } }static int __uc_resume (struct intel_uc *uc,bool enable_communication)
Signature · 1 line
2.28.0
PATCH 39/47 drm/i915/guc: Don't complain about reset races
In reply to Matthew BrostFrom: John Harrison <[email protected]>
It is impossible to seal all race conditions of resets occurring concurrent to other operations. At least, not without introducing excesive mutex locking. Instead, don't complain if it occurs. In particular, don't complain if trying to send a H2G during a reset. Whatever the H2G was about should get redone once the reset is over.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 5 ++++- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 3 +++ drivers/gpu/drm/i915/gt/uc/intel_uc.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4 -1
@@ -727,7 +727,10 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,int ret;if (unlikely (!ct->enabled)) { -WARN (1 ,"Unexpected send: action=%#x\n" , *action); +struct intel_guc *guc =ct_to_guc (ct); + struct intel_uc *uc = container_of(guc, struct intel_uc, guc); + +WARN (!uc->reset_in_progress,"Unexpected send: action=%#x\n" , *action);return -ENODEV ; }
drivers/gpu/drm/i915/gt/uc/intel_uc.c +3 -0
@@ -550,6 +550,7 @@ void intel_uc_reset_prepare(struct intel_uc *uc) {struct intel_guc *guc = &uc->guc; + uc->reset_in_progress = true;/* Nothing to do if GuC isn't supported */ if (!intel_uc_supports_guc (uc))
@@ -579,6 +580,8 @@ void intel_uc_reset_finish(struct intel_uc *uc) {struct intel_guc *guc = &uc->guc; + uc->reset_in_progress = false; +/* 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);
drivers/gpu/drm/i915/gt/uc/intel_uc.h +2 -0
@@ -30,6 +30,8 @@ struct intel_uc {/* Snapshot of GuC log from last failed load */ struct drm_i915_gem_object *load_err_log; + +bool reset_in_progress; };void intel_uc_init_early (struct intel_uc *uc);
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 46/47 drm/i915/guc: Add golden context to GuC ADS
In reply to Matthew BrostFrom: John Harrison <[email protected]>
The media watchdog mechanism involves GuC doing a silent reset and continue of the hung context. This requires the i915 driver provide a golden context to GuC in the ADS.
--- drivers/gpu/drm/i915/gt/intel_gt.c | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc.c | 5 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 213 ++++++++++++++++++--- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h | 1 + drivers/gpu/drm/i915/gt/uc/intel_uc.c | 5 + drivers/gpu/drm/i915/gt/uc/intel_uc.h | 1 + 7 files changed, 199 insertions(+), 30 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt.c +2 -0
@@ -654,6 +654,8 @@ int intel_gt_init(struct intel_gt *gt)if (err) goto err_gt; +intel_uc_init_late (>->uc); + err =i915_inject_probe_error (gt->i915, -EIO );if (err) goto err_gt;
drivers/gpu/drm/i915/gt/uc/intel_guc.c +5 -0
@@ -180,6 +180,11 @@ void intel_guc_init_early(struct intel_guc *guc) } } +void intel_guc_init_late (struct intel_guc *guc) +{ +intel_guc_ads_init_late (guc); +} +static u32 guc_ctl_debug_flags (struct intel_guc *guc) {u32 level =intel_guc_log_get_level (&guc->log);
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
@@ -59,6 +59,7 @@ struct intel_guc {struct i915_vma *ads_vma;struct __guc_ads_blob *ads_blob;u32 ads_regset_size; +u32 ads_golden_ctxt_size;struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr;
@@ -176,6 +177,7 @@ static inline u32 intel_guc_ggtt_offset(struct intel_guc *guc, }void intel_guc_init_early (struct intel_guc *guc); +void intel_guc_init_late (struct intel_guc *guc);void intel_guc_init_send_regs (struct intel_guc *guc);void intel_guc_write_params (struct intel_guc *guc);int intel_guc_init (struct intel_guc *guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +183 -30
284 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h +1 -0
@@ -11,6 +11,7 @@ struct drm_printer;int intel_guc_ads_create (struct intel_guc *guc);void intel_guc_ads_destroy (struct intel_guc *guc); +void intel_guc_ads_init_late (struct intel_guc *guc);void intel_guc_ads_reset (struct intel_guc *guc);void intel_guc_log_policy_info (struct intel_guc *guc,struct drm_printer *p);
drivers/gpu/drm/i915/gt/uc/intel_uc.c +5 -0
@@ -120,6 +120,11 @@ void intel_uc_init_early(struct intel_uc *uc) uc->ops = &uc_ops_off; } +void intel_uc_init_late (struct intel_uc *uc) +{ +intel_guc_init_late (&uc->guc); +} +void intel_uc_driver_late_release (struct intel_uc *uc) { }
drivers/gpu/drm/i915/gt/uc/intel_uc.h +1 -0
@@ -35,6 +35,7 @@ struct intel_uc { };void intel_uc_init_early (struct intel_uc *uc); +void intel_uc_init_late (struct intel_uc *uc);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);
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 28/47 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 · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 33/47 drm/i915/guc: Add disable interrupts to guc sanitize
In reply to Matthew BrostAdd disable GuC interrupts to intel_guc_sanitize(). Part of this requires moving the guc_*_interrupt wrapper function into header file intel_guc.h.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 16 ++++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_uc.c | 21 +++------------------ 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +16 -0
@@ -217,9 +217,25 @@ static inline bool intel_guc_is_ready(struct intel_guc *guc)return intel_guc_is_fw_running (guc) &&intel_guc_ct_enabled (&guc->ct); } +static inline void intel_guc_reset_interrupts (struct intel_guc *guc) +{ + guc->interrupts.reset (guc); +} + +static inline void intel_guc_enable_interrupts (struct intel_guc *guc) +{ + guc->interrupts.enable (guc); +} + +static inline void intel_guc_disable_interrupts (struct intel_guc *guc) +{ + guc->interrupts.disable (guc); +} +static inline int intel_guc_sanitize (struct intel_guc *guc) {intel_uc_fw_sanitize (&guc->fw); +intel_guc_disable_interrupts (guc);intel_guc_ct_sanitize (&guc->ct); guc->mmio_msg =0 ;
drivers/gpu/drm/i915/gt/uc/intel_uc.c +3 -18
@@ -207,21 +207,6 @@ static void guc_handle_mmio_msg(struct intel_guc *guc)spin_unlock_irq (&guc->irq_lock); } -static void guc_reset_interrupts (struct intel_guc *guc) -{ - guc->interrupts.reset (guc); -} - -static void guc_enable_interrupts (struct intel_guc *guc) -{ - guc->interrupts.enable (guc); -} - -static void guc_disable_interrupts (struct intel_guc *guc) -{ - guc->interrupts.disable (guc); -} -static int guc_enable_communication (struct intel_guc *guc) {struct intel_gt *gt =guc_to_gt (guc);
@@ -242,7 +227,7 @@ static int guc_enable_communication(struct intel_guc *guc)guc_get_mmio_msg (guc);guc_handle_mmio_msg (guc); -guc_enable_interrupts (guc); +intel_guc_enable_interrupts (guc);/* check for CT messages received before we enabled interrupts */ spin_lock_irq (>->irq_lock);
@@ -265,7 +250,7 @@ static void guc_disable_communication(struct intel_guc *guc)*/ guc_clear_mmio_msg (guc); -guc_disable_interrupts (guc); +intel_guc_disable_interrupts (guc);intel_guc_ct_disable (&guc->ct);
@@ -463,7 +448,7 @@ static int __uc_init_hw(struct intel_uc *uc)if (ret) goto err_out; -guc_reset_interrupts (guc); +intel_guc_reset_interrupts (guc);/* WaEnableuKernelHeaderValidFix:skl */ /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 41/47 drm/i915/guc: Capture error state on context reset
In reply to Matthew BrostWe receive notification of an engine reset from GuC at its completion. Meaning GuC has potentially cleared any HW state we may have been interested in capturing. GuC resumes scheduling on the engine post-reset, as the resets are meant to be transparent, further muddling our error state.
There is ongoing work to define an API for a GuC debug state dump. The suggestion for now is to manually disable FW initiated resets in cases where debug state is needed.
--- drivers/gpu/drm/i915/gt/intel_context.c | 20 +++++++++++ drivers/gpu/drm/i915/gt/intel_context.h | 3 ++ drivers/gpu/drm/i915/gt/intel_engine.h | 21 ++++++++++- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 11 ++++-- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 35 +++++++++---------- drivers/gpu/drm/i915/i915_gpu_error.c | 25 ++++++++++--- 7 files changed, 91 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +20 -0
@@ -514,6 +514,26 @@ struct i915_request *intel_context_create_request(struct intel_context *ce)return rq; } +struct i915_request *intel_context_find_active_request (struct intel_context *ce) +{ +struct i915_request *rq, *active =NULL ; +unsigned long flags; + +GEM_BUG_ON (!intel_engine_uses_guc (ce->engine)); + +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; +} +#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST )#include "selftest_context.c" #endif
drivers/gpu/drm/i915/gt/intel_context.h +3 -0
@@ -201,6 +201,9 @@ int intel_context_prepare_remote_request(struct intel_context *ce,struct i915_request *intel_context_create_request (struct intel_context *ce); +struct i915_request * +intel_context_find_active_request (struct intel_context *ce); +static inline struct intel_ring *__intel_context_ring_size (u64 sz) { return u64_to_ptr(struct intel_ring, sz);
drivers/gpu/drm/i915/gt/intel_engine.h +20 -1
@@ -245,7 +245,7 @@ ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine, ktime_t *now);struct i915_request * -intel_engine_find_active_request (struct intel_engine_cs *engine); +intel_engine_execlist_find_hung_request (struct intel_engine_cs *engine);u32 intel_engine_context_size (struct intel_gt *gt,u8 class); struct intel_context *
@@ -328,4 +328,23 @@ intel_engine_get_sibling(struct intel_engine_cs *engine, unsigned int sibling) return engine->cops->get_sibling(engine, sibling); } +static inline void +intel_engine_set_hung_context (struct intel_engine_cs *engine, +struct intel_context *ce) +{ + engine->hung_ce = ce; +} + +static inline void +intel_engine_clear_hung_context (struct intel_engine_cs *engine) +{ +intel_engine_set_hung_context (engine,NULL ); +} + +static inline struct intel_context * +intel_engine_get_hung_context (struct intel_engine_cs *engine) +{ +return engine->hung_ce; +} +#endif /* _INTEL_RINGBUFFER_H_ */
drivers/gpu/drm/i915/gt/intel_engine_cs.c +9 -2
@@ -1671,7 +1671,7 @@ void intel_engine_dump(struct intel_engine_cs *engine,drm_printf (m,"\tRequests:\n" );spin_lock_irqsave (&engine->sched_engine->lock, flags); - rq =intel_engine_find_active_request (engine); + rq =intel_engine_execlist_find_hung_request (engine);if (rq) {struct intel_timeline *tl =get_timeline (rq);
@@ -1782,10 +1782,17 @@ static bool match_ring(struct i915_request *rq) }struct i915_request * -intel_engine_find_active_request (struct intel_engine_cs *engine) +intel_engine_execlist_find_hung_request (struct intel_engine_cs *engine) {struct i915_request *request, *active =NULL ; +/* +* This search does not work in GuC submission mode. However, the GuC +* will report the hanging context directly to the driver itself. So +* the driver should never get here when in GuC mode. +*/ +GEM_BUG_ON (intel_uc_uses_guc_submission (&engine->gt->uc)); +/* * We are called by the error capture, reset and to dump engine * state at random points in time. In particular, note that neither is
drivers/gpu/drm/i915/gt/intel_engine_types.h +2 -0
@@ -303,6 +303,8 @@ struct intel_engine_cs {/* keep a request in reserve for a [pm] barrier under oom */ struct i915_request *request_pool; +struct intel_context *hung_ce; +struct llist_head barrier_tasks;struct intel_context *kernel_context;/* pinned */
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +16 -19
@@ -727,24 +727,6 @@ __unwind_incomplete_requests(struct intel_context *ce)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;
@@ -758,7 +740,7 @@ static void __guc_reset_context(struct intel_context *ce, bool stalled)*/ clr_context_enabled (ce); - rq =context_find_active_request (ce); + rq =intel_context_find_active_request (ce);if (!rq) { head = ce->ring->tail; stalled = false;
@@ -2192,6 +2174,20 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,return 0 ; } +static void capture_error_state (struct intel_guc *guc, +struct intel_context *ce) +{ +struct intel_gt *gt =guc_to_gt (guc); +struct drm_i915_private *i915 = gt->i915; +struct intel_engine_cs *engine =__context_to_physical_engine (ce); +intel_wakeref_t wakeref; + +intel_engine_set_hung_context (engine, ce); + with_intel_runtime_pm(&i915->runtime_pm, wakeref) +i915_capture_error_state (gt, engine->mask); +atomic_inc (&i915->gpu_error.reset_engine_count[engine->uabi_class]); +} +static void guc_context_replay (struct intel_context *ce) {struct i915_sched_engine *sched_engine = ce->engine->sched_engine;
@@ -2204,6 +2200,7 @@ static void guc_handle_context_reset(struct intel_guc *guc, struct intel_context *ce) {trace_intel_context_reset (ce); +capture_error_state (guc, ce);guc_context_replay (ce); }
drivers/gpu/drm/i915/i915_gpu_error.c +21 -4
@@ -1429,20 +1429,37 @@ capture_engine(struct intel_engine_cs *engine, {struct intel_engine_capture_vma *capture =NULL ;struct intel_engine_coredump *ee; -struct i915_request *rq; +struct intel_context *ce; +struct i915_request *rq =NULL ;unsigned long flags; ee =intel_engine_coredump_alloc (engine,GFP_KERNEL );if (!ee)return NULL ; -spin_lock_irqsave (&engine->sched_engine->lock, flags); - rq =intel_engine_find_active_request (engine); + ce =intel_engine_get_hung_context (engine); +if (ce) { +intel_engine_clear_hung_context (engine); + rq =intel_context_find_active_request (ce); +if (!rq || !i915_request_started (rq)) + goto no_request_capture; + }else { +/* +* Getting here with GuC enabled means it is a forced error capture +* with no actual hang. So, no need to attempt the execlist search. +*/ +if (!intel_uc_uses_guc_submission (&engine->gt->uc)) { +spin_lock_irqsave (&engine->sched_engine->lock, flags); + rq =intel_engine_execlist_find_hung_request (engine); +spin_unlock_irqrestore (&engine->sched_engine->lock, + flags); + } + }if (rq) capture =intel_engine_coredump_add_request (ee, rq,ATOMIC_MAYFAIL ); -spin_unlock_irqrestore (&engine->sched_engine->lock, flags);if (!capture) { +no_request_capture:kfree (ee);return NULL ; }
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 20/47 drm/i915/guc: Disable semaphores when using GuC scheduling
In reply to Matthew BrostSemaphores 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. Also long direction is just to delete semaphores from the i915 so another reason to not enable these for GuC submission.
v2: Reword commit message
--- 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);
@@ -1938,7 +1939,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
PATCH 35/47 drm/i915/guc: Handle context reset notification
In reply to Matthew BrostGuC will issue a reset on detecting an engine hang and will notify the driver via a G2H message. The driver will service the notification by resetting the guilty context to a simple state or banning it completely.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 ++ drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 3 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 35 +++++++++++++++++++ drivers/gpu/drm/i915/i915_trace.h | 10 ++++++ 4 files changed, 50 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
@@ -262,6 +262,8 @@ 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); +int intel_guc_context_reset_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);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3 -0
@@ -945,6 +945,9 @@ static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *rcase INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE : ret =intel_guc_sched_done_process_msg (guc, payload, len);break ; +case INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION : + ret =intel_guc_context_reset_process_msg (guc, payload, len); +break ;default : ret = -EOPNOTSUPP ;break ;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +35 -0
@@ -2192,6 +2192,41 @@ int intel_guc_sched_done_process_msg(struct intel_guc *guc,return 0 ; } +static void guc_context_replay (struct intel_context *ce) +{ +struct i915_sched_engine *sched_engine = ce->engine->sched_engine; + +__guc_reset_context (ce, true); +tasklet_hi_schedule (&sched_engine->tasklet); +} + +static void guc_handle_context_reset (struct intel_guc *guc, +struct intel_context *ce) +{ +trace_intel_context_reset (ce); +guc_context_replay (ce); +} + +int intel_guc_context_reset_process_msg (struct intel_guc *guc, +const u32 *msg,u32 len) +{ +struct intel_context *ce; +int 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 ; + +guc_handle_context_reset (guc, ce); + +return 0 ; +} +void intel_guc_log_submission_info (struct intel_guc *guc,struct drm_printer *p) {
drivers/gpu/drm/i915/i915_trace.h +10 -0
@@ -929,6 +929,11 @@ DECLARE_EVENT_CLASS(intel_context, __entry->guc_sched_state_no_lock) ); +DEFINE_EVENT (intel_context, intel_context_reset, + TP_PROTO(struct intel_context *ce), +TP_ARGS (ce) +); +DEFINE_EVENT (intel_context, intel_context_register, TP_PROTO(struct intel_context *ce), TP_ARGS(ce)
@@ -1026,6 +1031,11 @@ trace_i915_request_out(struct i915_request *rq) { } +static inline void +trace_intel_context_reset (struct intel_context *ce) +{ +} +static inline void trace_intel_context_register (struct intel_context *ce) {
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 47/47 drm/i915/guc: Unblock GuC submission on Gen11+
In reply to Matthew BrostFrom: Daniele Ceraolo Spurio <[email protected]>
Unblock GuC submission on Gen11+ platforms.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 8 ++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h | 3 +-- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 14 +++++++++----- 4 files changed, 19 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1 -0
@@ -54,6 +54,7 @@ struct intel_guc {struct ida guc_ids;struct list_head guc_id_list; +bool submission_supported;bool submission_selected;struct i915_vma *ads_vma;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +8 -0
@@ -2042,6 +2042,13 @@ void intel_guc_submission_disable(struct intel_guc *guc)/* Note: By the time we're here, GuC may have already been reset */ } +static bool __guc_submission_supported (struct intel_guc *guc) +{ +/* GuC submission is unavailable for pre-Gen11 */ +return intel_guc_is_supported (guc) && +INTEL_GEN (guc_to_gt (guc)->i915) >=11 ; +} +static bool __guc_submission_selected (struct intel_guc *guc) {struct drm_i915_private *i915 =guc_to_gt (guc)->i915;
@@ -2054,6 +2061,7 @@ static bool __guc_submission_selected(struct intel_guc *guc)void intel_guc_submission_init_early (struct intel_guc *guc) { + guc->submission_supported =__guc_submission_supported (guc); guc->submission_selected =__guc_submission_selected (guc); }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +1 -2
@@ -37,8 +37,7 @@ int intel_guc_wait_for_pending_msg(struct intel_guc *guc,static inline bool intel_guc_submission_is_supported (struct intel_guc *guc) { -/* XXX: GuC submission is unavailable for now */ -return false; +return guc->submission_supported; }static inline bool intel_guc_submission_is_wanted (struct intel_guc *guc)
drivers/gpu/drm/i915/gt/uc/intel_uc.c +9 -5
@@ -34,8 +34,15 @@ static void uc_expand_default_options(struct intel_uc *uc)return ; } -/* Default: enable HuC authentication only */ - i915->params.enable_guc =ENABLE_GUC_LOAD_HUC ; +/* Intermediate platforms are HuC authentication only */ +if (IS_DG1 (i915) ||IS_ALDERLAKE_S (i915)) { +drm_dbg (&i915->drm,"Disabling GuC only due to old platform\n" ); + i915->params.enable_guc =ENABLE_GUC_LOAD_HUC ; +return ; + } + +/* Default: enable HuC authentication and GuC submission */ + i915->params.enable_guc =ENABLE_GUC_LOAD_HUC |ENABLE_GUC_SUBMISSION ; }/* Reset GuC providing us with fresh state for both GuC and HuC.
@@ -313,9 +320,6 @@ static int __uc_init(struct intel_uc *uc)if (i915_inject_probe_failure (uc_to_gt (uc)->i915))return -ENOMEM ; -/* XXX: GuC submission is unavailable for now */ -GEM_BUG_ON (intel_uc_uses_guc_submission (uc)); - ret =intel_guc_init (guc);if (ret)return ret;
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 42/47 drm/i915/guc: Fix for error capture after full GPU reset with GuC
In reply to Matthew BrostFrom: John Harrison <[email protected]>
In the case of a full GPU reset (e.g. because GuC has died or because GuC's hang detection has been disabled), the driver can't rely on GuC reporting the guilty context. Instead, the driver needs to scan all active contexts and find one that is currently executing, as per the execlist mode behaviour. In GuC mode, this scan is different to execlist mode as the active request list is handled very differently.
Similarly, the request state dump in debugfs needs to be handled differently when in GuC submission mode.
Also refactured some of the request scanning code to avoid duplication across the multiple code paths that are now replicating it.
--- drivers/gpu/drm/i915/gt/intel_engine.h | 3 + drivers/gpu/drm/i915/gt/intel_engine_cs.c | 139 ++++++++++++------ .../gpu/drm/i915/gt/intel_engine_heartbeat.c | 8 + drivers/gpu/drm/i915/gt/intel_reset.c | 2 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 67 +++++++++ .../gpu/drm/i915/gt/uc/intel_guc_submission.h | 3 + drivers/gpu/drm/i915/i915_request.c | 41 ++++++ drivers/gpu/drm/i915/i915_request.h | 11 ++ 9 files changed, 229 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine.h +3 -0
@@ -240,6 +240,9 @@ __printf(3, 4)void intel_engine_dump (struct intel_engine_cs *engine,struct drm_printer *m,const char *header, ...); +void intel_engine_dump_active_requests (struct list_head *requests, +struct i915_request *hung_rq, +struct drm_printer *m);ktime_t intel_engine_get_busy_time (struct intel_engine_cs *engine,ktime_t *now);
drivers/gpu/drm/i915/gt/intel_engine_cs.c +93 -46
165 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c +8 -0
@@ -90,6 +90,14 @@ reset_engine(struct intel_engine_cs *engine, struct i915_request *rq)if (IS_ENABLED (CONFIG_DRM_I915_DEBUG_GEM ))show_heartbeat (rq, engine); +if (intel_engine_uses_guc (engine)) +/* +* GuC itself is toast or GuC's hang detection +* is disabled. Either way, need to find the +* hang culprit manually. +*/ +intel_guc_find_hung_context (engine); + intel_gt_handle_error(engine->gt, engine->mask, I915_ERROR_CAPTURE, "stopped heartbeat on %s",
drivers/gpu/drm/i915/gt/intel_reset.c +1 -1
@@ -156,7 +156,7 @@ void __i915_request_reset(struct i915_request *rq, bool guilty)if (guilty) {i915_request_set_error_once (rq, -EIO );__i915_request_skip (rq); -if (mark_guilty (rq)) +if (mark_guilty (rq) && !intel_engine_uses_guc (rq->engine))skip_context (rq); }else {i915_request_set_error_once (rq, -EAGAIN );
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -0
@@ -268,6 +268,8 @@ int intel_guc_context_reset_process_msg(struct intel_guc *guc,int intel_guc_engine_failure_process_msg (struct intel_guc *guc,const u32 *msg,u32 len); +void intel_guc_find_hung_context (struct intel_engine_cs *engine); +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);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +67 -0
73 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.h +3 -0
@@ -24,6 +24,9 @@ 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); +void intel_guc_dump_active_requests (struct intel_engine_cs *engine, +struct i915_request *hung_rq, +struct drm_printer *m);bool intel_guc_virtual_engine_has_heartbeat (const struct intel_engine_cs *ve);
drivers/gpu/drm/i915/i915_request.c +41 -0
47 lines not on this page · raw message
drivers/gpu/drm/i915/i915_request.h +11 -0
@@ -651,4 +651,15 @@ i915_request_active_engine(struct i915_request *rq,void i915_request_notify_execute_cb_imm (struct i915_request *rq); +enum i915_request_state +{ +I915_REQUEST_UNKNOWN =0 , +I915_REQUEST_COMPLETE , +I915_REQUEST_PENDING , +I915_REQUEST_QUEUED , +I915_REQUEST_ACTIVE , +}; + +enum i915_request_state i915_test_request_state (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
PATCH 40/47 drm/i915/guc: Enable GuC engine reset
In reply to Matthew BrostFrom: John Harrison <[email protected]>
Clear the 'disable resets' flag to allow GuC to reset hung contexts (detected via pre-emption timeout).
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +1 -2
@@ -81,8 +81,7 @@ static void guc_policies_init(struct guc_policies *policies) { policies->dpc_promote_time =GLOBAL_POLICY_DEFAULT_DPC_PROMOTE_TIME_US ; policies->max_num_work_items =GLOBAL_POLICY_MAX_NUM_WI ; -/* Disable automatic resets as not yet supported. */ - policies->global_flags =GLOBAL_POLICY_DISABLE_ENGINE_RESET ; + policies->global_flags =0 ; policies->is_valid =1 ; }
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 25/47 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
@@ -348,6 +348,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) {
@@ -812,6 +813,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); }
@@ -831,6 +834,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); }
@@ -905,6 +910,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);
@@ -963,6 +969,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),
@@ -1119,6 +1126,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);
@@ -1529,6 +1539,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;
@@ -1580,6 +1592,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 · 1 line
2.28.0
PATCH 32/47 drm/i915: Reset GPU immediately if submission is disabled
In reply to Matthew BrostIf submission is disabled by the backend for any reason, reset the GPU immediately in the heartbeat code as the backend can't be reenabled until the GPU is reset.
--- .../gpu/drm/i915/gt/intel_engine_heartbeat.c | 63 +++++++++++++++---- .../gpu/drm/i915/gt/intel_engine_heartbeat.h | 4 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 9 +++ drivers/gpu/drm/i915/i915_scheduler.c | 6 ++ drivers/gpu/drm/i915/i915_scheduler.h | 6 ++ drivers/gpu/drm/i915/i915_scheduler_types.h | 5 ++ 6 files changed, 80 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c +50 -13
@@ -70,12 +70,30 @@ static void show_heartbeat(const struct i915_request *rq, {struct drm_printer p =drm_debug_printer ("heartbeat" ); -intel_engine_dump (engine, &p, -"%s heartbeat {seqno:%llx:%lld, prio:%d} not ticking\n" , - engine->name, - rq->fence.context, - rq->fence.seqno, - rq->sched.attr.priority); +if (!rq) { +intel_engine_dump (engine, &p, +"%s heartbeat not ticking\n" , + engine->name); + }else { +intel_engine_dump (engine, &p, +"%s heartbeat {seqno:%llx:%lld, prio:%d} not ticking\n" , + engine->name, + rq->fence.context, + rq->fence.seqno, + rq->sched.attr.priority); + } +} + +static void +reset_engine (struct intel_engine_cs *engine,struct i915_request *rq) +{ +if (IS_ENABLED (CONFIG_DRM_I915_DEBUG_GEM )) +show_heartbeat (rq, engine); + +intel_gt_handle_error (engine->gt, engine->mask, +I915_ERROR_CAPTURE , +"stopped heartbeat on %s" , + engine->name); }static void heartbeat (struct work_struct *wrk)
@@ -102,6 +120,11 @@ static void heartbeat(struct work_struct *wrk)if (intel_gt_is_wedged (engine->gt)) goto out; +if (i915_sched_engine_disabled (engine->sched_engine)) { +reset_engine (engine, engine->heartbeat.systole); + goto out; + } +if (engine->heartbeat.systole) {long delay =READ_ONCE (engine->props.heartbeat_interval_ms);
@@ -139,13 +162,7 @@ static void heartbeat(struct work_struct *wrk) engine->sched_engine->schedule (rq, &attr);local_bh_enable (); }else { -if (IS_ENABLED (CONFIG_DRM_I915_DEBUG_GEM )) -show_heartbeat (rq, engine); - -intel_gt_handle_error (engine->gt, engine->mask, -I915_ERROR_CAPTURE , -"stopped heartbeat on %s" , - engine->name); +reset_engine (engine, rq); } rq->emitted_jiffies = jiffies;
@@ -194,6 +211,26 @@ void intel_engine_park_heartbeat(struct intel_engine_cs *engine)i915_request_put (fetch_and_zero (&engine->heartbeat.systole)); } +void intel_gt_unpark_heartbeats (struct intel_gt *gt) +{ +struct intel_engine_cs *engine; +enum intel_engine_id id; + +for_each_engine (engine, gt, id) +if (intel_engine_pm_is_awake (engine)) +intel_engine_unpark_heartbeat (engine); + +} + +void intel_gt_park_heartbeats (struct intel_gt *gt) +{ +struct intel_engine_cs *engine; +enum intel_engine_id id; + +for_each_engine (engine, gt, id) +intel_engine_park_heartbeat (engine); +} +void intel_engine_init_heartbeat (struct intel_engine_cs *engine) {INIT_DELAYED_WORK (&engine->heartbeat.work, heartbeat);
drivers/gpu/drm/i915/gt/intel_engine_heartbeat.h +4 -0
@@ -7,6 +7,7 @@#define INTEL_ENGINE_HEARTBEAT_H struct intel_engine_cs ; +struct intel_gt ;void intel_engine_init_heartbeat (struct intel_engine_cs *engine);
@@ -16,6 +17,9 @@ int intel_engine_set_heartbeat(struct intel_engine_cs *engine,void intel_engine_park_heartbeat (struct intel_engine_cs *engine);void intel_engine_unpark_heartbeat (struct intel_engine_cs *engine); +void intel_gt_park_heartbeats (struct intel_gt *gt); +void intel_gt_unpark_heartbeats (struct intel_gt *gt); +int intel_engine_pulse (struct intel_engine_cs *engine);int intel_engine_flush_barriers (struct intel_engine_cs *engine);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +9 -0
@@ -10,6 +10,7 @@#include "gt/intel_breadcrumbs.h" #include "gt/intel_context.h" #include "gt/intel_engine_pm.h" +#include "gt/intel_engine_heartbeat.h" #include "gt/intel_gt.h" #include "gt/intel_gt_irq.h" #include "gt/intel_gt_pm.h"
@@ -605,6 +606,7 @@ void intel_guc_submission_reset_prepare(struct intel_guc *guc)/* Reset called during driver load? GuC not yet initialised! */ return ; +intel_gt_park_heartbeats (guc_to_gt (guc));disable_submission (guc); guc->interrupts.disable (guc);
@@ -890,6 +892,7 @@ void intel_guc_submission_reset_finish(struct intel_guc *guc)atomic_set (&guc->outstanding_submission_g2h,0 );enable_submission (guc); +intel_gt_unpark_heartbeats (guc_to_gt (guc)); }/*
@@ -1859,6 +1862,11 @@ static int guc_resume(struct intel_engine_cs *engine)return 0 ; } +static bool guc_sched_engine_disabled (struct i915_sched_engine *sched_engine) +{ +return !sched_engine->tasklet.callback; +} +static void guc_set_default_submission (struct intel_engine_cs *engine) { engine->submit_request = guc_submit_request;
@@ -2009,6 +2017,7 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)return -ENOMEM ; guc->sched_engine->schedule = i915_schedule; + guc->sched_engine->disabled = guc_sched_engine_disabled; guc->sched_engine->private_data = guc;tasklet_setup (&guc->sched_engine->tasklet, guc_submission_tasklet);
drivers/gpu/drm/i915/i915_scheduler.c +6 -0
@@ -440,6 +440,11 @@ void i915_sched_engine_free(struct kref *kref)kfree (sched_engine); } +static bool default_disabled (struct i915_sched_engine *sched_engine) +{ +return false; +} +struct i915_sched_engine *i915_sched_engine_create (unsigned int subclass) {
@@ -453,6 +458,7 @@ i915_sched_engine_create(unsigned int subclass) sched_engine->queue =RB_ROOT_CACHED ; sched_engine->queue_priority_hint =INT_MIN ; + sched_engine->disabled = default_disabled;INIT_LIST_HEAD (&sched_engine->requests);INIT_LIST_HEAD (&sched_engine->hold);
drivers/gpu/drm/i915/i915_scheduler.h +6 -0
@@ -98,4 +98,10 @@ void i915_request_show_with_schedule(struct drm_printer *m,const char *prefix, int indent); +static inline bool +i915_sched_engine_disabled (struct i915_sched_engine *sched_engine) +{ +return sched_engine->disabled (sched_engine); +} +#endif /* _I915_SCHEDULER_H_ */
drivers/gpu/drm/i915/i915_scheduler_types.h +5 -0
@@ -163,6 +163,11 @@ struct i915_sched_engine {*/ void *private_data; +/** +* @disabled: check if backend has disabled submission +*/ +bool (*disabled)(struct i915_sched_engine *sched_engine); +/** * @kick_backend: kick backend after a request's priority has changed */
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 27/47 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
@@ -388,6 +388,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
@@ -3203,6 +3203,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) {
@@ -3212,6 +3217,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
@@ -1044,6 +1044,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;
@@ -1063,6 +1068,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
@@ -1496,6 +1496,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. */
@@ -1504,6 +1518,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;
@@ -1836,6 +1851,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
Patchwork
CI[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for GuC submission support
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: GuC submission support
URL : https://patchwork.freedesktop.org/series/91840/
State : warning
== Summary ==
$ dim checkpatch origin/drm-tip a582e9c666ff drm/i915/guc: Relax CTB response timeout 743d703ec315 drm/i915/guc: Improve error message for unsolicited CT response beb15fc92c92 drm/i915/guc: Increase size of CTB buffers 3d4dab7e7c81 drm/i915/guc: Add non blocking CTB send function c0779d6fc3b7 drm/i915/guc: Add stall timer to non blocking CTB send function 2c9efd827987 drm/i915/guc: Optimize CTB writes and reads -:112: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #112: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c:528: + CT_ERROR(ct, "Corrupted descriptor head=%u tail=%u size=%u\n", + ctb->desc->head, ctb->desc->tail, ctb->size);
total: 0 errors, 0 warnings, 1 checks, 184 lines checked28324246d8aa drm/i915/guc: Module load failure test for CT buffer creation
-:38: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: John Harrison <[email protected]>' != 'Signed-off-by: John Harrison <[email protected]>'
total: 0 errors, 1 warnings, 0 checks, 20 lines checked071d7fa76a91 drm/i915/guc: Add new GuC interface defines and structures -:98: WARNING:BLOCK_COMMENT_STYLE: Block comments use a trailing */ on a separate line #98: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h:275:
+ * reset. (in micro seconds). */
total: 0 errors, 1 warnings, 0 checks, 83 lines checked9cc26b390c65 drm/i915/guc: Remove GuC stage descriptor, add lrc descriptor
-:120: WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: __always_unused or __maybe_unused is preferred over __attribute__((__unused__)) #120: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:69:
+__attribute__ ((unused))
total: 0 errors, 1 warnings, 0 checks, 208 lines checked dbd8df00f28f drm/i915/guc: Add lrc descriptor context lookup array 0478ac5fcc47 drm/i915/guc: Implement GuC submission tasklet 86db42bdbf1a drm/i915/guc: Add bypass tasklet submission path to GuC b9faec389671 drm/i915/guc: Implement GuC context operations for new inteface -:109: ERROR:POINTER_LOCATION: "foo* bar" should be "foo *bar" #109: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc.h:113:
+static inline int intel_guc_send_busy_loop(struct intel_guc* guc,
-:117: ERROR:IN_ATOMIC: do not use in_atomic in drivers #117: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc.h:121:
+ might_sleep_if(loop && (!in_atomic() && !irqs_disabled()));
-:122: ERROR:IN_ATOMIC: do not use in_atomic in drivers #122: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc.h:126:
+ if (likely(!in_atomic() && !irqs_disabled()))
-:551: WARNING:REPEATED_WORD: Possible repeated word: 'from' #551: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:784:
+ * could be regisgered either the guc_id has been stole from from
-:789: WARNING:ONE_SEMICOLON: Statements terminations use 1 semicolon #789: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:985:
+ return ret;;
total: 3 errors, 2 warnings, 0 checks, 887 lines checked 0ddf4a0e5ead drm/i915/guc: Insert fence on context when deregistering -:7: WARNING:REPEATED_WORD: Possible repeated word: 'before' #7:
registered with the GuC. In this a case deregister must be before before
total: 0 errors, 1 warnings, 0 checks, 113 lines checked 53890c0d5072 drm/i915/guc: Defer context unpin until scheduling is disabled 9e9fc047e7c1 drm/i915/guc: Disable engine barriers with GuC during unpin e7452c180185 drm/i915/guc: Extend deregistration fence to schedule disable 195129a34fbe drm/i915: Disable preempt busywait when using GuC scheduling e53180c87b60 drm/i915/guc: Ensure request ordering via completion fences -:90: WARNING:LONG_LINE: line length of 101 exceeds 100 columns #90: FILE: drivers/gpu/drm/i915/i915_request.c:1675:
+ if ((!uses_guc && is_power_of_2(READ_ONCE(prev->engine)->mask | rq->engine->mask)) ||
total: 0 errors, 1 warnings, 0 checks, 64 lines checked 59c796b965e6 drm/i915/guc: Disable semaphores when using GuC scheduling 588df5bce44c drm/i915/guc: Ensure G2H response has space in buffer -:22: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'len' - possible side-effects? #22: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc.h:100:
+#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);})
-:24: ERROR:SPACING: space required after that ';' (ctx:VxV) #24: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc.h:102:
+ (FIELD_PREP(INTEL_GUC_SEND_G2H_DW_MASK, len) | INTEL_GUC_SEND_NB);})
^
-:202: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #202: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c:597:
+#define G2H_LEN_DW(f) \
+ FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) ? \
+ FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) + GUC_CTB_HXG_MSG_MIN_LEN : 0
-:202: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'f' - possible side-effects? #202: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c:597:
+#define G2H_LEN_DW(f) \
+ FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) ? \
+ FIELD_GET(INTEL_GUC_SEND_G2H_DW_MASK, f) + GUC_CTB_HXG_MSG_MIN_LEN : 0
total: 2 errors, 0 warnings, 2 checks, 296 lines checked a03438ead8d3 drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC -:218: ERROR:POINTER_LOCATION: "foo* bar" should be "foo *bar" #218: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:257:
+static int guc_submission_busy_loop(struct intel_guc* guc,
total: 1 errors, 0 warnings, 0 checks, 333 lines checked c84dc5dbebea drm/i915/guc: Update GuC debugfs to support new GuC 4adb7ce61e5f drm/i915/guc: Add several request trace points 37ebee77b9c2 drm/i915: Add intel_context tracing
-:152: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #152: FILE: drivers/gpu/drm/i915/i915_trace.h:909:
+DECLARE_EVENT_CLASS(intel_context,
+ TP_PROTO(struct intel_context *ce),
-:155: CHECK:OPEN_ENDED_LINE: Lines should not end with a '(' #155: FILE: drivers/gpu/drm/i915/i915_trace.h:912:
+ TP_STRUCT__entry(
-:162: CHECK:OPEN_ENDED_LINE: Lines should not end with a '(' #162: FILE: drivers/gpu/drm/i915/i915_trace.h:919:
+ TP_fast_assign(
total: 0 errors, 0 warnings, 3 checks, 264 lines checked351767d30288 drm/i915/guc: GuC virtual engines
-:122: WARNING:UNNECESSARY_ELSE: else is not generally useful after a break or return #122: FILE: drivers/gpu/drm/i915/gt/intel_engine.h:285:
+ return intel_guc_virtual_engine_has_heartbeat(engine);
+ else
-:847: CHECK:LINE_SPACING: Please don't use multiple blank lines #847: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:1894:
+
+
total: 0 errors, 1 warnings, 1 checks, 785 lines checked5ca8f1a503a8 drm/i915: Track 'serial' counts for virtual engines 81e0788642e7 drm/i915: Hold reference to intel_context over life of i915_request 2fca6597dcd8 drm/i915/guc: Disable bonding extension with GuC submission 7ae740c21ec4 drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs -:346: ERROR:CODE_INDENT: code indent should use tabs where possible #346: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:1411:
+ * In GuC submission mode we do not know which physical engine a request$
-:347: ERROR:CODE_INDENT: code indent should use tabs where possible #347: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:1412:
+ * will be scheduled on, this creates a problem because the breadcrumb$
-:348: ERROR:CODE_INDENT: code indent should use tabs where possible #348: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:1413:
+ * interrupt is per physical engine. To work around this we attach$
-:349: ERROR:CODE_INDENT: code indent should use tabs where possible #349: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:1414:
+ * requests and direct all breadcrumb interrupts to the first instance$
-:350: ERROR:CODE_INDENT: code indent should use tabs where possible #350: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:1415:
+ * of an engine per class. In addition all breadcrumb interrupts are$
-:352: ERROR:CODE_INDENT: code indent should use tabs where possible #352: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:1417:
+ */$
total: 6 errors, 0 warnings, 0 checks, 329 lines checked 3c79abc34b26 drm/i915/guc: Reset implementation for new GuC interface -:306: CHECK:LINE_SPACING: Please don't use multiple blank lines #306: FILE: drivers/gpu/drm/i915/gt/mock_engine.c:266:
+
+
-:390: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "guc->lrc_desc_pool_vaddr" #390: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:250:
+ return guc->lrc_desc_pool_vaddr != NULL;
-:545: ERROR:SPACING: spaces required around that '||' (ctx:VxW) #545: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:540:
+ if (pending_enable|| deregister)
^
-:585: WARNING:MEMORY_BARRIER: memory barrier without comment #585: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:580:
+ wmb();
-:637: ERROR:CODE_INDENT: code indent should use tabs where possible #637: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:622:
+ ^I */$
-:637: WARNING:SPACE_BEFORE_TAB: please, no space before tabs #637: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c:622:
+ ^I */$
-:1294: CHECK:LINE_SPACING: Please don't use multiple blank lines #1294: FILE: drivers/gpu/drm/i915/gt/uc/intel_uc.c:568:
+
total: 2 errors, 2 warnings, 3 checks, 1301 lines checked 848ca056fc3e drm/i915: Reset GPU immediately if submission is disabled -:93: CHECK:BRACES: Blank lines aren't necessary before a close brace '}' #93: FILE: drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c:223:
+
+}
total: 0 errors, 0 warnings, 1 checks, 181 lines checked17b20c0c8bd7 drm/i915/guc: Add disable interrupts to guc sanitize
-:11: ERROR:BAD_SIGN_OFF: Unrecognized email address: 'Daniele Ceraolo Spurio <[email protected]' #11:
Cc: Daniele Ceraolo Spurio <[email protected]
total: 1 errors, 0 warnings, 0 checks, 70 lines checked345f1eca0a86 drm/i915/guc: Suspend/resume implementation for new interface a921fc062048 drm/i915/guc: Handle context reset notification 5560a36d3f00 drm/i915/guc: Handle engine reset failure notification ee41dea700c0 drm/i915/guc: Enable the timer expired interrupt for GuC adcd1418b513 drm/i915/guc: Provide mmio list to be saved/restored on engine reset -:355: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #355: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c:212:
+ temp_set.registers = kmalloc_array(temp_set.size,
+ sizeof(*temp_set.registers),
-:384: CHECK:SPACING: No space is necessary after a cast #384: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c:241:
+ temp_set.registers = (struct guc_mmio_reg *) (((u8 *) blob) + offset);
total: 0 errors, 0 warnings, 2 checks, 400 lines checked b7f2c290b8da drm/i915/guc: Don't complain about reset races cf156af71348 drm/i915/guc: Enable GuC engine resetd43f902c9f69 drm/i915/guc: Capture error state on context reset c24a302b3409 drm/i915/guc: Fix for error capture after full GPU reset with GuC -:119: CHECK:BRACES: braces {} should be used on all arms of this statement #119: FILE: drivers/gpu/drm/i915/gt/intel_engine_cs.c:1701:
+ if (guc) {
[...]
+ } else
[...]
-:123: CHECK:BRACES: Unbalanced braces around else statement #123: FILE: drivers/gpu/drm/i915/gt/intel_engine_cs.c:1705:
+ } else
-:408: ERROR:OPEN_BRACE: open brace '{' following enum go on the same line #408: FILE: drivers/gpu/drm/i915/i915_request.h:655:
+enum i915_request_state
+{
-:418: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: John Harrison <[email protected]>' != 'Signed-off-by: John Harrison <[email protected]>'
total: 1 errors, 1 warnings, 2 checks, 348 lines checked 2529cfc15930 drm/i915/guc: Hook GuC scheduling policies up
-:80: WARNING:ENOTSUPP: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP #80: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c:113:
+ return -ENOTSUPP;
-:148: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: John Harrison <[email protected]>' != 'Signed-off-by: John Harrison <[email protected]>'
total: 0 errors, 2 warnings, 0 checks, 113 lines checked 055c438902ea drm/i915/guc: Connect reset modparam updates to GuC policy flags -:49: WARNING:LONG_LINE: line length of 107 exceeds 100 columns #49: FILE: drivers/gpu/drm/i915/i915_debugfs_params.c:14:
+#define MATCH_DEBUGFS_NODE_NAME(_file, _name) (strcmp((_file)->f_path.dentry->d_name.name, (_name)) == 0)
-:51: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'i915' - possible side-effects? #51: FILE: drivers/gpu/drm/i915/i915_debugfs_params.c:16:
+#define GET_I915(i915, name, ptr) \
+ do { \
+ struct i915_params *params; \
+ params = container_of(((void *) (ptr)), typeof(*params), name); \
+ (i915) = container_of(params, typeof(*(i915)), params); \
+ } while(0)
-:54: CHECK:SPACING: No space is necessary after a cast #54: FILE: drivers/gpu/drm/i915/i915_debugfs_params.c:19:
+ params = container_of(((void *) (ptr)), typeof(*params), name); \
-:56: ERROR:SPACING: space required before the open parenthesis '(' #56: FILE: drivers/gpu/drm/i915/i915_debugfs_params.c:21:
+ } while(0)
-:103: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: John Harrison <[email protected]>' != 'Signed-off-by: John Harrison <[email protected]>'
total: 1 errors, 2 warnings, 2 checks, 68 lines checked9bedfd84c9e8 drm/i915/guc: Include scheduling policies in the debugfs state dump
-:72: WARNING:FROM_SIGN_OFF_MISMATCH: From:/Signed-off-by: email address mismatch: 'From: John Harrison <[email protected]>' != 'Signed-off-by: John Harrison <[email protected]>'
total: 0 errors, 1 warnings, 0 checks, 44 lines checked b49edbcc9280 drm/i915/guc: Add golden context to GuC ADS -:254: CHECK:SPACING: No space is necessary after a cast #254: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c:453:
+ ptr = ((u8 *) blob) + offset;
-:279: WARNING:LONG_LINE: line length of 106 exceeds 100 columns #279: FILE: drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c:470:
+ drm_err(>->i915->drm, "No engine state recorded for class %d!\n", engine_class);
total: 0 errors, 1 warnings, 1 checks, 342 lines checked 8a320e973471 drm/i915/guc: Unblock GuC submission on Gen11+
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI[Intel-gfx] ✗ Fi.CI.SPARSE: warning for GuC submission support
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: GuC submission support
URL : https://patchwork.freedesktop.org/series/91840/
State : warning
== Summary ==
$ dim sparse --fast origin/drm-tip Sparse version: v0.6.2 Fast mode used, each commit won't be checked separately. +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +./include/linux/stddef.h:17:9: this was the original definition +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h:417:9: warning: preprocessor token offsetof redefined
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BAT: failure for GuC submission support
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: GuC submission support
URL : https://patchwork.freedesktop.org/series/91840/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_10271 -> Patchwork_20449
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with Patchwork_20449 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in Patchwork_20449, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20449/index.html
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in Patchwork_20449:
### IGT changes ###
#### Possible regressions ####
* igt@core_auth@basic-auth:
- fi-kbl-8809g: [PASS][1] -> [DMESG-WARN][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10271/fi-kbl-8809g/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20449/fi-kbl-8809g/igt@[email protected]
* igt@i915_selftest@live@workarounds:
- fi-snb-2520m: [PASS][3] -> [DMESG-FAIL][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10271/fi-snb-2520m/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20449/fi-snb-2520m/igt@i915_selftest@[email protected]
- fi-snb-2600: [PASS][5] -> [DMESG-FAIL][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10271/fi-snb-2600/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20449/fi-snb-2600/igt@i915_selftest@[email protected]
Known issues
------------
Here are the changes found in Patchwork_20449 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@amdgpu/amd_basic@cs-gfx:
- fi-kbl-soraka: NOTRUN -> [SKIP][7] ([fdo#109271]) +15 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20449/fi-kbl-soraka/igt@amdgpu/[email protected]
* igt@kms_chamelium@dp-crc-fast:
- fi-bsw-nick: NOTRUN -> [SKIP][8] ([fdo#109271] / [fdo#111827]) +8 similar issues
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20449/fi-bsw-nick/igt@[email protected]
* igt@prime_vgem@basic-fence-flip:
- fi-bsw-nick: NOTRUN -> [SKIP][9] ([fdo#109271]) +63 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20449/fi-bsw-nick/igt@[email protected]
* igt@runner@aborted:
- fi-kbl-8809g: NOTRUN -> [FAIL][10] ([i915#3363])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20449/fi-kbl-8809g/igt@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#3303]: https://gitlab.freedesktop.org/drm/intel/issues/3303
[i915#3363]: https://gitlab.freedesktop.org/drm/intel/issues/3363
Participating hosts (41 -> 38)
------------------------------
Missing (3): fi-ilk-m540 fi-bsw-cyan fi-bdw-samus
Build changes
-------------
* Linux: CI_DRM_10271 -> Patchwork_20449
CI-20190529: 20190529
CI_DRM_10271: 7a4a01d6716339c418394dbeb9a20d55bbb9a9ba @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_6117: 3ba0a02404f243d6d8f232c6215163cc4b0fd699 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_20449: 8a320e973471dadebf185470543bfff31807af3f @ git://anongit.freedesktop.org/gfx-ci/linux
== Linux commits ==
8a320e973471 drm/i915/guc: Unblock GuC submission on Gen11+ b49edbcc9280 drm/i915/guc: Add golden context to GuC ADS9bedfd84c9e8 drm/i915/guc: Include scheduling policies in the debugfs state dump 055c438902ea drm/i915/guc: Connect reset modparam updates to GuC policy flags 2529cfc15930 drm/i915/guc: Hook GuC scheduling policies up c24a302b3409 drm/i915/guc: Fix for error capture after full GPU reset with GuC d43f902c9f69 drm/i915/guc: Capture error state on context reset cf156af71348 drm/i915/guc: Enable GuC engine resetb7f2c290b8da drm/i915/guc: Don't complain about reset races adcd1418b513 drm/i915/guc: Provide mmio list to be saved/restored on engine reset ee41dea700c0 drm/i915/guc: Enable the timer expired interrupt for GuC 5560a36d3f00 drm/i915/guc: Handle engine reset failure notification a921fc062048 drm/i915/guc: Handle context reset notification 345f1eca0a86 drm/i915/guc: Suspend/resume implementation for new interface 17b20c0c8bd7 drm/i915/guc: Add disable interrupts to guc sanitize 848ca056fc3e drm/i915: Reset GPU immediately if submission is disabled 3c79abc34b26 drm/i915/guc: Reset implementation for new GuC interface 7ae740c21ec4 drm/i915/guc: Direct all breadcrumbs for a class to single breadcrumbs 2fca6597dcd8 drm/i915/guc: Disable bonding extension with GuC submission 81e0788642e7 drm/i915: Hold reference to intel_context over life of i915_request 5ca8f1a503a8 drm/i915: Track 'serial' counts for virtual engines 351767d30288 drm/i915/guc: GuC virtual engines37ebee77b9c2 drm/i915: Add intel_context tracing4adb7ce61e5f drm/i915/guc: Add several request trace points c84dc5dbebea drm/i915/guc: Update GuC debugfs to support new GuC a03438ead8d3 drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC 588df5bce44c drm/i915/guc: Ensure G2H response has space in buffer 59c796b965e6 drm/i915/guc: Disable semaphores when using GuC scheduling e53180c87b60 drm/i915/guc: Ensure request ordering via completion fences 195129a34fbe drm/i915: Disable preempt busywait when using GuC scheduling e7452c180185 drm/i915/guc: Extend deregistration fence to schedule disable 9e9fc047e7c1 drm/i915/guc: Disable engine barriers with GuC during unpin 53890c0d5072 drm/i915/guc: Defer context unpin until scheduling is disabled 0ddf4a0e5ead drm/i915/guc: Insert fence on context when deregistering b9faec389671 drm/i915/guc: Implement GuC context operations for new inteface 86db42bdbf1a drm/i915/guc: Add bypass tasklet submission path to GuC 0478ac5fcc47 drm/i915/guc: Implement GuC submission tasklet dbd8df00f28f drm/i915/guc: Add lrc descriptor context lookup array 9cc26b390c65 drm/i915/guc: Remove GuC stage descriptor, add lrc descriptor 071d7fa76a91 drm/i915/guc: Add new GuC interface defines and structures 28324246d8aa drm/i915/guc: Module load failure test for CT buffer creation 2c9efd827987 drm/i915/guc: Optimize CTB writes and readsc0779d6fc3b7 drm/i915/guc: Add stall timer to non blocking CTB send function 3d4dab7e7c81 drm/i915/guc: Add non blocking CTB send function beb15fc92c92 drm/i915/guc: Increase size of CTB buffers743d703ec315 drm/i915/guc: Improve error message for unsolicited CT response a582e9c666ff drm/i915/guc: Relax CTB response timeout
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20449/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 03/47] drm/i915/guc: Increase size of CTB buffers
In reply to Matthew BrostQuoted 35 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-2@@ -58,11 +58,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 2 dwords which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)struct ct_request {struct list_head link;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 649
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -641,7 +646,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);
CTB size is already printed in intel_guc_ct_init() and is fixed so not sure if repeating it on every ct_read has any benefit
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 652
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0GEM_BUG_ON (available <0 ); header = cmds[head];
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
In reply to Matthew BrostQuoted 24 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)
hmm, this flag really belongs to intel_guc_ct_send() so it should be defined as CTB flag near that function declaration
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));
or as we already switched to accept and return whole HXG messages in guc_send_mmio() maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header with HXG_EVENT type and then in CTB code just look at this type to make decision which code path to use
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;
here you are returning true(1) as has room
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0+} + +static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len,
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+ u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags; +u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );
but here you treat "1" it as en error
and this "1" is GUC_HXG_MSG_MIN_LEN, right ?
Quoted 28 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +17
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep (); +/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare.
shouldn't we at least try to log such cases with RATE_LIMITED to find out how "rare" it is, or if really unlikely just return -EBUSY as in case of non-blocking send ?
Quoted 53 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-1@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 93
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1@@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 03/47] drm/i915/guc: Increase size of CTB buffers
In reply to Michal WajdeczkoQuoted 35 lines · Michal Wajdeczko
Quoted 32 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-2@@ -58,11 +58,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 2 dwords which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 649
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1struct ct_request {struct list_head link;@@ -641,7 +646,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);CTB size is already printed in
intel_guc_ct_init()and is fixed so not sure if repeating it on everyct_readhas any benefit
I'd say more debug the better and if CT_DEBUG is enabled the logs are very verbose so an extra value doesn't really hurt.
Matt
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0GEM_BUG_ON (available <0 ); header = cmds[head];
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
In reply to Michal WajdeczkoQuoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)
Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declaration
I can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);
Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to use
Not sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?
Not exactly. This is following how ct_send() uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.
Quoted 33 lines
Quoted 33 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?
Definitely not return -EBUSY as this a blocking call. Perhaps we can log this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [Intel-gfx] [PATCH 39/47] drm/i915/guc: Don't complain about reset races
In reply to Matthew BrostQuoted 10 lines · Matthew Brost
From: John Harrison <[email protected]>
It is impossible to seal all race conditions of resets occurring concurrent to other operations. At least, not without introducing excesive mutex locking. Instead, don't complain if it occurs. In particular, don't complain if trying to send a H2G during a reset. Whatever the H2G was about should get redone once the reset is over.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>
Quoted 63 lines
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 5 ++++- drivers/gpu/drm/i915/gt/uc/intel_uc.c | 3 +++ drivers/gpu/drm/i915/gt/uc/intel_uc.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-1@@ -727,7 +727,10 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,int ret;if (unlikely (!ct->enabled)) { -WARN (1 ,"Unexpected send: action=%#x\n" , *action); +struct intel_guc *guc =ct_to_guc (ct); + struct intel_uc *uc = container_of(guc, struct intel_uc, guc); + +WARN (!uc->reset_in_progress,"Unexpected send: action=%#x\n" , *action);return -ENODEV ; }drivers/gpu/drm/i915/gt/uc/intel_uc.c +3
-0@@ -550,6 +550,7 @@ void intel_uc_reset_prepare(struct intel_uc *uc) {struct intel_guc *guc = &uc->guc; + uc->reset_in_progress = true;/* Nothing to do if GuC isn't supported */ if (!intel_uc_supports_guc (uc))@@ -579,6 +580,8 @@ void intel_uc_reset_finish(struct intel_uc *uc) {struct intel_guc *guc = &uc->guc; + uc->reset_in_progress = false; +/* 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);drivers/gpu/drm/i915/gt/uc/intel_uc.h +2
-0@@ -30,6 +30,8 @@ struct intel_uc {/* Snapshot of GuC log from last failed load */ struct drm_i915_gem_object *load_err_log; + +bool reset_in_progress; };void intel_uc_init_early (struct intel_uc *uc);Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 40/47] drm/i915/guc: Enable GuC engine reset
In reply to Matthew BrostQuoted 7 lines · Matthew Brost
From: John Harrison <[email protected]>
Clear the 'disable resets' flag to allow GuC to reset hung contexts (detected via pre-emption timeout).
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>
Quoted 25 lines
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +1
-2@@ -81,8 +81,7 @@ static void guc_policies_init(struct guc_policies *policies) { policies->dpc_promote_time =GLOBAL_POLICY_DEFAULT_DPC_PROMOTE_TIME_US ; policies->max_num_work_items =GLOBAL_POLICY_MAX_NUM_WI ; -/* Disable automatic resets as not yet supported. */ - policies->global_flags =GLOBAL_POLICY_DISABLE_ENGINE_RESET ; + policies->global_flags =0 ; policies->is_valid =1 ; }Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 45/47] drm/i915/guc: Include scheduling policies in the debugfs state dump
In reply to Matthew BrostQuoted 7 lines · Matthew Brost
From: John Harrison <[email protected]>
Added the scheduling policy parameters to the '
guc_info' debugfs state dump.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>
Quoted 69 lines
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 13 +++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h | 2 ++ drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 2 ++ 3 files changed, 17 insertions(+)drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +13
-0@@ -92,6 +92,19 @@ static void guc_policies_init(struct intel_guc *guc, struct guc_policies *polici policies->is_valid =1 ; } +void intel_guc_log_policy_info (struct intel_guc *guc,struct drm_printer *dp) +{ +struct __guc_ads_blob *blob = guc->ads_blob; + +if (unlikely (!blob)) +return ; + +drm_printf (dp,"Global scheduling policies:\n" ); +drm_printf (dp," DPC promote time = %u\n" , blob->policies.dpc_promote_time); +drm_printf (dp," Max num work items = %u\n" , blob->policies.max_num_work_items); +drm_printf (dp," Flags = %u\n" , blob->policies.global_flags); +} +static int guc_action_policies_update (struct intel_guc *guc,u32 policy_offset) {u32 action[] = {drivers/gpu/drm/i915/gt/uc/intel_guc_ads.h +2
-0@@ -7,9 +7,11 @@#define _INTEL_GUC_ADS_H_struct intel_guc ; +struct drm_printer ;int intel_guc_ads_create (struct intel_guc *guc);void intel_guc_ads_destroy (struct intel_guc *guc);void intel_guc_ads_reset (struct intel_guc *guc); +void intel_guc_log_policy_info (struct intel_guc *guc,struct drm_printer *p);#endif drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +2
-0@@ -10,6 +10,7 @@#include "intel_guc_debugfs.h" #include "intel_guc_log_debugfs.h" #include "gt/uc/intel_guc_ct.h" +#include "gt/uc/intel_guc_ads.h" #include "gt/uc/intel_guc_submission.h" static int guc_info_show (struct seq_file *m,void *data)@@ -29,6 +30,7 @@ static int guc_info_show(struct seq_file *m, void *data)intel_guc_log_ct_info (&guc->ct, &p);intel_guc_log_submission_info (guc, &p); +intel_guc_log_policy_info (guc, &p);return 0 ; }Signature · 1 line
2.28.0
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
In reply to Matthew BrostQuoted 157 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 6 lines
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.
well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
we can try do it later but by doing it right now we would avoid introducing this send_nb() function and deprecating them long term again
Quoted 44 lines
Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?
Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can log
blocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
Quoted 64 lines
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [PATCH 01/47] drm/i915/guc: Relax CTB response timeout
In reply to Matthew BrostQuoted 27 lines · Matthew Brost
In upcoming patch we will allow more CTB requests to be sent in parallel to the GuC for processing, so we shouldn't assume any more that GuC will always reply without 10ms.
Use bigger value hardcoded value of 1s instead.
v2: Add
CONFIG_DRM_I915_GUC_CTB_TIMEOUTconfig option v3:
(Daniel Vetter)
- Use hardcoded value of 1s rather than config optionSigned-off-by Matthew Brost <[email protected]>Cc Michal Wajdeczko <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -474,14 +474,16 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)/* * Fast commands should complete in less than 10us, so sample quickly * up to that length of time, then switch to a slower sleep-wait loop. -* No GuC command should ever take longer than 10ms. +* No GuC command should ever take longer than 10ms but many GuC
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 486
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-1+* commands can be inflight at time, so use a 1s timeout on the slower +* sleep-wait loop. */ #define done \ (FIELD_GET(GUC_HXG_MSG_0_ORIGIN, READ_ONCE(req->status)) == \ GUC_HXG_ORIGIN_GUC) err =wait_for_us (done,10 );if (err) - err =wait_for (done,10 ); + err =wait_for (done,1000 );
can we add #defines for these 10/1000 values? with that
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 489
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0#undef doneif (unlikely (err))
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 05/47] drm/i915/guc: Add stall timer to non blocking CTB send function
In reply to Matthew BrostQuoted 5 lines · Matthew Brost
Implement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Also update to
ct_writeto return-EIOrather than-EPIPEon a corrupted descriptor.
by doing so you will have the same error code for two different problems:
a) corrupted CTB descriptor (definitely unrecoverable)
b) long stall in CTB processing (still recoverable)
while caller is explicitly instructed to retry only on:
c) temporary stall in CTB processing (likely recoverable)
so why do we want to limit our diagnostics?
Quoted 40 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 47 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 ++ 2 files changed, 48 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-2@@ -319,6 +319,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) goto err_deregister; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;@@ -392,7 +393,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EIO ;if (unlikely (desc->status)) goto corrupted;@@ -464,7 +465,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EIO ; }/**
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 511
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -507,6 +508,18 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +#define GUC_CTB_TIMEOUT_MS 1500
it's 150% of core CTB timeout, maybe we should correlate them ?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0+static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +long timeout =GUC_CTB_TIMEOUT_MS ; +bool ret =ktime_ms_delta (ktime_get (), ct->stall_time) > timeout; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" );
nit: in commit message you said all these changes are to "prevent deadlock" so maybe this message should rather be:
int delta = ktime_ms_delta(ktime_get(), ct->stall_time); CT_ERROR(ct, "Communication stalled for %dms\n", delta);
(note that CT_ERROR already adds "CT" prefix)
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0+ +return ret; +} +static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;@@ -518,6 +531,26 @@ static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; } +static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw) · line 544
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct)))
and maybe above message should be printed somewhere around here when we detect "deadlock" for the first time?
Quoted 22 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-1+return -EIO ; + else + return -EBUSY; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -530,7 +563,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =h2g_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 611
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0@@ -574,11 +607,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();
as this is a repeated pattern, maybe it should be moved to h2g_has_room or other wrapper ?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 621
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EIO ; +cond_resched (); goto retry; } + ct->stall_time =KTIME_MAX ;
this one too
Quoted 18 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+ fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-0@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h"
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 77
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -68,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time; };void intel_guc_ct_init_early (struct intel_guc_ct *ct);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
In reply to Michal WajdeczkoQuoted 163 lines · Michal Wajdeczko
Quoted 160 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?
Quoted 7 lines
Quoted 3 lines
Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
Yes, I know. See above. To me GUC_HXG_MSG_MIN_LEN makes zero sense and it is worse than adding + 1. This + 1 accounts for the CT header not the HXG header. If any we add a new define, GUC_CT_HDR_LEN, and add that.
Matt
Quoted 125 lines
we can try do it later but by doing it right now we would avoid introducing this
send_nb()function and deprecating them long term againQuoted 44 lines
Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can logblocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
Quoted 64 lines
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
In reply to Michal WajdeczkoQuoted 217 lines · Michal Wajdeczko
Quoted 157 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 6 lines
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
we can try do it later but by doing it right now we would avoid introducing this
send_nb()function and deprecating them long term againQuoted 44 lines
Quoted 43 lines
Quoted 29 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +17
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep (); +/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?
Quoted 7 lines
Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can logblocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
And have to rewrite reset of the stack with the new behavior, that seems wrong. This function is allowed to block, so let it.
If you want to do this but all means go ahead but I'll likely NACK it as over engineered.
Quoted 7 lines
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
We don't care if this is hit in IGTs as this isn't a real world use case and will spam the dmesg if we hit this. I can make a note of this as an open and we can revisit later.
Matt
Quoted 64 lines
Quoted 64 lines
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [Intel-gfx] [PATCH 05/47] drm/i915/guc: Add stall timer to non blocking CTB send function
In reply to Michal WajdeczkoQuoted 6 lines · Michal Wajdeczko
Quoted 3 lines · Matthew Brost
Implement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Quoted 8 lines
Quoted 2 lines
Also update to
ct_writeto return-EIOrather than-EPIPEon a corrupted descriptor.by doing so you will have the same error code for two different problems:
a) corrupted CTB descriptor (definitely unrecoverable)
b) long stall in CTB processing (still recoverable)
Already discussed both are treated exactly the same by the rest of the stack so we return a single error code.
Quoted 44 lines
while caller is explicitly instructed to retry only on:
c) temporary stall in CTB processing (likely recoverable)
so why do we want to limit our diagnostics?
Quoted 38 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 47 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 4 ++ 2 files changed, 48 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-2@@ -319,6 +319,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) goto err_deregister; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;@@ -392,7 +393,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EIO ;if (unlikely (desc->status)) goto corrupted;@@ -464,7 +465,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EIO ; }
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 511
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0/** @@ -507,6 +508,18 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +#define GUC_CTB_TIMEOUT_MS 1500it's 150% of core CTB timeout, maybe we should correlate them ?
Seems overkill.
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0+static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +long timeout =GUC_CTB_TIMEOUT_MS ; +bool ret =ktime_ms_delta (ktime_get (), ct->stall_time) > timeout; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" );nit: in commit message you said all these changes are to "prevent deadlock" so maybe this message should rather be:
Quoted 4 lines
int delta = ktime_ms_delta(ktime_get(), ct->stall_time); CT_ERROR(ct, "Communication stalled for %dms\n", delta);
Sure.
Quoted 13 lines
(note that
CT_ERRORalready adds "CT" prefix)Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+ +return ret; +} +static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;@@ -518,6 +531,26 @@ static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; }
Quoted 15 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool h2g_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw) · line 544
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct)))and maybe above message should be printed somewhere around here when we detect "deadlock" for the first time?
Not sure I follow. The error message is in the correct place if ask me. Probably should set the broken flag though when the message is printed though.
Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-1+return -EIO ; + else + return -EBUSY; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -530,7 +563,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =h2g_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 611
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0@@ -574,11 +607,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();as this is a repeated pattern, maybe it should be moved to
h2g_has_roomor other wrapper ?
Once we check G2H credits the pattern changes, hence the reason for this outside of the wrapper. Also IMO sometimes we go a little overboard with wrappers and it makes the code harder to understand.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EIO ; +cond_resched (); goto retry; }
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 621
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+ ct->stall_time =KTIME_MAX ;this one too
Same as above.
Matt
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+ fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +4
-0@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -68,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time; };
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 77
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-0void intel_guc_ct_init_early (struct intel_guc_ct *ct);
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 43/47] drm/i915/guc: Hook GuC scheduling policies up
In reply to Matthew BrostQuoted 122 lines · Matthew Brost
From: John Harrison <[email protected]>
Use the official driver default scheduling policies for configuring the GuC scheduler rather than a bunch of hardcoded values.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>Cc Jose Souza <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 44 ++++++++++++++++++- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 11 +++-- 4 files changed, 53 insertions(+), 5 deletions(-)drivers/gpu/drm/i915/gt/intel_engine_types.h +1
-0@@ -455,6 +455,7 @@ struct intel_engine_cs {#define I915_ENGINE_IS_VIRTUAL BIT(5)#define I915_ENGINE_HAS_RELATIVE_MMIO BIT(6)#define I915_ENGINE_REQUIRES_CMD_PARSER BIT(7) +#define I915_ENGINE_WANT_FORCED_PREEMPTION BIT(8)unsigned int flags;/* drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0@@ -270,6 +270,8 @@ int intel_guc_engine_failure_process_msg(struct intel_guc *guc,void intel_guc_find_hung_context (struct intel_engine_cs *engine); +int intel_guc_global_policies_update (struct intel_guc *guc); +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);drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +42
-2@@ -77,14 +77,54 @@ static u32 guc_ads_blob_size(struct intel_guc *guc)guc_ads_private_data_size (guc); } -static void guc_policies_init (struct guc_policies *policies) +static void guc_policies_init (struct intel_guc *guc,struct guc_policies *policies) { +struct intel_gt *gt =guc_to_gt (guc); +struct drm_i915_private *i915 = gt->i915; + policies->dpc_promote_time =GLOBAL_POLICY_DEFAULT_DPC_PROMOTE_TIME_US ; policies->max_num_work_items =GLOBAL_POLICY_MAX_NUM_WI ; + policies->global_flags =0 ; +if (i915->params.reset <2 ) + policies->global_flags |=GLOBAL_POLICY_DISABLE_ENGINE_RESET ; + policies->is_valid =1 ; } +static int guc_action_policies_update (struct intel_guc *guc,u32 policy_offset) +{ +u32 action[] = { +INTEL_GUC_ACTION_GLOBAL_SCHED_POLICY_CHANGE , + policy_offset + }; + +return intel_guc_send (guc, action,ARRAY_SIZE (action)); +} + +int intel_guc_global_policies_update (struct intel_guc *guc) +{ +struct __guc_ads_blob *blob = guc->ads_blob; +struct intel_gt *gt =guc_to_gt (guc); +intel_wakeref_t wakeref; +int ret; + +if (!blob) +return -ENOTSUPP ; + +GEM_BUG_ON (!blob->ads.scheduler_policies); + +guc_policies_init (guc, &blob->policies); + +if (!intel_guc_is_ready (guc)) +return 0 ; + +with_intel_runtime_pm (>->i915->runtime_pm, wakeref) + ret = guc_action_policies_update(guc, blob->ads.scheduler_policies); + +return ret; +} +static void guc_mapping_table_init (struct intel_gt *gt,struct guc_gt_system_info *system_info) {@@ -281,7 +321,7 @@ static void __guc_ads_init(struct intel_guc *guc)u8 engine_class, guc_class;/* GuC scheduling policies */ -guc_policies_init (&blob->policies); +guc_policies_init (guc, &blob->policies);/* * GuC expects a per-engine-class context image and size drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -873,6 +873,7 @@ void intel_guc_submission_reset_finish(struct intel_guc *guc)GEM_WARN_ON (atomic_read (&guc->outstanding_submission_g2h));atomic_set (&guc->outstanding_submission_g2h,0 ); +intel_guc_global_policies_update (guc);enable_submission (guc);intel_gt_unpark_heartbeats (guc_to_gt (guc)); }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_context_policy_init(struct intel_engine_cs *engine, · line 1165
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-2@@ -1161,8 +1162,12 @@ static void guc_context_policy_init(struct intel_engine_cs *engine, { desc->policy_flags =0 ; - desc->execution_quantum =CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US ; - desc->preemption_timeout =CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US ; +if (engine->flags &I915_ENGINE_WANT_FORCED_PREEMPTION )
I can't see where we set this in this series, although I do see a selftest we need to fixup that sets this. Perhaps we drop this until we fix that selftest? Or at minimum add a comment saying it will be used in the future by selftests. What do you think John?
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+ desc->policy_flags |=CONTEXT_POLICY_FLAG_PREEMPT_TO_IDLE ; + +/* NB: For both of these, zero means disabled. */ + desc->execution_quantum = engine->props.timeslice_duration_ms *1000 ; + desc->preemption_timeout = engine->props.preempt_timeout_ms *1000 ; }static int guc_lrc_desc_pin (struct intel_context *ce,bool loop)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_default_vfuncs(struct intel_engine_cs *engine) · line 1956
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -1945,13 +1950,13 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->set_default_submission = guc_set_default_submission; engine->flags |=I915_ENGINE_HAS_PREEMPTION ; + engine->flags |=I915_ENGINE_HAS_TIMESLICES ;/* * TODO: GuC supports timeslicing and semaphores as well, but they're
Nit, we now support timeslicing. I can fix that up in next rev.
Matt
Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-1* handled by the firmware so some minor tweaks are required before * enabling. * -* engine->flags |= I915_ENGINE_HAS_TIMESLICES; * engine->flags |= I915_ENGINE_HAS_SEMAPHORES; */ Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 44/47] drm/i915/guc: Connect reset modparam updates to GuC policy flags
In reply to Matthew BrostQuoted 89 lines · Matthew Brost
From: John Harrison <[email protected]>
Changing the reset module parameter has no effect on a running GuC. The corresponding entry in the ADS must be updated and then the GuC informed via a Host2GuC message.
The new debugfs interface to module parameters allows this to happen. However, connecting the parameter data address back to anything useful is messy. One option would be to pass a new private data structure address through instead of just the parameter pointer. However, that means having a new (and different) data structure for each parameter and a new (and different) write function for each parameter. This method keeps everything generic by instead using a string lookup on the directory entry name.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 2 +- drivers/gpu/drm/i915/i915_debugfs_params.c | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +1
-1@@ -99,7 +99,7 @@ static int guc_action_policies_update(struct intel_guc *guc, u32 policy_offset) policy_offset }; -return intel_guc_send (guc, action,ARRAY_SIZE (action)); +return intel_guc_send_busy_loop (guc, action,ARRAY_SIZE (action),0 , true); }int intel_guc_global_policies_update (struct intel_guc *guc)drivers/gpu/drm/i915/i915_debugfs_params.c +23
-0@@ -6,9 +6,20 @@#include <linux/kernel.h> #include "i915_debugfs_params.h" +#include "gt/intel_gt.h" +#include "gt/uc/intel_guc.h" #include "i915_drv.h" #include "i915_params.h" +#define MATCH_DEBUGFS_NODE_NAME (_file, _name) (strcmp((_file)->f_path.dentry->d_name.name, (_name)) == 0) + +#define GET_I915 (i915, name, ptr) \ + do { \ + struct i915_params *params; \ + params = container_of(((void *) (ptr)), typeof(*params), name); \ + (i915) = container_of(params, typeof(*(i915)), params); \ + } while(0) +/* int param */ static int i915_param_int_show (struct seq_file *m,void *data) {@@ -24,6 +35,16 @@ static int i915_param_int_open(struct inode *inode, struct file *file)return single_open (file, i915_param_int_show, inode->i_private); } +static int notify_guc (struct drm_i915_private *i915) +{ +int ret =0 ; + +if (intel_uc_uses_guc_submission (&i915->gt.uc)) + ret =intel_guc_global_policies_update (&i915->gt.uc.guc); + +return ret; +} +static ssize_t i915_param_int_write (struct file *file,const char __user *ubuf,size_t len,loff_t *offp)@@ -81,8 +102,10 @@ static ssize_t i915_param_uint_write(struct file *file, const char __user *ubuf, size_t len, loff_t *offp) { + struct drm_i915_private *i915;struct seq_file *m = file->private_data;unsigned int *value = m->private; +unsigned int old = *value;int ret; ret =kstrtouint_from_user (ubuf, len,0 , value);
drivers/gpu/drm/i915/i915_debugfs_params.c static ssize_t i915_param_uint_write(struct file *file, · line 122
Quoted 5 lines
drivers/gpu/drm/i915/i915_debugfs_params.c +2
-0@@ -95,6 +118,14 @@ static ssize_t i915_param_uint_write(struct file *file, *value = b; } +if (!ret &&MATCH_DEBUGFS_NODE_NAME (file,"reset" )) { +GET_I915 (i915, reset, value);
We might want to make this into a macro in case we need to update more than just "reset" with the GuC going forward but that is not a blocker.
With that:
Quoted 16 lines
drivers/gpu/drm/i915/i915_debugfs_params.c +6
-0+ + ret =notify_guc (i915); +if (ret) + *value = old; + } +return ret ?: len; }Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
In reply to Matthew BrostQuoted 168 lines · Matthew Brost
Quoted 167 lines · Michal Wajdeczko
Quoted 163 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.
Quoted 7 lines
Quoted 3 lines
well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
Yes, I know. See above. To me
GUC_HXG_MSG_MIN_LENmakes zero sense and it is worse than adding + 1. This + 1 accounts for the CT header not the HXG header. If any we add a new define,GUC_CT_HDR_LEN, and add that.
you mean GUC_CTB_MSG_MIN_LEN ? it's already there [1]
Quoted 121 lines
Matt
Quoted 118 lines
we can try do it later but by doing it right now we would avoid introducing this
send_nb()function and deprecating them long term againQuoted 44 lines
Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can logblocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
Quoted 57 lines
Matt
Quoted 54 lines
Quoted 54 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-1@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 93
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 02/47] drm/i915/guc: Improve error message for unsolicited CT response
In reply to Matthew BrostQuoted 17 lines · Matthew Brost
Improve the error message when a unsolicited CT response is received by printing fence that couldn't be found, the last fence, and all requests with a response outstanding.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0@@ -730,12 +730,16 @@ static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r found = true;break ; }
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r · line 739
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3-spin_unlock_irqrestore (&ct->requests.lock, flags); -if (!found) {CT_ERROR (ct,"Unsolicited response (fence %u)\n" , fence); -return -ENOKEY ; +CT_ERROR (ct,"Could not find fence=%u, last_fence=%u\n" , fence, + ct->requests.last_fence); +list_for_each_entry (req, &ct->requests.pending, link) +CT_ERROR (ct,"request %u awaits response\n" , + req->fence);
not quite sure how listing of awaiting requests could help here (if we suspect that this is a duplicated reply, then we should rather track short list of already processed messages to look there) but since it does not hurt too much, this is:
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r · line 745
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0+ err = -ENOKEY ; } +spin_unlock_irqrestore (&ct->requests.lock, flags);if (unlikely (err))return err;
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Michal Wajdeczko
Reviewed-byRe: [PATCH 03/47] drm/i915/guc: Increase size of CTB buffers
In reply to Matthew BrostQuoted 49 lines · Matthew Brost
Quoted 35 lines · Michal Wajdeczko
Quoted 32 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-2@@ -58,11 +58,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 2 dwords which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 649
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1struct ct_request {struct list_head link;@@ -641,7 +646,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);CTB size is already printed in
intel_guc_ct_init()and is fixed so not sure if repeating it on everyct_readhas any benefit
Quoted 2 lines
I'd say more debug the better and if
CT_DEBUGis enabled the logs are very verbose so an extra value doesn't really hurt.
fair, but this doesn't mean we should add little/no value item, anyway since DEBUG_GUC is if off by default, this is:
Quoted 7 lines
Matt
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0GEM_BUG_ON (available <0 ); header = cmds[head];
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 06/47] drm/i915/guc: Optimize CTB writes and reads
In reply to Matthew BrostQuoted 42 lines · Matthew Brost
CTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail) which could result in accesses across the PCIe bus, store shadow local copies and only read/write the descriptor values when absolutely necessary. Also store the current space in the each channel locally.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 ++++++++++++++--------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 51 insertions(+), 31 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3@@ -130,6 +130,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }@@ -383,10 +387,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 403
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -398,25 +400,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC
since we are caching tail, we may want to check if it's sill correct:
tail = READ_ONCE(desc->tail);
if (unlikely(tail != ctb->tail)) {
CT_ERROR(ct, "Tail was modified %u != %u\n",
tail, ctb->tail);
desc->status |= GUC_CTB_STATUS_MISMATCH;
goto corrupted;
}and since we own the tail then we can be more strict:
GEM_BUG_ON(tail > size);
and then finally just check GuC head:
head = READ_ONCE(desc->head);
if (unlikely(head >= size)) {
...Quoted 25 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-14+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 453
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0@@ -457,7 +448,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;
this magic "1" is likely GUC_CTB_MSG_MIN_LEN, right ?
Quoted 30 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8
-5return 0 ;@@ -473,7 +466,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value. @@ -520,24 +513,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) { -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 535
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;
maybe here we could mark stall_time ?
if (space >= len_dw)
return true; if (ct->stall_time == KTIME_MAX) ct->stall_time = ktime_get(); return false;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 537
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0return space >= len_dw;
btw, maybe to avoid filling CTB to the last dword, this should be
space > len_dw
note the earlier comment:
/*
* tail == head condition indicates empty. GuC FW does not support
* using up the entire buffer to get tail == head meaning full. */
Quoted 45 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-7}static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -606,10 +610,10 @@ static int ct_send(struct intel_guc_ct *ct,*/ retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (ct_deadlocked (ct)))return -EIO ;@@ -632,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (err)) goto unlink;@@ -720,7 +724,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 742
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -735,12 +739,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC
as above we may want to check if our cached head was not modified
Quoted 40 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) { +CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;@@ -790,6 +803,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands 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 * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 48
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;
in later patch this is changing to atomic_t
maybe we can start with it ?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 51
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-0bool broken; };
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 10/47] drm/i915/guc: Add lrc descriptor context lookup array
In reply to Matthew BrostQuoted 5 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.
s/lrc/LRC
Quoted 13 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc.h line 9
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_ +#include "linux/xarray.h"
#include <linux/xarray.h>
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 55
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-0+#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h" @@ -46,6 +48,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr; +/* guc_id to intel_context lookup */ +struct xarray context_lookup; +/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];
btw, IIRC there was idea to move most struct definitions to intel_guc_types.h, is this still a plan ?
Quoted 58 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +28
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, 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 ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_init(struct intel_guc *guc) · line 433
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0@@ -400,6 +426,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool); +xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 13/47] drm/i915/guc: Implement GuC context operations for new inteface
In reply to Matthew BrostQuoted 64 lines · Matthew Brost
Implement GuC context operations which includes GuC specific operations alloc, 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 | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 664 ++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + 8 files changed, 677 insertions(+), 55 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 +14
-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; +/* GuC lrc descriptor ID */ +u16 guc_id; +
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 163
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +5
-3+/* 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;
some fields are being added with kerneldoc, some without what's the rule ?
Quoted 319 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +0
-0};#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@@ -44,6 +44,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 stolen +*/ +spinlock_t contexts_lock; +struct ida guc_ids; +struct list_head guc_id_list; +bool submission_selected;struct i915_vma *ads_vma;@@ -102,6 +110,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);@@ -203,6 +234,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 +4
-0@@ -901,6 +901,10 @@ 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); +break ;default : ret = -EOPNOTSUPP ;break ;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +190
-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" @@ -85,6 +87,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);@@ -155,6 +224,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;@@ -417,6 +489,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 ; }@@ -429,9 +505,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 ) +tasklet_hi_schedule (&sched_engine->tasklet); + +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 ; +
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_fini(struct intel_guc *guc) · line 632
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+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
C++ style comment
Quoted 468 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +354
-49+ } +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 ; + + 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; +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); + 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 +* 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,@@ -443,36 +813,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 @@ -483,56 +954,47 @@ 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; - -__i915_request_submit (rq); + rq->reserved_space -=GUC_REQUEST_SIZE ; -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; +/* +* 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 ; -/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&sched_engine->lock, flags); + ret =pin_guc_id (guc, ce);/* returns 1 if new guc_id assigned */ +if (unlikely (ret <0 )) +return ret;; +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 ) -tasklet_hi_schedule (&sched_engine->tasklet); +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)@@ -606,6 +1068,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 */ @@ -718,6 +1220,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)@@ -743,3 +1246,62 @@ void intel_guc_submission_init_early(struct intel_guc *guc) { guc->submission_selected =__guc_submission_selected (guc);
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_init_early(struct intel_guc *guc) · line 1257
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +9
-0} + +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);
just debug? why not an (fatal) error ?
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_init_early(struct intel_guc *guc) · line 1264
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0+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);
not an error ?
Quoted 68 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +43
-0+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@@ -4142,6 +4142,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) */
Re: [PATCH 10/47] drm/i915/guc: Add lrc descriptor context lookup array
In reply to Michal WajdeczkoQuoted 11 lines · Michal Wajdeczko
Quoted 5 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.s/lrc/LRC
I guess? lrc and LRC are used interchangeably throughout the current code base.
Quoted 16 lines
Quoted 16 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h line 9
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+#include "linux/xarray.h" #include <
linux/xarray.h>
Yep.
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h" @@ -46,6 +48,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 55
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +3
-0+/* guc_id to intel_context lookup */ +struct xarray context_lookup; +/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];btw, IIRC there was idea to move most struct definitions to
intel_guc_types.h, is this still a plan ?
I don't ever recall discussing this but we can certainly do this. For what it is worth we do introduce intel_guc_submission_types.h a bit later. I'll make a note about intel_guc_types.h though.
Matt
Quoted 60 lines
Quoted 60 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +28
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, 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 ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */ @@ -400,6 +426,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool);
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_init(struct intel_guc *guc) · line 433
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 13/47] drm/i915/guc: Implement GuC context operations for new inteface
In reply to Michal WajdeczkoQuoted 64 lines · Michal Wajdeczko
Quoted 61 lines · Matthew Brost
Implement GuC context operations which includes GuC specific operations alloc, 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 | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 664 ++++++++++++++++-- drivers/gpu/drm/i915/i915_reg.h | 1 + drivers/gpu/drm/i915/i915_request.c | 1 + 8 files changed, 677 insertions(+), 55 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;
Quoted 17 lines
drivers/gpu/drm/i915/gt/intel_context_types.h struct intel_context { · line 163
Quoted 13 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +8
-3+/* 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;some fields are being added with kerneldoc, some without what's the rule ?
Yea, idk. I think we need to scrub all the structures in the driver and add kernel doc everywhere. IMO not a blocker too as I think all the structures are going to be reworked with OO concepts after the GuC code lands before moving to DRM scheduler. That would be logical time to update all the kernel doc too.
Quoted 323 lines
Quoted 323 lines
drivers/gpu/drm/i915/gt/intel_context_types.h +0
-0};#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@@ -44,6 +44,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 stolen +*/ +spinlock_t contexts_lock; +struct ida guc_ids; +struct list_head guc_id_list; +bool submission_selected;struct i915_vma *ads_vma;@@ -102,6 +110,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);@@ -203,6 +234,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 +4
-0@@ -901,6 +901,10 @@ 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); +break ;default : ret = -EOPNOTSUPP ;break ;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +194
-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" @@ -85,6 +87,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);@@ -155,6 +224,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;@@ -417,6 +489,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 ; }@@ -429,9 +505,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 ) +tasklet_hi_schedule (&sched_engine->tasklet); + +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);
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_fini(struct intel_guc *guc) · line 632
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +6
-0+ +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 C++ style comment
Yep, will fix.
Quoted 464 lines
Quoted 464 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +354
-49+ } +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 ; + + 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; +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); + 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 +* 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,@@ -443,36 +813,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 @@ -483,56 +954,47 @@ 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; - -__i915_request_submit (rq); + rq->reserved_space -=GUC_REQUEST_SIZE ; -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; +/* +* 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 ; -/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&sched_engine->lock, flags); + ret =pin_guc_id (guc, ce);/* returns 1 if new guc_id assigned */ +if (unlikely (ret <0 )) +return ret;; +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 ) -tasklet_hi_schedule (&sched_engine->tasklet); +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)@@ -606,6 +1068,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 */ @@ -718,6 +1220,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); }
Quoted 17 lines
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0void intel_guc_submission_disable (struct intel_guc *guc)@@ -743,3 +1246,62 @@ void intel_guc_submission_init_early(struct intel_guc *guc) { guc->submission_selected =__guc_submission_selected (guc);drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_init_early(struct intel_guc *guc) · line 1257
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +9
-0} + +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);just debug? why not an (fatal) error ?
This is a G2H communication. We can't crash the driver if the GuC gives us crap.
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_init_early(struct intel_guc *guc) · line 1264
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7
-0+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);not an error ?
It is an error, we return NULL.
BTW - Can you include your name on the last comment? That makes it easier to know when I've reached the end of your comments.
Matt
Quoted 68 lines
Quoted 68 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +43
-0+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@@ -4142,6 +4142,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) */
Re: [Intel-gfx] [PATCH 04/47] drm/i915/guc: Add non blocking CTB send function
In reply to Michal WajdeczkoQuoted 175 lines · Michal Wajdeczko
Quoted 172 lines · Matthew Brost
Quoted 170 lines · Michal Wajdeczko
Quoted 157 lines · Matthew Brost
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. GuC submission will send CTBs in the critical path and does not need to wait for these CTBs to complete before moving on, hence the need for this new function.The non-blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with a properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 +++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 77 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 3 +- 3 files changed, 82 insertions(+), 10 deletions(-)Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) · line 80
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-1@@ -74,7 +74,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31)hmm, this flag really belongs to
intel_guc_ct_send()so it should be defined as CTB flag near that function declarationI can move this up a few lines.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +6
-1+static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -82,7 +90,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-1@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -373,7 +378,7 @@ static void write_barrier(struct intel_guc_ct *ct)static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -421,9 +426,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence);Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 435
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-3- hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));or as we already switched to accept and return whole HXG messages in
guc_send_mmio()maybe we should do the same for CTB variant too and instead of using extra flag just let caller to prepare proper HXG header withHXG_EVENTtype and then in CTB code just look at this type to make decision which code path to useNot sure I follow. Anyways could this be done in a follow up by you if want this change.
Quoted 10 lines
note that existing callers should not be impacted, as full HXG header for the REQUEST message looks exactly the same as "action" code alone.
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -498,6 +507,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 518
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw;here you are returning true(1) as has room
See below.
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-0+} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 533
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =h2g_has_room (ctb, len +1 );but here you treat "1" it as en error
Yes, this patch is broken but fixed in a follow up one. Regardless I'll fix this patch in place.
Quoted 6 lines
Quoted 2 lines
and this "1" is
GUC_HXG_MSG_MIN_LEN, right ?Not exactly. This is following how
ct_send()uses the action + len field. Action[0] field goes in the HXG header and extra + 1 is for the CT header.well, "len" already counts "action" so by treating input as full HXG message (including HXG header) will make it cleaner
Quoted 6 lines
Quoted 3 lines
Yes, I know. See above. To me
GUC_HXG_MSG_MIN_LENmakes zero sense and it is worse than adding + 1. This + 1 accounts for the CT header not the HXG header. If any we add a new define,GUC_CT_HDR_LEN, and add that.you mean
GUC_CTB_MSG_MIN_LEN? it's already there [1]
Kinda? I think we should have a define GUC_CTB_HDR_LEN which is 1 and GUC_CTB_MSG_MIN_LEN is defined as GUC_CTB_HDR_LEN. 'GUC_CTB_HDR_LEN' makes it clear that the + 1 is referring to the header. I've done this branch of these patches already.
Matt
Quoted 131 lines
Quoted 128 lines
Matt
Quoted 125 lines
we can try do it later but by doing it right now we would avoid introducing this
send_nb()function and deprecating them long term againQuoted 44 lines
Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -505,6 +554,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -514,8 +564,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 572
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. shouldn't we at least try to log such cases with
RATE_LIMITEDto find out how "rare" it is, or if really unlikely just return-EBUSYas in case of non-blocking send ?Quoted 1 line
Definitely not return
-EBUSYas this a blocking call. Perhaps we can logblocking calls still can fail for various reasons, full CTB is one of them, and if we return error (now broken) for non-blocking variant then we should do the same for blocking variant as well and let the caller decide about next steps
Quoted 3 lines
this, but IGTs likely can hit rather easily. It really is only interesting if real workloads hit this. Regardless that can be a follow up.
if we hide retry in a silent loop then we will not find it out if we hit this condition (IGT or real WL) or not
Quoted 64 lines
Matt
Quoted 61 lines
Quoted 61 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +12
-2+*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!h2g_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + } fence =ct_get_next_fence (ct); request.fence = fence;@@ -527,7 +589,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -569,7 +631,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -579,6 +641,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-2@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -88,7 +87,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [Intel-gfx] [PATCH 06/47] drm/i915/guc: Optimize CTB writes and reads
In reply to Michal WajdeczkoQuoted 63 lines · Michal Wajdeczko
Quoted 42 lines · Matthew Brost
CTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail) which could result in accesses across the PCIe bus, store shadow local copies and only read/write the descriptor values when absolutely necessary. Also store the current space in the each channel locally.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 ++++++++++++++--------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 51 insertions(+), 31 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3@@ -130,6 +130,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }@@ -383,10 +387,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 403
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -398,25 +400,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC since we are caching tail, we may want to check if it's sill correct:
tail = READ_ONCE(desc->tail); if (unlikely(tail != ctb->tail)) { CT_ERROR(ct, "Tail was modified %u != %u\n", tail, ctb->tail); desc->status |= GUC_CTB_STATUS_MISMATCH; goto corrupted; }and since we own the tail then we can be more strict:
Quoted 8 lines
GEM_BUG_ON(tail > size);and then finally just check GuC head:
head = READ_ONCE(desc->head); if (unlikely(head >= size)) { ...
Sure, but still hidden behind CONFIG_DRM_I915_DEBUG_GUC, right?
Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-14+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence) @@ -457,7 +448,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 453
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;this magic "1" is likely
GUC_CTB_MSG_MIN_LEN, right ?
Yes.
Quoted 43 lines
Quoted 30 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8
-5return 0 ;@@ -473,7 +466,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value. @@ -520,24 +513,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) { -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 535
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;maybe here we could mark
stall_time?
Quoted 7 lines
if (space >=
len_dw)return true; if (ct->stall_time == KTIME_MAX) ct->stall_time = ktime_get(); return false;
No. See my eariler comment [1] about why I'd rather leave this to the caller.
[1] https://patchwork.freedesktop.org/patch/440703/?series=91840&rev=1
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 537
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0return space >= len_dw;btw, maybe to avoid filling CTB to the last dword, this should be
space >
len_dw
CIRC_SPACE leaves an extra DW already.
Quoted 7 lines
note the earlier comment:
/*
* tail == head condition indicates empty. GuC FW does not support
* using up the entire buffer to get tail == head meaning full. */
Yes, again CIRC_SPACE uses this same algorithm.
Matt
Quoted 107 lines
Quoted 45 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-7}static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -606,10 +610,10 @@ static int ct_send(struct intel_guc_ct *ct,*/ retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (ct_deadlocked (ct)))return -EIO ;@@ -632,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (err)) goto unlink;@@ -720,7 +724,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 742
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -735,12 +739,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC as above we may want to check if our cached head was not modified
Quoted 40 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) { +CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;@@ -790,6 +803,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands 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 * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 48
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;in later patch this is changing to
atomic_t
maybe we can start with it ?Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-0bool broken; };
Re: [Intel-gfx] [PATCH 43/47] drm/i915/guc: Hook GuC scheduling policies up
In reply to Matthew BrostQuoted 126 lines · Matthew Brost
Quoted 125 lines · Matthew Brost
From: John Harrison <[email protected]>
Use the official driver default scheduling policies for configuring the GuC scheduler rather than a bunch of hardcoded values.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>Cc Jose Souza <[email protected]>--- drivers/gpu/drm/i915/gt/intel_engine_types.h | 1 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 2 + drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 44 ++++++++++++++++++- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 11 +++-- 4 files changed, 53 insertions(+), 5 deletions(-)drivers/gpu/drm/i915/gt/intel_engine_types.h +1
-0@@ -455,6 +455,7 @@ struct intel_engine_cs {#define I915_ENGINE_IS_VIRTUAL BIT(5)#define I915_ENGINE_HAS_RELATIVE_MMIO BIT(6)#define I915_ENGINE_REQUIRES_CMD_PARSER BIT(7) +#define I915_ENGINE_WANT_FORCED_PREEMPTION BIT(8)unsigned int flags;/* drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0@@ -270,6 +270,8 @@ int intel_guc_engine_failure_process_msg(struct intel_guc *guc,void intel_guc_find_hung_context (struct intel_engine_cs *engine); +int intel_guc_global_policies_update (struct intel_guc *guc); +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);drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +42
-2@@ -77,14 +77,54 @@ static u32 guc_ads_blob_size(struct intel_guc *guc)guc_ads_private_data_size (guc); } -static void guc_policies_init (struct guc_policies *policies) +static void guc_policies_init (struct intel_guc *guc,struct guc_policies *policies) { +struct intel_gt *gt =guc_to_gt (guc); +struct drm_i915_private *i915 = gt->i915; + policies->dpc_promote_time =GLOBAL_POLICY_DEFAULT_DPC_PROMOTE_TIME_US ; policies->max_num_work_items =GLOBAL_POLICY_MAX_NUM_WI ; + policies->global_flags =0 ; +if (i915->params.reset <2 ) + policies->global_flags |=GLOBAL_POLICY_DISABLE_ENGINE_RESET ; + policies->is_valid =1 ; } +static int guc_action_policies_update (struct intel_guc *guc,u32 policy_offset) +{ +u32 action[] = { +INTEL_GUC_ACTION_GLOBAL_SCHED_POLICY_CHANGE , + policy_offset + }; + +return intel_guc_send (guc, action,ARRAY_SIZE (action)); +} + +int intel_guc_global_policies_update (struct intel_guc *guc) +{ +struct __guc_ads_blob *blob = guc->ads_blob; +struct intel_gt *gt =guc_to_gt (guc); +intel_wakeref_t wakeref; +int ret; + +if (!blob) +return -ENOTSUPP ; + +GEM_BUG_ON (!blob->ads.scheduler_policies); + +guc_policies_init (guc, &blob->policies); + +if (!intel_guc_is_ready (guc)) +return 0 ; + +with_intel_runtime_pm (>->i915->runtime_pm, wakeref) + ret = guc_action_policies_update(guc, blob->ads.scheduler_policies); + +return ret; +} +static void guc_mapping_table_init (struct intel_gt *gt,struct guc_gt_system_info *system_info) {@@ -281,7 +321,7 @@ static void __guc_ads_init(struct intel_guc *guc)u8 engine_class, guc_class;/* GuC scheduling policies */ -guc_policies_init (&blob->policies); +guc_policies_init (guc, &blob->policies);/* * GuC expects a per-engine-class context image and size drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -873,6 +873,7 @@ void intel_guc_submission_reset_finish(struct intel_guc *guc)GEM_WARN_ON (atomic_read (&guc->outstanding_submission_g2h));atomic_set (&guc->outstanding_submission_g2h,0 ); +intel_guc_global_policies_update (guc);enable_submission (guc);intel_gt_unpark_heartbeats (guc_to_gt (guc)); }@@ -1161,8 +1162,12 @@ static void guc_context_policy_init(struct intel_engine_cs *engine, { desc->policy_flags =0 ;
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_context_policy_init(struct intel_engine_cs *engine, · line 1165
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-2- desc->execution_quantum =CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US ; - desc->preemption_timeout =CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US ; +if (engine->flags &I915_ENGINE_WANT_FORCED_PREEMPTION )I can't see where we set this in this series, although I do see a selftest we need to fixup that sets this. Perhaps we drop this until we fix that selftest? Or at minimum add a comment saying it will be used in the future by selftests. What do you think John?
Yeah, it is only ever intended to be used by selftests. So yes, it could be punted down the road until the selftest patch. Likewise the definition for the flag, too.
John.
Quoted 38 lines
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+ desc->policy_flags |=CONTEXT_POLICY_FLAG_PREEMPT_TO_IDLE ; + +/* NB: For both of these, zero means disabled. */ + desc->execution_quantum = engine->props.timeslice_duration_ms *1000 ; + desc->preemption_timeout = engine->props.preempt_timeout_ms *1000 ; }static int guc_lrc_desc_pin (struct intel_context *ce,bool loop)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void guc_default_vfuncs(struct intel_engine_cs *engine) · line 1956
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-0@@ -1945,13 +1950,13 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->set_default_submission = guc_set_default_submission; engine->flags |=I915_ENGINE_HAS_PREEMPTION ; + engine->flags |=I915_ENGINE_HAS_TIMESLICES ;/* * TODO: GuC supports timeslicing and semaphores as well, but they're Nit, we now support timeslicing. I can fix that up in next rev.
Matt
Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-1* handled by the firmware so some minor tweaks are required before * enabling. * -* engine->flags |= I915_ENGINE_HAS_TIMESLICES; * engine->flags |= I915_ENGINE_HAS_SEMAPHORES; */ Signature · 6 lines
2.28.0 _______________________________________________ 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: [PATCH 09/47] drm/i915/guc: Remove GuC stage descriptor, add lrc descriptor
In reply to Matthew BrostQuoted 5 lines · Matthew Brost
Remove old GuC stage descriptor, add lrc descriptor which will be used by the new GuC interface implemented in this patch series.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH 06/47] drm/i915/guc: Optimize CTB writes and reads
In reply to Michal WajdeczkoQuoted 10 lines · Michal Wajdeczko
Quoted 7 lines · Matthew Brost
CTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail) which could result in accesses across the PCIe bus, store shadow local copies and only read/write the descriptor values when absolutely necessary. Also store the current space in the each channel locally.
Missed two comments, addressed below.
Quoted 207 lines
Quoted 35 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 76 ++++++++++++++--------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 51 insertions(+), 31 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3@@ -130,6 +130,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }@@ -383,10 +387,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 403
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -398,25 +400,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC since we are caching tail, we may want to check if it's sill correct:
tail = READ_ONCE(desc->tail); if (unlikely(tail != ctb->tail)) { CT_ERROR(ct, "Tail was modified %u != %u\n", tail, ctb->tail); desc->status |= GUC_CTB_STATUS_MISMATCH; goto corrupted; }and since we own the tail then we can be more strict:
GEM_BUG_ON(tail > size);and then finally just check GuC head:
head = READ_ONCE(desc->head); if (unlikely(head >= size)) { ...Quoted 25 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-14+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence) drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 453
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0@@ -457,7 +448,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;this magic "1" is likely
GUC_CTB_MSG_MIN_LEN, right ?Quoted 30 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8
-5return 0 ;@@ -473,7 +466,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value. @@ -520,24 +513,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool h2g_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) { -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 535
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;maybe here we could mark
stall_time?if (space >=
len_dw)return true; if (ct->stall_time == KTIME_MAX) ct->stall_time = ktime_get(); return false;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 537
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0return space >= len_dw;btw, maybe to avoid filling CTB to the last dword, this should be
space >
len_dwnote the earlier comment:
/*
* tail == head condition indicates empty. GuC FW does not support
* using up the entire buffer to get tail == head meaning full. */Quoted 48 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-7}static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!h2g_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -606,10 +610,10 @@ static int ct_send(struct intel_guc_ct *ct,*/ retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!h2g_has_room (ctb, len +1 ))) { +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (ct_deadlocked (ct)))return -EIO ;@@ -632,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (err)) goto unlink;@@ -720,7 +724,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;@@ -735,12 +739,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted;
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 742
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1-if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC as above we may want to check if our cached head was not modified
Sure.
Quoted 41 lines
Quoted 41 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) { +CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;@@ -790,6 +803,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands 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 * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 48
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;in later patch this is changing to
atomic_t
maybe we can start with it ?
I'd rather leave this as is. It doesn't make to use an atomic here but G2H credits patch makes it clear why we need an atomic.
Matt
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 51
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-0bool broken; };
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 08/47] drm/i915/guc: Add new GuC interface defines and structures
In reply to Matthew BrostQuoted 5 lines · Matthew Brost
Add new GuC interface defines and structures while maintaining old ones in parallel.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>
I think there was some difference of opinion over whether these additions should be squashed in to the specific patches that first use them. However, on the grounds that such is basically a patch-only style comment and doesn't change the final product plus, we need to get this stuff merged efficiently and not spend forever rebasing and refactoring...
Quoted 90 lines
--- .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h | 14 +++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+)drivers/gpu/drm/i915/gt/uc/abi/guc_actions_abi.h +14
-0@@ -124,10 +124,24 @@ enum intel_guc_action {INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH =0x302 ,INTEL_GUC_ACTION_ENTER_S_STATE =0x501 ,INTEL_GUC_ACTION_EXIT_S_STATE =0x502 , +INTEL_GUC_ACTION_GLOBAL_SCHED_POLICY_CHANGE =0x506 , +INTEL_GUC_ACTION_SCHED_CONTEXT =0x1000 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET =0x1001 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE =0x1002 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_SET =0x1003 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_DONE =0x1004 , +INTEL_GUC_ACTION_SET_CONTEXT_PRIORITY =0x1005 , +INTEL_GUC_ACTION_SET_CONTEXT_EXECUTION_QUANTUM =0x1006 , +INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT =0x1007 , +INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION =0x1008 , +INTEL_GUC_ACTION_ENGINE_FAILURE_NOTIFICATION =0x1009 ,INTEL_GUC_ACTION_SLPC_REQUEST =0x3003 ,INTEL_GUC_ACTION_AUTHENTICATE_HUC =0x4000 , +INTEL_GUC_ACTION_REGISTER_CONTEXT =0x4502 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT =0x4503 ,INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER =0x4505 ,INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER =0x4506 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE =0x4600 ,INTEL_GUC_ACTION_LIMIT };drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +34
-0@@ -17,6 +17,9 @@#include "abi/guc_communication_ctb_abi.h" #include "abi/guc_messages_abi.h" +#define GUC_CONTEXT_DISABLE 0 +#define GUC_CONTEXT_ENABLE 1 +#define GUC_CLIENT_PRIORITY_KMD_HIGH 0#define GUC_CLIENT_PRIORITY_HIGH 1#define GUC_CLIENT_PRIORITY_KMD_NORMAL 2@@ -26,6 +29,9 @@#define GUC_MAX_STAGE_DESCRIPTORS 1024#define GUC_INVALID_STAGE_ID GUC_MAX_STAGE_DESCRIPTORS +#define GUC_MAX_LRC_DESCRIPTORS 65535 +#define GUC_INVALID_LRC_ID GUC_MAX_LRC_DESCRIPTORS +#define GUC_RENDER_ENGINE 0#define GUC_VIDEO_ENGINE 1#define GUC_BLITTER_ENGINE 2@@ -237,6 +243,41 @@ struct guc_stage_desc {u64 desc_private; } __packed; +#define CONTEXT_REGISTRATION_FLAG_KMD BIT(0) + +#define CONTEXT_POLICY_DEFAULT_EXECUTION_QUANTUM_US 1000000 +#define CONTEXT_POLICY_DEFAULT_PREEMPTION_TIME_US 500000 + +/* Preempt to idle on quantum expiry */ +#define CONTEXT_POLICY_FLAG_PREEMPT_TO_IDLE BIT(0) + +/* +* GuC Context registration descriptor. +* FIXME: This is only required to exist during context registration. +* The current 1:1 between guc_lrc_desc and LRCs for the lifetime of the LRC +* is not required. +*/ +struct guc_lrc_desc { +u32 hw_context_desc; +u32 slpm_perf_mode_hint;/* SPLC v1 only */ +u32 slpm_freq_hint; +u32 engine_submit_mask;/* In logical space */ +u8 engine_class; +u8 reserved0[3 ]; +u32 priority; +u32 process_desc; +u32 wq_addr; +u32 wq_size; +u32 context_flags;/* CONTEXT_REGISTRATION_* */ +/* Time for one workload to execute. (in micro seconds) */ +u32 execution_quantum;
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h struct guc_stage_desc { · line 283
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +7
-0+/* Time to wait for a preemption request to complete before issuing a +* reset. (in micro seconds). */ +u32 preemption_timeout; +u32 policy_flags;/* CONTEXT_POLICY_* */ +u32 reserved1[19 ]; +} __packed; +#define GUC_POWER_UNSPECIFIED 0#define GUC_POWER_D0 1#define GUC_POWER_D1 2
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
John Harrison
Reviewed-byRe: [PATCH 10/47] drm/i915/guc: Add lrc descriptor context lookup array
In reply to Matthew BrostQuoted 11 lines · Matthew Brost
Quoted 8 lines · Michal Wajdeczko
Quoted 5 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.s/lrc/LRC
I guess? lrc and LRC are used interchangeably throughout the current code base.
It is an abbreviation so LRC is technically the correct version for a comment. The fact that other existing comments are incorrect is not a valid reason to perpetuate a mistake :). Might as well fix it if you are going to repost the patch anyway for any other reason, but I would not call it a blocking issue.
Also, 'can determine in the' should be 'can determine if the'. Again, not exactly a blocking issue but should be fixed.
Quoted 36 lines
Quoted 15 lines
Quoted 15 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h line 9
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+#include "linux/xarray.h" #include <
linux/xarray.h>Yep.
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h" @@ -46,6 +48,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr;Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 55
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +3
-0+/* guc_id to intel_context lookup */ +struct xarray context_lookup; +/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];btw, IIRC there was idea to move most struct definitions to
intel_guc_types.h, is this still a plan ?
Quoted 5 lines
I don't ever recall discussing this but we can certainly do this. For what it is worth we do introduce
intel_guc_submission_types.ha bit later. I'll make a note aboutintel_guc_types.hthough.Matt
Yeah, my only recollection was about the submission types header. Are there sufficient non-submission fields in the GuC structure to warrant a general GuC types header?
With the commit message tweaks and #include fix mentioned above, it looks good to me.
Quoted 60 lines
Quoted 60 lines
Quoted 60 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +28
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, 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 ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */ @@ -400,6 +426,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool);
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c int intel_guc_submission_init(struct intel_guc *guc) · line 433
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx