Parallel submission aka multi-bb execbuf
Subsystems (4)
Re: [PATCH 19/46] drm/i915/guc: Assign contexts in parent-child relationship consecutive guc_ids
In reply to Daniel VetterQuoted 85 lines · Daniel Vetter
Quoted 70 lines · Matthew Brost
Assign contexts in parent-child relationship consecutive
guc_ids. This is accomplished by partitioningguc_idspace between ones that need to be consecutive (1/16 availableguc_ids) and ones that do not (15/16 of availableguc_ids). The consecutive search is implemented via the bitmap API.This is a precursor to the full GuC multi-lrc implementation but aligns to how GuC mutli-lrc interface is defined -
guc_idsmust be consecutive when using the GuC multi-lrc interface.Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.h | 6 + drivers/gpu/drm/i915/gt/intel_reset.c | 3 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 7 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 222 ++++++++++++------ .../i915/gt/uc/intel_guc_submission_types.h | 10 + 5 files changed, 179 insertions(+), 69 deletions(-)drivers/gpu/drm/i915/gt/intel_context.h +6
-0@@ -54,6 +54,12 @@ static inline bool intel_context_is_parent(struct intel_context *ce)return !!ce->guc_number_children; } +static inline struct intel_context * +intel_context_to_parent (struct intel_context *ce) +{ +return intel_context_is_child (ce) ? ce->parent : ce; +} +void intel_context_bind_parent_child (struct intel_context *parent,struct intel_context *child);drivers/gpu/drm/i915/gt/intel_reset.c +2
-1@@ -849,6 +849,7 @@ static void reset_finish(struct intel_gt *gt, intel_engine_mask_t awake)static void nop_submit_request (struct i915_request *request) { +struct intel_context *ce =intel_context_to_parent (request->context);RQ_TRACE (request,"-EIO\n" );/* @@ -857,7 +858,7 @@ static void nop_submit_request(struct i915_request *request)* this for now. */ if (intel_engine_uses_guc (request->engine)) -intel_guc_decr_num_rq_not_ready (request->context); +intel_guc_decr_num_rq_not_ready (ce); request =i915_request_mark_eio (request);if (request) {drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0@@ -24,6 +24,7 @@ struct __guc_ads_blob;enum {GUC_SUBMIT_ENGINE_SINGLE_LRC , +GUC_SUBMIT_ENGINE_MULTI_LRC ,GUC_SUBMIT_ENGINE_MAX };drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 66
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-2@@ -59,8 +60,10 @@ struct intel_guc {struct ida guc_ids;u32 num_guc_ids;u32 max_guc_ids; -struct list_head guc_id_list_no_ref; -struct list_head guc_id_list_unpinned; +unsigned long *guc_ids_bitmap; +#define MAX_GUC_ID_ORDER (order_base_2(MAX_ENGINE_INSTANCE + 1)) +struct list_head guc_id_list_no_ref[MAX_GUC_ID_ORDER +1 ]; +struct list_head guc_id_list_unpinned[MAX_GUC_ID_ORDER +1 ];Random new global lists definitely need kerneldoc about what is on them, how they're linked, what their lifetime rules are and what locks we're holding.
Quoted 3 lines
Leaving this all to reviews to figure out, and worse, future readers of your code, is not kind.
Got it.
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0spinlock_t destroy_lock;/* protects list / worker */ struct list_head destroyed_contexts;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -169,6 +169,15 @@ static void clr_guc_ids_exhausted(struct guc_submit_engine *gse)clear_bit (GSE_STATE_GUC_IDS_EXHAUSTED , &gse->flags); }
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void clr_guc_ids_exhausted(struct guc_submit_engine *gse) · line 173
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+/* +* We reserve 1/16 of the guc_ids for multi-lrc as these need to be contiguous I think it'd be good to put down the reason here for why. Is this a requirement of the guc interface, or just an artifact of our current implementation? In the latter case also explain what exactly the contstraint is (but honestly I can't think of much reasons for that)
Multi-lrc guc_ids need to be sequential between the parent and children
- this is a requirement of the GuC submission interface. Can explicitly state that here.
Matt
Quoted 407 lines
-Daniel
Quoted 400 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +154
-66+* and a different allocation algorithm is used (bitmap vs. ida). We believe the +* number of multi-lrc contexts in use should be low and 1/16 should be +* sufficient. Minimum of 32 ids for multi-lrc. +*/ +#define NUMBER_MULTI_LRC_GUC_ID (guc) \ + ((guc)->num_guc_ids / 16 > 32 ? (guc)->num_guc_ids / 16 : 32) +/* * Below is a set of functions which control the GuC scheduling state which do * not require a lock as all state transitions are mutually exclusive. i.e. It @@ -405,16 +414,10 @@ static inline void decr_context_blocked(struct intel_context *ce) ce->guc_state.sched_state -=SCHED_STATE_BLOCKED ; } -static inline struct intel_context * -to_parent (struct intel_context *ce) -{ -return intel_context_is_child (ce) ? ce->parent : ce; -} -static inline struct intel_context *request_to_scheduling_context (struct i915_request *rq) { -return to_parent (rq->context); +return intel_context_to_parent (rq->context); }static inline bool context_guc_id_invalid (struct intel_context *ce)@@ -1436,7 +1439,7 @@ static void destroy_worker_func(struct work_struct *w);*/ int intel_guc_submission_init (struct intel_guc *guc) { -int ret; +int ret, i;if (guc_submission_initialized (guc))return 0 ;@@ -1448,9 +1451,13 @@ 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_no_ref); -INIT_LIST_HEAD (&guc->guc_id_list_unpinned); +for (i =0 ; i <MAX_GUC_ID_ORDER +1 ; ++i) { +INIT_LIST_HEAD (&guc->guc_id_list_no_ref[i]); +INIT_LIST_HEAD (&guc->guc_id_list_unpinned[i]); + }ida_init (&guc->guc_ids); + guc->guc_ids_bitmap = +bitmap_zalloc (NUMBER_MULTI_LRC_GUC_ID (guc),GFP_KERNEL );spin_lock_init (&guc->destroy_lock);@@ -1476,6 +1483,8 @@ void intel_guc_submission_fini(struct intel_guc *guc)i915_sched_engine_put (sched_engine); } + +bitmap_free (guc->guc_ids_bitmap); } static inline void queue_request(struct i915_sched_engine *sched_engine,@@ -1499,11 +1508,13 @@ static inline void queue_request(struct i915_sched_engine *sched_engine,static bool too_many_guc_ids_not_ready (struct guc_submit_engine *gse,struct intel_context *ce) { -u32 available_guc_ids, guc_ids_consumed;struct intel_guc *guc = gse->sched_engine.private_data; +u32 available_guc_ids =intel_context_is_parent (ce) ? +NUMBER_MULTI_LRC_GUC_ID (guc) : + guc->num_guc_ids -NUMBER_MULTI_LRC_GUC_ID (guc); +u32 guc_ids_consumed =atomic_read (&gse->num_guc_ids_not_ready); - available_guc_ids = guc->num_guc_ids; - guc_ids_consumed =atomic_read (&gse->num_guc_ids_not_ready); +GEM_BUG_ON (intel_context_is_child (ce));if (TOO_MANY_GUC_IDS_NOT_READY (available_guc_ids, guc_ids_consumed)) {set_and_update_guc_ids_exhausted (gse);@@ -1517,17 +1528,26 @@ static void incr_num_rq_not_ready(struct intel_context *ce) {struct guc_submit_engine *gse =ce_to_gse (ce); +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!intel_context_is_parent (ce) && + ce->guc_number_children); +if (!atomic_fetch_add (1 , &ce->guc_num_rq_not_ready)) -atomic_inc (&gse->num_guc_ids_not_ready); +atomic_add (ce->guc_number_children +1 , + &gse->num_guc_ids_not_ready); }void intel_guc_decr_num_rq_not_ready (struct intel_context *ce) {struct guc_submit_engine *gse =ce_to_gse (ce); +GEM_BUG_ON (intel_context_is_child (ce)); +if (atomic_fetch_add (-1 , &ce->guc_num_rq_not_ready) ==1 ) {GEM_BUG_ON (!atomic_read (&gse->num_guc_ids_not_ready)); -atomic_dec (&gse->num_guc_ids_not_ready); + +atomic_sub (ce->guc_number_children +1 , + &gse->num_guc_ids_not_ready); } }@@ -1579,20 +1599,42 @@ static void guc_submit_request(struct i915_request *rq)spin_unlock_irqrestore (&sched_engine->lock, flags); -intel_guc_decr_num_rq_not_ready (rq->context); +intel_guc_decr_num_rq_not_ready (request_to_scheduling_context (rq)); } -static int new_guc_id (struct intel_guc *guc) +static int new_guc_id (struct intel_guc *guc,struct intel_context *ce) { -return ida_simple_get (&guc->guc_ids,0 , - guc->num_guc_ids,GFP_KERNEL | - __GFP_RETRY_MAYFAIL | __GFP_NOWARN); +int ret; + +GEM_BUG_ON (intel_context_is_child (ce)); + +if (intel_context_is_parent (ce)) + ret =bitmap_find_free_region (guc->guc_ids_bitmap, +NUMBER_MULTI_LRC_GUC_ID (guc), +order_base_2 (ce->guc_number_children + +1 )); +else + ret =ida_simple_get (&guc->guc_ids, +NUMBER_MULTI_LRC_GUC_ID (guc), + guc->num_guc_ids,GFP_KERNEL | + __GFP_RETRY_MAYFAIL | __GFP_NOWARN); +if (unlikely (ret <0 )) +return ret; + + ce->guc_id = ret; +return 0 ; }static void __release_guc_id (struct intel_guc *guc,struct intel_context *ce) { +GEM_BUG_ON (intel_context_is_child (ce));if (!context_guc_id_invalid (ce)) { -ida_simple_remove (&guc->guc_ids, ce->guc_id); +if (intel_context_is_parent (ce)) +bitmap_release_region (guc->guc_ids_bitmap, ce->guc_id, +order_base_2 (ce->guc_number_children + +1 )); +else +ida_simple_remove (&guc->guc_ids, ce->guc_id);clr_lrc_desc_registered (guc, ce->guc_id);set_context_guc_id_invalid (ce); }@@ -1604,6 +1646,8 @@ static void release_guc_id(struct intel_guc *guc, struct intel_context *ce) {unsigned long flags; +GEM_BUG_ON (intel_context_is_child (ce)); +spin_lock_irqsave (&guc->contexts_lock, flags);__release_guc_id (guc, ce);spin_unlock_irqrestore (&guc->contexts_lock, flags);@@ -1618,54 +1662,93 @@ static void release_guc_id(struct intel_guc *guc, struct intel_context *ce)* schedule disable H2G + a deregister H2G. */ static struct list_head *get_guc_id_list (struct intel_guc *guc, +u8 number_children,bool unpinned) { +GEM_BUG_ON (order_base_2 (number_children +1 ) >MAX_GUC_ID_ORDER ); +if (unpinned) -return &guc->guc_id_list_unpinned; +return &guc->guc_id_list_unpinned[order_base_2 (number_children +1 )];else -return &guc->guc_id_list_no_ref; +return &guc->guc_id_list_no_ref[order_base_2 (number_children +1 )]; } -static int steal_guc_id (struct intel_guc *guc,bool unpinned) +static int steal_guc_id (struct intel_guc *guc,struct intel_context *ce, +bool unpinned) { -struct intel_context *ce; -int guc_id; -struct list_head *guc_id_list =get_guc_id_list (guc, unpinned); +struct intel_context *cn; +u8 number_children = ce->guc_number_children;lockdep_assert_held (&guc->contexts_lock); +GEM_BUG_ON (intel_context_is_child (ce)); -if (!list_empty (guc_id_list)) { - ce =list_first_entry (guc_id_list, - struct intel_context, - guc_id_link); +do { +struct list_head *guc_id_list = +get_guc_id_list (guc, number_children, unpinned); -/* Ensure context getting stolen in expected state */ -GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); -GEM_BUG_ON (context_guc_id_invalid (ce)); -GEM_BUG_ON (context_guc_id_stolen (ce)); +if (!list_empty (guc_id_list)) { +u8 cn_o2, ce_o2 = +order_base_2 (ce->guc_number_children +1 ); -list_del_init (&ce->guc_id_link); - guc_id = ce->guc_id; -clr_context_registered (ce); + cn =list_first_entry (guc_id_list, + struct intel_context, + guc_id_link); + cn_o2 =order_base_2 (cn->guc_number_children +1 ); + +/* +* Corner case where a multi-lrc context steals a guc_id +* from another context that has more guc_id that itself. +*/ +if (cn_o2 != ce_o2) { +bitmap_release_region (guc->guc_ids_bitmap, + cn->guc_id, + cn_o2); +bitmap_allocate_region (guc->guc_ids_bitmap, + ce->guc_id, + ce_o2); + } + +/* Ensure context getting stolen in expected state */ +GEM_BUG_ON (atomic_read (&cn->guc_id_ref)); +GEM_BUG_ON (context_guc_id_invalid (cn)); +GEM_BUG_ON (context_guc_id_stolen (cn)); +GEM_BUG_ON (ce_to_gse (ce) !=ce_to_gse (cn)); + +list_del_init (&cn->guc_id_link); + ce->guc_id = cn->guc_id; + +/* +* If stealing from the pinned list, defer invalidating +* the guc_id until the retire workqueue processes this +* context. +*/ +clr_context_registered (cn); +if (!unpinned) { +GEM_BUG_ON (ce_to_gse (cn)->stalled_context); +ce_to_gse (cn)->stalled_context = +intel_context_get (cn); +set_context_guc_id_stolen (cn); + }else { +set_context_guc_id_invalid (cn); + } + +return 0 ; + }/* -* If stealing from the pinned list, defer invalidating -* the guc_id until the retire workqueue processes this -* context. +* When using multi-lrc we search the guc_id_lists with the +* least amount of guc_ids required first but will consume a +* block larger of guc_ids if necessary. 2x the children always +* moves you two the next list. */ -if (!unpinned) { -GEM_BUG_ON (ce_to_gse (ce)->stalled_context); +if (!number_children || +order_base_2 (number_children +1 ) ==MAX_GUC_ID_ORDER ) +break ; -ce_to_gse (ce)->stalled_context =intel_context_get (ce); -set_context_guc_id_stolen (ce); - }else { -set_context_guc_id_invalid (ce); - } + number_children *=2 ; + }while (true); -return guc_id; - }else { -return -EAGAIN ; - } +return -EAGAIN ; }enum {/* Return values for pin_guc_id / assign_guc_id */ @@ -1674,17 +1757,18 @@ enum { /* Return values for pin_guc_id / assign_guc_id */ NEW_GUC_ID_ENABLED = 2, }; -static int assign_guc_id (struct intel_guc *guc,u16 *out,bool tasklet) +static int assign_guc_id (struct intel_guc *guc,struct intel_context *ce, +bool tasklet) {int ret;lockdep_assert_held (&guc->contexts_lock); +GEM_BUG_ON (intel_context_is_child (ce)); - ret =new_guc_id (guc); + ret =new_guc_id (guc, ce);if (unlikely (ret <0 )) { - ret =steal_guc_id (guc, true); -if (ret >=0 ) { - *out = ret; + ret =steal_guc_id (guc, ce, true); +if (!ret) { ret =NEW_GUC_ID_DISABLED ; }else if (ret <0 && tasklet) {/* @@ -1692,15 +1776,18 @@ static int assign_guc_id(struct intel_guc *guc, u16 *out, bool tasklet)* enabled if guc_ids are exhausted and we are submitting * from the tasklet. */ - ret =steal_guc_id (guc, false); -if (ret >=0 ) { - *out = ret; + ret =steal_guc_id (guc, ce, false); +if (!ret) ret =NEW_GUC_ID_ENABLED ; - } } - }else { - *out = ret; - ret =SAME_GUC_ID ; + } + +if (!(ret <0 ) &&intel_context_is_parent (ce)) { +struct intel_context *child; +int i =1 ; + +for_each_child (ce, child) + child->guc_id = ce->guc_id + i++; }return ret;@@ -1713,6 +1800,7 @@ 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 (intel_context_is_child (ce));GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); try_again:@@ -1724,7 +1812,7 @@ static int pin_guc_id(struct intel_guc *guc, struct intel_context *ce, }if (context_guc_id_invalid (ce)) { - ret =assign_guc_id (guc, &ce->guc_id, tasklet); + ret =assign_guc_id (guc, ce, tasklet);if (unlikely (ret <0 )) goto out_unlock; }@@ -1770,6 +1858,7 @@ static void unpin_guc_id(struct intel_guc *guc,unsigned long flags;GEM_BUG_ON (atomic_read (&ce->guc_id_ref) <0 ); +GEM_BUG_ON (intel_context_is_child (ce));if (unlikely (context_guc_id_invalid (ce)))return ;@@ -1781,7 +1870,8 @@ static void unpin_guc_id(struct intel_guc *guc,if (!context_guc_id_invalid (ce) && !context_guc_id_stolen (ce) && !atomic_read (&ce->guc_id_ref)) { -struct list_head *head =get_guc_id_list (guc, unpinned); +struct list_head *head = +get_guc_id_list (guc, ce->guc_number_children, unpinned);list_add_tail (&ce->guc_id_link, head); }drivers/gpu/drm/i915/gt/uc/intel_guc_submission_types.h +10
-0@@ -22,6 +22,16 @@ struct guc_virtual_engine {/* * Object which encapsulates the globally operated on i915_sched_engine + * the GuC submission state machine described in intel_guc_submission.c. +* +* Currently we have two instances of these per GuC. One for single-lrc and one +* for multi-lrc submission. We split these into two submission engines as they +* can operate in parallel allowing a blocking condition on one not to affect +* the other. i.e. guc_ids are statically allocated between these two submission +* modes. One mode may have guc_ids exhausted which requires blocking while the +* other has plenty of guc_ids and can make forward progres. +* +* In the future if different submission use cases arise we can simply +* instantiate another of these objects and assign it to the context. */ struct guc_submit_engine {struct i915_sched_engine sched_engine;Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 19/46] drm/i915/guc: Assign contexts in parent-child relationship consecutive guc_ids
Quoted 86 lines · Matthew Brost
Quoted 85 lines · Daniel Vetter
Quoted 70 lines · Matthew Brost
Assign contexts in parent-child relationship consecutive
guc_ids. This is accomplished by partitioningguc_idspace between ones that need to be consecutive (1/16 availableguc_ids) and ones that do not (15/16 of availableguc_ids). The consecutive search is implemented via the bitmap API.This is a precursor to the full GuC multi-lrc implementation but aligns to how GuC mutli-lrc interface is defined -
guc_idsmust be consecutive when using the GuC multi-lrc interface.Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.h | 6 + drivers/gpu/drm/i915/gt/intel_reset.c | 3 +- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 7 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 222 ++++++++++++------ .../i915/gt/uc/intel_guc_submission_types.h | 10 + 5 files changed, 179 insertions(+), 69 deletions(-)drivers/gpu/drm/i915/gt/intel_context.h +6
-0@@ -54,6 +54,12 @@ static inline bool intel_context_is_parent(struct intel_context *ce)return !!ce->guc_number_children; } +static inline struct intel_context * +intel_context_to_parent (struct intel_context *ce) +{ +return intel_context_is_child (ce) ? ce->parent : ce; +} +void intel_context_bind_parent_child (struct intel_context *parent,struct intel_context *child);drivers/gpu/drm/i915/gt/intel_reset.c +2
-1@@ -849,6 +849,7 @@ static void reset_finish(struct intel_gt *gt, intel_engine_mask_t awake)static void nop_submit_request (struct i915_request *request) { +struct intel_context *ce =intel_context_to_parent (request->context);RQ_TRACE (request,"-EIO\n" );/* @@ -857,7 +858,7 @@ static void nop_submit_request(struct i915_request *request)* this for now. */ if (intel_engine_uses_guc (request->engine)) -intel_guc_decr_num_rq_not_ready (request->context); +intel_guc_decr_num_rq_not_ready (ce); request =i915_request_mark_eio (request);if (request) {drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0@@ -24,6 +24,7 @@ struct __guc_ads_blob;enum {GUC_SUBMIT_ENGINE_SINGLE_LRC , +GUC_SUBMIT_ENGINE_MULTI_LRC ,GUC_SUBMIT_ENGINE_MAX };drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 66
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4
-2@@ -59,8 +60,10 @@ struct intel_guc {struct ida guc_ids;u32 num_guc_ids;u32 max_guc_ids; -struct list_head guc_id_list_no_ref; -struct list_head guc_id_list_unpinned; +unsigned long *guc_ids_bitmap; +#define MAX_GUC_ID_ORDER (order_base_2(MAX_ENGINE_INSTANCE + 1)) +struct list_head guc_id_list_no_ref[MAX_GUC_ID_ORDER +1 ]; +struct list_head guc_id_list_unpinned[MAX_GUC_ID_ORDER +1 ];Random new global lists definitely need kerneldoc about what is on them, how they're linked, what their lifetime rules are and what locks we're holding.
Quoted 5 lines
Quoted 3 lines
Leaving this all to reviews to figure out, and worse, future readers of your code, is not kind.
Got it.
I forgot the usual disclaimer: I know that the current code isn't following this at all. But wee have to start somewhere :-/
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +0
-0spinlock_t destroy_lock;/* protects list / worker */ struct list_head destroyed_contexts;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -169,6 +169,15 @@ static void clr_guc_ids_exhausted(struct guc_submit_engine *gse)clear_bit (GSE_STATE_GUC_IDS_EXHAUSTED , &gse->flags); }Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void clr_guc_ids_exhausted(struct guc_submit_engine *gse) · line 173
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+/* +* We reserve 1/16 of the guc_ids for multi-lrc as these need to be contiguous I think it'd be good to put down the reason here for why. Is this a requirement of the guc interface, or just an artifact of our current implementation? In the latter case also explain what exactly the contstraint is (but honestly I can't think of much reasons for that)
Quoted 3 lines
Multi-lrc
guc_idsneed to be sequential between the parent and children
- this is a requirement of the GuC submission interface. Can explicitly state that here.
Ah yes that makes sense to document. That also gives us a very clear hint what probably the first step to fix any multi-lrc exhaustion issues are:
We need to scan the entire guc_id space for conseutively free spots are. Not sure xarray has support for that, but I know the guy who wrote it so the answer is at most a mail away :-)
This also means I'm a lot less worried about potentially walling ourselves into a corner with multi-lrc guc_id exhaustion. Might be good to note that in the commit message too.
-Daniel
Quoted 410 lines
Matt
Quoted 407 lines
-Daniel
Quoted 400 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +154
-66+* and a different allocation algorithm is used (bitmap vs. ida). We believe the +* number of multi-lrc contexts in use should be low and 1/16 should be +* sufficient. Minimum of 32 ids for multi-lrc. +*/ +#define NUMBER_MULTI_LRC_GUC_ID (guc) \ + ((guc)->num_guc_ids / 16 > 32 ? (guc)->num_guc_ids / 16 : 32) +/* * Below is a set of functions which control the GuC scheduling state which do * not require a lock as all state transitions are mutually exclusive. i.e. It @@ -405,16 +414,10 @@ static inline void decr_context_blocked(struct intel_context *ce) ce->guc_state.sched_state -=SCHED_STATE_BLOCKED ; } -static inline struct intel_context * -to_parent (struct intel_context *ce) -{ -return intel_context_is_child (ce) ? ce->parent : ce; -} -static inline struct intel_context *request_to_scheduling_context (struct i915_request *rq) { -return to_parent (rq->context); +return intel_context_to_parent (rq->context); }static inline bool context_guc_id_invalid (struct intel_context *ce)@@ -1436,7 +1439,7 @@ static void destroy_worker_func(struct work_struct *w);*/ int intel_guc_submission_init (struct intel_guc *guc) { -int ret; +int ret, i;if (guc_submission_initialized (guc))return 0 ;@@ -1448,9 +1451,13 @@ 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_no_ref); -INIT_LIST_HEAD (&guc->guc_id_list_unpinned); +for (i =0 ; i <MAX_GUC_ID_ORDER +1 ; ++i) { +INIT_LIST_HEAD (&guc->guc_id_list_no_ref[i]); +INIT_LIST_HEAD (&guc->guc_id_list_unpinned[i]); + }ida_init (&guc->guc_ids); + guc->guc_ids_bitmap = +bitmap_zalloc (NUMBER_MULTI_LRC_GUC_ID (guc),GFP_KERNEL );spin_lock_init (&guc->destroy_lock);@@ -1476,6 +1483,8 @@ void intel_guc_submission_fini(struct intel_guc *guc)i915_sched_engine_put (sched_engine); } + +bitmap_free (guc->guc_ids_bitmap); } static inline void queue_request(struct i915_sched_engine *sched_engine,@@ -1499,11 +1508,13 @@ static inline void queue_request(struct i915_sched_engine *sched_engine,static bool too_many_guc_ids_not_ready (struct guc_submit_engine *gse,struct intel_context *ce) { -u32 available_guc_ids, guc_ids_consumed;struct intel_guc *guc = gse->sched_engine.private_data; +u32 available_guc_ids =intel_context_is_parent (ce) ? +NUMBER_MULTI_LRC_GUC_ID (guc) : + guc->num_guc_ids -NUMBER_MULTI_LRC_GUC_ID (guc); +u32 guc_ids_consumed =atomic_read (&gse->num_guc_ids_not_ready); - available_guc_ids = guc->num_guc_ids; - guc_ids_consumed =atomic_read (&gse->num_guc_ids_not_ready); +GEM_BUG_ON (intel_context_is_child (ce));if (TOO_MANY_GUC_IDS_NOT_READY (available_guc_ids, guc_ids_consumed)) {set_and_update_guc_ids_exhausted (gse);@@ -1517,17 +1528,26 @@ static void incr_num_rq_not_ready(struct intel_context *ce) {struct guc_submit_engine *gse =ce_to_gse (ce); +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!intel_context_is_parent (ce) && + ce->guc_number_children); +if (!atomic_fetch_add (1 , &ce->guc_num_rq_not_ready)) -atomic_inc (&gse->num_guc_ids_not_ready); +atomic_add (ce->guc_number_children +1 , + &gse->num_guc_ids_not_ready); }void intel_guc_decr_num_rq_not_ready (struct intel_context *ce) {struct guc_submit_engine *gse =ce_to_gse (ce); +GEM_BUG_ON (intel_context_is_child (ce)); +if (atomic_fetch_add (-1 , &ce->guc_num_rq_not_ready) ==1 ) {GEM_BUG_ON (!atomic_read (&gse->num_guc_ids_not_ready)); -atomic_dec (&gse->num_guc_ids_not_ready); + +atomic_sub (ce->guc_number_children +1 , + &gse->num_guc_ids_not_ready); } }@@ -1579,20 +1599,42 @@ static void guc_submit_request(struct i915_request *rq)spin_unlock_irqrestore (&sched_engine->lock, flags); -intel_guc_decr_num_rq_not_ready (rq->context); +intel_guc_decr_num_rq_not_ready (request_to_scheduling_context (rq)); } -static int new_guc_id (struct intel_guc *guc) +static int new_guc_id (struct intel_guc *guc,struct intel_context *ce) { -return ida_simple_get (&guc->guc_ids,0 , - guc->num_guc_ids,GFP_KERNEL | - __GFP_RETRY_MAYFAIL | __GFP_NOWARN); +int ret; + +GEM_BUG_ON (intel_context_is_child (ce)); + +if (intel_context_is_parent (ce)) + ret =bitmap_find_free_region (guc->guc_ids_bitmap, +NUMBER_MULTI_LRC_GUC_ID (guc), +order_base_2 (ce->guc_number_children + +1 )); +else + ret =ida_simple_get (&guc->guc_ids, +NUMBER_MULTI_LRC_GUC_ID (guc), + guc->num_guc_ids,GFP_KERNEL | + __GFP_RETRY_MAYFAIL | __GFP_NOWARN); +if (unlikely (ret <0 )) +return ret; + + ce->guc_id = ret; +return 0 ; }static void __release_guc_id (struct intel_guc *guc,struct intel_context *ce) { +GEM_BUG_ON (intel_context_is_child (ce));if (!context_guc_id_invalid (ce)) { -ida_simple_remove (&guc->guc_ids, ce->guc_id); +if (intel_context_is_parent (ce)) +bitmap_release_region (guc->guc_ids_bitmap, ce->guc_id, +order_base_2 (ce->guc_number_children + +1 )); +else +ida_simple_remove (&guc->guc_ids, ce->guc_id);clr_lrc_desc_registered (guc, ce->guc_id);set_context_guc_id_invalid (ce); }@@ -1604,6 +1646,8 @@ static void release_guc_id(struct intel_guc *guc, struct intel_context *ce) {unsigned long flags; +GEM_BUG_ON (intel_context_is_child (ce)); +spin_lock_irqsave (&guc->contexts_lock, flags);__release_guc_id (guc, ce);spin_unlock_irqrestore (&guc->contexts_lock, flags);@@ -1618,54 +1662,93 @@ static void release_guc_id(struct intel_guc *guc, struct intel_context *ce)* schedule disable H2G + a deregister H2G. */ static struct list_head *get_guc_id_list (struct intel_guc *guc, +u8 number_children,bool unpinned) { +GEM_BUG_ON (order_base_2 (number_children +1 ) >MAX_GUC_ID_ORDER ); +if (unpinned) -return &guc->guc_id_list_unpinned; +return &guc->guc_id_list_unpinned[order_base_2 (number_children +1 )];else -return &guc->guc_id_list_no_ref; +return &guc->guc_id_list_no_ref[order_base_2 (number_children +1 )]; } -static int steal_guc_id (struct intel_guc *guc,bool unpinned) +static int steal_guc_id (struct intel_guc *guc,struct intel_context *ce, +bool unpinned) { -struct intel_context *ce; -int guc_id; -struct list_head *guc_id_list =get_guc_id_list (guc, unpinned); +struct intel_context *cn; +u8 number_children = ce->guc_number_children;lockdep_assert_held (&guc->contexts_lock); +GEM_BUG_ON (intel_context_is_child (ce)); -if (!list_empty (guc_id_list)) { - ce =list_first_entry (guc_id_list, - struct intel_context, - guc_id_link); +do { +struct list_head *guc_id_list = +get_guc_id_list (guc, number_children, unpinned); -/* Ensure context getting stolen in expected state */ -GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); -GEM_BUG_ON (context_guc_id_invalid (ce)); -GEM_BUG_ON (context_guc_id_stolen (ce)); +if (!list_empty (guc_id_list)) { +u8 cn_o2, ce_o2 = +order_base_2 (ce->guc_number_children +1 ); -list_del_init (&ce->guc_id_link); - guc_id = ce->guc_id; -clr_context_registered (ce); + cn =list_first_entry (guc_id_list, + struct intel_context, + guc_id_link); + cn_o2 =order_base_2 (cn->guc_number_children +1 ); + +/* +* Corner case where a multi-lrc context steals a guc_id +* from another context that has more guc_id that itself. +*/ +if (cn_o2 != ce_o2) { +bitmap_release_region (guc->guc_ids_bitmap, + cn->guc_id, + cn_o2); +bitmap_allocate_region (guc->guc_ids_bitmap, + ce->guc_id, + ce_o2); + } + +/* Ensure context getting stolen in expected state */ +GEM_BUG_ON (atomic_read (&cn->guc_id_ref)); +GEM_BUG_ON (context_guc_id_invalid (cn)); +GEM_BUG_ON (context_guc_id_stolen (cn)); +GEM_BUG_ON (ce_to_gse (ce) !=ce_to_gse (cn)); + +list_del_init (&cn->guc_id_link); + ce->guc_id = cn->guc_id; + +/* +* If stealing from the pinned list, defer invalidating +* the guc_id until the retire workqueue processes this +* context. +*/ +clr_context_registered (cn); +if (!unpinned) { +GEM_BUG_ON (ce_to_gse (cn)->stalled_context); +ce_to_gse (cn)->stalled_context = +intel_context_get (cn); +set_context_guc_id_stolen (cn); + }else { +set_context_guc_id_invalid (cn); + } + +return 0 ; + }/* -* If stealing from the pinned list, defer invalidating -* the guc_id until the retire workqueue processes this -* context. +* When using multi-lrc we search the guc_id_lists with the +* least amount of guc_ids required first but will consume a +* block larger of guc_ids if necessary. 2x the children always +* moves you two the next list. */ -if (!unpinned) { -GEM_BUG_ON (ce_to_gse (ce)->stalled_context); +if (!number_children || +order_base_2 (number_children +1 ) ==MAX_GUC_ID_ORDER ) +break ; -ce_to_gse (ce)->stalled_context =intel_context_get (ce); -set_context_guc_id_stolen (ce); - }else { -set_context_guc_id_invalid (ce); - } + number_children *=2 ; + }while (true); -return guc_id; - }else { -return -EAGAIN ; - } +return -EAGAIN ; }enum {/* Return values for pin_guc_id / assign_guc_id */ @@ -1674,17 +1757,18 @@ enum { /* Return values for pin_guc_id / assign_guc_id */ NEW_GUC_ID_ENABLED = 2, }; -static int assign_guc_id (struct intel_guc *guc,u16 *out,bool tasklet) +static int assign_guc_id (struct intel_guc *guc,struct intel_context *ce, +bool tasklet) {int ret;lockdep_assert_held (&guc->contexts_lock); +GEM_BUG_ON (intel_context_is_child (ce)); - ret =new_guc_id (guc); + ret =new_guc_id (guc, ce);if (unlikely (ret <0 )) { - ret =steal_guc_id (guc, true); -if (ret >=0 ) { - *out = ret; + ret =steal_guc_id (guc, ce, true); +if (!ret) { ret =NEW_GUC_ID_DISABLED ; }else if (ret <0 && tasklet) {/* @@ -1692,15 +1776,18 @@ static int assign_guc_id(struct intel_guc *guc, u16 *out, bool tasklet)* enabled if guc_ids are exhausted and we are submitting * from the tasklet. */ - ret =steal_guc_id (guc, false); -if (ret >=0 ) { - *out = ret; + ret =steal_guc_id (guc, ce, false); +if (!ret) ret =NEW_GUC_ID_ENABLED ; - } } - }else { - *out = ret; - ret =SAME_GUC_ID ; + } + +if (!(ret <0 ) &&intel_context_is_parent (ce)) { +struct intel_context *child; +int i =1 ; + +for_each_child (ce, child) + child->guc_id = ce->guc_id + i++; }return ret;@@ -1713,6 +1800,7 @@ 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 (intel_context_is_child (ce));GEM_BUG_ON (atomic_read (&ce->guc_id_ref)); try_again:@@ -1724,7 +1812,7 @@ static int pin_guc_id(struct intel_guc *guc, struct intel_context *ce, }if (context_guc_id_invalid (ce)) { - ret =assign_guc_id (guc, &ce->guc_id, tasklet); + ret =assign_guc_id (guc, ce, tasklet);if (unlikely (ret <0 )) goto out_unlock; }@@ -1770,6 +1858,7 @@ static void unpin_guc_id(struct intel_guc *guc,unsigned long flags;GEM_BUG_ON (atomic_read (&ce->guc_id_ref) <0 ); +GEM_BUG_ON (intel_context_is_child (ce));if (unlikely (context_guc_id_invalid (ce)))return ;@@ -1781,7 +1870,8 @@ static void unpin_guc_id(struct intel_guc *guc,if (!context_guc_id_invalid (ce) && !context_guc_id_stolen (ce) && !atomic_read (&ce->guc_id_ref)) { -struct list_head *head =get_guc_id_list (guc, unpinned); +struct list_head *head = +get_guc_id_list (guc, ce->guc_number_children, unpinned);list_add_tail (&ce->guc_id_link, head); }drivers/gpu/drm/i915/gt/uc/intel_guc_submission_types.h +10
-0@@ -22,6 +22,16 @@ struct guc_virtual_engine {/* * Object which encapsulates the globally operated on i915_sched_engine + * the GuC submission state machine described in intel_guc_submission.c. +* +* Currently we have two instances of these per GuC. One for single-lrc and one +* for multi-lrc submission. We split these into two submission engines as they +* can operate in parallel allowing a blocking condition on one not to affect +* the other. i.e. guc_ids are statically allocated between these two submission +* modes. One mode may have guc_ids exhausted which requires blocking while the +* other has plenty of guc_ids and can make forward progres. +* +* In the future if different submission use cases arise we can simply +* instantiate another of these objects and assign it to the context. */ struct guc_submit_engine {struct i915_sched_engine sched_engine;Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 20/46 drm/i915/guc: Add hang check to GuC submit engine
In reply to Matthew BrostThe heartbeat uses a single instance of a GuC submit engine (GSE) to do the hang check. As such if a different GSE's state machine hangs, the heartbeat cannot detect this hang. Add timer to each GSE which in turn can disable all submissions if it is hung.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 36 +++++++++++++++++++ .../i915/gt/uc/intel_guc_submission_types.h | 3 ++ 2 files changed, 39 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +36 -0
@@ -105,15 +105,21 @@ static bool tasklet_blocked(struct guc_submit_engine *gse)return test_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags); } +/* 2 seconds seems like a reasonable timeout waiting for a G2H */ +#define MAX_TASKLET_BLOCKED_NS 2000000000static void set_tasklet_blocked (struct guc_submit_engine *gse) {lockdep_assert_held (&gse->sched_engine.lock); +hrtimer_start_range_ns (&gse->hang_timer, +ns_to_ktime (MAX_TASKLET_BLOCKED_NS ),0 , +HRTIMER_MODE_REL_PINNED );set_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags); }static void __clr_tasklet_blocked (struct guc_submit_engine *gse) {lockdep_assert_held (&gse->sched_engine.lock); +hrtimer_cancel (&gse->hang_timer);clear_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags); }
@@ -1028,6 +1034,7 @@ static void disable_submission(struct intel_guc *guc)if (__tasklet_is_enabled (&sched_engine->tasklet)) {GEM_BUG_ON (!guc->ct.enabled);__tasklet_disable_sync_once (&sched_engine->tasklet); +hrtimer_try_to_cancel (&guc->gse[i]->hang_timer); sched_engine->tasklet.callback =NULL ; } }
@@ -3750,6 +3757,33 @@ static void guc_sched_engine_destroy(struct kref *kref)kfree (gse); } +static enum hrtimer_restart gse_hang (struct hrtimer *hrtimer) +{ +struct guc_submit_engine *gse = + container_of(hrtimer, struct guc_submit_engine, hang_timer); +struct intel_guc *guc = gse->sched_engine.private_data; + +#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST ) +if (guc->gse_hang_expected) +drm_dbg (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +else +drm_err (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +#else +drm_err (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +#endif + +/* +* Tasklet not making forward progress, disable submission which in turn +* will kick in the heartbeat to do a full GPU reset. +*/ +disable_submission (guc); + +return HRTIMER_NORESTART ; +} +static void guc_submit_engine_init (struct intel_guc *guc,struct guc_submit_engine *gse,int id)
@@ -3767,6 +3801,8 @@ static void guc_submit_engine_init(struct intel_guc *guc, sched_engine->retire_inflight_request_prio = guc_retire_inflight_request_prio; sched_engine->private_data = guc; +hrtimer_init (&gse->hang_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + gse->hang_timer.function = gse_hang; gse->id = id; }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission_types.h +3 -0
@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_SUBMISSION_TYPES_H_#define _INTEL_GUC_SUBMISSION_TYPES_H_ +#include <linux/xarray.h> +#include "gt/intel_engine_types.h" #include "gt/intel_context_types.h" #include "i915_scheduler_types.h"
@@ -41,6 +43,7 @@ struct guc_submit_engine {unsigned long flags;int total_num_rq_with_no_guc_id;atomic_t num_guc_ids_not_ready; +struct hrtimer hang_timer;int id;/*
Signature · 1 line
2.28.0
Re: [PATCH 20/46] drm/i915/guc: Add hang check to GuC submit engine
Quoted 19 lines · Matthew Brost
The heartbeat uses a single instance of a GuC submit engine (GSE) to do the hang check. As such if a different GSE's state machine hangs, the heartbeat cannot detect this hang. Add timer to each GSE which in turn can disable all submissions if it is hung.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 36 +++++++++++++++++++ .../i915/gt/uc/intel_guc_submission_types.h | 3 ++ 2 files changed, 39 insertions(+)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -105,15 +105,21 @@ static bool tasklet_blocked(struct guc_submit_engine *gse)return test_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags); }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static bool tasklet_blocked(struct guc_submit_engine *gse) · line 116
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+/* 2 seconds seems like a reasonable timeout waiting for a G2H */ +#define MAX_TASKLET_BLOCKED_NS 2000000000static void set_tasklet_blocked (struct guc_submit_engine *gse) {lockdep_assert_held (&gse->sched_engine.lock); +hrtimer_start_range_ns (&gse->hang_timer, +ns_to_ktime (MAX_TASKLET_BLOCKED_NS ),0 , +HRTIMER_MODE_REL_PINNED );set_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags);
So with drm/scheduler the reset handling is assumed to be single-threaded, and there's quite complex rules around that. I've recently worked with Boris Brezillion to clarify all this a bit and improve docs. Does this all still work in that glorious future? Might be good to at least sprinkle some comments/thoughts around in the commit message about the envisaged future direction for all this stuff, to keep people in the loop. Especially future people.
Ofc plan is still to just largely land all this.
Also: set_bit is an unordered atomic, which means you need barriers, which meanes ... *insert the full rant about justifying/documenting lockless algorithms from earlier *
But I think this all falls out with the removal of the guc-id allocation scheme?
-Daniel
Quoted 84 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +31
-0}static void __clr_tasklet_blocked (struct guc_submit_engine *gse) {lockdep_assert_held (&gse->sched_engine.lock); +hrtimer_cancel (&gse->hang_timer);clear_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags); }@@ -1028,6 +1034,7 @@ static void disable_submission(struct intel_guc *guc)if (__tasklet_is_enabled (&sched_engine->tasklet)) {GEM_BUG_ON (!guc->ct.enabled);__tasklet_disable_sync_once (&sched_engine->tasklet); +hrtimer_try_to_cancel (&guc->gse[i]->hang_timer); sched_engine->tasklet.callback =NULL ; } }@@ -3750,6 +3757,33 @@ static void guc_sched_engine_destroy(struct kref *kref)kfree (gse); } +static enum hrtimer_restart gse_hang (struct hrtimer *hrtimer) +{ +struct guc_submit_engine *gse = + container_of(hrtimer, struct guc_submit_engine, hang_timer); +struct intel_guc *guc = gse->sched_engine.private_data; + +#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST ) +if (guc->gse_hang_expected) +drm_dbg (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +else +drm_err (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +#else +drm_err (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +#endif + +/* +* Tasklet not making forward progress, disable submission which in turn +* will kick in the heartbeat to do a full GPU reset. +*/ +disable_submission (guc); + +return HRTIMER_NORESTART ; +} +static void guc_submit_engine_init (struct intel_guc *guc,struct guc_submit_engine *gse,int id)@@ -3767,6 +3801,8 @@ static void guc_submit_engine_init(struct intel_guc *guc, sched_engine->retire_inflight_request_prio = guc_retire_inflight_request_prio; sched_engine->private_data = guc; +hrtimer_init (&gse->hang_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + gse->hang_timer.function = gse_hang; gse->id = id; }drivers/gpu/drm/i915/gt/uc/intel_guc_submission_types.h +3
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_SUBMISSION_TYPES_H_#define _INTEL_GUC_SUBMISSION_TYPES_H_ +#include <linux/xarray.h> +#include "gt/intel_engine_types.h" #include "gt/intel_context_types.h" #include "i915_scheduler_types.h" @@ -41,6 +43,7 @@ struct guc_submit_engine {unsigned long flags;int total_num_rq_with_no_guc_id;atomic_t num_guc_ids_not_ready; +struct hrtimer hang_timer;int id;/* Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 20/46] drm/i915/guc: Add hang check to GuC submit engine
Quoted 39 lines · Daniel Vetter
Quoted 19 lines · Matthew Brost
The heartbeat uses a single instance of a GuC submit engine (GSE) to do the hang check. As such if a different GSE's state machine hangs, the heartbeat cannot detect this hang. Add timer to each GSE which in turn can disable all submissions if it is hung.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 36 +++++++++++++++++++ .../i915/gt/uc/intel_guc_submission_types.h | 3 ++ 2 files changed, 39 insertions(+)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -105,15 +105,21 @@ static bool tasklet_blocked(struct guc_submit_engine *gse)return test_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags); }drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static bool tasklet_blocked(struct guc_submit_engine *gse) · line 116
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+/* 2 seconds seems like a reasonable timeout waiting for a G2H */ +#define MAX_TASKLET_BLOCKED_NS 2000000000static void set_tasklet_blocked (struct guc_submit_engine *gse) {lockdep_assert_held (&gse->sched_engine.lock); +hrtimer_start_range_ns (&gse->hang_timer, +ns_to_ktime (MAX_TASKLET_BLOCKED_NS ),0 , +HRTIMER_MODE_REL_PINNED );set_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags);So with drm/scheduler the reset handling is assumed to be single-threaded, and there's quite complex rules around that. I've recently worked with Boris Brezillion to clarify all this a bit and improve docs. Does this all still work in that glorious future? Might be good to at least sprinkle some comments/thoughts around in the commit message about the envisaged future direction for all this stuff, to keep people in the loop. Especially future people.
Quoted 6 lines
Ofc plan is still to just largely land all this.
Also:
set_bitis an unordered atomic, which means you need barriers, which meanes ... *insert the full rant about justifying/documenting lockless algorithms from earlier *
lockdep_assert_held(&gse->sched_engine.lock);
Not lockless. Also spin locks act as barriers, right?
Quoted 2 lines
But I think this all falls out with the removal of the guc-id allocation scheme?
Yes, this patch is getting deleted.
Matt
Quoted 91 lines
-Daniel
Quoted 84 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +31
-0}static void __clr_tasklet_blocked (struct guc_submit_engine *gse) {lockdep_assert_held (&gse->sched_engine.lock); +hrtimer_cancel (&gse->hang_timer);clear_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags); }@@ -1028,6 +1034,7 @@ static void disable_submission(struct intel_guc *guc)if (__tasklet_is_enabled (&sched_engine->tasklet)) {GEM_BUG_ON (!guc->ct.enabled);__tasklet_disable_sync_once (&sched_engine->tasklet); +hrtimer_try_to_cancel (&guc->gse[i]->hang_timer); sched_engine->tasklet.callback =NULL ; } }@@ -3750,6 +3757,33 @@ static void guc_sched_engine_destroy(struct kref *kref)kfree (gse); } +static enum hrtimer_restart gse_hang (struct hrtimer *hrtimer) +{ +struct guc_submit_engine *gse = + container_of(hrtimer, struct guc_submit_engine, hang_timer); +struct intel_guc *guc = gse->sched_engine.private_data; + +#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST ) +if (guc->gse_hang_expected) +drm_dbg (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +else +drm_err (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +#else +drm_err (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +#endif + +/* +* Tasklet not making forward progress, disable submission which in turn +* will kick in the heartbeat to do a full GPU reset. +*/ +disable_submission (guc); + +return HRTIMER_NORESTART ; +} +static void guc_submit_engine_init (struct intel_guc *guc,struct guc_submit_engine *gse,int id)@@ -3767,6 +3801,8 @@ static void guc_submit_engine_init(struct intel_guc *guc, sched_engine->retire_inflight_request_prio = guc_retire_inflight_request_prio; sched_engine->private_data = guc; +hrtimer_init (&gse->hang_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + gse->hang_timer.function = gse_hang; gse->id = id; }drivers/gpu/drm/i915/gt/uc/intel_guc_submission_types.h +3
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_SUBMISSION_TYPES_H_#define _INTEL_GUC_SUBMISSION_TYPES_H_ +#include <linux/xarray.h> +#include "gt/intel_engine_types.h" #include "gt/intel_context_types.h" #include "i915_scheduler_types.h" @@ -41,6 +43,7 @@ struct guc_submit_engine {unsigned long flags;int total_num_rq_with_no_guc_id;atomic_t num_guc_ids_not_ready; +struct hrtimer hang_timer;int id;/* Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 20/46] drm/i915/guc: Add hang check to GuC submit engine
Quoted 42 lines · Matthew Brost
Quoted 41 lines · Daniel Vetter
Quoted 19 lines · Matthew Brost
The heartbeat uses a single instance of a GuC submit engine (GSE) to do the hang check. As such if a different GSE's state machine hangs, the heartbeat cannot detect this hang. Add timer to each GSE which in turn can disable all submissions if it is hung.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 36 +++++++++++++++++++ .../i915/gt/uc/intel_guc_submission_types.h | 3 ++ 2 files changed, 39 insertions(+)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -105,15 +105,21 @@ static bool tasklet_blocked(struct guc_submit_engine *gse)return test_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags); }drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static bool tasklet_blocked(struct guc_submit_engine *gse) · line 116
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+/* 2 seconds seems like a reasonable timeout waiting for a G2H */ +#define MAX_TASKLET_BLOCKED_NS 2000000000static void set_tasklet_blocked (struct guc_submit_engine *gse) {lockdep_assert_held (&gse->sched_engine.lock); +hrtimer_start_range_ns (&gse->hang_timer, +ns_to_ktime (MAX_TASKLET_BLOCKED_NS ),0 , +HRTIMER_MODE_REL_PINNED );set_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags);So with drm/scheduler the reset handling is assumed to be single-threaded, and there's quite complex rules around that. I've recently worked with Boris Brezillion to clarify all this a bit and improve docs. Does this all still work in that glorious future? Might be good to at least sprinkle some comments/thoughts around in the commit message about the envisaged future direction for all this stuff, to keep people in the loop. Especially future people.
Ofc plan is still to just largely land all this.
Quoted 8 lines
Quoted 4 lines
Also:
set_bitis an unordered atomic, which means you need barriers, which meanes ... *insert the full rant about justifying/documenting lockless algorithms from earlier *
lockdep_assert_held(&gse->sched_engine.lock);Not lockless. Also spin locks act as barriers, right?
Well if that spinlock is protecting that bit then that's good, but then it shouldn't be an atomic set_bit. In that case:
- either make the entire bitfield non-atomic so it's clear there's boring dumb locking going on
- or split out your new bit into a separate field so that there's no false sharing with the existing bitfield state machinery, and add a kernel doc to that field explaining the locking
set_bit itself is atomic and unordered, so means you need barriers and all that. If you don't have a lockless algorithm, don't use atomic bitops to avoid confusing readers because set_bit/test_bit sets of all the warning bells.
And yes it's annoying that for bitops the atomic ones don't have an atomic_ prefix. The non-atomic ones have a __ prefix. This is honestly why I don't think we should use bitfields as much as we do, because the main use-case for them is when you have bitfields which are longer than 64bits. They come from the cpumask world, and linux supports a lot of cpus.
Open-coding non-atomic simple bitfields with the usual C operators is perfectly fine and legible imo. But that part is maybe more a bikeshed.
Quoted 4 lines
Quoted 2 lines
But I think this all falls out with the removal of the guc-id allocation scheme?
Yes, this patch is getting deleted.
That works too :-)
-Daniel
Quoted 94 lines
Matt
Quoted 91 lines
-Daniel
Quoted 84 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +31
-0}static void __clr_tasklet_blocked (struct guc_submit_engine *gse) {lockdep_assert_held (&gse->sched_engine.lock); +hrtimer_cancel (&gse->hang_timer);clear_bit (GSE_STATE_TASKLET_BLOCKED , &gse->flags); }@@ -1028,6 +1034,7 @@ static void disable_submission(struct intel_guc *guc)if (__tasklet_is_enabled (&sched_engine->tasklet)) {GEM_BUG_ON (!guc->ct.enabled);__tasklet_disable_sync_once (&sched_engine->tasklet); +hrtimer_try_to_cancel (&guc->gse[i]->hang_timer); sched_engine->tasklet.callback =NULL ; } }@@ -3750,6 +3757,33 @@ static void guc_sched_engine_destroy(struct kref *kref)kfree (gse); } +static enum hrtimer_restart gse_hang (struct hrtimer *hrtimer) +{ +struct guc_submit_engine *gse = + container_of(hrtimer, struct guc_submit_engine, hang_timer); +struct intel_guc *guc = gse->sched_engine.private_data; + +#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST ) +if (guc->gse_hang_expected) +drm_dbg (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +else +drm_err (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +#else +drm_err (&guc_to_gt (guc)->i915->drm, +"GSE[%i] hung, disabling submission" , gse->id); +#endif + +/* +* Tasklet not making forward progress, disable submission which in turn +* will kick in the heartbeat to do a full GPU reset. +*/ +disable_submission (guc); + +return HRTIMER_NORESTART ; +} +static void guc_submit_engine_init (struct intel_guc *guc,struct guc_submit_engine *gse,int id)@@ -3767,6 +3801,8 @@ static void guc_submit_engine_init(struct intel_guc *guc, sched_engine->retire_inflight_request_prio = guc_retire_inflight_request_prio; sched_engine->private_data = guc; +hrtimer_init (&gse->hang_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + gse->hang_timer.function = gse_hang; gse->id = id; }drivers/gpu/drm/i915/gt/uc/intel_guc_submission_types.h +3
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_SUBMISSION_TYPES_H_#define _INTEL_GUC_SUBMISSION_TYPES_H_ +#include <linux/xarray.h> +#include "gt/intel_engine_types.h" #include "gt/intel_context_types.h" #include "i915_scheduler_types.h" @@ -41,6 +43,7 @@ struct guc_submit_engine {unsigned long flags;int total_num_rq_with_no_guc_id;atomic_t num_guc_ids_not_ready; +struct hrtimer hang_timer;int id;/* Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 21/46 drm/i915/guc: Add guc_child_context_destroy
In reply to Matthew BrostSince child contexts do not own the guc_ids or GuC context registration, child contexts can simply be freed on destroy. Add guc_child_context_destroy context operation to do this.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +7 -0
@@ -2828,6 +2828,13 @@ static void destroy_worker_func(struct work_struct *w)intel_gt_pm_unpark_work_add (gt, destroy_worker); } +/* Future patches will use this function */ +__maybe_unused +static void guc_child_context_destroy (struct kref *kref) +{ +__guc_context_destroy (container_of(kref ,struct intel_context ,ref )); +} +static void guc_context_destroy (struct kref *kref) {struct intel_context *ce =container_of (kref,typeof (*ce), ref);
Signature · 1 line
2.28.0
Re: [Intel-gfx] [PATCH 21/46] drm/i915/guc: Add guc_child_context_destroy
Quoted 14 lines · Matthew Brost
Since child contexts do not own the
guc_idsor GuC context registration, child contexts can simply be freed on destroy. Addguc_child_context_destroycontext operation to do this.Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void destroy_worker_func(struct work_struct *w) · line 2832
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0@@ -2828,6 +2828,13 @@ static void destroy_worker_func(struct work_struct *w)intel_gt_pm_unpark_work_add (gt, destroy_worker); } +/* Future patches will use this function */ +__maybe_unused
Pure bikeshed, but for something this small just squash it in with the first user. This kinda does nothing alone.
-Daniel
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+static void guc_child_context_destroy (struct kref *kref) +{ +__guc_context_destroy (container_of(kref ,struct intel_context ,ref )); +} +static void guc_context_destroy (struct kref *kref) {struct intel_context *ce =container_of (kref,typeof (*ce), ref);Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [PATCH 21/46] drm/i915/guc: Add guc_child_context_destroy
Quoted 18 lines · Daniel Vetter
Quoted 17 lines · Matthew Brost
Since child contexts do not own the
guc_idsor GuC context registration, child contexts can simply be freed on destroy. Addguc_child_context_destroycontext operation to do this.Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +0
-0@@ -2828,6 +2828,13 @@ static void destroy_worker_func(struct work_struct *w)intel_gt_pm_unpark_work_add (gt, destroy_worker); }
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c static void destroy_worker_func(struct work_struct *w) · line 2832
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+/* Future patches will use this function */ +__maybe_unused Pure bikeshed, but for something this small just squash it in with the first user. This kinda does nothing alone.
-Daniel
Sure.
Matt
Quoted 16 lines
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +5
-0+static void guc_child_context_destroy (struct kref *kref) +{ +__guc_context_destroy (container_of(kref ,struct intel_context ,ref )); +} +static void guc_context_destroy (struct kref *kref) {struct intel_context *ce =container_of (kref,typeof (*ce), ref);Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 22/46 drm/i915/guc: Implement multi-lrc submission
In reply to Matthew BrostImplement multi-lrc submission via a single workqueue entry and single H2G. The workqueue entry contains an updated tail value for each request, of all the contexts in the multi-lrc submission, and updates these values simultaneously. As such, the tasklet and bypass path have been updated to coalesce requests into a single submission.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 6 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 224 +++++++++++++++++- drivers/gpu/drm/i915/i915_request.h | 8 + 3 files changed, 223 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +4 -2
@@ -64,12 +64,14 @@#define WQ_TYPE_PSEUDO (0x2 << WQ_TYPE_SHIFT)#define WQ_TYPE_INORDER (0x3 << WQ_TYPE_SHIFT)#define WQ_TYPE_NOOP (0x4 << WQ_TYPE_SHIFT) -#define WQ_TARGET_SHIFT 10 +#define WQ_TYPE_MULTI_LRC (0x5 << WQ_TYPE_SHIFT) +#define WQ_TARGET_SHIFT 8#define WQ_LEN_SHIFT 16#define WQ_NO_WCFLUSH_WAIT (1 << 27)#define WQ_PRESENT_WORKLOAD (1 << 28) -#define WQ_RING_TAIL_SHIFT 20 +#define WQ_GUC_ID_SHIFT 0 +#define WQ_RING_TAIL_SHIFT 18#define WQ_RING_TAIL_MAX 0x7FF/* 2^11 QWords */ #define WQ_RING_TAIL_MASK (WQ_RING_TAIL_MAX << WQ_RING_TAIL_SHIFT)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +211 -13
315 lines not on this page · raw message
drivers/gpu/drm/i915/i915_request.h +8 -0
@@ -145,6 +145,14 @@ enum {* tasklet that the guc_id isn't pinned. */ I915_FENCE_FLAG_GUC_ID_NOT_PINNED , + +/* +* I915_FENCE_FLAG_SUBMIT_PARALLEL - request with a context in a +* parent-child relationship (parallel submission, multi-lrc) should +* trigger a submission to the GuC rather than just moving the context +* tail. +*/ + I915_FENCE_FLAG_SUBMIT_PARALLEL, };/**
Signature · 1 line
2.28.0
PATCH 23/46 drm/i915/guc: Insert submit fences between requests in parent-child relationship
In reply to Matthew BrostThe GuC must receive requests in the order submitted for contexts in a parent-child relationship to function correctly. To ensure this, insert a submit fence between the current request and last request submitted for requests / contexts in a parent child relationship. This is conceptually similar to a single timeline.
--- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 3 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 3 +- drivers/gpu/drm/i915/i915_request.c | 120 ++++++++++++++---- 5 files changed, 105 insertions(+), 28 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +2 -0
@@ -487,6 +487,8 @@ void intel_context_fini(struct intel_context *ce) {struct intel_context *child, *next; +if (ce->last_rq) +i915_request_put (ce->last_rq);if (ce->timeline)intel_timeline_put (ce->timeline);i915_vm_put (ce->vm);
drivers/gpu/drm/i915/gt/intel_context.h +5 -0
@@ -60,6 +60,11 @@ intel_context_to_parent(struct intel_context *ce)return intel_context_is_child (ce) ? ce->parent : ce; } +static inline bool intel_context_is_parallel (struct intel_context *ce) +{ +return intel_context_is_child (ce) ||intel_context_is_parent (ce); +} +void intel_context_bind_parent_child (struct intel_context *parent,struct intel_context *child);
drivers/gpu/drm/i915/gt/intel_context_types.h +3 -0
@@ -225,6 +225,9 @@ struct intel_context {*/ u8 guc_prio;u32 guc_prio_count[GUC_CLIENT_PRIORITY_NUM ]; + +/* Last request submitted on a parent */ + struct i915_request *last_rq; };#endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1 -2
@@ -820,8 +820,7 @@ static inline int rq_prio(const struct i915_request *rq)static inline bool is_multi_lrc_rq (struct i915_request *rq) { -return intel_context_is_child (rq->context) || -intel_context_is_parent (rq->context); +return intel_context_is_parallel (rq->context); }/*
drivers/gpu/drm/i915/i915_request.c +94 -26
149 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [Intel-gfx] [PATCH 23/46] drm/i915/guc: Insert submit fences between requests in parent-child relationship
Quoted 201 lines · Matthew Brost
The GuC must receive requests in the order submitted for contexts in a parent-child relationship to function correctly. To ensure this, insert a submit fence between the current request and last request submitted for requests / contexts in a parent child relationship. This is conceptually similar to a single timeline.
Signed-off-by Matthew Brost <[email protected]>Cc John Harrison <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 3 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 3 +- drivers/gpu/drm/i915/i915_request.c | 120 ++++++++++++++---- 5 files changed, 105 insertions(+), 28 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +2
-0@@ -487,6 +487,8 @@ void intel_context_fini(struct intel_context *ce) {struct intel_context *child, *next; +if (ce->last_rq) +i915_request_put (ce->last_rq);if (ce->timeline)intel_timeline_put (ce->timeline);i915_vm_put (ce->vm);drivers/gpu/drm/i915/gt/intel_context.h +5
-0@@ -60,6 +60,11 @@ intel_context_to_parent(struct intel_context *ce)return intel_context_is_child (ce) ? ce->parent : ce; } +static inline bool intel_context_is_parallel (struct intel_context *ce) +{ +return intel_context_is_child (ce) ||intel_context_is_parent (ce); +} +void intel_context_bind_parent_child (struct intel_context *parent,struct intel_context *child);drivers/gpu/drm/i915/gt/intel_context_types.h +3
-0@@ -225,6 +225,9 @@ struct intel_context {*/ u8 guc_prio;u32 guc_prio_count[GUC_CLIENT_PRIORITY_NUM ]; + +/* Last request submitted on a parent */ + struct i915_request *last_rq; };#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-2@@ -820,8 +820,7 @@ static inline int rq_prio(const struct i915_request *rq)static inline bool is_multi_lrc_rq (struct i915_request *rq) { -return intel_context_is_child (rq->context) || -intel_context_is_parent (rq->context); +return intel_context_is_parallel (rq->context); }/* drivers/gpu/drm/i915/i915_request.c +69
-26@@ -1546,36 +1546,62 @@ i915_request_await_object(struct i915_request *to,return ret; } +static inline bool is_parallel_rq (struct i915_request *rq) +{ +return intel_context_is_parallel (rq->context); +} + +static inline struct intel_context *request_to_parent (struct i915_request *rq) +{ +return intel_context_to_parent (rq->context); +} +static struct i915_request * -__i915_request_add_to_timeline (struct i915_request *rq) +__i915_request_ensure_parallel_ordering (struct i915_request *rq, +struct intel_timeline *timeline) { -struct intel_timeline *timeline =i915_request_timeline (rq);struct i915_request *prev; -/* -* Dependency tracking and request ordering along the timeline -* is special cased so that we can eliminate redundant ordering -* operations while building the request (we know that the timeline -* itself is ordered, and here we guarantee it). -* -* As we know we will need to emit tracking along the timeline, -* we embed the hooks into our request struct -- at the cost of -* having to have specialised no-allocation interfaces (which will -* be beneficial elsewhere). -* -* A second benefit to open-coding i915_request_await_request is -* that we can apply a slight variant of the rules specialised -* for timelines that jump between engines (such as virtual engines). -* If we consider the case of virtual engine, we must emit a dma-fence -* to prevent scheduling of the second request until the first is -* complete (to maximise our greedy late load balancing) and this -* precludes optimising to use semaphores serialisation of a single -* timeline across engines. -*/ +GEM_BUG_ON (!is_parallel_rq (rq)); + + prev =request_to_parent (rq)->last_rq; +if (prev) { +if (!__i915_request_is_complete (prev)) { +i915_sw_fence_await_sw_fence (&rq->submit, + &prev->submit, + &rq->submitq); + +if (rq->engine->sched_engine->schedule) +__i915_sched_node_add_dependency (&rq->sched, + &prev->sched, + &rq->dep, +0 ); + } +i915_request_put (prev); + } + +request_to_parent (rq)->last_rq =i915_request_get (rq); + +return to_request (__i915_active_fence_set (&timeline->last_request, + &rq->fence)); +} + +static struct i915_request * +__i915_request_ensure_ordering (struct i915_request *rq, +struct intel_timeline *timeline) +{ +struct i915_request *prev; + +GEM_BUG_ON (is_parallel_rq (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); +bool pow2 =is_power_of_2 (READ_ONCE (prev->engine)->mask | + rq->engine->mask); +bool same_context = prev->context == rq->context;/* * The requests are supposed to be kept in order. However, @@ -1583,13 +1609,11 @@ __i915_request_add_to_timeline(struct i915_request *rq)* is used as a barrier for external modification to this * context. */ -GEM_BUG_ON (prev->context == rq->context && +GEM_BUG_ON (same_context &&i915_seqno_passed (prev->fence.seqno, rq->fence.seqno)); -if ((!uses_guc && -is_power_of_2 (READ_ONCE (prev->engine)->mask | rq->engine->mask)) || - (uses_guc && prev->context == rq->context)) +if ((same_context && uses_guc) || (!uses_guc && pow2))i915_sw_fence_await_sw_fence (&rq->submit, &prev->submit, &rq->submitq);@@ -1604,6 +1628,50 @@ __i915_request_add_to_timeline(struct i915_request *rq) 0); } +return prev; +} + +static struct i915_request * +__i915_request_add_to_timeline (struct i915_request *rq) +{ +struct intel_timeline *timeline =i915_request_timeline (rq); +struct i915_request *prev; + +/* +* Dependency tracking and request ordering along the timeline +* is special cased so that we can eliminate redundant ordering +* operations while building the request (we know that the timeline +* itself is ordered, and here we guarantee it). +* +* As we know we will need to emit tracking along the timeline, +* we embed the hooks into our request struct -- at the cost of +* having to have specialised no-allocation interfaces (which will +* be beneficial elsewhere).
drivers/gpu/drm/i915/i915_request.c __i915_request_add_to_timeline(struct i915_request *rq) · line 1659
Quoted 10 lines
drivers/gpu/drm/i915/i915_request.c +10
-0+* +* A second benefit to open-coding i915_request_await_request is +* that we can apply a slight variant of the rules specialised +* for timelines that jump between engines (such as virtual engines). +* If we consider the case of virtual engine, we must emit a dma-fence +* to prevent scheduling of the second request until the first is +* complete (to maximise our greedy late load balancing) and this +* precludes optimising to use semaphores serialisation of a single +* timeline across engines. +*
Can we put a big FIXME in here that this should all be resolved with a proper interface which passes the entire thing down to the backend?
Or is that no longer (or wasn't ever) the long-term goal? -Daniel
Quoted 21 lines
drivers/gpu/drm/i915/i915_request.c +15
-0+* We do not order parallel submission requests on the timeline as each +* parallel submission context has its own timeline and the ordering +* rules for parallel requests are that they must be submitted in the +* order received from the execbuf IOCTL. So rather than using the +* timeline we store a pointer to last request submitted in the +* relationship in the gem context and insert a submission fence +* between that request and request passed into this function or +* alternatively we use completion fence if gem context has a single +* timeline and this is the first submission of an execbuf IOCTL. +*/ +if (likely (!is_parallel_rq (rq))) + prev =__i915_request_ensure_ordering (rq, timeline); +else + prev =__i915_request_ensure_parallel_ordering (rq, timeline); +/* * Make sure that no request gazumped us - if it was allocated after * our i915_request_alloc() and called __i915_request_add() before Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [PATCH 23/46] drm/i915/guc: Insert submit fences between requests in parent-child relationship
Quoted 216 lines · Daniel Vetter
Quoted 201 lines · Matthew Brost
The GuC must receive requests in the order submitted for contexts in a parent-child relationship to function correctly. To ensure this, insert a submit fence between the current request and last request submitted for requests / contexts in a parent child relationship. This is conceptually similar to a single timeline.
Signed-off-by Matthew Brost <[email protected]>Cc John Harrison <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 3 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 3 +- drivers/gpu/drm/i915/i915_request.c | 120 ++++++++++++++---- 5 files changed, 105 insertions(+), 28 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +2
-0@@ -487,6 +487,8 @@ void intel_context_fini(struct intel_context *ce) {struct intel_context *child, *next; +if (ce->last_rq) +i915_request_put (ce->last_rq);if (ce->timeline)intel_timeline_put (ce->timeline);i915_vm_put (ce->vm);drivers/gpu/drm/i915/gt/intel_context.h +5
-0@@ -60,6 +60,11 @@ intel_context_to_parent(struct intel_context *ce)return intel_context_is_child (ce) ? ce->parent : ce; } +static inline bool intel_context_is_parallel (struct intel_context *ce) +{ +return intel_context_is_child (ce) ||intel_context_is_parent (ce); +} +void intel_context_bind_parent_child (struct intel_context *parent,struct intel_context *child);drivers/gpu/drm/i915/gt/intel_context_types.h +3
-0@@ -225,6 +225,9 @@ struct intel_context {*/ u8 guc_prio;u32 guc_prio_count[GUC_CLIENT_PRIORITY_NUM ]; + +/* Last request submitted on a parent */ + struct i915_request *last_rq; };#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-2@@ -820,8 +820,7 @@ static inline int rq_prio(const struct i915_request *rq)static inline bool is_multi_lrc_rq (struct i915_request *rq) { -return intel_context_is_child (rq->context) || -intel_context_is_parent (rq->context); +return intel_context_is_parallel (rq->context); }/* drivers/gpu/drm/i915/i915_request.c +69
-26@@ -1546,36 +1546,62 @@ i915_request_await_object(struct i915_request *to,return ret; } +static inline bool is_parallel_rq (struct i915_request *rq) +{ +return intel_context_is_parallel (rq->context); +} + +static inline struct intel_context *request_to_parent (struct i915_request *rq) +{ +return intel_context_to_parent (rq->context); +} +static struct i915_request * -__i915_request_add_to_timeline (struct i915_request *rq) +__i915_request_ensure_parallel_ordering (struct i915_request *rq, +struct intel_timeline *timeline) { -struct intel_timeline *timeline =i915_request_timeline (rq);struct i915_request *prev; -/* -* Dependency tracking and request ordering along the timeline -* is special cased so that we can eliminate redundant ordering -* operations while building the request (we know that the timeline -* itself is ordered, and here we guarantee it). -* -* As we know we will need to emit tracking along the timeline, -* we embed the hooks into our request struct -- at the cost of -* having to have specialised no-allocation interfaces (which will -* be beneficial elsewhere). -* -* A second benefit to open-coding i915_request_await_request is -* that we can apply a slight variant of the rules specialised -* for timelines that jump between engines (such as virtual engines). -* If we consider the case of virtual engine, we must emit a dma-fence -* to prevent scheduling of the second request until the first is -* complete (to maximise our greedy late load balancing) and this -* precludes optimising to use semaphores serialisation of a single -* timeline across engines. -*/ +GEM_BUG_ON (!is_parallel_rq (rq)); + + prev =request_to_parent (rq)->last_rq; +if (prev) { +if (!__i915_request_is_complete (prev)) { +i915_sw_fence_await_sw_fence (&rq->submit, + &prev->submit, + &rq->submitq); + +if (rq->engine->sched_engine->schedule) +__i915_sched_node_add_dependency (&rq->sched, + &prev->sched, + &rq->dep, +0 ); + } +i915_request_put (prev); + } + +request_to_parent (rq)->last_rq =i915_request_get (rq); + +return to_request (__i915_active_fence_set (&timeline->last_request, + &rq->fence)); +} + +static struct i915_request * +__i915_request_ensure_ordering (struct i915_request *rq, +struct intel_timeline *timeline) +{ +struct i915_request *prev; + +GEM_BUG_ON (is_parallel_rq (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); +bool pow2 =is_power_of_2 (READ_ONCE (prev->engine)->mask | + rq->engine->mask); +bool same_context = prev->context == rq->context;/* * The requests are supposed to be kept in order. However, @@ -1583,13 +1609,11 @@ __i915_request_add_to_timeline(struct i915_request *rq)* is used as a barrier for external modification to this * context. */ -GEM_BUG_ON (prev->context == rq->context && +GEM_BUG_ON (same_context &&i915_seqno_passed (prev->fence.seqno, rq->fence.seqno)); -if ((!uses_guc && -is_power_of_2 (READ_ONCE (prev->engine)->mask | rq->engine->mask)) || - (uses_guc && prev->context == rq->context)) +if ((same_context && uses_guc) || (!uses_guc && pow2))i915_sw_fence_await_sw_fence (&rq->submit, &prev->submit, &rq->submitq);@@ -1604,6 +1628,50 @@ __i915_request_add_to_timeline(struct i915_request *rq) 0); } +return prev; +} + +static struct i915_request * +__i915_request_add_to_timeline (struct i915_request *rq) +{ +struct intel_timeline *timeline =i915_request_timeline (rq); +struct i915_request *prev; + +/* +* Dependency tracking and request ordering along the timeline +* is special cased so that we can eliminate redundant ordering +* operations while building the request (we know that the timeline +* itself is ordered, and here we guarantee it). +* +* As we know we will need to emit tracking along the timeline, +* we embed the hooks into our request struct -- at the cost of +* having to have specialised no-allocation interfaces (which will +* be beneficial elsewhere). drivers/gpu/drm/i915/i915_request.c __i915_request_add_to_timeline(struct i915_request *rq) · line 1659
Quoted 10 lines
drivers/gpu/drm/i915/i915_request.c +10
-0+* +* A second benefit to open-coding i915_request_await_request is +* that we can apply a slight variant of the rules specialised +* for timelines that jump between engines (such as virtual engines). +* If we consider the case of virtual engine, we must emit a dma-fence +* to prevent scheduling of the second request until the first is +* complete (to maximise our greedy late load balancing) and this +* precludes optimising to use semaphores serialisation of a single +* timeline across engines. +* Can we put a big FIXME in here that this should all be resolved with a proper interface which passes the entire thing down to the backend?
Quoted 1 line
Or is that no longer (or wasn't ever) the long-term goal?
I now you mentioned this in the past but I really don't think this all that great of an idea as it would be a pretty intrusive change and not sure what the real benefit is.
However, when we move the DRM scheduler this can be dropped because the ordering of jobs on a sched_entity.
Matt
Quoted 28 lines
-Daniel
Quoted 21 lines
drivers/gpu/drm/i915/i915_request.c +15
-0+* We do not order parallel submission requests on the timeline as each +* parallel submission context has its own timeline and the ordering +* rules for parallel requests are that they must be submitted in the +* order received from the execbuf IOCTL. So rather than using the +* timeline we store a pointer to last request submitted in the +* relationship in the gem context and insert a submission fence +* between that request and request passed into this function or +* alternatively we use completion fence if gem context has a single +* timeline and this is the first submission of an execbuf IOCTL. +*/ +if (likely (!is_parallel_rq (rq))) + prev =__i915_request_ensure_ordering (rq, timeline); +else + prev =__i915_request_ensure_parallel_ordering (rq, timeline); +/* * Make sure that no request gazumped us - if it was allocated after * our i915_request_alloc() and called __i915_request_add() before Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [PATCH 23/46] drm/i915/guc: Insert submit fences between requests in parent-child relationship
Quoted 217 lines · Matthew Brost
Quoted 216 lines · Daniel Vetter
Quoted 201 lines · Matthew Brost
The GuC must receive requests in the order submitted for contexts in a parent-child relationship to function correctly. To ensure this, insert a submit fence between the current request and last request submitted for requests / contexts in a parent child relationship. This is conceptually similar to a single timeline.
Signed-off-by Matthew Brost <[email protected]>Cc John Harrison <[email protected]>--- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 3 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 3 +- drivers/gpu/drm/i915/i915_request.c | 120 ++++++++++++++---- 5 files changed, 105 insertions(+), 28 deletions(-)drivers/gpu/drm/i915/gt/intel_context.c +2
-0@@ -487,6 +487,8 @@ void intel_context_fini(struct intel_context *ce) {struct intel_context *child, *next; +if (ce->last_rq) +i915_request_put (ce->last_rq);if (ce->timeline)intel_timeline_put (ce->timeline);i915_vm_put (ce->vm);drivers/gpu/drm/i915/gt/intel_context.h +5
-0@@ -60,6 +60,11 @@ intel_context_to_parent(struct intel_context *ce)return intel_context_is_child (ce) ? ce->parent : ce; } +static inline bool intel_context_is_parallel (struct intel_context *ce) +{ +return intel_context_is_child (ce) ||intel_context_is_parent (ce); +} +void intel_context_bind_parent_child (struct intel_context *parent,struct intel_context *child);drivers/gpu/drm/i915/gt/intel_context_types.h +3
-0@@ -225,6 +225,9 @@ struct intel_context {*/ u8 guc_prio;u32 guc_prio_count[GUC_CLIENT_PRIORITY_NUM ]; + +/* Last request submitted on a parent */ + struct i915_request *last_rq; };#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1
-2@@ -820,8 +820,7 @@ static inline int rq_prio(const struct i915_request *rq)static inline bool is_multi_lrc_rq (struct i915_request *rq) { -return intel_context_is_child (rq->context) || -intel_context_is_parent (rq->context); +return intel_context_is_parallel (rq->context); }/* drivers/gpu/drm/i915/i915_request.c +69
-26@@ -1546,36 +1546,62 @@ i915_request_await_object(struct i915_request *to,return ret; } +static inline bool is_parallel_rq (struct i915_request *rq) +{ +return intel_context_is_parallel (rq->context); +} + +static inline struct intel_context *request_to_parent (struct i915_request *rq) +{ +return intel_context_to_parent (rq->context); +} +static struct i915_request * -__i915_request_add_to_timeline (struct i915_request *rq) +__i915_request_ensure_parallel_ordering (struct i915_request *rq, +struct intel_timeline *timeline) { -struct intel_timeline *timeline =i915_request_timeline (rq);struct i915_request *prev; -/* -* Dependency tracking and request ordering along the timeline -* is special cased so that we can eliminate redundant ordering -* operations while building the request (we know that the timeline -* itself is ordered, and here we guarantee it). -* -* As we know we will need to emit tracking along the timeline, -* we embed the hooks into our request struct -- at the cost of -* having to have specialised no-allocation interfaces (which will -* be beneficial elsewhere). -* -* A second benefit to open-coding i915_request_await_request is -* that we can apply a slight variant of the rules specialised -* for timelines that jump between engines (such as virtual engines). -* If we consider the case of virtual engine, we must emit a dma-fence -* to prevent scheduling of the second request until the first is -* complete (to maximise our greedy late load balancing) and this -* precludes optimising to use semaphores serialisation of a single -* timeline across engines. -*/ +GEM_BUG_ON (!is_parallel_rq (rq)); + + prev =request_to_parent (rq)->last_rq; +if (prev) { +if (!__i915_request_is_complete (prev)) { +i915_sw_fence_await_sw_fence (&rq->submit, + &prev->submit, + &rq->submitq); + +if (rq->engine->sched_engine->schedule) +__i915_sched_node_add_dependency (&rq->sched, + &prev->sched, + &rq->dep, +0 ); + } +i915_request_put (prev); + } + +request_to_parent (rq)->last_rq =i915_request_get (rq); + +return to_request (__i915_active_fence_set (&timeline->last_request, + &rq->fence)); +} + +static struct i915_request * +__i915_request_ensure_ordering (struct i915_request *rq, +struct intel_timeline *timeline) +{ +struct i915_request *prev; + +GEM_BUG_ON (is_parallel_rq (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); +bool pow2 =is_power_of_2 (READ_ONCE (prev->engine)->mask | + rq->engine->mask); +bool same_context = prev->context == rq->context;/* * The requests are supposed to be kept in order. However, @@ -1583,13 +1609,11 @@ __i915_request_add_to_timeline(struct i915_request *rq)* is used as a barrier for external modification to this * context. */ -GEM_BUG_ON (prev->context == rq->context && +GEM_BUG_ON (same_context &&i915_seqno_passed (prev->fence.seqno, rq->fence.seqno)); -if ((!uses_guc && -is_power_of_2 (READ_ONCE (prev->engine)->mask | rq->engine->mask)) || - (uses_guc && prev->context == rq->context)) +if ((same_context && uses_guc) || (!uses_guc && pow2))i915_sw_fence_await_sw_fence (&rq->submit, &prev->submit, &rq->submitq);@@ -1604,6 +1628,50 @@ __i915_request_add_to_timeline(struct i915_request *rq) 0); } +return prev; +} + +static struct i915_request * +__i915_request_add_to_timeline (struct i915_request *rq) +{ +struct intel_timeline *timeline =i915_request_timeline (rq); +struct i915_request *prev; + +/* +* Dependency tracking and request ordering along the timeline +* is special cased so that we can eliminate redundant ordering +* operations while building the request (we know that the timeline +* itself is ordered, and here we guarantee it). +* +* As we know we will need to emit tracking along the timeline, +* we embed the hooks into our request struct -- at the cost of +* having to have specialised no-allocation interfaces (which will +* be beneficial elsewhere). drivers/gpu/drm/i915/i915_request.c __i915_request_add_to_timeline(struct i915_request *rq) · line 1659
Quoted 10 lines
drivers/gpu/drm/i915/i915_request.c +10
-0+* +* A second benefit to open-coding i915_request_await_request is +* that we can apply a slight variant of the rules specialised +* for timelines that jump between engines (such as virtual engines). +* If we consider the case of virtual engine, we must emit a dma-fence +* to prevent scheduling of the second request until the first is +* complete (to maximise our greedy late load balancing) and this +* precludes optimising to use semaphores serialisation of a single +* timeline across engines. +* Can we put a big FIXME in here that this should all be resolved with a proper interface which passes the entire thing down to the backend?
Quoted 8 lines
Quoted 1 line
Or is that no longer (or wasn't ever) the long-term goal?
I now you mentioned this in the past but I really don't think this all that great of an idea as it would be a pretty intrusive change and not sure what the real benefit is.
However, when we move the DRM scheduler this can be dropped because the ordering of jobs on a
sched_entity.
See further down. Your current design deadlocks - or well, can deadlock. I think at least.
-Daniel
Quoted 31 lines
Matt
Quoted 28 lines
-Daniel
Quoted 21 lines
drivers/gpu/drm/i915/i915_request.c +15
-0+* We do not order parallel submission requests on the timeline as each +* parallel submission context has its own timeline and the ordering +* rules for parallel requests are that they must be submitted in the +* order received from the execbuf IOCTL. So rather than using the +* timeline we store a pointer to last request submitted in the +* relationship in the gem context and insert a submission fence +* between that request and request passed into this function or +* alternatively we use completion fence if gem context has a single +* timeline and this is the first submission of an execbuf IOCTL. +*/ +if (likely (!is_parallel_rq (rq))) + prev =__i915_request_ensure_ordering (rq, timeline); +else + prev =__i915_request_ensure_parallel_ordering (rq, timeline); +/* * Make sure that no request gazumped us - if it was allocated after * our i915_request_alloc() and called __i915_request_add() before Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 24/46 drm/i915/guc: Implement multi-lrc reset
In reply to Matthew BrostUpdate context and full GPU reset to work with multi-lrc. The idea is parent context tracks all the active requests inflight for itself and its' children. The parent context owns the reset replaying / canceling requests as needed.
--- drivers/gpu/drm/i915/gt/intel_context.c | 12 ++-- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 57 ++++++++++++++----- 2 files changed, 49 insertions(+), 20 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +7 -5
@@ -595,20 +595,22 @@ struct i915_request *intel_context_create_request(struct intel_context *ce)struct i915_request *intel_context_find_active_request (struct intel_context *ce) { +struct intel_context *parent =intel_context_is_child (ce) ? + ce->parent : 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, +spin_lock_irqsave (&parent->guc_active.lock, flags); +list_for_each_entry_reverse (rq, &parent->guc_active.requests, sched.link) { -if (i915_request_completed (rq)) +if (i915_request_completed (rq) && rq->context == ce)break ; - active = rq; + active = (rq->context == ce) ? rq : active; } -spin_unlock_irqrestore (&ce->guc_active.lock, flags); +spin_unlock_irqrestore (&parent->guc_active.lock, flags);return active; }
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +42 -15
113 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 25/46 drm/i915/guc: Update debugfs for GuC multi-lrc
In reply to Matthew BrostDisplay the workqueue status in debugfs for GuC contexts that are in parent-child relationship.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +39 -17
@@ -4527,31 +4527,53 @@ void intel_guc_submission_print_info(struct intel_guc *guc,gse_log_submission_info (guc->gse[i], p, i); } +static inline void guc_log_context (struct drm_printer *p, +struct intel_context *ce) +{ +drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); +drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); +drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , + ce->ring->head, + ce->lrc_reg_state[CTX_RING_HEAD ]); +drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , + ce->ring->tail, + ce->lrc_reg_state[CTX_RING_TAIL ]); +drm_printf (p,"\t\tContext Pin Count: %u\n" , +atomic_read (&ce->pin_count)); +drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , +atomic_read (&ce->guc_id_ref)); +drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , +atomic_read (&ce->guc_num_rq_not_ready)); +drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock)); +} +void intel_guc_submission_print_context_info (struct intel_guc *guc,struct drm_printer *p) {struct intel_context *ce;unsigned long index;xa_for_each (&guc->context_lookup, index, ce) { -drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); -drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); -drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , - ce->ring->head, - ce->lrc_reg_state[CTX_RING_HEAD ]); -drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , - ce->ring->tail, - ce->lrc_reg_state[CTX_RING_TAIL ]); -drm_printf (p,"\t\tContext Pin Count: %u\n" , -atomic_read (&ce->pin_count)); -drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , -atomic_read (&ce->guc_id_ref)); -drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , -atomic_read (&ce->guc_num_rq_not_ready)); -drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , - ce->guc_state.sched_state, -atomic_read (&ce->guc_sched_state_no_lock)); +GEM_BUG_ON (intel_context_is_child (ce)); +guc_log_context (p, ce);guc_log_context_priority (p, ce); + +if (intel_context_is_parent (ce)) { +struct guc_process_desc *desc =__get_process_desc (ce); +struct intel_context *child; + +drm_printf (p,"\t\tWQI Head: %u\n" , +READ_ONCE (desc->head)); +drm_printf (p,"\t\tWQI Tail: %u\n" , +READ_ONCE (desc->tail)); +drm_printf (p,"\t\tWQI Status: %u\n\n" , +READ_ONCE (desc->wq_status)); + +for_each_child (ce, child) +guc_log_context (p, child); + } } }
Signature · 1 line
2.28.0
Re: [PATCH 25/46] drm/i915/guc: Update debugfs for GuC multi-lrc
Quoted 26 lines · Matthew Brost
Display the workqueue status in debugfs for GuC contexts that are in parent-child relationship.
Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0@@ -4527,31 +4527,53 @@ void intel_guc_submission_print_info(struct intel_guc *guc,gse_log_submission_info (guc->gse[i], p, i); } +static inline void guc_log_context (struct drm_printer *p, +struct intel_context *ce) +{ +drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); +drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); +drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , + ce->ring->head, + ce->lrc_reg_state[CTX_RING_HEAD ]); + drm_printf(p, "\t\tLRC Tail: Internal %u, Memory %u\n", + ce->ring->tail,
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4549
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +10
-0+ ce->lrc_reg_state[CTX_RING_TAIL]); +drm_printf (p,"\t\tContext Pin Count: %u\n" , +atomic_read (&ce->pin_count)); +drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , +atomic_read (&ce->guc_id_ref)); +drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , +atomic_read (&ce->guc_num_rq_not_ready)); +drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock));
It's all debugfs, but I think proper locking even there is good. It at least reduces the confusion when the locking scheme is largely undocumented. Also given how much we have rcu for everything would be good to double-check all pointer dererences are properly protected.
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4557
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+} +void intel_guc_submission_print_context_info (struct intel_guc *guc,struct drm_printer *p) {struct intel_context *ce;unsigned long index;xa_for_each (&guc->context_lookup, index, ce) {
xa_for_each doesn't provide any guarantees, so doesn't protect against concurrent removeal or anything like that. We need to do better than that. -Daniel
Quoted 42 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-17-drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); -drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); -drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , - ce->ring->head, - ce->lrc_reg_state[CTX_RING_HEAD ]); -drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , - ce->ring->tail, - ce->lrc_reg_state[CTX_RING_TAIL ]); -drm_printf (p,"\t\tContext Pin Count: %u\n" , -atomic_read (&ce->pin_count)); -drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , -atomic_read (&ce->guc_id_ref)); -drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , -atomic_read (&ce->guc_num_rq_not_ready)); -drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , - ce->guc_state.sched_state, -atomic_read (&ce->guc_sched_state_no_lock)); +GEM_BUG_ON (intel_context_is_child (ce)); +guc_log_context (p, ce);guc_log_context_priority (p, ce); + +if (intel_context_is_parent (ce)) { +struct guc_process_desc *desc =__get_process_desc (ce); +struct intel_context *child; + +drm_printf (p,"\t\tWQI Head: %u\n" , +READ_ONCE (desc->head)); +drm_printf (p,"\t\tWQI Tail: %u\n" , +READ_ONCE (desc->tail)); +drm_printf (p,"\t\tWQI Status: %u\n\n" , +READ_ONCE (desc->wq_status)); + +for_each_child (ce, child) +guc_log_context (p, child); + } } }Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 25/46] drm/i915/guc: Update debugfs for GuC multi-lrc
Quoted 34 lines · Daniel Vetter
Quoted 33 lines · Matthew Brost
Display the workqueue status in debugfs for GuC contexts that are in parent-child relationship.
Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-0@@ -4527,31 +4527,53 @@ void intel_guc_submission_print_info(struct intel_guc *guc,gse_log_submission_info (guc->gse[i], p, i); } +static inline void guc_log_context (struct drm_printer *p, +struct intel_context *ce) +{ +drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); +drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); +drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , + ce->ring->head, + ce->lrc_reg_state[CTX_RING_HEAD ]); +drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , + ce->ring->tail, + ce->lrc_reg_state[CTX_RING_TAIL ]); +drm_printf (p,"\t\tContext Pin Count: %u\n" , +atomic_read (&ce->pin_count)); +drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , +atomic_read (&ce->guc_id_ref)); +drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , +atomic_read (&ce->guc_num_rq_not_ready));
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4549
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-0+drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock));It's all debugfs, but I think proper locking even there is good. It at least reduces the confusion when the locking scheme is largely undocumented. Also given how much we have rcu for everything would be good to double-check all pointer dererences are properly protected.
Not sure if I 100% follow this but I don't think any of the pointers dref here are RCU protected. Certainly none of the GuC ones are.
Will double before the next respin though.
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4557
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+} +void intel_guc_submission_print_context_info (struct intel_guc *guc,struct drm_printer *p) {struct intel_context *ce;unsigned long index;xa_for_each (&guc->context_lookup, index, ce) {
xa_for_eachdoesn't provide any guarantees, so doesn't protect against concurrent removeal or anything like that. We need to do better than that.
https://elixir.bootlin.com/linux/latest/source/include/linux/xarray.h#L498
'It is safe to modify the array during the iteration.'
Matt
Quoted 49 lines
-Daniel
Quoted 42 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-17-drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); -drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); -drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , - ce->ring->head, - ce->lrc_reg_state[CTX_RING_HEAD ]); -drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , - ce->ring->tail, - ce->lrc_reg_state[CTX_RING_TAIL ]); -drm_printf (p,"\t\tContext Pin Count: %u\n" , -atomic_read (&ce->pin_count)); -drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , -atomic_read (&ce->guc_id_ref)); -drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , -atomic_read (&ce->guc_num_rq_not_ready)); -drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , - ce->guc_state.sched_state, -atomic_read (&ce->guc_sched_state_no_lock)); +GEM_BUG_ON (intel_context_is_child (ce)); +guc_log_context (p, ce);guc_log_context_priority (p, ce); + +if (intel_context_is_parent (ce)) { +struct guc_process_desc *desc =__get_process_desc (ce); +struct intel_context *child; + +drm_printf (p,"\t\tWQI Head: %u\n" , +READ_ONCE (desc->head)); +drm_printf (p,"\t\tWQI Tail: %u\n" , +READ_ONCE (desc->tail)); +drm_printf (p,"\t\tWQI Status: %u\n\n" , +READ_ONCE (desc->wq_status)); + +for_each_child (ce, child) +guc_log_context (p, child); + } } }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 25/46] drm/i915/guc: Update debugfs for GuC multi-lrc
Quoted 62 lines · Matthew Brost
Quoted 34 lines · Daniel Vetter
Quoted 33 lines · Matthew Brost
Display the workqueue status in debugfs for GuC contexts that are in parent-child relationship.
Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-0@@ -4527,31 +4527,53 @@ void intel_guc_submission_print_info(struct intel_guc *guc,gse_log_submission_info (guc->gse[i], p, i); } +static inline void guc_log_context (struct drm_printer *p, +struct intel_context *ce) +{ +drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); +drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); +drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , + ce->ring->head, + ce->lrc_reg_state[CTX_RING_HEAD ]); +drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , + ce->ring->tail, + ce->lrc_reg_state[CTX_RING_TAIL ]); +drm_printf (p,"\t\tContext Pin Count: %u\n" , +atomic_read (&ce->pin_count)); +drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , +atomic_read (&ce->guc_id_ref)); +drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , +atomic_read (&ce->guc_num_rq_not_ready));Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4549
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-0+drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock));It's all debugfs, but I think proper locking even there is good. It at least reduces the confusion when the locking scheme is largely undocumented. Also given how much we have rcu for everything would be good to double-check all pointer dererences are properly protected.
Not sure if I 100% follow this but I don't think any of the pointers dref here are RCU protected. Certainly none of the GuC ones are.
Will double before the next respin though.
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4557
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+} +void intel_guc_submission_print_context_info (struct intel_guc *guc,struct drm_printer *p) {struct intel_context *ce;unsigned long index;xa_for_each (&guc->context_lookup, index, ce) {
xa_for_eachdoesn't provide any guarantees, so doesn't protect against concurrent removeal or anything like that. We need to do better than that.
Quoted 2 lines
https://elixir.bootlin.com/linux/latest/source/include/linux/xarray.h#L498
'It is safe to modify the array during the iteration.'
The xarray. Not the thing you're dereferencing, because the xarray only stores pointers, not your data structure. So yeah correct statement is that it doesn't provide you any guarantees beyond "the iterator wont be confused if the xarray itself is modified during iteration". Which isn't what you need here, you need a lot more.
-Daniel
Quoted 52 lines
Matt
Quoted 49 lines
-Daniel
Quoted 42 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-17-drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); -drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); -drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , - ce->ring->head, - ce->lrc_reg_state[CTX_RING_HEAD ]); -drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , - ce->ring->tail, - ce->lrc_reg_state[CTX_RING_TAIL ]); -drm_printf (p,"\t\tContext Pin Count: %u\n" , -atomic_read (&ce->pin_count)); -drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , -atomic_read (&ce->guc_id_ref)); -drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , -atomic_read (&ce->guc_num_rq_not_ready)); -drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , - ce->guc_state.sched_state, -atomic_read (&ce->guc_sched_state_no_lock)); +GEM_BUG_ON (intel_context_is_child (ce)); +guc_log_context (p, ce);guc_log_context_priority (p, ce); + +if (intel_context_is_parent (ce)) { +struct guc_process_desc *desc =__get_process_desc (ce); +struct intel_context *child; + +drm_printf (p,"\t\tWQI Head: %u\n" , +READ_ONCE (desc->head)); +drm_printf (p,"\t\tWQI Tail: %u\n" , +READ_ONCE (desc->tail)); +drm_printf (p,"\t\tWQI Status: %u\n\n" , +READ_ONCE (desc->wq_status)); + +for_each_child (ce, child) +guc_log_context (p, child); + } } }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 25/46] drm/i915/guc: Update debugfs for GuC multi-lrc
Quoted 63 lines · Daniel Vetter
Quoted 62 lines · Matthew Brost
Quoted 34 lines · Daniel Vetter
Quoted 33 lines · Matthew Brost
Display the workqueue status in debugfs for GuC contexts that are in parent-child relationship.
Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-0@@ -4527,31 +4527,53 @@ void intel_guc_submission_print_info(struct intel_guc *guc,gse_log_submission_info (guc->gse[i], p, i); } +static inline void guc_log_context (struct drm_printer *p, +struct intel_context *ce) +{ +drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); +drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); +drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , + ce->ring->head, + ce->lrc_reg_state[CTX_RING_HEAD ]); +drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , + ce->ring->tail, + ce->lrc_reg_state[CTX_RING_TAIL ]); +drm_printf (p,"\t\tContext Pin Count: %u\n" , +atomic_read (&ce->pin_count)); +drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , +atomic_read (&ce->guc_id_ref)); +drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , +atomic_read (&ce->guc_num_rq_not_ready));Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4549
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-0+drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock));It's all debugfs, but I think proper locking even there is good. It at least reduces the confusion when the locking scheme is largely undocumented. Also given how much we have rcu for everything would be good to double-check all pointer dererences are properly protected.
Not sure if I 100% follow this but I don't think any of the pointers dref here are RCU protected. Certainly none of the GuC ones are.
Will double before the next respin though.
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4557
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+} +void intel_guc_submission_print_context_info (struct intel_guc *guc,struct drm_printer *p) {struct intel_context *ce;unsigned long index;xa_for_each (&guc->context_lookup, index, ce) {
xa_for_eachdoesn't provide any guarantees, so doesn't protect against concurrent removeal or anything like that. We need to do better than that.
Quoted 8 lines
Quoted 2 lines
https://elixir.bootlin.com/linux/latest/source/include/linux/xarray.h#L498
'It is safe to modify the array during the iteration.'The xarray. Not the thing you're dereferencing, because the xarray only stores pointers, not your data structure. So yeah correct statement is that it doesn't provide you any guarantees beyond "the iterator wont be confused if the xarray itself is modified during iteration". Which isn't what you need here, you need a lot more.
Or spelled out: The pointer you get could become immediately meaningless, before you can look at it, due to a concurrent removal/release. All the xa_for_each guarantees you is that on the next round you get the next pointer, until you got them all (plus/minus concurrent changes). But that next pointer could have become meaningless right away too.
So you need your own locking to make use of these pointers you got and make sure they're not immediately meaningless before your loop body even started.
One of the reasons why I think this is so important is that debugfs files nest a lot of loops fairly often, so are good cheat-sheet for the locking if it happens to be undocumented (which also shouldn't be the case). Ofc if there's no locking in debugfs, no cheat-sheet :-)
Cheers, Daniel
Quoted 59 lines
-Daniel
Quoted 52 lines
Matt
Quoted 49 lines
-Daniel
Quoted 42 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-17-drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); -drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); -drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , - ce->ring->head, - ce->lrc_reg_state[CTX_RING_HEAD ]); -drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , - ce->ring->tail, - ce->lrc_reg_state[CTX_RING_TAIL ]); -drm_printf (p,"\t\tContext Pin Count: %u\n" , -atomic_read (&ce->pin_count)); -drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , -atomic_read (&ce->guc_id_ref)); -drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , -atomic_read (&ce->guc_num_rq_not_ready)); -drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , - ce->guc_state.sched_state, -atomic_read (&ce->guc_sched_state_no_lock)); +GEM_BUG_ON (intel_context_is_child (ce)); +guc_log_context (p, ce);guc_log_context_priority (p, ce); + +if (intel_context_is_parent (ce)) { +struct guc_process_desc *desc =__get_process_desc (ce); +struct intel_context *child; + +drm_printf (p,"\t\tWQI Head: %u\n" , +READ_ONCE (desc->head)); +drm_printf (p,"\t\tWQI Tail: %u\n" , +READ_ONCE (desc->tail)); +drm_printf (p,"\t\tWQI Status: %u\n\n" , +READ_ONCE (desc->wq_status)); + +for_each_child (ce, child) +guc_log_context (p, child); + } } }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 25/46] drm/i915/guc: Update debugfs for GuC multi-lrc
Quoted 79 lines · Daniel Vetter
Quoted 63 lines · Daniel Vetter
Quoted 62 lines · Matthew Brost
Quoted 34 lines · Daniel Vetter
Quoted 33 lines · Matthew Brost
Display the workqueue status in debugfs for GuC contexts that are in parent-child relationship.
Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-0@@ -4527,31 +4527,53 @@ void intel_guc_submission_print_info(struct intel_guc *guc,gse_log_submission_info (guc->gse[i], p, i); } +static inline void guc_log_context (struct drm_printer *p, +struct intel_context *ce) +{ +drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); +drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); +drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , + ce->ring->head, + ce->lrc_reg_state[CTX_RING_HEAD ]); +drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , + ce->ring->tail, + ce->lrc_reg_state[CTX_RING_TAIL ]); +drm_printf (p,"\t\tContext Pin Count: %u\n" , +atomic_read (&ce->pin_count)); +drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , +atomic_read (&ce->guc_id_ref)); +drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , +atomic_read (&ce->guc_num_rq_not_ready));Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4549
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-0+drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock));It's all debugfs, but I think proper locking even there is good. It at least reduces the confusion when the locking scheme is largely undocumented. Also given how much we have rcu for everything would be good to double-check all pointer dererences are properly protected.
Not sure if I 100% follow this but I don't think any of the pointers dref here are RCU protected. Certainly none of the GuC ones are.
Will double before the next respin though.
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4557
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+} +void intel_guc_submission_print_context_info (struct intel_guc *guc,struct drm_printer *p) {struct intel_context *ce;unsigned long index;xa_for_each (&guc->context_lookup, index, ce) {
xa_for_eachdoesn't provide any guarantees, so doesn't protect against concurrent removeal or anything like that. We need to do better than that.Quoted 8 lines
Quoted 2 lines
https://elixir.bootlin.com/linux/latest/source/include/linux/xarray.h#L498
'It is safe to modify the array during the iteration.'The xarray. Not the thing you're dereferencing, because the xarray only stores pointers, not your data structure. So yeah correct statement is that it doesn't provide you any guarantees beyond "the iterator wont be confused if the xarray itself is modified during iteration". Which isn't what you need here, you need a lot more.
Or spelled out: The pointer you get could become immediately meaningless, before you can look at it, due to a concurrent removal/release. All the
xa_for_eachguarantees you is that on the next round you get the next pointer, until you got them all (plus/minus concurrent changes). But that next pointer could have become meaningless right away too.
Quoted 4 lines
So you need your own locking to make use of these pointers you got and make sure they're not immediately meaningless before your loop body even started.
Ok, I think I see your point. Likely whenever we do a xa_for_each over &guc->context_lookup we should just grab its lock as if it is in the xarray we have reference to object looked up. Also everytime we use xa_for_each on &guc->context_lookup it is a corner case we it is ok to block anyone else from using this (e.g. during a reset, checking debugfs, etc...). Does that sound correct?
Matt
Quoted 71 lines
One of the reasons why I think this is so important is that debugfs files nest a lot of loops fairly often, so are good cheat-sheet for the locking if it happens to be undocumented (which also shouldn't be the case). Ofc if there's no locking in debugfs, no cheat-sheet :-)
Cheers, Daniel
Quoted 59 lines
-Daniel
Quoted 52 lines
Matt
Quoted 49 lines
-Daniel
Quoted 42 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-17-drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); -drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); -drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , - ce->ring->head, - ce->lrc_reg_state[CTX_RING_HEAD ]); -drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , - ce->ring->tail, - ce->lrc_reg_state[CTX_RING_TAIL ]); -drm_printf (p,"\t\tContext Pin Count: %u\n" , -atomic_read (&ce->pin_count)); -drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , -atomic_read (&ce->guc_id_ref)); -drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , -atomic_read (&ce->guc_num_rq_not_ready)); -drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , - ce->guc_state.sched_state, -atomic_read (&ce->guc_sched_state_no_lock)); +GEM_BUG_ON (intel_context_is_child (ce)); +guc_log_context (p, ce);guc_log_context_priority (p, ce); + +if (intel_context_is_parent (ce)) { +struct guc_process_desc *desc =__get_process_desc (ce); +struct intel_context *child; + +drm_printf (p,"\t\tWQI Head: %u\n" , +READ_ONCE (desc->head)); +drm_printf (p,"\t\tWQI Tail: %u\n" , +READ_ONCE (desc->tail)); +drm_printf (p,"\t\tWQI Status: %u\n\n" , +READ_ONCE (desc->wq_status)); + +for_each_child (ce, child) +guc_log_context (p, child); + } } }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 25/46] drm/i915/guc: Update debugfs for GuC multi-lrc
Quoted 85 lines · Matthew Brost
Quoted 79 lines · Daniel Vetter
Quoted 63 lines · Daniel Vetter
Quoted 62 lines · Matthew Brost
Quoted 34 lines · Daniel Vetter
Quoted 33 lines · Matthew Brost
Display the workqueue status in debugfs for GuC contexts that are in parent-child relationship.
Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-0@@ -4527,31 +4527,53 @@ void intel_guc_submission_print_info(struct intel_guc *guc,gse_log_submission_info (guc->gse[i], p, i); } +static inline void guc_log_context (struct drm_printer *p, +struct intel_context *ce) +{ +drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); +drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); +drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , + ce->ring->head, + ce->lrc_reg_state[CTX_RING_HEAD ]); +drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , + ce->ring->tail, + ce->lrc_reg_state[CTX_RING_TAIL ]); +drm_printf (p,"\t\tContext Pin Count: %u\n" , +atomic_read (&ce->pin_count)); +drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , +atomic_read (&ce->guc_id_ref)); +drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , +atomic_read (&ce->guc_num_rq_not_ready));Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4549
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-0+drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock));It's all debugfs, but I think proper locking even there is good. It at least reduces the confusion when the locking scheme is largely undocumented. Also given how much we have rcu for everything would be good to double-check all pointer dererences are properly protected.
Not sure if I 100% follow this but I don't think any of the pointers dref here are RCU protected. Certainly none of the GuC ones are.
Will double before the next respin though.
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4557
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+} +void intel_guc_submission_print_context_info (struct intel_guc *guc,struct drm_printer *p) {struct intel_context *ce;unsigned long index;xa_for_each (&guc->context_lookup, index, ce) {
xa_for_eachdoesn't provide any guarantees, so doesn't protect against concurrent removeal or anything like that. We need to do better than that.Quoted 8 lines
Quoted 2 lines
https://elixir.bootlin.com/linux/latest/source/include/linux/xarray.h#L498
'It is safe to modify the array during the iteration.'The xarray. Not the thing you're dereferencing, because the xarray only stores pointers, not your data structure. So yeah correct statement is that it doesn't provide you any guarantees beyond "the iterator wont be confused if the xarray itself is modified during iteration". Which isn't what you need here, you need a lot more.
Or spelled out: The pointer you get could become immediately meaningless, before you can look at it, due to a concurrent removal/release. All the
xa_for_eachguarantees you is that on the next round you get the next pointer, until you got them all (plus/minus concurrent changes). But that next pointer could have become meaningless right away too.Quoted 4 lines
So you need your own locking to make use of these pointers you got and make sure they're not immediately meaningless before your loop body even started.
Quoted 6 lines
Ok, I think I see your point. Likely whenever we do a
xa_for_eachover&guc->context_lookupwe should just grab its lock as if it is in the xarray we have reference to object looked up. Also everytime we usexa_for_eachon&guc->context_lookupit is a corner case we it is ok to block anyone else from using this (e.g. during a reset, checking debugfs, etc...). Does that sound correct?
Yup, generally the simplest is to just hold the lock for the list/xarray/whatever to keep the object alive. Next up in complexity is to grab a temporary reference. This is usually required if the next step is taking a mutex, and your lookup lock is a spinlock. Or if you have some other locking inversion.
And yes anywhere in debugfs, or anywhere else where performance doesn't matter just use proper locking, no tricks with rcu or lockless or whatever.
Finally a word on gpu reset: It is currently not annotated, but gpu reset is a dma_fence signalling critical section (if we fail to get through gpu reset dma_fence are potentially stuck). That means any lock you take in gpu reset is very encumbered, so needs an audit to make sure you're not creating an inversion anywhere. While I bring this up, I noticed you're using i915_sw_fence instead of dma_fence directly in a bunch of places in GuC code. We're kinda aiming to get rid of i915_sw_fence (and maybe move the remaining useful bits into drivers/dma-buf/), so using less of the i915-NIH-isms would be really good in general. There's unfortunately way too much of that too.
-Daniel
Quoted 74 lines
Matt
Quoted 71 lines
One of the reasons why I think this is so important is that debugfs files nest a lot of loops fairly often, so are good cheat-sheet for the locking if it happens to be undocumented (which also shouldn't be the case). Ofc if there's no locking in debugfs, no cheat-sheet :-)
Cheers, Daniel
Quoted 59 lines
-Daniel
Quoted 52 lines
Matt
Quoted 49 lines
-Daniel
Quoted 42 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-17-drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); -drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); -drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , - ce->ring->head, - ce->lrc_reg_state[CTX_RING_HEAD ]); -drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , - ce->ring->tail, - ce->lrc_reg_state[CTX_RING_TAIL ]); -drm_printf (p,"\t\tContext Pin Count: %u\n" , -atomic_read (&ce->pin_count)); -drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , -atomic_read (&ce->guc_id_ref)); -drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , -atomic_read (&ce->guc_num_rq_not_ready)); -drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , - ce->guc_state.sched_state, -atomic_read (&ce->guc_sched_state_no_lock)); +GEM_BUG_ON (intel_context_is_child (ce)); +guc_log_context (p, ce);guc_log_context_priority (p, ce); + +if (intel_context_is_parent (ce)) { +struct guc_process_desc *desc =__get_process_desc (ce); +struct intel_context *child; + +drm_printf (p,"\t\tWQI Head: %u\n" , +READ_ONCE (desc->head)); +drm_printf (p,"\t\tWQI Tail: %u\n" , +READ_ONCE (desc->tail)); +drm_printf (p,"\t\tWQI Status: %u\n\n" , +READ_ONCE (desc->wq_status)); + +for_each_child (ce, child) +guc_log_context (p, child); + } } }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 25/46] drm/i915/guc: Update debugfs for GuC multi-lrc
Quoted 103 lines · Daniel Vetter
Quoted 85 lines · Matthew Brost
Quoted 79 lines · Daniel Vetter
Quoted 63 lines · Daniel Vetter
Quoted 62 lines · Matthew Brost
Quoted 34 lines · Daniel Vetter
Quoted 33 lines · Matthew Brost
Display the workqueue status in debugfs for GuC contexts that are in parent-child relationship.
Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-0@@ -4527,31 +4527,53 @@ void intel_guc_submission_print_info(struct intel_guc *guc,gse_log_submission_info (guc->gse[i], p, i); } +static inline void guc_log_context (struct drm_printer *p, +struct intel_context *ce) +{ +drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); +drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); +drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , + ce->ring->head, + ce->lrc_reg_state[CTX_RING_HEAD ]); +drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , + ce->ring->tail, + ce->lrc_reg_state[CTX_RING_TAIL ]); +drm_printf (p,"\t\tContext Pin Count: %u\n" , +atomic_read (&ce->pin_count)); +drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , +atomic_read (&ce->guc_id_ref)); +drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , +atomic_read (&ce->guc_num_rq_not_ready));Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4549
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +3
-0+drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , + ce->guc_state.sched_state, +atomic_read (&ce->guc_sched_state_no_lock));It's all debugfs, but I think proper locking even there is good. It at least reduces the confusion when the locking scheme is largely undocumented. Also given how much we have rcu for everything would be good to double-check all pointer dererences are properly protected.
Not sure if I 100% follow this but I don't think any of the pointers dref here are RCU protected. Certainly none of the GuC ones are.
Will double before the next respin though.
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c void intel_guc_submission_print_info(struct intel_guc *guc, · line 4557
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +2
-0+} +void intel_guc_submission_print_context_info (struct intel_guc *guc,struct drm_printer *p) {struct intel_context *ce;unsigned long index;xa_for_each (&guc->context_lookup, index, ce) {
xa_for_eachdoesn't provide any guarantees, so doesn't protect against concurrent removeal or anything like that. We need to do better than that.Quoted 8 lines
Quoted 2 lines
https://elixir.bootlin.com/linux/latest/source/include/linux/xarray.h#L498
'It is safe to modify the array during the iteration.'The xarray. Not the thing you're dereferencing, because the xarray only stores pointers, not your data structure. So yeah correct statement is that it doesn't provide you any guarantees beyond "the iterator wont be confused if the xarray itself is modified during iteration". Which isn't what you need here, you need a lot more.
Or spelled out: The pointer you get could become immediately meaningless, before you can look at it, due to a concurrent removal/release. All the
xa_for_eachguarantees you is that on the next round you get the next pointer, until you got them all (plus/minus concurrent changes). But that next pointer could have become meaningless right away too.Quoted 4 lines
So you need your own locking to make use of these pointers you got and make sure they're not immediately meaningless before your loop body even started.
Quoted 6 lines
Ok, I think I see your point. Likely whenever we do a
xa_for_eachover&guc->context_lookupwe should just grab its lock as if it is in the xarray we have reference to object looked up. Also everytime we usexa_for_eachon&guc->context_lookupit is a corner case we it is ok to block anyone else from using this (e.g. during a reset, checking debugfs, etc...). Does that sound correct?Yup, generally the simplest is to just hold the lock for the list/xarray/whatever to keep the object alive. Next up in complexity is to grab a temporary reference. This is usually required if the next step is taking a mutex, and your lookup lock is a spinlock. Or if you have some other locking inversion.
And yes anywhere in debugfs, or anywhere else where performance doesn't matter just use proper locking, no tricks with rcu or lockless or whatever.
Quoted 10 lines
Finally a word on gpu reset: It is currently not annotated, but gpu reset is a
dma_fencesignalling critical section (if we fail to get through gpu resetdma_fenceare potentially stuck). That means any lock you take in gpu reset is very encumbered, so needs an audit to make sure you're not creating an inversion anywhere. While I bring this up, I noticed you're usingi915_sw_fenceinstead ofdma_fencedirectly in a bunch of places in GuC code. We're kinda aiming to get rid ofi915_sw_fence(and maybe move the remaining useful bits intodrivers/dma-buf/), so using less of the i915-NIH-isms would be really good in general. There's unfortunately way too much of that too.
Yes, I'm aware of trying to get rid of the i915_sw_fence as a long term goal. That is going to take quite a while to unwind.
Matt
Quoted 81 lines
-Daniel
Quoted 74 lines
Matt
Quoted 71 lines
One of the reasons why I think this is so important is that debugfs files nest a lot of loops fairly often, so are good cheat-sheet for the locking if it happens to be undocumented (which also shouldn't be the case). Ofc if there's no locking in debugfs, no cheat-sheet :-)
Cheers, Daniel
Quoted 59 lines
-Daniel
Quoted 52 lines
Matt
Quoted 49 lines
-Daniel
Quoted 42 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +17
-17-drm_printf (p,"GuC lrc descriptor %u:\n" , ce->guc_id); -drm_printf (p,"\tHW Context Desc: 0x%08x\n" , ce->lrc.lrca); -drm_printf (p,"\t\tLRC Head: Internal %u, Memory %u\n" , - ce->ring->head, - ce->lrc_reg_state[CTX_RING_HEAD ]); -drm_printf (p,"\t\tLRC Tail: Internal %u, Memory %u\n" , - ce->ring->tail, - ce->lrc_reg_state[CTX_RING_TAIL ]); -drm_printf (p,"\t\tContext Pin Count: %u\n" , -atomic_read (&ce->pin_count)); -drm_printf (p,"\t\tGuC ID Ref Count: %u\n" , -atomic_read (&ce->guc_id_ref)); -drm_printf (p,"\t\tNumber Requests Not Ready: %u\n" , -atomic_read (&ce->guc_num_rq_not_ready)); -drm_printf (p,"\t\tSchedule State: 0x%x, 0x%x\n\n" , - ce->guc_state.sched_state, -atomic_read (&ce->guc_sched_state_no_lock)); +GEM_BUG_ON (intel_context_is_child (ce)); +guc_log_context (p, ce);guc_log_context_priority (p, ce); + +if (intel_context_is_parent (ce)) { +struct guc_process_desc *desc =__get_process_desc (ce); +struct intel_context *child; + +drm_printf (p,"\t\tWQI Head: %u\n" , +READ_ONCE (desc->head)); +drm_printf (p,"\t\tWQI Tail: %u\n" , +READ_ONCE (desc->tail)); +drm_printf (p,"\t\tWQI Status: %u\n\n" , +READ_ONCE (desc->wq_status)); + +for_each_child (ce, child) +guc_log_context (p, child); + } } }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 26/46 drm/i915: Connect UAPI to GuC multi-lrc interface
In reply to Matthew BrostIntroduce 'set parallel submit' extension to connect UAPI to GuC multi-lrc interface. Kernel doc in new uAPI should explain it all.
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 157 +++++++++++++++++- .../gpu/drm/i915/gem/i915_gem_context_types.h | 6 + drivers/gpu/drm/i915/gt/intel_context_types.h | 8 +- drivers/gpu/drm/i915/gt/intel_engine.h | 12 +- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 6 +- .../drm/i915/gt/intel_execlists_submission.c | 6 +- drivers/gpu/drm/i915/gt/selftest_execlists.c | 12 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 111 +++++++++++-- include/uapi/drm/i915_drm.h | 128 ++++++++++++++ 9 files changed, 417 insertions(+), 29 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +155 -2
@@ -515,9 +515,149 @@ set_proto_ctx_engines_bond(struct i915_user_extension __user *base, void *data)return 0 ; } +static int +set_proto_ctx_engines_parallel_submit (struct i915_user_extension __user *base, +void *data) +{ +struct i915_context_engines_parallel_submit __user *ext = +container_of_user (base,typeof (*ext), base); +const struct set_proto_ctx_engines *set = data; +struct drm_i915_private *i915 = set->i915; +u64 flags; +int err =0 , n, i, j; +u16 slot, width, num_siblings; +struct intel_engine_cs **siblings =NULL ; +intel_engine_mask_t prev_mask; + +/* Disabling for now */ +return -ENODEV ; + +if (!(intel_uc_uses_guc_submission (&i915->gt.uc))) +return -ENODEV ; + +if (get_user (slot, &ext->engine_index)) +return -EFAULT ; + +if (get_user (width, &ext->width)) +return -EFAULT ; + +if (get_user (num_siblings, &ext->num_siblings)) +return -EFAULT ; + +if (slot >= set->num_engines) { +drm_dbg (&i915->drm,"Invalid placement value, %d >= %d\n" , + slot, set->num_engines); +return -EINVAL ; + } + +if (set->engines[slot].type !=I915_GEM_ENGINE_TYPE_INVALID ) { +drm_dbg (&i915->drm, +"Invalid placement[%d], already occupied\n" , slot); +return -EINVAL ; + } + +if (get_user (flags, &ext->flags)) +return -EFAULT ; + +if (flags) { +drm_dbg (&i915->drm,"Unknown flags 0x%02llx" , flags); +return -EINVAL ; + } + +for (n =0 ; n <ARRAY_SIZE (ext->mbz64); n++) { + err =check_user_mbz (&ext->mbz64[n]); +if (err) +return err; + } + +if (width <2 ) { +drm_dbg (&i915->drm,"Width (%d) < 2\n" , width); +return -EINVAL ; + } + +if (num_siblings <1 ) { +drm_dbg (&i915->drm,"Number siblings (%d) < 1\n" , + num_siblings); +return -EINVAL ; + } + + siblings =kmalloc_array (num_siblings * width, +sizeof (*siblings), +GFP_KERNEL ); +if (!siblings) +return -ENOMEM ; + +/* Create contexts / engines */ +for (i =0 ; i < width; ++i) { +intel_engine_mask_t current_mask =0 ; +struct i915_engine_class_instance prev_engine; + +for (j =0 ; j < num_siblings; ++j) { +struct i915_engine_class_instance ci; + + n = i * num_siblings + j; +if (copy_from_user (&ci, &ext->engines[n],sizeof (ci))) { + err = -EFAULT ; + goto out_err; + } + + siblings[n] = +intel_engine_lookup_user (i915, ci.engine_class, + ci.engine_instance); +if (!siblings[n]) { +drm_dbg (&i915->drm, +"Invalid sibling[%d]: { class:%d, inst:%d }\n" , + n, ci.engine_class, ci.engine_instance); + err = -EINVAL ; + goto out_err; + } + +if (n) { +if (prev_engine.engine_class != + ci.engine_class) { +drm_dbg (&i915->drm, +"Mismatched class %d, %d\n" , + prev_engine.engine_class, + ci.engine_class); + err = -EINVAL ; + goto out_err; + } + } + + prev_engine = ci; + current_mask |= siblings[n]->logical_mask; + } + +if (i >0 ) { +if (current_mask != prev_mask <<1 ) { +drm_dbg (&i915->drm, +"Non contiguous logical mask 0x%x, 0x%x\n" , + prev_mask, current_mask); + err = -EINVAL ; + goto out_err; + } + } + prev_mask = current_mask; + } + + set->engines[slot].type =I915_GEM_ENGINE_TYPE_PARALLEL ; + set->engines[slot].num_siblings = num_siblings; + set->engines[slot].width = width; + set->engines[slot].siblings = siblings; + +return 0 ; + +out_err: +kfree (siblings); + +return err; +} +static const i915_user_extension_fn set_proto_ctx_engines_extensions[] = { [I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE ] = set_proto_ctx_engines_balance, [I915_CONTEXT_ENGINES_EXT_BOND ] = set_proto_ctx_engines_bond, + [I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT ] = + set_proto_ctx_engines_parallel_submit, }; static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
@@ -938,7 +1078,7 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx, e =alloc_engines (num_engines);for (n =0 ; n < num_engines; n++) { -struct intel_context *ce; +struct intel_context *ce, *child;int ret;switch (pe[n].type) {
@@ -948,7 +1088,13 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,case I915_GEM_ENGINE_TYPE_BALANCED : ce =intel_engine_create_virtual (pe[n].siblings, - pe[n].num_siblings); + pe[n].num_siblings,0 ); +break ; + +case I915_GEM_ENGINE_TYPE_PARALLEL : + ce =intel_engine_create_parallel (pe[n].siblings, + pe[n].num_siblings, + pe[n].width);break ;case I915_GEM_ENGINE_TYPE_INVALID :
@@ -969,6 +1115,13 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx, err =ERR_PTR (ret); goto free_engines; } +for_each_child (ce, child) { + ret =intel_context_set_gem (child, ctx, pe->sseu); +if (ret) { + err =ERR_PTR (ret); + goto free_engines; + } + } } e->num_engines = num_engines;
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +6 -0
@@ -78,6 +78,9 @@ enum i915_gem_engine_type {/** @I915_GEM_ENGINE_TYPE_BALANCED: A load-balanced engine set */ I915_GEM_ENGINE_TYPE_BALANCED , + +/** @I915_GEM_ENGINE_TYPE_PARALLEL: A parallel engine set */ + I915_GEM_ENGINE_TYPE_PARALLEL, };/**
@@ -108,6 +111,9 @@ struct i915_gem_proto_engine {/** @num_siblings: Number of balanced siblings */ unsigned int num_siblings; +/** @width: Width of each sibling */ +unsigned int width; +/** @siblings: Balanced siblings */ struct intel_engine_cs **siblings;
drivers/gpu/drm/i915/gt/intel_context_types.h +6 -2
@@ -55,9 +55,13 @@ struct intel_context_ops {void (*reset)(struct intel_context *ce);void (*destroy)(struct kref *kref); -/* virtual engine/context interface */ +/* virtual/parallel engine/context interface */ struct intel_context *(*create_virtual)(struct intel_engine_cs **engine, -unsigned int count); +unsigned int count, +unsigned long flags); +struct intel_context *(*create_parallel)(struct intel_engine_cs **engines, +unsigned int num_siblings, +unsigned int width);struct intel_engine_cs *(*get_sibling)(struct intel_engine_cs *engine,unsigned int sibling); };
drivers/gpu/drm/i915/gt/intel_engine.h +11 -1
@@ -279,9 +279,19 @@ intel_engine_has_preempt_reset(const struct intel_engine_cs *engine)return intel_engine_has_preemption (engine); } +#define FORCE_VIRTUAL BIT(0)struct intel_context *intel_engine_create_virtual (struct intel_engine_cs **siblings, -unsigned int count); +unsigned int count,unsigned long flags); + +static inline struct intel_context * +intel_engine_create_parallel (struct intel_engine_cs **engines, +unsigned int num_engines, +unsigned int width) +{ +GEM_BUG_ON (!engines[0 ]->cops->create_parallel); +return engines[0 ]->cops->create_parallel (engines, num_engines, width); +}static inline bool intel_virtual_engine_has_heartbeat (const struct intel_engine_cs *engine)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +3 -3
@@ -1923,16 +1923,16 @@ ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine, ktime_t *now)struct intel_context *intel_engine_create_virtual (struct intel_engine_cs **siblings, -unsigned int count) +unsigned int count,unsigned long flags) {if (count ==0 )return ERR_PTR (-EINVAL ); -if (count ==1 ) +if (count ==1 && !(flags &FORCE_VIRTUAL ))return intel_context_create (siblings[0 ]);GEM_BUG_ON (!siblings[0 ]->cops->create_virtual); -return siblings[0 ]->cops->create_virtual (siblings, count); +return siblings[0 ]->cops->create_virtual (siblings, count, flags); } struct i915_request *
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +4 -2
@@ -201,7 +201,8 @@ static struct virtual_engine *to_virtual_engine(struct intel_engine_cs *engine) }static struct intel_context * -execlists_create_virtual (struct intel_engine_cs **siblings,unsigned int count); +execlists_create_virtual (struct intel_engine_cs **siblings,unsigned int count, +unsigned long flags);static struct i915_request * __active_request(const struct intel_timeline * const tl,
@@ -3785,7 +3786,8 @@ static void virtual_submit_request(struct i915_request *rq) }static struct intel_context * -execlists_create_virtual (struct intel_engine_cs **siblings,unsigned int count) +execlists_create_virtual (struct intel_engine_cs **siblings,unsigned int count, +unsigned long flags) {struct virtual_engine *ve;unsigned int n;
drivers/gpu/drm/i915/gt/selftest_execlists.c +6 -6
@@ -3733,7 +3733,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_engine_create_virtual (siblings, nsibling); + ve[n] =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ve[n])) { err =PTR_ERR (ve[n]); nctx = n;
@@ -3929,7 +3929,7 @@ static int mask_virtual_engine(struct intel_gt *gt,* restrict it to our desired engine within the virtual engine. */ - ve =intel_engine_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ve)) { err =PTR_ERR (ve); goto out_close;
@@ -4060,7 +4060,7 @@ static int slicein_virtual_engine(struct intel_gt *gt,i915_request_add (rq); } - ce =intel_engine_create_virtual (siblings, nsibling); + ce =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ce)) { err =PTR_ERR (ce); goto out;
@@ -4112,7 +4112,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_engine_create_virtual (siblings, nsibling); + ce =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ce)) { err =PTR_ERR (ce); goto out;
@@ -4214,7 +4214,7 @@ static int preserved_virtual_engine(struct intel_gt *gt,if (err) goto out_scratch; - ve =intel_engine_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ve)) { err =PTR_ERR (ve); goto out_scratch;
@@ -4354,7 +4354,7 @@ static int reset_virtual_engine(struct intel_gt *gt,if (igt_spinner_init (&spin, gt))return -ENOMEM ; - ve =intel_engine_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ve)) { err =PTR_ERR (ve); goto out_spin;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +98 -13
177 lines not on this page · raw message
include/uapi/drm/i915_drm.h +128 -0
146 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [PATCH 26/46] drm/i915: Connect UAPI to GuC multi-lrc interface
Quoted 5 lines · Matthew Brost
Introduce 'set parallel submit' extension to connect UAPI to GuC multi-lrc interface. Kernel doc in new uAPI should explain it all.
Cc Tvrtko Ursulin <[email protected]>Signed-off-by Matthew Brost <[email protected]>
UMD merge request link + igt patchwork link because this is uapi please. -Daniel
Quoted 727 lines
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 157 +++++++++++++++++- .../gpu/drm/i915/gem/i915_gem_context_types.h | 6 + drivers/gpu/drm/i915/gt/intel_context_types.h | 8 +- drivers/gpu/drm/i915/gt/intel_engine.h | 12 +- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 6 +- .../drm/i915/gt/intel_execlists_submission.c | 6 +- drivers/gpu/drm/i915/gt/selftest_execlists.c | 12 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 111 +++++++++++-- include/uapi/drm/i915_drm.h | 128 ++++++++++++++ 9 files changed, 417 insertions(+), 29 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +155
-2@@ -515,9 +515,149 @@ set_proto_ctx_engines_bond(struct i915_user_extension __user *base, void *data)return 0 ; } +static int +set_proto_ctx_engines_parallel_submit (struct i915_user_extension __user *base, +void *data) +{ +struct i915_context_engines_parallel_submit __user *ext = +container_of_user (base,typeof (*ext), base); +const struct set_proto_ctx_engines *set = data; +struct drm_i915_private *i915 = set->i915; +u64 flags; +int err =0 , n, i, j; +u16 slot, width, num_siblings; +struct intel_engine_cs **siblings =NULL ; +intel_engine_mask_t prev_mask; + +/* Disabling for now */ +return -ENODEV ; + +if (!(intel_uc_uses_guc_submission (&i915->gt.uc))) +return -ENODEV ; + +if (get_user (slot, &ext->engine_index)) +return -EFAULT ; + +if (get_user (width, &ext->width)) +return -EFAULT ; + +if (get_user (num_siblings, &ext->num_siblings)) +return -EFAULT ; + +if (slot >= set->num_engines) { +drm_dbg (&i915->drm,"Invalid placement value, %d >= %d\n" , + slot, set->num_engines); +return -EINVAL ; + } + +if (set->engines[slot].type !=I915_GEM_ENGINE_TYPE_INVALID ) { +drm_dbg (&i915->drm, +"Invalid placement[%d], already occupied\n" , slot); +return -EINVAL ; + } + +if (get_user (flags, &ext->flags)) +return -EFAULT ; + +if (flags) { +drm_dbg (&i915->drm,"Unknown flags 0x%02llx" , flags); +return -EINVAL ; + } + +for (n =0 ; n <ARRAY_SIZE (ext->mbz64); n++) { + err =check_user_mbz (&ext->mbz64[n]); +if (err) +return err; + } + +if (width <2 ) { +drm_dbg (&i915->drm,"Width (%d) < 2\n" , width); +return -EINVAL ; + } + +if (num_siblings <1 ) { +drm_dbg (&i915->drm,"Number siblings (%d) < 1\n" , + num_siblings); +return -EINVAL ; + } + + siblings =kmalloc_array (num_siblings * width, +sizeof (*siblings), +GFP_KERNEL ); +if (!siblings) +return -ENOMEM ; + +/* Create contexts / engines */ +for (i =0 ; i < width; ++i) { +intel_engine_mask_t current_mask =0 ; +struct i915_engine_class_instance prev_engine; + +for (j =0 ; j < num_siblings; ++j) { +struct i915_engine_class_instance ci; + + n = i * num_siblings + j; +if (copy_from_user (&ci, &ext->engines[n],sizeof (ci))) { + err = -EFAULT ; + goto out_err; + } + + siblings[n] = +intel_engine_lookup_user (i915, ci.engine_class, + ci.engine_instance); +if (!siblings[n]) { +drm_dbg (&i915->drm, +"Invalid sibling[%d]: { class:%d, inst:%d }\n" , + n, ci.engine_class, ci.engine_instance); + err = -EINVAL ; + goto out_err; + } + +if (n) { +if (prev_engine.engine_class != + ci.engine_class) { +drm_dbg (&i915->drm, +"Mismatched class %d, %d\n" , + prev_engine.engine_class, + ci.engine_class); + err = -EINVAL ; + goto out_err; + } + } + + prev_engine = ci; + current_mask |= siblings[n]->logical_mask; + } + +if (i >0 ) { +if (current_mask != prev_mask <<1 ) { +drm_dbg (&i915->drm, +"Non contiguous logical mask 0x%x, 0x%x\n" , + prev_mask, current_mask); + err = -EINVAL ; + goto out_err; + } + } + prev_mask = current_mask; + } + + set->engines[slot].type =I915_GEM_ENGINE_TYPE_PARALLEL ; + set->engines[slot].num_siblings = num_siblings; + set->engines[slot].width = width; + set->engines[slot].siblings = siblings; + +return 0 ; + +out_err: +kfree (siblings); + +return err; +} +static const i915_user_extension_fn set_proto_ctx_engines_extensions[] = { [I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE ] = set_proto_ctx_engines_balance, [I915_CONTEXT_ENGINES_EXT_BOND ] = set_proto_ctx_engines_bond, + [I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT ] = + set_proto_ctx_engines_parallel_submit, }; static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,@@ -938,7 +1078,7 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx, e =alloc_engines (num_engines);for (n =0 ; n < num_engines; n++) { -struct intel_context *ce; +struct intel_context *ce, *child;int ret;switch (pe[n].type) {@@ -948,7 +1088,13 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,case I915_GEM_ENGINE_TYPE_BALANCED : ce =intel_engine_create_virtual (pe[n].siblings, - pe[n].num_siblings); + pe[n].num_siblings,0 ); +break ; + +case I915_GEM_ENGINE_TYPE_PARALLEL : + ce =intel_engine_create_parallel (pe[n].siblings, + pe[n].num_siblings, + pe[n].width);break ;case I915_GEM_ENGINE_TYPE_INVALID :@@ -969,6 +1115,13 @@ static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx, err =ERR_PTR (ret); goto free_engines; } +for_each_child (ce, child) { + ret =intel_context_set_gem (child, ctx, pe->sseu); +if (ret) { + err =ERR_PTR (ret); + goto free_engines; + } + } } e->num_engines = num_engines;drivers/gpu/drm/i915/gem/i915_gem_context_types.h +6
-0@@ -78,6 +78,9 @@ enum i915_gem_engine_type {/** @I915_GEM_ENGINE_TYPE_BALANCED: A load-balanced engine set */ I915_GEM_ENGINE_TYPE_BALANCED , + +/** @I915_GEM_ENGINE_TYPE_PARALLEL: A parallel engine set */ + I915_GEM_ENGINE_TYPE_PARALLEL, };/** @@ -108,6 +111,9 @@ struct i915_gem_proto_engine {/** @num_siblings: Number of balanced siblings */ unsigned int num_siblings; +/** @width: Width of each sibling */ +unsigned int width; +/** @siblings: Balanced siblings */ struct intel_engine_cs **siblings;drivers/gpu/drm/i915/gt/intel_context_types.h +6
-2@@ -55,9 +55,13 @@ struct intel_context_ops {void (*reset)(struct intel_context *ce);void (*destroy)(struct kref *kref); -/* virtual engine/context interface */ +/* virtual/parallel engine/context interface */ struct intel_context *(*create_virtual)(struct intel_engine_cs **engine, -unsigned int count); +unsigned int count, +unsigned long flags); +struct intel_context *(*create_parallel)(struct intel_engine_cs **engines, +unsigned int num_siblings, +unsigned int width);struct intel_engine_cs *(*get_sibling)(struct intel_engine_cs *engine,unsigned int sibling); };drivers/gpu/drm/i915/gt/intel_engine.h +11
-1@@ -279,9 +279,19 @@ intel_engine_has_preempt_reset(const struct intel_engine_cs *engine)return intel_engine_has_preemption (engine); } +#define FORCE_VIRTUAL BIT(0)struct intel_context *intel_engine_create_virtual (struct intel_engine_cs **siblings, -unsigned int count); +unsigned int count,unsigned long flags); + +static inline struct intel_context * +intel_engine_create_parallel (struct intel_engine_cs **engines, +unsigned int num_engines, +unsigned int width) +{ +GEM_BUG_ON (!engines[0 ]->cops->create_parallel); +return engines[0 ]->cops->create_parallel (engines, num_engines, width); +}static inline bool intel_virtual_engine_has_heartbeat (const struct intel_engine_cs *engine)drivers/gpu/drm/i915/gt/intel_engine_cs.c +3
-3@@ -1923,16 +1923,16 @@ ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine, ktime_t *now)struct intel_context *intel_engine_create_virtual (struct intel_engine_cs **siblings, -unsigned int count) +unsigned int count,unsigned long flags) {if (count ==0 )return ERR_PTR (-EINVAL ); -if (count ==1 ) +if (count ==1 && !(flags &FORCE_VIRTUAL ))return intel_context_create (siblings[0 ]);GEM_BUG_ON (!siblings[0 ]->cops->create_virtual); -return siblings[0 ]->cops->create_virtual (siblings, count); +return siblings[0 ]->cops->create_virtual (siblings, count, flags); } struct i915_request *drivers/gpu/drm/i915/gt/intel_execlists_submission.c +4
-2@@ -201,7 +201,8 @@ static struct virtual_engine *to_virtual_engine(struct intel_engine_cs *engine) }static struct intel_context * -execlists_create_virtual (struct intel_engine_cs **siblings,unsigned int count); +execlists_create_virtual (struct intel_engine_cs **siblings,unsigned int count, +unsigned long flags);static struct i915_request * __active_request(const struct intel_timeline * const tl,@@ -3785,7 +3786,8 @@ static void virtual_submit_request(struct i915_request *rq) }static struct intel_context * -execlists_create_virtual (struct intel_engine_cs **siblings,unsigned int count) +execlists_create_virtual (struct intel_engine_cs **siblings,unsigned int count, +unsigned long flags) {struct virtual_engine *ve;unsigned int n;drivers/gpu/drm/i915/gt/selftest_execlists.c +6
-6@@ -3733,7 +3733,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_engine_create_virtual (siblings, nsibling); + ve[n] =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ve[n])) { err =PTR_ERR (ve[n]); nctx = n;@@ -3929,7 +3929,7 @@ static int mask_virtual_engine(struct intel_gt *gt,* restrict it to our desired engine within the virtual engine. */ - ve =intel_engine_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ve)) { err =PTR_ERR (ve); goto out_close;@@ -4060,7 +4060,7 @@ static int slicein_virtual_engine(struct intel_gt *gt,i915_request_add (rq); } - ce =intel_engine_create_virtual (siblings, nsibling); + ce =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ce)) { err =PTR_ERR (ce); goto out;@@ -4112,7 +4112,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_engine_create_virtual (siblings, nsibling); + ce =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ce)) { err =PTR_ERR (ce); goto out;@@ -4214,7 +4214,7 @@ static int preserved_virtual_engine(struct intel_gt *gt,if (err) goto out_scratch; - ve =intel_engine_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ve)) { err =PTR_ERR (ve); goto out_scratch;@@ -4354,7 +4354,7 @@ static int reset_virtual_engine(struct intel_gt *gt,if (igt_spinner_init (&spin, gt))return -ENOMEM ; - ve =intel_engine_create_virtual (siblings, nsibling); + ve =intel_engine_create_virtual (siblings, nsibling,0 );if (IS_ERR (ve)) { err =PTR_ERR (ve); goto out_spin;drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +98
-13@@ -82,7 +82,8 @@*/ static struct intel_context * -guc_create_virtual (struct intel_engine_cs **siblings,unsigned int count); +guc_create_virtual (struct intel_engine_cs **siblings,unsigned int count, +unsigned long flags);#define GUC_REQUEST_SIZE 64/* bytes */ @@ -2514,8 +2515,6 @@ static void guc_context_post_unpin(struct intel_context *ce)__guc_context_post_unpin (ce); } -/* Future patches will use this function */ -__maybe_unused static int guc_parent_context_pre_pin (struct intel_context *ce,struct i915_gem_ww_ctx *ww) {@@ -2559,8 +2558,6 @@ static int guc_parent_context_pre_pin(struct intel_context *ce,return err; } -/* Future patches will use this function */ -__maybe_unused static void guc_parent_context_post_unpin (struct intel_context *ce) {struct intel_context *child;@@ -2576,8 +2573,6 @@ static void guc_parent_context_post_unpin(struct intel_context *ce) } } -/* Future patches will use this function */ -__maybe_unused static int guc_parent_context_pin (struct intel_context *ce) {int ret, i =0 , j =0 ;@@ -2623,8 +2618,6 @@ static int guc_parent_context_pin(struct intel_context *ce)return ret; } -/* Future patches will use this function */ -__maybe_unused static void guc_parent_context_unpin (struct intel_context *ce) {struct intel_context *child;@@ -3048,8 +3041,6 @@ static void destroy_worker_func(struct work_struct *w)intel_gt_pm_unpark_work_add (gt, destroy_worker); } -/* Future patches will use this function */ -__maybe_unused static void guc_child_context_destroy (struct kref *kref) {__guc_context_destroy (container_of(kref ,struct intel_context ,ref ));@@ -3272,6 +3263,11 @@ static void remove_from_context(struct i915_request *rq)i915_request_notify_execute_cb_imm (rq); } +static struct intel_context * +guc_create_parallel (struct intel_engine_cs **engines, +unsigned int num_siblings, +unsigned int width); +static const struct intel_context_ops guc_context_ops = { .alloc = guc_context_alloc,@@ -3293,6 +3289,7 @@ static const struct intel_context_ops guc_context_ops = { .destroy = guc_context_destroy, .create_virtual = guc_create_virtual, + .create_parallel = guc_create_parallel, };static void __guc_signal_context_fence (struct intel_context *ce)@@ -3782,6 +3779,91 @@ static void guc_retire_inflight_request_prio(struct i915_request *rq)spin_unlock (&ce->guc_active.lock); } +static const struct intel_context_ops virtual_parent_context_ops = { + .alloc = guc_virtual_context_alloc, + + .pre_pin = guc_parent_context_pre_pin, + .pin = guc_parent_context_pin, + .unpin = guc_parent_context_unpin, + .post_unpin = guc_parent_context_post_unpin, + + .ban = guc_context_ban, + + .enter = guc_virtual_context_enter, + .exit = guc_virtual_context_exit, + + .sched_disable = guc_context_sched_disable, + + .destroy = guc_context_destroy, + + .get_sibling = guc_virtual_get_sibling, +}; + +static const struct intel_context_ops virtual_child_context_ops = { + .alloc = guc_virtual_context_alloc, + + .enter = guc_virtual_context_enter, + .exit = guc_virtual_context_exit, + + .destroy = guc_child_context_destroy, +}; + +static struct intel_context * +guc_create_parallel (struct intel_engine_cs **engines, +unsigned int num_siblings, +unsigned int width) +{ +struct intel_engine_cs **siblings =NULL ; +struct intel_context *parent =NULL , *ce, *err; +int i, j; +int ret; + + siblings =kmalloc_array (num_siblings, +sizeof (*siblings), +GFP_KERNEL ); +if (!siblings) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < width; ++i) { +for (j =0 ; j < num_siblings; ++j) + siblings[j] = engines[i * num_siblings + j]; + + ce =intel_engine_create_virtual (siblings, num_siblings, +FORCE_VIRTUAL ); +if (!ce) { + err =ERR_PTR (-ENOMEM ); + goto unwind; + } + +if (i ==0 ) { + parent = ce; + }else { +intel_context_bind_parent_child (parent, ce); + ret =intel_context_alloc_state (ce); +if (ret) { + err =ERR_PTR (ret); + goto unwind; + } + } + } + + parent->ops = &virtual_parent_context_ops; +for_each_child (parent, ce) + ce->ops = &virtual_child_context_ops; + +kfree (siblings); +return parent; + +unwind: +if (parent) { +for_each_child (parent, ce) +intel_context_put (ce); +intel_context_put (parent); + } +kfree (siblings); +return err; +} +static void sanitize_hwsp (struct intel_engine_cs *engine) {struct intel_timeline *tl;@@ -4578,7 +4660,8 @@ void intel_guc_submission_print_context_info(struct intel_guc *guc, }static struct intel_context * -guc_create_virtual (struct intel_engine_cs **siblings,unsigned int count) +guc_create_virtual (struct intel_engine_cs **siblings,unsigned int count, +unsigned long flags) {struct guc_virtual_engine *ve;struct intel_guc *guc;@@ -4591,7 +4674,9 @@ guc_create_virtual(struct intel_engine_cs **siblings, unsigned int count)return ERR_PTR (-ENOMEM ); guc = &siblings[0 ]->gt->uc.guc; - sched_engine =guc_to_sched_engine (guc,GUC_SUBMIT_ENGINE_SINGLE_LRC ); + sched_engine =guc_to_sched_engine (guc, (flags &FORCE_VIRTUAL ) ? +GUC_SUBMIT_ENGINE_MULTI_LRC : +GUC_SUBMIT_ENGINE_SINGLE_LRC ); ve->base.i915 = siblings[0 ]->i915; ve->base.gt = siblings[0 ]->gt;include/uapi/drm/i915_drm.h +128
-0@@ -1821,6 +1821,7 @@ struct drm_i915_gem_context_param {* Extensions: * i915_context_engines_load_balance (I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE) * i915_context_engines_bond (I915_CONTEXT_ENGINES_EXT_BOND) +* i915_context_engines_parallel_submit (I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT) */ #define I915_CONTEXT_PARAM_ENGINES 0xa@@ -2046,6 +2047,132 @@ struct i915_context_engines_bond {struct i915_engine_class_instance engines[N__ ]; \ } __attribute__((packed))name__ +/** +* struct i915_context_engines_parallel_submit - Configure engine for +* parallel submission. +* +* Setup a slot in the context engine map to allow multiple BBs to be submitted +* in a single execbuf IOCTL. Those BBs will then be scheduled to run on the GPU +* in parallel. Multiple hardware contexts are created internally in the i915 +* run these BBs. Once a slot is configured for N BBs only N BBs can be +* submitted in each execbuf IOCTL and this is implicit behavior e.g. The user +* doesn't tell the execbuf IOCTL there are N BBs, the execbuf IOCTL knows how +* many BBs there are based on the slot's configuration. The N BBs are the last +* N buffer objects or first N if I915_EXEC_BATCH_FIRST is set. +* +* The default placement behavior is to create implicit bonds between each +* context if each context maps to more than 1 physical engine (e.g. context is +* a virtual engine). Also we only allow contexts of same engine class and these +* contexts must be in logically contiguous order. Examples of the placement +* behavior described below. Lastly, the default is to not allow BBs to +* preempted mid BB rather insert coordinated preemption on all hardware +* contexts between each set of BBs. Flags may be added in the future to change +* both of these default behaviors. +* +* Returns -EINVAL if hardware context placement configuration is invalid or if +* the placement configuration isn't supported on the platform / submission +* interface. +* Returns -ENODEV if extension isn't supported on the platform / submission +* interface. +* +* .. code-block:: none +* +* Example 1 pseudo code: +* CS[X] = generic engine of same class, logical instance X +* INVALID = I915_ENGINE_CLASS_INVALID, I915_ENGINE_CLASS_INVALID_NONE +* set_engines(INVALID) +* set_parallel(engine_index=0, width=2, num_siblings=1, +* engines=CS[0],CS[1]) +* +* Results in the following valid placement: +* CS[0], CS[1] +* +* Example 2 pseudo code: +* CS[X] = generic engine of same class, logical instance X +* INVALID = I915_ENGINE_CLASS_INVALID, I915_ENGINE_CLASS_INVALID_NONE +* set_engines(INVALID) +* set_parallel(engine_index=0, width=2, num_siblings=2, +* engines=CS[0],CS[2],CS[1],CS[3]) +* +* Results in the following valid placements: +* CS[0], CS[1] +* CS[2], CS[3] +* +* This can also be thought of as 2 virtual engines described by 2-D array +* in the engines the field with bonds placed between each index of the +* virtual engines. e.g. CS[0] is bonded to CS[1], CS[2] is bonded to +* CS[3]. +* VE[0] = CS[0], CS[2] +* VE[1] = CS[1], CS[3] +* +* Example 3 pseudo code: +* CS[X] = generic engine of same class, logical instance X +* INVALID = I915_ENGINE_CLASS_INVALID, I915_ENGINE_CLASS_INVALID_NONE +* set_engines(INVALID) +* set_parallel(engine_index=0, width=2, num_siblings=2, +* engines=CS[0],CS[1],CS[1],CS[3]) +* +* Results in the following valid and invalid placements: +* CS[0], CS[1] +* CS[1], CS[3] - Not logical contiguous, return -EINVAL +*/ +struct i915_context_engines_parallel_submit { +/** +* @base: base user extension. +*/ +struct i915_user_extension base; + +/** +* @engine_index: slot for parallel engine +*/ +__u16 engine_index; + +/** +* @width: number of contexts per parallel engine +*/ +__u16 width; + +/** +* @num_siblings: number of siblings per context +*/ +__u16 num_siblings; + +/** +* @mbz16: reserved for future use; must be zero +*/ +__u16 mbz16; + +/** +* @flags: all undefined flags must be zero, currently not defined flags +*/ +__u64 flags; + +/** +* @mbz64: reserved for future use; must be zero +*/ +__u64 mbz64[3 ]; + +/** +* @engines: 2-d array of engine instances to configure parallel engine +* +* length = width (i) * num_siblings (j) +* index = j + i * num_siblings +*/ +struct i915_engine_class_instance engines[0 ]; + +} __packed; + +#define I915_DEFINE_CONTEXT_ENGINES_PARALLEL_SUBMIT (name__,N__ ) struct { \ + struct i915_user_extension base; \ + __u16 engine_index; \ + __u16 width; \ + __u16 num_siblings; \ + __u16 mbz16; \ + __u64 flags; \ + __u64 mbz64[3]; \ + struct i915_engine_class_instance engines[N__]; \ +} __attribute__((packed)) name__ +/** * DOC: Context Engine Map uAPI * @@ -2105,6 +2232,7 @@ struct i915_context_param_engines {__u64 extensions;/* linked chain of extension blocks, 0 terminates */ #define I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE 0/* see i915_context_engines_load_balance */ #define I915_CONTEXT_ENGINES_EXT_BOND 1/* see i915_context_engines_bond */ +#define I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT 2/* see i915_context_engines_parallel_submit */ struct i915_engine_class_instance engines[0 ]; } __attribute__((packed));Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 27/46 drm/i915/doc: Update parallel submit doc to point to i915_drm.h
In reply to Matthew BrostUpdate parallel submit doc to point to i915_drm.h
--- Documentation/gpu/rfc/i915_parallel_execbuf.h | 122 ------------------ Documentation/gpu/rfc/i915_scheduler.rst | 4 +- 2 files changed, 2 insertions(+), 124 deletions(-) delete mode 100644 Documentation/gpu/rfc/i915_parallel_execbuf.h
Documentation/gpu/rfc/i915_parallel_execbuf.h deleted +0 -122
@@ -1,122 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* -* Copyright © 2021 Intel Corporation -*/ - -#define I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT 2/* see i915_context_engines_parallel_submit */ - -/** -* struct drm_i915_context_engines_parallel_submit - Configure engine for -* parallel submission. -* -* Setup a slot in the context engine map to allow multiple BBs to be submitted -* in a single execbuf IOCTL. Those BBs will then be scheduled to run on the GPU -* in parallel. Multiple hardware contexts are created internally in the i915 -* run these BBs. Once a slot is configured for N BBs only N BBs can be -* submitted in each execbuf IOCTL and this is implicit behavior e.g. The user -* doesn't tell the execbuf IOCTL there are N BBs, the execbuf IOCTL knows how -* many BBs there are based on the slot's configuration. The N BBs are the last -* N buffer objects or first N if I915_EXEC_BATCH_FIRST is set. -* -* The default placement behavior is to create implicit bonds between each -* context if each context maps to more than 1 physical engine (e.g. context is -* a virtual engine). Also we only allow contexts of same engine class and these -* contexts must be in logically contiguous order. Examples of the placement -* behavior described below. Lastly, the default is to not allow BBs to -* preempted mid BB rather insert coordinated preemption on all hardware -* contexts between each set of BBs. Flags may be added in the future to change -* both of these default behaviors. -* -* Returns -EINVAL if hardware context placement configuration is invalid or if -* the placement configuration isn't supported on the platform / submission -* interface. -* Returns -ENODEV if extension isn't supported on the platform / submission -* interface. -* -* .. code-block:: none -* -* Example 1 pseudo code: -* CS[X] = generic engine of same class, logical instance X -* INVALID = I915_ENGINE_CLASS_INVALID, I915_ENGINE_CLASS_INVALID_NONE -* set_engines(INVALID) -* set_parallel(engine_index=0, width=2, num_siblings=1, -* engines=CS[0],CS[1]) -* -* Results in the following valid placement: -* CS[0], CS[1] -* -* Example 2 pseudo code: -* CS[X] = generic engine of same class, logical instance X -* INVALID = I915_ENGINE_CLASS_INVALID, I915_ENGINE_CLASS_INVALID_NONE -* set_engines(INVALID) -* set_parallel(engine_index=0, width=2, num_siblings=2, -* engines=CS[0],CS[2],CS[1],CS[3]) -* -* Results in the following valid placements: -* CS[0], CS[1] -* CS[2], CS[3] -* -* This can also be thought of as 2 virtual engines described by 2-D array -* in the engines the field with bonds placed between each index of the -* virtual engines. e.g. CS[0] is bonded to CS[1], CS[2] is bonded to -* CS[3]. -* VE[0] = CS[0], CS[2] -* VE[1] = CS[1], CS[3] -* -* Example 3 pseudo code: -* CS[X] = generic engine of same class, logical instance X -* INVALID = I915_ENGINE_CLASS_INVALID, I915_ENGINE_CLASS_INVALID_NONE -* set_engines(INVALID) -* set_parallel(engine_index=0, width=2, num_siblings=2, -* engines=CS[0],CS[1],CS[1],CS[3]) -* -* Results in the following valid and invalid placements: -* CS[0], CS[1] -* CS[1], CS[3] - Not logical contiguous, return -EINVAL -*/ -struct drm_i915_context_engines_parallel_submit { -/** -* @base: base user extension. -*/ -struct i915_user_extension base; - -/** -* @engine_index: slot for parallel engine -*/ -__u16 engine_index; - -/** -* @width: number of contexts per parallel engine -*/ -__u16 width; - -/** -* @num_siblings: number of siblings per context -*/ -__u16 num_siblings; - -/** -* @mbz16: reserved for future use; must be zero -*/ -__u16 mbz16; - -/** -* @flags: all undefined flags must be zero, currently not defined flags -*/ -__u64 flags; - -/** -* @mbz64: reserved for future use; must be zero -*/ -__u64 mbz64[3 ]; - -/** -* @engines: 2-d array of engine instances to configure parallel engine -* -* length = width (i) * num_siblings (j) -* index = j + i * num_siblings -*/ -struct i915_engine_class_instance engines[0 ]; - -} __packed; -
Documentation/gpu/rfc/i915_scheduler.rst +2 -2
@@ -135,8 +135,8 @@ Add I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT and drm_i915_context_engines_parallel_submit to the uAPI to implement this extension. -.. kernel-doc:: Documentation/gpu/rfc/i915_parallel_execbuf.h - :functions: drm_i915_context_engines_parallel_submit +.. kernel-doc:: include/uapi/drm/i915_drm.h + :functions: i915_context_engines_parallel_submit Extend execbuf2 IOCTL to support submitting N BBs in a single IOCTL -------------------------------------------------------------------
Signature · 1 line
2.28.0
PATCH 28/46 drm/i915/guc: Add basic GuC multi-lrc selftest
In reply to Matthew BrostAdd very basic (single submission) multi-lrc selftest.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 1 + .../drm/i915/gt/uc/selftest_guc_multi_lrc.c | 168 ++++++++++++++++++ .../drm/i915/selftests/i915_live_selftests.h | 1 + 3 files changed, 170 insertions(+) create mode 100644 drivers/gpu/drm/i915/gt/uc/selftest_guc_multi_lrc.c
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +1 -0
@@ -4772,5 +4772,6 @@ bool intel_guc_virtual_engine_has_heartbeat(const struct intel_engine_cs *ve) }#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST ) +#include "selftest_guc_multi_lrc.c" #include "selftest_guc_flow_control.c" #endif
drivers/gpu/drm/i915/gt/uc/selftest_guc_multi_lrc.c new file +168 -0
168 lines not on this page · raw message
drivers/gpu/drm/i915/selftests/i915_live_selftests.h +1 -0
@@ -48,5 +48,6 @@ selftest(execlists, intel_execlists_live_selftests) selftest(ring_submission, intel_ring_submission_live_selftests) selftest(perf, i915_perf_live_selftests) selftest(guc_flow_control, intel_guc_flow_control) +selftest (guc_multi_lrc, intel_guc_multi_lrc) /* Here be dragons: keep last to run last! */selftest (late_gt_pm, intel_gt_pm_late_selftests)
Signature · 1 line
2.28.0
PATCH 29/46 drm/i915/guc: Extend GuC flow control selftest for multi-lrc
In reply to Matthew BrostProve multi-lrc and single-lrc are independent.
Prove multi-lrc guc_ids flow control works.
Prove multi-lrc hanging the tastlet can recover from a GPU reset.
--- .../i915/gt/uc/selftest_guc_flow_control.c | 299 ++++++++++++++++++ .../drm/i915/gt/uc/selftest_guc_multi_lrc.c | 15 +- 2 files changed, 312 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/selftest_guc_flow_control.c +299 -0
@@ -110,6 +110,65 @@ static int nop_request_wait(struct intel_engine_cs *engine, bool kernel,return ret; } +static int multi_lrc_not_blocked (struct intel_gt *gt,bool flow_control) +{ +struct intel_guc *guc = >->uc.guc; +struct i915_gpu_error *global = >->i915->gpu_error; +struct guc_submit_engine *gse = guc->gse[GUC_SUBMIT_ENGINE_MULTI_LRC ]; +unsigned int reset_count =i915_reset_count (global); +u64 tasklets_submit_count = gse->tasklets_submit_count; +struct intel_context *parent; +struct i915_request *rq; +int ret; + + parent =multi_lrc_create_parent (gt,VIDEO_DECODE_CLASS ,0 ); +if (IS_ERR (parent)) { +pr_err ("Failed creating multi-lrc contexts: %ld" , +PTR_ERR (parent)); +return PTR_ERR (parent); + }else if (!parent) { +pr_debug ("Not enough engines in class: %d" , +VIDEO_DECODE_CLASS ); +return 0 ; + } + + rq =multi_lrc_nop_request (parent,NULL ); +if (IS_ERR (rq)) { + ret =PTR_ERR (rq); +pr_err ("Failed creating multi-lrc requests: %d" , ret); + goto out; + } + + ret =intel_selftest_wait_for_rq (rq); +if (ret) +pr_err ("Failed waiting on multi-lrc request: %d" , ret); + +i915_request_put (rq); +if (ret) + goto out; + +if (!flow_control && + gse->tasklets_submit_count != tasklets_submit_count) { +pr_err ("Flow control for multi-lrc unexpectedly kicked in\n" ); + ret = -EINVAL ; + } + +if (flow_control && + gse->tasklets_submit_count == tasklets_submit_count) { +pr_err ("Flow control for multi-lrc did not kick in\n" ); + ret = -EINVAL ; + } + +if (i915_reset_count (global) != reset_count) { +pr_err ("Unexpected GPU reset during multi-lrc submit\n" ); + ret = -EINVAL ; + } + +out: +multi_lrc_context_put (parent); +return ret; +} +#define NUM_GUC_ID 256#define NUM_CONTEXT 1024#define NUM_RQ_PER_CONTEXT 2
@@ -240,6 +299,13 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hang goto err_spin_rq; } +/* Ensure Multi-LRC not blocked */ + ret =multi_lrc_not_blocked (gt, !limit_guc_ids); +if (ret <0 ) { +pr_err ("Multi-lrc can't make progress: %d\n" , ret); + goto err_spin_rq; + } +/* Inject hang in flow control state machine */ if (hang) { guc->gse_hang_expected = true;
@@ -559,6 +625,237 @@ static int intel_guc_flow_control_bad_desc_h2g(void *arg)return __intel_guc_flow_control_deadlock_h2g (arg, true); } +#define NUM_CONTEXT_MULTI_LRC 256 + +static int +__intel_guc_flow_control_multi_lrc_guc (void *arg,bool limit_guc_ids,bool hang) +{ +struct intel_gt *gt = arg; +struct intel_guc *guc = >->uc.guc; +struct guc_submit_engine *gse = guc->gse[GUC_SUBMIT_ENGINE_MULTI_LRC ]; +struct intel_context **contexts; +int ret =0 ; +int i, j, k; +struct intel_context *ce; +struct igt_spinner spin; +struct i915_request *spin_rq, *last =NULL ; +intel_wakeref_t wakeref; +struct intel_engine_cs *engine; +struct i915_gpu_error *global = >->i915->gpu_error; +unsigned int reset_count; +u64 tasklets_submit_count = gse->tasklets_submit_count; +u32 old_beat; + +if (limit_guc_ids) + guc->num_guc_ids =NUM_GUC_ID ; + + contexts =kmalloc (sizeof (*contexts) *NUM_CONTEXT ,GFP_KERNEL ); +if (!contexts) { +pr_err ("Context array allocation failed\n" ); +return -ENOMEM ; + } + + wakeref =intel_runtime_pm_get (gt->uncore->rpm); + + ce =intel_context_create (intel_selftest_find_any_engine (gt)); +if (IS_ERR (ce)) { + ret =PTR_ERR (ce); +pr_err ("Failed to create context: %d\n" , ret); + goto err; + } + + reset_count =i915_reset_count (global); + engine = ce->engine; + + old_beat = engine->props.heartbeat_interval_ms; +if (hang) { + ret =intel_engine_set_heartbeat (engine,HEARTBEAT_INTERVAL ); +if (ret) { +pr_err ("Failed to boost heatbeat interval: %d\n" , ret); +intel_context_put (ce); + goto err; + } + } + +/* Create spinner to block requests in below loop */ + ret =igt_spinner_init (&spin, engine->gt); +if (ret) { +pr_err ("Failed to create spinner: %d\n" , ret); +intel_context_put (ce); + goto err_heartbeat; + } + spin_rq =igt_spinner_create_request (&spin, ce,MI_ARB_CHECK ); +intel_context_put (ce); +if (IS_ERR (spin_rq)) { + ret =PTR_ERR (spin_rq); +pr_err ("Failed to create spinner request: %d\n" , ret); + goto err_spin_rq; + } + ret =__request_add_spin (spin_rq, &spin); +if (ret) { +pr_err ("Failed to add Spinner request: %d\n" , ret); + goto err_spin_rq; + } + +for (i =0 ; i <NUM_RQ_PER_CONTEXT ; ++i) { +for (j =0 ; j <NUM_CONTEXT_MULTI_LRC ; ++j) { +for (k =0 ; k <NUM_RQ_PER_CONTEXT ; ++k) { +bool first_pass = !i && !k; + +if (last) +i915_request_put (last); + last =NULL ; +if (first_pass) + contexts[j] =multi_lrc_create_parent (gt,VIDEO_DECODE_CLASS ,0 ); + ce = contexts[j]; + +if (IS_ERR (ce)) { + ret =PTR_ERR (ce); +pr_err ("Failed to create context: %d\n" , ret); + goto err_spin_rq; + }else if (!ce) { + ret =0 ; + goto err_spin_rq; + } + + last =multi_lrc_nop_request (ce, spin_rq); +if (first_pass) +multi_lrc_context_put (ce); +if (IS_ERR (last)) { + ret =PTR_ERR (last); +pr_err ("Failed to create request: %d\n" , ret); + goto err_spin_rq; + } + } + } + } + +/* Verify GuC submit engine state */ +if (limit_guc_ids && !guc_ids_exhausted (gse)) { +pr_err ("guc_ids not exhausted\n" ); + ret = -EINVAL ; + goto err_spin_rq; + } +if (!limit_guc_ids &&guc_ids_exhausted (gse)) { +pr_err ("guc_ids exhausted\n" ); + ret = -EINVAL ; + goto err_spin_rq; + } + +/* Ensure no DoS from unready requests */ + ret =multi_lrc_not_blocked (gt, true); +if (ret <0 ) { +pr_err ("Multi-lrc DoS: %d\n" , ret); + goto err_spin_rq; + } + +/* Ensure Single-LRC not blocked, not in flow control */ + ret =nop_request_wait (engine, false, !limit_guc_ids); +if (ret <0 ) { +pr_err ("User NOP request DoS: %d\n" , ret); + goto err_spin_rq; + } + +/* Inject hang in flow control state machine */ +if (hang) { + guc->gse_hang_expected = true; + guc->inject_bad_sched_disable = true; + } + +/* Release blocked requests */ +igt_spinner_end (&spin); + ret =intel_selftest_wait_for_rq (spin_rq); +if (ret) { +pr_err ("Spin request failed to complete: %d\n" , ret); + goto err_spin_rq; + } +i915_request_put (spin_rq); +igt_spinner_fini (&spin); + spin_rq =NULL ; + +/* Wait for last request / GT to idle */ + ret =i915_request_wait (last,0 , hang ?HZ *30 :HZ *5 ); +if (ret <0 ) { +pr_err ("Last request failed to complete: %d\n" , ret); + goto err_spin_rq; + } +i915_request_put (last); + last =NULL ; + ret =intel_gt_wait_for_idle (gt,HZ *5 ); +if (ret <0 ) { +pr_err ("GT failed to idle: %d\n" , ret); + goto err_spin_rq; + } + +/* Check state after idle */ +if (guc_ids_exhausted (gse)) { +pr_err ("guc_ids exhausted after last request signaled\n" ); + ret = -EINVAL ; + goto err_spin_rq; + } +if (hang) { +if (i915_reset_count (global) == reset_count) { +pr_err ("Failed to record a GPU reset\n" ); + ret = -EINVAL ; + goto err_spin_rq; + } + }else { +if (i915_reset_count (global) != reset_count) { +pr_err ("Unexpected GPU reset\n" ); + ret = -EINVAL ; + goto err_spin_rq; + } +if (gse->tasklets_submit_count == tasklets_submit_count) { +pr_err ("Flow control failed to kick in\n" ); + ret = -EINVAL ; + goto err_spin_rq; + } + } + +/* Verify requests can be submitted after flow control */ + ret =nop_request_wait (engine, true, false); +if (ret <0 ) { +pr_err ("Kernel NOP failed to complete: %d\n" , ret); + goto err_spin_rq; + } + ret =nop_request_wait (engine, false, false); +if (ret <0 ) { +pr_err ("User NOP failed to complete: %d\n" , ret); + goto err_spin_rq; + } + +err_spin_rq: +if (spin_rq) { +igt_spinner_end (&spin); +intel_selftest_wait_for_rq (spin_rq); +i915_request_put (spin_rq); +igt_spinner_fini (&spin); +intel_gt_wait_for_idle (gt,HZ *5 ); + } +err_heartbeat: +if (last) +i915_request_put (last); +intel_engine_set_heartbeat (engine, old_beat); +err: +intel_runtime_pm_put (gt->uncore->rpm, wakeref); + guc->num_guc_ids = guc->max_guc_ids; + guc->gse_hang_expected = false; + guc->inject_bad_sched_disable = false; +kfree (contexts); + +return ret; +} + +static int intel_guc_flow_control_multi_lrc_guc_ids (void *arg) +{ +return __intel_guc_flow_control_multi_lrc_guc (arg, true, false); +} + +static int intel_guc_flow_control_multi_lrc_hang (void *arg) +{ +return __intel_guc_flow_control_multi_lrc_guc (arg, true, true); +} +int intel_guc_flow_control (struct drm_i915_private *i915) {static const struct i915_subtest tests[] = {
@@ -566,6 +863,8 @@ int intel_guc_flow_control(struct drm_i915_private *i915)SUBTEST (intel_guc_flow_control_guc_ids),SUBTEST (intel_guc_flow_control_lrcd_reg),SUBTEST (intel_guc_flow_control_hang_state_machine), +SUBTEST (intel_guc_flow_control_multi_lrc_guc_ids), +SUBTEST (intel_guc_flow_control_multi_lrc_hang),SUBTEST (intel_guc_flow_control_deadlock_h2g), SUBTEST(intel_guc_flow_control_bad_desc_h2g), };
drivers/gpu/drm/i915/gt/uc/selftest_guc_multi_lrc.c +13 -2
@@ -62,11 +62,12 @@ static void multi_lrc_context_put(struct intel_context *ce) }static struct i915_request * -multi_lrc_nop_request (struct intel_context *ce) +multi_lrc_nop_request (struct intel_context *ce,struct i915_request *from) {struct intel_context *child;struct i915_request *rq, *child_rq;int i =0 ; +int ret;GEM_BUG_ON (!intel_context_is_parent (ce));
@@ -74,6 +75,16 @@ multi_lrc_nop_request(struct intel_context *ce)if (IS_ERR (rq))return rq; +if (from) { + ret =i915_sw_fence_await_dma_fence (&rq->submit, + &from->fence,0 , +I915_FENCE_GFP ); +if (ret <0 ) { +i915_request_put (rq); +return ERR_PTR (ret); + } + } +i915_request_get (rq);i915_request_add (rq);
@@ -112,7 +123,7 @@ static int __intel_guc_multi_lrc_basic(struct intel_gt *gt, unsigned int class)return 0 ; } - rq =multi_lrc_nop_request (parent); + rq =multi_lrc_nop_request (parent,NULL );if (IS_ERR (rq)) { ret =PTR_ERR (rq);pr_err ("Failed creating requests: %d" , ret);
Signature · 1 line
2.28.0
PATCH 30/46 drm/i915/guc: Implement no mid batch preemption for multi-lrc
In reply to Matthew BrostFor some users of multi-lrc, e.g. split frame, it isn't safe to preempt mid BB. To safely enable preemption at the BB boundary, a handshake between to parent and child is needed. This is implemented via custom emit_bb_start & emit_fini_breadcrumb functions and enabled via by default if a context is configured by set parallel extension.
--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- drivers/gpu/drm/i915/gt/intel_context_types.h | 3 + drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 2 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 283 +++++++++++++++++- 4 files changed, 287 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +1 -1
@@ -629,7 +629,7 @@ void intel_context_bind_parent_child(struct intel_context *parent,GEM_BUG_ON (intel_context_is_child (child));GEM_BUG_ON (intel_context_is_parent (child)); - parent->guc_number_children++; + child->guc_child_index = parent->guc_number_children++;list_add_tail (&child->guc_child_link, &parent->guc_child_list); child->parent = parent;
drivers/gpu/drm/i915/gt/intel_context_types.h +3 -0
@@ -222,6 +222,9 @@ struct intel_context {/* Number of children if parent */ u8 guc_number_children; +/* Child index if child */ +u8 guc_child_index; +u8 parent_page;/* if set, page num reserved for parent context */ /*
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +1 -1
@@ -181,7 +181,7 @@ struct guc_process_desc {u32 wq_status;u32 engine_presence;u32 priority; -u32 reserved[30 ]; +u32 reserved[36 ]; } __packed;#define CONTEXT_REGISTRATION_FLAG_KMD BIT(0)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +282 -1
334 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 31/46 drm/i915: Move secure execbuf check to execbuf2
In reply to Matthew BrostGoal is to remove all input sanity checks from the core submission.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +21 -14
@@ -3184,19 +3184,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.num_fences =0 ; eb.batch_flags =0 ; -if (args->flags &I915_EXEC_SECURE ) { -if (GRAPHICS_VER (i915) >=11 ) -return -ENODEV ; - -/* Return -EPERM to trigger fallback code on old binaries. */ -if (!HAS_SECURE_BATCHES (i915)) -return -EPERM ; - -if (!drm_is_current_master (file) || !capable (CAP_SYS_ADMIN )) -return -EPERM ; - +if (args->flags &I915_EXEC_SECURE ) eb.batch_flags |=I915_DISPATCH_SECURE ; - }if (args->flags &I915_EXEC_IS_PINNED ) eb.batch_flags |=I915_DISPATCH_PINNED ;
@@ -3414,6 +3403,18 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,return -EINVAL ; } +if (args->flags &I915_EXEC_SECURE ) { +if (GRAPHICS_VER (i915) >=11 ) +return -ENODEV ; + +/* Return -EPERM to trigger fallback code on old binaries. */ +if (!HAS_SECURE_BATCHES (i915)) +return -EPERM ; + +if (!drm_is_current_master (file) || !capable (CAP_SYS_ADMIN )) +return -EPERM ; + } + err =i915_gem_check_execbuffer (args);if (err)return err;
@@ -3430,8 +3431,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, u64_to_user_ptr(args->buffers_ptr), sizeof(*exec2_list) * count)) {drm_dbg (&i915->drm,"copy %zd exec entries failed\n" , count); -kvfree (exec2_list); -return -EFAULT ; + err = -EFAULT ; + goto err_copy; } err =i915_gem_do_execbuffer (dev, file, args, exec2_list);
@@ -3476,6 +3477,12 @@ end:; args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS;kvfree (exec2_list); + +return err; + +err_copy: +kvfree (exec2_list); +return err; }
Signature · 1 line
2.28.0
PATCH 32/46 drm/i915: Move input/exec fence handling to i915_gem_execbuffer2
In reply to Matthew BrostMove the job of creating an input/exec fences (from a file descriptor) out of i915_gem_do_execbuffer.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 75 +++++++++++-------- 1 file changed, 43 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +43 -32
@@ -3146,11 +3146,12 @@ static int i915_gem_do_execbuffer(struct drm_device *dev, struct drm_file *file, struct drm_i915_gem_execbuffer2 *args, - struct drm_i915_gem_exec_object2 *exec) + struct drm_i915_gem_exec_object2 *exec, + struct dma_fence *in_fence, + struct dma_fence *exec_fence) { struct drm_i915_private *i915 = to_i915(dev);struct i915_execbuffer eb; -struct dma_fence *in_fence =NULL ;struct sync_file *out_fence =NULL ;struct i915_vma *batch;int out_fence_fd =-1 ;
@@ -3197,25 +3198,10 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (err) goto err_ext; -#define IN_FENCES (I915_EXEC_FENCE_IN | I915_EXEC_FENCE_SUBMIT) -if (args->flags &IN_FENCES ) { -if ((args->flags &IN_FENCES ) ==IN_FENCES ) -return -EINVAL ; - - in_fence =sync_file_get_fence (lower_32_bits (args->rsvd2)); -if (!in_fence) { - err = -EINVAL ; - goto err_ext; - } - } -#undef IN_FENCES -if (args->flags &I915_EXEC_FENCE_OUT ) { out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); -if (out_fence_fd <0 ) { - err = out_fence_fd; - goto err_in_fence; - } +if (out_fence_fd <0 ) + goto err_ext; } err =eb_create (&eb);
@@ -3277,13 +3263,16 @@ i915_gem_do_execbuffer(struct drm_device *dev, goto err_ext; } +if (exec_fence) { + err =i915_request_await_execution (eb.request, + exec_fence); +if (err <0 ) + goto err_request; + } +if (in_fence) { -if (args->flags &I915_EXEC_FENCE_SUBMIT ) - err =i915_request_await_execution (eb.request, - in_fence); -else - err =i915_request_await_dma_fence (eb.request, - in_fence); + err =i915_request_await_dma_fence (eb.request, + in_fence);if (err <0 ) goto err_request; }
@@ -3363,8 +3352,6 @@ i915_gem_do_execbuffer(struct drm_device *dev, err_out_fence:if (out_fence_fd !=-1 )put_unused_fd (out_fence_fd); -err_in_fence: -dma_fence_put (in_fence); err_ext:put_fence_array (eb.fences, eb.num_fences);return err;
@@ -3395,6 +3382,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,struct drm_i915_private *i915 =to_i915 (dev);struct drm_i915_gem_execbuffer2 *args = data;struct drm_i915_gem_exec_object2 *exec2_list; +struct dma_fence *in_fence =NULL ; +struct dma_fence *exec_fence =NULL ;const size_t count = args->buffer_count;int err;
@@ -3419,13 +3408,33 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,if (err)return err; +if (args->flags &I915_EXEC_FENCE_IN ) { + in_fence =sync_file_get_fence (lower_32_bits (args->rsvd2)); +if (!in_fence) +return -EINVAL ; + } + +if (args->flags &I915_EXEC_FENCE_SUBMIT ) { +if (in_fence) { + err = -EINVAL ; + goto err_exec_fence; + } + + exec_fence =sync_file_get_fence (lower_32_bits (args->rsvd2)); +if (!exec_fence) { + err = -EINVAL ; + goto err_exec_fence; + } + } +/* Allocate extra slots for use by the command parser */ exec2_list =kvmalloc_array (count +2 ,eb_element_size (), __GFP_NOWARN |GFP_KERNEL );if (exec2_list ==NULL ) {drm_dbg (&i915->drm,"Failed to allocate exec list for %zd buffers\n" , count); -return -ENOMEM ; + err = -ENOMEM ; + goto err_alloc; } if (copy_from_user(exec2_list, u64_to_user_ptr(args->buffers_ptr),
@@ -3435,7 +3444,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, goto err_copy; } - err =i915_gem_do_execbuffer (dev, file, args, exec2_list); + err =i915_gem_do_execbuffer (dev, file, args, exec2_list, in_fence, + exec_fence);/* * Now that we have begun execution of the batchbuffer, we ignore
@@ -3476,12 +3486,13 @@ end:; } args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS; -kvfree (exec2_list); - -return err; err_copy:kvfree (exec2_list); +err_alloc: +dma_fence_put (exec_fence); +err_exec_fence: +dma_fence_put (in_fence);return err; }
Signature · 1 line
2.28.0
PATCH 33/46 drm/i915: Move output fence handling to i915_gem_execbuffer2
In reply to Matthew BrostMove the job of creating a new file descriptor and passing it back to userspace to i915_gem_execbuffer2.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +25 -20
@@ -3148,13 +3148,13 @@ i915_gem_do_execbuffer(struct drm_device *dev,struct drm_i915_gem_execbuffer2 *args, struct drm_i915_gem_exec_object2 *exec, struct dma_fence *in_fence, - struct dma_fence *exec_fence) + struct dma_fence *exec_fence, + int out_fence_fd) { struct drm_i915_private *i915 = to_i915(dev);struct i915_execbuffer eb;struct sync_file *out_fence =NULL ;struct i915_vma *batch; -int out_fence_fd =-1 ;int err;BUILD_BUG_ON (__EXEC_INTERNAL_FLAGS & ~__I915_EXEC_ILLEGAL_FLAGS);
@@ -3198,15 +3198,9 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (err) goto err_ext; -if (args->flags &I915_EXEC_FENCE_OUT ) { - out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); -if (out_fence_fd <0 ) - goto err_ext; - } - err =eb_create (&eb);if (err) - goto err_out_fence; + goto err_ext;GEM_BUG_ON (!eb.lut_size);
@@ -3283,7 +3277,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, goto err_request; } -if (out_fence_fd !=-1 ) { +if (out_fence_fd >=0 ) { out_fence =sync_file_create (&eb.request->fence);if (!out_fence) { err = -ENOMEM ;
@@ -3313,14 +3307,10 @@ i915_gem_do_execbuffer(struct drm_device *dev,signal_fence_array (&eb);if (out_fence) { -if (err ==0 ) { +if (err ==0 )fd_install (out_fence_fd, out_fence->file); - args->rsvd2 &=GENMASK_ULL (31 ,0 );/* keep in-fence */ - args->rsvd2 |= (u64 )out_fence_fd <<32 ; - out_fence_fd =-1 ; - }else { +else fput (out_fence->file); - } }if (unlikely (eb.gem_context->syncobj)) {
@@ -3349,9 +3339,6 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_gem_context_put (eb.gem_context); err_destroy:eb_destroy (&eb); -err_out_fence: -if (out_fence_fd !=-1 ) -put_unused_fd (out_fence_fd); err_ext:put_fence_array (eb.fences, eb.num_fences);return err;
@@ -3384,6 +3371,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,struct drm_i915_gem_exec_object2 *exec2_list;struct dma_fence *in_fence =NULL ;struct dma_fence *exec_fence =NULL ; +int out_fence_fd =-1 ;const size_t count = args->buffer_count;int err;
@@ -3427,6 +3415,14 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, } } +if (args->flags &I915_EXEC_FENCE_OUT ) { + out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); +if (out_fence_fd <0 ) { + err = out_fence_fd; + goto err_out_fence; + } + } +/* Allocate extra slots for use by the command parser */ exec2_list =kvmalloc_array (count +2 ,eb_element_size (), __GFP_NOWARN |GFP_KERNEL );
@@ -3445,7 +3441,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, } err =i915_gem_do_execbuffer (dev, file, args, exec2_list, in_fence, - exec_fence); + exec_fence, out_fence_fd);/* * Now that we have begun execution of the batchbuffer, we ignore
@@ -3485,11 +3481,20 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, end:; } +if (!err && out_fence_fd >=0 ) { + args->rsvd2 &=GENMASK_ULL (31 ,0 );/* keep in-fence */ + args->rsvd2 |= (u64 )out_fence_fd <<32 ; + out_fence_fd =-1 ; + } + args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS; err_copy:kvfree (exec2_list); err_alloc: +if (out_fence_fd >=0 ) +put_unused_fd (out_fence_fd); +err_out_fence:dma_fence_put (exec_fence); err_exec_fence:dma_fence_put (in_fence);
Signature · 1 line
2.28.0
PATCH 34/46 drm/i915: Return output fence from i915_gem_do_execbuffer
In reply to Matthew BrostMove the job of creating a new sync fence and installing it onto a file descriptor to i915_gem_execbuffer2.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +19 -20
@@ -3149,11 +3149,10 @@ i915_gem_do_execbuffer(struct drm_device *dev,struct drm_i915_gem_exec_object2 *exec, struct dma_fence *in_fence, struct dma_fence *exec_fence, - int out_fence_fd) + struct dma_fence **out_fence) { struct drm_i915_private *i915 = to_i915(dev);struct i915_execbuffer eb; -struct sync_file *out_fence =NULL ;struct i915_vma *batch;int err;
@@ -3277,14 +3276,6 @@ i915_gem_do_execbuffer(struct drm_device *dev, goto err_request; } -if (out_fence_fd >=0 ) { - out_fence =sync_file_create (&eb.request->fence); -if (!out_fence) { - err = -ENOMEM ; - goto err_request; - } - } -/* * Whilst this request exists, batch_obj will be on the * active_list, and so will hold the active reference. Only when this
@@ -3306,12 +3297,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (eb.fences)signal_fence_array (&eb); -if (out_fence) { -if (err ==0 ) -fd_install (out_fence_fd, out_fence->file); -else -fput (out_fence->file); - } +if (!err && out_fence) + *out_fence =dma_fence_get (&eb.request->fence);if (unlikely (eb.gem_context->syncobj)) { drm_syncobj_replace_fence(eb.gem_context->syncobj,
@@ -3369,6 +3356,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,struct drm_i915_private *i915 =to_i915 (dev);struct drm_i915_gem_execbuffer2 *args = data;struct drm_i915_gem_exec_object2 *exec2_list; +struct dma_fence **out_fence_p =NULL ; +struct dma_fence *out_fence =NULL ;struct dma_fence *in_fence =NULL ;struct dma_fence *exec_fence =NULL ;int out_fence_fd =-1 ;
@@ -3421,6 +3410,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, err = out_fence_fd; goto err_out_fence; } + out_fence_p = &out_fence; }/* Allocate extra slots for use by the command parser */
@@ -3441,7 +3431,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, } err =i915_gem_do_execbuffer (dev, file, args, exec2_list, in_fence, - exec_fence, out_fence_fd); + exec_fence, out_fence_p);/* * Now that we have begun execution of the batchbuffer, we ignore
@@ -3482,9 +3472,18 @@ end:; }if (!err && out_fence_fd >=0 ) { - args->rsvd2 &=GENMASK_ULL (31 ,0 );/* keep in-fence */ - args->rsvd2 |= (u64 )out_fence_fd <<32 ; - out_fence_fd =-1 ; +struct sync_file *sync_fence; + + sync_fence =sync_file_create (out_fence); +if (sync_fence) { +fd_install (out_fence_fd, sync_fence->file); + args->rsvd2 &=GENMASK_ULL (31 ,0 );/* keep in-fence */ + args->rsvd2 |= (u64 )out_fence_fd <<32 ; + out_fence_fd =-1 ; + } +dma_fence_put (out_fence); + }else if (out_fence) { +dma_fence_put (out_fence); } args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS;
Signature · 1 line
2.28.0
PATCH 35/46 drm/i915: Store batch index in struct i915_execbuffer
In reply to Matthew BrostThis will help with upcoming extensions where more than 1 batch can be submitted in a single execbuf IOCTL.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +9 -10
@@ -252,6 +252,9 @@ struct i915_execbuffer {struct eb_vma *batch;/** identity of the batch obj/vma */ struct i915_vma *trampoline;/** trampoline used for chaining */ +/* batch_index in vma list */ +unsigned int batch_index; +/** actual size of execobj[] as we may extend it for the cmdparser */ unsigned int buffer_count;
@@ -361,6 +364,11 @@ static int eb_create(struct i915_execbuffer *eb) eb->lut_size = -eb->buffer_count; } +if (eb->args->flags &I915_EXEC_BATCH_FIRST ) + eb->batch_index =0 ; +else + eb->batch_index = eb->args->buffer_count -1 ; +return 0 ; }
@@ -735,14 +743,6 @@ static int eb_reserve(struct i915_execbuffer *eb) }while (1 ); } -static unsigned int eb_batch_index (const struct i915_execbuffer *eb) -{ -if (eb->args->flags &I915_EXEC_BATCH_FIRST ) -return 0 ; -else -return eb->buffer_count -1 ; -} -static int eb_select_context (struct i915_execbuffer *eb) {struct i915_gem_context *ctx;
@@ -852,7 +852,6 @@ static struct i915_vma *eb_lookup_vma(struct i915_execbuffer *eb, u32 handle)static int eb_lookup_vmas (struct i915_execbuffer *eb) {struct drm_i915_private *i915 = eb->i915; -unsigned int batch =eb_batch_index (eb);unsigned int i;int err =0 ;
@@ -873,7 +872,7 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb) goto err; } -eb_add_vma (eb, i, batch, vma); +eb_add_vma (eb, i, eb->batch_index, vma);if (i915_gem_object_is_userptr (vma->obj)) { err =i915_gem_object_userptr_submit_init (vma->obj);
Signature · 1 line
2.28.0
PATCH 36/46 drm/i915: Allow callers of i915_gem_do_execbuffer to override the batch index
In reply to Matthew BrostAllow specifying the batch directly over what is inferred from passed in execbuf flags.
--- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +5 -1
@@ -3146,6 +3146,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,struct drm_file *file, struct drm_i915_gem_execbuffer2 *args, struct drm_i915_gem_exec_object2 *exec, + int batch_index, struct dma_fence *in_fence, struct dma_fence *exec_fence, struct dma_fence **out_fence)
@@ -3202,6 +3203,9 @@ i915_gem_do_execbuffer(struct drm_device *dev,GEM_BUG_ON (!eb.lut_size); +if (batch_index >=0 ) + eb.batch_index = batch_index; + err =eb_select_context (&eb);if (unlikely (err)) goto err_destroy;
@@ -3429,7 +3433,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, goto err_copy; } - err =i915_gem_do_execbuffer (dev, file, args, exec2_list, in_fence, + err =i915_gem_do_execbuffer (dev, file, args, exec2_list,-1 , in_fence, exec_fence, out_fence_p);/*
Signature · 1 line
2.28.0
PATCH 37/46 drm/i915: Teach execbuf there can be more than one batch in the objects list
In reply to Matthew BrostIn case of multiple batches all batches will be at the beginning in the exex objects array or at the end based on the existing execbuffer2 flag.
Batches not executed in the current execbuf call will not be processed for relocations or but will be pinned in same manner as the current batch.
This will enable multiple do_execbuf calls with a single exec object array in a later patch.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +22 -9
@@ -255,6 +255,9 @@ struct i915_execbuffer {/* batch_index in vma list */ unsigned int batch_index; +/* number of batches in execbuf IOCTL */ +unsigned int num_batches; +/** actual size of execobj[] as we may extend it for the cmdparser */ unsigned int buffer_count;
@@ -511,6 +514,14 @@ static bool platform_has_relocs_enabled(const struct i915_execbuffer *eb)return false; } +static inline bool +is_batch_buffer (struct i915_execbuffer *eb,unsigned int buffer_idx) +{ +return eb->args->flags &I915_EXEC_BATCH_FIRST ? + buffer_idx <= eb->num_batches : + buffer_idx >= eb->args->buffer_count - eb->num_batches; +} + static int eb_validate_vma(struct i915_execbuffer *eb, struct drm_i915_gem_exec_object2 *entry,
@@ -562,11 +573,10 @@ eb_validate_vma(struct i915_execbuffer *eb,static void eb_add_vma (struct i915_execbuffer *eb, -unsigned int i,unsigned batch_idx, -struct i915_vma *vma) +unsigned int buffer_idx,struct i915_vma *vma) { -struct drm_i915_gem_exec_object2 *entry = &eb->exec[i]; -struct eb_vma *ev = &eb->vma[i]; +struct drm_i915_gem_exec_object2 *entry = &eb->exec[buffer_idx]; +struct eb_vma *ev = &eb->vma[buffer_idx]; ev->vma = vma; ev->exec = entry;
@@ -591,14 +601,15 @@ eb_add_vma(struct i915_execbuffer *eb,* Note that actual hangs have only been observed on gen7, but for * paranoia do it everywhere. */ -if (i == batch_idx) { +if (is_batch_buffer (eb, buffer_idx)) {if (entry->relocation_count && !(ev->flags &EXEC_OBJECT_PINNED )) ev->flags |= __EXEC_OBJECT_NEEDS_BIAS;if (eb->reloc_cache.has_fence) ev->flags |=EXEC_OBJECT_NEEDS_FENCE ; - eb->batch = ev; +if (buffer_idx == eb->batch_index) + eb->batch = ev; } }
@@ -872,7 +883,7 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb) goto err; } -eb_add_vma (eb, i, eb->batch_index, vma); +eb_add_vma (eb, i, vma);if (i915_gem_object_is_userptr (vma->obj)) { err =i915_gem_object_userptr_submit_init (vma->obj);
@@ -3147,6 +3158,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,struct drm_i915_gem_execbuffer2 *args, struct drm_i915_gem_exec_object2 *exec, int batch_index, + unsigned int num_batches, struct dma_fence *in_fence, struct dma_fence *exec_fence, struct dma_fence **out_fence)
@@ -3203,6 +3215,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,GEM_BUG_ON (!eb.lut_size); + eb.num_batches = num_batches;if (batch_index >=0 ) eb.batch_index = batch_index;
@@ -3433,8 +3446,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, goto err_copy; } - err =i915_gem_do_execbuffer (dev, file, args, exec2_list,-1 , in_fence, - exec_fence, out_fence_p); + err =i915_gem_do_execbuffer (dev, file, args, exec2_list,-1 ,1 , + in_fence, exec_fence, out_fence_p);/* * Now that we have begun execution of the batchbuffer, we ignore
Signature · 1 line
2.28.0
PATCH 38/46 drm/i915: Only track object dependencies on first request
In reply to Matthew BrostOnly track object dependencies on the first request generated from the execbuf, this help with the upcoming multi-bb execbuf extension.
--- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +6 -5
@@ -2239,7 +2239,7 @@ static int eb_relocate_parse(struct i915_execbuffer *eb)return err; } -static int eb_move_to_gpu (struct i915_execbuffer *eb) +static int eb_move_to_gpu (struct i915_execbuffer *eb,bool first) {const unsigned int count = eb->buffer_count;unsigned int i = count;
@@ -2281,7 +2281,7 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb) flags &= ~EXEC_OBJECT_ASYNC ; } -if (err ==0 && !(flags &EXEC_OBJECT_ASYNC )) { +if (err ==0 && first && !(flags &EXEC_OBJECT_ASYNC )) { err =i915_request_await_object (eb->request, obj, flags &EXEC_OBJECT_WRITE ); }
@@ -2525,14 +2525,15 @@ static int eb_parse(struct i915_execbuffer *eb)return err; } -static int eb_submit (struct i915_execbuffer *eb,struct i915_vma *batch) +static int eb_submit (struct i915_execbuffer *eb,struct i915_vma *batch, +bool first) {int err;if (intel_context_nopreempt (eb->context))__set_bit (I915_FENCE_FLAG_NOPREEMPT , &eb->request->fence.flags); - err =eb_move_to_gpu (eb); + err =eb_move_to_gpu (eb, first);if (err)return err;
@@ -3304,7 +3305,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,intel_gt_buffer_pool_mark_active (eb.batch_pool, eb.request);trace_i915_request_queue (eb.request, eb.batch_flags); - err =eb_submit (&eb, batch); + err =eb_submit (&eb, batch, true); err_request:i915_request_get (eb.request);
Signature · 1 line
2.28.0
PATCH 39/46 drm/i915: Force parallel contexts to use copy engine for reloc
In reply to Matthew BrostSubmitting to a subset of hardware contexts is not allowed, so use the copy engine for GPU relocations when using a parallel context.
--- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +4 -2
@@ -1386,7 +1386,8 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb,if (err) goto err_unmap; -if (engine == eb->context->engine) { +if (engine == eb->context->engine && + !intel_context_is_parallel (eb->context)) { rq =i915_request_create (eb->context); }else {struct intel_context *ce = eb->reloc_context;
@@ -1483,7 +1484,8 @@ static u32 *reloc_gpu(struct i915_execbuffer *eb,if (eb_use_cmdparser (eb))return ERR_PTR (-EWOULDBLOCK ); -if (!reloc_can_use_engine (engine)) { +if (!reloc_can_use_engine (engine) || +intel_context_is_parallel (eb->context)) { engine = engine->gt->engine_class[COPY_ENGINE_CLASS ][0 ];if (!engine)return ERR_PTR (-ENODEV );
Signature · 1 line
2.28.0
Re: [PATCH 39/46] drm/i915: Force parallel contexts to use copy engine for reloc
Quoted 4 lines · Matthew Brost
Submitting to a subset of hardware contexts is not allowed, so use the copy engine for GPU relocations when using a parallel context.
Signed-off-by Matthew Brost <[email protected]>
Luckily I just pushed the patches to delete all this, so you can too. -Daniel
Quoted 31 lines
--- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +4
-2@@ -1386,7 +1386,8 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb,if (err) goto err_unmap; -if (engine == eb->context->engine) { +if (engine == eb->context->engine && + !intel_context_is_parallel (eb->context)) { rq =i915_request_create (eb->context); }else {struct intel_context *ce = eb->reloc_context;@@ -1483,7 +1484,8 @@ static u32 *reloc_gpu(struct i915_execbuffer *eb,if (eb_use_cmdparser (eb))return ERR_PTR (-EWOULDBLOCK ); -if (!reloc_can_use_engine (engine)) { +if (!reloc_can_use_engine (engine) || +intel_context_is_parallel (eb->context)) { engine = engine->gt->engine_class[COPY_ENGINE_CLASS ][0 ];if (!engine)return ERR_PTR (-ENODEV );Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 40/46 drm/i915: Multi-batch execbuffer2
In reply to Matthew BrostFor contexts with width set to two or more, we add a mode to execbuf2 which implies there are N batch buffers in the buffer list, each of which will be sent to one of the engines from the engine map array (I915_CONTEXT_PARAM_ENGINES, I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT).
Those N batches can either be first N, or last N objects in the list as controlled by the existing execbuffer2 flag.
The N batches will be submitted to consecutive engines from the previously configured allowed engine array starting at index 0.
Input and output fences are fully supported, with the latter getting signalled when all batch buffers have completed.
Last, it isn't safe for subsequent batches to touch any objects written to by a multi-BB submission until all the batches in that submission complete. As such all batches in a multi-BB submission must be combined into a single composite fence and put into the dma reseveration excl fence slot.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 262 +++++++++++++++--- drivers/gpu/drm/i915/gt/intel_context.c | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 9 + drivers/gpu/drm/i915/i915_vma.c | 13 +- drivers/gpu/drm/i915/i915_vma.h | 16 +- 5 files changed, 266 insertions(+), 39 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +231 -31
@@ -252,6 +252,9 @@ struct i915_execbuffer {struct eb_vma *batch;/** identity of the batch obj/vma */ struct i915_vma *trampoline;/** trampoline used for chaining */ +/** used for excl fence in dma_resv objects when > 1 BB submitted */ +struct dma_fence *composite_fence; +/* batch_index in vma list */ unsigned int batch_index;
@@ -367,11 +370,6 @@ static int eb_create(struct i915_execbuffer *eb) eb->lut_size = -eb->buffer_count; } -if (eb->args->flags &I915_EXEC_BATCH_FIRST ) - eb->batch_index =0 ; -else - eb->batch_index = eb->args->buffer_count -1 ; -return 0 ; }
@@ -2241,7 +2239,7 @@ static int eb_relocate_parse(struct i915_execbuffer *eb)return err; } -static int eb_move_to_gpu (struct i915_execbuffer *eb,bool first) +static int eb_move_to_gpu (struct i915_execbuffer *eb,bool first,bool last) {const unsigned int count = eb->buffer_count;unsigned int i = count;
@@ -2289,8 +2287,16 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb, bool first) }if (err ==0 ) - err =i915_vma_move_to_active (vma, eb->request, - flags | __EXEC_OBJECT_NO_RESERVE); + err =_i915_vma_move_to_active (vma, eb->request, + flags | __EXEC_OBJECT_NO_RESERVE, + !last ? +NULL : + eb->composite_fence ? + eb->composite_fence : + &eb->request->fence, + eb->composite_fence ? + eb->composite_fence : + &eb->request->fence); }#ifdef CONFIG_MMU_NOTIFIER
@@ -2528,14 +2534,14 @@ static int eb_parse(struct i915_execbuffer *eb) }static int eb_submit (struct i915_execbuffer *eb,struct i915_vma *batch, -bool first) +bool first,bool last) {int err;if (intel_context_nopreempt (eb->context))__set_bit (I915_FENCE_FLAG_NOPREEMPT , &eb->request->fence.flags); - err =eb_move_to_gpu (eb, first); + err =eb_move_to_gpu (eb, first, last);if (err)return err;
@@ -2748,7 +2754,7 @@ eb_select_legacy_ring(struct i915_execbuffer *eb) }static int -eb_select_engine (struct i915_execbuffer *eb) +eb_select_engine (struct i915_execbuffer *eb,unsigned int batch_number) {struct intel_context *ce;unsigned int idx;
@@ -2763,6 +2769,18 @@ eb_select_engine(struct i915_execbuffer *eb)if (IS_ERR (ce))return PTR_ERR (ce); +if (batch_number >0 ) { +struct intel_context *parent = ce; + +GEM_BUG_ON (!intel_context_is_parent (parent)); + +for_each_child (parent, ce) +if (!--batch_number) +break ; +intel_context_put (parent); +intel_context_get (ce); + } +intel_gt_pm_get (ce->engine->gt);if (!test_bit (CONTEXT_ALLOC_BIT , &ce->flags)) {
@@ -3155,13 +3173,49 @@ parse_execbuf2_extensions(struct drm_i915_gem_execbuffer2 *args, eb); } +static int setup_composite_fence (struct i915_execbuffer *eb, +struct dma_fence **out_fence, +unsigned int num_batches) +{ +struct dma_fence_array *fence_array; +struct dma_fence **fences =kmalloc (num_batches *sizeof (*fences), +GFP_KERNEL ); +struct intel_context *parent =intel_context_to_parent (eb->context); +int i; + +if (!fences) +return -ENOMEM ; + +for (i =0 ; i < num_batches; ++i) + fences[i] = out_fence[i]; + + fence_array =dma_fence_array_create (num_batches, + fences, + parent->fence_context, + ++parent->seqno, + false); +if (!fence_array) { +kfree (fences); +return -ENOMEM ; + } + +/* Move ownership to the dma_fence_array created above */ +for (i =0 ; i < num_batches; ++i) +dma_fence_get (fences[i]); + + eb->composite_fence = &fence_array->base; + +return 0 ; +} +static int i915_gem_do_execbuffer (struct drm_device *dev,struct drm_file *file,struct drm_i915_gem_execbuffer2 *args,struct drm_i915_gem_exec_object2 *exec, -int batch_index, +unsigned int batch_index,unsigned int num_batches, +unsigned int batch_number,struct dma_fence *in_fence,struct dma_fence *exec_fence,struct dma_fence **out_fence)
@@ -3170,6 +3224,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,struct i915_execbuffer eb;struct i915_vma *batch;int err; +bool first = batch_number ==0 ; +bool last = batch_number +1 == num_batches;BUILD_BUG_ON (__EXEC_INTERNAL_FLAGS & ~__I915_EXEC_ILLEGAL_FLAGS); BUILD_BUG_ON(__EXEC_OBJECT_INTERNAL_FLAGS &
@@ -3194,6 +3250,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.batch_start_offset = args->batch_start_offset; eb.batch_len = args->batch_len; eb.trampoline =NULL ; + eb.composite_fence =NULL ; eb.fences =NULL ; eb.num_fences =0 ;
@@ -3219,14 +3276,13 @@ i915_gem_do_execbuffer(struct drm_device *dev,GEM_BUG_ON (!eb.lut_size); eb.num_batches = num_batches; -if (batch_index >=0 ) - eb.batch_index = batch_index; + eb.batch_index = batch_index; err =eb_select_context (&eb);if (unlikely (err)) goto err_destroy; - err =eb_select_engine (&eb); + err =eb_select_engine (&eb, batch_number);if (unlikely (err)) goto err_context;
@@ -3275,6 +3331,23 @@ i915_gem_do_execbuffer(struct drm_device *dev, goto err_ext; } +if (out_fence) { +/* Move ownership to caller (i915_gem_execbuffer2_ioctl) */ + out_fence[batch_number] =dma_fence_get (&eb.request->fence); + +/* +* Need to create a composite fence (dma_fence_array, +* eb.composite_fence) for the excl fence of the dma_resv +* objects as each BB can write to the object. Since we create +*/ +if (num_batches >1 && last) { + err =setup_composite_fence (&eb, out_fence, + num_batches); +if (err <0 ) + goto err_request; + } + } +if (exec_fence) { err =i915_request_await_execution (eb.request, exec_fence);
@@ -3307,17 +3380,27 @@ i915_gem_do_execbuffer(struct drm_device *dev,intel_gt_buffer_pool_mark_active (eb.batch_pool, eb.request);trace_i915_request_queue (eb.request, eb.batch_flags); - err =eb_submit (&eb, batch, true); + err =eb_submit (&eb, batch, first, last); err_request: +if (last) +set_bit (I915_FENCE_FLAG_SUBMIT_PARALLEL , + &eb.request->fence.flags); +i915_request_get (eb.request); err =eb_request_add (&eb, err);if (eb.fences)signal_fence_array (&eb); -if (!err && out_fence) - *out_fence =dma_fence_get (&eb.request->fence); +/* +* Ownership of the composite fence (dma_fence_array, +* eb.composite_fence) has been moved to the dma_resv objects these BB +* write to in i915_vma_move_to_active. It is ok to release the creation +* reference of this fence now. +*/ +if (eb.composite_fence) +dma_fence_put (eb.composite_fence);if (unlikely (eb.gem_context->syncobj)) { drm_syncobj_replace_fence(eb.gem_context->syncobj,
@@ -3368,6 +3451,17 @@ static bool check_buffer_count(size_t count)return !(count <1 || count >INT_MAX || count >SIZE_MAX / sz -1 ); } +/* Release fences from the dma_fence_get in i915_gem_do_execbuffer. */ +static inline void put_out_fences (struct dma_fence **out_fences, +unsigned int num_batches) +{ +int i; + +for (i =0 ; i < num_batches; ++i) +if (out_fences[i]) +dma_fence_put (out_fences[i]); +} +int i915_gem_execbuffer2_ioctl (struct drm_device *dev,void *data,struct drm_file *file)
@@ -3375,13 +3469,16 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,struct drm_i915_private *i915 =to_i915 (dev);struct drm_i915_gem_execbuffer2 *args = data;struct drm_i915_gem_exec_object2 *exec2_list; -struct dma_fence **out_fence_p =NULL ; -struct dma_fence *out_fence =NULL ; +struct dma_fence **out_fences =NULL ;struct dma_fence *in_fence =NULL ;struct dma_fence *exec_fence =NULL ;int out_fence_fd =-1 ;const size_t count = args->buffer_count;int err; +struct i915_gem_context *ctx; +struct intel_context *parent =NULL ; +unsigned int num_batches =1 , i; +bool is_parallel = false;if (!check_buffer_count (count)) {drm_dbg (&i915->drm,"execbuf2 with %zd buffers\n" , count);
@@ -3404,10 +3501,39 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,if (err)return err; + ctx =i915_gem_context_lookup (file->driver_priv, args->rsvd1); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); + +if (i915_gem_context_user_engines (ctx)) { + parent =i915_gem_context_get_engine (ctx, args->flags & +I915_EXEC_RING_MASK ); +if (IS_ERR (parent)) { + err =PTR_ERR (parent); + goto err_context; + } + +if (intel_context_is_parent (parent)) { +if (args->batch_len) { + err = -EINVAL ; + goto err_context; + } + + num_batches = parent->guc_number_children +1 ; +if (num_batches > count) { +i915_gem_context_put (ctx); + goto err_parent; + } + is_parallel = true; + } + } +if (args->flags &I915_EXEC_FENCE_IN ) { in_fence =sync_file_get_fence (lower_32_bits (args->rsvd2)); -if (!in_fence) -return -EINVAL ; +if (!in_fence) { + err = -EINVAL ; + goto err_parent; + } }if (args->flags &I915_EXEC_FENCE_SUBMIT ) {
@@ -3423,13 +3549,25 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, } } -if (args->flags &I915_EXEC_FENCE_OUT ) { - out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); -if (out_fence_fd <0 ) { - err = out_fence_fd; +/* +* We always allocate out fences when doing multi-BB submission as +* this is required to create an excl fence for any dma buf objects +* these BBs touch. +*/ +if (args->flags &I915_EXEC_FENCE_OUT || is_parallel) { + out_fences =kcalloc (num_batches,sizeof (*out_fences), +GFP_KERNEL ); +if (!out_fences) { + err = -ENOMEM ; goto err_out_fence; } - out_fence_p = &out_fence; +if (args->flags &I915_EXEC_FENCE_OUT ) { + out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); +if (out_fence_fd <0 ) { + err = out_fence_fd; + goto err_out_fence; + } + } }/* Allocate extra slots for use by the command parser */
@@ -3449,8 +3587,35 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, goto err_copy; } - err =i915_gem_do_execbuffer (dev, file, args, exec2_list,-1 ,1 , - in_fence, exec_fence, out_fence_p); +/* +* Downstream submission code expects all parallel submissions to occur +* in intel_context sequence, thus only 1 submission can happen at a +* time. +*/ +if (is_parallel) +mutex_lock (&parent->parallel_submit); + + err =i915_gem_do_execbuffer (dev, file, args, exec2_list, + args->flags &I915_EXEC_BATCH_FIRST ? +0 : count - num_batches, + num_batches, +0 , + in_fence, + exec_fence, + out_fences); + +for (i =1 ; err ==0 && i < num_batches; i++) + err =i915_gem_do_execbuffer (dev, file, args, exec2_list, + args->flags &I915_EXEC_BATCH_FIRST ? + i : count - num_batches + i, + num_batches, + i, +NULL , +NULL , + out_fences); + +if (is_parallel) +mutex_unlock (&parent->parallel_submit);/* * Now that we have begun execution of the batchbuffer, we ignore
@@ -3491,8 +3656,31 @@ end:; }if (!err && out_fence_fd >=0 ) { +struct dma_fence *out_fence =NULL ;struct sync_file *sync_fence; +if (is_parallel) { +struct dma_fence_array *fence_array; + +/* +* The dma_fence_array now owns out_fences (from +* dma_fence_get in i915_gem_do_execbuffer) assuming +* successful creation of dma_fence_array. +*/ + fence_array =dma_fence_array_create (num_batches, + out_fences, + parent->fence_context, + ++parent->seqno, + false); +if (!fence_array) + goto put_out_fences; + + out_fence = &fence_array->base; + out_fences =NULL ; + }else { + out_fence = out_fences[0 ]; + } + sync_fence =sync_file_create (out_fence);if (sync_fence) {fd_install (out_fence_fd, sync_fence->file);
@@ -3500,9 +3688,15 @@ end:; args->rsvd2 |= (u64 )out_fence_fd <<32 ; out_fence_fd =-1 ; } + +/* +* The sync_file now owns out_fence, drop the creation +* reference. +*/ dma_fence_put (out_fence); - }else if (out_fence) { -dma_fence_put (out_fence); + }else if (out_fences) { +put_out_fences: +put_out_fences (out_fences, num_batches); } args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS;
@@ -3513,9 +3707,15 @@ end:;if (out_fence_fd >=0 )put_unused_fd (out_fence_fd); err_out_fence: +kfree (out_fences);dma_fence_put (exec_fence); err_exec_fence:dma_fence_put (in_fence); +err_parent: +if (parent) +intel_context_put (parent); +err_context: +i915_gem_context_put (ctx);return err; }
drivers/gpu/drm/i915/gt/intel_context.c +5 -0
@@ -472,6 +472,9 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link); +mutex_init (&ce->parallel_submit); + ce->fence_context =dma_fence_context_alloc (1 ); +/* * Initialize fence to be complete as this is expected to be complete * unless there is a pending schedule disable outstanding.
@@ -498,6 +501,8 @@ void intel_context_fini(struct intel_context *ce)for_each_child_safe (ce, child, next)intel_context_put (child); +mutex_destroy (&ce->parallel_submit); +mutex_destroy (&ce->pin_mutex);i915_active_fini (&ce->active); }
drivers/gpu/drm/i915/gt/intel_context_types.h +9 -0
@@ -235,6 +235,15 @@ struct intel_context {/* Last request submitted on a parent */ struct i915_request *last_rq; + +/* Parallel submission mutex */ +struct mutex parallel_submit; + +/* Fence context for parallel submission */ +u64 fence_context; + +/* Seqno for parallel submission */ + u32 seqno; };#endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/i915_vma.c +8 -5
@@ -1234,9 +1234,11 @@ int __i915_vma_move_to_active(struct i915_vma *vma, struct i915_request *rq)return i915_active_add_request (&vma->active, rq); } -int i915_vma_move_to_active (struct i915_vma *vma, -struct i915_request *rq, -unsigned int flags) +int _i915_vma_move_to_active (struct i915_vma *vma, +struct i915_request *rq, +unsigned int flags, +struct dma_fence *shared_fence, +struct dma_fence *excl_fence) {struct drm_i915_gem_object *obj = vma->obj;int err;
@@ -1257,7 +1259,7 @@ int i915_vma_move_to_active(struct i915_vma *vma,intel_frontbuffer_put (front); } -dma_resv_add_excl_fence (vma->resv, &rq->fence); +dma_resv_add_excl_fence (vma->resv, excl_fence); obj->write_domain =I915_GEM_DOMAIN_RENDER ; obj->read_domains =0 ; }else {
@@ -1267,7 +1269,8 @@ int i915_vma_move_to_active(struct i915_vma *vma,return err; } -dma_resv_add_shared_fence (vma->resv, &rq->fence); +if (shared_fence) +dma_resv_add_shared_fence (vma->resv, shared_fence); obj->write_domain =0 ; }
drivers/gpu/drm/i915/i915_vma.h +13 -3
@@ -57,9 +57,19 @@ static inline bool i915_vma_is_active(const struct i915_vma *vma)int __must_check __i915_vma_move_to_active (struct i915_vma *vma,struct i915_request *rq); -int __must_check i915_vma_move_to_active (struct i915_vma *vma, -struct i915_request *rq, -unsigned int flags); + +int __must_check _i915_vma_move_to_active (struct i915_vma *vma, +struct i915_request *rq, +unsigned int flags, +struct dma_fence *shared_fence, +struct dma_fence *excl_fence); +static inline int __must_check +i915_vma_move_to_active (struct i915_vma *vma, +struct i915_request *rq, +unsigned int flags) +{ +return _i915_vma_move_to_active (vma, rq, flags, &rq->fence, &rq->fence); +}#define __i915_vma_flags (v) ((unsigned long *)&(v)->flags.counter)
Signature · 1 line
2.28.0
Re: [PATCH 40/46] drm/i915: Multi-batch execbuffer2
Quoted 14 lines · Matthew Brost
For contexts with width set to two or more, we add a mode to execbuf2 which implies there are N batch buffers in the buffer list, each of which will be sent to one of the engines from the engine map array (
I915_CONTEXT_PARAM_ENGINES,I915_CONTEXT_ENGINES_EXT_PARALLEL_SUBMIT).Those N batches can either be first N, or last N objects in the list as controlled by the existing execbuffer2 flag.
The N batches will be submitted to consecutive engines from the previously configured allowed engine array starting at index 0.
Input and output fences are fully supported, with the latter getting signalled when all batch buffers have completed.
Quoted 8 lines
Last, it isn't safe for subsequent batches to touch any objects written to by a multi-BB submission until all the batches in that submission complete. As such all batches in a multi-BB submission must be combined into a single composite fence and put into the dma reseveration excl fence slot.
Suggested-by Tvrtko Ursulin <[email protected]>Signed-off-by Matthew Brost <[email protected]>
So either I've missed something, or this has the exact deadlock issue as the old submit fence, except it's all internally in the kmd.
Also, this is bad news (if I'm right about what's going on here).
- Between each batch submission we drop the dma_resv_locks on the objects. This can currently even happen due to relocations within a submission, but since we don't allow relocations on platforms with parallel submit/guc scheduler, this could be worked around.
- When the buffer is unlocked someone else could step in and do exactly what you say is not allowed, namely touch the object.
- The indivual batch fences won't completely until the last one has finished, leading to a deadlock which might or might not get resolved by gpu reset code. Since the deadlock is on the submission side I'm assuming the answer is "it won't be resolved by gpu reset", but maybe you do have a "I'm stuck for too long, let's ragequit" timer in your state machine somewhere. Old bonded submit would be rescued by the hangcheck we readded at least because there it's all completely free-floating requests.
- ttm on dgpu makes this all substantially worse.
The fundamental fix is still to build up a single i915_request, go through the execbuf flow once, and then split things up again in the backend. That would also mean all your prep work to pull execbuf prep step out of do_execbuf() is a pure distraction.
I'm not yet fully understanding all the ordering rules drm/sched has, but I don't think it will be any happier about this kind of submission model.
tldr; what do?
Cheers, Daniel
Quoted 572 lines
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 262 +++++++++++++++--- drivers/gpu/drm/i915/gt/intel_context.c | 5 + drivers/gpu/drm/i915/gt/intel_context_types.h | 9 + drivers/gpu/drm/i915/i915_vma.c | 13 +- drivers/gpu/drm/i915/i915_vma.h | 16 +- 5 files changed, 266 insertions(+), 39 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +231
-31@@ -252,6 +252,9 @@ struct i915_execbuffer {struct eb_vma *batch;/** identity of the batch obj/vma */ struct i915_vma *trampoline;/** trampoline used for chaining */ +/** used for excl fence in dma_resv objects when > 1 BB submitted */ +struct dma_fence *composite_fence; +/* batch_index in vma list */ unsigned int batch_index;@@ -367,11 +370,6 @@ static int eb_create(struct i915_execbuffer *eb) eb->lut_size = -eb->buffer_count; } -if (eb->args->flags &I915_EXEC_BATCH_FIRST ) - eb->batch_index =0 ; -else - eb->batch_index = eb->args->buffer_count -1 ; -return 0 ; }@@ -2241,7 +2239,7 @@ static int eb_relocate_parse(struct i915_execbuffer *eb)return err; } -static int eb_move_to_gpu (struct i915_execbuffer *eb,bool first) +static int eb_move_to_gpu (struct i915_execbuffer *eb,bool first,bool last) {const unsigned int count = eb->buffer_count;unsigned int i = count;@@ -2289,8 +2287,16 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb, bool first) }if (err ==0 ) - err =i915_vma_move_to_active (vma, eb->request, - flags | __EXEC_OBJECT_NO_RESERVE); + err =_i915_vma_move_to_active (vma, eb->request, + flags | __EXEC_OBJECT_NO_RESERVE, + !last ? +NULL : + eb->composite_fence ? + eb->composite_fence : + &eb->request->fence, + eb->composite_fence ? + eb->composite_fence : + &eb->request->fence); }#ifdef CONFIG_MMU_NOTIFIER @@ -2528,14 +2534,14 @@ static int eb_parse(struct i915_execbuffer *eb) }static int eb_submit (struct i915_execbuffer *eb,struct i915_vma *batch, -bool first) +bool first,bool last) {int err;if (intel_context_nopreempt (eb->context))__set_bit (I915_FENCE_FLAG_NOPREEMPT , &eb->request->fence.flags); - err =eb_move_to_gpu (eb, first); + err =eb_move_to_gpu (eb, first, last);if (err)return err;@@ -2748,7 +2754,7 @@ eb_select_legacy_ring(struct i915_execbuffer *eb) }static int -eb_select_engine (struct i915_execbuffer *eb) +eb_select_engine (struct i915_execbuffer *eb,unsigned int batch_number) {struct intel_context *ce;unsigned int idx;@@ -2763,6 +2769,18 @@ eb_select_engine(struct i915_execbuffer *eb)if (IS_ERR (ce))return PTR_ERR (ce); +if (batch_number >0 ) { +struct intel_context *parent = ce; + +GEM_BUG_ON (!intel_context_is_parent (parent)); + +for_each_child (parent, ce) +if (!--batch_number) +break ; +intel_context_put (parent); +intel_context_get (ce); + } +intel_gt_pm_get (ce->engine->gt);if (!test_bit (CONTEXT_ALLOC_BIT , &ce->flags)) {@@ -3155,13 +3173,49 @@ parse_execbuf2_extensions(struct drm_i915_gem_execbuffer2 *args, eb); } +static int setup_composite_fence (struct i915_execbuffer *eb, +struct dma_fence **out_fence, +unsigned int num_batches) +{ +struct dma_fence_array *fence_array; +struct dma_fence **fences =kmalloc (num_batches *sizeof (*fences), +GFP_KERNEL ); +struct intel_context *parent =intel_context_to_parent (eb->context); +int i; + +if (!fences) +return -ENOMEM ; + +for (i =0 ; i < num_batches; ++i) + fences[i] = out_fence[i]; + + fence_array =dma_fence_array_create (num_batches, + fences, + parent->fence_context, + ++parent->seqno, + false); +if (!fence_array) { +kfree (fences); +return -ENOMEM ; + } + +/* Move ownership to the dma_fence_array created above */ +for (i =0 ; i < num_batches; ++i) +dma_fence_get (fences[i]); + + eb->composite_fence = &fence_array->base; + +return 0 ; +} +static int i915_gem_do_execbuffer (struct drm_device *dev,struct drm_file *file,struct drm_i915_gem_execbuffer2 *args,struct drm_i915_gem_exec_object2 *exec, -int batch_index, +unsigned int batch_index,unsigned int num_batches, +unsigned int batch_number,struct dma_fence *in_fence,struct dma_fence *exec_fence,struct dma_fence **out_fence)@@ -3170,6 +3224,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,struct i915_execbuffer eb;struct i915_vma *batch;int err; +bool first = batch_number ==0 ; +bool last = batch_number +1 == num_batches;BUILD_BUG_ON (__EXEC_INTERNAL_FLAGS & ~__I915_EXEC_ILLEGAL_FLAGS); BUILD_BUG_ON(__EXEC_OBJECT_INTERNAL_FLAGS &@@ -3194,6 +3250,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.batch_start_offset = args->batch_start_offset; eb.batch_len = args->batch_len; eb.trampoline =NULL ; + eb.composite_fence =NULL ; eb.fences =NULL ; eb.num_fences =0 ;@@ -3219,14 +3276,13 @@ i915_gem_do_execbuffer(struct drm_device *dev,GEM_BUG_ON (!eb.lut_size); eb.num_batches = num_batches; -if (batch_index >=0 ) - eb.batch_index = batch_index; + eb.batch_index = batch_index; err =eb_select_context (&eb);if (unlikely (err)) goto err_destroy; - err =eb_select_engine (&eb); + err =eb_select_engine (&eb, batch_number);if (unlikely (err)) goto err_context;@@ -3275,6 +3331,23 @@ i915_gem_do_execbuffer(struct drm_device *dev, goto err_ext; } +if (out_fence) { +/* Move ownership to caller (i915_gem_execbuffer2_ioctl) */ + out_fence[batch_number] =dma_fence_get (&eb.request->fence); + +/* +* Need to create a composite fence (dma_fence_array, +* eb.composite_fence) for the excl fence of the dma_resv +* objects as each BB can write to the object. Since we create +*/ +if (num_batches >1 && last) { + err =setup_composite_fence (&eb, out_fence, + num_batches); +if (err <0 ) + goto err_request; + } + } +if (exec_fence) { err =i915_request_await_execution (eb.request, exec_fence);@@ -3307,17 +3380,27 @@ i915_gem_do_execbuffer(struct drm_device *dev,intel_gt_buffer_pool_mark_active (eb.batch_pool, eb.request);trace_i915_request_queue (eb.request, eb.batch_flags); - err =eb_submit (&eb, batch, true); + err =eb_submit (&eb, batch, first, last); err_request: +if (last) +set_bit (I915_FENCE_FLAG_SUBMIT_PARALLEL , + &eb.request->fence.flags); +i915_request_get (eb.request); err =eb_request_add (&eb, err);if (eb.fences)signal_fence_array (&eb); -if (!err && out_fence) - *out_fence =dma_fence_get (&eb.request->fence); +/* +* Ownership of the composite fence (dma_fence_array, +* eb.composite_fence) has been moved to the dma_resv objects these BB +* write to in i915_vma_move_to_active. It is ok to release the creation +* reference of this fence now. +*/ +if (eb.composite_fence) +dma_fence_put (eb.composite_fence);if (unlikely (eb.gem_context->syncobj)) { drm_syncobj_replace_fence(eb.gem_context->syncobj,@@ -3368,6 +3451,17 @@ static bool check_buffer_count(size_t count)return !(count <1 || count >INT_MAX || count >SIZE_MAX / sz -1 ); } +/* Release fences from the dma_fence_get in i915_gem_do_execbuffer. */ +static inline void put_out_fences (struct dma_fence **out_fences, +unsigned int num_batches) +{ +int i; + +for (i =0 ; i < num_batches; ++i) +if (out_fences[i]) +dma_fence_put (out_fences[i]); +} +int i915_gem_execbuffer2_ioctl (struct drm_device *dev,void *data,struct drm_file *file)@@ -3375,13 +3469,16 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,struct drm_i915_private *i915 =to_i915 (dev);struct drm_i915_gem_execbuffer2 *args = data;struct drm_i915_gem_exec_object2 *exec2_list; -struct dma_fence **out_fence_p =NULL ; -struct dma_fence *out_fence =NULL ; +struct dma_fence **out_fences =NULL ;struct dma_fence *in_fence =NULL ;struct dma_fence *exec_fence =NULL ;int out_fence_fd =-1 ;const size_t count = args->buffer_count;int err; +struct i915_gem_context *ctx; +struct intel_context *parent =NULL ; +unsigned int num_batches =1 , i; +bool is_parallel = false;if (!check_buffer_count (count)) {drm_dbg (&i915->drm,"execbuf2 with %zd buffers\n" , count);@@ -3404,10 +3501,39 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,if (err)return err; + ctx =i915_gem_context_lookup (file->driver_priv, args->rsvd1); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); + +if (i915_gem_context_user_engines (ctx)) { + parent =i915_gem_context_get_engine (ctx, args->flags & +I915_EXEC_RING_MASK ); +if (IS_ERR (parent)) { + err =PTR_ERR (parent); + goto err_context; + } + +if (intel_context_is_parent (parent)) { +if (args->batch_len) { + err = -EINVAL ; + goto err_context; + } + + num_batches = parent->guc_number_children +1 ; +if (num_batches > count) { +i915_gem_context_put (ctx); + goto err_parent; + } + is_parallel = true; + } + } +if (args->flags &I915_EXEC_FENCE_IN ) { in_fence =sync_file_get_fence (lower_32_bits (args->rsvd2)); -if (!in_fence) -return -EINVAL ; +if (!in_fence) { + err = -EINVAL ; + goto err_parent; + } }if (args->flags &I915_EXEC_FENCE_SUBMIT ) {@@ -3423,13 +3549,25 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, } } -if (args->flags &I915_EXEC_FENCE_OUT ) { - out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); -if (out_fence_fd <0 ) { - err = out_fence_fd; +/* +* We always allocate out fences when doing multi-BB submission as +* this is required to create an excl fence for any dma buf objects +* these BBs touch. +*/ +if (args->flags &I915_EXEC_FENCE_OUT || is_parallel) { + out_fences =kcalloc (num_batches,sizeof (*out_fences), +GFP_KERNEL ); +if (!out_fences) { + err = -ENOMEM ; goto err_out_fence; } - out_fence_p = &out_fence; +if (args->flags &I915_EXEC_FENCE_OUT ) { + out_fence_fd =get_unused_fd_flags (O_CLOEXEC ); +if (out_fence_fd <0 ) { + err = out_fence_fd; + goto err_out_fence; + } + } }/* Allocate extra slots for use by the command parser */ @@ -3449,8 +3587,35 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, goto err_copy; } - err =i915_gem_do_execbuffer (dev, file, args, exec2_list,-1 ,1 , - in_fence, exec_fence, out_fence_p); +/* +* Downstream submission code expects all parallel submissions to occur +* in intel_context sequence, thus only 1 submission can happen at a +* time. +*/ +if (is_parallel) +mutex_lock (&parent->parallel_submit); + + err =i915_gem_do_execbuffer (dev, file, args, exec2_list, + args->flags &I915_EXEC_BATCH_FIRST ? +0 : count - num_batches, + num_batches, +0 , + in_fence, + exec_fence, + out_fences); + +for (i =1 ; err ==0 && i < num_batches; i++) + err =i915_gem_do_execbuffer (dev, file, args, exec2_list, + args->flags &I915_EXEC_BATCH_FIRST ? + i : count - num_batches + i, + num_batches, + i, +NULL , +NULL , + out_fences); + +if (is_parallel) +mutex_unlock (&parent->parallel_submit);/* * Now that we have begun execution of the batchbuffer, we ignore @@ -3491,8 +3656,31 @@ end:; }if (!err && out_fence_fd >=0 ) { +struct dma_fence *out_fence =NULL ;struct sync_file *sync_fence; +if (is_parallel) { +struct dma_fence_array *fence_array; + +/* +* The dma_fence_array now owns out_fences (from +* dma_fence_get in i915_gem_do_execbuffer) assuming +* successful creation of dma_fence_array. +*/ + fence_array =dma_fence_array_create (num_batches, + out_fences, + parent->fence_context, + ++parent->seqno, + false); +if (!fence_array) + goto put_out_fences; + + out_fence = &fence_array->base; + out_fences =NULL ; + }else { + out_fence = out_fences[0 ]; + } + sync_fence =sync_file_create (out_fence);if (sync_fence) {fd_install (out_fence_fd, sync_fence->file);@@ -3500,9 +3688,15 @@ end:; args->rsvd2 |= (u64 )out_fence_fd <<32 ; out_fence_fd =-1 ; } + +/* +* The sync_file now owns out_fence, drop the creation +* reference. +*/ dma_fence_put (out_fence); - }else if (out_fence) { -dma_fence_put (out_fence); + }else if (out_fences) { +put_out_fences: +put_out_fences (out_fences, num_batches); } args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS;@@ -3513,9 +3707,15 @@ end:;if (out_fence_fd >=0 )put_unused_fd (out_fence_fd); err_out_fence: +kfree (out_fences);dma_fence_put (exec_fence); err_exec_fence:dma_fence_put (in_fence); +err_parent: +if (parent) +intel_context_put (parent); +err_context: +i915_gem_context_put (ctx);return err; }drivers/gpu/drm/i915/gt/intel_context.c +5
-0@@ -472,6 +472,9 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link); +mutex_init (&ce->parallel_submit); + ce->fence_context =dma_fence_context_alloc (1 ); +/* * Initialize fence to be complete as this is expected to be complete * unless there is a pending schedule disable outstanding. @@ -498,6 +501,8 @@ void intel_context_fini(struct intel_context *ce)for_each_child_safe (ce, child, next)intel_context_put (child); +mutex_destroy (&ce->parallel_submit); +mutex_destroy (&ce->pin_mutex);i915_active_fini (&ce->active); }drivers/gpu/drm/i915/gt/intel_context_types.h +9
-0@@ -235,6 +235,15 @@ struct intel_context {/* Last request submitted on a parent */ struct i915_request *last_rq; + +/* Parallel submission mutex */ +struct mutex parallel_submit; + +/* Fence context for parallel submission */ +u64 fence_context; + +/* Seqno for parallel submission */ + u32 seqno; };#endif /* __INTEL_CONTEXT_TYPES__ */ drivers/gpu/drm/i915/i915_vma.c +8
-5@@ -1234,9 +1234,11 @@ int __i915_vma_move_to_active(struct i915_vma *vma, struct i915_request *rq)return i915_active_add_request (&vma->active, rq); } -int i915_vma_move_to_active (struct i915_vma *vma, -struct i915_request *rq, -unsigned int flags) +int _i915_vma_move_to_active (struct i915_vma *vma, +struct i915_request *rq, +unsigned int flags, +struct dma_fence *shared_fence, +struct dma_fence *excl_fence) {struct drm_i915_gem_object *obj = vma->obj;int err;@@ -1257,7 +1259,7 @@ int i915_vma_move_to_active(struct i915_vma *vma,intel_frontbuffer_put (front); } -dma_resv_add_excl_fence (vma->resv, &rq->fence); +dma_resv_add_excl_fence (vma->resv, excl_fence); obj->write_domain =I915_GEM_DOMAIN_RENDER ; obj->read_domains =0 ; }else {@@ -1267,7 +1269,8 @@ int i915_vma_move_to_active(struct i915_vma *vma,return err; } -dma_resv_add_shared_fence (vma->resv, &rq->fence); +if (shared_fence) +dma_resv_add_shared_fence (vma->resv, shared_fence); obj->write_domain =0 ; }drivers/gpu/drm/i915/i915_vma.h +13
-3@@ -57,9 +57,19 @@ static inline bool i915_vma_is_active(const struct i915_vma *vma)int __must_check __i915_vma_move_to_active (struct i915_vma *vma,struct i915_request *rq); -int __must_check i915_vma_move_to_active (struct i915_vma *vma, -struct i915_request *rq, -unsigned int flags); + +int __must_check _i915_vma_move_to_active (struct i915_vma *vma, +struct i915_request *rq, +unsigned int flags, +struct dma_fence *shared_fence, +struct dma_fence *excl_fence); +static inline int __must_check +i915_vma_move_to_active (struct i915_vma *vma, +struct i915_request *rq, +unsigned int flags) +{ +return _i915_vma_move_to_active (vma, rq, flags, &rq->fence, &rq->fence); +}#define __i915_vma_flags (v) ((unsigned long *)&(v)->flags.counter)Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 41/46 drm/i915: Eliminate unnecessary VMA calls for multi-BB submission
In reply to Matthew BrostCertain VMA functions in the execbuf IOCTL only need to be called on first or last BB of a multi-BB submission. eb_relocate() on the first and eb_release_vmas() on the last. Doing so will save CPU / GPU cycles.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 127 +++++++++++------- .../i915/gem/selftests/i915_gem_execbuffer.c | 14 +- 2 files changed, 83 insertions(+), 58 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +75 -52
@@ -270,7 +270,7 @@ struct i915_execbuffer {/** list of vma that have execobj.relocation_count */ struct list_head relocs; -struct i915_gem_ww_ctx ww; +struct i915_gem_ww_ctx *ww;/** * Track the most recently used object for relocations, as we
@@ -448,7 +448,7 @@ eb_pin_vma(struct i915_execbuffer *eb, pin_flags |=PIN_GLOBAL ;/* Attempt to reuse the current location if available */ - err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 , pin_flags); + err =i915_vma_pin_ww (vma, eb->ww,0 ,0 , pin_flags);if (err == -EDEADLK )return err;
@@ -457,11 +457,11 @@ eb_pin_vma(struct i915_execbuffer *eb,return err;/* Failing that pick any _free_ space if suitable */ - err =i915_vma_pin_ww (vma, &eb->ww, - entry->pad_to_size, - entry->alignment, -eb_pin_flags (entry, ev->flags) | -PIN_USER |PIN_NOEVICT ); + err =i915_vma_pin_ww (vma, eb->ww, + entry->pad_to_size, + entry->alignment, +eb_pin_flags (entry, ev->flags) | +PIN_USER |PIN_NOEVICT );if (unlikely (err))return err; }
@@ -643,9 +643,9 @@ static int eb_reserve_vma(struct i915_execbuffer *eb,return err; } - err =i915_vma_pin_ww (vma, &eb->ww, - entry->pad_to_size, entry->alignment, -eb_pin_flags (entry, ev->flags) | pin_flags); + err =i915_vma_pin_ww (vma, eb->ww, + entry->pad_to_size, entry->alignment, +eb_pin_flags (entry, ev->flags) | pin_flags);if (err)return err;
@@ -940,7 +940,7 @@ static int eb_lock_vmas(struct i915_execbuffer *eb)struct eb_vma *ev = &eb->vma[i];struct i915_vma *vma = ev->vma; - err =i915_gem_object_lock (vma->obj, &eb->ww); + err =i915_gem_object_lock (vma->obj, eb->ww);if (err)return err; }
@@ -1020,12 +1020,13 @@ eb_get_vma(const struct i915_execbuffer *eb, unsigned long handle) } } -static void eb_release_vmas (struct i915_execbuffer *eb,bool final) +static void eb_release_vmas (struct i915_execbuffer *eb,bool final, +bool unreserve) {const unsigned int count = eb->buffer_count;unsigned int i; -for (i =0 ; i < count; i++) { +for (i =0 ; unreserve && i < count; i++) {struct eb_vma *ev = &eb->vma[i];struct i915_vma *vma = ev->vma;
@@ -1237,7 +1238,7 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj,if (err)return ERR_PTR (err); - vma =i915_gem_object_ggtt_pin_ww (obj, &eb->ww,NULL ,0 ,0 , + vma =i915_gem_object_ggtt_pin_ww (obj, eb->ww,NULL ,0 ,0 ,PIN_MAPPABLE |PIN_NONBLOCK /* NOWARN */ |PIN_NOEVICT );
@@ -1361,7 +1362,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, } eb->reloc_pool =NULL ; - err =i915_gem_object_lock (pool->obj, &eb->ww); + err =i915_gem_object_lock (pool->obj, eb->ww);if (err) goto err_pool;
@@ -1380,7 +1381,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, goto err_unmap; } - err =i915_vma_pin_ww (batch, &eb->ww,0 ,0 ,PIN_USER |PIN_NONBLOCK ); + err =i915_vma_pin_ww (batch, eb->ww,0 ,0 ,PIN_USER |PIN_NONBLOCK );if (err) goto err_unmap;
@@ -1402,7 +1403,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, eb->reloc_context = ce; } - err =intel_context_pin_ww (ce, &eb->ww); + err =intel_context_pin_ww (ce, eb->ww);if (err) goto err_unpin;
@@ -2017,8 +2018,8 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, }/* We may process another execbuffer during the unlock... */ -eb_release_vmas (eb, false); -i915_gem_ww_ctx_fini (&eb->ww); +eb_release_vmas (eb, false, true); +i915_gem_ww_ctx_fini (eb->ww);if (rq) {/* nonblocking is always false */
@@ -2062,7 +2063,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err =eb_reinit_userptr (eb); err_relock: -i915_gem_ww_ctx_init (&eb->ww, true); +i915_gem_ww_ctx_init (eb->ww, true);if (err) goto out;
@@ -2119,8 +2120,8 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); - err =i915_gem_ww_ctx_backoff (&eb->ww); +eb_release_vmas (eb, false, true); + err =i915_gem_ww_ctx_backoff (eb->ww);if (!err) goto repeat_validate; }
@@ -2152,7 +2153,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb,return err; } -static int eb_relocate_parse (struct i915_execbuffer *eb) +static int eb_relocate_parse (struct i915_execbuffer *eb,bool first) {int err;struct i915_request *rq =NULL ;
@@ -2189,14 +2190,16 @@ static int eb_relocate_parse(struct i915_execbuffer *eb)/* only throttle once, even if we didn't need to throttle */ throttle = false; - err =eb_validate_vmas (eb); -if (err == -EAGAIN ) - goto slow; -else if (err) - goto err; +if (first) { + err =eb_validate_vmas (eb); +if (err == -EAGAIN ) + goto slow; +else if (err) + goto err; + }/* The objects are in their final locations, apply the relocations. */ -if (eb->args->flags & __EXEC_HAS_RELOC) { +if (eb->args->flags & __EXEC_HAS_RELOC && first) {struct eb_vma *ev;list_for_each_entry (ev, &eb->relocs, reloc_link) {
@@ -2211,13 +2214,13 @@ static int eb_relocate_parse(struct i915_execbuffer *eb) goto slow; } -if (!err) +if (!err && first) err =eb_parse (eb); err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); - err =i915_gem_ww_ctx_backoff (&eb->ww); +eb_release_vmas (eb, false, true); + err =i915_gem_ww_ctx_backoff (eb->ww);if (!err) goto retry; }
@@ -2398,7 +2401,7 @@ shadow_batch_pin(struct i915_execbuffer *eb,if (IS_ERR (vma))return vma; - err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 , flags); + err =i915_vma_pin_ww (vma, eb->ww,0 ,0 , flags);if (err)return ERR_PTR (err);
@@ -2412,7 +2415,7 @@ static struct i915_vma *eb_dispatch_secure(struct i915_execbuffer *eb, struct i9* batch" bit. Hence we need to pin secure batches into the global gtt. * hsw should have this fixed, but bdw mucks it up again. */ if (eb->batch_flags &I915_DISPATCH_SECURE ) -return i915_gem_object_ggtt_pin_ww (vma->obj, &eb->ww,NULL ,0 ,0 ,0 ); +return i915_gem_object_ggtt_pin_ww (vma->obj, eb->ww,NULL ,0 ,0 ,0 );return NULL ; }
@@ -2458,7 +2461,7 @@ static int eb_parse(struct i915_execbuffer *eb) eb->batch_pool = pool; } - err =i915_gem_object_lock (pool->obj, &eb->ww); + err =i915_gem_object_lock (pool->obj, eb->ww);if (err) goto err;
@@ -2666,7 +2669,7 @@ static struct i915_request *eb_pin_engine(struct i915_execbuffer *eb, bool throt* GGTT space, so do this first before we reserve a seqno for * ourselves. */ - err =intel_context_pin_ww (ce, &eb->ww); + err =intel_context_pin_ww (ce, eb->ww);if (err)return ERR_PTR (err);
@@ -3218,7 +3221,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,unsigned int batch_number, struct dma_fence *in_fence, struct dma_fence *exec_fence, - struct dma_fence **out_fence) + struct dma_fence **out_fence, + struct i915_gem_ww_ctx *ww) { struct drm_i915_private *i915 = to_i915(dev);struct i915_execbuffer eb;
@@ -3239,7 +3243,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.exec = exec; eb.vma = (struct eb_vma *)(exec + args->buffer_count +1 ); - eb.vma[0 ].vma =NULL ; +if (first) + eb.vma[0 ].vma =NULL ; eb.reloc_pool = eb.batch_pool =NULL ; eb.reloc_context =NULL ;
@@ -3251,6 +3256,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.batch_len = args->batch_len; eb.trampoline =NULL ; eb.composite_fence =NULL ; + eb.ww = ww; eb.fences =NULL ; eb.num_fences =0 ;
@@ -3269,9 +3275,14 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (err) goto err_ext; - err =eb_create (&eb); -if (err) - goto err_ext; +if (first) { + err =eb_create (&eb); +if (err) + goto err_ext; + }else { + eb.lut_size = -eb.buffer_count; + } +GEM_BUG_ON (!eb.lut_size);
@@ -3286,15 +3297,22 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (unlikely (err)) goto err_context; - err =eb_lookup_vmas (&eb); -if (err) { -eb_release_vmas (&eb, true); - goto err_engine; +if (first) { + err =eb_lookup_vmas (&eb); +if (err) { +eb_release_vmas (&eb, true, true); + goto err_engine; + } + + }else { + eb.batch = &eb.vma[eb.batch_index]; } -i915_gem_ww_ctx_init (&eb.ww, true); - err =eb_relocate_parse (&eb); +if (first) +i915_gem_ww_ctx_init (eb.ww, true); + + err =eb_relocate_parse (&eb, first);if (err) {/* * If the user expects the execobject.offset and
@@ -3307,7 +3325,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, goto err_vma; } -ww_acquire_done (&eb.ww.ctx); +if (first) +ww_acquire_done (&eb.ww->ctx); batch = eb.batch->vma;
@@ -3410,11 +3429,12 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_request_put (eb.request); err_vma: -eb_release_vmas (&eb, true); +eb_release_vmas (&eb, true, err || last);if (eb.trampoline)i915_vma_unpin (eb.trampoline);WARN_ON (err == -EDEADLK ); -i915_gem_ww_ctx_fini (&eb.ww); +if (err || last) +i915_gem_ww_ctx_fini (eb.ww);if (eb.batch_pool)intel_gt_buffer_pool_put (eb.batch_pool);
@@ -3476,6 +3496,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,const size_t count = args->buffer_count;int err;struct i915_gem_context *ctx; +struct i915_gem_ww_ctx ww;struct intel_context *parent =NULL ;unsigned int num_batches =1 , i;bool is_parallel = false;
@@ -3602,7 +3623,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,0 , in_fence, exec_fence, - out_fences); + out_fences, + &ww);for (i =1 ; err ==0 && i < num_batches; i++) err = i915_gem_do_execbuffer(dev, file, args, exec2_list,
@@ -3612,7 +3634,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, i,NULL ,NULL , - out_fences); + out_fences, + &ww);if (is_parallel)mutex_unlock (&parent->parallel_submit);
drivers/gpu/drm/i915/gem/selftests/i915_gem_execbuffer.c +8 -6
@@ -32,11 +32,11 @@ static int __igt_gpu_reloc(struct i915_execbuffer *eb,if (IS_ERR (vma))return PTR_ERR (vma); - err =i915_gem_object_lock (obj, &eb->ww); + err =i915_gem_object_lock (obj, eb->ww);if (err)return err; - err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 ,PIN_USER |PIN_HIGH ); + err =i915_vma_pin_ww (vma, eb->ww,0 ,0 ,PIN_USER |PIN_HIGH );if (err)return err;
@@ -106,10 +106,12 @@ static int __igt_gpu_reloc(struct i915_execbuffer *eb,static int igt_gpu_reloc (void *arg) {struct i915_execbuffer eb; +struct i915_gem_ww_ctx ww;struct drm_i915_gem_object *scratch;int err =0 ;u32 *map; + eb.ww = &ww; eb.i915 = arg; scratch =i915_gem_object_create_internal (eb.i915,4096 );
@@ -141,20 +143,20 @@ static int igt_gpu_reloc(void *arg) eb.reloc_pool =NULL ; eb.reloc_context =NULL ; -i915_gem_ww_ctx_init (&eb.ww, false); +i915_gem_ww_ctx_init (eb.ww, false); retry: - err =intel_context_pin_ww (eb.context, &eb.ww); + err =intel_context_pin_ww (eb.context, eb.ww);if (!err) { err =__igt_gpu_reloc (&eb, scratch);intel_context_unpin (eb.context); }if (err == -EDEADLK ) { - err =i915_gem_ww_ctx_backoff (&eb.ww); + err =i915_gem_ww_ctx_backoff (eb.ww);if (!err) goto retry; } -i915_gem_ww_ctx_fini (&eb.ww); +i915_gem_ww_ctx_fini (eb.ww);if (eb.reloc_pool)intel_gt_buffer_pool_put (eb.reloc_pool);
Signature · 1 line
2.28.0
Re: [Intel-gfx] [PATCH 41/46] drm/i915: Eliminate unnecessary VMA calls for multi-BB submission
Quoted 2 lines · Matthew Brost
Certain VMA functions in the execbuf IOCTL only need to be called on first or last BB of a multi-BB submission.
eb_relocate()on the first
eb_relocate should be outright disallowed on multi lrc execbuf ioctl. There's no users of that left, and it does substantially simplify the entire locking problem if we outright disallow that.
Quoted 1 line
and
eb_release_vmas()on the last. Doing so will save CPU / GPU cycles.
Yah for our mix of pin/unpin vs dma_resv_lock/unlock. Now with the current unpin design this move is ok, but we want/need to switch vma over to dma_resv_lock. And then it gets really nasty, because you run into a ton of problems.
To more I read this the less I like this :-/
-Daniel
Quoted 423 lines
Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 127 +++++++++++------- .../i915/gem/selftests/i915_gem_execbuffer.c | 14 +- 2 files changed, 83 insertions(+), 58 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +75
-52@@ -270,7 +270,7 @@ struct i915_execbuffer {/** list of vma that have execobj.relocation_count */ struct list_head relocs; -struct i915_gem_ww_ctx ww; +struct i915_gem_ww_ctx *ww;/** * Track the most recently used object for relocations, as we @@ -448,7 +448,7 @@ eb_pin_vma(struct i915_execbuffer *eb, pin_flags |=PIN_GLOBAL ;/* Attempt to reuse the current location if available */ - err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 , pin_flags); + err =i915_vma_pin_ww (vma, eb->ww,0 ,0 , pin_flags);if (err == -EDEADLK )return err;@@ -457,11 +457,11 @@ eb_pin_vma(struct i915_execbuffer *eb,return err;/* Failing that pick any _free_ space if suitable */ - err =i915_vma_pin_ww (vma, &eb->ww, - entry->pad_to_size, - entry->alignment, -eb_pin_flags (entry, ev->flags) | -PIN_USER |PIN_NOEVICT ); + err =i915_vma_pin_ww (vma, eb->ww, + entry->pad_to_size, + entry->alignment, +eb_pin_flags (entry, ev->flags) | +PIN_USER |PIN_NOEVICT );if (unlikely (err))return err; }@@ -643,9 +643,9 @@ static int eb_reserve_vma(struct i915_execbuffer *eb,return err; } - err =i915_vma_pin_ww (vma, &eb->ww, - entry->pad_to_size, entry->alignment, -eb_pin_flags (entry, ev->flags) | pin_flags); + err =i915_vma_pin_ww (vma, eb->ww, + entry->pad_to_size, entry->alignment, +eb_pin_flags (entry, ev->flags) | pin_flags);if (err)return err;@@ -940,7 +940,7 @@ static int eb_lock_vmas(struct i915_execbuffer *eb)struct eb_vma *ev = &eb->vma[i];struct i915_vma *vma = ev->vma; - err =i915_gem_object_lock (vma->obj, &eb->ww); + err =i915_gem_object_lock (vma->obj, eb->ww);if (err)return err; }@@ -1020,12 +1020,13 @@ eb_get_vma(const struct i915_execbuffer *eb, unsigned long handle) } } -static void eb_release_vmas (struct i915_execbuffer *eb,bool final) +static void eb_release_vmas (struct i915_execbuffer *eb,bool final, +bool unreserve) {const unsigned int count = eb->buffer_count;unsigned int i; -for (i =0 ; i < count; i++) { +for (i =0 ; unreserve && i < count; i++) {struct eb_vma *ev = &eb->vma[i];struct i915_vma *vma = ev->vma;@@ -1237,7 +1238,7 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj,if (err)return ERR_PTR (err); - vma =i915_gem_object_ggtt_pin_ww (obj, &eb->ww,NULL ,0 ,0 , + vma =i915_gem_object_ggtt_pin_ww (obj, eb->ww,NULL ,0 ,0 ,PIN_MAPPABLE |PIN_NONBLOCK /* NOWARN */ |PIN_NOEVICT );@@ -1361,7 +1362,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, } eb->reloc_pool =NULL ; - err =i915_gem_object_lock (pool->obj, &eb->ww); + err =i915_gem_object_lock (pool->obj, eb->ww);if (err) goto err_pool;@@ -1380,7 +1381,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, goto err_unmap; } - err =i915_vma_pin_ww (batch, &eb->ww,0 ,0 ,PIN_USER |PIN_NONBLOCK ); + err =i915_vma_pin_ww (batch, eb->ww,0 ,0 ,PIN_USER |PIN_NONBLOCK );if (err) goto err_unmap;@@ -1402,7 +1403,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, eb->reloc_context = ce; } - err =intel_context_pin_ww (ce, &eb->ww); + err =intel_context_pin_ww (ce, eb->ww);if (err) goto err_unpin;@@ -2017,8 +2018,8 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, }/* We may process another execbuffer during the unlock... */ -eb_release_vmas (eb, false); -i915_gem_ww_ctx_fini (&eb->ww); +eb_release_vmas (eb, false, true); +i915_gem_ww_ctx_fini (eb->ww);if (rq) {/* nonblocking is always false */ @@ -2062,7 +2063,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err =eb_reinit_userptr (eb); err_relock: -i915_gem_ww_ctx_init (&eb->ww, true); +i915_gem_ww_ctx_init (eb->ww, true);if (err) goto out;@@ -2119,8 +2120,8 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); - err =i915_gem_ww_ctx_backoff (&eb->ww); +eb_release_vmas (eb, false, true); + err =i915_gem_ww_ctx_backoff (eb->ww);if (!err) goto repeat_validate; }@@ -2152,7 +2153,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb,return err; } -static int eb_relocate_parse (struct i915_execbuffer *eb) +static int eb_relocate_parse (struct i915_execbuffer *eb,bool first) {int err;struct i915_request *rq =NULL ;@@ -2189,14 +2190,16 @@ static int eb_relocate_parse(struct i915_execbuffer *eb)/* only throttle once, even if we didn't need to throttle */ throttle = false; - err =eb_validate_vmas (eb); -if (err == -EAGAIN ) - goto slow; -else if (err) - goto err; +if (first) { + err =eb_validate_vmas (eb); +if (err == -EAGAIN ) + goto slow; +else if (err) + goto err; + }/* The objects are in their final locations, apply the relocations. */ -if (eb->args->flags & __EXEC_HAS_RELOC) { +if (eb->args->flags & __EXEC_HAS_RELOC && first) {struct eb_vma *ev;list_for_each_entry (ev, &eb->relocs, reloc_link) {@@ -2211,13 +2214,13 @@ static int eb_relocate_parse(struct i915_execbuffer *eb) goto slow; } -if (!err) +if (!err && first) err =eb_parse (eb); err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); - err =i915_gem_ww_ctx_backoff (&eb->ww); +eb_release_vmas (eb, false, true); + err =i915_gem_ww_ctx_backoff (eb->ww);if (!err) goto retry; }@@ -2398,7 +2401,7 @@ shadow_batch_pin(struct i915_execbuffer *eb,if (IS_ERR (vma))return vma; - err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 , flags); + err =i915_vma_pin_ww (vma, eb->ww,0 ,0 , flags);if (err)return ERR_PTR (err);@@ -2412,7 +2415,7 @@ static struct i915_vma *eb_dispatch_secure(struct i915_execbuffer *eb, struct i9* batch" bit. Hence we need to pin secure batches into the global gtt. * hsw should have this fixed, but bdw mucks it up again. */ if (eb->batch_flags &I915_DISPATCH_SECURE ) -return i915_gem_object_ggtt_pin_ww (vma->obj, &eb->ww,NULL ,0 ,0 ,0 ); +return i915_gem_object_ggtt_pin_ww (vma->obj, eb->ww,NULL ,0 ,0 ,0 );return NULL ; }@@ -2458,7 +2461,7 @@ static int eb_parse(struct i915_execbuffer *eb) eb->batch_pool = pool; } - err =i915_gem_object_lock (pool->obj, &eb->ww); + err =i915_gem_object_lock (pool->obj, eb->ww);if (err) goto err;@@ -2666,7 +2669,7 @@ static struct i915_request *eb_pin_engine(struct i915_execbuffer *eb, bool throt* GGTT space, so do this first before we reserve a seqno for * ourselves. */ - err =intel_context_pin_ww (ce, &eb->ww); + err =intel_context_pin_ww (ce, eb->ww);if (err)return ERR_PTR (err);@@ -3218,7 +3221,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,unsigned int batch_number, struct dma_fence *in_fence, struct dma_fence *exec_fence, - struct dma_fence **out_fence) + struct dma_fence **out_fence, + struct i915_gem_ww_ctx *ww) { struct drm_i915_private *i915 = to_i915(dev);struct i915_execbuffer eb;@@ -3239,7 +3243,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.exec = exec; eb.vma = (struct eb_vma *)(exec + args->buffer_count +1 ); - eb.vma[0 ].vma =NULL ; +if (first) + eb.vma[0 ].vma =NULL ; eb.reloc_pool = eb.batch_pool =NULL ; eb.reloc_context =NULL ;@@ -3251,6 +3256,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.batch_len = args->batch_len; eb.trampoline =NULL ; eb.composite_fence =NULL ; + eb.ww = ww; eb.fences =NULL ; eb.num_fences =0 ;@@ -3269,9 +3275,14 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (err) goto err_ext; - err =eb_create (&eb); -if (err) - goto err_ext; +if (first) { + err =eb_create (&eb); +if (err) + goto err_ext; + }else { + eb.lut_size = -eb.buffer_count; + } +GEM_BUG_ON (!eb.lut_size);@@ -3286,15 +3297,22 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (unlikely (err)) goto err_context; - err =eb_lookup_vmas (&eb); -if (err) { -eb_release_vmas (&eb, true); - goto err_engine; +if (first) { + err =eb_lookup_vmas (&eb); +if (err) { +eb_release_vmas (&eb, true, true); + goto err_engine; + } + + }else { + eb.batch = &eb.vma[eb.batch_index]; } -i915_gem_ww_ctx_init (&eb.ww, true); - err =eb_relocate_parse (&eb); +if (first) +i915_gem_ww_ctx_init (eb.ww, true); + + err =eb_relocate_parse (&eb, first);if (err) {/* * If the user expects the execobject.offset and @@ -3307,7 +3325,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, goto err_vma; } -ww_acquire_done (&eb.ww.ctx); +if (first) +ww_acquire_done (&eb.ww->ctx); batch = eb.batch->vma;@@ -3410,11 +3429,12 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_request_put (eb.request); err_vma: -eb_release_vmas (&eb, true); +eb_release_vmas (&eb, true, err || last);if (eb.trampoline)i915_vma_unpin (eb.trampoline);WARN_ON (err == -EDEADLK ); -i915_gem_ww_ctx_fini (&eb.ww); +if (err || last) +i915_gem_ww_ctx_fini (eb.ww);if (eb.batch_pool)intel_gt_buffer_pool_put (eb.batch_pool);@@ -3476,6 +3496,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,const size_t count = args->buffer_count;int err;struct i915_gem_context *ctx; +struct i915_gem_ww_ctx ww;struct intel_context *parent =NULL ;unsigned int num_batches =1 , i;bool is_parallel = false;@@ -3602,7 +3623,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,0 , in_fence, exec_fence, - out_fences); + out_fences, + &ww);for (i =1 ; err ==0 && i < num_batches; i++) err = i915_gem_do_execbuffer(dev, file, args, exec2_list,@@ -3612,7 +3634,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, i,NULL ,NULL , - out_fences); + out_fences, + &ww);if (is_parallel)mutex_unlock (&parent->parallel_submit);drivers/gpu/drm/i915/gem/selftests/i915_gem_execbuffer.c +8
-6@@ -32,11 +32,11 @@ static int __igt_gpu_reloc(struct i915_execbuffer *eb,if (IS_ERR (vma))return PTR_ERR (vma); - err =i915_gem_object_lock (obj, &eb->ww); + err =i915_gem_object_lock (obj, eb->ww);if (err)return err; - err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 ,PIN_USER |PIN_HIGH ); + err =i915_vma_pin_ww (vma, eb->ww,0 ,0 ,PIN_USER |PIN_HIGH );if (err)return err;@@ -106,10 +106,12 @@ static int __igt_gpu_reloc(struct i915_execbuffer *eb,static int igt_gpu_reloc (void *arg) {struct i915_execbuffer eb; +struct i915_gem_ww_ctx ww;struct drm_i915_gem_object *scratch;int err =0 ;u32 *map; + eb.ww = &ww; eb.i915 = arg; scratch =i915_gem_object_create_internal (eb.i915,4096 );@@ -141,20 +143,20 @@ static int igt_gpu_reloc(void *arg) eb.reloc_pool =NULL ; eb.reloc_context =NULL ; -i915_gem_ww_ctx_init (&eb.ww, false); +i915_gem_ww_ctx_init (eb.ww, false); retry: - err =intel_context_pin_ww (eb.context, &eb.ww); + err =intel_context_pin_ww (eb.context, eb.ww);if (!err) { err =__igt_gpu_reloc (&eb, scratch);intel_context_unpin (eb.context); }if (err == -EDEADLK ) { - err =i915_gem_ww_ctx_backoff (&eb.ww); + err =i915_gem_ww_ctx_backoff (eb.ww);if (!err) goto retry; } -i915_gem_ww_ctx_fini (&eb.ww); +i915_gem_ww_ctx_fini (eb.ww);if (eb.reloc_pool)intel_gt_buffer_pool_put (eb.reloc_pool);Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [PATCH 41/46] drm/i915: Eliminate unnecessary VMA calls for multi-BB submission
Quoted 8 lines · Daniel Vetter
Quoted 2 lines · Matthew Brost
Certain VMA functions in the execbuf IOCTL only need to be called on first or last BB of a multi-BB submission.
eb_relocate()on the first
eb_relocateshould be outright disallowed on multi lrc execbuf ioctl. There's no users of that left, and it does substantially simplify the entire locking problem if we outright disallow that.
Quoted 6 lines
Quoted 1 line
and
eb_release_vmas()on the last. Doing so will save CPU / GPU cycles.Yah for our mix of pin/unpin vs dma_resv_lock/unlock. Now with the current unpin design this move is ok, but we want/need to switch vma over to
dma_resv_lock. And then it gets really nasty, because you run into a ton of problems.
To give a bit more context of how much this is all nasty: When you publish a fence, which thanks to rcu lookup of dma_resv happens when you install a fence, not when you unlock the dma_resv_lock, you're not allowed to allocate _any_ memory anymore until you're request has finished executing. This means no allocating anything, including kmalloc for your i915_request struct for the remaining batches, or the composite fence or anything else you might do.
userptr also makes this requirement even more fun with additional serialization requirements against mmu notifier invalidations.
The current execbuf code is a mess in this regard, and the idea is to fix this with the conversion to drm/sched, because that has a very clear point of no return. With the design you're pushing you're essentially making this problem unfixable.
-Daniel
Quoted 432 lines
To more I read this the less I like this :-/
-DanielQuoted 423 lines
Signed-off-by Matthew Brost <[email protected]>--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 127 +++++++++++------- .../i915/gem/selftests/i915_gem_execbuffer.c | 14 +- 2 files changed, 83 insertions(+), 58 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +75
-52@@ -270,7 +270,7 @@ struct i915_execbuffer {/** list of vma that have execobj.relocation_count */ struct list_head relocs; -struct i915_gem_ww_ctx ww; +struct i915_gem_ww_ctx *ww;/** * Track the most recently used object for relocations, as we @@ -448,7 +448,7 @@ eb_pin_vma(struct i915_execbuffer *eb, pin_flags |=PIN_GLOBAL ;/* Attempt to reuse the current location if available */ - err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 , pin_flags); + err =i915_vma_pin_ww (vma, eb->ww,0 ,0 , pin_flags);if (err == -EDEADLK )return err;@@ -457,11 +457,11 @@ eb_pin_vma(struct i915_execbuffer *eb,return err;/* Failing that pick any _free_ space if suitable */ - err =i915_vma_pin_ww (vma, &eb->ww, - entry->pad_to_size, - entry->alignment, -eb_pin_flags (entry, ev->flags) | -PIN_USER |PIN_NOEVICT ); + err =i915_vma_pin_ww (vma, eb->ww, + entry->pad_to_size, + entry->alignment, +eb_pin_flags (entry, ev->flags) | +PIN_USER |PIN_NOEVICT );if (unlikely (err))return err; }@@ -643,9 +643,9 @@ static int eb_reserve_vma(struct i915_execbuffer *eb,return err; } - err =i915_vma_pin_ww (vma, &eb->ww, - entry->pad_to_size, entry->alignment, -eb_pin_flags (entry, ev->flags) | pin_flags); + err =i915_vma_pin_ww (vma, eb->ww, + entry->pad_to_size, entry->alignment, +eb_pin_flags (entry, ev->flags) | pin_flags);if (err)return err;@@ -940,7 +940,7 @@ static int eb_lock_vmas(struct i915_execbuffer *eb)struct eb_vma *ev = &eb->vma[i];struct i915_vma *vma = ev->vma; - err =i915_gem_object_lock (vma->obj, &eb->ww); + err =i915_gem_object_lock (vma->obj, eb->ww);if (err)return err; }@@ -1020,12 +1020,13 @@ eb_get_vma(const struct i915_execbuffer *eb, unsigned long handle) } } -static void eb_release_vmas (struct i915_execbuffer *eb,bool final) +static void eb_release_vmas (struct i915_execbuffer *eb,bool final, +bool unreserve) {const unsigned int count = eb->buffer_count;unsigned int i; -for (i =0 ; i < count; i++) { +for (i =0 ; unreserve && i < count; i++) {struct eb_vma *ev = &eb->vma[i];struct i915_vma *vma = ev->vma;@@ -1237,7 +1238,7 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj,if (err)return ERR_PTR (err); - vma =i915_gem_object_ggtt_pin_ww (obj, &eb->ww,NULL ,0 ,0 , + vma =i915_gem_object_ggtt_pin_ww (obj, eb->ww,NULL ,0 ,0 ,PIN_MAPPABLE |PIN_NONBLOCK /* NOWARN */ |PIN_NOEVICT );@@ -1361,7 +1362,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, } eb->reloc_pool =NULL ; - err =i915_gem_object_lock (pool->obj, &eb->ww); + err =i915_gem_object_lock (pool->obj, eb->ww);if (err) goto err_pool;@@ -1380,7 +1381,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, goto err_unmap; } - err =i915_vma_pin_ww (batch, &eb->ww,0 ,0 ,PIN_USER |PIN_NONBLOCK ); + err =i915_vma_pin_ww (batch, eb->ww,0 ,0 ,PIN_USER |PIN_NONBLOCK );if (err) goto err_unmap;@@ -1402,7 +1403,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, eb->reloc_context = ce; } - err =intel_context_pin_ww (ce, &eb->ww); + err =intel_context_pin_ww (ce, eb->ww);if (err) goto err_unpin;@@ -2017,8 +2018,8 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, }/* We may process another execbuffer during the unlock... */ -eb_release_vmas (eb, false); -i915_gem_ww_ctx_fini (&eb->ww); +eb_release_vmas (eb, false, true); +i915_gem_ww_ctx_fini (eb->ww);if (rq) {/* nonblocking is always false */ @@ -2062,7 +2063,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err =eb_reinit_userptr (eb); err_relock: -i915_gem_ww_ctx_init (&eb->ww, true); +i915_gem_ww_ctx_init (eb->ww, true);if (err) goto out;@@ -2119,8 +2120,8 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); - err =i915_gem_ww_ctx_backoff (&eb->ww); +eb_release_vmas (eb, false, true); + err =i915_gem_ww_ctx_backoff (eb->ww);if (!err) goto repeat_validate; }@@ -2152,7 +2153,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb,return err; } -static int eb_relocate_parse (struct i915_execbuffer *eb) +static int eb_relocate_parse (struct i915_execbuffer *eb,bool first) {int err;struct i915_request *rq =NULL ;@@ -2189,14 +2190,16 @@ static int eb_relocate_parse(struct i915_execbuffer *eb)/* only throttle once, even if we didn't need to throttle */ throttle = false; - err =eb_validate_vmas (eb); -if (err == -EAGAIN ) - goto slow; -else if (err) - goto err; +if (first) { + err =eb_validate_vmas (eb); +if (err == -EAGAIN ) + goto slow; +else if (err) + goto err; + }/* The objects are in their final locations, apply the relocations. */ -if (eb->args->flags & __EXEC_HAS_RELOC) { +if (eb->args->flags & __EXEC_HAS_RELOC && first) {struct eb_vma *ev;list_for_each_entry (ev, &eb->relocs, reloc_link) {@@ -2211,13 +2214,13 @@ static int eb_relocate_parse(struct i915_execbuffer *eb) goto slow; } -if (!err) +if (!err && first) err =eb_parse (eb); err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); - err =i915_gem_ww_ctx_backoff (&eb->ww); +eb_release_vmas (eb, false, true); + err =i915_gem_ww_ctx_backoff (eb->ww);if (!err) goto retry; }@@ -2398,7 +2401,7 @@ shadow_batch_pin(struct i915_execbuffer *eb,if (IS_ERR (vma))return vma; - err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 , flags); + err =i915_vma_pin_ww (vma, eb->ww,0 ,0 , flags);if (err)return ERR_PTR (err);@@ -2412,7 +2415,7 @@ static struct i915_vma *eb_dispatch_secure(struct i915_execbuffer *eb, struct i9* batch" bit. Hence we need to pin secure batches into the global gtt. * hsw should have this fixed, but bdw mucks it up again. */ if (eb->batch_flags &I915_DISPATCH_SECURE ) -return i915_gem_object_ggtt_pin_ww (vma->obj, &eb->ww,NULL ,0 ,0 ,0 ); +return i915_gem_object_ggtt_pin_ww (vma->obj, eb->ww,NULL ,0 ,0 ,0 );return NULL ; }@@ -2458,7 +2461,7 @@ static int eb_parse(struct i915_execbuffer *eb) eb->batch_pool = pool; } - err =i915_gem_object_lock (pool->obj, &eb->ww); + err =i915_gem_object_lock (pool->obj, eb->ww);if (err) goto err;@@ -2666,7 +2669,7 @@ static struct i915_request *eb_pin_engine(struct i915_execbuffer *eb, bool throt* GGTT space, so do this first before we reserve a seqno for * ourselves. */ - err =intel_context_pin_ww (ce, &eb->ww); + err =intel_context_pin_ww (ce, eb->ww);if (err)return ERR_PTR (err);@@ -3218,7 +3221,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,unsigned int batch_number, struct dma_fence *in_fence, struct dma_fence *exec_fence, - struct dma_fence **out_fence) + struct dma_fence **out_fence, + struct i915_gem_ww_ctx *ww) { struct drm_i915_private *i915 = to_i915(dev);struct i915_execbuffer eb;@@ -3239,7 +3243,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.exec = exec; eb.vma = (struct eb_vma *)(exec + args->buffer_count +1 ); - eb.vma[0 ].vma =NULL ; +if (first) + eb.vma[0 ].vma =NULL ; eb.reloc_pool = eb.batch_pool =NULL ; eb.reloc_context =NULL ;@@ -3251,6 +3256,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, eb.batch_len = args->batch_len; eb.trampoline =NULL ; eb.composite_fence =NULL ; + eb.ww = ww; eb.fences =NULL ; eb.num_fences =0 ;@@ -3269,9 +3275,14 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (err) goto err_ext; - err =eb_create (&eb); -if (err) - goto err_ext; +if (first) { + err =eb_create (&eb); +if (err) + goto err_ext; + }else { + eb.lut_size = -eb.buffer_count; + } +GEM_BUG_ON (!eb.lut_size);@@ -3286,15 +3297,22 @@ i915_gem_do_execbuffer(struct drm_device *dev,if (unlikely (err)) goto err_context; - err =eb_lookup_vmas (&eb); -if (err) { -eb_release_vmas (&eb, true); - goto err_engine; +if (first) { + err =eb_lookup_vmas (&eb); +if (err) { +eb_release_vmas (&eb, true, true); + goto err_engine; + } + + }else { + eb.batch = &eb.vma[eb.batch_index]; } -i915_gem_ww_ctx_init (&eb.ww, true); - err =eb_relocate_parse (&eb); +if (first) +i915_gem_ww_ctx_init (eb.ww, true); + + err =eb_relocate_parse (&eb, first);if (err) {/* * If the user expects the execobject.offset and @@ -3307,7 +3325,8 @@ i915_gem_do_execbuffer(struct drm_device *dev, goto err_vma; } -ww_acquire_done (&eb.ww.ctx); +if (first) +ww_acquire_done (&eb.ww->ctx); batch = eb.batch->vma;@@ -3410,11 +3429,12 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_request_put (eb.request); err_vma: -eb_release_vmas (&eb, true); +eb_release_vmas (&eb, true, err || last);if (eb.trampoline)i915_vma_unpin (eb.trampoline);WARN_ON (err == -EDEADLK ); -i915_gem_ww_ctx_fini (&eb.ww); +if (err || last) +i915_gem_ww_ctx_fini (eb.ww);if (eb.batch_pool)intel_gt_buffer_pool_put (eb.batch_pool);@@ -3476,6 +3496,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,const size_t count = args->buffer_count;int err;struct i915_gem_context *ctx; +struct i915_gem_ww_ctx ww;struct intel_context *parent =NULL ;unsigned int num_batches =1 , i;bool is_parallel = false;@@ -3602,7 +3623,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,0 , in_fence, exec_fence, - out_fences); + out_fences, + &ww);for (i =1 ; err ==0 && i < num_batches; i++) err = i915_gem_do_execbuffer(dev, file, args, exec2_list,@@ -3612,7 +3634,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, i,NULL ,NULL , - out_fences); + out_fences, + &ww);if (is_parallel)mutex_unlock (&parent->parallel_submit);drivers/gpu/drm/i915/gem/selftests/i915_gem_execbuffer.c +8
-6@@ -32,11 +32,11 @@ static int __igt_gpu_reloc(struct i915_execbuffer *eb,if (IS_ERR (vma))return PTR_ERR (vma); - err =i915_gem_object_lock (obj, &eb->ww); + err =i915_gem_object_lock (obj, eb->ww);if (err)return err; - err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 ,PIN_USER |PIN_HIGH ); + err =i915_vma_pin_ww (vma, eb->ww,0 ,0 ,PIN_USER |PIN_HIGH );if (err)return err;@@ -106,10 +106,12 @@ static int __igt_gpu_reloc(struct i915_execbuffer *eb,static int igt_gpu_reloc (void *arg) {struct i915_execbuffer eb; +struct i915_gem_ww_ctx ww;struct drm_i915_gem_object *scratch;int err =0 ;u32 *map; + eb.ww = &ww; eb.i915 = arg; scratch =i915_gem_object_create_internal (eb.i915,4096 );@@ -141,20 +143,20 @@ static int igt_gpu_reloc(void *arg) eb.reloc_pool =NULL ; eb.reloc_context =NULL ; -i915_gem_ww_ctx_init (&eb.ww, false); +i915_gem_ww_ctx_init (eb.ww, false); retry: - err =intel_context_pin_ww (eb.context, &eb.ww); + err =intel_context_pin_ww (eb.context, eb.ww);if (!err) { err =__igt_gpu_reloc (&eb, scratch);intel_context_unpin (eb.context); }if (err == -EDEADLK ) { - err =i915_gem_ww_ctx_backoff (&eb.ww); + err =i915_gem_ww_ctx_backoff (eb.ww);if (!err) goto retry; } -i915_gem_ww_ctx_fini (&eb.ww); +i915_gem_ww_ctx_fini (eb.ww);if (eb.reloc_pool)intel_gt_buffer_pool_put (eb.reloc_pool);Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 42/46 drm/i915: Hold all parallel requests until last request, properly handle error
In reply to Matthew BrostHold all parallel requests, via a submit fence, until the last request is generated. If an error occurs in the middle of generating the requests, skip the requests signal the backend of the error via a request flag.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 40 +++++++++++++++++-- drivers/gpu/drm/i915/i915_request.h | 9 +++++ 2 files changed, 45 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +36 -4
@@ -3351,7 +3351,12 @@ i915_gem_do_execbuffer(struct drm_device *dev, }if (out_fence) { -/* Move ownership to caller (i915_gem_execbuffer2_ioctl) */ +/* +* Move ownership to caller (i915_gem_execbuffer2_ioctl), this +* must be done before anything in this function can jump to the +* 'err_request' label so the caller can safely cleanup any +* errors. +*/ out_fence[batch_number] =dma_fence_get (&eb.request->fence);/*
@@ -3402,10 +3407,21 @@ i915_gem_do_execbuffer(struct drm_device *dev, err =eb_submit (&eb, batch, first, last); err_request: -if (last) +if (last || err)set_bit (I915_FENCE_FLAG_SUBMIT_PARALLEL , &eb.request->fence.flags); +/* +* If the execbuf IOCTL is generating more than 1 request, we hold all +* the requests until the last request has been generated in case any of +* the requests hit an error. If an error is hit the caller is +* responsible for flaging all the requests generated with an error. The +* caller is always responsible for releasing the fence on the first +* request. +*/ +if (intel_context_is_parallel (eb.context) && first) +i915_sw_fence_await (&eb.request->submit); +i915_request_get (eb.request); err =eb_request_add (&eb, err);
@@ -3498,7 +3514,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,struct i915_gem_context *ctx;struct i915_gem_ww_ctx ww;struct intel_context *parent =NULL ; -unsigned int num_batches =1 , i; +unsigned int num_batches =1 , i =0 , j;bool is_parallel = false;if (!check_buffer_count (count)) {
@@ -3637,8 +3653,24 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, out_fences, &ww); -if (is_parallel) +if (is_parallel) { +/* +* Mark all requests generated with an error if any of the +* requests encountered an error. +*/ +for (j =0 ; err && j < i; ++j) +if (out_fences[j]) { +__i915_request_skip (to_request (out_fences[j])); +set_bit (I915_FENCE_FLAG_SKIP_PARALLEL , + &out_fences[j]->flags); + } + +/* Release fence on first request generated */ +if (out_fences[0 ]) +i915_sw_fence_complete (&to_request (out_fences[0 ])->submit); +mutex_unlock (&parent->parallel_submit); + }/* * Now that we have begun execution of the batchbuffer, we ignore
drivers/gpu/drm/i915/i915_request.h +9 -0
@@ -153,6 +153,15 @@ enum {* tail. */ I915_FENCE_FLAG_SUBMIT_PARALLEL , + +/* +* I915_FENCE_FLAG_SKIP_PARALLEL - request with a context in a +* parent-child relationship (parallel submission, multi-lrc) that +* hit an error while generating requests in the execbuf IOCTL. +* Indicates this request should be skipped as another request in +* submission / relationship encoutered an error. +*/ + I915_FENCE_FLAG_SKIP_PARALLEL, };/**
Signature · 1 line
2.28.0
PATCH 43/46 drm/i915/guc: Handle errors in multi-lrc requests
In reply to Matthew BrostIf an error occurs in the front end when multi-lrc requests are getting generated we need to skip these in the backend but we still need to emit the breadcrumbs seqno. An issues arrises because with multi-lrc breadcrumbs there is a handshake between the parent and children to make forwad progress. If all the requests are not present this handshake doesn't work. To work around this, if multi-lrc request has an error we skip the handshake but still emit the breadcrumbs seqno.
--- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +58 -3
@@ -4394,8 +4394,8 @@ static int emit_bb_start_child_no_preempt_mid_batch(struct i915_request *rq, }static u32 * -emit_fini_breadcrumb_parent_no_preempt_mid_batch (struct i915_request *rq, -u32 *cs) +__emit_fini_breadcrumb_parent_no_preempt_mid_batch (struct i915_request *rq, +u32 *cs) {struct intel_context *ce = rq->context;u8 i;
@@ -4423,6 +4423,41 @@ emit_fini_breadcrumb_parent_no_preempt_mid_batch(struct i915_request *rq,get_children_go_addr (ce), 0); +return cs; +} + +/* +* If this true, a submission of multi-lrc requests had an error and the +* requests need to be skipped. The front end (execuf IOCTL) should've called +* i915_request_skip which squashes the BB but we still need to emit the fini +* breadrcrumbs seqno write. At this point we don't know how many of the +* requests in the multi-lrc submission were generated so we can't do the +* handshake between the parent and children (e.g. if 4 requests should be +* generated but 2nd hit an error only 1 would be seen by the GuC backend). +* Simply skip the handshake, but still emit the breadcrumbd seqno, if an error +* has occurred on any of the requests in submission / relationship. +*/ +static inline bool skip_handshake (struct i915_request *rq) +{ +return test_bit (I915_FENCE_FLAG_SKIP_PARALLEL , &rq->fence.flags); +} + +static u32 * +emit_fini_breadcrumb_parent_no_preempt_mid_batch (struct i915_request *rq, +u32 *cs) +{ +struct intel_context *ce = rq->context; + +GEM_BUG_ON (!intel_context_is_parent (ce)); + +if (unlikely (skip_handshake (rq))) { +memset (cs,0 ,sizeof (u32) * + (ce->engine->emit_fini_breadcrumb_dw -6 )); + cs += ce->engine->emit_fini_breadcrumb_dw -6 ; + }else { + cs =__emit_fini_breadcrumb_parent_no_preempt_mid_batch (rq, cs); + } +/* Emit fini breadcrumb */ cs = gen8_emit_ggtt_write(cs, rq->fence.seqno,
@@ -4439,7 +4474,8 @@ emit_fini_breadcrumb_parent_no_preempt_mid_batch(struct i915_request *rq, }static u32 * -emit_fini_breadcrumb_child_no_preempt_mid_batch (struct i915_request *rq,u32 *cs) +__emit_fini_breadcrumb_child_no_preempt_mid_batch (struct i915_request *rq, +u32 *cs) {struct intel_context *ce = rq->context;
@@ -4465,6 +4501,25 @@ emit_fini_breadcrumb_child_no_preempt_mid_batch(struct i915_request *rq, u32 *cs *cs++ =get_children_go_addr (ce->parent); *cs++ =0 ; +return cs; +} + +static u32 * +emit_fini_breadcrumb_child_no_preempt_mid_batch (struct i915_request *rq, +u32 *cs) +{ +struct intel_context *ce = rq->context; + +GEM_BUG_ON (!intel_context_is_child (ce)); + +if (unlikely (skip_handshake (rq))) { +memset (cs,0 ,sizeof (u32) * + (ce->engine->emit_fini_breadcrumb_dw -6 )); + cs += ce->engine->emit_fini_breadcrumb_dw -6 ; + }else { + cs =__emit_fini_breadcrumb_child_no_preempt_mid_batch (rq, cs); + } +/* Emit fini breadcrumb */ cs = gen8_emit_ggtt_write(cs, rq->fence.seqno,
Signature · 1 line
2.28.0
PATCH 44/46 drm/i915: Enable multi-bb execbuf
In reply to Matthew BrostEnable multi-bb execbuf by enabling the set_parallel extension.
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +0 -3
@@ -529,9 +529,6 @@ set_proto_ctx_engines_parallel_submit(struct i915_user_extension __user *base,struct intel_engine_cs **siblings =NULL ;intel_engine_mask_t prev_mask; -/* Disabling for now */ -return -ENODEV ; -if (!(intel_uc_uses_guc_submission (&i915->gt.uc)))return -ENODEV ;
Signature · 1 line
2.28.0
PATCH 45/46 drm/i915/execlists: Weak parallel submission support for execlists
In reply to Matthew BrostA weak implementation of parallel submission (multi-bb execbuf IOCTL) for execlists. Basically doing as little as possible to support this interface for execlists - basically just passing submit fences between each request generated and virtual engines are not allowed. This is on par with what is there for the existing (hopefully soon deprecated) bonding interface.
As with the GuC implementation the pinning interface laying is broken. This will get cleaned up once the pre_pin / post_unpin laying violations get fixed. Rather than try to fix it here, just do what the GuC is doing in the meantime.
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 9 +- drivers/gpu/drm/i915/gt/intel_context.c | 1 - .../drm/i915/gt/intel_execlists_submission.c | 201 +++++++++++++++++- 3 files changed, 205 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +6 -3
@@ -529,9 +529,6 @@ set_proto_ctx_engines_parallel_submit(struct i915_user_extension __user *base,struct intel_engine_cs **siblings =NULL ;intel_engine_mask_t prev_mask; -if (!(intel_uc_uses_guc_submission (&i915->gt.uc))) -return -ENODEV ; -if (get_user (slot, &ext->engine_index))return -EFAULT ;
@@ -541,6 +538,12 @@ set_proto_ctx_engines_parallel_submit(struct i915_user_extension __user *base,if (get_user (num_siblings, &ext->num_siblings))return -EFAULT ; +if (!intel_uc_uses_guc_submission (&i915->gt.uc) && num_siblings !=1 ) { +drm_dbg (&i915->drm,"Only 1 sibling (%d) supported in non-GuC mode\n" , + num_siblings); +return -EINVAL ; + } +if (slot >= set->num_engines) {drm_dbg (&i915->drm,"Invalid placement value, %d >= %d\n" , slot, set->num_engines);
drivers/gpu/drm/i915/gt/intel_context.c +0 -1
@@ -627,7 +627,6 @@ void intel_context_bind_parent_child(struct intel_context *parent,* Callers responsibility to validate that this function is used * correctly but we use GEM_BUG_ON here ensure that they do. */ -GEM_BUG_ON (!intel_engine_uses_guc (parent->engine));GEM_BUG_ON (intel_context_is_pinned (parent));GEM_BUG_ON (intel_context_is_child (parent));GEM_BUG_ON (intel_context_is_pinned (child));
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +199 -2
219 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 46/46 drm/i915/guc: Add delay before disabling scheduling on contexts
In reply to Matthew BrostSome workloads use lots of contexts that continually pin / unpin contexts. With GuC submission an unpin translates to a schedule disable H2G which puts pressure on both the i915 and GuC. A schedule disable can also block future requests from being submitted until the operation completes. None of this is ideal.
Add a configurable, via debugfs, delay period before the schedule disable is issued. Default delay period is 1 second. The delay period is skipped if more than 3/4 of the guc_ids are in use.
This patch also updates the selftests to turn off this delay period as this extra time would likely cause many selftests to fail. Follow up patches will fix all the selftests and enable the delay period.
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +- .../i915/gem/selftests/i915_gem_coherency.c | 2 +- .../drm/i915/gem/selftests/i915_gem_dmabuf.c | 2 +- .../drm/i915/gem/selftests/i915_gem_mman.c | 2 +- .../drm/i915/gem/selftests/i915_gem_object.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 9 + drivers/gpu/drm/i915/gt/intel_context_types.h | 8 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 7 + .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 28 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 322 +++++++++++++++++- .../i915/gt/uc/selftest_guc_flow_control.c | 19 +- drivers/gpu/drm/i915/i915_selftest.h | 2 + drivers/gpu/drm/i915/i915_trace.h | 10 + drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 2 +- drivers/gpu/drm/i915/selftests/i915_perf.c | 2 +- drivers/gpu/drm/i915/selftests/i915_request.c | 2 +- drivers/gpu/drm/i915/selftests/i915_vma.c | 2 +- 18 files changed, 405 insertions(+), 20 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
@@ -1298,7 +1298,7 @@ static void engines_idle_release(struct i915_gem_context *ctx,int err;/* serialises with execbuf */ -set_bit (CONTEXT_CLOSED_BIT , &ce->flags); +intel_context_close (ce);if (!intel_context_pin_if_active (ce))continue ;
drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +1 -1
@@ -434,5 +434,5 @@ int i915_gem_coherency_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_coherency), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }
drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c +1 -1
@@ -474,5 +474,5 @@ int i915_gem_dmabuf_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_dmabuf_import_same_driver_lmem_smem), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }
drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +1 -1
@@ -1414,5 +1414,5 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_mmap_gpu), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }
drivers/gpu/drm/i915/gem/selftests/i915_gem_object.c +1 -1
@@ -95,5 +95,5 @@ int i915_gem_object_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_huge), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }
drivers/gpu/drm/i915/gt/intel_context.c +2 -0
@@ -472,6 +472,8 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link); +INIT_LIST_HEAD (&ce->guc_sched_disable_link); +mutex_init (&ce->parallel_submit); ce->fence_context =dma_fence_context_alloc (1 );
drivers/gpu/drm/i915/gt/intel_context.h +9 -0
@@ -215,6 +215,15 @@ static inline bool intel_context_is_barrier(const struct intel_context *ce)return test_bit (CONTEXT_BARRIER_BIT , &ce->flags); } +static inline void intel_context_close (struct intel_context *ce) +{ +set_bit (CONTEXT_CLOSED_BIT , &ce->flags); + +trace_intel_context_close (ce); +if (ce->ops->close) + ce->ops->close (ce); +} +static inline bool intel_context_is_closed (const struct intel_context *ce) {return test_bit (CONTEXT_CLOSED_BIT , &ce->flags);
drivers/gpu/drm/i915/gt/intel_context_types.h +8 -0
@@ -11,6 +11,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/types.h> +#include <linux/ktime.h> #include "i915_active_types.h" #include "i915_sw_fence.h"
@@ -38,6 +39,7 @@ struct intel_context_ops {int (*alloc)(struct intel_context *ce);void (*ban)(struct intel_context *ce,struct i915_request *rq); +void (*close)(struct intel_context *ce);int (*pre_pin)(struct intel_context *ce,struct i915_gem_ww_ctx *ww);int (*pin)(struct intel_context *ce);
@@ -203,6 +205,12 @@ struct intel_context {*/ struct list_head guc_id_link; +/* +* GuC schedule disable link / time +*/ +struct list_head guc_sched_disable_link; +ktime_t guc_sched_disable_time; +/* GuC context blocked fence */ struct i915_sw_fence guc_blocked;
drivers/gpu/drm/i915/gt/uc/intel_guc.h +7 -0
@@ -60,6 +60,7 @@ struct intel_guc {struct ida guc_ids;u32 num_guc_ids;u32 max_guc_ids; +u32 guc_ids_in_use[GUC_SUBMIT_ENGINE_MAX ];unsigned long *guc_ids_bitmap;#define MAX_GUC_ID_ORDER (order_base_2(MAX_ENGINE_INSTANCE + 1))struct list_head guc_id_list_no_ref[MAX_GUC_ID_ORDER +1 ];
@@ -69,6 +70,12 @@ struct intel_guc {struct list_head destroyed_contexts;struct intel_gt_pm_unpark_work destroy_worker; +spinlock_t sched_disable_lock;/* protects schedule disable list */ +struct list_head sched_disable_list; +struct hrtimer sched_disable_timer; +#define SCHED_DISABLE_DELAY_NS 1000000000 +u64 sched_disable_delay_ns; +bool submission_supported;bool submission_selected;
drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +28 -0
@@ -80,12 +80,40 @@ static int guc_num_id_set(void *data, u64 val) }DEFINE_SIMPLE_ATTRIBUTE (guc_num_id_fops, guc_num_id_get, guc_num_id_set,"%lld\n" ); +static int guc_sched_disable_delay_ns_get (void *data,u64 *val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + *val = guc->sched_disable_delay_ns; + +return 0 ; +} + +static int guc_sched_disable_delay_ns_set (void *data,u64 val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + guc->sched_disable_delay_ns = val; + +return 0 ; +} +DEFINE_SIMPLE_ATTRIBUTE (guc_sched_disable_delay_ns_fops, + guc_sched_disable_delay_ns_get, + guc_sched_disable_delay_ns_set,"%lld\n" ); +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 }, {"guc_num_id" , &guc_num_id_fops,NULL }, + {"guc_sched_disable_delay_ns" , &guc_sched_disable_delay_ns_fops,NULL }, };if (!intel_guc_is_supported (guc))
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +315 -7
474 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/selftest_guc_flow_control.c +15 -4
@@ -174,7 +174,8 @@ static int multi_lrc_not_blocked(struct intel_gt *gt, bool flow_control)#define NUM_RQ_PER_CONTEXT 2#define HEARTBEAT_INTERVAL 1500 -static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids,bool hang) +static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids, +bool hang,bool sched_disable_delay) {struct intel_gt *gt = arg;struct intel_guc *guc = >->uc.guc;
@@ -203,6 +204,9 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangif (limit_guc_ids) guc->num_guc_ids =NUM_GUC_ID ; +if (sched_disable_delay) + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS /5 ; + ce =intel_context_create (intel_selftest_find_any_engine (gt));if (IS_ERR (ce)) { ret =PTR_ERR (ce);
@@ -391,6 +395,7 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hang guc->num_guc_ids = guc->max_guc_ids; guc->gse_hang_expected = false; guc->inject_bad_sched_disable = false; + guc->sched_disable_delay_ns =0 ;kfree (contexts);return ret;
@@ -398,17 +403,22 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangstatic int intel_guc_flow_control_guc_ids (void *arg) { -return __intel_guc_flow_control_guc (arg, true, false); +return __intel_guc_flow_control_guc (arg, true, false, false); +} + +static int intel_guc_flow_control_guc_ids_sched_disable_delay (void *arg) +{ +return __intel_guc_flow_control_guc (arg, true, false, true); }static int intel_guc_flow_control_lrcd_reg (void *arg) { -return __intel_guc_flow_control_guc (arg, false, false); +return __intel_guc_flow_control_guc (arg, false, false, false); }static int intel_guc_flow_control_hang_state_machine (void *arg) { -return __intel_guc_flow_control_guc (arg, true, true); +return __intel_guc_flow_control_guc (arg, true, true, false); }#define NUM_RQ_STRESS_CTBS 0x4000
@@ -861,6 +871,7 @@ int intel_guc_flow_control(struct drm_i915_private *i915)static const struct i915_subtest tests[] = {SUBTEST (intel_guc_flow_control_stress_ctbs),SUBTEST (intel_guc_flow_control_guc_ids), +SUBTEST (intel_guc_flow_control_guc_ids_sched_disable_delay),SUBTEST (intel_guc_flow_control_lrcd_reg),SUBTEST (intel_guc_flow_control_hang_state_machine),SUBTEST (intel_guc_flow_control_multi_lrc_guc_ids),
drivers/gpu/drm/i915/i915_selftest.h +2 -0
@@ -92,12 +92,14 @@ int __i915_subtests(const char *caller, T, ARRAY_SIZE(T), data)#define i915_live_subtests (T , data) ({ \ typecheck(struct drm_i915_private *, data); \ + (data)->gt.uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __i915_live_setup, __i915_live_teardown, \ T, ARRAY_SIZE(T), data); \ })#define intel_gt_live_subtests (T , data) ({ \ typecheck(struct intel_gt *, data); \ + (data)->uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __intel_gt_live_setup, __intel_gt_live_teardown, \ T, ARRAY_SIZE(T), data); \
drivers/gpu/drm/i915/i915_trace.h +10 -0
@@ -933,6 +933,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,TP_ARGS (ce) ); +DEFINE_EVENT (intel_context, intel_context_close, + TP_PROTO(struct intel_context *ce), +TP_ARGS (ce) +); +DEFINE_EVENT (intel_context, intel_context_ban, TP_PROTO(struct intel_context *ce), TP_ARGS(ce)
@@ -1035,6 +1040,11 @@ trace_intel_context_reset(struct intel_context *ce) { } +static inline void +trace_intel_context_close (struct intel_context *ce) +{ +} +static inline void trace_intel_context_ban (struct intel_context *ce) {
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +1 -1
@@ -2112,5 +2112,5 @@ int i915_gem_gtt_live_selftests(struct drm_i915_private *i915)GEM_BUG_ON (offset_in_page (i915->ggtt.vm.total)); -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }
drivers/gpu/drm/i915/selftests/i915_perf.c +1 -1
@@ -431,7 +431,7 @@ int i915_perf_live_selftests(struct drm_i915_private *i915)if (err)return err; - err =i915_subtests (tests, i915); + err =i915_live_subtests (tests, i915);destroy_empty_config (&i915->perf);
drivers/gpu/drm/i915/selftests/i915_request.c +1 -1
@@ -1693,7 +1693,7 @@ int i915_request_live_selftests(struct drm_i915_private *i915)if (intel_gt_is_wedged (&i915->gt))return 0 ; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }static int switch_to_kernel_sync (struct intel_context *ce,int err)
drivers/gpu/drm/i915/selftests/i915_vma.c +1 -1
@@ -1085,5 +1085,5 @@ int i915_vma_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_vma_remapped_gtt), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }
Signature · 1 line
2.28.0
Re: [Intel-gfx] [PATCH 46/46] drm/i915/guc: Add delay before disabling scheduling on contexts
Quoted 10 lines · Matthew Brost
Some workloads use lots of contexts that continually pin / unpin contexts. With GuC submission an unpin translates to a schedule disable H2G which puts pressure on both the i915 and GuC. A schedule disable can also block future requests from being submitted until the operation completes. None of this is ideal.
Add a configurable, via debugfs, delay period before the schedule disable is issued. Default delay period is 1 second. The delay period is skipped if more than 3/4 of the
guc_idsare in use.
Quoted 5 lines
This patch also updates the selftests to turn off this delay period as this extra time would likely cause many selftests to fail. Follow up patches will fix all the selftests and enable the delay period.
Signed-off-by Matthew Brost <[email protected]>
I think this is more evidence that we should just pin/unpin context at create/destruction time. The current scheme doesn't really work that well and causes way more pain than benefits it seems.
If anyone screams, and that's a big if aside of some igts, we can come up with a proper scheme to evict contexts without pin/unpin and layer hacks over that misdesign.
-Daniel
Quoted 878 lines
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +- .../i915/gem/selftests/i915_gem_coherency.c | 2 +- .../drm/i915/gem/selftests/i915_gem_dmabuf.c | 2 +- .../drm/i915/gem/selftests/i915_gem_mman.c | 2 +- .../drm/i915/gem/selftests/i915_gem_object.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 9 + drivers/gpu/drm/i915/gt/intel_context_types.h | 8 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 7 + .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 28 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 322 +++++++++++++++++- .../i915/gt/uc/selftest_guc_flow_control.c | 19 +- drivers/gpu/drm/i915/i915_selftest.h | 2 + drivers/gpu/drm/i915/i915_trace.h | 10 + drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 2 +- drivers/gpu/drm/i915/selftests/i915_perf.c | 2 +- drivers/gpu/drm/i915/selftests/i915_request.c | 2 +- drivers/gpu/drm/i915/selftests/i915_vma.c | 2 +- 18 files changed, 405 insertions(+), 20 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +1
-1@@ -1298,7 +1298,7 @@ static void engines_idle_release(struct i915_gem_context *ctx,int err;/* serialises with execbuf */ -set_bit (CONTEXT_CLOSED_BIT , &ce->flags); +intel_context_close (ce);if (!intel_context_pin_if_active (ce))continue ;drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +1
-1@@ -434,5 +434,5 @@ int i915_gem_coherency_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_coherency), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c +1
-1@@ -474,5 +474,5 @@ int i915_gem_dmabuf_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_dmabuf_import_same_driver_lmem_smem), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +1
-1@@ -1414,5 +1414,5 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_mmap_gpu), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_object.c +1
-1@@ -95,5 +95,5 @@ int i915_gem_object_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_huge), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gt/intel_context.c +2
-0@@ -472,6 +472,8 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link); +INIT_LIST_HEAD (&ce->guc_sched_disable_link); +mutex_init (&ce->parallel_submit); ce->fence_context =dma_fence_context_alloc (1 );drivers/gpu/drm/i915/gt/intel_context.h +9
-0@@ -215,6 +215,15 @@ static inline bool intel_context_is_barrier(const struct intel_context *ce)return test_bit (CONTEXT_BARRIER_BIT , &ce->flags); } +static inline void intel_context_close (struct intel_context *ce) +{ +set_bit (CONTEXT_CLOSED_BIT , &ce->flags); + +trace_intel_context_close (ce); +if (ce->ops->close) + ce->ops->close (ce); +} +static inline bool intel_context_is_closed (const struct intel_context *ce) {return test_bit (CONTEXT_CLOSED_BIT , &ce->flags);drivers/gpu/drm/i915/gt/intel_context_types.h +8
-0@@ -11,6 +11,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/types.h> +#include <linux/ktime.h> #include "i915_active_types.h" #include "i915_sw_fence.h" @@ -38,6 +39,7 @@ struct intel_context_ops {int (*alloc)(struct intel_context *ce);void (*ban)(struct intel_context *ce,struct i915_request *rq); +void (*close)(struct intel_context *ce);int (*pre_pin)(struct intel_context *ce,struct i915_gem_ww_ctx *ww);int (*pin)(struct intel_context *ce);@@ -203,6 +205,12 @@ struct intel_context {*/ struct list_head guc_id_link; +/* +* GuC schedule disable link / time +*/ +struct list_head guc_sched_disable_link; +ktime_t guc_sched_disable_time; +/* GuC context blocked fence */ struct i915_sw_fence guc_blocked;drivers/gpu/drm/i915/gt/uc/intel_guc.h +7
-0@@ -60,6 +60,7 @@ struct intel_guc {struct ida guc_ids;u32 num_guc_ids;u32 max_guc_ids; +u32 guc_ids_in_use[GUC_SUBMIT_ENGINE_MAX ];unsigned long *guc_ids_bitmap;#define MAX_GUC_ID_ORDER (order_base_2(MAX_ENGINE_INSTANCE + 1))struct list_head guc_id_list_no_ref[MAX_GUC_ID_ORDER +1 ];@@ -69,6 +70,12 @@ struct intel_guc {struct list_head destroyed_contexts;struct intel_gt_pm_unpark_work destroy_worker; +spinlock_t sched_disable_lock;/* protects schedule disable list */ +struct list_head sched_disable_list; +struct hrtimer sched_disable_timer; +#define SCHED_DISABLE_DELAY_NS 1000000000 +u64 sched_disable_delay_ns; +bool submission_supported;bool submission_selected;drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +28
-0@@ -80,12 +80,40 @@ static int guc_num_id_set(void *data, u64 val) }DEFINE_SIMPLE_ATTRIBUTE (guc_num_id_fops, guc_num_id_get, guc_num_id_set,"%lld\n" ); +static int guc_sched_disable_delay_ns_get (void *data,u64 *val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + *val = guc->sched_disable_delay_ns; + +return 0 ; +} + +static int guc_sched_disable_delay_ns_set (void *data,u64 val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + guc->sched_disable_delay_ns = val; + +return 0 ; +} +DEFINE_SIMPLE_ATTRIBUTE (guc_sched_disable_delay_ns_fops, + guc_sched_disable_delay_ns_get, + guc_sched_disable_delay_ns_set,"%lld\n" ); +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 }, {"guc_num_id" , &guc_num_id_fops,NULL }, + {"guc_sched_disable_delay_ns" , &guc_sched_disable_delay_ns_fops,NULL }, };if (!intel_guc_is_supported (guc))drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +315
-7@@ -654,11 +654,15 @@ int intel_guc_wait_for_pending_msg(struct intel_guc *guc,return (timeout <0 ) ? timeout :0 ; } +static void sched_disable_contexts_flush (struct intel_guc *guc); +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) {if (!intel_uc_uses_guc_submission (&guc_to_gt (guc)->uc))return 0 ; +sched_disable_contexts_flush (guc); +return intel_guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, true, timeout);@@ -1135,6 +1139,7 @@ static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);static void guc_signal_context_fence (struct intel_context *ce);static void guc_cancel_context_requests (struct intel_context *ce);static void guc_blocked_fence_complete (struct intel_context *ce); +static void sched_disable_context_delete (struct intel_context *ce);static void scrub_guc_desc_for_outstanding_g2h (struct intel_guc *guc) {@@ -1160,6 +1165,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc) deregister =context_wait_for_deregister_to_register (ce); banned =context_banned (ce);init_sched_state (ce); +sched_disable_context_delete (ce);if (pending_enable || destroyed || deregister) {atomic_dec (&guc->outstanding_submission_g2h);@@ -1299,6 +1305,7 @@ void intel_guc_submission_reset_prepare(struct intel_guc *guc)intel_gt_park_heartbeats (guc_to_gt (guc));disable_submission (guc); +hrtimer_cancel (&guc->sched_disable_timer); guc->interrupts.disable (guc);/* Flush IRQ handler */ @@ -1656,6 +1663,8 @@ static void guc_lrcd_reg_fini(struct intel_guc *guc);static void destroy_worker_func (struct work_struct *w); +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer); +/* * Set up the memory resources to be shared with the GuC (via the GGTT) * at firmware loading time. @@ -1687,6 +1696,13 @@ int intel_guc_submission_init(struct intel_guc *guc)INIT_LIST_HEAD (&guc->destroyed_contexts);intel_gt_pm_unpark_work_init (&guc->destroy_worker, destroy_worker_func); +spin_lock_init (&guc->sched_disable_lock); +INIT_LIST_HEAD (&guc->sched_disable_list); +hrtimer_init (&guc->sched_disable_timer,CLOCK_MONOTONIC , +HRTIMER_MODE_REL ); + guc->sched_disable_timer.function = sched_disable_timer_func; + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS ; +return 0 ; }@@ -1852,6 +1868,12 @@ static int new_guc_id(struct intel_guc *guc, struct intel_context *ce)if (unlikely (ret <0 ))return ret; +if (intel_context_is_parent (ce)) + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 ); +else + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]++; + ce->guc_id = ret;return 0 ; }@@ -1860,13 +1882,18 @@ static void __release_guc_id(struct intel_guc *guc, struct intel_context *ce) {GEM_BUG_ON (intel_context_is_child (ce));if (!context_guc_id_invalid (ce)) { -if (intel_context_is_parent (ce)) +if (intel_context_is_parent (ce)) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (ce->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, ce->guc_id,order_base_2 (ce->guc_number_children +1 )); -else + }else { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]--;ida_simple_remove (&guc->guc_ids, ce->guc_id); + }clr_lrc_desc_registered (guc, ce->guc_id); +set_context_guc_id_invalid (ce); }if (!list_empty (&ce->guc_id_link))@@ -1931,9 +1958,13 @@ static int steal_guc_id(struct intel_guc *guc, struct intel_context *ce,* from another context that has more guc_id that itself. */ if (cn_o2 != ce_o2) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (cn->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, cn->guc_id, cn_o2); + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 );bitmap_allocate_region (guc->guc_ids_bitmap, ce->guc_id, ce_o2);@@ -2538,7 +2569,7 @@ static void guc_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);if (likely (!intel_context_is_barrier (ce))) -intel_engine_pm_put (ce->engine); +intel_engine_pm_put_async (ce->engine); }static void guc_context_post_unpin (struct intel_context *ce)@@ -2665,11 +2696,11 @@ static void guc_parent_context_unpin(struct intel_context *ce)for_each_engine_masked (engine, ce->engine->gt, ce->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine);for_each_child (ce, child)for_each_engine_masked (engine, child->engine->gt, child->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); } static void __guc_context_sched_enable(struct intel_guc *guc,@@ -2788,6 +2819,8 @@ static struct i915_sw_fence *guc_context_block(struct intel_context *ce)spin_unlock_irqrestore (&ce->guc_state.lock, flags); +sched_disable_context_delete (ce); + with_intel_runtime_pm(runtime_pm, wakeref)__guc_context_sched_disable (guc, ce, guc_id);@@ -2914,8 +2947,202 @@ static void guc_context_ban(struct intel_context *ce, struct i915_request *rq) 1);spin_unlock_irqrestore (&ce->guc_state.lock, flags); } + +sched_disable_context_delete (ce); +} + +#define next_sched_disable_time (guc, now, ce) \ + (guc->sched_disable_delay_ns - \ + (ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time))) +static void ____sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +bool is_first; + +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (list_empty (&ce->guc_sched_disable_link)); + + is_first =list_is_first (&ce->guc_sched_disable_link, + &guc->sched_disable_list); +list_del_init (&ce->guc_sched_disable_link); +if (list_empty (&guc->sched_disable_list)) { +hrtimer_try_to_cancel (&guc->sched_disable_timer); + }else if (is_first) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc,ktime_get (), + first); + +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (next_time), +HRTIMER_MODE_REL_PINNED ); + } +} + +static void __sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +intel_context_sched_disable_unpin (ce); +____sched_disable_context_delete (guc, ce); + } +} + +static void sched_disable_context_delete (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__sched_disable_context_delete (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} + +static void sched_disable_context_add (struct intel_guc *guc, +struct intel_context *ce) +{ +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link)); + + ce->guc_sched_disable_time =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); +if (list_empty (&guc->sched_disable_list)) +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (guc->sched_disable_delay_ns), +HRTIMER_MODE_REL_PINNED ); +list_add_tail (&ce->guc_sched_disable_link, &guc->sched_disable_list); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); +} + +static void sched_disable_contexts_flush (struct intel_guc *guc) +{ +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +hrtimer_try_to_cancel (&guc->sched_disable_timer); + +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); } +#define should_sched_be_disabled (guc, now, ce) \ + ((ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time)) > \ + (guc->sched_disable_delay_ns / 4) * 3) +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer) +{ + struct intel_guc *guc = container_of(hrtimer, struct intel_guc, + sched_disable_timer); +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; +ktime_t now; + +if (list_empty (&guc->sched_disable_list)) +return HRTIMER_NORESTART ; + + now =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +/* +* If a context has been waiting for 3/4 of its delay or more, +* issue the schedule disable. Using this heuristic allows more +* than 1 context to have its scheduling disabled when this +* timer is run. +*/ +if (!should_sched_be_disabled (guc, now, ce)) +break ; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +if (!list_empty (&guc->sched_disable_list)) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc, now, first); + +hrtimer_forward (hrtimer, now,ns_to_ktime (next_time)); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_RESTART ; + }else { +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_NORESTART ; + } +} + +#define guc_id_pressure (max, in_use) (in_use > (max / 4) * 3)static void guc_context_sched_disable (struct intel_context *ce) {struct intel_guc *guc =ce_to_guc (ce);@@ -2924,8 +3151,14 @@ static void guc_context_sched_disable(struct intel_context *ce)intel_wakeref_t wakeref;u16 guc_id;bool enabled; +int guc_id_index =intel_context_is_parent (ce) ? +GUC_SUBMIT_ENGINE_MULTI_LRC :GUC_SUBMIT_ENGINE_SINGLE_LRC ; +int max_guc_ids =intel_context_is_parent (ce) ? +NUMBER_MULTI_LRC_GUC_ID (guc) : + guc->num_guc_ids -NUMBER_MULTI_LRC_GUC_ID (guc);GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link));if (submission_disabled (guc) ||context_guc_id_invalid (ce) || !lrc_desc_registered (guc, ce->guc_id)) {@@ -2936,6 +3169,18 @@ static void guc_context_sched_disable(struct intel_context *ce)if (!context_enabled (ce)) goto unpin; +/* +* If no guc_id pressure and the context isn't closed we delay the +* schedule disable to not to continuously disable / enable scheduling +* putting pressure on both the i915 and GuC. Delay is configurable via +* debugfs, default 1s. +*/ +if (!guc_id_pressure (max_guc_ids, guc->guc_ids_in_use[guc_id_index]) && + !intel_context_is_closed (ce) && guc->sched_disable_delay_ns) { +sched_disable_context_add (guc, ce); +return ; + } +spin_lock_irqsave (&ce->guc_state.lock, flags);/* @@ -3294,6 +3539,58 @@ static void remove_from_context(struct i915_request *rq)i915_request_notify_execute_cb_imm (rq); } +static void __guc_context_close (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +struct intel_runtime_pm *runtime_pm = + ce->engine->uncore->rpm; +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); + goto update_list; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); + goto update_list; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); +update_list: +____sched_disable_context_delete (guc, ce); + } +} + +static void guc_context_close (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +/* +* If we close the context and a schedule disable is pending a delay, do +* it immediately. +*/ +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__guc_context_close (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} +static struct intel_context * guc_create_parallel(struct intel_engine_cs **engines, unsigned int num_siblings,@@ -3308,6 +3605,7 @@ static const struct intel_context_ops guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3538,6 +3836,10 @@ static int guc_request_alloc(struct i915_request *rq) rq->reserved_space -=GUC_REQUEST_SIZE ; +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link) && +atomic_read (&ce->pin_count) <3 ); +sched_disable_context_delete (ce); +/* * guc_ids are exhausted or a heuristic is met indicating too many * guc_ids are waiting on requests with submission dependencies (not @@ -3667,7 +3969,7 @@ static void guc_virtual_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);for_each_engine_masked (engine, ce->engine->gt, mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); }static void guc_virtual_context_enter (struct intel_context *ce)@@ -3708,6 +4010,7 @@ static const struct intel_context_ops virtual_guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3819,6 +4122,7 @@ static const struct intel_context_ops virtual_parent_context_ops = { .post_unpin = guc_parent_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .enter = guc_virtual_context_enter, .exit = guc_virtual_context_exit,@@ -4924,7 +5228,11 @@ void intel_guc_submission_print_info(struct intel_guc *guc,drm_printf (p,"GuC Number Outstanding Submission G2H: %u\n" ,atomic_read (&guc->outstanding_submission_g2h));drm_printf (p,"GuC Number GuC IDs: %d\n" , guc->num_guc_ids); -drm_printf (p,"GuC Max Number GuC IDs: %d\n\n" , guc->max_guc_ids); +drm_printf (p,"GuC Max Number GuC IDs: %d\n" , guc->max_guc_ids); +drm_printf (p,"GuC single-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]); +drm_printf (p,"GuC multi-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ]);drm_printf (p,"GuC max context registered: %u\n\n" , guc->lrcd_reg.max_idx);drivers/gpu/drm/i915/gt/uc/selftest_guc_flow_control.c +15
-4@@ -174,7 +174,8 @@ static int multi_lrc_not_blocked(struct intel_gt *gt, bool flow_control)#define NUM_RQ_PER_CONTEXT 2#define HEARTBEAT_INTERVAL 1500 -static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids,bool hang) +static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids, +bool hang,bool sched_disable_delay) {struct intel_gt *gt = arg;struct intel_guc *guc = >->uc.guc;@@ -203,6 +204,9 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangif (limit_guc_ids) guc->num_guc_ids =NUM_GUC_ID ; +if (sched_disable_delay) + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS /5 ; + ce =intel_context_create (intel_selftest_find_any_engine (gt));if (IS_ERR (ce)) { ret =PTR_ERR (ce);@@ -391,6 +395,7 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hang guc->num_guc_ids = guc->max_guc_ids; guc->gse_hang_expected = false; guc->inject_bad_sched_disable = false; + guc->sched_disable_delay_ns =0 ;kfree (contexts);return ret;@@ -398,17 +403,22 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangstatic int intel_guc_flow_control_guc_ids (void *arg) { -return __intel_guc_flow_control_guc (arg, true, false); +return __intel_guc_flow_control_guc (arg, true, false, false); +} + +static int intel_guc_flow_control_guc_ids_sched_disable_delay (void *arg) +{ +return __intel_guc_flow_control_guc (arg, true, false, true); }static int intel_guc_flow_control_lrcd_reg (void *arg) { -return __intel_guc_flow_control_guc (arg, false, false); +return __intel_guc_flow_control_guc (arg, false, false, false); }static int intel_guc_flow_control_hang_state_machine (void *arg) { -return __intel_guc_flow_control_guc (arg, true, true); +return __intel_guc_flow_control_guc (arg, true, true, false); }#define NUM_RQ_STRESS_CTBS 0x4000@@ -861,6 +871,7 @@ int intel_guc_flow_control(struct drm_i915_private *i915)static const struct i915_subtest tests[] = {SUBTEST (intel_guc_flow_control_stress_ctbs),SUBTEST (intel_guc_flow_control_guc_ids), +SUBTEST (intel_guc_flow_control_guc_ids_sched_disable_delay),SUBTEST (intel_guc_flow_control_lrcd_reg),SUBTEST (intel_guc_flow_control_hang_state_machine),SUBTEST (intel_guc_flow_control_multi_lrc_guc_ids),drivers/gpu/drm/i915/i915_selftest.h +2
-0@@ -92,12 +92,14 @@ int __i915_subtests(const char *caller, T, ARRAY_SIZE(T), data)#define i915_live_subtests (T , data) ({ \ typecheck(struct drm_i915_private *, data); \ + (data)->gt.uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __i915_live_setup, __i915_live_teardown, \ T, ARRAY_SIZE(T), data); \ })#define intel_gt_live_subtests (T , data) ({ \ typecheck(struct intel_gt *, data); \ + (data)->uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __intel_gt_live_setup, __intel_gt_live_teardown, \ T, ARRAY_SIZE(T), data); \drivers/gpu/drm/i915/i915_trace.h +10
-0@@ -933,6 +933,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,TP_ARGS (ce) ); +DEFINE_EVENT (intel_context, intel_context_close, + TP_PROTO(struct intel_context *ce), +TP_ARGS (ce) +); +DEFINE_EVENT (intel_context, intel_context_ban, TP_PROTO(struct intel_context *ce), TP_ARGS(ce)@@ -1035,6 +1040,11 @@ trace_intel_context_reset(struct intel_context *ce) { } +static inline void +trace_intel_context_close (struct intel_context *ce) +{ +} +static inline void trace_intel_context_ban (struct intel_context *ce) {drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +1
-1@@ -2112,5 +2112,5 @@ int i915_gem_gtt_live_selftests(struct drm_i915_private *i915)GEM_BUG_ON (offset_in_page (i915->ggtt.vm.total)); -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/selftests/i915_perf.c +1
-1@@ -431,7 +431,7 @@ int i915_perf_live_selftests(struct drm_i915_private *i915)if (err)return err; - err =i915_subtests (tests, i915); + err =i915_live_subtests (tests, i915);destroy_empty_config (&i915->perf);drivers/gpu/drm/i915/selftests/i915_request.c +1
-1@@ -1693,7 +1693,7 @@ int i915_request_live_selftests(struct drm_i915_private *i915)if (intel_gt_is_wedged (&i915->gt))return 0 ; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }static int switch_to_kernel_sync (struct intel_context *ce,int err)drivers/gpu/drm/i915/selftests/i915_vma.c +1
-1@@ -1085,5 +1085,5 @@ int i915_vma_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_vma_remapped_gtt), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [PATCH 46/46] drm/i915/guc: Add delay before disabling scheduling on contexts
Quoted 15 lines · Daniel Vetter
Quoted 14 lines · Matthew Brost
Some workloads use lots of contexts that continually pin / unpin contexts. With GuC submission an unpin translates to a schedule disable H2G which puts pressure on both the i915 and GuC. A schedule disable can also block future requests from being submitted until the operation completes. None of this is ideal.
Add a configurable, via debugfs, delay period before the schedule disable is issued. Default delay period is 1 second. The delay period is skipped if more than 3/4 of the
guc_idsare in use.This patch also updates the selftests to turn off this delay period as this extra time would likely cause many selftests to fail. Follow up patches will fix all the selftests and enable the delay period.
Quoted 6 lines
Quoted 1 line
Signed-off-by Matthew Brost <[email protected]>I think this is more evidence that we should just pin/unpin context at create/destruction time. The current scheme doesn't really work that well and causes way more pain than benefits it seems.
Well that choice is above my pay grade, but for what it is worth it would simplify the GuC backend quite a bit if we perma-pin contexts. By quite a bit, I actually mean a lot of complexity goes away.
In the meantime I think we probably need this code though to avoid trashes on the scheduling enable / disable.
Matt
Quoted 888 lines
If anyone screams, and that's a big if aside of some igts, we can come up with a proper scheme to evict contexts without pin/unpin and layer hacks over that misdesign.
-DanielQuoted 878 lines
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +- .../i915/gem/selftests/i915_gem_coherency.c | 2 +- .../drm/i915/gem/selftests/i915_gem_dmabuf.c | 2 +- .../drm/i915/gem/selftests/i915_gem_mman.c | 2 +- .../drm/i915/gem/selftests/i915_gem_object.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 9 + drivers/gpu/drm/i915/gt/intel_context_types.h | 8 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 7 + .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 28 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 322 +++++++++++++++++- .../i915/gt/uc/selftest_guc_flow_control.c | 19 +- drivers/gpu/drm/i915/i915_selftest.h | 2 + drivers/gpu/drm/i915/i915_trace.h | 10 + drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 2 +- drivers/gpu/drm/i915/selftests/i915_perf.c | 2 +- drivers/gpu/drm/i915/selftests/i915_request.c | 2 +- drivers/gpu/drm/i915/selftests/i915_vma.c | 2 +- 18 files changed, 405 insertions(+), 20 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +1
-1@@ -1298,7 +1298,7 @@ static void engines_idle_release(struct i915_gem_context *ctx,int err;/* serialises with execbuf */ -set_bit (CONTEXT_CLOSED_BIT , &ce->flags); +intel_context_close (ce);if (!intel_context_pin_if_active (ce))continue ;drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +1
-1@@ -434,5 +434,5 @@ int i915_gem_coherency_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_coherency), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c +1
-1@@ -474,5 +474,5 @@ int i915_gem_dmabuf_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_dmabuf_import_same_driver_lmem_smem), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +1
-1@@ -1414,5 +1414,5 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_mmap_gpu), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_object.c +1
-1@@ -95,5 +95,5 @@ int i915_gem_object_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_huge), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gt/intel_context.c +2
-0@@ -472,6 +472,8 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link); +INIT_LIST_HEAD (&ce->guc_sched_disable_link); +mutex_init (&ce->parallel_submit); ce->fence_context =dma_fence_context_alloc (1 );drivers/gpu/drm/i915/gt/intel_context.h +9
-0@@ -215,6 +215,15 @@ static inline bool intel_context_is_barrier(const struct intel_context *ce)return test_bit (CONTEXT_BARRIER_BIT , &ce->flags); } +static inline void intel_context_close (struct intel_context *ce) +{ +set_bit (CONTEXT_CLOSED_BIT , &ce->flags); + +trace_intel_context_close (ce); +if (ce->ops->close) + ce->ops->close (ce); +} +static inline bool intel_context_is_closed (const struct intel_context *ce) {return test_bit (CONTEXT_CLOSED_BIT , &ce->flags);drivers/gpu/drm/i915/gt/intel_context_types.h +8
-0@@ -11,6 +11,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/types.h> +#include <linux/ktime.h> #include "i915_active_types.h" #include "i915_sw_fence.h" @@ -38,6 +39,7 @@ struct intel_context_ops {int (*alloc)(struct intel_context *ce);void (*ban)(struct intel_context *ce,struct i915_request *rq); +void (*close)(struct intel_context *ce);int (*pre_pin)(struct intel_context *ce,struct i915_gem_ww_ctx *ww);int (*pin)(struct intel_context *ce);@@ -203,6 +205,12 @@ struct intel_context {*/ struct list_head guc_id_link; +/* +* GuC schedule disable link / time +*/ +struct list_head guc_sched_disable_link; +ktime_t guc_sched_disable_time; +/* GuC context blocked fence */ struct i915_sw_fence guc_blocked;drivers/gpu/drm/i915/gt/uc/intel_guc.h +7
-0@@ -60,6 +60,7 @@ struct intel_guc {struct ida guc_ids;u32 num_guc_ids;u32 max_guc_ids; +u32 guc_ids_in_use[GUC_SUBMIT_ENGINE_MAX ];unsigned long *guc_ids_bitmap;#define MAX_GUC_ID_ORDER (order_base_2(MAX_ENGINE_INSTANCE + 1))struct list_head guc_id_list_no_ref[MAX_GUC_ID_ORDER +1 ];@@ -69,6 +70,12 @@ struct intel_guc {struct list_head destroyed_contexts;struct intel_gt_pm_unpark_work destroy_worker; +spinlock_t sched_disable_lock;/* protects schedule disable list */ +struct list_head sched_disable_list; +struct hrtimer sched_disable_timer; +#define SCHED_DISABLE_DELAY_NS 1000000000 +u64 sched_disable_delay_ns; +bool submission_supported;bool submission_selected;drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +28
-0@@ -80,12 +80,40 @@ static int guc_num_id_set(void *data, u64 val) }DEFINE_SIMPLE_ATTRIBUTE (guc_num_id_fops, guc_num_id_get, guc_num_id_set,"%lld\n" ); +static int guc_sched_disable_delay_ns_get (void *data,u64 *val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + *val = guc->sched_disable_delay_ns; + +return 0 ; +} + +static int guc_sched_disable_delay_ns_set (void *data,u64 val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + guc->sched_disable_delay_ns = val; + +return 0 ; +} +DEFINE_SIMPLE_ATTRIBUTE (guc_sched_disable_delay_ns_fops, + guc_sched_disable_delay_ns_get, + guc_sched_disable_delay_ns_set,"%lld\n" ); +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 }, {"guc_num_id" , &guc_num_id_fops,NULL }, + {"guc_sched_disable_delay_ns" , &guc_sched_disable_delay_ns_fops,NULL }, };if (!intel_guc_is_supported (guc))drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +315
-7@@ -654,11 +654,15 @@ int intel_guc_wait_for_pending_msg(struct intel_guc *guc,return (timeout <0 ) ? timeout :0 ; } +static void sched_disable_contexts_flush (struct intel_guc *guc); +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) {if (!intel_uc_uses_guc_submission (&guc_to_gt (guc)->uc))return 0 ; +sched_disable_contexts_flush (guc); +return intel_guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, true, timeout);@@ -1135,6 +1139,7 @@ static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);static void guc_signal_context_fence (struct intel_context *ce);static void guc_cancel_context_requests (struct intel_context *ce);static void guc_blocked_fence_complete (struct intel_context *ce); +static void sched_disable_context_delete (struct intel_context *ce);static void scrub_guc_desc_for_outstanding_g2h (struct intel_guc *guc) {@@ -1160,6 +1165,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc) deregister =context_wait_for_deregister_to_register (ce); banned =context_banned (ce);init_sched_state (ce); +sched_disable_context_delete (ce);if (pending_enable || destroyed || deregister) {atomic_dec (&guc->outstanding_submission_g2h);@@ -1299,6 +1305,7 @@ void intel_guc_submission_reset_prepare(struct intel_guc *guc)intel_gt_park_heartbeats (guc_to_gt (guc));disable_submission (guc); +hrtimer_cancel (&guc->sched_disable_timer); guc->interrupts.disable (guc);/* Flush IRQ handler */ @@ -1656,6 +1663,8 @@ static void guc_lrcd_reg_fini(struct intel_guc *guc);static void destroy_worker_func (struct work_struct *w); +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer); +/* * Set up the memory resources to be shared with the GuC (via the GGTT) * at firmware loading time. @@ -1687,6 +1696,13 @@ int intel_guc_submission_init(struct intel_guc *guc)INIT_LIST_HEAD (&guc->destroyed_contexts);intel_gt_pm_unpark_work_init (&guc->destroy_worker, destroy_worker_func); +spin_lock_init (&guc->sched_disable_lock); +INIT_LIST_HEAD (&guc->sched_disable_list); +hrtimer_init (&guc->sched_disable_timer,CLOCK_MONOTONIC , +HRTIMER_MODE_REL ); + guc->sched_disable_timer.function = sched_disable_timer_func; + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS ; +return 0 ; }@@ -1852,6 +1868,12 @@ static int new_guc_id(struct intel_guc *guc, struct intel_context *ce)if (unlikely (ret <0 ))return ret; +if (intel_context_is_parent (ce)) + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 ); +else + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]++; + ce->guc_id = ret;return 0 ; }@@ -1860,13 +1882,18 @@ static void __release_guc_id(struct intel_guc *guc, struct intel_context *ce) {GEM_BUG_ON (intel_context_is_child (ce));if (!context_guc_id_invalid (ce)) { -if (intel_context_is_parent (ce)) +if (intel_context_is_parent (ce)) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (ce->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, ce->guc_id,order_base_2 (ce->guc_number_children +1 )); -else + }else { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]--;ida_simple_remove (&guc->guc_ids, ce->guc_id); + }clr_lrc_desc_registered (guc, ce->guc_id); +set_context_guc_id_invalid (ce); }if (!list_empty (&ce->guc_id_link))@@ -1931,9 +1958,13 @@ static int steal_guc_id(struct intel_guc *guc, struct intel_context *ce,* from another context that has more guc_id that itself. */ if (cn_o2 != ce_o2) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (cn->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, cn->guc_id, cn_o2); + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 );bitmap_allocate_region (guc->guc_ids_bitmap, ce->guc_id, ce_o2);@@ -2538,7 +2569,7 @@ static void guc_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);if (likely (!intel_context_is_barrier (ce))) -intel_engine_pm_put (ce->engine); +intel_engine_pm_put_async (ce->engine); }static void guc_context_post_unpin (struct intel_context *ce)@@ -2665,11 +2696,11 @@ static void guc_parent_context_unpin(struct intel_context *ce)for_each_engine_masked (engine, ce->engine->gt, ce->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine);for_each_child (ce, child)for_each_engine_masked (engine, child->engine->gt, child->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); } static void __guc_context_sched_enable(struct intel_guc *guc,@@ -2788,6 +2819,8 @@ static struct i915_sw_fence *guc_context_block(struct intel_context *ce)spin_unlock_irqrestore (&ce->guc_state.lock, flags); +sched_disable_context_delete (ce); + with_intel_runtime_pm(runtime_pm, wakeref)__guc_context_sched_disable (guc, ce, guc_id);@@ -2914,8 +2947,202 @@ static void guc_context_ban(struct intel_context *ce, struct i915_request *rq) 1);spin_unlock_irqrestore (&ce->guc_state.lock, flags); } + +sched_disable_context_delete (ce); +} + +#define next_sched_disable_time (guc, now, ce) \ + (guc->sched_disable_delay_ns - \ + (ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time))) +static void ____sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +bool is_first; + +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (list_empty (&ce->guc_sched_disable_link)); + + is_first =list_is_first (&ce->guc_sched_disable_link, + &guc->sched_disable_list); +list_del_init (&ce->guc_sched_disable_link); +if (list_empty (&guc->sched_disable_list)) { +hrtimer_try_to_cancel (&guc->sched_disable_timer); + }else if (is_first) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc,ktime_get (), + first); + +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (next_time), +HRTIMER_MODE_REL_PINNED ); + } +} + +static void __sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +intel_context_sched_disable_unpin (ce); +____sched_disable_context_delete (guc, ce); + } +} + +static void sched_disable_context_delete (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__sched_disable_context_delete (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} + +static void sched_disable_context_add (struct intel_guc *guc, +struct intel_context *ce) +{ +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link)); + + ce->guc_sched_disable_time =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); +if (list_empty (&guc->sched_disable_list)) +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (guc->sched_disable_delay_ns), +HRTIMER_MODE_REL_PINNED ); +list_add_tail (&ce->guc_sched_disable_link, &guc->sched_disable_list); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); +} + +static void sched_disable_contexts_flush (struct intel_guc *guc) +{ +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +hrtimer_try_to_cancel (&guc->sched_disable_timer); + +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); } +#define should_sched_be_disabled (guc, now, ce) \ + ((ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time)) > \ + (guc->sched_disable_delay_ns / 4) * 3) +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer) +{ + struct intel_guc *guc = container_of(hrtimer, struct intel_guc, + sched_disable_timer); +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; +ktime_t now; + +if (list_empty (&guc->sched_disable_list)) +return HRTIMER_NORESTART ; + + now =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +/* +* If a context has been waiting for 3/4 of its delay or more, +* issue the schedule disable. Using this heuristic allows more +* than 1 context to have its scheduling disabled when this +* timer is run. +*/ +if (!should_sched_be_disabled (guc, now, ce)) +break ; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +if (!list_empty (&guc->sched_disable_list)) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc, now, first); + +hrtimer_forward (hrtimer, now,ns_to_ktime (next_time)); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_RESTART ; + }else { +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_NORESTART ; + } +} + +#define guc_id_pressure (max, in_use) (in_use > (max / 4) * 3)static void guc_context_sched_disable (struct intel_context *ce) {struct intel_guc *guc =ce_to_guc (ce);@@ -2924,8 +3151,14 @@ static void guc_context_sched_disable(struct intel_context *ce)intel_wakeref_t wakeref;u16 guc_id;bool enabled; +int guc_id_index =intel_context_is_parent (ce) ? +GUC_SUBMIT_ENGINE_MULTI_LRC :GUC_SUBMIT_ENGINE_SINGLE_LRC ; +int max_guc_ids =intel_context_is_parent (ce) ? +NUMBER_MULTI_LRC_GUC_ID (guc) : + guc->num_guc_ids -NUMBER_MULTI_LRC_GUC_ID (guc);GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link));if (submission_disabled (guc) ||context_guc_id_invalid (ce) || !lrc_desc_registered (guc, ce->guc_id)) {@@ -2936,6 +3169,18 @@ static void guc_context_sched_disable(struct intel_context *ce)if (!context_enabled (ce)) goto unpin; +/* +* If no guc_id pressure and the context isn't closed we delay the +* schedule disable to not to continuously disable / enable scheduling +* putting pressure on both the i915 and GuC. Delay is configurable via +* debugfs, default 1s. +*/ +if (!guc_id_pressure (max_guc_ids, guc->guc_ids_in_use[guc_id_index]) && + !intel_context_is_closed (ce) && guc->sched_disable_delay_ns) { +sched_disable_context_add (guc, ce); +return ; + } +spin_lock_irqsave (&ce->guc_state.lock, flags);/* @@ -3294,6 +3539,58 @@ static void remove_from_context(struct i915_request *rq)i915_request_notify_execute_cb_imm (rq); } +static void __guc_context_close (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +struct intel_runtime_pm *runtime_pm = + ce->engine->uncore->rpm; +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); + goto update_list; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); + goto update_list; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); +update_list: +____sched_disable_context_delete (guc, ce); + } +} + +static void guc_context_close (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +/* +* If we close the context and a schedule disable is pending a delay, do +* it immediately. +*/ +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__guc_context_close (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} +static struct intel_context * guc_create_parallel(struct intel_engine_cs **engines, unsigned int num_siblings,@@ -3308,6 +3605,7 @@ static const struct intel_context_ops guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3538,6 +3836,10 @@ static int guc_request_alloc(struct i915_request *rq) rq->reserved_space -=GUC_REQUEST_SIZE ; +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link) && +atomic_read (&ce->pin_count) <3 ); +sched_disable_context_delete (ce); +/* * guc_ids are exhausted or a heuristic is met indicating too many * guc_ids are waiting on requests with submission dependencies (not @@ -3667,7 +3969,7 @@ static void guc_virtual_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);for_each_engine_masked (engine, ce->engine->gt, mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); }static void guc_virtual_context_enter (struct intel_context *ce)@@ -3708,6 +4010,7 @@ static const struct intel_context_ops virtual_guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3819,6 +4122,7 @@ static const struct intel_context_ops virtual_parent_context_ops = { .post_unpin = guc_parent_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .enter = guc_virtual_context_enter, .exit = guc_virtual_context_exit,@@ -4924,7 +5228,11 @@ void intel_guc_submission_print_info(struct intel_guc *guc,drm_printf (p,"GuC Number Outstanding Submission G2H: %u\n" ,atomic_read (&guc->outstanding_submission_g2h));drm_printf (p,"GuC Number GuC IDs: %d\n" , guc->num_guc_ids); -drm_printf (p,"GuC Max Number GuC IDs: %d\n\n" , guc->max_guc_ids); +drm_printf (p,"GuC Max Number GuC IDs: %d\n" , guc->max_guc_ids); +drm_printf (p,"GuC single-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]); +drm_printf (p,"GuC multi-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ]);drm_printf (p,"GuC max context registered: %u\n\n" , guc->lrcd_reg.max_idx);drivers/gpu/drm/i915/gt/uc/selftest_guc_flow_control.c +15
-4@@ -174,7 +174,8 @@ static int multi_lrc_not_blocked(struct intel_gt *gt, bool flow_control)#define NUM_RQ_PER_CONTEXT 2#define HEARTBEAT_INTERVAL 1500 -static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids,bool hang) +static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids, +bool hang,bool sched_disable_delay) {struct intel_gt *gt = arg;struct intel_guc *guc = >->uc.guc;@@ -203,6 +204,9 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangif (limit_guc_ids) guc->num_guc_ids =NUM_GUC_ID ; +if (sched_disable_delay) + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS /5 ; + ce =intel_context_create (intel_selftest_find_any_engine (gt));if (IS_ERR (ce)) { ret =PTR_ERR (ce);@@ -391,6 +395,7 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hang guc->num_guc_ids = guc->max_guc_ids; guc->gse_hang_expected = false; guc->inject_bad_sched_disable = false; + guc->sched_disable_delay_ns =0 ;kfree (contexts);return ret;@@ -398,17 +403,22 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangstatic int intel_guc_flow_control_guc_ids (void *arg) { -return __intel_guc_flow_control_guc (arg, true, false); +return __intel_guc_flow_control_guc (arg, true, false, false); +} + +static int intel_guc_flow_control_guc_ids_sched_disable_delay (void *arg) +{ +return __intel_guc_flow_control_guc (arg, true, false, true); }static int intel_guc_flow_control_lrcd_reg (void *arg) { -return __intel_guc_flow_control_guc (arg, false, false); +return __intel_guc_flow_control_guc (arg, false, false, false); }static int intel_guc_flow_control_hang_state_machine (void *arg) { -return __intel_guc_flow_control_guc (arg, true, true); +return __intel_guc_flow_control_guc (arg, true, true, false); }#define NUM_RQ_STRESS_CTBS 0x4000@@ -861,6 +871,7 @@ int intel_guc_flow_control(struct drm_i915_private *i915)static const struct i915_subtest tests[] = {SUBTEST (intel_guc_flow_control_stress_ctbs),SUBTEST (intel_guc_flow_control_guc_ids), +SUBTEST (intel_guc_flow_control_guc_ids_sched_disable_delay),SUBTEST (intel_guc_flow_control_lrcd_reg),SUBTEST (intel_guc_flow_control_hang_state_machine),SUBTEST (intel_guc_flow_control_multi_lrc_guc_ids),drivers/gpu/drm/i915/i915_selftest.h +2
-0@@ -92,12 +92,14 @@ int __i915_subtests(const char *caller, T, ARRAY_SIZE(T), data)#define i915_live_subtests (T , data) ({ \ typecheck(struct drm_i915_private *, data); \ + (data)->gt.uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __i915_live_setup, __i915_live_teardown, \ T, ARRAY_SIZE(T), data); \ })#define intel_gt_live_subtests (T , data) ({ \ typecheck(struct intel_gt *, data); \ + (data)->uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __intel_gt_live_setup, __intel_gt_live_teardown, \ T, ARRAY_SIZE(T), data); \drivers/gpu/drm/i915/i915_trace.h +10
-0@@ -933,6 +933,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,TP_ARGS (ce) ); +DEFINE_EVENT (intel_context, intel_context_close, + TP_PROTO(struct intel_context *ce), +TP_ARGS (ce) +); +DEFINE_EVENT (intel_context, intel_context_ban, TP_PROTO(struct intel_context *ce), TP_ARGS(ce)@@ -1035,6 +1040,11 @@ trace_intel_context_reset(struct intel_context *ce) { } +static inline void +trace_intel_context_close (struct intel_context *ce) +{ +} +static inline void trace_intel_context_ban (struct intel_context *ce) {drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +1
-1@@ -2112,5 +2112,5 @@ int i915_gem_gtt_live_selftests(struct drm_i915_private *i915)GEM_BUG_ON (offset_in_page (i915->ggtt.vm.total)); -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/selftests/i915_perf.c +1
-1@@ -431,7 +431,7 @@ int i915_perf_live_selftests(struct drm_i915_private *i915)if (err)return err; - err =i915_subtests (tests, i915); + err =i915_live_subtests (tests, i915);destroy_empty_config (&i915->perf);drivers/gpu/drm/i915/selftests/i915_request.c +1
-1@@ -1693,7 +1693,7 @@ int i915_request_live_selftests(struct drm_i915_private *i915)if (intel_gt_is_wedged (&i915->gt))return 0 ; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }static int switch_to_kernel_sync (struct intel_context *ce,int err)drivers/gpu/drm/i915/selftests/i915_vma.c +1
-1@@ -1085,5 +1085,5 @@ int i915_vma_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_vma_remapped_gtt), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [PATCH 46/46] drm/i915/guc: Add delay before disabling scheduling on contexts
Quoted 23 lines · Matthew Brost
Quoted 15 lines · Daniel Vetter
Quoted 14 lines · Matthew Brost
Some workloads use lots of contexts that continually pin / unpin contexts. With GuC submission an unpin translates to a schedule disable H2G which puts pressure on both the i915 and GuC. A schedule disable can also block future requests from being submitted until the operation completes. None of this is ideal.
Add a configurable, via debugfs, delay period before the schedule disable is issued. Default delay period is 1 second. The delay period is skipped if more than 3/4 of the
guc_idsare in use.This patch also updates the selftests to turn off this delay period as this extra time would likely cause many selftests to fail. Follow up patches will fix all the selftests and enable the delay period.
Quoted 6 lines
Quoted 1 line
Signed-off-by Matthew Brost <[email protected]>I think this is more evidence that we should just pin/unpin context at create/destruction time. The current scheme doesn't really work that well and causes way more pain than benefits it seems.
Quoted 6 lines
Well that choice is above my pay grade, but for what it is worth it would simplify the GuC backend quite a bit if we perma-pin contexts. By quite a bit, I actually mean a lot of complexity goes away.
In the meantime I think we probably need this code though to avoid trashes on the scheduling enable / disable.
The trouble is that you muck around with the context close state bit, which is one of these lockless trickeries where my cursory analysis (just a few days in total of randomly stumbling over it when reading other code) strongly suggests it's busted.
I really don't want to build more on top, especially not without careful review and all that.
Also since this is a perf claim, the commit message needs some numbers.
Finally even if we decide to make contexts properly evictable, we need a different scheme anyway. As you realized the current active tracking is kinda backwards because it unpins immediately when no longer in use. -Daniel
Quoted 891 lines
Matt
Quoted 888 lines
If anyone screams, and that's a big if aside of some igts, we can come up with a proper scheme to evict contexts without pin/unpin and layer hacks over that misdesign.
-DanielQuoted 878 lines
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +- .../i915/gem/selftests/i915_gem_coherency.c | 2 +- .../drm/i915/gem/selftests/i915_gem_dmabuf.c | 2 +- .../drm/i915/gem/selftests/i915_gem_mman.c | 2 +- .../drm/i915/gem/selftests/i915_gem_object.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 9 + drivers/gpu/drm/i915/gt/intel_context_types.h | 8 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 7 + .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 28 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 322 +++++++++++++++++- .../i915/gt/uc/selftest_guc_flow_control.c | 19 +- drivers/gpu/drm/i915/i915_selftest.h | 2 + drivers/gpu/drm/i915/i915_trace.h | 10 + drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 2 +- drivers/gpu/drm/i915/selftests/i915_perf.c | 2 +- drivers/gpu/drm/i915/selftests/i915_request.c | 2 +- drivers/gpu/drm/i915/selftests/i915_vma.c | 2 +- 18 files changed, 405 insertions(+), 20 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +1
-1@@ -1298,7 +1298,7 @@ static void engines_idle_release(struct i915_gem_context *ctx,int err;/* serialises with execbuf */ -set_bit (CONTEXT_CLOSED_BIT , &ce->flags); +intel_context_close (ce);if (!intel_context_pin_if_active (ce))continue ;drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +1
-1@@ -434,5 +434,5 @@ int i915_gem_coherency_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_coherency), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c +1
-1@@ -474,5 +474,5 @@ int i915_gem_dmabuf_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_dmabuf_import_same_driver_lmem_smem), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +1
-1@@ -1414,5 +1414,5 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_mmap_gpu), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_object.c +1
-1@@ -95,5 +95,5 @@ int i915_gem_object_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_huge), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gt/intel_context.c +2
-0@@ -472,6 +472,8 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link); +INIT_LIST_HEAD (&ce->guc_sched_disable_link); +mutex_init (&ce->parallel_submit); ce->fence_context =dma_fence_context_alloc (1 );drivers/gpu/drm/i915/gt/intel_context.h +9
-0@@ -215,6 +215,15 @@ static inline bool intel_context_is_barrier(const struct intel_context *ce)return test_bit (CONTEXT_BARRIER_BIT , &ce->flags); } +static inline void intel_context_close (struct intel_context *ce) +{ +set_bit (CONTEXT_CLOSED_BIT , &ce->flags); + +trace_intel_context_close (ce); +if (ce->ops->close) + ce->ops->close (ce); +} +static inline bool intel_context_is_closed (const struct intel_context *ce) {return test_bit (CONTEXT_CLOSED_BIT , &ce->flags);drivers/gpu/drm/i915/gt/intel_context_types.h +8
-0@@ -11,6 +11,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/types.h> +#include <linux/ktime.h> #include "i915_active_types.h" #include "i915_sw_fence.h" @@ -38,6 +39,7 @@ struct intel_context_ops {int (*alloc)(struct intel_context *ce);void (*ban)(struct intel_context *ce,struct i915_request *rq); +void (*close)(struct intel_context *ce);int (*pre_pin)(struct intel_context *ce,struct i915_gem_ww_ctx *ww);int (*pin)(struct intel_context *ce);@@ -203,6 +205,12 @@ struct intel_context {*/ struct list_head guc_id_link; +/* +* GuC schedule disable link / time +*/ +struct list_head guc_sched_disable_link; +ktime_t guc_sched_disable_time; +/* GuC context blocked fence */ struct i915_sw_fence guc_blocked;drivers/gpu/drm/i915/gt/uc/intel_guc.h +7
-0@@ -60,6 +60,7 @@ struct intel_guc {struct ida guc_ids;u32 num_guc_ids;u32 max_guc_ids; +u32 guc_ids_in_use[GUC_SUBMIT_ENGINE_MAX ];unsigned long *guc_ids_bitmap;#define MAX_GUC_ID_ORDER (order_base_2(MAX_ENGINE_INSTANCE + 1))struct list_head guc_id_list_no_ref[MAX_GUC_ID_ORDER +1 ];@@ -69,6 +70,12 @@ struct intel_guc {struct list_head destroyed_contexts;struct intel_gt_pm_unpark_work destroy_worker; +spinlock_t sched_disable_lock;/* protects schedule disable list */ +struct list_head sched_disable_list; +struct hrtimer sched_disable_timer; +#define SCHED_DISABLE_DELAY_NS 1000000000 +u64 sched_disable_delay_ns; +bool submission_supported;bool submission_selected;drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +28
-0@@ -80,12 +80,40 @@ static int guc_num_id_set(void *data, u64 val) }DEFINE_SIMPLE_ATTRIBUTE (guc_num_id_fops, guc_num_id_get, guc_num_id_set,"%lld\n" ); +static int guc_sched_disable_delay_ns_get (void *data,u64 *val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + *val = guc->sched_disable_delay_ns; + +return 0 ; +} + +static int guc_sched_disable_delay_ns_set (void *data,u64 val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + guc->sched_disable_delay_ns = val; + +return 0 ; +} +DEFINE_SIMPLE_ATTRIBUTE (guc_sched_disable_delay_ns_fops, + guc_sched_disable_delay_ns_get, + guc_sched_disable_delay_ns_set,"%lld\n" ); +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 }, {"guc_num_id" , &guc_num_id_fops,NULL }, + {"guc_sched_disable_delay_ns" , &guc_sched_disable_delay_ns_fops,NULL }, };if (!intel_guc_is_supported (guc))drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +315
-7@@ -654,11 +654,15 @@ int intel_guc_wait_for_pending_msg(struct intel_guc *guc,return (timeout <0 ) ? timeout :0 ; } +static void sched_disable_contexts_flush (struct intel_guc *guc); +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) {if (!intel_uc_uses_guc_submission (&guc_to_gt (guc)->uc))return 0 ; +sched_disable_contexts_flush (guc); +return intel_guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, true, timeout);@@ -1135,6 +1139,7 @@ static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);static void guc_signal_context_fence (struct intel_context *ce);static void guc_cancel_context_requests (struct intel_context *ce);static void guc_blocked_fence_complete (struct intel_context *ce); +static void sched_disable_context_delete (struct intel_context *ce);static void scrub_guc_desc_for_outstanding_g2h (struct intel_guc *guc) {@@ -1160,6 +1165,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc) deregister =context_wait_for_deregister_to_register (ce); banned =context_banned (ce);init_sched_state (ce); +sched_disable_context_delete (ce);if (pending_enable || destroyed || deregister) {atomic_dec (&guc->outstanding_submission_g2h);@@ -1299,6 +1305,7 @@ void intel_guc_submission_reset_prepare(struct intel_guc *guc)intel_gt_park_heartbeats (guc_to_gt (guc));disable_submission (guc); +hrtimer_cancel (&guc->sched_disable_timer); guc->interrupts.disable (guc);/* Flush IRQ handler */ @@ -1656,6 +1663,8 @@ static void guc_lrcd_reg_fini(struct intel_guc *guc);static void destroy_worker_func (struct work_struct *w); +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer); +/* * Set up the memory resources to be shared with the GuC (via the GGTT) * at firmware loading time. @@ -1687,6 +1696,13 @@ int intel_guc_submission_init(struct intel_guc *guc)INIT_LIST_HEAD (&guc->destroyed_contexts);intel_gt_pm_unpark_work_init (&guc->destroy_worker, destroy_worker_func); +spin_lock_init (&guc->sched_disable_lock); +INIT_LIST_HEAD (&guc->sched_disable_list); +hrtimer_init (&guc->sched_disable_timer,CLOCK_MONOTONIC , +HRTIMER_MODE_REL ); + guc->sched_disable_timer.function = sched_disable_timer_func; + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS ; +return 0 ; }@@ -1852,6 +1868,12 @@ static int new_guc_id(struct intel_guc *guc, struct intel_context *ce)if (unlikely (ret <0 ))return ret; +if (intel_context_is_parent (ce)) + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 ); +else + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]++; + ce->guc_id = ret;return 0 ; }@@ -1860,13 +1882,18 @@ static void __release_guc_id(struct intel_guc *guc, struct intel_context *ce) {GEM_BUG_ON (intel_context_is_child (ce));if (!context_guc_id_invalid (ce)) { -if (intel_context_is_parent (ce)) +if (intel_context_is_parent (ce)) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (ce->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, ce->guc_id,order_base_2 (ce->guc_number_children +1 )); -else + }else { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]--;ida_simple_remove (&guc->guc_ids, ce->guc_id); + }clr_lrc_desc_registered (guc, ce->guc_id); +set_context_guc_id_invalid (ce); }if (!list_empty (&ce->guc_id_link))@@ -1931,9 +1958,13 @@ static int steal_guc_id(struct intel_guc *guc, struct intel_context *ce,* from another context that has more guc_id that itself. */ if (cn_o2 != ce_o2) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (cn->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, cn->guc_id, cn_o2); + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 );bitmap_allocate_region (guc->guc_ids_bitmap, ce->guc_id, ce_o2);@@ -2538,7 +2569,7 @@ static void guc_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);if (likely (!intel_context_is_barrier (ce))) -intel_engine_pm_put (ce->engine); +intel_engine_pm_put_async (ce->engine); }static void guc_context_post_unpin (struct intel_context *ce)@@ -2665,11 +2696,11 @@ static void guc_parent_context_unpin(struct intel_context *ce)for_each_engine_masked (engine, ce->engine->gt, ce->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine);for_each_child (ce, child)for_each_engine_masked (engine, child->engine->gt, child->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); } static void __guc_context_sched_enable(struct intel_guc *guc,@@ -2788,6 +2819,8 @@ static struct i915_sw_fence *guc_context_block(struct intel_context *ce)spin_unlock_irqrestore (&ce->guc_state.lock, flags); +sched_disable_context_delete (ce); + with_intel_runtime_pm(runtime_pm, wakeref)__guc_context_sched_disable (guc, ce, guc_id);@@ -2914,8 +2947,202 @@ static void guc_context_ban(struct intel_context *ce, struct i915_request *rq) 1);spin_unlock_irqrestore (&ce->guc_state.lock, flags); } + +sched_disable_context_delete (ce); +} + +#define next_sched_disable_time (guc, now, ce) \ + (guc->sched_disable_delay_ns - \ + (ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time))) +static void ____sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +bool is_first; + +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (list_empty (&ce->guc_sched_disable_link)); + + is_first =list_is_first (&ce->guc_sched_disable_link, + &guc->sched_disable_list); +list_del_init (&ce->guc_sched_disable_link); +if (list_empty (&guc->sched_disable_list)) { +hrtimer_try_to_cancel (&guc->sched_disable_timer); + }else if (is_first) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc,ktime_get (), + first); + +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (next_time), +HRTIMER_MODE_REL_PINNED ); + } +} + +static void __sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +intel_context_sched_disable_unpin (ce); +____sched_disable_context_delete (guc, ce); + } +} + +static void sched_disable_context_delete (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__sched_disable_context_delete (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} + +static void sched_disable_context_add (struct intel_guc *guc, +struct intel_context *ce) +{ +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link)); + + ce->guc_sched_disable_time =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); +if (list_empty (&guc->sched_disable_list)) +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (guc->sched_disable_delay_ns), +HRTIMER_MODE_REL_PINNED ); +list_add_tail (&ce->guc_sched_disable_link, &guc->sched_disable_list); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); +} + +static void sched_disable_contexts_flush (struct intel_guc *guc) +{ +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +hrtimer_try_to_cancel (&guc->sched_disable_timer); + +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); } +#define should_sched_be_disabled (guc, now, ce) \ + ((ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time)) > \ + (guc->sched_disable_delay_ns / 4) * 3) +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer) +{ + struct intel_guc *guc = container_of(hrtimer, struct intel_guc, + sched_disable_timer); +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; +ktime_t now; + +if (list_empty (&guc->sched_disable_list)) +return HRTIMER_NORESTART ; + + now =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +/* +* If a context has been waiting for 3/4 of its delay or more, +* issue the schedule disable. Using this heuristic allows more +* than 1 context to have its scheduling disabled when this +* timer is run. +*/ +if (!should_sched_be_disabled (guc, now, ce)) +break ; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +if (!list_empty (&guc->sched_disable_list)) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc, now, first); + +hrtimer_forward (hrtimer, now,ns_to_ktime (next_time)); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_RESTART ; + }else { +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_NORESTART ; + } +} + +#define guc_id_pressure (max, in_use) (in_use > (max / 4) * 3)static void guc_context_sched_disable (struct intel_context *ce) {struct intel_guc *guc =ce_to_guc (ce);@@ -2924,8 +3151,14 @@ static void guc_context_sched_disable(struct intel_context *ce)intel_wakeref_t wakeref;u16 guc_id;bool enabled; +int guc_id_index =intel_context_is_parent (ce) ? +GUC_SUBMIT_ENGINE_MULTI_LRC :GUC_SUBMIT_ENGINE_SINGLE_LRC ; +int max_guc_ids =intel_context_is_parent (ce) ? +NUMBER_MULTI_LRC_GUC_ID (guc) : + guc->num_guc_ids -NUMBER_MULTI_LRC_GUC_ID (guc);GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link));if (submission_disabled (guc) ||context_guc_id_invalid (ce) || !lrc_desc_registered (guc, ce->guc_id)) {@@ -2936,6 +3169,18 @@ static void guc_context_sched_disable(struct intel_context *ce)if (!context_enabled (ce)) goto unpin; +/* +* If no guc_id pressure and the context isn't closed we delay the +* schedule disable to not to continuously disable / enable scheduling +* putting pressure on both the i915 and GuC. Delay is configurable via +* debugfs, default 1s. +*/ +if (!guc_id_pressure (max_guc_ids, guc->guc_ids_in_use[guc_id_index]) && + !intel_context_is_closed (ce) && guc->sched_disable_delay_ns) { +sched_disable_context_add (guc, ce); +return ; + } +spin_lock_irqsave (&ce->guc_state.lock, flags);/* @@ -3294,6 +3539,58 @@ static void remove_from_context(struct i915_request *rq)i915_request_notify_execute_cb_imm (rq); } +static void __guc_context_close (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +struct intel_runtime_pm *runtime_pm = + ce->engine->uncore->rpm; +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); + goto update_list; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); + goto update_list; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); +update_list: +____sched_disable_context_delete (guc, ce); + } +} + +static void guc_context_close (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +/* +* If we close the context and a schedule disable is pending a delay, do +* it immediately. +*/ +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__guc_context_close (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} +static struct intel_context * guc_create_parallel(struct intel_engine_cs **engines, unsigned int num_siblings,@@ -3308,6 +3605,7 @@ static const struct intel_context_ops guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3538,6 +3836,10 @@ static int guc_request_alloc(struct i915_request *rq) rq->reserved_space -=GUC_REQUEST_SIZE ; +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link) && +atomic_read (&ce->pin_count) <3 ); +sched_disable_context_delete (ce); +/* * guc_ids are exhausted or a heuristic is met indicating too many * guc_ids are waiting on requests with submission dependencies (not @@ -3667,7 +3969,7 @@ static void guc_virtual_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);for_each_engine_masked (engine, ce->engine->gt, mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); }static void guc_virtual_context_enter (struct intel_context *ce)@@ -3708,6 +4010,7 @@ static const struct intel_context_ops virtual_guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3819,6 +4122,7 @@ static const struct intel_context_ops virtual_parent_context_ops = { .post_unpin = guc_parent_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .enter = guc_virtual_context_enter, .exit = guc_virtual_context_exit,@@ -4924,7 +5228,11 @@ void intel_guc_submission_print_info(struct intel_guc *guc,drm_printf (p,"GuC Number Outstanding Submission G2H: %u\n" ,atomic_read (&guc->outstanding_submission_g2h));drm_printf (p,"GuC Number GuC IDs: %d\n" , guc->num_guc_ids); -drm_printf (p,"GuC Max Number GuC IDs: %d\n\n" , guc->max_guc_ids); +drm_printf (p,"GuC Max Number GuC IDs: %d\n" , guc->max_guc_ids); +drm_printf (p,"GuC single-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]); +drm_printf (p,"GuC multi-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ]);drm_printf (p,"GuC max context registered: %u\n\n" , guc->lrcd_reg.max_idx);drivers/gpu/drm/i915/gt/uc/selftest_guc_flow_control.c +15
-4@@ -174,7 +174,8 @@ static int multi_lrc_not_blocked(struct intel_gt *gt, bool flow_control)#define NUM_RQ_PER_CONTEXT 2#define HEARTBEAT_INTERVAL 1500 -static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids,bool hang) +static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids, +bool hang,bool sched_disable_delay) {struct intel_gt *gt = arg;struct intel_guc *guc = >->uc.guc;@@ -203,6 +204,9 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangif (limit_guc_ids) guc->num_guc_ids =NUM_GUC_ID ; +if (sched_disable_delay) + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS /5 ; + ce =intel_context_create (intel_selftest_find_any_engine (gt));if (IS_ERR (ce)) { ret =PTR_ERR (ce);@@ -391,6 +395,7 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hang guc->num_guc_ids = guc->max_guc_ids; guc->gse_hang_expected = false; guc->inject_bad_sched_disable = false; + guc->sched_disable_delay_ns =0 ;kfree (contexts);return ret;@@ -398,17 +403,22 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangstatic int intel_guc_flow_control_guc_ids (void *arg) { -return __intel_guc_flow_control_guc (arg, true, false); +return __intel_guc_flow_control_guc (arg, true, false, false); +} + +static int intel_guc_flow_control_guc_ids_sched_disable_delay (void *arg) +{ +return __intel_guc_flow_control_guc (arg, true, false, true); }static int intel_guc_flow_control_lrcd_reg (void *arg) { -return __intel_guc_flow_control_guc (arg, false, false); +return __intel_guc_flow_control_guc (arg, false, false, false); }static int intel_guc_flow_control_hang_state_machine (void *arg) { -return __intel_guc_flow_control_guc (arg, true, true); +return __intel_guc_flow_control_guc (arg, true, true, false); }#define NUM_RQ_STRESS_CTBS 0x4000@@ -861,6 +871,7 @@ int intel_guc_flow_control(struct drm_i915_private *i915)static const struct i915_subtest tests[] = {SUBTEST (intel_guc_flow_control_stress_ctbs),SUBTEST (intel_guc_flow_control_guc_ids), +SUBTEST (intel_guc_flow_control_guc_ids_sched_disable_delay),SUBTEST (intel_guc_flow_control_lrcd_reg),SUBTEST (intel_guc_flow_control_hang_state_machine),SUBTEST (intel_guc_flow_control_multi_lrc_guc_ids),drivers/gpu/drm/i915/i915_selftest.h +2
-0@@ -92,12 +92,14 @@ int __i915_subtests(const char *caller, T, ARRAY_SIZE(T), data)#define i915_live_subtests (T , data) ({ \ typecheck(struct drm_i915_private *, data); \ + (data)->gt.uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __i915_live_setup, __i915_live_teardown, \ T, ARRAY_SIZE(T), data); \ })#define intel_gt_live_subtests (T , data) ({ \ typecheck(struct intel_gt *, data); \ + (data)->uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __intel_gt_live_setup, __intel_gt_live_teardown, \ T, ARRAY_SIZE(T), data); \drivers/gpu/drm/i915/i915_trace.h +10
-0@@ -933,6 +933,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,TP_ARGS (ce) ); +DEFINE_EVENT (intel_context, intel_context_close, + TP_PROTO(struct intel_context *ce), +TP_ARGS (ce) +); +DEFINE_EVENT (intel_context, intel_context_ban, TP_PROTO(struct intel_context *ce), TP_ARGS(ce)@@ -1035,6 +1040,11 @@ trace_intel_context_reset(struct intel_context *ce) { } +static inline void +trace_intel_context_close (struct intel_context *ce) +{ +} +static inline void trace_intel_context_ban (struct intel_context *ce) {drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +1
-1@@ -2112,5 +2112,5 @@ int i915_gem_gtt_live_selftests(struct drm_i915_private *i915)GEM_BUG_ON (offset_in_page (i915->ggtt.vm.total)); -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/selftests/i915_perf.c +1
-1@@ -431,7 +431,7 @@ int i915_perf_live_selftests(struct drm_i915_private *i915)if (err)return err; - err =i915_subtests (tests, i915); + err =i915_live_subtests (tests, i915);destroy_empty_config (&i915->perf);drivers/gpu/drm/i915/selftests/i915_request.c +1
-1@@ -1693,7 +1693,7 @@ int i915_request_live_selftests(struct drm_i915_private *i915)if (intel_gt_is_wedged (&i915->gt))return 0 ; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }static int switch_to_kernel_sync (struct intel_context *ce,int err)drivers/gpu/drm/i915/selftests/i915_vma.c +1
-1@@ -1085,5 +1085,5 @@ int i915_vma_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_vma_remapped_gtt), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [PATCH 46/46] drm/i915/guc: Add delay before disabling scheduling on contexts
Quoted 24 lines · Daniel Vetter
Quoted 23 lines · Matthew Brost
Quoted 21 lines · Daniel Vetter
Quoted 10 lines · Matthew Brost
Some workloads use lots of contexts that continually pin / unpin contexts. With GuC submission an unpin translates to a schedule disable H2G which puts pressure on both the i915 and GuC. A schedule disable can also block future requests from being submitted until the operation completes. None of this is ideal.
Add a configurable, via debugfs, delay period before the schedule disable is issued. Default delay period is 1 second. The delay period is skipped if more than 3/4 of the
guc_idsare in use.Quoted 5 lines
This patch also updates the selftests to turn off this delay period as this extra time would likely cause many selftests to fail. Follow up patches will fix all the selftests and enable the delay period.
Signed-off-by Matthew Brost <[email protected]>I think this is more evidence that we should just pin/unpin context at create/destruction time. The current scheme doesn't really work that well and causes way more pain than benefits it seems.
Quoted 8 lines
Quoted 6 lines
Well that choice is above my pay grade, but for what it is worth it would simplify the GuC backend quite a bit if we perma-pin contexts. By quite a bit, I actually mean a lot of complexity goes away.
In the meantime I think we probably need this code though to avoid trashes on the scheduling enable / disable.
The trouble is that you muck around with the context close state bit,
This really doesn't mess this bit anymore that what is there, it just adds callback to the backend.
Quoted 9 lines
which is one of these lockless trickeries where my cursory analysis (just a few days in total of randomly stumbling over it when reading other code) strongly suggests it's busted.
I really don't want to build more on top, especially not without careful review and all that.
Also since this is a perf claim, the commit message needs some numbers.
This was basically just visual inspection of ftrace of a media workload that uses lots of contexts. The contexts were repeatedly pinned / unpinned. Disabling / enabling scheduling is a rather expensive operation so we really shouldn't be doing it all the time. We visually observed an ftrace after this change and all this unnecessary traffic went away.
Quoted 3 lines
Finally even if we decide to make contexts properly evictable, we need a different scheme anyway. As you realized the current active tracking is kinda backwards because it unpins immediately when no longer in use.
Right, this basically just works around the fact that contexts are immediately unpinned when not in use. As stated before if we perma-pin contexts all this goes away.
Matt
Quoted 898 lines
-Daniel
Quoted 891 lines
Matt
Quoted 888 lines
If anyone screams, and that's a big if aside of some igts, we can come up with a proper scheme to evict contexts without pin/unpin and layer hacks over that misdesign.
-DanielQuoted 878 lines
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +- .../i915/gem/selftests/i915_gem_coherency.c | 2 +- .../drm/i915/gem/selftests/i915_gem_dmabuf.c | 2 +- .../drm/i915/gem/selftests/i915_gem_mman.c | 2 +- .../drm/i915/gem/selftests/i915_gem_object.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 9 + drivers/gpu/drm/i915/gt/intel_context_types.h | 8 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 7 + .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 28 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 322 +++++++++++++++++- .../i915/gt/uc/selftest_guc_flow_control.c | 19 +- drivers/gpu/drm/i915/i915_selftest.h | 2 + drivers/gpu/drm/i915/i915_trace.h | 10 + drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 2 +- drivers/gpu/drm/i915/selftests/i915_perf.c | 2 +- drivers/gpu/drm/i915/selftests/i915_request.c | 2 +- drivers/gpu/drm/i915/selftests/i915_vma.c | 2 +- 18 files changed, 405 insertions(+), 20 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +1
-1@@ -1298,7 +1298,7 @@ static void engines_idle_release(struct i915_gem_context *ctx,int err;/* serialises with execbuf */ -set_bit (CONTEXT_CLOSED_BIT , &ce->flags); +intel_context_close (ce);if (!intel_context_pin_if_active (ce))continue ;drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +1
-1@@ -434,5 +434,5 @@ int i915_gem_coherency_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_coherency), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c +1
-1@@ -474,5 +474,5 @@ int i915_gem_dmabuf_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_dmabuf_import_same_driver_lmem_smem), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +1
-1@@ -1414,5 +1414,5 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_mmap_gpu), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_object.c +1
-1@@ -95,5 +95,5 @@ int i915_gem_object_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_huge), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gt/intel_context.c +2
-0@@ -472,6 +472,8 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link); +INIT_LIST_HEAD (&ce->guc_sched_disable_link); +mutex_init (&ce->parallel_submit); ce->fence_context =dma_fence_context_alloc (1 );drivers/gpu/drm/i915/gt/intel_context.h +9
-0@@ -215,6 +215,15 @@ static inline bool intel_context_is_barrier(const struct intel_context *ce)return test_bit (CONTEXT_BARRIER_BIT , &ce->flags); } +static inline void intel_context_close (struct intel_context *ce) +{ +set_bit (CONTEXT_CLOSED_BIT , &ce->flags); + +trace_intel_context_close (ce); +if (ce->ops->close) + ce->ops->close (ce); +} +static inline bool intel_context_is_closed (const struct intel_context *ce) {return test_bit (CONTEXT_CLOSED_BIT , &ce->flags);drivers/gpu/drm/i915/gt/intel_context_types.h +8
-0@@ -11,6 +11,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/types.h> +#include <linux/ktime.h> #include "i915_active_types.h" #include "i915_sw_fence.h" @@ -38,6 +39,7 @@ struct intel_context_ops {int (*alloc)(struct intel_context *ce);void (*ban)(struct intel_context *ce,struct i915_request *rq); +void (*close)(struct intel_context *ce);int (*pre_pin)(struct intel_context *ce,struct i915_gem_ww_ctx *ww);int (*pin)(struct intel_context *ce);@@ -203,6 +205,12 @@ struct intel_context {*/ struct list_head guc_id_link; +/* +* GuC schedule disable link / time +*/ +struct list_head guc_sched_disable_link; +ktime_t guc_sched_disable_time; +/* GuC context blocked fence */ struct i915_sw_fence guc_blocked;drivers/gpu/drm/i915/gt/uc/intel_guc.h +7
-0@@ -60,6 +60,7 @@ struct intel_guc {struct ida guc_ids;u32 num_guc_ids;u32 max_guc_ids; +u32 guc_ids_in_use[GUC_SUBMIT_ENGINE_MAX ];unsigned long *guc_ids_bitmap;#define MAX_GUC_ID_ORDER (order_base_2(MAX_ENGINE_INSTANCE + 1))struct list_head guc_id_list_no_ref[MAX_GUC_ID_ORDER +1 ];@@ -69,6 +70,12 @@ struct intel_guc {struct list_head destroyed_contexts;struct intel_gt_pm_unpark_work destroy_worker; +spinlock_t sched_disable_lock;/* protects schedule disable list */ +struct list_head sched_disable_list; +struct hrtimer sched_disable_timer; +#define SCHED_DISABLE_DELAY_NS 1000000000 +u64 sched_disable_delay_ns; +bool submission_supported;bool submission_selected;drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +28
-0@@ -80,12 +80,40 @@ static int guc_num_id_set(void *data, u64 val) }DEFINE_SIMPLE_ATTRIBUTE (guc_num_id_fops, guc_num_id_get, guc_num_id_set,"%lld\n" ); +static int guc_sched_disable_delay_ns_get (void *data,u64 *val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + *val = guc->sched_disable_delay_ns; + +return 0 ; +} + +static int guc_sched_disable_delay_ns_set (void *data,u64 val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + guc->sched_disable_delay_ns = val; + +return 0 ; +} +DEFINE_SIMPLE_ATTRIBUTE (guc_sched_disable_delay_ns_fops, + guc_sched_disable_delay_ns_get, + guc_sched_disable_delay_ns_set,"%lld\n" ); +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 }, {"guc_num_id" , &guc_num_id_fops,NULL }, + {"guc_sched_disable_delay_ns" , &guc_sched_disable_delay_ns_fops,NULL }, };if (!intel_guc_is_supported (guc))drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +315
-7@@ -654,11 +654,15 @@ int intel_guc_wait_for_pending_msg(struct intel_guc *guc,return (timeout <0 ) ? timeout :0 ; } +static void sched_disable_contexts_flush (struct intel_guc *guc); +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) {if (!intel_uc_uses_guc_submission (&guc_to_gt (guc)->uc))return 0 ; +sched_disable_contexts_flush (guc); +return intel_guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, true, timeout);@@ -1135,6 +1139,7 @@ static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);static void guc_signal_context_fence (struct intel_context *ce);static void guc_cancel_context_requests (struct intel_context *ce);static void guc_blocked_fence_complete (struct intel_context *ce); +static void sched_disable_context_delete (struct intel_context *ce);static void scrub_guc_desc_for_outstanding_g2h (struct intel_guc *guc) {@@ -1160,6 +1165,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc) deregister =context_wait_for_deregister_to_register (ce); banned =context_banned (ce);init_sched_state (ce); +sched_disable_context_delete (ce);if (pending_enable || destroyed || deregister) {atomic_dec (&guc->outstanding_submission_g2h);@@ -1299,6 +1305,7 @@ void intel_guc_submission_reset_prepare(struct intel_guc *guc)intel_gt_park_heartbeats (guc_to_gt (guc));disable_submission (guc); +hrtimer_cancel (&guc->sched_disable_timer); guc->interrupts.disable (guc);/* Flush IRQ handler */ @@ -1656,6 +1663,8 @@ static void guc_lrcd_reg_fini(struct intel_guc *guc);static void destroy_worker_func (struct work_struct *w); +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer); +/* * Set up the memory resources to be shared with the GuC (via the GGTT) * at firmware loading time. @@ -1687,6 +1696,13 @@ int intel_guc_submission_init(struct intel_guc *guc)INIT_LIST_HEAD (&guc->destroyed_contexts);intel_gt_pm_unpark_work_init (&guc->destroy_worker, destroy_worker_func); +spin_lock_init (&guc->sched_disable_lock); +INIT_LIST_HEAD (&guc->sched_disable_list); +hrtimer_init (&guc->sched_disable_timer,CLOCK_MONOTONIC , +HRTIMER_MODE_REL ); + guc->sched_disable_timer.function = sched_disable_timer_func; + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS ; +return 0 ; }@@ -1852,6 +1868,12 @@ static int new_guc_id(struct intel_guc *guc, struct intel_context *ce)if (unlikely (ret <0 ))return ret; +if (intel_context_is_parent (ce)) + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 ); +else + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]++; + ce->guc_id = ret;return 0 ; }@@ -1860,13 +1882,18 @@ static void __release_guc_id(struct intel_guc *guc, struct intel_context *ce) {GEM_BUG_ON (intel_context_is_child (ce));if (!context_guc_id_invalid (ce)) { -if (intel_context_is_parent (ce)) +if (intel_context_is_parent (ce)) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (ce->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, ce->guc_id,order_base_2 (ce->guc_number_children +1 )); -else + }else { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]--;ida_simple_remove (&guc->guc_ids, ce->guc_id); + }clr_lrc_desc_registered (guc, ce->guc_id); +set_context_guc_id_invalid (ce); }if (!list_empty (&ce->guc_id_link))@@ -1931,9 +1958,13 @@ static int steal_guc_id(struct intel_guc *guc, struct intel_context *ce,* from another context that has more guc_id that itself. */ if (cn_o2 != ce_o2) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (cn->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, cn->guc_id, cn_o2); + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 );bitmap_allocate_region (guc->guc_ids_bitmap, ce->guc_id, ce_o2);@@ -2538,7 +2569,7 @@ static void guc_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);if (likely (!intel_context_is_barrier (ce))) -intel_engine_pm_put (ce->engine); +intel_engine_pm_put_async (ce->engine); }static void guc_context_post_unpin (struct intel_context *ce)@@ -2665,11 +2696,11 @@ static void guc_parent_context_unpin(struct intel_context *ce)for_each_engine_masked (engine, ce->engine->gt, ce->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine);for_each_child (ce, child)for_each_engine_masked (engine, child->engine->gt, child->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); } static void __guc_context_sched_enable(struct intel_guc *guc,@@ -2788,6 +2819,8 @@ static struct i915_sw_fence *guc_context_block(struct intel_context *ce)spin_unlock_irqrestore (&ce->guc_state.lock, flags); +sched_disable_context_delete (ce); + with_intel_runtime_pm(runtime_pm, wakeref)__guc_context_sched_disable (guc, ce, guc_id);@@ -2914,8 +2947,202 @@ static void guc_context_ban(struct intel_context *ce, struct i915_request *rq) 1);spin_unlock_irqrestore (&ce->guc_state.lock, flags); } + +sched_disable_context_delete (ce); +} + +#define next_sched_disable_time (guc, now, ce) \ + (guc->sched_disable_delay_ns - \ + (ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time))) +static void ____sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +bool is_first; + +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (list_empty (&ce->guc_sched_disable_link)); + + is_first =list_is_first (&ce->guc_sched_disable_link, + &guc->sched_disable_list); +list_del_init (&ce->guc_sched_disable_link); +if (list_empty (&guc->sched_disable_list)) { +hrtimer_try_to_cancel (&guc->sched_disable_timer); + }else if (is_first) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc,ktime_get (), + first); + +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (next_time), +HRTIMER_MODE_REL_PINNED ); + } +} + +static void __sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +intel_context_sched_disable_unpin (ce); +____sched_disable_context_delete (guc, ce); + } +} + +static void sched_disable_context_delete (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__sched_disable_context_delete (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} + +static void sched_disable_context_add (struct intel_guc *guc, +struct intel_context *ce) +{ +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link)); + + ce->guc_sched_disable_time =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); +if (list_empty (&guc->sched_disable_list)) +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (guc->sched_disable_delay_ns), +HRTIMER_MODE_REL_PINNED ); +list_add_tail (&ce->guc_sched_disable_link, &guc->sched_disable_list); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); +} + +static void sched_disable_contexts_flush (struct intel_guc *guc) +{ +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +hrtimer_try_to_cancel (&guc->sched_disable_timer); + +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); } +#define should_sched_be_disabled (guc, now, ce) \ + ((ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time)) > \ + (guc->sched_disable_delay_ns / 4) * 3) +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer) +{ + struct intel_guc *guc = container_of(hrtimer, struct intel_guc, + sched_disable_timer); +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; +ktime_t now; + +if (list_empty (&guc->sched_disable_list)) +return HRTIMER_NORESTART ; + + now =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +/* +* If a context has been waiting for 3/4 of its delay or more, +* issue the schedule disable. Using this heuristic allows more +* than 1 context to have its scheduling disabled when this +* timer is run. +*/ +if (!should_sched_be_disabled (guc, now, ce)) +break ; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +if (!list_empty (&guc->sched_disable_list)) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc, now, first); + +hrtimer_forward (hrtimer, now,ns_to_ktime (next_time)); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_RESTART ; + }else { +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_NORESTART ; + } +} + +#define guc_id_pressure (max, in_use) (in_use > (max / 4) * 3)static void guc_context_sched_disable (struct intel_context *ce) {struct intel_guc *guc =ce_to_guc (ce);@@ -2924,8 +3151,14 @@ static void guc_context_sched_disable(struct intel_context *ce)intel_wakeref_t wakeref;u16 guc_id;bool enabled; +int guc_id_index =intel_context_is_parent (ce) ? +GUC_SUBMIT_ENGINE_MULTI_LRC :GUC_SUBMIT_ENGINE_SINGLE_LRC ; +int max_guc_ids =intel_context_is_parent (ce) ? +NUMBER_MULTI_LRC_GUC_ID (guc) : + guc->num_guc_ids -NUMBER_MULTI_LRC_GUC_ID (guc);GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link));if (submission_disabled (guc) ||context_guc_id_invalid (ce) || !lrc_desc_registered (guc, ce->guc_id)) {@@ -2936,6 +3169,18 @@ static void guc_context_sched_disable(struct intel_context *ce)if (!context_enabled (ce)) goto unpin; +/* +* If no guc_id pressure and the context isn't closed we delay the +* schedule disable to not to continuously disable / enable scheduling +* putting pressure on both the i915 and GuC. Delay is configurable via +* debugfs, default 1s. +*/ +if (!guc_id_pressure (max_guc_ids, guc->guc_ids_in_use[guc_id_index]) && + !intel_context_is_closed (ce) && guc->sched_disable_delay_ns) { +sched_disable_context_add (guc, ce); +return ; + } +spin_lock_irqsave (&ce->guc_state.lock, flags);/* @@ -3294,6 +3539,58 @@ static void remove_from_context(struct i915_request *rq)i915_request_notify_execute_cb_imm (rq); } +static void __guc_context_close (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +struct intel_runtime_pm *runtime_pm = + ce->engine->uncore->rpm; +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); + goto update_list; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); + goto update_list; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); +update_list: +____sched_disable_context_delete (guc, ce); + } +} + +static void guc_context_close (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +/* +* If we close the context and a schedule disable is pending a delay, do +* it immediately. +*/ +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__guc_context_close (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} +static struct intel_context * guc_create_parallel(struct intel_engine_cs **engines, unsigned int num_siblings,@@ -3308,6 +3605,7 @@ static const struct intel_context_ops guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3538,6 +3836,10 @@ static int guc_request_alloc(struct i915_request *rq) rq->reserved_space -=GUC_REQUEST_SIZE ; +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link) && +atomic_read (&ce->pin_count) <3 ); +sched_disable_context_delete (ce); +/* * guc_ids are exhausted or a heuristic is met indicating too many * guc_ids are waiting on requests with submission dependencies (not @@ -3667,7 +3969,7 @@ static void guc_virtual_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);for_each_engine_masked (engine, ce->engine->gt, mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); }static void guc_virtual_context_enter (struct intel_context *ce)@@ -3708,6 +4010,7 @@ static const struct intel_context_ops virtual_guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3819,6 +4122,7 @@ static const struct intel_context_ops virtual_parent_context_ops = { .post_unpin = guc_parent_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .enter = guc_virtual_context_enter, .exit = guc_virtual_context_exit,@@ -4924,7 +5228,11 @@ void intel_guc_submission_print_info(struct intel_guc *guc,drm_printf (p,"GuC Number Outstanding Submission G2H: %u\n" ,atomic_read (&guc->outstanding_submission_g2h));drm_printf (p,"GuC Number GuC IDs: %d\n" , guc->num_guc_ids); -drm_printf (p,"GuC Max Number GuC IDs: %d\n\n" , guc->max_guc_ids); +drm_printf (p,"GuC Max Number GuC IDs: %d\n" , guc->max_guc_ids); +drm_printf (p,"GuC single-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]); +drm_printf (p,"GuC multi-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ]);drm_printf (p,"GuC max context registered: %u\n\n" , guc->lrcd_reg.max_idx);drivers/gpu/drm/i915/gt/uc/selftest_guc_flow_control.c +15
-4@@ -174,7 +174,8 @@ static int multi_lrc_not_blocked(struct intel_gt *gt, bool flow_control)#define NUM_RQ_PER_CONTEXT 2#define HEARTBEAT_INTERVAL 1500 -static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids,bool hang) +static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids, +bool hang,bool sched_disable_delay) {struct intel_gt *gt = arg;struct intel_guc *guc = >->uc.guc;@@ -203,6 +204,9 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangif (limit_guc_ids) guc->num_guc_ids =NUM_GUC_ID ; +if (sched_disable_delay) + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS /5 ; + ce =intel_context_create (intel_selftest_find_any_engine (gt));if (IS_ERR (ce)) { ret =PTR_ERR (ce);@@ -391,6 +395,7 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hang guc->num_guc_ids = guc->max_guc_ids; guc->gse_hang_expected = false; guc->inject_bad_sched_disable = false; + guc->sched_disable_delay_ns =0 ;kfree (contexts);return ret;@@ -398,17 +403,22 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangstatic int intel_guc_flow_control_guc_ids (void *arg) { -return __intel_guc_flow_control_guc (arg, true, false); +return __intel_guc_flow_control_guc (arg, true, false, false); +} + +static int intel_guc_flow_control_guc_ids_sched_disable_delay (void *arg) +{ +return __intel_guc_flow_control_guc (arg, true, false, true); }static int intel_guc_flow_control_lrcd_reg (void *arg) { -return __intel_guc_flow_control_guc (arg, false, false); +return __intel_guc_flow_control_guc (arg, false, false, false); }static int intel_guc_flow_control_hang_state_machine (void *arg) { -return __intel_guc_flow_control_guc (arg, true, true); +return __intel_guc_flow_control_guc (arg, true, true, false); }#define NUM_RQ_STRESS_CTBS 0x4000@@ -861,6 +871,7 @@ int intel_guc_flow_control(struct drm_i915_private *i915)static const struct i915_subtest tests[] = {SUBTEST (intel_guc_flow_control_stress_ctbs),SUBTEST (intel_guc_flow_control_guc_ids), +SUBTEST (intel_guc_flow_control_guc_ids_sched_disable_delay),SUBTEST (intel_guc_flow_control_lrcd_reg),SUBTEST (intel_guc_flow_control_hang_state_machine),SUBTEST (intel_guc_flow_control_multi_lrc_guc_ids),drivers/gpu/drm/i915/i915_selftest.h +2
-0@@ -92,12 +92,14 @@ int __i915_subtests(const char *caller, T, ARRAY_SIZE(T), data)#define i915_live_subtests (T , data) ({ \ typecheck(struct drm_i915_private *, data); \ + (data)->gt.uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __i915_live_setup, __i915_live_teardown, \ T, ARRAY_SIZE(T), data); \ })#define intel_gt_live_subtests (T , data) ({ \ typecheck(struct intel_gt *, data); \ + (data)->uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __intel_gt_live_setup, __intel_gt_live_teardown, \ T, ARRAY_SIZE(T), data); \drivers/gpu/drm/i915/i915_trace.h +10
-0@@ -933,6 +933,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,TP_ARGS (ce) ); +DEFINE_EVENT (intel_context, intel_context_close, + TP_PROTO(struct intel_context *ce), +TP_ARGS (ce) +); +DEFINE_EVENT (intel_context, intel_context_ban, TP_PROTO(struct intel_context *ce), TP_ARGS(ce)@@ -1035,6 +1040,11 @@ trace_intel_context_reset(struct intel_context *ce) { } +static inline void +trace_intel_context_close (struct intel_context *ce) +{ +} +static inline void trace_intel_context_ban (struct intel_context *ce) {drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +1
-1@@ -2112,5 +2112,5 @@ int i915_gem_gtt_live_selftests(struct drm_i915_private *i915)GEM_BUG_ON (offset_in_page (i915->ggtt.vm.total)); -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/selftests/i915_perf.c +1
-1@@ -431,7 +431,7 @@ int i915_perf_live_selftests(struct drm_i915_private *i915)if (err)return err; - err =i915_subtests (tests, i915); + err =i915_live_subtests (tests, i915);destroy_empty_config (&i915->perf);drivers/gpu/drm/i915/selftests/i915_request.c +1
-1@@ -1693,7 +1693,7 @@ int i915_request_live_selftests(struct drm_i915_private *i915)if (intel_gt_is_wedged (&i915->gt))return 0 ; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }static int switch_to_kernel_sync (struct intel_context *ce,int err)drivers/gpu/drm/i915/selftests/i915_vma.c +1
-1@@ -1085,5 +1085,5 @@ int i915_vma_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_vma_remapped_gtt), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [PATCH 46/46] drm/i915/guc: Add delay before disabling scheduling on contexts
Quoted 47 lines · Matthew Brost
Quoted 24 lines · Daniel Vetter
Quoted 23 lines · Matthew Brost
Quoted 21 lines · Daniel Vetter
Quoted 10 lines · Matthew Brost
Some workloads use lots of contexts that continually pin / unpin contexts. With GuC submission an unpin translates to a schedule disable H2G which puts pressure on both the i915 and GuC. A schedule disable can also block future requests from being submitted until the operation completes. None of this is ideal.
Add a configurable, via debugfs, delay period before the schedule disable is issued. Default delay period is 1 second. The delay period is skipped if more than 3/4 of the
guc_idsare in use.Quoted 5 lines
This patch also updates the selftests to turn off this delay period as this extra time would likely cause many selftests to fail. Follow up patches will fix all the selftests and enable the delay period.
Signed-off-by Matthew Brost <[email protected]>I think this is more evidence that we should just pin/unpin context at create/destruction time. The current scheme doesn't really work that well and causes way more pain than benefits it seems.
Quoted 8 lines
Quoted 6 lines
Well that choice is above my pay grade, but for what it is worth it would simplify the GuC backend quite a bit if we perma-pin contexts. By quite a bit, I actually mean a lot of complexity goes away.
In the meantime I think we probably need this code though to avoid trashes on the scheduling enable / disable.
The trouble is that you muck around with the context close state bit,
This really doesn't mess this bit anymore that what is there, it just adds callback to the backend.
Quoted 9 lines
which is one of these lockless trickeries where my cursory analysis (just a few days in total of randomly stumbling over it when reading other code) strongly suggests it's busted.
I really don't want to build more on top, especially not without careful review and all that.
Also since this is a perf claim, the commit message needs some numbers.
Quoted 6 lines
This was basically just visual inspection of ftrace of a media workload that uses lots of contexts. The contexts were repeatedly pinned / unpinned. Disabling / enabling scheduling is a rather expensive operation so we really shouldn't be doing it all the time. We visually observed an ftrace after this change and all this unnecessary traffic went away.
That's the kinds of stuff that should be included in the commit message, ideally with some numbers (like how many you manage to remove or whatever metric it is you picked, something quick like done with grep and line counting is good enough).
Quoted 7 lines
Quoted 3 lines
Finally even if we decide to make contexts properly evictable, we need a different scheme anyway. As you realized the current active tracking is kinda backwards because it unpins immediately when no longer in use.
Right, this basically just works around the fact that contexts are immediately unpinned when not in use. As stated before if we perma-pin contexts all this goes away.
Yeah, sounds all good then. Well, more or less.
-Daniel
Quoted 901 lines
Matt
Quoted 898 lines
-Daniel
Quoted 891 lines
Matt
Quoted 888 lines
If anyone screams, and that's a big if aside of some igts, we can come up with a proper scheme to evict contexts without pin/unpin and layer hacks over that misdesign.
-DanielQuoted 878 lines
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +- .../i915/gem/selftests/i915_gem_coherency.c | 2 +- .../drm/i915/gem/selftests/i915_gem_dmabuf.c | 2 +- .../drm/i915/gem/selftests/i915_gem_mman.c | 2 +- .../drm/i915/gem/selftests/i915_gem_object.c | 2 +- drivers/gpu/drm/i915/gt/intel_context.c | 2 + drivers/gpu/drm/i915/gt/intel_context.h | 9 + drivers/gpu/drm/i915/gt/intel_context_types.h | 8 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 7 + .../gpu/drm/i915/gt/uc/intel_guc_debugfs.c | 28 ++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 322 +++++++++++++++++- .../i915/gt/uc/selftest_guc_flow_control.c | 19 +- drivers/gpu/drm/i915/i915_selftest.h | 2 + drivers/gpu/drm/i915/i915_trace.h | 10 + drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 2 +- drivers/gpu/drm/i915/selftests/i915_perf.c | 2 +- drivers/gpu/drm/i915/selftests/i915_request.c | 2 +- drivers/gpu/drm/i915/selftests/i915_vma.c | 2 +- 18 files changed, 405 insertions(+), 20 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +1
-1@@ -1298,7 +1298,7 @@ static void engines_idle_release(struct i915_gem_context *ctx,int err;/* serialises with execbuf */ -set_bit (CONTEXT_CLOSED_BIT , &ce->flags); +intel_context_close (ce);if (!intel_context_pin_if_active (ce))continue ;drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +1
-1@@ -434,5 +434,5 @@ int i915_gem_coherency_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_coherency), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c +1
-1@@ -474,5 +474,5 @@ int i915_gem_dmabuf_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_dmabuf_import_same_driver_lmem_smem), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +1
-1@@ -1414,5 +1414,5 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_mmap_gpu), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gem/selftests/i915_gem_object.c +1
-1@@ -95,5 +95,5 @@ int i915_gem_object_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_gem_huge), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/gt/intel_context.c +2
-0@@ -472,6 +472,8 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine) ce->guc_id =GUC_INVALID_LRC_ID ;INIT_LIST_HEAD (&ce->guc_id_link); +INIT_LIST_HEAD (&ce->guc_sched_disable_link); +mutex_init (&ce->parallel_submit); ce->fence_context =dma_fence_context_alloc (1 );drivers/gpu/drm/i915/gt/intel_context.h +9
-0@@ -215,6 +215,15 @@ static inline bool intel_context_is_barrier(const struct intel_context *ce)return test_bit (CONTEXT_BARRIER_BIT , &ce->flags); } +static inline void intel_context_close (struct intel_context *ce) +{ +set_bit (CONTEXT_CLOSED_BIT , &ce->flags); + +trace_intel_context_close (ce); +if (ce->ops->close) + ce->ops->close (ce); +} +static inline bool intel_context_is_closed (const struct intel_context *ce) {return test_bit (CONTEXT_CLOSED_BIT , &ce->flags);drivers/gpu/drm/i915/gt/intel_context_types.h +8
-0@@ -11,6 +11,7 @@#include <linux/list.h> #include <linux/mutex.h> #include <linux/types.h> +#include <linux/ktime.h> #include "i915_active_types.h" #include "i915_sw_fence.h" @@ -38,6 +39,7 @@ struct intel_context_ops {int (*alloc)(struct intel_context *ce);void (*ban)(struct intel_context *ce,struct i915_request *rq); +void (*close)(struct intel_context *ce);int (*pre_pin)(struct intel_context *ce,struct i915_gem_ww_ctx *ww);int (*pin)(struct intel_context *ce);@@ -203,6 +205,12 @@ struct intel_context {*/ struct list_head guc_id_link; +/* +* GuC schedule disable link / time +*/ +struct list_head guc_sched_disable_link; +ktime_t guc_sched_disable_time; +/* GuC context blocked fence */ struct i915_sw_fence guc_blocked;drivers/gpu/drm/i915/gt/uc/intel_guc.h +7
-0@@ -60,6 +60,7 @@ struct intel_guc {struct ida guc_ids;u32 num_guc_ids;u32 max_guc_ids; +u32 guc_ids_in_use[GUC_SUBMIT_ENGINE_MAX ];unsigned long *guc_ids_bitmap;#define MAX_GUC_ID_ORDER (order_base_2(MAX_ENGINE_INSTANCE + 1))struct list_head guc_id_list_no_ref[MAX_GUC_ID_ORDER +1 ];@@ -69,6 +70,12 @@ struct intel_guc {struct list_head destroyed_contexts;struct intel_gt_pm_unpark_work destroy_worker; +spinlock_t sched_disable_lock;/* protects schedule disable list */ +struct list_head sched_disable_list; +struct hrtimer sched_disable_timer; +#define SCHED_DISABLE_DELAY_NS 1000000000 +u64 sched_disable_delay_ns; +bool submission_supported;bool submission_selected;drivers/gpu/drm/i915/gt/uc/intel_guc_debugfs.c +28
-0@@ -80,12 +80,40 @@ static int guc_num_id_set(void *data, u64 val) }DEFINE_SIMPLE_ATTRIBUTE (guc_num_id_fops, guc_num_id_get, guc_num_id_set,"%lld\n" ); +static int guc_sched_disable_delay_ns_get (void *data,u64 *val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + *val = guc->sched_disable_delay_ns; + +return 0 ; +} + +static int guc_sched_disable_delay_ns_set (void *data,u64 val) +{ +struct intel_guc *guc = data; + +if (!intel_guc_submission_is_used (guc)) +return -ENODEV ; + + guc->sched_disable_delay_ns = val; + +return 0 ; +} +DEFINE_SIMPLE_ATTRIBUTE (guc_sched_disable_delay_ns_fops, + guc_sched_disable_delay_ns_get, + guc_sched_disable_delay_ns_set,"%lld\n" ); +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 }, {"guc_num_id" , &guc_num_id_fops,NULL }, + {"guc_sched_disable_delay_ns" , &guc_sched_disable_delay_ns_fops,NULL }, };if (!intel_guc_is_supported (guc))drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +315
-7@@ -654,11 +654,15 @@ int intel_guc_wait_for_pending_msg(struct intel_guc *guc,return (timeout <0 ) ? timeout :0 ; } +static void sched_disable_contexts_flush (struct intel_guc *guc); +int intel_guc_wait_for_idle (struct intel_guc *guc,long timeout) {if (!intel_uc_uses_guc_submission (&guc_to_gt (guc)->uc))return 0 ; +sched_disable_contexts_flush (guc); +return intel_guc_wait_for_pending_msg (guc, &guc->outstanding_submission_g2h, true, timeout);@@ -1135,6 +1139,7 @@ static void release_guc_id(struct intel_guc *guc, struct intel_context *ce);static void guc_signal_context_fence (struct intel_context *ce);static void guc_cancel_context_requests (struct intel_context *ce);static void guc_blocked_fence_complete (struct intel_context *ce); +static void sched_disable_context_delete (struct intel_context *ce);static void scrub_guc_desc_for_outstanding_g2h (struct intel_guc *guc) {@@ -1160,6 +1165,7 @@ static void scrub_guc_desc_for_outstanding_g2h(struct intel_guc *guc) deregister =context_wait_for_deregister_to_register (ce); banned =context_banned (ce);init_sched_state (ce); +sched_disable_context_delete (ce);if (pending_enable || destroyed || deregister) {atomic_dec (&guc->outstanding_submission_g2h);@@ -1299,6 +1305,7 @@ void intel_guc_submission_reset_prepare(struct intel_guc *guc)intel_gt_park_heartbeats (guc_to_gt (guc));disable_submission (guc); +hrtimer_cancel (&guc->sched_disable_timer); guc->interrupts.disable (guc);/* Flush IRQ handler */ @@ -1656,6 +1663,8 @@ static void guc_lrcd_reg_fini(struct intel_guc *guc);static void destroy_worker_func (struct work_struct *w); +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer); +/* * Set up the memory resources to be shared with the GuC (via the GGTT) * at firmware loading time. @@ -1687,6 +1696,13 @@ int intel_guc_submission_init(struct intel_guc *guc)INIT_LIST_HEAD (&guc->destroyed_contexts);intel_gt_pm_unpark_work_init (&guc->destroy_worker, destroy_worker_func); +spin_lock_init (&guc->sched_disable_lock); +INIT_LIST_HEAD (&guc->sched_disable_list); +hrtimer_init (&guc->sched_disable_timer,CLOCK_MONOTONIC , +HRTIMER_MODE_REL ); + guc->sched_disable_timer.function = sched_disable_timer_func; + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS ; +return 0 ; }@@ -1852,6 +1868,12 @@ static int new_guc_id(struct intel_guc *guc, struct intel_context *ce)if (unlikely (ret <0 ))return ret; +if (intel_context_is_parent (ce)) + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 ); +else + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]++; + ce->guc_id = ret;return 0 ; }@@ -1860,13 +1882,18 @@ static void __release_guc_id(struct intel_guc *guc, struct intel_context *ce) {GEM_BUG_ON (intel_context_is_child (ce));if (!context_guc_id_invalid (ce)) { -if (intel_context_is_parent (ce)) +if (intel_context_is_parent (ce)) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (ce->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, ce->guc_id,order_base_2 (ce->guc_number_children +1 )); -else + }else { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]--;ida_simple_remove (&guc->guc_ids, ce->guc_id); + }clr_lrc_desc_registered (guc, ce->guc_id); +set_context_guc_id_invalid (ce); }if (!list_empty (&ce->guc_id_link))@@ -1931,9 +1958,13 @@ static int steal_guc_id(struct intel_guc *guc, struct intel_context *ce,* from another context that has more guc_id that itself. */ if (cn_o2 != ce_o2) { + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] -= +order_base_2 (cn->guc_number_children +1 );bitmap_release_region (guc->guc_ids_bitmap, cn->guc_id, cn_o2); + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ] += +order_base_2 (ce->guc_number_children +1 );bitmap_allocate_region (guc->guc_ids_bitmap, ce->guc_id, ce_o2);@@ -2538,7 +2569,7 @@ static void guc_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);if (likely (!intel_context_is_barrier (ce))) -intel_engine_pm_put (ce->engine); +intel_engine_pm_put_async (ce->engine); }static void guc_context_post_unpin (struct intel_context *ce)@@ -2665,11 +2696,11 @@ static void guc_parent_context_unpin(struct intel_context *ce)for_each_engine_masked (engine, ce->engine->gt, ce->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine);for_each_child (ce, child)for_each_engine_masked (engine, child->engine->gt, child->engine->mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); } static void __guc_context_sched_enable(struct intel_guc *guc,@@ -2788,6 +2819,8 @@ static struct i915_sw_fence *guc_context_block(struct intel_context *ce)spin_unlock_irqrestore (&ce->guc_state.lock, flags); +sched_disable_context_delete (ce); + with_intel_runtime_pm(runtime_pm, wakeref)__guc_context_sched_disable (guc, ce, guc_id);@@ -2914,8 +2947,202 @@ static void guc_context_ban(struct intel_context *ce, struct i915_request *rq) 1);spin_unlock_irqrestore (&ce->guc_state.lock, flags); } + +sched_disable_context_delete (ce); +} + +#define next_sched_disable_time (guc, now, ce) \ + (guc->sched_disable_delay_ns - \ + (ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time))) +static void ____sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +bool is_first; + +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (list_empty (&ce->guc_sched_disable_link)); + + is_first =list_is_first (&ce->guc_sched_disable_link, + &guc->sched_disable_list); +list_del_init (&ce->guc_sched_disable_link); +if (list_empty (&guc->sched_disable_list)) { +hrtimer_try_to_cancel (&guc->sched_disable_timer); + }else if (is_first) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc,ktime_get (), + first); + +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (next_time), +HRTIMER_MODE_REL_PINNED ); + } +} + +static void __sched_disable_context_delete (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +intel_context_sched_disable_unpin (ce); +____sched_disable_context_delete (guc, ce); + } +} + +static void sched_disable_context_delete (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__sched_disable_context_delete (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} + +static void sched_disable_context_add (struct intel_guc *guc, +struct intel_context *ce) +{ +unsigned long flags; + +GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link)); + + ce->guc_sched_disable_time =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); +if (list_empty (&guc->sched_disable_list)) +hrtimer_start (&guc->sched_disable_timer, +ns_to_ktime (guc->sched_disable_delay_ns), +HRTIMER_MODE_REL_PINNED ); +list_add_tail (&ce->guc_sched_disable_link, &guc->sched_disable_list); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); +} + +static void sched_disable_contexts_flush (struct intel_guc *guc) +{ +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +hrtimer_try_to_cancel (&guc->sched_disable_timer); + +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); } +#define should_sched_be_disabled (guc, now, ce) \ + ((ktime_to_ns(now) - ktime_to_ns(ce->guc_sched_disable_time)) > \ + (guc->sched_disable_delay_ns / 4) * 3) +static enum hrtimer_restart sched_disable_timer_func (struct hrtimer *hrtimer) +{ + struct intel_guc *guc = container_of(hrtimer, struct intel_guc, + sched_disable_timer); +struct intel_runtime_pm *runtime_pm = &guc_to_gt (guc)->i915->runtime_pm; +struct intel_context *ce, *cn; +unsigned long flags; +ktime_t now; + +if (list_empty (&guc->sched_disable_list)) +return HRTIMER_NORESTART ; + + now =ktime_get (); + +spin_lock_irqsave (&guc->sched_disable_lock, flags); + +list_for_each_entry_safe_reverse (ce, cn, &guc->sched_disable_list, + guc_sched_disable_link) { +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +/* +* If a context has been waiting for 3/4 of its delay or more, +* issue the schedule disable. Using this heuristic allows more +* than 1 context to have its scheduling disabled when this +* timer is run. +*/ +if (!should_sched_be_disabled (guc, now, ce)) +break ; + +list_del_init (&ce->guc_sched_disable_link); + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); +continue ; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); +continue ; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); + } + +if (!list_empty (&guc->sched_disable_list)) { +struct intel_context *first = +list_first_entry (&guc->sched_disable_list, +typeof (*first), + guc_sched_disable_link); +u64 next_time =next_sched_disable_time (guc, now, first); + +hrtimer_forward (hrtimer, now,ns_to_ktime (next_time)); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_RESTART ; + }else { +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + +return HRTIMER_NORESTART ; + } +} + +#define guc_id_pressure (max, in_use) (in_use > (max / 4) * 3)static void guc_context_sched_disable (struct intel_context *ce) {struct intel_guc *guc =ce_to_guc (ce);@@ -2924,8 +3151,14 @@ static void guc_context_sched_disable(struct intel_context *ce)intel_wakeref_t wakeref;u16 guc_id;bool enabled; +int guc_id_index =intel_context_is_parent (ce) ? +GUC_SUBMIT_ENGINE_MULTI_LRC :GUC_SUBMIT_ENGINE_SINGLE_LRC ; +int max_guc_ids =intel_context_is_parent (ce) ? +NUMBER_MULTI_LRC_GUC_ID (guc) : + guc->num_guc_ids -NUMBER_MULTI_LRC_GUC_ID (guc);GEM_BUG_ON (intel_context_is_child (ce)); +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link));if (submission_disabled (guc) ||context_guc_id_invalid (ce) || !lrc_desc_registered (guc, ce->guc_id)) {@@ -2936,6 +3169,18 @@ static void guc_context_sched_disable(struct intel_context *ce)if (!context_enabled (ce)) goto unpin; +/* +* If no guc_id pressure and the context isn't closed we delay the +* schedule disable to not to continuously disable / enable scheduling +* putting pressure on both the i915 and GuC. Delay is configurable via +* debugfs, default 1s. +*/ +if (!guc_id_pressure (max_guc_ids, guc->guc_ids_in_use[guc_id_index]) && + !intel_context_is_closed (ce) && guc->sched_disable_delay_ns) { +sched_disable_context_add (guc, ce); +return ; + } +spin_lock_irqsave (&ce->guc_state.lock, flags);/* @@ -3294,6 +3539,58 @@ static void remove_from_context(struct i915_request *rq)i915_request_notify_execute_cb_imm (rq); } +static void __guc_context_close (struct intel_guc *guc, +struct intel_context *ce) +{ +lockdep_assert_held (&guc->sched_disable_lock); +GEM_BUG_ON (intel_context_is_child (ce)); + +if (!list_empty (&ce->guc_sched_disable_link)) { +struct intel_runtime_pm *runtime_pm = + ce->engine->uncore->rpm; +intel_wakeref_t wakeref; +bool enabled; +u16 guc_id; + +spin_lock (&ce->guc_state.lock); + enabled =context_enabled (ce); +if (unlikely (!enabled ||submission_disabled (guc))) { +if (enabled) +clr_context_enabled (ce); +spin_unlock (&ce->guc_state.lock); +intel_context_sched_disable_unpin (ce); + goto update_list; + } +if (unlikely (atomic_add_unless (&ce->pin_count,-2 ,2 ))) { +spin_unlock (&ce->guc_state.lock); + goto update_list; + } + guc_id =prep_context_pending_disable (ce); +spin_unlock (&ce->guc_state.lock); + + with_intel_runtime_pm(runtime_pm, wakeref) +__guc_context_sched_disable (guc, ce, guc_id); +update_list: +____sched_disable_context_delete (guc, ce); + } +} + +static void guc_context_close (struct intel_context *ce) +{ +struct intel_guc *guc =ce_to_guc (ce); +unsigned long flags; + +/* +* If we close the context and a schedule disable is pending a delay, do +* it immediately. +*/ +if (!list_empty (&ce->guc_sched_disable_link)) { +spin_lock_irqsave (&guc->sched_disable_lock, flags); +__guc_context_close (guc, ce); +spin_unlock_irqrestore (&guc->sched_disable_lock, flags); + } +} +static struct intel_context * guc_create_parallel(struct intel_engine_cs **engines, unsigned int num_siblings,@@ -3308,6 +3605,7 @@ static const struct intel_context_ops guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3538,6 +3836,10 @@ static int guc_request_alloc(struct i915_request *rq) rq->reserved_space -=GUC_REQUEST_SIZE ; +GEM_BUG_ON (!list_empty (&ce->guc_sched_disable_link) && +atomic_read (&ce->pin_count) <3 ); +sched_disable_context_delete (ce); +/* * guc_ids are exhausted or a heuristic is met indicating too many * guc_ids are waiting on requests with submission dependencies (not @@ -3667,7 +3969,7 @@ static void guc_virtual_context_unpin(struct intel_context *ce)__guc_context_unpin (ce);for_each_engine_masked (engine, ce->engine->gt, mask, tmp) -intel_engine_pm_put (engine); +intel_engine_pm_put_async (engine); }static void guc_virtual_context_enter (struct intel_context *ce)@@ -3708,6 +4010,7 @@ static const struct intel_context_ops virtual_guc_context_ops = { .post_unpin = guc_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .cancel_request = guc_context_cancel_request,@@ -3819,6 +4122,7 @@ static const struct intel_context_ops virtual_parent_context_ops = { .post_unpin = guc_parent_context_post_unpin, .ban = guc_context_ban, + .close = guc_context_close, .enter = guc_virtual_context_enter, .exit = guc_virtual_context_exit,@@ -4924,7 +5228,11 @@ void intel_guc_submission_print_info(struct intel_guc *guc,drm_printf (p,"GuC Number Outstanding Submission G2H: %u\n" ,atomic_read (&guc->outstanding_submission_g2h));drm_printf (p,"GuC Number GuC IDs: %d\n" , guc->num_guc_ids); -drm_printf (p,"GuC Max Number GuC IDs: %d\n\n" , guc->max_guc_ids); +drm_printf (p,"GuC Max Number GuC IDs: %d\n" , guc->max_guc_ids); +drm_printf (p,"GuC single-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_SINGLE_LRC ]); +drm_printf (p,"GuC multi-lrc GuC IDs in use: %d\n" , + guc->guc_ids_in_use[GUC_SUBMIT_ENGINE_MULTI_LRC ]);drm_printf (p,"GuC max context registered: %u\n\n" , guc->lrcd_reg.max_idx);drivers/gpu/drm/i915/gt/uc/selftest_guc_flow_control.c +15
-4@@ -174,7 +174,8 @@ static int multi_lrc_not_blocked(struct intel_gt *gt, bool flow_control)#define NUM_RQ_PER_CONTEXT 2#define HEARTBEAT_INTERVAL 1500 -static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids,bool hang) +static int __intel_guc_flow_control_guc (void *arg,bool limit_guc_ids, +bool hang,bool sched_disable_delay) {struct intel_gt *gt = arg;struct intel_guc *guc = >->uc.guc;@@ -203,6 +204,9 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangif (limit_guc_ids) guc->num_guc_ids =NUM_GUC_ID ; +if (sched_disable_delay) + guc->sched_disable_delay_ns =SCHED_DISABLE_DELAY_NS /5 ; + ce =intel_context_create (intel_selftest_find_any_engine (gt));if (IS_ERR (ce)) { ret =PTR_ERR (ce);@@ -391,6 +395,7 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hang guc->num_guc_ids = guc->max_guc_ids; guc->gse_hang_expected = false; guc->inject_bad_sched_disable = false; + guc->sched_disable_delay_ns =0 ;kfree (contexts);return ret;@@ -398,17 +403,22 @@ static int __intel_guc_flow_control_guc(void *arg, bool limit_guc_ids, bool hangstatic int intel_guc_flow_control_guc_ids (void *arg) { -return __intel_guc_flow_control_guc (arg, true, false); +return __intel_guc_flow_control_guc (arg, true, false, false); +} + +static int intel_guc_flow_control_guc_ids_sched_disable_delay (void *arg) +{ +return __intel_guc_flow_control_guc (arg, true, false, true); }static int intel_guc_flow_control_lrcd_reg (void *arg) { -return __intel_guc_flow_control_guc (arg, false, false); +return __intel_guc_flow_control_guc (arg, false, false, false); }static int intel_guc_flow_control_hang_state_machine (void *arg) { -return __intel_guc_flow_control_guc (arg, true, true); +return __intel_guc_flow_control_guc (arg, true, true, false); }#define NUM_RQ_STRESS_CTBS 0x4000@@ -861,6 +871,7 @@ int intel_guc_flow_control(struct drm_i915_private *i915)static const struct i915_subtest tests[] = {SUBTEST (intel_guc_flow_control_stress_ctbs),SUBTEST (intel_guc_flow_control_guc_ids), +SUBTEST (intel_guc_flow_control_guc_ids_sched_disable_delay),SUBTEST (intel_guc_flow_control_lrcd_reg),SUBTEST (intel_guc_flow_control_hang_state_machine),SUBTEST (intel_guc_flow_control_multi_lrc_guc_ids),drivers/gpu/drm/i915/i915_selftest.h +2
-0@@ -92,12 +92,14 @@ int __i915_subtests(const char *caller, T, ARRAY_SIZE(T), data)#define i915_live_subtests (T , data) ({ \ typecheck(struct drm_i915_private *, data); \ + (data)->gt.uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __i915_live_setup, __i915_live_teardown, \ T, ARRAY_SIZE(T), data); \ })#define intel_gt_live_subtests (T , data) ({ \ typecheck(struct intel_gt *, data); \ + (data)->uc.guc.sched_disable_delay_ns = 0; \ __i915_subtests(__func__, \ __intel_gt_live_setup, __intel_gt_live_teardown, \ T, ARRAY_SIZE(T), data); \drivers/gpu/drm/i915/i915_trace.h +10
-0@@ -933,6 +933,11 @@ DEFINE_EVENT(intel_context, intel_context_reset,TP_ARGS (ce) ); +DEFINE_EVENT (intel_context, intel_context_close, + TP_PROTO(struct intel_context *ce), +TP_ARGS (ce) +); +DEFINE_EVENT (intel_context, intel_context_ban, TP_PROTO(struct intel_context *ce), TP_ARGS(ce)@@ -1035,6 +1040,11 @@ trace_intel_context_reset(struct intel_context *ce) { } +static inline void +trace_intel_context_close (struct intel_context *ce) +{ +} +static inline void trace_intel_context_ban (struct intel_context *ce) {drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +1
-1@@ -2112,5 +2112,5 @@ int i915_gem_gtt_live_selftests(struct drm_i915_private *i915)GEM_BUG_ON (offset_in_page (i915->ggtt.vm.total)); -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }drivers/gpu/drm/i915/selftests/i915_perf.c +1
-1@@ -431,7 +431,7 @@ int i915_perf_live_selftests(struct drm_i915_private *i915)if (err)return err; - err =i915_subtests (tests, i915); + err =i915_live_subtests (tests, i915);destroy_empty_config (&i915->perf);drivers/gpu/drm/i915/selftests/i915_request.c +1
-1@@ -1693,7 +1693,7 @@ int i915_request_live_selftests(struct drm_i915_private *i915)if (intel_gt_is_wedged (&i915->gt))return 0 ; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }static int switch_to_kernel_sync (struct intel_context *ce,int err)drivers/gpu/drm/i915/selftests/i915_vma.c +1
-1@@ -1085,5 +1085,5 @@ int i915_vma_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_vma_remapped_gtt), }; -return i915_subtests (tests, i915); +return i915_live_subtests (tests, i915); }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch